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/devel-api/threading/conditional-wait.h>
25 #include <dali/devel-api/threading/mutex.h>
28 #include <string_view>
34 namespace Internal DALI_INTERNAL
36 class ShaderPrecompiler;
42 std::vector<std::string_view> vertexPrefix;
43 std::vector<std::string_view> fragmentPrefix;
44 std::string_view vertexShader;
45 std::string_view fragmentShader;
51 * ShaderPrecompiler is used to precompile shaders.
52 * The precompiled shaders are stored in a file.
55 class DALI_CORE_API ShaderPrecompiler : public BaseHandle
59 * @brief Gets the singleton of ShaderPrecompiler object.
62 * @return A handle to the ShaderPrecompiler
64 static ShaderPrecompiler& Get();
67 * @brief Get the precompile shader list.
70 * @param[in] shaders shader data for precompile
72 void GetPrecompileShaderList(std::vector<RawShaderData>& shaders);
75 * @brief Save the precompile shader list.
78 * @param[in] shaders shader data for precompile
80 void SavePrecomipleShaderList(std::vector<RawShaderData>& shaders);
83 * @brief Check precompile list is ready or not
86 * @return true if precompile list is ready
91 * @brief Enable the feature of precompile
98 * @brief Check the feature of precompile is enabled or not
101 * @return true if the feature of precompile is enabled
106 * @brief Waiting for a list of shaders to be precompiled
109 void WaitPrecompileList();
112 * @brief Stop waiting for a list of shaders to be precompiled
115 void StopPrecompile();
118 * Construct a new ShaderPrecompiler.
123 ShaderPrecompiler(const ShaderPrecompiler&) = delete;
126 ShaderPrecompiler& operator=(const ShaderPrecompiler& rhs) = delete;
129 static std::unique_ptr<ShaderPrecompiler> mInstance;
130 static std::once_flag mOnceFlag;
131 std::vector<RawShaderData> mRawShaderList;
132 ConditionalWait mConditionalWait;
136 bool mNeedsSleep{true};
139 } // namespace Integration
143 #endif // DALI_INTEGRATION_SHADER_PRECOMPILER_H