Syncing Test harness updates 17/254417/2
authorDavid Steele <david.steele@samsung.com>
Tue, 2 Mar 2021 12:26:40 +0000 (12:26 +0000)
committerDavid Steele <david.steele@samsung.com>
Tue, 2 Mar 2021 17:47:14 +0000 (17:47 +0000)
Change-Id: If7f9dc0a05eb8c7cafd4aff594ad336097bb7a5e

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-program.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-program.h

index 5679a01..7aacf76 100644 (file)
@@ -2496,7 +2496,7 @@ private:
 
   // Shaders & Uniforms
   GLuint                                 mLastShaderIdUsed;
-  GLuint                                 mLastProgramIdUsed;
+  GLuint                                 mLastProgramIdUsed{0u};
   GLuint                                 mLastUniformIdUsed;
   typedef std::map<std::string, GLint>   UniformIDMap;
   typedef std::map<GLuint, UniformIDMap> ProgramUniformMap;
index adacc11..fe9c329 100644 (file)
@@ -54,6 +54,12 @@ T* Uncast(const Graphics::Buffer* object)
   return const_cast<T*>(static_cast<const T*>(object));
 }
 
+template<typename T>
+T* Uncast(const Graphics::Shader* object)
+{
+  return const_cast<T*>(static_cast<const T*>(object));
+}
+
 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo)
 {
   return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size;
@@ -711,7 +717,33 @@ Graphics::UniquePtr<Graphics::Pipeline> TestGraphicsController::CreatePipeline(c
 Graphics::UniquePtr<Graphics::Program> TestGraphicsController::CreateProgram(const Graphics::ProgramCreateInfo& programCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram)
 {
   mCallStack.PushCall("CreateProgram", "");
-  return Graphics::MakeUnique<TestGraphicsProgram>(mGl, programCreateInfo, mVertexFormats);
+
+  for(auto cacheEntry : mProgramCache)
+  {
+    bool found = true;
+    for(auto& shader : *(programCreateInfo.shaderState))
+    {
+      auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
+      if(memcmp(cacheEntry.shaders[shader.pipelineStage], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize))
+      {
+        found = false;
+        break;
+      }
+    }
+    if(found)
+    {
+      return Graphics::MakeUnique<TestGraphicsProgram>(cacheEntry.programImpl);
+    }
+  }
+
+  mProgramCache.emplace_back();
+  mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats);
+  for(auto& shader : *(programCreateInfo.shaderState))
+  {
+    auto graphicsShader                                = Uncast<TestGraphicsShader>(shader.shader);
+    mProgramCache.back().shaders[shader.pipelineStage] = graphicsShader->mCreateInfo.sourceData;
+  }
+  return Graphics::MakeUnique<TestGraphicsProgram>(mProgramCache.back().programImpl);
 }
 
 Graphics::UniquePtr<Graphics::Shader> TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader)
@@ -789,7 +821,7 @@ bool TestGraphicsController::PipelineEquals(const Graphics::Pipeline& pipeline0,
   return false;
 }
 
-bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData )
+bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData)
 {
   mCallStack.PushCall("GetProgramParameter", "");
   auto graphicsProgram = Uncast<TestGraphicsProgram>(&program);
index 9179a39..fa2fd63 100644 (file)
@@ -21,6 +21,7 @@
 #include "test-gl-abstraction.h"
 #include "test-gl-context-helper-abstraction.h"
 #include "test-gl-sync-abstraction.h"
+#include "test-graphics-program.h"
 #include "test-graphics-reflection.h"
 
 namespace Dali
@@ -313,7 +314,7 @@ public: // Test Functions
    * @param[out] outData Pointer to output memory
    * @return True on success
    */
-  bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData ) override;
+  bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) override;
 
 public:
   mutable TraceCallStack                    mCallStack;
@@ -328,6 +329,13 @@ public:
   bool isDrawOnResumeRequiredResult{true};
 
   Property::Array mVertexFormats;
+
+  struct ProgramCache
+  {
+    std::map<Graphics::PipelineStage, const void*> shaders;
+    TestGraphicsProgramImpl*                       programImpl;
+  };
+  std::vector<ProgramCache> mProgramCache;
 };
 
 } // namespace Dali
index 1b23380..9a0afa6 100644 (file)
 
 namespace Dali
 {
-TestGraphicsProgram::TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats)
+TestGraphicsProgramImpl::TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats)
 : mGl(gl),
   mCreateInfo(createInfo),
   mReflection(gl, vertexFormats)
 {
-  mId = 0;//mGl.CreateProgram();
+  mId = mGl.CreateProgram();
+  mGl.LinkProgram(1); // Ensure active sampler uniforms are set
 }
 
-bool TestGraphicsProgram::GetParameter(uint32_t parameterId, void* outData )
+bool TestGraphicsProgramImpl::GetParameter(uint32_t parameterId, void* outData)
 {
   reinterpret_cast<uint32_t*>(outData)[0] = mId;
   return true;
 }
 
+TestGraphicsProgram::TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats)
+{
+  mImpl = new TestGraphicsProgramImpl(gl, createInfo, vertexFormats);
+}
 
+TestGraphicsProgram::TestGraphicsProgram(TestGraphicsProgramImpl* impl)
+{
+  mImpl = impl;
+}
 
 } // namespace Dali
index d5f5b85..c098718 100644 (file)
 
 namespace Dali
 {
-class TestGraphicsProgram : public Graphics::Program
+class TestGraphicsProgramImpl
 {
 public:
-  TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats);
+  TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats);
 
   // For API
   const TestGraphicsReflection& GetReflection() const
@@ -37,12 +37,12 @@ public:
   }
 
   // For tests
-  TestGraphicsReflection& GetProgamReflection()
+  TestGraphicsReflection& GetProgramReflection()
   {
     return mReflection;
   }
 
-  bool GetParameter(uint32_t parameterId, void* outData );
+  bool GetParameter(uint32_t parameterId, void* outData);
 
 public:
   TestGlAbstraction&          mGl;
@@ -51,6 +51,30 @@ public:
   TestGraphicsReflection      mReflection;
 };
 
+class TestGraphicsProgram : public Graphics::Program
+{
+public:
+  TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats);
+  TestGraphicsProgram(TestGraphicsProgramImpl* impl);
+
+  const TestGraphicsReflection& GetReflection() const
+  {
+    return mImpl->GetReflection();
+  }
+  bool GetParameter(uint32_t parameterId, void* outData)
+  {
+    return mImpl->GetParameter(parameterId, outData);
+  }
+
+  TestGraphicsReflection& GetProgamReflection()
+  {
+    return mImpl->GetProgramReflection();
+  }
+
+public:
+  TestGraphicsProgramImpl* mImpl;
+};
+
 } // namespace Dali
 
 #endif //DALI_TEST_GRAPHICS_PROGRAM_H