Merge "Added shader support to pipeline cache" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-graphics-pipeline-cache.h
1 #ifndef DALI_GRAPHICS_GLES_PIPELINE_CACHE_H
2 #define DALI_GRAPHICS_GLES_PIPELINE_CACHE_H
3
4 /*
5  * Copyright (c) 2023 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
21 // EXTERNAL INCLUDES
22 #include <dali/graphics-api/graphics-pipeline-create-info.h>
23 #include <dali/graphics-api/graphics-pipeline.h>
24 #include <dali/graphics-api/graphics-program-create-info.h>
25 #include <dali/graphics-api/graphics-program.h>
26 #include <dali/graphics-api/graphics-shader-create-info.h>
27 #include <dali/graphics-api/graphics-shader.h>
28
29 // INTERNAL INCLUDES
30 #include "gles-graphics-resource.h"
31
32 namespace Dali::Graphics
33 {
34 class EglGraphicsController;
35 namespace GLES
36 {
37 class Pipeline;
38 class PipelineImpl;
39 class Program;
40 class ProgramImpl;
41 class Shader;
42 class ShaderImpl;
43
44 /**
45  * @brief PipelineCache manages pipeline and program
46  * objects so there are no duplicates created.
47  */
48 class PipelineCache
49 {
50 public:
51   /**
52    * @brief Constructor
53    */
54   explicit PipelineCache(EglGraphicsController& controller);
55
56   /**
57    * @brief Destructor
58    */
59   ~PipelineCache();
60
61   /**
62    * @brief Retrieves pipeline matching the spec
63    *
64    * Function returns either existing pipeline if one is found
65    * in the cache or creates new one.
66    *
67    * @param[in] pipelineCreateInfo Valid PipelineCreateInfo structure
68    * @param[in] oldPipeline previous pipeline object
69    * @return Pipeline object
70    */
71   Graphics::UniquePtr<Graphics::Pipeline> GetPipeline(const PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline);
72
73   /**
74    * @brief Retrieves program matching the spec
75    *
76    * Function returns either existing program if one is found
77    * in the cache or creates new one.
78    *
79    * @param[in] programCreateInfo Valid ProgramCreateInfo structure
80    * @param[in] oldProgram previous program object
81    * @return Program object
82    */
83   Graphics::UniquePtr<Graphics::Program> GetProgram(const ProgramCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram);
84
85   /**
86    * @brief Retrieves shader matching the spec
87    *
88    * Function returns either existing shader if one is found
89    * in the cache or creates new one.
90    *
91    * @param[in] shaderCreateInfo Valid ShaderCreateInfo structure
92    * @param[in] oldShader previous shader object
93    * @return Shader object
94    */
95   Graphics::UniquePtr<Graphics::Shader> GetShader(const ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader);
96
97   /**
98    * @brief Flushes pipeline and program cache
99    *
100    * Removes cached items when they are no longer needed. This function
101    * should be called at the very end of Controller render loop iteration.
102    */
103   void FlushCache();
104
105   /**
106    * @brief Notify that we need to flush pipeline cache next FlushCache API.
107    */
108   void MarkPipelineCacheFlushRequired();
109
110   /**
111    * @brief Notify that we need to flush program cache next FlushCache API.
112    */
113   void MarkProgramCacheFlushRequired();
114
115   /**
116    * @brief Notify that we need to flush shader cache next FlushCache API.
117    */
118   void MarkShaderCacheFlushRequired();
119
120 private:
121   /**
122    * @brief Finds pipeline implementation based on the spec
123    * @param[in] info Valid create info structure
124    * @return Returns pointer to pipeline or nullptr
125    */
126   PipelineImpl* FindPipelineImpl(const PipelineCreateInfo& info);
127
128   /**
129    * @brief Finds program implementation based on the spec
130    * @param[in] info Valid create info structure
131    * @return Returns pointer to program or nullptr
132    */
133   ProgramImpl* FindProgramImpl(const ProgramCreateInfo& info);
134
135   /**
136    * @brief Finds shader implementation based on create info
137    *
138    * @param[in] shadercreateinfo Valid create info structure
139    * @return Returns pointer to shader or nullptr
140    */
141   ShaderImpl* FindShaderImpl(const ShaderCreateInfo& shaderCreateInfo);
142
143 private:
144   struct Impl;
145   std::unique_ptr<Impl> mImpl;
146 };
147 } // namespace GLES
148 } // namespace Dali::Graphics
149 #endif