#define DALI_INTEGRATION_SHADER_PRECOMPILER_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.
*/
// INTERNAL HEADER
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/object/base-handle.h>
-#include <dali/public-api/common/vector-wrapper.h>
#include <dali/devel-api/threading/conditional-wait.h>
#include <dali/devel-api/threading/mutex.h>
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/vector-wrapper.h>
+#include <dali/public-api/object/base-handle.h>
// EXTERNAL HEDAER
-#include <string_view>
-#include <memory>
-#include <mutex>
#include <dali/graphics-api/graphics-program.h>
#include <dali/graphics-api/graphics-types.h>
+#include <memory>
+#include <mutex>
+#include <string_view>
namespace Dali
{
struct RawShaderData
{
- int shaderCount;
+ int shaderCount;
std::vector<std::string_view> vertexPrefix;
std::vector<std::string_view> fragmentPrefix;
- std::string_view vertexShader;
- std::string_view fragmentShader;
+ std::vector<std::string_view> shaderName;
+ std::string_view vertexShader;
+ std::string_view fragmentShader;
};
/**
private:
std::vector<Graphics::UniquePtr<Dali::Graphics::Program>> mProgram;
- static std::unique_ptr<ShaderPreCompiler> mInstance;
- static std::once_flag mOnceFlag;
- std::vector<RawShaderData> mRawShaderList;
- ConditionalWait mConditionalWait;
- Dali::Mutex mMutex;
- bool mPrecompiled;
- bool mEnabled;
- bool mNeedsSleep{true};
+ static std::unique_ptr<ShaderPreCompiler> mInstance;
+ static std::once_flag mOnceFlag;
+ std::vector<RawShaderData> mRawShaderList;
+ ConditionalWait mConditionalWait;
+ Dali::Mutex mMutex;
+ bool mPrecompiled;
+ bool mEnabled;
+ bool mNeedsSleep{true};
};
} // namespace Dali
{
auto vertexShader = graphics.GetController().GetGraphicsConfig().GetVertexShaderPrefix() + std::string(precompiledShader->vertexPrefix[i].data()) + std::string(precompiledShader->vertexShader.data());
auto fragmentShader = graphics.GetController().GetGraphicsConfig().GetFragmentShaderPrefix() + std::string(precompiledShader->fragmentPrefix[i].data()) + std::string(precompiledShader->fragmentShader.data());
- PreCompileShader(std::move(vertexShader), std::move(fragmentShader));
+ PreCompileShader(std::move(vertexShader), std::move(fragmentShader), static_cast<uint32_t>(i) < precompiledShader->shaderName.size() ? std::string(precompiledShader->shaderName[i]) : "");
}
DALI_LOG_RELEASE_INFO("ShaderPreCompiler[ENABLE], shader count :%d \n", numberOfPrecompiledShader);
}
}
}
-void CombinedUpdateRenderController::PreCompileShader(std::string vertexShader, std::string fragmentShader)
+void CombinedUpdateRenderController::PreCompileShader(std::string vertexShader, std::string fragmentShader, std::string shaderName)
{
GraphicsInterface& graphics = mAdaptorInterfaces.GetGraphicsInterface();
auto createInfo = Graphics::ProgramCreateInfo();
createInfo.SetShaderState(shaderStates);
+ createInfo.SetName(shaderName);
auto graphicsProgram = graphics.GetController().CreateProgram(createInfo, nullptr);
ShaderPreCompiler::Get().AddPreCompiledProgram(std::move(graphicsProgram));
*
* @param[in] vertexShader vertexShader need to precompile
* @param[in] fragmentShader fragmentShader need to precompile
+ * @param[in] shaderName the name of precompile shader (option)
*/
- void PreCompileShader(std::string vertexShader, std::string fragmentShader);
+ void PreCompileShader(std::string vertexShader, std::string fragmentShader, std::string shaderName = "");
/**
* Cancel the precompile
{
createInfo.shaderState = new std::vector<ShaderState>(*info.shaderState);
}
+
+ // Create new reference of std::string_view.
+ name = std::string(info.name);
+ createInfo.name = name;
}
~Impl()
EglGraphicsController& controller;
ProgramCreateInfo createInfo;
+ std::string name;
uint32_t glProgram{};
uint32_t refCount{0u};
auto program = gl->CreateProgram();
+ DALI_LOG_INFO(gGraphicsProgramLogFilter, Debug::Verbose, "Program[%s] create program id : %u\n", mImpl->name.c_str(), program);
+
const auto& info = mImpl->createInfo;
for(const auto& state : *info.shaderState)
{
// Compile shader first (ignored when compiled)
if(shader->GetImplementation()->Compile())
{
- gl->AttachShader(program, shader->GetImplementation()->GetGLShader());
+ auto shaderId = shader->GetImplementation()->GetGLShader();
+ DALI_LOG_INFO(gGraphicsProgramLogFilter, Debug::Verbose, "Program[%s] attach shader : %u\n", mImpl->name.c_str(), shaderId);
+ gl->AttachShader(program, shaderId);
}
}
+
+ DALI_LOG_INFO(gGraphicsProgramLogFilter, Debug::Verbose, "Program[%s] call glLinkProgram\n", mImpl->name.c_str());
gl->LinkProgram(program);
GLint status{0};
gl->GetProgramInfoLog(program, 4096, &size, output);
// log on error
- DALI_LOG_ERROR("glLinkProgam failed:\n%s\n", output);
+ DALI_LOG_ERROR("glLinkProgam[%s] failed:\n%s\n", mImpl->name.c_str(), output);
gl->DeleteProgram(program);
return false;
}