X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fvulkan%2Fwsi%2Fwsi_common_wayland.c;h=644ed62b414f2fb01c30f848fcee9b0d9b063d07;hb=1586768e7475a2732650f0ec2738b4e8429e4b40;hp=5c72c8aa2364b68bc997d095ade878111761d3aa;hpb=52e6271ffd68b78f154ac312a01989ce92b59348;p=mesa.git diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index 5c72c8aa236..644ed62b414 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -46,7 +46,11 @@ struct wsi_wayland; struct wsi_wl_display { - struct wl_display * display; + /* The real wl_display */ + struct wl_display * wl_display; + /* Actually a proxy wrapper around the event queue */ + struct wl_display * wl_display_wrapper; + struct wl_event_queue * queue; struct wl_drm * drm; struct wsi_wayland *wsi_wl; @@ -251,6 +255,10 @@ wsi_wl_display_destroy(struct wsi_wayland *wsi, struct wsi_wl_display *display) u_vector_finish(&display->formats); if (display->drm) wl_drm_destroy(display->drm); + if (display->wl_display_wrapper) + wl_proxy_wrapper_destroy(display->wl_display_wrapper); + if (display->queue) + wl_event_queue_destroy(display->queue); vk_free(wsi->alloc, display); } @@ -265,40 +273,53 @@ wsi_wl_display_create(struct wsi_wayland *wsi, struct wl_display *wl_display) memset(display, 0, sizeof(*display)); - display->display = wl_display; display->wsi_wl = wsi; + display->wl_display = wl_display; if (!u_vector_init(&display->formats, sizeof(VkFormat), 8)) goto fail; - struct wl_registry *registry = wl_display_get_registry(wl_display); + display->queue = wl_display_create_queue(wl_display); + if (!display->queue) + goto fail; + + display->wl_display_wrapper = wl_proxy_create_wrapper(wl_display); + if (!display->wl_display_wrapper) + goto fail; + + wl_proxy_set_queue((struct wl_proxy *) display->wl_display_wrapper, + display->queue); + + struct wl_registry *registry = + wl_display_get_registry(display->wl_display_wrapper); if (!registry) - return NULL; + goto fail; wl_registry_add_listener(registry, ®istry_listener, display); - /* Round-rip to get the wl_drm global */ - wl_display_roundtrip(wl_display); + /* Round-trip to get the wl_drm global */ + wl_display_roundtrip_queue(display->wl_display, display->queue); if (!display->drm) - goto fail; + goto fail_registry; - /* Round-rip to get wl_drm formats and capabilities */ - wl_display_roundtrip(wl_display); + /* Round-trip to get wl_drm formats and capabilities */ + wl_display_roundtrip_queue(display->wl_display, display->queue); /* We need prime support */ if (!(display->capabilities & WL_DRM_CAPABILITY_PRIME)) - goto fail; + goto fail_registry; /* We don't need this anymore */ wl_registry_destroy(registry); return display; -fail: +fail_registry: if (registry) wl_registry_destroy(registry); +fail: wsi_wl_display_destroy(wsi, display); return NULL; } @@ -401,6 +422,16 @@ wsi_wl_surface_get_capabilities(VkIcdSurfaceBase *surface, return VK_SUCCESS; } +static VkResult +wsi_wl_surface_get_capabilities2(VkIcdSurfaceBase *surface, + const void *info_next, + VkSurfaceCapabilities2KHR* caps) +{ + assert(caps->sType == VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR); + + return wsi_wl_surface_get_capabilities(surface, &caps->surfaceCapabilities); +} + static VkResult wsi_wl_surface_get_formats(VkIcdSurfaceBase *icd_surface, struct wsi_device *wsi_device, @@ -426,6 +457,32 @@ wsi_wl_surface_get_formats(VkIcdSurfaceBase *icd_surface, return vk_outarray_status(&out); } +static VkResult +wsi_wl_surface_get_formats2(VkIcdSurfaceBase *icd_surface, + struct wsi_device *wsi_device, + const void *info_next, + uint32_t* pSurfaceFormatCount, + VkSurfaceFormat2KHR* pSurfaceFormats) +{ + VkIcdSurfaceWayland *surface = (VkIcdSurfaceWayland *)icd_surface; + struct wsi_wl_display *display = + wsi_wl_get_display(wsi_device, surface->display); + if (!display) + return VK_ERROR_OUT_OF_HOST_MEMORY; + + VK_OUTARRAY_MAKE(out, pSurfaceFormats, pSurfaceFormatCount); + + VkFormat *disp_fmt; + u_vector_foreach(disp_fmt, &display->formats) { + vk_outarray_append(&out, out_fmt) { + out_fmt->surfaceFormat.format = *disp_fmt; + out_fmt->surfaceFormat.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; + } + } + + return vk_outarray_status(&out); +} + static VkResult wsi_wl_surface_get_present_modes(VkIcdSurfaceBase *surface, uint32_t* pPresentModeCount, @@ -479,6 +536,8 @@ struct wsi_wl_swapchain { struct wl_event_queue * queue; struct wl_surface * surface; uint32_t surface_version; + struct wl_drm * drm_wrapper; + struct wl_callback * frame; VkExtent2D extent; VkFormat vk_format; @@ -524,7 +583,7 @@ wsi_wl_swapchain_acquire_next_image(struct wsi_swapchain *wsi_chain, { struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)wsi_chain; - int ret = wl_display_dispatch_queue_pending(chain->display->display, + int ret = wl_display_dispatch_queue_pending(chain->display->wl_display, chain->queue); /* XXX: I'm not sure if out-of-date is the right error here. If * wl_display_dispatch_queue_pending fails it most likely means we got @@ -546,7 +605,7 @@ wsi_wl_swapchain_acquire_next_image(struct wsi_swapchain *wsi_chain, /* This time we do a blocking dispatch because we can't go * anywhere until we get an event. */ - int ret = wl_display_roundtrip_queue(chain->display->display, + int ret = wl_display_roundtrip_queue(chain->display->wl_display, chain->queue); if (ret < 0) return VK_ERROR_OUT_OF_DATE_KHR; @@ -558,6 +617,7 @@ frame_handle_done(void *data, struct wl_callback *callback, uint32_t serial) { struct wsi_wl_swapchain *chain = data; + chain->frame = NULL; chain->fifo_ready = true; wl_callback_destroy(callback); @@ -576,7 +636,7 @@ wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain, if (chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR) { while (!chain->fifo_ready) { - int ret = wl_display_dispatch_queue(chain->display->display, + int ret = wl_display_dispatch_queue(chain->display->wl_display, chain->queue); if (ret < 0) return VK_ERROR_OUT_OF_DATE_KHR; @@ -600,15 +660,14 @@ wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain, } if (chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR) { - struct wl_callback *frame = wl_surface_frame(chain->surface); - wl_proxy_set_queue((struct wl_proxy *)frame, chain->queue); - wl_callback_add_listener(frame, &frame_listener, chain); + chain->frame = wl_surface_frame(chain->surface); + wl_callback_add_listener(chain->frame, &frame_listener, chain); chain->fifo_ready = false; } chain->images[image_index].busy = true; wl_surface_commit(chain->surface); - wl_display_flush(chain->display->display); + wl_display_flush(chain->display->wl_display); return VK_SUCCESS; } @@ -653,7 +712,7 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, if (result != VK_SUCCESS) return result; - image->buffer = wl_drm_create_prime_buffer(chain->display->drm, + image->buffer = wl_drm_create_prime_buffer(chain->drm_wrapper, fd, /* name */ chain->extent.width, chain->extent.height, @@ -661,13 +720,11 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, offset, row_pitch, 0, 0, 0, 0 /* unused */); - wl_display_roundtrip(chain->display->display); close(fd); if (!image->buffer) goto fail_image; - wl_proxy_set_queue((struct wl_proxy *)image->buffer, chain->queue); wl_buffer_add_listener(image->buffer, &buffer_listener, image); return VK_SUCCESS; @@ -686,12 +743,23 @@ wsi_wl_swapchain_destroy(struct wsi_swapchain *wsi_chain, struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)wsi_chain; for (uint32_t i = 0; i < chain->base.image_count; i++) { - if (chain->images[i].buffer) + if (chain->images[i].buffer) { + wl_buffer_destroy(chain->images[i].buffer); chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator, chain->images[i].image, chain->images[i].memory); + } } + if (chain->frame) + wl_callback_destroy(chain->frame); + if (chain->surface) + wl_proxy_wrapper_destroy(chain->surface); + if (chain->drm_wrapper) + wl_proxy_wrapper_destroy(chain->drm_wrapper); + if (chain->queue) + wl_event_queue_destroy(chain->queue); + vk_free(pAllocator, chain); return VK_SUCCESS; @@ -721,6 +789,16 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, if (chain == NULL) return VK_ERROR_OUT_OF_HOST_MEMORY; + /* Mark a bunch of stuff as NULL. This way we can just call + * destroy_swapchain for cleanup. + */ + for (uint32_t i = 0; i < num_images; i++) + chain->images[i].buffer = NULL; + chain->queue = NULL; + chain->surface = NULL; + chain->drm_wrapper = NULL; + chain->frame = NULL; + bool alpha = pCreateInfo->compositeAlpha == VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR; @@ -733,34 +811,39 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, chain->base.present_mode = pCreateInfo->presentMode; chain->base.image_count = num_images; chain->base.needs_linear_copy = false; - chain->surface = surface->surface; - chain->surface_version = wl_proxy_get_version((void *)surface->surface); chain->extent = pCreateInfo->imageExtent; chain->vk_format = pCreateInfo->imageFormat; chain->drm_format = wl_drm_format_for_vk_format(chain->vk_format, alpha); - chain->fifo_ready = true; - - /* Mark a bunch of stuff as NULL. This way we can just call - * destroy_swapchain for cleanup. - */ - for (uint32_t i = 0; i < chain->base.image_count; i++) - chain->images[i].buffer = NULL; - chain->queue = NULL; - - chain->display = wsi_wl_get_display(wsi_device, - surface->display); + chain->display = wsi_wl_get_display(wsi_device, surface->display); if (!chain->display) { result = VK_ERROR_INITIALIZATION_FAILED; goto fail; } - chain->queue = wl_display_create_queue(chain->display->display); + chain->queue = wl_display_create_queue(chain->display->wl_display); if (!chain->queue) { result = VK_ERROR_INITIALIZATION_FAILED; goto fail; } + chain->surface = wl_proxy_create_wrapper(surface->surface); + if (!chain->surface) { + result = VK_ERROR_INITIALIZATION_FAILED; + goto fail; + } + wl_proxy_set_queue((struct wl_proxy *) chain->surface, chain->queue); + chain->surface_version = wl_proxy_get_version((void *)surface->surface); + + chain->drm_wrapper = wl_proxy_create_wrapper(chain->display->drm); + if (!chain->drm_wrapper) { + result = VK_ERROR_INITIALIZATION_FAILED; + goto fail; + } + wl_proxy_set_queue((struct wl_proxy *) chain->drm_wrapper, chain->queue); + + chain->fifo_ready = true; + for (uint32_t i = 0; i < chain->base.image_count; i++) { result = wsi_wl_image_init(chain, &chain->images[i], pCreateInfo, pAllocator); @@ -819,7 +902,9 @@ wsi_wl_init_wsi(struct wsi_device *wsi_device, wsi->base.get_support = wsi_wl_surface_get_support; wsi->base.get_capabilities = wsi_wl_surface_get_capabilities; + wsi->base.get_capabilities2 = wsi_wl_surface_get_capabilities2; wsi->base.get_formats = wsi_wl_surface_get_formats; + wsi->base.get_formats2 = wsi_wl_surface_get_formats2; wsi->base.get_present_modes = wsi_wl_surface_get_present_modes; wsi->base.create_swapchain = wsi_wl_surface_create_swapchain;