-
Notifications
You must be signed in to change notification settings - Fork 284
/
loader_phys_dev_inst_ext_tests.cpp
5619 lines (4800 loc) · 285 KB
/
loader_phys_dev_inst_ext_tests.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) 2021-2022 The Khronos Group Inc.
* Copyright (c) 2021-2022 Valve Corporation
* Copyright (c) 2021-2022 LunarG, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and/or associated documentation files (the "Materials"), to
* deal in the Materials without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Materials, and to permit persons to whom the Materials are
* furnished to do so, subject to the following conditions:
*
* The above copyright notice(s) and this permission notice shall be included in
* all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
* USE OR OTHER DEALINGS IN THE MATERIALS.
*
* Author: Charles Giessen <[email protected]>
* Author: Mark Young <[email protected]>
*/
#include "test_environment.h"
// These tests are all instance extension tests that touch physical devices. This was
// before the idea that physical device extensions were more appropriately found in the
// list of device extensions. Because of that, all these tests need to support devices
// that don't support the extension and have a fallback path in the loader that needs
// validation.
// Fill in random but valid data into the device properties struct for the current physical device
void FillInRandomICDInfo(uint32_t& vendor_id, uint32_t& driver_vers) {
vendor_id = VK_MAKE_API_VERSION(0, rand() % 64, rand() % 255, rand() % 255);
driver_vers = VK_MAKE_API_VERSION(0, rand() % 64, rand() % 255, rand() % 255);
}
// Fill in random but valid data into the device properties struct for the current physical device
void FillInRandomDeviceProps(VkPhysicalDeviceProperties& props, uint32_t api_vers, uint32_t vendor, uint32_t driver_vers) {
props.apiVersion = api_vers;
props.driverVersion = driver_vers;
props.vendorID = vendor;
props.deviceID = (static_cast<uint32_t>(rand()) >> 4) + (static_cast<uint32_t>(rand()) << 2);
props.deviceType = static_cast<VkPhysicalDeviceType>(rand() % 5);
for (uint8_t idx = 0; idx < VK_UUID_SIZE; ++idx) {
props.pipelineCacheUUID[idx] = static_cast<uint8_t>(rand() % 255);
}
}
//
// VK_KHR_get_physical_device_properties2
//
// Test vkGetPhysicalDeviceProperties2KHR where nothing supports it.
TEST(LoaderInstPhysDevExts, PhysDevProps2KHRNoSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).physical_devices.push_back({});
InstWrapper instance(env.vulkan_functions);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceProperties2KHR GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2KHR");
ASSERT_EQ(GetPhysDevProps2, nullptr);
}
// Test vkGetPhysicalDeviceProperties2KHR where instance supports it, but nothing else.
TEST(LoaderInstPhysDevExts, PhysDevProps2KHRNoICDSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).physical_devices.push_back({});
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT);
PFN_vkGetPhysicalDeviceProperties2KHR GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2KHR");
ASSERT_EQ(GetPhysDevProps2, nullptr);
}
// Test vkGetPhysicalDeviceProperties2KHR where instance and ICD supports it, but device does not support it.
TEST(LoaderInstPhysDevExts, PhysDevProps2KHRInstanceAndICDSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
FillInRandomDeviceProps(env.get_test_icd(0).physical_devices.back().properties, VK_API_VERSION_1_0, 5, 123);
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceProperties2KHR GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2KHR");
ASSERT_NE(GetPhysDevProps2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceProperties props{};
instance->vkGetPhysicalDeviceProperties(physical_device, &props);
VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR};
GetPhysDevProps2(physical_device, &props2);
// Both properties should match
ASSERT_EQ(props.apiVersion, props2.properties.apiVersion);
ASSERT_EQ(props.driverVersion, props2.properties.driverVersion);
ASSERT_EQ(props.vendorID, props2.properties.vendorID);
ASSERT_EQ(props.deviceID, props2.properties.deviceID);
ASSERT_EQ(props.deviceType, props2.properties.deviceType);
ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE));
}
// Test vkGetPhysicalDeviceProperties2 where instance supports, an ICD, and a device under that ICD
// also support, so everything should work and return properly.
// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1
TEST(LoaderInstPhysDevExts, PhysDevProps2Simple) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_1));
env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1;
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0});
FillInRandomDeviceProps(env.get_test_icd(0).physical_devices.back().properties, VK_API_VERSION_1_1, 5, 123);
{
InstWrapper instance(env.vulkan_functions);
instance.create_info.set_api_version(VK_API_VERSION_1_1);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2");
ASSERT_NE(GetPhysDevProps2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceProperties props{};
instance->vkGetPhysicalDeviceProperties(physical_device, &props);
VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR};
GetPhysDevProps2(physical_device, &props2);
// Both properties should match
ASSERT_EQ(props.apiVersion, props2.properties.apiVersion);
ASSERT_EQ(props.driverVersion, props2.properties.driverVersion);
ASSERT_EQ(props.vendorID, props2.properties.vendorID);
ASSERT_EQ(props.deviceID, props2.properties.deviceID);
ASSERT_EQ(props.deviceType, props2.properties.deviceType);
ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE));
}
{ // Do the same logic but have the application forget to use 1.1 and doesn't enable the extension - should emulate the call
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2");
ASSERT_NE(GetPhysDevProps2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceProperties props{};
instance->vkGetPhysicalDeviceProperties(physical_device, &props);
VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR};
GetPhysDevProps2(physical_device, &props2);
// Both properties should match
ASSERT_EQ(props.apiVersion, props2.properties.apiVersion);
ASSERT_EQ(props.driverVersion, props2.properties.driverVersion);
ASSERT_EQ(props.vendorID, props2.properties.vendorID);
ASSERT_EQ(props.deviceID, props2.properties.deviceID);
ASSERT_EQ(props.deviceType, props2.properties.deviceType);
ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE));
ASSERT_TRUE(log.find("Emulating call in ICD"));
}
env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{}
.set_name("modify_api_version_layer")
.set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
.set_disable_environment("DisableEnvVar")),
"modify_api_version_layer.json");
env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1);
{ // Now do the same as above but with a layer that updates the version to 1.1
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2");
ASSERT_NE(GetPhysDevProps2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceProperties props{};
instance->vkGetPhysicalDeviceProperties(physical_device, &props);
VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR};
GetPhysDevProps2(physical_device, &props2);
// Both properties should match
ASSERT_EQ(props.apiVersion, props2.properties.apiVersion);
ASSERT_EQ(props.driverVersion, props2.properties.driverVersion);
ASSERT_EQ(props.vendorID, props2.properties.vendorID);
ASSERT_EQ(props.deviceID, props2.properties.deviceID);
ASSERT_EQ(props.deviceType, props2.properties.deviceType);
ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE));
ASSERT_FALSE(log.find("Emulating call in ICD"));
}
}
// Test vkGetPhysicalDeviceProperties2 and vkGetPhysicalDeviceProperties2KHR where ICD is 1.0 and supports
// extension but the instance supports 1.1 and the extension
TEST(LoaderInstPhysDevExts, PhysDevProps2KHRInstanceSupports11) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_0));
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0});
FillInRandomDeviceProps(env.get_test_icd(0).physical_devices.back().properties, VK_API_VERSION_1_0, 5, 123);
InstWrapper instance(env.vulkan_functions);
instance.create_info.set_api_version(VK_API_VERSION_1_1);
instance.create_info.add_extensions(
{VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME});
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2");
ASSERT_NE(GetPhysDevProps2, nullptr);
PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2KHR = instance.load("vkGetPhysicalDeviceProperties2KHR");
ASSERT_NE(GetPhysDevProps2KHR, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceProperties props{};
instance->vkGetPhysicalDeviceProperties(physical_device, &props);
VkPhysicalDeviceProperties2 props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
GetPhysDevProps2(physical_device, &props2);
// Both VkPhysicalDeviceProperties2 properties should match
ASSERT_EQ(props.apiVersion, props2.properties.apiVersion);
ASSERT_EQ(props.driverVersion, props2.properties.driverVersion);
ASSERT_EQ(props.vendorID, props2.properties.vendorID);
ASSERT_EQ(props.deviceID, props2.properties.deviceID);
ASSERT_EQ(props.deviceType, props2.properties.deviceType);
ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE));
VkPhysicalDeviceProperties2KHR props2KHR{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR};
GetPhysDevProps2(physical_device, &props2KHR);
// Both VkPhysicalDeviceProperties2KHR properties should match
ASSERT_EQ(props.apiVersion, props2KHR.properties.apiVersion);
ASSERT_EQ(props.driverVersion, props2KHR.properties.driverVersion);
ASSERT_EQ(props.vendorID, props2KHR.properties.vendorID);
ASSERT_EQ(props.deviceID, props2KHR.properties.deviceID);
ASSERT_EQ(props.deviceType, props2KHR.properties.deviceType);
ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2KHR.properties.pipelineCacheUUID, VK_UUID_SIZE));
ASSERT_FALSE(log.find("Emulating call in ICD"));
}
// Test vkGetPhysicalDeviceProperties2 where instance supports it with some ICDs that both support
// and don't support it:
// ICD 0 supports
// Physical device 0 does not
// Physical device 1 does
// Physical device 2 does not
// ICD 1 doesn't support
// Physical device 3 does not
// ICD 2 supports
// Physical device 4 does not
// Physical device 5 does not
// ICD 3 supports
// Physical device 6 does
TEST(LoaderInstPhysDevExts, PhysDevProps2Mixed) {
FrameworkEnvironment env{};
const uint32_t max_icd_count = 4;
const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1};
const uint32_t max_phys_devs = 7;
for (uint32_t icd = 0; icd < max_icd_count; ++icd) {
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0));
auto& cur_icd = env.get_test_icd(icd);
// ICD 1 should not have 1.1
if (icd != 1) {
cur_icd.icd_api_version = VK_API_VERSION_1_1;
cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
}
uint32_t rand_vendor_id;
uint32_t rand_driver_vers;
FillInRandomICDInfo(rand_vendor_id, rand_driver_vers);
for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) {
uint32_t device_version = VK_API_VERSION_1_0;
cur_icd.physical_devices.push_back({});
auto& cur_dev = cur_icd.physical_devices.back();
// 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1
if ((icd == 0 && dev == 1) || icd == 3) {
cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0});
device_version = VK_API_VERSION_1_1;
}
FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers);
}
}
InstWrapper instance(env.vulkan_functions);
instance.create_info.set_api_version(VK_API_VERSION_1_1);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceProperties2 GetPhysDevProps2 = instance.load("vkGetPhysicalDeviceProperties2");
ASSERT_NE(GetPhysDevProps2, nullptr);
uint32_t device_count = max_phys_devs;
std::array<VkPhysicalDevice, max_phys_devs> physical_devices;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data()));
ASSERT_EQ(device_count, max_phys_devs);
for (uint32_t dev = 0; dev < device_count; ++dev) {
VkPhysicalDeviceProperties props{};
instance->vkGetPhysicalDeviceProperties(physical_devices[dev], &props);
VkPhysicalDeviceProperties2KHR props2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
GetPhysDevProps2(physical_devices[dev], &props2);
// Both properties should match
ASSERT_EQ(props.apiVersion, props2.properties.apiVersion);
ASSERT_EQ(props.driverVersion, props2.properties.driverVersion);
ASSERT_EQ(props.vendorID, props2.properties.vendorID);
ASSERT_EQ(props.deviceID, props2.properties.deviceID);
ASSERT_EQ(props.deviceType, props2.properties.deviceType);
ASSERT_EQ(0, memcmp(props.pipelineCacheUUID, props2.properties.pipelineCacheUUID, VK_UUID_SIZE));
}
}
// Fill in random but valid data into the features struct for the current physical device
void FillInRandomFeatures(VkPhysicalDeviceFeatures& feats) {
feats.robustBufferAccess = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.fullDrawIndexUint32 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.imageCubeArray = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.independentBlend = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.geometryShader = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.tessellationShader = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sampleRateShading = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.dualSrcBlend = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.logicOp = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.multiDrawIndirect = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.drawIndirectFirstInstance = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.depthClamp = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.depthBiasClamp = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.fillModeNonSolid = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.depthBounds = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.wideLines = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.largePoints = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.alphaToOne = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.multiViewport = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.samplerAnisotropy = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.textureCompressionETC2 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.textureCompressionASTC_LDR = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.textureCompressionBC = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.occlusionQueryPrecise = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.pipelineStatisticsQuery = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.vertexPipelineStoresAndAtomics = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.fragmentStoresAndAtomics = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderTessellationAndGeometryPointSize = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderImageGatherExtended = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderStorageImageExtendedFormats = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderStorageImageMultisample = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderStorageImageReadWithoutFormat = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderStorageImageWriteWithoutFormat = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderUniformBufferArrayDynamicIndexing = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderSampledImageArrayDynamicIndexing = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderStorageBufferArrayDynamicIndexing = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderStorageImageArrayDynamicIndexing = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderClipDistance = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderCullDistance = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderFloat64 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderInt64 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderInt16 = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderResourceResidency = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.shaderResourceMinLod = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sparseBinding = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sparseResidencyBuffer = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sparseResidencyImage2D = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sparseResidencyImage3D = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sparseResidency2Samples = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sparseResidency4Samples = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sparseResidency8Samples = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sparseResidency16Samples = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.sparseResidencyAliased = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.variableMultisampleRate = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
feats.inheritedQueries = (rand() % 2) == 0 ? VK_FALSE : VK_TRUE;
}
// Test vkGetPhysicalDeviceFeatures2KHR where nothing supports it.
TEST(LoaderInstPhysDevExts, PhysDevFeats2KHRNoSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).physical_devices.push_back({});
InstWrapper instance(env.vulkan_functions);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysDevFeats2KHR = instance.load("vkGetPhysicalDeviceFeatures2KHR");
ASSERT_EQ(GetPhysDevFeats2KHR, nullptr);
}
// Test vkGetPhysicalDeviceFeatures2KHR where instance supports it, but nothing else.
TEST(LoaderInstPhysDevExts, PhysDevFeatsKHRNoICDSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).physical_devices.push_back({});
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT);
PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysDevFeats2KHR = instance.load("vkGetPhysicalDeviceFeatures2KHR");
ASSERT_EQ(GetPhysDevFeats2KHR, nullptr);
}
// Test vkGetPhysicalDeviceFeatures2KHR where instance and ICD supports it, but device does not support it.
TEST(LoaderInstPhysDevExts, PhysDevFeats2KHRInstanceAndICDSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
FillInRandomFeatures(env.get_test_icd(0).physical_devices.back().features);
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysDevFeats2KHR = instance.load("vkGetPhysicalDeviceFeatures2KHR");
ASSERT_NE(GetPhysDevFeats2KHR, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceFeatures feats{};
instance->vkGetPhysicalDeviceFeatures(physical_device, &feats);
VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR};
GetPhysDevFeats2KHR(physical_device, &feats2);
ASSERT_EQ(feats, feats2);
}
// Test vkGetPhysicalDeviceFeatures2 where instance supports, an ICD, and a device under that ICD
// also support, so everything should work and return properly.
// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1
TEST(LoaderInstPhysDevExts, PhysDevFeats2Simple) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_1));
env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1;
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0});
env.get_test_icd(0).physical_devices.back().set_api_version(VK_API_VERSION_1_1);
FillInRandomFeatures(env.get_test_icd(0).physical_devices.back().features);
{
InstWrapper instance(env.vulkan_functions);
instance.create_info.set_api_version(VK_API_VERSION_1_1);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2");
ASSERT_NE(GetPhysDevFeats2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceFeatures feats{};
instance->vkGetPhysicalDeviceFeatures(physical_device, &feats);
VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
GetPhysDevFeats2(physical_device, &feats2);
ASSERT_EQ(feats, feats2);
}
{ // Now do the same logic but the application didn't enable 1.0 or the extension so they get the emulated call
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2");
ASSERT_NE(GetPhysDevFeats2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceFeatures feats{};
instance->vkGetPhysicalDeviceFeatures(physical_device, &feats);
VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
GetPhysDevFeats2(physical_device, &feats2);
ASSERT_EQ(feats, feats2);
ASSERT_TRUE(log.find("Emulating call in ICD"));
}
env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{}
.set_name("modify_api_version_layer")
.set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
.set_disable_environment("DisableEnvVar")),
"modify_api_version_layer.json");
env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1);
{ // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2");
ASSERT_NE(GetPhysDevFeats2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceFeatures feats{};
instance->vkGetPhysicalDeviceFeatures(physical_device, &feats);
VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
GetPhysDevFeats2(physical_device, &feats2);
ASSERT_EQ(feats, feats2);
ASSERT_FALSE(log.find("Emulating call in ICD"));
}
}
// Test vkGetPhysicalDeviceFeatures2 and vkGetPhysicalDeviceFeatures2KHR where ICD is 1.0 and supports
// extension but the instance supports 1.1 and the extension
TEST(LoaderInstPhysDevExts, PhysDevFeats2KHRInstanceSupports11) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_0));
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0});
FillInRandomFeatures(env.get_test_icd(0).physical_devices.back().features);
InstWrapper instance(env.vulkan_functions);
instance.create_info.set_api_version(VK_API_VERSION_1_1);
instance.create_info.add_extensions(
{VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME});
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysDevFeats2KHR = instance.load("vkGetPhysicalDeviceFeatures2KHR");
ASSERT_NE(GetPhysDevFeats2KHR, nullptr);
PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2");
ASSERT_NE(GetPhysDevFeats2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkPhysicalDeviceFeatures feats{};
instance->vkGetPhysicalDeviceFeatures(physical_device, &feats);
VkPhysicalDeviceFeatures2KHR feats2KHR{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR};
GetPhysDevFeats2KHR(physical_device, &feats2KHR);
ASSERT_EQ(feats, feats2KHR);
VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
GetPhysDevFeats2(physical_device, &feats2);
ASSERT_EQ(feats, feats2);
ASSERT_FALSE(log.find("Emulating call in ICD"));
}
// Test vkGetPhysicalDeviceFeatures2 where instance supports it with some ICDs that both support
// and don't support it:
// ICD 0 supports
// Physical device 0 does not
// Physical device 1 does
// Physical device 2 does not
// ICD 1 doesn't support
// Physical device 3 does not
// ICD 2 supports
// Physical device 4 does not
// Physical device 5 does not
// ICD 3 supports
// Physical device 6 does
TEST(LoaderInstPhysDevExts, PhysDevFeatsMixed) {
FrameworkEnvironment env{};
const uint32_t max_icd_count = 4;
const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1};
const uint32_t max_phys_devs = 7;
for (uint32_t icd = 0; icd < max_icd_count; ++icd) {
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0));
auto& cur_icd = env.get_test_icd(icd);
// ICD 1 should not have 1.1
if (icd != 1) {
cur_icd.icd_api_version = VK_API_VERSION_1_1;
cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
}
uint32_t rand_vendor_id;
uint32_t rand_driver_vers;
FillInRandomICDInfo(rand_vendor_id, rand_driver_vers);
for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) {
uint32_t device_version = VK_API_VERSION_1_0;
cur_icd.physical_devices.push_back({});
auto& cur_dev = cur_icd.physical_devices.back();
// 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1
if ((icd == 0 && dev == 1) || icd == 3) {
cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0});
device_version = VK_API_VERSION_1_1;
}
// Still set physical device properties (so we can determine if device is correct API version)
FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers);
FillInRandomFeatures(cur_dev.features);
}
}
InstWrapper instance(env.vulkan_functions);
instance.create_info.set_api_version(VK_API_VERSION_1_1);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceFeatures2 GetPhysDevFeats2 = instance.load("vkGetPhysicalDeviceFeatures2");
ASSERT_NE(GetPhysDevFeats2, nullptr);
uint32_t device_count = max_phys_devs;
std::array<VkPhysicalDevice, max_phys_devs> physical_devices;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data()));
ASSERT_EQ(device_count, max_phys_devs);
for (uint32_t dev = 0; dev < device_count; ++dev) {
VkPhysicalDeviceFeatures feats{};
instance->vkGetPhysicalDeviceFeatures(physical_devices[dev], &feats);
VkPhysicalDeviceFeatures2 feats2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
GetPhysDevFeats2(physical_devices[dev], &feats2);
ASSERT_EQ(feats, feats2);
}
}
// Fill in random but valid data into the format properties struct for the current physical device
void FillInRandomFormatProperties(std::vector<VkFormatProperties>& props) {
props.resize(5);
for (uint8_t form = 0; form < 5; ++form) {
props[form].bufferFeatures = static_cast<VkFormatFeatureFlags>(rand());
props[form].linearTilingFeatures = static_cast<VkFormatFeatureFlags>(rand());
props[form].optimalTilingFeatures = static_cast<VkFormatFeatureFlags>(rand());
}
}
// Test vkGetPhysicalDeviceFormatProperties2KHR where nothing supports it.
TEST(LoaderInstPhysDevExts, PhysDevFormatProps2KHRNoSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).physical_devices.push_back({});
InstWrapper instance(env.vulkan_functions);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceFormatProperties2KHR GetPhysDevFormatProps2KHR =
instance.load("vkGetPhysicalDeviceFormatProperties2KHR");
ASSERT_EQ(GetPhysDevFormatProps2KHR, nullptr);
}
// Test vkGetPhysicalDeviceFormatProperties2KHR where instance supports it, but nothing else.
TEST(LoaderInstPhysDevExts, PhysDevFormatPropsKHRNoICDSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).physical_devices.push_back({});
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT);
PFN_vkGetPhysicalDeviceFormatProperties2KHR GetPhysDevFormatProps2KHR =
instance.load("vkGetPhysicalDeviceFormatProperties2KHR");
ASSERT_EQ(GetPhysDevFormatProps2KHR, nullptr);
}
// Test vkGetPhysicalDeviceFormatProperties2KHR where instance and ICD supports it, but device does not support it.
TEST(LoaderInstPhysDevExts, PhysDevFormatProps2KHRInstanceAndICDSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
FillInRandomFormatProperties(env.get_test_icd(0).physical_devices.back().format_properties);
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extensions(
{VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME});
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceFormatProperties2KHR GetPhysDevFormatProps2KHR =
instance.load("vkGetPhysicalDeviceFormatProperties2KHR");
ASSERT_NE(GetPhysDevFormatProps2KHR, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkFormatProperties props{};
instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props);
VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
GetPhysDevFormatProps2KHR(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2);
ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures);
ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures);
ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures);
}
// Test vkGetPhysicalDeviceFormatProperties2 where instance supports, an ICD, and a device under that ICD
// also support, so everything should work and return properly.
// Also check if the application didn't enable 1.1 and when a layer 'upgrades' the api version to 1.1
TEST(LoaderInstPhysDevExts, PhysDevFormatProps2Simple) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, VK_API_VERSION_1_1));
env.get_test_icd(0).icd_api_version = VK_API_VERSION_1_1;
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0});
env.get_test_icd(0).physical_devices.back().set_api_version(VK_API_VERSION_1_1);
FillInRandomFormatProperties(env.get_test_icd(0).physical_devices.back().format_properties);
{
InstWrapper instance(env.vulkan_functions);
instance.create_info.set_api_version(VK_API_VERSION_1_1);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2");
ASSERT_NE(GetPhysDevFormatProps2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkFormatProperties props{};
instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props);
VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
GetPhysDevFormatProps2(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2);
ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures);
ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures);
ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures);
}
{ // Do the same logic but have the application forget to enable 1.1 and doesn't enable the extension
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2");
ASSERT_NE(GetPhysDevFormatProps2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkFormatProperties props{};
instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props);
VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
GetPhysDevFormatProps2(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2);
ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures);
ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures);
ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures);
ASSERT_TRUE(log.find("Emulating call in ICD"));
}
env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{}
.set_name("modify_api_version_layer")
.set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
.set_disable_environment("DisableEnvVar")),
"modify_api_version_layer.json");
env.get_test_layer().set_alter_api_version(VK_API_VERSION_1_1);
{ // Now do the same as above but with a layer that updates the version to 1.1 on behalf of the application
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2");
ASSERT_NE(GetPhysDevFormatProps2, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkFormatProperties props{};
instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props);
VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
GetPhysDevFormatProps2(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2);
ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures);
ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures);
ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures);
ASSERT_FALSE(log.find("Emulating call in ICD"));
}
}
// Test vkGetPhysicalDeviceFormatProperties2 and vkGetPhysicalDeviceFormatProperties2KHR where ICD is 1.0 and supports
// extension but the instance supports 1.1 and the extension
TEST(LoaderInstPhysDevExts, PhysDevFormatProps2KHRInstanceSupports11) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
env.get_test_icd(0).physical_devices.back().extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0});
FillInRandomFormatProperties(env.get_test_icd(0).physical_devices.back().format_properties);
InstWrapper instance(env.vulkan_functions);
instance.create_info.set_api_version(VK_API_VERSION_1_1);
instance.create_info.add_extensions(
{VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME});
instance.CheckCreate();
DebugUtilsWrapper log{instance, VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
CreateDebugUtilsMessenger(log);
PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2");
ASSERT_NE(GetPhysDevFormatProps2, nullptr);
PFN_vkGetPhysicalDeviceFormatProperties2KHR GetPhysDevFormatProps2KHR =
instance.load("vkGetPhysicalDeviceFormatProperties2KHR");
ASSERT_NE(GetPhysDevFormatProps2KHR, nullptr);
uint32_t driver_count = 1;
VkPhysicalDevice physical_device;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &driver_count, &physical_device));
ASSERT_EQ(driver_count, 1U);
VkFormatProperties props{};
instance->vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props);
VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
GetPhysDevFormatProps2(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2);
ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures);
ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures);
ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures);
VkFormatProperties2KHR props2KHR{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
GetPhysDevFormatProps2KHR(physical_device, VK_FORMAT_R4G4_UNORM_PACK8, &props2KHR);
ASSERT_EQ(props.bufferFeatures, props2KHR.formatProperties.bufferFeatures);
ASSERT_EQ(props.linearTilingFeatures, props2KHR.formatProperties.linearTilingFeatures);
ASSERT_EQ(props.optimalTilingFeatures, props2KHR.formatProperties.optimalTilingFeatures);
ASSERT_FALSE(log.find("Emulating call in ICD"));
}
// Test vkGetPhysicalDeviceFormatProperties2 where instance supports it with some ICDs that both support
// and don't support it:
// ICD 0 supports
// Physical device 0 does not
// Physical device 1 does
// Physical device 2 does not
// ICD 1 doesn't support
// Physical device 3 does not
// ICD 2 supports
// Physical device 4 does not
// Physical device 5 does not
// ICD 3 supports
// Physical device 6 does
TEST(LoaderInstPhysDevExts, PhysDevFormatPropsMixed) {
FrameworkEnvironment env{};
const uint32_t max_icd_count = 4;
const uint32_t dev_counts[max_icd_count] = {3, 1, 2, 1};
const uint32_t max_phys_devs = 7;
for (uint32_t icd = 0; icd < max_icd_count; ++icd) {
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA, icd != 1 ? VK_API_VERSION_1_1 : VK_API_VERSION_1_0));
auto& cur_icd = env.get_test_icd(icd);
// ICD 1 should not have 1.1
if (icd != 1) {
cur_icd.icd_api_version = VK_API_VERSION_1_1;
cur_icd.add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
}
uint32_t rand_vendor_id;
uint32_t rand_driver_vers;
FillInRandomICDInfo(rand_vendor_id, rand_driver_vers);
for (uint32_t dev = 0; dev < dev_counts[icd]; ++dev) {
uint32_t device_version = VK_API_VERSION_1_0;
cur_icd.physical_devices.push_back({});
auto& cur_dev = cur_icd.physical_devices.back();
// 2nd device in ICD 0 and the one device in ICD 3 support the extension and 1.1
if ((icd == 0 && dev == 1) || icd == 3) {
cur_dev.extensions.push_back({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 0});
device_version = VK_API_VERSION_1_1;
}
// Still set physical device properties (so we can determine if device is correct API version)
FillInRandomDeviceProps(cur_dev.properties, device_version, rand_vendor_id, rand_driver_vers);
FillInRandomFormatProperties(cur_dev.format_properties);
}
}
InstWrapper instance(env.vulkan_functions);
instance.create_info.set_api_version(VK_API_VERSION_1_1);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysDevFormatProps2 = instance.load("vkGetPhysicalDeviceFormatProperties2");
ASSERT_NE(GetPhysDevFormatProps2, nullptr);
uint32_t device_count = max_phys_devs;
std::array<VkPhysicalDevice, max_phys_devs> physical_devices;
ASSERT_EQ(VK_SUCCESS, instance->vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data()));
ASSERT_EQ(device_count, max_phys_devs);
for (uint32_t dev = 0; dev < device_count; ++dev) {
VkFormat format = static_cast<VkFormat>((dev + 1) % 5);
VkFormatProperties props{};
instance->vkGetPhysicalDeviceFormatProperties(physical_devices[dev], format, &props);
VkFormatProperties2 props2{VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
GetPhysDevFormatProps2(physical_devices[dev], format, &props2);
ASSERT_EQ(props.bufferFeatures, props2.formatProperties.bufferFeatures);
ASSERT_EQ(props.linearTilingFeatures, props2.formatProperties.linearTilingFeatures);
ASSERT_EQ(props.optimalTilingFeatures, props2.formatProperties.optimalTilingFeatures);
}
}
// Fill in random but valid data into the image format data struct for the current physical device
void FillInRandomImageFormatData(VkImageFormatProperties& props) {
props.maxExtent = {static_cast<uint32_t>(rand() % 512), static_cast<uint32_t>(rand() % 512),
static_cast<uint32_t>(rand() % 512)};
props.maxMipLevels = static_cast<uint32_t>(1 << (rand() % 16));
props.maxArrayLayers = static_cast<uint32_t>(1 << (rand() % 16));
props.sampleCounts = static_cast<VkSampleCountFlags>(1 << (rand() % 7));
props.maxResourceSize = static_cast<uint64_t>(rand());
}
// Test vkGetPhysicalDeviceImageFormatProperties2KHR where nothing supports it.
TEST(LoaderInstPhysDevExts, PhysDevImageFormatProps2KHRNoSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).physical_devices.push_back({});
InstWrapper instance(env.vulkan_functions);
instance.CheckCreate();
PFN_vkGetPhysicalDeviceImageFormatProperties2KHR GetPhysDevImageFormatProps2 =
instance.load("vkGetPhysicalDeviceImageFormatProperties2KHR");
ASSERT_EQ(GetPhysDevImageFormatProps2, nullptr);
}
// Test vkGetPhysicalDeviceImageFormatProperties2KHR where instance supports it, but nothing else.
TEST(LoaderInstPhysDevExts, PhysDevImageFormatPropsKHRNoICDSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).physical_devices.push_back({});
InstWrapper instance(env.vulkan_functions);
instance.create_info.add_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
instance.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT);
PFN_vkGetPhysicalDeviceImageFormatProperties2KHR GetPhysDevImageFormatProps2KHR =
instance.load("vkGetPhysicalDeviceImageFormatProperties2KHR");
ASSERT_EQ(GetPhysDevImageFormatProps2KHR, nullptr);
}
// Test vkGetPhysicalDeviceImageFormatProperties2KHR where instance and ICD supports it, but device does not support it.
TEST(LoaderInstPhysDevExts, PhysDevImageFormatProps2KHRInstanceAndICDSupport) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
env.get_test_icd(0).add_instance_extension({VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME});
env.get_test_icd(0).physical_devices.push_back({});
FillInRandomImageFormatData(env.get_test_icd(0).physical_devices.back().image_format_properties);