vk/wsi/x11: move surface alpha check from get_caps to creation

this makes get_caps a bit less heavy

Acked-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23835>
This commit is contained in:
Mike Blumenkrantz 2023-06-13 16:18:44 -04:00 committed by Marge Bot
parent 776f258ddb
commit fb9f697fbb

View file

@ -86,6 +86,13 @@ struct wsi_x11 {
struct hash_table *connections; struct hash_table *connections;
}; };
struct wsi_x11_vk_surface {
union {
VkIcdSurfaceXlib xlib;
VkIcdSurfaceXcb xcb;
};
bool has_alpha;
};
/** /**
* Wrapper around xcb_dri3_open. Returns the opened fd or -1 on error. * Wrapper around xcb_dri3_open. Returns the opened fd or -1 on error.
@ -678,26 +685,19 @@ x11_surface_get_capabilities(VkIcdSurfaceBase *icd_surface,
{ {
xcb_connection_t *conn = x11_surface_get_connection(icd_surface); xcb_connection_t *conn = x11_surface_get_connection(icd_surface);
xcb_window_t window = x11_surface_get_window(icd_surface); xcb_window_t window = x11_surface_get_window(icd_surface);
struct wsi_x11_vk_surface *surface = (struct wsi_x11_vk_surface*)icd_surface;
struct wsi_x11_connection *wsi_conn = struct wsi_x11_connection *wsi_conn =
wsi_x11_get_connection(wsi_device, conn); wsi_x11_get_connection(wsi_device, conn);
xcb_get_geometry_cookie_t geom_cookie; xcb_get_geometry_cookie_t geom_cookie;
xcb_generic_error_t *err; xcb_generic_error_t *err;
xcb_get_geometry_reply_t *geom; xcb_get_geometry_reply_t *geom;
unsigned visual_depth;
geom_cookie = xcb_get_geometry(conn, window); geom_cookie = xcb_get_geometry(conn, window);
/* This does a round-trip. This is why we do get_geometry first and
* wait to read the reply until after we have a visual.
*/
xcb_visualtype_t *visual =
get_visualtype_for_window(conn, window, &visual_depth, NULL);
if (!visual)
return VK_ERROR_SURFACE_LOST_KHR;
geom = xcb_get_geometry_reply(conn, geom_cookie, &err); geom = xcb_get_geometry_reply(conn, geom_cookie, &err);
if (geom) { if (!geom)
return VK_ERROR_SURFACE_LOST_KHR;
{
VkExtent2D extent = { geom->width, geom->height }; VkExtent2D extent = { geom->width, geom->height };
caps->currentExtent = extent; caps->currentExtent = extent;
caps->minImageExtent = extent; caps->minImageExtent = extent;
@ -708,7 +708,7 @@ x11_surface_get_capabilities(VkIcdSurfaceBase *icd_surface,
if (!geom) if (!geom)
return VK_ERROR_SURFACE_LOST_KHR; return VK_ERROR_SURFACE_LOST_KHR;
if (visual_has_alpha(visual, visual_depth)) { if (surface->has_alpha) {
caps->supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR | caps->supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR |
VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR; VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR;
} else { } else {
@ -964,20 +964,28 @@ wsi_CreateXcbSurfaceKHR(VkInstance _instance,
VkSurfaceKHR *pSurface) VkSurfaceKHR *pSurface)
{ {
VK_FROM_HANDLE(vk_instance, instance, _instance); VK_FROM_HANDLE(vk_instance, instance, _instance);
VkIcdSurfaceXcb *surface; struct wsi_x11_vk_surface *surface;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR); assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR);
surface = vk_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8, unsigned visual_depth;
xcb_visualtype_t *visual =
get_visualtype_for_window(pCreateInfo->connection, pCreateInfo->window, &visual_depth, NULL);
if (!visual)
return VK_ERROR_OUT_OF_HOST_MEMORY;
surface = vk_alloc2(&instance->alloc, pAllocator, sizeof(struct wsi_x11_vk_surface), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (surface == NULL) if (surface == NULL)
return VK_ERROR_OUT_OF_HOST_MEMORY; return VK_ERROR_OUT_OF_HOST_MEMORY;
surface->base.platform = VK_ICD_WSI_PLATFORM_XCB; surface->xcb.base.platform = VK_ICD_WSI_PLATFORM_XCB;
surface->connection = pCreateInfo->connection; surface->xcb.connection = pCreateInfo->connection;
surface->window = pCreateInfo->window; surface->xcb.window = pCreateInfo->window;
*pSurface = VkIcdSurfaceBase_to_handle(&surface->base); surface->has_alpha = visual_has_alpha(visual, visual_depth);
*pSurface = VkIcdSurfaceBase_to_handle(&surface->xcb.base);
return VK_SUCCESS; return VK_SUCCESS;
} }
@ -988,20 +996,28 @@ wsi_CreateXlibSurfaceKHR(VkInstance _instance,
VkSurfaceKHR *pSurface) VkSurfaceKHR *pSurface)
{ {
VK_FROM_HANDLE(vk_instance, instance, _instance); VK_FROM_HANDLE(vk_instance, instance, _instance);
VkIcdSurfaceXlib *surface; struct wsi_x11_vk_surface *surface;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR); assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR);
surface = vk_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8, unsigned visual_depth;
xcb_visualtype_t *visual =
get_visualtype_for_window(XGetXCBConnection(pCreateInfo->dpy), pCreateInfo->window, &visual_depth, NULL);
if (!visual)
return VK_ERROR_OUT_OF_HOST_MEMORY;
surface = vk_alloc2(&instance->alloc, pAllocator, sizeof(struct wsi_x11_vk_surface), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (surface == NULL) if (surface == NULL)
return VK_ERROR_OUT_OF_HOST_MEMORY; return VK_ERROR_OUT_OF_HOST_MEMORY;
surface->base.platform = VK_ICD_WSI_PLATFORM_XLIB; surface->xlib.base.platform = VK_ICD_WSI_PLATFORM_XLIB;
surface->dpy = pCreateInfo->dpy; surface->xlib.dpy = pCreateInfo->dpy;
surface->window = pCreateInfo->window; surface->xlib.window = pCreateInfo->window;
*pSurface = VkIcdSurfaceBase_to_handle(&surface->base); surface->has_alpha = visual_has_alpha(visual, visual_depth);
*pSurface = VkIcdSurfaceBase_to_handle(&surface->xlib.base);
return VK_SUCCESS; return VK_SUCCESS;
} }