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"
37 #include "util/hash_table.h"
39 #include "wsi_common.h"
40 #include "wsi_common_x11.h"
42 #define typed_memcpy(dest, src, count) ({ \
43 static_assert(sizeof(*src) == sizeof(*dest), ""); \
44 memcpy((dest), (src), (count) * sizeof(*(src))); \
47 struct wsi_x11_connection
{
53 struct wsi_interface base
;
55 pthread_mutex_t mutex
;
56 /* Hash table of xcb_connection -> wsi_x11_connection mappings */
57 struct hash_table
*connections
;
60 static struct wsi_x11_connection
*
61 wsi_x11_connection_create(const VkAllocationCallbacks
*alloc
,
62 xcb_connection_t
*conn
)
64 xcb_query_extension_cookie_t dri3_cookie
, pres_cookie
;
65 xcb_query_extension_reply_t
*dri3_reply
, *pres_reply
;
67 struct wsi_x11_connection
*wsi_conn
=
68 vk_alloc(alloc
, sizeof(*wsi_conn
), 8,
69 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
73 dri3_cookie
= xcb_query_extension(conn
, 4, "DRI3");
74 pres_cookie
= xcb_query_extension(conn
, 7, "PRESENT");
76 dri3_reply
= xcb_query_extension_reply(conn
, dri3_cookie
, NULL
);
77 pres_reply
= xcb_query_extension_reply(conn
, pres_cookie
, NULL
);
78 if (dri3_reply
== NULL
|| pres_reply
== NULL
) {
81 vk_free(alloc
, wsi_conn
);
85 wsi_conn
->has_dri3
= dri3_reply
->present
!= 0;
86 wsi_conn
->has_present
= pres_reply
->present
!= 0;
95 wsi_x11_connection_destroy(const VkAllocationCallbacks
*alloc
,
96 struct wsi_x11_connection
*conn
)
101 static struct wsi_x11_connection
*
102 wsi_x11_get_connection(struct wsi_device
*wsi_dev
,
103 const VkAllocationCallbacks
*alloc
,
104 xcb_connection_t
*conn
)
106 struct wsi_x11
*wsi
=
107 (struct wsi_x11
*)wsi_dev
->wsi
[VK_ICD_WSI_PLATFORM_XCB
];
109 pthread_mutex_lock(&wsi
->mutex
);
111 struct hash_entry
*entry
= _mesa_hash_table_search(wsi
->connections
, conn
);
113 /* We're about to make a bunch of blocking calls. Let's drop the
114 * mutex for now so we don't block up too badly.
116 pthread_mutex_unlock(&wsi
->mutex
);
118 struct wsi_x11_connection
*wsi_conn
=
119 wsi_x11_connection_create(alloc
, conn
);
121 pthread_mutex_lock(&wsi
->mutex
);
123 entry
= _mesa_hash_table_search(wsi
->connections
, conn
);
125 /* Oops, someone raced us to it */
126 wsi_x11_connection_destroy(alloc
, wsi_conn
);
128 entry
= _mesa_hash_table_insert(wsi
->connections
, conn
, wsi_conn
);
132 pthread_mutex_unlock(&wsi
->mutex
);
137 static const VkSurfaceFormatKHR formats
[] = {
138 { .format
= VK_FORMAT_B8G8R8A8_SRGB
, },
139 { .format
= VK_FORMAT_B8G8R8A8_UNORM
, },
142 static const VkPresentModeKHR present_modes
[] = {
143 VK_PRESENT_MODE_MAILBOX_KHR
,
146 static xcb_screen_t
*
147 get_screen_for_root(xcb_connection_t
*conn
, xcb_window_t root
)
149 xcb_screen_iterator_t screen_iter
=
150 xcb_setup_roots_iterator(xcb_get_setup(conn
));
152 for (; screen_iter
.rem
; xcb_screen_next (&screen_iter
)) {
153 if (screen_iter
.data
->root
== root
)
154 return screen_iter
.data
;
160 static xcb_visualtype_t
*
161 screen_get_visualtype(xcb_screen_t
*screen
, xcb_visualid_t visual_id
,
164 xcb_depth_iterator_t depth_iter
=
165 xcb_screen_allowed_depths_iterator(screen
);
167 for (; depth_iter
.rem
; xcb_depth_next (&depth_iter
)) {
168 xcb_visualtype_iterator_t visual_iter
=
169 xcb_depth_visuals_iterator (depth_iter
.data
);
171 for (; visual_iter
.rem
; xcb_visualtype_next (&visual_iter
)) {
172 if (visual_iter
.data
->visual_id
== visual_id
) {
174 *depth
= depth_iter
.data
->depth
;
175 return visual_iter
.data
;
183 static xcb_visualtype_t
*
184 connection_get_visualtype(xcb_connection_t
*conn
, xcb_visualid_t visual_id
,
187 xcb_screen_iterator_t screen_iter
=
188 xcb_setup_roots_iterator(xcb_get_setup(conn
));
190 /* For this we have to iterate over all of the screens which is rather
191 * annoying. Fortunately, there is probably only 1.
193 for (; screen_iter
.rem
; xcb_screen_next (&screen_iter
)) {
194 xcb_visualtype_t
*visual
= screen_get_visualtype(screen_iter
.data
,
203 static xcb_visualtype_t
*
204 get_visualtype_for_window(xcb_connection_t
*conn
, xcb_window_t window
,
207 xcb_query_tree_cookie_t tree_cookie
;
208 xcb_get_window_attributes_cookie_t attrib_cookie
;
209 xcb_query_tree_reply_t
*tree
;
210 xcb_get_window_attributes_reply_t
*attrib
;
212 tree_cookie
= xcb_query_tree(conn
, window
);
213 attrib_cookie
= xcb_get_window_attributes(conn
, window
);
215 tree
= xcb_query_tree_reply(conn
, tree_cookie
, NULL
);
216 attrib
= xcb_get_window_attributes_reply(conn
, attrib_cookie
, NULL
);
217 if (attrib
== NULL
|| tree
== NULL
) {
223 xcb_window_t root
= tree
->root
;
224 xcb_visualid_t visual_id
= attrib
->visual
;
228 xcb_screen_t
*screen
= get_screen_for_root(conn
, root
);
232 return screen_get_visualtype(screen
, visual_id
, depth
);
236 visual_has_alpha(xcb_visualtype_t
*visual
, unsigned depth
)
238 uint32_t rgb_mask
= visual
->red_mask
|
242 uint32_t all_mask
= 0xffffffff >> (32 - depth
);
244 /* Do we have bits left over after RGB? */
245 return (all_mask
& ~rgb_mask
) != 0;
248 VkBool32
wsi_get_physical_device_xcb_presentation_support(
249 struct wsi_device
*wsi_device
,
250 VkAllocationCallbacks
*alloc
,
251 uint32_t queueFamilyIndex
,
252 xcb_connection_t
* connection
,
253 xcb_visualid_t visual_id
)
255 struct wsi_x11_connection
*wsi_conn
=
256 wsi_x11_get_connection(wsi_device
, alloc
, connection
);
258 if (!wsi_conn
->has_dri3
) {
259 fprintf(stderr
, "vulkan: No DRI3 support\n");
263 unsigned visual_depth
;
264 if (!connection_get_visualtype(connection
, visual_id
, &visual_depth
))
267 if (visual_depth
!= 24 && visual_depth
!= 32)
273 static xcb_connection_t
*
274 x11_surface_get_connection(VkIcdSurfaceBase
*icd_surface
)
276 if (icd_surface
->platform
== VK_ICD_WSI_PLATFORM_XLIB
)
277 return XGetXCBConnection(((VkIcdSurfaceXlib
*)icd_surface
)->dpy
);
279 return ((VkIcdSurfaceXcb
*)icd_surface
)->connection
;
283 x11_surface_get_window(VkIcdSurfaceBase
*icd_surface
)
285 if (icd_surface
->platform
== VK_ICD_WSI_PLATFORM_XLIB
)
286 return ((VkIcdSurfaceXlib
*)icd_surface
)->window
;
288 return ((VkIcdSurfaceXcb
*)icd_surface
)->window
;
292 x11_surface_get_support(VkIcdSurfaceBase
*icd_surface
,
293 struct wsi_device
*wsi_device
,
294 const VkAllocationCallbacks
*alloc
,
295 uint32_t queueFamilyIndex
,
296 VkBool32
* pSupported
)
298 xcb_connection_t
*conn
= x11_surface_get_connection(icd_surface
);
299 xcb_window_t window
= x11_surface_get_window(icd_surface
);
301 struct wsi_x11_connection
*wsi_conn
=
302 wsi_x11_get_connection(wsi_device
, alloc
, conn
);
304 return VK_ERROR_OUT_OF_HOST_MEMORY
;
306 if (!wsi_conn
->has_dri3
) {
307 fprintf(stderr
, "vulkan: No DRI3 support\n");
312 unsigned visual_depth
;
313 if (!get_visualtype_for_window(conn
, window
, &visual_depth
)) {
318 if (visual_depth
!= 24 && visual_depth
!= 32) {
328 x11_surface_get_capabilities(VkIcdSurfaceBase
*icd_surface
,
329 VkSurfaceCapabilitiesKHR
*caps
)
331 xcb_connection_t
*conn
= x11_surface_get_connection(icd_surface
);
332 xcb_window_t window
= x11_surface_get_window(icd_surface
);
333 xcb_get_geometry_cookie_t geom_cookie
;
334 xcb_generic_error_t
*err
;
335 xcb_get_geometry_reply_t
*geom
;
336 unsigned visual_depth
;
338 geom_cookie
= xcb_get_geometry(conn
, window
);
340 /* This does a round-trip. This is why we do get_geometry first and
341 * wait to read the reply until after we have a visual.
343 xcb_visualtype_t
*visual
=
344 get_visualtype_for_window(conn
, window
, &visual_depth
);
346 geom
= xcb_get_geometry_reply(conn
, geom_cookie
, &err
);
348 VkExtent2D extent
= { geom
->width
, geom
->height
};
349 caps
->currentExtent
= extent
;
350 caps
->minImageExtent
= extent
;
351 caps
->maxImageExtent
= extent
;
353 /* This can happen if the client didn't wait for the configure event
354 * to come back from the compositor. In that case, we don't know the
355 * size of the window so we just return valid "I don't know" stuff.
357 caps
->currentExtent
= (VkExtent2D
) { -1, -1 };
358 caps
->minImageExtent
= (VkExtent2D
) { 1, 1 };
359 caps
->maxImageExtent
= (VkExtent2D
) { INT16_MAX
, INT16_MAX
};
364 if (visual_has_alpha(visual
, visual_depth
)) {
365 caps
->supportedCompositeAlpha
= VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR
|
366 VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR
;
368 caps
->supportedCompositeAlpha
= VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR
|
369 VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR
;
372 caps
->minImageCount
= 2;
373 caps
->maxImageCount
= 4;
374 caps
->supportedTransforms
= VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR
;
375 caps
->currentTransform
= VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR
;
376 caps
->maxImageArrayLayers
= 1;
377 caps
->supportedUsageFlags
=
378 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
379 VK_IMAGE_USAGE_SAMPLED_BIT
|
380 VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
381 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
387 x11_surface_get_formats(VkIcdSurfaceBase
*surface
,
388 struct wsi_device
*wsi_device
,
389 uint32_t *pSurfaceFormatCount
,
390 VkSurfaceFormatKHR
*pSurfaceFormats
)
392 if (pSurfaceFormats
== NULL
) {
393 *pSurfaceFormatCount
= ARRAY_SIZE(formats
);
397 VkResult result
= VK_SUCCESS
;
399 if (*pSurfaceFormatCount
> ARRAY_SIZE(formats
))
400 *pSurfaceFormatCount
= ARRAY_SIZE(formats
);
401 else if (*pSurfaceFormatCount
< ARRAY_SIZE(formats
))
402 result
= VK_INCOMPLETE
;
404 typed_memcpy(pSurfaceFormats
, formats
, *pSurfaceFormatCount
);
410 x11_surface_get_present_modes(VkIcdSurfaceBase
*surface
,
411 uint32_t *pPresentModeCount
,
412 VkPresentModeKHR
*pPresentModes
)
414 if (pPresentModes
== NULL
) {
415 *pPresentModeCount
= ARRAY_SIZE(present_modes
);
419 assert(*pPresentModeCount
>= ARRAY_SIZE(present_modes
));
420 typed_memcpy(pPresentModes
, present_modes
, *pPresentModeCount
);
421 *pPresentModeCount
= ARRAY_SIZE(present_modes
);
426 VkResult
wsi_create_xcb_surface(const VkAllocationCallbacks
*pAllocator
,
427 const VkXcbSurfaceCreateInfoKHR
*pCreateInfo
,
428 VkSurfaceKHR
*pSurface
)
430 VkIcdSurfaceXcb
*surface
;
432 surface
= vk_alloc(pAllocator
, sizeof *surface
, 8,
433 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
435 return VK_ERROR_OUT_OF_HOST_MEMORY
;
437 surface
->base
.platform
= VK_ICD_WSI_PLATFORM_XCB
;
438 surface
->connection
= pCreateInfo
->connection
;
439 surface
->window
= pCreateInfo
->window
;
441 *pSurface
= _VkIcdSurfaceBase_to_handle(&surface
->base
);
445 VkResult
wsi_create_xlib_surface(const VkAllocationCallbacks
*pAllocator
,
446 const VkXlibSurfaceCreateInfoKHR
*pCreateInfo
,
447 VkSurfaceKHR
*pSurface
)
449 VkIcdSurfaceXlib
*surface
;
451 surface
= vk_alloc(pAllocator
, sizeof *surface
, 8,
452 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
454 return VK_ERROR_OUT_OF_HOST_MEMORY
;
456 surface
->base
.platform
= VK_ICD_WSI_PLATFORM_XLIB
;
457 surface
->dpy
= pCreateInfo
->dpy
;
458 surface
->window
= pCreateInfo
->window
;
460 *pSurface
= _VkIcdSurfaceBase_to_handle(&surface
->base
);
466 VkDeviceMemory memory
;
469 struct xshmfence
* shm_fence
;
473 struct x11_swapchain
{
474 struct wsi_swapchain base
;
476 xcb_connection_t
* conn
;
480 uint32_t image_count
;
482 xcb_present_event_t event_id
;
483 xcb_special_event_t
* special_event
;
487 struct x11_image images
[0];
491 x11_get_images(struct wsi_swapchain
*anv_chain
,
492 uint32_t* pCount
, VkImage
*pSwapchainImages
)
494 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
496 if (pSwapchainImages
== NULL
) {
497 *pCount
= chain
->image_count
;
501 assert(chain
->image_count
<= *pCount
);
502 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
503 pSwapchainImages
[i
] = chain
->images
[i
].image
;
505 *pCount
= chain
->image_count
;
511 x11_handle_dri3_present_event(struct x11_swapchain
*chain
,
512 xcb_present_generic_event_t
*event
)
514 switch (event
->evtype
) {
515 case XCB_PRESENT_CONFIGURE_NOTIFY
: {
516 xcb_present_configure_notify_event_t
*config
= (void *) event
;
518 if (config
->width
!= chain
->extent
.width
||
519 config
->height
!= chain
->extent
.height
)
520 return VK_ERROR_OUT_OF_DATE_KHR
;
525 case XCB_PRESENT_EVENT_IDLE_NOTIFY
: {
526 xcb_present_idle_notify_event_t
*idle
= (void *) event
;
528 for (unsigned i
= 0; i
< chain
->image_count
; i
++) {
529 if (chain
->images
[i
].pixmap
== idle
->pixmap
) {
530 chain
->images
[i
].busy
= false;
538 case XCB_PRESENT_COMPLETE_NOTIFY
:
547 x11_acquire_next_image(struct wsi_swapchain
*anv_chain
,
549 VkSemaphore semaphore
,
550 uint32_t *image_index
)
552 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
555 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
556 if (!chain
->images
[i
].busy
) {
557 /* We found a non-busy image */
558 xshmfence_await(chain
->images
[i
].shm_fence
);
560 chain
->images
[i
].busy
= true;
565 xcb_flush(chain
->conn
);
566 xcb_generic_event_t
*event
=
567 xcb_wait_for_special_event(chain
->conn
, chain
->special_event
);
569 return VK_ERROR_OUT_OF_DATE_KHR
;
571 VkResult result
= x11_handle_dri3_present_event(chain
, (void *)event
);
573 if (result
!= VK_SUCCESS
)
579 x11_queue_present(struct wsi_swapchain
*anv_chain
,
580 uint32_t image_index
)
582 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
583 struct x11_image
*image
= &chain
->images
[image_index
];
585 assert(image_index
< chain
->image_count
);
587 uint32_t options
= XCB_PRESENT_OPTION_NONE
;
589 int64_t target_msc
= 0;
591 int64_t remainder
= 0;
593 options
|= XCB_PRESENT_OPTION_ASYNC
;
595 xshmfence_reset(image
->shm_fence
);
598 xcb_void_cookie_t cookie
=
599 xcb_present_pixmap(chain
->conn
,
602 (uint32_t) chain
->send_sbc
,
607 XCB_NONE
, /* target_crtc */
614 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
617 xcb_flush(chain
->conn
);
623 x11_image_init(VkDevice device_h
, struct x11_swapchain
*chain
,
624 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
625 const VkAllocationCallbacks
* pAllocator
,
626 struct x11_image
*image
)
628 xcb_void_cookie_t cookie
;
637 result
= chain
->base
.image_fns
->create_wsi_image(device_h
,
646 if (result
!= VK_SUCCESS
)
649 image
->pixmap
= xcb_generate_id(chain
->conn
);
652 xcb_dri3_pixmap_from_buffer_checked(chain
->conn
,
656 pCreateInfo
->imageExtent
.width
,
657 pCreateInfo
->imageExtent
.height
,
660 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
662 int fence_fd
= xshmfence_alloc_shm();
666 image
->shm_fence
= xshmfence_map_shm(fence_fd
);
667 if (image
->shm_fence
== NULL
)
668 goto fail_shmfence_alloc
;
670 image
->sync_fence
= xcb_generate_id(chain
->conn
);
671 xcb_dri3_fence_from_fd(chain
->conn
,
678 xshmfence_trigger(image
->shm_fence
);
686 cookie
= xcb_free_pixmap(chain
->conn
, image
->pixmap
);
687 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
689 chain
->base
.image_fns
->free_wsi_image(device_h
, pAllocator
,
690 image
->image
, image
->memory
);
696 x11_image_finish(struct x11_swapchain
*chain
,
697 const VkAllocationCallbacks
* pAllocator
,
698 struct x11_image
*image
)
700 xcb_void_cookie_t cookie
;
702 cookie
= xcb_sync_destroy_fence(chain
->conn
, image
->sync_fence
);
703 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
704 xshmfence_unmap_shm(image
->shm_fence
);
706 cookie
= xcb_free_pixmap(chain
->conn
, image
->pixmap
);
707 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
709 chain
->base
.image_fns
->free_wsi_image(chain
->base
.device
, pAllocator
,
710 image
->image
, image
->memory
);
714 x11_swapchain_destroy(struct wsi_swapchain
*anv_chain
,
715 const VkAllocationCallbacks
*pAllocator
)
717 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
718 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
719 x11_image_finish(chain
, pAllocator
, &chain
->images
[i
]);
721 xcb_unregister_for_special_event(chain
->conn
, chain
->special_event
);
723 vk_free(pAllocator
, chain
);
729 x11_surface_create_swapchain(VkIcdSurfaceBase
*icd_surface
,
731 struct wsi_device
*wsi_device
,
732 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
733 const VkAllocationCallbacks
* pAllocator
,
734 const struct wsi_image_fns
*image_fns
,
735 struct wsi_swapchain
**swapchain_out
)
737 struct x11_swapchain
*chain
;
738 xcb_void_cookie_t cookie
;
741 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
);
743 int num_images
= pCreateInfo
->minImageCount
;
745 /* For true mailbox mode, we need at least 4 images:
746 * 1) One to scan out from
747 * 2) One to have queued for scan-out
748 * 3) One to be currently held by the Wayland compositor
749 * 4) One to render to
751 if (pCreateInfo
->presentMode
== VK_PRESENT_MODE_MAILBOX_KHR
)
752 num_images
= MAX2(num_images
, 4);
754 size_t size
= sizeof(*chain
) + num_images
* sizeof(chain
->images
[0]);
755 chain
= vk_alloc(pAllocator
, size
, 8,
756 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
758 return VK_ERROR_OUT_OF_HOST_MEMORY
;
760 chain
->base
.device
= device
;
761 chain
->base
.destroy
= x11_swapchain_destroy
;
762 chain
->base
.get_images
= x11_get_images
;
763 chain
->base
.acquire_next_image
= x11_acquire_next_image
;
764 chain
->base
.queue_present
= x11_queue_present
;
765 chain
->base
.image_fns
= image_fns
;
766 chain
->conn
= x11_surface_get_connection(icd_surface
);
767 chain
->window
= x11_surface_get_window(icd_surface
);
768 chain
->extent
= pCreateInfo
->imageExtent
;
769 chain
->image_count
= num_images
;
772 chain
->event_id
= xcb_generate_id(chain
->conn
);
773 xcb_present_select_input(chain
->conn
, chain
->event_id
, chain
->window
,
774 XCB_PRESENT_EVENT_MASK_CONFIGURE_NOTIFY
|
775 XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY
|
776 XCB_PRESENT_EVENT_MASK_IDLE_NOTIFY
);
778 /* Create an XCB event queue to hold present events outside of the usual
779 * application event queue
781 chain
->special_event
=
782 xcb_register_for_special_xge(chain
->conn
, &xcb_present_id
,
783 chain
->event_id
, NULL
);
785 chain
->gc
= xcb_generate_id(chain
->conn
);
787 /* FINISHME: Choose a better error. */
788 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
792 cookie
= xcb_create_gc(chain
->conn
,
795 XCB_GC_GRAPHICS_EXPOSURES
,
796 (uint32_t []) { 0 });
797 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
800 for (; image
< chain
->image_count
; image
++) {
801 result
= x11_image_init(device
, chain
, pCreateInfo
, pAllocator
,
802 &chain
->images
[image
]);
803 if (result
!= VK_SUCCESS
)
804 goto fail_init_images
;
807 *swapchain_out
= &chain
->base
;
812 for (uint32_t j
= 0; j
< image
; j
++)
813 x11_image_finish(chain
, pAllocator
, &chain
->images
[j
]);
816 xcb_unregister_for_special_event(chain
->conn
, chain
->special_event
);
818 vk_free(pAllocator
, chain
);
824 wsi_x11_init_wsi(struct wsi_device
*wsi_device
,
825 const VkAllocationCallbacks
*alloc
)
830 wsi
= vk_alloc(alloc
, sizeof(*wsi
), 8,
831 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
833 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
837 int ret
= pthread_mutex_init(&wsi
->mutex
, NULL
);
840 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
842 /* FINISHME: Choose a better error. */
843 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
849 wsi
->connections
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
850 _mesa_key_pointer_equal
);
851 if (!wsi
->connections
) {
852 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
856 wsi
->base
.get_support
= x11_surface_get_support
;
857 wsi
->base
.get_capabilities
= x11_surface_get_capabilities
;
858 wsi
->base
.get_formats
= x11_surface_get_formats
;
859 wsi
->base
.get_present_modes
= x11_surface_get_present_modes
;
860 wsi
->base
.create_swapchain
= x11_surface_create_swapchain
;
862 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XCB
] = &wsi
->base
;
863 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XLIB
] = &wsi
->base
;
868 pthread_mutex_destroy(&wsi
->mutex
);
872 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XCB
] = NULL
;
873 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XLIB
] = NULL
;
879 wsi_x11_finish_wsi(struct wsi_device
*wsi_device
,
880 const VkAllocationCallbacks
*alloc
)
882 struct wsi_x11
*wsi
=
883 (struct wsi_x11
*)wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XCB
];
886 _mesa_hash_table_destroy(wsi
->connections
, NULL
);
888 pthread_mutex_destroy(&wsi
->mutex
);