forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vklayertests_ray_tracing.cpp
2896 lines (2434 loc) · 153 KB
/
vklayertests_ray_tracing.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 Advanced Micro Devices, 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
*
* Author: Chia-I Wu <olvaffe@gmail.com>
* Author: Chris Forbes <chrisf@ijw.co.nz>
* Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
* Author: Mark Lobodzinski <mark@lunarg.com>
* Author: Mike Stroyan <mike@LunarG.com>
* Author: Tobin Ehlis <tobine@google.com>
* Author: Tony Barbour <tony@LunarG.com>
* Author: Cody Northrop <cnorthrop@google.com>
* Author: Dave Houlton <daveh@lunarg.com>
* Author: Jeremy Kniager <jeremyk@lunarg.com>
* Author: Shannon McPherson <shannon@lunarg.com>
* Author: John Zulauf <jzulauf@lunarg.com>
* Author: Tobias Hector <tobias.hector@amd.com>
*/
#include "layer_validation_tests.h"
TEST_F(VkLayerTest, RayTracingTestBarrierAccessAccelerationStructure) {
TEST_DESCRIPTION("Test barrier with access ACCELERATION_STRUCTURE bit.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "Test requires at least Vulkan 1.1.";
}
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
if (!CheckSynchronization2SupportAndInitState(this)) {
GTEST_SKIP() << "Synchronization2 not supported";
}
VkMemoryBarrier2 mem_barrier = LvlInitStruct<VkMemoryBarrier2>();
mem_barrier.dstAccessMask = VK_ACCESS_2_SHADER_READ_BIT;
mem_barrier.dstStageMask = VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT;
VkDependencyInfo dependency_info = LvlInitStruct<VkDependencyInfo>();
dependency_info.memoryBarrierCount = 1;
dependency_info.pMemoryBarriers = &mem_barrier;
m_commandBuffer->begin();
mem_barrier.srcAccessMask = VK_ACCESS_2_ACCELERATION_STRUCTURE_READ_BIT_KHR;
mem_barrier.srcStageMask = VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkMemoryBarrier2-srcAccessMask-03927");
m_commandBuffer->PipelineBarrier2KHR(&dependency_info);
mem_barrier.srcAccessMask = VK_ACCESS_2_ACCELERATION_STRUCTURE_WRITE_BIT_KHR;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkMemoryBarrier2-srcAccessMask-03928");
m_commandBuffer->PipelineBarrier2KHR(&dependency_info);
mem_barrier.srcStageMask = VK_PIPELINE_STAGE_2_ACCELERATION_STRUCTURE_BUILD_BIT_KHR;
mem_barrier.dstAccessMask = VK_ACCESS_2_ACCELERATION_STRUCTURE_READ_BIT_KHR;
mem_barrier.dstStageMask = VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkMemoryBarrier2-dstAccessMask-03927");
m_commandBuffer->PipelineBarrier2KHR(&dependency_info);
mem_barrier.dstAccessMask = VK_ACCESS_2_ACCELERATION_STRUCTURE_WRITE_BIT_KHR;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkMemoryBarrier2-dstAccessMask-03928");
m_commandBuffer->PipelineBarrier2KHR(&dependency_info);
m_commandBuffer->end();
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, RayTracingValidateDescriptorBindingUpdateAfterBindWithAccelerationStructure) {
TEST_DESCRIPTION("Validate acceleration structure descriptor writing.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_MAINTENANCE_3_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
if (!InitFrameworkForRayTracingTest(this, false)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
ASSERT_NO_FATAL_FAILURE(InitState());
VkDescriptorSetLayoutBinding binding = {};
binding.binding = 0;
binding.descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
binding.descriptorCount = 1;
binding.stageFlags = VK_SHADER_STAGE_ALL;
binding.pImmutableSamplers = nullptr;
VkDescriptorBindingFlags flags = VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT;
auto flags_create_info = LvlInitStruct<VkDescriptorSetLayoutBindingFlagsCreateInfoEXT>();
flags_create_info.bindingCount = 1;
flags_create_info.pBindingFlags = &flags;
VkDescriptorSetLayoutCreateInfo create_info = LvlInitStruct<VkDescriptorSetLayoutCreateInfo>(&flags_create_info);
create_info.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT;
create_info.bindingCount = 1;
create_info.pBindings = &binding;
VkDescriptorSetLayout setLayout;
m_errorMonitor->SetDesiredFailureMsg(
kErrorBit, "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingAccelerationStructureUpdateAfterBind-03570");
vk::CreateDescriptorSetLayout(device(), &create_info, nullptr, &setLayout);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, RayTracingAccelerationStructureBindings) {
TEST_DESCRIPTION("Use more bindings with a descriptorType of VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR than allowed");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto acc_structure_props = LvlInitStruct<VkPhysicalDeviceAccelerationStructurePropertiesKHR>();
GetPhysicalDeviceProperties2(acc_structure_props);
ASSERT_NO_FATAL_FAILURE(InitState());
uint32_t maxBlocks = acc_structure_props.maxPerStageDescriptorUpdateAfterBindAccelerationStructures;
if (maxBlocks > 4096) {
GTEST_SKIP() << "Too large of a maximum number of per stage descriptor update after bind for acceleration structures, "
"skipping tests";
}
if (maxBlocks < 1) {
GTEST_SKIP() << "Test requires maxPerStageDescriptorUpdateAfterBindAccelerationStructures >= 1";
}
std::vector<VkDescriptorSetLayoutBinding> dslb_vec = {};
dslb_vec.reserve(maxBlocks);
VkDescriptorSetLayoutBinding dslb = {};
dslb.descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
dslb.descriptorCount = 1;
dslb.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
for (uint32_t i = 0; i < maxBlocks; ++i) {
dslb.binding = i;
dslb_vec.push_back(dslb);
}
VkDescriptorSetLayoutCreateInfo ds_layout_ci = LvlInitStruct<VkDescriptorSetLayoutCreateInfo>();
ds_layout_ci.bindingCount = dslb_vec.size();
ds_layout_ci.pBindings = dslb_vec.data();
vk_testing::DescriptorSetLayout ds_layout(*m_device, ds_layout_ci);
ASSERT_TRUE(ds_layout.initialized());
VkPipelineLayoutCreateInfo pipeline_layout_ci = LvlInitStruct<VkPipelineLayoutCreateInfo>();
pipeline_layout_ci.setLayoutCount = 1;
pipeline_layout_ci.pSetLayouts = &ds_layout.handle();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineLayoutCreateInfo-descriptorType-03572");
vk_testing::PipelineLayout pipeline_layout(*m_device, pipeline_layout_ci);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, RayTracingValidateBeginQueryQueryPoolType) {
TEST_DESCRIPTION("Test CmdBeginQuery with invalid queryPool queryType");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddOptionalExtensions(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
AddOptionalExtensions(VK_NV_RAY_TRACING_EXTENSION_NAME);
AddOptionalExtensions(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "Test requires at least Vulkan 1.1.";
}
bool khr_acceleration_structure = IsExtensionsEnabled(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
bool nv_ray_tracing = IsExtensionsEnabled(VK_NV_RAY_TRACING_EXTENSION_NAME);
bool ext_transform_feedback = IsExtensionsEnabled(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
if (!khr_acceleration_structure && !nv_ray_tracing) {
GTEST_SKIP() << "Extensions " << VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME << " and " << VK_NV_RAY_TRACING_EXTENSION_NAME
<< " are not supported.";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
const auto vkCmdBeginQueryIndexedEXT = GetDeviceProcAddr<PFN_vkCmdBeginQueryIndexedEXT, false>("vkCmdBeginQueryIndexedEXT");
VkQueryPoolCreateInfo query_pool_ci = LvlInitStruct<VkQueryPoolCreateInfo>();
query_pool_ci.queryCount = 1;
if (khr_acceleration_structure) {
{
query_pool_ci.queryType = VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR;
vk_testing::QueryPool query_pool(*m_device, query_pool_ci);
ASSERT_TRUE(query_pool.initialized());
m_commandBuffer->begin();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBeginQuery-queryType-04728");
vk::CmdBeginQuery(m_commandBuffer->handle(), query_pool.handle(), 0, 0);
m_errorMonitor->VerifyFound();
if (ext_transform_feedback) {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBeginQueryIndexedEXT-queryType-04728");
vkCmdBeginQueryIndexedEXT(m_commandBuffer->handle(), query_pool.handle(), 0, 0, 0);
m_errorMonitor->VerifyFound();
}
m_commandBuffer->end();
}
{
query_pool_ci.queryType = VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR;
vk_testing::QueryPool query_pool(*m_device, query_pool_ci);
ASSERT_TRUE(query_pool.initialized());
m_commandBuffer->begin();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBeginQuery-queryType-04728");
vk::CmdBeginQuery(m_commandBuffer->handle(), query_pool.handle(), 0, 0);
m_errorMonitor->VerifyFound();
if (ext_transform_feedback) {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBeginQueryIndexedEXT-queryType-04728");
vkCmdBeginQueryIndexedEXT(m_commandBuffer->handle(), query_pool.handle(), 0, 0, 0);
m_errorMonitor->VerifyFound();
}
m_commandBuffer->end();
}
}
if (nv_ray_tracing) {
query_pool_ci.queryType = VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_NV;
vk_testing::QueryPool query_pool(*m_device, query_pool_ci);
ASSERT_TRUE(query_pool.initialized());
m_commandBuffer->begin();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBeginQuery-queryType-04729");
vk::CmdBeginQuery(m_commandBuffer->handle(), query_pool.handle(), 0, 0);
m_errorMonitor->VerifyFound();
if (ext_transform_feedback) {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBeginQueryIndexedEXT-queryType-04729");
vkCmdBeginQueryIndexedEXT(m_commandBuffer->handle(), query_pool.handle(), 0, 0, 0);
m_errorMonitor->VerifyFound();
}
m_commandBuffer->end();
}
}
TEST_F(VkLayerTest, RayTracingCopyUnboundAccelerationStructure) {
TEST_DESCRIPTION("Test CmdCopyQueryPoolResults with unsupported query type");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_MAINTENANCE3_EXTENSION_NAME);
if (!InitFrameworkForRayTracingTest(this, true)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
auto as_features = LvlInitStruct<VkPhysicalDeviceAccelerationStructureFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(as_features);
if (as_features.accelerationStructure == VK_FALSE) {
GTEST_SKIP() << "accelerationStructure feature is not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
auto vkCmdCopyAccelerationStructureKHR = reinterpret_cast<PFN_vkCmdCopyAccelerationStructureKHR>(
vk::GetDeviceProcAddr(device(), "vkCmdCopyAccelerationStructureKHR"));
assert(vkCmdCopyAccelerationStructureKHR != nullptr);
auto buffer_ci = LvlInitStruct<VkBufferCreateInfo>();
buffer_ci.size = 4096;
buffer_ci.usage = VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR;
VkBufferObj buffer_no_mem;
buffer_no_mem.init_no_mem(*m_device, buffer_ci);
ASSERT_TRUE(buffer_no_mem.initialized());
VkBufferObj buffer;
buffer.init(*m_device, buffer_ci);
auto as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoKHR>();
as_create_info.buffer = buffer_no_mem.handle();
as_create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
vk_testing::AccelerationStructureKHR invalid_as(*m_device, as_create_info);
as_create_info.buffer = buffer.handle();
vk_testing::AccelerationStructureKHR valid_as(*m_device, as_create_info);
auto copy_info = LvlInitStruct<VkCopyAccelerationStructureInfoKHR>();
copy_info.src = invalid_as.handle();
copy_info.dst = valid_as.handle();
copy_info.mode = VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR;
m_commandBuffer->begin();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCopyAccelerationStructureInfoKHR-buffer-03718");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyAccelerationStructureKHR-buffer-03737");
vkCmdCopyAccelerationStructureKHR(m_commandBuffer->handle(), ©_info);
m_errorMonitor->VerifyFound();
copy_info.src = valid_as.handle();
copy_info.dst = invalid_as.handle();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCopyAccelerationStructureInfoKHR-buffer-03719");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyAccelerationStructureKHR-buffer-03738");
vkCmdCopyAccelerationStructureKHR(m_commandBuffer->handle(), ©_info);
m_errorMonitor->VerifyFound();
m_commandBuffer->end();
}
TEST_F(VkLayerTest, RayTracingCmdCopyUnboundAccelerationStructure) {
TEST_DESCRIPTION("Test CmdCopyAccelerationStructureKHR with buffers not bound to memory");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto accel_features = LvlInitStruct<VkPhysicalDeviceAccelerationStructureFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(accel_features);
if (accel_features.accelerationStructureHostCommands == VK_FALSE) {
GTEST_SKIP() << "accelerationStructureHostCommands feature is not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
auto vkCmdCopyAccelerationStructureKHR = reinterpret_cast<PFN_vkCmdCopyAccelerationStructureKHR>(
vk::GetDeviceProcAddr(device(), "vkCmdCopyAccelerationStructureKHR"));
assert(vkCmdCopyAccelerationStructureKHR != nullptr);
auto vkCopyAccelerationStructureKHR =
reinterpret_cast<PFN_vkCopyAccelerationStructureKHR>(vk::GetDeviceProcAddr(device(), "vkCopyAccelerationStructureKHR"));
assert(vkCopyAccelerationStructureKHR != nullptr);
auto buffer_ci = LvlInitStruct<VkBufferCreateInfo>();
buffer_ci.size = 4096;
buffer_ci.usage = VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR;
VkBufferObj buffer_no_mem;
buffer_no_mem.init_no_mem(*m_device, buffer_ci);
VkBufferObj buffer;
buffer.init(*m_device, buffer_ci);
VkBufferObj host_visible_buffer;
host_visible_buffer.init(*m_device, buffer_ci.size, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, buffer_ci.usage);
auto as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoKHR>();
as_create_info.buffer = buffer_no_mem.handle();
as_create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
vk_testing::AccelerationStructureKHR as_no_mem(*m_device, as_create_info);
as_create_info.buffer = buffer.handle();
vk_testing::AccelerationStructureKHR as_mem(*m_device, as_create_info);
as_create_info.buffer = host_visible_buffer.handle();
vk_testing::AccelerationStructureKHR as_host_mem(*m_device, as_create_info);
auto copy_info = LvlInitStruct<VkCopyAccelerationStructureInfoKHR>();
copy_info.src = as_no_mem.handle();
copy_info.dst = as_mem.handle();
copy_info.mode = VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR;
m_commandBuffer->begin();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCopyAccelerationStructureInfoKHR-buffer-03718");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyAccelerationStructureKHR-buffer-03737");
vkCmdCopyAccelerationStructureKHR(m_commandBuffer->handle(), ©_info);
m_errorMonitor->VerifyFound();
m_commandBuffer->end();
copy_info.src = as_mem.handle();
copy_info.dst = as_no_mem.handle();
m_commandBuffer->begin();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCopyAccelerationStructureInfoKHR-buffer-03719");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyAccelerationStructureKHR-buffer-03738");
vkCmdCopyAccelerationStructureKHR(m_commandBuffer->handle(), ©_info);
m_errorMonitor->VerifyFound();
m_commandBuffer->end();
copy_info.src = as_mem.handle();
copy_info.dst = as_host_mem.handle();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCopyAccelerationStructureKHR-buffer-03727");
vkCopyAccelerationStructureKHR(device(), VK_NULL_HANDLE, ©_info);
m_errorMonitor->VerifyFound();
copy_info.src = as_host_mem.handle();
copy_info.dst = as_mem.handle();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCopyAccelerationStructureKHR-buffer-03728");
vkCopyAccelerationStructureKHR(device(), VK_NULL_HANDLE, ©_info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, RayTracingTestCmdCopyMemoryToAccelerationStructureKHR) {
TEST_DESCRIPTION("Validate CmdCopyMemoryToAccelerationStructureKHR with dst buffer not bound to memory");
SetTargetApiVersion(VK_API_VERSION_1_2);
auto accel_features = LvlInitStruct<VkPhysicalDeviceAccelerationStructureFeaturesKHR>();
auto bda_features = LvlInitStruct<VkPhysicalDeviceBufferDeviceAddressFeaturesKHR>(&accel_features);
auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2KHR>(&bda_features);
if (!InitFrameworkForRayTracingTest(this, true, &features2)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
const auto vkCmdCopyMemoryToAccelerationStructureKHR =
GetInstanceProcAddr<PFN_vkCmdCopyMemoryToAccelerationStructureKHR>("vkCmdCopyMemoryToAccelerationStructureKHR");
const auto vkGetBufferDeviceAddressKHR = GetDeviceProcAddr<PFN_vkGetBufferDeviceAddressKHR>("vkGetBufferDeviceAddressKHR");
const auto vkCreateAccelerationStructureKHR =
GetDeviceProcAddr<PFN_vkCreateAccelerationStructureKHR>("vkCreateAccelerationStructureKHR");
const auto vkDestroyAccelerationStructureKHR =
GetDeviceProcAddr<PFN_vkDestroyAccelerationStructureKHR>("vkDestroyAccelerationStructureKHR");
auto alloc_flags = LvlInitStruct<VkMemoryAllocateFlagsInfo>();
alloc_flags.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR;
VkBufferObj src_buffer;
src_buffer.init(*m_device, 4096, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, &alloc_flags);
VkBufferCreateInfo buffer_ci = LvlInitStruct<VkBufferCreateInfo>();
buffer_ci.size = 1024;
buffer_ci.usage = VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR;
VkBufferObj dst_buffer;
dst_buffer.init_no_mem(*m_device, buffer_ci);
VkAccelerationStructureCreateInfoKHR as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoKHR>();
as_create_info.buffer = dst_buffer.handle();
as_create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
VkAccelerationStructureKHR as;
vkCreateAccelerationStructureKHR(device(), &as_create_info, nullptr, &as);
VkBufferDeviceAddressInfo device_address_info = {VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO, nullptr, src_buffer.handle()};
VkDeviceAddress device_address = vkGetBufferDeviceAddressKHR(device(), &device_address_info);
VkCopyMemoryToAccelerationStructureInfoKHR copy_info = LvlInitStruct<VkCopyMemoryToAccelerationStructureInfoKHR>();
copy_info.src.deviceAddress = device_address;
copy_info.dst = as;
copy_info.mode = VK_COPY_ACCELERATION_STRUCTURE_MODE_DESERIALIZE_KHR;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdCopyMemoryToAccelerationStructureKHR-buffer-03745");
m_commandBuffer->begin();
vkCmdCopyMemoryToAccelerationStructureKHR(m_commandBuffer->handle(), ©_info);
m_commandBuffer->end();
m_errorMonitor->VerifyFound();
vkDestroyAccelerationStructureKHR(device(), as, nullptr);
}
TEST_F(VkLayerTest, RayTracingBuildAccelerationStructureKHR) {
TEST_DESCRIPTION("Validate buffers used in vkBuildAccelerationStructureKHR");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto acc_structure_features = LvlInitStruct<VkPhysicalDeviceAccelerationStructureFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(acc_structure_features);
if (acc_structure_features.accelerationStructureHostCommands == VK_FALSE) {
GTEST_SKIP() << "accelerationStructureHostCommands feature not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
const auto vkBuildAccelerationStructuresKHR =
GetInstanceProcAddr<PFN_vkBuildAccelerationStructuresKHR>("vkBuildAccelerationStructuresKHR");
VkBufferObj buffer;
buffer.init(*m_device, 4096, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR);
VkBufferObj host_buffer;
host_buffer.init(*m_device, 4096, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR);
VkAccelerationStructureCreateInfoKHR as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoKHR>();
as_create_info.buffer = buffer.handle();
as_create_info.createFlags = 0;
as_create_info.offset = 0;
as_create_info.size = 0;
as_create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
as_create_info.deviceAddress = 0;
VkAccelerationStructurekhrObj bot_level_as(*m_device, as_create_info);
as_create_info.buffer = host_buffer.handle();
VkAccelerationStructurekhrObj host_bot_level_as(*m_device, as_create_info);
auto build_info_khr = LvlInitStruct<VkAccelerationStructureBuildGeometryInfoKHR>();
build_info_khr.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
build_info_khr.mode = VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHR;
build_info_khr.srcAccelerationStructure = VK_NULL_HANDLE;
build_info_khr.dstAccelerationStructure = bot_level_as.handle();
build_info_khr.geometryCount = 0;
build_info_khr.pGeometries = nullptr;
build_info_khr.ppGeometries = nullptr;
VkAccelerationStructureBuildRangeInfoKHR build_range_info;
build_range_info.firstVertex = 0;
build_range_info.primitiveCount = 1;
build_range_info.primitiveOffset = 3;
build_range_info.transformOffset = 0;
VkAccelerationStructureBuildRangeInfoKHR *p_build_range_info = &build_range_info;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkBuildAccelerationStructuresKHR-pInfos-03722");
vkBuildAccelerationStructuresKHR(device(), VK_NULL_HANDLE, 1, &build_info_khr, &p_build_range_info);
m_errorMonitor->VerifyFound();
build_info_khr.srcAccelerationStructure = bot_level_as.handle();
build_info_khr.dstAccelerationStructure = host_bot_level_as.handle();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkBuildAccelerationStructuresKHR-pInfos-03723");
vkBuildAccelerationStructuresKHR(device(), VK_NULL_HANDLE, 1, &build_info_khr, &p_build_range_info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, RayTracingTestWriteAccelerationStructureMemory) {
TEST_DESCRIPTION("Test memory in vkWriteAccelerationStructuresPropertiesKHR is host visible");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto as_features = LvlInitStruct<VkPhysicalDeviceAccelerationStructureFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(as_features);
if (as_features.accelerationStructure == VK_FALSE) {
GTEST_SKIP() << "accelerationStructure feature is not supported";
}
if (as_features.accelerationStructureHostCommands == VK_FALSE) {
GTEST_SKIP() << "accelerationStructureHostCommands feature is not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
const auto vkWriteAccelerationStructuresPropertiesKHR =
GetInstanceProcAddr<PFN_vkWriteAccelerationStructuresPropertiesKHR>("vkWriteAccelerationStructuresPropertiesKHR");
const auto vkBuildAccelerationStructuresKHR =
GetInstanceProcAddr<PFN_vkBuildAccelerationStructuresKHR>("vkBuildAccelerationStructuresKHR");
VkBufferObj buffer;
buffer.init(*m_device, 4096, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR);
VkAccelerationStructureCreateInfoKHR as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoKHR>();
as_create_info.buffer = buffer.handle();
as_create_info.offset = 0;
as_create_info.size = 0;
as_create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
as_create_info.deviceAddress = 0;
vk_testing::AccelerationStructureKHR acceleration_structure(*m_device, as_create_info);
auto build_info_khr = LvlInitStruct<VkAccelerationStructureBuildGeometryInfoKHR>();
build_info_khr.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
build_info_khr.mode = VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHR;
build_info_khr.flags = VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_COMPACTION_BIT_KHR;
build_info_khr.srcAccelerationStructure = VK_NULL_HANDLE;
build_info_khr.dstAccelerationStructure = acceleration_structure.handle();
build_info_khr.geometryCount = 0;
build_info_khr.pGeometries = nullptr;
build_info_khr.ppGeometries = nullptr;
VkAccelerationStructureBuildRangeInfoKHR build_range_info;
build_range_info.firstVertex = 0;
build_range_info.primitiveCount = 1;
build_range_info.primitiveOffset = 3;
build_range_info.transformOffset = 0;
VkAccelerationStructureBuildRangeInfoKHR *pBuildRangeInfos = &build_range_info;
m_errorMonitor->SetAllowedFailureMsg("VUID-vkBuildAccelerationStructuresKHR-pInfos-03722");
vkBuildAccelerationStructuresKHR(device(), VK_NULL_HANDLE, 1, &build_info_khr, &pBuildRangeInfos);
m_errorMonitor->VerifyFound();
std::vector<uint32_t> data(4096);
VkAccelerationStructureKHR acceleration_structure_handle = acceleration_structure.handle();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkWriteAccelerationStructuresPropertiesKHR-buffer-03733");
vkWriteAccelerationStructuresPropertiesKHR(device(), 1, &acceleration_structure_handle,
VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR, 4096, data.data(), 4096);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, RayTracingTestCopyMemoryToAsBuffer) {
TEST_DESCRIPTION("Test invalid buffer used in vkCopyMemoryToAccelerationStructureKHR.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto accel_features = LvlInitStruct<VkPhysicalDeviceAccelerationStructureFeaturesKHR>();
auto features2 = GetPhysicalDeviceFeatures2(accel_features);
if (accel_features.accelerationStructureHostCommands == VK_FALSE) {
GTEST_SKIP() << "accelerationStructureHostCommands feature is not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
const auto vkCopyMemoryToAccelerationStructureKHR =
GetDeviceProcAddr<PFN_vkCopyMemoryToAccelerationStructureKHR>("vkCopyMemoryToAccelerationStructureKHR");
VkBufferObj buffer;
buffer.init(*m_device, 4096, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR);
VkAccelerationStructureCreateInfoKHR as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoKHR>();
as_create_info.buffer = buffer.handle();
as_create_info.createFlags = 0;
as_create_info.offset = 0;
as_create_info.size = 0;
as_create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
as_create_info.deviceAddress = 0;
VkAccelerationStructurekhrObj bot_level_as(*m_device, as_create_info);
uint8_t output[4096];
VkDeviceOrHostAddressConstKHR output_data;
output_data.hostAddress = reinterpret_cast<void *>(output);
auto info = LvlInitStruct<VkCopyMemoryToAccelerationStructureInfoKHR>();
info.dst = bot_level_as.handle();
info.src = output_data;
info.mode = VK_COPY_ACCELERATION_STRUCTURE_MODE_DESERIALIZE_KHR;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCopyMemoryToAccelerationStructureKHR-buffer-03730");
vkCopyMemoryToAccelerationStructureKHR(device(), VK_NULL_HANDLE, &info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, RayTracingValidationArrayOOBRayTracingShaders) {
TEST_DESCRIPTION(
"Core validation: Verify detection of out-of-bounds descriptor array indexing and use of uninitialized descriptors for "
"ray tracing shaders.");
OOBRayTracingShadersTestBody(false);
}
TEST_F(VkLayerTest, RayTracingValidateCreateAccelerationStructureKHR) {
TEST_DESCRIPTION("Validate acceleration structure creation.");
SetTargetApiVersion(VK_API_VERSION_1_1);
auto ray_tracing_features = LvlInitStruct<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>();
auto ray_query_features = LvlInitStruct<VkPhysicalDeviceRayQueryFeaturesKHR>(&ray_tracing_features);
auto acc_struct_features = LvlInitStruct<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(&ray_query_features);
auto bda_features = LvlInitStruct<VkPhysicalDeviceBufferDeviceAddressFeaturesKHR>(&acc_struct_features);
auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2KHR>(&bda_features);
if (!InitFrameworkForRayTracingTest(this, true, &features2)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
if (ray_query_features.rayQuery == VK_FALSE && ray_tracing_features.rayTracingPipeline == VK_FALSE) {
GTEST_SKIP() << "Both of the required features rayQuery and rayTracing are not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
const auto vkCreateAccelerationStructureKHR =
GetDeviceProcAddr<PFN_vkCreateAccelerationStructureKHR>("vkCreateAccelerationStructureKHR");
const auto vkGetBufferDeviceAddressKHR = GetDeviceProcAddr<PFN_vkGetBufferDeviceAddressKHR>("vkGetBufferDeviceAddressKHR");
VkAccelerationStructureKHR as;
VkAccelerationStructureCreateInfoKHR as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoKHR>();
auto alloc_flags = LvlInitStruct<VkMemoryAllocateFlagsInfo>();
alloc_flags.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR;
VkBufferObj buffer;
buffer.init(*m_device, 4096, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, &alloc_flags);
as_create_info.buffer = buffer.handle();
as_create_info.createFlags = 0;
as_create_info.offset = 0;
as_create_info.size = 0;
as_create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
as_create_info.deviceAddress = 0;
VkBufferDeviceAddressInfo device_address_info = {VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO, NULL, buffer.handle()};
VkDeviceAddress device_address = vkGetBufferDeviceAddressKHR(device(), &device_address_info);
// invalid buffer;
{
VkBufferObj invalid_buffer;
invalid_buffer.init(*m_device, 4096, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR);
VkAccelerationStructureCreateInfoKHR invalid_as_create_info = as_create_info;
invalid_as_create_info.buffer = invalid_buffer.handle();
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"VUID-VkAccelerationStructureCreateInfoKHR-buffer-03614");
vkCreateAccelerationStructureKHR(device(), &invalid_as_create_info, nullptr, &as);
m_errorMonitor->VerifyFound();
}
// invalid deviceAddress and flag;
{
VkAccelerationStructureCreateInfoKHR invalid_as_create_info = as_create_info;
invalid_as_create_info.deviceAddress = device_address;
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"VUID-VkAccelerationStructureCreateInfoKHR-deviceAddress-03612");
vkCreateAccelerationStructureKHR(device(), &invalid_as_create_info, nullptr, &as);
m_errorMonitor->VerifyFound();
invalid_as_create_info.deviceAddress = 0;
invalid_as_create_info.createFlags = VK_ACCELERATION_STRUCTURE_CREATE_FLAG_BITS_MAX_ENUM_KHR;
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"VUID-VkAccelerationStructureCreateInfoKHR-createFlags-parameter");
vkCreateAccelerationStructureKHR(device(), &invalid_as_create_info, nullptr, &as);
m_errorMonitor->VerifyFound();
}
// invalid size and offset;
{
VkAccelerationStructureCreateInfoKHR invalid_as_create_info = as_create_info;
invalid_as_create_info.size = 4097; // buffer size is 4096
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"VUID-VkAccelerationStructureCreateInfoKHR-offset-03616");
vkCreateAccelerationStructureKHR(device(), &invalid_as_create_info, nullptr, &as);
m_errorMonitor->VerifyFound();
}
// invalid sType;
{
VkAccelerationStructureCreateInfoKHR invalid_as_create_info = as_create_info;
invalid_as_create_info.sType = VK_STRUCTURE_TYPE_MAX_ENUM;
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"VUID-VkAccelerationStructureCreateInfoKHR-sType-sType");
vkCreateAccelerationStructureKHR(device(), &invalid_as_create_info, nullptr, &as);
m_errorMonitor->VerifyFound();
}
// invalid type;
{
VkAccelerationStructureCreateInfoKHR invalid_as_create_info = as_create_info;
invalid_as_create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_MAX_ENUM_KHR;
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
"VUID-VkAccelerationStructureCreateInfoKHR-type-parameter");
vkCreateAccelerationStructureKHR(device(), &invalid_as_create_info, nullptr, &as);
m_errorMonitor->VerifyFound();
}
}
TEST_F(VkLayerTest, RayTracingValidateCreateAccelerationStructureKHRReplayFeature) {
TEST_DESCRIPTION("Validate acceleration structure creation replay feature.");
SetTargetApiVersion(VK_API_VERSION_1_1);
auto acc_struct_features = LvlInitStruct<VkPhysicalDeviceAccelerationStructureFeaturesKHR>();
auto bda_features = LvlInitStruct<VkPhysicalDeviceBufferDeviceAddressFeaturesKHR>(&acc_struct_features);
auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2KHR>(&bda_features);
if (!InitFrameworkForRayTracingTest(this, true, &features2)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
acc_struct_features.accelerationStructureCaptureReplay = VK_FALSE;
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
const auto vkCreateAccelerationStructureKHR =
GetDeviceProcAddr<PFN_vkCreateAccelerationStructureKHR>("vkCreateAccelerationStructureKHR");
const auto vkGetBufferDeviceAddressKHR = GetDeviceProcAddr<PFN_vkGetBufferDeviceAddressKHR>("vkGetBufferDeviceAddressKHR");
auto alloc_flags = LvlInitStruct<VkMemoryAllocateFlagsInfo>();
alloc_flags.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR;
VkBufferObj buffer;
buffer.init(*m_device, 4096, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, &alloc_flags);
VkBufferDeviceAddressInfo device_address_info = LvlInitStruct<VkBufferDeviceAddressInfo>();
device_address_info.buffer = buffer.handle();
VkDeviceAddress device_address = vkGetBufferDeviceAddressKHR(device(), &device_address_info);
VkAccelerationStructureCreateInfoKHR as_create_info = LvlInitStruct<VkAccelerationStructureCreateInfoKHR>();
as_create_info.buffer = buffer.handle();
as_create_info.createFlags = VK_ACCELERATION_STRUCTURE_CREATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_KHR;
as_create_info.offset = 0;
as_create_info.size = 0;
as_create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR;
as_create_info.deviceAddress = device_address;
VkAccelerationStructureKHR as;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkAccelerationStructureCreateInfoKHR-createFlags-03613");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCreateAccelerationStructureKHR-deviceAddress-03488");
vkCreateAccelerationStructureKHR(device(), &as_create_info, nullptr, &as);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, RayTracingValidateCmdTraceRaysKHR) {
TEST_DESCRIPTION("Validate vkCmdTraceRaysKHR.");
SetTargetApiVersion(VK_API_VERSION_1_2);
auto bda_features = LvlInitStruct<VkPhysicalDeviceBufferDeviceAddressFeaturesKHR>();
bda_features.bufferDeviceAddress = VK_TRUE;
auto ray_tracing_features = LvlInitStruct<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(&bda_features);
auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2KHR>(&ray_tracing_features);
if (!InitFrameworkForRayTracingTest(this, true, &features2)) {
GTEST_SKIP() << "unable to init ray tracing test";
}
// Needed for Ray Tracing
if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
GTEST_SKIP() << "At least Vulkan version 1.2 is required";
}
if (!ray_tracing_features.rayTracingPipeline) {
GTEST_SKIP() << "Feature rayTracing is not supported.";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
// Create ray tracing pipeline
VkPipeline raytracing_pipeline = VK_NULL_HANDLE;
{
const VkPipelineLayoutObj empty_pipeline_layout(m_device, {});
const char *empty_shader = R"glsl(
#version 460
#extension GL_EXT_ray_tracing : require
void main() {}
)glsl";
VkShaderObj rgen_shader(this, empty_shader, VK_SHADER_STAGE_RAYGEN_BIT_KHR, SPV_ENV_VULKAN_1_2);
VkShaderObj chit_shader(this, empty_shader, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, SPV_ENV_VULKAN_1_2);
auto vkCreateRayTracingPipelinesKHR = reinterpret_cast<PFN_vkCreateRayTracingPipelinesKHR>(
vk::GetInstanceProcAddr(instance(), "vkCreateRayTracingPipelinesKHR"));
ASSERT_TRUE(vkCreateRayTracingPipelinesKHR != nullptr);
const VkPipelineLayoutObj pipeline_layout(m_device, {});
std::vector<VkPipelineShaderStageCreateInfo> shader_stages;
VkPipelineShaderStageCreateInfo stage_create_info = LvlInitStruct<VkPipelineShaderStageCreateInfo>();
stage_create_info.stage = VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
stage_create_info.module = chit_shader.handle();
stage_create_info.pName = "main";
shader_stages.emplace_back(stage_create_info);
stage_create_info.stage = VK_SHADER_STAGE_RAYGEN_BIT_KHR;
stage_create_info.module = rgen_shader.handle();
shader_stages.emplace_back(stage_create_info);
VkRayTracingPipelineCreateInfoKHR raytracing_pipeline_ci = LvlInitStruct<VkRayTracingPipelineCreateInfoKHR>();
raytracing_pipeline_ci.flags = 0;
raytracing_pipeline_ci.stageCount = static_cast<uint32_t>(shader_stages.size());
raytracing_pipeline_ci.pStages = shader_stages.data();
raytracing_pipeline_ci.layout = pipeline_layout.handle();
const VkResult result = vkCreateRayTracingPipelinesKHR(m_device->handle(), VK_NULL_HANDLE, VK_NULL_HANDLE, 1,
&raytracing_pipeline_ci, nullptr, &raytracing_pipeline);
ASSERT_VK_SUCCESS(result);
}
VkBufferObj buffer;
VkBufferCreateInfo buffer_ci = LvlInitStruct<VkBufferCreateInfo>();
buffer_ci.usage =
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR;
buffer_ci.size = 4096;
buffer_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
buffer.init_no_mem(*m_device, buffer_ci);
VkMemoryRequirements mem_reqs;
vk::GetBufferMemoryRequirements(device(), buffer.handle(), &mem_reqs);
auto alloc_flags = LvlInitStruct<VkMemoryAllocateFlagsInfo>();
alloc_flags.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR;
VkMemoryAllocateInfo alloc_info = LvlInitStruct<VkMemoryAllocateInfo>(&alloc_flags);
alloc_info.allocationSize = 4096;
vk_testing::DeviceMemory mem(*m_device, alloc_info);
vk::BindBufferMemory(device(), buffer.handle(), mem.handle(), 0);
const auto vkGetPhysicalDeviceProperties2KHR =
GetInstanceProcAddr<PFN_vkGetPhysicalDeviceProperties2KHR>("vkGetPhysicalDeviceProperties2KHR");
ASSERT_TRUE(vkGetPhysicalDeviceProperties2KHR != nullptr);
auto ray_tracing_properties = LvlInitStruct<VkPhysicalDeviceRayTracingPipelinePropertiesKHR>();
auto properties2 = LvlInitStruct<VkPhysicalDeviceProperties2KHR>(&ray_tracing_properties);
vkGetPhysicalDeviceProperties2KHR(gpu(), &properties2);
const auto vkCmdTraceRaysKHR = GetInstanceProcAddr<PFN_vkCmdTraceRaysKHR>("vkCmdTraceRaysKHR");
ASSERT_TRUE(vkCmdTraceRaysKHR != nullptr);
const VkDeviceAddress device_address = buffer.address();
VkStridedDeviceAddressRegionKHR stridebufregion = {};
stridebufregion.deviceAddress = device_address;
stridebufregion.stride = ray_tracing_properties.shaderGroupHandleAlignment;
stridebufregion.size = stridebufregion.stride;
m_commandBuffer->begin();
// Invalid stride multiplier
{
VkStridedDeviceAddressRegionKHR invalid_stride = stridebufregion;
invalid_stride.stride = (stridebufregion.size + 1) % stridebufregion.size;
if (invalid_stride.stride > 0) {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdTraceRaysKHR-stride-03694");
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &stridebufregion, &stridebufregion, &stridebufregion, &invalid_stride, 100,
100, 1);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdTraceRaysKHR-stride-03690");
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &stridebufregion, &stridebufregion, &invalid_stride, &stridebufregion, 100,
100, 1);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdTraceRaysKHR-stride-03686");
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &stridebufregion, &invalid_stride, &stridebufregion, &stridebufregion, 100,
100, 1);
m_errorMonitor->VerifyFound();
}
}
// Invalid stride, greater than maxShaderGroupStride
{
VkStridedDeviceAddressRegionKHR invalid_stride = stridebufregion;
uint32_t align = ray_tracing_properties.shaderGroupHandleSize;
invalid_stride.stride =
ray_tracing_properties.maxShaderGroupStride + (align - (ray_tracing_properties.maxShaderGroupStride % align));
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdTraceRaysKHR-stride-04041");
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &stridebufregion, &stridebufregion, &stridebufregion, &invalid_stride, 100,
100, 1);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdTraceRaysKHR-stride-04035");
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &stridebufregion, &stridebufregion, &invalid_stride, &stridebufregion, 100,
100, 1);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdTraceRaysKHR-stride-04029");
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &stridebufregion, &invalid_stride, &stridebufregion, &stridebufregion, 100,
100, 1);
m_errorMonitor->VerifyFound();
}
vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, raytracing_pipeline);
// buffer is missing flag VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR
VkBufferObj buffer_missing_flag;
buffer_ci.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
buffer_missing_flag.init_no_mem(*m_device, buffer_ci);
vk::BindBufferMemory(device(), buffer_missing_flag.handle(), mem.handle(), 0);
const VkDeviceAddress device_address_missing_flag = buffer_missing_flag.address();
// pRayGenShaderBindingTable->deviceAddress == 0
{
VkStridedDeviceAddressRegionKHR invalid_stride = stridebufregion;
invalid_stride.deviceAddress = 0;
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &invalid_stride, &stridebufregion, &stridebufregion, &stridebufregion, 100,
100, 1);
}
// buffer is missing flag VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR
{
VkStridedDeviceAddressRegionKHR invalid_stride = stridebufregion;
// This address is the same as the one from the first (valid) buffer, so no validation error
invalid_stride.deviceAddress = device_address_missing_flag;
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &invalid_stride, &stridebufregion, &stridebufregion, &stridebufregion, 100,
100, 1);
}
// pRayGenShaderBindingTable address range and stride are invalid
{
VkStridedDeviceAddressRegionKHR invalid_stride = stridebufregion;
invalid_stride.stride = 8128;
invalid_stride.size = 8128;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdTraceRaysKHR-pRayGenShaderBindingTable-03681");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkStridedDeviceAddressRegionKHR-size-04631");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkStridedDeviceAddressRegionKHR-size-04632");
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &invalid_stride, &stridebufregion, &stridebufregion, &stridebufregion, 100,
100, 1);
m_errorMonitor->VerifyFound();
}
// pMissShaderBindingTable->deviceAddress == 0
{
VkStridedDeviceAddressRegionKHR invalid_stride = stridebufregion;
invalid_stride.deviceAddress = 0;
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &stridebufregion, &invalid_stride, &stridebufregion, &stridebufregion, 100,
100, 1);
m_errorMonitor->VerifyFound();
}
// pHitShaderBindingTable->deviceAddress == 0
{
VkStridedDeviceAddressRegionKHR invalid_stride = stridebufregion;
invalid_stride.deviceAddress = 0;
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &stridebufregion, &stridebufregion, &invalid_stride, &stridebufregion, 100,
100, 1);
}
// pCallableShaderBindingTable->deviceAddress == 0
{
VkStridedDeviceAddressRegionKHR invalid_stride = stridebufregion;
invalid_stride.deviceAddress = 0;
vkCmdTraceRaysKHR(m_commandBuffer->handle(), &stridebufregion, &stridebufregion, &stridebufregion, &invalid_stride, 100,