• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef GLES_NODE_CONTEXT_DESCRIPTOR_SET_MANAGER_GLES_H
17 #define GLES_NODE_CONTEXT_DESCRIPTOR_SET_MANAGER_GLES_H
18 
19 #include <base/containers/array_view.h>
20 #include <base/containers/vector.h>
21 #include <render/device/pipeline_layout_desc.h>
22 #include <render/namespace.h>
23 #include <render/render_data_structures.h>
24 
25 #include "nodecontext/node_context_descriptor_set_manager.h"
26 
27 RENDER_BEGIN_NAMESPACE()
28 class GpuImageGLES;
29 
30 namespace Gles {
31 inline constexpr uint32_t EXTERNAL_BIT = 0x8000000;
32 
33 struct BufferType {
34     uint32_t bufferId;
35     uint32_t offset;
36     uint32_t size;
37 };
38 
39 struct ImageType {
40     GpuImageGLES* image;
41     uint32_t mode;
42     uint32_t mipLevel;
43 };
44 
45 struct SamplerType {
46     uint32_t samplerId;
47 };
48 
49 struct Bind {
50     struct Resource {
51         union {
52             BufferType buffer { 0U, 0U, 0U };
53             ImageType image;
54         };
55         SamplerType sampler { 0U };
56     };
57 
58     DescriptorType descriptorType { CORE_DESCRIPTOR_TYPE_MAX_ENUM };
59     BASE_NS::vector<Resource> resources;
60 };
61 } // namespace Gles
62 struct RenderPassBeginInfo;
63 class GpuResourceManager;
64 
65 class DescriptorSetManagerGles final : public DescriptorSetManager {
66 public:
67     explicit DescriptorSetManagerGles(Device& device);
68     ~DescriptorSetManagerGles() override = default;
69 
70     void BeginFrame() override;
71     void BeginBackendFrame();
72 
73     bool UpdateDescriptorSetGpuHandle(const RenderHandle& handle) override;
74     void UpdateCpuDescriptorSetPlatform(const DescriptorSetLayoutBindingResources& bindingResources) override;
75 
76     void CreateDescriptorSets(const uint32_t arrayIndex, const uint32_t descriptorSetCount,
77         const BASE_NS::array_view<const DescriptorSetLayoutBinding> descriptorSetLayoutBindings) override;
78 
79     BASE_NS::array_view<const Gles::Bind> GetResources(RenderHandle handle) const;
80 
81 private:
82     BASE_NS::vector<BASE_NS::vector<BASE_NS::vector<Gles::Bind>>> resources_;
83 };
84 
85 class NodeContextDescriptorSetManagerGles final : public NodeContextDescriptorSetManager {
86 public:
87     explicit NodeContextDescriptorSetManagerGles(Device& device);
88     ~NodeContextDescriptorSetManagerGles();
89 
90     void ResetAndReserve(const DescriptorCounts& descriptorCounts) override;
91     void BeginFrame() override;
92 
93     RenderHandle CreateDescriptorSet(
94         const BASE_NS::array_view<const DescriptorSetLayoutBinding> descriptorSetLayoutBindings) override;
95     RenderHandle CreateOneFrameDescriptorSet(
96         const BASE_NS::array_view<const DescriptorSetLayoutBinding> descriptorSetLayoutBindings) override;
97 
98     bool UpdateDescriptorSetGpuHandle(const RenderHandle handle) override;
99     void UpdateCpuDescriptorSetPlatform(const DescriptorSetLayoutBindingResources& bindingResources) override;
100 
101     BASE_NS::array_view<const Gles::Bind> GetResources(RenderHandle handle) const;
102 
103 private:
104     Device& device_;
105     // common descriptor sets and one frame descriptor sets
106     BASE_NS::vector<BASE_NS::vector<Gles::Bind>>
107         resources_[NodeContextDescriptorSetManager::DESCRIPTOR_SET_INDEX_TYPE_COUNT];
108     uint32_t oneFrameDescSetGeneration_ { 0u };
109 #if (RENDER_VALIDATION_ENABLED == 1)
110     static constexpr uint32_t MAX_ONE_FRAME_GENERATION_IDX { 16u };
111 #endif
112 };
113 RENDER_END_NAMESPACE()
114 
115 #endif // GLES_NODE_CONTEXT_DESCRIPTOR_SET_MANAGER_GLES_H
116