VideoCommon: Add dynamic vertex loader to ubershaders

This commit is contained in:
TellowKrinkle
2022-06-18 01:09:35 -05:00
parent 720b3f5519
commit 4c629c2bee
17 changed files with 253 additions and 66 deletions

View File

@ -606,13 +606,42 @@ void VertexShaderManager::SetMaterialColorChanged(int index)
nMaterialsChanged[index] = true;
}
void VertexShaderManager::SetVertexFormat(u32 components)
static void UpdateValue(bool* dirty, u32* old_value, u32 new_value)
{
if (components != constants.components)
{
constants.components = components;
dirty = true;
}
if (*old_value == new_value)
return;
*old_value = new_value;
*dirty = true;
}
static void UpdateOffset(bool* dirty, bool include_components, u32* old_value,
const AttributeFormat& attribute)
{
if (!attribute.enable)
return;
u32 new_value = attribute.offset / 4; // GPU uses uint offsets
if (include_components)
new_value |= attribute.components << 16;
UpdateValue(dirty, old_value, new_value);
}
template <size_t N>
static void UpdateOffsets(bool* dirty, bool include_components, u32 (*old_value)[N],
const AttributeFormat (&attribute)[N])
{
for (size_t i = 0; i < N; i++)
UpdateOffset(dirty, include_components, &(*old_value)[i], attribute[i]);
}
void VertexShaderManager::SetVertexFormat(u32 components, const PortableVertexDeclaration& format)
{
UpdateValue(&dirty, &constants.components, components);
UpdateValue(&dirty, &constants.vertex_stride, format.stride / 4);
UpdateOffset(&dirty, true, &constants.vertex_offset_position, format.position);
UpdateOffset(&dirty, false, &constants.vertex_offset_posmtx, format.posmtx);
UpdateOffsets(&dirty, true, &constants.vertex_offset_texcoords, format.texcoords);
UpdateOffsets(&dirty, false, &constants.vertex_offset_colors, format.colors);
UpdateOffsets(&dirty, false, &constants.vertex_offset_normals, format.normals);
}
void VertexShaderManager::SetTexMatrixInfoChanged(int index)