vulkan/wsi: Add a wsi_image structure
authorDaniel Stone <daniels@collabora.com>
Thu, 20 Jul 2017 10:51:48 +0000 (11:51 +0100)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 4 Dec 2017 18:04:19 +0000 (10:04 -0800)
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 <daniels@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Chad Versace <chadversary@chromium.org>
src/amd/vulkan/radv_wsi.c
src/intel/vulkan/anv_wsi.c
src/vulkan/wsi/wsi_common.h
src/vulkan/wsi/wsi_common_wayland.c
src/vulkan/wsi/wsi_common_x11.c

index 98346cae0625377b9ac22499b68969088b9b301b..f5f9a3fbeba51ce46f285eab6522772a7dec3c78 100644 (file)
@@ -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 = {
index 945b01147eaffffe6acfffd7dc31f08b4f292057..d8c4885b5b895fb4ad1c38cf2edf2d8417d63742 100644 (file)
@@ -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 = {
index 7be0182adfa23d814848f9a72d15be33897aa391..565219d4e26c0a67f1f6f49f2775ec4c2d31b883 100644 (file)
 #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 {
index b93c3d7e0d711716efa9a5aaaccd828cc98d794b..c7c7da64979a4ecd6fa23f5d34b3d6102dd5bc4f 100644 (file)
@@ -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);
       }
    }
 
index 22b067bf787b92b87825bbaabf6346d3dfd466fd..22b894edf0061a4efd1e50df6365ff6cc159cd76 100644 (file)
@@ -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