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 assert(*pSurfaceFormatCount
>= ARRAY_SIZE(formats
));
398 typed_memcpy(pSurfaceFormats
, formats
, *pSurfaceFormatCount
);
399 *pSurfaceFormatCount
= ARRAY_SIZE(formats
);
405 x11_surface_get_present_modes(VkIcdSurfaceBase
*surface
,
406 uint32_t *pPresentModeCount
,
407 VkPresentModeKHR
*pPresentModes
)
409 if (pPresentModes
== NULL
) {
410 *pPresentModeCount
= ARRAY_SIZE(present_modes
);
414 assert(*pPresentModeCount
>= ARRAY_SIZE(present_modes
));
415 typed_memcpy(pPresentModes
, present_modes
, *pPresentModeCount
);
416 *pPresentModeCount
= ARRAY_SIZE(present_modes
);
421 VkResult
wsi_create_xcb_surface(const VkAllocationCallbacks
*pAllocator
,
422 const VkXcbSurfaceCreateInfoKHR
*pCreateInfo
,
423 VkSurfaceKHR
*pSurface
)
425 VkIcdSurfaceXcb
*surface
;
427 surface
= vk_alloc(pAllocator
, sizeof *surface
, 8,
428 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
430 return VK_ERROR_OUT_OF_HOST_MEMORY
;
432 surface
->base
.platform
= VK_ICD_WSI_PLATFORM_XCB
;
433 surface
->connection
= pCreateInfo
->connection
;
434 surface
->window
= pCreateInfo
->window
;
436 *pSurface
= _VkIcdSurfaceBase_to_handle(&surface
->base
);
440 VkResult
wsi_create_xlib_surface(const VkAllocationCallbacks
*pAllocator
,
441 const VkXlibSurfaceCreateInfoKHR
*pCreateInfo
,
442 VkSurfaceKHR
*pSurface
)
444 VkIcdSurfaceXlib
*surface
;
446 surface
= vk_alloc(pAllocator
, sizeof *surface
, 8,
447 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
449 return VK_ERROR_OUT_OF_HOST_MEMORY
;
451 surface
->base
.platform
= VK_ICD_WSI_PLATFORM_XLIB
;
452 surface
->dpy
= pCreateInfo
->dpy
;
453 surface
->window
= pCreateInfo
->window
;
455 *pSurface
= _VkIcdSurfaceBase_to_handle(&surface
->base
);
461 VkDeviceMemory memory
;
464 struct xshmfence
* shm_fence
;
468 struct x11_swapchain
{
469 struct wsi_swapchain base
;
471 xcb_connection_t
* conn
;
475 uint32_t image_count
;
477 xcb_present_event_t event_id
;
478 xcb_special_event_t
* special_event
;
482 struct x11_image images
[0];
486 x11_get_images(struct wsi_swapchain
*anv_chain
,
487 uint32_t* pCount
, VkImage
*pSwapchainImages
)
489 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
491 if (pSwapchainImages
== NULL
) {
492 *pCount
= chain
->image_count
;
496 assert(chain
->image_count
<= *pCount
);
497 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
498 pSwapchainImages
[i
] = chain
->images
[i
].image
;
500 *pCount
= chain
->image_count
;
506 x11_handle_dri3_present_event(struct x11_swapchain
*chain
,
507 xcb_present_generic_event_t
*event
)
509 switch (event
->evtype
) {
510 case XCB_PRESENT_CONFIGURE_NOTIFY
: {
511 xcb_present_configure_notify_event_t
*config
= (void *) event
;
513 if (config
->width
!= chain
->extent
.width
||
514 config
->height
!= chain
->extent
.height
)
515 return VK_ERROR_OUT_OF_DATE_KHR
;
520 case XCB_PRESENT_EVENT_IDLE_NOTIFY
: {
521 xcb_present_idle_notify_event_t
*idle
= (void *) event
;
523 for (unsigned i
= 0; i
< chain
->image_count
; i
++) {
524 if (chain
->images
[i
].pixmap
== idle
->pixmap
) {
525 chain
->images
[i
].busy
= false;
533 case XCB_PRESENT_COMPLETE_NOTIFY
:
542 x11_acquire_next_image(struct wsi_swapchain
*anv_chain
,
544 VkSemaphore semaphore
,
545 uint32_t *image_index
)
547 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
550 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
551 if (!chain
->images
[i
].busy
) {
552 /* We found a non-busy image */
553 xshmfence_await(chain
->images
[i
].shm_fence
);
555 chain
->images
[i
].busy
= true;
560 xcb_flush(chain
->conn
);
561 xcb_generic_event_t
*event
=
562 xcb_wait_for_special_event(chain
->conn
, chain
->special_event
);
564 return VK_ERROR_OUT_OF_DATE_KHR
;
566 VkResult result
= x11_handle_dri3_present_event(chain
, (void *)event
);
568 if (result
!= VK_SUCCESS
)
574 x11_queue_present(struct wsi_swapchain
*anv_chain
,
575 uint32_t image_index
)
577 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
578 struct x11_image
*image
= &chain
->images
[image_index
];
580 assert(image_index
< chain
->image_count
);
582 uint32_t options
= XCB_PRESENT_OPTION_NONE
;
584 int64_t target_msc
= 0;
586 int64_t remainder
= 0;
588 options
|= XCB_PRESENT_OPTION_ASYNC
;
590 xshmfence_reset(image
->shm_fence
);
593 xcb_void_cookie_t cookie
=
594 xcb_present_pixmap(chain
->conn
,
597 (uint32_t) chain
->send_sbc
,
602 XCB_NONE
, /* target_crtc */
609 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
612 xcb_flush(chain
->conn
);
618 x11_image_init(VkDevice device_h
, struct x11_swapchain
*chain
,
619 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
620 const VkAllocationCallbacks
* pAllocator
,
621 struct x11_image
*image
)
623 xcb_void_cookie_t cookie
;
632 result
= chain
->base
.image_fns
->create_wsi_image(device_h
,
641 if (result
!= VK_SUCCESS
)
644 image
->pixmap
= xcb_generate_id(chain
->conn
);
647 xcb_dri3_pixmap_from_buffer_checked(chain
->conn
,
651 pCreateInfo
->imageExtent
.width
,
652 pCreateInfo
->imageExtent
.height
,
655 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
657 int fence_fd
= xshmfence_alloc_shm();
661 image
->shm_fence
= xshmfence_map_shm(fence_fd
);
662 if (image
->shm_fence
== NULL
)
663 goto fail_shmfence_alloc
;
665 image
->sync_fence
= xcb_generate_id(chain
->conn
);
666 xcb_dri3_fence_from_fd(chain
->conn
,
673 xshmfence_trigger(image
->shm_fence
);
681 cookie
= xcb_free_pixmap(chain
->conn
, image
->pixmap
);
682 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
684 chain
->base
.image_fns
->free_wsi_image(device_h
, pAllocator
,
685 image
->image
, image
->memory
);
691 x11_image_finish(struct x11_swapchain
*chain
,
692 const VkAllocationCallbacks
* pAllocator
,
693 struct x11_image
*image
)
695 xcb_void_cookie_t cookie
;
697 cookie
= xcb_sync_destroy_fence(chain
->conn
, image
->sync_fence
);
698 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
699 xshmfence_unmap_shm(image
->shm_fence
);
701 cookie
= xcb_free_pixmap(chain
->conn
, image
->pixmap
);
702 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
704 chain
->base
.image_fns
->free_wsi_image(chain
->base
.device
, pAllocator
,
705 image
->image
, image
->memory
);
709 x11_swapchain_destroy(struct wsi_swapchain
*anv_chain
,
710 const VkAllocationCallbacks
*pAllocator
)
712 struct x11_swapchain
*chain
= (struct x11_swapchain
*)anv_chain
;
713 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
714 x11_image_finish(chain
, pAllocator
, &chain
->images
[i
]);
716 xcb_unregister_for_special_event(chain
->conn
, chain
->special_event
);
718 vk_free(pAllocator
, chain
);
724 x11_surface_create_swapchain(VkIcdSurfaceBase
*icd_surface
,
726 struct wsi_device
*wsi_device
,
727 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
728 const VkAllocationCallbacks
* pAllocator
,
729 const struct wsi_image_fns
*image_fns
,
730 struct wsi_swapchain
**swapchain_out
)
732 struct x11_swapchain
*chain
;
733 xcb_void_cookie_t cookie
;
736 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
);
738 int num_images
= pCreateInfo
->minImageCount
;
740 /* For true mailbox mode, we need at least 4 images:
741 * 1) One to scan out from
742 * 2) One to have queued for scan-out
743 * 3) One to be currently held by the Wayland compositor
744 * 4) One to render to
746 if (pCreateInfo
->presentMode
== VK_PRESENT_MODE_MAILBOX_KHR
)
747 num_images
= MAX2(num_images
, 4);
749 size_t size
= sizeof(*chain
) + num_images
* sizeof(chain
->images
[0]);
750 chain
= vk_alloc(pAllocator
, size
, 8,
751 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
753 return VK_ERROR_OUT_OF_HOST_MEMORY
;
755 chain
->base
.device
= device
;
756 chain
->base
.destroy
= x11_swapchain_destroy
;
757 chain
->base
.get_images
= x11_get_images
;
758 chain
->base
.acquire_next_image
= x11_acquire_next_image
;
759 chain
->base
.queue_present
= x11_queue_present
;
760 chain
->base
.image_fns
= image_fns
;
761 chain
->conn
= x11_surface_get_connection(icd_surface
);
762 chain
->window
= x11_surface_get_window(icd_surface
);
763 chain
->extent
= pCreateInfo
->imageExtent
;
764 chain
->image_count
= num_images
;
767 chain
->event_id
= xcb_generate_id(chain
->conn
);
768 xcb_present_select_input(chain
->conn
, chain
->event_id
, chain
->window
,
769 XCB_PRESENT_EVENT_MASK_CONFIGURE_NOTIFY
|
770 XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY
|
771 XCB_PRESENT_EVENT_MASK_IDLE_NOTIFY
);
773 /* Create an XCB event queue to hold present events outside of the usual
774 * application event queue
776 chain
->special_event
=
777 xcb_register_for_special_xge(chain
->conn
, &xcb_present_id
,
778 chain
->event_id
, NULL
);
780 chain
->gc
= xcb_generate_id(chain
->conn
);
782 /* FINISHME: Choose a better error. */
783 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
787 cookie
= xcb_create_gc(chain
->conn
,
790 XCB_GC_GRAPHICS_EXPOSURES
,
791 (uint32_t []) { 0 });
792 xcb_discard_reply(chain
->conn
, cookie
.sequence
);
795 for (; image
< chain
->image_count
; image
++) {
796 result
= x11_image_init(device
, chain
, pCreateInfo
, pAllocator
,
797 &chain
->images
[image
]);
798 if (result
!= VK_SUCCESS
)
799 goto fail_init_images
;
802 *swapchain_out
= &chain
->base
;
807 for (uint32_t j
= 0; j
< image
; j
++)
808 x11_image_finish(chain
, pAllocator
, &chain
->images
[j
]);
811 xcb_unregister_for_special_event(chain
->conn
, chain
->special_event
);
813 vk_free(pAllocator
, chain
);
819 wsi_x11_init_wsi(struct wsi_device
*wsi_device
,
820 const VkAllocationCallbacks
*alloc
)
825 wsi
= vk_alloc(alloc
, sizeof(*wsi
), 8,
826 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
828 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
832 int ret
= pthread_mutex_init(&wsi
->mutex
, NULL
);
835 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
837 /* FINISHME: Choose a better error. */
838 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
844 wsi
->connections
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
845 _mesa_key_pointer_equal
);
846 if (!wsi
->connections
) {
847 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
851 wsi
->base
.get_support
= x11_surface_get_support
;
852 wsi
->base
.get_capabilities
= x11_surface_get_capabilities
;
853 wsi
->base
.get_formats
= x11_surface_get_formats
;
854 wsi
->base
.get_present_modes
= x11_surface_get_present_modes
;
855 wsi
->base
.create_swapchain
= x11_surface_create_swapchain
;
857 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XCB
] = &wsi
->base
;
858 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XLIB
] = &wsi
->base
;
863 pthread_mutex_destroy(&wsi
->mutex
);
867 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XCB
] = NULL
;
868 wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XLIB
] = NULL
;
874 wsi_x11_finish_wsi(struct wsi_device
*wsi_device
,
875 const VkAllocationCallbacks
*alloc
)
877 struct wsi_x11
*wsi
=
878 (struct wsi_x11
*)wsi_device
->wsi
[VK_ICD_WSI_PLATFORM_XCB
];
881 _mesa_hash_table_destroy(wsi
->connections
, NULL
);
883 pthread_mutex_destroy(&wsi
->mutex
);