• 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 RENDER_NODE_RENDER_NODE_SINGLE_POST_PROCESS_H
17 #define RENDER_NODE_RENDER_NODE_SINGLE_POST_PROCESS_H
18 
19 #include <base/containers/string.h>
20 #include <base/util/uid.h>
21 #include <render/datastore/intf_render_data_store_post_process.h>
22 #include <render/datastore/render_data_store_render_pods.h>
23 #include <render/device/pipeline_state_desc.h>
24 #include <render/namespace.h>
25 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h>
26 #include <render/nodecontext/intf_render_node.h>
27 #include <render/render_data_structures.h>
28 #include <render/resource_handle.h>
29 
30 #include "nodecontext/render_node_copy_util.h"
31 #include "util/log.h"
32 
33 RENDER_BEGIN_NAMESPACE()
34 class IGpuResourceManager;
35 class IRenderCommandList;
36 class IRenderNodeContextManager;
37 class IRenderNodeRenderDataStoreManager;
38 struct RenderNodeGraphInputs;
39 
40 class RenderNodeSinglePostProcess final : public IRenderNode {
41 public:
42     RenderNodeSinglePostProcess() = default;
43     ~RenderNodeSinglePostProcess() override = default;
44 
45     void InitNode(IRenderNodeContextManager& renderNodeContextMgr) override;
46     void PreExecuteFrame() override;
47     void ExecuteFrame(IRenderCommandList& cmdList) override;
GetExecuteFlags()48     ExecuteFlags GetExecuteFlags() const override
49     {
50         return 0U;
51     }
52 
53     // for plugin / factory interface
54     static constexpr BASE_NS::Uid UID { "f4495799-9db7-477f-9eaf-6fad26260304" };
55     static constexpr const char* TYPE_NAME = "CORE_RN_SINGLE_POST_PROCESS";
56     static constexpr IRenderNode::BackendFlags BACKEND_FLAGS = IRenderNode::BackendFlagBits::BACKEND_FLAG_BITS_DEFAULT;
57     static constexpr IRenderNode::ClassType CLASS_TYPE = IRenderNode::ClassType::CLASS_TYPE_NODE;
58     static IRenderNode* Create();
59     static void Destroy(IRenderNode* instance);
60 
61 private:
62     IRenderNodeContextManager* renderNodeContextMgr_ { nullptr };
63 
64     void ParseRenderNodeInputs();
65     void InitCreateBinders();
66     void UpdateGlobalPostProcessUbo();
67     void UpdateImageData();
68     void ProcessPostProcessConfiguration();
69     void RegisterOutputs(RenderHandle output);
70     void BindDefaultResources(uint32_t set, const DescriptorSetLayoutBindingResources& bindings);
71     void ExecuteSinglePostProcess(IRenderCommandList& cmdList);
72 
73     enum class DefaultOutputImage : uint32_t {
74         OUTPUT = 0,
75         INPUT_OUTPUT_COPY = 1,
76         INPUT = 2,
77         WHITE = 3,
78         BLACK = 4,
79     };
80     // Json resources which might need re-fetching
81     struct JsonInputs {
82         RenderNodeGraphInputs::InputRenderPass renderPass;
83         RenderNodeGraphInputs::InputResources resources;
84         RenderNodeGraphInputs::InputResources dispatchResources;
85 
86         RenderNodeGraphInputs::RenderDataStore renderDataStore;
87 
88         BASE_NS::string ppName;
89         DefaultOutputImage defaultOutputImage { DefaultOutputImage::OUTPUT };
90 
91         bool hasChangeableRenderPassHandles { false };
92         bool hasChangeableResourceHandles { false };
93         bool hasChangeableDispatchHandles { false };
94 
95         uint32_t inputIdx { ~0u };
96         uint32_t outputIdx { ~0u };
97     };
98     JsonInputs jsonInputs_;
99 
100     struct BuiltInVariables {
101         RenderHandle input;
102 
103         RenderHandle output;
104 
105         RenderHandle defBuffer;
106         RenderHandle defBlackImage;
107         RenderHandle defWhiteImage;
108         RenderHandle defSampler;
109 
110         // the flag for the post built-in post process
111         uint32_t postProcessFlag { 0u };
112     };
113     BuiltInVariables builtInVariables_;
114 
115     RenderNodeHandles::InputRenderPass inputRenderPass_;
116     RenderNodeHandles::InputResources inputResources_;
117     RenderNodeHandles::InputResources dispatchResources_;
118     RenderHandle shader_;
119     PipelineLayout pipelineLayout_;
120     RenderHandle psoHandle_;
121     PushConstant pushConstant_;
122     bool graphics_ { true };
123     ShaderThreadGroup threadGroupSize_ { 1u, 1u, 1u };
124 
125     IPipelineDescriptorSetBinder::Ptr pipelineDescriptorSetBinder_;
126     IDescriptorSetBinder::Ptr copyBinder_;
127 
128     RenderNodeCopyUtil renderCopy_;
129 
130     PostProcessConfiguration ppGlobalConfig_;
131     IRenderDataStorePostProcess::PostProcess ppLocalConfig_;
132 
133     struct UboHandles {
134         // first 512 aligned is global post process
135         // after (256) we have effect local data
136         RenderHandleReference postProcess;
137 
138         uint32_t effectLocalDataIndex { 1u };
139     };
140     UboHandles ubos_;
141 
142     bool useAutoBindSet0_ { false };
143     bool valid_ { false };
144 };
145 RENDER_END_NAMESPACE()
146 
147 #endif // RENDER_NODE_RENDER_NODE_SINGLE_POST_PROCESS_H
148