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_COMBINED_NODE_H 17 #define RENDER_POSTPROCESS_RENDER_POST_PROCESS_COMBINED_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_gpu_resource_manager.h> 35 #include <render/device/intf_shader_manager.h> 36 #include <render/namespace.h> 37 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h> 38 #include <render/nodecontext/intf_render_node.h> 39 #include <render/nodecontext/intf_render_node_post_process_util.h> 40 #include <render/nodecontext/intf_render_post_process.h> 41 #include <render/nodecontext/intf_render_post_process_node.h> 42 #include <render/render_data_structures.h> 43 44 RENDER_BEGIN_NAMESPACE() 45 class IRenderCommandList; 46 class IRenderNodeRenderDataStoreManager; 47 struct RenderNodeGraphInputs; 48 49 class RenderPostProcessCombinedNode final : public CORE_NS::IInterfaceHelper<IRenderPostProcessNode> { 50 public: 51 static constexpr auto UID = BASE_NS::Uid("e3ac92f0-ccb2-4573-9536-ac1f24d8e47b"); 52 53 using Ptr = BASE_NS::refcnt_ptr<RenderPostProcessCombinedNode>; 54 55 RenderPostProcessCombinedNode(); 56 ~RenderPostProcessCombinedNode() = default; 57 58 CORE_NS::IPropertyHandle* GetRenderInputProperties() override; 59 CORE_NS::IPropertyHandle* GetRenderOutputProperties() override; 60 DescriptorCounts GetRenderDescriptorCounts() const override; 61 void SetRenderAreaRequest(const RenderAreaRequest& renderAreaRequest) override; 62 IRenderNode::ExecuteFlags GetExecuteFlags() const override; 63 64 struct UboHandles { 65 // first 512 aligned is global post process 66 // after (256) we have effect local data 67 RenderHandleReference postProcess; 68 }; 69 70 struct EffectProperties { 71 bool enabled { false }; 72 bool glOptimizedLayerCopyEnabled { false }; 73 PostProcessConfiguration postProcessConfiguration; 74 }; 75 76 void Init(const IRenderPostProcess::Ptr& postProcess, IRenderNodeContextManager& renderNodeContextMgr) override; 77 void PreExecute() override; 78 void Execute(IRenderCommandList& cmdList) override; 79 80 // for plugin / factory interface 81 static constexpr const char* TYPE_NAME = "RenderPostProcessCombinedNode"; 82 83 struct NodeInputs { 84 BindableImage input; 85 BindableImage bloomFinalTarget; 86 BindableImage dirtMask; 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 RenderPass CreateRenderPass(const RenderHandle input); 100 void UpdatePostProcessData(const PostProcessConfiguration& postProcessConfiguration); 101 void CheckDescriptorSetNeed(); 102 103 struct EffectData { 104 IShaderManager::ShaderData sd; 105 RenderHandle pso; 106 }; 107 EffectData combineData_; 108 // additional optimized layer copy for GL(ES) 109 EffectData combineDataLayer_; 110 111 RenderHandle reservedUboHandle_; 112 IRenderNodeGpuResourceManager::MappedGpuBufferData acquiredGpuBufferData_; 113 struct Binders { 114 IDescriptorSetBinder::Ptr set0; 115 IDescriptorSetBinder::Ptr combineBinder; 116 IDescriptorSetBinder::Ptr combineLayerBinder; 117 }; 118 Binders binders_; 119 120 struct DefaultSamplers { 121 RenderHandle nearest; 122 RenderHandle linear; 123 }; 124 DefaultSamplers samplers_; 125 126 RenderAreaRequest renderAreaRequest_; 127 bool useRequestedRenderArea_ { false }; 128 129 CORE_NS::PropertyApiImpl<NodeInputs> inputProperties_; 130 CORE_NS::PropertyApiImpl<NodeOutputs> outputProperties_; 131 132 RENDER_NS::DescriptorCounts descriptorCounts_; 133 bool valid_ { false }; 134 135 EffectProperties effectProperties_; 136 }; 137 RENDER_END_NAMESPACE() 138 139 #endif // RENDER_POSTPROCESS_RENDER_POST_PROCESS_COMBINED_NODE_H 140