Blender V5.3
vk_render_graph_node.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
8
9#pragma once
10
27#include "nodes/vk_draw_node.hh"
35
37
42
50template<typename T, int BlockSize = 1024> struct VKNodeStorage {
53
54 T &alloc(int64_t &r_index)
55 {
56 if (next >= data.size()) {
57 data.resize(data.size() + BlockSize);
58 }
59 int64_t index = next++;
60 r_index = index;
61 return data[index];
62 }
63
64 void reset()
65 {
66 next = 0;
67 }
68
70 {
71 return data[index];
72 }
73
74 const T &operator[](int64_t index) const
75 {
76 return data[index];
77 }
78
79 int64_t size() const
80 {
81 return next;
82 }
83
85 {
86 return data.capacity();
87 }
88};
89
128
154
161
170 template<typename NodeInfo>
172 const typename NodeInfo::CreateInfo &create_info)
173 {
175 /* Instance of NodeInfo is needed to call virtual methods. CPP doesn't support overloading of
176 * static methods. */
177 NodeInfo node_info;
178 type = NodeInfo::node_type;
179 node_info.set_node_data(*this, storage, create_info);
180 }
181
187 template<typename NodeInfo>
190 const typename NodeInfo::CreateInfo &create_info)
191 {
192 /* Instance of NodeInfo is needed to call virtual methods. CPP doesn't support overloading of
193 * static methods. */
194 NodeInfo node_info;
195 int64_t buffer_index_start = links.buffers.size();
196 int64_t image_index_start = links.images.size();
197 node_info.build_links(resources, links, create_info);
198 this->links.buffers = IndexRange::from_begin_end(buffer_index_start, links.buffers.size());
199 this->links.images = IndexRange::from_begin_end(image_index_start, links.images.size());
200 }
201
211 template<typename NodeInfo>
213 {
215 type = NodeInfo::node_type;
216 return NodeInfo::alloc_node_data(storage, storage_index);
217 }
218
225 template<typename NodeInfo>
227 VKResourceStateTracker &resources,
229 const typename NodeInfo::CreateInfo &create_info)
230 {
231 NodeInfo node_info;
232 int64_t buffer_index_start = links.buffers.size();
233 int64_t image_index_start = links.images.size();
234 node_info.build_links(
235 resources, links, create_info, NodeInfo::storage_data(storage, storage_index));
236 this->links.buffers = IndexRange::from_begin_end(buffer_index_start, links.buffers.size());
237 this->links.images = IndexRange::from_begin_end(image_index_start, links.images.size());
238 }
239
245 VkPipelineStageFlags pipeline_stage_get() const
246 {
247 switch (type) {
249 return VK_PIPELINE_STAGE_NONE;
282 case VKNodeType::DRAW:
298 }
300 return VK_PIPELINE_STAGE_NONE;
301 }
302
311 VKBoundPipelines &r_bound_pipelines)
312 {
313 switch (type) {
314 case VKNodeType::UNUSED: {
315 break;
316 }
317#define BUILD_COMMANDS_STORAGE(NODE_TYPE, NODE_CLASS, ATTRIBUTE_NAME) \
318 case NODE_TYPE: { \
319 NODE_CLASS node_info; \
320 node_info.build_commands(command_buffer, \
321 storage.ATTRIBUTE_NAME[storage_index], \
322 storage.push_constants, \
323 r_bound_pipelines); \
324 break; \
325 }
326
327#define BUILD_COMMANDS(NODE_TYPE, NODE_CLASS, ATTRIBUTE_NAME) \
328 case NODE_TYPE: { \
329 NODE_CLASS node_info; \
330 node_info.build_commands( \
331 command_buffer, ATTRIBUTE_NAME, storage.push_constants, r_bound_pipelines); \
332 break; \
333 }
334
339 build_acceleration_structure)
345 clear_depth_stencil_image)
367#undef BUILD_COMMANDS
368#undef BUILD_COMMANDS_STORAGE
369 }
370 }
371
376 {
377 switch (type) {
378
379#define FREE_DATA(NODE_TYPE, NODE_CLASS, ATTRIBUTE_NAME) \
380 case NODE_TYPE: { \
381 NODE_CLASS node_info; \
382 node_info.free_data(ATTRIBUTE_NAME); \
383 break; \
384 }
385
387
388#undef FREE_DATA
389
410 case VKNodeType::DRAW:
414 break;
415 }
416 }
417
424 void reset()
425 {
426 free_data();
428 storage_index = -1;
429 }
430};
431
433 "VKRenderGraphNode should be kept small. Consider moving data to the "
434 "VKRenderGraphStorage class.");
435
436} // namespace blender::gpu::render_graph
#define BLI_assert_unreachable()
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
#define storage(slot, qualifiers)
#define T
BLI_STATIC_ASSERT(sizeof(VKRenderGraphNode)<=104, "VKRenderGraphNode should be kept small. Consider moving data to the " "VKRenderGraphStorage class.")
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
NodeInfo::Data & alloc_node_data(VKRenderGraphStorage &storage)
struct blender::gpu::render_graph::VKRenderGraphNode::@257247171043172251003146323044156133205032067022 links
void finalize_node(VKRenderGraphStorage &storage, VKResourceStateTracker &resources, VKRenderGraphLinks &links, const typename NodeInfo::CreateInfo &create_info)
void build_links(VKResourceStateTracker &resources, VKRenderGraphLinks &links, const typename NodeInfo::CreateInfo &create_info)
void set_node_data(VKRenderGraphStorage &storage, const typename NodeInfo::CreateInfo &create_info)
void build_commands(VKCommandBufferInterface &command_buffer, VKRenderGraphStorage &storage, VKBoundPipelines &r_bound_pipelines)
Vector< VKClearAttachmentsNode::Data, 1024 > clear_attachments
Vector< VKBlitImageNode::Data, 1024 > blit_image
VKNodeStorage< VKDrawIndirectNode::Data > draw_indirect
Vector< VKCopyImageToBufferNode::Data, 1024 > copy_image_to_buffer
Vector< VKCopyBufferToImageNode::Data, 1024 > copy_buffer_to_image
VKNodeStorage< VKDrawIndexedIndirectNode::Data > draw_indexed_indirect
Vector< VKCopyImageNode::Data, 1024 > copy_image
Vector< VKBuildAccelerationStructureNode::Data, 1024 > build_acceleration_structure
VKNodeStorage< VKDrawIndexedNode::Data > draw_indexed
Vector< VKBeginRenderingNode::Data, 1024 > begin_rendering
#define BUILD_COMMANDS(NODE_TYPE, NODE_CLASS, ATTRIBUTE_NAME)
#define BUILD_COMMANDS_STORAGE(NODE_TYPE, NODE_CLASS, ATTRIBUTE_NAME)
#define FREE_DATA(NODE_TYPE, NODE_CLASS, ATTRIBUTE_NAME)