diff options
| author | JMC47 <JMC4789@gmail.com> | 2022-09-20 17:14:07 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-20 17:14:07 -0400 |
| commit | 22197c09a3cf2753c007d8ef8d75daa5fc2c44b9 (patch) | |
| tree | 14d5aa4ae61d100f3bc7a394021963258fbf3dc1 /Source/Core/VideoCommon/VertexShaderManager.cpp | |
| parent | 4ea694a7e403c673b457643e52435b355c96fd87 (diff) | |
| parent | ee692abbe1032e9eb888defedb1bb00f569f68a3 (diff) | |
Merge pull request #10781 from tellowkrinkle/UberVertexLoader
VideoCommon: Add dynamic vertex loader for ubershaders to reduce pipeline count
Diffstat (limited to 'Source/Core/VideoCommon/VertexShaderManager.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VertexShaderManager.cpp | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index ce43235977..b74c820271 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -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, std::array<u32, N>* old_value, + const std::array<AttributeFormat, N>& attribute) +{ + 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) |
