87fb1ec352
So far, we have only been supporting X11, so we assumed that we were running inside X11 and would always try to get an authenticated fd from Xorg during device initialization. While this works for desktop Raspbian, it is not really correct and it is not what we want to do when we start considering other WSIs. Initially, one could think we can still do this by guarding the WSI code under the proper instance extension check. This, however, doesn't work reliably, as the Vulkan loader can call vkEnumerateDevices without enabling surface extensions on the instance, which then can lead to us not initializing any display_fd and failing with VK_ERROR_INITIALIZATION_FAILED, which is not correct, so while we can try to acquire the display_fd here, it might not always work, and we should definitely not fail initialization of the physical device for that. Instead, with this change we move acquisition of display_fd to swapchain creation time where required extensions need to be enabled in the instance. This was also suggested by Daniel Stone during review of a work-in-progress implementation for the Wayland WSI. There is a special case to consider though: applications like Zink that don't use Vulkan's swapchains at all but still allocate images that they intend to use for WSI. We need to handle these by checking that we have indeed acquired a display_fd before doing any memory allocation for WSI, and acquiring one at that time if that's not the case. This change also removes the render_fd and display_fd fields from the logical device (which we were copying from the physical device), because now there is no guarantee that we have acquired a display_fd at the time we create a logical device. Instead, we now put a reference to the physical device on the logical device from which we can access these. Finally, this also fixes a regression introduced with VK_KHR_display, where if that extension is enabled but we are running inside a compositor, we would acquire a display_fd that is not authenticated and try to use that instead of acquiring an authenticated display_fd from the display server. Fixes: b1188c9451 (v3dv: VK_KHR_display extension support) Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7546>