Cleanup loader_icd_init_entries
authorCharles Giessen <charles@lunarg.com>
Sun, 12 Nov 2023 08:37:50 +0000 (01:37 -0700)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Mon, 13 Nov 2023 21:26:36 +0000 (14:26 -0700)
The logic of the function indicates that at a previous time, the
functions being loaded used dlsym/GetProcAddress to query functions.
Whenever that was changed to vkGetInstanceProcAddr, the error logging
wasn't updated to remove loader_platform_get_proc_address_error.
Trying to call dlerror() when no error has occured will return NULL,
which was dutifully passed onto loader_log, causing crashes.

The cleanup removes usage of that, as well as making the loading
logic uses 2 macros, one for required & one for non-required
function pointers.

Cleanup also meant streamlining the parameter list of
loader_icd_init_entries, since VkInstance and GetInstanceProcAddr
are both able to be gotten from the icd_term. And also meant cleaning
up the inst parameter being passed into loader_log, which was turning
the drivers VkInstance into loader_instance* erroneously.

A test was added to ensure that the error path when drivers do not
support the required functions correctly returns an error from
vkCreateInstance instead of crashing.

loader/generated/vk_loader_extensions.c
loader/generated/vk_loader_extensions.h
loader/loader.c
loader/log.c
scripts/loader_extension_generator.py
tests/framework/icd/test_icd.cpp
tests/framework/icd/test_icd.h
tests/loader_get_proc_addr_tests.cpp

index 16677bdacb01d92c0f4da885c43ff5a23cd526db..43275d075e09d06204ddb08c1fd5f69c62cf1a09 100644 (file)
@@ -46,267 +46,270 @@ VKAPI_ATTR VkResult VKAPI_CALL vkDevExtError(VkDevice dev) {
     return VK_ERROR_EXTENSION_NOT_PRESENT;
 }
 
-VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_icd_term *icd_term, VkInstance inst,
-                                                   const PFN_vkGetInstanceProcAddr fp_gipa) {
-
-#define LOOKUP_GIPA(func, required)                                                        \
-    do {                                                                                   \
-        icd_term->dispatch.func = (PFN_vk##func)fp_gipa(inst, "vk" #func);                 \
-        if (!icd_term->dispatch.func && required) {                                        \
-            loader_log((struct loader_instance *)inst, VULKAN_LOADER_WARN_BIT, 0, \
-                       loader_platform_get_proc_address_error("vk" #func));                \
-            return false;                                                                  \
-        }                                                                                  \
+VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_instance* inst, struct loader_icd_term *icd_term) {
+    const PFN_vkGetInstanceProcAddr fp_gipa = icd_term->scanned_icd->GetInstanceProcAddr;
+
+#define LOOKUP_GIPA(func) icd_term->dispatch.func = (PFN_vk##func)fp_gipa(icd_term->instance, "vk" #func);
+
+#define LOOKUP_REQUIRED_GIPA(func)                                                      \
+    do {                                                                                \
+        LOOKUP_GIPA(func);                                                              \
+        if (!icd_term->dispatch.func) {                                                 \
+            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0, "Unable to load %s from ICD %s",\
+                       "vk"#func, icd_term->scanned_icd->lib_name);                     \
+            return false;                                                               \
+        }                                                                               \
     } while (0)
 
 
     // ---- Core 1_0
-    LOOKUP_GIPA(DestroyInstance, true);
-    LOOKUP_GIPA(EnumeratePhysicalDevices, true);
-    LOOKUP_GIPA(GetPhysicalDeviceFeatures, true);
-    LOOKUP_GIPA(GetPhysicalDeviceFormatProperties, true);
-    LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties, true);
-    LOOKUP_GIPA(GetPhysicalDeviceProperties, true);
-    LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties, true);
-    LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties, true);
-    LOOKUP_GIPA(GetDeviceProcAddr, true);
-    LOOKUP_GIPA(CreateDevice, true);
-    LOOKUP_GIPA(EnumerateDeviceExtensionProperties, true);
-    LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties, true);
+    LOOKUP_REQUIRED_GIPA(DestroyInstance);
+    LOOKUP_REQUIRED_GIPA(EnumeratePhysicalDevices);
+    LOOKUP_REQUIRED_GIPA(GetPhysicalDeviceFeatures);
+    LOOKUP_REQUIRED_GIPA(GetPhysicalDeviceFormatProperties);
+    LOOKUP_REQUIRED_GIPA(GetPhysicalDeviceImageFormatProperties);
+    LOOKUP_REQUIRED_GIPA(GetPhysicalDeviceProperties);
+    LOOKUP_REQUIRED_GIPA(GetPhysicalDeviceQueueFamilyProperties);
+    LOOKUP_REQUIRED_GIPA(GetPhysicalDeviceMemoryProperties);
+    LOOKUP_REQUIRED_GIPA(GetDeviceProcAddr);
+    LOOKUP_REQUIRED_GIPA(CreateDevice);
+    LOOKUP_REQUIRED_GIPA(EnumerateDeviceExtensionProperties);
+    LOOKUP_REQUIRED_GIPA(GetPhysicalDeviceSparseImageFormatProperties);
 
     // ---- Core 1_1
-    LOOKUP_GIPA(EnumeratePhysicalDeviceGroups, false);
-    LOOKUP_GIPA(GetPhysicalDeviceFeatures2, false);
-    LOOKUP_GIPA(GetPhysicalDeviceProperties2, false);
-    LOOKUP_GIPA(GetPhysicalDeviceFormatProperties2, false);
-    LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties2, false);
-    LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties2, false);
-    LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties2, false);
-    LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties2, false);
-    LOOKUP_GIPA(GetPhysicalDeviceExternalBufferProperties, false);
-    LOOKUP_GIPA(GetPhysicalDeviceExternalFenceProperties, false);
-    LOOKUP_GIPA(GetPhysicalDeviceExternalSemaphoreProperties, false);
+    LOOKUP_GIPA(EnumeratePhysicalDeviceGroups);
+    LOOKUP_GIPA(GetPhysicalDeviceFeatures2);
+    LOOKUP_GIPA(GetPhysicalDeviceProperties2);
+    LOOKUP_GIPA(GetPhysicalDeviceFormatProperties2);
+    LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties2);
+    LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties2);
+    LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties2);
+    LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties2);
+    LOOKUP_GIPA(GetPhysicalDeviceExternalBufferProperties);
+    LOOKUP_GIPA(GetPhysicalDeviceExternalFenceProperties);
+    LOOKUP_GIPA(GetPhysicalDeviceExternalSemaphoreProperties);
 
     // ---- Core 1_3
-    LOOKUP_GIPA(GetPhysicalDeviceToolProperties, false);
+    LOOKUP_GIPA(GetPhysicalDeviceToolProperties);
 
     // ---- VK_KHR_surface extension commands
-    LOOKUP_GIPA(DestroySurfaceKHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceSurfaceSupportKHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilitiesKHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceSurfaceFormatsKHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceSurfacePresentModesKHR, false);
+    LOOKUP_GIPA(DestroySurfaceKHR);
+    LOOKUP_GIPA(GetPhysicalDeviceSurfaceSupportKHR);
+    LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilitiesKHR);
+    LOOKUP_GIPA(GetPhysicalDeviceSurfaceFormatsKHR);
+    LOOKUP_GIPA(GetPhysicalDeviceSurfacePresentModesKHR);
 
     // ---- VK_KHR_swapchain extension commands
-    LOOKUP_GIPA(GetPhysicalDevicePresentRectanglesKHR, false);
+    LOOKUP_GIPA(GetPhysicalDevicePresentRectanglesKHR);
 
     // ---- VK_KHR_display extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceDisplayPropertiesKHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceDisplayPlanePropertiesKHR, false);
-    LOOKUP_GIPA(GetDisplayPlaneSupportedDisplaysKHR, false);
-    LOOKUP_GIPA(GetDisplayModePropertiesKHR, false);
-    LOOKUP_GIPA(CreateDisplayModeKHR, false);
-    LOOKUP_GIPA(GetDisplayPlaneCapabilitiesKHR, false);
-    LOOKUP_GIPA(CreateDisplayPlaneSurfaceKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceDisplayPropertiesKHR);
+    LOOKUP_GIPA(GetPhysicalDeviceDisplayPlanePropertiesKHR);
+    LOOKUP_GIPA(GetDisplayPlaneSupportedDisplaysKHR);
+    LOOKUP_GIPA(GetDisplayModePropertiesKHR);
+    LOOKUP_GIPA(CreateDisplayModeKHR);
+    LOOKUP_GIPA(GetDisplayPlaneCapabilitiesKHR);
+    LOOKUP_GIPA(CreateDisplayPlaneSurfaceKHR);
 
     // ---- VK_KHR_xlib_surface extension commands
 #if defined(VK_USE_PLATFORM_XLIB_KHR)
-    LOOKUP_GIPA(CreateXlibSurfaceKHR, false);
+    LOOKUP_GIPA(CreateXlibSurfaceKHR);
 #endif // VK_USE_PLATFORM_XLIB_KHR
 #if defined(VK_USE_PLATFORM_XLIB_KHR)
-    LOOKUP_GIPA(GetPhysicalDeviceXlibPresentationSupportKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceXlibPresentationSupportKHR);
 #endif // VK_USE_PLATFORM_XLIB_KHR
 
     // ---- VK_KHR_xcb_surface extension commands
 #if defined(VK_USE_PLATFORM_XCB_KHR)
-    LOOKUP_GIPA(CreateXcbSurfaceKHR, false);
+    LOOKUP_GIPA(CreateXcbSurfaceKHR);
 #endif // VK_USE_PLATFORM_XCB_KHR
 #if defined(VK_USE_PLATFORM_XCB_KHR)
-    LOOKUP_GIPA(GetPhysicalDeviceXcbPresentationSupportKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceXcbPresentationSupportKHR);
 #endif // VK_USE_PLATFORM_XCB_KHR
 
     // ---- VK_KHR_wayland_surface extension commands
 #if defined(VK_USE_PLATFORM_WAYLAND_KHR)
-    LOOKUP_GIPA(CreateWaylandSurfaceKHR, false);
+    LOOKUP_GIPA(CreateWaylandSurfaceKHR);
 #endif // VK_USE_PLATFORM_WAYLAND_KHR
 #if defined(VK_USE_PLATFORM_WAYLAND_KHR)
-    LOOKUP_GIPA(GetPhysicalDeviceWaylandPresentationSupportKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceWaylandPresentationSupportKHR);
 #endif // VK_USE_PLATFORM_WAYLAND_KHR
 
     // ---- VK_KHR_android_surface extension commands
 #if defined(VK_USE_PLATFORM_ANDROID_KHR)
-    LOOKUP_GIPA(CreateAndroidSurfaceKHR, false);
+    LOOKUP_GIPA(CreateAndroidSurfaceKHR);
 #endif // VK_USE_PLATFORM_ANDROID_KHR
 
     // ---- VK_KHR_win32_surface extension commands
 #if defined(VK_USE_PLATFORM_WIN32_KHR)
-    LOOKUP_GIPA(CreateWin32SurfaceKHR, false);
+    LOOKUP_GIPA(CreateWin32SurfaceKHR);
 #endif // VK_USE_PLATFORM_WIN32_KHR
 #if defined(VK_USE_PLATFORM_WIN32_KHR)
-    LOOKUP_GIPA(GetPhysicalDeviceWin32PresentationSupportKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceWin32PresentationSupportKHR);
 #endif // VK_USE_PLATFORM_WIN32_KHR
 
     // ---- VK_KHR_video_queue extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceVideoCapabilitiesKHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceVideoFormatPropertiesKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceVideoCapabilitiesKHR);
+    LOOKUP_GIPA(GetPhysicalDeviceVideoFormatPropertiesKHR);
 
     // ---- VK_KHR_get_physical_device_properties2 extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceFeatures2KHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceProperties2KHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceFormatProperties2KHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties2KHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties2KHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties2KHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties2KHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceFeatures2KHR);
+    LOOKUP_GIPA(GetPhysicalDeviceProperties2KHR);
+    LOOKUP_GIPA(GetPhysicalDeviceFormatProperties2KHR);
+    LOOKUP_GIPA(GetPhysicalDeviceImageFormatProperties2KHR);
+    LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyProperties2KHR);
+    LOOKUP_GIPA(GetPhysicalDeviceMemoryProperties2KHR);
+    LOOKUP_GIPA(GetPhysicalDeviceSparseImageFormatProperties2KHR);
 
     // ---- VK_KHR_device_group_creation extension commands
-    LOOKUP_GIPA(EnumeratePhysicalDeviceGroupsKHR, false);
+    LOOKUP_GIPA(EnumeratePhysicalDeviceGroupsKHR);
 
     // ---- VK_KHR_external_memory_capabilities extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceExternalBufferPropertiesKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceExternalBufferPropertiesKHR);
 
     // ---- VK_KHR_external_semaphore_capabilities extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceExternalSemaphorePropertiesKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceExternalSemaphorePropertiesKHR);
 
     // ---- VK_KHR_external_fence_capabilities extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceExternalFencePropertiesKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceExternalFencePropertiesKHR);
 
     // ---- VK_KHR_performance_query extension commands
-    LOOKUP_GIPA(EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR, false);
+    LOOKUP_GIPA(EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR);
+    LOOKUP_GIPA(GetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR);
 
     // ---- VK_KHR_get_surface_capabilities2 extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilities2KHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceSurfaceFormats2KHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilities2KHR);
+    LOOKUP_GIPA(GetPhysicalDeviceSurfaceFormats2KHR);
 
     // ---- VK_KHR_get_display_properties2 extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceDisplayProperties2KHR, false);
-    LOOKUP_GIPA(GetPhysicalDeviceDisplayPlaneProperties2KHR, false);
-    LOOKUP_GIPA(GetDisplayModeProperties2KHR, false);
-    LOOKUP_GIPA(GetDisplayPlaneCapabilities2KHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceDisplayProperties2KHR);
+    LOOKUP_GIPA(GetPhysicalDeviceDisplayPlaneProperties2KHR);
+    LOOKUP_GIPA(GetDisplayModeProperties2KHR);
+    LOOKUP_GIPA(GetDisplayPlaneCapabilities2KHR);
 
     // ---- VK_KHR_fragment_shading_rate extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceFragmentShadingRatesKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceFragmentShadingRatesKHR);
 
     // ---- VK_KHR_video_encode_queue extension commands
 #if defined(VK_ENABLE_BETA_EXTENSIONS)
-    LOOKUP_GIPA(GetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR);
 #endif // VK_ENABLE_BETA_EXTENSIONS
 
     // ---- VK_KHR_cooperative_matrix extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceCooperativeMatrixPropertiesKHR, false);
+    LOOKUP_GIPA(GetPhysicalDeviceCooperativeMatrixPropertiesKHR);
 
     // ---- VK_EXT_debug_report extension commands
-    LOOKUP_GIPA(CreateDebugReportCallbackEXT, false);
-    LOOKUP_GIPA(DestroyDebugReportCallbackEXT, false);
-    LOOKUP_GIPA(DebugReportMessageEXT, false);
+    LOOKUP_GIPA(CreateDebugReportCallbackEXT);
+    LOOKUP_GIPA(DestroyDebugReportCallbackEXT);
+    LOOKUP_GIPA(DebugReportMessageEXT);
 
     // ---- VK_GGP_stream_descriptor_surface extension commands
 #if defined(VK_USE_PLATFORM_GGP)
-    LOOKUP_GIPA(CreateStreamDescriptorSurfaceGGP, false);
+    LOOKUP_GIPA(CreateStreamDescriptorSurfaceGGP);
 #endif // VK_USE_PLATFORM_GGP
 
     // ---- VK_NV_external_memory_capabilities extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceExternalImageFormatPropertiesNV, false);
+    LOOKUP_GIPA(GetPhysicalDeviceExternalImageFormatPropertiesNV);
 
     // ---- VK_NN_vi_surface extension commands
 #if defined(VK_USE_PLATFORM_VI_NN)
-    LOOKUP_GIPA(CreateViSurfaceNN, false);
+    LOOKUP_GIPA(CreateViSurfaceNN);
 #endif // VK_USE_PLATFORM_VI_NN
 
     // ---- VK_EXT_direct_mode_display extension commands
-    LOOKUP_GIPA(ReleaseDisplayEXT, false);
+    LOOKUP_GIPA(ReleaseDisplayEXT);
 
     // ---- VK_EXT_acquire_xlib_display extension commands
 #if defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
-    LOOKUP_GIPA(AcquireXlibDisplayEXT, false);
+    LOOKUP_GIPA(AcquireXlibDisplayEXT);
 #endif // VK_USE_PLATFORM_XLIB_XRANDR_EXT
 #if defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
-    LOOKUP_GIPA(GetRandROutputDisplayEXT, false);
+    LOOKUP_GIPA(GetRandROutputDisplayEXT);
 #endif // VK_USE_PLATFORM_XLIB_XRANDR_EXT
 
     // ---- VK_EXT_display_surface_counter extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilities2EXT, false);
+    LOOKUP_GIPA(GetPhysicalDeviceSurfaceCapabilities2EXT);
 
     // ---- VK_MVK_ios_surface extension commands
 #if defined(VK_USE_PLATFORM_IOS_MVK)
-    LOOKUP_GIPA(CreateIOSSurfaceMVK, false);
+    LOOKUP_GIPA(CreateIOSSurfaceMVK);
 #endif // VK_USE_PLATFORM_IOS_MVK
 
     // ---- VK_MVK_macos_surface extension commands
 #if defined(VK_USE_PLATFORM_MACOS_MVK)
-    LOOKUP_GIPA(CreateMacOSSurfaceMVK, false);
+    LOOKUP_GIPA(CreateMacOSSurfaceMVK);
 #endif // VK_USE_PLATFORM_MACOS_MVK
 
     // ---- VK_EXT_debug_utils extension commands
-    LOOKUP_GIPA(CreateDebugUtilsMessengerEXT, false);
-    LOOKUP_GIPA(DestroyDebugUtilsMessengerEXT, false);
-    LOOKUP_GIPA(SubmitDebugUtilsMessageEXT, false);
+    LOOKUP_GIPA(CreateDebugUtilsMessengerEXT);
+    LOOKUP_GIPA(DestroyDebugUtilsMessengerEXT);
+    LOOKUP_GIPA(SubmitDebugUtilsMessageEXT);
 
     // ---- VK_EXT_sample_locations extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceMultisamplePropertiesEXT, false);
+    LOOKUP_GIPA(GetPhysicalDeviceMultisamplePropertiesEXT);
 
     // ---- VK_EXT_calibrated_timestamps extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceCalibrateableTimeDomainsEXT, false);
+    LOOKUP_GIPA(GetPhysicalDeviceCalibrateableTimeDomainsEXT);
 
     // ---- VK_FUCHSIA_imagepipe_surface extension commands
 #if defined(VK_USE_PLATFORM_FUCHSIA)
-    LOOKUP_GIPA(CreateImagePipeSurfaceFUCHSIA, false);
+    LOOKUP_GIPA(CreateImagePipeSurfaceFUCHSIA);
 #endif // VK_USE_PLATFORM_FUCHSIA
 
     // ---- VK_EXT_metal_surface extension commands
 #if defined(VK_USE_PLATFORM_METAL_EXT)
-    LOOKUP_GIPA(CreateMetalSurfaceEXT, false);
+    LOOKUP_GIPA(CreateMetalSurfaceEXT);
 #endif // VK_USE_PLATFORM_METAL_EXT
 
     // ---- VK_EXT_tooling_info extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceToolPropertiesEXT, false);
+    LOOKUP_GIPA(GetPhysicalDeviceToolPropertiesEXT);
 
     // ---- VK_NV_cooperative_matrix extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceCooperativeMatrixPropertiesNV, false);
+    LOOKUP_GIPA(GetPhysicalDeviceCooperativeMatrixPropertiesNV);
 
     // ---- VK_NV_coverage_reduction_mode extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV, false);
+    LOOKUP_GIPA(GetPhysicalDeviceSupportedFramebufferMixedSamplesCombinationsNV);
 
     // ---- VK_EXT_full_screen_exclusive extension commands
 #if defined(VK_USE_PLATFORM_WIN32_KHR)
-    LOOKUP_GIPA(GetPhysicalDeviceSurfacePresentModes2EXT, false);
+    LOOKUP_GIPA(GetPhysicalDeviceSurfacePresentModes2EXT);
 #endif // VK_USE_PLATFORM_WIN32_KHR
 
     // ---- VK_EXT_headless_surface extension commands
-    LOOKUP_GIPA(CreateHeadlessSurfaceEXT, false);
+    LOOKUP_GIPA(CreateHeadlessSurfaceEXT);
 
     // ---- VK_EXT_acquire_drm_display extension commands
-    LOOKUP_GIPA(AcquireDrmDisplayEXT, false);
-    LOOKUP_GIPA(GetDrmDisplayEXT, false);
+    LOOKUP_GIPA(AcquireDrmDisplayEXT);
+    LOOKUP_GIPA(GetDrmDisplayEXT);
 
     // ---- VK_NV_acquire_winrt_display extension commands
 #if defined(VK_USE_PLATFORM_WIN32_KHR)
-    LOOKUP_GIPA(AcquireWinrtDisplayNV, false);
+    LOOKUP_GIPA(AcquireWinrtDisplayNV);
 #endif // VK_USE_PLATFORM_WIN32_KHR
 #if defined(VK_USE_PLATFORM_WIN32_KHR)
-    LOOKUP_GIPA(GetWinrtDisplayNV, false);
+    LOOKUP_GIPA(GetWinrtDisplayNV);
 #endif // VK_USE_PLATFORM_WIN32_KHR
 
     // ---- VK_EXT_directfb_surface extension commands
 #if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
-    LOOKUP_GIPA(CreateDirectFBSurfaceEXT, false);
+    LOOKUP_GIPA(CreateDirectFBSurfaceEXT);
 #endif // VK_USE_PLATFORM_DIRECTFB_EXT
 #if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
-    LOOKUP_GIPA(GetPhysicalDeviceDirectFBPresentationSupportEXT, false);
+    LOOKUP_GIPA(GetPhysicalDeviceDirectFBPresentationSupportEXT);
 #endif // VK_USE_PLATFORM_DIRECTFB_EXT
 
     // ---- VK_QNX_screen_surface extension commands
 #if defined(VK_USE_PLATFORM_SCREEN_QNX)
-    LOOKUP_GIPA(CreateScreenSurfaceQNX, false);
+    LOOKUP_GIPA(CreateScreenSurfaceQNX);
 #endif // VK_USE_PLATFORM_SCREEN_QNX
 #if defined(VK_USE_PLATFORM_SCREEN_QNX)
-    LOOKUP_GIPA(GetPhysicalDeviceScreenPresentationSupportQNX, false);
+    LOOKUP_GIPA(GetPhysicalDeviceScreenPresentationSupportQNX);
 #endif // VK_USE_PLATFORM_SCREEN_QNX
 
     // ---- VK_NV_optical_flow extension commands
-    LOOKUP_GIPA(GetPhysicalDeviceOpticalFlowImageFormatsNV, false);
+    LOOKUP_GIPA(GetPhysicalDeviceOpticalFlowImageFormatsNV);
 
+#undef LOOKUP_REQUIRED_GIPA
 #undef LOOKUP_GIPA
 
     return true;
index ca8bbd27916bd8f2da3b56816f3371eac7253ed9..dd5628c02d34966c94d1b86993d33c01485f9d33 100644 (file)
@@ -54,8 +54,7 @@ extern const VkLayerInstanceDispatchTable instance_disp;
 // Array of extension strings for instance extensions we support.
 extern const char *const LOADER_INSTANCE_EXTENSIONS[];
 
-VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_icd_term *icd_term, VkInstance inst,
-                                                   const PFN_vkGetInstanceProcAddr fp_gipa);
+VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_instance* inst, struct loader_icd_term *icd_term);
 
 // Init Device function pointer dispatch table with core commands
 VKAPI_ATTR void VKAPI_CALL loader_init_device_dispatch_table(struct loader_dev_dispatch_table *dev_table, PFN_vkGetDeviceProcAddr gpa,
index aee5be418bf0e3947e19cf9dca31ab171fd2da88..8acd5befad4c75681f002c929ede514879fe955b 100644 (file)
@@ -5413,8 +5413,7 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateInstance(const VkInstanceCreateI
             continue;
         }
 
-        if (!loader_icd_init_entries(icd_term, icd_term->instance,
-                                     ptr_instance->icd_tramp_list.scanned_list[i].GetInstanceProcAddr)) {
+        if (!loader_icd_init_entries(ptr_instance, icd_term)) {
             loader_log(ptr_instance, VULKAN_LOADER_WARN_BIT, 0,
                        "terminator_CreateInstance: Failed to CreateInstance and find entrypoints with ICD.  Skipping ICD.");
             ptr_instance->icd_terms = icd_term->next;
index 26de6a634d0a7f19270959fda62046cca08bd3e4..867d93dd565d790738c02ccd14796785bc44d5e1 100644 (file)
@@ -102,9 +102,9 @@ void loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t ms
 
     if (inst) {
         VkDebugUtilsMessageSeverityFlagBitsEXT severity = 0;
-        VkDebugUtilsMessageTypeFlagsEXT type;
-        VkDebugUtilsMessengerCallbackDataEXT callback_data;
-        VkDebugUtilsObjectNameInfoEXT object_name;
+        VkDebugUtilsMessageTypeFlagsEXT type = 0;
+        VkDebugUtilsMessengerCallbackDataEXT callback_data = {0};
+        VkDebugUtilsObjectNameInfoEXT object_name = {0};
 
         if ((msg_type & VULKAN_LOADER_INFO_BIT) != 0) {
             severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT;
@@ -130,22 +130,13 @@ void loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t ms
         }
 
         callback_data.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT;
-        callback_data.pNext = NULL;
-        callback_data.flags = 0;
         callback_data.pMessageIdName = "Loader Message";
-        callback_data.messageIdNumber = 0;
         callback_data.pMessage = msg;
-        callback_data.queueLabelCount = 0;
-        callback_data.pQueueLabels = NULL;
-        callback_data.cmdBufLabelCount = 0;
-        callback_data.pCmdBufLabels = NULL;
         callback_data.objectCount = 1;
         callback_data.pObjects = &object_name;
         object_name.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
-        object_name.pNext = NULL;
         object_name.objectType = VK_OBJECT_TYPE_INSTANCE;
         object_name.objectHandle = (uint64_t)(uintptr_t)inst;
-        object_name.pObjectName = NULL;
 
         util_SubmitDebugUtilsMessageEXT(inst, severity, type, &callback_data);
     }
index c52ca8862570b555fe1db11959afa8f6312fbdca..89132775158274054b59d96bbe477e5377e13558 100644 (file)
@@ -463,8 +463,7 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
         protos += '// Array of extension strings for instance extensions we support.\n'
         protos += 'extern const char *const LOADER_INSTANCE_EXTENSIONS[];\n'
         protos += '\n'
-        protos += 'VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_icd_term *icd_term, VkInstance inst,\n'
-        protos += '                                                   const PFN_vkGetInstanceProcAddr fp_gipa);\n'
+        protos += 'VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_instance* inst, struct loader_icd_term *icd_term);\n'
         protos += '\n'
         protos += '// Init Device function pointer dispatch table with core commands\n'
         protos += 'VKAPI_ATTR void VKAPI_CALL loader_init_device_dispatch_table(struct loader_dev_dispatch_table *dev_table, PFN_vkGetDeviceProcAddr gpa,\n'
@@ -655,20 +654,23 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
         cur_extension_name = ''
 
         table = ''
-        table += 'VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_icd_term *icd_term, VkInstance inst,\n'
-        table += '                                                   const PFN_vkGetInstanceProcAddr fp_gipa) {\n'
+        table += 'VKAPI_ATTR bool VKAPI_CALL loader_icd_init_entries(struct loader_instance* inst, struct loader_icd_term *icd_term) {\n'
+        table += '    const PFN_vkGetInstanceProcAddr fp_gipa = icd_term->scanned_icd->GetInstanceProcAddr;\n'
         table += '\n'
-        table += '#define LOOKUP_GIPA(func, required)                                                        \\\n'
-        table += '    do {                                                                                   \\\n'
-        table += '        icd_term->dispatch.func = (PFN_vk##func)fp_gipa(inst, "vk" #func);                 \\\n'
-        table += '        if (!icd_term->dispatch.func && required) {                                        \\\n'
-        table += '            loader_log((struct loader_instance *)inst, VULKAN_LOADER_WARN_BIT, 0, \\\n'
-        table += '                       loader_platform_get_proc_address_error("vk" #func));                \\\n'
-        table += '            return false;                                                                  \\\n'
-        table += '        }                                                                                  \\\n'
+        table += '#define LOOKUP_GIPA(func) icd_term->dispatch.func = (PFN_vk##func)fp_gipa(icd_term->instance, "vk" #func);\n'
+        table += '\n'
+        table += '#define LOOKUP_REQUIRED_GIPA(func)                                                      \\\n'
+        table += '    do {                                                                                \\\n'
+        table += '        LOOKUP_GIPA(func);                                                              \\\n'
+        table += '        if (!icd_term->dispatch.func) {                                                 \\\n'
+        table += '            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0, "Unable to load %s from ICD %s",\\\n'
+        table += '                       "vk"#func, icd_term->scanned_icd->lib_name);                     \\\n'
+        table += '            return false;                                                               \\\n'
+        table += '        }                                                                               \\\n'
         table += '    } while (0)\n'
         table += '\n'
 
+
         skip_gipa_commands = ['vkGetInstanceProcAddr',
                               'vkEnumerateDeviceLayerProperties',
                               'vkCreateInstance',
@@ -702,14 +704,17 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
                     if cur_cmd.protect is not None:
                         table += '#if defined(%s)\n' % cur_cmd.protect
 
-                    # The Core Vulkan code will be wrapped in a feature called VK_VERSION_#_#
-                    # For example: VK_VERSION_1_0 wraps the core 1.0 Vulkan functionality
-                    table += '    LOOKUP_GIPA(%s, %s);\n' % (base_name, 'true' if required else 'false')
-
+                    if required:
+                        # The Core Vulkan code will be wrapped in a feature called VK_VERSION_#_#
+                        # For example: VK_VERSION_1_0 wraps the core 1.0 Vulkan functionality
+                        table += f'    LOOKUP_REQUIRED_GIPA({base_name});\n'
+                    else:
+                        table += f'    LOOKUP_GIPA({base_name});\n'
                     if cur_cmd.protect is not None:
                         table += '#endif // %s\n' % cur_cmd.protect
 
         table += '\n'
+        table += '#undef LOOKUP_REQUIRED_GIPA\n'
         table += '#undef LOOKUP_GIPA\n'
         table += '\n'
         table += '    return true;\n'
index 2c44239b0fd345d7e23bbea21d736cb396d18ab2..d3eb0aa7ce1a2228479acae51faf5abd84e911da 100644 (file)
@@ -1333,14 +1333,19 @@ PFN_vkVoidFunction get_physical_device_func([[maybe_unused]] VkInstance instance
         return to_vkVoidFunction(test_vkGetPhysicalDeviceQueueFamilyProperties);
     if (string_eq(pName, "vkCreateDevice")) return to_vkVoidFunction(test_vkCreateDevice);
 
-    if (string_eq(pName, "vkGetPhysicalDeviceFeatures")) return to_vkVoidFunction(test_vkGetPhysicalDeviceFeatures);
-    if (string_eq(pName, "vkGetPhysicalDeviceProperties")) return to_vkVoidFunction(test_vkGetPhysicalDeviceProperties);
-    if (string_eq(pName, "vkGetPhysicalDeviceMemoryProperties")) return to_vkVoidFunction(test_vkGetPhysicalDeviceMemoryProperties);
+    if (string_eq(pName, "vkGetPhysicalDeviceFeatures"))
+        return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceFeatures) : nullptr;
+    if (string_eq(pName, "vkGetPhysicalDeviceProperties"))
+        return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceProperties) : nullptr;
+    if (string_eq(pName, "vkGetPhysicalDeviceMemoryProperties"))
+        return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceMemoryProperties) : nullptr;
     if (string_eq(pName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
-        return to_vkVoidFunction(test_vkGetPhysicalDeviceSparseImageFormatProperties);
-    if (string_eq(pName, "vkGetPhysicalDeviceFormatProperties")) return to_vkVoidFunction(test_vkGetPhysicalDeviceFormatProperties);
+        return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceSparseImageFormatProperties)
+                                                    : nullptr;
+    if (string_eq(pName, "vkGetPhysicalDeviceFormatProperties"))
+        return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceFormatProperties) : nullptr;
     if (string_eq(pName, "vkGetPhysicalDeviceImageFormatProperties"))
-        return to_vkVoidFunction(test_vkGetPhysicalDeviceImageFormatProperties);
+        return icd.can_query_GetPhysicalDeviceFuncs ? to_vkVoidFunction(test_vkGetPhysicalDeviceImageFormatProperties) : nullptr;
 
     if (IsInstanceExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
         if (string_eq(pName, "vkGetPhysicalDeviceFeatures2KHR")) return to_vkVoidFunction(test_vkGetPhysicalDeviceFeatures2);
index 760a08b2f8cb112a736fe480270c30ee2aa42073..8515a849390361efd34a9db4b20073de2caea960 100644 (file)
@@ -121,6 +121,7 @@ struct TestICD {
     std::vector<uint64_t> swapchain_handles;
 
     BUILDER_VALUE(TestICD, bool, can_query_vkEnumerateInstanceVersion, true);
+    BUILDER_VALUE(TestICD, bool, can_query_GetPhysicalDeviceFuncs, true);
 
     // Unknown instance functions Add a `VulkanFunction` to this list which will be searched in
     // vkGetInstanceProcAddr for custom_instance_functions and vk_icdGetPhysicalDeviceProcAddr for
index 6a167d160717d0cfcd9df4e14d611074fbd8f723..295eee7b94bfb842b2d2f805d7a79c1293ce113f 100644 (file)
@@ -178,6 +178,25 @@ TEST(GetProcAddr, GlobalFunctions) {
     }
 }
 
+TEST(GetProcAddr, Verify10FunctionsFailToLoadWithSingleDriver) {
+    FrameworkEnvironment env{};
+    env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)).add_physical_device({}).set_can_query_GetPhysicalDeviceFuncs(false);
+
+    InstWrapper inst{env.vulkan_functions};
+    inst.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
+}
+
+TEST(GetProcAddr, Verify10FunctionsLoadWithMultipleDrivers) {
+    FrameworkEnvironment env{};
+    env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)).add_physical_device({});
+    env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)).add_physical_device({}).set_can_query_GetPhysicalDeviceFuncs(false);
+
+    InstWrapper inst{env.vulkan_functions};
+    inst.CheckCreate();
+
+    inst.GetPhysDevs(1);
+}
+
 // Swapchain functions which require a terminator in all cases have situations where the driver may have a
 // NULL function pointer but the loader shouldn't abort() if that is the case. Rather, it should log a message
 // and return VK_SUCCESS to maintain previous behavior.