Instanced draw test code sync 97/291497/1
authorDavid Steele <david.steele@samsung.com>
Mon, 17 Apr 2023 12:18:30 +0000 (13:18 +0100)
committerDavid Steele <david.steele@samsung.com>
Mon, 17 Apr 2023 12:18:30 +0000 (13:18 +0100)
Change-Id: I6da7476602ae2d7fceae75a8459370d132b7b198

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

index 7ba7834..834ae6f 100644 (file)
@@ -2,7 +2,7 @@
 #define TEST_GL_ABSTRACTION_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -1893,10 +1893,26 @@ public:
 
   inline void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount) override
   {
+    std::stringstream out;
+    out << mode << ", " << first << ", " << count << ", " << instanceCount;
+    TraceCallStack::NamedParams namedParams;
+    namedParams["mode"] << std::hex << mode;
+    namedParams["first"] << first;
+    namedParams["count"] << count;
+    namedParams["instanceCount"] << instanceCount;
+    mDrawTrace.PushCall("DrawArraysInstanced", out.str(), namedParams);
   }
 
   inline void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount) override
   {
+    std::stringstream out;
+    out << mode << ", " << count << ", " << type << ", " << instanceCount;
+    TraceCallStack::NamedParams namedParams;
+    namedParams["mode"] << std::hex << mode;
+    namedParams["count"] << count;
+    namedParams["type"] << std::hex << type;
+    namedParams["indexCount"] << instanceCount;
+    mDrawTrace.PushCall("DrawElementsInstanced", out.str(), namedParams);
   }
 
   inline GLsync FenceSync(GLenum condition, GLbitfield flags) override
@@ -1981,6 +1997,12 @@ public:
 
   inline void VertexAttribDivisor(GLuint index, GLuint divisor) override
   {
+    std::stringstream out;
+    out << index << ", " << divisor;
+    TraceCallStack::NamedParams namedParams;
+    namedParams["index"] << index;
+    namedParams["divisor"] << divisor;
+    mBufferTrace.PushCall("VertexAttribDivisor", out.str(), namedParams);
   }
 
   inline void BindTransformFeedback(GLenum target, GLuint id) override
index 319ec67..3cc464c 100644 (file)
@@ -712,9 +712,19 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com
       {
         if(currentPipeline)
         {
-          mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology),
-                         0,
-                         cmd.data.draw.draw.vertexCount);
+          if(cmd.data.draw.draw.instanceCount == 0)
+          {
+            mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology),
+                           0,
+                           cmd.data.draw.draw.vertexCount);
+          }
+          else
+          {
+            mGl.DrawArraysInstanced(GetTopology(currentPipeline->inputAssemblyState.topology),
+                                    0,
+                                    cmd.data.draw.draw.vertexCount,
+                                    cmd.data.draw.draw.instanceCount);
+          }
         }
         break;
       }
@@ -722,10 +732,21 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com
       {
         if(currentPipeline)
         {
-          mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
-                           static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
-                           GL_UNSIGNED_SHORT,
-                           reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
+          if(cmd.data.draw.draw.instanceCount == 0)
+          {
+            mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
+                             static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
+                             GL_UNSIGNED_SHORT,
+                             reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
+          }
+          else
+          {
+            mGl.DrawElementsInstanced(GetTopology(currentPipeline->inputAssemblyState.topology),
+                                      static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
+                                      GL_UNSIGNED_SHORT,
+                                      reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex),
+                                      cmd.data.draw.drawIndexed.instanceCount);
+          }
         }
         break;
       }
@@ -983,12 +1004,22 @@ void TestGraphicsController::BindPipeline(TestGraphicsPipeline* pipeline)
     uint32_t attributeOffset = attribute.offset;
     GLsizei  stride          = vi.bufferBindings[attribute.binding].stride;
 
+    auto rate = vi.bufferBindings[attribute.binding].inputRate;
+
     mGl.VertexAttribPointer(attribute.location,
                             GetNumComponents(attribute.format),
                             GetGlType(attribute.format),
                             GL_FALSE, // Not normalized
                             stride,
                             reinterpret_cast<void*>(attributeOffset));
+    if(rate == Graphics::VertexInputRate::PER_VERTEX)
+    {
+      mGl.VertexAttribDivisor(attribute.location, 0);
+    }
+    else if(rate == Graphics::VertexInputRate::PER_INSTANCE)
+    {
+      mGl.VertexAttribDivisor(attribute.location, 1);
+    }
   }
 
   // Cull face setup