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_NODE_RENDER_NODE_SINGLE_POST_PROCESS_H 17 #define RENDER_NODE_RENDER_NODE_SINGLE_POST_PROCESS_H 18 19 #include <base/util/uid.h> 20 #include <render/datastore/intf_render_data_store_post_process.h> 21 #include <render/datastore/render_data_store_render_pods.h> 22 #include <render/device/pipeline_state_desc.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 #include "node/render_bloom.h" 30 #include "node/render_blur.h" 31 #include "nodecontext/render_node_copy_util.h" 32 #include "util/log.h" 33 34 RENDER_BEGIN_NAMESPACE() 35 class IGpuResourceManager; 36 class IRenderCommandList; 37 class IRenderNodeContextManager; 38 class IRenderNodeRenderDataStoreManager; 39 struct RenderNodeGraphInputs; 40 41 class RenderNodeSinglePostProcess final : public IRenderNode { 42 public: 43 RenderNodeSinglePostProcess() = default; 44 ~RenderNodeSinglePostProcess() override = default; 45 46 void InitNode(IRenderNodeContextManager& renderNodeContextMgr) override; 47 void PreExecuteFrame() override; 48 void ExecuteFrame(IRenderCommandList& cmdList) override; GetExecuteFlags()49 ExecuteFlags GetExecuteFlags() const override 50 { 51 return 0U; 52 } 53 54 // for plugin / factory interface 55 static constexpr BASE_NS::Uid UID { "f4495799-9db7-477f-9eaf-6fad26260304" }; 56 static constexpr const char* TYPE_NAME = "CORE_RN_SINGLE_POST_PROCESS"; 57 static constexpr IRenderNode::BackendFlags BACKEND_FLAGS = IRenderNode::BackendFlagBits::BACKEND_FLAG_BITS_DEFAULT; 58 static constexpr IRenderNode::ClassType CLASS_TYPE = IRenderNode::ClassType::CLASS_TYPE_NODE; 59 static IRenderNode* Create(); 60 static void Destroy(IRenderNode* instance); 61 62 private: 63 IRenderNodeContextManager* renderNodeContextMgr_ { nullptr }; 64 65 void ParseRenderNodeInputs(); 66 void InitCreateBinders(); 67 void UpdateGlobalPostProcessUbo(); 68 void UpdateImageData(); 69 void ProcessPostProcessConfiguration(); 70 void RegisterOutputs(RenderHandle output); 71 void BindDefaultResources(uint32_t set, const DescriptorSetLayoutBindingResources& bindings); 72 void ExecuteSinglePostProcess(IRenderCommandList& cmdList); 73 74 enum class DefaultOutputImage : uint32_t { 75 OUTPUT = 0, 76 INPUT_OUTPUT_COPY = 1, 77 INPUT = 2, 78 WHITE = 3, 79 BLACK = 4, 80 }; 81 // Json resources which might need re-fetching 82 struct JsonInputs { 83 RenderNodeGraphInputs::InputRenderPass renderPass; 84 RenderNodeGraphInputs::InputResources resources; 85 RenderNodeGraphInputs::InputResources dispatchResources; 86 87 RenderNodeGraphInputs::RenderDataStore renderDataStore; 88 89 BASE_NS::string ppName; 90 DefaultOutputImage defaultOutputImage { DefaultOutputImage::OUTPUT }; 91 92 bool hasChangeableRenderPassHandles { false }; 93 bool hasChangeableResourceHandles { false }; 94 bool hasChangeableDispatchHandles { false }; 95 96 uint32_t inputIdx { ~0u }; 97 uint32_t outputIdx { ~0u }; 98 }; 99 JsonInputs jsonInputs_; 100 101 struct BuiltInVariables { 102 RenderHandle input; 103 104 RenderHandle output; 105 106 RenderHandle defBuffer; 107 RenderHandle defBlackImage; 108 RenderHandle defWhiteImage; 109 RenderHandle defSampler; 110 111 // the flag for the post built-in post process 112 uint32_t postProcessFlag { 0u }; 113 }; 114 BuiltInVariables builtInVariables_; 115 116 RenderNodeHandles::InputRenderPass inputRenderPass_; 117 RenderNodeHandles::InputResources inputResources_; 118 RenderNodeHandles::InputResources dispatchResources_; 119 RenderHandle shader_; 120 PipelineLayout pipelineLayout_; 121 RenderHandle psoHandle_; 122 PushConstant pushConstant_; 123 bool graphics_ { true }; 124 ShaderThreadGroup threadGroupSize_ { 1u, 1u, 1u }; 125 126 IPipelineDescriptorSetBinder::Ptr pipelineDescriptorSetBinder_; 127 IDescriptorSetBinder::Ptr copyBinder_; 128 129 RenderBloom renderBloom_; 130 RenderBlur renderBlur_; 131 RenderNodeCopyUtil renderCopy_; 132 133 PostProcessConfiguration ppGlobalConfig_; 134 IRenderDataStorePostProcess::PostProcess ppLocalConfig_; 135 136 struct UboHandles { 137 // first 512 aligned is global post process 138 // after (256) we have effect local data 139 RenderHandleReference postProcess; 140 141 uint32_t effectLocalDataIndex { 1u }; 142 }; 143 UboHandles ubos_; 144 145 bool useAutoBindSet0_ { false }; 146 bool valid_ { false }; 147 }; 148 RENDER_END_NAMESPACE() 149 150 #endif // RENDER_NODE_RENDER_NODE_SINGLE_POST_PROCESS_H 151