@@ -425,30 +425,51 @@ VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDevi
425425 }
426426
427427 // Initialize the device dispatch table
428- vulkan_device device = { *pDevice, get_device_proc_addr, instance.handle , get_instance_proc_addr, instance.dispatch_table };
428+ vulkan_device device = { *pDevice, instance.handle , instance.dispatch_table };
429+ device.dispatch_table .GetDeviceProcAddr = get_device_proc_addr;
430+ device.dispatch_table .GetInstanceProcAddr = get_instance_proc_addr;
429431
430432 gladLoadVulkanContextUserPtr (&device.dispatch_table , physicalDevice,
431433 [](void *user, const char *name) -> GLADapiproc {
432434 const auto &device = *static_cast <const vulkan_device *>(user);
433- // Need to distinguish between instance and device functions somehow
434- if ((strcmp (name, " vkGetDeviceProcAddr" ) != 0 ) &&
435- (strcmp (name, " vkGetInstanceProcAddr" ) != 0 ) &&
436- (strcmp (name, " vkCreateDevice" ) != 0 ) &&
437- (strcmp (name, " vkCreateInstance" ) != 0 ) &&
438- (strcmp (name, " vkDestroyInstance" ) != 0 ) &&
439- (strcmp (name, " vkCreateDebugUtilsMessengerEXT" ) != 0 ) &&
440- (strcmp (name, " vkDestroyDebugUtilsMessengerEXT" ) != 0 ) &&
441- (strcmp (name, " vkSubmitDebugUtilsMessageEXT" ) != 0 ) &&
442- (strstr (name, " Properties" ) == nullptr || strstr (name, " AccelerationStructures" ) != nullptr || strstr (name, " Handle" ) != nullptr ) &&
443- (strstr (name, " Surface" ) == nullptr || strstr (name, " DeviceGroupSurface" ) != nullptr ) &&
444- (strstr (name, " PhysicalDevice" ) == nullptr ))
445- return reinterpret_cast <GLADapiproc>(device.get_proc_addr (device.handle , name));
446- else
447- return reinterpret_cast <GLADapiproc>(device.get_instance_proc_addr (device.instance_handle , name));
448- }, &device);
449435
450- device.dispatch_table .GetDeviceProcAddr = get_device_proc_addr;
451- device.dispatch_table .GetInstanceProcAddr = get_instance_proc_addr;
436+ // Do not load existing instance function pointers anew
437+ if (0 == std::strcmp (name, " vkGetDeviceProcAddr" ))
438+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .GetDeviceProcAddr );
439+ if (0 == std::strcmp (name, " vkGetInstanceProcAddr" ))
440+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .GetInstanceProcAddr );
441+
442+ if (0 == std::strcmp (name, " vkEnumerateInstanceVersion" ))
443+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .EnumerateInstanceVersion );
444+
445+ if (0 == std::strcmp (name, " vkEnumerateDeviceLayerProperties" ))
446+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .EnumerateDeviceLayerProperties );
447+ if (0 == std::strcmp (name, " vkEnumerateInstanceLayerProperties" ))
448+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .EnumerateInstanceLayerProperties );
449+ if (0 == std::strcmp (name, " vkEnumerateDeviceExtensionProperties" ))
450+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .EnumerateDeviceExtensionProperties );
451+ if (0 == std::strcmp (name, " vkEnumerateInstanceExtensionProperties" ))
452+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .EnumerateInstanceExtensionProperties );
453+
454+ if (0 == std::strcmp (name, " vkEnumeratePhysicalDevices" ))
455+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .EnumeratePhysicalDevices );
456+ if (0 == std::strcmp (name, " vkEnumeratePhysicalDeviceGroups" ))
457+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .EnumeratePhysicalDeviceGroups );
458+
459+ if (0 == std::strcmp (name, " vkCreateDevice" ) ||
460+ 0 == std::strcmp (name, " vkCreateInstance" ) ||
461+ 0 == std::strcmp (name, " vkDestroyInstance" ) ||
462+ 0 == std::strcmp (name, " vkSubmitDebugUtilsMessageEXT" ) ||
463+ 0 == std::strcmp (name, " vkCreateDebugUtilsMessengerEXT" ) ||
464+ 0 == std::strcmp (name, " vkDestroyDebugUtilsMessengerEXT" ) ||
465+ (std::strstr (name, " Properties" ) != nullptr && std::strstr (name, " AccelerationStructures" ) == nullptr && std::strstr (name, " Handle" ) == nullptr ) ||
466+ (std::strstr (name, " Surface" ) != nullptr && std::strstr (name, " DeviceGroupSurface" ) == nullptr ) ||
467+ (std::strstr (name, " PhysicalDevice" ) != nullptr ))
468+ return reinterpret_cast <GLADapiproc>(device.dispatch_table .GetInstanceProcAddr (device.instance_handle , name));
469+
470+ const PFN_vkVoidFunction device_proc_address = device.dispatch_table .GetDeviceProcAddr (device.handle , name);
471+ return reinterpret_cast <GLADapiproc>(device_proc_address);
472+ }, &device);
452473
453474 device.dispatch_table .KHR_push_descriptor &= push_descriptor_ext ? 1 : 0 ;
454475 device.dispatch_table .KHR_dynamic_rendering &= dynamic_rendering_ext ? 1 : 0 ;
0 commit comments