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_RENDER__NODE__RENDER_NODE_FULLSCREEN_SHADER_BINDER_GENERIC_H
17 #define RENDER_RENDER__NODE__RENDER_NODE_FULLSCREEN_SHADER_BINDER_GENERIC_H
18 
19 #include <base/util/uid.h>
20 #include <render/namespace.h>
21 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h>
22 #include <render/nodecontext/intf_render_node.h>
23 #include <render/render_data_structures.h>
24 #include <render/resource_handle.h>
25 
26 #include "datastore/render_data_store_shader_passes.h"
27 
28 RENDER_BEGIN_NAMESPACE()
29 class IRenderCommandList;
30 struct RenderNodeGraphInputs;
31 
32 class RenderNodeShaderPassesGeneric final : public IRenderNode {
33 public:
34     RenderNodeShaderPassesGeneric() = default;
35     ~RenderNodeShaderPassesGeneric() override = default;
36 
37     void InitNode(IRenderNodeContextManager& renderNodeContextMgr) override;
38     void PreExecuteFrame() override;
39     void ExecuteFrame(IRenderCommandList& cmdList) override;
GetExecuteFlags()40     ExecuteFlags GetExecuteFlags() const override
41     {
42         return 0U;
43     }
44 
45     // for plugin / factory interface
46     static constexpr BASE_NS::Uid UID { "2e258acc-caad-4035-9ab1-c6debca7f6fa" };
47     static constexpr char const* TYPE_NAME = "RenderNodeShaderPassesGeneric";
48     static constexpr IRenderNode::BackendFlags BACKEND_FLAGS = IRenderNode::BackendFlagBits::BACKEND_FLAG_BITS_DEFAULT;
49     static constexpr IRenderNode::ClassType CLASS_TYPE = IRenderNode::ClassType::CLASS_TYPE_NODE;
50     static IRenderNode* Create();
51     static void Destroy(IRenderNode* instance);
52 
53 private:
54     IRenderNodeContextManager* renderNodeContextMgr_ { nullptr };
55     const RenderDataStoreShaderPasses* dsShaderPasses_ { nullptr };
56 
57     void ProcessExecuteData();
58     void ExecuteFrameGraphics(IRenderCommandList& cmdList);
59     void ExecuteFrameCompute(IRenderCommandList& cmdList);
60 
61     void ParseRenderNodeInputs();
62     RenderHandle GetPsoHandleGraphics(
63         const RenderPass& renderPass, const RenderHandle& shader, const PipelineLayout& pipelineLayout);
64     RenderHandle GetPsoHandleCompute(const RenderHandle& shader, const PipelineLayout& pipelineLayout);
65     bool ValidRenderPass(const RenderPassWithHandleReference& renderPass);
66 
67     // returns buffer offset
68     uint32_t WriteLocalUboData(BASE_NS::array_view<const uint8_t> uboData);
69 
70     // Json resources which might need re-fetching
71     struct JsonInputs {
72         RenderNodeGraphInputs::RenderDataStore renderDataStore;
73     };
74     JsonInputs jsonInputs_;
75 
76     bool valid_ { false };
77     struct LocalUboData {
78         uint32_t byteSize { 0U };
79         RenderHandleReference handle;
80 
81         uint8_t* mapData { nullptr };
82         uint32_t currentOffset { 0U };
83     };
84     LocalUboData uboData_;
85 };
86 RENDER_END_NAMESPACE()
87 
88 #endif // CORE__RENDER__NODE__RENDER_NODE_FULLSCREEN_GENERIC_H