From: Daniel Stone <dani...@collabora.com> This is pretty much radv-specific anyway.
Signed-off-by: Daniel Stone <dani...@collabora.com> --- src/amd/vulkan/radv_wsi.c | 49 +++++++++++++++++++++++-------------- src/intel/vulkan/anv_wsi.c | 23 ++++++++--------- src/vulkan/wsi/wsi_common.h | 4 ++- src/vulkan/wsi/wsi_common_wayland.c | 1 - src/vulkan/wsi/wsi_common_x11.c | 44 ++++++++------------------------- 5 files changed, 54 insertions(+), 67 deletions(-) diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c index cd2b36a57f..bcdbd7ffe9 100644 --- a/src/amd/vulkan/radv_wsi.c +++ b/src/amd/vulkan/radv_wsi.c @@ -212,35 +212,40 @@ static VkResult radv_wsi_image_create(VkDevice device_h, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks* pAllocator, - bool should_export, bool linear, struct wsi_image_base *wsi_image) { VkResult result = VK_SUCCESS; struct radeon_surf *surface; - VkImage image_h; - VkDeviceMemory memory_h; struct radv_image *image; result = radv_wsi_image_alloc(device_h, pCreateInfo, pAllocator, - linear, &image_h, &memory_h); + false, &wsi_image->image, + &wsi_image->memory); if (result != VK_SUCCESS) return result; - image = radv_image_from_handle(image_h); - surface = &image->surface; - - if (should_export) { - RADV_FROM_HANDLE(radv_device, device, device_h); - RADV_FROM_HANDLE(radv_device_memory, memory, memory_h); - if (!radv_get_memory_fd(device, memory, &wsi_image->fds[0])) + if (linear) { + result = radv_wsi_image_alloc(device_h, pCreateInfo, pAllocator, + true, &wsi_image->linear_image, + &wsi_image->linear_memory); + if (result != VK_SUCCESS) goto fail_alloc; } else { - wsi_image->fds[0] = -1; + wsi_image->linear_image = VK_NULL_HANDLE; + wsi_image->linear_memory = VK_NULL_HANDLE; } - wsi_image->image = image_h; - wsi_image->memory = memory_h; + RADV_FROM_HANDLE(radv_device_memory, memory, + linear ? wsi_image->linear_memory : wsi_image->memory); + image = radv_image_from_handle(linear ? wsi_image->linear_image : + wsi_image->image); + surface = &image->surface; + + RADV_FROM_HANDLE(radv_device, device, device_h); + if (!radv_get_memory_fd(device, memory, &wsi_image->fds[0])) + goto fail_linear; + wsi_image->num_planes = 1; wsi_image->sizes[0] = image->size; wsi_image->offsets[0] = image->offset; @@ -253,9 +258,14 @@ radv_wsi_image_create(VkDevice device_h, return VK_SUCCESS; - fail_alloc: - radv_FreeMemory(device_h, memory_h, pAllocator); - radv_DestroyImage(device_h, image_h, pAllocator); +fail_linear: + if (wsi_image->linear_memory != VK_NULL_HANDLE) + radv_FreeMemory(device_h, wsi_image->linear_memory, pAllocator); + if (wsi_image->linear_image != VK_NULL_HANDLE) + radv_DestroyImage(device_h, wsi_image->linear_image, pAllocator); +fail_alloc: + radv_FreeMemory(device_h, wsi_image->memory, pAllocator); + radv_DestroyImage(device_h, wsi_image->image, pAllocator); return result; } @@ -264,8 +274,11 @@ radv_wsi_image_free(VkDevice device, const VkAllocationCallbacks* pAllocator, struct wsi_image_base *wsi_image) { + if (wsi_image->linear_image != VK_NULL_HANDLE) + radv_DestroyImage(device, wsi_image->linear_image, pAllocator); + if (wsi_image->linear_memory != VK_NULL_HANDLE) + radv_FreeMemory(device, wsi_image->linear_memory, pAllocator); radv_DestroyImage(device, wsi_image->image, pAllocator); - radv_FreeMemory(device, wsi_image->memory, pAllocator); } diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c index 4454930d45..f59d349b50 100644 --- a/src/intel/vulkan/anv_wsi.c +++ b/src/intel/vulkan/anv_wsi.c @@ -172,7 +172,6 @@ static VkResult anv_wsi_image_create(VkDevice device_h, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks* pAllocator, - bool should_export, bool linear, struct wsi_image_base *wsi_image) { @@ -249,22 +248,20 @@ anv_wsi_image_create(VkDevice device_h, goto fail_alloc_memory; } - int fd; - if (should_export) { - fd = anv_gem_handle_to_fd(device, memory->bo->gem_handle); - if (fd == -1) { - /* FINISHME: Choose a better error. */ - result = vk_errorf(device->instance, device, - VK_ERROR_OUT_OF_DEVICE_MEMORY, - "handle_to_fd failed: %m"); - goto fail_alloc_memory; - } - } else { - fd = -1; + int fd = anv_gem_handle_to_fd(device, memory->bo->gem_handle); + if (fd == -1) { + /* FINISHME: Choose a better error. */ + result = vk_errorf(device->instance, device, + VK_ERROR_OUT_OF_DEVICE_MEMORY, + "handle_to_fd failed: %m"); + goto fail_alloc_memory; } wsi_image->image = image_h; wsi_image->memory = memory_h; + wsi_image->linear_image = VK_NULL_HANDLE; + wsi_image->linear_memory = VK_NULL_HANDLE; + wsi_image->num_planes = 1; wsi_image->fds[0] = fd; wsi_image->sizes[0] = image->size; diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h index b6c5a438b1..33fa8c2b0d 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -33,6 +33,9 @@ struct wsi_image_base { VkImage image; VkDeviceMemory memory; + VkImage linear_image; + VkDeviceMemory linear_memory; + int num_planes; uint32_t sizes[4]; uint32_t offsets[4]; @@ -45,7 +48,6 @@ struct wsi_image_fns { VkResult (*create_wsi_image)(VkDevice device_h, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, - bool should_export, bool linear, struct wsi_image_base *image_p); void (*free_wsi_image)(VkDevice device, diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index a76e29d26e..8df30d993c 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -730,7 +730,6 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, result = chain->base.image_fns->create_wsi_image(vk_device, pCreateInfo, pAllocator, - true, false, &image->base); if (result != VK_SUCCESS) diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index f9954d6e37..784d275dc5 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -616,7 +616,6 @@ VkResult wsi_create_xlib_surface(const VkAllocationCallbacks *pAllocator, struct x11_image { struct wsi_image_base base; - struct wsi_image_base linear_base; xcb_pixmap_t pixmap; bool busy; struct xshmfence * shm_fence; @@ -679,7 +678,7 @@ x11_get_image_and_linear(struct wsi_swapchain *drv_chain, { struct x11_swapchain *chain = (struct x11_swapchain *)drv_chain; *image = chain->images[imageIndex].base.image; - *linear_image = chain->images[imageIndex].linear_base.image; + *linear_image = chain->images[imageIndex].base.linear_image; } static VkResult @@ -962,47 +961,32 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain, result = chain->base.image_fns->create_wsi_image(device_h, pCreateInfo, pAllocator, - !chain->base.needs_linear_copy, - false, + chain->base.needs_linear_copy, &image->base); if (result != VK_SUCCESS) return result; - if (chain->base.needs_linear_copy) { - result = chain->base.image_fns->create_wsi_image(device_h, - pCreateInfo, - pAllocator, - true, - true, - &image->linear_base); - - if (result != VK_SUCCESS) { - chain->base.image_fns->free_wsi_image(device_h, pAllocator, - &image->base); - return result; - } - } + /* The driver has decided to allocate a linear copy, for whatever reason. */ + if (image->base.linear_image != VK_NULL_HANDLE) + chain->base.needs_linear_copy = true; image->pixmap = xcb_generate_id(chain->conn); - struct wsi_image_base *image_ws = - chain->base.needs_linear_copy ? &image->linear_base : &image->base; - /* Without passing modifiers, we can't have multi-plane RGB images. */ - assert(image_ws->num_planes == 1); + assert(image->base.num_planes == 1); cookie = xcb_dri3_pixmap_from_buffer_checked(chain->conn, image->pixmap, chain->window, - image_ws->sizes[0], + image->base.sizes[0], pCreateInfo->imageExtent.width, pCreateInfo->imageExtent.height, - image_ws->row_pitches[0], + image->base.row_pitches[0], chain->depth, bpp, - image_ws->fds[0]); + image->base.fds[0]); xcb_discard_reply(chain->conn, cookie.sequence); - image_ws->fds[0] = -1; /* XCB has now taken ownership of the FD */ + image->base.fds[0] = -1; /* XCB has now taken ownership of the FD */ int fence_fd = xshmfence_alloc_shm(); if (fence_fd < 0) @@ -1031,10 +1015,6 @@ fail_pixmap: cookie = xcb_free_pixmap(chain->conn, image->pixmap); xcb_discard_reply(chain->conn, cookie.sequence); - if (chain->base.needs_linear_copy) { - chain->base.image_fns->free_wsi_image(device_h, pAllocator, - &image->linear_base); - } chain->base.image_fns->free_wsi_image(device_h, pAllocator, &image->base); return result; @@ -1054,10 +1034,6 @@ x11_image_finish(struct x11_swapchain *chain, cookie = xcb_free_pixmap(chain->conn, image->pixmap); xcb_discard_reply(chain->conn, cookie.sequence); - if (chain->base.needs_linear_copy) { - chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator, - &image->linear_base); - } chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator, &image->base); } -- 2.13.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev