1 #ifndef DALI_INTERNAL_SHADER_CACHE_H
2 #define DALI_INTERNAL_SHADER_CACHE_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.
20 #include <dali/graphics-api/graphics-controller.h>
21 #include <dali/graphics-api/graphics-shader-create-info.h>
22 #include <dali/graphics-api/graphics-shader.h>
32 * Caches graphics shaders as they are created by SceneGraph::Shader.
39 Item(const Item&) = delete;
40 Item(Item&&) = default;
41 Item& operator=(const Item&) = delete;
42 Item& operator=(Item&&) = default;
44 Item(Graphics::UniquePtr<Dali::Graphics::Shader> shader,
45 const std::vector<char>& shaderCode,
46 Graphics::PipelineStage stage,
47 Graphics::ShaderSourceMode type)
48 : shader(std::move(shader)),
49 shaderCode(shaderCode),
58 Graphics::UniquePtr<Dali::Graphics::Shader> shader{nullptr};
59 std::vector<char> shaderCode;
60 Graphics::PipelineStage stage;
61 Graphics::ShaderSourceMode type;
68 * @param[in] controller The graphics controller
70 explicit ShaderCache(Dali::Graphics::Controller& controller);
73 * Get a shader from it's source code
74 * It will increate getted shader item reference count.
76 * @param[in] shaderCode The shader code
77 * @param[in] stage The pipeline stage (e.g. VERTEX_SHADER or FRAGMENT_SHADER etc.)
78 * @param[in] type The type of the shader (i.e. text or binary)
79 * @return the graphics shader
81 Dali::Graphics::Shader& GetShader(const std::vector<char>& shaderCode, Graphics::PipelineStage stage, Graphics::ShaderSourceMode type);
84 * @brief Reset all items reference count as 0.
86 void ResetReferenceCount();
89 * @brief Clear items who the reference count is 0.
91 void ClearUnusedCache();
94 std::vector<Item> mItems;
95 Dali::Graphics::Controller& mController;
99 } // namespace Internal
102 #endif //DALI_INTERNAL_SHADER_CACHE_H