Added shader support to pipeline cache
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-texture-dependency-checker.h
1 #ifndef DALI_GLES_TEXTURE_DEPENDENCY_CHECKER_H
2 #define DALI_GLES_TEXTURE_DEPENDENCY_CHECKER_H
3
4 /*
5  * Copyright (c) 2022 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 #include <dali/public-api/common/vector-wrapper.h>
21
22 namespace Dali::Graphics
23 {
24 class EglGraphicsController;
25
26 namespace GLES
27 {
28 class Context;
29 class Framebuffer;
30 class Texture;
31 class AgingSyncObject;
32
33 /**
34  * Class to handle dependency checks between textures on different
35  * GL Contexts.
36  *
37  * We have a shared (resource) context for writing to offscreen framebuffers,
38  * and separate contexts for each window/scene.
39  * If a framebuffer attachment is used in a scene, then it needs a sync point
40  * in the GPU in order to ensure that the first context finishes writing to the
41  * texture before it is read in the scene context.
42  */
43 class TextureDependencyChecker
44 {
45 public:
46   explicit TextureDependencyChecker(EglGraphicsController& controller)
47   : mController(controller)
48   {
49   }
50
51   /**
52    * Clear all the textures. Call at the start of a frame
53    */
54   void Reset();
55
56   /**
57    * Add Texture dependencies
58    *
59    * @param[in] writeContext The context of the framebuffer's render pass
60    * @param[in] framebuffer The framebuffer to collect textures from
61    */
62   void AddTextures(const Context* writeContext, const Framebuffer* framebuffer);
63
64   /**
65    * Check if the given texture needs syncing before being read.  This
66    * will perform a glWaitSync() (GPU side semaphore) if the texture
67    * needs syncing.
68    * @param[in] readContext The context that the texture is being read (drawn with)
69    * @param[in] texture The texture being read
70    */
71   void CheckNeedsSync(const Context* readContext, const Texture* texture);
72
73 private:
74   struct TextureDependency
75   {
76     std::vector<Texture*> textures;
77     Context*              writeContext{nullptr};
78     Framebuffer*          framebuffer{nullptr};
79     AgingSyncObject*      agingSyncObject;
80     bool                  syncing{false};
81   };
82   std::vector<TextureDependency> mTextureDependencies;
83   EglGraphicsController&         mController;
84 };
85
86 } // namespace GLES
87 } // namespace Dali::Graphics
88
89 #endif //DALI_GLES_TEXTURE_DEPENDENCY_CHECKER_H