Test harness sync 83/272183/2
authorDavid Steele <david.steele@samsung.com>
Thu, 10 Mar 2022 14:46:43 +0000 (14:46 +0000)
committerDavid Steele <david.steele@samsung.com>
Fri, 11 Mar 2022 10:35:08 +0000 (10:35 +0000)
Change-Id: I5eb7873c01501e66ed1b94f5463dbbea407c4236

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

index aec9f5d..cc7fac4 100644 (file)
@@ -2,7 +2,7 @@
 #define TEST_GL_ABSTRACTION_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -913,8 +913,8 @@ public:
     if(it2 == uniformIDs.end())
     {
       // Uniform not found, so add it...
-      uniformIDs[name] = mLastUniformIdUsed++;
-      return mLastUniformIdUsed;
+      uniformIDs[name] = ++mLastUniformIdUsed;
+      return uniformIDs[name];
     }
 
     return it2->second;
@@ -991,7 +991,23 @@ public:
 
     for(const auto& uniform : mCustomUniformData)
     {
-      GetUniformLocation(program, uniform.name.c_str());
+      auto iter = uniform.name.find("[");
+      auto name = uniform.name;
+      if(iter != std::string::npos)
+      {
+        name            = uniform.name.substr(0, iter);
+        auto arrayCount = std::stoi(uniform.name.substr(iter + 1));
+        for(int i = 0; i < arrayCount; ++i)
+        {
+          std::stringstream nss;
+          nss << name << "[" << i << "]";
+          GetUniformLocation(program, nss.str().c_str()); // Generate a GL loc per element
+        }
+      }
+      else
+      {
+        GetUniformLocation(program, name.c_str());
+      }
     }
   }
 
index 8f9b9fc..27f0dce 100644 (file)
@@ -82,65 +82,67 @@ GLenum TestGraphicsBuffer::GetTarget()
 
 void TestGraphicsBuffer::BindAsUniformBuffer(const TestGraphicsProgram* program, const Dali::UniformBufferBindingDescriptor& uboBinding) const
 {
-  auto* reflection = static_cast<const TestGraphicsReflection*>(&program->GetReflection());
-
-  Graphics::UniformBlockInfo uboInfo{};
-  reflection->GetUniformBlock(0, uboInfo);
+  auto*       reflection = static_cast<const TestGraphicsReflection*>(&program->GetReflection());
+  const auto& uboInfo    = reflection->GetTestUniformBlock(0u);
 
   auto  offset = uboBinding.offset;
   auto* data   = memory.data() + offset;
 
   for(const auto& member : uboInfo.members)
   {
-    auto type = reflection->GetMemberType(0, member.location);
-    switch(type)
+    uint32_t numElements = member.numElements > 0 ? member.numElements : 1;
+
+    for(uint32_t i = 0; i < numElements; ++i)
     {
-      case Property::VECTOR4:
-      {
-        auto value = *reinterpret_cast<const Dali::Vector4*>(data + member.offset);
-        mGl.Uniform4f(member.location, value.x, value.y, value.z, value.w);
-        break;
-      }
-      case Property::VECTOR3:
-      {
-        auto value = *reinterpret_cast<const Dali::Vector3*>(data + member.offset);
-        mGl.Uniform3f(member.location, value.x, value.y, value.z);
-        break;
-      }
-      case Property::VECTOR2:
-      {
-        auto value = *reinterpret_cast<const Dali::Vector2*>(data + member.offset);
-        mGl.Uniform2f(member.location, value.x, value.y);
-        break;
-      }
-      case Property::FLOAT:
-      {
-        auto value = *reinterpret_cast<const float*>(data + member.offset);
-        mGl.Uniform1f(member.location, value);
-        break;
-      }
-      case Property::INTEGER:
-      {
-        auto ptr   = reinterpret_cast<const GLint*>(data + member.offset);
-        auto value = *ptr;
-        mGl.Uniform1i(member.location, value);
-        break;
-      }
-      case Property::MATRIX:
-      {
-        auto value = reinterpret_cast<const float*>(data + member.offset);
-        mGl.UniformMatrix4fv(member.location, 1, GL_FALSE, value);
-        break;
-      }
-      case Property::MATRIX3:
-      {
-        auto value = reinterpret_cast<const float*>(data + member.offset);
-        mGl.UniformMatrix3fv(member.location, 1, GL_FALSE, value);
-        break;
-      }
-      default:
+      switch(member.type)
       {
-        fprintf(stderr, "\n%s type not found\n", member.name.c_str());
+        case Property::VECTOR4:
+        {
+          auto value = *reinterpret_cast<const Dali::Vector4*>(data + member.offsets[i]);
+          mGl.Uniform4f(member.locations[i], value.x, value.y, value.z, value.w);
+          break;
+        }
+        case Property::VECTOR3:
+        {
+          auto value = *reinterpret_cast<const Dali::Vector3*>(data + member.offsets[i]);
+          mGl.Uniform3f(member.locations[i], value.x, value.y, value.z);
+          break;
+        }
+        case Property::VECTOR2:
+        {
+          auto value = *reinterpret_cast<const Dali::Vector2*>(data + member.offsets[i]);
+          mGl.Uniform2f(member.locations[i], value.x, value.y);
+          break;
+        }
+        case Property::FLOAT:
+        {
+          auto value = *reinterpret_cast<const float*>(data + member.offsets[i]);
+          mGl.Uniform1f(member.locations[i], value);
+          break;
+        }
+        case Property::INTEGER:
+        {
+          auto ptr   = reinterpret_cast<const GLint*>(data + member.offsets[i]);
+          auto value = *ptr;
+          mGl.Uniform1i(member.locations[i], value);
+          break;
+        }
+        case Property::MATRIX:
+        {
+          auto value = reinterpret_cast<const float*>(data + member.offsets[i]);
+          mGl.UniformMatrix4fv(member.locations[i], 1, GL_FALSE, value);
+          break;
+        }
+        case Property::MATRIX3:
+        {
+          auto value = reinterpret_cast<const float*>(data + member.offsets[i]);
+          mGl.UniformMatrix3fv(member.locations[i], 1, GL_FALSE, value);
+          break;
+        }
+        default:
+        {
+          fprintf(stderr, "\n%s type not found\n", member.name.c_str());
+        }
       }
     }
   }
index a994157..8f2e0c7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,14 +20,15 @@ namespace Dali
 {
 TestGraphicsProgramImpl::TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats, std::vector<UniformData>& customUniforms)
 : mGl(gl),
+  mId(gl.CreateProgram()),
   mCreateInfo(createInfo),
-  mReflection(gl, vertexFormats, createInfo, customUniforms)
+  mReflection(gl, mId, vertexFormats, createInfo, customUniforms)
 {
-  mId = mGl.CreateProgram();
-
   // Ensure active sampler uniforms are set
   mGl.SetCustomUniforms(customUniforms);
-  mGl.LinkProgram(mId);
+
+  // Don't need to re-register uniforms in GL side - now done in creation of mReflection.
+  // Was previously done in mGl.LinkProgram(mId);
 }
 
 bool TestGraphicsProgramImpl::GetParameter(uint32_t parameterId, void* outData)
index 6971b71..5b3da8c 100644 (file)
@@ -53,9 +53,57 @@ static const std::vector<UniformData> UNIFORMS =
 
     // WARNING: IF YOU CHANGE THIS LIST, ALSO CHANGE mActiveUniforms IN test-gl-abstraction, Initialize
 };
+
+/**
+ * Helper function that returns size of uniform datatypes based
+ * on property type.
+ */
+constexpr int GetSizeForType(Property::Type type)
+{
+  switch(type)
+  {
+    case Property::Type::BOOLEAN:
+    {
+      return sizeof(bool);
+    }
+    case Property::Type::FLOAT:
+    {
+      return sizeof(float);
+    }
+    case Property::Type::INTEGER:
+    {
+      return sizeof(int);
+    }
+    case Property::Type::VECTOR2:
+    {
+      return sizeof(Vector2);
+    }
+    case Property::Type::VECTOR3:
+    {
+      return sizeof(Vector3);
+    }
+    case Property::Type::VECTOR4:
+    {
+      return sizeof(Vector4);
+    }
+    case Property::Type::MATRIX3:
+    {
+      return sizeof(Matrix3);
+    }
+    case Property::Type::MATRIX:
+    {
+      return sizeof(Matrix);
+    }
+    default:
+    {
+      return 0;
+    }
+  };
 }
 
-TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vfs, const Graphics::ProgramCreateInfo& createInfo, std::vector<UniformData>& customUniforms)
+} // namespace
+
+TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t programId, Property::Array& vfs, const Graphics::ProgramCreateInfo& createInfo, std::vector<UniformData>& customUniforms)
 : mGl(gl),
   mCustomUniforms(customUniforms)
 {
@@ -78,34 +126,72 @@ 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;
+
+  int offset = 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++;
+    auto& item   = mDefaultUniformBlock.members.back();
+    item.name    = data.name;
+    item.binding = 0;
+    item.offsets.push_back(offset);
+    item.locations.push_back(gl.GetUniformLocation(programId, data.name.c_str()));
     item.bufferIndex  = 0;
     item.uniformClass = Graphics::UniformClass::UNIFORM;
+    item.type         = data.type;
+    offset += GetSizeForType(data.type);
   }
 
   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;
+    auto& item = mDefaultUniformBlock.members.back();
+
+    auto iter        = data.name.find("[", 0);
+    int  numElements = 1;
+    if(iter != std::string::npos)
+    {
+      auto baseName = data.name.substr(0, iter);
+      iter++;
+      numElements = std::stoi(data.name.substr(iter));
+      if(numElements == 0)
+      {
+        numElements = 1;
+      }
+
+      item.name         = baseName;
+      item.binding      = 0;
+      item.bufferIndex  = 0;
+      item.uniformClass = Graphics::UniformClass::UNIFORM;
+      item.type         = data.type;
+      item.numElements  = numElements;
+
+      for(int i = 0; i < numElements; ++i)
+      {
+        std::stringstream elementNameStream;
+        elementNameStream << baseName << "[" << i << "]";
+
+        item.locations.push_back(gl.GetUniformLocation(programId, elementNameStream.str().c_str()));
+        item.offsets.push_back(offset);
+        offset += GetSizeForType(data.type);
+      }
+    }
+    else
+    {
+      item.name    = data.name;
+      item.binding = 0;
+      item.offsets.push_back(offset);
+      item.locations.push_back(gl.GetUniformLocation(programId, item.name.c_str()));
+      item.bufferIndex  = 0;
+      item.uniformClass = Graphics::UniformClass::UNIFORM;
+      item.type         = data.type;
+      offset += GetSizeForType(data.type);
+    }
   }
+  mDefaultUniformBlock.size = offset;
 
   mUniformBlocks.push_back(mDefaultUniformBlock);
 }
@@ -159,9 +245,13 @@ uint32_t TestGraphicsReflection::GetUniformBlockBinding(uint32_t index) const
 
 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() + mCustomUniforms.size());
+  if(index >= mUniformBlocks.size())
+  {
+    return 0;
+  }
+
+  const auto& block = mUniformBlocks[index];
+  return block.size;
 }
 
 bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInfo& out) const
@@ -185,8 +275,8 @@ bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::Uni
     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;
+    out.members[i].offset       = memberUniform.offsets[0];
+    out.members[i].location     = memberUniform.locations[0];
   }
 
   return true;
@@ -230,7 +320,7 @@ uint32_t TestGraphicsReflection::GetUniformBlockMemberOffset(uint32_t blockIndex
 {
   if(blockIndex < mUniformBlocks.size() && memberLocation < mUniformBlocks[blockIndex].members.size())
   {
-    return mUniformBlocks[blockIndex].members[memberLocation].offset;
+    return mUniformBlocks[blockIndex].members[memberLocation].offsets[0];
   }
   else
   {
@@ -254,9 +344,4 @@ Graphics::ShaderLanguage TestGraphicsReflection::GetLanguage() const
   return Graphics::ShaderLanguage::GLSL_3_1;
 }
 
-Dali::Property::Type TestGraphicsReflection::GetMemberType(int blockIndex, int location) const
-{
-  return location < static_cast<int>(UNIFORMS.size()) ? UNIFORMS[location].type : mCustomUniforms[location - UNIFORMS.size()].type;
-}
-
 } // namespace Dali
index 2147cae..e968bd5 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TEST_GRAPHICS_REFLECTION_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ namespace Dali
 class TestGraphicsReflection : public Graphics::Reflection
 {
 public:
-  TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vertexFormats, const Graphics::ProgramCreateInfo& createInfo, std::vector<UniformData>& customUniforms);
+  TestGraphicsReflection(TestGlAbstraction& gl, uint32_t program_id, 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;
@@ -46,6 +46,27 @@ public:
   Graphics::ShaderLanguage                        GetLanguage() const override;
 
 public: // Test methods
+  struct TestUniformInfo
+  {
+    std::string            name{""}; // baseName in the case of arrays
+    Graphics::UniformClass uniformClass{Graphics::UniformClass::UNDEFINED};
+    uint32_t               binding{0u};
+    uint32_t               bufferIndex{0u};
+    std::vector<uint32_t>  offsets{};
+    std::vector<uint32_t>  locations{};
+    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;
+  };
+
+  struct TestUniformBlockInfo
+  {
+    std::string                  name{""};
+    uint32_t                     descriptorSet{0u};
+    uint32_t                     binding{0u};
+    uint32_t                     size{0u};
+    std::vector<TestUniformInfo> members{};
+  };
+
   void SetAttributes(std::vector<std::string> locations)
   {
     mAttributes.clear();
@@ -56,14 +77,17 @@ public: // Test methods
     }
   }
 
-  Dali::Property::Type GetMemberType(int blockIndex, int location) const;
+  const TestUniformBlockInfo& GetTestUniformBlock(uint32_t index) const
+  {
+    return mUniformBlocks[index];
+  }
 
   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
+  TestUniformBlockInfo              mDefaultUniformBlock{}; ///< The emulated UBO containing all the standalone uniforms
+  std::vector<TestUniformBlockInfo> mUniformBlocks{};       ///< List of uniform blocks
 };
 
 } // namespace Dali