forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvklayertests_dynamic_rendering.cpp
7362 lines (5762 loc) · 332 KB
/
vklayertests_dynamic_rendering.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2015-2023 The Khronos Group Inc.
* Copyright (c) 2015-2023 Valve Corporation
* Copyright (c) 2015-2023 LunarG, Inc.
* Copyright (c) 2015-2023 Google, Inc.
* Modifications Copyright (C) 2020-2022 Advanced Micro Devices, Inc. All rights reserved.
* Modifications Copyright (C) 2021-2022 ARM, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
#include "cast_utils.h"
#include "layer_validation_tests.h"
class DynamicRenderingCommandBufferInheritanceRenderingInfoTest : public VkLayerTest {
public:
void Test(bool const useLinearColorAttachmen);
};
void DynamicRenderingCommandBufferInheritanceRenderingInfoTest::Test(bool const useLinearColorAttachment) {
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
if (useLinearColorAttachment) {
AddRequiredExtensions(VK_NV_LINEAR_COLOR_ATTACHMENT_EXTENSION_NAME);
}
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
GTEST_SKIP() << "At least Vulkan version 1.2 is required";
}
auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
auto linear_color_attachment = LvlInitStruct<VkPhysicalDeviceLinearColorAttachmentFeaturesNV>();
if (IsExtensionsEnabled(VK_NV_LINEAR_COLOR_ATTACHMENT_EXTENSION_NAME)) {
dynamic_rendering_features.pNext = &linear_color_attachment;
}
VkPhysicalDeviceFeatures2 features2 = GetPhysicalDeviceFeatures2(dynamic_rendering_features);
if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
GTEST_SKIP() << "Test requires (unsupported) dynamicRendering";
}
if (useLinearColorAttachment && !linear_color_attachment.linearColorAttachment) {
GTEST_SKIP() << "Test requires linearColorAttachment";
}
features2.features.variableMultisampleRate = VK_FALSE;
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
VkPhysicalDeviceMultiviewProperties multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
VkPhysicalDeviceProperties2 pd_props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&multiview_props);
GetPhysicalDeviceProperties2(pd_props2);
VkFormat color_format = VK_FORMAT_D32_SFLOAT;
auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>();
cmd_buffer_inheritance_rendering_info.colorAttachmentCount = 1;
cmd_buffer_inheritance_rendering_info.pColorAttachmentFormats = &color_format;
cmd_buffer_inheritance_rendering_info.depthAttachmentFormat = VK_FORMAT_R8G8B8_UNORM;
cmd_buffer_inheritance_rendering_info.stencilAttachmentFormat = VK_FORMAT_R8G8B8_SNORM;
cmd_buffer_inheritance_rendering_info.viewMask = 1 << multiview_props.maxMultiviewViewCount;
auto sample_count_info_amd = LvlInitStruct<VkAttachmentSampleCountInfoAMD>();
sample_count_info_amd.pNext = &cmd_buffer_inheritance_rendering_info;
sample_count_info_amd.colorAttachmentCount = 2;
auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
cmd_buffer_inheritance_info.pNext = &sample_count_info_amd;
auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>();
cmd_buffer_allocate_info.commandPool = m_commandPool->handle();
cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
cmd_buffer_allocate_info.commandBufferCount = 0x1;
VkCommandBuffer secondary_cmd_buffer;
VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer);
ASSERT_VK_SUCCESS(err);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06003");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-colorAttachmentCount-06004");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-variableMultisampleRate-06005");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06007");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-multiview-06008");
if (multiview_props.maxMultiviewViewCount != 32) {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-viewMask-06009");
}
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-stencilAttachmentFormat-06199");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06200");
if (linear_color_attachment.linearColorAttachment) {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit,
"VUID-VkCommandBufferInheritanceRenderingInfoKHR-pColorAttachmentFormats-06492");
} else {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit,
"VUID-VkCommandBufferInheritanceRenderingInfo-pColorAttachmentFormats-06006");
}
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06540");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-stencilAttachmentFormat-06541");
VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
m_errorMonitor->VerifyFound();
}
TEST_F(DynamicRenderingCommandBufferInheritanceRenderingInfoTest, Core) {
TEST_DESCRIPTION("VkCommandBufferInheritanceRenderingInfoKHR Dynamic Rendering Tests.");
Test(false);
}
TEST_F(DynamicRenderingCommandBufferInheritanceRenderingInfoTest, LinearColorAttachment) {
TEST_DESCRIPTION("VkCommandBufferInheritanceRenderingInfoKHR Dynamic Rendering Tests with linearColorAttachment.");
Test(true);
}
TEST_F(VkLayerTest, DynamicRenderingCommandDraw) {
TEST_DESCRIPTION("vkCmdDraw* Dynamic Rendering Tests.");
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
GTEST_SKIP() << "At least Vulkan version 1.2 is required";
}
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(dynamic_rendering_features);
if (!dynamic_rendering_features.dynamicRendering) {
GTEST_SKIP() << "Test requires (unsupported) dynamicRendering , skipping.";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
auto ds_state = LvlInitStruct<VkPipelineDepthStencilStateCreateInfo>();
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
pipe.AddDefaultColorAttachment();
pipe.SetDepthStencil(&ds_state);
VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
const VkPipelineLayoutObj pl(m_device, {&dsl});
VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
pipeline_rendering_info.depthAttachmentFormat = depth_format;
pipeline_rendering_info.stencilAttachmentFormat = depth_format;
auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>();
multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT;
auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
pipe.InitGraphicsPipelineCreateInfo(&create_info);
create_info.pMultisampleState = &multisample_state_create_info;
create_info.renderPass = VkRenderPass(0x1);
create_info.pNext = &pipeline_rendering_info;
VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
ASSERT_VK_SUCCESS(err);
VkViewport viewport = {0, 0, 16, 16, 0, 1};
VkRect2D scissor = {{0, 0}, {16, 16}};
VkImageObj image(m_device);
image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR, 0);
ASSERT_TRUE(image.initialized());
VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
nullptr,
0,
image.handle(),
VK_IMAGE_VIEW_TYPE_2D,
depth_format,
{VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY},
{VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
vk_testing::ImageView depth_image_view(*m_device, ivci);
VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
depth_attachment.imageView = depth_image_view.handle();
VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
begin_rendering_info.pDepthAttachment = &depth_attachment;
begin_rendering_info.pStencilAttachment = &depth_attachment;
begin_rendering_info.layerCount = 1;
m_commandBuffer->begin();
m_commandBuffer->BeginRendering(begin_rendering_info);
vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
vk::CmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
vk::CmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190");
vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
m_errorMonitor->VerifyFound();
m_commandBuffer->EndRendering();
m_commandBuffer->end();
}
TEST_F(VkLayerTest, DynamicRenderingCmdClearAttachmentTests) {
TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments with Dynamic Rendering");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(dynamic_rendering_features);
if (!dynamic_rendering_features.dynamicRendering) {
GTEST_SKIP() << "Test requires (unsupported) dynamicRendering";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
VkImageFormatProperties image_format_properties{};
vk::GetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), m_renderTargets[0]->format(), VK_IMAGE_TYPE_2D,
VK_IMAGE_TILING_OPTIMAL, m_renderTargets[0]->usage(), 0, &image_format_properties);
if (image_format_properties.maxArrayLayers < 4) {
GTEST_SKIP() << "Test needs to create image 2D array of 4 image view, but VkImageFormatProperties::maxArrayLayers is < 4. "
"Skipping test.";
}
// render pass instance is going to have 2 layers, and image view 4 layers,
// to make sure that considered layer count is the one coming from frame buffer
// (test would not fail if layer count used to do validation was 4)
VkImageObj render_target(m_device);
assert(!m_renderTargets.empty());
const auto render_target_ci = VkImageObj::ImageCreateInfo2D(
m_renderTargets[0]->width(), m_renderTargets[0]->height(), m_renderTargets[0]->create_info().mipLevels, 4,
m_renderTargets[0]->format(), m_renderTargets[0]->usage(), VK_IMAGE_TILING_OPTIMAL);
render_target.Init(render_target_ci, 0);
auto ivci = LvlInitStruct<VkImageViewCreateInfo>();
ivci.image = render_target.handle();
ivci.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
ivci.format = render_target_ci.format;
ivci.subresourceRange.layerCount = render_target_ci.arrayLayers;
ivci.subresourceRange.baseMipLevel = 0;
ivci.subresourceRange.levelCount = 1;
ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
ivci.components.r = VK_COMPONENT_SWIZZLE_R;
ivci.components.g = VK_COMPONENT_SWIZZLE_G;
ivci.components.b = VK_COMPONENT_SWIZZLE_B;
ivci.components.a = VK_COMPONENT_SWIZZLE_A;
vk_testing::ImageView render_target_view(*m_device, ivci);
// Create secondary command buffer
auto secondary_cmd_buffer_alloc_info = LvlInitStruct<VkCommandBufferAllocateInfo>();
secondary_cmd_buffer_alloc_info.commandPool = m_commandPool->handle();
secondary_cmd_buffer_alloc_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
secondary_cmd_buffer_alloc_info.commandBufferCount = 1;
vk_testing::CommandBuffer secondary_cmd_buffer(*m_device, secondary_cmd_buffer_alloc_info);
auto inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>();
inheritance_rendering_info.colorAttachmentCount = 1;
inheritance_rendering_info.pColorAttachmentFormats = &render_target_ci.format;
inheritance_rendering_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
VkCommandBufferInheritanceInfo secondary_cmd_buffer_inheritance_info =
LvlInitStruct<VkCommandBufferInheritanceInfo>(&inheritance_rendering_info);
VkCommandBufferBeginInfo secondary_cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
secondary_cmd_buffer_begin_info.flags =
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
secondary_cmd_buffer_begin_info.pInheritanceInfo = &secondary_cmd_buffer_inheritance_info;
// Create clear rect
VkClearAttachment color_attachment;
color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
color_attachment.clearValue.color.float32[0] = 1.0;
color_attachment.clearValue.color.float32[1] = 1.0;
color_attachment.clearValue.color.float32[2] = 1.0;
color_attachment.clearValue.color.float32[3] = 1.0;
color_attachment.colorAttachment = 0;
VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}, 0, 1};
auto clear_cmds = [this, &color_attachment](VkCommandBuffer cmd_buffer, VkClearRect clear_rect) {
// extent too wide
VkClearRect clear_rect_too_large = clear_rect;
clear_rect_too_large.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
clear_rect_too_large.rect.extent.height = clear_rect_too_large.rect.extent.height / 2;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdClearAttachments-pRects-00016");
vk::CmdClearAttachments(cmd_buffer, 1, &color_attachment, 1, &clear_rect_too_large);
// baseLayer < render pass instance layer count
clear_rect.baseArrayLayer = 1;
clear_rect.layerCount = 1;
vk::CmdClearAttachments(cmd_buffer, 1, &color_attachment, 1, &clear_rect);
// baseLayer + layerCount <= render pass instance layer count
clear_rect.baseArrayLayer = 0;
clear_rect.layerCount = 2;
vk::CmdClearAttachments(cmd_buffer, 1, &color_attachment, 1, &clear_rect);
// baseLayer >= render pass instance layer count
clear_rect.baseArrayLayer = 2;
clear_rect.layerCount = 1;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdClearAttachments-pRects-06937");
vk::CmdClearAttachments(cmd_buffer, 1, &color_attachment, 1, &clear_rect);
// baseLayer + layerCount > render pass instance layer count
clear_rect.baseArrayLayer = 0;
clear_rect.layerCount = 4;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdClearAttachments-pRects-06937");
vk::CmdClearAttachments(cmd_buffer, 1, &color_attachment, 1, &clear_rect);
};
// Register clear commands to secondary command buffer
secondary_cmd_buffer.begin(&secondary_cmd_buffer_begin_info);
clear_cmds(secondary_cmd_buffer.handle(), clear_rect);
secondary_cmd_buffer.end();
m_commandBuffer->begin();
auto color_attachment_info = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
color_attachment_info.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
color_attachment_info.imageView = render_target_view.handle();
auto begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
begin_rendering_info.flags = VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR;
begin_rendering_info.renderArea = clear_rect.rect;
begin_rendering_info.layerCount = 2;
begin_rendering_info.colorAttachmentCount = 1;
begin_rendering_info.pColorAttachments = &color_attachment_info;
// Execute secondary command buffer
m_commandBuffer->BeginRendering(begin_rendering_info);
vk::CmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_cmd_buffer.handle());
m_errorMonitor->VerifyFound();
m_commandBuffer->EndRendering();
// Execute same commands as previously, but in a primary command buffer
begin_rendering_info.flags = 0;
m_commandBuffer->BeginRendering(begin_rendering_info);
clear_cmds(m_commandBuffer->handle(), clear_rect);
m_errorMonitor->VerifyFound();
m_commandBuffer->EndRendering();
m_commandBuffer->end();
}
TEST_F(VkLayerTest, DynamicRenderingClearAttachments) {
TEST_DESCRIPTION("Call CmdClearAttachments with invalid aspect masks.");
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
GTEST_SKIP() << "At least Vulkan version 1.2 is required.";
}
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(dynamic_rendering_features);
if (!dynamic_rendering_features.dynamicRendering) {
GTEST_SKIP() << "Test requires (unsupported) " VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME ", skipping\n";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
// Create color image
const VkFormat color_format = VK_FORMAT_R32_SFLOAT;
VkImageObj color_image(m_device);
auto imci = LvlInitStruct<VkImageCreateInfo>();
imci.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
imci.imageType = VK_IMAGE_TYPE_2D;
imci.format = color_format;
imci.extent = {32, 32, 1};
imci.mipLevels = 1;
imci.arrayLayers = 1;
imci.samples = VK_SAMPLE_COUNT_1_BIT;
imci.tiling = VK_IMAGE_TILING_OPTIMAL;
imci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
imci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
imci.queueFamilyIndexCount = 0;
imci.pQueueFamilyIndices = nullptr;
imci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
color_image.Init(imci);
ASSERT_TRUE(color_image.initialized());
// Create correct color image view
VkImageViewCreateInfo color_ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
nullptr,
0,
color_image.handle(),
VK_IMAGE_VIEW_TYPE_2D,
color_format,
{VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY},
{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
vk_testing::ImageView color_image_view(*m_device, color_ivci);
// Create depth image
const VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
VkImageObj depth_image(m_device);
depth_image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR);
ASSERT_TRUE(depth_image.initialized());
// Create depth image view
VkImageViewCreateInfo depth_stencil_ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
nullptr,
0,
depth_image.handle(),
VK_IMAGE_VIEW_TYPE_2D,
depth_format,
{VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY},
{VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1}};
vk_testing::ImageView depth_image_view(*m_device, depth_stencil_ivci);
depth_stencil_ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
vk_testing::ImageView stencil_image_view(*m_device, depth_stencil_ivci);
depth_stencil_ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
vk_testing::ImageView depth_stencil_image_view(*m_device, depth_stencil_ivci);
// Dynamic rendering structs
VkRect2D rect{{0, 0}, {32, 32}};
auto depth_attachment_info = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
depth_attachment_info.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL_KHR;
depth_attachment_info.imageView = depth_stencil_image_view.handle();
auto stencil_attachment_info = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stencil_attachment_info.imageLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL;
stencil_attachment_info.imageView = depth_stencil_image_view.handle();
auto color_attachment_info = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
color_attachment_info.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
auto begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
begin_rendering_info.renderArea = rect;
begin_rendering_info.layerCount = 1;
begin_rendering_info.pDepthAttachment = &depth_attachment_info;
begin_rendering_info.pStencilAttachment = &stencil_attachment_info;
begin_rendering_info.colorAttachmentCount = 1;
begin_rendering_info.pColorAttachments = &color_attachment_info;
begin_rendering_info.viewMask = 0;
// Render pass structs
std::array<VkAttachmentDescription, 2> attachments = {
{{0, depth_stencil_ivci.format, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE,
VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
{0, color_ivci.format, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE,
VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}}};
std::array<VkAttachmentReference, 4> attachment_references = {{{0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
{1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
{VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
{1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}}};
std::array<VkSubpassDescription, 2> subpass_descs = {};
subpass_descs[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass_descs[0].colorAttachmentCount = 1;
subpass_descs[0].pColorAttachments = &attachment_references[1];
subpass_descs[0].pDepthStencilAttachment = &attachment_references[0];
subpass_descs[1].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass_descs[1].colorAttachmentCount = 3;
subpass_descs[1].pColorAttachments = &attachment_references[1];
subpass_descs[1].pDepthStencilAttachment = &attachment_references[0];
VkSubpassDependency subpass_dependency = {};
subpass_dependency.srcSubpass = 0;
subpass_dependency.dstSubpass = 1;
subpass_dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
subpass_dependency.dstStageMask = subpass_dependency.srcStageMask;
subpass_dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
subpass_dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
subpass_dependency.dependencyFlags = 0;
auto renderpass_ci = LvlInitStruct<VkRenderPassCreateInfo>();
renderpass_ci.attachmentCount = static_cast<uint32_t>(attachments.size());
renderpass_ci.pAttachments = attachments.data();
renderpass_ci.subpassCount = static_cast<uint32_t>(subpass_descs.size());
renderpass_ci.pSubpasses = subpass_descs.data();
renderpass_ci.dependencyCount = 1;
renderpass_ci.pDependencies = &subpass_dependency;
VkRenderPass renderpass = VK_NULL_HANDLE;
VkResult err = vk::CreateRenderPass(m_device->handle(), &renderpass_ci, nullptr, &renderpass);
ASSERT_VK_SUCCESS(err);
std::array<VkImageView, 2> renderpass_image_views = {depth_stencil_image_view.handle(), color_image_view.handle()};
auto framebuffer_ci = LvlInitStruct<VkFramebufferCreateInfo>();
framebuffer_ci.renderPass = renderpass;
framebuffer_ci.attachmentCount = 2;
framebuffer_ci.pAttachments = renderpass_image_views.data();
framebuffer_ci.width = 32;
framebuffer_ci.height = 32;
framebuffer_ci.layers = 1;
auto renderpass_bi = LvlInitStruct<VkRenderPassBeginInfo>();
renderpass_bi.renderPass = renderpass;
renderpass_bi.renderArea = rect;
renderpass_bi.clearValueCount = 2;
std::array<VkClearValue, 2> renderpass_clear_values;
renderpass_clear_values[0].depthStencil.depth = 1.0f;
std::fill(&renderpass_clear_values[0].color.float32[0], &renderpass_clear_values[0].color.float32[0] + 4, 0.0f);
renderpass_bi.pClearValues = renderpass_clear_values.data();
auto clear_cmd_test = [&](const bool use_dynamic_rendering) {
std::array<VkFramebuffer, 4> framebuffers = {VK_NULL_HANDLE};
m_commandBuffer->begin();
// Try to clear stencil, but image view does not have stencil aspect
// This is a valid clear because the ImageView aspect are ignored
// https://gitlab.khronos.org/vulkan/vulkan/-/merge_requests/5733#note_398961
{
if (use_dynamic_rendering) {
depth_attachment_info.imageView = depth_image_view.handle();
stencil_attachment_info.imageView = depth_image_view.handle();
m_commandBuffer->BeginRendering(begin_rendering_info);
} else {
renderpass_image_views[0] = depth_image_view.handle();
const VkResult err = vk::CreateFramebuffer(m_device->handle(), &framebuffer_ci, nullptr, &framebuffers[0]);
ASSERT_VK_SUCCESS(err);
renderpass_bi.framebuffer = framebuffers[0];
m_commandBuffer->BeginRenderPass(renderpass_bi);
}
VkClearAttachment clear_stencil_attachment;
clear_stencil_attachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
clear_stencil_attachment.clearValue.depthStencil.depth = 1.0f;
clear_stencil_attachment.clearValue.depthStencil.stencil = 0;
VkClearRect clear_rect{rect, 0, 1};
vk::CmdClearAttachments(m_commandBuffer->handle(), 1, &clear_stencil_attachment, 1, &clear_rect);
if (use_dynamic_rendering) {
m_commandBuffer->EndRendering();
depth_attachment_info.imageView = depth_stencil_image_view.handle();
stencil_attachment_info.imageView = depth_stencil_image_view.handle();
} else {
m_commandBuffer->NextSubpass();
m_commandBuffer->EndRenderPass();
renderpass_image_views[0] = depth_stencil_image_view.handle();
}
}
// Try to clear depth, but image view does not have depth aspect (valid, see stencil above)
{
if (use_dynamic_rendering) {
depth_attachment_info.imageView = stencil_image_view.handle();
stencil_attachment_info.imageView = stencil_image_view.handle();
m_commandBuffer->BeginRendering(begin_rendering_info);
} else {
renderpass_image_views[0] = stencil_image_view.handle();
const VkResult err = vk::CreateFramebuffer(m_device->handle(), &framebuffer_ci, nullptr, &framebuffers[1]);
ASSERT_VK_SUCCESS(err);
renderpass_bi.framebuffer = framebuffers[1];
m_commandBuffer->BeginRenderPass(renderpass_bi);
}
VkClearAttachment clear_depth_attachment;
clear_depth_attachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
clear_depth_attachment.clearValue.depthStencil.depth = 1.0f;
VkClearRect clear_rect{rect, 0, 1};
vk::CmdClearAttachments(m_commandBuffer->handle(), 1, &clear_depth_attachment, 1, &clear_rect);
if (use_dynamic_rendering) {
m_commandBuffer->EndRendering();
depth_attachment_info.imageView = depth_stencil_image_view.handle();
stencil_attachment_info.imageView = depth_stencil_image_view.handle();
} else {
m_commandBuffer->NextSubpass();
m_commandBuffer->EndRenderPass();
renderpass_image_views[0] = depth_stencil_image_view.handle();
}
}
{
if (!use_dynamic_rendering) {
const VkResult err = vk::CreateFramebuffer(m_device->handle(), &framebuffer_ci, nullptr, &framebuffers[2]);
ASSERT_VK_SUCCESS(err);
renderpass_bi.framebuffer = framebuffers[2];
}
// Try to clear color, but aspect also has depth
{
// begin rendering
if (use_dynamic_rendering) {
m_commandBuffer->BeginRendering(begin_rendering_info);
} else {
m_commandBuffer->BeginRenderPass(renderpass_bi);
}
// issue clear cmd
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkClearAttachment-aspectMask-00019");
VkClearAttachment clear_depth_attachment;
clear_depth_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
clear_depth_attachment.colorAttachment = 0;
VkClearRect clear_rect{rect, 0, 1};
vk::CmdClearAttachments(m_commandBuffer->handle(), 1, &clear_depth_attachment, 1, &clear_rect);
m_errorMonitor->VerifyFound();
// end rendering
if (use_dynamic_rendering) {
m_commandBuffer->EndRendering();
} else {
m_commandBuffer->NextSubpass();
m_commandBuffer->EndRenderPass();
}
}
// Try to clear color, but color attachment is out of range
{
// begin rendering
if (use_dynamic_rendering) {
m_commandBuffer->BeginRendering(begin_rendering_info);
} else {
m_commandBuffer->BeginRenderPass(renderpass_bi);
}
// issue clear cmd
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdClearAttachments-aspectMask-07271");
VkClearAttachment clear_depth_attachment;
clear_depth_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
clear_depth_attachment.colorAttachment = 2;
VkClearRect clear_rect{rect, 0, 1};
vk::CmdClearAttachments(m_commandBuffer->handle(), 1, &clear_depth_attachment, 1, &clear_rect);
m_errorMonitor->VerifyFound();
// end rendering
if (use_dynamic_rendering) {
m_commandBuffer->EndRendering();
} else {
m_commandBuffer->NextSubpass();
m_commandBuffer->EndRenderPass();
}
}
// Clear color, subpass has unused attachments
if (!use_dynamic_rendering) {
m_commandBuffer->BeginRenderPass(renderpass_bi);
m_commandBuffer->NextSubpass();
std::array<VkClearAttachment, 4> clears = {{{VK_IMAGE_ASPECT_DEPTH_BIT, 0},
{VK_IMAGE_ASPECT_COLOR_BIT, 0},
{VK_IMAGE_ASPECT_COLOR_BIT, 1},
{VK_IMAGE_ASPECT_COLOR_BIT, 2}}};
VkClearRect clear_rect{rect, 0, 1};
vk::CmdClearAttachments(m_commandBuffer->handle(), static_cast<uint32_t>(clears.size()), clears.data(), 1,
&clear_rect);
m_commandBuffer->EndRenderPass();
}
}
m_commandBuffer->end();
{
delete m_commandBuffer;
m_commandBuffer = new VkCommandBufferObj(m_device, m_commandPool);
std::unique_ptr<VkCommandBufferObj> secondary_cmd_buffer(
new VkCommandBufferObj(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY));
auto inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfo>();
const VkFormat color_format = VK_FORMAT_R32_SFLOAT;
inheritance_rendering_info.colorAttachmentCount = begin_rendering_info.colorAttachmentCount;
inheritance_rendering_info.pColorAttachmentFormats = &color_format;
inheritance_rendering_info.depthAttachmentFormat = depth_format;
inheritance_rendering_info.stencilAttachmentFormat = depth_format;
inheritance_rendering_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
VkCommandBufferInheritanceInfo cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
if (use_dynamic_rendering) {
cmd_buffer_inheritance_info.pNext = &inheritance_rendering_info;
} else {
const VkResult err = vk::CreateFramebuffer(m_device->handle(), &framebuffer_ci, nullptr, &framebuffers[3]);
ASSERT_VK_SUCCESS(err);
renderpass_bi.framebuffer = framebuffers[3];
cmd_buffer_inheritance_info.renderPass = renderpass;
cmd_buffer_inheritance_info.subpass = 0;
cmd_buffer_inheritance_info.framebuffer = framebuffers[3];
}
secondary_cmd_buffer->begin(&cmd_buffer_begin_info);
// issue clear cmd to secondary cmd buffer
std::array<VkClearAttachment, 3> clear_attachments = {};
clear_attachments[0].aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
clear_attachments[0].clearValue.depthStencil.depth = 1.0f;
clear_attachments[1].aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
clear_attachments[1].clearValue.depthStencil.depth = 1.0f;
clear_attachments[2].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
clear_attachments[2].colorAttachment = 0;
VkClearRect clear_rect{rect, 0, 1};
// Expected to succeeed
vk::CmdClearAttachments(secondary_cmd_buffer->handle(), static_cast<uint32_t>(clear_attachments.size()),
clear_attachments.data(), 1, &clear_rect);
// Clear color out of range
VkClearAttachment clear_color_out_of_range{VK_IMAGE_ASPECT_COLOR_BIT, 1, VkClearValue{}};
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdClearAttachments-aspectMask-07271");
vk::CmdClearAttachments(secondary_cmd_buffer->handle(), 1, &clear_color_out_of_range, 1, &clear_rect);
m_errorMonitor->VerifyFound();
secondary_cmd_buffer->end();
m_commandBuffer->begin();
// begin rendering
if (use_dynamic_rendering) {
begin_rendering_info.flags |= VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT;
m_commandBuffer->BeginRendering(begin_rendering_info);
begin_rendering_info.flags &= ~VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT;
} else {
m_commandBuffer->BeginRenderPass(renderpass_bi, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
}
vk::CmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_cmd_buffer->handle());
// end rendering
if (use_dynamic_rendering) {
m_commandBuffer->EndRendering();
} else {
m_commandBuffer->NextSubpass();
m_commandBuffer->EndRenderPass();
}
m_commandBuffer->end();
}
for (auto framebuffer : framebuffers) {
vk::DestroyFramebuffer(m_device->handle(), framebuffer, nullptr);
}
};
clear_cmd_test(true);
delete m_commandBuffer;
m_commandBuffer = new VkCommandBufferObj(m_device, m_commandPool);
clear_cmd_test(false);
vk::DestroyRenderPass(m_device->handle(), renderpass, nullptr);
}
TEST_F(VkLayerTest, DynamicRenderingGraphicsPipelineCreateInfo) {
TEST_DESCRIPTION("Test graphics pipeline creation with dynamic rendering.");
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
GTEST_SKIP() << "At least Vulkan version 1.2 is required";
}
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(dynamic_rendering_features);
if (!dynamic_rendering_features.dynamicRendering) {
GTEST_SKIP() << "Test requires (unsupported) dynamicRendering";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
if (m_device->props.limits.maxGeometryOutputVertices == 0) {
GTEST_SKIP() << "Device doesn't support required maxGeometryOutputVertices";
}
const VkPipelineLayoutObj pl(m_device);
VkPipelineObj pipe(m_device);
VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
auto color_blend_state_create_info = LvlInitStruct<VkPipelineColorBlendStateCreateInfo>();
color_blend_state_create_info.attachmentCount = 1;
color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
VkFormat color_format[2] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_D32_SFLOAT_S8_UINT};
auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
pipeline_rendering_info.colorAttachmentCount = 2;
pipeline_rendering_info.pColorAttachmentFormats = &color_format[0];
pipeline_rendering_info.viewMask = 0x2;
pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
auto pipeline_tessellation_state_info = LvlInitStruct<VkPipelineTessellationStateCreateInfo>();
pipeline_tessellation_state_info.patchControlPoints = 1;
auto pipeline_input_assembly_state_info = LvlInitStruct<VkPipelineInputAssemblyStateCreateInfo>();
pipeline_input_assembly_state_info.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
VkShaderObj gs(this, bindStateGeomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT);
VkShaderObj te(this, bindStateTeshaderText, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
VkShaderObj tc(this, bindStateTscShaderText, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
pipe.AddShader(&vs);
pipe.AddShader(&gs);
pipe.AddShader(&te);
pipe.AddShader(&tc);
pipe.AddShader(&fs);
pipe.InitGraphicsPipelineCreateInfo(&create_info);
create_info.pColorBlendState = &color_blend_state_create_info;
create_info.pNext = &pipeline_rendering_info;
create_info.pTessellationState = &pipeline_tessellation_state_info;
create_info.pInputAssemblyState = &pipeline_input_assembly_state_info;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06053");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06581");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06055");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06057");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06058");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-multiview-06577");
pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
m_errorMonitor->VerifyFound();
create_info.pColorBlendState = nullptr;
pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
pipeline_rendering_info.viewMask = 0x0;
pipeline_rendering_info.colorAttachmentCount = 1;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06054");
pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
m_errorMonitor->VerifyFound();
color_format[0] = VK_FORMAT_D32_SFLOAT_S8_UINT;
color_blend_attachment_state.blendEnable = VK_TRUE;
create_info.pColorBlendState = &color_blend_state_create_info;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06581");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06062");
pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
m_errorMonitor->VerifyFound();
color_format[0] = VK_FORMAT_R8G8B8A8_UNORM;
auto ds_ci = LvlInitStruct<VkPipelineDepthStencilStateCreateInfo>();
ds_ci.flags = VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_ARM;
color_blend_state_create_info.flags = VK_PIPELINE_COLOR_BLEND_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_BIT_ARM;
create_info.pColorBlendState = &color_blend_state_create_info;
create_info.pDepthStencilState = &ds_ci;
create_info.renderPass = VK_NULL_HANDLE;
pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06482");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06483");
pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, DynamicRenderingWithMismatchingViewMask) {
TEST_DESCRIPTION("Draw with Dynamic Rendering and a mismatching viewMask");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
auto multiview_features = LvlInitStruct<VkPhysicalDeviceMultiviewFeatures>();
auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(&multiview_features);
auto features2 = GetPhysicalDeviceFeatures2(dynamic_rendering_features);
if (!dynamic_rendering_features.dynamicRendering) {
GTEST_SKIP() << "Test requires (unsupported) dynamicRendering";
}
if (!multiview_features.multiview) {
GTEST_SKIP() << "Test requires (unsupported) multview";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
char const *fsSource = R"glsl(
#version 450
layout(location=0) out vec4 color;
void main() {
color = vec4(1.0f);
}
)glsl";
VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
VkPipelineObj pipe(m_device);
pipe.AddShader(&vs);
pipe.AddShader(&fs);
pipe.AddDefaultColorAttachment();
VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
const VkPipelineLayoutObj pl(m_device, {&dsl});
VkFormat color_formats = VK_FORMAT_UNDEFINED;
auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
pipeline_rendering_info.colorAttachmentCount = 1;
pipeline_rendering_info.pColorAttachmentFormats = &color_formats;
pipeline_rendering_info.viewMask = 1;
VkViewport viewport = {0, 0, 16, 16, 0, 1};
VkRect2D scissor = {{0, 0}, {16, 16}};
m_viewports.push_back(viewport);
m_scissors.push_back(scissor);
pipe.SetViewport(m_viewports);
pipe.SetScissor(m_scissors);
auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
pipe.InitGraphicsPipelineCreateInfo(&create_info);
create_info.pNext = &pipeline_rendering_info;
pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
begin_rendering_info.colorAttachmentCount = 1;
begin_rendering_info.pColorAttachments = &color_attachment;
begin_rendering_info.viewMask = 2;
begin_rendering_info.layerCount = 1;
m_commandBuffer->begin();
m_commandBuffer->BeginRendering(begin_rendering_info);
vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-viewMask-06178");
m_commandBuffer->Draw(1, 1, 0, 0);
m_errorMonitor->VerifyFound();
m_commandBuffer->EndRendering();
m_commandBuffer->end();
}
TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachments) {
TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color attachment counts and depth/stencil formats");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(dynamic_rendering_features);