Blender V5.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
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 VKRenderGraphLinks &links,
81 const CreateInfo &create_info) override
82 {
83 create_info.resources.build_links(resources, links);
84 }
85
90 Data &data,
91 Span<uint8_t> /*storage_push_constants*/,
92 VKBoundPipelines & /*r_bound_pipelines*/) override
93 {
94 /* Localize pointers just before sending to the command buffer. Pointer can (and will) change
95 * as they are stored in a union which is stored in a vector. When the vector reallocates,
96 * the pointers will become invalid. */
97 if (data.vk_rendering_info.pColorAttachments) {
98 data.vk_rendering_info.pColorAttachments = data.color_attachments;
99 }
100 if (data.vk_rendering_info.pDepthAttachment) {
101 data.vk_rendering_info.pDepthAttachment = &data.depth_attachment;
102 }
103 if (data.vk_rendering_info.pStencilAttachment) {
104 data.vk_rendering_info.pStencilAttachment = &data.stencil_attachment;
105 }
106 command_buffer.begin_rendering(&data.vk_rendering_info);
107 }
108
115 static void reconfigure_for_restart(VKBeginRenderingData &begin_rendering_data)
116 {
117 auto reconfigure_attachment = [](VkRenderingAttachmentInfo &rendering_attachment) {
118 if (ELEM(rendering_attachment.loadOp,
119 VK_ATTACHMENT_LOAD_OP_CLEAR,
120 VK_ATTACHMENT_LOAD_OP_DONT_CARE))
121 {
122 rendering_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
123 }
124 };
125
126 if (begin_rendering_data.vk_rendering_info.pStencilAttachment != nullptr) {
127 reconfigure_attachment(begin_rendering_data.stencil_attachment);
128 }
129 if (begin_rendering_data.vk_rendering_info.pDepthAttachment != nullptr) {
130 reconfigure_attachment(begin_rendering_data.depth_attachment);
131 }
132 for (VkRenderingAttachmentInfo &color_attachment : MutableSpan<VkRenderingAttachmentInfo>(
133 begin_rendering_data.color_attachments,
134 begin_rendering_data.vk_rendering_info.colorAttachmentCount))
135 {
136 reconfigure_attachment(color_attachment);
137 }
138 }
139};
140
141} // namespace blender::gpu::render_graph
#define ELEM(...)
#define BLI_assert_msg(a, msg)
static void reconfigure_for_restart(VKBeginRenderingData &begin_rendering_data)
void build_links(VKResourceStateTracker &resources, VKRenderGraphLinks &links, const CreateInfo &create_info) override
void build_commands(VKCommandBufferInterface &command_buffer, Data &data, Span< uint8_t >, VKBoundPipelines &) override
void set_node_data(Node &node, Storage &storage, const CreateInfo &create_info)
virtual void begin_rendering(const VkRenderingInfo *p_rendering_info)=0
#define storage(slot, qualifiers)
BMesh const char void * data
VKBeginRenderingCreateInfo(const VKResourceAccessInfo &resources)
void build_links(VKResourceStateTracker &resources, VKRenderGraphLinks &links) const