• 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_NODECONTEXT_RENDER_NODE_POST_PROCESS_UTIL_H
17 #define RENDER_NODECONTEXT_RENDER_NODE_POST_PROCESS_UTIL_H
18 
19 #include <cstdint>
20 
21 #include <base/containers/array_view.h>
22 #include <render/datastore/render_data_store_render_pods.h>
23 #include <render/device/intf_shader_manager.h>
24 #include <render/device/pipeline_state_desc.h>
25 #include <render/namespace.h>
26 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h>
27 #include <render/nodecontext/intf_render_node_post_process_util.h>
28 #include <render/nodecontext/intf_render_post_process.h>
29 #include <render/nodecontext/intf_render_post_process_node.h>
30 #include <render/render_data_structures.h>
31 
32 #include "nodecontext/render_node_copy_util.h"
33 
34 RENDER_BEGIN_NAMESPACE()
35 struct RenderableList;
36 struct PipelineLayout;
37 class IRenderNodeContextManager;
38 class IRenderNodeCommandList;
39 
40 class RenderNodePostProcessUtil final {
41 public:
42     RenderNodePostProcessUtil() = default;
43     ~RenderNodePostProcessUtil() = default;
44 
45     void Init(IRenderNodeContextManager& renderNodeContextMgr,
46         const IRenderNodePostProcessUtil::PostProcessInfo& postProcessInfo);
47     void PreExecute(const IRenderNodePostProcessUtil::PostProcessInfo& postProcessInfo);
48     void Execute(IRenderCommandList& cmdList);
49 
50 private:
51     IRenderNodeContextManager* renderNodeContextMgr_;
52 
53     void ParseRenderNodeInputs();
54     void UpdateImageData();
55 
56     void ProcessPostProcessConfiguration();
57     void InitCreateShaderResources();
58     void InitCreateBinders();
59     void CreatePostProcessInterfaces();
60 
61     struct InputOutput {
62         BindableImage input;
63         BindableImage output;
64     };
65     void ExecuteBlit(IRenderCommandList& cmdList, const InputOutput& inOut);
66 
67     // Json resources which might need re-fetching
68     struct JsonInputs {
69         RenderNodeGraphInputs::InputResources resources;
70         RenderNodeGraphInputs::RenderDataStore renderDataStore;
71         bool hasChangeableResourceHandles { false };
72 
73         uint32_t colorIndex { ~0u };
74         uint32_t depthIndex { ~0u };
75         uint32_t velocityIndex { ~0u };
76         uint32_t historyIndex { ~0u };
77         uint32_t historyNextIndex { ~0u };
78     };
79     JsonInputs jsonInputs_;
80     RenderNodeHandles::InputResources inputResources_;
81 
82     struct EffectData {
83         IShaderManager::ShaderData sd;
84         RenderHandle pso;
85     };
86     EffectData copyData_;
87 
88     // additional layer copy
89     RenderNodeCopyUtil renderCopyLayer_;
90 
91     struct PostProcessInterfaces {
92         IRenderPostProcess::Ptr postProcess;
93         IRenderPostProcessNode::Ptr postProcessNode;
94     };
95     PostProcessInterfaces ppLensFlareInterface_;
96     PostProcessInterfaces ppRenderBlurInterface_;
97     PostProcessInterfaces ppRenderTaaInterface_;
98     PostProcessInterfaces ppRenderFxaaInterface_;
99     PostProcessInterfaces ppRenderDofInterface_;
100     PostProcessInterfaces ppRenderMotionBlurInterface_;
101     PostProcessInterfaces ppRenderBloomInterface_;
102     PostProcessInterfaces ppRenderUpscaleInterface_;
103     PostProcessInterfaces ppRenderCombinedInterface_;
104 
105     struct AdditionalImageData {
106         RenderHandle black;
107         RenderHandle white;
108     };
109     IRenderNodePostProcessUtil::ImageData images_;
110     AdditionalImageData aimg_;
111 
112     IRenderNodePostProcessUtil::PostProcessInfo postProcessInfo_;
113 
114     BASE_NS::Math::UVec2 outputSize_ { 0U, 0U };
115 
116     bool validInputs_ { true };
117     bool validInputsForTaa_ { false };
118     bool validInputsForDof_ { false };
119     bool validInputsForMb_ { false };
120     bool validInputsForUpscale_ { false };
121 
122     BASE_NS::vector<InputOutput> framePostProcessInOut_;
123 
124     struct DefaultSamplers {
125         RenderHandle nearest;
126         RenderHandle linear;
127         RenderHandle mipLinear;
128     };
129     DefaultSamplers samplers_;
130     PostProcessConfiguration ppConfig_;
131 
132     struct TemporaryImages {
133         uint32_t idx = 0U;
134         uint32_t imageCount = 0U;
135         uint32_t mipIdx = 0U;
136         uint32_t mipImageCount = 0U;
137         RenderHandleReference images[2U];
138         RenderHandleReference mipImages[2U];
139         BASE_NS::Math::Vec4 targetSize { 0.0f, 0.0f, 0.0f, 0.0f };
140         uint32_t mipCount[2U];
141 
142         RenderHandleReference layerCopyImage;
143     };
144     TemporaryImages ti_;
GetIntermediateImage(const RenderHandle & input)145     BindableImage GetIntermediateImage(const RenderHandle& input)
146     {
147         if (ti_.imageCount == 0U) {
148             return {};
149         }
150         if (input == ti_.images[ti_.idx].GetHandle()) {
151             ti_.idx = (ti_.idx + 1) % static_cast<uint32_t>(ti_.imageCount);
152         }
153         return { ti_.images[ti_.idx].GetHandle() };
154     }
GetMipImage(const RenderHandle & input)155     BindableImage GetMipImage(const RenderHandle& input)
156     {
157         if (ti_.mipImageCount == 0U) {
158             return {};
159         }
160         if (input == ti_.mipImages[ti_.mipIdx].GetHandle()) {
161             ti_.mipIdx = (ti_.mipIdx + 1) % static_cast<uint32_t>(ti_.mipImageCount);
162         }
163         return { ti_.mipImages[ti_.mipIdx].GetHandle() };
164     }
165 
166     struct AllBinders {
167         IDescriptorSetBinder::Ptr copyBinder;
168     };
169     AllBinders binders_;
170 
171     DeviceBackendType deviceBackendType_ { DeviceBackendType::VULKAN };
172 
173     bool glOptimizedLayerCopyEnabled_ { false };
174 };
175 
176 class RenderNodePostProcessUtilImpl final : public IRenderNodePostProcessUtil {
177 public:
178     RenderNodePostProcessUtilImpl() = default;
179     ~RenderNodePostProcessUtilImpl() override = default;
180 
181     void Init(IRenderNodeContextManager& renderNodeContextMgr,
182         const IRenderNodePostProcessUtil::PostProcessInfo& postProcessInfo) override;
183     void PreExecute(const IRenderNodePostProcessUtil::PostProcessInfo& postProcessInfo) override;
184     void Execute(IRenderCommandList& cmdList) override;
185 
186     const CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) const override;
187     CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) override;
188 
189     void Ref() override;
190     void Unref() override;
191 
192 private:
193     RenderNodePostProcessUtil rn_;
194 
195     uint32_t refCount_ { 0U };
196 };
197 RENDER_END_NAMESPACE()
198 
199 #endif // RENDER__RENDER_NODE_POST_PROCESS_UTIL_H
200