-
Notifications
You must be signed in to change notification settings - Fork 293
/
Copy pathtest_icd.cpp
1694 lines (1562 loc) · 89.9 KB
/
test_icd.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-2023 The Khronos Group Inc.
* Copyright (c) 2021-2023 Valve Corporation
* Copyright (c) 2021-2023 LunarG, Inc.
* Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2023-2023 RasterGrid Kft.
*
* 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 <charles@lunarg.com>
*/
#include "test_icd.h"
// export vk_icdGetInstanceProcAddr
#if !defined(TEST_ICD_EXPORT_ICD_GIPA)
#define TEST_ICD_EXPORT_ICD_GIPA 0
#endif
// export vk_icdNegotiateLoaderICDInterfaceVersion
#if !defined(TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION)
#define TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION 0
#endif
// export vk_icdGetPhysicalDeviceProcAddr
#if !defined(TEST_ICD_EXPORT_ICD_GPDPA)
#define TEST_ICD_EXPORT_ICD_GPDPA 0
#endif
// export vk_icdEnumerateAdapterPhysicalDevices
#if !defined(TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES)
#define TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES 0
#endif
// export vk_icdNegotiateLoaderICDInterfaceVersion, vk_icdEnumerateAdapterPhysicalDevices, and vk_icdGetPhysicalDeviceProcAddr
// through dlsym/GetProcAddress
// Default is *on*
#if !defined(TEST_ICD_EXPORT_VERSION_7)
#define TEST_ICD_EXPORT_VERSION_7 1
#endif
TestICD icd;
extern "C" {
FRAMEWORK_EXPORT TestICD* get_test_icd_func() { return &icd; }
FRAMEWORK_EXPORT TestICD* reset_icd_func() {
icd.~TestICD();
return new (&icd) TestICD();
}
}
LayerDefinition& FindLayer(std::vector<LayerDefinition>& layers, std::string layerName) {
for (auto& layer : layers) {
if (layer.layerName == layerName) return layer;
}
assert(false && "Layer name not found!");
return layers[0];
}
bool CheckLayer(std::vector<LayerDefinition>& layers, std::string layerName) {
for (auto& layer : layers) {
if (layer.layerName == layerName) return true;
}
return false;
}
bool IsInstanceExtensionSupported(const char* extension_name) {
return icd.instance_extensions.end() !=
std::find_if(icd.instance_extensions.begin(), icd.instance_extensions.end(),
[extension_name](Extension const& ext) { return string_eq(&ext.extensionName[0], extension_name); });
}
bool IsInstanceExtensionEnabled(const char* extension_name) {
return icd.enabled_instance_extensions.end() !=
std::find_if(icd.enabled_instance_extensions.begin(), icd.enabled_instance_extensions.end(),
[extension_name](Extension const& ext) { return string_eq(&ext.extensionName[0], extension_name); });
}
bool IsPhysicalDeviceExtensionAvailable(const char* extension_name) {
for (auto& phys_dev : icd.physical_devices) {
if (phys_dev.extensions.end() !=
std::find_if(phys_dev.extensions.begin(), phys_dev.extensions.end(),
[extension_name](Extension const& ext) { return ext.extensionName == extension_name; })) {
return true;
}
}
return false;
}
// typename T must have '.get()' function that returns a type U
template <typename T, typename U>
VkResult FillCountPtr(std::vector<T> const& data_vec, uint32_t* pCount, U* pData) {
if (pCount == nullptr) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
if (pData == nullptr) {
*pCount = static_cast<uint32_t>(data_vec.size());
return VK_SUCCESS;
}
uint32_t amount_written = 0;
uint32_t amount_to_write = static_cast<uint32_t>(data_vec.size());
if (*pCount < data_vec.size()) {
amount_to_write = *pCount;
}
for (size_t i = 0; i < amount_to_write; i++) {
pData[i] = data_vec[i].get();
amount_written++;
}
if (*pCount < data_vec.size()) {
*pCount = amount_written;
return VK_INCOMPLETE;
}
*pCount = amount_written;
return VK_SUCCESS;
}
template <typename T>
VkResult FillCountPtr(std::vector<T> const& data_vec, uint32_t* pCount, T* pData) {
if (pCount == nullptr) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
if (pData == nullptr) {
*pCount = static_cast<uint32_t>(data_vec.size());
return VK_SUCCESS;
}
uint32_t amount_written = 0;
uint32_t amount_to_write = static_cast<uint32_t>(data_vec.size());
if (*pCount < data_vec.size()) {
amount_to_write = *pCount;
}
for (size_t i = 0; i < amount_to_write; i++) {
pData[i] = data_vec[i];
amount_written++;
}
if (*pCount < data_vec.size()) {
*pCount = amount_written;
return VK_INCOMPLETE;
}
*pCount = amount_written;
return VK_SUCCESS;
}
//// Instance Functions ////
// VK_SUCCESS,VK_INCOMPLETE
VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceExtensionProperties(const char* pLayerName, uint32_t* pPropertyCount,
VkExtensionProperties* pProperties) {
if (pLayerName != nullptr) {
auto& layer = FindLayer(icd.instance_layers, std::string(pLayerName));
return FillCountPtr(layer.extensions, pPropertyCount, pProperties);
} else { // instance extensions
FillCountPtr(icd.instance_extensions, pPropertyCount, pProperties);
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount, VkLayerProperties* pProperties) {
return FillCountPtr(icd.instance_layers, pPropertyCount, pProperties);
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceVersion(uint32_t* pApiVersion) {
if (pApiVersion != nullptr) {
*pApiVersion = icd.icd_api_version;
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkInstance* pInstance) {
if (pCreateInfo == nullptr) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
uint32_t default_api_version = VK_API_VERSION_1_0;
uint32_t api_version =
(pCreateInfo->pApplicationInfo == nullptr) ? default_api_version : pCreateInfo->pApplicationInfo->apiVersion;
if (icd.icd_api_version < VK_API_VERSION_1_1) {
if (api_version > VK_API_VERSION_1_0) {
return VK_ERROR_INCOMPATIBLE_DRIVER;
}
}
// Add to the list of enabled extensions only those that the ICD actively supports
icd.enabled_instance_extensions.clear();
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
if (IsInstanceExtensionSupported(pCreateInfo->ppEnabledExtensionNames[i])) {
icd.enabled_instance_extensions.push_back({pCreateInfo->ppEnabledExtensionNames[i]});
}
}
// VK_SUCCESS
*pInstance = icd.instance_handle.handle;
icd.passed_in_instance_create_flags = pCreateInfo->flags;
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkDestroyInstance([[maybe_unused]] VkInstance instance,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator) {
icd.enabled_instance_extensions.clear();
}
// VK_SUCCESS,VK_INCOMPLETE
VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumeratePhysicalDevices([[maybe_unused]] VkInstance instance, uint32_t* pPhysicalDeviceCount,
VkPhysicalDevice* pPhysicalDevices) {
if (icd.enum_physical_devices_return_code != VK_SUCCESS) {
return icd.enum_physical_devices_return_code;
}
if (pPhysicalDevices == nullptr) {
*pPhysicalDeviceCount = static_cast<uint32_t>(icd.physical_devices.size());
} else {
uint32_t handles_written = 0;
for (size_t i = 0; i < icd.physical_devices.size(); i++) {
if (i < *pPhysicalDeviceCount) {
handles_written++;
pPhysicalDevices[i] = icd.physical_devices[i].vk_physical_device.handle;
} else {
*pPhysicalDeviceCount = handles_written;
return VK_INCOMPLETE;
}
}
*pPhysicalDeviceCount = handles_written;
}
return VK_SUCCESS;
}
// VK_SUCCESS,VK_INCOMPLETE, VK_ERROR_INITIALIZATION_FAILED
VKAPI_ATTR VkResult VKAPI_CALL
test_vkEnumeratePhysicalDeviceGroups([[maybe_unused]] VkInstance instance, uint32_t* pPhysicalDeviceGroupCount,
VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) {
VkResult result = VK_SUCCESS;
if (pPhysicalDeviceGroupProperties == nullptr) {
if (0 == icd.physical_device_groups.size()) {
*pPhysicalDeviceGroupCount = static_cast<uint32_t>(icd.physical_devices.size());
} else {
*pPhysicalDeviceGroupCount = static_cast<uint32_t>(icd.physical_device_groups.size());
}
} else {
// NOTE: This is a fake struct to make sure the pNext chain is properly passed down to the ICD
// vkEnumeratePhysicalDeviceGroups.
// The two versions must match:
// "FakePNext" test in loader_regresion_tests.cpp
// "test_vkEnumeratePhysicalDeviceGroups" in test_icd.cpp
struct FakePnextSharedWithICD {
VkStructureType sType;
void* pNext;
uint32_t value;
};
uint32_t group_count = 0;
if (0 == icd.physical_device_groups.size()) {
group_count = static_cast<uint32_t>(icd.physical_devices.size());
for (size_t device_group = 0; device_group < icd.physical_devices.size(); device_group++) {
if (device_group >= *pPhysicalDeviceGroupCount) {
group_count = *pPhysicalDeviceGroupCount;
result = VK_INCOMPLETE;
break;
}
pPhysicalDeviceGroupProperties[device_group].subsetAllocation = false;
pPhysicalDeviceGroupProperties[device_group].physicalDeviceCount = 1;
pPhysicalDeviceGroupProperties[device_group].physicalDevices[0] =
icd.physical_devices[device_group].vk_physical_device.handle;
for (size_t i = 1; i < VK_MAX_DEVICE_GROUP_SIZE; i++) {
pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] = {};
}
}
} else {
group_count = static_cast<uint32_t>(icd.physical_device_groups.size());
for (size_t device_group = 0; device_group < icd.physical_device_groups.size(); device_group++) {
if (device_group >= *pPhysicalDeviceGroupCount) {
group_count = *pPhysicalDeviceGroupCount;
result = VK_INCOMPLETE;
break;
}
pPhysicalDeviceGroupProperties[device_group].subsetAllocation =
icd.physical_device_groups[device_group].subset_allocation;
uint32_t handles_written = 0;
for (size_t i = 0; i < icd.physical_device_groups[device_group].physical_device_handles.size(); i++) {
handles_written++;
pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] =
icd.physical_device_groups[device_group].physical_device_handles[i]->vk_physical_device.handle;
}
for (size_t i = handles_written; i < VK_MAX_DEVICE_GROUP_SIZE; i++) {
pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] = {};
}
pPhysicalDeviceGroupProperties[device_group].physicalDeviceCount = handles_written;
}
}
// NOTE: The following code is purely to test pNext passing in vkEnumeratePhysicalDevice groups
// and includes normally invalid information.
for (size_t device_group = 0; device_group < group_count; device_group++) {
if (nullptr != pPhysicalDeviceGroupProperties[device_group].pNext) {
VkBaseInStructure* base = reinterpret_cast<VkBaseInStructure*>(pPhysicalDeviceGroupProperties[device_group].pNext);
if (base->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTI_DRAW_PROPERTIES_EXT) {
FakePnextSharedWithICD* fake = reinterpret_cast<FakePnextSharedWithICD*>(base);
fake->value = 0xDECAFBAD;
}
}
}
*pPhysicalDeviceGroupCount = static_cast<uint32_t>(group_count);
}
return result;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDebugUtilsMessengerEXT(
[[maybe_unused]] VkInstance instance, [[maybe_unused]] const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger) {
if (nullptr != pMessenger) {
uint8_t* new_handle_ptr = nullptr;
if (pAllocator) {
new_handle_ptr =
(uint8_t*)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(uint8_t*), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
} else {
new_handle_ptr = new uint8_t;
}
uint64_t fake_msgr_handle = reinterpret_cast<uint64_t>(new_handle_ptr);
icd.messenger_handles.push_back(fake_msgr_handle);
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
*pMessenger = reinterpret_cast<VkDebugUtilsMessengerEXT>(fake_msgr_handle);
#else
*pMessenger = fake_msgr_handle;
#endif
}
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkDestroyDebugUtilsMessengerEXT([[maybe_unused]] VkInstance instance,
VkDebugUtilsMessengerEXT messenger,
const VkAllocationCallbacks* pAllocator) {
if (messenger != VK_NULL_HANDLE) {
uint64_t fake_msgr_handle = (uint64_t)(messenger);
auto found_iter = std::find(icd.messenger_handles.begin(), icd.messenger_handles.end(), fake_msgr_handle);
if (found_iter != icd.messenger_handles.end()) {
// Remove it from the list
icd.messenger_handles.erase(found_iter);
// Delete the handle
if (pAllocator) {
pAllocator->pfnFree(pAllocator->pUserData, (uint8_t*)fake_msgr_handle);
} else {
delete (uint8_t*)(fake_msgr_handle);
}
} else {
std::cerr << "Messenger not found during destroy!\n";
abort();
}
}
}
// debug report create/destroy
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDebugReportCallbackEXT(
[[maybe_unused]] VkInstance instance, [[maybe_unused]] const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback) {
if (nullptr != pCallback) {
uint8_t* new_handle_ptr = nullptr;
if (pAllocator) {
new_handle_ptr =
(uint8_t*)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(uint8_t*), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
} else {
new_handle_ptr = new uint8_t;
}
uint64_t fake_msgr_handle = reinterpret_cast<uint64_t>(new_handle_ptr);
icd.callback_handles.push_back(fake_msgr_handle);
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
*pCallback = reinterpret_cast<VkDebugReportCallbackEXT>(fake_msgr_handle);
#else
*pCallback = fake_msgr_handle;
#endif
}
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkDestroyDebugReportCallbackEXT([[maybe_unused]] VkInstance instance,
VkDebugReportCallbackEXT callback,
const VkAllocationCallbacks* pAllocator) {
if (callback != VK_NULL_HANDLE) {
uint64_t fake_msgr_handle = (uint64_t)(callback);
auto found_iter = std::find(icd.callback_handles.begin(), icd.callback_handles.end(), fake_msgr_handle);
if (found_iter != icd.callback_handles.end()) {
// Remove it from the list
icd.callback_handles.erase(found_iter);
// Delete the handle
if (pAllocator) {
pAllocator->pfnFree(pAllocator->pUserData, (uint8_t*)fake_msgr_handle);
} else {
delete (uint8_t*)(fake_msgr_handle);
}
} else {
std::cerr << "callback not found during destroy!\n";
abort();
}
}
}
// Debug utils & debug marker ext stubs
VKAPI_ATTR VkResult VKAPI_CALL test_vkDebugMarkerSetObjectTagEXT(VkDevice dev, const VkDebugMarkerObjectTagInfoEXT* pTagInfo) {
if (pTagInfo && pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {
VkPhysicalDevice pd = (VkPhysicalDevice)(uintptr_t)(pTagInfo->object);
if (pd != icd.physical_devices.at(icd.lookup_device(dev).phys_dev_index).vk_physical_device.handle)
return VK_ERROR_DEVICE_LOST;
}
if (pTagInfo && pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) {
if (pTagInfo->object != icd.surface_handles.at(0)) return VK_ERROR_DEVICE_LOST;
}
if (pTagInfo && pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT) {
if (pTagInfo->object != (uint64_t)(uintptr_t)icd.instance_handle.handle) return VK_ERROR_DEVICE_LOST;
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkDebugMarkerSetObjectNameEXT(VkDevice dev, const VkDebugMarkerObjectNameInfoEXT* pNameInfo) {
if (pNameInfo && pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {
VkPhysicalDevice pd = (VkPhysicalDevice)(uintptr_t)(pNameInfo->object);
if (pd != icd.physical_devices.at(icd.lookup_device(dev).phys_dev_index).vk_physical_device.handle)
return VK_ERROR_DEVICE_LOST;
}
if (pNameInfo && pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) {
if (pNameInfo->object != icd.surface_handles.at(0)) return VK_ERROR_DEVICE_LOST;
}
if (pNameInfo && pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT) {
if (pNameInfo->object != (uint64_t)(uintptr_t)icd.instance_handle.handle) return VK_ERROR_DEVICE_LOST;
}
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkCmdDebugMarkerBeginEXT(VkCommandBuffer, const VkDebugMarkerMarkerInfoEXT*) {}
VKAPI_ATTR void VKAPI_CALL test_vkCmdDebugMarkerEndEXT(VkCommandBuffer) {}
VKAPI_ATTR void VKAPI_CALL test_vkCmdDebugMarkerInsertEXT(VkCommandBuffer, const VkDebugMarkerMarkerInfoEXT*) {}
VKAPI_ATTR VkResult VKAPI_CALL test_vkSetDebugUtilsObjectNameEXT(VkDevice dev, const VkDebugUtilsObjectNameInfoEXT* pNameInfo) {
if (pNameInfo && pNameInfo->objectType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) {
VkPhysicalDevice pd = (VkPhysicalDevice)(uintptr_t)(pNameInfo->objectHandle);
if (pd != icd.physical_devices.at(icd.lookup_device(dev).phys_dev_index).vk_physical_device.handle)
return VK_ERROR_DEVICE_LOST;
}
if (pNameInfo && pNameInfo->objectType == VK_OBJECT_TYPE_SURFACE_KHR) {
if (pNameInfo->objectHandle != icd.surface_handles.at(0)) return VK_ERROR_DEVICE_LOST;
}
if (pNameInfo && pNameInfo->objectType == VK_OBJECT_TYPE_INSTANCE) {
if (pNameInfo->objectHandle != (uint64_t)(uintptr_t)icd.instance_handle.handle) return VK_ERROR_DEVICE_LOST;
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkSetDebugUtilsObjectTagEXT(VkDevice dev, const VkDebugUtilsObjectTagInfoEXT* pTagInfo) {
if (pTagInfo && pTagInfo->objectType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) {
VkPhysicalDevice pd = (VkPhysicalDevice)(uintptr_t)(pTagInfo->objectHandle);
if (pd != icd.physical_devices.at(icd.lookup_device(dev).phys_dev_index).vk_physical_device.handle)
return VK_ERROR_DEVICE_LOST;
}
if (pTagInfo && pTagInfo->objectType == VK_OBJECT_TYPE_SURFACE_KHR) {
if (pTagInfo->objectHandle != icd.surface_handles.at(0)) return VK_ERROR_DEVICE_LOST;
}
if (pTagInfo && pTagInfo->objectType == VK_OBJECT_TYPE_INSTANCE) {
if (pTagInfo->objectHandle != (uint64_t)(uintptr_t)icd.instance_handle.handle) return VK_ERROR_DEVICE_LOST;
}
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkQueueBeginDebugUtilsLabelEXT(VkQueue, const VkDebugUtilsLabelEXT*) {}
VKAPI_ATTR void VKAPI_CALL test_vkQueueEndDebugUtilsLabelEXT(VkQueue) {}
VKAPI_ATTR void VKAPI_CALL test_vkQueueInsertDebugUtilsLabelEXT(VkQueue, const VkDebugUtilsLabelEXT*) {}
VKAPI_ATTR void VKAPI_CALL test_vkCmdBeginDebugUtilsLabelEXT(VkCommandBuffer, const VkDebugUtilsLabelEXT*) {}
VKAPI_ATTR void VKAPI_CALL test_vkCmdEndDebugUtilsLabelEXT(VkCommandBuffer) {}
VKAPI_ATTR void VKAPI_CALL test_vkCmdInsertDebugUtilsLabelEXT(VkCommandBuffer, const VkDebugUtilsLabelEXT*) {}
//// Physical Device functions ////
// VK_SUCCESS,VK_INCOMPLETE
VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateDeviceLayerProperties(VkPhysicalDevice, uint32_t*, VkLayerProperties*) {
assert(false && "ICD's don't contain layers???");
return VK_SUCCESS;
}
// VK_SUCCESS, VK_INCOMPLETE, VK_ERROR_LAYER_NOT_PRESENT
VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char* pLayerName,
uint32_t* pPropertyCount,
VkExtensionProperties* pProperties) {
auto& phys_dev = icd.GetPhysDevice(physicalDevice);
if (pLayerName != nullptr) {
assert(false && "Drivers don't contain layers???");
return VK_SUCCESS;
} else { // instance extensions
return FillCountPtr(phys_dev.extensions, pPropertyCount, pProperties);
}
}
VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
uint32_t* pQueueFamilyPropertyCount,
VkQueueFamilyProperties* pQueueFamilyProperties) {
auto& phys_dev = icd.GetPhysDevice(physicalDevice);
FillCountPtr(phys_dev.queue_family_properties, pQueueFamilyPropertyCount, pQueueFamilyProperties);
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) {
// VK_SUCCESS
auto found = std::find_if(icd.physical_devices.begin(), icd.physical_devices.end(), [physicalDevice](PhysicalDevice& phys_dev) {
return phys_dev.vk_physical_device.handle == physicalDevice;
});
if (found == icd.physical_devices.end()) return VK_ERROR_INITIALIZATION_FAILED;
auto device_handle = DispatchableHandle<VkDevice>();
*pDevice = device_handle.handle;
found->device_handles.push_back(device_handle.handle);
found->device_create_infos.push_back(DeviceCreateInfo{pCreateInfo});
for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
found->queue_handles.emplace_back();
}
icd.device_handles.emplace_back(std::move(device_handle));
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkDestroyDevice(VkDevice device, [[maybe_unused]] const VkAllocationCallbacks* pAllocator) {
auto found = std::find(icd.device_handles.begin(), icd.device_handles.end(), device);
if (found != icd.device_handles.end()) icd.device_handles.erase(found);
auto fd = icd.lookup_device(device);
if (!fd.found) return;
auto& phys_dev = icd.physical_devices.at(fd.phys_dev_index);
phys_dev.device_handles.erase(phys_dev.device_handles.begin() + fd.dev_index);
phys_dev.device_create_infos.erase(phys_dev.device_create_infos.begin() + fd.dev_index);
}
VKAPI_ATTR VkResult VKAPI_CALL generic_tool_props_function([[maybe_unused]] VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
VkPhysicalDeviceToolPropertiesEXT* pToolProperties) {
if (icd.tooling_properties.size() == 0) {
return VK_SUCCESS;
}
if (pToolProperties == nullptr && pToolCount != nullptr) {
*pToolCount = static_cast<uint32_t>(icd.tooling_properties.size());
} else if (pToolCount != nullptr) {
for (size_t i = 0; i < *pToolCount; i++) {
if (i >= icd.tooling_properties.size()) {
return VK_INCOMPLETE;
}
pToolProperties[i] = icd.tooling_properties[i];
}
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
VkPhysicalDeviceToolPropertiesEXT* pToolProperties) {
return generic_tool_props_function(physicalDevice, pToolCount, pToolProperties);
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
VkPhysicalDeviceToolPropertiesEXT* pToolProperties) {
return generic_tool_props_function(physicalDevice, pToolCount, pToolProperties);
}
template <typename T>
T to_nondispatch_handle(uint64_t handle) {
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
return reinterpret_cast<T>(handle);
#else
return handle;
#endif
}
template <typename T>
uint64_t from_nondispatch_handle(T handle) {
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
return reinterpret_cast<uint64_t>(handle);
#else
return handle;
#endif
}
//// WSI ////
template <typename HandleType>
void common_nondispatch_handle_creation(std::vector<uint64_t>& handles, HandleType* pHandle) {
if (nullptr != pHandle) {
if (handles.size() == 0)
handles.push_back(800851234);
else
handles.push_back(handles.back() + 102030);
*pHandle = to_nondispatch_handle<HandleType>(handles.back());
}
}
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
#endif
#if defined(VK_USE_PLATFORM_WIN32_KHR)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateWin32SurfaceKHR([[maybe_unused]] VkInstance instance,
[[maybe_unused]] const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice, uint32_t) { return VK_TRUE; }
#endif // VK_USE_PLATFORM_WIN32_KHR
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateWaylandSurfaceKHR([[maybe_unused]] VkInstance instance,
[[maybe_unused]] const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice, uint32_t,
struct wl_display*) {
return VK_TRUE;
}
#endif // VK_USE_PLATFORM_WAYLAND_KHR
#if defined(VK_USE_PLATFORM_XCB_KHR)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateXcbSurfaceKHR([[maybe_unused]] VkInstance instance,
[[maybe_unused]] const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice, uint32_t, xcb_connection_t*,
xcb_visualid_t) {
return VK_TRUE;
}
#endif // VK_USE_PLATFORM_XCB_KHR
#if defined(VK_USE_PLATFORM_XLIB_KHR)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateXlibSurfaceKHR([[maybe_unused]] VkInstance instance,
[[maybe_unused]] const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice, uint32_t, Display*, VisualID) {
return VK_TRUE;
}
#endif // VK_USE_PLATFORM_XLIB_KHR
#if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDirectFBSurfaceEXT(VkInstance instance,
const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex, IDirectFB* dfb) {
return VK_TRUE;
}
#endif // VK_USE_PLATFORM_DIRECTFB_EXT
#if defined(VK_USE_PLATFORM_MACOS_MVK)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateMacOSSurfaceMVK([[maybe_unused]] VkInstance instance,
[[maybe_unused]] const VkMacOSSurfaceCreateInfoMVK* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
#endif // VK_USE_PLATFORM_MACOS_MVK
#if defined(VK_USE_PLATFORM_IOS_MVK)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateIOSSurfaceMVK([[maybe_unused]] VkInstance instance,
[[maybe_unused]] const VkIOSSurfaceCreateInfoMVK* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
#endif // VK_USE_PLATFORM_IOS_MVK
#if defined(VK_USE_PLATFORM_GGP)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateStreamDescriptorSurfaceGGP(VkInstance instance,
const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
#endif // VK_USE_PLATFORM_GGP
#if defined(VK_USE_PLATFORM_METAL_EXT)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateMetalSurfaceEXT([[maybe_unused]] VkInstance instance,
[[maybe_unused]] const VkMetalSurfaceCreateInfoEXT* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
#endif // VK_USE_PLATFORM_METAL_EXT
#if defined(VK_USE_PLATFORM_SCREEN_QNX)
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateScreenSurfaceQNX(VkInstance instance, const VkScreenSurfaceCreateInfoQNX* pCreateInfo,
const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceScreenPresentationSupportQNX(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex,
struct _screen_window* window) {
return VK_TRUE;
}
#endif // VK_USE_PLATFORM_SCREEN_QNX
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateHeadlessSurfaceEXT([[maybe_unused]] VkInstance instance,
[[maybe_unused]] const VkHeadlessSurfaceCreateInfoEXT* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkDestroySurfaceKHR([[maybe_unused]] VkInstance instance, VkSurfaceKHR surface,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator) {
if (surface != VK_NULL_HANDLE) {
uint64_t fake_surf_handle = from_nondispatch_handle(surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
if (found_iter != icd.surface_handles.end()) {
// Remove it from the list
icd.surface_handles.erase(found_iter);
} else {
assert(false && "Surface not found during destroy!");
}
}
}
// VK_KHR_swapchain
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateSwapchainKHR([[maybe_unused]] VkDevice device,
[[maybe_unused]] const VkSwapchainCreateInfoKHR* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSwapchainKHR* pSwapchain) {
common_nondispatch_handle_creation(icd.swapchain_handles, pSwapchain);
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetSwapchainImagesKHR([[maybe_unused]] VkDevice device,
[[maybe_unused]] VkSwapchainKHR swapchain,
uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages) {
std::vector<uint64_t> handles{123, 234, 345, 345, 456};
if (pSwapchainImages == nullptr) {
if (pSwapchainImageCount) *pSwapchainImageCount = static_cast<uint32_t>(handles.size());
} else if (pSwapchainImageCount) {
for (uint32_t i = 0; i < *pSwapchainImageCount && i < handles.size(); i++) {
pSwapchainImages[i] = to_nondispatch_handle<VkImage>(handles.back());
}
if (*pSwapchainImageCount < handles.size()) return VK_INCOMPLETE;
}
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkDestroySwapchainKHR([[maybe_unused]] VkDevice device, VkSwapchainKHR swapchain,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator) {
if (swapchain != VK_NULL_HANDLE) {
uint64_t fake_swapchain_handle = from_nondispatch_handle(swapchain);
auto found_iter = icd.swapchain_handles.erase(
std::remove(icd.swapchain_handles.begin(), icd.swapchain_handles.end(), fake_swapchain_handle),
icd.swapchain_handles.end());
if (!icd.swapchain_handles.empty() && found_iter == icd.swapchain_handles.end()) {
assert(false && "Swapchain not found during destroy!");
}
}
}
// VK_KHR_swapchain with 1.1
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDeviceGroupSurfacePresentModesKHR([[maybe_unused]] VkDevice device,
[[maybe_unused]] VkSurfaceKHR surface,
VkDeviceGroupPresentModeFlagsKHR* pModes) {
if (!pModes) return VK_ERROR_INITIALIZATION_FAILED;
*pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHR;
return VK_SUCCESS;
}
// VK_KHR_surface
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
VkSurfaceKHR surface, VkBool32* pSupported) {
if (surface != VK_NULL_HANDLE) {
uint64_t fake_surf_handle = (uint64_t)(surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
if (found_iter == icd.surface_handles.end()) {
assert(false && "Surface not found during GetPhysicalDeviceSurfaceSupportKHR query!");
return VK_ERROR_UNKNOWN;
}
}
if (nullptr != pSupported) {
*pSupported = icd.GetPhysDevice(physicalDevice).queue_family_properties.at(queueFamilyIndex).support_present;
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) {
if (surface != VK_NULL_HANDLE) {
uint64_t fake_surf_handle = (uint64_t)(surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
if (found_iter == icd.surface_handles.end()) {
assert(false && "Surface not found during GetPhysicalDeviceSurfaceCapabilitiesKHR query!");
return VK_ERROR_UNKNOWN;
}
}
if (nullptr != pSurfaceCapabilities) {
*pSurfaceCapabilities = icd.GetPhysDevice(physicalDevice).surface_capabilities;
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
uint32_t* pSurfaceFormatCount,
VkSurfaceFormatKHR* pSurfaceFormats) {
if (surface != VK_NULL_HANDLE) {
uint64_t fake_surf_handle = (uint64_t)(surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
if (found_iter == icd.surface_handles.end()) {
assert(false && "Surface not found during GetPhysicalDeviceSurfaceFormatsKHR query!");
return VK_ERROR_UNKNOWN;
}
}
FillCountPtr(icd.GetPhysDevice(physicalDevice).surface_formats, pSurfaceFormatCount, pSurfaceFormats);
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
uint32_t* pPresentModeCount,
VkPresentModeKHR* pPresentModes) {
if (surface != VK_NULL_HANDLE) {
uint64_t fake_surf_handle = (uint64_t)(surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
if (found_iter == icd.surface_handles.end()) {
assert(false && "Surface not found during GetPhysicalDeviceSurfacePresentModesKHR query!");
return VK_ERROR_UNKNOWN;
}
}
FillCountPtr(icd.GetPhysDevice(physicalDevice).surface_present_modes, pPresentModeCount, pPresentModes);
return VK_SUCCESS;
}
// VK_KHR_display
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
uint32_t* pPropertyCount,
VkDisplayPropertiesKHR* pProperties) {
FillCountPtr(icd.GetPhysDevice(physicalDevice).display_properties, pPropertyCount, pProperties);
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
uint32_t* pPropertyCount,
VkDisplayPlanePropertiesKHR* pProperties) {
FillCountPtr(icd.GetPhysDevice(physicalDevice).display_plane_properties, pPropertyCount, pProperties);
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,
[[maybe_unused]] uint32_t planeIndex,
uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) {
FillCountPtr(icd.GetPhysDevice(physicalDevice).displays, pDisplayCount, pDisplays);
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice,
[[maybe_unused]] VkDisplayKHR display, uint32_t* pPropertyCount,
VkDisplayModePropertiesKHR* pProperties) {
FillCountPtr(icd.GetPhysDevice(physicalDevice).display_mode_properties, pPropertyCount, pProperties);
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, [[maybe_unused]] VkDisplayKHR display,
[[maybe_unused]] const VkDisplayModeCreateInfoKHR* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkDisplayModeKHR* pMode) {
if (nullptr != pMode) {
*pMode = icd.GetPhysDevice(physicalDevice).display_mode;
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice,
[[maybe_unused]] VkDisplayModeKHR mode,
[[maybe_unused]] uint32_t planeIndex,
VkDisplayPlaneCapabilitiesKHR* pCapabilities) {
if (nullptr != pCapabilities) {
*pCapabilities = icd.GetPhysDevice(physicalDevice).display_plane_capabilities;
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDisplayPlaneSurfaceKHR(
[[maybe_unused]] VkInstance instance, [[maybe_unused]] const VkDisplaySurfaceCreateInfoKHR* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
common_nondispatch_handle_creation(icd.surface_handles, pSurface);
return VK_SUCCESS;
}
// VK_KHR_get_surface_capabilities2
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice,
const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
VkSurfaceCapabilities2KHR* pSurfaceCapabilities) {
if (nullptr != pSurfaceInfo && nullptr != pSurfaceCapabilities) {
return test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, pSurfaceInfo->surface,
&pSurfaceCapabilities->surfaceCapabilities);
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
uint32_t* pSurfaceFormatCount,
VkSurfaceFormat2KHR* pSurfaceFormats) {
if (nullptr != pSurfaceFormatCount) {
test_vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, pSurfaceInfo->surface, pSurfaceFormatCount, nullptr);
if (nullptr != pSurfaceFormats) {
auto& phys_dev = icd.GetPhysDevice(physicalDevice);
// Since the structures are different, we have to copy each item over seperately. Since we have multiple, we
// have to manually copy the data here instead of calling the next function
for (uint32_t cnt = 0; cnt < *pSurfaceFormatCount; ++cnt) {
memcpy(&pSurfaceFormats[cnt].surfaceFormat, &phys_dev.surface_formats[cnt], sizeof(VkSurfaceFormatKHR));
}
}
}
return VK_SUCCESS;
}
// VK_KHR_display_swapchain
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateSharedSwapchainsKHR([[maybe_unused]] VkDevice device, uint32_t swapchainCount,
const VkSwapchainCreateInfoKHR* pCreateInfos,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkSwapchainKHR* pSwapchains) {
for (uint32_t i = 0; i < swapchainCount; i++) {
uint64_t surface_integer_value = from_nondispatch_handle(pCreateInfos[i].surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), surface_integer_value);
if (found_iter == icd.surface_handles.end()) {
return VK_ERROR_INITIALIZATION_FAILED;
}
common_nondispatch_handle_creation(icd.swapchain_handles, &pSwapchains[i]);
}
return VK_SUCCESS;
}
//// misc
VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateCommandPool([[maybe_unused]] VkDevice device,
[[maybe_unused]] const VkCommandPoolCreateInfo* pCreateInfo,
[[maybe_unused]] const VkAllocationCallbacks* pAllocator,
VkCommandPool* pCommandPool) {
if (pCommandPool != nullptr) {
pCommandPool = reinterpret_cast<VkCommandPool*>(0xdeadbeefdeadbeef);
}
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkDestroyCommandPool(VkDevice, VkCommandPool, const VkAllocationCallbacks*) {
// do nothing, leak memory for now
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkAllocateCommandBuffers([[maybe_unused]] VkDevice device,
const VkCommandBufferAllocateInfo* pAllocateInfo,
VkCommandBuffer* pCommandBuffers) {
if (pAllocateInfo != nullptr && pCommandBuffers != nullptr) {
for (size_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
icd.allocated_command_buffers.push_back({});
pCommandBuffers[i] = icd.allocated_command_buffers.back().handle;
}
}
return VK_SUCCESS;
}
VKAPI_ATTR void VKAPI_CALL test_vkGetDeviceQueue([[maybe_unused]] VkDevice device, [[maybe_unused]] uint32_t queueFamilyIndex,
uint32_t queueIndex, VkQueue* pQueue) {
auto fd = icd.lookup_device(device);
if (fd.found) {
*pQueue = icd.physical_devices.at(fd.phys_dev_index).queue_handles[queueIndex].handle;
}
}
// VK_EXT_acquire_drm_display
VKAPI_ATTR VkResult VKAPI_CALL test_vkAcquireDrmDisplayEXT(VkPhysicalDevice, int32_t, VkDisplayKHR) { return VK_SUCCESS; }
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDrmDisplayEXT(VkPhysicalDevice physicalDevice, [[maybe_unused]] int32_t drmFd,
[[maybe_unused]] uint32_t connectorId, VkDisplayKHR* display) {
if (nullptr != display && icd.GetPhysDevice(physicalDevice).displays.size() > 0) {
*display = icd.GetPhysDevice(physicalDevice).displays[0];
}
return VK_SUCCESS;
}
//// stubs
// 1.0
VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) {