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