Blender V5.0
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
8
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, typename Storage>
53 void set_node_data(Node &node, Storage &storage, const CreateInfo &create_info)
54 {
55 BLI_assert_msg(ELEM(create_info.node_data.vk_rendering_info.pColorAttachments,
56 nullptr,
57 create_info.node_data.color_attachments),
58 "When create_info.node_data.vk_rendering_info.pColorAttachments points to "
59 "something, it should point to create_info.node_data.color_attachments.");
60 BLI_assert_msg(ELEM(create_info.node_data.vk_rendering_info.pDepthAttachment,
61 nullptr,
62 &create_info.node_data.depth_attachment),
63 "When create_info.node_data.vk_rendering_info.pDepthAttachment points to "
64 "something, it should point to create_info.node_data.depth_attachment.");
65 BLI_assert_msg(ELEM(create_info.node_data.vk_rendering_info.pStencilAttachment,
66 nullptr,
67 &create_info.node_data.stencil_attachment),
68 "When create_info.node_data.vk_rendering_info.pStencilAttachment points to "
69 "something, it should point to create_info.node_data.stencil_attachment.");
70 node.storage_index = storage.begin_rendering.append_and_get_index(create_info.node_data);
71 /* NOTE: pointers in vk_rendering_info will be set to the correct location just before sending
72 * to the command buffer. In the meantime these pointers are invalid.
73 * VKRenderingAttachmentInfo's should be used instead. */
74 }
75
80 VKRenderGraphNodeLinks &node_links,
81 const CreateInfo &create_info) override
82 {
83 create_info.resources.build_links(resources, node_links);
84 }
85
90 Data &data,
91 VKBoundPipelines & /*r_bound_pipelines*/) override
92 {
93 /* Localize pointers just before sending to the command buffer. Pointer can (and will) change
94 * as they are stored in a union which is stored in a vector. When the vector reallocates,
95 * the pointers will become invalid. */
96 if (data.vk_rendering_info.pColorAttachments) {
97 data.vk_rendering_info.pColorAttachments = data.color_attachments;
98 }
99 if (data.vk_rendering_info.pDepthAttachment) {
100 data.vk_rendering_info.pDepthAttachment = &data.depth_attachment;
101 }
102 if (data.vk_rendering_info.pStencilAttachment) {
103 data.vk_rendering_info.pStencilAttachment = &data.stencil_attachment;
104 }
105 command_buffer.begin_rendering(&data.vk_rendering_info);
106 }
107
114 static void reconfigure_for_restart(VKBeginRenderingData &begin_rendering_data)
115 {
116 auto reconfigure_attachment = [](VkRenderingAttachmentInfo &rendering_attachment) {
117 if (ELEM(rendering_attachment.loadOp,
118 VK_ATTACHMENT_LOAD_OP_CLEAR,
119 VK_ATTACHMENT_LOAD_OP_DONT_CARE))
120 {
121 rendering_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
122 }
123 };
124
125 if (begin_rendering_data.vk_rendering_info.pStencilAttachment != nullptr) {
126 reconfigure_attachment(begin_rendering_data.stencil_attachment);
127 }
128 if (begin_rendering_data.vk_rendering_info.pDepthAttachment != nullptr) {
129 reconfigure_attachment(begin_rendering_data.depth_attachment);
130 }
131 for (VkRenderingAttachmentInfo &color_attachment : MutableSpan<VkRenderingAttachmentInfo>(
132 begin_rendering_data.color_attachments,
133 begin_rendering_data.vk_rendering_info.colorAttachmentCount))
134 {
135 reconfigure_attachment(color_attachment);
136 }
137 }
138};
139
140} // namespace blender::gpu::render_graph
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
#define ELEM(...)
BMesh const char void * data
static void reconfigure_for_restart(VKBeginRenderingData &begin_rendering_data)
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, Storage &storage, 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