unknownue/vulkan-tutorial-rust

Calling query_swapchain_support before checking if swapchain extension is available violates the spec

Closed this issue · 3 comments

We're calling query_swapchain_support here:

let swapchain_support =
VulkanApp::query_swapchain_support(**physical_device, surface_stuff);
, before the check for the swapchain extension availability happens there:
let is_device_extension_supported =
VulkanApp::check_device_extension_support(instance, physical_device);

Vulkan Tutorial says:

"It is important that we only try to query for swap chain support after verifying that the extension is available."

I've asked around why is it important and found out this spec section:
https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#initialization-phys-dev-extensions

The spec says:

"Applications must not use a VkPhysicalDevice in any command added by an extension or core version that is not supported by that physical device."

So when we're calling get_physical_device_surface_capabilities and friends without knowing in advance that VK_KHR_swapchain is available, we're getting an undefined behavior.

I'll submit a PR to handle that.

Some more context in this reddit thread:
https://www.reddit.com/r/vulkan/comments/dmu7vd/q_about_an_order_of_querying_for_physical_device/

While nothing bad should really happen if we write code as it is now, I think it still makes sense to adhere to the spec, especially since it's rather easy in our case.

Yes, this must be my carelessness.
This is one of the difficulties for coding in Vulkan level API. You gain flexibility and freedom, but also undertake more responsibility.

True, true. Especially given that validation layers don't really help with such subtleties.