Blender V5.3
vk_render_graph_test_scheduler.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
8
10
12
14TEST_P(VKRenderGraphTestScheduler, begin_rendering_copy_buffer_end_rendering)
15{
17 VkHandle<VkImageView> image_view(2u);
18 VKTrackedHandle<VkBuffer> buffer_src(3u);
19 VKTrackedHandle<VkBuffer> buffer_dst(4u);
20
21 resources.add_image(image, false);
22 buffer_src.set_resource_handle(resources.add_buffer(buffer_src));
23 buffer_dst.set_resource_handle(resources.add_buffer(buffer_dst));
24
25 {
26 VKResourceAccessInfo access_info = {};
27 access_info.images.append(
28 {image, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, {}});
29 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
30 begin_rendering.node_data.color_attachments[0].sType =
31 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
32 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
33 begin_rendering.node_data.color_attachments[0].imageView = image_view;
34 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
35 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
36 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
37 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
38 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
39 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
40 begin_rendering.node_data.color_attachments;
41
42 render_graph->add_node(begin_rendering);
43 }
44
45 {
46 VKCopyBufferNode::CreateInfo copy_buffer = {};
47 copy_buffer.src_buffer = buffer_src;
48 copy_buffer.dst_buffer = buffer_dst;
49 render_graph->add_node(copy_buffer);
50 }
51
52 {
53 VKEndRenderingNode::CreateInfo end_rendering = {};
54 render_graph->add_node(end_rendering);
55 }
56
57 {
59 synchronization.vk_image = image;
60 synchronization.vk_image_layout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
61 synchronization.vk_image_aspect = VK_IMAGE_ASPECT_COLOR_BIT;
62 render_graph->add_node(synchronization);
63 }
64
65 submit(render_graph, command_buffer);
66 EXPECT_EQ(5, log.size());
67
68 EXPECT_EQ("copy_buffer(src_buffer=0x3, dst_buffer=0x4" + endl() +
69 " - region(src_offset=0, dst_offset=0, size=0)" + endl() + ")",
70 log[0]);
72 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
73 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
74 endl() +
75 " - image_barrier(src_access_mask=, "
76 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
77 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
78 "new_layout=" +
79 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
80 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
81 "base_array_layer=0, layer_count=4294967295 )" +
82 endl() + ")",
83 log[1]);
84 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
85 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
86 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
87 "p_color_attachments=" +
88 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
89 ", "
90 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
91 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
92 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
93 endl() + ")",
94 log[2]);
95 EXPECT_EQ("end_rendering()", log[3]);
97 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
98 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT" +
99 endl() +
100 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
101 "dst_access_mask=, "
102 "old_layout=" +
103 color_attachment_layout_str() +
104 ", "
105 "new_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, image=0x1, subresource_range=" +
106 endl() +
107 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
108 "base_array_layer=0, layer_count=4294967295 )" +
109 endl() + ")",
110 log[4]);
111}
112
113TEST_P(VKRenderGraphTestScheduler, begin_clear_attachments_copy_buffer_end)
114{
116 VkHandle<VkImageView> image_view(2u);
117 VKTrackedHandle<VkBuffer> buffer_src(3u);
118 VKTrackedHandle<VkBuffer> buffer_dst(4u);
119
120 resources.add_image(image, false);
121 buffer_src.set_resource_handle(resources.add_buffer(buffer_src));
122 buffer_dst.set_resource_handle(resources.add_buffer(buffer_dst));
123
124 {
125 VKResourceAccessInfo access_info = {};
126 access_info.images.append(
127 {image, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, {}});
128 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
129 begin_rendering.node_data.color_attachments[0].sType =
130 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
131 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
132 begin_rendering.node_data.color_attachments[0].imageView = image_view;
133 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
134 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
135 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
136 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
137 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
138 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
139 begin_rendering.node_data.color_attachments;
140
141 render_graph->add_node(begin_rendering);
142 }
143
144 {
145 VKClearAttachmentsNode::CreateInfo clear_attachments = {};
146 clear_attachments.attachment_count = 1;
147 clear_attachments.attachments[0].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
148 clear_attachments.attachments[0].clearValue.color.float32[0] = 0.2;
149 clear_attachments.attachments[0].clearValue.color.float32[1] = 0.4;
150 clear_attachments.attachments[0].clearValue.color.float32[2] = 0.6;
151 clear_attachments.attachments[0].clearValue.color.float32[3] = 1.0;
152 clear_attachments.attachments[0].colorAttachment = 0;
153 clear_attachments.vk_clear_rect.baseArrayLayer = 0;
154 clear_attachments.vk_clear_rect.layerCount = 1;
155 clear_attachments.vk_clear_rect.rect.extent.width = 1920;
156 clear_attachments.vk_clear_rect.rect.extent.height = 1080;
157 render_graph->add_node(clear_attachments);
158 }
159
160 {
161 VKCopyBufferNode::CreateInfo copy_buffer = {};
162 copy_buffer.src_buffer = buffer_src;
163 copy_buffer.dst_buffer = buffer_dst;
164 render_graph->add_node(copy_buffer);
165 }
166
167 {
168 VKEndRenderingNode::CreateInfo end_rendering = {};
169 render_graph->add_node(end_rendering);
170 }
171
172 {
174 synchronization.vk_image = image;
175 synchronization.vk_image_layout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
176 synchronization.vk_image_aspect = VK_IMAGE_ASPECT_COLOR_BIT;
177 render_graph->add_node(synchronization);
178 }
179
180 submit(render_graph, command_buffer);
181 EXPECT_EQ(6, log.size());
182 EXPECT_EQ("copy_buffer(src_buffer=0x3, dst_buffer=0x4" + endl() +
183 " - region(src_offset=0, dst_offset=0, size=0)" + endl() + ")",
184 log[0]);
185 EXPECT_EQ(
186 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
187 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
188 endl() +
189 " - image_barrier(src_access_mask=, "
190 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
191 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
192 "new_layout=" +
193 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
194 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
195 "base_array_layer=0, layer_count=4294967295 )" +
196 endl() + ")",
197 log[1]);
198 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
199 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
200 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
201 "p_color_attachments=" +
202 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
203 ", "
204 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
205 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
206 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
207 endl() + ")",
208 log[2]);
209 EXPECT_EQ(
210 "clear_attachments( - attachment(aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, "
211 "color_attachment=0)" +
212 endl() + " - rect(rect=" + endl() + " offset=" + endl() +
213 " x=0, y=0 , extent=" + endl() +
214 " width=1920, height=1080 , base_array_layer=0, layer_count=1)" + endl() + ")",
215 log[3]);
216 EXPECT_EQ("end_rendering()", log[4]);
217 EXPECT_EQ(
218 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
219 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT" +
220 endl() +
221 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
222 "dst_access_mask=, "
223 "old_layout=" +
224 color_attachment_layout_str() +
225 ", "
226 "new_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, image=0x1, subresource_range=" +
227 endl() +
228 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
229 "base_array_layer=0, layer_count=4294967295 )" +
230 endl() + ")",
231 log[5]);
232}
233
234TEST_P(VKRenderGraphTestScheduler, begin_copy_buffer_clear_attachments_end)
235{
237 VkHandle<VkImageView> image_view(2u);
238 VKTrackedHandle<VkBuffer> buffer_src(3u);
239 VKTrackedHandle<VkBuffer> buffer_dst(4u);
240
241 resources.add_image(image, false);
242 buffer_src.set_resource_handle(resources.add_buffer(buffer_src));
243 buffer_dst.set_resource_handle(resources.add_buffer(buffer_dst));
244
245 {
246 VKResourceAccessInfo access_info = {};
247 access_info.images.append(
248 {image, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, {}});
249 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
250 begin_rendering.node_data.color_attachments[0].sType =
251 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
252 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
253 begin_rendering.node_data.color_attachments[0].imageView = image_view;
254 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
255 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
256 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
257 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
258 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
259 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
260 begin_rendering.node_data.color_attachments;
261
262 render_graph->add_node(begin_rendering);
263 }
264
265 {
266 VKCopyBufferNode::CreateInfo copy_buffer = {};
267 copy_buffer.src_buffer = buffer_src;
268 copy_buffer.dst_buffer = buffer_dst;
269 render_graph->add_node(copy_buffer);
270 }
271
272 {
273 VKClearAttachmentsNode::CreateInfo clear_attachments = {};
274 clear_attachments.attachment_count = 1;
275 clear_attachments.attachments[0].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
276 clear_attachments.attachments[0].clearValue.color.float32[0] = 0.2;
277 clear_attachments.attachments[0].clearValue.color.float32[1] = 0.4;
278 clear_attachments.attachments[0].clearValue.color.float32[2] = 0.6;
279 clear_attachments.attachments[0].clearValue.color.float32[3] = 1.0;
280 clear_attachments.attachments[0].colorAttachment = 0;
281 clear_attachments.vk_clear_rect.baseArrayLayer = 0;
282 clear_attachments.vk_clear_rect.layerCount = 1;
283 clear_attachments.vk_clear_rect.rect.extent.width = 1920;
284 clear_attachments.vk_clear_rect.rect.extent.height = 1080;
285 render_graph->add_node(clear_attachments);
286 }
287
288 {
289 VKEndRenderingNode::CreateInfo end_rendering = {};
290 render_graph->add_node(end_rendering);
291 }
292
293 {
295 synchronization.vk_image = image;
296 synchronization.vk_image_layout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
297 synchronization.vk_image_aspect = VK_IMAGE_ASPECT_COLOR_BIT;
298 render_graph->add_node(synchronization);
299 }
300
301 submit(render_graph, command_buffer);
302 EXPECT_EQ(6, log.size());
303 EXPECT_EQ("copy_buffer(src_buffer=0x3, dst_buffer=0x4" + endl() +
304 " - region(src_offset=0, dst_offset=0, size=0)" + endl() + ")",
305 log[0]);
306 EXPECT_EQ(
307 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
308 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
309 endl() +
310 " - image_barrier(src_access_mask=, "
311 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
312 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
313 "new_layout=" +
314 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
315 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
316 "base_array_layer=0, layer_count=4294967295 )" +
317 endl() + ")",
318 log[1]);
319 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
320 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
321 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
322 "p_color_attachments=" +
323 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
324 ", "
325 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
326 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
327 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
328 endl() + ")",
329 log[2]);
330 EXPECT_EQ(
331 "clear_attachments( - attachment(aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, "
332 "color_attachment=0)" +
333 endl() + " - rect(rect=" + endl() + " offset=" + endl() +
334 " x=0, y=0 , extent=" + endl() +
335 " width=1920, height=1080 , base_array_layer=0, layer_count=1)" + endl() + ")",
336 log[3]);
337 EXPECT_EQ("end_rendering()", log[4]);
338 EXPECT_EQ(
339 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
340 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT" +
341 endl() +
342 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
343 "dst_access_mask=, "
344 "old_layout=" +
345 color_attachment_layout_str() +
346 ", "
347 "new_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, image=0x1, subresource_range=" +
348 endl() +
349 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
350 "base_array_layer=0, layer_count=4294967295 )" +
351 endl() + ")",
352 log[5]);
353}
354
355TEST_P(VKRenderGraphTestScheduler, begin_clear_attachments_copy_buffer_clear_attachments_end)
356{
358 VkHandle<VkImageView> image_view(2u);
359 VKTrackedHandle<VkBuffer> buffer_src(3u);
360 VKTrackedHandle<VkBuffer> buffer_dst(4u);
361
362 resources.add_image(image, false);
363 buffer_src.set_resource_handle(resources.add_buffer(buffer_src));
364 buffer_dst.set_resource_handle(resources.add_buffer(buffer_dst));
365
366 {
367 VKResourceAccessInfo access_info = {};
368 access_info.images.append(
369 {image, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, {}});
370 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
371 begin_rendering.node_data.color_attachments[0].sType =
372 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
373 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
374 begin_rendering.node_data.color_attachments[0].imageView = image_view;
375 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
376 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
377 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
378 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
379 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
380 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
381 begin_rendering.node_data.color_attachments;
382
383 render_graph->add_node(begin_rendering);
384 }
385
386 {
387 VKClearAttachmentsNode::CreateInfo clear_attachments = {};
388 clear_attachments.attachment_count = 1;
389 clear_attachments.attachments[0].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
390 clear_attachments.attachments[0].clearValue.color.float32[0] = 0.2;
391 clear_attachments.attachments[0].clearValue.color.float32[1] = 0.4;
392 clear_attachments.attachments[0].clearValue.color.float32[2] = 0.6;
393 clear_attachments.attachments[0].clearValue.color.float32[3] = 1.0;
394 clear_attachments.attachments[0].colorAttachment = 0;
395 clear_attachments.vk_clear_rect.baseArrayLayer = 0;
396 clear_attachments.vk_clear_rect.layerCount = 1;
397 clear_attachments.vk_clear_rect.rect.extent.width = 1920;
398 clear_attachments.vk_clear_rect.rect.extent.height = 1080;
399 render_graph->add_node(clear_attachments);
400 }
401
402 {
403 VKCopyBufferNode::CreateInfo copy_buffer = {};
404 copy_buffer.src_buffer = buffer_src;
405 copy_buffer.dst_buffer = buffer_dst;
406 render_graph->add_node(copy_buffer);
407 }
408
409 {
410 VKClearAttachmentsNode::CreateInfo clear_attachments = {};
411 clear_attachments.attachment_count = 1;
412 clear_attachments.attachments[0].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
413 clear_attachments.attachments[0].clearValue.color.float32[0] = 0.2;
414 clear_attachments.attachments[0].clearValue.color.float32[1] = 0.4;
415 clear_attachments.attachments[0].clearValue.color.float32[2] = 0.6;
416 clear_attachments.attachments[0].clearValue.color.float32[3] = 1.0;
417 clear_attachments.attachments[0].colorAttachment = 0;
418 clear_attachments.vk_clear_rect.baseArrayLayer = 0;
419 clear_attachments.vk_clear_rect.layerCount = 1;
420 clear_attachments.vk_clear_rect.rect.extent.width = 1920;
421 clear_attachments.vk_clear_rect.rect.extent.height = 1080;
422 render_graph->add_node(clear_attachments);
423 }
424
425 {
426 VKEndRenderingNode::CreateInfo end_rendering = {};
427 render_graph->add_node(end_rendering);
428 }
429
430 {
432 synchronization.vk_image = image;
433 synchronization.vk_image_layout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
434 synchronization.vk_image_aspect = VK_IMAGE_ASPECT_COLOR_BIT;
435 render_graph->add_node(synchronization);
436 }
437
438 submit(render_graph, command_buffer);
439 ASSERT_EQ(7, log.size());
440
441 EXPECT_EQ("copy_buffer(src_buffer=0x3, dst_buffer=0x4" + endl() +
442 " - region(src_offset=0, dst_offset=0, size=0)" + endl() + ")",
443 log[0]);
444 EXPECT_EQ(
445 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
446 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
447 endl() +
448 " - image_barrier(src_access_mask=, "
449 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
450 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
451 "new_layout=" +
452 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
453 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
454 "base_array_layer=0, layer_count=4294967295 )" +
455 endl() + ")",
456 log[1]);
457 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
458 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
459 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
460 "p_color_attachments=" +
461 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
462 ", "
463 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
464 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
465 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
466 endl() + ")",
467 log[2]);
468 EXPECT_EQ(
469 "clear_attachments( - attachment(aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, "
470 "color_attachment=0)" +
471 endl() + " - rect(rect=" + endl() + " offset=" + endl() +
472 " x=0, y=0 , extent=" + endl() +
473 " width=1920, height=1080 , base_array_layer=0, layer_count=1)" + endl() + ")",
474 log[3]);
475 EXPECT_EQ(
476 "clear_attachments( - attachment(aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, "
477 "color_attachment=0)" +
478 endl() + " - rect(rect=" + endl() + " offset=" + endl() +
479 " x=0, y=0 , extent=" + endl() +
480 " width=1920, height=1080 , base_array_layer=0, layer_count=1)" + endl() + ")",
481 log[4]);
482 EXPECT_EQ("end_rendering()", log[5]);
483 EXPECT_EQ(
484 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
485 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT" +
486 endl() +
487 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
488 "dst_access_mask=, old_layout=" +
489 color_attachment_layout_str() +
490 ", "
491 "new_layout=VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, image=0x1, subresource_range=" +
492 endl() +
493 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
494 "base_array_layer=0, layer_count=4294967295 )" +
495 endl() + ")",
496 log[6]);
497}
498
505TEST_P(VKRenderGraphTestScheduler, begin_draw_copy_framebuffer_draw_end)
506{
507 VkHandle<VkImage> image_attachment(1u);
508 VkHandle<VkImage> image_feedback(2u);
509 VkHandle<VkImageView> image_view_attachment(3u);
510 VkHandle<VkPipelineLayout> pipeline_layout_combine(4u);
511 VkHandle<VkPipeline> pipeline_combine(5u);
512 VkHandle<VkPipelineLayout> pipeline_layout_background(6u);
513 VkHandle<VkPipeline> pipeline_background(7u);
514
515 resources.add_image(image_attachment, false);
516 resources.add_image(image_feedback, false);
517
518 {
519 VKResourceAccessInfo access_info = {};
520 access_info.images.append(
521 {image_attachment, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, {}});
522 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
523 begin_rendering.node_data.color_attachments[0].sType =
524 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
525 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
526 begin_rendering.node_data.color_attachments[0].imageView = image_view_attachment;
527 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
528 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
529 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
530 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
531 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
532 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
533 begin_rendering.node_data.color_attachments;
534
535 render_graph->add_node(begin_rendering);
536 }
537
538 {
539 VKResourceAccessInfo access_info = {};
541 node.data.first_instance = 0;
542 node.data.first_vertex = 0;
543 node.data.instance_count = 1;
544 node.data.vertex_count = 4;
545 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
546 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
547 node.data.graphics.pipeline_data.vk_pipeline = pipeline_combine;
548 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout_combine;
549 node.data.graphics.viewport.viewports.append(VkViewport{});
550 node.data.graphics.viewport.scissors.append(VkRect2D{});
551 VKDrawNode::CreateInfo draw_create_info(access_info);
552 node.finalize(*render_graph, draw_create_info);
553 }
554
555 {
556 VKCopyImageNode::CreateInfo copy_image = {};
557 copy_image.vk_image_aspect = VK_IMAGE_ASPECT_COLOR_BIT;
558 copy_image.node_data.src_image = image_attachment;
559 copy_image.node_data.dst_image = image_feedback;
560 copy_image.node_data.mip_levels = 1u;
561 copy_image.node_data.region.extent.width = 1920;
562 copy_image.node_data.region.extent.height = 1080;
563 copy_image.node_data.region.extent.depth = 1;
564 copy_image.node_data.region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
565 copy_image.node_data.region.srcSubresource.baseArrayLayer = 0;
566 copy_image.node_data.region.srcSubresource.layerCount = 1;
567 copy_image.node_data.region.srcSubresource.mipLevel = 0;
568 render_graph->add_node(copy_image);
569 }
570
571 {
572 VKResourceAccessInfo access_info = {};
574 node.data.first_instance = 0;
575 node.data.first_vertex = 0;
576 node.data.instance_count = 1;
577 node.data.vertex_count = 4;
578 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
579 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
580 node.data.graphics.pipeline_data.vk_pipeline = pipeline_background;
581 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout_background;
582 node.data.graphics.viewport.viewports.append(VkViewport{});
583 node.data.graphics.viewport.scissors.append(VkRect2D{});
584 VKDrawNode::CreateInfo draw_create_info(access_info);
585 node.finalize(*render_graph, draw_create_info);
586 }
587
588 {
589 VKEndRenderingNode::CreateInfo end_rendering = {};
590 render_graph->add_node(end_rendering);
591 }
592
593 submit(render_graph, command_buffer);
594 ASSERT_EQ(14, log.size());
595
596 EXPECT_EQ(
597 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
598 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
599 endl() +
600 " - image_barrier(src_access_mask=, "
601 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
602 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
603 "new_layout=" +
604 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
605 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
606 "base_array_layer=0, layer_count=4294967295 )" +
607 endl() + ")",
608 log[0]);
609 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
610 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
611 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
612 "p_color_attachments=" +
613 endl() + " image_view=0x3, image_layout=" + color_attachment_layout_str() +
614 ", resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
615 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
616 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
617 endl() + ")",
618 log[1]);
619 EXPECT_EQ("set_viewport(num_viewports=1)", log[2]);
620 EXPECT_EQ("set_scissor(num_scissors=1)", log[3]);
621 EXPECT_EQ("bind_pipeline(pipeline_bind_point=VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline=0x5)",
622 log[4]);
623 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[5]);
624 EXPECT_EQ("end_rendering()", log[6]);
625 EXPECT_EQ(
626 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
627 "dst_stage_mask=VK_PIPELINE_STAGE_TRANSFER_BIT" +
628 endl() +
629 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
630 "dst_access_mask=VK_ACCESS_TRANSFER_READ_BIT, "
631 "old_layout=" +
632 color_attachment_layout_str() +
633 ", "
634 "new_layout=VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, image=0x1, subresource_range=" +
635 endl() +
636 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
637 "base_array_layer=0, layer_count=4294967295 )" +
638 endl() +
639 " - image_barrier(src_access_mask=, dst_access_mask=VK_ACCESS_TRANSFER_WRITE_BIT, "
640 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, new_layout=VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "
641 "image=0x2, subresource_range=" +
642 endl() +
643 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
644 "base_array_layer=0, layer_count=4294967295 )" +
645 endl() + ")",
646 log[7]);
647 EXPECT_EQ(
648 "copy_image(src_image=0x1, src_image_layout=VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "
649 "dst_image=0x2, dst_image_layout=VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL" +
650 endl() + " - region(src_subresource=" + endl() +
651 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, mip_level=0, base_array_layer=0, "
652 "layer_count=1 , src_offset=" +
653 endl() + " x=0, y=0, z=0 , dst_subresource=" + endl() +
654 " aspect_mask=, mip_level=0, base_array_layer=0, layer_count=0 , dst_offset=" +
655 endl() + " x=0, y=0, z=0 , extent=" + endl() +
656 " width=1920, height=1080, depth=1 )" + endl() + ")",
657 log[8]);
658 EXPECT_EQ(
659 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TRANSFER_BIT, "
660 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
661 endl() +
662 " - image_barrier(src_access_mask=VK_ACCESS_TRANSFER_READ_BIT, "
663 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
664 "old_layout=VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "
665 "new_layout=" +
666 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
667 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
668 "base_array_layer=0, layer_count=4294967295 )" +
669 endl() + ")",
670 log[9]);
671 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
672 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
673 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
674 "p_color_attachments=" +
675 endl() + " image_view=0x3, image_layout=" + color_attachment_layout_str() +
676 ", resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
677 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
678 "load_op=VK_ATTACHMENT_LOAD_OP_LOAD, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
679 endl() + ")",
680 log[10]);
681 EXPECT_EQ("bind_pipeline(pipeline_bind_point=VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline=0x7)",
682 log[11]);
683 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[12]);
684 EXPECT_EQ("end_rendering()", log[13]);
685}
686
691TEST_P(VKRenderGraphTestScheduler, begin_update_draw_update_draw_update_draw_end)
692{
693 VKTrackedHandle<VkBuffer> buffer_a(1u);
694 VKTrackedHandle<VkBuffer> buffer_b(2u);
696 VkHandle<VkImageView> image_view(4u);
697 VkHandle<VkPipelineLayout> pipeline_layout(5u);
698 VkHandle<VkPipeline> pipeline(6u);
699
700 resources.add_image(image, false);
701 buffer_a.set_resource_handle(resources.add_buffer(buffer_a));
702 buffer_b.set_resource_handle(resources.add_buffer(buffer_b));
703
704 {
705 VKResourceAccessInfo access_info = {};
706 access_info.images.append(
707 {image, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, {}});
708 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
709 begin_rendering.node_data.color_attachments[0].sType =
710 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
711 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
712 begin_rendering.node_data.color_attachments[0].imageView = image_view;
713 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
714 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
715 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
716 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
717 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
718 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
719 begin_rendering.node_data.color_attachments;
720
721 render_graph->add_node(begin_rendering);
722 }
723
724 {
725 VKUpdateBufferNode::CreateInfo update_buffer = {};
726 update_buffer.dst_buffer = buffer_a;
727 update_buffer.data_size = 16;
728 update_buffer.data = MEM_new_zeroed(16, __func__);
729
730 render_graph->add_node(update_buffer);
731 }
732
733 {
734 VKResourceAccessInfo access_info = {};
735 access_info.buffers.append({buffer_a.get_resource_handle(), VK_ACCESS_UNIFORM_READ_BIT});
737 node.data.first_instance = 0;
738 node.data.first_vertex = 0;
739 node.data.instance_count = 1;
740 node.data.vertex_count = 1;
741 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
742 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
743 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
744 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
745 node.data.graphics.viewport.viewports.append(VkViewport{});
746 node.data.graphics.viewport.scissors.append(VkRect2D{});
747 VKDrawNode::CreateInfo draw_create_info(access_info);
748 node.finalize(*render_graph, draw_create_info);
749 }
750
751 {
752 VKUpdateBufferNode::CreateInfo update_buffer = {};
753 update_buffer.dst_buffer = buffer_b;
754 update_buffer.data_size = 24;
755 update_buffer.data = MEM_new_zeroed(24, __func__);
756
757 render_graph->add_node(update_buffer);
758 }
759
760 {
761 VKResourceAccessInfo access_info = {};
762 access_info.buffers.append({buffer_b.get_resource_handle(), VK_ACCESS_UNIFORM_READ_BIT});
764 node.data.first_instance = 0;
765 node.data.first_vertex = 0;
766 node.data.instance_count = 1;
767 node.data.vertex_count = 2;
768 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
769 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
770 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
771 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
772 node.data.graphics.viewport.viewports.append(VkViewport{});
773 node.data.graphics.viewport.scissors.append(VkRect2D{});
774 VKDrawNode::CreateInfo draw_create_info(access_info);
775 node.finalize(*render_graph, draw_create_info);
776 }
777
778 {
779 VKUpdateBufferNode::CreateInfo update_buffer = {};
780 update_buffer.dst_buffer = buffer_a;
781 update_buffer.data_size = 16;
782 update_buffer.data = MEM_new_zeroed(16, __func__);
783
784 render_graph->add_node(update_buffer);
785 }
786
787 {
788 VKResourceAccessInfo access_info = {};
789 access_info.buffers.append({buffer_a.get_resource_handle(), VK_ACCESS_UNIFORM_READ_BIT});
791 node.data.first_instance = 0;
792 node.data.first_vertex = 0;
793 node.data.instance_count = 1;
794 node.data.vertex_count = 3;
795 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
796 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
797 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
798 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
799 node.data.graphics.viewport.viewports.append(VkViewport{});
800 node.data.graphics.viewport.scissors.append(VkRect2D{});
801 VKDrawNode::CreateInfo draw_create_info(access_info);
802 node.finalize(*render_graph, draw_create_info);
803 }
804
805 {
806 VKEndRenderingNode::CreateInfo end_rendering = {};
807 render_graph->add_node(end_rendering);
808 }
809
810 submit(render_graph, command_buffer);
811 ASSERT_EQ(19, log.size());
812 EXPECT_EQ("update_buffer(dst_buffer=0x1, dst_offset=0, data_size=16)", log[0]);
813 EXPECT_EQ("update_buffer(dst_buffer=0x2, dst_offset=0, data_size=24)", log[1]);
814 EXPECT_EQ(
815 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
816 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
817 endl() +
818 " - image_barrier(src_access_mask=, "
819 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
820 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
821 "new_layout=" +
822 color_attachment_layout_str() +
823 ", "
824 "image=0x3, subresource_range=" +
825 endl() +
826 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, "
827 "base_mip_level=0, level_count=4294967295, base_array_layer=0, layer_count=4294967295 "
828 ")" +
829 endl() + ")",
830 log[2]);
831 EXPECT_EQ(
832 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TRANSFER_BIT, "
833 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
834 endl() +
835 " - "
836 "buffer_barrier(src_access_mask=VK_ACCESS_TRANSFER_WRITE_BIT, "
837 "dst_access_mask=VK_ACCESS_UNIFORM_READ_BIT, buffer=0x1, offset=0, "
838 "size=18446744073709551615)" +
839 endl() + ")",
840 log[3]);
841 EXPECT_EQ(
842 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TRANSFER_BIT, "
843 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
844 endl() +
845 " - "
846 "buffer_barrier(src_access_mask=VK_ACCESS_TRANSFER_WRITE_BIT, "
847 "dst_access_mask=VK_ACCESS_UNIFORM_READ_BIT, buffer=0x2, offset=0, "
848 "size=18446744073709551615)" +
849 endl() + ")",
850 log[4]);
851 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
852 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
853 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
854 "p_color_attachments=" +
855 endl() + " image_view=0x4, image_layout=" + color_attachment_layout_str() +
856 ", resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
857 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
858 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
859 endl() + ")",
860 log[5]);
861 EXPECT_EQ("set_viewport(num_viewports=1)", log[6]);
862 EXPECT_EQ("set_scissor(num_scissors=1)", log[7]);
863 EXPECT_EQ("bind_pipeline(pipeline_bind_point=VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline=0x6)",
864 log[8]);
865 EXPECT_EQ("draw(vertex_count=1, instance_count=1, first_vertex=0, first_instance=0)", log[9]);
866 EXPECT_EQ("draw(vertex_count=2, instance_count=1, first_vertex=0, first_instance=0)", log[10]);
867 EXPECT_EQ("end_rendering()", log[11]);
868 EXPECT_EQ(
869 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
870 "dst_stage_mask=VK_PIPELINE_STAGE_TRANSFER_BIT" +
871 endl() +
872 " - buffer_barrier(src_access_mask=VK_ACCESS_UNIFORM_READ_BIT, "
873 "dst_access_mask=VK_ACCESS_TRANSFER_WRITE_BIT, buffer=0x1, offset=0, "
874 "size=18446744073709551615)" +
875 endl() + ")",
876 log[12]);
877 EXPECT_EQ("update_buffer(dst_buffer=0x1, dst_offset=0, data_size=16)", log[13]);
878 EXPECT_EQ(
879 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TRANSFER_BIT, "
880 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
881 endl() +
882 " - buffer_barrier(src_access_mask=VK_ACCESS_TRANSFER_WRITE_BIT, "
883 "dst_access_mask=VK_ACCESS_UNIFORM_READ_BIT, buffer=0x1, offset=0, "
884 "size=18446744073709551615)" +
885 endl() + ")",
886 log[14]);
887 EXPECT_EQ(
888 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
889 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
890 endl() +
891 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
892 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
893 "old_layout=" +
894 color_attachment_layout_str() +
895 ", "
896 "new_layout=" +
897 color_attachment_layout_str() + ", image=0x3, subresource_range=" + endl() +
898 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
899 "base_array_layer=0, layer_count=4294967295 )" +
900 endl() + ")",
901 log[15]);
902 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
903 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
904 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
905 "p_color_attachments=" +
906 endl() + " image_view=0x4, image_layout=" + color_attachment_layout_str() +
907 ", resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
908 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
909 "load_op=VK_ATTACHMENT_LOAD_OP_LOAD, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
910 endl() + ")",
911 log[16]);
912 EXPECT_EQ("draw(vertex_count=3, instance_count=1, first_vertex=0, first_instance=0)", log[17]);
913 EXPECT_EQ("end_rendering()", log[18]);
914}
915
922TEST_P(VKRenderGraphTestScheduler, begin_draw_copy_to_attachment_draw_end)
923{
924 VkHandle<VkImage> image_attachment(1u);
925 VkHandle<VkImage> image_editor(2u);
926 VkHandle<VkImageView> image_view_attachment(3u);
927 VkHandle<VkPipelineLayout> pipeline_layout(4u);
928 VkHandle<VkPipeline> pipeline(5u);
929
930 resources.add_image(image_attachment, false);
931 resources.add_image(image_editor, false);
932
933 {
934 VKResourceAccessInfo access_info = {};
935 access_info.images.append(
936 {image_attachment, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, {}});
937 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
938 begin_rendering.node_data.color_attachments[0].sType =
939 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
940 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
941 begin_rendering.node_data.color_attachments[0].imageView = image_view_attachment;
942 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
943 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
944 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
945 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
946 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
947 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
948 begin_rendering.node_data.color_attachments;
949
950 render_graph->add_node(begin_rendering);
951 }
952
953 {
954 VKResourceAccessInfo access_info = {};
956 node.data.first_instance = 0;
957 node.data.first_vertex = 0;
958 node.data.instance_count = 1;
959 node.data.vertex_count = 4;
960 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
961 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
962 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
963 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
964 node.data.graphics.viewport.viewports.append(VkViewport{});
965 node.data.graphics.viewport.scissors.append(VkRect2D{});
966 VKDrawNode::CreateInfo draw_create_info(access_info);
967 node.finalize(*render_graph, draw_create_info);
968 }
969
970 {
971 VKCopyImageNode::CreateInfo copy_image = {};
972 copy_image.vk_image_aspect = VK_IMAGE_ASPECT_COLOR_BIT;
973 copy_image.node_data.src_image = image_editor;
974 copy_image.node_data.dst_image = image_attachment;
975 copy_image.node_data.mip_levels = 1u;
976 copy_image.node_data.region.extent.width = 1920;
977 copy_image.node_data.region.extent.height = 1080;
978 copy_image.node_data.region.extent.depth = 1;
979 copy_image.node_data.region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
980 copy_image.node_data.region.srcSubresource.baseArrayLayer = 0;
981 copy_image.node_data.region.srcSubresource.layerCount = 1;
982 copy_image.node_data.region.srcSubresource.mipLevel = 0;
983 render_graph->add_node(copy_image);
984 }
985
986 {
987 VKResourceAccessInfo access_info = {};
989 node.data.first_instance = 0;
990 node.data.first_vertex = 0;
991 node.data.instance_count = 1;
992 node.data.vertex_count = 4;
993 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
994 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
995 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
996 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
997 node.data.graphics.viewport.viewports.append(VkViewport{});
998 node.data.graphics.viewport.scissors.append(VkRect2D{});
999 VKDrawNode::CreateInfo draw_create_info(access_info);
1000 node.finalize(*render_graph, draw_create_info);
1001 }
1002
1003 {
1004 VKEndRenderingNode::CreateInfo end_rendering = {};
1005 render_graph->add_node(end_rendering);
1006 }
1007
1008 submit(render_graph, command_buffer);
1009 ASSERT_EQ(13, log.size());
1010 EXPECT_EQ(
1011 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
1012 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
1013 endl() +
1014 " - image_barrier(src_access_mask=, "
1015 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1016 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1017 "new_layout=" +
1018 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
1019 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1020 "base_array_layer=0, layer_count=4294967295 )" +
1021 endl() + ")",
1022 log[0]);
1023 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
1024 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
1025 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
1026 "p_color_attachments=" +
1027 endl() + " image_view=0x3, image_layout=" + color_attachment_layout_str() +
1028 ", resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
1029 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1030 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
1031 endl() + ")",
1032 log[1]);
1033 EXPECT_EQ("set_viewport(num_viewports=1)", log[2]);
1034 EXPECT_EQ("set_scissor(num_scissors=1)", log[3]);
1035 EXPECT_EQ("bind_pipeline(pipeline_bind_point=VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline=0x5)",
1036 log[4]);
1037 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[5]);
1038 EXPECT_EQ("end_rendering()", log[6]);
1039 EXPECT_EQ(
1040 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
1041 "dst_stage_mask=VK_PIPELINE_STAGE_TRANSFER_BIT" +
1042 endl() +
1043 " - image_barrier(src_access_mask=, dst_access_mask=VK_ACCESS_TRANSFER_READ_BIT, "
1044 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, new_layout=VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "
1045 "image=0x2, subresource_range=" +
1046 endl() +
1047 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1048 "base_array_layer=0, layer_count=4294967295 )" +
1049 endl() +
1050 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1051 "dst_access_mask=VK_ACCESS_TRANSFER_WRITE_BIT, "
1052 "old_layout=" +
1053 color_attachment_layout_str() +
1054 ", "
1055 "new_layout=VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, image=0x1, subresource_range=" +
1056 endl() +
1057 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1058 "base_array_layer=0, layer_count=4294967295 )" +
1059 endl() + ")",
1060 log[7]);
1061 EXPECT_EQ(
1062 "copy_image(src_image=0x2, src_image_layout=VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, "
1063 "dst_image=0x1, dst_image_layout=VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL" +
1064 endl() + " - region(src_subresource=" + endl() +
1065 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, mip_level=0, base_array_layer=0, "
1066 "layer_count=1 , src_offset=" +
1067 endl() + " x=0, y=0, z=0 , dst_subresource=" + endl() +
1068 " aspect_mask=, mip_level=0, base_array_layer=0, layer_count=0 , dst_offset=" +
1069 endl() + " x=0, y=0, z=0 , extent=" + endl() +
1070 " width=1920, height=1080, depth=1 )" + endl() + ")",
1071 log[8]);
1072 EXPECT_EQ(
1073 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TRANSFER_BIT, "
1074 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
1075 endl() +
1076 " - image_barrier(src_access_mask=VK_ACCESS_TRANSFER_WRITE_BIT, "
1077 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1078 "old_layout=VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, "
1079 "new_layout=" +
1080 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
1081 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1082 "base_array_layer=0, layer_count=4294967295 )" +
1083 endl() + ")",
1084 log[9]);
1085 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
1086 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
1087 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
1088 "p_color_attachments=" +
1089 endl() + " image_view=0x3, image_layout=" + color_attachment_layout_str() +
1090 ", resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
1091 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1092 "load_op=VK_ATTACHMENT_LOAD_OP_LOAD, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
1093 endl() + ")",
1094 log[10]);
1095 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[11]);
1096 EXPECT_EQ("end_rendering()", log[12]);
1097}
1098
1104TEST_P(VKRenderGraphTestScheduler, begin_rendering_end_rendering_begin_rendering_draw)
1105{
1107 VkHandle<VkImageView> image_view(2u);
1108 VkHandle<VkPipelineLayout> pipeline_layout(4u);
1109 VkHandle<VkPipeline> pipeline(3u);
1110
1111 resources.add_image(image, false);
1112
1113 /* First scope: proper BEGIN/DRAW/END pair. */
1114 {
1115 VKResourceAccessInfo access_info = {};
1116 access_info.images.append(
1117 {image, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, {}});
1118 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1119 begin_rendering.node_data.color_attachments[0].sType =
1120 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1121 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
1122 begin_rendering.node_data.color_attachments[0].imageView = image_view;
1123 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1124 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1125 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1126 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
1127 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1128 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
1129 begin_rendering.node_data.color_attachments;
1130
1131 render_graph->add_node(begin_rendering);
1132 }
1133
1134 {
1135 VKResourceAccessInfo access_info = {};
1137 node.data.first_instance = 0;
1138 node.data.first_vertex = 0;
1139 node.data.instance_count = 1;
1140 node.data.vertex_count = 4;
1141 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1142 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1143 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1144 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1145 node.data.graphics.viewport.viewports.append(VkViewport{});
1146 node.data.graphics.viewport.scissors.append(VkRect2D{});
1147 VKDrawNode::CreateInfo draw_create_info(access_info);
1148 node.finalize(*render_graph, draw_create_info);
1149 }
1150
1151 {
1152 VKEndRenderingNode::CreateInfo end_rendering = {};
1153 render_graph->add_node(end_rendering);
1154 }
1155
1156 /* Second scope: BEGIN/DRAW without matching END, simulating subpass_transition_impl
1157 * with VK_EXT_dynamic_rendering_local_read.
1158 * Only applicable when local read is enabled - without it, orphaned BEGIN nodes
1159 * indicate a real bug. */
1160 if (use_dynamic_rendering_local_read) {
1161 VKResourceAccessInfo access_info = {};
1162 access_info.images.append(
1163 {image, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, {}});
1164 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1165 begin_rendering.node_data.color_attachments[0].sType =
1166 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1167 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
1168 begin_rendering.node_data.color_attachments[0].imageView = image_view;
1169 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
1170 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1171 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1172 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
1173 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1174 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
1175 begin_rendering.node_data.color_attachments;
1176
1177 render_graph->add_node(begin_rendering);
1178
1179 {
1180 VKResourceAccessInfo access_info = {};
1182 node.data.first_instance = 0;
1183 node.data.first_vertex = 0;
1184 node.data.instance_count = 1;
1185 node.data.vertex_count = 4;
1186 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1187 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1188 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1189 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1190 node.data.graphics.viewport.viewports.append(VkViewport{});
1191 node.data.graphics.viewport.scissors.append(VkRect2D{});
1192 VKDrawNode::CreateInfo draw_create_info(access_info);
1193 node.finalize(*render_graph, draw_create_info);
1194 }
1195
1196 /* Should not assert. */
1197 submit(render_graph, command_buffer);
1198
1199 ASSERT_EQ(11, log.size());
1200 EXPECT_EQ(
1201 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
1202 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
1203 endl() +
1204 " - image_barrier(src_access_mask=, "
1205 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1206 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1207 "new_layout=" +
1208 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
1209 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1210 "base_array_layer=0, layer_count=4294967295 )" +
1211 endl() + ")",
1212 log[0]);
1213 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
1214 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
1215 " width=0, height=0 , layer_count=1, view_mask=0, "
1216 "color_attachment_count=1, "
1217 "p_color_attachments=" +
1218 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
1219 ", "
1220 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
1221 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1222 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, "
1223 "store_op=VK_ATTACHMENT_STORE_OP_STORE" +
1224 endl() + ")",
1225 log[1]);
1226 EXPECT_EQ("set_viewport(num_viewports=1)", log[2]);
1227 EXPECT_EQ("set_scissor(num_scissors=1)", log[3]);
1228 EXPECT_EQ("bind_pipeline(pipeline_bind_point=VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline=0x3)",
1229 log[4]);
1230 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[5]);
1231 EXPECT_EQ("end_rendering()", log[6]);
1232 EXPECT_EQ(
1233 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
1234 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
1235 endl() +
1236 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1237 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1238 "old_layout=" +
1239 color_attachment_layout_str() +
1240 ", "
1241 "new_layout=" +
1242 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
1243 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, "
1244 "level_count=4294967295, "
1245 "base_array_layer=0, layer_count=4294967295 )" +
1246 endl() + ")",
1247 log[7]);
1248 /* Second rendering scope (orphaned BEGIN, no END node). Implicit end_rendering at group
1249 * end. */
1250 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
1251 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
1252 " width=0, height=0 , layer_count=1, view_mask=0, "
1253 "color_attachment_count=1, "
1254 "p_color_attachments=" +
1255 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
1256 ", "
1257 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
1258 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1259 "load_op=VK_ATTACHMENT_LOAD_OP_LOAD, "
1260 "store_op=VK_ATTACHMENT_STORE_OP_STORE" +
1261 endl() + ")",
1262 log[8]);
1263 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[9]);
1264 EXPECT_EQ("end_rendering()", log[10]);
1265 }
1266 else {
1267 /* Without local read, a second BEGIN with no matching END is a bug.
1268 * Skip verification (the scheduler will assert, which is correct behavior). */
1269 GTEST_SKIP() << "This test only applies when VK_EXT_dynamic_rendering_local_read is enabled";
1270 }
1271}
1272
1278TEST_P(VKRenderGraphTestScheduler, begin_draw_storage_end_begin_draw_end)
1279{
1281 VkHandle<VkImageView> image_view(2u);
1282 VkHandle<VkPipelineLayout> pipeline_layout(4u);
1283 VkHandle<VkPipeline> pipeline(3u);
1284
1285 resources.add_image(image, false);
1286
1287 /* First scope: BEGIN/DRAW(storage)/END. */
1288 {
1289 VKResourceAccessInfo access_info = {};
1290 access_info.images.append(
1291 {image,
1292 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1293 VK_IMAGE_ASPECT_COLOR_BIT,
1294 {}});
1295 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1296 begin_rendering.node_data.color_attachments[0].sType =
1297 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1298 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
1299 begin_rendering.node_data.color_attachments[0].imageView = image_view;
1300 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1301 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1302 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1303 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
1304 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1305 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
1306 begin_rendering.node_data.color_attachments;
1307
1308 render_graph->add_node(begin_rendering);
1309 }
1310
1311 {
1312 VKResourceAccessInfo access_info = {};
1313 /* Image accessed as shader storage (simulates storage image binding in EEVEE gbuffer). */
1314 access_info.images.append({image,
1315 VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
1316 VK_IMAGE_ASPECT_COLOR_BIT,
1317 {}});
1319 node.data.first_instance = 0;
1320 node.data.first_vertex = 0;
1321 node.data.instance_count = 1;
1322 node.data.vertex_count = 4;
1323 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1324 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1325 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1326 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1327 node.data.graphics.viewport.viewports.append(VkViewport{});
1328 node.data.graphics.viewport.scissors.append(VkRect2D{});
1329 VKDrawNode::CreateInfo draw_create_info(access_info);
1330 node.finalize(*render_graph, draw_create_info);
1331 }
1332
1333 {
1334 VKEndRenderingNode::CreateInfo end_rendering = {};
1335 render_graph->add_node(end_rendering);
1336 }
1337
1338 /* Second scope: BEGIN/DRAW/END. */
1339 {
1340 VKResourceAccessInfo access_info = {};
1341 access_info.images.append(
1342 {image,
1343 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1344 VK_IMAGE_ASPECT_COLOR_BIT,
1345 {}});
1346 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1347 begin_rendering.node_data.color_attachments[0].sType =
1348 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1349 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
1350 begin_rendering.node_data.color_attachments[0].imageView = image_view;
1351 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
1352 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1353 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1354 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
1355 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1356 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
1357 begin_rendering.node_data.color_attachments;
1358
1359 render_graph->add_node(begin_rendering);
1360 }
1361
1362 {
1363 VKResourceAccessInfo access_info = {};
1365 node.data.first_instance = 0;
1366 node.data.first_vertex = 0;
1367 node.data.instance_count = 1;
1368 node.data.vertex_count = 4;
1369 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1370 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1371 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1372 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1373 node.data.graphics.viewport.viewports.append(VkViewport{});
1374 node.data.graphics.viewport.scissors.append(VkRect2D{});
1375 VKDrawNode::CreateInfo draw_create_info(access_info);
1376 node.finalize(*render_graph, draw_create_info);
1377 }
1378
1379 {
1380 VKEndRenderingNode::CreateInfo end_rendering = {};
1381 render_graph->add_node(end_rendering);
1382 }
1383
1384 submit(render_graph, command_buffer);
1385
1386 ASSERT_EQ(12, log.size());
1387 /* Test the pipeline barriers have correct synchronization. */
1388 EXPECT_EQ(
1389 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
1390 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
1391 endl() +
1392 " - image_barrier(src_access_mask=, "
1393 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "
1394 "VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1395 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1396 "new_layout=" +
1397 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
1398 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1399 "base_array_layer=0, layer_count=4294967295 )" +
1400 endl() + ")",
1401 log[0]);
1402 EXPECT_EQ(
1403 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
1404 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
1405 endl() +
1406 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "
1407 "VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1408 "dst_access_mask=VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_SHADER_WRITE_BIT, "
1409 "old_layout=" +
1410 color_attachment_layout_str() +
1411 ", "
1412 "new_layout=VK_IMAGE_LAYOUT_GENERAL, image=0x1, subresource_range=" +
1413 endl() +
1414 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1415 "base_array_layer=0, layer_count=4294967295 )" +
1416 endl() + ")",
1417 log[1]);
1418 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
1419 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
1420 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
1421 "p_color_attachments=" +
1422 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
1423 ", "
1424 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
1425 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1426 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
1427 endl() + ")",
1428 log[2]);
1429 EXPECT_EQ("set_viewport(num_viewports=1)", log[3]);
1430 EXPECT_EQ("set_scissor(num_scissors=1)", log[4]);
1431 EXPECT_EQ("bind_pipeline(pipeline_bind_point=VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline=0x3)",
1432 log[5]);
1433 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[6]);
1434 EXPECT_EQ("end_rendering()", log[7]);
1435 EXPECT_EQ(
1436 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
1437 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
1438 endl() +
1439 " - image_barrier(src_access_mask=VK_ACCESS_SHADER_READ_BIT, "
1440 "VK_ACCESS_SHADER_WRITE_BIT, "
1441 "VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1442 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "
1443 "VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1444 "old_layout=VK_IMAGE_LAYOUT_GENERAL, "
1445 "new_layout=" +
1446 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
1447 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1448 "base_array_layer=0, layer_count=4294967295 )" +
1449 endl() + ")",
1450 log[8]);
1451 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
1452 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
1453 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
1454 "p_color_attachments=" +
1455 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
1456 ", "
1457 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
1458 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1459 "load_op=VK_ATTACHMENT_LOAD_OP_LOAD, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
1460 endl() + ")",
1461 log[9]);
1462 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[10]);
1463 EXPECT_EQ("end_rendering()", log[11]);
1464}
1465
1471TEST_P(VKRenderGraphTestScheduler, begin_draw_storage_end_begin_draw_end_subresource)
1472{
1474 VkHandle<VkImageView> image_view(2u);
1475 VkHandle<VkPipelineLayout> pipeline_layout(4u);
1476 VkHandle<VkPipeline> pipeline(3u);
1477
1478 /* Enable subresource tracking to exercise the ImageTracker code path. */
1479 resources.add_image(image, true);
1480
1481 /* First scope: BEGIN/DRAW(storage)/END. */
1482 {
1483 VKResourceAccessInfo access_info = {};
1484 access_info.images.append(
1485 {image,
1486 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1487 VK_IMAGE_ASPECT_COLOR_BIT,
1488 {}});
1489 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1490 begin_rendering.node_data.color_attachments[0].sType =
1491 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1492 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
1493 begin_rendering.node_data.color_attachments[0].imageView = image_view;
1494 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1495 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1496 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1497 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
1498 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1499 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
1500 begin_rendering.node_data.color_attachments;
1501
1502 render_graph->add_node(begin_rendering);
1503 }
1504
1505 {
1506 VKResourceAccessInfo access_info = {};
1507 /* Image accessed as shader storage. */
1508 access_info.images.append({image,
1509 VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
1510 VK_IMAGE_ASPECT_COLOR_BIT,
1511 {}});
1513 node.data.first_instance = 0;
1514 node.data.first_vertex = 0;
1515 node.data.instance_count = 1;
1516 node.data.vertex_count = 4;
1517 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1518 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1519 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1520 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1521 node.data.graphics.viewport.viewports.append(VkViewport{});
1522 node.data.graphics.viewport.scissors.append(VkRect2D{});
1523 VKDrawNode::CreateInfo draw_create_info(access_info);
1524 node.finalize(*render_graph, draw_create_info);
1525 }
1526
1527 {
1528 VKEndRenderingNode::CreateInfo end_rendering = {};
1529 render_graph->add_node(end_rendering);
1530 }
1531
1532 /* Second scope: BEGIN/DRAW/END. */
1533 {
1534 VKResourceAccessInfo access_info = {};
1535 access_info.images.append(
1536 {image,
1537 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1538 VK_IMAGE_ASPECT_COLOR_BIT,
1539 {}});
1540 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1541 begin_rendering.node_data.color_attachments[0].sType =
1542 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1543 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
1544 begin_rendering.node_data.color_attachments[0].imageView = image_view;
1545 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
1546 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1547 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1548 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
1549 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1550 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
1551 begin_rendering.node_data.color_attachments;
1552
1553 render_graph->add_node(begin_rendering);
1554 }
1555
1556 {
1557 VKResourceAccessInfo access_info = {};
1559 node.data.first_instance = 0;
1560 node.data.first_vertex = 0;
1561 node.data.instance_count = 1;
1562 node.data.vertex_count = 4;
1563 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1564 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1565 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1566 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1567 node.data.graphics.viewport.viewports.append(VkViewport{});
1568 node.data.graphics.viewport.scissors.append(VkRect2D{});
1569 VKDrawNode::CreateInfo draw_create_info(access_info);
1570 node.finalize(*render_graph, draw_create_info);
1571 }
1572
1573 {
1574 VKEndRenderingNode::CreateInfo end_rendering = {};
1575 render_graph->add_node(end_rendering);
1576 }
1577
1578 submit(render_graph, command_buffer);
1579
1580 ASSERT_EQ(13, log.size());
1581 /* Initial transition: UNDEFINED -> color_attachment_layout. */
1582 EXPECT_EQ(
1583 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
1584 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
1585 endl() +
1586 " - image_barrier(src_access_mask=, "
1587 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "
1588 "VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1589 "old_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1590 "new_layout=" +
1591 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
1592 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1593 "base_array_layer=0, layer_count=4294967295 )" +
1594 endl() + ")",
1595 log[0]);
1596 /* Storage access transition: color_attachment_layout -> GENERAL, merged with access sync. */
1597 EXPECT_EQ(
1598 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
1599 "VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, "
1600 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
1601 "VK_PIPELINE_STAGE_ALL_COMMANDS_BIT" +
1602 endl() +
1603 " - image_barrier(src_access_mask=VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "
1604 "VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, "
1605 "dst_access_mask=VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_SHADER_WRITE_BIT, "
1606 "VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1607 "VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, "
1608 "old_layout=" +
1609 color_attachment_layout_str() +
1610 ", "
1611 "new_layout=VK_IMAGE_LAYOUT_GENERAL, image=0x1, subresource_range=" +
1612 endl() +
1613 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1614 "base_array_layer=0, layer_count=4294967295 )" +
1615 endl() + ")",
1616 log[1]);
1617 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
1618 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
1619 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
1620 "p_color_attachments=" +
1621 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
1622 ", "
1623 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
1624 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1625 "load_op=VK_ATTACHMENT_LOAD_OP_DONT_CARE, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
1626 endl() + ")",
1627 log[2]);
1628 EXPECT_EQ("set_viewport(num_viewports=1)", log[3]);
1629 EXPECT_EQ("set_scissor(num_scissors=1)", log[4]);
1630 EXPECT_EQ("bind_pipeline(pipeline_bind_point=VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline=0x3)",
1631 log[5]);
1632 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[6]);
1633 EXPECT_EQ("end_rendering()", log[7]);
1634 /* Suspend barrier from image_tracker.end(). Reverts GENERAL -> default layout. */
1635 EXPECT_EQ(
1636 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, "
1637 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_COMMANDS_BIT" +
1638 endl() +
1639 " - image_barrier(src_access_mask=VK_ACCESS_SHADER_READ_BIT, "
1640 "VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "
1641 "VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, "
1642 "VK_ACCESS_TRANSFER_WRITE_BIT, "
1643 "dst_access_mask=VK_ACCESS_SHADER_READ_BIT, "
1644 "VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "
1645 "VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, "
1646 "VK_ACCESS_TRANSFER_WRITE_BIT, "
1647 "old_layout=VK_IMAGE_LAYOUT_GENERAL, "
1648 "new_layout=" +
1649 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
1650 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1651 "base_array_layer=0, layer_count=4294967295 )" +
1652 endl() + ")",
1653 log[8]);
1654 /* Transition between scopes: same-layout access-sync barrier. Must use the default layout
1655 * as oldLayout (not GENERAL) to match the actual image layout after suspend. */
1656 EXPECT_EQ(
1657 "pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, "
1658 "dst_stage_mask=VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT" +
1659 endl() +
1660 " - image_barrier(src_access_mask=VK_ACCESS_SHADER_READ_BIT, "
1661 "VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1662 "dst_access_mask=VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "
1663 "VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "
1664 "old_layout=" +
1665 color_attachment_layout_str() +
1666 ", "
1667 "new_layout=" +
1668 color_attachment_layout_str() + ", image=0x1, subresource_range=" + endl() +
1669 " aspect_mask=VK_IMAGE_ASPECT_COLOR_BIT, base_mip_level=0, level_count=4294967295, "
1670 "base_array_layer=0, layer_count=4294967295 )" +
1671 endl() + ")",
1672 log[9]);
1673 EXPECT_EQ("begin_rendering(p_rendering_info=flags=, render_area=" + endl() +
1674 " offset=" + endl() + " x=0, y=0 , extent=" + endl() +
1675 " width=0, height=0 , layer_count=1, view_mask=0, color_attachment_count=1, "
1676 "p_color_attachments=" +
1677 endl() + " image_view=0x2, image_layout=" + color_attachment_layout_str() +
1678 ", "
1679 "resolve_mode=VK_RESOLVE_MODE_NONE, resolve_image_view=0, "
1680 "resolve_image_layout=VK_IMAGE_LAYOUT_UNDEFINED, "
1681 "load_op=VK_ATTACHMENT_LOAD_OP_LOAD, store_op=VK_ATTACHMENT_STORE_OP_STORE" +
1682 endl() + ")",
1683 log[10]);
1684 EXPECT_EQ("draw(vertex_count=4, instance_count=1, first_vertex=0, first_instance=0)", log[11]);
1685 EXPECT_EQ("end_rendering()", log[12]);
1686}
1687
1693TEST_P(VKRenderGraphTestScheduler, begin_draw_storage_dispatch_begin_draw_end_subresource)
1694{
1696 VkHandle<VkImageView> image_view(2u);
1697 VkHandle<VkPipelineLayout> pipeline_layout(4u);
1698 VkHandle<VkPipeline> pipeline(3u);
1699 VKTrackedHandle<VkBuffer> buffer_src(5u);
1700 VKTrackedHandle<VkBuffer> buffer_dst(6u);
1701
1702 resources.add_image(image, true);
1703 buffer_src.set_resource_handle(resources.add_buffer(buffer_src));
1704 buffer_dst.set_resource_handle(resources.add_buffer(buffer_dst));
1705
1706 /* First scope: BEGIN_RENDERING + DRAW(storage) in one group.
1707 * No END_RENDERING in this group, so the after-group-loop suspend fires. */
1708 {
1709 VKResourceAccessInfo access_info = {};
1710 access_info.images.append(
1711 {image,
1712 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1713 VK_IMAGE_ASPECT_COLOR_BIT,
1714 {}});
1715 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1716 begin_rendering.node_data.color_attachments[0].sType =
1717 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1718 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
1719 begin_rendering.node_data.color_attachments[0].imageView = image_view;
1720 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1721 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1722 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1723 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
1724 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1725 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
1726 begin_rendering.node_data.color_attachments;
1727
1728 render_graph->add_node(begin_rendering);
1729 }
1730
1731 {
1732 VKResourceAccessInfo access_info = {};
1733 access_info.images.append({image,
1734 VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
1735 VK_IMAGE_ASPECT_COLOR_BIT,
1736 {}});
1738 node.data.first_instance = 0;
1739 node.data.first_vertex = 0;
1740 node.data.instance_count = 1;
1741 node.data.vertex_count = 4;
1742 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1743 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1744 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1745 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1746 node.data.graphics.viewport.viewports.append(VkViewport{});
1747 node.data.graphics.viewport.scissors.append(VkRect2D{});
1748 VKDrawNode::CreateInfo draw_create_info(access_info);
1749 node.finalize(*render_graph, draw_create_info);
1750 }
1751
1752 /* Non-rendering node splits the group, triggering after-group-loop suspend. */
1753 {
1754 VKCopyBufferNode::CreateInfo copy_buffer = {};
1755 copy_buffer.src_buffer = buffer_src;
1756 copy_buffer.dst_buffer = buffer_dst;
1757 render_graph->add_node(copy_buffer);
1758 }
1759
1760 /* Second scope: BEGIN_RENDERING + DRAW + END_RENDERING in one group. */
1761 {
1762 VKResourceAccessInfo access_info = {};
1763 access_info.images.append(
1764 {image,
1765 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1766 VK_IMAGE_ASPECT_COLOR_BIT,
1767 {}});
1768 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1769 begin_rendering.node_data.color_attachments[0].sType =
1770 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1771 begin_rendering.node_data.color_attachments[0].imageLayout = color_attachment_layout();
1772 begin_rendering.node_data.color_attachments[0].imageView = image_view;
1773 begin_rendering.node_data.color_attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
1774 begin_rendering.node_data.color_attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1775 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1776 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 1;
1777 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1778 begin_rendering.node_data.vk_rendering_info.pColorAttachments =
1779 begin_rendering.node_data.color_attachments;
1780
1781 render_graph->add_node(begin_rendering);
1782 }
1783
1784 {
1785 VKResourceAccessInfo access_info = {};
1786 access_info.images.append(
1787 {image,
1788 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1789 VK_IMAGE_ASPECT_COLOR_BIT,
1790 {}});
1792 node.data.first_instance = 0;
1793 node.data.first_vertex = 0;
1794 node.data.instance_count = 1;
1795 node.data.vertex_count = 4;
1796 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1797 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1798 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1799 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1800 node.data.graphics.viewport.viewports.append(VkViewport{});
1801 node.data.graphics.viewport.scissors.append(VkRect2D{});
1802 VKDrawNode::CreateInfo draw_create_info(access_info);
1803 node.finalize(*render_graph, draw_create_info);
1804 }
1805
1806 {
1807 VKEndRenderingNode::CreateInfo end_rendering = {};
1808 render_graph->add_node(end_rendering);
1809 }
1810
1811 submit(render_graph, command_buffer);
1812
1813 /* Log structure (determined by scheduler topological order):
1814 * [0]: copy_buffer (non-rendering, scheduled first)
1815 * [1]: BEGIN_RENDERING pre-barrier (UNDEFINED -> color_attachment_layout)
1816 * [2]: DRAW(storage) pre-barrier (color_attachment_layout -> GENERAL)
1817 * [3]: begin_rendering
1818 * [4-7]: draw commands (set_viewport, set_scissor, bind_pipeline, draw)
1819 * [8]: end_rendering (after-group-loop in groups_build_commands)
1820 * [9]: after-group-loop suspend barrier (GENERAL -> color_attachment_layout)
1821 * [10]: second scope access barrier (color_attachment_layout -> same, for access sync)
1822 * [11]: begin_rendering (second scope)
1823 * [12]: draw
1824 * [13]: end_rendering
1825 */
1826 ASSERT_EQ(14, log.size());
1827 /* Log[0]: copy buffer. */
1828 EXPECT_NE(log[0].find("copy_buffer"), std::string::npos);
1829 /* Log[1]: initial UNDEFINED -> color_attachment_layout barrier. */
1830 EXPECT_NE(log[1].find("old_layout=VK_IMAGE_LAYOUT_UNDEFINED"), std::string::npos);
1831 EXPECT_NE(log[1].find("new_layout=" + color_attachment_layout_str()), std::string::npos);
1832 /* Log[2]: storage access transition (color_attachment_layout -> GENERAL). */
1833 EXPECT_NE(log[2].find("new_layout=VK_IMAGE_LAYOUT_GENERAL"), std::string::npos);
1834 /* Log[3]: begin_rendering. */
1835 EXPECT_NE(log[3].find("begin_rendering"), std::string::npos);
1836 /* Log[8]: end_rendering (from after-group-loop). */
1837 EXPECT_NE(log[8].find("end_rendering"), std::string::npos);
1838 /* Log[9]: after-group-loop suspend barrier: GENERAL -> color_attachment_layout. */
1839 EXPECT_NE(log[9].find("pipeline_barrier"), std::string::npos);
1840 EXPECT_NE(log[9].find("old_layout=VK_IMAGE_LAYOUT_GENERAL"), std::string::npos);
1841 EXPECT_NE(log[9].find("new_layout=" + color_attachment_layout_str()), std::string::npos);
1842 /* Log[10]: second scope pre-barrier - must use color_attachment_layout (not GENERAL) as
1843 * oldLayout, proving the after-group-loop sync correctly updated resource_state. */
1844 EXPECT_NE(log[10].find("pipeline_barrier"), std::string::npos);
1845 EXPECT_NE(log[10].find("old_layout=" + color_attachment_layout_str()), std::string::npos);
1846 EXPECT_NE(log[10].find("new_layout=" + color_attachment_layout_str()), std::string::npos);
1847 /* Log[13]: final end_rendering. */
1848 EXPECT_NE(log[13].find("end_rendering"), std::string::npos);
1849}
1850
1856TEST_P(VKRenderGraphTestScheduler, begin_draw_storage_end_begin_draw_restart_depth)
1857{
1859 VkHandle<VkImageView> image_view(2u);
1860 VkHandle<VkPipelineLayout> pipeline_layout(4u);
1861 VkHandle<VkPipeline> pipeline(3u);
1862
1863 resources.add_image(image, false);
1864
1865 /* First scope: BEGIN(rendering depth) -> DRAW(storage=GENERAL) -> END. */
1866 {
1867 VKResourceAccessInfo access_info = {};
1868 access_info.images.append(
1869 {image, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_DEPTH_BIT, {}});
1870 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1871 begin_rendering.node_data.depth_attachment.sType =
1872 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1873 begin_rendering.node_data.depth_attachment.imageLayout =
1874 VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
1875 begin_rendering.node_data.depth_attachment.imageView = image_view;
1876 begin_rendering.node_data.depth_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1877 begin_rendering.node_data.depth_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1878 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1879 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 0;
1880 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1881 begin_rendering.node_data.vk_rendering_info.pDepthAttachment =
1882 &begin_rendering.node_data.depth_attachment;
1883
1884 render_graph->add_node(begin_rendering);
1885 }
1886
1887 {
1888 VKResourceAccessInfo access_info = {};
1889 /* Image accessed as shader storage, forcing GENERAL layout. */
1890 access_info.images.append({image,
1891 VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
1892 VK_IMAGE_ASPECT_DEPTH_BIT,
1893 {}});
1895 node.data.first_instance = 0;
1896 node.data.first_vertex = 0;
1897 node.data.instance_count = 1;
1898 node.data.vertex_count = 4;
1899 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1900 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1901 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1902 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1903 node.data.graphics.viewport.viewports.append(VkViewport{});
1904 node.data.graphics.viewport.scissors.append(VkRect2D{});
1905 VKDrawNode::CreateInfo draw_create_info(access_info);
1906 node.finalize(*render_graph, draw_create_info);
1907 }
1908
1909 {
1910 VKEndRenderingNode::CreateInfo end_rendering = {};
1911 render_graph->add_node(end_rendering);
1912 }
1913
1914 /* Second scope: BEGIN(rendering depth) -> DRAW (storage=DEPTH_ATTACHMENT_OPTIMAL) -> END. */
1915 {
1916 VKResourceAccessInfo access_info = {};
1917 access_info.images.append(
1918 {image, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, VK_IMAGE_ASPECT_DEPTH_BIT, {}});
1919 VKBeginRenderingNode::CreateInfo begin_rendering(access_info);
1920 begin_rendering.node_data.depth_attachment.sType =
1921 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
1922 begin_rendering.node_data.depth_attachment.imageLayout =
1923 VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
1924 begin_rendering.node_data.depth_attachment.imageView = image_view;
1925 begin_rendering.node_data.depth_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
1926 begin_rendering.node_data.depth_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1927 begin_rendering.node_data.vk_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
1928 begin_rendering.node_data.vk_rendering_info.colorAttachmentCount = 0;
1929 begin_rendering.node_data.vk_rendering_info.layerCount = 1;
1930 begin_rendering.node_data.vk_rendering_info.pDepthAttachment =
1931 &begin_rendering.node_data.depth_attachment;
1932
1933 render_graph->add_node(begin_rendering);
1934 }
1935
1936 {
1937 VKResourceAccessInfo access_info = {};
1938 access_info.images.append(
1939 {image, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_DEPTH_BIT, {}});
1941 node.data.first_instance = 0;
1942 node.data.first_vertex = 0;
1943 node.data.instance_count = 1;
1944 node.data.vertex_count = 4;
1945 node.data.graphics.pipeline_data.push_constants_range = IndexRange(0);
1946 node.data.graphics.pipeline_data.vk_descriptor_set = VK_NULL_HANDLE;
1947 node.data.graphics.pipeline_data.vk_pipeline = pipeline;
1948 node.data.graphics.pipeline_data.vk_pipeline_layout = pipeline_layout;
1949 node.data.graphics.viewport.viewports.append(VkViewport{});
1950 node.data.graphics.viewport.scissors.append(VkRect2D{});
1951 VKDrawNode::CreateInfo draw_create_info(access_info);
1952 node.finalize(*render_graph, draw_create_info);
1953 }
1954
1955 {
1956 VKEndRenderingNode::CreateInfo end_rendering = {};
1957 render_graph->add_node(end_rendering);
1958 }
1959
1960 submit(render_graph, command_buffer);
1961
1962 /* Verify there is a barrier transitioning GENERAL -> DEPTH_ATTACHMENT_OPTIMAL
1963 * that appears after end_rendering of the first scope and before begin_rendering
1964 * of the second scope. */
1965 bool found_restart_barrier = false;
1966 bool passed_first_scope_end = false;
1967 for (const std::string &entry : log) {
1968 if (entry == "end_rendering()") {
1969 passed_first_scope_end = true;
1970 continue;
1971 }
1972 if (passed_first_scope_end && entry.find("pipeline_barrier") != std::string::npos &&
1973 entry.find("old_layout=VK_IMAGE_LAYOUT_GENERAL") != std::string::npos &&
1974 entry.find("new_layout=VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL") != std::string::npos)
1975 {
1976 found_restart_barrier = true;
1977 break;
1978 }
1979 }
1980 EXPECT_TRUE(found_restart_barrier)
1981 << "Missing restart barrier to transition depth attachment from GENERAL layout back to "
1982 "DEPTH_ATTACHMENT_OPTIMAL before begin_rendering.";
1983}
1984
1985INSTANTIATE_TEST_SUITE_P(, VKRenderGraphTestScheduler, ::testing::Values(true, false));
1986
1987} // namespace blender::gpu::render_graph
constexpr IndexRange()=default
#define log
#define EXPECT_NE(result, expect)
#define EXPECT_TRUE(result)
INSTANTIATE_TEST_SUITE_P(, VKRenderGraphTestRender, ::testing::Values(true, false))
TEST_P(VKRenderGraphTestRender, begin_clear_attachments_end_read_back)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
VKResourceWithHandle< VkBuffer > dst_buffer
VKResourceWithHandle< VkBuffer > src_buffer
int32_t mip_levels
The number of mip-levels to copy.
Convenience wrapper for tracked resources.