vulkan/wsi/x11: return VK_SUBOPTIMAL_KHR on mismatched swapchain

If the swapchain already does not match the current geometry at the time
of creation, set the initial status to VK_SUBOPTIMAL_KHR as a way to
inform clients to please resize the swapchain.

This solves a race condition where users have no way of knowing if the
surface extent changed in between the user querying the current extent
and creating the swapchain, and might end up missing a resize event
because of it, since XCB_PRESENT_CONFIGURE_NOTIFY is not yet being
handled.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3196>
This commit is contained in:
Niklas Haas
2019-12-22 02:58:39 +01:00
committed by Marge Bot
parent 91cbe8d855
commit 4a1f230e35
+5
View File
@@ -1591,6 +1591,8 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
if (geometry == NULL)
return VK_ERROR_SURFACE_LOST_KHR;
const uint32_t bit_depth = geometry->depth;
const uint16_t cur_width = geometry->width;
const uint16_t cur_height = geometry->height;
free(geometry);
size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]);
@@ -1622,6 +1624,9 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
chain->status = VK_SUCCESS;
chain->has_dri3_modifiers = wsi_conn->has_dri3_modifiers;
if (chain->extent.width != cur_width || chain->extent.height != cur_height)
chain->status = VK_SUBOPTIMAL_KHR;
/* If we are reallocating from an old swapchain, then we inherit its
* last completion mode, to ensure we don't get into reallocation
* cycles. If we are starting anew, we set 'COPY', as that is the only