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 <lionel.g.landwerlin@intel.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16333>
This commit is contained in:
Jason Ekstrand 2020-03-02 17:40:09 -06:00 committed by Marge Bot
parent 17fb3ad94f
commit 5576e8b735
3 changed files with 8 additions and 12 deletions

View file

@ -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;

View file

@ -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,

View file

@ -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)