#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>
#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)
{
{
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;
}
// 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
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)
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);
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
{
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());
#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>
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,
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())
{
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
mDefines(other.mDefines),
mHints(other.mHints),
mUniforms(other.mUniforms),
+ mShadowOptionHash(other.mShadowOptionHash),
mUseBuiltInShader(other.mUseBuiltInShader)
{
}
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]);
#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.
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
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();