From a69a4f393b0b0ae36241c8ced2c47438386a529e Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 15 Jun 2023 13:26:23 -0400 Subject: [PATCH] vk/wsi: unify dmabuf exporting Acked-by: Daniel Stone Reviewed-by: Joshua Ashton Part-of: --- src/vulkan/wsi/wsi_common_drm.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/vulkan/wsi/wsi_common_drm.c b/src/vulkan/wsi/wsi_common_drm.c index 43c380c..35fa913 100644 --- a/src/vulkan/wsi/wsi_common_drm.c +++ b/src/vulkan/wsi/wsi_common_drm.c @@ -451,6 +451,23 @@ fail_oom: } static VkResult +wsi_init_image_dmabuf_fd(const struct wsi_swapchain *chain, + struct wsi_image *image, + bool linear) +{ + const struct wsi_device *wsi = chain->wsi; + const VkMemoryGetFdInfoKHR memory_get_fd_info = { + .sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR, + .pNext = NULL, + .memory = linear ? image->blit.memory : image->memory, + .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + }; + + return wsi->GetMemoryFdKHR(chain->device, &memory_get_fd_info, + &image->dma_buf_fd); +} + +static VkResult wsi_create_native_image_mem(const struct wsi_swapchain *chain, const struct wsi_image_info *info, struct wsi_image *image) @@ -489,15 +506,7 @@ wsi_create_native_image_mem(const struct wsi_swapchain *chain, if (result != VK_SUCCESS) return result; - const VkMemoryGetFdInfoKHR memory_get_fd_info = { - .sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR, - .pNext = NULL, - .memory = image->memory, - .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, - }; - - result = wsi->GetMemoryFdKHR(chain->device, &memory_get_fd_info, - &image->dma_buf_fd); + result = wsi_init_image_dmabuf_fd(chain, image, false); if (result != VK_SUCCESS) return result; @@ -558,7 +567,6 @@ wsi_create_prime_image_mem(const struct wsi_swapchain *chain, const struct wsi_image_info *info, struct wsi_image *image) { - const struct wsi_device *wsi = chain->wsi; VkResult result = wsi_create_buffer_blit_context(chain, info, image, VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, @@ -566,14 +574,7 @@ wsi_create_prime_image_mem(const struct wsi_swapchain *chain, if (result != VK_SUCCESS) return result; - const VkMemoryGetFdInfoKHR linear_memory_get_fd_info = { - .sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR, - .pNext = NULL, - .memory = image->blit.memory, - .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, - }; - result = wsi->GetMemoryFdKHR(chain->device, &linear_memory_get_fd_info, - &image->dma_buf_fd); + result = wsi_init_image_dmabuf_fd(chain, image, true); if (result != VK_SUCCESS) return result; -- 2.7.4