• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 The Khronos Group Inc.
3  * Copyright (c) 2021-2022 Valve Corporation
4  * Copyright (c) 2021-2022 LunarG, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and/or associated documentation files (the "Materials"), to
8  * deal in the Materials without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Materials, and to permit persons to whom the Materials are
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice(s) and this permission notice shall be included in
14  * all copies or substantial portions of the Materials.
15  *
16  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  *
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23  * USE OR OTHER DEALINGS IN THE MATERIALS.
24  *
25  * Author: Charles Giessen <charles@lunarg.com>
26  */
27 
28 #include "test_icd.h"
29 
30 // export vk_icdGetInstanceProcAddr
31 #ifndef TEST_ICD_EXPORT_ICD_GIPA
32 #define TEST_ICD_EXPORT_ICD_GIPA 0
33 #endif
34 
35 // export vk_icdNegotiateLoaderICDInterfaceVersion
36 #ifndef TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION
37 #define TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION 0
38 #endif
39 
40 // export vk_icdGetPhysicalDeviceProcAddr
41 #ifndef TEST_ICD_EXPORT_ICD_GPDPA
42 #define TEST_ICD_EXPORT_ICD_GPDPA 0
43 #endif
44 
45 // export vk_icdEnumerateAdapterPhysicalDevices
46 #ifndef TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES
47 #define TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES 0
48 #endif
49 
50 TestICD icd;
51 extern "C" {
get_test_icd_func()52 FRAMEWORK_EXPORT TestICD* get_test_icd_func() { return &icd; }
reset_icd_func()53 FRAMEWORK_EXPORT TestICD* reset_icd_func() {
54     icd.~TestICD();
55     return new (&icd) TestICD();
56 }
57 }
58 
FindLayer(std::vector<LayerDefinition> & layers,std::string layerName)59 LayerDefinition& FindLayer(std::vector<LayerDefinition>& layers, std::string layerName) {
60     for (auto& layer : layers) {
61         if (layer.layerName == layerName) return layer;
62     }
63     assert(false && "Layer name not found!");
64     return layers[0];
65 }
CheckLayer(std::vector<LayerDefinition> & layers,std::string layerName)66 bool CheckLayer(std::vector<LayerDefinition>& layers, std::string layerName) {
67     for (auto& layer : layers) {
68         if (layer.layerName == layerName) return true;
69     }
70     return false;
71 }
72 
IsInstanceExtensionSupported(const char * extension_name)73 bool IsInstanceExtensionSupported(const char* extension_name) {
74     return icd.instance_extensions.end() !=
75            std::find_if(icd.instance_extensions.begin(), icd.instance_extensions.end(),
76                         [extension_name](Extension const& ext) { return string_eq(&ext.extensionName[0], extension_name); });
77 }
78 
IsInstanceExtensionEnabled(const char * extension_name)79 bool IsInstanceExtensionEnabled(const char* extension_name) {
80     return icd.enabled_instance_extensions.end() !=
81            std::find_if(icd.enabled_instance_extensions.begin(), icd.enabled_instance_extensions.end(),
82                         [extension_name](Extension const& ext) { return string_eq(&ext.extensionName[0], extension_name); });
83 }
84 
IsPhysicalDeviceExtensionAvailable(const char * extension_name)85 bool IsPhysicalDeviceExtensionAvailable(const char* extension_name) {
86     for (auto& phys_dev : icd.physical_devices) {
87         if (phys_dev.extensions.end() !=
88             std::find_if(phys_dev.extensions.begin(), phys_dev.extensions.end(),
89                          [extension_name](Extension const& ext) { return ext.extensionName == extension_name; })) {
90             return true;
91         }
92     }
93     return false;
94 }
95 
96 // typename T must have '.get()' function that returns a type U
97 template <typename T, typename U>
FillCountPtr(std::vector<T> const & data_vec,uint32_t * pCount,U * pData)98 VkResult FillCountPtr(std::vector<T> const& data_vec, uint32_t* pCount, U* pData) {
99     if (pCount == nullptr) {
100         return VK_ERROR_OUT_OF_HOST_MEMORY;
101     }
102     if (pData == nullptr) {
103         *pCount = static_cast<uint32_t>(data_vec.size());
104         return VK_SUCCESS;
105     }
106     uint32_t amount_written = 0;
107     uint32_t amount_to_write = static_cast<uint32_t>(data_vec.size());
108     if (*pCount < data_vec.size()) {
109         amount_to_write = *pCount;
110     }
111     for (size_t i = 0; i < amount_to_write; i++) {
112         pData[i] = data_vec[i].get();
113         amount_written++;
114     }
115     if (*pCount < data_vec.size()) {
116         *pCount = amount_written;
117         return VK_INCOMPLETE;
118     }
119     *pCount = amount_written;
120     return VK_SUCCESS;
121 }
122 
123 template <typename T>
FillCountPtr(std::vector<T> const & data_vec,uint32_t * pCount,T * pData)124 VkResult FillCountPtr(std::vector<T> const& data_vec, uint32_t* pCount, T* pData) {
125     if (pCount == nullptr) {
126         return VK_ERROR_OUT_OF_HOST_MEMORY;
127     }
128     if (pData == nullptr) {
129         *pCount = static_cast<uint32_t>(data_vec.size());
130         return VK_SUCCESS;
131     }
132     uint32_t amount_written = 0;
133     uint32_t amount_to_write = static_cast<uint32_t>(data_vec.size());
134     if (*pCount < data_vec.size()) {
135         amount_to_write = *pCount;
136     }
137     for (size_t i = 0; i < amount_to_write; i++) {
138         pData[i] = data_vec[i];
139         amount_written++;
140     }
141     if (*pCount < data_vec.size()) {
142         *pCount = amount_written;
143         return VK_INCOMPLETE;
144     }
145     *pCount = amount_written;
146     return VK_SUCCESS;
147 }
148 
149 //// Instance Functions ////
150 
151 // VK_SUCCESS,VK_INCOMPLETE
test_vkEnumerateInstanceExtensionProperties(const char * pLayerName,uint32_t * pPropertyCount,VkExtensionProperties * pProperties)152 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceExtensionProperties(const char* pLayerName, uint32_t* pPropertyCount,
153                                                                            VkExtensionProperties* pProperties) {
154     if (pLayerName != nullptr) {
155         auto& layer = FindLayer(icd.instance_layers, std::string(pLayerName));
156         return FillCountPtr(layer.extensions, pPropertyCount, pProperties);
157     } else {  // instance extensions
158         FillCountPtr(icd.instance_extensions, pPropertyCount, pProperties);
159     }
160 
161     return VK_SUCCESS;
162 }
163 
test_vkEnumerateInstanceLayerProperties(uint32_t * pPropertyCount,VkLayerProperties * pProperties)164 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount, VkLayerProperties* pProperties) {
165     return FillCountPtr(icd.instance_layers, pPropertyCount, pProperties);
166 }
167 
test_vkEnumerateInstanceVersion(uint32_t * pApiVersion)168 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceVersion(uint32_t* pApiVersion) {
169     if (pApiVersion != nullptr) {
170         *pApiVersion = VK_API_VERSION_1_0;
171     }
172     return VK_SUCCESS;
173 }
174 
test_vkCreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance)175 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo,
176                                                      const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) {
177     if (pCreateInfo == nullptr || pCreateInfo->pApplicationInfo == nullptr) {
178         return VK_ERROR_OUT_OF_HOST_MEMORY;
179     }
180 
181     if (icd.icd_api_version < VK_API_VERSION_1_1) {
182         if (pCreateInfo->pApplicationInfo->apiVersion > VK_API_VERSION_1_0) {
183             return VK_ERROR_INCOMPATIBLE_DRIVER;
184         }
185     }
186 
187     // Add to the list of enabled extensions only those that the ICD actively supports
188     for (uint32_t iii = 0; iii < pCreateInfo->enabledExtensionCount; ++iii) {
189         if (IsInstanceExtensionSupported(pCreateInfo->ppEnabledExtensionNames[iii])) {
190             icd.add_enabled_instance_extension({pCreateInfo->ppEnabledExtensionNames[iii]});
191         }
192     }
193 
194     // VK_SUCCESS
195     *pInstance = icd.instance_handle.handle;
196 
197     icd.passed_in_instance_create_flags = pCreateInfo->flags;
198 
199     return VK_SUCCESS;
200 }
201 
test_vkDestroyInstance(VkInstance instance,const VkAllocationCallbacks * pAllocator)202 VKAPI_ATTR void VKAPI_CALL test_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator) {}
203 
204 // VK_SUCCESS,VK_INCOMPLETE
test_vkEnumeratePhysicalDevices(VkInstance instance,uint32_t * pPhysicalDeviceCount,VkPhysicalDevice * pPhysicalDevices)205 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount,
206                                                                VkPhysicalDevice* pPhysicalDevices) {
207     if (pPhysicalDevices == nullptr) {
208         *pPhysicalDeviceCount = static_cast<uint32_t>(icd.physical_devices.size());
209     } else {
210         uint32_t handles_written = 0;
211         for (size_t i = 0; i < icd.physical_devices.size(); i++) {
212             if (i < *pPhysicalDeviceCount) {
213                 handles_written++;
214                 pPhysicalDevices[i] = icd.physical_devices[i].vk_physical_device.handle;
215             } else {
216                 *pPhysicalDeviceCount = handles_written;
217                 return VK_INCOMPLETE;
218             }
219         }
220         *pPhysicalDeviceCount = handles_written;
221     }
222     return VK_SUCCESS;
223 }
224 
225 // VK_SUCCESS,VK_INCOMPLETE, VK_ERROR_INITIALIZATION_FAILED
test_vkEnumeratePhysicalDeviceGroups(VkInstance instance,uint32_t * pPhysicalDeviceGroupCount,VkPhysicalDeviceGroupProperties * pPhysicalDeviceGroupProperties)226 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumeratePhysicalDeviceGroups(
227     VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties) {
228     VkResult result = VK_SUCCESS;
229 
230     if (pPhysicalDeviceGroupProperties == nullptr) {
231         if (0 == icd.physical_device_groups.size()) {
232             *pPhysicalDeviceGroupCount = static_cast<uint32_t>(icd.physical_devices.size());
233         } else {
234             *pPhysicalDeviceGroupCount = static_cast<uint32_t>(icd.physical_device_groups.size());
235         }
236     } else {
237         // NOTE: This is a fake struct to make sure the pNext chain is properly passed down to the ICD
238         //       vkEnumeratePhysicalDeviceGroups.
239         //       The two versions must match:
240         //           "FakePNext" test in loader_regresion_tests.cpp
241         //           "test_vkEnumeratePhysicalDeviceGroups" in test_icd.cpp
242         struct FakePnextSharedWithICD {
243             VkStructureType sType;
244             void* pNext;
245             uint32_t value;
246         };
247 
248         uint32_t group_count = 0;
249         if (0 == icd.physical_device_groups.size()) {
250             group_count = static_cast<uint32_t>(icd.physical_devices.size());
251             for (size_t device_group = 0; device_group < icd.physical_devices.size(); device_group++) {
252                 if (device_group >= *pPhysicalDeviceGroupCount) {
253                     group_count = *pPhysicalDeviceGroupCount;
254                     result = VK_INCOMPLETE;
255                     break;
256                 }
257                 pPhysicalDeviceGroupProperties[device_group].subsetAllocation = false;
258                 pPhysicalDeviceGroupProperties[device_group].physicalDeviceCount = 1;
259                 pPhysicalDeviceGroupProperties[device_group].physicalDevices[0] =
260                     icd.physical_devices[device_group].vk_physical_device.handle;
261             }
262         } else {
263             group_count = static_cast<uint32_t>(icd.physical_device_groups.size());
264             for (size_t device_group = 0; device_group < icd.physical_device_groups.size(); device_group++) {
265                 if (device_group >= *pPhysicalDeviceGroupCount) {
266                     group_count = *pPhysicalDeviceGroupCount;
267                     result = VK_INCOMPLETE;
268                     break;
269                 }
270                 pPhysicalDeviceGroupProperties[device_group].subsetAllocation =
271                     icd.physical_device_groups[device_group].subset_allocation;
272                 uint32_t handles_written = 0;
273                 for (size_t i = 0; i < icd.physical_device_groups[device_group].physical_device_handles.size(); i++) {
274                     handles_written++;
275                     pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] =
276                         icd.physical_device_groups[device_group].physical_device_handles[i]->vk_physical_device.handle;
277                 }
278                 pPhysicalDeviceGroupProperties[device_group].physicalDeviceCount = handles_written;
279             }
280         }
281         // NOTE: The following code is purely to test pNext passing in vkEnumeratePhysicalDevice groups
282         //       and includes normally invalid information.
283         for (size_t device_group = 0; device_group < group_count; device_group++) {
284             if (nullptr != pPhysicalDeviceGroupProperties[device_group].pNext) {
285                 VkBaseInStructure* base = reinterpret_cast<VkBaseInStructure*>(pPhysicalDeviceGroupProperties[device_group].pNext);
286                 if (base->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTI_DRAW_PROPERTIES_EXT) {
287                     FakePnextSharedWithICD* fake = reinterpret_cast<FakePnextSharedWithICD*>(base);
288                     fake->value = 0xDECAFBAD;
289                 }
290             }
291         }
292         *pPhysicalDeviceGroupCount = static_cast<uint32_t>(group_count);
293     }
294     return result;
295 }
296 
test_vkCreateDebugUtilsMessengerEXT(VkInstance instance,const VkDebugUtilsMessengerCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDebugUtilsMessengerEXT * pMessenger)297 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDebugUtilsMessengerEXT(VkInstance instance,
298                                                                    const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
299                                                                    const VkAllocationCallbacks* pAllocator,
300                                                                    VkDebugUtilsMessengerEXT* pMessenger) {
301     if (nullptr != pMessenger) {
302         uint64_t fake_msgr_handle = reinterpret_cast<uint64_t>(new uint8_t);
303         icd.messenger_handles.push_back(fake_msgr_handle);
304 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
305     defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
306         *pMessenger = reinterpret_cast<VkDebugUtilsMessengerEXT>(fake_msgr_handle);
307 #else
308         *pMessenger = fake_msgr_handle;
309 #endif
310     }
311     return VK_SUCCESS;
312 }
313 
test_vkDestroyDebugUtilsMessengerEXT(VkInstance instance,VkDebugUtilsMessengerEXT messenger,const VkAllocationCallbacks * pAllocator)314 VKAPI_ATTR void VKAPI_CALL test_vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger,
315                                                                 const VkAllocationCallbacks* pAllocator) {
316     if (messenger != VK_NULL_HANDLE) {
317         uint64_t fake_msgr_handle = (uint64_t)(messenger);
318         auto found_iter = std::find(icd.messenger_handles.begin(), icd.messenger_handles.end(), fake_msgr_handle);
319         if (found_iter != icd.messenger_handles.end()) {
320             // Remove it from the list
321             icd.messenger_handles.erase(found_iter);
322             // Delete the handle
323             delete (uint8_t*)fake_msgr_handle;
324         } else {
325             assert(false && "Messenger not found during destroy!");
326         }
327     }
328 }
329 
330 //// Physical Device functions ////
331 
332 // VK_SUCCESS,VK_INCOMPLETE
test_vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkLayerProperties * pProperties)333 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount,
334                                                                      VkLayerProperties* pProperties) {
335     assert(false && "ICD's don't contain layers???");
336     return VK_SUCCESS;
337 }
338 
339 // VK_SUCCESS, VK_INCOMPLETE, VK_ERROR_LAYER_NOT_PRESENT
test_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,const char * pLayerName,uint32_t * pPropertyCount,VkExtensionProperties * pProperties)340 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char* pLayerName,
341                                                                          uint32_t* pPropertyCount,
342                                                                          VkExtensionProperties* pProperties) {
343     auto& phys_dev = icd.GetPhysDevice(physicalDevice);
344     if (pLayerName != nullptr) {
345         assert(false && "Drivers don't contain layers???");
346         return VK_SUCCESS;
347     } else {  // instance extensions
348         return FillCountPtr(phys_dev.extensions, pPropertyCount, pProperties);
349     }
350 }
351 
test_vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties * pQueueFamilyProperties)352 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
353                                                                          uint32_t* pQueueFamilyPropertyCount,
354                                                                          VkQueueFamilyProperties* pQueueFamilyProperties) {
355     auto& phys_dev = icd.GetPhysDevice(physicalDevice);
356     FillCountPtr(phys_dev.queue_family_properties, pQueueFamilyPropertyCount, pQueueFamilyProperties);
357 }
358 
test_vkCreateDevice(VkPhysicalDevice physicalDevice,const VkDeviceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDevice * pDevice)359 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo,
360                                                    const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) {
361     // VK_SUCCESS
362     auto found = std::find_if(icd.physical_devices.begin(), icd.physical_devices.end(), [physicalDevice](PhysicalDevice& phys_dev) {
363         return phys_dev.vk_physical_device.handle == physicalDevice;
364     });
365     if (found == icd.physical_devices.end()) return VK_ERROR_INITIALIZATION_FAILED;
366     auto device_handle = DispatchableHandle<VkDevice>();
367     *pDevice = device_handle.handle;
368     found->device_handles.push_back(device_handle.handle);
369     icd.device_handles.emplace_back(std::move(device_handle));
370 
371     for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
372         found->queue_handles.emplace_back();
373     }
374 
375     return VK_SUCCESS;
376 }
377 
test_vkDestroyDevice(VkDevice device,const VkAllocationCallbacks * pAllocator)378 VKAPI_ATTR void VKAPI_CALL test_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) {
379     auto found = std::find(icd.device_handles.begin(), icd.device_handles.end(), device);
380     if (found != icd.device_handles.end()) icd.device_handles.erase(found);
381 }
382 
generic_tool_props_function(VkPhysicalDevice physicalDevice,uint32_t * pToolCount,VkPhysicalDeviceToolPropertiesEXT * pToolProperties)383 VKAPI_ATTR VkResult VKAPI_CALL generic_tool_props_function(VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
384                                                            VkPhysicalDeviceToolPropertiesEXT* pToolProperties) {
385     if (icd.tooling_properties.size() == 0) {
386         return VK_SUCCESS;
387     }
388     if (pToolProperties == nullptr && pToolCount != nullptr) {
389         *pToolCount = static_cast<uint32_t>(icd.tooling_properties.size());
390     } else if (pToolCount != nullptr) {
391         for (size_t i = 0; i < *pToolCount; i++) {
392             if (i >= icd.tooling_properties.size()) {
393                 return VK_INCOMPLETE;
394             }
395             pToolProperties[i] = icd.tooling_properties[i];
396         }
397     }
398     return VK_SUCCESS;
399 }
400 
test_vkGetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice,uint32_t * pToolCount,VkPhysicalDeviceToolPropertiesEXT * pToolProperties)401 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceToolPropertiesEXT(VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
402                                                                          VkPhysicalDeviceToolPropertiesEXT* pToolProperties) {
403     return generic_tool_props_function(physicalDevice, pToolCount, pToolProperties);
404 }
405 
test_vkGetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice,uint32_t * pToolCount,VkPhysicalDeviceToolPropertiesEXT * pToolProperties)406 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice, uint32_t* pToolCount,
407                                                                       VkPhysicalDeviceToolPropertiesEXT* pToolProperties) {
408     return generic_tool_props_function(physicalDevice, pToolCount, pToolProperties);
409 }
410 
411 template <typename T>
to_nondispatch_handle(uint64_t handle)412 T to_nondispatch_handle(uint64_t handle) {
413 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
414     defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
415     return reinterpret_cast<T>(handle);
416 #else
417     return handle;
418 #endif
419 }
420 
421 template <typename T>
from_nondispatch_handle(T handle)422 uint64_t from_nondispatch_handle(T handle) {
423 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
424     defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
425     return reinterpret_cast<uint64_t>(handle);
426 #else
427     return handle;
428 #endif
429 }
430 
431 //// WSI ////
432 template <typename HandleType>
common_nondispatch_handle_creation(std::vector<uint64_t> & handles,HandleType * pHandle)433 void common_nondispatch_handle_creation(std::vector<uint64_t>& handles, HandleType* pHandle) {
434     if (nullptr != pHandle) {
435         if (handles.size() == 0)
436             handles.push_back(800851234);
437         else
438             handles.push_back(handles.back() + 102030);
439         *pHandle = to_nondispatch_handle<HandleType>(handles.back());
440     }
441 }
442 #ifdef VK_USE_PLATFORM_ANDROID_KHR
443 
test_vkCreateAndroidSurfaceKHR(VkInstance instance,const VkAndroidSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)444 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
445                                                               const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
446     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
447     return VK_SUCCESS;
448 }
449 #endif
450 
451 #ifdef VK_USE_PLATFORM_WIN32_KHR
test_vkCreateWin32SurfaceKHR(VkInstance instance,const VkWin32SurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)452 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
453                                                             const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
454     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
455     return VK_SUCCESS;
456 }
457 
test_vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex)458 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice physicalDevice,
459                                                                                    uint32_t queueFamilyIndex) {
460     return VK_TRUE;
461 }
462 #endif  // VK_USE_PLATFORM_WIN32_KHR
463 
464 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
test_vkCreateWaylandSurfaceKHR(VkInstance instance,const VkWaylandSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)465 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
466                                                               const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
467     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
468     return VK_SUCCESS;
469 }
470 
test_vkGetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,struct wl_display * display)471 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice physicalDevice,
472                                                                                      uint32_t queueFamilyIndex,
473                                                                                      struct wl_display* display) {
474     return VK_TRUE;
475 }
476 #endif  // VK_USE_PLATFORM_WAYLAND_KHR
477 #ifdef VK_USE_PLATFORM_XCB_KHR
test_vkCreateXcbSurfaceKHR(VkInstance instance,const VkXcbSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)478 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
479                                                           const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
480     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
481     return VK_SUCCESS;
482 }
483 
test_vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,xcb_connection_t * connection,xcb_visualid_t visual_id)484 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceXcbPresentationSupportKHR(VkPhysicalDevice physicalDevice,
485                                                                                  uint32_t queueFamilyIndex,
486                                                                                  xcb_connection_t* connection,
487                                                                                  xcb_visualid_t visual_id) {
488     return VK_TRUE;
489 }
490 #endif  // VK_USE_PLATFORM_XCB_KHR
491 
492 #ifdef VK_USE_PLATFORM_XLIB_KHR
test_vkCreateXlibSurfaceKHR(VkInstance instance,const VkXlibSurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)493 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
494                                                            const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
495     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
496     return VK_SUCCESS;
497 }
498 
test_vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,Display * dpy,VisualID visualID)499 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice,
500                                                                                   uint32_t queueFamilyIndex, Display* dpy,
501                                                                                   VisualID visualID) {
502     return VK_TRUE;
503 }
504 #endif  // VK_USE_PLATFORM_XLIB_KHR
505 
506 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
test_vkCreateDirectFBSurfaceEXT(VkInstance instance,const VkDirectFBSurfaceCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)507 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDirectFBSurfaceEXT(VkInstance instance,
508                                                                const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo,
509                                                                const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
510     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
511     return VK_SUCCESS;
512 }
513 
test_vkGetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,IDirectFB * dfb)514 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceDirectFBPresentationSupportEXT(VkPhysicalDevice physicalDevice,
515                                                                                       uint32_t queueFamilyIndex, IDirectFB* dfb) {
516     return VK_TRUE;
517 }
518 
519 #endif  // VK_USE_PLATFORM_DIRECTFB_EXT
520 
521 #ifdef VK_USE_PLATFORM_MACOS_MVK
test_vkCreateMacOSSurfaceMVK(VkInstance instance,const VkMacOSSurfaceCreateInfoMVK * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)522 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo,
523                                                             const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
524     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
525     return VK_SUCCESS;
526 }
527 #endif  // VK_USE_PLATFORM_MACOS_MVK
528 
529 #ifdef VK_USE_PLATFORM_IOS_MVK
test_vkCreateIOSSurfaceMVK(VkInstance instance,const VkIOSSurfaceCreateInfoMVK * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)530 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo,
531                                                           const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
532     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
533     return VK_SUCCESS;
534 }
535 #endif  // VK_USE_PLATFORM_IOS_MVK
536 
537 #ifdef VK_USE_PLATFORM_GGP
test_vkCreateStreamDescriptorSurfaceGGP(VkInstance instance,const VkStreamDescriptorSurfaceCreateInfoGGP * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)538 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateStreamDescriptorSurfaceGGP(VkInstance instance,
539                                                                        const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo,
540                                                                        const VkAllocationCallbacks* pAllocator,
541                                                                        VkSurfaceKHR* pSurface) {
542     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
543     return VK_SUCCESS;
544 }
545 #endif  // VK_USE_PLATFORM_GGP
546 
547 #if defined(VK_USE_PLATFORM_METAL_EXT)
test_vkCreateMetalSurfaceEXT(VkInstance instance,const VkMetalSurfaceCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)548 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateMetalSurfaceEXT(VkInstance instance, const VkMetalSurfaceCreateInfoEXT* pCreateInfo,
549                                                             const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
550     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
551     return VK_SUCCESS;
552 }
553 #endif  // VK_USE_PLATFORM_METAL_EXT
554 
555 #ifdef VK_USE_PLATFORM_SCREEN_QNX
test_vkCreateScreenSurfaceQNX(VkInstance instance,const VkScreenSurfaceCreateInfoQNX * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)556 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateScreenSurfaceQNX(VkInstance instance, const VkScreenSurfaceCreateInfoQNX* pCreateInfo,
557                                                              const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
558     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
559     return VK_SUCCESS;
560 }
561 
test_vkGetPhysicalDeviceScreenPresentationSupportQNX(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,struct _screen_window * window)562 VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceScreenPresentationSupportQNX(VkPhysicalDevice physicalDevice,
563                                                                                     uint32_t queueFamilyIndex,
564                                                                                     struct _screen_window* window) {
565     return VK_TRUE;
566 }
567 #endif  // VK_USE_PLATFORM_SCREEN_QNX
568 
test_vkCreateHeadlessSurfaceEXT(VkInstance instance,const VkHeadlessSurfaceCreateInfoEXT * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)569 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateHeadlessSurfaceEXT(VkInstance instance,
570                                                                const VkHeadlessSurfaceCreateInfoEXT* pCreateInfo,
571                                                                const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
572     common_nondispatch_handle_creation(icd.surface_handles, pSurface);
573     return VK_SUCCESS;
574 }
575 
test_vkDestroySurfaceKHR(VkInstance instance,VkSurfaceKHR surface,const VkAllocationCallbacks * pAllocator)576 VKAPI_ATTR void VKAPI_CALL test_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
577                                                     const VkAllocationCallbacks* pAllocator) {
578     if (surface != VK_NULL_HANDLE) {
579         uint64_t fake_surf_handle = from_nondispatch_handle(surface);
580         auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
581         if (found_iter != icd.surface_handles.end()) {
582             // Remove it from the list
583             icd.surface_handles.erase(found_iter);
584         } else {
585             assert(false && "Surface not found during destroy!");
586         }
587     }
588 }
589 
test_vkCreateSwapchainKHR(VkDevice device,const VkSwapchainCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSwapchainKHR * pSwapchain)590 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo,
591                                                          const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) {
592     common_nondispatch_handle_creation(icd.swapchain_handles, pSwapchain);
593     return VK_SUCCESS;
594 }
595 
test_vkDestroySwapchainKHR(VkDevice device,VkSwapchainKHR swapchain,const VkAllocationCallbacks * pAllocator)596 VKAPI_ATTR void VKAPI_CALL test_vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
597                                                       const VkAllocationCallbacks* pAllocator) {
598     if (swapchain != VK_NULL_HANDLE) {
599         uint64_t fake_swapchain_handle = from_nondispatch_handle(swapchain);
600         auto found_iter = icd.swapchain_handles.erase(
601             std::remove(icd.swapchain_handles.begin(), icd.swapchain_handles.end(), fake_swapchain_handle),
602             icd.swapchain_handles.end());
603         if (found_iter == icd.swapchain_handles.end()) {
604             assert(false && "Swapchain not found during destroy!");
605         }
606     }
607 }
608 
609 // VK_KHR_surface
test_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,VkSurfaceKHR surface,VkBool32 * pSupported)610 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
611                                                                          VkSurfaceKHR surface, VkBool32* pSupported) {
612     if (surface != VK_NULL_HANDLE) {
613         uint64_t fake_surf_handle = (uint64_t)(surface);
614         auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
615         if (found_iter == icd.surface_handles.end()) {
616             assert(false && "Surface not found during GetPhysicalDeviceSurfaceSupportKHR query!");
617             return VK_ERROR_UNKNOWN;
618         }
619     }
620     if (nullptr != pSupported) {
621         *pSupported = icd.GetPhysDevice(physicalDevice).queue_family_properties.at(queueFamilyIndex).support_present;
622     }
623     return VK_SUCCESS;
624 }
test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,VkSurfaceCapabilitiesKHR * pSurfaceCapabilities)625 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
626                                                                               VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) {
627     if (surface != VK_NULL_HANDLE) {
628         uint64_t fake_surf_handle = (uint64_t)(surface);
629         auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
630         if (found_iter == icd.surface_handles.end()) {
631             assert(false && "Surface not found during GetPhysicalDeviceSurfaceCapabilitiesKHR query!");
632             return VK_ERROR_UNKNOWN;
633         }
634     }
635     if (nullptr != pSurfaceCapabilities) {
636         *pSurfaceCapabilities = icd.GetPhysDevice(physicalDevice).surface_capabilities;
637     }
638     return VK_SUCCESS;
639 }
test_vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pSurfaceFormatCount,VkSurfaceFormatKHR * pSurfaceFormats)640 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
641                                                                          uint32_t* pSurfaceFormatCount,
642                                                                          VkSurfaceFormatKHR* pSurfaceFormats) {
643     if (surface != VK_NULL_HANDLE) {
644         uint64_t fake_surf_handle = (uint64_t)(surface);
645         auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
646         if (found_iter == icd.surface_handles.end()) {
647             assert(false && "Surface not found during GetPhysicalDeviceSurfaceFormatsKHR query!");
648             return VK_ERROR_UNKNOWN;
649         }
650     }
651     FillCountPtr(icd.GetPhysDevice(physicalDevice).surface_formats, pSurfaceFormatCount, pSurfaceFormats);
652     return VK_SUCCESS;
653 }
test_vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,VkSurfaceKHR surface,uint32_t * pPresentModeCount,VkPresentModeKHR * pPresentModes)654 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
655                                                                               uint32_t* pPresentModeCount,
656                                                                               VkPresentModeKHR* pPresentModes) {
657     if (surface != VK_NULL_HANDLE) {
658         uint64_t fake_surf_handle = (uint64_t)(surface);
659         auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
660         if (found_iter == icd.surface_handles.end()) {
661             assert(false && "Surface not found during GetPhysicalDeviceSurfacePresentModesKHR query!");
662             return VK_ERROR_UNKNOWN;
663         }
664     }
665     FillCountPtr(icd.GetPhysDevice(physicalDevice).surface_present_modes, pPresentModeCount, pPresentModes);
666     return VK_SUCCESS;
667 }
668 
669 // VK_KHR_display
test_vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayPropertiesKHR * pProperties)670 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice,
671                                                                             uint32_t* pPropertyCount,
672                                                                             VkDisplayPropertiesKHR* pProperties) {
673     FillCountPtr(icd.GetPhysDevice(physicalDevice).display_properties, pPropertyCount, pProperties);
674     return VK_SUCCESS;
675 }
test_vkGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,uint32_t * pPropertyCount,VkDisplayPlanePropertiesKHR * pProperties)676 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
677                                                                                  uint32_t* pPropertyCount,
678                                                                                  VkDisplayPlanePropertiesKHR* pProperties) {
679     FillCountPtr(icd.GetPhysDevice(physicalDevice).display_plane_properties, pPropertyCount, pProperties);
680     return VK_SUCCESS;
681 }
test_vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice,uint32_t planeIndex,uint32_t * pDisplayCount,VkDisplayKHR * pDisplays)682 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex,
683                                                                           uint32_t* pDisplayCount, VkDisplayKHR* pDisplays) {
684     FillCountPtr(icd.GetPhysDevice(physicalDevice).displays, pDisplayCount, pDisplays);
685     return VK_SUCCESS;
686 }
test_vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,uint32_t * pPropertyCount,VkDisplayModePropertiesKHR * pProperties)687 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
688                                                                   uint32_t* pPropertyCount,
689                                                                   VkDisplayModePropertiesKHR* pProperties) {
690     FillCountPtr(icd.GetPhysDevice(physicalDevice).display_mode_properties, pPropertyCount, pProperties);
691     return VK_SUCCESS;
692 }
test_vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice,VkDisplayKHR display,const VkDisplayModeCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDisplayModeKHR * pMode)693 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
694                                                            const VkDisplayModeCreateInfoKHR* pCreateInfo,
695                                                            const VkAllocationCallbacks* pAllocator, VkDisplayModeKHR* pMode) {
696     if (nullptr != pMode) {
697         *pMode = icd.GetPhysDevice(physicalDevice).display_mode;
698     }
699     return VK_SUCCESS;
700 }
test_vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice,VkDisplayModeKHR mode,uint32_t planeIndex,VkDisplayPlaneCapabilitiesKHR * pCapabilities)701 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode,
702                                                                      uint32_t planeIndex,
703                                                                      VkDisplayPlaneCapabilitiesKHR* pCapabilities) {
704     if (nullptr != pCapabilities) {
705         *pCapabilities = icd.GetPhysDevice(physicalDevice).display_plane_capabilities;
706     }
707     return VK_SUCCESS;
708 }
test_vkCreateDisplayPlaneSurfaceKHR(VkInstance instance,const VkDisplaySurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface)709 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDisplayPlaneSurfaceKHR(VkInstance instance,
710                                                                    const VkDisplaySurfaceCreateInfoKHR* pCreateInfo,
711                                                                    const VkAllocationCallbacks* pAllocator,
712                                                                    VkSurfaceKHR* pSurface) {
713     if (nullptr != pSurface) {
714         uint64_t fake_surf_handle = reinterpret_cast<uint64_t>(new uint8_t);
715         icd.surface_handles.push_back(fake_surf_handle);
716 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
717     defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
718         *pSurface = reinterpret_cast<VkSurfaceKHR>(fake_surf_handle);
719 #else
720         *pSurface = fake_surf_handle;
721 #endif
722     }
723     return VK_SUCCESS;
724 }
725 
726 // VK_KHR_get_surface_capabilities2
test_vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,VkSurfaceCapabilities2KHR * pSurfaceCapabilities)727 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice,
728                                                                                const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
729                                                                                VkSurfaceCapabilities2KHR* pSurfaceCapabilities) {
730     if (nullptr != pSurfaceInfo && nullptr != pSurfaceCapabilities) {
731         return test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, pSurfaceInfo->surface,
732                                                               &pSurfaceCapabilities->surfaceCapabilities);
733     }
734     return VK_SUCCESS;
735 }
test_vkGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,uint32_t * pSurfaceFormatCount,VkSurfaceFormat2KHR * pSurfaceFormats)736 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
737                                                                           const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
738                                                                           uint32_t* pSurfaceFormatCount,
739                                                                           VkSurfaceFormat2KHR* pSurfaceFormats) {
740     if (nullptr != pSurfaceFormatCount) {
741         test_vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, pSurfaceInfo->surface, pSurfaceFormatCount, nullptr);
742         if (nullptr != pSurfaceFormats) {
743             auto& phys_dev = icd.GetPhysDevice(physicalDevice);
744             // Since the structures are different, we have to copy each item over seperately.  Since we have multiple, we
745             // have to manually copy the data here instead of calling the next function
746             for (uint32_t cnt = 0; cnt < *pSurfaceFormatCount; ++cnt) {
747                 memcpy(&pSurfaceFormats[cnt].surfaceFormat, &phys_dev.surface_formats[cnt], sizeof(VkSurfaceFormatKHR));
748             }
749         }
750     }
751     return VK_SUCCESS;
752 }
753 
754 //// misc
test_vkCreateCommandPool(VkDevice device,const VkCommandPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkCommandPool * pCommandPool)755 VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo,
756                                                         const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool) {
757     if (pCommandPool != nullptr) {
758         pCommandPool = reinterpret_cast<VkCommandPool*>(0xdeadbeefdeadbeef);
759     }
760     return VK_SUCCESS;
761 }
762 
test_vkDestroyCommandPool(VkDevice device,VkCommandPool commandPool,const VkAllocationCallbacks * pAllocator)763 VKAPI_ATTR void VKAPI_CALL test_vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
764                                                      const VkAllocationCallbacks* pAllocator) {
765     // do nothing, leak memory for now
766 }
test_vkAllocateCommandBuffers(VkDevice device,const VkCommandBufferAllocateInfo * pAllocateInfo,VkCommandBuffer * pCommandBuffers)767 VKAPI_ATTR VkResult VKAPI_CALL test_vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo,
768                                                              VkCommandBuffer* pCommandBuffers) {
769     if (pAllocateInfo != nullptr && pCommandBuffers != nullptr) {
770         for (size_t i = 0; i < pAllocateInfo->commandBufferCount; i++) {
771             icd.allocated_command_buffers.push_back({});
772             pCommandBuffers[i] = icd.allocated_command_buffers.back().handle;
773         }
774     }
775     return VK_SUCCESS;
776 }
777 
test_vkGetDeviceQueue(VkDevice device,uint32_t queueFamilyIndex,uint32_t queueIndex,VkQueue * pQueue)778 VKAPI_ATTR void VKAPI_CALL test_vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue) {
779     *pQueue = icd.physical_devices.back().queue_handles[queueIndex].handle;
780 }
781 
782 // VK_EXT_acquire_drm_display
test_vkAcquireDrmDisplayEXT(VkPhysicalDevice physicalDevice,int32_t drmFd,VkDisplayKHR display)783 VKAPI_ATTR VkResult VKAPI_CALL test_vkAcquireDrmDisplayEXT(VkPhysicalDevice physicalDevice, int32_t drmFd, VkDisplayKHR display) {
784     return VK_SUCCESS;
785 }
786 
test_vkGetDrmDisplayEXT(VkPhysicalDevice physicalDevice,int32_t drmFd,uint32_t connectorId,VkDisplayKHR * display)787 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetDrmDisplayEXT(VkPhysicalDevice physicalDevice, int32_t drmFd, uint32_t connectorId,
788                                                        VkDisplayKHR* display) {
789     if (nullptr != display && icd.GetPhysDevice(physicalDevice).displays.size() > 0) {
790         *display = icd.GetPhysDevice(physicalDevice).displays[0];
791     }
792     return VK_SUCCESS;
793 }
794 
795 //// stubs
796 // 1.0
test_vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,VkPhysicalDeviceFeatures * pFeatures)797 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures) {
798     if (nullptr != pFeatures) {
799         memcpy(pFeatures, &icd.GetPhysDevice(physicalDevice).features, sizeof(VkPhysicalDeviceFeatures));
800     }
801 }
test_vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,VkPhysicalDeviceProperties * pProperties)802 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
803                                                               VkPhysicalDeviceProperties* pProperties) {
804     if (nullptr != pProperties) {
805         auto& phys_dev = icd.GetPhysDevice(physicalDevice);
806         memcpy(pProperties, &phys_dev.properties, sizeof(VkPhysicalDeviceProperties));
807         size_t max_len = (phys_dev.deviceName.length() > VK_MAX_PHYSICAL_DEVICE_NAME_SIZE) ? VK_MAX_PHYSICAL_DEVICE_NAME_SIZE
808                                                                                            : phys_dev.deviceName.length();
809         std::copy(phys_dev.deviceName.c_str(), phys_dev.deviceName.c_str() + max_len, pProperties->deviceName);
810         pProperties->deviceName[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE - 1] = '\0';
811     }
812 }
test_vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,VkPhysicalDeviceMemoryProperties * pMemoryProperties)813 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,
814                                                                     VkPhysicalDeviceMemoryProperties* pMemoryProperties) {
815     if (nullptr != pMemoryProperties) {
816         memcpy(pMemoryProperties, &icd.GetPhysDevice(physicalDevice).memory_properties, sizeof(VkPhysicalDeviceMemoryProperties));
817     }
818 }
test_vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice,VkFormat format,VkImageType type,VkSampleCountFlagBits samples,VkImageUsageFlags usage,VkImageTiling tiling,uint32_t * pPropertyCount,VkSparseImageFormatProperties * pProperties)819 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
820                                                                                VkImageType type, VkSampleCountFlagBits samples,
821                                                                                VkImageUsageFlags usage, VkImageTiling tiling,
822                                                                                uint32_t* pPropertyCount,
823                                                                                VkSparseImageFormatProperties* pProperties) {
824     FillCountPtr(icd.GetPhysDevice(physicalDevice).sparse_image_format_properties, pPropertyCount, pProperties);
825 }
test_vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,VkFormat format,VkFormatProperties * pFormatProperties)826 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
827                                                                     VkFormatProperties* pFormatProperties) {
828     if (nullptr != pFormatProperties) {
829         memcpy(pFormatProperties, &icd.GetPhysDevice(physicalDevice).format_properties[static_cast<uint32_t>(format)],
830                sizeof(VkFormatProperties));
831     }
832 }
test_vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice,VkFormat format,VkImageType type,VkImageTiling tiling,VkImageUsageFlags usage,VkImageCreateFlags flags,VkImageFormatProperties * pImageFormatProperties)833 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
834                                                                              VkImageType type, VkImageTiling tiling,
835                                                                              VkImageUsageFlags usage, VkImageCreateFlags flags,
836                                                                              VkImageFormatProperties* pImageFormatProperties) {
837     if (nullptr != pImageFormatProperties) {
838         memcpy(pImageFormatProperties, &icd.GetPhysDevice(physicalDevice).image_format_properties, sizeof(VkImageFormatProperties));
839     }
840     return VK_SUCCESS;
841 }
842 
843 // 1.1
test_vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,VkPhysicalDeviceFeatures2 * pFeatures)844 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
845                                                              VkPhysicalDeviceFeatures2* pFeatures) {
846     if (nullptr != pFeatures) {
847         test_vkGetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
848     }
849 }
test_vkGetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,VkPhysicalDeviceProperties2 * pProperties)850 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
851                                                                VkPhysicalDeviceProperties2* pProperties) {
852     if (nullptr != pProperties) {
853         auto& phys_dev = icd.GetPhysDevice(physicalDevice);
854         test_vkGetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
855         VkBaseInStructure* pNext = reinterpret_cast<VkBaseInStructure*>(pProperties->pNext);
856         while (pNext) {
857             if (pNext->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT) {
858                 VkPhysicalDevicePCIBusInfoPropertiesEXT* bus_info =
859                     reinterpret_cast<VkPhysicalDevicePCIBusInfoPropertiesEXT*>(pNext);
860                 bus_info->pciBus = phys_dev.pci_bus;
861             }
862             pNext = reinterpret_cast<VkBaseInStructure*>(const_cast<VkBaseInStructure*>(pNext->pNext));
863         }
864     }
865 }
test_vkGetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice,VkPhysicalDeviceMemoryProperties2 * pMemoryProperties)866 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice,
867                                                                      VkPhysicalDeviceMemoryProperties2* pMemoryProperties) {
868     if (nullptr != pMemoryProperties) {
869         test_vkGetPhysicalDeviceMemoryProperties(physicalDevice, &pMemoryProperties->memoryProperties);
870     }
871 }
test_vkGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,uint32_t * pQueueFamilyPropertyCount,VkQueueFamilyProperties2 * pQueueFamilyProperties)872 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,
873                                                                           uint32_t* pQueueFamilyPropertyCount,
874                                                                           VkQueueFamilyProperties2* pQueueFamilyProperties) {
875     if (nullptr != pQueueFamilyPropertyCount) {
876         test_vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, nullptr);
877         if (nullptr != pQueueFamilyProperties) {
878             auto& phys_dev = icd.GetPhysDevice(physicalDevice);
879             // Since the structures are different, we have to copy each item over seperately.  Since we have multiple, we
880             // have to manually copy the data here instead of calling the next function
881             for (uint32_t queue = 0; queue < *pQueueFamilyPropertyCount; ++queue) {
882                 memcpy(&pQueueFamilyProperties[queue].queueFamilyProperties, &phys_dev.queue_family_properties[queue].properties,
883                        sizeof(VkQueueFamilyProperties));
884             }
885         }
886     }
887 }
test_vkGetPhysicalDeviceSparseImageFormatProperties2(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceSparseImageFormatInfo2 * pFormatInfo,uint32_t * pPropertyCount,VkSparseImageFormatProperties2 * pProperties)888 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceSparseImageFormatProperties2(
889     VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, uint32_t* pPropertyCount,
890     VkSparseImageFormatProperties2* pProperties) {
891     if (nullptr != pPropertyCount) {
892         test_vkGetPhysicalDeviceSparseImageFormatProperties(physicalDevice, pFormatInfo->format, pFormatInfo->type,
893                                                             pFormatInfo->samples, pFormatInfo->usage, pFormatInfo->tiling,
894                                                             pPropertyCount, nullptr);
895         if (nullptr != pProperties) {
896             auto& phys_dev = icd.GetPhysDevice(physicalDevice);
897             // Since the structures are different, we have to copy each item over seperately.  Since we have multiple, we
898             // have to manually copy the data here instead of calling the next function
899             for (uint32_t cnt = 0; cnt < *pPropertyCount; ++cnt) {
900                 memcpy(&pProperties[cnt].properties, &phys_dev.sparse_image_format_properties[cnt],
901                        sizeof(VkSparseImageFormatProperties));
902             }
903         }
904     }
905 }
test_vkGetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice,VkFormat format,VkFormatProperties2 * pFormatProperties)906 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, VkFormat format,
907                                                                      VkFormatProperties2* pFormatProperties) {
908     if (nullptr != pFormatProperties) {
909         test_vkGetPhysicalDeviceFormatProperties(physicalDevice, format, &pFormatProperties->formatProperties);
910     }
911 }
test_vkGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceImageFormatInfo2 * pImageFormatInfo,VkImageFormatProperties2 * pImageFormatProperties)912 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceImageFormatProperties2(
913     VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo,
914     VkImageFormatProperties2* pImageFormatProperties) {
915     if (nullptr != pImageFormatInfo) {
916         VkImageFormatProperties* ptr = nullptr;
917         if (pImageFormatProperties) {
918             ptr = &pImageFormatProperties->imageFormatProperties;
919         }
920         test_vkGetPhysicalDeviceImageFormatProperties(physicalDevice, pImageFormatInfo->format, pImageFormatInfo->type,
921                                                       pImageFormatInfo->tiling, pImageFormatInfo->usage, pImageFormatInfo->flags,
922                                                       ptr);
923     }
924     return VK_SUCCESS;
925 }
test_vkGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceExternalBufferInfo * pExternalBufferInfo,VkExternalBufferProperties * pExternalBufferProperties)926 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceExternalBufferProperties(
927     VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo,
928     VkExternalBufferProperties* pExternalBufferProperties) {
929     if (nullptr != pExternalBufferProperties) {
930         auto& phys_dev = icd.GetPhysDevice(physicalDevice);
931         memcpy(&pExternalBufferProperties->externalMemoryProperties, &phys_dev.external_memory_properties,
932                sizeof(VkExternalMemoryProperties));
933     }
934 }
test_vkGetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceExternalSemaphoreInfo * pExternalSemaphoreInfo,VkExternalSemaphoreProperties * pExternalSemaphoreProperties)935 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceExternalSemaphoreProperties(
936     VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo,
937     VkExternalSemaphoreProperties* pExternalSemaphoreProperties) {
938     if (nullptr != pExternalSemaphoreProperties) {
939         auto& phys_dev = icd.GetPhysDevice(physicalDevice);
940         memcpy(pExternalSemaphoreProperties, &phys_dev.external_semaphore_properties, sizeof(VkExternalSemaphoreProperties));
941     }
942 }
test_vkGetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceExternalFenceInfo * pExternalFenceInfo,VkExternalFenceProperties * pExternalFenceProperties)943 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceExternalFenceProperties(
944     VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo,
945     VkExternalFenceProperties* pExternalFenceProperties) {
946     if (nullptr != pExternalFenceProperties) {
947         auto& phys_dev = icd.GetPhysDevice(physicalDevice);
948         memcpy(pExternalFenceProperties, &phys_dev.external_fence_properties, sizeof(VkExternalFenceProperties));
949     }
950 }
951 // Entry-points associated with the VK_KHR_performance_query extension
test_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(VkPhysicalDevice physicalDevice,uint32_t queueFamilyIndex,uint32_t * pCounterCount,VkPerformanceCounterKHR * pCounters,VkPerformanceCounterDescriptionKHR * pCounterDescriptions)952 VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
953     VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t* pCounterCount, VkPerformanceCounterKHR* pCounters,
954     VkPerformanceCounterDescriptionKHR* pCounterDescriptions) {
955     return VK_SUCCESS;
956 }
test_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(VkPhysicalDevice physicalDevice,const VkQueryPoolPerformanceCreateInfoKHR * pPerformanceQueryCreateInfo,uint32_t * pNumPasses)957 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(
958     VkPhysicalDevice physicalDevice, const VkQueryPoolPerformanceCreateInfoKHR* pPerformanceQueryCreateInfo, uint32_t* pNumPasses) {
959 }
test_vkAcquireProfilingLockKHR(VkDevice device,const VkAcquireProfilingLockInfoKHR * pInfo)960 VKAPI_ATTR VkResult VKAPI_CALL test_vkAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR* pInfo) {
961     return VK_SUCCESS;
962 }
test_vkReleaseProfilingLockKHR(VkDevice device)963 VKAPI_ATTR void VKAPI_CALL test_vkReleaseProfilingLockKHR(VkDevice device) {}
964 // Entry-points associated with the VK_EXT_sample_locations extension
test_vkCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,const VkSampleLocationsInfoEXT * pSampleLocationsInfo)965 VKAPI_ATTR void VKAPI_CALL test_vkCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
966                                                            const VkSampleLocationsInfoEXT* pSampleLocationsInfo) {}
test_vkGetPhysicalDeviceMultisamplePropertiesEXT(VkPhysicalDevice physicalDevice,VkSampleCountFlagBits samples,VkMultisamplePropertiesEXT * pMultisampleProperties)967 VKAPI_ATTR void VKAPI_CALL test_vkGetPhysicalDeviceMultisamplePropertiesEXT(VkPhysicalDevice physicalDevice,
968                                                                             VkSampleCountFlagBits samples,
969                                                                             VkMultisamplePropertiesEXT* pMultisampleProperties) {}
970 // Entry-points associated with the VK_EXT_calibrated_timestamps extension
test_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(VkPhysicalDevice physicalDevice,uint32_t * pTimeDomainCount,VkTimeDomainEXT * pTimeDomains)971 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(VkPhysicalDevice physicalDevice,
972                                                                                    uint32_t* pTimeDomainCount,
973                                                                                    VkTimeDomainEXT* pTimeDomains) {
974     return VK_SUCCESS;
975 }
test_vkGetCalibratedTimestampsEXT(VkDevice device,uint32_t timestampCount,const VkCalibratedTimestampInfoEXT * pTimestampInfos,uint64_t * pTimestamps,uint64_t * pMaxDeviation)976 VKAPI_ATTR VkResult VKAPI_CALL test_vkGetCalibratedTimestampsEXT(VkDevice device, uint32_t timestampCount,
977                                                                  const VkCalibratedTimestampInfoEXT* pTimestampInfos,
978                                                                  uint64_t* pTimestamps, uint64_t* pMaxDeviation) {
979     return VK_SUCCESS;
980 }
981 
982 //// trampolines
983 
get_instance_func_ver_1_1(VkInstance instance,const char * pName)984 PFN_vkVoidFunction get_instance_func_ver_1_1(VkInstance instance, const char* pName) {
985     if (icd.icd_api_version >= VK_API_VERSION_1_1) {
986         if (string_eq(pName, "test_vkEnumerateInstanceVersion")) {
987             return to_vkVoidFunction(test_vkEnumerateInstanceVersion);
988         }
989         if (string_eq(pName, "vkEnumeratePhysicalDeviceGroups")) {
990             return to_vkVoidFunction(test_vkEnumeratePhysicalDeviceGroups);
991         }
992     }
993     return nullptr;
994 }
get_instance_func_ver_1_2(VkInstance instance,const char * pName)995 PFN_vkVoidFunction get_instance_func_ver_1_2(VkInstance instance, const char* pName) {
996     if (icd.icd_api_version >= VK_API_VERSION_1_2) {
997         return nullptr;
998     }
999     return nullptr;
1000 }
1001 
get_physical_device_func_wsi(VkInstance instance,const char * pName)1002 PFN_vkVoidFunction get_physical_device_func_wsi(VkInstance instance, const char* pName) {
1003     if (IsInstanceExtensionEnabled("VK_KHR_surface")) {
1004         if (string_eq(pName, "vkGetPhysicalDeviceSurfaceSupportKHR"))
1005             return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceSupportKHR);
1006         if (string_eq(pName, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR"))
1007             return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
1008         if (string_eq(pName, "vkGetPhysicalDeviceSurfaceFormatsKHR"))
1009             return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceFormatsKHR);
1010         if (string_eq(pName, "vkGetPhysicalDeviceSurfacePresentModesKHR"))
1011             return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfacePresentModesKHR);
1012     }
1013     if (IsInstanceExtensionEnabled("VK_KHR_get_surface_capabilities2")) {
1014         if (string_eq(pName, "vkGetPhysicalDeviceSurfaceCapabilities2KHR"))
1015             return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceCapabilities2KHR);
1016         if (string_eq(pName, "vkGetPhysicalDeviceSurfaceFormats2KHR"))
1017             return to_vkVoidFunction(test_vkGetPhysicalDeviceSurfaceFormats2KHR);
1018     }
1019     if (IsInstanceExtensionEnabled("VK_KHR_display")) {
1020         if (string_eq(pName, "vkGetPhysicalDeviceDisplayPropertiesKHR"))
1021             return to_vkVoidFunction(test_vkGetPhysicalDeviceDisplayPropertiesKHR);
1022         if (string_eq(pName, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR"))
1023             return to_vkVoidFunction(test_vkGetPhysicalDeviceDisplayPlanePropertiesKHR);
1024         if (string_eq(pName, "vkGetDisplayPlaneSupportedDisplaysKHR"))
1025             return to_vkVoidFunction(test_vkGetDisplayPlaneSupportedDisplaysKHR);
1026         if (string_eq(pName, "vkGetDisplayModePropertiesKHR")) return to_vkVoidFunction(test_vkGetDisplayModePropertiesKHR);
1027         if (string_eq(pName, "vkCreateDisplayModeKHR")) return to_vkVoidFunction(test_vkCreateDisplayModeKHR);
1028         if (string_eq(pName, "vkGetDisplayPlaneCapabilitiesKHR")) return to_vkVoidFunction(test_vkGetDisplayPlaneCapabilitiesKHR);
1029         if (string_eq(pName, "vkCreateDisplayPlaneSurfaceKHR")) return to_vkVoidFunction(test_vkCreateDisplayPlaneSurfaceKHR);
1030     }
1031     if (IsInstanceExtensionEnabled("VK_EXT_acquire_drm_display")) {
1032         if (string_eq(pName, "vkAcquireDrmDisplayEXT")) return to_vkVoidFunction(test_vkAcquireDrmDisplayEXT);
1033         if (string_eq(pName, "vkGetDrmDisplayEXT")) return to_vkVoidFunction(test_vkGetDrmDisplayEXT);
1034     }
1035     return nullptr;
1036 }
1037 
get_instance_func_wsi(VkInstance instance,const char * pName)1038 PFN_vkVoidFunction get_instance_func_wsi(VkInstance instance, const char* pName) {
1039     if (icd.min_icd_interface_version >= 3 && icd.enable_icd_wsi == true) {
1040 #ifdef VK_USE_PLATFORM_ANDROID_KHR
1041         if (string_eq(pName, "vkCreateAndroidSurfaceKHR")) {
1042             icd.is_using_icd_wsi = UsingICDProvidedWSI::is_using;
1043             return to_vkVoidFunction(test_vkCreateAndroidSurfaceKHR);
1044         }
1045 #endif
1046 #ifdef VK_USE_PLATFORM_METAL_EXT
1047         if (string_eq(pName, "vkCreateMetalSurfaceEXT")) {
1048             return to_vkVoidFunction(test_vkCreateMetalSurfaceEXT);
1049         }
1050 #endif
1051 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
1052         if (string_eq(pName, "vkCreateWaylandSurfaceKHR")) {
1053             return to_vkVoidFunction(test_vkCreateWaylandSurfaceKHR);
1054         }
1055         if (string_eq(pName, "vkGetPhysicalDeviceWaylandPresentationSupportKHR")) {
1056             return to_vkVoidFunction(test_vkGetPhysicalDeviceWaylandPresentationSupportKHR);
1057         }
1058 #endif
1059 #ifdef VK_USE_PLATFORM_XCB_KHR
1060         if (string_eq(pName, "vkCreateXcbSurfaceKHR")) {
1061             return to_vkVoidFunction(test_vkCreateXcbSurfaceKHR);
1062         }
1063         if (string_eq(pName, "vkGetPhysicalDeviceXcbPresentationSupportKHR")) {
1064             return to_vkVoidFunction(test_vkGetPhysicalDeviceXcbPresentationSupportKHR);
1065         }
1066 #endif
1067 #ifdef VK_USE_PLATFORM_XLIB_KHR
1068         if (string_eq(pName, "vkCreateXlibSurfaceKHR")) {
1069             return to_vkVoidFunction(test_vkCreateXlibSurfaceKHR);
1070         }
1071         if (string_eq(pName, "vkGetPhysicalDeviceXlibPresentationSupportKHR")) {
1072             return to_vkVoidFunction(test_vkGetPhysicalDeviceXlibPresentationSupportKHR);
1073         }
1074 #endif
1075 #ifdef VK_USE_PLATFORM_WIN32_KHR
1076         if (string_eq(pName, "vkCreateWin32SurfaceKHR")) {
1077             return to_vkVoidFunction(test_vkCreateWin32SurfaceKHR);
1078         }
1079         if (string_eq(pName, "vkGetPhysicalDeviceWin32PresentationSupportKHR")) {
1080             return to_vkVoidFunction(test_vkGetPhysicalDeviceWin32PresentationSupportKHR);
1081         }
1082 #endif
1083 #ifdef VK_USE_PLATFORM_DIRECTFB_EXT
1084         if (string_eq(pName, "vkCreateDirectFBSurfaceEXT")) {
1085             return to_vkVoidFunction(test_vkCreateDirectFBSurfaceEXT);
1086         }
1087         if (string_eq(pName, "vkGetPhysicalDeviceDirectFBPresentationSupportEXT")) {
1088             return to_vkVoidFunction(test_vkGetPhysicalDeviceDirectFBPresentationSupportEXT);
1089         }
1090 #endif  // VK_USE_PLATFORM_DIRECTFB_EXT
1091 
1092 #ifdef VK_USE_PLATFORM_MACOS_MVK
1093         if (string_eq(pName, "vkCreateMacOSSurfaceMVK")) {
1094             return to_vkVoidFunction(test_vkCreateMacOSSurfaceMVK);
1095         }
1096 #endif  // VK_USE_PLATFORM_MACOS_MVK
1097 
1098 #ifdef VK_USE_PLATFORM_IOS_MVK
1099         if (string_eq(pName, "vkCreateIOSSurfaceMVK")) {
1100             return to_vkVoidFunction(test_vkCreateIOSSurfaceMVK);
1101         }
1102 #endif  // VK_USE_PLATFORM_IOS_MVK
1103 
1104 #ifdef VK_USE_PLATFORM_GGP
1105         if (string_eq(pName, "vkCreateStreamDescriptorSurfaceGGP")) {
1106             return to_vkVoidFunction(test_vkCreateStreamDescriptorSurfaceGGP);
1107         }
1108 #endif  // VK_USE_PLATFORM_GGP
1109 
1110 #ifdef VK_USE_PLATFORM_SCREEN_QNX
1111         if (string_eq(pName, "vkCreateScreenSurfaceQNX")) {
1112             return to_vkVoidFunction(test_vkCreateScreenSurfaceQNX);
1113         }
1114         if (string_eq(pName, "vkGetPhysicalDeviceScreenPresentationSupportQNX")) {
1115             return to_vkVoidFunction(test_vkGetPhysicalDeviceScreenPresentationSupportQNX);
1116         }
1117 #endif  // VK_USE_PLATFORM_SCREEN_QNX
1118 
1119         if (string_eq(pName, "vkCreateHeadlessSurfaceEXT")) {
1120             return to_vkVoidFunction(test_vkCreateHeadlessSurfaceEXT);
1121         }
1122 
1123         if (string_eq(pName, "vkDestroySurfaceKHR")) {
1124             icd.is_using_icd_wsi = UsingICDProvidedWSI::is_using;
1125             return to_vkVoidFunction(test_vkDestroySurfaceKHR);
1126         }
1127     }
1128     if (IsInstanceExtensionEnabled(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) {
1129         if (string_eq(pName, "vkCreateDebugUtilsMessengerEXT")) {
1130             return to_vkVoidFunction(test_vkCreateDebugUtilsMessengerEXT);
1131         }
1132         if (string_eq(pName, "vkDestroyDebugUtilsMessengerEXT")) {
1133             return to_vkVoidFunction(test_vkDestroyDebugUtilsMessengerEXT);
1134         }
1135     }
1136 
1137     PFN_vkVoidFunction ret_phys_dev_wsi = get_physical_device_func_wsi(instance, pName);
1138     if (ret_phys_dev_wsi != nullptr) return ret_phys_dev_wsi;
1139     return nullptr;
1140 }
get_physical_device_func(VkInstance instance,const char * pName)1141 PFN_vkVoidFunction get_physical_device_func(VkInstance instance, const char* pName) {
1142     if (string_eq(pName, "vkEnumerateDeviceLayerProperties")) return to_vkVoidFunction(test_vkEnumerateDeviceLayerProperties);
1143     if (string_eq(pName, "vkEnumerateDeviceExtensionProperties"))
1144         return to_vkVoidFunction(test_vkEnumerateDeviceExtensionProperties);
1145     if (string_eq(pName, "vkGetPhysicalDeviceQueueFamilyProperties"))
1146         return to_vkVoidFunction(test_vkGetPhysicalDeviceQueueFamilyProperties);
1147     if (string_eq(pName, "vkCreateDevice")) return to_vkVoidFunction(test_vkCreateDevice);
1148 
1149     if (string_eq(pName, "vkGetPhysicalDeviceFeatures")) return to_vkVoidFunction(test_vkGetPhysicalDeviceFeatures);
1150     if (string_eq(pName, "vkGetPhysicalDeviceProperties")) return to_vkVoidFunction(test_vkGetPhysicalDeviceProperties);
1151     if (string_eq(pName, "vkGetPhysicalDeviceMemoryProperties")) return to_vkVoidFunction(test_vkGetPhysicalDeviceMemoryProperties);
1152     if (string_eq(pName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
1153         return to_vkVoidFunction(test_vkGetPhysicalDeviceSparseImageFormatProperties);
1154     if (string_eq(pName, "vkGetPhysicalDeviceFormatProperties")) return to_vkVoidFunction(test_vkGetPhysicalDeviceFormatProperties);
1155     if (string_eq(pName, "vkGetPhysicalDeviceImageFormatProperties"))
1156         return to_vkVoidFunction(test_vkGetPhysicalDeviceImageFormatProperties);
1157 
1158     if (IsInstanceExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
1159         if (string_eq(pName, "vkGetPhysicalDeviceFeatures2KHR")) return to_vkVoidFunction(test_vkGetPhysicalDeviceFeatures2);
1160         if (string_eq(pName, "vkGetPhysicalDeviceProperties2KHR")) return to_vkVoidFunction(test_vkGetPhysicalDeviceProperties2);
1161         if (string_eq(pName, "vkGetPhysicalDeviceFormatProperties2KHR"))
1162             return to_vkVoidFunction(test_vkGetPhysicalDeviceFormatProperties2);
1163         if (string_eq(pName, "vkGetPhysicalDeviceMemoryProperties2KHR"))
1164             return to_vkVoidFunction(test_vkGetPhysicalDeviceMemoryProperties2);
1165 
1166         if (string_eq(pName, "vkGetPhysicalDeviceQueueFamilyProperties2KHR"))
1167             return to_vkVoidFunction(test_vkGetPhysicalDeviceQueueFamilyProperties2);
1168 
1169         if (string_eq(pName, "vkGetPhysicalDeviceSparseImageFormatProperties2KHR"))
1170             return to_vkVoidFunction(test_vkGetPhysicalDeviceSparseImageFormatProperties2);
1171 
1172         if (string_eq(pName, "vkGetPhysicalDeviceImageFormatProperties2KHR")) {
1173             return to_vkVoidFunction(test_vkGetPhysicalDeviceImageFormatProperties2);
1174         }
1175     }
1176     if (IsInstanceExtensionEnabled(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME)) {
1177         if (string_eq(pName, "vkGetPhysicalDeviceExternalBufferPropertiesKHR"))
1178             return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalBufferProperties);
1179     }
1180     if (IsInstanceExtensionEnabled(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME)) {
1181         if (string_eq(pName, "vkGetPhysicalDeviceExternalSemaphorePropertiesKHR"))
1182             return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalSemaphoreProperties);
1183     }
1184     if (IsInstanceExtensionEnabled(VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME)) {
1185         if (string_eq(pName, "vkGetPhysicalDeviceExternalFencePropertiesKHR"))
1186             return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalFenceProperties);
1187     }
1188 
1189     // The following physical device extensions only need 1 device to support them for the ICD to export
1190     // them
1191     if (IsPhysicalDeviceExtensionAvailable(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME)) {
1192         if (string_eq(pName, "vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR"))
1193             return to_vkVoidFunction(test_vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR);
1194         if (string_eq(pName, "vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR"))
1195             return to_vkVoidFunction(test_vkGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR);
1196         if (string_eq(pName, "vkAcquireProfilingLockKHR")) return to_vkVoidFunction(test_vkAcquireProfilingLockKHR);
1197         if (string_eq(pName, "vkReleaseProfilingLockKHR")) return to_vkVoidFunction(test_vkReleaseProfilingLockKHR);
1198     }
1199     if (IsPhysicalDeviceExtensionAvailable(VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME)) {
1200         if (string_eq(pName, "vkCmdSetSampleLocationsEXT")) return to_vkVoidFunction(test_vkCmdSetSampleLocationsEXT);
1201         if (string_eq(pName, "vkGetPhysicalDeviceMultisamplePropertiesEXT"))
1202             return to_vkVoidFunction(test_vkGetPhysicalDeviceMultisamplePropertiesEXT);
1203     }
1204     if (IsPhysicalDeviceExtensionAvailable(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME)) {
1205         if (string_eq(pName, "vkGetPhysicalDeviceCalibrateableTimeDomainsEXT"))
1206             return to_vkVoidFunction(test_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT);
1207         if (string_eq(pName, "vkGetCalibratedTimestampsEXT")) return to_vkVoidFunction(test_vkGetCalibratedTimestampsEXT);
1208     }
1209 
1210     if (icd.icd_api_version >= VK_MAKE_API_VERSION(0, 1, 1, 0)) {
1211         if (string_eq(pName, "vkGetPhysicalDeviceFeatures2")) return to_vkVoidFunction(test_vkGetPhysicalDeviceFeatures2);
1212         if (string_eq(pName, "vkGetPhysicalDeviceProperties2")) return to_vkVoidFunction(test_vkGetPhysicalDeviceProperties2);
1213         if (string_eq(pName, "vkGetPhysicalDeviceFormatProperties2"))
1214             return to_vkVoidFunction(test_vkGetPhysicalDeviceFormatProperties2);
1215         if (string_eq(pName, "vkGetPhysicalDeviceMemoryProperties2"))
1216             return to_vkVoidFunction(test_vkGetPhysicalDeviceMemoryProperties2);
1217 
1218         if (string_eq(pName, "vkGetPhysicalDeviceQueueFamilyProperties2"))
1219             return to_vkVoidFunction(test_vkGetPhysicalDeviceQueueFamilyProperties2);
1220 
1221         if (string_eq(pName, "vkGetPhysicalDeviceSparseImageFormatProperties2"))
1222             return to_vkVoidFunction(test_vkGetPhysicalDeviceSparseImageFormatProperties2);
1223 
1224         if (string_eq(pName, "vkGetPhysicalDeviceImageFormatProperties2")) {
1225             return to_vkVoidFunction(test_vkGetPhysicalDeviceImageFormatProperties2);
1226         }
1227 
1228         if (string_eq(pName, "vkGetPhysicalDeviceExternalBufferProperties"))
1229             return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalBufferProperties);
1230         if (string_eq(pName, "vkGetPhysicalDeviceExternalSemaphoreProperties"))
1231             return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalSemaphoreProperties);
1232         if (string_eq(pName, "vkGetPhysicalDeviceExternalFenceProperties"))
1233             return to_vkVoidFunction(test_vkGetPhysicalDeviceExternalFenceProperties);
1234     }
1235 
1236     if (icd.supports_tooling_info_core) {
1237         if (string_eq(pName, "vkGetPhysicalDeviceToolProperties")) return to_vkVoidFunction(test_vkGetPhysicalDeviceToolProperties);
1238     }
1239     if (icd.supports_tooling_info_ext) {
1240         if (string_eq(pName, "vkGetPhysicalDeviceToolPropertiesEXT"))
1241             return to_vkVoidFunction(test_vkGetPhysicalDeviceToolPropertiesEXT);
1242     }
1243 
1244     for (auto& phys_dev : icd.physical_devices) {
1245         for (auto& func : phys_dev.custom_physical_device_functions) {
1246             if (func.name == pName) {
1247                 return to_vkVoidFunction(func.function);
1248             }
1249         }
1250     }
1251     return nullptr;
1252 }
1253 
get_instance_func(VkInstance instance,const char * pName)1254 PFN_vkVoidFunction get_instance_func(VkInstance instance, const char* pName) {
1255     if (string_eq(pName, "vkEnumerateInstanceExtensionProperties"))
1256         return to_vkVoidFunction(test_vkEnumerateInstanceExtensionProperties);
1257     if (string_eq(pName, "vkEnumerateInstanceLayerProperties")) return to_vkVoidFunction(test_vkEnumerateInstanceLayerProperties);
1258     if (string_eq(pName, "vkCreateInstance")) return to_vkVoidFunction(test_vkCreateInstance);
1259     if (string_eq(pName, "vkDestroyInstance")) return to_vkVoidFunction(test_vkDestroyInstance);
1260     if (string_eq(pName, "vkEnumeratePhysicalDevices")) return to_vkVoidFunction(test_vkEnumeratePhysicalDevices);
1261 
1262     if (IsInstanceExtensionEnabled(VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME)) {
1263         if (string_eq(pName, "vkEnumeratePhysicalDeviceGroupsKHR")) return to_vkVoidFunction(test_vkEnumeratePhysicalDeviceGroups);
1264     }
1265 
1266     PFN_vkVoidFunction ret_phys_dev = get_physical_device_func(instance, pName);
1267     if (ret_phys_dev != nullptr) return ret_phys_dev;
1268 
1269     PFN_vkVoidFunction ret_1_1 = get_instance_func_ver_1_1(instance, pName);
1270     if (ret_1_1 != nullptr) return ret_1_1;
1271 
1272     PFN_vkVoidFunction ret_1_2 = get_instance_func_ver_1_2(instance, pName);
1273     if (ret_1_2 != nullptr) return ret_1_2;
1274 
1275     PFN_vkVoidFunction ret_wsi = get_instance_func_wsi(instance, pName);
1276     if (ret_wsi != nullptr) return ret_wsi;
1277 
1278     for (auto& func : icd.custom_instance_functions) {
1279         if (func.name == pName) {
1280             return to_vkVoidFunction(func.function);
1281         }
1282     }
1283 
1284     return nullptr;
1285 }
1286 
get_device_func(VkDevice device,const char * pName)1287 PFN_vkVoidFunction get_device_func(VkDevice device, const char* pName) {
1288     if (device != nullptr) {
1289         if (!std::any_of(icd.physical_devices.begin(), icd.physical_devices.end(), [&](const PhysicalDevice& pd) {
1290                 return std::any_of(pd.device_handles.begin(), pd.device_handles.end(),
1291                                    [&](const VkDevice& pd_device) { return pd_device == device; });
1292             })) {
1293             return nullptr;
1294         }
1295     }
1296     if (string_eq(pName, "vkDestroyDevice")) return to_vkVoidFunction(test_vkDestroyDevice);
1297     if (string_eq(pName, "vkCreateSwapchainKHR")) return to_vkVoidFunction(test_vkCreateSwapchainKHR);
1298     if (string_eq(pName, "vkDestroySwapchainKHR")) return to_vkVoidFunction(test_vkDestroySwapchainKHR);
1299     if (string_eq(pName, "vkCreateCommandPool")) return to_vkVoidFunction(test_vkCreateCommandPool);
1300     if (string_eq(pName, "vkAllocateCommandBuffers")) return to_vkVoidFunction(test_vkAllocateCommandBuffers);
1301     if (string_eq(pName, "vkDestroyCommandPool")) return to_vkVoidFunction(test_vkDestroyCommandPool);
1302     if (string_eq(pName, "vkGetDeviceQueue")) return to_vkVoidFunction(test_vkGetDeviceQueue);
1303     // look for device functions setup from a test
1304     for (const auto& phys_dev : icd.physical_devices) {
1305         for (const auto& function : phys_dev.known_device_functions) {
1306             if (function.name == pName) {
1307                 return to_vkVoidFunction(function.function);
1308             }
1309         }
1310     }
1311     return nullptr;
1312 }
1313 
test_vkGetInstanceProcAddr(VkInstance instance,const char * pName)1314 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL test_vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
1315     return get_instance_func(instance, pName);
1316 }
1317 
test_vkGetDeviceProcAddr(VkDevice device,const char * pName)1318 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL test_vkGetDeviceProcAddr(VkDevice device, const char* pName) {
1319     return get_device_func(device, pName);
1320 }
1321 
base_get_instance_proc_addr(VkInstance instance,const char * pName)1322 PFN_vkVoidFunction base_get_instance_proc_addr(VkInstance instance, const char* pName) {
1323     if (pName == nullptr) return nullptr;
1324     if (instance == NULL) {
1325         if (string_eq(pName, "vkGetInstanceProcAddr")) return to_vkVoidFunction(test_vkGetInstanceProcAddr);
1326         if (string_eq(pName, "vkEnumerateInstanceExtensionProperties"))
1327             return to_vkVoidFunction(test_vkEnumerateInstanceExtensionProperties);
1328         if (string_eq(pName, "vkEnumerateInstanceLayerProperties"))
1329             return to_vkVoidFunction(test_vkEnumerateInstanceLayerProperties);
1330         if (string_eq(pName, "vkEnumerateInstanceVersion")) return to_vkVoidFunction(test_vkEnumerateInstanceVersion);
1331     }
1332     if (string_eq(pName, "vkGetDeviceProcAddr")) return to_vkVoidFunction(test_vkGetDeviceProcAddr);
1333 
1334     auto instance_func_return = get_instance_func(instance, pName);
1335     if (instance_func_return != nullptr) return instance_func_return;
1336 
1337     // Need to return function pointers for device extensions
1338     auto device_func_return = get_device_func(nullptr, pName);
1339     if (device_func_return != nullptr) return device_func_return;
1340     return nullptr;
1341 }
1342 
1343 // Exported functions
1344 extern "C" {
1345 #if TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION
vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t * pSupportedVersion)1346 extern FRAMEWORK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) {
1347     if (icd.called_vk_icd_gipa == CalledICDGIPA::not_called &&
1348         icd.called_negotiate_interface == CalledNegotiateInterface::not_called)
1349         icd.called_negotiate_interface = CalledNegotiateInterface::vk_icd_negotiate;
1350     else if (icd.called_vk_icd_gipa != CalledICDGIPA::not_called)
1351         icd.called_negotiate_interface = CalledNegotiateInterface::vk_icd_gipa_first;
1352 
1353     // loader puts the minimum it supports in pSupportedVersion, if that is lower than our minimum
1354     // If the ICD doesn't supports the interface version provided by the loader, report VK_ERROR_INCOMPATIBLE_DRIVER
1355     if (icd.min_icd_interface_version > *pSupportedVersion) {
1356         icd.interface_version_check = InterfaceVersionCheck::loader_version_too_old;
1357         *pSupportedVersion = icd.min_icd_interface_version;
1358         return VK_ERROR_INCOMPATIBLE_DRIVER;
1359     }
1360 
1361     // the loader-provided interface version is newer than that supported by the ICD
1362     if (icd.max_icd_interface_version < *pSupportedVersion) {
1363         icd.interface_version_check = InterfaceVersionCheck::loader_version_too_new;
1364         *pSupportedVersion = icd.max_icd_interface_version;
1365     }
1366     // ICD interface version is greater than the loader's,  return the loader's version
1367     else if (icd.max_icd_interface_version > *pSupportedVersion) {
1368         icd.interface_version_check = InterfaceVersionCheck::icd_version_too_new;
1369         // don't change *pSupportedVersion
1370     } else {
1371         icd.interface_version_check = InterfaceVersionCheck::version_is_supported;
1372         *pSupportedVersion = icd.max_icd_interface_version;
1373     }
1374 
1375     return VK_SUCCESS;
1376 }
1377 #endif  // TEST_ICD_EXPORT_NEGOTIATE_INTERFACE_VERSION
1378 
1379 #if TEST_ICD_EXPORT_ICD_GPDPA
vk_icdGetPhysicalDeviceProcAddr(VkInstance instance,const char * pName)1380 FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance instance, const char* pName) {
1381     return get_physical_device_func(instance, pName);
1382 }
1383 #endif  // TEST_ICD_EXPORT_ICD_GPDPA
1384 
1385 #if TEST_ICD_EXPORT_ICD_GIPA
vk_icdGetInstanceProcAddr(VkInstance instance,const char * pName)1386 FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName) {
1387     // std::cout << "icdGetInstanceProcAddr: " << pName << "\n";
1388 
1389     if (icd.called_vk_icd_gipa == CalledICDGIPA::not_called) icd.called_vk_icd_gipa = CalledICDGIPA::vk_icd_gipa;
1390 
1391     return base_get_instance_proc_addr(instance, pName);
1392 }
1393 #else   // !TEST_ICD_EXPORT_ICD_GIPA
vkGetInstanceProcAddr(VkInstance instance,const char * pName)1394 FRAMEWORK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
1395     // std::cout << "icdGetInstanceProcAddr: " << pName << "\n";
1396 
1397     if (icd.called_vk_icd_gipa == CalledICDGIPA::not_called) icd.called_vk_icd_gipa = CalledICDGIPA::vk_gipa;
1398     return base_get_instance_proc_addr(instance, pName);
1399 }
vkCreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance)1400 FRAMEWORK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo,
1401                                                                  const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) {
1402     return test_vkCreateInstance(pCreateInfo, pAllocator, pInstance);
1403 }
vkEnumerateInstanceExtensionProperties(const char * pLayerName,uint32_t * pPropertyCount,VkExtensionProperties * pProperties)1404 FRAMEWORK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char* pLayerName,
1405                                                                                        uint32_t* pPropertyCount,
1406                                                                                        VkExtensionProperties* pProperties) {
1407     return test_vkEnumerateInstanceExtensionProperties(pLayerName, pPropertyCount, pProperties);
1408 }
1409 #endif  // TEST_ICD_EXPORT_ICD_GIPA
1410 
1411 #if TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES
1412 #if defined(WIN32)
vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance,LUID adapterLUID,uint32_t * pPhysicalDeviceCount,VkPhysicalDevice * pPhysicalDevices)1413 FRAMEWORK_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance, LUID adapterLUID,
1414                                                                                       uint32_t* pPhysicalDeviceCount,
1415                                                                                       VkPhysicalDevice* pPhysicalDevices) {
1416     if (adapterLUID.LowPart != icd.adapterLUID.LowPart || adapterLUID.HighPart != icd.adapterLUID.HighPart) {
1417         *pPhysicalDeviceCount = 0;
1418         return VK_SUCCESS;
1419     }
1420     icd.called_enumerate_adapter_physical_devices = true;
1421     VkResult res = test_vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
1422     // For this testing, flip order intentionally
1423     if (nullptr != pPhysicalDevices) {
1424         std::reverse(pPhysicalDevices, pPhysicalDevices + *pPhysicalDeviceCount);
1425     }
1426     return res;
1427 }
1428 #endif  // defined(WIN32)
1429 #endif  // TEST_ICD_EXPORT_ICD_ENUMERATE_ADAPTER_PHYSICAL_DEVICES
1430 
1431 }  // extern "C"
1432