Change non-shared uniform shader also ignore UBO 52/323452/2
authorEunki Hong <eunkiki.hong@samsung.com>
Mon, 28 Apr 2025 13:23:46 +0000 (22:23 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 29 Apr 2025 01:43:39 +0000 (10:43 +0900)
Let we make non-shared UBO also use standalone uniform blocks,
instead of UBO.

We should remove this code after UBO performance issue resolved.

Change-Id: If1bef2679ae993faf5d32efd4d1aa760365a2865
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/graphics/shaders/text-scroller-shader.vert
dali-toolkit/internal/graphics/shaders/text-visual-shader.vert
dali-toolkit/internal/visuals/visual-factory-cache.cpp

index 8a74212432a72f1dad878cf986ade51448cd7162..240820744db905d6abe7d32039d8548ac1614c97 100644 (file)
@@ -18,7 +18,7 @@ UNIFORM_BLOCK VertBlock
   UNIFORM highp mat4 uMvpMatrix;
 };
 
-UNIFORM_BLOCK VisualVertBlock
+UNIFORM_BLOCK NisualVertBlock
 {
   //Visual size and offset
   UNIFORM highp vec2 offset;
index d5a529bdbe64c6e450689a5213ccb22c79a4d3d3..a31f4b0f15f65514b5330c3d5bdb2d9a923ecf46 100644 (file)
@@ -13,7 +13,7 @@ UNIFORM_BLOCK VertBlock
   UNIFORM highp vec3 uSize;
 };
 
-UNIFORM_BLOCK VisualVertBlock
+UNIFORM_BLOCK NisualVertBlock
 {
   //Visual size and offset
   UNIFORM highp vec2 offset;
index 751aa67212b6e620b3d93e0880bd5bfaf6b11798..a9651fb46e54b8cf84ae0702fc9a1a40c7e15717 100644 (file)
@@ -57,6 +57,24 @@ bool NeedToLoadYuvPlanes()
   return loadYuvPlanes;
 }
 
+// Happy trick for Tizen platform! since 2025-04-22. eunkiki.hong@samsung.com
+// Since uniform buffer reduce fps near 10% than before, let we ignore uniform block feature
+// except several default SharedUniformBlocks, like "VisualVertBlock".
+// If we resolve performance issue, please remove below code!
+#define IGNORE_UNIFORM_BLOCKS_FOR_NORMAL_CASES 1
+
+#if IGNORE_UNIFORM_BLOCKS_FOR_NORMAL_CASES
+inline bool ApplyNonDefaultUniformBlockVertexShaderCode(std::string& vertexShader)
+{
+  auto it = vertexShader.find("VisualVertBlock");
+  if(it != std::string::npos)
+  {
+    vertexShader.replace(it, 15, "NisualVertBlock");
+    return true;
+  }
+  return false;
+}
+#endif
 } // namespace
 
 VisualFactoryCache::VisualFactoryCache(bool preMultiplyOnLoad)
@@ -101,11 +119,11 @@ Shader VisualFactoryCache::GetShader(ShaderType type, bool useDefaultUniforms)
 
 Shader VisualFactoryCache::GenerateAndSaveShader(ShaderType type, std::string_view vertexShader, std::string_view fragmentShader, bool useDefaultUniforms)
 {
-  Shader shader;
+  Shader      shader;
   std::string shaderName = Scripting::GetLinearEnumerationName<ShaderType>(type, VISUAL_SHADER_TYPE_TABLE, VISUAL_SHADER_TYPE_TABLE_COUNT);
 
   // If the shader name is empty, it means that the shader is not generated internally. So, there is need to support file caching. Otherwise, it is defined externally. So, it needs not to support file caching.
-  Shader::Hint::Value shaderHints = shaderName.empty()? Shader::Hint::NONE : Shader::Hint::FILE_CACHE_SUPPORT;
+  Shader::Hint::Value shaderHints = shaderName.empty() ? Shader::Hint::NONE : Shader::Hint::FILE_CACHE_SUPPORT;
 
   if(useDefaultUniforms)
   {
@@ -114,7 +132,15 @@ Shader VisualFactoryCache::GenerateAndSaveShader(ShaderType type, std::string_vi
   }
   else
   {
-    shader = Shader::New(vertexShader, fragmentShader, shaderHints, shaderName);
+#if IGNORE_UNIFORM_BLOCKS_FOR_NORMAL_CASES
+    std::string convertedVertexShader = std::string(vertexShader);
+    if(ApplyNonDefaultUniformBlockVertexShaderCode(convertedVertexShader))
+    {
+      vertexShader = convertedVertexShader;
+      shaderName += "_N";
+    }
+#endif
+    shader        = Shader::New(vertexShader, fragmentShader, shaderHints, shaderName);
     mShader[type] = shader;
   }