From a2d765d4bfea7bdeece306b04a056265f80db03c Mon Sep 17 00:00:00 2001 From: Etaash Mathamsetty <45927311+Etaash-mathamsetty@users.noreply.github.com> Date: Tue, 27 May 2025 14:14:56 -0400 Subject: [PATCH 1/2] vulkan/wsi/wayland: Move drm syncobj to swapchain. cc: mesa-stable --- src/vulkan/wsi/wsi_common_wayland.c | 39 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index fd0b398d5f1..97e792a6ac6 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -185,9 +185,6 @@ struct wsi_wl_surface { struct zwp_linux_dmabuf_feedback_v1 *wl_dmabuf_feedback; struct dmabuf_feedback dmabuf_feedback, pending_dmabuf_feedback; - - struct wp_linux_drm_syncobj_surface_v1 *wl_syncobj_surface; - struct vk_instance *instance; struct { @@ -206,6 +203,7 @@ struct wsi_wl_swapchain { struct wp_tearing_control_v1 *tearing_control; struct wp_fifo_v1 *fifo; struct wp_commit_timer_v1 *commit_timer; + struct wp_linux_drm_syncobj_surface_v1 *wl_syncobj_surface; struct wl_callback *frame; @@ -1409,7 +1407,7 @@ wsi_wl_swapchain_update_colorspace(struct wsi_wl_swapchain *chain) } } - wp_color_management_surface_v1_set_image_description(chain->wsi_wl_surface->color.color_surface, + wp_color_management_surface_v1_set_image_description(chain->color.color_surface, image_desc, WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL); wp_image_description_v1_destroy(image_desc); @@ -2203,9 +2201,6 @@ wsi_wl_surface_destroy(VkIcdSurfaceBase *icd_surface, VkInstance _instance, struct wsi_wl_surface *wsi_wl_surface = wl_container_of((VkIcdSurfaceWayland *)icd_surface, wsi_wl_surface, base); - if (wsi_wl_surface->wl_syncobj_surface) - wp_linux_drm_syncobj_surface_v1_destroy(wsi_wl_surface->wl_syncobj_surface); - if (wsi_wl_surface->wl_dmabuf_feedback) { zwp_linux_dmabuf_feedback_v1_destroy(wsi_wl_surface->wl_dmabuf_feedback); dmabuf_feedback_fini(&wsi_wl_surface->dmabuf_feedback); @@ -2468,15 +2463,6 @@ static VkResult wsi_wl_surface_init(struct wsi_wl_surface *wsi_wl_surface, wsi_wl_surface->display->queue); } - if (wsi_wl_use_explicit_sync(wsi_wl_surface->display, wsi_device)) { - wsi_wl_surface->wl_syncobj_surface = - wp_linux_drm_syncobj_manager_v1_get_surface(wsi_wl_surface->display->wl_syncobj, - wsi_wl_surface->wayland_surface.wrapper); - - if (!wsi_wl_surface->wl_syncobj_surface) - goto fail; - } - return VK_SUCCESS; fail: @@ -3238,11 +3224,11 @@ wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain, /* Incremented by signal in base queue_present. */ uint64_t acquire_point = image->base.explicit_sync[WSI_ES_ACQUIRE].timeline; uint64_t release_point = image->base.explicit_sync[WSI_ES_RELEASE].timeline; - wp_linux_drm_syncobj_surface_v1_set_acquire_point(wsi_wl_surface->wl_syncobj_surface, + wp_linux_drm_syncobj_surface_v1_set_acquire_point(chain->wl_syncobj_surface, image->wl_syncobj_timeline[WSI_ES_ACQUIRE], (uint32_t)(acquire_point >> 32), (uint32_t)(acquire_point & 0xffffffff)); - wp_linux_drm_syncobj_surface_v1_set_release_point(wsi_wl_surface->wl_syncobj_surface, + wp_linux_drm_syncobj_surface_v1_set_release_point(chain->wl_syncobj_surface, image->wl_syncobj_timeline[WSI_ES_RELEASE], (uint32_t)(release_point >> 32), (uint32_t)(release_point & 0xffffffff)); @@ -3591,6 +3577,8 @@ wsi_wl_swapchain_chain_free(struct wsi_wl_swapchain *chain, wl_callback_destroy(chain->frame); if (chain->tearing_control) wp_tearing_control_v1_destroy(chain->tearing_control); + if (chain->wl_syncobj_surface) + wp_linux_drm_syncobj_surface_v1_destroy(chain->wl_syncobj_surface); if (needs_color_surface(wsi_wl_surface->display, chain->color.colorspace) && wsi_wl_surface->color.color_surface) { wsi_wl_surface_remove_color_refcount(wsi_wl_surface); @@ -3722,6 +3710,10 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, wp_commit_timer_v1_destroy(old_chain->commit_timer); old_chain->commit_timer = NULL; } + if (old_chain->wl_syncobj_surface) { + wp_linux_drm_syncobj_surface_v1_destroy(old_chain->wl_syncobj_surface); + old_chain->wl_syncobj_surface = NULL; + } } /* Take ownership of the wsi_wl_surface */ @@ -3770,6 +3762,17 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, WP_TEARING_CONTROL_V1_PRESENTATION_HINT_ASYNC); } + if (wsi_wl_use_explicit_sync(wsi_wl_surface->display, wsi_device)) { + chain->wl_syncobj_surface = + wp_linux_drm_syncobj_manager_v1_get_surface(wsi_wl_surface->display->wl_syncobj, + wsi_wl_surface->wayland_surface.wrapper); + + if (!chain->wl_syncobj_surface) { + result = VK_ERROR_OUT_OF_HOST_MEMORY; + goto fail; + } + } + chain->color.colorspace = pCreateInfo->imageColorSpace; enum wsi_wl_buffer_type buffer_type; From 99f6c3308cd4189691d53faa5bb8998452b3a4d6 Mon Sep 17 00:00:00 2001 From: Etaash Mathamsetty <45927311+Etaash-mathamsetty@users.noreply.github.com> Date: Tue, 27 May 2025 15:01:29 -0400 Subject: [PATCH 2/2] vulkan/wsi/wayland: Move color management surface to swapchain. cc: mesa-stable --- src/vulkan/wsi/wsi_common_wayland.c | 45 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index 97e792a6ac6..885d1eff490 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -188,8 +188,6 @@ struct wsi_wl_surface { struct vk_instance *instance; struct { - struct wp_color_management_surface_v1 *color_surface; - int color_surface_refcount; VkColorSpaceKHR colorspace; VkHdrMetadataEXT hdr_metadata; bool has_hdr_metadata; @@ -248,6 +246,8 @@ struct wsi_wl_swapchain { } present_ids; struct { + struct wp_color_management_surface_v1 *color_surface; + int color_surface_refcount; VkColorSpaceKHR colorspace; VkHdrMetadataEXT hdr_metadata; bool has_hdr_metadata; @@ -1196,23 +1196,24 @@ needs_color_surface(struct wsi_wl_display *display, VkColorSpaceKHR colorspace) } static void -wsi_wl_surface_add_color_refcount(struct wsi_wl_surface *wsi_surface) +wsi_wl_swapchain_add_color_refcount(struct wsi_wl_swapchain *chain) { - wsi_surface->color.color_surface_refcount++; - if (wsi_surface->color.color_surface_refcount == 1) { - wsi_surface->color.color_surface = + struct wsi_wl_surface *wsi_surface = chain->wsi_wl_surface; + chain->color.color_surface_refcount++; + if (chain->color.color_surface_refcount == 1) { + chain->color.color_surface = wp_color_manager_v1_get_surface(wsi_surface->display->color_manager, wsi_surface->wayland_surface.wrapper); } } static void -wsi_wl_surface_remove_color_refcount(struct wsi_wl_surface *wsi_surface) +wsi_wl_swapchain_remove_color_refcount(struct wsi_wl_swapchain *chain) { - wsi_surface->color.color_surface_refcount--; - if (wsi_surface->color.color_surface_refcount == 0) { - wp_color_management_surface_v1_destroy(wsi_surface->color.color_surface); - wsi_surface->color.color_surface = NULL; + chain->color.color_surface_refcount--; + if (chain->color.color_surface_refcount == 0) { + wp_color_management_surface_v1_destroy(chain->color.color_surface); + chain->color.color_surface = NULL; } } @@ -1288,14 +1289,14 @@ wsi_wl_swapchain_update_colorspace(struct wsi_wl_swapchain *chain) } } - bool new_color_surface = !surface->color.color_surface; + bool new_color_surface = !chain->color.color_surface; bool needs_color_surface_new = needs_color_surface(display, chain->color.colorspace); - bool needs_color_surface_old = surface->color.color_surface && + bool needs_color_surface_old = chain->color.color_surface && needs_color_surface(display, surface->color.colorspace); if (!needs_color_surface_old && needs_color_surface_new) { - wsi_wl_surface_add_color_refcount(surface); + wsi_wl_swapchain_add_color_refcount(chain); } else if (needs_color_surface_old && !needs_color_surface_new) { - wsi_wl_surface_remove_color_refcount(surface); + wsi_wl_swapchain_remove_color_refcount(chain); } struct wayland_hdr_metadata wayland_hdr_metadata = { @@ -2207,9 +2208,6 @@ wsi_wl_surface_destroy(VkIcdSurfaceBase *icd_surface, VkInstance _instance, dmabuf_feedback_fini(&wsi_wl_surface->pending_dmabuf_feedback); } - if (wsi_wl_surface->color.color_surface) - wp_color_management_surface_v1_destroy(wsi_wl_surface->color.color_surface); - loader_wayland_surface_destroy(&wsi_wl_surface->wayland_surface); if (wsi_wl_surface->display) @@ -3579,10 +3577,8 @@ wsi_wl_swapchain_chain_free(struct wsi_wl_swapchain *chain, wp_tearing_control_v1_destroy(chain->tearing_control); if (chain->wl_syncobj_surface) wp_linux_drm_syncobj_surface_v1_destroy(chain->wl_syncobj_surface); - if (needs_color_surface(wsi_wl_surface->display, chain->color.colorspace) && - wsi_wl_surface->color.color_surface) { - wsi_wl_surface_remove_color_refcount(wsi_wl_surface); - } + if (chain->color.color_surface) + wp_color_management_surface_v1_destroy(chain->color.color_surface); /* Only unregister if we are the non-retired swapchain, or * we are a retired swapchain and memory allocation failed, @@ -3714,6 +3710,11 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, wp_linux_drm_syncobj_surface_v1_destroy(old_chain->wl_syncobj_surface); old_chain->wl_syncobj_surface = NULL; } + if (old_chain->color.color_surface) { + wp_color_management_surface_v1_destroy(old_chain->color.color_surface); + old_chain->color.color_surface_refcount = 0; + old_chain->color.color_surface = NULL; + } } /* Take ownership of the wsi_wl_surface */