• 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_MOTION_BLUR_NODE_H
17 #define RENDER_POSTPROCESS_RENDER_POST_PROCESS_MOTION_BLUR_NODE_H
18 
19 #include <base/math/vector.h>
20 #include <base/util/uid.h>
21 #include <core/plugin/intf_interface.h>
22 #include <core/plugin/intf_interface_helper.h>
23 #include <core/property/intf_property_api.h>
24 #include <core/property/intf_property_handle.h>
25 #include <core/property/property_types.h>
26 #include <core/property_tools/property_api_impl.h>
27 #include <core/property_tools/property_macros.h>
28 #include <render/datastore/render_data_store_render_pods.h>
29 #include <render/device/intf_shader_manager.h>
30 #include <render/namespace.h>
31 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h>
32 #include <render/nodecontext/intf_render_node.h>
33 #include <render/nodecontext/intf_render_node_post_process_util.h>
34 #include <render/nodecontext/intf_render_post_process.h>
35 #include <render/nodecontext/intf_render_post_process_node.h>
36 #include <render/render_data_structures.h>
37 
38 RENDER_BEGIN_NAMESPACE()
39 class IRenderCommandList;
40 class IRenderNodeRenderDataStoreManager;
41 struct RenderNodeGraphInputs;
42 
43 class RenderPostProcessMotionBlurNode final : public CORE_NS::IInterfaceHelper<IRenderPostProcessNode> {
44 public:
45     static constexpr auto UID = BASE_NS::Uid("b77a0280-8669-4492-a9a1-96a16c79e64f");
46 
47     using Ptr = BASE_NS::refcnt_ptr<RenderPostProcessMotionBlurNode>;
48 
49     RenderPostProcessMotionBlurNode();
50     ~RenderPostProcessMotionBlurNode() = default;
51 
52     CORE_NS::IPropertyHandle* GetRenderInputProperties() override;
53     CORE_NS::IPropertyHandle* GetRenderOutputProperties() override;
54     DescriptorCounts GetRenderDescriptorCounts() const override;
55     void SetRenderAreaRequest(const RenderAreaRequest& renderAreaRequest) override;
56     IRenderNode::ExecuteFlags GetExecuteFlags() const override;
57 
58     struct EffectProperties {
59         bool enabled { false };
60         BASE_NS::Math::UVec2 size { 0U, 0U };
61         MotionBlurConfiguration motionBlurConfiguration;
62     };
63 
64     void Init(const IRenderPostProcess::Ptr& postProcess, IRenderNodeContextManager& renderNodeContextMgr) override;
65     void PreExecute() override;
66     void Execute(IRenderCommandList& cmdList) override;
67 
68     struct NodeInputs {
69         BindableImage input;
70         BindableImage velocity;
71         BindableImage depth;
72     };
73     struct NodeOutputs {
74         BindableImage output;
75     };
76 
77     NodeInputs nodeInputsData;
78     NodeOutputs nodeOutputsData;
79 
80     BASE_NS::Math::Vec4 shaderParameters_;
81 
82 private:
83     IRenderNodeContextManager* renderNodeContextMgr_ { nullptr };
84     IRenderPostProcess::Ptr postProcess_;
85 
86     BASE_NS::Math::Vec4 GetFactorMotionBlur() const;
87     void ExecuteTileVelocity(IRenderCommandList& cmdList);
88     RenderHandle GetTileVelocityForMotionBlur() const;
89     void CheckDescriptorSetNeed();
90 
91     struct RenderDataHandles {
92         RenderHandle shader;
93         RenderHandle pso;
94         PipelineLayout pipelineLayout;
95     };
96     RenderDataHandles renderData_;
97     RenderDataHandles renderTileMaxData_;
98     struct RenderDataHandlesTileNeighborhood {
99         RenderHandle shader;
100         PipelineLayout pipelineLayout;
101         RenderHandle psoNeighborhood;
102         RenderHandle psoHorizontal;
103         RenderHandle psoVertical;
104         bool doublePass { true };
105     };
106     RenderDataHandlesTileNeighborhood renderTileNeighborData_;
107 
108     struct Binders {
109         IDescriptorSetBinder::Ptr localSet0;
110         IDescriptorSetBinder::Ptr localTileMaxSet0;
111         IDescriptorSetBinder::Ptr localTileNeighborhoodSet0[2U];
112     };
113     Binders binders_;
114 
115     RenderHandle samplerHandle_;
116     RenderHandle samplerNearestHandle_;
117 
118     RENDER_NS::RenderHandleReference gpuBuffer_;
119 
120     RenderHandleReference tileVelocityImages_[2U];
121     BASE_NS::Math::UVec2 tileImageSize_ { 0U, 0U };
122 
123     RenderAreaRequest renderAreaRequest_;
124     bool useRequestedRenderArea_ { false };
125 
126     CORE_NS::PropertyApiImpl<NodeInputs> inputProperties_;
127     CORE_NS::PropertyApiImpl<NodeOutputs> outputProperties_;
128 
129     bool valid_ { false };
130 
131     EffectProperties effectProperties_;
132 };
133 RENDER_END_NAMESPACE()
134 
135 #endif // RENDER_POSTPROCESS_RENDER_POST_PROCESS_MOTION_BLUR_NODE_H
136