• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #include "render_node_context_manager.h"
17 
18 #include <cstdint>
19 
20 #include <render/intf_render_context.h>
21 #include <render/namespace.h>
22 #include <render/nodecontext/intf_node_context_descriptor_set_manager.h>
23 #include <render/nodecontext/intf_node_context_pso_manager.h>
24 #include <render/nodecontext/intf_render_node_context_manager.h>
25 
26 #include "datastore/render_data_store_manager.h"
27 #include "device/gpu_resource_manager.h"
28 #include "device/shader_manager.h"
29 #include "nodecontext/node_context_descriptor_set_manager.h"
30 #include "nodecontext/node_context_pso_manager.h"
31 #include "nodecontext/render_command_list.h"
32 #include "nodecontext/render_node_graph_share_manager.h"
33 #include "nodecontext/render_node_parser_util.h"
34 #include "nodecontext/render_node_util.h"
35 
36 using namespace BASE_NS;
37 
RENDER_BEGIN_NAMESPACE()38 RENDER_BEGIN_NAMESPACE()
39 RenderNodeContextManager::RenderNodeContextManager(const CreateInfo& createInfo)
40     : renderContext_(createInfo.renderContext), renderNodeGraphData_(createInfo.renderNodeGraphData),
41       renderNodeGraphInputs_(createInfo.renderNodeGraphInputs),
42       fullName_(renderNodeGraphData_.renderNodeGraphName + createInfo.name), nodeName_(createInfo.name),
43       nodeJson_(createInfo.nodeJson), renderNodeGpuResourceMgr_(createInfo.gpuResourceMgr),
44       renderNodeGraphShareDataMgr_(createInfo.renderNodeGraphShareDataMgr),
45       descriptorSetMgr_(createInfo.descriptorSetMgr), psoMgr_(createInfo.psoMgr), renderCommandList_(createInfo.cmdList)
46 {
47     IDevice& dev = createInfo.renderContext.GetDevice();
48     renderNodeShaderMgr_ = make_unique<RenderNodeShaderManager>((ShaderManager&)dev.GetShaderManager());
49     renderNodeRenderDataStoreMgr_ = make_unique<RenderNodeRenderDataStoreManager>(
50         (RenderDataStoreManager&)renderContext_.GetRenderDataStoreManager());
51     renderNodeUtil_ = make_unique<RenderNodeUtil>(*this);
52     renderNodeGraphShareMgr_ = make_unique<RenderNodeGraphShareManager>(renderNodeGraphShareDataMgr_);
53     renderNodeParserUtil_ = make_unique<RenderNodeParserUtil>(RenderNodeParserUtil::CreateInfo {});
54 
55     // there are only build-in render node context interfaces
56     contextInterfaces_.push_back({ RenderNodeContextManager::UID, this });
57     contextInterfaces_.push_back({ RenderCommandList::UID, &renderCommandList_ });
58     contextInterfaces_.push_back({ RenderNodeGraphShareManager::UID, renderNodeGraphShareMgr_.get() });
59     contextInterfaces_.push_back({ RenderNodeParserUtil::UID, renderNodeParserUtil_.get() });
60 }
61 
62 RenderNodeContextManager::~RenderNodeContextManager() = default;
63 
BeginFrame(const uint32_t renderNodeIdx,const PerFrameTimings & frameTimings)64 void RenderNodeContextManager::BeginFrame(const uint32_t renderNodeIdx, const PerFrameTimings& frameTimings)
65 {
66     if (renderNodeIdx_ == ~0u) {
67         renderNodeGraphShareMgr_->Init(renderNodeIdx, nodeName_);
68     }
69     renderNodeIdx_ = renderNodeIdx;
70     renderNodeGraphShareMgr_->BeginFrame(renderNodeIdx);
71     {
72         // automatic timings to render nodes
73         constexpr double uToMsDiv = 1000.0;
74         constexpr double uToSDiv = 1000000.0;
75         const float deltaTime = static_cast<float>(
76             static_cast<double>(frameTimings.deltaTimeUs) / uToMsDiv); // real delta time used for scene as well
77         const float totalTime = static_cast<float>(static_cast<double>(frameTimings.totalTimeUs) / uToSDiv);
78         const uint32_t frameIndex =
79             static_cast<uint32_t>((frameTimings.frameIndex % std::numeric_limits<uint32_t>::max()));
80         auto& timings = renderNodeGraphData_.renderingConfiguration.renderTimings;
81         timings = { deltaTime, deltaTime, totalTime, *reinterpret_cast<const float*>(&frameIndex) };
82     }
83 }
84 
GetRenderDataStoreManager() const85 const IRenderNodeRenderDataStoreManager& RenderNodeContextManager::GetRenderDataStoreManager() const
86 {
87     return *renderNodeRenderDataStoreMgr_;
88 }
89 
GetShaderManager() const90 const IRenderNodeShaderManager& RenderNodeContextManager::GetShaderManager() const
91 {
92     return *renderNodeShaderMgr_;
93 }
94 
GetGpuResourceManager()95 IRenderNodeGpuResourceManager& RenderNodeContextManager::GetGpuResourceManager()
96 {
97     return renderNodeGpuResourceMgr_;
98 }
99 
GetDescriptorSetManager()100 INodeContextDescriptorSetManager& RenderNodeContextManager::GetDescriptorSetManager()
101 {
102     return descriptorSetMgr_;
103 }
104 
GetPsoManager()105 INodeContextPsoManager& RenderNodeContextManager::GetPsoManager()
106 {
107     return psoMgr_;
108 }
109 
GetRenderNodeGraphShareManager()110 IRenderNodeGraphShareManager& RenderNodeContextManager::GetRenderNodeGraphShareManager()
111 {
112     return *renderNodeGraphShareMgr_;
113 }
114 
GetRenderNodeUtil() const115 const IRenderNodeUtil& RenderNodeContextManager::GetRenderNodeUtil() const
116 {
117     return *renderNodeUtil_;
118 }
119 
GetRenderNodeParserUtil() const120 const IRenderNodeParserUtil& RenderNodeContextManager::GetRenderNodeParserUtil() const
121 {
122     return *renderNodeParserUtil_;
123 }
124 
GetRenderNodeGraphData() const125 const RenderNodeGraphData& RenderNodeContextManager::GetRenderNodeGraphData() const
126 {
127     return renderNodeGraphData_;
128 }
129 
GetName() const130 string_view RenderNodeContextManager::GetName() const
131 {
132     return fullName_;
133 }
134 
GetNodeName() const135 string_view RenderNodeContextManager::GetNodeName() const
136 {
137     return nodeName_;
138 }
139 
GetNodeJson() const140 CORE_NS::json::value RenderNodeContextManager::GetNodeJson() const
141 {
142     return CORE_NS::json::parse(nodeJson_.data());
143 }
144 
GetRenderNodeGraphInputs() const145 const RenderNodeGraphInputs& RenderNodeContextManager::GetRenderNodeGraphInputs() const
146 {
147     return renderNodeGraphInputs_;
148 }
149 
GetRenderContext() const150 IRenderContext& RenderNodeContextManager::GetRenderContext() const
151 {
152     return renderContext_;
153 }
154 
GetInterface(const Uid & uid) const155 IRenderNodeInterface* RenderNodeContextManager::GetInterface(const Uid& uid) const
156 {
157     for (const auto& ref : contextInterfaces_) {
158         if (ref.uid == uid) {
159             return ref.contextInterface;
160         }
161     }
162     return nullptr;
163 }
164 RENDER_END_NAMESPACE()
165