• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "render_node_generics.h"
16 
17 #include <core/image/intf_image_loader_manager.h>
18 #include <core/intf_engine.h>
19 #include <core/log.h>
20 #include <render/device/intf_gpu_resource_manager.h>
21 #include <render/device/intf_shader_manager.h>
22 #include <render/intf_render_context.h>
23 #include <render/nodecontext/intf_node_context_pso_manager.h>
24 #include <render/nodecontext/intf_render_command_list.h>
25 #include <render/nodecontext/intf_render_node_context_manager.h>
26 #include <render/nodecontext/intf_render_node_graph_share_manager.h>
27 #include <render/nodecontext/intf_render_node_parser_util.h>
28 #include <render/nodecontext/intf_render_node_util.h>
29 
30 using namespace RENDER_NS;
31 using namespace CORE_NS;
32 
Load(const BASE_NS::string_view shader,BASE_NS::vector<DescriptorCounts> & counts,ComputeShaderData & debugShaderData,size_t reserved)33 void RenderNodeMixin::Load(const BASE_NS::string_view shader, BASE_NS::vector<DescriptorCounts>& counts,
34     ComputeShaderData& debugShaderData, size_t reserved)
35 {
36     RENDER_NS::IRenderNodeContextManager* renderNodeContextMgr_ = *this;
37     if (!renderNodeContextMgr_) {
38         CORE_LOG_E("null RenderNodeContextManager");
39         return;
40     }
41     auto& utils = renderNodeContextMgr_->GetRenderNodeUtil();
42 
43     auto& shaderMgr = renderNodeContextMgr_->GetShaderManager();
44     const IShaderManager::ShaderData sd = shaderMgr.GetShaderDataByShaderName(shader);
45     debugShaderData.shader = sd.shader;
46     debugShaderData.pipelineLayout = sd.pipelineLayout;
47     debugShaderData.pipelineLayoutData = sd.pipelineLayoutData;
48     debugShaderData.threadGroupSize = shaderMgr.GetReflectionThreadGroupSize(debugShaderData.shader);
49 
50     debugShaderData.pso = renderNodeContextMgr_->GetPsoManager().GetComputePsoHandle(
51         debugShaderData.shader, debugShaderData.pipelineLayout, {});
52 
53     for (size_t i = 0; i < reserved; ++i)
54         counts.push_back(utils.GetDescriptorCounts(debugShaderData.pipelineLayoutData));
55 }
56 
Load(const BASE_NS::string_view shader,BASE_NS::vector<DescriptorCounts> & counts,GraphicsShaderData & debugShaderData,Base::array_view<const DynamicStateEnum> dynstates,size_t reserved)57 void RenderNodeMixin::Load(const BASE_NS::string_view shader, BASE_NS::vector<DescriptorCounts>& counts,
58     GraphicsShaderData& debugShaderData, Base::array_view<const DynamicStateEnum> dynstates, size_t reserved)
59 {
60     RENDER_NS::IRenderNodeContextManager* renderNodeContextMgr_ = *this;
61     if (!renderNodeContextMgr_) {
62         CORE_LOG_E("null RenderNodeContextManager");
63         return;
64     }
65     auto& utils = renderNodeContextMgr_->GetRenderNodeUtil();
66 
67     auto& shaderMgr = renderNodeContextMgr_->GetShaderManager();
68 
69     const IShaderManager::GraphicsShaderData sd =
70         shaderMgr.GetGraphicsShaderDataByShaderHandle(shaderMgr.GetShaderHandle(shader));
71 
72     debugShaderData.shader = sd.shader;
73     debugShaderData.pipelineLayout = sd.pipelineLayout;
74     debugShaderData.graphicsState = sd.graphicsState;
75     debugShaderData.pipelineLayoutData = sd.pipelineLayoutData;
76 
77     debugShaderData.pso = renderNodeContextMgr_->GetPsoManager().GetGraphicsPsoHandle(
78         debugShaderData.shader, debugShaderData.graphicsState, debugShaderData.pipelineLayout, {}, {}, dynstates);
79 
80     for (size_t i = 0; i < reserved; ++i) {
81         counts.push_back(utils.GetDescriptorCounts(debugShaderData.pipelineLayoutData));
82     }
83 }
84 
CreateRenderPass(const RenderHandle input)85 RenderPass RenderNodeMixin::CreateRenderPass(const RenderHandle input)
86 {
87     RENDER_NS::IRenderNodeContextManager* renderNodeContextMgr_ = *this;
88     if (!renderNodeContextMgr_) {
89         CORE_LOG_E("null RenderNodeContextManager");
90         return {};
91     }
92     const GpuImageDesc desc = renderNodeContextMgr_->GetGpuResourceManager().GetImageDescriptor(input);
93     RenderPass rp;
94     rp.renderPassDesc.attachmentCount = 1u;
95     rp.renderPassDesc.attachmentHandles[0u] = input;
96     rp.renderPassDesc.attachments[0u].loadOp = AttachmentLoadOp::CORE_ATTACHMENT_LOAD_OP_CLEAR;
97     rp.renderPassDesc.attachments[0u].clearValue.color = { 1.0f, 1.0f, 1.0f, 1.0f };
98     rp.renderPassDesc.attachments[0u].storeOp = AttachmentStoreOp::CORE_ATTACHMENT_STORE_OP_STORE;
99     rp.renderPassDesc.renderArea = { 0, 0, desc.width, desc.height };
100 
101     rp.renderPassDesc.subpassCount = 1u;
102     rp.subpassDesc.colorAttachmentCount = 1u;
103     rp.subpassDesc.colorAttachmentIndices[0u] = 0u;
104     rp.subpassStartIndex = 0u;
105 
106     return rp;
107 }
108 
RecreateImages(RenderSize size,RENDER_NS::RenderHandleReference & handle)109 void RenderNodeMixin::RecreateImages(RenderSize size, RENDER_NS::RenderHandleReference& handle)
110 {
111     if (size.w == 0 || size.h == 0) {
112         return;
113     }
114 
115     RENDER_NS::IRenderNodeContextManager* renderNodeContextMgr_ = *this;
116     if (!renderNodeContextMgr_) {
117         CORE_LOG_E("null RenderNodeContextManager");
118         return;
119     }
120     auto& gpuResourceManager = renderNodeContextMgr_->GetGpuResourceManager();
121     auto desc = gpuResourceManager.GetImageDescriptor(handle.GetHandle());
122     desc.width = uint32_t(size.w);
123     desc.height = uint32_t(size.h);
124     handle = gpuResourceManager.Create(handle, desc);
125     CORE_ASSERT(gpuResourceManager.IsValid(handle.GetHandle()));
126 }
127 
RecreateImages(RenderSize size,RENDER_NS::RenderHandleReference & handle,RENDER_NS::GpuImageDesc desc)128 void RenderNodeMixin::RecreateImages(
129     RenderSize size, RENDER_NS::RenderHandleReference& handle, RENDER_NS::GpuImageDesc desc)
130 {
131     if (size.w == 0 || size.h == 0) {
132         return;
133     }
134 
135     RENDER_NS::IRenderNodeContextManager* renderNodeContextMgr_ = *this;
136     if (!renderNodeContextMgr_) {
137         CORE_LOG_E("null RenderNodeContextManager");
138         return;
139     }
140     auto& gpuResourceManager = renderNodeContextMgr_->GetGpuResourceManager();
141     auto descCurr = gpuResourceManager.GetImageDescriptor(handle.GetHandle());
142 
143     if (int(descCurr.width) != size.w || int(descCurr.height) != size.h) {
144         desc.width = uint32_t(size.w);
145         desc.height = uint32_t(size.h);
146         handle = gpuResourceManager.Create(handle, desc);
147         CORE_ASSERT(gpuResourceManager.IsValid(handle.GetHandle()));
148     }
149 }
150