Debian Codegraph @

tests/framework/icd/test_icd.cpp

raw
1 /*
2 * Copyright (c) 2021-2023 The Khronos Group Inc.
3 * Copyright (c) 2021-2023 Valve Corporation
4 * Copyright (c) 2021-2023 LunarG, Inc.
5 * Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
6 * Copyright (c) 2023-2023 RasterGrid Kft.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and/or associated documentation files (the "Materials"), to
10 * deal in the Materials without restriction, including without limitation the
11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Materials, and to permit persons to whom the Materials are
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice(s) and this permission notice shall be included in
16 * all copies or substantial portions of the Materials.
17 *
18 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 *
22 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
25 * USE OR OTHER DEALINGS IN THE MATERIALS.
26 *
27 * Author: Charles Giessen <[email protected]>
28 */
29
30 #include "test_icd.h"
31
32 #include <assert.h>
33 #include <cstring>
34
35 #include <iostream>
36
37 #include "equality_helpers.h"
38
39 // export vk_icdGetInstanceProcAddr
40 #if !defined(TEST_ICD_EXPORT_ICD_GIPA)
41 #define TEST_ICD_EXPORT_ICD_GIPA 0
42 #endif
43
44 // export vk_icdNegotiateLoaderICDInterfaceVersion
45 #if !defined(TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION)
46 #define TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION 0
47 #endif
48
49 // export vk_icdGetPhysicalDeviceProcAddr
50 #if !defined(TEST_ICD_EXPORT_ICD_GPDPA)
51 #define TEST_ICD_EXPORT_ICD_GPDPA 0
52 #endif
53
54 // export vk_icdEnumerateAdapterPhysicalDevices
55 #if !defined(TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES)
56 #define TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES 0
57 #endif
58
59 // export vk_icdNegotiateLoaderICDInterfaceVersion, vk_icdEnumerateAdapterPhysicalDevices, and vk_icdGetPhysicalDeviceProcAddr
60 // through dlsym/GetProcAddress
61 // Default is *on*
62 #if !defined(TEST_ICD_EXPORT_VERSION_7)
63 #define TEST_ICD_EXPORT_VERSION_7 1
64 #endif
65
66 TestICD icd;
67 extern "C" {
68 FRAMEWORK_EXPORT TestICD* get_test_icd_func() { return &icd; }
69 FRAMEWORK_EXPORT TestICD* reset_icd_func() {
70 icd.~TestICD();
71 return new (&icd) TestICD();
72 }
73 }
74
75 LayerDefinition& FindLayer(std::vector<LayerDefinition>& layers, std::string layerName) {
76 for (auto& layer : layers) {
77 if (layer.layerName == layerName) return layer;
78 }
79 assert(false && "Layer name not found!");
80 return layers[0];
81 }
82 bool CheckLayer(std::vector<LayerDefinition>& layers, std::string layerName) {
83 for (auto& layer : layers) {
84 if (layer.layerName == layerName) return true;
85 }
86 return false;
87 }
88
89 bool IsInstanceExtensionSupported(const char* extension_name) {
90 return icd.instance_extensions.end() !=
91 std::find_if(icd.instance_extensions.begin(), icd.instance_extensions.end(),
92 [extension_name](Extension const& ext) { return string_eq(&ext.extensionName[0], extension_name); });
93 }
94
95 bool IsInstanceExtensionEnabled(const char* extension_name) {
96 return icd.enabled_instance_extensions.end() !=
97 std::find_if(icd.enabled_instance_extensions.begin(), icd.enabled_instance_extensions.end(),
98 [extension_name](Extension const& ext) { return string_eq(&ext.extensionName[0], extension_name); });
99 }
100
101 bool IsPhysicalDeviceExtensionAvailable(const char* extension_name) {
102 for (auto const& [phys_dev_handle, phys_dev] : icd.physical_devices) {
103 if (phys_dev.extensions.end() !=
104 std::find_if(phys_dev.extensions.begin(), phys_dev.extensions.end(),
105 [extension_name](Extension const& ext) { return ext.extensionName == extension_name; })) {
106 return true;
107 }
108 }
109 return false;
110 }
111
112 PhysicalDevice& GetPhysDevice(VkPhysicalDevice physicalDevice) {
113 if (icd.physical_devices.count(physicalDevice) > 0) {
114 return icd.physical_devices.at(physicalDevice);
115 }
116 assert(false && "vkPhysicalDevice not found!");
117 return icd.physical_devices.at(icd.physical_devices.begin()->first);
118 }
119
120 bool is_valid_surface(VkSurfaceKHR surface_to_check) {
121 uint64_t surf_handle = (uint64_t)(surface_to_check);
122 auto found = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), surf_handle);
123 return found != icd.surface_handles.end();
124 }
125
126 struct FindDevice {
127 bool found = false;
128 VkPhysicalDevice phys_dev = 0;
129 uint32_t dev_index = 0;
130 };
131
132 FindDevice lookup_device(VkDevice device) {
133 FindDevice fd{};
134 auto it = icd.device_to_physical_device_map.find(device);
135 if (it != icd.device_to_physical_device_map.end()) {
136 auto& phys_dev = icd.physical_devices.at(it->second);
137 fd.found = true;
138 fd.phys_dev = phys_dev.vk_physical_device.handle;
139 for (uint32_t d = 0; d < phys_dev.device_handles.size(); d++) {
140 if (phys_dev.device_handles.at(d) == device) {
141 fd.dev_index = d;
142 break;
143 }
144 }
145 return fd;
146 }
147 return fd;
148 }
149
150 // typename T must have '.get()' function that returns a type U
151 template <typename T, typename U>
152 VkResult FillCountPtr(std::vector<T> const& data_vec, uint32_t* pCount, U* pData) {
153 if (pCount == nullptr) {
154 return VK_ERROR_OUT_OF_HOST_MEMORY;
155 }
156 if (pData == nullptr) {
157 *pCount = static_cast<uint32_t>(data_vec.size());
158 return VK_SUCCESS;
159 }
160 uint32_t amount_written = 0;
161 uint32_t amount_to_write = static_cast<uint32_t>(data_vec.size());
162 if (*pCount < data_vec.size()) {
163 amount_to_write = *pCount;
164 }
165 for (size_t i = 0; i < amount_to_write; i++) {
166 pData[i] = data_vec[i].get();
167 amount_written++;
168 }
169 if (*pCount < data_vec.size()) {
170 *pCount = amount_written;
171 return VK_INCOMPLETE;
172 }
173 *pCount = amount_written;
174 return VK_SUCCESS;
175 }
176
177 template <typename T>
178 VkResult FillCountPtr(std::vector<T> const& data_vec, uint32_t* pCount, T* pData) {
179 if (pCount == nullptr) {
180 return VK_ERROR_OUT_OF_HOST_MEMORY;
181 }
182 if (pData == nullptr) {
183 *pCount = static_cast<uint32_t>(data_vec.size());
184 return VK_SUCCESS;
185 }
186 uint32_t amount_written = 0;
187 uint32_t amount_to_write = static_cast<uint32_t>(data_vec.size());
188 if (*pCount < data_vec.size()) {
189 amount_to_write = *pCount;
190 }
191 for (size_t i = 0; i < amount_to_write; i++) {
192 pData[i] = data_vec[i];
193 amount_written++;
194 }
195 if (*pCount < data_vec.size()) {
196 *pCount = amount_written;
197 return VK_INCOMPLETE;
198 }
199 *pCount = amount_written;
200 return VK_SUCCESS;
201 }
202
203 void check_allocator_handle(const VkAllocationCallbacks* pAllocator) {
204 if (pAllocator) {
205 if (nullptr == pAllocator->pfnAllocation || nullptr == pAllocator->pfnFree || nullptr == pAllocator->pfnReallocation) {
206 std::cout << "pAllocator functions are NULL!\n";
207 abort();
208 }
209 }
210 }
211
212 //// Instance Functions ////
213
214 // VK_SUCCESS,VK_INCOMPLETE
215 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceExtensionProperties(const char* pLayerName, uint32_t* pPropertyCount,
216 VkExtensionProperties* pProperties) {
217 if (pLayerName != nullptr) {
218 auto& layer = FindLayer(icd.instance_layers, std::string(pLayerName));
219 return FillCountPtr(layer.extensions, pPropertyCount, pProperties);
220 } else { // instance extensions
221 FillCountPtr(icd.instance_extensions, pPropertyCount, pProperties);
222 }
223
224 return VK_SUCCESS;
225 }
226
227 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount, VkLayerProperties* pProperties) {
228 return FillCountPtr(icd.instance_layers, pPropertyCount, pProperties);
229 }
230
231 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceVersion(uint32_t* pApiVersion) {
232 if (pApiVersion != nullptr) {
233 *pApiVersion = icd.icd_api_version;
234 }
235 return VK_SUCCESS;
236 }
237
238 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo,
239 const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) {
240 if (pCreateInfo == nullptr) {
241 return VK_ERROR_OUT_OF_HOST_MEMORY;
242 }
243 check_allocator_handle(pAllocator);
244
245 uint32_t default_api_version = VK_API_VERSION_1_0;
246 uint32_t api_version =
247 (pCreateInfo->pApplicationInfo == nullptr) ? default_api_version : pCreateInfo->pApplicationInfo->apiVersion;
248
249 if (icd.icd_api_version < VK_API_VERSION_1_1) {
250 if (api_version > VK_API_VERSION_1_0) {
251 return VK_ERROR_INCOMPATIBLE_DRIVER;
252 }
253 }
254
255 // Add to the list of enabled extensions only those that the ICD actively supports
256 icd.enabled_instance_extensions.clear();
257 for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
258 if (IsInstanceExtensionSupported(pCreateInfo->ppEnabledExtensionNames[i])) {
259 icd.enabled_instance_extensions.push_back({pCreateInfo->ppEnabledExtensionNames[i]});
260 }
261 }
262
263 // VK_SUCCESS
264 *pInstance = icd.instance_handle.handle;
265
266 icd.passed_in_instance_create_flags = pCreateInfo->flags;
267
268 return VK_SUCCESS;
269 }
270
271 VKAPI_ATTR void VKAPI_CALL test_vkDestroyInstance([[maybe_unused]] VkInstance instance, const VkAllocationCallbacks* pAllocator) {
272 icd.enabled_instance_extensions.clear();
273 check_allocator_handle(pAllocator);
274 }
275
276 // VK_SUCCESS,VK_INCOMPLETE
277 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumeratePhysicalDevices([[maybe_unused]] VkInstance instance, uint32_t* pPhysicalDeviceCount,
278 VkPhysicalDevice* pPhysicalDevices) {
279 if (icd.enum_physical_devices_return_code != VK_SUCCESS) {
280 return icd.enum_physical_devices_return_code;
281 }
282 if (pPhysicalDevices == nullptr) {
283 *pPhysicalDeviceCount = static_cast<uint32_t>(icd.physical_devices.size());
284 } else {
285 using SortPair = std::pair<size_t, VkPhysicalDevice>;
286 std::vector<SortPair> in_order_phys_dev;
287 for (auto const& [phys_dev_handle, phys_dev] : icd.physical_devices) {
288 in_order_phys_dev.push_back({phys_dev.iteration_order, phys_dev_handle});
289 }
290
291 std::sort(in_order_phys_dev.begin(), in_order_phys_dev.end(),
292 [](SortPair const& a, SortPair const& b) { return a.first < b.first; });
293
294 uint32_t handles_written = 0;
295 for (auto const& phys_dev : in_order_phys_dev) {
296 if (handles_written + 1 > *pPhysicalDeviceCount) {
297 *pPhysicalDeviceCount = handles_written;
298 return VK_INCOMPLETE;
299 }
300 pPhysicalDevices[handles_written++] = phys_dev.second;
301 }
302 *pPhysicalDeviceCount = handles_written;
303 }
304 return VK_SUCCESS;
305 }
306
307 // VK_SUCCESS,VK_INCOMPLETE, VK_ERROR_INITIALIZATION_FAILED
308 VKAPI_ATTR VkResult VKAPI_CALL
309 test_vkEnumeratePhysicalDeviceGroups([[maybe_unused]] VkInstance instance, uint32_t* pPhysicalDeviceGroupCount,
310 VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) {
311 VkResult result = VK_SUCCESS;
312
313 if (pPhysicalDeviceGroupProperties == nullptr) {
314 if (0 == icd.physical_device_groups.size()) {
315 *pPhysicalDeviceGroupCount = static_cast<uint32_t>(icd.physical_devices.size());
316 } else {
317 *pPhysicalDeviceGroupCount = static_cast<uint32_t>(icd.physical_device_groups.size());
318 }
319 } else {
320 // NOTE: This is a fake struct to make sure the pNext chain is properly passed down to the ICD
321 // vkEnumeratePhysicalDeviceGroups.
322 // The two versions must match:
323 // "FakePNext" test in loader_regresion_tests.cpp
324 // "test_vkEnumeratePhysicalDeviceGroups" in test_icd.cpp
325 struct FakePnextSharedWithICD {
326 VkStructureType sType;
327 void* pNext;
328 uint32_t value;
329 };
330
331 uint32_t group_count = 0;
332 if (0 == icd.physical_device_groups.size()) {
333 group_count = static_cast<uint32_t>(icd.physical_devices.size());
334 for (size_t device_group = 0; device_group < icd.physical_devices.size(); device_group++) {
335 if (device_group >= *pPhysicalDeviceGroupCount) {
336 group_count = *pPhysicalDeviceGroupCount;
337 result = VK_INCOMPLETE;
338 break;
339 }
340
341 pPhysicalDeviceGroupProperties[device_group].subsetAllocation = false;
342 pPhysicalDeviceGroupProperties[device_group].physicalDeviceCount = 1;
343 for (auto const& [phys_dev_handle, phys_dev] : icd.physical_devices) {
344 if (phys_dev.iteration_order == device_group) {
345 pPhysicalDeviceGroupProperties[device_group].physicalDevices[0] = phys_dev_handle;
346 break;
347 }
348 }
349 for (size_t i = 1; i < VK_MAX_DEVICE_GROUP_SIZE; i++) {
350 pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] = {};
351 }
352 }
353 } else {
354 group_count = static_cast<uint32_t>(icd.physical_device_groups.size());
355 for (size_t device_group = 0; device_group < icd.physical_device_groups.size(); device_group++) {
356 if (device_group >= *pPhysicalDeviceGroupCount) {
357 group_count = *pPhysicalDeviceGroupCount;
358 result = VK_INCOMPLETE;
359 break;
360 }
361 pPhysicalDeviceGroupProperties[device_group].subsetAllocation =
362 icd.physical_device_groups[device_group].subset_allocation;
363 uint32_t handles_written = 0;
364 for (size_t i = 0; i < icd.physical_device_groups[device_group].physical_device_handles.size(); i++) {
365 handles_written++;
366 pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] =
367 icd.physical_device_groups[device_group].physical_device_handles[i]->vk_physical_device.handle;
368 }
369 for (size_t i = handles_written; i < VK_MAX_DEVICE_GROUP_SIZE; i++) {
370 pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] = {};
371 }
372 pPhysicalDeviceGroupProperties[device_group].physicalDeviceCount = handles_written;
373 }
374 }
375 // NOTE: The following code is purely to test pNext passing in vkEnumeratePhysicalDevice groups
376 // and includes normally invalid information.
377 for (size_t device_group = 0; device_group < group_count; device_group++) {
378 if (nullptr != pPhysicalDeviceGroupProperties[device_group].pNext) {
379 VkBaseInStructure* base = reinterpret_cast<VkBaseInStructure*>(pPhysicalDeviceGroupProperties[device_group].pNext);
380 if (base->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTI_DRAW_PROPERTIES_EXT) {
381 FakePnextSharedWithICD* fake = reinterpret_cast<FakePnextSharedWithICD*>(base);
382 fake->value = 0xDECAFBAD;
383 }
384 }
385 }
386 *pPhysicalDeviceGroupCount = static_cast<uint32_t>(group_count);
387 }
388 return result;
389 }
390
391 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDebugUtilsMessengerEXT(
392 [[maybe_unused]] VkInstance instance, [[maybe_unused]] const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
393 const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger) {
394 if (nullptr != pMessenger) {
395 uint8_t* new_handle_ptr = nullptr;
396 if (pAllocator) {
397 new_handle_ptr =
398 (uint8_t*)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(uint8_t*), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
399 } else {
400 new_handle_ptr = new uint8_t;
401 }
402 uint64_t fake_msgr_handle = reinterpret_cast<uint64_t>(new_handle_ptr);
403 icd.messenger_handles.push_back(fake_msgr_handle);
404 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
405 defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
406 *pMessenger = reinterpret_cast<VkDebugUtilsMessengerEXT>(fake_msgr_handle);
407 #else
408 *pMessenger = fake_msgr_handle;
409 #endif
410 }
411 return VK_SUCCESS;
412 }
413
414 VKAPI_ATTR void VKAPI_CALL test_vkDestroyDebugUtilsMessengerEXT([[maybe_unused]] VkInstance instance,
415 VkDebugUtilsMessengerEXT messenger,
416 const VkAllocationCallbacks* pAllocator) {
417 if (messenger != VK_NULL_HANDLE) {
418 uint64_t fake_msgr_handle = (uint64_t)(messenger);
419 auto found_iter = std::find(icd.messenger_handles.begin(), icd.messenger_handles.end(), fake_msgr_handle);
420 if (found_iter != icd.messenger_handles.end()) {
421 // Remove it from the list
422 icd.messenger_handles.erase(found_iter);
423 // Delete the handle
424 if (pAllocator) {
425 pAllocator->pfnFree(pAllocator->pUserData, (uint8_t*)fake_msgr_handle);
426 } else {
427 delete (uint8_t*)(fake_msgr_handle);
428 }
429 } else {
430 std::cerr << "Messenger not found during destroy!\n";
431 abort();
432 }
433 }
434 }
435
436 // debug report create/destroy
437
438 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDebugReportCallbackEXT(
439 [[maybe_unused]] VkInstance instance, [[maybe_unused]] const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
440 const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback) {
441 if (nullptr != pCallback) {
442 uint8_t* new_handle_ptr = nullptr;
443 if (pAllocator) {
444 new_handle_ptr =
445 (uint8_t*)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(uint8_t*), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
446 } else {
447 new_handle_ptr = new uint8_t;
448 }
449 uint64_t fake_msgr_handle = reinterpret_cast<uint64_t>(new_handle_ptr);
450 icd.callback_handles.push_back(fake_msgr_handle);
451 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
452 defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
453 *pCallback = reinterpret_cast<VkDebugReportCallbackEXT>(fake_msgr_handle);
454 #else
455 *pCallback = fake_msgr_handle;
456 #endif
457 }
458 return VK_SUCCESS;
459 }
460
461 VKAPI_ATTR void VKAPI_CALL test_vkDestroyDebugReportCallbackEXT([[maybe_unused]] VkInstance instance,
462 VkDebugReportCallbackEXT callback,
463 const VkAllocationCallbacks* pAllocator) {
464 if (callback != VK_NULL_HANDLE) {
465 uint64_t fake_msgr_handle = (uint64_t)(callback);
466 auto found_iter = std::find(icd.callback_handles.begin(), icd.callback_handles.end(), fake_msgr_handle);
467 if (found_iter != icd.callback_handles.end()) {
468 // Remove it from the list
469 icd.callback_handles.erase(found_iter);
470 // Delete the handle
471 if (pAllocator) {
472 pAllocator->pfnFree(pAllocator->pUserData, (uint8_t*)fake_msgr_handle);
473 } else {
474 delete (uint8_t*)(fake_msgr_handle);
475 }
476 } else {
477 std::cerr << "callback not found during destroy!\n";
478 abort();
479 }
480 }
481 }
482
483 // Debug utils & debug marker ext stubs
484 VKAPI_ATTR VkResult VKAPI_CALL test_vkDebugMarkerSetObjectTagEXT(VkDevice dev, const VkDebugMarkerObjectTagInfoEXT* pTagInfo) {
485 if (pTagInfo && pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {
486 VkPhysicalDevice pd = (VkPhysicalDevice)(uintptr_t)(pTagInfo->object);
487 if (pd != lookup_device(dev).phys_dev) return VK_ERROR_DEVICE_LOST;
488 }
489 if (pTagInfo && pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) {
490 if (pTagInfo->object != icd.surface_handles.at(0)) return VK_ERROR_DEVICE_LOST;
491 }
492 if (pTagInfo && pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT) {
493 if (pTagInfo->object != (uint64_t)(uintptr_t)icd.instance_handle.handle) return VK_ERROR_DEVICE_LOST;
494 }
495 return VK_SUCCESS;
496 }
497 VKAPI_ATTR VkResult VKAPI_CALL test_vkDebugMarkerSetObjectNameEXT(VkDevice dev, const VkDebugMarkerObjectNameInfoEXT* pNameInfo) {
498 if (pNameInfo && pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) {
499 VkPhysicalDevice pd = (VkPhysicalDevice)(uintptr_t)(pNameInfo->object);
500 if (pd != lookup_device(dev).phys_dev) return VK_ERROR_DEVICE_LOST;
501 }
502 if (pNameInfo && pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) {
503 if (pNameInfo->object != icd.surface_handles.at(0)) return VK_ERROR_DEVICE_LOST;
504 }
505 if (pNameInfo && pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT) {
506 if (pNameInfo->object != (uint64_t)(uintptr_t)icd.instance_handle.handle) return VK_ERROR_DEVICE_LOST;
507 }
508 return VK_SUCCESS;
509 }
510 VKAPI_ATTR void VKAPI_CALL test_vkCmdDebugMarkerBeginEXT(VkCommandBuffer, const VkDebugMarkerMarkerInfoEXT*) {}
511 VKAPI_ATTR void VKAPI_CALL test_vkCmdDebugMarkerEndEXT(VkCommandBuffer) {}
512 VKAPI_ATTR void VKAPI_CALL test_vkCmdDebugMarkerInsertEXT(VkCommandBuffer, const VkDebugMarkerMarkerInfoEXT*) {}
513
514 VKAPI_ATTR VkResult VKAPI_CALL test_vkSetDebugUtilsObjectNameEXT(VkDevice dev, const VkDebugUtilsObjectNameInfoEXT* pNameInfo) {
515 if (pNameInfo && pNameInfo->objectType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) {
516 VkPhysicalDevice pd = (VkPhysicalDevice)(uintptr_t)(pNameInfo->objectHandle);
517 if (pd != lookup_device(dev).phys_dev) return VK_ERROR_DEVICE_LOST;
518 }
519 if (pNameInfo && pNameInfo->objectType == VK_OBJECT_TYPE_SURFACE_KHR) {
520 if (pNameInfo->objectHandle != icd.surface_handles.at(0)) return VK_ERROR_DEVICE_LOST;
521 }
522 if (pNameInfo && pNameInfo->objectType == VK_OBJECT_TYPE_INSTANCE) {
523 if (pNameInfo->objectHandle != (uint64_t)(uintptr_t)icd.instance_handle.handle) return VK_ERROR_DEVICE_LOST;
524 }
525 return VK_SUCCESS;
526 }
527 VKAPI_ATTR VkResult VKAPI_CALL test_vkSetDebugUtilsObjectTagEXT(VkDevice dev, const VkDebugUtilsObjectTagInfoEXT* pTagInfo) {
528 if (pTagInfo && pTagInfo->objectType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) {
529 VkPhysicalDevice pd = (VkPhysicalDevice)(uintptr_t)(pTagInfo->objectHandle);
530 if (pd != lookup_device(dev).phys_dev) return VK_ERROR_DEVICE_LOST;
531 }
532 if (pTagInfo && pTagInfo->objectType == VK_OBJECT_TYPE_SURFACE_KHR) {
533 if (pTagInfo->objectHandle != icd.surface_handles.at(0)) return VK_ERROR_DEVICE_LOST;
534 }
535 if (pTagInfo && pTagInfo->objectType == VK_OBJECT_TYPE_INSTANCE) {
536 if (pTagInfo->objectHandle != (uint64_t)(uintptr_t)icd.instance_handle.handle) return VK_ERROR_DEVICE_LOST;
537 }
538 return VK_SUCCESS;
539 }
540 VKAPI_ATTR void VKAPI_CALL test_vkQueueBeginDebugUtilsLabelEXT(VkQueue, const VkDebugUtilsLabelEXT*) {}
541 VKAPI_ATTR void VKAPI_CALL test_vkQueueEndDebugUtilsLabelEXT(VkQueue) {}
542 VKAPI_ATTR void VKAPI_CALL test_vkQueueInsertDebugUtilsLabelEXT(VkQueue, const VkDebugUtilsLabelEXT*) {}
543 VKAPI_ATTR void VKAPI_CALL test_vkCmdBeginDebugUtilsLabelEXT(VkCommandBuffer, const VkDebugUtilsLabelEXT*) {}
544 VKAPI_ATTR void VKAPI_CALL test_vkCmdEndDebugUtilsLabelEXT(VkCommandBuffer) {}
545 VKAPI_ATTR void VKAPI_CALL test_vkCmdInsertDebugUtilsLabelEXT(VkCommandBuffer, const VkDebugUtilsLabelEXT*) {}
546
547 //// Physical Device functions ////
548
549 // VK_SUCCESS,VK_INCOMPLETE
550 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateDeviceLayerProperties(VkPhysicalDevice, uint32_t*, VkLayerProperties*) {
551 assert(false && "ICD's don't contain layers???");
552 return VK_SUCCESS;
553 }
554
555 // VK_SUCCESS, VK_INCOMPLETE, VK_ERROR_LAYER_NOT_PRESENT
556 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char* pLayerName,
557 uint32_t* pPropertyCount,
558 VkExtensionProperties* pProperties) {
559 auto& phys_dev = GetPhysDevice(physicalDevice);
560 if (pLayerName != nullptr) {
561 assert(false && "Drivers don't contain layers???");
562 return VK_SUCCESS;
563 } else { // instance extensions
564 return FillCountPtr(phys_dev.extensions, pPropertyCount, pProperties);
565 }
566 }
567
568 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
569 uint32_t* pQueueFamilyPropertyCount,
570 VkQueueFamilyProperties* pQueueFamilyProperties) {
571 auto& phys_dev = GetPhysDevice(physicalDevice);
572 FillCountPtr(phys_dev.queue_family_properties, pQueueFamilyPropertyCount, pQueueFamilyProperties);
573 }
574
575 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo,
576 const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) {
577 check_allocator_handle(pAllocator);
578 if (icd.physical_devices.count(physicalDevice) == 0) {
579 return VK_ERROR_INITIALIZATION_FAILED;
580 }
581 auto& found = icd.physical_devices.at(physicalDevice);
582 auto device_handle = DispatchableHandle<VkDevice>();
583 *pDevice = device_handle.handle;
584 found.device_handles.push_back(device_handle.handle);
585 found.device_create_infos.emplace_back(pCreateInfo);
586 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
587 found.queue_handles.emplace_back();
588 }
589 icd.device_to_physical_device_map.emplace(device_handle.handle, physicalDevice);
590 icd.device_handles.emplace_back(std::move(device_handle));
591 return VK_SUCCESS;
592 }
593
594 VKAPI_ATTR void VKAPI_CALL test_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) {
595 check_allocator_handle(pAllocator);
596 auto found = std::find(icd.device_handles.begin(), icd.device_handles.end(), device);
597 if (found != icd.device_handles.end()) icd.device_handles.erase(found);
598 auto fd = lookup_device(device);
599 if (!fd.found) return;
600 auto& phys_dev = icd.physical_devices.at(fd.phys_dev);
601 phys_dev.device_handles.erase(phys_dev.device_handles.begin() + fd.dev_index);
602 phys_dev.device_create_infos.erase(phys_dev.device_create_infos.begin() + fd.dev_index);
603 icd.device_to_physical_device_map.erase(device);
604 }
605
606 VKAPI_ATTR VkResult VKAPI_CALL generic_tool_props_function([[maybe_unused]] VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
607 VkPhysicalDeviceToolPropertiesEXT* pToolProperties) {
608 if (icd.tooling_properties.size() == 0) {
609 return VK_SUCCESS;
610 }
611 if (pToolProperties == nullptr && pToolCount != nullptr) {
612 *pToolCount = static_cast<uint32_t>(icd.tooling_properties.size());
613 } else if (pToolCount != nullptr) {
614 for (size_t i = 0; i < *pToolCount; i++) {
615 if (i >= icd.tooling_properties.size()) {
616 return VK_INCOMPLETE;
617 }
618 pToolProperties[i] = icd.tooling_properties[i];
619 }
620 }
621 return VK_SUCCESS;
622 }
623
624 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
625 VkPhysicalDeviceToolPropertiesEXT* pToolProperties) {
626 return generic_tool_props_function(physicalDevice, pToolCount, pToolProperties);
627 }
628
629 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
630 VkPhysicalDeviceToolPropertiesEXT* pToolProperties) {
631 return generic_tool_props_function(physicalDevice, pToolCount, pToolProperties);
632 }
633
634 template <typename T>
635 T to_nondispatch_handle(uint64_t handle) {
636 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
637 defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
638 return reinterpret_cast<T>(handle);
639 #else
640 return handle;
641 #endif
642 }
643
644 template <typename T>
645 uint64_t from_nondispatch_handle(T handle) {
646 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
647 defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
648 return reinterpret_cast<uint64_t>(handle);
649 #else
650 return handle;
651 #endif
652 }
653
654 //// WSI ////
655 template <typename HandleType>
656 void common_nondispatch_handle_creation(std::vector<uint64_t>& handles, HandleType* pHandle) {
657 if (nullptr != pHandle) {
658 if (handles.size() == 0)
659 handles.push_back(800851234);
660 else
661 handles.push_back(handles.back() + 102030);
662 *pHandle = to_nondispatch_handle<HandleType>(handles.back());
663 }
664 }
665 #if defined(VK_USE_PLATFORM_ANDROID_KHR)
666
667 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
668 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
669 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
670 return VK_SUCCESS;
671 }
672 #endif
673
674 #if defined(VK_USE_PLATFORM_WIN32_KHR)
675 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateWin32SurfaceKHR([[maybe_unused]] VkInstance instance,
676 [[maybe_unused]] const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
677 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
678 check_allocator_handle(pAllocator);
679 if (IsInstanceExtensionSupported(VK_KHR_WIN32_SURFACE_EXTENSION_NAME)) {
680 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
681 }
682 return VK_SUCCESS;
683 }
684
685 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice, uint32_t) { return VK_TRUE; }
686 #endif // VK_USE_PLATFORM_WIN32_KHR
687
688 #if defined(VK_USE_PLATFORM_WAYLAND_KHR)
689 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateWaylandSurfaceKHR([[maybe_unused]] VkInstance instance,
690 [[maybe_unused]] const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
691 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
692 check_allocator_handle(pAllocator);
693 if (IsInstanceExtensionSupported(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME)) {
694 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
695 }
696 return VK_SUCCESS;
697 }
698
699 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice, uint32_t,
700 struct wl_display*) {
701 return VK_TRUE;
702 }
703 #endif // VK_USE_PLATFORM_WAYLAND_KHR
704 #if defined(VK_USE_PLATFORM_XCB_KHR)
705 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateXcbSurfaceKHR([[maybe_unused]] VkInstance instance,
706 [[maybe_unused]] const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
707 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
708 check_allocator_handle(pAllocator);
709 if (IsInstanceExtensionSupported(VK_KHR_XCB_SURFACE_EXTENSION_NAME)) {
710 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
711 }
712 return VK_SUCCESS;
713 }
714
715 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice, uint32_t, xcb_connection_t*,
716 xcb_visualid_t) {
717 return VK_TRUE;
718 }
719 #endif // VK_USE_PLATFORM_XCB_KHR
720
721 #if defined(VK_USE_PLATFORM_XLIB_KHR)
722 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateXlibSurfaceKHR([[maybe_unused]] VkInstance instance,
723 [[maybe_unused]] const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
724 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
725 check_allocator_handle(pAllocator);
726 if (IsInstanceExtensionSupported(VK_KHR_XCB_SURFACE_EXTENSION_NAME)) {
727 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
728 }
729 return VK_SUCCESS;
730 }
731
732 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice, uint32_t, Display*, VisualID) {
733 return VK_TRUE;
734 }
735 #endif // VK_USE_PLATFORM_XLIB_KHR
736
737 #if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
738 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDirectFBSurfaceEXT([[maybe_unused]] VkInstance instance,
739 [[maybe_unused]] const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo,
740 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
741 check_allocator_handle(pAllocator);
742 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
743 return VK_SUCCESS;
744 }
745
746 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice, uint32_t, IDirectFB*) {
747 return VK_TRUE;
748 }
749
750 #endif // VK_USE_PLATFORM_DIRECTFB_EXT
751
752 #if defined(VK_USE_PLATFORM_MACOS_MVK)
753 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateMacOSSurfaceMVK([[maybe_unused]] VkInstance instance,
754 [[maybe_unused]] const VkMacOSSurfaceCreateInfoMVK* pCreateInfo,
755 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
756 check_allocator_handle(pAllocator);
757 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
758 return VK_SUCCESS;
759 }
760 #endif // VK_USE_PLATFORM_MACOS_MVK
761
762 #if defined(VK_USE_PLATFORM_IOS_MVK)
763 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateIOSSurfaceMVK([[maybe_unused]] VkInstance instance,
764 [[maybe_unused]] const VkIOSSurfaceCreateInfoMVK* pCreateInfo,
765 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
766 check_allocator_handle(pAllocator);
767 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
768 return VK_SUCCESS;
769 }
770 #endif // VK_USE_PLATFORM_IOS_MVK
771
772 #if defined(VK_USE_PLATFORM_GGP)
773 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateStreamDescriptorSurfaceGGP(
774 [[maybe_unused]] VkInstance instance, [[maybe_unused]] const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo,
775 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
776 check_allocator_handle(pAllocator);
777 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
778 return VK_SUCCESS;
779 }
780 #endif // VK_USE_PLATFORM_GGP
781
782 #if defined(VK_USE_PLATFORM_METAL_EXT)
783 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateMetalSurfaceEXT([[maybe_unused]] VkInstance instance,
784 [[maybe_unused]] const VkMetalSurfaceCreateInfoEXT* pCreateInfo,
785 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
786 check_allocator_handle(pAllocator);
787 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
788 return VK_SUCCESS;
789 }
790 #endif // VK_USE_PLATFORM_METAL_EXT
791
792 #if defined(VK_USE_PLATFORM_SCREEN_QNX)
793 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateScreenSurfaceQNX([[maybe_unused]] VkInstance instance,
794 [[maybe_unused]] const VkScreenSurfaceCreateInfoQNX* pCreateInfo,
795 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
796 check_allocator_handle(pAllocator);
797 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
798 return VK_SUCCESS;
799 }
800
801 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceScreenPresentationSupportQNX(VkPhysicalDevice, uint32_t,
802 struct _screen_window*) {
803 return VK_TRUE;
804 }
805 #endif // VK_USE_PLATFORM_SCREEN_QNX
806
807 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateHeadlessSurfaceEXT([[maybe_unused]] VkInstance instance,
808 [[maybe_unused]] const VkHeadlessSurfaceCreateInfoEXT* pCreateInfo,
809 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
810 check_allocator_handle(pAllocator);
811 if (IsInstanceExtensionSupported(VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME)) {
812 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
813 }
814 return VK_SUCCESS;
815 }
816
817 VKAPI_ATTR void VKAPI_CALL test_vkDestroySurfaceKHR([[maybe_unused]] VkInstance instance, VkSurfaceKHR surface,
818 const VkAllocationCallbacks* pAllocator) {
819 if (surface != VK_NULL_HANDLE) {
820 uint64_t surf_handle = from_nondispatch_handle(surface);
821 auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), surf_handle);
822 if (found_iter != icd.surface_handles.end()) {
823 // Remove it from the list
824 icd.surface_handles.erase(found_iter);
825 } else {
826 assert(false && "Surface not found during destroy!");
827 }
828 }
829 }
830 // VK_KHR_swapchain
831 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateSwapchainKHR([[maybe_unused]] VkDevice device,
832 [[maybe_unused]] const VkSwapchainCreateInfoKHR* pCreateInfo,
833 const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) {
834 check_allocator_handle(pAllocator);
835 common_nondispatch_handle_creation(icd.swapchain_handles, pSwapchain);
836 return VK_SUCCESS;
837 }
838
839 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetSwapchainImagesKHR([[maybe_unused]] VkDevice device,
840 [[maybe_unused]] VkSwapchainKHR swapchain,
841 uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages) {
842 std::vector<uint64_t> handles{123, 234, 345, 345, 456};
843 if (pSwapchainImages == nullptr) {
844 if (pSwapchainImageCount) *pSwapchainImageCount = static_cast<uint32_t>(handles.size());
845 } else if (pSwapchainImageCount) {
846 for (uint32_t i = 0; i < *pSwapchainImageCount && i < handles.size(); i++) {
847 pSwapchainImages[i] = to_nondispatch_handle<VkImage>(handles.back());
848 }
849 if (*pSwapchainImageCount < handles.size()) return VK_INCOMPLETE;
850 }
851 return VK_SUCCESS;
852 }
853
854 VKAPI_ATTR void VKAPI_CALL test_vkDestroySwapchainKHR([[maybe_unused]] VkDevice device, VkSwapchainKHR swapchain,
855 const VkAllocationCallbacks* pAllocator) {
856 check_allocator_handle(pAllocator);
857 if (swapchain != VK_NULL_HANDLE) {
858 uint64_t fake_swapchain_handle = from_nondispatch_handle(swapchain);
859 auto found_iter = icd.swapchain_handles.erase(
860 std::remove(icd.swapchain_handles.begin(), icd.swapchain_handles.end(), fake_swapchain_handle),
861 icd.swapchain_handles.end());
862 if (!icd.swapchain_handles.empty() && found_iter == icd.swapchain_handles.end()) {
863 assert(false && "Swapchain not found during destroy!");
864 }
865 }
866 }
867 // VK_KHR_swapchain with 1.1
868 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDeviceGroupSurfacePresentModesKHR([[maybe_unused]] VkDevice device,
869 [[maybe_unused]] VkSurfaceKHR surface,
870 VkDeviceGroupPresentModeFlagsKHR* pModes) {
871 if (!pModes) return VK_ERROR_INITIALIZATION_FAILED;
872 *pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHR;
873 return VK_SUCCESS;
874 }
875
876 // VK_KHR_surface
877 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
878 VkSurfaceKHR surface, VkBool32* pSupported) {
879 if (surface != VK_NULL_HANDLE) {
880 if (!is_valid_surface(surface)) {
881 *pSupported = VK_FALSE;
882 return VK_SUCCESS;
883 }
884 }
885 if (nullptr != pSupported) {
886 if (icd.physical_devices.count(physicalDevice) > 0) {
887 *pSupported = icd.physical_devices.at(physicalDevice).queue_family_properties.at(queueFamilyIndex).support_present;
888 } else {
889 *pSupported = VK_FALSE;
890 return VK_SUCCESS;
891 }
892 }
893 return VK_SUCCESS;
894 }
895 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
896 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) {
897 if (surface != VK_NULL_HANDLE) {
898 if (!is_valid_surface(surface)) {
899 assert(false && "Surface not found during GetPhysicalDeviceSurfaceCapabilitiesKHR query!");
900 return VK_ERROR_UNKNOWN;
901 }
902 }
903 if (nullptr != pSurfaceCapabilities) {
904 *pSurfaceCapabilities = GetPhysDevice(physicalDevice).surface_capabilities;
905 }
906 return VK_SUCCESS;
907 }
908 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
909 uint32_t* pSurfaceFormatCount,
910 VkSurfaceFormatKHR* pSurfaceFormats) {
911 if (surface != VK_NULL_HANDLE) {
912 if (!is_valid_surface(surface)) {
913 assert(false && "Surface not found during GetPhysicalDeviceSurfaceFormatsKHR query!");
914 return VK_ERROR_UNKNOWN;
915 }
916 } else {
917 if (!IsInstanceExtensionEnabled(VK_GOOGLE_SURFACELESS_QUERY_EXTENSION_NAME)) {
918 assert(false && "Surface is NULL but VK_GOOGLE_surfaceless_query was not enabled!");
919 return VK_ERROR_UNKNOWN;
920 }
921 }
922 FillCountPtr(GetPhysDevice(physicalDevice).surface_formats, pSurfaceFormatCount, pSurfaceFormats);
923 return VK_SUCCESS;
924 }
925 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
926 uint32_t* pPresentModeCount,
927 VkPresentModeKHR* pPresentModes) {
928 if (surface != VK_NULL_HANDLE) {
929 if (!is_valid_surface(surface)) {
930 assert(false && "Surface not found during GetPhysicalDeviceSurfacePresentModesKHR query!");
931 return VK_ERROR_UNKNOWN;
932 }
933 } else {
934 if (!IsInstanceExtensionEnabled(VK_GOOGLE_SURFACELESS_QUERY_EXTENSION_NAME)) {
935 assert(false && "Surface is NULL but VK_GOOGLE_surfaceless_query was not enabled!");
936 return VK_ERROR_UNKNOWN;
937 }
938 }
939 FillCountPtr(GetPhysDevice(physicalDevice).surface_present_modes, pPresentModeCount, pPresentModes);
940 return VK_SUCCESS;
941 }
942
943 #if defined(WIN32)
944 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfacePresentModes2EXT(VkPhysicalDevice physicalDevice,
945 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
946 uint32_t* pPresentModeCount,
947 VkPresentModeKHR* pPresentModes) {
948 if (pSurfaceInfo->surface != VK_NULL_HANDLE) {
949 if (!is_valid_surface(pSurfaceInfo->surface)) {
950 assert(false && "Surface not found during GetPhysicalDeviceSurfacePresentModesKHR query!");
951 return VK_ERROR_UNKNOWN;
952 }
953 } else {
954 if (!IsInstanceExtensionEnabled(VK_GOOGLE_SURFACELESS_QUERY_EXTENSION_NAME)) {
955 assert(false && "Surface is NULL but VK_GOOGLE_surfaceless_query was not enabled!");
956 return VK_ERROR_UNKNOWN;
957 }
958 }
959 FillCountPtr(GetPhysDevice(physicalDevice).surface_present_modes, pPresentModeCount, pPresentModes);
960 return VK_SUCCESS;
961 }
962 #endif
963
964 // VK_KHR_display
965 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
966 uint32_t* pPropertyCount,
967 VkDisplayPropertiesKHR* pProperties) {
968 FillCountPtr(GetPhysDevice(physicalDevice).display_properties, pPropertyCount, pProperties);
969 return VK_SUCCESS;
970 }
971 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
972 uint32_t* pPropertyCount,
973 VkDisplayPlanePropertiesKHR* pProperties) {
974 FillCountPtr(GetPhysDevice(physicalDevice).display_plane_properties, pPropertyCount, pProperties);
975 return VK_SUCCESS;
976 }
977 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,
978 [[maybe_unused]] uint32_t planeIndex,
979 uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) {
980 FillCountPtr(GetPhysDevice(physicalDevice).displays, pDisplayCount, pDisplays);
981 return VK_SUCCESS;
982 }
983 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice,
984 [[maybe_unused]] VkDisplayKHR display, uint32_t* pPropertyCount,
985 VkDisplayModePropertiesKHR* pProperties) {
986 FillCountPtr(GetPhysDevice(physicalDevice).display_mode_properties, pPropertyCount, pProperties);
987 return VK_SUCCESS;
988 }
989 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, [[maybe_unused]] VkDisplayKHR display,
990 [[maybe_unused]] const VkDisplayModeCreateInfoKHR* pCreateInfo,
991 const VkAllocationCallbacks* pAllocator, VkDisplayModeKHR* pMode) {
992 check_allocator_handle(pAllocator);
993 if (nullptr != pMode) {
994 *pMode = GetPhysDevice(physicalDevice).display_mode;
995 }
996 return VK_SUCCESS;
997 }
998 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice,
999 [[maybe_unused]] VkDisplayModeKHR mode,
1000 [[maybe_unused]] uint32_t planeIndex,
1001 VkDisplayPlaneCapabilitiesKHR* pCapabilities) {
1002 if (nullptr != pCapabilities) {
1003 *pCapabilities = GetPhysDevice(physicalDevice).display_plane_capabilities;
1004 }
1005 return VK_SUCCESS;
1006 }
1007 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDisplayPlaneSurfaceKHR(
1008 [[maybe_unused]] VkInstance instance, [[maybe_unused]] const VkDisplaySurfaceCreateInfoKHR* pCreateInfo,
1009 const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
1010 check_allocator_handle(pAllocator);
1011 if (IsInstanceExtensionSupported(VK_KHR_DISPLAY_EXTENSION_NAME)) {
1012 common_nondispatch_handle_creation(icd.surface_handles, pSurface);
1013 }
1014 return VK_SUCCESS;
1015 }
1016
1017 // VK_KHR_get_surface_capabilities2
1018 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice,
1019 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
1020 VkSurfaceCapabilities2KHR* pSurfaceCapabilities) {
1021 if (nullptr != pSurfaceInfo && nullptr != pSurfaceCapabilities) {
1022 if (IsInstanceExtensionSupported("VK_EXT_surface_maintenance1") &&
1023 IsInstanceExtensionEnabled("VK_EXT_surface_maintenance1")) {
1024 auto& phys_dev = GetPhysDevice(physicalDevice);
1025 void* pNext = pSurfaceCapabilities->pNext;
1026 while (pNext) {
1027 VkBaseOutStructure pNext_base_structure{};
1028 std::memcpy(&pNext_base_structure, pNext, sizeof(VkBaseInStructure));
1029 if (pNext_base_structure.sType == VK_STRUCTURE_TYPE_SURFACE_PRESENT_MODE_COMPATIBILITY_EXT) {
1030 // First must find the present mode that is being queried
1031 VkPresentModeKHR present_mode = VK_PRESENT_MODE_MAX_ENUM_KHR;
1032 const void* pSurfaceInfo_pNext = pSurfaceInfo->pNext;
1033 while (pSurfaceInfo_pNext) {
1034 VkBaseInStructure pSurfaceInfo_pNext_base_structure{};
1035 std::memcpy(&pSurfaceInfo_pNext_base_structure, pSurfaceInfo_pNext, sizeof(VkBaseInStructure));
1036 if (pSurfaceInfo_pNext_base_structure.sType == VK_STRUCTURE_TYPE_SURFACE_PRESENT_MODE_EXT) {
1037 present_mode = reinterpret_cast<const VkSurfacePresentModeEXT*>(pSurfaceInfo_pNext)->presentMode;
1038 }
1039 pSurfaceInfo_pNext = pSurfaceInfo_pNext_base_structure.pNext;
1040 }
1041
1042 VkSurfacePresentModeCompatibilityEXT* present_mode_compatibility =
1043 reinterpret_cast<VkSurfacePresentModeCompatibilityEXT*>(pNext);
1044 if (present_mode == VK_PRESENT_MODE_MAX_ENUM_KHR) {
1045 present_mode_compatibility->presentModeCount = 0;
1046 } else {
1047 auto it =
1048 std::find(phys_dev.surface_present_modes.begin(), phys_dev.surface_present_modes.end(), present_mode);
1049 if (it != phys_dev.surface_present_modes.end()) {
1050 size_t index = it - phys_dev.surface_present_modes.begin();
1051 present_mode_compatibility->presentModeCount =
1052 static_cast<uint32_t>(phys_dev.surface_present_mode_compatibility[index].size());
1053 if (present_mode_compatibility->pPresentModes) {
1054 for (size_t i = 0; i < phys_dev.surface_present_mode_compatibility[index].size(); i++) {
1055 present_mode_compatibility->pPresentModes[i] =
1056 phys_dev.surface_present_mode_compatibility[index][i];
1057 }
1058 }
1059 }
1060 }
1061 } else if (pNext_base_structure.sType == VK_STRUCTURE_TYPE_SURFACE_PRESENT_SCALING_CAPABILITIES_EXT) {
1062 VkSurfacePresentScalingCapabilitiesEXT* present_scaling_capabilities =
1063 reinterpret_cast<VkSurfacePresentScalingCapabilitiesEXT*>(pNext);
1064 present_scaling_capabilities->minScaledImageExtent =
1065 phys_dev.surface_present_scaling_capabilities.minScaledImageExtent;
1066 present_scaling_capabilities->maxScaledImageExtent =
1067 phys_dev.surface_present_scaling_capabilities.maxScaledImageExtent;
1068 present_scaling_capabilities->supportedPresentScaling =
1069 phys_dev.surface_present_scaling_capabilities.supportedPresentScaling;
1070 present_scaling_capabilities->supportedPresentGravityX =
1071 phys_dev.surface_present_scaling_capabilities.supportedPresentGravityX;
1072 present_scaling_capabilities->supportedPresentGravityY =
1073 phys_dev.surface_present_scaling_capabilities.supportedPresentGravityY;
1074 }
1075 pNext = pNext_base_structure.pNext;
1076 }
1077 }
1078 return test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, pSurfaceInfo->surface,
1079 &pSurfaceCapabilities->surfaceCapabilities);
1080 }
1081 return VK_SUCCESS;
1082 }
1083 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
1084 const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
1085 uint32_t* pSurfaceFormatCount,
1086 VkSurfaceFormat2KHR* pSurfaceFormats) {
1087 if (nullptr != pSurfaceFormatCount) {
1088 test_vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, pSurfaceInfo->surface, pSurfaceFormatCount, nullptr);
1089 if (nullptr != pSurfaceFormats) {
1090 auto& phys_dev = GetPhysDevice(physicalDevice);
1091 // Since the structures are different, we have to copy each item over seperately. Since we have multiple, we
1092 // have to manually copy the data here instead of calling the next function
1093 for (uint32_t cnt = 0; cnt < *pSurfaceFormatCount; ++cnt) {
1094 memcpy(&pSurfaceFormats[cnt].surfaceFormat, &phys_dev.surface_formats[cnt], sizeof(VkSurfaceFormatKHR));
1095 }
1096 }
1097 }
1098 return VK_SUCCESS;
1099 }
1100 // VK_KHR_display_swapchain
1101 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateSharedSwapchainsKHR([[maybe_unused]] VkDevice device, uint32_t swapchainCount,
1102 const VkSwapchainCreateInfoKHR* pCreateInfos,
1103 const VkAllocationCallbacks* pAllocator,
1104 VkSwapchainKHR* pSwapchains) {
1105 check_allocator_handle(pAllocator);
1106 for (uint32_t i = 0; i < swapchainCount; i++) {
1107 uint64_t surface_integer_value = from_nondispatch_handle(pCreateInfos[i].surface);
1108 auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), surface_integer_value);
1109 if (found_iter == icd.surface_handles.end()) {
1110 return VK_ERROR_INITIALIZATION_FAILED;
1111 }
1112 common_nondispatch_handle_creation(icd.swapchain_handles, &pSwapchains[i]);
1113 }
1114 return VK_SUCCESS;
1115 }
1116
1117 //// misc
1118 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateCommandPool([[maybe_unused]] VkDevice device,
1119 [[maybe_unused]] const VkCommandPoolCreateInfo* pCreateInfo,
1120 const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool) {
1121 check_allocator_handle(pAllocator);
1122 if (pCommandPool != nullptr) {
1123 pCommandPool = reinterpret_cast<VkCommandPool*>(0xdeadbeefdeadbeef);
1124 }
1125 return VK_SUCCESS;
1126 }
1127
1128 VKAPI_ATTR void VKAPI_CALL test_vkDestroyCommandPool(VkDevice, VkCommandPool, const VkAllocationCallbacks*) {
1129 // do nothing, leak memory for now
1130 }
1131 VKAPI_ATTR VkResult VKAPI_CALL test_vkAllocateCommandBuffers([[maybe_unused]] VkDevice device,
1132 const VkCommandBufferAllocateInfo* pAllocateInfo,
1133 VkCommandBuffer* pCommandBuffers) {
1134 if (pAllocateInfo != nullptr && pCommandBuffers != nullptr) {
1135 for (size_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
1136 icd.allocated_command_buffers.push_back({});
1137 pCommandBuffers[i] = icd.allocated_command_buffers.back().handle;
1138 }
1139 }
1140 return VK_SUCCESS;
1141 }
1142
1143 VKAPI_ATTR void VKAPI_CALL test_vkGetDeviceQueue([[maybe_unused]] VkDevice device, [[maybe_unused]] uint32_t queueFamilyIndex,
1144 uint32_t queueIndex, VkQueue* pQueue) {
1145 auto fd = lookup_device(device);
1146 if (fd.found) {
1147 *pQueue = icd.physical_devices.at(fd.phys_dev).queue_handles[queueIndex].handle;
1148 }
1149 }
1150
1151 // VK_EXT_acquire_drm_display
1152 VKAPI_ATTR VkResult VKAPI_CALL test_vkAcquireDrmDisplayEXT(VkPhysicalDevice, int32_t, VkDisplayKHR) { return VK_SUCCESS; }
1153
1154 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDrmDisplayEXT(VkPhysicalDevice physicalDevice, [[maybe_unused]] int32_t drmFd,
1155 [[maybe_unused]] uint32_t connectorId, VkDisplayKHR* display) {
1156 if (nullptr != display && GetPhysDevice(physicalDevice).displays.size() > 0) {
1157 *display = GetPhysDevice(physicalDevice).displays[0];
1158 }
1159 return VK_SUCCESS;
1160 }
1161
1162 //// stubs
1163 // 1.0
1164 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) {
1165 if (nullptr != pFeatures) {
1166 memcpy(pFeatures, &GetPhysDevice(physicalDevice).features, sizeof(VkPhysicalDeviceFeatures));
1167 }
1168 }
1169 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
1170 VkPhysicalDeviceProperties* pProperties) {
1171 if (nullptr != pProperties) {
1172 auto& phys_dev = GetPhysDevice(physicalDevice);
1173 memcpy(pProperties, &phys_dev.properties, sizeof(VkPhysicalDeviceProperties));
1174 size_t max_len = (phys_dev.deviceName.length() > VK_MAX_PHYSICAL_DEVICE_NAME_SIZE) ? VK_MAX_PHYSICAL_DEVICE_NAME_SIZE
1175 : phys_dev.deviceName.length();
1176 std::copy(phys_dev.deviceName.c_str(), phys_dev.deviceName.c_str() + max_len, pProperties->deviceName);
1177 pProperties->deviceName[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE - 1] = '\0';
1178 }
1179 }
1180 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,
1181 VkPhysicalDeviceMemoryProperties* pMemoryProperties) {
1182 if (nullptr != pMemoryProperties) {
1183 memcpy(pMemoryProperties, &GetPhysDevice(physicalDevice).memory_properties, sizeof(VkPhysicalDeviceMemoryProperties));
1184 }
1185 }
1186 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceSparseImageFormatProperties(
1187 VkPhysicalDevice physicalDevice, [[maybe_unused]] VkFormat format, [[maybe_unused]] VkImageType type,
1188 [[maybe_unused]] VkSampleCountFlagBits samples, [[maybe_unused]] VkImageUsageFlags usage, [[maybe_unused]] VkImageTiling tiling,
1189 uint32_t* pPropertyCount, VkSparseImageFormatProperties* pProperties) {
1190 FillCountPtr(GetPhysDevice(physicalDevice).sparse_image_format_properties, pPropertyCount, pProperties);
1191 }
1192 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
1193 VkFormatProperties* pFormatProperties) {
1194 if (nullptr != pFormatProperties) {
1195 memcpy(pFormatProperties, &GetPhysDevice(physicalDevice).format_properties[static_cast<uint32_t>(format)],
1196 sizeof(VkFormatProperties));
1197 }
1198 }
1199 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceImageFormatProperties(
1200 VkPhysicalDevice physicalDevice, [[maybe_unused]] VkFormat format, [[maybe_unused]] VkImageType type,
1201 [[maybe_unused]] VkImageTiling tiling, [[maybe_unused]] VkImageUsageFlags usage, [[maybe_unused]] VkImageCreateFlags flags,
1202 VkImageFormatProperties* pImageFormatProperties) {
1203 if (nullptr != pImageFormatProperties) {
1204 memcpy(pImageFormatProperties, &GetPhysDevice(physicalDevice).image_format_properties, sizeof(VkImageFormatProperties));
1205 }
1206 return VK_SUCCESS;
1207 }
1208
1209 // 1.1
1210 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
1211 VkPhysicalDeviceFeatures2* pFeatures) {
1212 if (nullptr != pFeatures) {
1213 test_vkGetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
1214 }
1215 }
1216 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
1217 VkPhysicalDeviceProperties2* pProperties) {
1218 if (nullptr != pProperties) {
1219 auto& phys_dev = GetPhysDevice(physicalDevice);
1220 test_vkGetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
1221 VkBaseInStructure* pNext = reinterpret_cast<VkBaseInStructure*>(pProperties->pNext);
1222 while (pNext) {
1223 if (pNext->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT) {
1224 auto* bus_info = reinterpret_cast<VkPhysicalDevicePCIBusInfoPropertiesEXT*>(pNext);
1225 bus_info->pciBus = phys_dev.pci_bus;
1226 }
1227 if (pNext->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LAYERED_DRIVER_PROPERTIES_MSFT) {
1228 auto* layered_driver_props = reinterpret_cast<VkPhysicalDeviceLayeredDriverPropertiesMSFT*>(pNext);
1229 layered_driver_props->underlyingAPI = phys_dev.layered_driver_underlying_api;
1230 }
1231 if (pNext->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES) {
1232 auto* vulkan_11_props = reinterpret_cast<VkPhysicalDeviceVulkan11Properties*>(pNext);
1233 memcpy(vulkan_11_props->deviceUUID, phys_dev.deviceUUID.data(), VK_UUID_SIZE);
1234 memcpy(vulkan_11_props->driverUUID, phys_dev.driverUUID.data(), VK_UUID_SIZE);
1235 }
1236 if (pNext->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES) {
1237 auto* device_id_props = reinterpret_cast<VkPhysicalDeviceIDProperties*>(pNext);
1238 memcpy(device_id_props->deviceUUID, phys_dev.deviceUUID.data(), VK_UUID_SIZE);
1239 memcpy(device_id_props->driverUUID, phys_dev.driverUUID.data(), VK_UUID_SIZE);
1240 }
1241 if (pNext->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES) {
1242 auto* device_driver_props = reinterpret_cast<VkPhysicalDeviceDriverProperties*>(pNext);
1243 *device_driver_props = phys_dev.driver_properties;
1244 }
1245 pNext = reinterpret_cast<VkBaseInStructure*>(const_cast<VkBaseInStructure*>(pNext->pNext));
1246 }
1247 }
1248 }
1249 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice,
1250 VkPhysicalDeviceMemoryProperties2* pMemoryProperties) {
1251 if (nullptr != pMemoryProperties) {
1252 test_vkGetPhysicalDeviceMemoryProperties(physicalDevice, &pMemoryProperties->memoryProperties);
1253 }
1254 }
1255 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,
1256 uint32_t* pQueueFamilyPropertyCount,
1257 VkQueueFamilyProperties2* pQueueFamilyProperties) {
1258 if (nullptr != pQueueFamilyPropertyCount) {
1259 test_vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, nullptr);
1260 if (nullptr != pQueueFamilyProperties) {
1261 auto& phys_dev = GetPhysDevice(physicalDevice);
1262 // Since the structures are different, we have to copy each item over seperately. Since we have multiple, we
1263 // have to manually copy the data here instead of calling the next function
1264 for (uint32_t queue = 0; queue < *pQueueFamilyPropertyCount; ++queue) {
1265 memcpy(&pQueueFamilyProperties[queue].queueFamilyProperties, &phys_dev.queue_family_properties[queue].properties,
1266 sizeof(VkQueueFamilyProperties));
1267 }
1268 }
1269 }
1270 }
1271 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceSparseImageFormatProperties2(
1272 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, uint32_t* pPropertyCount,
1273 VkSparseImageFormatProperties2* pProperties) {
1274 if (nullptr != pPropertyCount) {
1275 test_vkGetPhysicalDeviceSparseImageFormatProperties(physicalDevice, pFormatInfo->format, pFormatInfo->type,
1276 pFormatInfo->samples, pFormatInfo->usage, pFormatInfo->tiling,
1277 pPropertyCount, nullptr);
1278 if (nullptr != pProperties) {
1279 auto& phys_dev = GetPhysDevice(physicalDevice);
1280 // Since the structures are different, we have to copy each item over seperately. Since we have multiple, we
1281 // have to manually copy the data here instead of calling the next function
1282 for (uint32_t cnt = 0; cnt < *pPropertyCount; ++cnt) {
1283 memcpy(&pProperties[cnt].properties, &phys_dev.sparse_image_format_properties[cnt],
1284 sizeof(VkSparseImageFormatProperties));
1285 }
1286 }
1287 }
1288 }
1289 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, VkFormat format,
1290 VkFormatProperties2* pFormatProperties) {
1291 if (nullptr != pFormatProperties) {
1292 test_vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &pFormatProperties->formatProperties);
1293 }
1294 }
1295 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceImageFormatProperties2(
1296 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo,
1297 VkImageFormatProperties2* pImageFormatProperties) {
1298 if (nullptr != pImageFormatInfo) {
1299 VkImageFormatProperties* ptr = nullptr;
1300 if (pImageFormatProperties) {
1301 ptr = &pImageFormatProperties->imageFormatProperties;
1302 }
1303 test_vkGetPhysicalDeviceImageFormatProperties(physicalDevice, pImageFormatInfo->format, pImageFormatInfo->type,
1304 pImageFormatInfo->tiling, pImageFormatInfo->usage, pImageFormatInfo->flags,
1305 ptr);
1306 }
1307 return VK_SUCCESS;
1308 }
1309 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceExternalBufferProperties(
1310 VkPhysicalDevice physicalDevice, [[maybe_unused]] const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo,
1311 VkExternalBufferProperties* pExternalBufferProperties) {
1312 if (nullptr != pExternalBufferProperties) {
1313 auto& phys_dev = GetPhysDevice(physicalDevice);
1314 memcpy(&pExternalBufferProperties->externalMemoryProperties, &phys_dev.external_memory_properties,
1315 sizeof(VkExternalMemoryProperties));
1316 }
1317 }
1318 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceExternalSemaphoreProperties(
1319 VkPhysicalDevice physicalDevice, [[maybe_unused]] const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo,
1320 VkExternalSemaphoreProperties* pExternalSemaphoreProperties) {
1321 if (nullptr != pExternalSemaphoreProperties) {
1322 auto& phys_dev = GetPhysDevice(physicalDevice);
1323 memcpy(pExternalSemaphoreProperties, &phys_dev.external_semaphore_properties, sizeof(VkExternalSemaphoreProperties));
1324 }
1325 }
1326 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceExternalFenceProperties(
1327 VkPhysicalDevice physicalDevice, [[maybe_unused]] const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo,
1328 VkExternalFenceProperties* pExternalFenceProperties) {
1329 if (nullptr != pExternalFenceProperties) {
1330 auto& phys_dev = GetPhysDevice(physicalDevice);
1331 memcpy(pExternalFenceProperties, &phys_dev.external_fence_properties, sizeof(VkExternalFenceProperties));
1332 }
1333 }
1334 // Entry-points associated with the VK_KHR_performance_query extension
1335 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
1336 VkPhysicalDevice, uint32_t, uint32_t*, VkPerformanceCounterKHR*, VkPerformanceCounterDescriptionKHR*) {
1337 return VK_SUCCESS;
1338 }
1339 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(VkPhysicalDevice,
1340 const VkQueryPoolPerformanceCreateInfoKHR*,
1341 uint32_t*) {}
1342 VKAPI_ATTR VkResult VKAPI_CALL test_vkAcquireProfilingLockKHR(VkDevice, const VkAcquireProfilingLockInfoKHR*) { return VK_SUCCESS; }
1343 VKAPI_ATTR void VKAPI_CALL test_vkReleaseProfilingLockKHR(VkDevice) {}
1344 // Entry-points associated with the VK_EXT_sample_locations extension
1345 VKAPI_ATTR void VKAPI_CALL test_vkCmdSetSampleLocationsEXT(VkCommandBuffer, const VkSampleLocationsInfoEXT*) {}
1346 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceMultisamplePropertiesEXT(VkPhysicalDevice, VkSampleCountFlagBits,
1347 VkMultisamplePropertiesEXT*) {}
1348 // Entry-points associated with the VK_EXT_calibrated_timestamps extension
1349 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(VkPhysicalDevice, uint32_t*, VkTimeDomainEXT*) {
1350 return VK_SUCCESS;
1351 }
1352 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetCalibratedTimestampsEXT(VkDevice, uint32_t, const VkCalibratedTimestampInfoEXT*, uint64_t*,
1353 uint64_t*) {
1354 return VK_SUCCESS;
1355 }
1356
1357 #if defined(WIN32)
1358 VKAPI_ATTR VkResult VKAPI_CALL test_vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance, LUID adapterLUID,
1359 uint32_t* pPhysicalDeviceCount,
1360 VkPhysicalDevice* pPhysicalDevices) {
1361 if (icd.enum_adapter_physical_devices_return_code != VK_SUCCESS) {
1362 return icd.enum_adapter_physical_devices_return_code;
1363 }
1364 if (adapterLUID.LowPart != icd.adapterLUID.LowPart || adapterLUID.HighPart != icd.adapterLUID.HighPart) {
1365 *pPhysicalDeviceCount = 0;
1366 return VK_ERROR_INCOMPATIBLE_DRIVER;
1367 }
1368 icd.called_enumerate_adapter_physical_devices = true;
1369 VkResult res = test_vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
1370 // For this testing, flip order intentionally
1371 if (nullptr != pPhysicalDevices) {
1372 std::reverse(pPhysicalDevices, pPhysicalDevices + *pPhysicalDeviceCount);
1373 }
1374 return res;
1375 }
1376 #endif // defined(WIN32)
1377
1378 VKAPI_ATTR VkResult VKAPI_CALL test_vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) {
1379 if (icd.called_vk_icd_gipa == CalledICDGIPA::not_called &&
1380 icd.called_negotiate_interface == CalledNegotiateInterface::not_called)
1381 icd.called_negotiate_interface = CalledNegotiateInterface::vk_icd_negotiate;
1382 else if (icd.called_vk_icd_gipa != CalledICDGIPA::not_called)
1383 icd.called_negotiate_interface = CalledNegotiateInterface::vk_icd_gipa_first;
1384
1385 // loader puts the minimum it supports in pSupportedVersion, if that is lower than our minimum
1386 // If the ICD doesn't supports the interface version provided by the loader, report VK_ERROR_INCOMPATIBLE_DRIVER
1387 if (icd.min_icd_interface_version > *pSupportedVersion) {
1388 icd.interface_version_check = InterfaceVersionCheck::loader_version_too_old;
1389 *pSupportedVersion = icd.min_icd_interface_version;
1390 return VK_ERROR_INCOMPATIBLE_DRIVER;
1391 }
1392
1393 // the loader-provided interface version is newer than that supported by the ICD
1394 if (icd.max_icd_interface_version < *pSupportedVersion) {
1395 icd.interface_version_check = InterfaceVersionCheck::loader_version_too_new;
1396 *pSupportedVersion = icd.max_icd_interface_version;
1397 }
1398 // ICD interface version is greater than the loader's, return the loader's version
1399 else if (icd.max_icd_interface_version > *pSupportedVersion) {
1400 icd.interface_version_check = InterfaceVersionCheck::icd_version_too_new;
1401 // don't change *pSupportedVersion
1402 } else {
1403 icd.interface_version_check = InterfaceVersionCheck::version_is_supported;
1404 *pSupportedVersion = icd.max_icd_interface_version;
1405 }
1406
1407 return VK_SUCCESS;
1408 }
1409
1410 //// trampolines
1411
1412 PFN_vkVoidFunction get_instance_func_ver_1_1([[maybe_unused]] VkInstance instance, const char* pName) {
1413 if (icd.icd_api_version >= VK_API_VERSION_1_1) {
1414 if (string_eq(pName, "test_vkEnumerateInstanceVersion")) {
1415 return icd.can_query_vkEnumerateInstanceVersion ? to_vkVoidFunction(test_vkEnumerateInstanceVersion) : nullptr;
1416 }
1417 if (string_eq(pName, "vkEnumeratePhysicalDeviceGroups")) {
1418 return to_vkVoidFunction(test_vkEnumeratePhysicalDeviceGroups);
1419 }
1420 }
1421 return nullptr;
1422 }
1423
1424 PFN_vkVoidFunction get_physical_device_func_wsi([[maybe_unused]] VkInstance instance, const char* pName) {
1425 if (IsInstanceExtensionEnabled("VK_KHR_surface")) {
1426 if (string_eq(pName, "vkGetPhysicalDeviceSurfaceSupportKHR"))
1427 return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceSupportKHR);
1428 if (string_eq(pName, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"))
1429 return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
1430 if (string_eq(pName, "vkGetPhysicalDeviceSurfaceFormatsKHR"))
1431 return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceFormatsKHR);
1432 if (string_eq(pName, "vkGetPhysicalDeviceSurfacePresentModesKHR"))
1433 return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfacePresentModesKHR);
1434 }
1435 #if defined(WIN32)
1436 if (IsPhysicalDeviceExtensionAvailable("VK_EXT_full_screen_exclusive")) {
1437 if (string_eq(pName, "vkGetPhysicalDeviceSurfacePresentModes2EXT"))
1438 return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfacePresentModes2EXT);
1439 }
1440 #endif
1441 if (IsInstanceExtensionEnabled("VK_KHR_get_surface_capabilities2")) {
1442 if (string_eq(pName, "vkGetPhysicalDeviceSurfaceCapabilities2KHR"))
1443 return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceCapabilities2KHR);
1444 if (string_eq(pName, "vkGetPhysicalDeviceSurfaceFormats2KHR"))
1445 return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceFormats2KHR);
1446 }
1447 if (IsInstanceExtensionEnabled("VK_KHR_display")) {
1448 if (string_eq(pName, "vkGetPhysicalDeviceDisplayPropertiesKHR"))
1449 return to_vkVoidFunction(test_vkGetPhysicalDeviceDisplayPropertiesKHR);
1450 if (string_eq(pName, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR"))
1451 return to_vkVoidFunction(test_vkGetPhysicalDeviceDisplayPlanePropertiesKHR);
1452 if (string_eq(pName, "vkGetDisplayPlaneSupportedDisplaysKHR"))
1453 return to_vkVoidFunction(test_vkGetDisplayPlaneSupportedDisplaysKHR);
1454 if (string_eq(pName, "vkGetDisplayModePropertiesKHR")) return to_vkVoidFunction(test_vkGetDisplayModePropertiesKHR);
1455 if (string_eq(pName, "vkCreateDisplayModeKHR")) return to_vkVoidFunction(test_vkCreateDisplayModeKHR);
1456 if (string_eq(pName, "vkGetDisplayPlaneCapabilitiesKHR")) return to_vkVoidFunction(test_vkGetDisplayPlaneCapabilitiesKHR);
1457 if (string_eq(pName, "vkCreateDisplayPlaneSurfaceKHR")) return to_vkVoidFunction(test_vkCreateDisplayPlaneSurfaceKHR);
1458 }
1459 if (IsInstanceExtensionEnabled("VK_EXT_acquire_drm_display")) {
1460 if (string_eq(pName, "vkAcquireDrmDisplayEXT")) return to_vkVoidFunction(test_vkAcquireDrmDisplayEXT);
1461 if (string_eq(pName, "vkGetDrmDisplayEXT")) return to_vkVoidFunction(test_vkGetDrmDisplayEXT);
1462 }
1463 return nullptr;
1464 }
1465
1466 PFN_vkVoidFunction get_instance_func_wsi(VkInstance instance, const char* pName) {
1467 if (icd.min_icd_interface_version >= 3 && icd.enable_icd_wsi == true) {
1468 #if defined(VK_USE_PLATFORM_ANDROID_KHR)
1469 if (string_eq(pName, "vkCreateAndroidSurfaceKHR")) {
1470 icd.is_using_icd_wsi = true;
1471 return to_vkVoidFunction(test_vkCreateAndroidSurfaceKHR);
1472 }
1473 #endif
1474 #if defined(VK_USE_PLATFORM_METAL_EXT)
1475 if (string_eq(pName, "vkCreateMetalSurfaceEXT")) {
1476 return to_vkVoidFunction(test_vkCreateMetalSurfaceEXT);
1477 }
1478 #endif
1479 #if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1480 if (string_eq(pName, "vkCreateWaylandSurfaceKHR")) {
1481 return to_vkVoidFunction(test_vkCreateWaylandSurfaceKHR);
1482 }
1483 if (string_eq(pName, "vkGetPhysicalDeviceWaylandPresentationSupportKHR")) {
1484 return to_vkVoidFunction(test_vkGetPhysicalDeviceWaylandPresentationSupportKHR);
1485 }
1486 #endif
1487 #if defined(VK_USE_PLATFORM_XCB_KHR)
1488 if (string_eq(pName, "vkCreateXcbSurfaceKHR")) {
1489 return to_vkVoidFunction(test_vkCreateXcbSurfaceKHR);
1490 }
1491 if (string_eq(pName, "vkGetPhysicalDeviceXcbPresentationSupportKHR")) {
1492 return to_vkVoidFunction(test_vkGetPhysicalDeviceXcbPresentationSupportKHR);
1493 }
1494 #endif
1495 #if defined(VK_USE_PLATFORM_XLIB_KHR)
1496 if (string_eq(pName, "vkCreateXlibSurfaceKHR")) {
1497 return to_vkVoidFunction(test_vkCreateXlibSurfaceKHR);
1498 }
1499 if (string_eq(pName, "vkGetPhysicalDeviceXlibPresentationSupportKHR")) {
1500 return to_vkVoidFunction(test_vkGetPhysicalDeviceXlibPresentationSupportKHR);
1501 }
1502 #endif
1503 #if defined(VK_USE_PLATFORM_WIN32_KHR)
1504 if (string_eq(pName, "vkCreateWin32SurfaceKHR")) {
1505 return to_vkVoidFunction(test_vkCreateWin32SurfaceKHR);
1506 }
1507 if (string_eq(pName, "vkGetPhysicalDeviceWin32PresentationSupportKHR")) {
1508 return to_vkVoidFunction(test_vkGetPhysicalDeviceWin32PresentationSupportKHR);
1509 }
1510 #endif
1511 #if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
1512 if (string_eq(pName, "vkCreateDirectFBSurfaceEXT")) {
1513 return to_vkVoidFunction(test_vkCreateDirectFBSurfaceEXT);
1514 }
1515 if (string_eq(pName, "vkGetPhysicalDeviceDirectFBPresentationSupportEXT")) {
1516 return to_vkVoidFunction(test_vkGetPhysicalDeviceDirectFBPresentationSupportEXT);
1517 }
1518 #endif // VK_USE_PLATFORM_DIRECTFB_EXT
1519
1520 #if defined(VK_USE_PLATFORM_MACOS_MVK)
1521 if (string_eq(pName, "vkCreateMacOSSurfaceMVK")) {
1522 return to_vkVoidFunction(test_vkCreateMacOSSurfaceMVK);
1523 }
1524 #endif // VK_USE_PLATFORM_MACOS_MVK
1525
1526 #if defined(VK_USE_PLATFORM_IOS_MVK)
1527 if (string_eq(pName, "vkCreateIOSSurfaceMVK")) {
1528 return to_vkVoidFunction(test_vkCreateIOSSurfaceMVK);
1529 }
1530 #endif // VK_USE_PLATFORM_IOS_MVK
1531
1532 #if defined(VK_USE_PLATFORM_GGP)
1533 if (string_eq(pName, "vkCreateStreamDescriptorSurfaceGGP")) {
1534 return to_vkVoidFunction(test_vkCreateStreamDescriptorSurfaceGGP);
1535 }
1536 #endif // VK_USE_PLATFORM_GGP
1537
1538 #if defined(VK_USE_PLATFORM_SCREEN_QNX)
1539 if (string_eq(pName, "vkCreateScreenSurfaceQNX")) {
1540 return to_vkVoidFunction(test_vkCreateScreenSurfaceQNX);
1541 }
1542 if (string_eq(pName, "vkGetPhysicalDeviceScreenPresentationSupportQNX")) {
1543 return to_vkVoidFunction(test_vkGetPhysicalDeviceScreenPresentationSupportQNX);
1544 }
1545 #endif // VK_USE_PLATFORM_SCREEN_QNX
1546
1547 if (string_eq(pName, "vkCreateHeadlessSurfaceEXT")) {
1548 return to_vkVoidFunction(test_vkCreateHeadlessSurfaceEXT);
1549 }
1550
1551 if (string_eq(pName, "vkDestroySurfaceKHR")) {
1552 icd.is_using_icd_wsi = true;
1553 return to_vkVoidFunction(test_vkDestroySurfaceKHR);
1554 }
1555 }
1556 if (IsInstanceExtensionEnabled(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) {
1557 if (string_eq(pName, "vkCreateDebugUtilsMessengerEXT")) {
1558 return to_vkVoidFunction(test_vkCreateDebugUtilsMessengerEXT);
1559 }
1560 if (string_eq(pName, "vkDestroyDebugUtilsMessengerEXT")) {
1561 return to_vkVoidFunction(test_vkDestroyDebugUtilsMessengerEXT);
1562 }
1563 }
1564 if (IsInstanceExtensionEnabled(VK_EXT_DEBUG_MARKER_EXTENSION_NAME)) {
1565 if (string_eq(pName, "vkCreateDebugReportCallbackEXT")) {
1566 return to_vkVoidFunction(test_vkCreateDebugReportCallbackEXT);
1567 }
1568 if (string_eq(pName, "vkDestroyDebugReportCallbackEXT")) {
1569 return to_vkVoidFunction(test_vkDestroyDebugReportCallbackEXT);
1570 }
1571 }
1572
1573 PFN_vkVoidFunction ret_phys_dev_wsi = get_physical_device_func_wsi(instance, pName);
1574 if (ret_phys_dev_wsi != nullptr) return ret_phys_dev_wsi;
1575 return nullptr;
1576 }
1577 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_physical_device_func([[maybe_unused]] VkInstance instance, const char* pName) {
1578 if (string_eq(pName, "vkEnumerateDeviceLayerProperties")) return to_vkVoidFunction(test_vkEnumerateDeviceLayerProperties);
1579 if (string_eq(pName, "vkEnumerateDeviceExtensionProperties"))
1580 return to_vkVoidFunction(test_vkEnumerateDeviceExtensionProperties);
1581 if (string_eq(pName, "vkGetPhysicalDeviceQueueFamilyProperties"))
1582 return to_vkVoidFunction(test_vkGetPhysicalDeviceQueueFamilyProperties);
1583 if (string_eq(pName, "vkCreateDevice")) return to_vkVoidFunction(test_vkCreateDevice);
1584
1585 if (string_eq(pName, "vkGetPhysicalDeviceFeatures"))
1586 return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceFeatures) : nullptr;
1587 if (string_eq(pName, "vkGetPhysicalDeviceProperties"))
1588 return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceProperties) : nullptr;
1589 if (string_eq(pName, "vkGetPhysicalDeviceMemoryProperties"))
1590 return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceMemoryProperties) : nullptr;
1591 if (string_eq(pName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
1592 return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceSparseImageFormatProperties)
1593 : nullptr;
1594 if (string_eq(pName, "vkGetPhysicalDeviceFormatProperties"))
1595 return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceFormatProperties) : nullptr;
1596 if (string_eq(pName, "vkGetPhysicalDeviceImageFormatProperties"))
1597 return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceImageFormatProperties) : nullptr;
1598
1599 if (IsInstanceExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
1600 if (string_eq(pName, "vkGetPhysicalDeviceFeatures2KHR")) return to_vkVoidFunction(test_vkGetPhysicalDeviceFeatures2);
1601 if (string_eq(pName, "vkGetPhysicalDeviceProperties2KHR")) return to_vkVoidFunction(test_vkGetPhysicalDeviceProperties2);
1602 if (string_eq(pName, "vkGetPhysicalDeviceFormatProperties2KHR"))
1603 return to_vkVoidFunction(test_vkGetPhysicalDeviceFormatProperties2);
1604 if (string_eq(pName, "vkGetPhysicalDeviceMemoryProperties2KHR"))
1605 return to_vkVoidFunction(test_vkGetPhysicalDeviceMemoryProperties2);
1606
1607 if (string_eq(pName, "vkGetPhysicalDeviceQueueFamilyProperties2KHR"))
1608 return to_vkVoidFunction(test_vkGetPhysicalDeviceQueueFamilyProperties2);
1609
1610 if (string_eq(pName, "vkGetPhysicalDeviceSparseImageFormatProperties2KHR"))
1611 return to_vkVoidFunction(test_vkGetPhysicalDeviceSparseImageFormatProperties2);
1612
1613 if (string_eq(pName, "vkGetPhysicalDeviceImageFormatProperties2KHR")) {
1614 return to_vkVoidFunction(test_vkGetPhysicalDeviceImageFormatProperties2);
1615 }
1616 }
1617 if (IsInstanceExtensionEnabled(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME)) {
1618 if (string_eq(pName, "vkGetPhysicalDeviceExternalBufferPropertiesKHR"))
1619 return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalBufferProperties);
1620 }
1621 if (IsInstanceExtensionEnabled(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME)) {
1622 if (string_eq(pName, "vkGetPhysicalDeviceExternalSemaphorePropertiesKHR"))
1623 return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalSemaphoreProperties);
1624 }
1625 if (IsInstanceExtensionEnabled(VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME)) {
1626 if (string_eq(pName, "vkGetPhysicalDeviceExternalFencePropertiesKHR"))
1627 return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalFenceProperties);
1628 }
1629
1630 // The following physical device extensions only need 1 device to support them for the ICD to export
1631 // them
1632 if (IsPhysicalDeviceExtensionAvailable(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME)) {
1633 if (string_eq(pName, "vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR"))
1634 return to_vkVoidFunction(test_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR);
1635 if (string_eq(pName, "vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR"))
1636 return to_vkVoidFunction(test_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR);
1637 if (string_eq(pName, "vkAcquireProfilingLockKHR")) return to_vkVoidFunction(test_vkAcquireProfilingLockKHR);
1638 if (string_eq(pName, "vkReleaseProfilingLockKHR")) return to_vkVoidFunction(test_vkReleaseProfilingLockKHR);
1639 }
1640 if (IsPhysicalDeviceExtensionAvailable(VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME)) {
1641 if (string_eq(pName, "vkCmdSetSampleLocationsEXT")) return to_vkVoidFunction(test_vkCmdSetSampleLocationsEXT);
1642 if (string_eq(pName, "vkGetPhysicalDeviceMultisamplePropertiesEXT"))
1643 return to_vkVoidFunction(test_vkGetPhysicalDeviceMultisamplePropertiesEXT);
1644 }
1645 if (IsPhysicalDeviceExtensionAvailable(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME)) {
1646 if (string_eq(pName, "vkGetPhysicalDeviceCalibrateableTimeDomainsEXT"))
1647 return to_vkVoidFunction(test_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT);
1648 if (string_eq(pName, "vkGetCalibratedTimestampsEXT")) return to_vkVoidFunction(test_vkGetCalibratedTimestampsEXT);
1649 }
1650
1651 if (icd.icd_api_version >= VK_MAKE_API_VERSION(0, 1, 1, 0)) {
1652 if (string_eq(pName, "vkGetPhysicalDeviceFeatures2")) return to_vkVoidFunction(test_vkGetPhysicalDeviceFeatures2);
1653 if (string_eq(pName, "vkGetPhysicalDeviceProperties2")) return to_vkVoidFunction(test_vkGetPhysicalDeviceProperties2);
1654 if (string_eq(pName, "vkGetPhysicalDeviceFormatProperties2"))
1655 return to_vkVoidFunction(test_vkGetPhysicalDeviceFormatProperties2);
1656 if (string_eq(pName, "vkGetPhysicalDeviceMemoryProperties2"))
1657 return to_vkVoidFunction(test_vkGetPhysicalDeviceMemoryProperties2);
1658
1659 if (string_eq(pName, "vkGetPhysicalDeviceQueueFamilyProperties2"))
1660 return to_vkVoidFunction(test_vkGetPhysicalDeviceQueueFamilyProperties2);
1661
1662 if (string_eq(pName, "vkGetPhysicalDeviceSparseImageFormatProperties2"))
1663 return to_vkVoidFunction(test_vkGetPhysicalDeviceSparseImageFormatProperties2);
1664
1665 if (string_eq(pName, "vkGetPhysicalDeviceImageFormatProperties2")) {
1666 return to_vkVoidFunction(test_vkGetPhysicalDeviceImageFormatProperties2);
1667 }
1668
1669 if (string_eq(pName, "vkGetPhysicalDeviceExternalBufferProperties"))
1670 return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalBufferProperties);
1671 if (string_eq(pName, "vkGetPhysicalDeviceExternalSemaphoreProperties"))
1672 return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalSemaphoreProperties);
1673 if (string_eq(pName, "vkGetPhysicalDeviceExternalFenceProperties"))
1674 return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalFenceProperties);
1675 }
1676
1677 if (icd.supports_tooling_info_core) {
1678 if (string_eq(pName, "vkGetPhysicalDeviceToolProperties")) return to_vkVoidFunction(test_vkGetPhysicalDeviceToolProperties);
1679 }
1680 if (icd.supports_tooling_info_ext) {
1681 if (string_eq(pName, "vkGetPhysicalDeviceToolPropertiesEXT"))
1682 return to_vkVoidFunction(test_vkGetPhysicalDeviceToolPropertiesEXT);
1683 }
1684
1685 for (auto const& [phys_dev_handle, phys_dev] : icd.physical_devices) {
1686 for (auto& func : phys_dev.custom_physical_device_functions) {
1687 if (func.name == pName) {
1688 return to_vkVoidFunction(func.function);
1689 }
1690 }
1691 }
1692 return nullptr;
1693 }
1694
1695 PFN_vkVoidFunction get_instance_func(VkInstance instance, const char* pName) {
1696 if (string_eq(pName, "vkDestroyInstance")) return to_vkVoidFunction(test_vkDestroyInstance);
1697 if (string_eq(pName, "vkEnumeratePhysicalDevices")) return to_vkVoidFunction(test_vkEnumeratePhysicalDevices);
1698
1699 if (IsInstanceExtensionEnabled(VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME)) {
1700 if (string_eq(pName, "vkEnumeratePhysicalDeviceGroupsKHR")) return to_vkVoidFunction(test_vkEnumeratePhysicalDeviceGroups);
1701 }
1702
1703 PFN_vkVoidFunction ret_phys_dev = get_physical_device_func(instance, pName);
1704 if (ret_phys_dev != nullptr) return ret_phys_dev;
1705
1706 PFN_vkVoidFunction ret_1_1 = get_instance_func_ver_1_1(instance, pName);
1707 if (ret_1_1 != nullptr) return ret_1_1;
1708
1709 PFN_vkVoidFunction ret_wsi = get_instance_func_wsi(instance, pName);
1710 if (ret_wsi != nullptr) return ret_wsi;
1711
1712 for (auto& func : icd.custom_instance_functions) {
1713 if (func.name == pName) {
1714 return to_vkVoidFunction(func.function);
1715 }
1716 }
1717
1718 return nullptr;
1719 }
1720
1721 bool should_check(std::vector<const char*>* exts, VkDevice device, const char* ext_name) {
1722 if (exts == nullptr || device == VK_NULL_HANDLE) return true; // always look if device is NULL
1723 for (auto const& ext : *exts) {
1724 if (string_eq(ext, ext_name)) {
1725 return true;
1726 }
1727 }
1728 return false;
1729 }
1730
1731 PFN_vkVoidFunction get_device_func(VkDevice device, const char* pName) {
1732 std::vector<const char*>* enabled_extensions = nullptr;
1733 FindDevice found_device{};
1734 if (device != nullptr) {
1735 found_device = lookup_device(device);
1736 if (!found_device.found) return NULL;
1737 enabled_extensions =
1738 &icd.physical_devices.at(found_device.phys_dev).device_create_infos.at(found_device.dev_index).enabled_extensions;
1739 }
1740 if (string_eq(pName, "vkCreateCommandPool")) return to_vkVoidFunction(test_vkCreateCommandPool);
1741 if (string_eq(pName, "vkAllocateCommandBuffers")) return to_vkVoidFunction(test_vkAllocateCommandBuffers);
1742 if (string_eq(pName, "vkDestroyCommandPool")) return to_vkVoidFunction(test_vkDestroyCommandPool);
1743 if (string_eq(pName, "vkGetDeviceQueue")) return to_vkVoidFunction(test_vkGetDeviceQueue);
1744 if (string_eq(pName, "vkDestroyDevice")) return to_vkVoidFunction(test_vkDestroyDevice);
1745 if (should_check(enabled_extensions, device, "VK_KHR_swapchain")) {
1746 if (string_eq(pName, "vkCreateSwapchainKHR")) return to_vkVoidFunction(test_vkCreateSwapchainKHR);
1747 if (string_eq(pName, "vkGetSwapchainImagesKHR")) return to_vkVoidFunction(test_vkGetSwapchainImagesKHR);
1748 if (string_eq(pName, "vkDestroySwapchainKHR")) return to_vkVoidFunction(test_vkDestroySwapchainKHR);
1749
1750 if (icd.icd_api_version >= VK_API_VERSION_1_1 && string_eq(pName, "vkGetDeviceGroupSurfacePresentModesKHR"))
1751 return to_vkVoidFunction(test_vkGetDeviceGroupSurfacePresentModesKHR);
1752 }
1753 if (should_check(enabled_extensions, device, "VK_KHR_display_swapchain")) {
1754 if (string_eq(pName, "vkCreateSharedSwapchainsKHR")) return to_vkVoidFunction(test_vkCreateSharedSwapchainsKHR);
1755 }
1756 if (should_check(enabled_extensions, device, "VK_KHR_device_group")) {
1757 if (string_eq(pName, "vkGetDeviceGroupSurfacePresentModesKHR"))
1758 return to_vkVoidFunction(test_vkGetDeviceGroupSurfacePresentModesKHR);
1759 }
1760 if (should_check(enabled_extensions, device, "VK_EXT_debug_marker")) {
1761 if (string_eq(pName, "vkDebugMarkerSetObjectTagEXT")) return to_vkVoidFunction(test_vkDebugMarkerSetObjectTagEXT);
1762 if (string_eq(pName, "vkDebugMarkerSetObjectNameEXT")) return to_vkVoidFunction(test_vkDebugMarkerSetObjectNameEXT);
1763 if (string_eq(pName, "vkCmdDebugMarkerBeginEXT")) return to_vkVoidFunction(test_vkCmdDebugMarkerBeginEXT);
1764 if (string_eq(pName, "vkCmdDebugMarkerEndEXT")) return to_vkVoidFunction(test_vkCmdDebugMarkerEndEXT);
1765 if (string_eq(pName, "vkCmdDebugMarkerInsertEXT")) return to_vkVoidFunction(test_vkCmdDebugMarkerInsertEXT);
1766 }
1767 if (IsInstanceExtensionEnabled("VK_EXT_debug_utils")) {
1768 if (string_eq(pName, "vkSetDebugUtilsObjectNameEXT")) return to_vkVoidFunction(test_vkSetDebugUtilsObjectNameEXT);
1769 if (string_eq(pName, "vkSetDebugUtilsObjectTagEXT")) return to_vkVoidFunction(test_vkSetDebugUtilsObjectTagEXT);
1770 if (string_eq(pName, "vkQueueBeginDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkQueueBeginDebugUtilsLabelEXT);
1771 if (string_eq(pName, "vkQueueEndDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkQueueEndDebugUtilsLabelEXT);
1772 if (string_eq(pName, "vkQueueInsertDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkQueueInsertDebugUtilsLabelEXT);
1773 if (string_eq(pName, "vkCmdBeginDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkCmdBeginDebugUtilsLabelEXT);
1774 if (string_eq(pName, "vkCmdEndDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkCmdEndDebugUtilsLabelEXT);
1775 if (string_eq(pName, "vkCmdInsertDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkCmdInsertDebugUtilsLabelEXT);
1776 }
1777 if (found_device.found) {
1778 // look for device functions setup from a test
1779 for (const auto& function : icd.physical_devices.at(found_device.phys_dev).known_device_functions) {
1780 if (function.name == pName) {
1781 return to_vkVoidFunction(function.function);
1782 }
1783 }
1784 } else {
1785 for (const auto& [handle, phys_dev] : icd.physical_devices) {
1786 for (const auto& function : phys_dev.known_device_functions) {
1787 if (function.name == pName) {
1788 return to_vkVoidFunction(function.function);
1789 }
1790 }
1791 }
1792 }
1793 return nullptr;
1794 }
1795
1796 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL test_vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
1797 return get_instance_func(instance, pName);
1798 }
1799
1800 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL test_vkGetDeviceProcAddr(VkDevice device, const char* pName) {
1801 return get_device_func(device, pName);
1802 }
1803
1804 PFN_vkVoidFunction base_get_instance_proc_addr(VkInstance instance, const char* pName) {
1805 if (pName == nullptr) return nullptr;
1806 if (instance == NULL) {
1807 if (string_eq(pName, "vk_icdNegotiateLoaderICDInterfaceVersion"))
1808 return icd.exposes_vk_icdNegotiateLoaderICDInterfaceVersion
1809 ? to_vkVoidFunction(test_vk_icdNegotiateLoaderICDInterfaceVersion)
1810 : NULL;
1811
1812 if (string_eq(pName, "vk_icdGetPhysicalDeviceProcAddr"))
1813 return icd.exposes_vk_icdGetPhysicalDeviceProcAddr ? to_vkVoidFunction(get_physical_device_func) : NULL;
1814 #if defined(WIN32)
1815 if (string_eq(pName, "vk_icdEnumerateAdapterPhysicalDevices"))
1816 return icd.exposes_vk_icdEnumerateAdapterPhysicalDevices ? to_vkVoidFunction(test_vk_icdEnumerateAdapterPhysicalDevices)
1817 : NULL;
1818 #endif // defined(WIN32)
1819
1820 if (string_eq(pName, "vkGetInstanceProcAddr")) return to_vkVoidFunction(test_vkGetInstanceProcAddr);
1821 if (string_eq(pName, "vkEnumerateInstanceExtensionProperties"))
1822 return icd.exposes_vkEnumerateInstanceExtensionProperties
1823 ? to_vkVoidFunction(test_vkEnumerateInstanceExtensionProperties)
1824 : NULL;
1825 if (string_eq(pName, "vkEnumerateInstanceLayerProperties"))
1826 return to_vkVoidFunction(test_vkEnumerateInstanceLayerProperties);
1827 if (string_eq(pName, "vkEnumerateInstanceVersion"))
1828 return icd.can_query_vkEnumerateInstanceVersion ? to_vkVoidFunction(test_vkEnumerateInstanceVersion) : nullptr;
1829 if (string_eq(pName, "vkCreateInstance")) return to_vkVoidFunction(test_vkCreateInstance);
1830 }
1831 if (string_eq(pName, "vkGetDeviceProcAddr")) return to_vkVoidFunction(test_vkGetDeviceProcAddr);
1832
1833 auto instance_func_return = get_instance_func(instance, pName);
1834 if (instance_func_return != nullptr) return instance_func_return;
1835
1836 // Need to return function pointers for device extensions
1837 auto device_func_return = get_device_func(nullptr, pName);
1838 if (device_func_return != nullptr) return device_func_return;
1839 return nullptr;
1840 }
1841
1842 // Exported functions
1843 extern "C" {
1844 #if TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION && TEST_ICD_EXPORT_VERSION_7
1845 FRAMEWORK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) {
1846 return test_vk_icdNegotiateLoaderICDInterfaceVersion(pSupportedVersion);
1847 }
1848 #endif // TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION
1849
1850 #if TEST_ICD_EXPORT_ICD_GPDPA && TEST_ICD_EXPORT_VERSION_7
1851 FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance instance, const char* pName) {
1852 return get_physical_device_func(instance, pName);
1853 }
1854 #endif // TEST_ICD_EXPORT_ICD_GPDPA
1855
1856 #if TEST_ICD_EXPORT_ICD_GIPA
1857 FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName) {
1858 if (icd.called_vk_icd_gipa == CalledICDGIPA::not_called) icd.called_vk_icd_gipa = CalledICDGIPA::vk_icd_gipa;
1859 return base_get_instance_proc_addr(instance, pName);
1860 }
1861 #else // !TEST_ICD_EXPORT_ICD_GIPA
1862 FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
1863 if (icd.called_vk_icd_gipa == CalledICDGIPA::not_called) icd.called_vk_icd_gipa = CalledICDGIPA::vk_gipa;
1864 return base_get_instance_proc_addr(instance, pName);
1865 }
1866 FRAMEWORK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo,
1867 const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) {
1868 return test_vkCreateInstance(pCreateInfo, pAllocator, pInstance);
1869 }
1870 FRAMEWORK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char* pLayerName,
1871 uint32_t* pPropertyCount,
1872 VkExtensionProperties* pProperties) {
1873 return test_vkEnumerateInstanceExtensionProperties(pLayerName, pPropertyCount, pProperties);
1874 }
1875 #endif // TEST_ICD_EXPORT_ICD_GIPA
1876
1877 #if TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES && TEST_ICD_EXPORT_VERSION_7
1878 #if defined(WIN32)
1879 FRAMEWORK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance, LUID adapterLUID,
1880 uint32_t* pPhysicalDeviceCount,
1881 VkPhysicalDevice* pPhysicalDevices) {
1882 return test_vk_icdEnumerateAdapterPhysicalDevices(instance, adapterLUID, pPhysicalDeviceCount, pPhysicalDevices);
1883 }
1884 #endif // defined(WIN32)
1885 #endif // TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES
1886
1887 } // extern "C"