• 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_POSTPROCESS_RENDER_POST_PROCESS_DOF_NODE_H
17 #define RENDER_POSTPROCESS_RENDER_POST_PROCESS_DOF_NODE_H
18 
19 #include <array>
20 
21 #include <base/containers/string.h>
22 #include <base/containers/string_view.h>
23 #include <base/containers/unique_ptr.h>
24 #include <base/math/vector.h>
25 #include <base/util/uid.h>
26 #include <core/plugin/intf_interface.h>
27 #include <core/plugin/intf_interface_helper.h>
28 #include <core/property/intf_property_api.h>
29 #include <core/property/intf_property_handle.h>
30 #include <core/property/property_types.h>
31 #include <core/property_tools/property_api_impl.h>
32 #include <core/property_tools/property_macros.h>
33 #include <render/datastore/render_data_store_render_pods.h>
34 #include <render/device/intf_shader_manager.h>
35 #include <render/namespace.h>
36 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h>
37 #include <render/nodecontext/intf_render_node.h>
38 #include <render/nodecontext/intf_render_node_post_process_util.h>
39 #include <render/nodecontext/intf_render_post_process.h>
40 #include <render/nodecontext/intf_render_post_process_node.h>
41 #include <render/render_data_structures.h>
42 
43 RENDER_BEGIN_NAMESPACE()
44 class IRenderCommandList;
45 class IRenderNodeRenderDataStoreManager;
46 struct RenderNodeGraphInputs;
47 
48 class RenderPostProcessDofNode final : public CORE_NS::IInterfaceHelper<IRenderPostProcessNode> {
49 public:
50     static constexpr auto UID = BASE_NS::Uid("134815e1-915e-40d9-b230-2467fb946cf7");
51 
52     using Ptr = BASE_NS::refcnt_ptr<RenderPostProcessDofNode>;
53 
54     RenderPostProcessDofNode();
55     ~RenderPostProcessDofNode() = default;
56 
57     CORE_NS::IPropertyHandle* GetRenderInputProperties() override;
58     CORE_NS::IPropertyHandle* GetRenderOutputProperties() override;
59     DescriptorCounts GetRenderDescriptorCounts() const override;
60     void SetRenderAreaRequest(const RenderAreaRequest& renderAreaRequest) override;
61     IRenderNode::ExecuteFlags GetExecuteFlags() const override;
62 
63     struct EffectProperties {
64         bool enabled { false };
65         DofConfiguration dofConfiguration;
66         RenderHandleReference mipImages[2U];
67         BindableImage nearMip;
68         BindableImage farMip;
69     };
70 
71     void Init(const IRenderPostProcess::Ptr& postProcess, IRenderNodeContextManager& renderNodeContextMgr) override;
72     void PreExecute() override;
73     void Execute(IRenderCommandList& cmdList) override;
74 
75     // for plugin / factory interface
76     static constexpr const char* TYPE_NAME = "RenderPostProcessDofNode";
77 
78     struct DofConfig {
79         BASE_NS::Math::Vec4 factors0;
80         BASE_NS::Math::Vec4 factors1;
81     };
82     DofConfig shaderParameters_;
83 
84     struct NodeInputs {
85         BindableImage input;
86         BindableImage depth;
87     };
88     struct NodeOutputs {
89         BindableImage output;
90     };
91 
92     NodeInputs nodeInputsData;
93     NodeOutputs nodeOutputsData;
94 
95 private:
96     IRenderNodeContextManager* renderNodeContextMgr_ { nullptr };
97     IRenderPostProcess::Ptr postProcess_;
98 
99     BASE_NS::Math::Vec4 GetFactorDof() const;
100     BASE_NS::Math::Vec4 GetFactorDof2() const;
101     void CheckDescriptorSetNeed();
102 
103     struct PostProcessInterfaces {
104         IRenderPostProcess::Ptr postProcess;
105         IRenderPostProcessNode::Ptr postProcessNode;
106     };
107     PostProcessInterfaces ppRenderNearBlurInterface_;
108     PostProcessInterfaces ppRenderFarBlurInterface_;
109     PostProcessInterfaces ppRenderBlurInterface_;
110 
111     RenderPass CreateRenderPass(const RenderHandle input);
112     void ExecuteDofBlur(IRenderCommandList& cmdList);
113 
114     IShaderManager::ShaderData dofShaderData_;
115     IShaderManager::ShaderData dofBlurShaderData_;
116 
117     struct PSOs {
118         RenderHandle dofPso;
119         RenderHandle dofBlurPso;
120     };
121     PSOs psos_;
122 
123     struct Binders {
124         IDescriptorSetBinder::Ptr dofBinder;
125         IDescriptorSetBinder::Ptr dofBlurBinder;
126     };
127     Binders binders_;
128 
129     struct DefaultSamplers {
130         RenderHandle nearest;
131         RenderHandle mipLinear;
132     };
133     DefaultSamplers samplers_;
134 
135     RENDER_NS::RenderHandleReference gpuBuffer_;
136 
137     RenderAreaRequest renderAreaRequest_;
138     bool useRequestedRenderArea_ { false };
139 
140     CORE_NS::PropertyApiImpl<NodeInputs> inputProperties_;
141     CORE_NS::PropertyApiImpl<NodeOutputs> outputProperties_;
142 
143     RENDER_NS::DescriptorCounts descriptorCounts_;
144     bool valid_ { false };
145 
146     EffectProperties effectProperties_;
147 };
148 RENDER_END_NAMESPACE()
149 
150 #endif // RENDER_POSTPROCESS_RENDER_POST_PROCESS_DOF_NODE_H
151