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_RENDER_POST_PROCESS_RENDER_POST_PROCESS_BLUR_NODE_H 17 #define RENDER_RENDER_POST_PROCESS_RENDER_POST_PROCESS_BLUR_NODE_H 18 19 #include <base/containers/unique_ptr.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_render_node.h> 32 #include <render/nodecontext/intf_render_post_process.h> 33 #include <render/nodecontext/intf_render_post_process_node.h> 34 #include <render/property/property_types.h> 35 #include <render/render_data_structures.h> 36 #include <render/shaders/common/render_blur_common.h> 37 38 RENDER_BEGIN_NAMESPACE() 39 class IRenderCommandList; 40 41 class RenderPostProcessBlurNode final : public CORE_NS::IInterfaceHelper<IRenderPostProcessNode> { 42 public: 43 static constexpr auto UID = BASE_NS::Uid("65ec929c-c38c-4d4e-b0a0-62fffb55d338"); 44 45 using Ptr = BASE_NS::refcnt_ptr<RenderPostProcessBlurNode>; 46 47 // needs to match the shader 48 enum BlurShaderType { 49 BLUR_SHADER_TYPE_RGBA = 0, 50 BLUR_SHADER_TYPE_R = 1, 51 BLUR_SHADER_TYPE_RG = 2, 52 BLUR_SHADER_TYPE_RGB = 3, 53 BLUR_SHADER_TYPE_A = 4, 54 BLUR_SHADER_TYPE_SOFT_DOWNSCALE_RGB = 5, 55 BLUR_SHADER_TYPE_DOWNSCALE_RGBA = 6, 56 BLUR_SHADER_TYPE_DOWNSCALE_RGBA_ALPHA_WEIGHT = 7, 57 BLUR_SHADER_TYPE_RGBA_ALPHA_WEIGHT = 8, 58 }; 59 struct EffectProperties { 60 bool enabled { false }; 61 BlurConfiguration blurConfiguration; 62 uint32_t blurShaderType { BlurShaderType::BLUR_SHADER_TYPE_RGBA }; 63 uint32_t blurShaderScaleType { BlurShaderType::BLUR_SHADER_TYPE_DOWNSCALE_RGBA }; 64 }; 65 66 RenderPostProcessBlurNode(); 67 ~RenderPostProcessBlurNode() = default; 68 69 CORE_NS::IPropertyHandle* GetRenderInputProperties() override; 70 CORE_NS::IPropertyHandle* GetRenderOutputProperties() override; 71 DescriptorCounts GetRenderDescriptorCounts() const override; 72 void SetRenderAreaRequest(const RenderAreaRequest& renderAreaRequest) override; 73 74 IRenderNode::ExecuteFlags GetExecuteFlags() const override; 75 void Init(const IRenderPostProcess::Ptr& postProcess, IRenderNodeContextManager& renderNodeContextMgr) override; 76 void PreExecute() override; 77 void Execute(IRenderCommandList& cmdList) override; 78 79 struct NodeInputs { 80 BindableImage input; 81 }; 82 struct NodeOutputs { 83 BindableImage output; 84 }; 85 86 NodeInputs nodeInputsData; 87 NodeOutputs nodeOutputsData; 88 89 private: 90 IRenderNodeContextManager* renderNodeContextMgr_ { nullptr }; 91 IRenderPostProcess::Ptr postProcess_; 92 93 struct ImageData { 94 BASE_NS::Math::UVec2 size { 0U, 0U }; 95 uint32_t mipCount { 0U }; 96 RenderHandleReference handle; 97 RenderHandle rawHandle; 98 RenderHandleReference handleExt; 99 RenderHandle rawHandleExt; 100 }; 101 ImageData tmpImgTargets_; 102 ImageData inputImgData_; 103 104 void EvaluateTemporaryTargets(); 105 bool EvaluateInOut(); 106 void CheckDescriptorSetNeed(); 107 void RenderData(IRenderCommandList& cmdList, const RenderPass& renderPassBase); 108 void RenderGaussian(IRenderCommandList& cmdList, const RenderPass& renderPassBase); 109 void RenderDirectionalBlur(IRenderCommandList& cmdList, const RenderPass& renderPassBase); 110 111 struct PushConstantStruct { 112 BASE_NS::Math::Vec4 texSizeInvTexSize; 113 }; 114 115 RenderAreaRequest renderAreaRequest_; 116 bool useRequestedRenderArea_ { false }; 117 118 struct PipelineData { 119 IShaderManager::GraphicsShaderData gsd; 120 RenderHandle psoScale; 121 RenderHandle psoBlur; 122 }; 123 PipelineData pipelineData_; 124 125 CORE_NS::PropertyApiImpl<NodeInputs> inputProperties_; 126 CORE_NS::PropertyApiImpl<NodeOutputs> outputProperties_; 127 128 BindableImage defaultInput_; 129 130 DescriptorCounts descriptorCounts_; 131 bool valid_ { false }; 132 133 BASE_NS::vector<IDescriptorSetBinder::Ptr> binders_; 134 135 EffectProperties effectProperties_; 136 bool mipsBlur { true }; 137 }; 138 RENDER_END_NAMESPACE() 139 140 #endif // RENDER_RENDER_POST_PROCESS_RENDER_POST_PROCESS_BLUR_NODE_H 141