Ensure to call program.GetUniform() only 1 times even if we found failed. 69/322869/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 17 Apr 2025 05:58:46 +0000 (14:58 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Fri, 18 Apr 2025 02:08:02 +0000 (02:08 +0000)
Until now, UniformIndexMap state mark as initialized = false if given unform
not found at shader.

In this case, we always try to re-search about given uniform name, which is useless.

To avoid this case, let we make the uniform found result as enum,
and so we can ensure that program.GetUniform only 1 time.

Change-Id: I23a180980f556e3f05302622453258f87742344d
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-renderer.h
dali/internal/render/renderers/render-uniform-block.cpp
dali/internal/render/renderers/render-uniform-block.h

index 445d10da6f5b9b56bc0f05d525fea3e98cc70bfa..04e3a19511bd114048a40ba3ee63682a9c8880cc 100644 (file)
@@ -967,50 +967,58 @@ void Renderer::FillUniformBuffer(Program&
   {
     auto& uniform = iter;
 
-    if(!uniform.initialized)
+    switch(uniform.state)
     {
-      auto uniformInfo  = Graphics::UniformInfo{};
-      auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(),
-                                             uniform.uniformNameHash,
-                                             uniform.uniformNameHashNoArray,
-                                             uniformInfo);
-
-      if(!uniformFound)
+      case UniformIndexMap::State::INITIALIZE_REQUIRED:
       {
-        continue;
-      }
+        auto uniformInfo  = Graphics::UniformInfo{};
+        auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(),
+                                               uniform.uniformNameHash,
+                                               uniform.uniformNameHashNoArray,
+                                               uniformInfo);
 
-      uniform.uniformOffset     = uniformInfo.offset;
-      uniform.uniformLocation   = int16_t(uniformInfo.location);
-      uniform.uniformBlockIndex = uniformInfo.bufferIndex;
-      uniform.initialized       = true;
+        if(!uniformFound)
+        {
+          uniform.state = UniformIndexMap::State::NOT_USED;
+          continue;
+        }
 
-      const auto typeSize        = iter.propertyValue->GetValueSize();
-      uniform.arrayElementStride = uniformInfo.elementCount > 0 ? (uniformInfo.elementStride ? uniformInfo.elementStride : typeSize) : typeSize;
-      uniform.matrixStride       = uniformInfo.matrixStride;
+        uniform.uniformOffset     = uniformInfo.offset;
+        uniform.uniformLocation   = int16_t(uniformInfo.location);
+        uniform.uniformBlockIndex = uniformInfo.bufferIndex;
 
-      WriteDynUniform(iter.propertyValue, uniform, uboViews, updateBufferIndex);
-    }
-    else
-    {
-      WriteDynUniform(iter.propertyValue, uniform, uboViews, updateBufferIndex);
+        const auto typeSize        = iter.propertyValue->GetValueSize();
+        uniform.arrayElementStride = uniformInfo.elementCount > 0 ? (uniformInfo.elementStride ? uniformInfo.elementStride : typeSize) : typeSize;
+        uniform.matrixStride       = uniformInfo.matrixStride;
+
+        uniform.state = UniformIndexMap::State::INITIALIZED;
+        DALI_FALLTHROUGH;
+      }
+      case UniformIndexMap::State::INITIALIZED:
+      {
+        Render::UniformBufferView* ubo = uboViews[uniform.uniformBlockIndex].get();
+        if(ubo == nullptr) // Uniform belongs to shared UniformBlock, can't overwrite
+        {
+          uniform.state = UniformIndexMap::State::NOT_USED;
+          continue;
+        }
+        WriteDynUniform(iter.propertyValue, uniform, *ubo, updateBufferIndex);
+        break;
+      }
+      default:
+      {
+        break;
+      }
     }
   }
 }
 
 void Renderer::WriteDynUniform(
-  const PropertyInputImpl*                                       propertyValue,
-  UniformIndexMap&                                               uniform,
-  const std::vector<std::unique_ptr<Render::UniformBufferView>>& uboViews,
-  BufferIndex                                                    updateBufferIndex)
+  const PropertyInputImpl*   propertyValue,
+  UniformIndexMap&           uniform,
+  Render::UniformBufferView& ubo,
+  BufferIndex                updateBufferIndex)
 {
-  UniformBufferView* ubo = uboViews[uniform.uniformBlockIndex].get();
-
-  if(ubo == nullptr) // Uniform belongs to shared UniformBlock, can't overwrite
-  {
-    return;
-  }
-
   const auto dest = uniform.uniformOffset + uniform.arrayElementStride * uniform.arrayIndex;
 
   const auto valueAddress = propertyValue->GetValueAddress(updateBufferIndex);
@@ -1023,15 +1031,15 @@ void Renderer::WriteDynUniform(
     const uint32_t matrixRow = (propertyValue->GetType() == Property::MATRIX3) ? 3 : 2;
     for(uint32_t i = 0; i < matrixRow; ++i)
     {
-      ubo->Write(reinterpret_cast<const float*>(valueAddress) + i * matrixRow,
-                 sizeof(float) * matrixRow,
-                 dest + (i * uniform.matrixStride));
+      ubo.Write(reinterpret_cast<const float*>(valueAddress) + i * matrixRow,
+                sizeof(float) * matrixRow,
+                dest + (i * uniform.matrixStride));
     }
   }
   else
   {
     const auto typeSize = propertyValue->GetValueSize();
-    ubo->Write(valueAddress, typeSize, dest);
+    ubo.Write(valueAddress, typeSize, dest);
   }
 }
 
index ce572b6b4ed5f91bcfd9e2013085afe7282ba34b..8336b816d905291e3743512f90e8e8ff7a4cc472 100644 (file)
@@ -649,13 +649,13 @@ private:
    *
    * @param[in] propertyValue The property value to write
    * @param[in] uniform The map describing the uniform
-   * @param[in] uboViews Target uniform buffer object
+   * @param[in] ubo Target uniform buffer view
    * @param[in] updateBufferIndex update buffer index
    */
-  void WriteDynUniform(const PropertyInputImpl*                                       propertyValue,
-                       UniformIndexMap&                                               uniform,
-                       const std::vector<std::unique_ptr<Render::UniformBufferView>>& uboViews,
-                       BufferIndex                                                    updateBufferIndex);
+  void WriteDynUniform(const PropertyInputImpl*   propertyValue,
+                       UniformIndexMap&           uniform,
+                       Render::UniformBufferView& ubo,
+                       BufferIndex                updateBufferIndex);
 
 private:
   Graphics::Controller*           mGraphicsController;
@@ -676,6 +676,12 @@ private:
 
   struct UniformIndexMap
   {
+    enum class State : uint8_t
+    {
+      INITIALIZE_REQUIRED,
+      INITIALIZED,
+      NOT_USED,
+    };
     ConstString              uniformName;            ///< The uniform name
     const PropertyInputImpl* propertyValue{nullptr}; ///< The property value
     Hash                     uniformNameHash{0u};
@@ -687,7 +693,7 @@ private:
     int16_t  uniformLocation{0u};
     uint16_t uniformOffset{0u};
     uint16_t uniformBlockIndex{0u};
-    bool     initialized{false};
+    State    state{State::INITIALIZE_REQUIRED};
   };
 
   StencilParameters mStencilParameters; ///< Struct containing all stencil related options
index f592bd785963d3a631e62cd9ce22bf8811e04719..0610d29c461cb1bff86057eb200df816e0020dd5 100644 (file)
@@ -57,33 +57,42 @@ void UniformBlock::WriteUniforms(BufferIndex renderBufferIndex, const Program& p
   {
     auto& uniform = iter;
 
-    if(!uniform.initialized)
+    switch(uniform.state)
     {
-      auto uniformInfo  = Graphics::UniformInfo{};
-      auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(),
-                                             uniform.uniformNameHash,
-                                             uniform.uniformNameHashNoArray,
-                                             uniformInfo);
-
-      if(!uniformFound)
+      case UniformIndexMap::State::INITIALIZE_REQUIRED:
       {
-        continue;
+        auto uniformInfo  = Graphics::UniformInfo{};
+        auto uniformFound = program.GetUniform(uniform.uniformName.GetStringView(),
+                                               uniform.uniformNameHash,
+                                               uniform.uniformNameHashNoArray,
+                                               uniformInfo);
+
+        if(!uniformFound)
+        {
+          uniform.state = UniformIndexMap::State::NOT_USED;
+          continue;
+        }
+
+        uniform.uniformOffset     = uniformInfo.offset;
+        uniform.uniformLocation   = int16_t(uniformInfo.location);
+        uniform.uniformBlockIndex = uniformInfo.bufferIndex;
+
+        const auto typeSize        = iter.propertyValue->GetValueSize();
+        uniform.arrayElementStride = uniformInfo.elementCount > 0 ? (uniformInfo.elementStride ? uniformInfo.elementStride : typeSize) : typeSize;
+        uniform.matrixStride       = uniformInfo.matrixStride;
+
+        uniform.state = UniformIndexMap::State::INITIALIZED;
+        DALI_FALLTHROUGH;
+      }
+      case UniformIndexMap::State::INITIALIZED:
+      {
+        WriteDynUniform(iter.propertyValue, uniform, ubo, renderBufferIndex);
+        break;
+      }
+      default:
+      {
+        break;
       }
-
-      uniform.uniformOffset     = uniformInfo.offset;
-      uniform.uniformLocation   = int16_t(uniformInfo.location);
-      uniform.uniformBlockIndex = uniformInfo.bufferIndex;
-      uniform.initialized       = true;
-
-      const auto typeSize        = iter.propertyValue->GetValueSize();
-      uniform.arrayElementStride = uniformInfo.elementCount > 0 ? (uniformInfo.elementStride ? uniformInfo.elementStride : typeSize) : typeSize;
-      uniform.matrixStride       = uniformInfo.matrixStride;
-
-      WriteDynUniform(iter.propertyValue, uniform, ubo, renderBufferIndex);
-    }
-    else
-    {
-      WriteDynUniform(iter.propertyValue, uniform, ubo, renderBufferIndex);
     }
   }
 }
index 11c1d680243b7a0b59c3c607286504910e71f376..fc996da7ff84eeb7af9f3bad3607d56e388bd0a2 100644 (file)
@@ -69,6 +69,12 @@ private:
   using Hash = std::size_t;
   struct UniformIndexMap
   {
+    enum class State : uint8_t
+    {
+      INITIALIZE_REQUIRED,
+      INITIALIZED,
+      NOT_USED,
+    };
     ConstString              uniformName;            ///< The uniform name
     const PropertyInputImpl* propertyValue{nullptr}; ///< The property value
     Hash                     uniformNameHash{0u};
@@ -80,7 +86,7 @@ private:
     int16_t  uniformLocation{0u};
     uint16_t uniformOffset{0u};
     uint16_t uniformBlockIndex{0u};
-    bool     initialized{false};
+    State    state{State::INITIALIZE_REQUIRED};
   };
 
   void WriteDynUniform(const PropertyInputImpl* propertyValue,