1 /* 2 * Copyright (C) 2023 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__RENDER_NODE_GRAPH_NODE_STORE_H 17 #define RENDER_RENDER__RENDER_NODE_GRAPH_NODE_STORE_H 18 19 #include <base/containers/string.h> 20 #include <base/containers/string_view.h> 21 #include <base/containers/unique_ptr.h> 22 #include <base/containers/vector.h> 23 #include <render/namespace.h> 24 #include <render/nodecontext/intf_render_node.h> 25 #include <render/render_data_structures.h> 26 27 #include "nodecontext/node_context_descriptor_set_manager.h" 28 #include "nodecontext/node_context_pool_manager.h" 29 #include "nodecontext/node_context_pso_manager.h" 30 #include "nodecontext/render_barrier_list.h" 31 #include "nodecontext/render_command_list.h" 32 #include "nodecontext/render_node_context_manager.h" 33 #include "nodecontext/render_node_graph_share_manager.h" 34 #include "nodecontext/render_node_manager.h" 35 36 RENDER_BEGIN_NAMESPACE() 37 class IRenderBackendNode; 38 class RenderFrameSync; 39 class RenderNodeGpuResourceManager; 40 41 struct SubmitDependencies { 42 // should this command buffer signal when submitting 43 bool signalSemaphore { false }; 44 // valid command buffer indices for wait semaphores 45 uint32_t waitSemaphoreCount { 0u }; 46 // render node indices or actual render command context indices (depending on the use context) 47 uint32_t waitSemaphoreNodeIndices[PipelineStateConstants::MAX_RENDER_NODE_GPU_WAIT_SIGNALS] {}; 48 // wait for acquired swapchain image 49 bool waitForSwapchainAcquireSignal { false }; 50 }; 51 52 struct RenderCommandContext { 53 // if backend specific node code 54 IRenderBackendNode* renderBackendNode { nullptr }; 55 RenderCommandList* renderCommandList { nullptr }; 56 RenderBarrierList* renderBarrierList { nullptr }; 57 NodeContextPsoManager* nodeContextPsoMgr { nullptr }; 58 NodeContextDescriptorSetManager* nodeContextDescriptorSetMgr { nullptr }; 59 NodeContextPoolManager* contextPoolMgr { nullptr }; 60 61 bool multiRenderCommandListRenderPassDependancy { false }; 62 uint32_t multiRenderCommandListCount { 0 }; 63 64 uint32_t renderGraphRenderNodeIndex { ~0u }; 65 SubmitDependencies submitDepencies; 66 67 BASE_NS::string_view debugName; // full node name with RNG name + node name 68 }; 69 70 struct RenderCommandFrameData { 71 BASE_NS::vector<RenderCommandContext> renderCommandContexts; 72 RenderFrameSync* renderFrameSync { nullptr }; 73 }; 74 75 struct RenderNodeContextData { 76 struct CpuDependency { 77 BASE_NS::vector<RenderDataConstants::RenderDataFixedString> cpuDependencyWaitRenderNodes; 78 }; 79 80 CpuDependency cpuDependency; 81 SubmitDependencies submitInfo; 82 83 BASE_NS::unique_ptr<RenderCommandList> renderCommandList; 84 BASE_NS::unique_ptr<RenderBarrierList> renderBarrierList; 85 BASE_NS::unique_ptr<RenderNodeContextManager> renderNodeContextManager; 86 BASE_NS::unique_ptr<NodeContextPsoManager> nodeContextPsoMgr; 87 BASE_NS::unique_ptr<NodeContextDescriptorSetManager> nodeContextDescriptorSetMgr; 88 BASE_NS::unique_ptr<NodeContextPoolManager> contextPoolMgr; 89 90 // with dynamic render node graphs we need initilization data per render node 91 bool initialized { false }; 92 93 // optional render backend node pointer 94 IRenderBackendNode* renderBackendNode { nullptr }; 95 }; 96 97 struct RenderNodeGraphShareData { 98 // render node graph inputs/outputs which can be set through render node graph manager 99 static constexpr uint32_t MAX_RENDER_NODE_GRAPH_RES_COUNT { 4u }; 100 RenderHandle inputs[MAX_RENDER_NODE_GRAPH_RES_COUNT] { {}, {}, {}, {} }; 101 RenderHandle outputs[MAX_RENDER_NODE_GRAPH_RES_COUNT] { {}, {}, {}, {} }; 102 uint32_t inputCount { 0 }; 103 uint32_t outputCount { 0 }; 104 }; 105 106 /** 107 * RenderNodeGraphNodeStore. 108 * Store render nodes and related data per render node graph. 109 * NOTE: When running the render node graphs, the real global name used is render node graph name + render node name 110 */ 111 struct RenderNodeGraphNodeStore { 112 struct RenderNodeData { 113 BASE_NS::unique_ptr<IRenderNode, RenderNodeTypeInfo::DestroyRenderNodeFn> node; 114 RenderDataConstants::RenderDataFixedString typeName; 115 RenderDataConstants::RenderDataFixedString fullName; // rng name + node name 116 RenderDataConstants::RenderDataFixedString nodeName; // node name 117 // NOTE: should be cleared after first init if not dev-mode 118 BASE_NS::unique_ptr<RenderNodeGraphInputs> inputData; 119 BASE_NS::string nodeJson; 120 }; 121 BASE_NS::vector<RenderNodeData> renderNodeData; 122 BASE_NS::vector<RenderNodeContextData> renderNodeContextData; 123 // NOTE: used in backend and accessed in update 124 RenderNodeGraphShareData renderNodeGraphShareData; 125 126 // NOTE: If render nodes are heavily added/removed this is not optimal 127 // due to removing of the resources in the destructor of RNG mgr 128 BASE_NS::unique_ptr<RenderNodeGpuResourceManager> renderNodeGpuResourceMgr; 129 BASE_NS::unique_ptr<RenderNodeGraphShareDataManager> renderNodeGraphShareDataMgr; 130 131 bool initialized { false }; 132 bool dynamic { false }; 133 134 RenderDataConstants::RenderDataFixedString renderNodeGraphName; 135 RenderDataConstants::RenderDataFixedString renderNodeGraphDataStoreName; 136 RenderDataConstants::RenderDataFixedString renderNodeGraphUri; 137 }; 138 RENDER_END_NAMESPACE() 139 140 #endif // CORE__RENDER__RENDER_NODE_GRAPH_NODE_STORE_H 141