c9027d3b9f52543fc432d9c51526eb2c0bc80e42
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / pipeline-cache.h
1 #ifndef DALI_INTERNAL_RENDER_PIPELINE_CACHE_H
2 #define DALI_INTERNAL_RENDER_PIPELINE_CACHE_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // INTERNAL INCLUDES
21 #include <dali/internal/common/blending-options.h>
22 #include <dali/graphics-api/graphics-types.h>
23 #include <dali/graphics-api/graphics-controller.h>
24 #include <dali/graphics-api/graphics-pipeline.h>
25
26 // EXTERNAL INCLUDES
27 #include <vector>
28
29 namespace Dali::Internal
30 {
31 class Program;
32 namespace Render
33 {
34 class Renderer;
35 class Geometry;
36
37 /**
38  * Cache Level 2 : Last level of cache, stores actual pipeline
39  */
40 struct PipelineCacheL2
41 {
42   uint32_t                                hash{};
43   Graphics::ColorBlendState               colorBlendState;
44   Graphics::UniquePtr<Graphics::Pipeline> pipeline;
45 };
46
47 /**
48  * Cache Level 1 : Stores rasterization and input assembly states
49  */
50 struct PipelineCacheL1
51 {
52
53   PipelineCacheL2 *GetPipelineCacheL2(bool blend, bool premul, BlendingOptions &blendingOptions);
54
55   uint32_t                     hashCode{}; // 1byte cull, 1byte poly, 1byte frontface
56   Graphics::RasterizationState rs{};
57   Graphics::InputAssemblyState ia{};
58
59   PipelineCacheL2              noBlend; // special case
60   std::vector<PipelineCacheL2> level2nodes;
61 };
62
63 /**
64  * Cache Level 0 : Stores geometry, program amd vertex input state
65  */
66 struct PipelineCacheL0 // L0 cache
67 {
68   PipelineCacheL1 *GetPipelineCacheL1(Render::Renderer *renderer, bool usingReflection);
69
70   Geometry                   *geometry{};
71   Program                    *program{};
72   Graphics::VertexInputState inputState;
73
74   std::vector<PipelineCacheL1> level1nodes;
75 };
76
77 struct PipelineCacheQueryInfo
78 {
79   // Program/Geometry
80   Renderer *renderer;
81   Program  *program;
82   Geometry *geometry;
83
84   bool cameraUsingReflection;
85
86   // Blending
87   bool blendingEnabled;
88   bool alphaPremultiplied;
89   BlendingOptions *blendingOptions;
90
91 };
92
93 /**
94  * Result of PipelineCache::GetPipeline() call
95  */
96 struct PipelineResult
97 {
98   Graphics::Pipeline* pipeline;
99
100   PipelineCacheL0* level0;
101   PipelineCacheL1* level1;
102   PipelineCacheL2* level2;
103 };
104
105 /**
106  * Pipeline cache
107  */
108 class PipelineCache
109 {
110 public:
111   /**
112    * Constructor
113    * @param[in] controller Graphics controller
114    */
115   explicit PipelineCache(Graphics::Controller& controller);
116
117   /**
118    * Retrieves next cache level
119    */
120   PipelineCacheL0* GetPipelineCacheL0( Program *program, Render::Geometry *geometry);
121
122   /**
123    * Retrieves pipeline matching queryInfo struct
124    *
125    * May retrieve existing pipeline or create one or return nullptr.
126    */
127   PipelineResult GetPipeline( const PipelineCacheQueryInfo& queryInfo, bool createNewIfNotFound );
128
129 private:
130
131   Graphics::Controller* graphicsController{nullptr};
132   std::vector<PipelineCacheL0> level0nodes;
133 };
134
135 }
136 }
137
138 #endif // DALI_INTERNAL_RENDER_PIPELINE_CACHE_H