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 /* TODO: Figure out what all the formats mean and make this table
87 case VK_FORMAT_R4G4B4A4_UNORM
:
88 return alpha
? WL_DRM_FORMAT_ABGR4444
: WL_DRM_FORMAT_XBGR4444
;
89 case VK_FORMAT_R5G6B5_UNORM
:
90 return WL_DRM_FORMAT_BGR565
;
91 case VK_FORMAT_R5G5B5A1_UNORM
:
92 return alpha
? WL_DRM_FORMAT_ABGR1555
: WL_DRM_FORMAT_XBGR1555
;
93 case VK_FORMAT_R8G8B8_UNORM
:
94 return WL_DRM_FORMAT_XBGR8888
;
95 case VK_FORMAT_R8G8B8A8_UNORM
:
96 return alpha
? WL_DRM_FORMAT_ABGR8888
: WL_DRM_FORMAT_XBGR8888
;
97 case VK_FORMAT_R10G10B10A2_UNORM
:
98 return alpha
? WL_DRM_FORMAT_ABGR2101010
: WL_DRM_FORMAT_XBGR2101010
;
99 case VK_FORMAT_B4G4R4A4_UNORM
:
100 return alpha
? WL_DRM_FORMAT_ARGB4444
: WL_DRM_FORMAT_XRGB4444
;
101 case VK_FORMAT_B5G6R5_UNORM
:
102 return WL_DRM_FORMAT_RGB565
;
103 case VK_FORMAT_B5G5R5A1_UNORM
:
104 return alpha
? WL_DRM_FORMAT_XRGB1555
: WL_DRM_FORMAT_XRGB1555
;
106 case VK_FORMAT_B8G8R8_UNORM
:
107 return WL_DRM_FORMAT_BGRX8888
;
108 case VK_FORMAT_B8G8R8A8_UNORM
:
109 return alpha
? WL_DRM_FORMAT_ARGB8888
: WL_DRM_FORMAT_XRGB8888
;
111 case VK_FORMAT_B10G10R10A2_UNORM
:
112 return alpha
? WL_DRM_FORMAT_ARGB2101010
: WL_DRM_FORMAT_XRGB2101010
;
116 assert("!Unsupported Vulkan format");
122 drm_handle_format(void *data
, struct wl_drm
*drm
, uint32_t wl_format
)
124 struct wsi_wl_display
*display
= data
;
128 case WL_DRM_FORMAT_ABGR4444
:
129 case WL_DRM_FORMAT_XBGR4444
:
130 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R4G4B4A4_UNORM
);
132 case WL_DRM_FORMAT_BGR565
:
133 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R5G6B5_UNORM
);
135 case WL_DRM_FORMAT_ABGR1555
:
136 case WL_DRM_FORMAT_XBGR1555
:
137 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R5G5B5A1_UNORM
);
139 case WL_DRM_FORMAT_XBGR8888
:
140 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R8G8B8_UNORM
);
142 case WL_DRM_FORMAT_ABGR8888
:
143 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R8G8B8A8_UNORM
);
145 case WL_DRM_FORMAT_ABGR2101010
:
146 case WL_DRM_FORMAT_XBGR2101010
:
147 wsi_wl_display_add_vk_format(display
, VK_FORMAT_R10G10B10A2_UNORM
);
149 case WL_DRM_FORMAT_ARGB4444
:
150 case WL_DRM_FORMAT_XRGB4444
:
151 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B4G4R4A4_UNORM
);
153 case WL_DRM_FORMAT_RGB565
:
154 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B5G6R5_UNORM
);
156 case WL_DRM_FORMAT_ARGB1555
:
157 case WL_DRM_FORMAT_XRGB1555
:
158 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B5G5R5A1_UNORM
);
161 case WL_DRM_FORMAT_XRGB8888
:
162 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B8G8R8_UNORM
);
164 case WL_DRM_FORMAT_ARGB8888
:
165 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B8G8R8A8_UNORM
);
168 case WL_DRM_FORMAT_ARGB2101010
:
169 case WL_DRM_FORMAT_XRGB2101010
:
170 wsi_wl_display_add_vk_format(display
, VK_FORMAT_B10G10R10A2_UNORM
);
177 drm_handle_authenticated(void *data
, struct wl_drm
*drm
)
182 drm_handle_capabilities(void *data
, struct wl_drm
*drm
, uint32_t capabilities
)
184 struct wsi_wl_display
*display
= data
;
186 display
->capabilities
= capabilities
;
189 static const struct wl_drm_listener drm_listener
= {
192 drm_handle_authenticated
,
193 drm_handle_capabilities
,
197 registry_handle_global(void *data
, struct wl_registry
*registry
,
198 uint32_t name
, const char *interface
, uint32_t version
)
200 struct wsi_wl_display
*display
= data
;
202 if (strcmp(interface
, "wl_drm") == 0) {
203 assert(display
->drm
== NULL
);
205 assert(version
>= 2);
206 display
->drm
= wl_registry_bind(registry
, name
, &wl_drm_interface
, 2);
209 wl_drm_add_listener(display
->drm
, &drm_listener
, display
);
214 registry_handle_global_remove(void *data
, struct wl_registry
*registry
,
218 static const struct wl_registry_listener registry_listener
= {
219 registry_handle_global
,
220 registry_handle_global_remove
224 wsi_wl_display_destroy(struct wsi_wayland
*wsi
, struct wsi_wl_display
*display
)
226 anv_vector_finish(&display
->formats
);
228 wl_drm_destroy(display
->drm
);
229 anv_free(&wsi
->instance
->alloc
, display
);
232 static struct wsi_wl_display
*
233 wsi_wl_display_create(struct wsi_wayland
*wsi
, struct wl_display
*wl_display
)
235 struct wsi_wl_display
*display
=
236 anv_alloc(&wsi
->instance
->alloc
, sizeof(*display
), 8,
237 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
241 memset(display
, 0, sizeof(*display
));
243 display
->display
= wl_display
;
245 if (!anv_vector_init(&display
->formats
, sizeof(VkFormat
), 8))
248 struct wl_registry
*registry
= wl_display_get_registry(wl_display
);
252 wl_registry_add_listener(registry
, ®istry_listener
, display
);
254 /* Round-rip to get the wl_drm global */
255 wl_display_roundtrip(wl_display
);
260 /* Round-rip to get wl_drm formats and capabilities */
261 wl_display_roundtrip(wl_display
);
263 /* We need prime support */
264 if (!(display
->capabilities
& WL_DRM_CAPABILITY_PRIME
))
267 /* We don't need this anymore */
268 wl_registry_destroy(registry
);
274 wl_registry_destroy(registry
);
276 wsi_wl_display_destroy(wsi
, display
);
280 static struct wsi_wl_display
*
281 wsi_wl_get_display(struct wsi_wayland
*wsi
, struct wl_display
*wl_display
)
283 pthread_mutex_lock(&wsi
->mutex
);
285 struct hash_entry
*entry
= _mesa_hash_table_search(wsi
->displays
,
288 /* We're about to make a bunch of blocking calls. Let's drop the
289 * mutex for now so we don't block up too badly.
291 pthread_mutex_unlock(&wsi
->mutex
);
293 struct wsi_wl_display
*display
= wsi_wl_display_create(wsi
, wl_display
);
295 pthread_mutex_lock(&wsi
->mutex
);
297 entry
= _mesa_hash_table_search(wsi
->displays
, wl_display
);
299 /* Oops, someone raced us to it */
300 wsi_wl_display_destroy(wsi
, display
);
302 entry
= _mesa_hash_table_insert(wsi
->displays
, wl_display
, display
);
306 pthread_mutex_unlock(&wsi
->mutex
);
312 wsi_wl_get_window_supported(struct anv_wsi_implementation
*impl
,
313 struct anv_physical_device
*physical_device
,
314 const VkSurfaceDescriptionWindowKHR
*window
,
315 VkBool32
*pSupported
)
317 struct wsi_wayland
*wsi
= (struct wsi_wayland
*)impl
;
319 *pSupported
= wsi_wl_get_display(wsi
, window
->pPlatformHandle
) != NULL
;
324 static const VkPresentModeKHR present_modes
[] = {
325 VK_PRESENT_MODE_MAILBOX_KHR
,
326 VK_PRESENT_MODE_FIFO_KHR
,
330 wsi_wl_get_surface_properties(struct anv_wsi_implementation
*impl
,
331 struct anv_device
*device
,
332 const VkSurfaceDescriptionWindowKHR
*window
,
333 VkSurfacePropertiesKHR
*props
)
335 props
->minImageCount
= MIN_NUM_IMAGES
;
336 props
->maxImageCount
= 4;
337 props
->currentExtent
= (VkExtent2D
) { -1, -1 };
338 props
->minImageExtent
= (VkExtent2D
) { 1, 1 };
339 props
->maxImageExtent
= (VkExtent2D
) { INT16_MAX
, INT16_MAX
};
340 props
->supportedTransforms
= VK_SURFACE_TRANSFORM_NONE_BIT_KHR
;
341 props
->currentTransform
= VK_SURFACE_TRANSFORM_NONE_KHR
;
342 props
->maxImageArraySize
= 1;
343 props
->supportedUsageFlags
=
344 VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
345 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
351 wsi_wl_get_surface_formats(struct anv_wsi_implementation
*impl
,
352 struct anv_device
*device
,
353 const VkSurfaceDescriptionWindowKHR
*window
,
355 VkSurfaceFormatKHR
*pSurfaceFormats
)
357 struct wsi_wayland
*wsi
= (struct wsi_wayland
*)impl
;
358 struct wsi_wl_display
*display
=
359 wsi_wl_get_display(wsi
, window
->pPlatformHandle
);
361 uint32_t count
= anv_vector_length(&display
->formats
);
363 if (pSurfaceFormats
== NULL
) {
368 assert(*pCount
>= count
);
372 anv_vector_foreach(f
, &display
->formats
) {
373 *(pSurfaceFormats
++) = (VkSurfaceFormatKHR
) {
375 /* TODO: We should get this from the compositor somehow */
376 .colorSpace
= VK_COLORSPACE_SRGB_NONLINEAR_KHR
,
384 wsi_wl_get_surface_present_modes(struct anv_wsi_implementation
*impl
,
385 struct anv_device
*device
,
386 const VkSurfaceDescriptionWindowKHR
*window
,
388 VkPresentModeKHR
*pPresentModes
)
390 if (pPresentModes
== NULL
) {
391 *pCount
= ARRAY_SIZE(present_modes
);
395 assert(*pCount
>= ARRAY_SIZE(present_modes
));
396 typed_memcpy(pPresentModes
, present_modes
, *pCount
);
397 *pCount
= ARRAY_SIZE(present_modes
);
402 struct wsi_wl_image
{
403 struct anv_image
* image
;
404 struct anv_device_memory
* memory
;
405 struct wl_buffer
* buffer
;
409 struct wsi_wl_swapchain
{
410 struct anv_swapchain base
;
412 struct wsi_wl_display
* display
;
413 struct wl_event_queue
* queue
;
414 struct wl_surface
* surface
;
420 VkPresentModeKHR present_mode
;
423 uint32_t image_count
;
424 struct wsi_wl_image images
[0];
428 wsi_wl_get_images(struct anv_swapchain
*anv_chain
,
429 uint32_t *pCount
, VkImage
*pSwapchainImages
)
431 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)anv_chain
;
433 if (pSwapchainImages
== NULL
) {
434 *pCount
= chain
->image_count
;
438 assert(chain
->image_count
<= *pCount
);
439 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
440 pSwapchainImages
[i
] = anv_image_to_handle(chain
->images
[i
].image
);
442 *pCount
= chain
->image_count
;
448 wsi_wl_acquire_next_image(struct anv_swapchain
*anv_chain
,
450 VkSemaphore semaphore
,
451 uint32_t *image_index
)
453 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)anv_chain
;
455 int ret
= wl_display_dispatch_queue_pending(chain
->display
->display
,
457 /* XXX: I'm not sure if out-of-date is the right error here. If
458 * wl_display_dispatch_queue_pending fails it most likely means we got
459 * kicked by the server so this seems more-or-less correct.
462 return vk_error(VK_ERROR_OUT_OF_DATE_KHR
);
465 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
466 if (!chain
->images
[i
].busy
) {
467 /* We found a non-busy image */
473 /* This time we do a blocking dispatch because we can't go
474 * anywhere until we get an event.
476 int ret
= wl_display_dispatch_queue(chain
->display
->display
,
479 return vk_error(VK_ERROR_OUT_OF_DATE_KHR
);
484 frame_handle_done(void *data
, struct wl_callback
*callback
, uint32_t serial
)
486 struct wsi_wl_swapchain
*chain
= data
;
488 chain
->fifo_ready
= true;
490 wl_callback_destroy(callback
);
493 static const struct wl_callback_listener frame_listener
= {
498 wsi_wl_queue_present(struct anv_swapchain
*anv_chain
,
499 struct anv_queue
*queue
,
500 uint32_t image_index
)
502 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)anv_chain
;
504 if (chain
->present_mode
== VK_PRESENT_MODE_FIFO_KHR
) {
505 while (!chain
->fifo_ready
) {
506 int ret
= wl_display_dispatch_queue(chain
->display
->display
,
509 return vk_error(VK_ERROR_OUT_OF_DATE_KHR
);
513 assert(image_index
< chain
->image_count
);
514 wl_surface_attach(chain
->surface
, chain
->images
[image_index
].buffer
, 0, 0);
515 wl_surface_damage(chain
->surface
, 0, 0, INT32_MAX
, INT32_MAX
);
517 if (chain
->present_mode
== VK_PRESENT_MODE_FIFO_KHR
) {
518 struct wl_callback
*frame
= wl_surface_frame(chain
->surface
);
519 wl_proxy_set_queue((struct wl_proxy
*)frame
, chain
->queue
);
520 wl_callback_add_listener(frame
, &frame_listener
, chain
);
521 chain
->fifo_ready
= false;
524 wl_surface_commit(chain
->surface
);
525 wl_display_flush(chain
->display
->display
);
531 wsi_wl_image_finish(struct wsi_wl_swapchain
*chain
, struct wsi_wl_image
*image
)
533 VkDevice vk_device
= anv_device_to_handle(chain
->base
.device
);
534 anv_FreeMemory(vk_device
, anv_device_memory_to_handle(image
->memory
), NULL
);
535 anv_DestroyImage(vk_device
, anv_image_to_handle(image
->image
), NULL
);
539 buffer_handle_release(void *data
, struct wl_buffer
*buffer
)
541 struct wsi_wl_image
*image
= data
;
543 assert(image
->buffer
== buffer
);
548 static const struct wl_buffer_listener buffer_listener
= {
549 buffer_handle_release
,
553 wsi_wl_image_init(struct wsi_wl_swapchain
*chain
, struct wsi_wl_image
*image
)
555 VkDevice vk_device
= anv_device_to_handle(chain
->base
.device
);
559 result
= anv_image_create(vk_device
,
560 &(struct anv_image_create_info
) {
561 .force_tiling
= true,
562 .tiling
= ISL_TILING_X
,
565 &(VkImageCreateInfo
) {
566 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
567 .imageType
= VK_IMAGE_TYPE_2D
,
568 .format
= chain
->vk_format
,
570 .width
= chain
->extent
.width
,
571 .height
= chain
->extent
.height
,
577 /* FIXME: Need a way to use X tiling to allow scanout */
578 .tiling
= VK_IMAGE_TILING_OPTIMAL
,
579 .usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
,
585 if (result
!= VK_SUCCESS
)
588 image
->image
= anv_image_from_handle(vk_image
);
589 assert(anv_format_is_color(image
->image
->format
));
591 struct anv_surface
*surface
= &image
->image
->color_surface
;
593 VkDeviceMemory vk_memory
;
594 result
= anv_AllocateMemory(vk_device
,
595 &(VkMemoryAllocateInfo
) {
596 .sType
= VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
,
597 .allocationSize
= image
->image
->size
,
598 .memoryTypeIndex
= 0,
603 if (result
!= VK_SUCCESS
)
606 image
->memory
= anv_device_memory_from_handle(vk_memory
);
608 result
= anv_BindImageMemory(vk_device
, vk_image
, vk_memory
, 0);
610 if (result
!= VK_SUCCESS
)
613 int ret
= anv_gem_set_tiling(chain
->base
.device
,
614 image
->memory
->bo
.gem_handle
,
615 surface
->stride
, I915_TILING_X
);
617 /* FINISHME: Choose a better error. */
618 result
= vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
622 int fd
= anv_gem_handle_to_fd(chain
->base
.device
,
623 image
->memory
->bo
.gem_handle
);
625 /* FINISHME: Choose a better error. */
626 result
= vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
630 image
->buffer
= wl_drm_create_prime_buffer(chain
->display
->drm
,
633 chain
->extent
.height
,
637 0, 0, 0, 0 /* unused */);
638 wl_display_roundtrip(chain
->display
->display
);
641 wl_proxy_set_queue((struct wl_proxy
*)image
->buffer
, chain
->queue
);
642 wl_buffer_add_listener(image
->buffer
, &buffer_listener
, image
);
647 anv_FreeMemory(vk_device
, vk_memory
, NULL
);
649 anv_DestroyImage(vk_device
, vk_image
, NULL
);
655 wsi_wl_destroy_swapchain(struct anv_swapchain
*anv_chain
)
657 struct wsi_wl_swapchain
*chain
= (struct wsi_wl_swapchain
*)anv_chain
;
659 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
660 if (chain
->images
[i
].buffer
)
661 wsi_wl_image_finish(chain
, &chain
->images
[i
]);
664 anv_free(&chain
->base
.device
->alloc
, chain
);
670 wsi_wl_create_swapchain(struct anv_wsi_implementation
*impl
,
671 struct anv_device
*device
,
672 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
673 struct anv_swapchain
**swapchain_out
)
675 struct wsi_wayland
*wsi
= (struct wsi_wayland
*)impl
;
676 struct wsi_wl_swapchain
*chain
;
679 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
);
681 assert(pCreateInfo
->pSurfaceDescription
->sType
==
682 VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_KHR
);
683 VkSurfaceDescriptionWindowKHR
*vk_window
=
684 (VkSurfaceDescriptionWindowKHR
*)pCreateInfo
->pSurfaceDescription
;
685 assert(vk_window
->platform
== VK_PLATFORM_WAYLAND_KHR
);
687 int num_images
= pCreateInfo
->minImageCount
;
689 assert(num_images
>= MIN_NUM_IMAGES
);
691 /* For true mailbox mode, we need at least 4 images:
692 * 1) One to scan out from
693 * 2) One to have queued for scan-out
694 * 3) One to be currently held by the Wayland compositor
695 * 4) One to render to
697 if (pCreateInfo
->presentMode
== VK_PRESENT_MODE_MAILBOX_KHR
)
698 num_images
= MAX2(num_images
, 4);
700 size_t size
= sizeof(*chain
) + num_images
* sizeof(chain
->images
[0]);
701 chain
= anv_alloc(&device
->alloc
, size
, 8,
702 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
704 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
706 chain
->base
.device
= device
;
707 chain
->base
.destroy
= wsi_wl_destroy_swapchain
;
708 chain
->base
.get_images
= wsi_wl_get_images
;
709 chain
->base
.acquire_next_image
= wsi_wl_acquire_next_image
;
710 chain
->base
.queue_present
= wsi_wl_queue_present
;
712 chain
->surface
= vk_window
->pPlatformWindow
;
713 chain
->extent
= pCreateInfo
->imageExtent
;
714 chain
->vk_format
= pCreateInfo
->imageFormat
;
715 chain
->drm_format
= wl_drm_format_for_vk_format(chain
->vk_format
, false);
717 chain
->present_mode
= pCreateInfo
->presentMode
;
718 chain
->fifo_ready
= true;
720 chain
->image_count
= num_images
;
722 /* Mark a bunch of stuff as NULL. This way we can just call
723 * destroy_swapchain for cleanup.
725 for (uint32_t i
= 0; i
< chain
->image_count
; i
++)
726 chain
->images
[i
].buffer
= NULL
;
729 chain
->display
= wsi_wl_get_display(wsi
, vk_window
->pPlatformHandle
);
733 chain
->queue
= wl_display_create_queue(chain
->display
->display
);
737 for (uint32_t i
= 0; i
< chain
->image_count
; i
++) {
738 result
= wsi_wl_image_init(chain
, &chain
->images
[i
]);
739 if (result
!= VK_SUCCESS
)
741 chain
->images
[i
].busy
= false;
744 *swapchain_out
= &chain
->base
;
749 wsi_wl_destroy_swapchain(&chain
->base
);
755 anv_wl_init_wsi(struct anv_instance
*instance
)
757 struct wsi_wayland
*wsi
;
760 wsi
= anv_alloc(&instance
->alloc
, sizeof(*wsi
), 8,
761 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
763 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
765 wsi
->base
.get_window_supported
= wsi_wl_get_window_supported
;
766 wsi
->base
.get_surface_properties
= wsi_wl_get_surface_properties
;
767 wsi
->base
.get_surface_formats
= wsi_wl_get_surface_formats
;
768 wsi
->base
.get_surface_present_modes
= wsi_wl_get_surface_present_modes
;
769 wsi
->base
.create_swapchain
= wsi_wl_create_swapchain
;
771 wsi
->instance
= instance
;
773 int ret
= pthread_mutex_init(&wsi
->mutex
, NULL
);
776 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
778 /* FINISHME: Choose a better error. */
779 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
785 wsi
->displays
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
786 _mesa_key_pointer_equal
);
787 if (!wsi
->displays
) {
788 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
792 instance
->wsi_impl
[VK_PLATFORM_WAYLAND_KHR
] = &wsi
->base
;
797 pthread_mutex_destroy(&wsi
->mutex
);
800 anv_free(&instance
->alloc
, wsi
);
806 anv_wl_finish_wsi(struct anv_instance
*instance
)
808 struct wsi_wayland
*wsi
=
809 (struct wsi_wayland
*)instance
->wsi_impl
[VK_PLATFORM_WAYLAND_KHR
];
811 _mesa_hash_table_destroy(wsi
->displays
, NULL
);
813 pthread_mutex_destroy(&wsi
->mutex
);
815 anv_free(&instance
->alloc
, wsi
);