Test harness for custom uniform support in uniform block 14/254714/5
authorRichard Huang <r.huang@samsung.com>
Mon, 8 Mar 2021 14:50:55 +0000 (14:50 +0000)
committerDavid Steele <david.steele@samsung.com>
Mon, 8 Mar 2021 16:31:02 +0000 (16:31 +0000)
Change-Id: Ic323a50da0251d9880d5934950af1308df42d4c2

automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h
automated-tests/src/dali/dali-test-suite-utils/test-graphics-command-buffer.cpp
automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.cpp
automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.h
automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.cpp
automated-tests/src/dali/dali-test-suite-utils/test-graphics-program.h
automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.cpp
automated-tests/src/dali/dali-test-suite-utils/test-graphics-reflection.h

index 64696b7..d096f7e 100644 (file)
 
 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<UniformData>& customUniformData)
+  {
+    mCustomUniformData = customUniformData;
+  }
+
   inline GLuint GetLastShaderCompiled() const
   {
     return mLastShaderCompiled;
@@ -2527,6 +2547,8 @@ private:
   typedef std::map<GLuint, UniformIDMap> ProgramUniformMap;
   ProgramUniformMap                      mUniforms;
 
+  std::vector<UniformData>               mCustomUniformData{};
+
   template<typename T>
   struct ProgramUniformValue : public std::map<GLuint, std::map<GLint, T> >
   {
index 88e7168..70f3f0e 100644 (file)
@@ -58,8 +58,6 @@ void TestGraphicsCommandBuffer::GetStateForDrawCall( int drawCallIndex )
       ++index;
     }
   }
-
-  //
 }
 
 std::vector<Command*> TestGraphicsCommandBuffer::GetCommandsByType( CommandTypeMask mask )
index 755d259..782835e 100644 (file)
@@ -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<const TestGraphicsProgram*>(pipeline->programState.program) );
@@ -773,7 +772,7 @@ Graphics::UniquePtr<Graphics::Program> 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<TestGraphicsShader>(shader.shader);
index fa2fd63..cbe78ec 100644 (file)
@@ -299,6 +299,11 @@ public: // Test Functions
     mVertexFormats = vfs;
   }
 
+  void AddCustomUniforms(std::vector<UniformData>& customUniforms)
+  {
+    mCustomUniforms = customUniforms;
+  }
+
   void ClearSubmitStack()
   {
     mSubmitStack.clear();
@@ -336,6 +341,8 @@ public:
     TestGraphicsProgramImpl*                       programImpl;
   };
   std::vector<ProgramCache> mProgramCache;
+
+  std::vector<UniformData> mCustomUniforms;
 };
 
 } // namespace Dali
index 9a0afa6..0bf698a 100644 (file)
 
 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<UniformData>& 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<UniformData>& customUniforms)
 {
-  mImpl = new TestGraphicsProgramImpl(gl, createInfo, vertexFormats);
+  mImpl = new TestGraphicsProgramImpl(gl, createInfo, vertexFormats, customUniforms);
 }
 
 TestGraphicsProgram::TestGraphicsProgram(TestGraphicsProgramImpl* impl)
index c098718..3aae276 100644 (file)
@@ -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<UniformData>& 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<UniformData>& customUniforms);
   TestGraphicsProgram(TestGraphicsProgramImpl* impl);
 
   const TestGraphicsReflection& GetReflection() const
index 7b2b0dc..883eb2d 100644 (file)
@@ -15,6 +15,8 @@
  */
 
 #include "test-graphics-reflection.h"
+#include "test-graphics-shader.h"
+
 #include <dali/public-api/object/property-map.h>
 #include <vector>
 #include <string>
@@ -22,46 +24,37 @@ namespace Dali
 {
 namespace
 {
-// Add members
-struct UniformData
+static const std::vector<UniformData> 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<UniformData> 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<UniformData>& 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<uint32_t> 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<uint32_t>(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<int>(UNIFORMS.size()) ? UNIFORMS[location].type : mCustomUniforms[location - UNIFORMS.size()].type;
 }
 
 } // namespace Dali
index 543cf6e..9e71989 100644 (file)
  */
 
 #include <dali/graphics-api/graphics-reflection.h>
+#include <dali/graphics-api/graphics-program-create-info.h>
 #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<UniformData>& 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<std::string> mAttributes;
+  std::vector<UniformData>         mCustomUniforms;
+
+  Graphics::UniformBlockInfo              mDefaultUniformBlock{};       ///< The emulated UBO containing all the standalone uniforms
+  std::vector<Graphics::UniformBlockInfo> mUniformBlocks{};             ///< List of uniform blocks
 };
 
 } // namespace Dali