• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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_RENDER__NODE__RENDER_NODE_COMBINED_POST_PROCESS_H
17 #define RENDER_RENDER__NODE__RENDER_NODE_COMBINED_POST_PROCESS_H
18 
19 #include <base/util/uid.h>
20 #include <render/datastore/render_data_store_render_pods.h>
21 #include <render/device/pipeline_state_desc.h>
22 #include <render/namespace.h>
23 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h>
24 #include <render/nodecontext/intf_render_node.h>
25 #include <render/render_data_structures.h>
26 #include <render/resource_handle.h>
27 
28 #include "node/render_bloom.h"
29 #include "node/render_blur.h"
30 
31 RENDER_BEGIN_NAMESPACE()
32 class IGpuResourceManager;
33 class IRenderCommandList;
34 class IRenderNodeContextManager;
35 class IRenderNodeRenderDataStoreManager;
36 struct RenderNodeGraphInputs;
37 
38 class RenderNodeCombinedPostProcess final : public IRenderNode {
39 public:
40     RenderNodeCombinedPostProcess() = default;
41     ~RenderNodeCombinedPostProcess() override = default;
42 
43     void InitNode(IRenderNodeContextManager& renderNodeContextMgr) override;
44     void PreExecuteFrame() override;
45     void ExecuteFrame(IRenderCommandList& cmdList) override;
46 
47     // for plugin / factory interface
48     static constexpr BASE_NS::Uid UID { "82fbcb54-5762-499f-a039-b3862b316f33" };
49     static constexpr char const* TYPE_NAME = "CORE_RN_COMBINED_POST_PROCESS";
50     static constexpr IRenderNode::BackendFlags BACKEND_FLAGS = IRenderNode::BackendFlagBits::BACKEND_FLAG_BITS_DEFAULT;
51     static constexpr IRenderNode::ClassType CLASS_TYPE = IRenderNode::ClassType::CLASS_TYPE_NODE;
52     static IRenderNode* Create();
53     static void Destroy(IRenderNode* instance);
54 
55 private:
56     IRenderNodeContextManager* renderNodeContextMgr_ { nullptr };
57 
58     void ParseRenderNodeInputs();
59     void UpdateImageData();
60 
61     void InitCreateShaderResources();
62     void InitCreateBinders();
63 
64     // Json resources which might need re-fetching
65     struct JsonInputs {
66         RenderNodeGraphInputs::InputResources resources;
67         bool hasChangeableResourceHandles { false };
68 
69         uint32_t colorIndex { ~0u };
70         uint32_t depthIndex { ~0u };
71         uint32_t velocityIndex { ~0u };
72         uint32_t historyIndex { ~0u };
73         uint32_t historyNextIndex { ~0u };
74     };
75     JsonInputs jsonInputs_;
76     RenderNodeHandles::InputResources inputResources_;
77     RenderNodeGraphInputs::RenderDataStore renderDataStore_;
78 
79     struct PsoSpecializationData {
80         TonemapConfiguration::TonemapType tonemapType {};
81         bool enableVignette { false };
82         bool enableColorFringe { false };
83         bool enableTonemap { false };
84     };
85     void CheckForPsoSpecilization();
86     void UpdatePostProcessData(const PostProcessConfiguration& postProcessConfiguration);
87     void ProcessPostProcessConfiguration();
88     void ExecuteCombine(IRenderCommandList& cmdList);
89     void ExecuteFXAA(IRenderCommandList& cmdList);
90     void ExecuteBlit(IRenderCommandList& cmdList);
91     void ExecuteTAA(IRenderCommandList& cmdList);
92 
93     struct EffectData {
94         RenderHandle shader;
95         RenderHandle pl;
96         RenderHandle pso;
97 
98         PipelineLayout pipelineLayout;
99     };
100 
101     RenderHandle psoHandle_;
102     RenderHandle copyPsoHandle_;
103     RenderPass renderPass_;
104 
105     struct ConfigurationNames {
106         BASE_NS::string renderDataStoreName;
107         BASE_NS::string postProcessConfigurationName;
108     };
109     ConfigurationNames configurationNames_;
110 
111     PipelineLayout pipelineLayout_;
112     PipelineLayout copyPipelineLayout_;
113 
114     struct AllBinders {
115         // main, taa, fxaa
116         static constexpr uint32_t GLOBAL_SET0_COUNT { 3u };
117 
118         IDescriptorSetBinder::Ptr globalSet0[GLOBAL_SET0_COUNT];
119         uint32_t globalSetIndex { 0u }; // needs to be reset every frame
120 
121         IDescriptorSetBinder::Ptr mainBinder;
122         IDescriptorSetBinder::Ptr taaBinder;
123         IDescriptorSetBinder::Ptr fxaaBinder;
124 
125         IDescriptorSetBinder::Ptr copyBinder;
126     };
127     AllBinders binders_;
128 
129     RenderHandleReference intermediateImage_;
130 
131     RenderHandle combinedShader_;
132     RenderHandle copyShader_;
133     RenderHandle sampler_;
134     PostProcessConfiguration ppConfig_;
135 
136     struct ImageData {
137         // input and output as in render node graph
138         RenderHandle globalInput;
139         RenderHandle globalOutput;
140 
141         // input and output used in post processes
142         // TAA will set the input to post processes to be historyOutput
143         RenderHandle input;
144         RenderHandle output;
145         // TAA related
146         RenderHandle history;
147         RenderHandle historyNext;
148 
149         RenderHandle depth;
150         // Required by TAA
151         RenderHandle velocity;
152 
153         RenderHandle dirtMask;
154         RenderHandle black;
155         RenderHandle white;
156     };
157     ImageData images_;
158 
159     EffectData fxaaData_;
160     EffectData taaData_;
161 
162     RenderBloom renderBloom_;
163     RenderBlur renderBlur_;
164 
165     struct UboHandles {
166         // first 256 aligned is global post process
167         // after (256) we have effect local data
168         RenderHandleReference postProcess;
169 
170         uint32_t taaIndex { 1u };
171         uint32_t bloomIndex { 2u };
172         uint32_t blurIndex { 3u };
173         uint32_t fxaaIndex { 4u };
174         uint32_t combinedIndex { 5u };
175     };
176     UboHandles ubos_;
177 
178     BASE_NS::Math::Vec4 fxaaTargetSize_ { 0.0f, 0.0f, 0.0f, 0.0f };
179 
180     bool validInputs_ { true };
181     bool validInputsForTaa_ { false };
182 };
183 RENDER_END_NAMESPACE()
184 
185 #endif // CORE__RENDER__NODE__RENDER_NODE_COMBINED_POST_PROCESS_H
186