1 #ifndef DALI_INTEGRATION_SHADER_PRECOMPILER_H
2 #define DALI_INTEGRATION_SHADER_PRECOMPILER_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/devel-api/threading/conditional-wait.h>
26 #include <dali/devel-api/threading/mutex.h>
29 #include <string_view>
32 #include <dali/graphics-api/graphics-program.h>
33 #include <dali/graphics-api/graphics-types.h>
40 std::vector<std::string_view> vertexPrefix;
41 std::vector<std::string_view> fragmentPrefix;
42 std::string_view vertexShader;
43 std::string_view fragmentShader;
47 * ShaderPreCompiler is used to precompile shaders.
48 * The precompiled shaders are stored in a file.
51 class DALI_CORE_API ShaderPreCompiler : public BaseHandle
55 * @brief Gets the singleton of ShaderPreCompiler object.
57 * @return A handle to the ShaderPreCompiler
59 static ShaderPreCompiler& Get();
62 * @brief Add a precompiled program to the ShaderPreCompiler
64 * @param[in] program precompiled program
66 void AddPreCompiledProgram(Graphics::UniquePtr<Dali::Graphics::Program> program);
69 * @brief Gets the shader list to be precompiled
71 * @param[in] shaders shader data for precompile
73 void GetPreCompileShaderList(std::vector<RawShaderData>& shaders);
76 * @brief Save the shader list to be precompiled
78 * @param[in] shaders shader data for precompile
80 void SavePreCompileShaderList(std::vector<RawShaderData>& shaders);
83 * @brief Checks whether the precompiled list is ready or not
85 * @return true if precompile list is ready
90 * @brief Enable the feature of precompile
96 * @brief Check the feature of precompile is enabled or not
98 * @return true if the feature of precompile is enabled
103 * @brief Waiting for a list of shaders to be precompiled
109 * @brief Awake waiting for a list of shaders to be precompiled
116 * Construct a new ShaderPreCompiler.
121 ShaderPreCompiler(const ShaderPreCompiler&) = delete;
124 ShaderPreCompiler& operator=(const ShaderPreCompiler& rhs) = delete;
127 std::vector<Graphics::UniquePtr<Dali::Graphics::Program>> mProgram;
128 static std::unique_ptr<ShaderPreCompiler> mInstance;
129 static std::once_flag mOnceFlag;
130 std::vector<RawShaderData> mRawShaderList;
131 ConditionalWait mConditionalWait;
135 bool mNeedsSleep{true};
140 #endif // DALI_INTEGRATION_SHADER_PRECOMPILER_H