From 9009bb26304a3f312804c361917a5b2d5202c43c Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 22 Oct 2024 14:48:48 +0100 Subject: [PATCH] Added matrix row stride to reflection The shader reflection needs to specify the row stride for matrix3 types. This ensures that when mat3 is in a uniform block that the padding is taken into account when writing. Rowstride is number of bytes that a row takes in memory. Change-Id: Ide7629bd1615acafb0d451c46375b57ff5718cb0 Signed-off-by: David Steele --- .../test-graphics-controller.cpp | 18 ++++++++++++- .../test-graphics-controller.h | 1 + .../test-graphics-reflection.cpp | 1 + .../test-graphics-reflection.h | 3 ++- .../gles-impl/gles-graphics-reflection.cpp | 27 ++++++++++--------- .../vulkan-impl/vulkan-reflection.cpp | 4 ++- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp index f241257e2..c12f6a95c 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp @@ -718,10 +718,26 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com if(currentPipeline) { auto& bindings = cmd.data.bindUniformBuffers; - auto buffer = bindings.standaloneUniformsBufferBinding; + auto buffer = bindings.standaloneUniformsBufferBinding; // based on reflection, issue gl calls buffer.buffer->BindAsUniformBuffer(static_cast(currentPipeline->programState.program), bindings.standaloneUniformsBufferBinding); + + // Store off uniform bindings for test retrieval: + if(!bindings.uniformBufferBindings.empty()) + { + mLastUniformBinding.buffer = bindings.uniformBufferBindings.back().buffer; + mLastUniformBinding.binding = bindings.uniformBufferBindings.back().binding; + mLastUniformBinding.offset = bindings.uniformBufferBindings.back().offset; + mLastUniformBinding.emulated = bindings.uniformBufferBindings.back().emulated; + } + else + { + mLastUniformBinding.buffer = bindings.standaloneUniformsBufferBinding.buffer; + mLastUniformBinding.binding = bindings.standaloneUniformsBufferBinding.binding; + mLastUniformBinding.offset = bindings.standaloneUniformsBufferBinding.offset; + mLastUniformBinding.emulated = true; + } } break; } diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.h b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.h index ba91f897f..0ccda5913 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.h +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.h @@ -565,6 +565,7 @@ public: std::vector mCustomUniforms; std::vector mCustomUniformBlocks; + UniformBufferBindingDescriptor mLastUniformBinding; }; } // namespace Dali diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.cpp b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.cpp index 2d507f78b..d2cc49c50 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.cpp +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.cpp @@ -333,6 +333,7 @@ bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::Uni out.members[i].location = memberUniform.locations[0]; out.members[i].elementCount = memberUniform.numElements; out.members[i].elementStride = memberUniform.elementStride; + out.members[i].matrixStride = memberUniform.matrixStride; } return true; diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.h b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.h index 3521ed0dc..221c3ef1b 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.h +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-reflection.h @@ -61,6 +61,7 @@ public: // Test methods uint32_t numElements{0u}; // 0 elements means this isn't an array; 1 element means this is an array of size 1 Property::Type type; uint32_t elementStride{0u}; // array element stride, 0 - tightly packed + uint32_t matrixStride{0u}; // Matrix row stride in bytes, 0 - tightly packed }; struct TestUniformBlockInfo @@ -98,4 +99,4 @@ public: // Test methods } // namespace Dali -#endif //DALI_TEST_GRAPHICS_REFLECTION_H +#endif // DALI_TEST_GRAPHICS_REFLECTION_H diff --git a/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp b/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp index 1fb69a0be..deff32df6 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-reflection.cpp @@ -304,19 +304,20 @@ void Reflection::BuildUniformBlockReflection() } // Obtain all parameters for active uniforms - auto getActiveUniformParams = [gl, glProgram, uniformIndices](GLenum param) { + auto getActiveUniformParams = [gl, glProgram, uniformIndices](GLenum param) + { std::vector params; params.resize(uniformIndices.size()); gl->GetActiveUniformsiv(glProgram, uniformIndices.size(), uniformIndices.data(), param, params.data()); return params; }; - auto activeUniformType = getActiveUniformParams(GL_UNIFORM_TYPE); - auto activeUniformSize = getActiveUniformParams(GL_UNIFORM_SIZE); - auto activeUniformNameLength = getActiveUniformParams(GL_UNIFORM_NAME_LENGTH); - auto activeUniformBlockIndex = getActiveUniformParams(GL_UNIFORM_BLOCK_INDEX); - auto activeUniformOffset = getActiveUniformParams(GL_UNIFORM_OFFSET); - + auto activeUniformType = getActiveUniformParams(GL_UNIFORM_TYPE); + auto activeUniformSize = getActiveUniformParams(GL_UNIFORM_SIZE); + auto activeUniformNameLength = getActiveUniformParams(GL_UNIFORM_NAME_LENGTH); + auto activeUniformBlockIndex = getActiveUniformParams(GL_UNIFORM_BLOCK_INDEX); + auto activeUniformOffset = getActiveUniformParams(GL_UNIFORM_OFFSET); + auto activeUniformMatrixStride = getActiveUniformParams(GL_UNIFORM_MATRIX_STRIDE); // Extract only uniform blocks and collect data // collect samplers into separate array std::vector samplers; @@ -350,6 +351,7 @@ void Reflection::BuildUniformBlockReflection() uniformInfo->bufferIndex = blockIndex; uniformInfo->binding = blockIndex == 0 ? i : 0; // this will be reset later uniformInfo->offset = activeUniformOffset[i]; + uniformInfo->matrixStride = activeUniformMatrixStride[i]; } uniformInfo->location = location; // location must be set later and sorted by offset @@ -373,9 +375,8 @@ void Reflection::BuildUniformBlockReflection() uint32_t blockIndex = 0; for(auto& ubo : mUniformBlocks) { - std::sort(ubo.members.begin(), ubo.members.end(), [](auto& lhs, auto& rhs) { - return lhs.offset < rhs.offset; - }); + std::sort(ubo.members.begin(), ubo.members.end(), [](auto& lhs, auto& rhs) + { return lhs.offset < rhs.offset; }); if(blockIndex > 0) { @@ -542,6 +543,7 @@ bool Reflection::GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInf out.members[i].location = memberUniform.location; out.members[i].elementCount = memberUniform.elementCount; out.members[i].elementStride = memberUniform.elementStride; + out.members[i].matrixStride = memberUniform.matrixStride; } return true; @@ -690,7 +692,7 @@ Graphics::ShaderLanguage Reflection::GetLanguage() const void Reflection::SortOpaques() { - //Determine declaration order of each sampler + // Determine declaration order of each sampler auto& programCreateInfo = mProgram.GetCreateInfo(); std::vector data; @@ -715,7 +717,8 @@ void Reflection::SortOpaques() ParseShaderSamplers(vertShader, mUniformOpaques, samplerPosition, samplerPositions); ParseShaderSamplers(fragShader, mUniformOpaques, samplerPosition, samplerPositions); - std::sort(mUniformOpaques.begin(), mUniformOpaques.end(), [](const UniformInfo& a, const UniformInfo& b) { return a.offset < b.offset; }); + std::sort(mUniformOpaques.begin(), mUniformOpaques.end(), [](const UniformInfo& a, const UniformInfo& b) + { return a.offset < b.offset; }); } } // namespace Dali::Graphics::GLES diff --git a/dali/internal/graphics/vulkan-impl/vulkan-reflection.cpp b/dali/internal/graphics/vulkan-impl/vulkan-reflection.cpp index 57bdd248c..27889e282 100644 --- a/dali/internal/graphics/vulkan-impl/vulkan-reflection.cpp +++ b/dali/internal/graphics/vulkan-impl/vulkan-reflection.cpp @@ -249,7 +249,8 @@ void Reflection::BuildReflection() out.location = 0; out.offset = memb.offset; out.elementStride = memb.array.dims_count ? memb.array.stride : 0; - out.elementCount = memb.array.dims[0]; // will be zero for non-array + out.matrixStride = memb.numeric.matrix.stride; // will be zero for non-matrix + out.elementCount = memb.array.dims[0]; // will be zero for non-array out.uniformClass = UniformClass::UNIFORM_BUFFER; out.bufferIndex = blockIndex++; // TODO: do we need this for Vulkan? block.size += memb.padded_size; @@ -443,6 +444,7 @@ bool Reflection::GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInf out.members[i].location = memberUniform.location; out.members[i].elementCount = memberUniform.elementCount; out.members[i].elementStride = memberUniform.elementStride; + out.members[i].matrixStride = memberUniform.matrixStride; } return true; -- 2.34.1