2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include <X11/Xlib-xcb.h>
25 #include <X11/xshmfence.h>
28 #include <xcb/present.h>
30 #include "util/macros.h"
39 #include <drm_fourcc.h>
40 #include "util/hash_table.h"
43 #include "wsi_common_private.h"
44 #include "wsi_common_x11.h"
45 #include "wsi_common_queue.h"
47 #define typed_memcpy(dest, src, count) ({ \
48 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
49 memcpy((dest), (src), (count) * sizeof(*(src))); \
52 struct wsi_x11_connection
{
54 bool has_dri3_modifiers
;
56 bool is_proprietary_x11
;
60 struct wsi_interface base
;
62 pthread_mutex_t mutex
;
63 /* Hash table of xcb_connection -> wsi_x11_connection mappings */
64 struct hash_table
*connections
;
70 * Wrapper around xcb_dri3_open
73 wsi_dri3_open(xcb_connection_t
*conn
,
77 xcb_dri3_open_cookie_t cookie
;
78 xcb_dri3_open_reply_t
*reply
;
81 cookie
= xcb_dri3_open(conn
,
85 reply
= xcb_dri3_open_reply(conn
, cookie
, NULL
);
89 if (reply
->nfd
!= 1) {
94 fd
= xcb_dri3_open_reply_fds(conn
, reply
)[0];
96 fcntl(fd
, F_SETFD
, fcntl(fd
, F_GETFD
) | FD_CLOEXEC
);
102 wsi_x11_check_dri3_compatible(xcb_connection_t
*conn
, int local_fd
)
104 xcb_screen_iterator_t screen_iter
=
105 xcb_setup_roots_iterator(xcb_get_setup(conn
));
106 xcb_screen_t
*screen
= screen_iter
.data
;
108 int dri3_fd
= wsi_dri3_open(conn
, screen
->root
, None
);
110 char *local_dev
= drmGetRenderDeviceNameFromFd(local_fd
);
111 char *dri3_dev
= drmGetRenderDeviceNameFromFd(dri3_fd
);
116 ret
= strcmp(local_dev
, dri3_dev
);
127 static struct wsi_x11_connection
*
128 wsi_x11_connection_create(struct wsi_device
*wsi_dev
,
129 xcb_connection_t
*conn
)
131 xcb_query_extension_cookie_t dri3_cookie
, pres_cookie
, amd_cookie
, nv_cookie
;
132 xcb_query_extension_reply_t
*dri3_reply
, *pres_reply
, *amd_reply
, *nv_reply
;
133 bool has_dri3_v1_2
= false;
134 bool has_present_v1_2
= false;
136 struct wsi_x11_connection
*wsi_conn
=
137 vk_alloc(&wsi_dev
->instance_alloc
, sizeof(*wsi_conn
), 8,
138 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
142 dri3_cookie
= xcb_query_extension(conn
, 4, "DRI3");
143 pres_cookie
= xcb_query_extension(conn
, 7, "Present");
145 /* We try to be nice to users and emit a warning if they try to use a
146 * Vulkan application on a system without DRI3 enabled. However, this ends
147 * up spewing the warning when a user has, for example, both Intel
148 * integrated graphics and a discrete card with proprietary drivers and are
149 * running on the discrete card with the proprietary DDX. In this case, we
150 * really don't want to print the warning because it just confuses users.
151 * As a heuristic to detect this case, we check for a couple of proprietary
154 amd_cookie
= xcb_query_extension(conn
, 11, "ATIFGLRXDRI");
155 nv_cookie
= xcb_query_extension(conn
, 10, "NV-CONTROL");
157 dri3_reply
= xcb_query_extension_reply(conn
, dri3_cookie
, NULL
);
158 pres_reply
= xcb_query_extension_reply(conn
, pres_cookie
, NULL
);
159 amd_reply
= xcb_query_extension_reply(conn
, amd_cookie
, NULL
);
160 nv_reply
= xcb_query_extension_reply(conn
, nv_cookie
, NULL
);
161 if (!dri3_reply
|| !pres_reply
) {
166 vk_free(&wsi_dev
->instance_alloc
, wsi_conn
);
170 wsi_conn
->has_dri3
= dri3_reply
->present
!= 0;
171 #ifdef HAVE_DRI3_MODIFIERS
172 if (wsi_conn
->has_dri3
) {
173 xcb_dri3_query_version_cookie_t ver_cookie
;
174 xcb_dri3_query_version_reply_t
*ver_reply
;
176 ver_cookie
= xcb_dri3_query_version(conn
, 1, 2);
177 ver_reply
= xcb_dri3_query_version_reply(conn
, ver_cookie
, NULL
);
179 (ver_reply
->major_version
> 1 || ver_reply
->minor_version
>= 2);
184 wsi_conn
->has_present
= pres_reply
->present
!= 0;
185 #ifdef HAVE_DRI3_MODIFIERS
186 if (wsi_conn
->has_present
) {
187 xcb_present_query_version_cookie_t ver_cookie
;
188 xcb_present_query_version_reply_t
*ver_reply
;
190 ver_cookie
= xcb_present_query_version(conn
, 1, 2);
191 ver_reply
= xcb_present_query_version_reply(conn
, ver_cookie
, NULL
);
193 (ver_reply
->major_version
> 1 || ver_reply
->minor_version
>= 2);
198 wsi_conn
->has_dri3_modifiers
= has_dri3_v1_2
&& has_present_v1_2
;
199 wsi_conn
->is_proprietary_x11
= false;
200 if (amd_reply
&& amd_reply
->present
)
201 wsi_conn
->is_proprietary_x11
= true;
202 if (nv_reply
&& nv_reply
->present
)
203 wsi_conn
->is_proprietary_x11
= true;
214 wsi_x11_connection_destroy(struct wsi_device
*wsi_dev
,
215 struct wsi_x11_connection
*conn
)
217 vk_free(&wsi_dev
->instance_alloc
, conn
);
221 wsi_x11_check_for_dri3(struct wsi_x11_connection
*wsi_conn
)
223 if (wsi_conn
->has_dri3
)
225 if (!wsi_conn
->is_proprietary_x11
) {
226 fprintf(stderr
, "vulkan: No DRI3 support detected - required for presentation\n"
227 "Note: you can probably enable DRI3 in your Xorg config\n");
232 static struct wsi_x11_connection
*
233 wsi_x11_get_connection(struct wsi_device
*wsi_dev
,
234 xcb_connection_t
*conn
)
236 struct wsi_x11
*wsi
=
237 (struct wsi_x11
*)wsi_dev
->wsi
[VK_ICD_WSI_PLATFORM_XCB
];
239 pthread_mutex_lock(&wsi
->mutex
);
241 struct hash_entry
*entry
= _mesa_hash_table_search(wsi
->connections
, conn
);
243 /* We're about to make a bunch of blocking calls. Let's drop the
244 * mutex for now so we don't block up too badly.
246 pthread_mutex_unlock(&wsi
->mutex
);
248 struct wsi_x11_connection
*wsi_conn
=
249 wsi_x11_connection_create(wsi_dev
, conn
);
253 pthread_mutex_lock(&wsi
->mutex
);
255 entry
= _mesa_hash_table_search(wsi
->connections
, conn
);
257 /* Oops, someone raced us to it */
258 wsi_x11_connection_destroy(wsi_dev
, wsi_conn
);
260 entry
= _mesa_hash_table_insert(wsi
->connections
, conn
, wsi_conn
);
264 pthread_mutex_unlock(&wsi
->mutex
);
269 static const VkFormat formats
[] = {
270 VK_FORMAT_B8G8R8A8_SRGB
,
271 VK_FORMAT_B8G8R8A8_UNORM
,
274 static const VkPresentModeKHR present_modes
[] = {
275 VK_PRESENT_MODE_IMMEDIATE_KHR
,
276 VK_PRESENT_MODE_MAILBOX_KHR
,
277 VK_PRESENT_MODE_FIFO_KHR
,
280 static xcb_screen_t
*
281 get_screen_for_root(xcb_connection_t
*conn
, xcb_window_t root
)
283 xcb_screen_iterator_t screen_iter
=
284 xcb_setup_roots_iterator(xcb_get_setup(conn
));
286 for (; screen_iter
.rem
; xcb_screen_next (&screen_iter
)) {
287 if (screen_iter
.data
->root
== root
)
288 return screen_iter
.data
;
294 static xcb_visualtype_t
*
295 screen_get_visualtype(xcb_screen_t
*screen
, xcb_visualid_t visual_id
,
298 xcb_depth_iterator_t depth_iter
=
299 xcb_screen_allowed_depths_iterator(screen
);
301 for (; depth_iter
.rem
; xcb_depth_next (&depth_iter
)) {
302 xcb_visualtype_iterator_t visual_iter
=
303 xcb_depth_visuals_iterator (depth_iter
.data
);
305 for (; visual_iter
.rem
; xcb_visualtype_next (&visual_iter
)) {
306 if (visual_iter
.data
->visual_id
== visual_id
) {
308 *depth
= depth_iter
.data
->depth
;
309 return visual_iter
.data
;
317 static xcb_visualtype_t
*
318 connection_get_visualtype(xcb_connection_t
*conn
, xcb_visualid_t visual_id
,
321 xcb_screen_iterator_t screen_iter
=
322 xcb_setup_roots_iterator(xcb_get_setup(conn
));
324 /* For this we have to iterate over all of the screens which is rather
325 * annoying. Fortunately, there is probably only 1.
327 for (; screen_iter
.rem
; xcb_screen_next (&screen_iter
)) {
328 xcb_visualtype_t
*visual
= screen_get_visualtype(screen_iter
.data
,
337 static xcb_visualtype_t
*
338 get_visualtype_for_window(xcb_connection_t
*conn
, xcb_window_t window
,
341 xcb_query_tree_cookie_t tree_cookie
;
342 xcb_get_window_attributes_cookie_t attrib_cookie
;
343 xcb_query_tree_reply_t
*tree
;
344 xcb_get_window_attributes_reply_t
*attrib
;
346 tree_cookie
= xcb_query_tree(conn
, window
);
347 attrib_cookie
= xcb_get_window_attributes(conn
, window
);
349 tree
= xcb_query_tree_reply(conn
, tree_cookie
, NULL
);
350 attrib
= xcb_get_window_attributes_reply(conn
, attrib_cookie
, NULL
);
351 if (attrib
== NULL
|| tree
== NULL
) {
357 xcb_window_t root
= tree
->root
;
358 xcb_visualid_t visual_id
= attrib
->visual
;
362 xcb_screen_t
*screen
= get_screen_for_root(conn
, root
);
366 return screen_get_visualtype(screen
, visual_id
, depth
);
370 visual_has_alpha(xcb_visualtype_t
*visual
, unsigned depth
)
372 uint32_t rgb_mask
= visual
->red_mask
|
376 uint32_t all_mask
= 0xffffffff >> (32 - depth
);
378 /* Do we have bits left over after RGB? */
379 return (all_mask
& ~rgb_mask
) != 0;
382 VkBool32
wsi_get_physical_device_xcb_presentation_support(
383 struct wsi_device
*wsi_device
,
384 uint32_t queueFamilyIndex
,
386 bool can_handle_different_gpu
,
387 xcb_connection_t
* connection
,
388 xcb_visualid_t visual_id
)
390 struct wsi_x11_connection
*wsi_conn
=
391 wsi_x11_get_connection(wsi_device
, connection
);
396 if (!wsi_x11_check_for_dri3(wsi_conn
))
399 if (!can_handle_different_gpu
)
400 if (!wsi_x11_check_dri3_compatible(connection
, fd
))
403 unsigned visual_depth
;
404 if (!connection_get_visualtype(connection
, visual_id
, &visual_depth
))
407 if (visual_depth
!= 24 && visual_depth
!= 32)
413 static xcb_connection_t
*
414 x11_surface_get_connection(VkIcdSurfaceBase
*icd_surface
)
416 if (icd_surface
->platform
== VK_ICD_WSI_PLATFORM_XLIB
)
417 return XGetXCBConnection(((VkIcdSurfaceXlib
*)icd_surface
)->dpy
);
419 return ((VkIcdSurfaceXcb
*)icd_surface
)->connection
;
423 x11_surface_get_window(VkIcdSurfaceBase
*icd_surface
)
425 if (icd_surface
->platform
== VK_ICD_WSI_PLATFORM_XLIB
)
426 return ((VkIcdSurfaceXlib
*)icd_surface
)->window
;
428 return ((VkIcdSurfaceXcb
*)icd_surface
)->window
;
432 x11_surface_get_support(VkIcdSurfaceBase
*icd_surface
,
433 struct wsi_device
*wsi_device
,
434 uint32_t queueFamilyIndex
,
436 VkBool32
* pSupported
)
438 xcb_connection_t
*conn
= x11_surface_get_connection(icd_surface
);
439 xcb_window_t window
= x11_surface_get_window(icd_surface
);
441 struct wsi_x11_connection
*wsi_conn
=
442 wsi_x11_get_connection(wsi_device
, conn
);
444 return VK_ERROR_OUT_OF_HOST_MEMORY
;
446 if (!wsi_x11_check_for_dri3(wsi_conn
)) {
451 unsigned visual_depth
;
452 if (!get_visualtype_for_window(conn
, window
, &visual_depth
)) {
457 if (visual_depth
!= 24 && visual_depth
!= 32) {
467 x11_surface_get_capabilities(VkIcdSurfaceBase
*icd_surface
,
468 VkSurfaceCapabilitiesKHR
*caps
)
470 xcb_connection_t
*conn
= x11_surface_get_connection(icd_surface
);
471 xcb_window_t window
= x11_surface_get_window(icd_surface
);
472 xcb_get_geometry_cookie_t geom_cookie
;
473 xcb_generic_error_t
*err
;
474 xcb_get_geometry_reply_t
*geom
;
475 unsigned visual_depth
;
477 geom_cookie
= xcb_get_geometry(conn
, window
);
479 /* This does a round-trip. This is why we do get_geometry first and
480 * wait to read the reply until after we have a visual.
482 xcb_visualtype_t
*visual
=
483 get_visualtype_for_window(conn
, window
, &visual_depth
);
486 return VK_ERROR_SURFACE_LOST_KHR
;
488 geom
= xcb_get_geometry_reply(conn
, geom_cookie
, &err
);
490 VkExtent2D extent
= { geom
->width
, geom
->height
};
491 caps
->currentExtent
= extent
;
492 caps
->minImageExtent
= extent
;
493 caps
->maxImageExtent
= extent
;
495 /* This can happen if the client didn't wait for the configure event
496 * to come back from the compositor. In that case, we don't know the
497 * size of the window so we just return valid "I don't know" stuff.
499 caps
->currentExtent
= (VkExtent2D
) { -1, -1 };
500 caps
->minImageExtent
= (VkExtent2D
) { 1, 1 };
501 /* This is the maximum supported size on Intel */
502 caps
->maxImageExtent
= (VkExtent2D
) { 1 << 14, 1 << 14 };
507 if (visual_has_alpha(visual
, visual_depth
)) {
508 caps
->supportedCompositeAlpha
= VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR
|
509 VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR
;
511 caps
->supportedCompositeAlpha
= VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR
|
512 VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR
;
515 /* For true mailbox mode, we need at least 4 images:
516 * 1) One to scan out from
517 * 2) One to have queued for scan-out
518 * 3) One to be currently held by the X server
519 * 4) One to render to
521 caps
->minImageCount
= 2;
522 /* There is no real maximum */
523 caps
->maxImageCount
= 0;
525 caps
->supportedTransforms
= VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR
;
526 caps
->currentTransform
= VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR
;
527 caps
->maxImageArrayLayers
= 1;
528 caps
->supportedUsageFlags
=
529 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
530 VK_IMAGE_USAGE_SAMPLED_BIT
|
531 VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
532 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
538 x11_surface_get_capabilities2(VkIcdSurfaceBase
*icd_surface
,
539 const void *info_next
,
540 VkSurfaceCapabilities2KHR
*caps
)
542 assert(caps
->sType
== VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR
);
544 return x11_surface_get_capabilities(icd_surface
, &caps
->surfaceCapabilities
);
548 x11_surface_get_formats(VkIcdSurfaceBase
*surface
,
549 struct wsi_device
*wsi_device
,
550 uint32_t *pSurfaceFormatCount
,
551 VkSurfaceFormatKHR
*pSurfaceFormats
)
553 VK_OUTARRAY_MAKE(out
, pSurfaceFormats
, pSurfaceFormatCount
);
555 for (unsigned i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
556 vk_outarray_append(&out
, f
) {
557 f
->format
= formats
[i
];
558 f
->colorSpace
= VK_COLORSPACE_SRGB_NONLINEAR_KHR
;
562 return vk_outarray_status(&out
);
566 x11_surface_get_formats2(VkIcdSurfaceBase
*surface
,
567 struct wsi_device
*wsi_device
,
568 const void *info_next
,
569 uint32_t *pSurfaceFormatCount
,
570 VkSurfaceFormat2KHR
*pSurfaceFormats
)
572 VK_OUTARRAY_MAKE(out
, pSurfaceFormats
, pSurfaceFormatCount
);
574 for (unsigned i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
575 vk_outarray_append(&out
, f
) {
576 assert(f
->sType
== VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR
);
577 f
->surfaceFormat
.format
= formats
[i
];
578 f
->surfaceFormat
.colorSpace
= VK_COLORSPACE_SRGB_NONLINEAR_KHR
;
582 return vk_outarray_status(&out
);
586 x11_surface_get_present_modes(VkIcdSurfaceBase
*surface
,
587 uint32_t *pPresentModeCount
,
588 VkPresentModeKHR
*pPresentModes
)
590 if (pPresentModes
== NULL
) {
591 *pPresentModeCount
= ARRAY_SIZE(present_modes
);
595 *pPresentModeCount
= MIN2(*pPresentModeCount
, ARRAY_SIZE(present_modes
));
596 typed_memcpy(pPresentModes
, present_modes
, *pPresentModeCount
);
598 return *pPresentModeCount
< ARRAY_SIZE(present_modes
) ?
599 VK_INCOMPLETE
: VK_SUCCESS
;
602 VkResult
wsi_create_xcb_surface(const VkAllocationCallbacks
*pAllocator
,
603 const VkXcbSurfaceCreateInfoKHR
*pCreateInfo
,
604 VkSurfaceKHR
*pSurface
)
606 VkIcdSurfaceXcb
*surface
;
608 surface
= vk_alloc(pAllocator
, sizeof *surface
, 8,
609 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
611 return VK_ERROR_OUT_OF_HOST_MEMORY
;
613 surface
->base
.platform
= VK_ICD_WSI_PLATFORM_XCB
;
614 surface
->connection
= pCreateInfo
->connection
;
615 surface
->window
= pCreateInfo
->window
;
617 *pSurface
= VkIcdSurfaceBase_to_handle(&surface
->base
);
621 VkResult
wsi_create_xlib_surface(const VkAllocationCallbacks
*pAllocator
,
622 const VkXlibSurfaceCreateInfoKHR
*pCreateInfo
,
623 VkSurfaceKHR
*pSurface
)
625 VkIcdSurfaceXlib
*surface
;
627 surface
= vk_alloc(pAllocator
, sizeof *surface
, 8,
628 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
630 return VK_ERROR_OUT_OF_HOST_MEMORY
;
632 surface
->base
.platform
= VK_ICD_WSI_PLATFORM_XLIB
;
633 surface
->dpy
= pCreateInfo
->dpy
;
634 surface
->window
= pCreateInfo
->window
;
636 *pSurface
= VkIcdSurfaceBase_to_handle(&surface
->base
);
641 struct wsi_image base
;
644 struct xshmfence
* shm_fence
;
648 struct x11_swapchain
{
649 struct wsi_swapchain base
;
651 bool has_dri3_modifiers
;
653 xcb_connection_t
* conn
;
659 xcb_present_event_t event_id
;
660 xcb_special_event_t
* special_event
;
662 uint64_t last_present_msc
;
667 xcb_present_complete_mode_t last_present_mode
;
668 struct wsi_queue present_queue
;
669 struct wsi_queue acquire_queue
;
670 pthread_t queue_manager
;
672 struct x11_image images
[0];
676 * Update the swapchain status with the result of an operation, and return
677 * the combined status. The chain status will eventually be returned from
678 * AcquireNextImage and QueuePresent.
680 * We make sure to 'stick' more pessimistic statuses: an out-of-date error
681 * is permanent once seen, and every subsequent call will return this. If
682 * this has not been seen, success will be returned.
685 x11_swapchain_result(struct x11_swapchain
*chain
, VkResult result
)
687 /* Prioritise returning existing errors for consistency. */
688 if (chain
->status
< 0)
689 return chain
->status
;
691 /* If we have a new error, mark it as permanent on the chain and return. */
693 chain
->status
= result
;
697 /* Return temporary errors, but don't persist them. */
698 if (result
== VK_TIMEOUT
|| result
== VK_NOT_READY
)
701 /* Suboptimal isn't an error, but is a status which sticks to the swapchain
702 * and is always returned rather than success.
704 if (result
== VK_SUBOPTIMAL_KHR
) {
705 chain
->status
= result
;
709 /* No changes, so return the last status. */
710 return chain
->status
;
713 static struct wsi_image
*
714 x11_get_wsi_image(struct wsi_swapchain
*wsi_chain
, uint32_t image_index
)
716 struct x11_swapchain
*chain
= (struct x11_swapchain
*)wsi_chain
;
717 return &chain
->images
[image_index
].base
;
721 * Process an X11 Present event. Does not update chain->status.
724 x11_handle_dri3_present_event(struct x11_swapchain
*chain
,
725 xcb_present_generic_event_t
*event
)
727 switch (event
->evtype
) {
728 case XCB_PRESENT_CONFIGURE_NOTIFY
: {
729 xcb_present_configure_notify_event_t
*config
= (void *) event
;
731 if (config
->width
!= chain
->extent
.width
||
732 config
->height
!= chain
->extent
.height
)
733 return VK_ERROR_OUT_OF_DATE_KHR
;
738 case XCB_PRESENT_EVENT_IDLE_NOTIFY
: {
739 xcb_present_idle_notify_event_t
*idle
= (void *) event
;
741 for (unsigned i
= 0; i
< chain
->base
.image_count
; i
++) {
742 if (chain
->images
[i
].pixmap
== idle
->pixmap
) {
743 chain
->images
[i
].busy
= false;
745 wsi_queue_push(&chain
->acquire_queue
, i
);
753 case XCB_PRESENT_EVENT_COMPLETE_NOTIFY
: {
754 xcb_present_complete_notify_event_t
*complete
= (void *) event
;
755 if (complete
->kind
== XCB_PRESENT_COMPLETE_KIND_PIXMAP
)
756 chain
->last_present_msc
= complete
->msc
;
758 VkResult result
= VK_SUCCESS
;
760 /* The winsys is now trying to flip directly and cannot due to our
761 * configuration. Request the user reallocate.
763 #ifdef HAVE_DRI3_MODIFIERS
764 if (complete
->mode
== XCB_PRESENT_COMPLETE_MODE_SUBOPTIMAL_COPY
&&
765 chain
->last_present_mode
!= XCB_PRESENT_COMPLETE_MODE_SUBOPTIMAL_COPY
)
766 result
= VK_SUBOPTIMAL_KHR
;
769 /* When we go from flipping to copying, the odds are very likely that
770 * we could reallocate in a more optimal way if we didn't have to care
771 * about scanout, so we always do this.
773 if (complete
->mode
== XCB_PRESENT_COMPLETE_MODE_COPY
&&
774 chain
->last_present_mode
== XCB_PRESENT_COMPLETE_MODE_FLIP
)
775 result
= VK_SUBOPTIMAL_KHR
;
777 chain
->last_present_mode
= complete
->mode
;
789 static uint64_t wsi_get_current_time(void)
791 uint64_t current_time
;
794 clock_gettime(CLOCK_MONOTONIC
, &tv
);
795 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
799 static uint64_t wsi_get_absolute_timeout(uint64_t timeout
)
801 uint64_t current_time
= wsi_get_current_time();
803 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
805 return current_time
+ timeout
;
809 x11_acquire_next_image_poll_x11(struct x11_swapchain
*chain
,
810 uint32_t *image_index
, uint64_t timeout
)
812 xcb_generic_event_t
*event
;
816 for (uint32_t i
= 0; i
< chain
->base
.image_count
; i
++) {
817 if (!chain
->images
[i
].busy
) {
818 /* We found a non-busy image */
819 xshmfence_await(chain
->images
[i
].shm_fence
);
821 chain
->images
[i
].busy
= true;
822 return x11_swapchain_result(chain
, VK_SUCCESS
);
826 xcb_flush(chain
->conn
);
828 if (timeout
== UINT64_MAX
) {
829 event
= xcb_wait_for_special_event(chain
->conn
, chain
->special_event
);
831 return x11_swapchain_result(chain
, VK_ERROR_OUT_OF_DATE_KHR
);
833 event
= xcb_poll_for_special_event(chain
->conn
, chain
->special_event
);
837 return x11_swapchain_result(chain
, VK_NOT_READY
);
839 atimeout
= wsi_get_absolute_timeout(timeout
);
841 pfds
.fd
= xcb_get_file_descriptor(chain
->conn
);
842 pfds
.events
= POLLIN
;
843 ret
= poll(&pfds
, 1, timeout
/ 1000 / 1000);
845 return x11_swapchain_result(chain
, VK_TIMEOUT
);
847 return x11_swapchain_result(chain
, VK_ERROR_OUT_OF_DATE_KHR
);
849 /* If a non-special event happens, the fd will still
850 * poll. So recalculate the timeout now just in case.
852 uint64_t current_time
= wsi_get_current_time();
853 if (atimeout
> current_time
)
854 timeout
= atimeout
- current_time
;
861 /* Update the swapchain status here. We may catch non-fatal errors here,
862 * in which case we need to update the status and continue.
864 VkResult result
= x11_handle_dri3_present_event(chain
, (void *)event
);
867 return x11_swapchain_result(chain
, result
);
872 x11_acquire_next_image_from_queue(struct x11_swapchain
*chain
,
873 uint32_t *image_index_out
, uint64_t timeout
)
875 assert(chain
->threaded
);
877 uint32_t image_index
;
878 VkResult result
= wsi_queue_pull(&chain
->acquire_queue
,
879 &image_index
, timeout
);
880 if (result
< 0 || result
== VK_TIMEOUT
) {
881 /* On error, the thread has shut down, so safe to update chain->status.
882 * Calling x11_swapchain_result with VK_TIMEOUT won't modify
883 * chain->status so that is also safe.
885 return x11_swapchain_result(chain
, result
);
886 } else if (chain
->status
< 0) {
887 return chain
->status
;
890 assert(image_index
< chain
->base
.image_count
);
891 xshmfence_await(chain
->images
[image_index
].shm_fence
);
893 *image_index_out
= image_index
;
895 return chain
->status
;
899 x11_present_to_x11(struct x11_swapchain
*chain
, uint32_t image_index
,
902 struct x11_image
*image
= &chain
->images
[image_index
];
904 assert(image_index
< chain
->base
.image_count
);
906 uint32_t options
= XCB_PRESENT_OPTION_NONE
;
909 int64_t remainder
= 0;
911 if (chain
->base
.present_mode
== VK_PRESENT_MODE_IMMEDIATE_KHR
)
912 options
|= XCB_PRESENT_OPTION_ASYNC
;
914 #ifdef HAVE_DRI3_MODIFIERS
915 if (chain
->has_dri3_modifiers
)
916 options
|= XCB_PRESENT_OPTION_SUBOPTIMAL
;
919 xshmfence_reset(image
->shm_fence
);
922 xcb_void_cookie_t cookie
=
923 xcb_present_pixmap(chain
->conn
,
926 (uint32_t) chain
->send_sbc
,
931 XCB_NONE
, /* target_crtc */
938 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
941 xcb_flush(chain
->conn
);
943 return x11_swapchain_result(chain
, VK_SUCCESS
);
947 x11_acquire_next_image(struct wsi_swapchain
*anv_chain
,
948 const VkAcquireNextImageInfoKHR
*info
,
949 uint32_t *image_index
)
951 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
952 uint64_t timeout
= info
->timeout
;
954 if (chain
->threaded
) {
955 return x11_acquire_next_image_from_queue(chain
, image_index
, timeout
);
957 return x11_acquire_next_image_poll_x11(chain
, image_index
, timeout
);
962 x11_queue_present(struct wsi_swapchain
*anv_chain
,
963 uint32_t image_index
,
964 const VkPresentRegionKHR
*damage
)
966 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
968 if (chain
->threaded
) {
969 wsi_queue_push(&chain
->present_queue
, image_index
);
970 return chain
->status
;
972 return x11_present_to_x11(chain
, image_index
, 0);
977 x11_manage_fifo_queues(void *state
)
979 struct x11_swapchain
*chain
= state
;
980 VkResult result
= VK_SUCCESS
;
982 assert(chain
->base
.present_mode
== VK_PRESENT_MODE_FIFO_KHR
);
984 while (chain
->status
>= 0) {
985 /* It should be safe to unconditionally block here. Later in the loop
986 * we blocks until the previous present has landed on-screen. At that
987 * point, we should have received IDLE_NOTIFY on all images presented
988 * before that point so the client should be able to acquire any image
989 * other than the currently presented one.
991 uint32_t image_index
= 0;
992 result
= wsi_queue_pull(&chain
->present_queue
, &image_index
, INT64_MAX
);
993 assert(result
!= VK_TIMEOUT
);
996 } else if (chain
->status
< 0) {
997 /* The status can change underneath us if the swapchain is destroyed
998 * from another thread.
1003 uint64_t target_msc
= chain
->last_present_msc
+ 1;
1004 result
= x11_present_to_x11(chain
, image_index
, target_msc
);
1008 while (chain
->last_present_msc
< target_msc
) {
1009 xcb_generic_event_t
*event
=
1010 xcb_wait_for_special_event(chain
->conn
, chain
->special_event
);
1012 result
= VK_ERROR_OUT_OF_DATE_KHR
;
1016 result
= x11_handle_dri3_present_event(chain
, (void *)event
);
1024 x11_swapchain_result(chain
, result
);
1025 wsi_queue_push(&chain
->acquire_queue
, UINT32_MAX
);
1031 x11_image_init(VkDevice device_h
, struct x11_swapchain
*chain
,
1032 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
1033 const VkAllocationCallbacks
* pAllocator
,
1034 const uint64_t *const *modifiers
,
1035 const uint32_t *num_modifiers
,
1036 int num_tranches
, struct x11_image
*image
)
1038 xcb_void_cookie_t cookie
;
1042 if (chain
->base
.use_prime_blit
) {
1043 bool use_modifier
= num_tranches
> 0;
1044 result
= wsi_create_prime_image(&chain
->base
, pCreateInfo
, use_modifier
, &image
->base
);
1046 result
= wsi_create_native_image(&chain
->base
, pCreateInfo
,
1047 num_tranches
, num_modifiers
, modifiers
,
1053 image
->pixmap
= xcb_generate_id(chain
->conn
);
1055 #ifdef HAVE_DRI3_MODIFIERS
1056 if (image
->base
.drm_modifier
!= DRM_FORMAT_MOD_INVALID
) {
1057 /* If the image has a modifier, we must have DRI3 v1.2. */
1058 assert(chain
->has_dri3_modifiers
);
1061 xcb_dri3_pixmap_from_buffers_checked(chain
->conn
,
1064 image
->base
.num_planes
,
1065 pCreateInfo
->imageExtent
.width
,
1066 pCreateInfo
->imageExtent
.height
,
1067 image
->base
.row_pitches
[0],
1068 image
->base
.offsets
[0],
1069 image
->base
.row_pitches
[1],
1070 image
->base
.offsets
[1],
1071 image
->base
.row_pitches
[2],
1072 image
->base
.offsets
[2],
1073 image
->base
.row_pitches
[3],
1074 image
->base
.offsets
[3],
1076 image
->base
.drm_modifier
,
1081 /* Without passing modifiers, we can't have multi-plane RGB images. */
1082 assert(image
->base
.num_planes
== 1);
1085 xcb_dri3_pixmap_from_buffer_checked(chain
->conn
,
1088 image
->base
.sizes
[0],
1089 pCreateInfo
->imageExtent
.width
,
1090 pCreateInfo
->imageExtent
.height
,
1091 image
->base
.row_pitches
[0],
1093 image
->base
.fds
[0]);
1096 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
1098 /* XCB has now taken ownership of the FDs. */
1099 for (int i
= 0; i
< image
->base
.num_planes
; i
++)
1100 image
->base
.fds
[i
] = -1;
1102 int fence_fd
= xshmfence_alloc_shm();
1106 image
->shm_fence
= xshmfence_map_shm(fence_fd
);
1107 if (image
->shm_fence
== NULL
)
1108 goto fail_shmfence_alloc
;
1110 image
->sync_fence
= xcb_generate_id(chain
->conn
);
1111 xcb_dri3_fence_from_fd(chain
->conn
,
1117 image
->busy
= false;
1118 xshmfence_trigger(image
->shm_fence
);
1122 fail_shmfence_alloc
:
1126 cookie
= xcb_free_pixmap(chain
->conn
, image
->pixmap
);
1127 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
1129 wsi_destroy_image(&chain
->base
, &image
->base
);
1135 x11_image_finish(struct x11_swapchain
*chain
,
1136 const VkAllocationCallbacks
* pAllocator
,
1137 struct x11_image
*image
)
1139 xcb_void_cookie_t cookie
;
1141 cookie
= xcb_sync_destroy_fence(chain
->conn
, image
->sync_fence
);
1142 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
1143 xshmfence_unmap_shm(image
->shm_fence
);
1145 cookie
= xcb_free_pixmap(chain
->conn
, image
->pixmap
);
1146 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
1148 wsi_destroy_image(&chain
->base
, &image
->base
);
1152 wsi_x11_get_dri3_modifiers(struct wsi_x11_connection
*wsi_conn
,
1153 xcb_connection_t
*conn
, xcb_window_t window
,
1154 uint8_t depth
, uint8_t bpp
,
1155 VkCompositeAlphaFlagsKHR vk_alpha
,
1156 uint64_t **modifiers_in
, uint32_t *num_modifiers_in
,
1157 uint32_t *num_tranches_in
,
1158 const VkAllocationCallbacks
*pAllocator
)
1160 if (!wsi_conn
->has_dri3_modifiers
)
1163 #ifdef HAVE_DRI3_MODIFIERS
1164 xcb_generic_error_t
*error
= NULL
;
1165 xcb_dri3_get_supported_modifiers_cookie_t mod_cookie
=
1166 xcb_dri3_get_supported_modifiers(conn
, window
, depth
, bpp
);
1167 xcb_dri3_get_supported_modifiers_reply_t
*mod_reply
=
1168 xcb_dri3_get_supported_modifiers_reply(conn
, mod_cookie
, &error
);
1171 if (!mod_reply
|| (mod_reply
->num_window_modifiers
== 0 &&
1172 mod_reply
->num_screen_modifiers
== 0)) {
1179 uint64_t *modifiers
[2];
1181 if (mod_reply
->num_window_modifiers
) {
1182 counts
[n
] = mod_reply
->num_window_modifiers
;
1183 modifiers
[n
] = vk_alloc(pAllocator
,
1184 counts
[n
] * sizeof(uint64_t),
1185 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1186 if (!modifiers
[n
]) {
1191 memcpy(modifiers
[n
],
1192 xcb_dri3_get_supported_modifiers_window_modifiers(mod_reply
),
1193 counts
[n
] * sizeof(uint64_t));
1197 if (mod_reply
->num_screen_modifiers
) {
1198 counts
[n
] = mod_reply
->num_screen_modifiers
;
1199 modifiers
[n
] = vk_alloc(pAllocator
,
1200 counts
[n
] * sizeof(uint64_t),
1201 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1202 if (!modifiers
[n
]) {
1204 vk_free(pAllocator
, modifiers
[0]);
1209 memcpy(modifiers
[n
],
1210 xcb_dri3_get_supported_modifiers_screen_modifiers(mod_reply
),
1211 counts
[n
] * sizeof(uint64_t));
1215 for (int i
= 0; i
< n
; i
++) {
1216 modifiers_in
[i
] = modifiers
[i
];
1217 num_modifiers_in
[i
] = counts
[i
];
1219 *num_tranches_in
= n
;
1225 *num_tranches_in
= 0;
1229 x11_swapchain_destroy(struct wsi_swapchain
*anv_chain
,
1230 const VkAllocationCallbacks
*pAllocator
)
1232 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
1233 xcb_void_cookie_t cookie
;
1235 if (chain
->threaded
) {
1236 chain
->status
= VK_ERROR_OUT_OF_DATE_KHR
;
1237 /* Push a UINT32_MAX to wake up the manager */
1238 wsi_queue_push(&chain
->present_queue
, UINT32_MAX
);
1239 pthread_join(chain
->queue_manager
, NULL
);
1240 wsi_queue_destroy(&chain
->acquire_queue
);
1241 wsi_queue_destroy(&chain
->present_queue
);
1244 for (uint32_t i
= 0; i
< chain
->base
.image_count
; i
++)
1245 x11_image_finish(chain
, pAllocator
, &chain
->images
[i
]);
1247 xcb_unregister_for_special_event(chain
->conn
, chain
->special_event
);
1248 cookie
= xcb_present_select_input_checked(chain
->conn
, chain
->event_id
,
1250 XCB_PRESENT_EVENT_MASK_NO_EVENT
);
1251 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
1253 wsi_swapchain_finish(&chain
->base
);
1255 vk_free(pAllocator
, chain
);
1261 x11_surface_create_swapchain(VkIcdSurfaceBase
*icd_surface
,
1263 struct wsi_device
*wsi_device
,
1265 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
1266 const VkAllocationCallbacks
* pAllocator
,
1267 struct wsi_swapchain
**swapchain_out
)
1269 struct x11_swapchain
*chain
;
1270 xcb_void_cookie_t cookie
;
1273 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
);
1275 const unsigned num_images
= pCreateInfo
->minImageCount
;
1277 xcb_connection_t
*conn
= x11_surface_get_connection(icd_surface
);
1278 struct wsi_x11_connection
*wsi_conn
=
1279 wsi_x11_get_connection(wsi_device
, conn
);
1281 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1283 /* Check for whether or not we have a window up-front */
1284 xcb_window_t window
= x11_surface_get_window(icd_surface
);
1285 xcb_get_geometry_reply_t
*geometry
=
1286 xcb_get_geometry_reply(conn
, xcb_get_geometry(conn
, window
), NULL
);
1287 if (geometry
== NULL
)
1288 return VK_ERROR_SURFACE_LOST_KHR
;
1289 const uint32_t bit_depth
= geometry
->depth
;
1292 size_t size
= sizeof(*chain
) + num_images
* sizeof(chain
->images
[0]);
1293 chain
= vk_alloc(pAllocator
, size
, 8,
1294 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1296 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1298 result
= wsi_swapchain_init(wsi_device
, &chain
->base
, device
,
1299 pCreateInfo
, pAllocator
);
1300 if (result
!= VK_SUCCESS
)
1303 chain
->base
.destroy
= x11_swapchain_destroy
;
1304 chain
->base
.get_wsi_image
= x11_get_wsi_image
;
1305 chain
->base
.acquire_next_image
= x11_acquire_next_image
;
1306 chain
->base
.queue_present
= x11_queue_present
;
1307 chain
->base
.present_mode
= pCreateInfo
->presentMode
;
1308 chain
->base
.image_count
= num_images
;
1310 chain
->window
= window
;
1311 chain
->depth
= bit_depth
;
1312 chain
->extent
= pCreateInfo
->imageExtent
;
1313 chain
->send_sbc
= 0;
1314 chain
->last_present_msc
= 0;
1315 chain
->threaded
= false;
1316 chain
->status
= VK_SUCCESS
;
1317 chain
->has_dri3_modifiers
= wsi_conn
->has_dri3_modifiers
;
1319 /* If we are reallocating from an old swapchain, then we inherit its
1320 * last completion mode, to ensure we don't get into reallocation
1321 * cycles. If we are starting anew, we set 'COPY', as that is the only
1322 * mode which provokes reallocation when anything changes, to make
1323 * sure we have the most optimal allocation.
1325 struct x11_swapchain
*old_chain
= (void *)(intptr_t) pCreateInfo
->oldSwapchain
;
1327 chain
->last_present_mode
= old_chain
->last_present_mode
;
1329 chain
->last_present_mode
= XCB_PRESENT_COMPLETE_MODE_COPY
;
1331 if (!wsi_x11_check_dri3_compatible(conn
, local_fd
))
1332 chain
->base
.use_prime_blit
= true;
1334 chain
->event_id
= xcb_generate_id(chain
->conn
);
1335 xcb_present_select_input(chain
->conn
, chain
->event_id
, chain
->window
,
1336 XCB_PRESENT_EVENT_MASK_CONFIGURE_NOTIFY
|
1337 XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY
|
1338 XCB_PRESENT_EVENT_MASK_IDLE_NOTIFY
);
1340 /* Create an XCB event queue to hold present events outside of the usual
1341 * application event queue
1343 chain
->special_event
=
1344 xcb_register_for_special_xge(chain
->conn
, &xcb_present_id
,
1345 chain
->event_id
, NULL
);
1347 chain
->gc
= xcb_generate_id(chain
->conn
);
1349 /* FINISHME: Choose a better error. */
1350 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1354 cookie
= xcb_create_gc(chain
->conn
,
1357 XCB_GC_GRAPHICS_EXPOSURES
,
1358 (uint32_t []) { 0 });
1359 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
1361 uint64_t *modifiers
[2] = {NULL
, NULL
};
1362 uint32_t num_modifiers
[2] = {0, 0};
1363 uint32_t num_tranches
= 0;
1364 if (wsi_device
->supports_modifiers
)
1365 wsi_x11_get_dri3_modifiers(wsi_conn
, conn
, window
, chain
->depth
, 32,
1366 pCreateInfo
->compositeAlpha
,
1367 modifiers
, num_modifiers
, &num_tranches
,
1371 for (; image
< chain
->base
.image_count
; image
++) {
1372 result
= x11_image_init(device
, chain
, pCreateInfo
, pAllocator
,
1373 (const uint64_t *const *)modifiers
,
1374 num_modifiers
, num_tranches
,
1375 &chain
->images
[image
]);
1376 if (result
!= VK_SUCCESS
)
1377 goto fail_init_images
;
1380 if (chain
->base
.present_mode
== VK_PRESENT_MODE_FIFO_KHR
) {
1381 chain
->threaded
= true;
1383 /* Initialize our queues. We make them base.image_count + 1 because we will
1384 * occasionally use UINT32_MAX to signal the other thread that an error
1385 * has occurred and we don't want an overflow.
1388 ret
= wsi_queue_init(&chain
->acquire_queue
, chain
->base
.image_count
+ 1);
1390 goto fail_init_images
;
1393 ret
= wsi_queue_init(&chain
->present_queue
, chain
->base
.image_count
+ 1);
1395 wsi_queue_destroy(&chain
->acquire_queue
);
1396 goto fail_init_images
;
1399 for (unsigned i
= 0; i
< chain
->base
.image_count
; i
++)
1400 wsi_queue_push(&chain
->acquire_queue
, i
);
1402 ret
= pthread_create(&chain
->queue_manager
, NULL
,
1403 x11_manage_fifo_queues
, chain
);
1405 wsi_queue_destroy(&chain
->present_queue
);
1406 wsi_queue_destroy(&chain
->acquire_queue
);
1407 goto fail_init_images
;
1411 for (int i
= 0; i
< ARRAY_SIZE(modifiers
); i
++)
1412 vk_free(pAllocator
, modifiers
[i
]);
1413 *swapchain_out
= &chain
->base
;
1418 for (uint32_t j
= 0; j
< image
; j
++)
1419 x11_image_finish(chain
, pAllocator
, &chain
->images
[j
]);
1421 for (int i
= 0; i
< ARRAY_SIZE(modifiers
); i
++)
1422 vk_free(pAllocator
, modifiers
[i
]);
1425 xcb_unregister_for_special_event(chain
->conn
, chain
->special_event
);
1427 wsi_swapchain_finish(&chain
->base
);
1430 vk_free(pAllocator
, chain
);
1436 wsi_x11_init_wsi(struct wsi_device
*wsi_device
,
1437 const VkAllocationCallbacks
*alloc
)
1439 struct wsi_x11
*wsi
;
1442 wsi
= vk_alloc(alloc
, sizeof(*wsi
), 8,
1443 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
1445 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1449 int ret
= pthread_mutex_init(&wsi
->mutex
, NULL
);
1451 if (ret
== ENOMEM
) {
1452 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1454 /* FINISHME: Choose a better error. */
1455 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1461 wsi
->connections
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
1462 _mesa_key_pointer_equal
);
1463 if (!wsi
->connections
) {
1464 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1468 wsi
->base
.get_support
= x11_surface_get_support
;
1469 wsi
->base
.get_capabilities2
= x11_surface_get_capabilities2
;
1470 wsi
->base
.get_formats
= x11_surface_get_formats
;
1471 wsi
->base
.get_formats2
= x11_surface_get_formats2
;
1472 wsi
->base
.get_present_modes
= x11_surface_get_present_modes
;
1473 wsi
->base
.create_swapchain
= x11_surface_create_swapchain
;
1475 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XCB
] = &wsi
->base
;
1476 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XLIB
] = &wsi
->base
;
1481 pthread_mutex_destroy(&wsi
->mutex
);
1483 vk_free(alloc
, wsi
);
1485 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XCB
] = NULL
;
1486 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XLIB
] = NULL
;
1492 wsi_x11_finish_wsi(struct wsi_device
*wsi_device
,
1493 const VkAllocationCallbacks
*alloc
)
1495 struct wsi_x11
*wsi
=
1496 (struct wsi_x11
*)wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XCB
];
1499 struct hash_entry
*entry
;
1500 hash_table_foreach(wsi
->connections
, entry
)
1501 wsi_x11_connection_destroy(wsi_device
, entry
->data
);
1503 _mesa_hash_table_destroy(wsi
->connections
, NULL
);
1505 pthread_mutex_destroy(&wsi
->mutex
);
1507 vk_free(alloc
, wsi
);