From 5576e8b73576ff71f08aa8f73ff9cdf945ead536 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 2 Mar 2020 17:40:09 -0600 Subject: [PATCH] vulkan/wsi: Hang on to file descriptors Instead of closing the dma-buf file descriptors immediately after handing them to the window system, hang on to them. We want to be able to use them for synchronization. Reviewed-by: Lionel Landwerlin Reviewed-by: Simon Ser Reviewed-by: Adam Jackson Part-of: --- src/vulkan/wsi/wsi_common_display.c | 2 -- src/vulkan/wsi/wsi_common_wayland.c | 2 -- src/vulkan/wsi/wsi_common_x11.c | 16 ++++++++-------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c index 22823c0aea6..a16b8c5c5ca 100644 --- a/src/vulkan/wsi/wsi_common_display.c +++ b/src/vulkan/wsi/wsi_common_display.c @@ -1109,8 +1109,6 @@ wsi_display_image_init(VkDevice device_h, if (ret < 0) goto fail_handle; } - close(image->base.dma_buf_fd); - image->base.dma_buf_fd = -1; image->chain = chain; image->state = WSI_IMAGE_IDLE; diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index 06e3c395aa4..ce7da864cc5 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -1167,8 +1167,6 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, image->base.drm_modifier >> 32, image->base.drm_modifier & 0xffffffff); } - close(image->base.dma_buf_fd); - image->base.dma_buf_fd = -1; image->buffer = zwp_linux_buffer_params_v1_create_immed(params, diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index ebfa345351f..1c387abcc4b 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -1623,11 +1623,10 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain, /* XCB requires an array of file descriptors but we only have one */ int fds[4] = { -1, -1, -1, -1 }; - fds[0] = image->base.dma_buf_fd; - for (int i = 1; i < image->base.num_planes; i++) { + for (int i = 0; i < image->base.num_planes; i++) { fds[i] = os_dupfd_cloexec(image->base.dma_buf_fd); if (fds[i] == -1) { - for (int j = 1; j < i; j++) + for (int j = 0; j < i; j++) close(fds[j]); return VK_ERROR_OUT_OF_HOST_MEMORY; @@ -1658,6 +1657,11 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain, /* Without passing modifiers, we can't have multi-plane RGB images. */ assert(image->base.num_planes == 1); + /* XCB will take ownership of the FD we pass it. */ + int fd = os_dupfd_cloexec(image->base.dma_buf_fd); + if (fd == -1) + return VK_ERROR_OUT_OF_HOST_MEMORY; + cookie = xcb_dri3_pixmap_from_buffer_checked(chain->conn, image->pixmap, @@ -1666,15 +1670,11 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain, pCreateInfo->imageExtent.width, pCreateInfo->imageExtent.height, image->base.row_pitches[0], - chain->depth, bpp, - image->base.dma_buf_fd); + chain->depth, bpp, fd); } xcb_discard_reply(chain->conn, cookie.sequence); - /* XCB has now taken ownership of the FD. */ - image->base.dma_buf_fd = -1; - out_fence: fence_fd = xshmfence_alloc_shm(); if (fence_fd < 0)