Skip to content

Commit

Permalink
Track the extension used to create each VkSurfaceKHR
Browse files Browse the repository at this point in the history
The Vulkan-Loader now doesn't call into drivers if they do not support the
extension that was used to create the VkSurfaceKHR handle. This prevents
crashes from occuring where a driver is called using a surface that it does
not know about, due to the driver not supporting the surface extension.

Because the specification requires that VkSurfaceKHR must be a valid handle,
the loader should not allow calls down into drivers which cannot know about
the surface. Instead it should "emulate" the call as appropriate, returning
0 for counts and setting to 0 any structures that were passed in.
  • Loading branch information
charles-lunarg committed Oct 29, 2024
1 parent b3b62dc commit a94c46a
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 1 deletion.
72 changes: 72 additions & 0 deletions loader/generated/vk_loader_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -12241,6 +12241,78 @@ void fill_out_enabled_instance_extensions(uint32_t extension_count, const char *
}
};

bool check_if_instance_extension_is_available(const struct loader_instance_extension_enables* enabled, const struct loader_instance_extension_enables* desired) {
bool out = false;
out = out || (enabled->khr_surface && desired->khr_surface);
out = out || (enabled->khr_display && desired->khr_display);
#if defined(VK_USE_PLATFORM_XLIB_KHR)
out = out || (enabled->khr_xlib_surface && desired->khr_xlib_surface);
#endif // defined(VK_USE_PLATFORM_XLIB_KHR)
#if defined(VK_USE_PLATFORM_XCB_KHR)
out = out || (enabled->khr_xcb_surface && desired->khr_xcb_surface);
#endif // defined(VK_USE_PLATFORM_XCB_KHR)
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
out = out || (enabled->khr_wayland_surface && desired->khr_wayland_surface);
#endif // defined(VK_USE_PLATFORM_WAYLAND_KHR)
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
out = out || (enabled->khr_android_surface && desired->khr_android_surface);
#endif // defined(VK_USE_PLATFORM_ANDROID_KHR)
#if defined(VK_USE_PLATFORM_WIN32_KHR)
out = out || (enabled->khr_win32_surface && desired->khr_win32_surface);
#endif // defined(VK_USE_PLATFORM_WIN32_KHR)
out = out || (enabled->khr_get_physical_device_properties2 && desired->khr_get_physical_device_properties2);
out = out || (enabled->khr_device_group_creation && desired->khr_device_group_creation);
out = out || (enabled->khr_external_memory_capabilities && desired->khr_external_memory_capabilities);
out = out || (enabled->khr_external_semaphore_capabilities && desired->khr_external_semaphore_capabilities);
out = out || (enabled->khr_external_fence_capabilities && desired->khr_external_fence_capabilities);
out = out || (enabled->khr_get_surface_capabilities2 && desired->khr_get_surface_capabilities2);
out = out || (enabled->khr_get_display_properties2 && desired->khr_get_display_properties2);
out = out || (enabled->khr_surface_protected_capabilities && desired->khr_surface_protected_capabilities);
out = out || (enabled->khr_portability_enumeration && desired->khr_portability_enumeration);
out = out || (enabled->ext_debug_report && desired->ext_debug_report);
#if defined(VK_USE_PLATFORM_GGP)
out = out || (enabled->ggp_stream_descriptor_surface && desired->ggp_stream_descriptor_surface);
#endif // defined(VK_USE_PLATFORM_GGP)
out = out || (enabled->nv_external_memory_capabilities && desired->nv_external_memory_capabilities);
out = out || (enabled->ext_validation_flags && desired->ext_validation_flags);
#if defined(VK_USE_PLATFORM_VI_NN)
out = out || (enabled->nn_vi_surface && desired->nn_vi_surface);
#endif // defined(VK_USE_PLATFORM_VI_NN)
out = out || (enabled->ext_direct_mode_display && desired->ext_direct_mode_display);
#if defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
out = out || (enabled->ext_acquire_xlib_display && desired->ext_acquire_xlib_display);
#endif // defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
out = out || (enabled->ext_display_surface_counter && desired->ext_display_surface_counter);
out = out || (enabled->ext_swapchain_colorspace && desired->ext_swapchain_colorspace);
#if defined(VK_USE_PLATFORM_IOS_MVK)
out = out || (enabled->mvk_ios_surface && desired->mvk_ios_surface);
#endif // defined(VK_USE_PLATFORM_IOS_MVK)
#if defined(VK_USE_PLATFORM_MACOS_MVK)
out = out || (enabled->mvk_macos_surface && desired->mvk_macos_surface);
#endif // defined(VK_USE_PLATFORM_MACOS_MVK)
out = out || (enabled->ext_debug_utils && desired->ext_debug_utils);
#if defined(VK_USE_PLATFORM_FUCHSIA)
out = out || (enabled->fuchsia_imagepipe_surface && desired->fuchsia_imagepipe_surface);
#endif // defined(VK_USE_PLATFORM_FUCHSIA)
#if defined(VK_USE_PLATFORM_METAL_EXT)
out = out || (enabled->ext_metal_surface && desired->ext_metal_surface);
#endif // defined(VK_USE_PLATFORM_METAL_EXT)
out = out || (enabled->ext_validation_features && desired->ext_validation_features);
out = out || (enabled->ext_headless_surface && desired->ext_headless_surface);
out = out || (enabled->ext_surface_maintenance1 && desired->ext_surface_maintenance1);
out = out || (enabled->ext_acquire_drm_display && desired->ext_acquire_drm_display);
#if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
out = out || (enabled->ext_directfb_surface && desired->ext_directfb_surface);
#endif // defined(VK_USE_PLATFORM_DIRECTFB_EXT)
#if defined(VK_USE_PLATFORM_SCREEN_QNX)
out = out || (enabled->qnx_screen_surface && desired->qnx_screen_surface);
#endif // defined(VK_USE_PLATFORM_SCREEN_QNX)
out = out || (enabled->google_surfaceless_query && desired->google_surfaceless_query);
out = out || (enabled->lunarg_direct_driver_loading && desired->lunarg_direct_driver_loading);
out = out || (enabled->ext_layer_settings && desired->ext_layer_settings);
return out;
};

// Some device commands still need a terminator because the loader needs to unwrap something about them.
// In many cases, the item needing unwrapping is a VkPhysicalDevice or VkSurfaceKHR object. But there may be other items
// in the future.
Expand Down
2 changes: 2 additions & 0 deletions loader/generated/vk_loader_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct loader_instance_extension_enables; // Forward declaration
void fill_out_enabled_instance_extensions(uint32_t extension_count, const char *const * extension_list, struct loader_instance_extension_enables* enables);


bool check_if_instance_extension_is_available(const struct loader_instance_extension_enables* enabled, const struct loader_instance_extension_enables* desired);

// Extension interception for vkGetDeviceProcAddr function, so we can return
// an appropriate terminator if this is one of those few device commands requiring
// a terminator.
Expand Down
Loading

0 comments on commit a94c46a

Please sign in to comment.