diff options
author | Daniel Stone <[email protected]> | 2017-07-20 11:51:48 +0100 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2017-12-04 10:04:19 -0800 |
commit | c1163f7b1c3f56bb268f61205a67f019806ae785 (patch) | |
tree | 340277936ee22565d86fddae622a8efc266f7c42 /src | |
parent | 2cbeb32555421ae302222e6e730b412c82742d74 (diff) |
vulkan/wsi: Add a wsi_image structure
This is used to hold information about the allocated image, rather than
an ever-growing function argument list.
v2 (Jason Ekstrand):
- Rename wsi_image_base to wsi_image
Signed-off-by: Daniel Stone <[email protected]>
Reviewed-by: Jason Ekstrand <[email protected]>
Reviewed-by: Dave Airlie <[email protected]>
Reviewed-by: Chad Versace <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/amd/vulkan/radv_wsi.c | 31 | ||||
-rw-r--r-- | src/intel/vulkan/anv_wsi.c | 25 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common.h | 19 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_wayland.c | 31 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_x11.c | 52 |
5 files changed, 65 insertions, 93 deletions
diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c index 98346cae062..f5f9a3fbeba 100644 --- a/src/amd/vulkan/radv_wsi.c +++ b/src/amd/vulkan/radv_wsi.c @@ -145,11 +145,7 @@ radv_wsi_image_create(VkDevice device_h, const VkAllocationCallbacks* pAllocator, bool needs_linear_copy, bool linear, - VkImage *image_p, - VkDeviceMemory *memory_p, - uint32_t *size, - uint32_t *offset, - uint32_t *row_pitch, int *fd_p) + struct wsi_image *wsi_image) { VkResult result = VK_SUCCESS; struct radeon_surf *surface; @@ -232,20 +228,22 @@ radv_wsi_image_create(VkDevice device_h, RADV_FROM_HANDLE(radv_device_memory, memory, memory_h); if (!radv_get_memory_fd(device, memory, &fd)) goto fail_alloc_memory; - *fd_p = fd; + wsi_image->fd = fd; } surface = &image->surface; - *image_p = image_h; - *memory_p = memory_h; - *size = image->size; - *offset = image->offset; - + wsi_image->image = image_h; + wsi_image->memory = memory_h; + wsi_image->size = image->size; + wsi_image->offset = image->offset; if (device->physical_device->rad_info.chip_class >= GFX9) - *row_pitch = surface->u.gfx9.surf_pitch * surface->bpe; + wsi_image->row_pitch = + surface->u.gfx9.surf_pitch * surface->bpe; else - *row_pitch = surface->u.legacy.level[0].nblk_x * surface->bpe; + wsi_image->row_pitch = + surface->u.legacy.level[0].nblk_x * surface->bpe; + return VK_SUCCESS; fail_alloc_memory: radv_FreeMemory(device_h, memory_h, pAllocator); @@ -259,12 +257,11 @@ fail_create_image: static void radv_wsi_image_free(VkDevice device, const VkAllocationCallbacks* pAllocator, - VkImage image_h, - VkDeviceMemory memory_h) + struct wsi_image *wsi_image) { - radv_DestroyImage(device, image_h, pAllocator); + radv_DestroyImage(device, wsi_image->image, pAllocator); - radv_FreeMemory(device, memory_h, pAllocator); + radv_FreeMemory(device, wsi_image->memory, pAllocator); } static const struct wsi_image_fns radv_wsi_image_fns = { diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c index 945b01147ea..d8c4885b5b8 100644 --- a/src/intel/vulkan/anv_wsi.c +++ b/src/intel/vulkan/anv_wsi.c @@ -175,11 +175,7 @@ anv_wsi_image_create(VkDevice device_h, const VkAllocationCallbacks* pAllocator, bool different_gpu, bool linear, - VkImage *image_p, - VkDeviceMemory *memory_p, - uint32_t *size, - uint32_t *offset, - uint32_t *row_pitch, int *fd_p) + struct wsi_image *wsi_image) { struct anv_device *device = anv_device_from_handle(device_h); VkImage image_h; @@ -245,7 +241,6 @@ anv_wsi_image_create(VkDevice device_h, struct anv_surface *surface = &image->planes[0].surface; assert(surface->isl.tiling == ISL_TILING_X); - *row_pitch = surface->isl.row_pitch; int ret = anv_gem_set_tiling(device, memory->bo->gem_handle, surface->isl.row_pitch, I915_TILING_X); if (ret) { @@ -265,11 +260,12 @@ anv_wsi_image_create(VkDevice device_h, goto fail_alloc_memory; } - *image_p = image_h; - *memory_p = memory_h; - *fd_p = fd; - *size = image->size; - *offset = 0; + wsi_image->image = image_h; + wsi_image->memory = memory_h; + wsi_image->fd = fd; + wsi_image->size = image->size; + wsi_image->offset = 0; + wsi_image->row_pitch = surface->isl.row_pitch; return VK_SUCCESS; fail_alloc_memory: anv_FreeMemory(device_h, memory_h, pAllocator); @@ -282,12 +278,11 @@ fail_create_image: static void anv_wsi_image_free(VkDevice device, const VkAllocationCallbacks* pAllocator, - VkImage image_h, - VkDeviceMemory memory_h) + struct wsi_image *wsi_image) { - anv_DestroyImage(device, image_h, pAllocator); + anv_DestroyImage(device, wsi_image->image, pAllocator); - anv_FreeMemory(device, memory_h, pAllocator); + anv_FreeMemory(device, wsi_image->memory, pAllocator); } static const struct wsi_image_fns anv_wsi_image_fns = { diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h index 7be0182adfa..565219d4e26 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -30,6 +30,15 @@ #include <vulkan/vulkan.h> #include <vulkan/vk_icd.h> +struct wsi_image { + VkImage image; + VkDeviceMemory memory; + uint32_t size; + uint32_t offset; + uint32_t row_pitch; + int fd; +}; + struct wsi_device; struct wsi_image_fns { VkResult (*create_wsi_image)(VkDevice device_h, @@ -37,16 +46,10 @@ struct wsi_image_fns { const VkAllocationCallbacks *pAllocator, bool needs_linear_copy, bool linear, - VkImage *image_p, - VkDeviceMemory *memory_p, - uint32_t *size_p, - uint32_t *offset_p, - uint32_t *row_pitch_p, - int *fd_p); + struct wsi_image *image_p); void (*free_wsi_image)(VkDevice device, const VkAllocationCallbacks *pAllocator, - VkImage image_h, - VkDeviceMemory memory_h); + struct wsi_image *image); }; struct wsi_swapchain { diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index b93c3d7e0d7..c7c7da64979 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -556,8 +556,7 @@ VkResult wsi_create_wl_surface(const VkAllocationCallbacks *pAllocator, } struct wsi_wl_image { - VkImage image; - VkDeviceMemory memory; + struct wsi_image base; struct wl_buffer * buffer; bool busy; }; @@ -603,7 +602,7 @@ wsi_wl_swapchain_get_images(struct wsi_swapchain *wsi_chain, } for (uint32_t i = 0; i < ret_count; i++) - pSwapchainImages[i] = chain->images[i].image; + pSwapchainImages[i] = chain->images[i].base.image; return result; } @@ -727,33 +726,25 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, { VkDevice vk_device = chain->base.device; VkResult result; - int fd; - uint32_t size; - uint32_t row_pitch; - uint32_t offset; + result = chain->base.image_fns->create_wsi_image(vk_device, pCreateInfo, pAllocator, false, false, - &image->image, - &image->memory, - &size, - &offset, - &row_pitch, - &fd); + &image->base); if (result != VK_SUCCESS) return result; image->buffer = wl_drm_create_prime_buffer(chain->drm_wrapper, - fd, /* name */ + image->base.fd, /* name */ chain->extent.width, chain->extent.height, chain->drm_format, - offset, - row_pitch, + image->base.offset, + image->base.row_pitch, 0, 0, 0, 0 /* unused */); - close(fd); + close(image->base.fd); if (!image->buffer) goto fail_image; @@ -763,8 +754,7 @@ wsi_wl_image_init(struct wsi_wl_swapchain *chain, return VK_SUCCESS; fail_image: - chain->base.image_fns->free_wsi_image(vk_device, pAllocator, - image->image, image->memory); + chain->base.image_fns->free_wsi_image(vk_device, pAllocator, &image->base); return result; } @@ -779,8 +769,7 @@ wsi_wl_swapchain_destroy(struct wsi_swapchain *wsi_chain, if (chain->images[i].buffer) { wl_buffer_destroy(chain->images[i].buffer); chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator, - chain->images[i].image, - chain->images[i].memory); + &chain->images[i].base); } } diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index 22b067bf787..22b894edf00 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -615,10 +615,8 @@ VkResult wsi_create_xlib_surface(const VkAllocationCallbacks *pAllocator, } struct x11_image { - VkImage image; - VkImage linear_image; // for prime - VkDeviceMemory memory; - VkDeviceMemory linear_memory; // for prime + struct wsi_image base; + struct wsi_image linear_base; xcb_pixmap_t pixmap; bool busy; struct xshmfence * shm_fence; @@ -670,7 +668,7 @@ x11_get_images(struct wsi_swapchain *anv_chain, } for (uint32_t i = 0; i < ret_count; i++) - pSwapchainImages[i] = chain->images[i].image; + pSwapchainImages[i] = chain->images[i].base.image; return result; } @@ -680,8 +678,8 @@ x11_get_image_and_linear(struct wsi_swapchain *drv_chain, int imageIndex, VkImage *image, VkImage *linear_image) { struct x11_swapchain *chain = (struct x11_swapchain *)drv_chain; - *image = chain->images[imageIndex].image; - *linear_image = chain->images[imageIndex].linear_image; + *image = chain->images[imageIndex].base.image; + *linear_image = chain->images[imageIndex].linear_base.image; } static VkResult @@ -960,23 +958,14 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain, { xcb_void_cookie_t cookie; VkResult result; - uint32_t row_pitch; - uint32_t offset; uint32_t bpp = 32; - int fd; - uint32_t size; result = chain->base.image_fns->create_wsi_image(device_h, pCreateInfo, pAllocator, chain->base.needs_linear_copy, false, - &image->image, - &image->memory, - &size, - &offset, - &row_pitch, - &fd); + &image->base); if (result != VK_SUCCESS) return result; @@ -986,31 +975,31 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain, pAllocator, chain->base.needs_linear_copy, true, - &image->linear_image, - &image->linear_memory, - &size, - &offset, - &row_pitch, - &fd); + &image->linear_base); + if (result != VK_SUCCESS) { chain->base.image_fns->free_wsi_image(device_h, pAllocator, - image->image, image->memory); + &image->base); return result; } } image->pixmap = xcb_generate_id(chain->conn); + struct wsi_image *image_ws = + chain->base.needs_linear_copy ? &image->linear_base : &image->base; cookie = xcb_dri3_pixmap_from_buffer_checked(chain->conn, image->pixmap, chain->window, - size, + image_ws->size, pCreateInfo->imageExtent.width, pCreateInfo->imageExtent.height, - row_pitch, - chain->depth, bpp, fd); + image_ws->row_pitch, + chain->depth, bpp, + image_ws->fd); xcb_discard_reply(chain->conn, cookie.sequence); + image_ws->fd = -1; /* XCB has now taken ownership of the FD */ int fence_fd = xshmfence_alloc_shm(); if (fence_fd < 0) @@ -1041,10 +1030,9 @@ fail_pixmap: if (chain->base.needs_linear_copy) { chain->base.image_fns->free_wsi_image(device_h, pAllocator, - image->linear_image, image->linear_memory); + &image->linear_base); } - chain->base.image_fns->free_wsi_image(device_h, pAllocator, - image->image, image->memory); + chain->base.image_fns->free_wsi_image(device_h, pAllocator, &image->base); return result; } @@ -1065,10 +1053,10 @@ x11_image_finish(struct x11_swapchain *chain, if (chain->base.needs_linear_copy) { chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator, - image->linear_image, image->linear_memory); + &image->linear_base); } chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator, - image->image, image->memory); + &image->base); } static VkResult |