Blender V4.3
vk_begin_rendering_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
9#pragma once
10
12#include "vk_node_info.hh"
13
15
20 VkRenderingAttachmentInfo color_attachments[8];
21 VkRenderingAttachmentInfo depth_attachment;
22 VkRenderingAttachmentInfo stencil_attachment;
23 VkRenderingInfoKHR vk_rendering_info;
24};
25
31
39class VKBeginRenderingNode : public VKNodeInfo<VKNodeType::BEGIN_RENDERING,
40 VKBeginRenderingCreateInfo,
41 VKBeginRenderingData,
42 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
43 VKResourceType::IMAGE> {
44 public:
52 template<typename Node> void set_node_data(Node &node, const CreateInfo &create_info)
53 {
54 BLI_assert_msg(ELEM(create_info.node_data.vk_rendering_info.pColorAttachments,
55 nullptr,
56 create_info.node_data.color_attachments),
57 "When create_info.node_data.vk_rendering_info.pColorAttachments points to "
58 "something, it should point to create_info.node_data.color_attachments.");
59 BLI_assert_msg(ELEM(create_info.node_data.vk_rendering_info.pDepthAttachment,
60 nullptr,
61 &create_info.node_data.depth_attachment),
62 "When create_info.node_data.vk_rendering_info.pDepthAttachment points to "
63 "something, it should point to create_info.node_data.depth_attachment.");
64 BLI_assert_msg(ELEM(create_info.node_data.vk_rendering_info.pStencilAttachment,
65 nullptr,
66 &create_info.node_data.stencil_attachment),
67 "When create_info.node_data.vk_rendering_info.pStencilAttachment points to "
68 "something, it should point to create_info.node_data.stencil_attachment.");
69 node.begin_rendering = create_info.node_data;
70 /* NOTE: pointers in vk_rendering_info will be set to the correct location just before sending
71 * to the command buffer. In the meantime these pointers are invalid.
72 * VKRenderingAttachmentInfo's should be used instead.*/
73 }
74
79 VKRenderGraphNodeLinks &node_links,
80 const CreateInfo &create_info) override
81 {
82 create_info.resources.build_links(resources, node_links);
83 }
84
89 Data &data,
90 VKBoundPipelines & /*r_bound_pipelines*/) override
91 {
92 /* Localize pointers just before sending to the command buffer. Pointer can (and will) change
93 * as they are stored in a union which is stored in a vector. When the vector reallocates, the
94 * pointers will become invalid. */
95 if (data.vk_rendering_info.pColorAttachments) {
96 data.vk_rendering_info.pColorAttachments = data.color_attachments;
97 }
98 if (data.vk_rendering_info.pDepthAttachment) {
99 data.vk_rendering_info.pDepthAttachment = &data.depth_attachment;
100 }
101 if (data.vk_rendering_info.pStencilAttachment) {
102 data.vk_rendering_info.pStencilAttachment = &data.stencil_attachment;
103 }
104 command_buffer.begin_rendering(&data.vk_rendering_info);
105 }
106};
107} // namespace blender::gpu::render_graph
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
#define ELEM(...)
void build_links(VKResourceStateTracker &resources, VKRenderGraphNodeLinks &node_links, const CreateInfo &create_info) override
void build_commands(VKCommandBufferInterface &command_buffer, Data &data, VKBoundPipelines &) override
void set_node_data(Node &node, const CreateInfo &create_info)
virtual void begin_rendering(const VkRenderingInfo *p_rendering_info)=0
VKBeginRenderingCreateInfo(const VKResourceAccessInfo &resources)
void build_links(VKResourceStateTracker &resources, VKRenderGraphNodeLinks &node_links) const