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_RENDER_POST_PROCESSES_GENERIC_H 17 #define RENDER_NODE_RENDER_NODE_RENDER_POST_PROCESSES_GENERIC_H 18 19 #include <base/containers/string.h> 20 #include <base/util/uid.h> 21 #include <render/datastore/intf_render_data_store_render_post_processes.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/nodecontext/intf_render_post_process_node.h> 27 #include <render/render_data_structures.h> 28 #include <render/resource_handle.h> 29 30 #include "nodecontext/render_node_copy_util.h" 31 32 RENDER_BEGIN_NAMESPACE() 33 class IGpuResourceManager; 34 class IRenderCommandList; 35 class IRenderNodeContextManager; 36 class IRenderNodeRenderDataStoreManager; 37 struct RenderNodeGraphInputs; 38 39 class RenderNodeRenderPostProcessesGeneric final : public IRenderNode { 40 public: 41 RenderNodeRenderPostProcessesGeneric() = default; 42 ~RenderNodeRenderPostProcessesGeneric() override = default; 43 44 void InitNode(IRenderNodeContextManager& renderNodeContextMgr) override; 45 void PreExecuteFrame() override; 46 void ExecuteFrame(IRenderCommandList& cmdList) override; 47 ExecuteFlags GetExecuteFlags() const override; 48 49 // for plugin / factory interface 50 static constexpr BASE_NS::Uid UID { "0e82f5f1-9122-40f2-bd5e-5e43728417ab" }; 51 static constexpr const char* TYPE_NAME = "RenderNodeRenderPostProcessesGeneric"; 52 static constexpr IRenderNode::BackendFlags BACKEND_FLAGS = IRenderNode::BackendFlagBits::BACKEND_FLAG_BITS_DEFAULT; 53 static constexpr IRenderNode::ClassType CLASS_TYPE = IRenderNode::ClassType::CLASS_TYPE_NODE; 54 static IRenderNode* Create(); 55 static void Destroy(IRenderNode* instance); 56 57 private: 58 IRenderNodeContextManager* renderNodeContextMgr_ { nullptr }; 59 60 void ParseRenderNodeInputs(); 61 void UpdateImageData(); 62 void ProcessPostProcessConfiguration(); 63 void RegisterOutputs(); 64 65 enum class DefaultInOutImage : uint32_t { 66 OUTPUT = 0, 67 INPUT_OUTPUT_COPY = 1, 68 INPUT = 2, 69 WHITE = 3, 70 BLACK = 4, 71 }; 72 // Json resources which might need re-fetching 73 struct JsonInputs { 74 RenderNodeGraphInputs::InputResources resources; 75 RenderNodeGraphInputs::RenderDataStore renderDataStore; 76 77 DefaultInOutImage defaultOutputImage { DefaultInOutImage::OUTPUT }; 78 DefaultInOutImage defaultInputImage { DefaultInOutImage::INPUT }; 79 80 uint32_t inputIdx { ~0u }; 81 uint32_t outputIdx { ~0u }; 82 }; 83 JsonInputs jsonInputs_; 84 85 struct BuiltInVariables { 86 RenderHandle input; 87 RenderHandle output; 88 89 RenderHandle defInput; 90 RenderHandle defOutput; 91 92 RenderHandle defBlackImage; 93 RenderHandle defWhiteImage; 94 RenderHandle defSampler; 95 }; 96 BuiltInVariables builtInVariables_; 97 98 RenderNodeHandles::InputResources inputResources_; 99 RenderNodeCopyUtil renderCopy_; 100 bool copyInitNeeded_ { true }; 101 102 struct PostProcessPipelineNode { 103 uint64_t id { ~0ULL }; 104 IRenderPostProcessNode::Ptr ppNode; 105 }; 106 struct AllPostProcesses { 107 // instanciated when there are new post processes set to the pipeline 108 BASE_NS::vector<PostProcessPipelineNode> postProcessNodeInstances; 109 // all post processes, fetched every frame 110 IRenderDataStoreRenderPostProcesses::PostProcessPipeline pipeline; 111 112 // keep track for new post processes 113 bool newPostProcesses { false }; 114 uint32_t postProcessCount { 0U }; 115 }; 116 AllPostProcesses allPostProcesses_; 117 bool valid_ { false }; 118 }; 119 RENDER_END_NAMESPACE() 120 121 #endif // RENDER_NODE_RENDER_NODE_RENDER_POST_PROCESSES_GENERIC_H 122