Blender V4.5
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 VkRenderPassBeginInfo vk_render_pass_begin_info;
25};
26
32
40class VKBeginRenderingNode : public VKNodeInfo<VKNodeType::BEGIN_RENDERING,
41 VKBeginRenderingCreateInfo,
42 VKBeginRenderingData,
43 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
44 VKResourceType::IMAGE> {
45 public:
53 template<typename Node, typename Storage>
54 void set_node_data(Node &node, Storage &storage, const CreateInfo &create_info)
55 {
56 const bool use_render_pass = create_info.node_data.vk_render_pass_begin_info.renderPass !=
57 VK_NULL_HANDLE;
58 UNUSED_VARS_NDEBUG(use_render_pass);
59 BLI_assert_msg(use_render_pass ||
60 ELEM(create_info.node_data.vk_rendering_info.pColorAttachments,
61 nullptr,
62 create_info.node_data.color_attachments),
63 "When create_info.node_data.vk_rendering_info.pColorAttachments points to "
64 "something, it should point to create_info.node_data.color_attachments.");
65 BLI_assert_msg(use_render_pass ||
66 ELEM(create_info.node_data.vk_rendering_info.pDepthAttachment,
67 nullptr,
68 &create_info.node_data.depth_attachment),
69 "When create_info.node_data.vk_rendering_info.pDepthAttachment points to "
70 "something, it should point to create_info.node_data.depth_attachment.");
71 BLI_assert_msg(use_render_pass ||
72 ELEM(create_info.node_data.vk_rendering_info.pStencilAttachment,
73 nullptr,
74 &create_info.node_data.stencil_attachment),
75 "When create_info.node_data.vk_rendering_info.pStencilAttachment points to "
76 "something, it should point to create_info.node_data.stencil_attachment.");
77 node.storage_index = storage.begin_rendering.append_and_get_index(create_info.node_data);
78 /* NOTE: pointers in vk_rendering_info will be set to the correct location just before sending
79 * to the command buffer. In the meantime these pointers are invalid.
80 * VKRenderingAttachmentInfo's should be used instead. */
81 }
82
87 VKRenderGraphNodeLinks &node_links,
88 const CreateInfo &create_info) override
89 {
90 create_info.resources.build_links(resources, node_links);
91 }
92
97 Data &data,
98 VKBoundPipelines & /*r_bound_pipelines*/) override
99 {
100 const bool is_dynamic_rendering = data.vk_render_pass_begin_info.renderPass == VK_NULL_HANDLE;
101 if (is_dynamic_rendering) {
102 /* Localize pointers just before sending to the command buffer. Pointer can (and will) change
103 * as they are stored in a union which is stored in a vector. When the vector reallocates,
104 * the pointers will become invalid. */
105 if (data.vk_rendering_info.pColorAttachments) {
106 data.vk_rendering_info.pColorAttachments = data.color_attachments;
107 }
108 if (data.vk_rendering_info.pDepthAttachment) {
109 data.vk_rendering_info.pDepthAttachment = &data.depth_attachment;
110 }
111 if (data.vk_rendering_info.pStencilAttachment) {
112 data.vk_rendering_info.pStencilAttachment = &data.stencil_attachment;
113 }
114 command_buffer.begin_rendering(&data.vk_rendering_info);
115 }
116 else {
117 command_buffer.begin_render_pass(&data.vk_render_pass_begin_info);
118 }
119 }
120
127 static void reconfigure_for_restart(VKBeginRenderingData &begin_rendering_data)
128 {
129 auto reconfigure_attachment = [](VkRenderingAttachmentInfo &rendering_attachment) {
130 if (ELEM(rendering_attachment.loadOp,
131 VK_ATTACHMENT_LOAD_OP_CLEAR,
132 VK_ATTACHMENT_LOAD_OP_DONT_CARE))
133 {
134 rendering_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
135 }
136 };
137
138 if (begin_rendering_data.vk_rendering_info.pStencilAttachment != nullptr) {
139 reconfigure_attachment(begin_rendering_data.stencil_attachment);
140 }
141 if (begin_rendering_data.vk_rendering_info.pDepthAttachment != nullptr) {
142 reconfigure_attachment(begin_rendering_data.depth_attachment);
143 }
144 for (VkRenderingAttachmentInfo &color_attachment : MutableSpan<VkRenderingAttachmentInfo>(
145 begin_rendering_data.color_attachments,
146 begin_rendering_data.vk_rendering_info.colorAttachmentCount))
147 {
148 reconfigure_attachment(color_attachment);
149 }
150 }
151};
152
153} // namespace blender::gpu::render_graph
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
#define UNUSED_VARS_NDEBUG(...)
#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_render_pass(const VkRenderPassBeginInfo *render_pass_begin_info)=0
virtual void begin_rendering(const VkRenderingInfo *p_rendering_info)=0
VKBeginRenderingCreateInfo(const VKResourceAccessInfo &resources)
void build_links(VKResourceStateTracker &resources, VKRenderGraphNodeLinks &node_links) const