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 | 18 +++++--------- src/vulkan/wsi/wsi_common.h | 4 ++- src/vulkan/wsi/wsi_common_wayland.c | 1 - src/vulkan/wsi/wsi_common_x11.c | 42 ++++++------------------------- 5 files changed, 46 insertions(+), 68 deletions(-)
diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c index 258e755194..f3095c17e4 100644 --- a/src/amd/vulkan/radv_wsi.c +++ b/src/amd/vulkan/radv_wsi.c @@ -211,45 +211,53 @@ 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; - int fd; 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; - if (should_export) - return VK_SUCCESS; + if (linear) { + result = radv_wsi_image_alloc(device_h, pCreateInfo, pAllocator, + false, &wsi_image->linear_image, + &wsi_image->linear_memory); + if (result != VK_SUCCESS) + goto fail_alloc; + } else { + wsi_image->linear_image = VK_NULL_HANDLE; + wsi_image->linear_memory = VK_NULL_HANDLE; + } - image = radv_image_from_handle(image_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); - RADV_FROM_HANDLE(radv_device_memory, memory, memory_h); - if (!radv_get_memory_fd(device, memory, &fd)) - goto fail_alloc; - - wsi_image->fds[0] = fd; - wsi_image->image = image_h; - wsi_image->memory = memory_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; wsi_image->row_pitches[0] = surface->u.legacy.level[0].nblk_x * surface->bpe; 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; } @@ -258,8 +266,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 82708b6dbc..8a40627a15 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) { @@ -248,17 +247,12 @@ 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(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(VK_ERROR_OUT_OF_DEVICE_MEMORY, + "handle_to_fd failed: %m"); + goto fail_alloc_memory; } wsi_image->image = image_h; 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 c44db405be..22d7785a7a 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -697,7 +697,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..456a649bb6 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,28 @@ 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; - } - } - 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 +1011,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 +1030,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.2 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev