From 477ea5d68367c49f1de6ec68a51d1c6d43059906 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Mon, 8 Mar 2021 14:50:55 +0000 Subject: [PATCH] Test harness for custom uniform support in uniform block Change-Id: Ic323a50da0251d9880d5934950af1308df42d4c2 --- .../dali-test-suite-utils/test-gl-abstraction.h | 26 ++- .../test-graphics-command-buffer.cpp | 2 - .../test-graphics-controller.cpp | 3 +- .../test-graphics-controller.h | 7 + .../test-graphics-program.cpp | 13 +- .../dali-test-suite-utils/test-graphics-program.h | 4 +- .../test-graphics-reflection.cpp | 174 +++++++++++++-------- .../test-graphics-reflection.h | 8 +- 8 files changed, 162 insertions(+), 75 deletions(-) diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h index 64696b7..d096f7e 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h @@ -38,6 +38,16 @@ namespace Dali { + +struct UniformData +{ + std::string name; + Property::Type type; + UniformData( const std::string& name, Property::Type type = Property::Type::NONE) + : name(name), type(type) + {} +}; + class DALI_CORE_API TestGlAbstraction : public Dali::Integration::GlAbstraction { public: @@ -995,6 +1005,11 @@ public: GetUniformLocation(program, "uViewMatrix"); GetUniformLocation(program, "uLightCameraProjectionMatrix"); GetUniformLocation(program, "uLightCameraViewMatrix"); + + for( const auto& uniform : mCustomUniformData ) + { + GetUniformLocation(program, uniform.name.c_str()); + } } inline void PixelStorei(GLenum pname, GLint param) override @@ -2291,7 +2306,7 @@ public: // TEST FUNCTIONS } } - fprintf(stderr, "Not found, printing possible values:\n"); + fprintf(stderr, "%s Not found, printing possible values:\n", name); for(ProgramUniformMap::const_iterator program_it = mUniforms.begin(); program_it != mUniforms.end(); ++program_it) @@ -2310,7 +2325,7 @@ public: // TEST FUNCTIONS if(mProgramUniforms.GetUniformValue(programId, uniformId, origValue)) { std::stringstream out; - out << uniform_it->first << ": " << origValue; + out << "Program: " << programId << ", " << uniform_it->first << ": " << origValue; fprintf(stderr, "%s\n", out.str().c_str()); } } @@ -2344,6 +2359,11 @@ public: // TEST FUNCTIONS return false; } + inline void SetCustomUniforms(std::vector& customUniformData) + { + mCustomUniformData = customUniformData; + } + inline GLuint GetLastShaderCompiled() const { return mLastShaderCompiled; @@ -2527,6 +2547,8 @@ private: typedef std::map ProgramUniformMap; ProgramUniformMap mUniforms; + std::vector mCustomUniformData{}; + template struct ProgramUniformValue : public std::map > { diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-command-buffer.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-command-buffer.cpp index 88e7168..70f3f0e 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-command-buffer.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-command-buffer.cpp @@ -58,8 +58,6 @@ void TestGraphicsCommandBuffer::GetStateForDrawCall( int drawCallIndex ) ++index; } } - - // } std::vector TestGraphicsCommandBuffer::GetCommandsByType( CommandTypeMask mask ) diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.cpp index 755d259..782835e 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.cpp @@ -579,7 +579,6 @@ void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& su if (!bindUniformBuffersCmds.empty()) { auto buffer = bindUniformBuffersCmds[0]->bindUniformBuffers.standaloneUniformsBufferBinding; - printf("%p\n", buffer.buffer); // based on reflection, issue gl calls buffer.buffer->BindAsUniformBuffer( static_cast(pipeline->programState.program) ); @@ -773,7 +772,7 @@ Graphics::UniquePtr TestGraphicsController::CreateProgram(con } mProgramCache.emplace_back(); - mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats); + mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats, mCustomUniforms); for(auto& shader : *(programCreateInfo.shaderState)) { auto graphicsShader = Uncast(shader.shader); diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.h b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.h index fa2fd63..cbe78ec 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.h @@ -299,6 +299,11 @@ public: // Test Functions mVertexFormats = vfs; } + void AddCustomUniforms(std::vector& customUniforms) + { + mCustomUniforms = customUniforms; + } + void ClearSubmitStack() { mSubmitStack.clear(); @@ -336,6 +341,8 @@ public: TestGraphicsProgramImpl* programImpl; }; std::vector mProgramCache; + + std::vector mCustomUniforms; }; } // namespace Dali diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.cpp index 9a0afa6..0bf698a 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.cpp @@ -18,13 +18,16 @@ namespace Dali { -TestGraphicsProgramImpl::TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats) +TestGraphicsProgramImpl::TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats, std::vector& customUniforms) : mGl(gl), mCreateInfo(createInfo), - mReflection(gl, vertexFormats) + mReflection(gl, vertexFormats, createInfo, customUniforms) { mId = mGl.CreateProgram(); - mGl.LinkProgram(1); // Ensure active sampler uniforms are set + + // Ensure active sampler uniforms are set + mGl.SetCustomUniforms(customUniforms); + mGl.LinkProgram(mId); } bool TestGraphicsProgramImpl::GetParameter(uint32_t parameterId, void* outData) @@ -33,9 +36,9 @@ bool TestGraphicsProgramImpl::GetParameter(uint32_t parameterId, void* outData) return true; } -TestGraphicsProgram::TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats) +TestGraphicsProgram::TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats, std::vector& customUniforms) { - mImpl = new TestGraphicsProgramImpl(gl, createInfo, vertexFormats); + mImpl = new TestGraphicsProgramImpl(gl, createInfo, vertexFormats, customUniforms); } TestGraphicsProgram::TestGraphicsProgram(TestGraphicsProgramImpl* impl) diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.h b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.h index c098718..3aae276 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.h @@ -27,7 +27,7 @@ namespace Dali class TestGraphicsProgramImpl { public: - TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats); + TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats, std::vector& customUniforms); // For API const TestGraphicsReflection& GetReflection() const @@ -54,7 +54,7 @@ public: class TestGraphicsProgram : public Graphics::Program { public: - TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats); + TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats, std::vector& customUniforms); TestGraphicsProgram(TestGraphicsProgramImpl* impl); const TestGraphicsReflection& GetReflection() const diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp index 7b2b0dc..883eb2d 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp @@ -15,6 +15,8 @@ */ #include "test-graphics-reflection.h" +#include "test-graphics-shader.h" + #include #include #include @@ -22,46 +24,37 @@ namespace Dali { namespace { -// Add members -struct UniformData +static const std::vector UNIFORMS = { - std::string name; - Property::Type type; - UniformData( const std::string& name, Property::Type type = Property::Type::NONE) - : name(name), type(type) - {} + UniformData("uRendererColor",Property::Type::FLOAT), + UniformData("uCustom", Property::Type::INTEGER), + UniformData("uCustom3", Property::Type::VECTOR3), + UniformData("uFadeColor", Property::Type::VECTOR4), + UniformData("uUniform1", Property::Type::VECTOR4), + UniformData("uUniform2", Property::Type::VECTOR4), + UniformData("uUniform3", Property::Type::VECTOR4), + UniformData("uFadeProgress", Property::Type::FLOAT), + UniformData("uANormalMatrix", Property::Type::MATRIX3), + UniformData("sEffect", Property::Type::FLOAT), + UniformData("sTexture", Property::Type::FLOAT), + UniformData("sTextureRect", Property::Type::FLOAT), + UniformData("sGloss", Property::Type::FLOAT), + UniformData("uColor", Property::Type::VECTOR4), + UniformData("uModelMatrix", Property::Type::MATRIX), + UniformData("uModelView", Property::Type::MATRIX), + UniformData("uMvpMatrix", Property::Type::MATRIX), + UniformData("uNormalMatrix", Property::Type::MATRIX3), + UniformData("uProjection", Property::Type::MATRIX), + UniformData("uSize", Property::Type::VECTOR3), + UniformData("uViewMatrix", Property::Type::MATRIX), + UniformData("uLightCameraProjectionMatrix", Property::Type::MATRIX), + UniformData("uLightCameraViewMatrix", Property::Type::MATRIX), }; -static const std::vector UNIFORMS = - { - UniformData("uRendererColor",Property::Type::FLOAT), - UniformData("uCustom", Property::Type::INTEGER), - UniformData("uCustom3", Property::Type::VECTOR3), - UniformData("uFadeColor", Property::Type::VECTOR4), - UniformData("uUniform1", Property::Type::VECTOR4), - UniformData("uUniform2", Property::Type::VECTOR4), - UniformData("uUniform3", Property::Type::VECTOR4), - UniformData("uFadeProgress", Property::Type::FLOAT), - UniformData("uANormalMatrix", Property::Type::MATRIX3), - UniformData("sEffect", Property::Type::FLOAT), - UniformData("sTexture", Property::Type::FLOAT), - UniformData("sTextureRect", Property::Type::FLOAT), - UniformData("sGloss", Property::Type::FLOAT), - UniformData("uColor", Property::Type::VECTOR4), - UniformData("uModelMatrix", Property::Type::MATRIX), - UniformData("uModelView", Property::Type::MATRIX), - UniformData("uMvpMatrix", Property::Type::MATRIX), - UniformData("uNormalMatrix", Property::Type::MATRIX3), - UniformData("uProjection", Property::Type::MATRIX), - UniformData("uSize", Property::Type::VECTOR3), - UniformData("uViewMatrix", Property::Type::MATRIX), - UniformData("uLightCameraProjectionMatrix", Property::Type::MATRIX), - UniformData("uLightCameraViewMatrix", Property::Type::MATRIX), - - }; -} - -TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vfs) - : mGl(gl) +} + +TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vfs, const Graphics::ProgramCreateInfo& createInfo, std::vector& customUniforms) + : mGl(gl), + mCustomUniforms(customUniforms) { for(Property::Array::SizeType i = 0; i < vfs.Count(); ++i) { @@ -78,6 +71,40 @@ TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, Property:: } } } + + mDefaultUniformBlock.name = ""; + mDefaultUniformBlock.members = {}; + mDefaultUniformBlock.binding = 0; + mDefaultUniformBlock.size = 64 * (UNIFORMS.size() + mCustomUniforms.size()); + mDefaultUniformBlock.descriptorSet = 0; + mDefaultUniformBlock.members.clear(); + int loc = 0; + for( const auto& data : UNIFORMS ) + { + mDefaultUniformBlock.members.emplace_back(); + auto& item = mDefaultUniformBlock.members.back(); + item.name = data.name; + item.binding = 0; + item.offset = loc*64; + item.location = loc++; + item.bufferIndex = 0; + item.uniformClass = Graphics::UniformClass::UNIFORM; + } + + for( const auto& data : mCustomUniforms ) + { + fprintf(stderr, "\ncustom uniforms: %s\n", data.name.c_str()); + mDefaultUniformBlock.members.emplace_back(); + auto& item = mDefaultUniformBlock.members.back(); + item.name = data.name; + item.binding = 0; + item.offset = loc*64; + item.location = loc++; + item.bufferIndex = 0; + item.uniformClass = Graphics::UniformClass::UNIFORM; + } + + mUniformBlocks.push_back(mDefaultUniformBlock); } uint32_t TestGraphicsReflection::GetVertexAttributeLocation(const std::string& name) const @@ -119,7 +146,7 @@ std::vector TestGraphicsReflection::GetVertexAttributeLocations() cons uint32_t TestGraphicsReflection::GetUniformBlockCount() const { - return 1u; + return mUniformBlocks.size(); } uint32_t TestGraphicsReflection::GetUniformBlockBinding(uint32_t index) const @@ -131,30 +158,34 @@ uint32_t TestGraphicsReflection::GetUniformBlockSize(uint32_t index) const { // 64 bytes per uniform (64 = 4x4 matrix) // TODO: fix if array will be used - return 64 * UNIFORMS.size(); + return 64 * (UNIFORMS.size() + mCustomUniforms.size()); } bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInfo& out) const { - auto& info = out; - info.name = ""; - info.members = {}; - info.binding = 0; - info.size = 64 * UNIFORMS.size(); - info.descriptorSet = 0; - info.members.clear(); - int loc = 0; - for( const auto& data : UNIFORMS ) + if(index >= mUniformBlocks.size()) { - info.members.emplace_back(); - auto& item = info.members.back(); - item.name = data.name; - item.binding = 0; - item.offset = loc*64; - item.location = loc++; - item.bufferIndex = 0; - item.uniformClass = Graphics::UniformClass::UNIFORM; + return false; + } + + const auto& block = mUniformBlocks[index]; + + out.name = block.name; + out.binding = block.binding; + out.descriptorSet = block.descriptorSet; + auto membersSize = block.members.size(); + out.members.resize(membersSize); + out.size = block.size; + for(auto i = 0u; i < out.members.size(); ++i) + { + const auto& memberUniform = block.members[i]; + out.members[i].name = memberUniform.name; + out.members[i].binding = block.binding; + out.members[i].uniformClass = Graphics::UniformClass::UNIFORM; + out.members[i].offset = memberUniform.offset; + out.members[i].location = memberUniform.location; } + return true; } @@ -170,17 +201,38 @@ std::string TestGraphicsReflection::GetUniformBlockName(uint32_t blockIndex) con uint32_t TestGraphicsReflection::GetUniformBlockMemberCount(uint32_t blockIndex) const { - return UNIFORMS.size(); + if(blockIndex < mUniformBlocks.size()) + { + return static_cast(mUniformBlocks[blockIndex].members.size()); + } + else + { + return 0u; + } } std::string TestGraphicsReflection::GetUniformBlockMemberName(uint32_t blockIndex, uint32_t memberLocation) const { - return UNIFORMS[memberLocation].name; + if(blockIndex < mUniformBlocks.size() && memberLocation < mUniformBlocks[blockIndex].members.size()) + { + return mUniformBlocks[blockIndex].members[memberLocation].name; + } + else + { + return std::string(); + } } uint32_t TestGraphicsReflection::GetUniformBlockMemberOffset(uint32_t blockIndex, uint32_t memberLocation) const { - return 0u; + if(blockIndex < mUniformBlocks.size() && memberLocation < mUniformBlocks[blockIndex].members.size()) + { + return mUniformBlocks[blockIndex].members[memberLocation].offset; + } + else + { + return 0u; + } } bool TestGraphicsReflection::GetNamedUniform(const std::string& name, Dali::Graphics::UniformInfo& out) const @@ -200,7 +252,7 @@ Graphics::ShaderLanguage TestGraphicsReflection::GetLanguage() const Dali::Property::Type TestGraphicsReflection::GetMemberType( int blockIndex, int location) const { - return UNIFORMS[location].type; + return location < static_cast(UNIFORMS.size()) ? UNIFORMS[location].type : mCustomUniforms[location - UNIFORMS.size()].type; } } // namespace Dali diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.h b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.h index 543cf6e..9e71989 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.h @@ -18,14 +18,16 @@ */ #include +#include #include "test-gl-abstraction.h" namespace Dali { + class TestGraphicsReflection : public Graphics::Reflection { public: - TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vertexFormats); + TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vertexFormats, const Graphics::ProgramCreateInfo& createInfo, std::vector& customUniforms); uint32_t GetVertexAttributeLocation(const std::string& name) const override; Dali::Graphics::VertexInputAttributeFormat GetVertexAttributeFormat(uint32_t location) const override; @@ -59,6 +61,10 @@ public: // Test methods TestGlAbstraction& mGl; mutable std::vector mAttributes; + std::vector mCustomUniforms; + + Graphics::UniformBlockInfo mDefaultUniformBlock{}; ///< The emulated UBO containing all the standalone uniforms + std::vector mUniformBlocks{}; ///< List of uniform blocks }; } // namespace Dali -- 2.7.4