1 #ifndef DALI_INTERNAL_RENDER_PIPELINE_CACHE_H
2 #define DALI_INTERNAL_RENDER_PIPELINE_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.
21 #include <dali/graphics-api/graphics-controller.h>
22 #include <dali/graphics-api/graphics-pipeline.h>
23 #include <dali/graphics-api/graphics-types.h>
24 #include <dali/internal/common/blending-options.h>
29 namespace Dali::Internal
38 * Cache Level 2 : Last level of cache, stores actual pipeline
40 struct PipelineCacheL2
43 Graphics::ColorBlendState colorBlendState;
44 Graphics::UniquePtr<Graphics::Pipeline> pipeline;
48 * Cache Level 1 : Stores rasterization and input assembly states
50 struct PipelineCacheL1
52 PipelineCacheL2* GetPipelineCacheL2(bool blend, bool premul, BlendingOptions& blendingOptions);
54 uint32_t hashCode{}; // 1byte cull, 1byte poly, 1byte frontface
55 Graphics::RasterizationState rs{};
56 Graphics::InputAssemblyState ia{};
58 PipelineCacheL2 noBlend; // special case
59 std::vector<PipelineCacheL2> level2nodes;
63 * Cache Level 0 : Stores hash, geometry, program amd vertex input state
65 struct PipelineCacheL0 // L0 cache
67 PipelineCacheL1* GetPipelineCacheL1(Render::Renderer* renderer, bool usingReflection);
72 Graphics::VertexInputState inputState;
74 std::vector<PipelineCacheL1> level1nodes;
77 struct PipelineCacheQueryInfo
84 bool cameraUsingReflection;
88 bool alphaPremultiplied;
89 BlendingOptions* blendingOptions;
91 // Lightweight hash value before compare each query.
94 // Generate hash value for this query.
97 // Value comparision between two query info.
98 static bool Equal(const PipelineCacheQueryInfo& lhs, const PipelineCacheQueryInfo& rhs) noexcept;
102 * Result of PipelineCache::GetPipeline() call
104 struct PipelineResult
106 Graphics::Pipeline* pipeline;
108 PipelineCacheL0* level0;
109 PipelineCacheL1* level1;
110 PipelineCacheL2* level2;
121 * @param[in] controller Graphics controller
123 explicit PipelineCache(Graphics::Controller& controller);
126 * Retrieves next cache level
128 PipelineCacheL0* GetPipelineCacheL0(std::size_t hash, Program* program, Render::Geometry* geometry);
131 * Retrieves pipeline matching queryInfo struct
133 * May retrieve existing pipeline or create one or return nullptr.
135 PipelineResult GetPipeline(const PipelineCacheQueryInfo& queryInfo, bool createNewIfNotFound);
138 * @brief Check whether we can reuse latest found PipelineResult.
139 * We can reuse latest pipeline only if query info is equal with latest query
140 * and we don't call CleanLatestUsedCache() before.
142 * @param[in] latestUsedCacheIndex Index of cache we want to compare.
143 * @param[in] queryInfo Query for current pipeline.
144 * @return True if we can reuse latest pipeline result. False otherwise
146 bool ReuseLatestBoundPipeline(const int latestUsedCacheIndex, const PipelineCacheQueryInfo& queryInfo) const;
149 * @brief Clear latest bound result.
151 void CleanLatestUsedCache()
153 // Set pipeline as nullptr is enough.
154 mLatestResult[0].pipeline = nullptr;
155 mLatestResult[1].pipeline = nullptr;
159 Graphics::Controller* graphicsController{nullptr};
160 std::vector<PipelineCacheL0> level0nodes;
162 // Cache latest queries whether blend enabled or not.
163 // (Since most UI case (like Text and Image) enable blend, and most 3D case disable blend.)
164 PipelineCacheQueryInfo mLatestQuery[2]; ///< Latest requested query info. It will be invalidate after query's renderer / geometry / blendingOptions value changed.
165 PipelineResult mLatestResult[2]; ///< Latest used result. It will be invalidate when we call CleanLatestUsedCache() or some cache changed.
168 } // namespace Render
169 } // namespace Dali::Internal
171 #endif // DALI_INTERNAL_RENDER_PIPELINE_CACHE_H