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_DOTFIELD_SIMULATION_H 17 #define RENDER_NODE_DOTFIELD_SIMULATION_H 18 19 #include <3d/render/intf_render_node_scene_util.h> 20 #include <base/containers/string.h> 21 #include <base/containers/string_view.h> 22 #include <base/containers/unordered_map.h> 23 #include <base/containers/vector.h> 24 #include <base/math/vector.h> 25 #include <base/util/uid.h> 26 #include <core/namespace.h> 27 #include <render/device/pipeline_layout_desc.h> 28 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h> 29 #include <render/nodecontext/intf_render_node.h> 30 #include <render/render_data_structures.h> 31 #include <render/resource_handle.h> 32 33 namespace RENDER_NS { 34 class IRenderCommandList; 35 class IRenderNodeContextManager; 36 class IPipelineDescriptorSetBinder; 37 } // namespace RENDER_NS 38 39 namespace Dotfield { 40 class RenderNodeDotfieldSimulation final : public RENDER_NS::IRenderNode { 41 public: 42 RenderNodeDotfieldSimulation() = default; 43 ~RenderNodeDotfieldSimulation() override = default; 44 45 void InitNode(RENDER_NS::IRenderNodeContextManager& renderNodeContextMgr) override; 46 void PreExecuteFrame() override; 47 void ExecuteFrame(RENDER_NS::IRenderCommandList& cmdList) override; GetExecuteFlags()48 ExecuteFlags GetExecuteFlags() const override 49 { 50 return 0U; 51 } 52 53 // for plugin / factory interface 54 static constexpr BASE_NS::Uid UID { "c82a51c3-1be3-4479-b867-bd92a2a9e98b" }; 55 static constexpr char const *TYPE_NAME = "RenderNodeDotfieldSimulation"; 56 static constexpr IRenderNode::BackendFlags BACKEND_FLAGS = IRenderNode::BackendFlagBits::BACKEND_FLAG_BITS_DEFAULT; 57 static constexpr IRenderNode::ClassType CLASS_TYPE = IRenderNode::ClassType::CLASS_TYPE_NODE; 58 static IRenderNode* Create(); 59 static void Destroy(IRenderNode* instance); 60 61 struct Binders { 62 struct SimulateBinders { 63 RENDER_NS::IDescriptorSetBinder::Ptr argsBuffersSet0; 64 BASE_NS::vector<RENDER_NS::IDescriptorSetBinder::Ptr> prevBuffersSet1; 65 BASE_NS::vector<RENDER_NS::IDescriptorSetBinder::Ptr> currBuffersSet2; 66 RENDER_NS::PipelineLayout pl; 67 }; 68 SimulateBinders simulate; 69 }; 70 71 private: 72 RENDER_NS::IRenderNodeContextManager* renderNodeContextMgr_ { nullptr }; 73 CORE3D_NS::SceneRenderDataStores stores_; 74 75 struct PsoData { 76 RENDER_NS::RenderHandle psoHandle; 77 RENDER_NS::PushConstant pushConstant; 78 }; 79 80 void ComputeSimulate( 81 RENDER_NS::IRenderNodeContextManager& renderNodeContextMgr, RENDER_NS::IRenderCommandList& cmdList); 82 83 PsoData GetPsoData(RENDER_NS::IRenderNodeContextManager& renderNodeContextMgr, const RENDER_NS::PipelineLayout& pl, 84 const RENDER_NS::RenderHandle& shaderHandle, bool firstFrame); 85 86 BASE_NS::unordered_map<uint32_t, PsoData> specializationToPsoData_; 87 Binders binders_; 88 RENDER_NS::RenderHandle shaderHandle_; 89 bool firstFrame_ { true }; 90 }; 91 } // namespace Dotfield 92 93 #endif // RENDER_NODE_DOTFIELD_SIMULATION_H 94