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 CORE__RENDER__NODE__RENDER_NODE_MORPH_H
17 #define CORE__RENDER__NODE__RENDER_NODE_MORPH_H
18 
19 #include <3d/render/intf_render_data_store_morph.h>
20 #include <base/containers/array_view.h>
21 #include <base/containers/unique_ptr.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/nodecontext/intf_pipeline_descriptor_set_binder.h>
27 #include <render/nodecontext/intf_render_node.h>
28 #include <render/render_data_structures.h>
29 #include <render/resource_handle.h>
30 
31 #include "render/render_node_scene_util.h"
32 
CORE3D_BEGIN_NAMESPACE()33 CORE3D_BEGIN_NAMESPACE()
34 class RenderNodeMorph final : public RENDER_NS::IRenderNode {
35 public:
36     RenderNodeMorph() = default;
37     ~RenderNodeMorph() override = default;
38 
39     void InitNode(RENDER_NS::IRenderNodeContextManager& renderNodeContextMgr) override;
40     void PreExecuteFrame() override;
41     void ExecuteFrame(RENDER_NS::IRenderCommandList& cmdList) override;
42     ExecuteFlags GetExecuteFlags() const override;
43 
44     // for plugin / factory interface
45     static constexpr BASE_NS::Uid UID { "8e5bd3ad-f95b-4c47-9cf2-a9d908aa7c72" };
46     static constexpr char const* const TYPE_NAME = "RenderNodeMorph";
47     static constexpr IRenderNode::BackendFlags BACKEND_FLAGS = IRenderNode::BackendFlagBits::BACKEND_FLAG_BITS_DEFAULT;
48     static constexpr IRenderNode::ClassType CLASS_TYPE = IRenderNode::ClassType::CLASS_TYPE_NODE;
49     static IRenderNode* Create();
50     static void Destroy(IRenderNode* instance);
51 
52 private:
53     void UpdateWeightsAndTargets(BASE_NS::array_view<const RenderDataMorph::Submesh> submeshes);
54     void ComputeMorphs(
55         RENDER_NS::IRenderCommandList& cmdList, BASE_NS::array_view<const RenderDataMorph::Submesh> submeshes);
56 
57     RENDER_NS::IRenderNodeContextManager* renderNodeContextMgr_ { nullptr };
58 
59     SceneRenderDataStores stores_;
60 
61     uint32_t maxObjectCount_ { 0 };
62     uint32_t maxStructCount_ { 0 };
63     uint32_t bufferSize_ { 0 };
64     RENDER_NS::RenderHandleReference morphTargetBufferHandle_;
65 
66     RENDER_NS::RenderHandle psoHandle_;
67 
68     RENDER_NS::PipelineLayout pipelineLayout_;
69     RENDER_NS::ShaderThreadGroup threadGroupSize_ { 1u, 1u, 1u };
70 
71     struct AllDescriptorSets {
72         RENDER_NS::IDescriptorSetBinder::Ptr params;
73         BASE_NS::vector<RENDER_NS::IDescriptorSetBinder::Ptr> inputs;
74         BASE_NS::vector<RENDER_NS::IDescriptorSetBinder::Ptr> outputs;
75     };
76     AllDescriptorSets allDescriptorSets_;
77 
78     bool hasExecuteData_ { false };
79 };
80 CORE3D_END_NAMESPACE()
81 
82 #endif // CORE__RENDER__NODE__RENDER_NODE_MORPH_H
83