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 <wayland-client.h>
25 #include <wayland-drm-client-protocol.h>
29 #include <util/hash_table.h>
31 #define MIN_NUM_IMAGES 2
33 struct wsi_wl_display
{
34 struct wl_display
* display
;
37 /* Vector of VkFormats supported */
38 struct anv_vector formats
;
40 uint32_t capabilities
;
44 struct anv_wsi_implementation base
;
46 struct anv_instance
* instance
;
48 pthread_mutex_t mutex
;
49 /* Hash table of wl_display -> wsi_wl_display mappings */
50 struct hash_table
* displays
;
54 wsi_wl_display_add_vk_format(struct wsi_wl_display
*display
, VkFormat format
)
56 /* Don't add a format that's already in the list */
58 anv_vector_foreach(f
, &display
->formats
)
62 /* Don't add formats which aren't supported by the driver */
63 if (anv_format_for_vk_format(format
)->surface_format
==
64 ISL_FORMAT_UNSUPPORTED
) {
68 f
= anv_vector_add(&display
->formats
);
74 drm_handle_device(void *data
, struct wl_drm
*drm
, const char *name
)
76 fprintf(stderr
, "wl_drm.device(%s)\n", name
);
80 wl_drm_format_for_vk_format(VkFormat vk_format
, bool alpha
)
83 case VK_FORMAT_R4G4B4A4_UNORM
:
84 return alpha
? WL_DRM_FORMAT_ABGR4444
: WL_DRM_FORMAT_XBGR4444
;
85 case VK_FORMAT_R5G6B5_UNORM
:
86 return WL_DRM_FORMAT_BGR565
;
87 case VK_FORMAT_R5G5B5A1_UNORM
:
88 return alpha
? WL_DRM_FORMAT_ABGR1555
: WL_DRM_FORMAT_XBGR1555
;
89 case VK_FORMAT_R8G8B8_UNORM
:
90 return WL_DRM_FORMAT_XBGR8888
;
91 case VK_FORMAT_R8G8B8A8_UNORM
:
92 return alpha
? WL_DRM_FORMAT_ABGR8888
: WL_DRM_FORMAT_XBGR8888
;
93 case VK_FORMAT_R10G10B10A2_UNORM
:
94 return alpha
? WL_DRM_FORMAT_ABGR2101010
: WL_DRM_FORMAT_XBGR2101010
;
95 case VK_FORMAT_B4G4R4A4_UNORM
:
96 return alpha
? WL_DRM_FORMAT_ARGB4444
: WL_DRM_FORMAT_XRGB4444
;
97 case VK_FORMAT_B5G6R5_UNORM
:
98 return WL_DRM_FORMAT_RGB565
;
99 case VK_FORMAT_B5G5R5A1_UNORM
:
100 return alpha
? WL_DRM_FORMAT_XRGB1555
: WL_DRM_FORMAT_XRGB1555
;
101 case VK_FORMAT_B8G8R8_UNORM
:
102 return WL_DRM_FORMAT_BGRX8888
;
103 case VK_FORMAT_B8G8R8A8_UNORM
:
104 return alpha
? WL_DRM_FORMAT_ARGB8888
: WL_DRM_FORMAT_XRGB8888
;
105 case VK_FORMAT_B10G10R10A2_UNORM
:
106 return alpha
? WL_DRM_FORMAT_ARGB2101010
: WL_DRM_FORMAT_XRGB2101010
;
109 assert("!Unsupported Vulkan format");
115 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t wl_format
)
117 struct wsi_wl_display
*display
= data
;
120 case WL_DRM_FORMAT_ABGR4444
:
121 case WL_DRM_FORMAT_XBGR4444
:
122 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R4G4B4A4_UNORM
);
124 case WL_DRM_FORMAT_BGR565
:
125 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R5G6B5_UNORM
);
127 case WL_DRM_FORMAT_ABGR1555
:
128 case WL_DRM_FORMAT_XBGR1555
:
129 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R5G5B5A1_UNORM
);
131 case WL_DRM_FORMAT_XBGR8888
:
132 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R8G8B8_UNORM
);
134 case WL_DRM_FORMAT_ABGR8888
:
135 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R8G8B8A8_UNORM
);
137 case WL_DRM_FORMAT_ABGR2101010
:
138 case WL_DRM_FORMAT_XBGR2101010
:
139 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R10G10B10A2_UNORM
);
141 case WL_DRM_FORMAT_ARGB4444
:
142 case WL_DRM_FORMAT_XRGB4444
:
143 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B4G4R4A4_UNORM
);
145 case WL_DRM_FORMAT_RGB565
:
146 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B5G6R5_UNORM
);
148 case WL_DRM_FORMAT_ARGB1555
:
149 case WL_DRM_FORMAT_XRGB1555
:
150 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B5G5R5A1_UNORM
);
152 case WL_DRM_FORMAT_XRGB8888
:
153 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B8G8R8_UNORM
);
155 case WL_DRM_FORMAT_ARGB8888
:
156 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B8G8R8A8_UNORM
);
158 case WL_DRM_FORMAT_ARGB2101010
:
159 case WL_DRM_FORMAT_XRGB2101010
:
160 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B10G10R10A2_UNORM
);
166 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
171 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t capabilities
)
173 struct wsi_wl_display
*display
= data
;
175 display
->capabilities
= capabilities
;
178 static const struct wl_drm_listener drm_listener
= {
181 drm_handle_authenticated
,
182 drm_handle_capabilities
,
186 registry_handle_global(void *data
, struct wl_registry
*registry
,
187 uint32_t name
, const char *interface
, uint32_t version
)
189 struct wsi_wl_display
*display
= data
;
191 if (strcmp(interface
, "wl_drm") == 0) {
192 assert(display
->drm
== NULL
);
194 assert(version
>= 2);
195 display
->drm
= wl_registry_bind(registry
, name
, &wl_drm_interface
, 2);
198 wl_drm_add_listener(display
->drm
, &drm_listener
, display
);
203 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
207 static const struct wl_registry_listener registry_listener
= {
208 registry_handle_global
,
209 registry_handle_global_remove
213 wsi_wl_display_destroy(struct wsi_wayland
*wsi
, struct wsi_wl_display
*display
)
215 anv_vector_finish(&display
->formats
);
217 wl_drm_destroy(display
->drm
);
218 anv_instance_free(wsi
->instance
, display
);
221 static struct wsi_wl_display
*
222 wsi_wl_display_create(struct wsi_wayland
*wsi
, struct wl_display
*wl_display
)
224 struct wsi_wl_display
*display
=
225 anv_instance_alloc(wsi
->instance
, sizeof(*display
), 8,
226 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
230 memset(display
, 0, sizeof(*display
));
232 display
->display
= wl_display
;
234 if (!anv_vector_init(&display
->formats
, sizeof(VkFormat
), 8))
237 struct wl_registry
*registry
= wl_display_get_registry(wl_display
);
241 wl_registry_add_listener(registry
, ®istry_listener
, display
);
243 /* Round-rip to get the wl_drm global */
244 wl_display_roundtrip(wl_display
);
249 /* Round-rip to get wl_drm formats and capabilities */
250 wl_display_roundtrip(wl_display
);
252 /* We need prime support */
253 if (!(display
->capabilities
& WL_DRM_CAPABILITY_PRIME
))
256 /* We don't need this anymore */
257 wl_registry_destroy(registry
);
263 wl_registry_destroy(registry
);
265 wsi_wl_display_destroy(wsi
, display
);
269 static struct wsi_wl_display
*
270 wsi_wl_get_display(struct wsi_wayland
*wsi
, struct wl_display
*wl_display
)
272 pthread_mutex_lock(&wsi
->mutex
);
274 struct hash_entry
*entry
= _mesa_hash_table_search(wsi
->displays
,
277 /* We're about to make a bunch of blocking calls. Let's drop the
278 * mutex for now so we don't block up too badly.
280 pthread_mutex_unlock(&wsi
->mutex
);
282 struct wsi_wl_display
*display
= wsi_wl_display_create(wsi
, wl_display
);
284 pthread_mutex_lock(&wsi
->mutex
);
286 entry
= _mesa_hash_table_search(wsi
->displays
, wl_display
);
288 /* Oops, someone raced us to it */
289 wsi_wl_display_destroy(wsi
, display
);
291 entry
= _mesa_hash_table_insert(wsi
->displays
, wl_display
, display
);
295 pthread_mutex_unlock(&wsi
->mutex
);
301 wsi_wl_get_window_supported(struct anv_wsi_implementation
*impl
,
302 struct anv_physical_device
*physical_device
,
303 const VkSurfaceDescriptionWindowKHR
*window
,
304 VkBool32
*pSupported
)
306 struct wsi_wayland
*wsi
= (struct wsi_wayland
*)impl
;
308 *pSupported
= wsi_wl_get_display(wsi
, window
->pPlatformHandle
) != NULL
;
313 static const VkPresentModeKHR present_modes
[] = {
314 VK_PRESENT_MODE_MAILBOX_KHR
,
315 VK_PRESENT_MODE_FIFO_KHR
,
319 wsi_wl_get_surface_properties(struct anv_wsi_implementation
*impl
,
320 struct anv_device
*device
,
321 const VkSurfaceDescriptionWindowKHR
*window
,
322 VkSurfacePropertiesKHR
*props
)
324 props
->minImageCount
= MIN_NUM_IMAGES
;
325 props
->maxImageCount
= 4;
326 props
->currentExtent
= (VkExtent2D
) { -1, -1 };
327 props
->minImageExtent
= (VkExtent2D
) { 1, 1 };
328 props
->maxImageExtent
= (VkExtent2D
) { INT16_MAX
, INT16_MAX
};
329 props
->supportedTransforms
= VK_SURFACE_TRANSFORM_NONE_BIT_KHR
;
330 props
->currentTransform
= VK_SURFACE_TRANSFORM_NONE_KHR
;
331 props
->maxImageArraySize
= 1;
332 props
->supportedUsageFlags
=
333 VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT
|
334 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
340 wsi_wl_get_surface_formats(struct anv_wsi_implementation
*impl
,
341 struct anv_device
*device
,
342 const VkSurfaceDescriptionWindowKHR
*window
,
344 VkSurfaceFormatKHR
*pSurfaceFormats
)
346 struct wsi_wayland
*wsi
= (struct wsi_wayland
*)impl
;
347 struct wsi_wl_display
*display
=
348 wsi_wl_get_display(wsi
, window
->pPlatformHandle
);
350 uint32_t count
= anv_vector_length(&display
->formats
);
352 if (pSurfaceFormats
== NULL
) {
357 assert(*pCount
>= count
);
361 anv_vector_foreach(f
, &display
->formats
) {
362 *(pSurfaceFormats
++) = (VkSurfaceFormatKHR
) {
364 /* TODO: We should get this from the compositor somehow */
365 .colorSpace
= VK_COLORSPACE_SRGB_NONLINEAR_KHR
,
373 wsi_wl_get_surface_present_modes(struct anv_wsi_implementation
*impl
,
374 struct anv_device
*device
,
375 const VkSurfaceDescriptionWindowKHR
*window
,
377 VkPresentModeKHR
*pPresentModes
)
379 if (pPresentModes
== NULL
) {
380 *pCount
= ARRAY_SIZE(present_modes
);
384 assert(*pCount
>= ARRAY_SIZE(present_modes
));
385 typed_memcpy(pPresentModes
, present_modes
, *pCount
);
386 *pCount
= ARRAY_SIZE(present_modes
);
391 struct wsi_wl_image
{
392 struct anv_image
* image
;
393 struct anv_device_memory
* memory
;
394 struct wl_buffer
* buffer
;
398 struct wsi_wl_swapchain
{
399 struct anv_swapchain base
;
401 struct wsi_wl_display
* display
;
402 struct wl_event_queue
* queue
;
403 struct wl_surface
* surface
;
409 VkPresentModeKHR present_mode
;
412 uint32_t image_count
;
413 struct wsi_wl_image images
[0];
417 wsi_wl_get_images(struct anv_swapchain
*anv_chain
,
418 uint32_t *pCount
, VkImage
*pSwapchainImages
)
420 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)anv_chain
;
422 if (pSwapchainImages
== NULL
) {
423 *pCount
= chain
->image_count
;
427 assert(chain
->image_count
<= *pCount
);
428 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
429 pSwapchainImages
[i
] = anv_image_to_handle(chain
->images
[i
].image
);
431 *pCount
= chain
->image_count
;
437 wsi_wl_acquire_next_image(struct anv_swapchain
*anv_chain
,
439 VkSemaphore semaphore
,
440 uint32_t *image_index
)
442 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)anv_chain
;
444 int ret
= wl_display_dispatch_queue_pending(chain
->display
->display
,
446 /* XXX: I'm not sure if out-of-date is the right error here. If
447 * wl_display_dispatch_queue_pending fails it most likely means we got
448 * kicked by the server so this seems more-or-less correct.
451 return vk_error(VK_ERROR_OUT_OF_DATE_KHR
);
454 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
455 if (!chain
->images
[i
].busy
) {
456 /* We found a non-busy image */
462 /* This time we do a blocking dispatch because we can't go
463 * anywhere until we get an event.
465 int ret
= wl_display_dispatch_queue(chain
->display
->display
,
468 return vk_error(VK_ERROR_OUT_OF_DATE_KHR
);
473 frame_handle_done(void *data
, struct wl_callback
*callback
, uint32_t serial
)
475 struct wsi_wl_swapchain
*chain
= data
;
477 chain
->fifo_ready
= true;
479 wl_callback_destroy(callback
);
482 static const struct wl_callback_listener frame_listener
= {
487 wsi_wl_queue_present(struct anv_swapchain
*anv_chain
,
488 struct anv_queue
*queue
,
489 uint32_t image_index
)
491 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)anv_chain
;
493 if (chain
->present_mode
== VK_PRESENT_MODE_FIFO_KHR
) {
494 while (!chain
->fifo_ready
) {
495 int ret
= wl_display_dispatch_queue(chain
->display
->display
,
498 return vk_error(VK_ERROR_OUT_OF_DATE_KHR
);
502 assert(image_index
< chain
->image_count
);
503 wl_surface_attach(chain
->surface
, chain
->images
[image_index
].buffer
, 0, 0);
504 wl_surface_damage(chain
->surface
, 0, 0, INT32_MAX
, INT32_MAX
);
506 if (chain
->present_mode
== VK_PRESENT_MODE_FIFO_KHR
) {
507 struct wl_callback
*frame
= wl_surface_frame(chain
->surface
);
508 wl_proxy_set_queue((struct wl_proxy
*)frame
, chain
->queue
);
509 wl_callback_add_listener(frame
, &frame_listener
, chain
);
510 chain
->fifo_ready
= false;
513 wl_surface_commit(chain
->surface
);
514 wl_display_flush(chain
->display
->display
);
520 wsi_wl_image_finish(struct wsi_wl_swapchain
*chain
, struct wsi_wl_image
*image
)
522 VkDevice vk_device
= anv_device_to_handle(chain
->base
.device
);
523 anv_FreeMemory(vk_device
, anv_device_memory_to_handle(image
->memory
));
524 anv_DestroyImage(vk_device
, anv_image_to_handle(image
->image
));
528 buffer_handle_release(void *data
, struct wl_buffer
*buffer
)
530 struct wsi_wl_image
*image
= data
;
532 assert(image
->buffer
== buffer
);
537 static const struct wl_buffer_listener buffer_listener
= {
538 buffer_handle_release
,
542 wsi_wl_image_init(struct wsi_wl_swapchain
*chain
, struct wsi_wl_image
*image
)
544 VkDevice vk_device
= anv_device_to_handle(chain
->base
.device
);
548 result
= anv_image_create(vk_device
,
549 &(struct anv_image_create_info
) {
550 .force_tiling
= true,
551 .tiling
= ISL_TILING_X
,
554 &(VkImageCreateInfo
) {
555 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
556 .imageType
= VK_IMAGE_TYPE_2D
,
557 .format
= chain
->vk_format
,
559 .width
= chain
->extent
.width
,
560 .height
= chain
->extent
.height
,
566 /* FIXME: Need a way to use X tiling to allow scanout */
567 .tiling
= VK_IMAGE_TILING_OPTIMAL
,
568 .usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
,
573 if (result
!= VK_SUCCESS
)
576 image
->image
= anv_image_from_handle(vk_image
);
577 assert(anv_format_is_color(image
->image
->format
));
579 struct anv_surface
*surface
= &image
->image
->color_surface
;
581 VkDeviceMemory vk_memory
;
582 result
= anv_AllocMemory(vk_device
,
583 &(VkMemoryAllocInfo
) {
584 .sType
= VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO
,
585 .allocationSize
= image
->image
->size
,
586 .memoryTypeIndex
= 0,
590 if (result
!= VK_SUCCESS
)
593 image
->memory
= anv_device_memory_from_handle(vk_memory
);
595 result
= anv_BindImageMemory(vk_device
, vk_image
, vk_memory
, 0);
597 if (result
!= VK_SUCCESS
)
600 int ret
= anv_gem_set_tiling(chain
->base
.device
,
601 image
->memory
->bo
.gem_handle
,
602 surface
->stride
, I915_TILING_X
);
604 /* FINISHME: Choose a better error. */
605 result
= vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
609 int fd
= anv_gem_handle_to_fd(chain
->base
.device
,
610 image
->memory
->bo
.gem_handle
);
612 /* FINISHME: Choose a better error. */
613 result
= vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
617 image
->buffer
= wl_drm_create_prime_buffer(chain
->display
->drm
,
620 chain
->extent
.height
,
624 0, 0, 0, 0 /* unused */);
625 wl_display_roundtrip(chain
->display
->display
);
628 wl_proxy_set_queue((struct wl_proxy
*)image
->buffer
, chain
->queue
);
629 wl_buffer_add_listener(image
->buffer
, &buffer_listener
, image
);
634 anv_FreeMemory(vk_device
, vk_memory
);
636 anv_DestroyImage(vk_device
, vk_image
);
642 wsi_wl_destroy_swapchain(struct anv_swapchain
*anv_chain
)
644 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)anv_chain
;
646 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
647 if (chain
->images
[i
].buffer
)
648 wsi_wl_image_finish(chain
, &chain
->images
[i
]);
651 anv_device_free(chain
->base
.device
, chain
);
657 wsi_wl_create_swapchain(struct anv_wsi_implementation
*impl
,
658 struct anv_device
*device
,
659 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
660 struct anv_swapchain
**swapchain_out
)
662 struct wsi_wayland
*wsi
= (struct wsi_wayland
*)impl
;
663 struct wsi_wl_swapchain
*chain
;
666 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
);
668 assert(pCreateInfo
->pSurfaceDescription
->sType
==
669 VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_KHR
);
670 VkSurfaceDescriptionWindowKHR
*vk_window
=
671 (VkSurfaceDescriptionWindowKHR
*)pCreateInfo
->pSurfaceDescription
;
672 assert(vk_window
->platform
== VK_PLATFORM_WAYLAND_KHR
);
674 int num_images
= pCreateInfo
->minImageCount
;
676 assert(num_images
>= MIN_NUM_IMAGES
);
678 /* For true mailbox mode, we need at least 4 images:
679 * 1) One to scan out from
680 * 2) One to have queued for scan-out
681 * 3) One to be currently held by the Wayland compositor
682 * 4) One to render to
684 if (pCreateInfo
->presentMode
== VK_PRESENT_MODE_MAILBOX_KHR
)
685 num_images
= MAX2(num_images
, 4);
687 size_t size
= sizeof(*chain
) + num_images
* sizeof(chain
->images
[0]);
688 chain
= anv_device_alloc(device
, size
, 8,
689 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
691 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
693 chain
->base
.device
= device
;
694 chain
->base
.destroy
= wsi_wl_destroy_swapchain
;
695 chain
->base
.get_images
= wsi_wl_get_images
;
696 chain
->base
.acquire_next_image
= wsi_wl_acquire_next_image
;
697 chain
->base
.queue_present
= wsi_wl_queue_present
;
699 chain
->surface
= vk_window
->pPlatformWindow
;
700 chain
->extent
= pCreateInfo
->imageExtent
;
701 chain
->vk_format
= pCreateInfo
->imageFormat
;
702 chain
->drm_format
= wl_drm_format_for_vk_format(chain
->vk_format
, false);
704 chain
->present_mode
= pCreateInfo
->presentMode
;
705 chain
->fifo_ready
= true;
707 chain
->image_count
= num_images
;
709 /* Mark a bunch of stuff as NULL. This way we can just call
710 * destroy_swapchain for cleanup.
712 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
713 chain
->images
[i
].buffer
= NULL
;
716 chain
->display
= wsi_wl_get_display(wsi
, vk_window
->pPlatformHandle
);
720 chain
->queue
= wl_display_create_queue(chain
->display
->display
);
724 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
725 result
= wsi_wl_image_init(chain
, &chain
->images
[i
]);
726 if (result
!= VK_SUCCESS
)
728 chain
->images
[i
].busy
= false;
731 *swapchain_out
= &chain
->base
;
736 wsi_wl_destroy_swapchain(&chain
->base
);
742 anv_wl_init_wsi(struct anv_instance
*instance
)
744 struct wsi_wayland
*wsi
;
747 wsi
= anv_instance_alloc(instance
, sizeof(*wsi
), 8,
748 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
750 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
752 wsi
->base
.get_window_supported
= wsi_wl_get_window_supported
;
753 wsi
->base
.get_surface_properties
= wsi_wl_get_surface_properties
;
754 wsi
->base
.get_surface_formats
= wsi_wl_get_surface_formats
;
755 wsi
->base
.get_surface_present_modes
= wsi_wl_get_surface_present_modes
;
756 wsi
->base
.create_swapchain
= wsi_wl_create_swapchain
;
758 wsi
->instance
= instance
;
760 int ret
= pthread_mutex_init(&wsi
->mutex
, NULL
);
763 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
765 /* FINISHME: Choose a better error. */
766 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
772 wsi
->displays
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
773 _mesa_key_pointer_equal
);
774 if (!wsi
->displays
) {
775 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
779 instance
->wsi_impl
[VK_PLATFORM_WAYLAND_KHR
] = &wsi
->base
;
784 pthread_mutex_destroy(&wsi
->mutex
);
787 anv_instance_free(instance
, wsi
);
793 anv_wl_finish_wsi(struct anv_instance
*instance
)
795 struct wsi_wayland
*wsi
=
796 (struct wsi_wayland
*)instance
->wsi_impl
[VK_PLATFORM_WAYLAND_KHR
];
798 _mesa_hash_table_destroy(wsi
->displays
, NULL
);
800 pthread_mutex_destroy(&wsi
->mutex
);
802 anv_instance_free(instance
, wsi
);