forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvklayertests_external_memory_sync.cpp
1485 lines (1248 loc) · 72.1 KB
/
vklayertests_external_memory_sync.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
*/
#include "cast_utils.h"
#include "enum_flag_bits.h"
#include "layer_validation_tests.h"
#include "vk_layer_utils.h"
TEST_F(VkLayerTest, CreateBufferIncompatibleExternalHandleTypes) {
TEST_DESCRIPTION("Creating buffer with incompatible external memory handle types");
SetTargetApiVersion(VK_API_VERSION_1_1);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
ASSERT_NO_FATAL_FAILURE(InitState());
// Try all flags first. It's unlikely all of them are compatible.
auto external_memory_info = LvlInitStruct<VkExternalMemoryBufferCreateInfo>();
external_memory_info.handleTypes = AllVkExternalMemoryHandleTypeFlagBits;
auto buffer_create_info = LvlInitStruct<VkBufferCreateInfo>(&external_memory_info);
buffer_create_info.size = 1024;
buffer_create_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
CreateBufferTest(*this, &buffer_create_info, "VUID-VkBufferCreateInfo-pNext-00920");
// Get all exportable handle types supported by the platform.
VkExternalMemoryHandleTypeFlags supported_handle_types = 0;
VkExternalMemoryHandleTypeFlags any_compatible_group = 0;
IterateFlags<VkExternalMemoryHandleTypeFlagBits>(
AllVkExternalMemoryHandleTypeFlagBits, [&](VkExternalMemoryHandleTypeFlagBits flag) {
auto external_buffer_info = LvlInitStruct<VkPhysicalDeviceExternalBufferInfo>();
external_buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
external_buffer_info.handleType = flag;
auto external_buffer_properties = LvlInitStruct<VkExternalBufferProperties>();
vk::GetPhysicalDeviceExternalBufferProperties(gpu(), &external_buffer_info, &external_buffer_properties);
const auto external_features = external_buffer_properties.externalMemoryProperties.externalMemoryFeatures;
if (external_features & VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT) {
supported_handle_types |= external_buffer_info.handleType;
any_compatible_group = external_buffer_properties.externalMemoryProperties.compatibleHandleTypes;
}
});
// Main test case. Handle types are supported but not compatible with each other
if ((supported_handle_types & any_compatible_group) != supported_handle_types) {
external_memory_info.handleTypes = supported_handle_types;
CreateBufferTest(*this, &buffer_create_info, "VUID-VkBufferCreateInfo-pNext-00920");
}
}
TEST_F(VkLayerTest, CreateImageIncompatibleExternalHandleTypes) {
TEST_DESCRIPTION("Creating image with incompatible external memory handle types");
SetTargetApiVersion(VK_API_VERSION_1_1);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
ASSERT_NO_FATAL_FAILURE(InitState());
// Try all flags first. It's unlikely all of them are compatible.
auto external_memory_info = LvlInitStruct<VkExternalMemoryImageCreateInfo>();
external_memory_info.handleTypes = AllVkExternalMemoryHandleTypeFlagBits;
auto image_create_info = LvlInitStruct<VkImageCreateInfo>(&external_memory_info);
image_create_info.imageType = VK_IMAGE_TYPE_2D;
image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
image_create_info.extent.width = 32;
image_create_info.extent.height = 32;
image_create_info.extent.depth = 1;
image_create_info.mipLevels = 1;
image_create_info.arrayLayers = 1;
image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-pNext-00990");
// Get all exportable handle types supported by the platform.
VkExternalMemoryHandleTypeFlags supported_handle_types = 0;
VkExternalMemoryHandleTypeFlags any_compatible_group = 0;
auto external_image_info = LvlInitStruct<VkPhysicalDeviceExternalImageFormatInfo>();
auto image_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&external_image_info);
image_info.format = image_create_info.format;
image_info.type = image_create_info.imageType;
image_info.tiling = image_create_info.tiling;
image_info.usage = image_create_info.usage;
image_info.flags = image_create_info.flags;
IterateFlags<VkExternalMemoryHandleTypeFlagBits>(
AllVkExternalMemoryHandleTypeFlagBits, [&](VkExternalMemoryHandleTypeFlagBits flag) {
external_image_info.handleType = flag;
auto external_image_properties = LvlInitStruct<VkExternalImageFormatProperties>();
auto image_properties = LvlInitStruct<VkImageFormatProperties2>(&external_image_properties);
VkResult result = vk::GetPhysicalDeviceImageFormatProperties2(gpu(), &image_info, &image_properties);
const auto external_features = external_image_properties.externalMemoryProperties.externalMemoryFeatures;
if (result == VK_SUCCESS && (external_features & VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT)) {
supported_handle_types |= external_image_info.handleType;
any_compatible_group = external_image_properties.externalMemoryProperties.compatibleHandleTypes;
}
});
// Main test case. Handle types are supported but not compatible with each other
if ((supported_handle_types & any_compatible_group) != supported_handle_types) {
external_memory_info.handleTypes = supported_handle_types;
CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-pNext-00990");
}
}
TEST_F(VkLayerTest, CreateImageIncompatibleExternalHandleTypesNV) {
TEST_DESCRIPTION("Creating image with incompatible external memory handle types from NVIDIA extension");
AddRequiredExtensions(VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState());
auto external_memory_info = LvlInitStruct<VkExternalMemoryImageCreateInfoNV>();
auto image_create_info = LvlInitStruct<VkImageCreateInfo>(&external_memory_info);
image_create_info.imageType = VK_IMAGE_TYPE_2D;
image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
image_create_info.extent.width = 32;
image_create_info.extent.height = 32;
image_create_info.extent.depth = 1;
image_create_info.mipLevels = 1;
image_create_info.arrayLayers = 1;
image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
// Get all exportable handle types supported by the platform.
VkExternalMemoryHandleTypeFlagsNV supported_handle_types = 0;
VkExternalMemoryHandleTypeFlagsNV any_compatible_group = 0;
auto vkGetPhysicalDeviceExternalImageFormatPropertiesNV =
GetInstanceProcAddr<PFN_vkGetPhysicalDeviceExternalImageFormatPropertiesNV>(
"vkGetPhysicalDeviceExternalImageFormatPropertiesNV");
IterateFlags<VkExternalMemoryHandleTypeFlagBitsNV>(
AllVkExternalMemoryHandleTypeFlagBitsNV, [&](VkExternalMemoryHandleTypeFlagBitsNV flag) {
VkExternalImageFormatPropertiesNV external_image_properties = {};
VkResult result = vkGetPhysicalDeviceExternalImageFormatPropertiesNV(
gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling, image_create_info.usage,
image_create_info.flags, flag, &external_image_properties);
if (result == VK_SUCCESS &&
(external_image_properties.externalMemoryFeatures & VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_NV)) {
supported_handle_types |= flag;
any_compatible_group = external_image_properties.compatibleHandleTypes;
}
});
// Main test case. Handle types are supported but not compatible with each other
if ((supported_handle_types & any_compatible_group) != supported_handle_types) {
external_memory_info.handleTypes = supported_handle_types;
CreateImageTest(*this, &image_create_info, "VUID-VkImageCreateInfo-pNext-00991");
}
}
TEST_F(VkLayerTest, InvalidExportExternalImageHandleType) {
TEST_DESCRIPTION("Test exporting memory with mismatching handleTypes.");
SetTargetApiVersion(VK_API_VERSION_1_1);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
ASSERT_NO_FATAL_FAILURE(InitState());
// Create export image
auto external_image_info = LvlInitStruct<VkExternalMemoryImageCreateInfo>();
auto image_info = LvlInitStruct<VkImageCreateInfo>(&external_image_info);
image_info.imageType = VK_IMAGE_TYPE_2D;
image_info.arrayLayers = 1;
image_info.extent = {64, 64, 1};
image_info.format = VK_FORMAT_R8G8B8A8_UNORM;
image_info.mipLevels = 1;
image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
image_info.samples = VK_SAMPLE_COUNT_1_BIT;
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
auto exportable_types = FindSupportedExternalMemoryHandleTypes(gpu(), image_info, VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT);
if (GetBitSetCount(exportable_types) < 2) {
GTEST_SKIP() << "Cannot find two distinct exportable handle types, skipping test";
}
const auto handle_type = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(exportable_types);
exportable_types &= ~handle_type;
const auto handle_type2 = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(exportable_types);
assert(handle_type != handle_type2);
// Create an image with one of the handle types
external_image_info.handleTypes = handle_type;
vk_testing::Image image(*m_device, image_info, vk_testing::NoMemT{});
// Create export memory with a different handle type
auto export_memory_info = LvlInitStruct<VkExportMemoryAllocateInfo>();
export_memory_info.handleTypes = handle_type2;
VkMemoryRequirements image_mem_reqs;
vk::GetImageMemoryRequirements(device(), image.handle(), &image_mem_reqs);
const auto alloc_info = vk_testing::DeviceMemory::get_resource_alloc_info(
*m_device, image_mem_reqs, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &export_memory_info);
const auto memory = vk_testing::DeviceMemory(*m_device, alloc_info);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkBindImageMemory-memory-02728");
vk::BindImageMemory(device(), image.handle(), memory.handle(), 0);
m_errorMonitor->VerifyFound();
auto bind_image_info = LvlInitStruct<VkBindImageMemoryInfo>();
bind_image_info.image = image.handle();
bind_image_info.memory = memory.handle();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkBindImageMemoryInfo-memory-02728");
vk::BindImageMemory2(device(), 1, &bind_image_info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, BufferMemoryWithUnsupportedExternalHandleType) {
TEST_DESCRIPTION("Bind buffer memory with unsupported external memory handle type.");
SetTargetApiVersion(VK_API_VERSION_1_1);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
ASSERT_NO_FATAL_FAILURE(InitState());
auto external_buffer_info = LvlInitStruct<VkExternalMemoryBufferCreateInfo>();
const auto buffer_info =
vk_testing::Buffer::create_info(4096, VK_BUFFER_USAGE_TRANSFER_DST_BIT, nullptr, &external_buffer_info);
const auto exportable_types =
FindSupportedExternalMemoryHandleTypes(gpu(), buffer_info, VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT);
if (!exportable_types) {
GTEST_SKIP() << "Unable to find exportable handle type";
}
if (exportable_types == AllVkExternalMemoryHandleTypeFlagBits) {
GTEST_SKIP() << "This test requires at least one unsupported handle type, but all handle types are supported";
}
const auto handle_type = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(exportable_types);
external_buffer_info.handleTypes = handle_type;
// Create memory object with unsupported handle type
const auto not_supported_type = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(~exportable_types);
auto export_memory_info = LvlInitStruct<VkExportMemoryAllocateInfo>();
export_memory_info.handleTypes = handle_type | not_supported_type;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkExportMemoryAllocateInfo-handleTypes-00656");
vk_testing::Buffer buffer(*m_device, buffer_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &export_memory_info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, BufferMemoryWithIncompatibleExternalHandleTypes) {
TEST_DESCRIPTION("Bind buffer memory with incompatible external memory handle types.");
SetTargetApiVersion(VK_API_VERSION_1_1);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
ASSERT_NO_FATAL_FAILURE(InitState());
auto external_buffer_info = LvlInitStruct<VkExternalMemoryBufferCreateInfo>();
const auto buffer_info =
vk_testing::Buffer::create_info(4096, VK_BUFFER_USAGE_TRANSFER_DST_BIT, nullptr, &external_buffer_info);
const auto exportable_types =
FindSupportedExternalMemoryHandleTypes(gpu(), buffer_info, VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT);
if (!exportable_types) {
GTEST_SKIP() << "Unable to find exportable handle type";
}
const auto handle_type = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(exportable_types);
const auto compatible_types = GetCompatibleHandleTypes(gpu(), buffer_info, handle_type);
if ((exportable_types & compatible_types) == exportable_types) {
GTEST_SKIP() << "Cannot find handle types that are supported but not compatible with each other";
}
external_buffer_info.handleTypes = handle_type;
// Create memory object with incompatible handle types
auto export_memory_info = LvlInitStruct<VkExportMemoryAllocateInfo>();
export_memory_info.handleTypes = exportable_types;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkExportMemoryAllocateInfo-handleTypes-00656");
vk_testing::Buffer buffer(*m_device, buffer_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &export_memory_info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, ImageMemoryWithUnsupportedExternalHandleType) {
TEST_DESCRIPTION("Bind image memory with unsupported external memory handle type.");
SetTargetApiVersion(VK_API_VERSION_1_1);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
ASSERT_NO_FATAL_FAILURE(InitState());
auto external_image_info = LvlInitStruct<VkExternalMemoryImageCreateInfo>();
auto image_info = LvlInitStruct<VkImageCreateInfo>(&external_image_info);
image_info.imageType = VK_IMAGE_TYPE_2D;
image_info.arrayLayers = 1;
image_info.extent = {64, 64, 1};
image_info.format = VK_FORMAT_R8G8B8A8_UNORM;
image_info.mipLevels = 1;
image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
image_info.samples = VK_SAMPLE_COUNT_1_BIT;
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
auto exportable_types = FindSupportedExternalMemoryHandleTypes(gpu(), image_info, VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT);
// This test does not support the AHB handle type, which does not
// allow to query memory requirements before memory is bound
exportable_types &= ~VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
if (!exportable_types) {
GTEST_SKIP() << "Unable to find exportable handle type";
}
if (exportable_types == AllVkExternalMemoryHandleTypeFlagBits) {
GTEST_SKIP() << "This test requires at least one unsupported handle type, but all handle types are supported";
}
const auto handle_type = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(exportable_types);
external_image_info.handleTypes = handle_type;
// Create memory object with unsupported handle type
const auto not_supported_type = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(~exportable_types);
auto export_memory_info = LvlInitStruct<VkExportMemoryAllocateInfo>();
export_memory_info.handleTypes = handle_type | not_supported_type;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkExportMemoryAllocateInfo-handleTypes-00656");
vk_testing::Image image(*m_device, image_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &export_memory_info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, ImageMemoryWithIncompatibleExternalHandleTypes) {
TEST_DESCRIPTION("Bind image memory with incompatible external memory handle types.");
SetTargetApiVersion(VK_API_VERSION_1_1);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
ASSERT_NO_FATAL_FAILURE(InitState());
// Create export image
auto external_image_info = LvlInitStruct<VkExternalMemoryImageCreateInfo>();
auto image_info = LvlInitStruct<VkImageCreateInfo>(&external_image_info);
image_info.imageType = VK_IMAGE_TYPE_2D;
image_info.arrayLayers = 1;
image_info.extent = {64, 64, 1};
image_info.format = VK_FORMAT_R8G8B8A8_UNORM;
image_info.mipLevels = 1;
image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
image_info.samples = VK_SAMPLE_COUNT_1_BIT;
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
auto exportable_types = FindSupportedExternalMemoryHandleTypes(gpu(), image_info, VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT);
// This test does not support the AHB handle type, which does not
// allow to query memory requirements before memory is bound
exportable_types &= ~VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
if (!exportable_types) {
GTEST_SKIP() << "Unable to find exportable handle type";
}
const auto handle_type = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(exportable_types);
const auto compatible_types = GetCompatibleHandleTypes(gpu(), image_info, handle_type);
if ((exportable_types & compatible_types) == exportable_types) {
GTEST_SKIP() << "Cannot find handle types that are supported but not compatible with each other";
}
external_image_info.handleTypes = handle_type;
// Create memory object with incompatible handle types
auto export_memory_info = LvlInitStruct<VkExportMemoryAllocateInfo>();
export_memory_info.handleTypes = exportable_types;
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkExportMemoryAllocateInfo-handleTypes-00656");
vk_testing::Image image(*m_device, image_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &export_memory_info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, InvalidExportExternalBufferHandleType) {
TEST_DESCRIPTION("Test exporting memory with mismatching handleTypes.");
SetTargetApiVersion(VK_API_VERSION_1_1);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
GTEST_SKIP() << "At least Vulkan version 1.1 is required";
}
ASSERT_NO_FATAL_FAILURE(InitState());
// Create export buffer
auto external_info = LvlInitStruct<VkExternalMemoryBufferCreateInfo>();
auto buffer_info = LvlInitStruct<VkBufferCreateInfo>(&external_info);
buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
buffer_info.size = 4096;
auto exportable_types = FindSupportedExternalMemoryHandleTypes(gpu(), buffer_info, VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT);
if (GetBitSetCount(exportable_types) < 2) {
GTEST_SKIP() << "Cannot find two distinct exportable handle types, skipping test";
}
const auto handle_type = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(exportable_types);
exportable_types &= ~handle_type;
const auto handle_type2 = LeastSignificantFlag<VkExternalMemoryHandleTypeFlagBits>(exportable_types);
assert(handle_type != handle_type2);
// Create a buffer with one of the handle types
external_info.handleTypes = handle_type;
vk_testing::Buffer buffer(*m_device, buffer_info, vk_testing::NoMemT{});
// Create export memory with a different handle type
auto export_memory_info = LvlInitStruct<VkExportMemoryAllocateInfo>();
export_memory_info.handleTypes = handle_type2;
VkMemoryRequirements buffer_mem_reqs;
vk::GetBufferMemoryRequirements(device(), buffer.handle(), &buffer_mem_reqs);
const auto alloc_info = vk_testing::DeviceMemory::get_resource_alloc_info(
*m_device, buffer_mem_reqs, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &export_memory_info);
const auto memory = vk_testing::DeviceMemory(*m_device, alloc_info);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkBindBufferMemory-memory-02726");
vk::BindBufferMemory(device(), buffer.handle(), memory.handle(), 0);
m_errorMonitor->VerifyFound();
auto bind_buffer_info = LvlInitStruct<VkBindBufferMemoryInfo>();
bind_buffer_info.buffer = buffer.handle();
bind_buffer_info.memory = memory.handle();
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkBindBufferMemoryInfo-memory-02726");
vk::BindBufferMemory2(device(), 1, &bind_buffer_info);
m_errorMonitor->VerifyFound();
}
TEST_F(VkLayerTest, ExternalTimelineSemaphore) {
#ifdef VK_USE_PLATFORM_WIN32_KHR
const auto extension_name = VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR;
const char *no_tempory_tl_vuid = "VUID-VkImportSemaphoreWin32HandleInfoKHR-flags-03322";
#else
const auto extension_name = VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
const char *no_tempory_tl_vuid = "VUID-VkImportSemaphoreFdInfoKHR-flags-03323";
#endif
AddRequiredExtensions(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
AddRequiredExtensions(extension_name);
AddRequiredExtensions(VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto timeline_semaphore_features = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreFeatures>();
GetPhysicalDeviceFeatures2(timeline_semaphore_features);
if (!timeline_semaphore_features.timelineSemaphore) {
GTEST_SKIP() << "timelineSemaphore not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &timeline_semaphore_features));
// Check for external semaphore import and export capability
{
auto sti = LvlInitStruct<VkSemaphoreTypeCreateInfo>();
sti.semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE;
auto esi = LvlInitStruct<VkPhysicalDeviceExternalSemaphoreInfoKHR>(&sti);
esi.handleType = handle_type;
auto esp = LvlInitStruct<VkExternalSemaphorePropertiesKHR>();
auto vkGetPhysicalDeviceExternalSemaphorePropertiesKHR =
(PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR)vk::GetInstanceProcAddr(
instance(), "vkGetPhysicalDeviceExternalSemaphorePropertiesKHR");
vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(gpu(), &esi, &esp);
if (!(esp.externalSemaphoreFeatures & VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR) ||
!(esp.externalSemaphoreFeatures & VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR)) {
GTEST_SKIP() << "External semaphore does not support importing and exporting, skipping test";
}
}
VkResult err;
// Create a semaphore to export payload from
auto esci = LvlInitStruct<VkExportSemaphoreCreateInfoKHR>();
esci.handleTypes = handle_type;
auto stci = LvlInitStruct<VkSemaphoreTypeCreateInfoKHR>(&esci);
stci.semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE_KHR;
auto sci = LvlInitStruct<VkSemaphoreCreateInfo>(&stci);
vk_testing::Semaphore export_semaphore(*m_device, sci);
// Create a semaphore to import payload into
stci.pNext = nullptr;
vk_testing::Semaphore import_semaphore(*m_device, sci);
vk_testing::Semaphore::ExternalHandle ext_handle{};
err = export_semaphore.export_handle(ext_handle, handle_type);
ASSERT_VK_SUCCESS(err);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, no_tempory_tl_vuid);
err = import_semaphore.import_handle(ext_handle, handle_type, VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR);
m_errorMonitor->VerifyFound();
err = import_semaphore.import_handle(ext_handle, handle_type);
ASSERT_VK_SUCCESS(err);
}
TEST_F(VkLayerTest, ExternalSyncFdSemaphore) {
const auto handle_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
AddRequiredExtensions(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
auto timeline_semaphore_features = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreFeatures>();
GetPhysicalDeviceFeatures2(timeline_semaphore_features);
if (!timeline_semaphore_features.timelineSemaphore) {
GTEST_SKIP() << "timelineSemaphore not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &timeline_semaphore_features, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
// Check for external semaphore import and export capability
auto esi = LvlInitStruct<VkPhysicalDeviceExternalSemaphoreInfoKHR>();
esi.handleType = handle_type;
auto esp = LvlInitStruct<VkExternalSemaphorePropertiesKHR>();
auto vkGetPhysicalDeviceExternalSemaphorePropertiesKHR =
(PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR)vk::GetInstanceProcAddr(
instance(), "vkGetPhysicalDeviceExternalSemaphorePropertiesKHR");
vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(gpu(), &esi, &esp);
if (!(esp.externalSemaphoreFeatures & VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR) ||
!(esp.externalSemaphoreFeatures & VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR)) {
GTEST_SKIP() << "External semaphore does not support importing and exporting";
}
if (!(esp.compatibleHandleTypes & handle_type)) {
GTEST_SKIP() << "External semaphore does not support VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT";
}
VkResult err;
// create a timeline semaphore.
// Note that adding a sync fd VkExportSemaphoreCreateInfo will cause creation to fail.
auto stci = LvlInitStruct<VkSemaphoreTypeCreateInfoKHR>();
stci.semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE;
auto sci = LvlInitStruct<VkSemaphoreCreateInfo>(&stci);
vk_testing::Semaphore timeline_sem(*m_device, sci);
// binary semaphore works fine.
auto esci = LvlInitStruct<VkExportSemaphoreCreateInfo>();
esci.handleTypes = handle_type;
stci.pNext = &esci;
stci.semaphoreType = VK_SEMAPHORE_TYPE_BINARY;
vk_testing::Semaphore binary_sem(*m_device, sci);
// Create a semaphore to import payload into
vk_testing::Semaphore import_semaphore(*m_device);
vk_testing::Semaphore::ExternalHandle ext_handle{};
// timeline not allowed
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSemaphoreGetFdInfoKHR-handleType-01132");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSemaphoreGetFdInfoKHR-handleType-03253");
timeline_sem.export_handle(ext_handle, handle_type);
m_errorMonitor->VerifyFound();
// must have pending signal
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSemaphoreGetFdInfoKHR-handleType-03254");
binary_sem.export_handle(ext_handle, handle_type);
m_errorMonitor->VerifyFound();
auto si = LvlInitStruct<VkSubmitInfo>();
si.signalSemaphoreCount = 1;
si.pSignalSemaphores = &binary_sem.handle();
err = vk::QueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
ASSERT_VK_SUCCESS(err);
err = binary_sem.export_handle(ext_handle, handle_type);
ASSERT_VK_SUCCESS(err);
// must be temporary
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkImportSemaphoreFdInfoKHR-handleType-07307");
import_semaphore.import_handle(ext_handle, handle_type);
m_errorMonitor->VerifyFound();
err = import_semaphore.import_handle(ext_handle, handle_type, VK_SEMAPHORE_IMPORT_TEMPORARY_BIT);
ASSERT_VK_SUCCESS(err);
err = vk::QueueWaitIdle(m_device->m_queue);
ASSERT_VK_SUCCESS(err);
}
TEST_F(VkLayerTest, TemporaryExternalFence) {
#ifdef VK_USE_PLATFORM_WIN32_KHR
const auto extension_name = VK_KHR_EXTERNAL_FENCE_WIN32_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR;
#else
const auto extension_name = VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
#endif
AddRequiredExtensions(VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME);
AddRequiredExtensions(extension_name);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
ASSERT_NO_FATAL_FAILURE(InitState());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
// Check for external fence import and export capability
auto efi = LvlInitStruct<VkPhysicalDeviceExternalFenceInfoKHR>();
efi.handleType = handle_type;
auto efp = LvlInitStruct<VkExternalFencePropertiesKHR>();
auto vkGetPhysicalDeviceExternalFencePropertiesKHR = (PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR)vk::GetInstanceProcAddr(
instance(), "vkGetPhysicalDeviceExternalFencePropertiesKHR");
vkGetPhysicalDeviceExternalFencePropertiesKHR(gpu(), &efi, &efp);
if (!(efp.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR) ||
!(efp.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT_KHR)) {
GTEST_SKIP() << "External fence does not support importing and exporting, skipping test.";
}
VkResult err;
// Create a fence to export payload from
auto efci = LvlInitStruct<VkExportFenceCreateInfoKHR>();
efci.handleTypes = handle_type;
auto fci = LvlInitStruct<VkFenceCreateInfo>(&efci);
vk_testing::Fence export_fence(*m_device, fci);
// Create a fence to import payload into
fci.pNext = nullptr;
vk_testing::Fence import_fence(*m_device, fci);
// Export fence payload to an opaque handle
vk_testing::Fence::ExternalHandle ext_fence{};
err = export_fence.export_handle(ext_fence, handle_type);
ASSERT_VK_SUCCESS(err);
err = import_fence.import_handle(ext_fence, handle_type, VK_FENCE_IMPORT_TEMPORARY_BIT_KHR);
ASSERT_VK_SUCCESS(err);
// Undo the temporary import
vk::ResetFences(m_device->device(), 1, &import_fence.handle());
// Signal the previously imported fence twice, the second signal should produce a validation error
vk::QueueSubmit(m_device->m_queue, 0, nullptr, import_fence.handle());
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkQueueSubmit-fence-00064");
vk::QueueSubmit(m_device->m_queue, 0, nullptr, import_fence.handle());
m_errorMonitor->VerifyFound();
err = vk::QueueWaitIdle(m_device->m_queue);
ASSERT_VK_SUCCESS(err);
// Signal without reseting
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkQueueSubmit-fence-00063");
vk::QueueSubmit(m_device->m_queue, 0, nullptr, import_fence.handle());
m_errorMonitor->VerifyFound();
err = vk::QueueWaitIdle(m_device->m_queue);
ASSERT_VK_SUCCESS(err);
}
TEST_F(VkLayerTest, InvalidExternalFence) {
#ifdef VK_USE_PLATFORM_WIN32_KHR
const auto extension_name = VK_KHR_EXTERNAL_FENCE_WIN32_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT;
const auto other_type = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT;
const auto bad_type = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
const char *bad_export_type_vuid = "VUID-VkFenceGetWin32HandleInfoKHR-handleType-01452";
const char *other_export_type_vuid = "VUID-VkFenceGetWin32HandleInfoKHR-handleType-01448";
const char *bad_import_type_vuid = "VUID-VkImportFenceWin32HandleInfoKHR-handleType-01457";
#else
const auto extension_name = VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
const auto other_type = VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR;
const auto bad_type = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR;
const char *bad_export_type_vuid = "VUID-VkFenceGetFdInfoKHR-handleType-01456";
const char *other_export_type_vuid = "VUID-VkFenceGetFdInfoKHR-handleType-01453";
const char *bad_import_type_vuid = "VUID-VkImportFenceFdInfoKHR-handleType-01464";
#endif
AddRequiredExtensions(VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME);
AddRequiredExtensions(extension_name);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
ASSERT_NO_FATAL_FAILURE(InitState());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
// Check for external fence import and export capability
auto efi = LvlInitStruct<VkPhysicalDeviceExternalFenceInfoKHR>();
efi.handleType = handle_type;
auto efp = LvlInitStruct<VkExternalFencePropertiesKHR>();
auto vkGetPhysicalDeviceExternalFencePropertiesKHR = (PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR)vk::GetInstanceProcAddr(
instance(), "vkGetPhysicalDeviceExternalFencePropertiesKHR");
vkGetPhysicalDeviceExternalFencePropertiesKHR(gpu(), &efi, &efp);
if (!(efp.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR) ||
!(efp.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT_KHR)) {
GTEST_SKIP() << "External fence does not support importing and exporting, skipping test.";
}
// Create a fence to export payload from
auto efci = LvlInitStruct<VkExportFenceCreateInfoKHR>();
efci.handleTypes = handle_type;
auto fci = LvlInitStruct<VkFenceCreateInfo>(&efci);
vk_testing::Fence export_fence(*m_device, fci);
// Create a fence to import payload into
fci.pNext = nullptr;
vk_testing::Fence import_fence(*m_device, fci);
vk_testing::Fence::ExternalHandle ext_handle{};
// windows vs unix mismatch
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, bad_export_type_vuid);
export_fence.export_handle(ext_handle, bad_type);
m_errorMonitor->VerifyFound();
// a valid type for the platform which we didn't ask for during create
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, other_export_type_vuid);
if (other_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR) {
// SYNC_FD is a special snowflake
m_errorMonitor->SetAllowedFailureMsg("VUID-VkFenceGetFdInfoKHR-handleType-01454");
}
export_fence.export_handle(ext_handle, other_type);
m_errorMonitor->VerifyFound();
export_fence.export_handle(ext_handle, handle_type);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, bad_import_type_vuid);
import_fence.import_handle(ext_handle, bad_type);
m_errorMonitor->VerifyFound();
#ifdef VK_USE_PLATFORM_WIN32_KHR
auto ifi = LvlInitStruct<VkImportFenceWin32HandleInfoKHR>();
ifi.fence = import_fence.handle();
ifi.handleType = handle_type;
ifi.handle = ext_handle;
ifi.flags = 0;
ifi.name = L"something";
auto vkImportFenceWin32HandleKHR =
reinterpret_cast<PFN_vkImportFenceWin32HandleKHR>(vk::GetDeviceProcAddr(device(), "vkImportFenceWin32HandleKHR"));
// If handleType is not VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT, name must be NULL
// However, it looks like at least some windows drivers don't support exporting KMT handles for fences
if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT) {
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkImportFenceWin32HandleInfoKHR-handleType-01459");
}
// If handle is not NULL, name must be NULL
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkImportFenceWin32HandleInfoKHR-handle-01462");
vkImportFenceWin32HandleKHR(m_device->device(), &ifi);
m_errorMonitor->VerifyFound();
#endif
auto err = import_fence.import_handle(ext_handle, handle_type);
ASSERT_VK_SUCCESS(err);
}
TEST_F(VkLayerTest, ExternalSyncFdFence) {
const auto handle_type = VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR;
AddRequiredExtensions(VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
ASSERT_NO_FATAL_FAILURE(InitState());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
// Check for external fence import and export capability
auto efi = LvlInitStruct<VkPhysicalDeviceExternalFenceInfoKHR>();
efi.handleType = handle_type;
auto efp = LvlInitStruct<VkExternalFencePropertiesKHR>();
auto vkGetPhysicalDeviceExternalFencePropertiesKHR = (PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR)vk::GetInstanceProcAddr(
instance(), "vkGetPhysicalDeviceExternalFencePropertiesKHR");
vkGetPhysicalDeviceExternalFencePropertiesKHR(gpu(), &efi, &efp);
if (!(efp.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR) ||
!(efp.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT_KHR)) {
GTEST_SKIP() << "External fence does not support importing and exporting, skipping test.";
}
// Create a fence to export payload from
auto efci = LvlInitStruct<VkExportFenceCreateInfoKHR>();
efci.handleTypes = handle_type;
auto fci = LvlInitStruct<VkFenceCreateInfo>(&efci);
vk_testing::Fence export_fence(*m_device, fci);
// Create a fence to import payload into
fci.pNext = nullptr;
vk_testing::Fence import_fence(*m_device, fci);
vk_testing::Fence::ExternalHandle ext_handle{};
// SYNC_FD must have a pending signal for export
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFenceGetFdInfoKHR-handleType-01454");
export_fence.export_handle(ext_handle, handle_type);
m_errorMonitor->VerifyFound();
vk::QueueSubmit(m_device->m_queue, 0, nullptr, export_fence.handle());
export_fence.export_handle(ext_handle, handle_type);
// must be temporary
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkImportFenceFdInfoKHR-handleType-07306");
import_fence.import_handle(ext_handle, handle_type);
m_errorMonitor->VerifyFound();
import_fence.import_handle(ext_handle, handle_type, VK_FENCE_IMPORT_TEMPORARY_BIT);
import_fence.wait(1000000000);
}
TEST_F(VkLayerTest, TemporaryExternalSemaphore) {
#ifdef VK_USE_PLATFORM_WIN32_KHR
const auto extension_name = VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR;
#else
const auto extension_name = VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
#endif
AddRequiredExtensions(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
AddRequiredExtensions(extension_name);
AddRequiredExtensions(VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
ASSERT_NO_FATAL_FAILURE(InitState());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
// Check for external semaphore import and export capability
auto esi = LvlInitStruct<VkPhysicalDeviceExternalSemaphoreInfoKHR>();
esi.handleType = handle_type;
auto esp = LvlInitStruct<VkExternalSemaphorePropertiesKHR>();
auto vkGetPhysicalDeviceExternalSemaphorePropertiesKHR =
(PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR)vk::GetInstanceProcAddr(
instance(), "vkGetPhysicalDeviceExternalSemaphorePropertiesKHR");
vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(gpu(), &esi, &esp);
if (!(esp.externalSemaphoreFeatures & VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR) ||
!(esp.externalSemaphoreFeatures & VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR)) {
GTEST_SKIP() << "External semaphore does not support importing and exporting, skipping test";
}
VkResult err;
// Create a semaphore to export payload from
auto esci = LvlInitStruct<VkExportSemaphoreCreateInfoKHR>();
esci.handleTypes = handle_type;
auto sci = LvlInitStruct<VkSemaphoreCreateInfo>(&esci);
vk_testing::Semaphore export_semaphore(*m_device, sci);
// Create a semaphore to import payload into
sci.pNext = nullptr;
vk_testing::Semaphore import_semaphore(*m_device, sci);
vk_testing::Semaphore::ExternalHandle ext_handle{};
err = export_semaphore.export_handle(ext_handle, handle_type);
ASSERT_VK_SUCCESS(err);
err = import_semaphore.import_handle(ext_handle, handle_type, VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR);
ASSERT_VK_SUCCESS(err);
// Wait on the imported semaphore twice in vk::QueueSubmit, the second wait should be an error
VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
std::vector<VkSubmitInfo> si(4, LvlInitStruct<VkSubmitInfo>());
si[0].signalSemaphoreCount = 1;
si[0].pSignalSemaphores = &export_semaphore.handle();
si[1].waitSemaphoreCount = 1;
si[1].pWaitSemaphores = &import_semaphore.handle();
si[1].pWaitDstStageMask = &flags;
si[2] = si[0];
si[3] = si[1];
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "UNASSIGNED-CoreValidation-DrawState-QueueForwardProgress");
vk::QueueSubmit(m_device->m_queue, si.size(), si.data(), VK_NULL_HANDLE);
m_errorMonitor->VerifyFound();
auto index = m_device->graphics_queue_node_index_;
if (m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) {
// Wait on the imported semaphore twice in vk::QueueBindSparse, the second wait should be an error
std::vector<VkBindSparseInfo> bi(4, LvlInitStruct<VkBindSparseInfo>());
bi[0].signalSemaphoreCount = 1;
bi[0].pSignalSemaphores = &export_semaphore.handle();
bi[1].waitSemaphoreCount = 1;
bi[1].pWaitSemaphores = &import_semaphore.handle();
bi[2] = bi[0];
bi[3] = bi[1];
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "UNASSIGNED-CoreValidation-DrawState-QueueForwardProgress");
vk::QueueBindSparse(m_device->m_queue, bi.size(), bi.data(), VK_NULL_HANDLE);
m_errorMonitor->VerifyFound();
}
// Cleanup
err = vk::QueueWaitIdle(m_device->m_queue);
ASSERT_VK_SUCCESS(err);
}
TEST_F(VkLayerTest, InvalidExternalSemaphore) {
TEST_DESCRIPTION("Import and export invalid external semaphores, no queue sumbits involved.");
#ifdef VK_USE_PLATFORM_WIN32_KHR
const auto extension_name = VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR;
const auto bad_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
const auto other_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR;
const char *bad_export_type_vuid = "VUID-VkSemaphoreGetWin32HandleInfoKHR-handleType-01131";
const char *other_export_type_vuid = "VUID-VkSemaphoreGetWin32HandleInfoKHR-handleType-01126";
const char *bad_import_type_vuid = "VUID-VkImportSemaphoreWin32HandleInfoKHR-handleType-01140";
#else
const auto extension_name = VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME;
const auto handle_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
const auto bad_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR;
const auto other_type = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR;
const char *bad_export_type_vuid = "VUID-VkSemaphoreGetFdInfoKHR-handleType-01136";
const char *other_export_type_vuid = "VUID-VkSemaphoreGetFdInfoKHR-handleType-01132";
const char *bad_import_type_vuid = "VUID-VkImportSemaphoreFdInfoKHR-handleType-01143";
#endif
AddRequiredExtensions(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
AddRequiredExtensions(extension_name);
AddRequiredExtensions(VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
ASSERT_NO_FATAL_FAILURE(InitState());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
// Check for external semaphore import and export capability
auto esi = LvlInitStruct<VkPhysicalDeviceExternalSemaphoreInfoKHR>();
esi.handleType = handle_type;
auto esp = LvlInitStruct<VkExternalSemaphorePropertiesKHR>();
auto vkGetPhysicalDeviceExternalSemaphorePropertiesKHR =
(PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR)vk::GetInstanceProcAddr(
instance(), "vkGetPhysicalDeviceExternalSemaphorePropertiesKHR");
vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(gpu(), &esi, &esp);
if (!(esp.externalSemaphoreFeatures & VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR) ||
!(esp.externalSemaphoreFeatures & VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR)) {
GTEST_SKIP() << "External semaphore does not support importing and exporting, skipping test";
}
// Create a semaphore to export payload from
auto esci = LvlInitStruct<VkExportSemaphoreCreateInfoKHR>();
esci.handleTypes = handle_type;
auto sci = LvlInitStruct<VkSemaphoreCreateInfo>(&esci);
vk_testing::Semaphore export_semaphore(*m_device, sci);
// Create a semaphore for importing
vk_testing::Semaphore import_semaphore(*m_device);
vk_testing::Semaphore::ExternalHandle ext_handle{};
// windows vs unix mismatch
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, bad_export_type_vuid);
export_semaphore.export_handle(ext_handle, bad_type);
m_errorMonitor->VerifyFound();
// not specified during create
if (other_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR) {
// SYNC_FD must have pending signal
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSemaphoreGetFdInfoKHR-handleType-03254");
}
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, other_export_type_vuid);
export_semaphore.export_handle(ext_handle, other_type);
m_errorMonitor->VerifyFound();
export_semaphore.export_handle(ext_handle, handle_type);
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, bad_import_type_vuid);
export_semaphore.import_handle(ext_handle, bad_type);