Print duration of model load if required + Apply shader option as name 09/315609/3
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 5 Aug 2024 07:22:25 +0000 (16:22 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 5 Aug 2024 07:43:21 +0000 (16:43 +0900)
Change-Id: Id80dad75b3cd49bb70d39bc681b98b42e31bb85e
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-scene3d/internal/common/image-resource-loader.cpp
dali-scene3d/internal/common/model-load-task.cpp
dali-scene3d/public-api/loader/material-definition.cpp
dali-scene3d/public-api/loader/shader-definition.cpp
dali-scene3d/public-api/loader/shader-definition.h
dali-scene3d/public-api/loader/shader-manager.cpp

index 3d3ab93..98acb95 100644 (file)
@@ -28,6 +28,7 @@
 #include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/pixel-data-integ.h>
+#include <dali/integration-api/trace.h>
 #include <dali/public-api/adaptor-framework/timer.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/base-object.h>
@@ -50,6 +51,7 @@ constexpr uint32_t GC_PERIOD_MILLISECONDS                     = 1000u;
 #ifdef DEBUG_ENABLED
 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_IMAGE_RESOURCE_LOADER");
 #endif
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_MODEL_PERFORMANCE_MARKER, false);
 
 bool IsDefaultPixelData(const Dali::PixelData& pixelData)
 {
@@ -153,12 +155,29 @@ Dali::PixelData CreatePixelDataFromImageInfo(const ImageInformation& info, bool
 {
   Dali::PixelData pixelData;
 
+  DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_MODEL_LOAD_IMAGE_FROM_FILE", [&](std::ostringstream& oss) {
+    oss << "[";
+    if(info.mDimensions.GetWidth() > 0 || info.mDimensions.GetHeight() > 0)
+    {
+      oss << "d:" << info.mDimensions.GetWidth() << "x" << info.mDimensions.GetHeight() << " ";
+    }
+    oss << "f:" << info.mFittingMode << " s:" << info.mSamplingMode << " c:" << info.mOrientationCorrection << " ";
+    oss << "u:" << info.mUrl << "]";
+  });
   // Load the image synchronously (block the thread here).
   Dali::Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile(info.mUrl, info.mDimensions, info.mFittingMode, info.mSamplingMode, info.mOrientationCorrection);
   if(pixelBuffer)
   {
     pixelData = Dali::Devel::PixelBuffer::Convert(pixelBuffer, releasePixelData);
   }
+  DALI_TRACE_END_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_MODEL_LOAD_IMAGE_FROM_FILE", [&](std::ostringstream& oss) {
+    oss << "[";
+    if(pixelData)
+    {
+      oss << "d:" << pixelData.GetWidth() << "x" << pixelData.GetHeight() << " f:" << pixelData.GetPixelFormat() << " ";
+    }
+    oss << "u:" << info.mUrl << "]";
+  });
   return pixelData;
 }
 
index 10e0aba..5d279e4 100644 (file)
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
+#include <dali/integration-api/trace.h>
 #include <filesystem>
 
+#ifdef TRACE_ENABLED
+#include <chrono>
+#include <iomanip>
+#include <sstream>
+#include <thread>
+#endif
+
 namespace Dali
 {
 namespace Scene3D
@@ -31,6 +39,18 @@ namespace Internal
 namespace
 {
 static constexpr Vector3 Y_DIRECTION(1.0f, -1.0f, 1.0f);
+
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_MODEL_PERFORMANCE_MARKER, false);
+
+#ifdef TRACE_ENABLED
+uint64_t GetNanoseconds()
+{
+  // Get the time of a monotonic clock since its epoch.
+  auto epoch    = std::chrono::steady_clock::now().time_since_epoch();
+  auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(epoch);
+  return static_cast<uint64_t>(duration.count());
+}
+#endif
 } // namespace
 
 ModelLoadTask::ModelLoadTask(const std::string& modelUrl, const std::string& resourceDirectoryUrl, CallbackBase* callback)
@@ -51,6 +71,18 @@ ModelLoadTask::~ModelLoadTask()
 
 void ModelLoadTask::Process()
 {
+#ifdef TRACE_ENABLED
+  uint64_t mStartTimeNanoSceonds = 0;
+  uint64_t mEndTimeNanoSceonds   = 0;
+  if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+  {
+    mStartTimeNanoSceonds = GetNanoseconds();
+    DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_MODEL_LOADING_TASK", [&](std::ostringstream& oss) {
+      oss << "[u:" << mModelUrl << ",dir:" << mResourceDirectoryUrl << "]";
+    });
+  }
+#endif
+
   if(mResourceDirectoryUrl.empty())
   {
     std::filesystem::path modelUrl(mModelUrl);
@@ -63,13 +95,15 @@ void ModelLoadTask::Process()
 
   mModelLoader = std::make_shared<Dali::Scene3D::Loader::ModelLoader>(mModelUrl, mResourceDirectoryUrl, mLoadResult);
 
-  bool loadSucceeded = false;
+  bool loadSucceeded  = false;
+  bool useCachedModel = false;
   {
     // Lock model url during process, so let we do not try to load same model multiple times.
     mModelCacheManager.LockModelLoadScene(mModelUrl);
     if(mModelCacheManager.IsSceneLoaded(mModelUrl))
     {
-      loadSucceeded = true;
+      useCachedModel = true;
+      loadSucceeded  = true;
     }
     else
     {
@@ -90,6 +124,21 @@ void ModelLoadTask::Process()
     mModelCacheManager.UnlockModelLoadScene(mModelUrl);
   }
 
+#ifdef TRACE_ENABLED
+  if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+  {
+    mEndTimeNanoSceonds = GetNanoseconds();
+    DALI_TRACE_END_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_MODEL_LOADING_TASK", [&](std::ostringstream& oss) {
+      oss << std::fixed << std::setprecision(3);
+      oss << "[";
+      oss << "d:" << static_cast<float>(mEndTimeNanoSceonds - mStartTimeNanoSceonds) / 1000000.0f << "ms ";
+      oss << "c?" << useCachedModel << " ";
+      oss << "s?" << loadSucceeded << " ";
+      oss << "dir:" << mResourceDirectoryUrl << " ";
+      oss << "u:" << mModelUrl << "]";
+    });
+  }
+#endif
   if(!loadSucceeded)
   {
     DALI_LOG_ERROR("Failed to load scene from '%s'\n", mModelUrl.c_str());
index b61005b..f3f328e 100644 (file)
@@ -22,7 +22,9 @@
 #include <dali-toolkit/devel-api/builder/base64-encoding.h>
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#include <dali/integration-api/debug.h>
 #include <dali/integration-api/pixel-data-integ.h>
+#include <dali/integration-api/trace.h>
 
 // INTERNAL INCLUDES
 #include <dali-scene3d/internal/common/image-resource-loader.h>
@@ -39,6 +41,8 @@ const Matrix3 TextureDefinition::DEFAULT_TRANSFORM = Matrix3::IDENTITY;
 
 namespace
 {
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_MODEL_PERFORMANCE_MARKER, false);
+
 constexpr SamplerFlags::Type FILTER_MODES_FROM_DALI[]{
   SamplerFlags::FILTER_LINEAR | SamplerFlags::FILTER_MIPMAP_NEAREST,
   SamplerFlags::FILTER_LINEAR,
@@ -89,11 +93,22 @@ Dali::PixelData LoadImageResource(const std::string& resourcePath,
   Dali::PixelData pixelData;
   if(!textureDefinition.mTextureBuffer.empty())
   {
+    DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_MODEL_LOAD_IMAGE_FROM_BUFFER", [&](std::ostringstream& oss) {
+      oss << "[b:" << textureDefinition.mTextureBuffer.data() << ",s:" << textureDefinition.mTextureBuffer.size() << "]";
+    });
     Dali::Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromBuffer(textureDefinition.mTextureBuffer.data(), textureDefinition.mTextureBuffer.size(), textureDefinition.mMinImageDimensions, fittingMode, textureDefinition.mSamplingMode, orientationCorrection);
     if(pixelBuffer)
     {
       pixelData = Devel::PixelBuffer::Convert(pixelBuffer);
     }
+    DALI_TRACE_END_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_MODEL_LOAD_IMAGE_FROM_BUFFER", [&](std::ostringstream& oss) {
+      oss << "[";
+      if(pixelData)
+      {
+        oss << "d:" << pixelData.GetWidth() << "x" << pixelData.GetHeight() << " f:" << pixelData.GetPixelFormat() << " ";
+      }
+      oss << "b:" << textureDefinition.mTextureBuffer.data() << ",s:" << textureDefinition.mTextureBuffer.size() << "]";
+    });
   }
   else if(textureDefinition.mImageUri.find(EMBEDDED_DATA_PREFIX.data()) == 0 && textureDefinition.mImageUri.find(EMBEDDED_DATA_IMAGE_MEDIA_TYPE.data(), EMBEDDED_DATA_PREFIX.length()) == EMBEDDED_DATA_PREFIX.length())
   {
@@ -106,11 +121,22 @@ Dali::PixelData LoadImageResource(const std::string& resourcePath,
       Dali::Toolkit::DecodeBase64FromString(data, buffer);
       uint32_t bufferSize = buffer.size();
 
+      DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_MODEL_LOAD_IMAGE_FROM_BUFFER", [&](std::ostringstream& oss) {
+        oss << "[s:" << bufferSize << "]";
+      });
       Dali::Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromBuffer(reinterpret_cast<uint8_t*>(buffer.data()), bufferSize, textureDefinition.mMinImageDimensions, fittingMode, textureDefinition.mSamplingMode, orientationCorrection);
       if(pixelBuffer)
       {
         pixelData = Dali::Devel::PixelBuffer::Convert(pixelBuffer, true);
       }
+      DALI_TRACE_END_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_MODEL_LOAD_IMAGE_FROM_BUFFER", [&](std::ostringstream& oss) {
+        oss << "[";
+        if(pixelData)
+        {
+          oss << "d:" << pixelData.GetWidth() << "x" << pixelData.GetHeight() << " f:" << pixelData.GetPixelFormat() << " ";
+        }
+        oss << "s:" << bufferSize << "]";
+      });
     }
   }
   else
index 8cd505e..b6978e2 100644 (file)
@@ -50,6 +50,7 @@ ShaderDefinition::ShaderDefinition(const ShaderDefinition& other)
   mDefines(other.mDefines),
   mHints(other.mHints),
   mUniforms(other.mUniforms),
+  mShadowOptionHash(other.mShadowOptionHash),
   mUseBuiltInShader(other.mUseBuiltInShader)
 {
 }
@@ -193,12 +194,23 @@ Shader ShaderDefinition::Load(RawData&& raw) const
   map[0]["fragment"]      = raw.mFragmentShaderSource;
   map[0]["renderPassTag"] = 0;
   map[0]["hints"]         = static_cast<Shader::Hint::Value>(hints);
-  map[0]["name"]          = "SCENE3D_PBR";
 
   map[1]["vertex"]        = raw.mShadowVertexShaderSource;
   map[1]["fragment"]      = raw.mShadowFragmentShaderSource;
   map[1]["renderPassTag"] = 10;
-  map[1]["name"]          = "SCENE3D_SHADOW_MAP";
+
+  if(mUseBuiltInShader)
+  {
+    std::ostringstream oss;
+    oss << "_0x" << std::hex << mShadowOptionHash;
+    map[0]["name"] = std::string("SCENE3D_PBR") + oss.str();
+    map[1]["name"] = std::string("SCENE3D_SHADOW_MAP") + oss.str();
+  }
+  else
+  {
+    map[0]["name"] = "SCENE3D_CUSTOM";
+    map[1]["name"] = "SCENE3D_CUSTOM_SHADOW";
+  }
 
   Property::Array array;
   array.PushBack(map[0]);
index 743d343..af2a640 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef DALI_SCENE3D_LOADER_SHADER_DEFINITION_H
 #define DALI_SCENE3D_LOADER_SHADER_DEFINITION_H
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -81,7 +81,9 @@ public: // DATA
   std::vector<ShaderOption::MacroDefinition> mMacros;
   std::vector<std::string>                   mHints;
   Property::Map                              mUniforms;
-  bool                                       mUseBuiltInShader{false};
+
+  uint64_t mShadowOptionHash{0u};
+  bool     mUseBuiltInShader{false};
 };
 
 } // namespace Dali::Scene3D::Loader
index 776092c..95d9644 100644 (file)
@@ -236,6 +236,7 @@ Dali::Shader ShaderManager::ProduceShader(const ShaderOption& shaderOption)
     DALI_LOG_INFO(gLogFilter, Debug::Concise, "Creating new shader: hash: %lx\n", hash);
     ShaderDefinition shaderDef;
     shaderDef.mUseBuiltInShader = true;
+    shaderDef.mShadowOptionHash = hash;
 
     shaderOption.GetDefines(shaderDef.mDefines);
     shaderDef.mMacros                  = shaderOption.GetMacroDefinitions();