Blender V4.5
vk_render_graph.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
37
38#pragma once
39
40#include <mutex>
41#include <optional>
42#include <pthread.h>
43
44#include "BKE_global.hh"
45
46#include "BLI_color.hh"
47#include "BLI_map.hh"
48#include "BLI_utility_mixins.hh"
49#include "BLI_vector.hh"
50#include "BLI_vector_set.hh"
51
52#include "BKE_global.hh"
53
54#include "vk_common.hh"
55
57#include "vk_command_builder.hh"
61
63class VKScheduler;
64
65class VKRenderGraph : public NonCopyable {
66 friend class VKCommandBuilder;
67 friend class VKScheduler;
68 using DebugGroupNameID = int64_t;
69 using DebugGroupID = int64_t;
70
76 VKRenderGraphStorage storage_;
77
86 VKResourceStateTracker &resources_;
87
88 struct DebugGroup {
89 std::string name;
91
92 BLI_STRUCT_EQUALITY_OPERATORS_2(DebugGroup, name, color)
93 uint64_t hash() const
94 {
96 }
97 };
98
99 struct {
101
104
109 bool group_used = false;
110
113
123 } debug_;
124
125 public:
127
135
136 private:
140 template<typename NodeInfo> void add_node(const typename NodeInfo::CreateInfo &create_info)
141 {
142 std::scoped_lock lock(resources_.mutex);
143 static VKRenderGraphNode node_template = {};
144 NodeHandle node_handle = nodes_.append_and_get_index(node_template);
145#if 0
146 /* Useful during debugging. When a validation error occurs during submission we know the node
147 * type and node handle, but we don't know when and by who that specific node was added to the
148 * render graph. By enabling this part of the code and set the correct node_handle and node
149 * type a debugger can break at the moment the node has been added to the render graph. */
150 if (node_handle == 267 && NodeInfo::node_type == VKNodeType::DRAW) {
151 std::cout << "break\n";
152 }
153#endif
154 if (nodes_.size() > links_.size()) {
155 links_.resize(nodes_.size());
156 }
157 VKRenderGraphNode &node = nodes_[node_handle];
158 node.set_node_data<NodeInfo>(storage_, create_info);
159
160 VKRenderGraphNodeLinks &node_links = links_[node_handle];
161 BLI_assert(node_links.inputs.is_empty());
162 BLI_assert(node_links.outputs.is_empty());
163 node.build_links<NodeInfo>(resources_, node_links, create_info);
164
165 if (G.debug & G_DEBUG_GPU) {
166 if (!debug_.group_used) {
167 debug_.group_used = true;
168 debug_.used_groups.append(debug_.group_stack);
169 }
170 if (nodes_.size() > debug_.node_group_map.size()) {
171 debug_.node_group_map.resize(nodes_.size());
172 }
173 debug_.node_group_map[node_handle] = debug_.used_groups.size() - 1;
174 }
175 }
176
177 public:
178#define ADD_NODE(NODE_CLASS) \
179 void add_node(const NODE_CLASS::CreateInfo &create_info) \
180 { \
181 add_node<NODE_CLASS>(create_info); \
182 }
183 ADD_NODE(VKBeginQueryNode)
184 ADD_NODE(VKBeginRenderingNode)
185 ADD_NODE(VKEndQueryNode)
186 ADD_NODE(VKEndRenderingNode)
187 ADD_NODE(VKClearAttachmentsNode)
188 ADD_NODE(VKClearColorImageNode)
189 ADD_NODE(VKClearDepthStencilImageNode)
190 ADD_NODE(VKFillBufferNode)
191 ADD_NODE(VKCopyBufferNode)
192 ADD_NODE(VKCopyBufferToImageNode)
193 ADD_NODE(VKCopyImageNode)
194 ADD_NODE(VKCopyImageToBufferNode)
195 ADD_NODE(VKBlitImageNode)
196 ADD_NODE(VKDispatchNode)
197 ADD_NODE(VKDispatchIndirectNode)
198 ADD_NODE(VKDrawNode)
199 ADD_NODE(VKDrawIndexedNode)
200 ADD_NODE(VKDrawIndexedIndirectNode)
201 ADD_NODE(VKDrawIndirectNode)
202 ADD_NODE(VKResetQueryPoolNode)
203 ADD_NODE(VKUpdateBufferNode)
204 ADD_NODE(VKUpdateMipmapsNode)
205 ADD_NODE(VKSynchronizationNode)
206#undef ADD_NODE
207
213 void debug_group_begin(const char *name, const ColorTheme4f &color);
214
221 void debug_group_end();
222
227 std::string full_debug_group(NodeHandle node_handle) const;
228
237 {
238 return nodes_.size();
239 }
240
241 bool is_empty()
242 {
243 return nodes_.is_empty();
244 }
245
246 void debug_print(NodeHandle node_handle) const;
247
251 void reset();
252
253 void memstats() const;
254
255 private:
256};
257
258} // namespace blender::gpu::render_graph
@ G_DEBUG_GPU
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_STRUCT_EQUALITY_OPERATORS_2(Type, m1, m2)
volatile int lock
long long int int64_t
unsigned long long int uint64_t
NonCopyable(const NonCopyable &other)=delete
int64_t size() const
int64_t append_and_get_index(const T &value)
void resize(const int64_t new_size)
VKRenderGraph(VKResourceStateTracker &resources)
void debug_group_begin(const char *name, const ColorTheme4f &color)
Vector< Vector< DebugGroupNameID > > used_groups
void debug_print(NodeHandle node_handle) const
std::string full_debug_group(NodeHandle node_handle) const
#define G(x, y, z)
uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:233
ColorTheme4< float > ColorTheme4f
Definition BLI_color.hh:292
#define hash
Definition noise_c.cc:154
#define ADD_NODE(NODE_CLASS)