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