1 /*
2  * Copyright (c) 2024 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_MOTION_BLUR_H
17 #define RENDER_RENDER__NODE__RENDER_MOTION_BLUR_H
18 
19 #include <base/containers/string.h>
20 #include <base/containers/vector.h>
21 #include <base/math/vector.h>
22 #include <render/datastore/render_data_store_render_pods.h>
23 #include <render/namespace.h>
24 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h>
25 #include <render/nodecontext/intf_render_node.h>
26 #include <render/render_data_structures.h>
27 #include <render/resource_handle.h>
28 
29 RENDER_BEGIN_NAMESPACE()
30 class IRenderCommandList;
31 
32 class RenderMotionBlur final {
33 public:
34     RenderMotionBlur() = default;
35     ~RenderMotionBlur() = default;
36 
37     struct MotionBlurInfo {
38         RenderHandle input;
39         RenderHandle output;
40         RenderHandle velocity;
41         RenderHandle depth;
42         RenderHandle globalUbo;
43         uint32_t globalUboByteOffset { 0U };
44         BASE_NS::Math::UVec2 size { 0U, 0U };
45     };
46     void Init(IRenderNodeContextManager& renderNodeContextMgr, const MotionBlurInfo& blurInfo);
47     void PreExecute(IRenderNodeContextManager& renderNodeContextMgr, const MotionBlurInfo& blurInfo,
48         const PostProcessConfiguration& ppConfig);
49     void Execute(IRenderNodeContextManager& renderNodeContextMgr, IRenderCommandList& cmdList,
50         const MotionBlurInfo& blurInfo, const PostProcessConfiguration& ppConfig);
51 
52     DescriptorCounts GetDescriptorCounts() const;
53 
54 private:
55     void ExecuteTileVelocity(IRenderNodeContextManager& renderNodeContextMgr, IRenderCommandList& cmdList,
56         const MotionBlurInfo& blurInfo, const PostProcessConfiguration& ppConfig);
57     void UpdateDescriptorSet0(IRenderNodeContextManager& renderNodeContextMgr, IRenderCommandList& cmdList,
58         const MotionBlurInfo& blurInfo, const PostProcessConfiguration& ppConfig);
59     RenderHandle GetTileVelocityForMotionBlur() const;
60 
61     struct RenderDataHandles {
62         RenderHandle shader;
63         RenderHandle pso;
64         PipelineLayout pipelineLayout;
65     };
66     RenderDataHandles renderData_;
67     RenderDataHandles renderTileMaxData_;
68     struct RenderDataHandlesTileNeighborhood {
69         RenderHandle shader;
70         PipelineLayout pipelineLayout;
71         RenderHandle psoNeighborhood;
72         RenderHandle psoHorizontal;
73         RenderHandle psoVertical;
74         bool doublePass { true };
75     };
76     RenderDataHandlesTileNeighborhood renderTileNeighborData_;
77 
78     IDescriptorSetBinder::Ptr globalSet0_;
79     IDescriptorSetBinder::Ptr localSet1_;
80     IDescriptorSetBinder::Ptr localTileMaxSet1_;
81     IDescriptorSetBinder::Ptr localTileNeighborhoodSet1_[2U];
82     RenderHandle samplerHandle_;
83     RenderHandle samplerNearestHandle_;
84     MotionBlurInfo motionBlurInfo_;
85 
86     RenderHandleReference tileVelocityImages_[2U];
87     BASE_NS::Math::UVec2 tileImageSize_ { 0U, 0U };
88 };
89 RENDER_END_NAMESPACE()
90 
91 #endif // CORE__RENDER__NODE__RENDER_MOTION_BLUR_H
92