Let we don't touch RenderItemKey or RendererKey during sort RenderItems 47/323947/4
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 9 May 2025 11:00:30 +0000 (20:00 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 12 May 2025 01:23:31 +0000 (10:23 +0900)
Until now, we try to ask RenderItem->mDepthIndex at comparitor.

Let we make some other way to compair the depth index for the UI layer case.

Change-Id: Ib2e15b85b2e76cd1953bb03b0cf800b0cc65596d
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-Layer.cpp
dali/internal/render/renderers/render-renderer.cpp
dali/internal/render/renderers/render-renderer.h
dali/internal/update/manager/render-instruction-processor.cpp
dali/internal/update/manager/render-instruction-processor.h

index a681a25ec2dced2314b2018b13930f7fe04d7bde..5edf4427e2d76bc755168c50365a56aced87cb42 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -411,6 +411,9 @@ int UtcDaliLayerSetSortFunction(void)
 
   Layer root              = application.GetScene().GetLayer(0);
   gTestSortFunctionCalled = 0;
+
+  // Set the behavior to LAYER_3D and set the sort function
+  root.SetProperty(Layer::Property::BEHAVIOR, Dali::Layer::LAYER_3D);
   root.SetSortFunction(TestSortFunction);
 
   // flush the queue and render once
@@ -421,6 +424,39 @@ int UtcDaliLayerSetSortFunction(void)
   END_TEST;
 }
 
+int UtcDaliLayerSetSortFunctionLayerUI(void)
+{
+  tet_infoline("Testing Dali::Layer::SetSortFunction()");
+  TestApplication application;
+
+  // create two transparent actors so there is something to sort
+  Actor actor  = CreateRenderableActor();
+  Actor actor2 = CreateRenderableActor();
+  actor.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
+  actor.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
+  actor2.SetProperty(Actor::Property::SIZE, Vector2(1, 1));
+  actor2.SetProperty(Actor::Property::COLOR, Vector4(1, 1, 1, 0.5f)); // 50% transparent
+
+  // add to scene
+  application.GetScene().Add(actor);
+  application.GetScene().Add(actor2);
+
+  Layer root              = application.GetScene().GetLayer(0);
+  gTestSortFunctionCalled = 0;
+
+  // Set the sort function
+  root.SetSortFunction(TestSortFunction);
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  // The sort function should not be called as the layer is LAYER_UI
+  // Since LAYER_UI don't use the sort function.
+  DALI_TEST_CHECK(gTestSortFunctionCalled == 0);
+  END_TEST;
+}
+
 int UtcDaliLayerRaiseAbove(void)
 {
   tet_infoline("Testing Dali::Layer::RaiseAbove()");
index a729ef9a1442b7215c522f43eb734d6b09f4d09f..fe070d8c413935613dd2dabb080203c0b15be26d 100644 (file)
@@ -711,7 +711,8 @@ std::size_t Renderer::BuildUniformIndexMap(BufferIndex bufferIndex, const SceneG
   const auto nodeChangeCounter          = nodePtr ? uniformMapNode.GetChangeCounter() : 0;
   const auto renderItemMapChangeCounter = uniformMap.GetChangeCounter();
 
-  auto iter = std::find_if(mNodeIndexMap.begin(), mNodeIndexMap.end(), [nodePtr, programPtr](RenderItemLookup& element) { return (element.node == nodePtr && element.program == programPtr); });
+  auto iter = std::find_if(mNodeIndexMap.begin(), mNodeIndexMap.end(), [nodePtr, programPtr](RenderItemLookup& element)
+                           { return (element.node == nodePtr && element.program == programPtr); });
 
   std::size_t renderItemMapIndex;
   if(iter == mNodeIndexMap.end())
@@ -1058,20 +1059,6 @@ void Renderer::WriteDynUniform(
   }
 }
 
-void Renderer::SetSortAttributes(SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes) const
-{
-  if(!mRenderCallback)
-  {
-    sortAttributes.shader   = &mRenderDataProvider->GetShader();
-    sortAttributes.geometry = mGeometry;
-  }
-  else
-  {
-    sortAttributes.shader   = nullptr;
-    sortAttributes.geometry = nullptr;
-  }
-}
-
 void Renderer::SetShaderChanged(bool value)
 {
   mShaderChanged = value;
index 182c6fd8a770231138b43ca5231be36f74f69acd..dec81db7327f321b59bb1826992f97e1db3fe78c 100644 (file)
@@ -53,7 +53,7 @@ namespace SceneGraph
 class SceneController;
 class Shader;
 class NodeDataProvider;
-class RenderInstruction; //for reflection effect
+class RenderInstruction; // for reflection effect
 } // namespace SceneGraph
 
 namespace Render
@@ -70,8 +70,8 @@ using PipelineCachePtr         = PipelineCacheL2Container::iterator;
 using RendererKey = MemoryPoolKey<Render::Renderer>;
 
 using UboViewContainer = Dali::OwnerContainer<Render::UniformBufferView*>;
-} //namespace Render
-} //namespace Internal
+} // namespace Render
+} // namespace Internal
 
 // Ensure RendererKey can be used in Dali::Vector
 template<>
@@ -488,7 +488,19 @@ public:
    *
    * @param[out] sortAttributes
    */
-  void SetSortAttributes(SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes) const;
+  void SetSortAttributes(SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes) const
+  {
+    if(!mRenderCallback)
+    {
+      sortAttributes.shader   = &mRenderDataProvider->GetShader();
+      sortAttributes.geometry = mGeometry;
+    }
+    else
+    {
+      sortAttributes.shader   = nullptr;
+      sortAttributes.geometry = nullptr;
+    }
+  }
 
   /**
    * Sets the flag indicating whether shader changed.
@@ -738,8 +750,8 @@ private:
     const SceneGraph::NodeDataProvider* node{nullptr};    ///< Node key. It can be nullptr if this NodeIndex don't need node uniform
     const Program*                      program{nullptr}; ///< Program key.
 
-    std::size_t index{0};                       ///<Index into mUniformIndexMap
-    std::size_t nodeChangeCounter{0};           ///<The last known change counter for this node's uniform map
+    std::size_t index{0};                       ///< Index into mUniformIndexMap
+    std::size_t nodeChangeCounter{0};           ///< The last known change counter for this node's uniform map
     std::size_t renderItemMapChangeCounter{0u}; ///< Change counter of the renderer & shader collected uniform map for this render item (node/renderer pair)
   };
   std::vector<RenderItemLookup> mNodeIndexMap; ///< usually only 1 element.
index 6bd40e50c959d43a9725a367666a652f458ed840..631832a67328b81a83d38a0b9de0c5b707233758 100644 (file)
@@ -81,11 +81,11 @@ bool CompareItems(const RenderInstructionProcessor::SortAttributes& lhs, const R
 {
   // @todo Consider replacing all these sortAttributes with a single long int that
   // encapsulates the same data (e.g. the middle-order bits of the ptrs).
-  if(lhs.renderItem->mDepthIndex == rhs.renderItem->mDepthIndex)
+  if(lhs.depthIndex == rhs.depthIndex)
   {
     return PartialCompareItems(lhs, rhs);
   }
-  return lhs.renderItem->mDepthIndex < rhs.renderItem->mDepthIndex;
+  return lhs.depthIndex < rhs.depthIndex;
 }
 
 /**
@@ -186,7 +186,8 @@ inline void AddRendererToRenderList(BufferIndex               updateBufferIndex,
   // Don't cull items which have render callback
   bool hasRenderCallback = (rendererExist && renderable.mRenderer->GetRenderCallback());
 
-  auto requiredInsideCheck = [&]() {
+  auto requiredInsideCheck = [&]()
+  {
     if(node != stopperNode &&
        cullingEnabled &&
        !hasRenderCallback &&
@@ -451,8 +452,10 @@ inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex,
 
   // List of zValue calculating functions.
   const Dali::Layer::SortFunctionType zValueFunctionFromVector3[] = {
-    [](const Vector3& position) { return position.z; },
-    [](const Vector3& position) { return position.LengthSquared(); },
+    [](const Vector3& position)
+    { return position.z; },
+    [](const Vector3& position)
+    { return position.LengthSquared(); },
     layer.GetSortFunction(),
   };
 
@@ -466,10 +469,17 @@ inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex,
   //   2 is user defined function.
   const int zValueFunctionIndex = layer.UsesDefaultSortFunction() ? ((layer.GetBehavior() == Dali::Layer::LAYER_UI || isOrthographicCamera) ? 0 : 1) : 2;
 
+  // Here we determine which comparitor (of the 3) to use.
+  //   0 is LAYER_UI
+  //   1 is LAYER_3D
+  //   2 is LAYER_3D + Clipping
+  const int comparitorIndex = layer.GetBehavior() == Dali::Layer::LAYER_3D ? respectClippingOrder ? 2u : 1u : 0u;
+
   for(uint32_t index = 0; index < renderableCount; ++index)
   {
     RenderItemKey itemKey = renderList.GetItemKey(index);
     RenderItem&   item    = *itemKey.Get();
+
     if(DALI_LIKELY(item.mRenderer))
     {
       item.mRenderer->SetSortAttributes(mSortingHelper[index]);
@@ -478,18 +488,21 @@ inline void RenderInstructionProcessor::SortRenderItems(BufferIndex bufferIndex,
     // texture set
     mSortingHelper[index].textureSet = item.mTextureSet;
 
-    mSortingHelper[index].zValue = zValueFunctionFromVector3[zValueFunctionIndex](item.mModelViewMatrix.GetTranslation3()) - static_cast<float>(item.mDepthIndex);
+    if(comparitorIndex == 0)
+    {
+      // If we are under LAYER_UI, We don't need to get zValue and renderer sort attributes.
+      // Since all render items well-sorted by draw order normally.
+      mSortingHelper[index].depthIndex = item.mDepthIndex;
+    }
+    else
+    {
+      mSortingHelper[index].zValue = zValueFunctionFromVector3[zValueFunctionIndex](item.mModelViewMatrix.GetTranslation3()) - static_cast<float>(item.mDepthIndex);
+    }
 
     // Keep the renderitem pointer in the helper so we can quickly reorder items after sort.
     mSortingHelper[index].renderItem = itemKey;
   }
 
-  // Here we determine which comparitor (of the 3) to use.
-  //   0 is LAYER_UI
-  //   1 is LAYER_3D
-  //   2 is LAYER_3D + Clipping
-  const unsigned int comparitorIndex = layer.GetBehavior() == Dali::Layer::LAYER_3D ? respectClippingOrder ? 2u : 1u : 0u;
-
   std::stable_sort(mSortingHelper.begin(), mSortingHelper.end(), mSortComparitors[comparitorIndex]);
 
   // Reorder / re-populate the RenderItems in the RenderList to correct order based on the sortinghelper.
index 138c3bd61ab65c49f23ef20c289df4ee9d097333..dd09b81d62d8aa453a7d6cd47be3c681cd70b132 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_PROCESSOR_H
 
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -78,7 +78,11 @@ public:
     const Shader*           shader;     ///< The shader instance
     const void*             textureSet; ///< The textureSet instance
     const Render::Geometry* geometry;   ///< The geometry instance
-    float                   zValue;     ///< The Z value of the given renderer (either distance from camera, or a custom calculated value)
+    union
+    {
+      float   zValue;     ///< The Z value of the given renderer (either distance from camera, or a custom calculated value)
+      int32_t depthIndex; ///< The depth index of the given render item. Only be used for LAYER_UI
+    };
   };
 
   /**