Mesa (main): vulkan/wsi: Add a helper for the configure/create/bind pattern

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 31 20:20:13 UTC 2022


Module: Mesa
Branch: main
Commit: 830d9967db0ca390c898108a4b62f4dcd454daa7
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=830d9967db0ca390c898108a4b62f4dcd454daa7

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Thu Jul 22 22:31:57 2021 -0500

vulkan/wsi: Add a helper for the configure/create/bind pattern

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Acked-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12031>

---

 src/vulkan/wsi/wsi_common.c         | 33 +++++++++++++++++++++++++++++++++
 src/vulkan/wsi/wsi_common_drm.c     | 30 +++++++-----------------------
 src/vulkan/wsi/wsi_common_private.h |  9 +++++++++
 3 files changed, 49 insertions(+), 23 deletions(-)

diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c
index d549dad8687..30f781d7599 100644
--- a/src/vulkan/wsi/wsi_common.c
+++ b/src/vulkan/wsi/wsi_common.c
@@ -456,6 +456,39 @@ wsi_destroy_image_info(const struct wsi_swapchain *chain,
    vk_free(&chain->alloc, info->modifier_props);
 }
 
+VkResult
+wsi_create_image(const struct wsi_swapchain *chain,
+                 const struct wsi_image_info *info,
+                 struct wsi_image *image)
+{
+   const struct wsi_device *wsi = chain->wsi;
+   VkResult result;
+
+   memset(image, 0, sizeof(*image));
+   for (int i = 0; i < ARRAY_SIZE(image->fds); i++)
+      image->fds[i] = -1;
+
+   result = wsi->CreateImage(chain->device, &info->create,
+                             &chain->alloc, &image->image);
+   if (result != VK_SUCCESS)
+      goto fail;
+
+   result = info->create_mem(chain, info, image);
+   if (result != VK_SUCCESS)
+      goto fail;
+
+   result = wsi->BindImageMemory(chain->device, image->image,
+                                 image->memory, 0);
+   if (result != VK_SUCCESS)
+      goto fail;
+
+   return VK_SUCCESS;
+
+fail:
+   wsi_destroy_image(chain, image);
+   return result;
+}
+
 void
 wsi_destroy_image(const struct wsi_swapchain *chain,
                   struct wsi_image *image)
diff --git a/src/vulkan/wsi/wsi_common_drm.c b/src/vulkan/wsi/wsi_common_drm.c
index 3a212e1cb35..50a6a6c3e7c 100644
--- a/src/vulkan/wsi/wsi_common_drm.c
+++ b/src/vulkan/wsi/wsi_common_drm.c
@@ -136,6 +136,11 @@ get_modifier_props(const struct wsi_image_info *info, uint64_t modifier)
    return NULL;
 }
 
+static VkResult
+wsi_create_native_image_mem(const struct wsi_swapchain *chain,
+                            const struct wsi_image_info *info,
+                            struct wsi_image *image);
+
 VkResult
 wsi_configure_native_image(const struct wsi_swapchain *chain,
                            const VkSwapchainCreateInfoKHR *pCreateInfo,
@@ -270,6 +275,7 @@ wsi_configure_native_image(const struct wsi_swapchain *chain,
    }
 
    info->alloc_shm = alloc_shm;
+   info->create_mem = wsi_create_native_image_mem;
 
    return VK_SUCCESS;
 
@@ -422,13 +428,8 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
                         uint8_t *(alloc_shm)(struct wsi_image *image, unsigned size),
                         struct wsi_image *image)
 {
-   const struct wsi_device *wsi = chain->wsi;
    VkResult result;
 
-   memset(image, 0, sizeof(*image));
-   for (int i = 0; i < ARRAY_SIZE(image->fds); i++)
-      image->fds[i] = -1;
-
    struct wsi_image_info info;
    result = wsi_configure_native_image(chain, pCreateInfo,
                                        num_modifier_lists,
@@ -437,27 +438,10 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
    if (result != VK_SUCCESS)
       return result;
 
-   result = wsi->CreateImage(chain->device, &info.create,
-                             &chain->alloc, &image->image);
-   if (result != VK_SUCCESS)
-      goto fail;
-
-   result = wsi_create_native_image_mem(chain, &info, image);
-   if (result != VK_SUCCESS)
-      goto fail;
-
-   result = wsi->BindImageMemory(chain->device, image->image,
-                                 image->memory, 0);
-   if (result != VK_SUCCESS)
-      goto fail;
+   result = wsi_create_image(chain, &info, image);
 
    wsi_destroy_image_info(chain, &info);
 
-   return VK_SUCCESS;
-
-fail:
-   wsi_destroy_image_info(chain, &info);
-   wsi_destroy_image(chain, image);
    return result;
 }
 
diff --git a/src/vulkan/wsi/wsi_common_private.h b/src/vulkan/wsi/wsi_common_private.h
index 0e8c1511153..10008c53867 100644
--- a/src/vulkan/wsi/wsi_common_private.h
+++ b/src/vulkan/wsi/wsi_common_private.h
@@ -27,6 +27,7 @@
 #include "vulkan/runtime/vk_object.h"
 
 struct wsi_image;
+struct wsi_swapchain;
 
 struct wsi_image_info {
    VkImageCreateInfo create;
@@ -42,6 +43,10 @@ struct wsi_image_info {
    struct VkDrmFormatModifierPropertiesEXT *modifier_props;
 
    uint8_t *(*alloc_shm)(struct wsi_image *image, unsigned size);
+
+   VkResult (*create_mem)(const struct wsi_swapchain *chain,
+                          const struct wsi_image_info *info,
+                          struct wsi_image *image);
 };
 
 struct wsi_image {
@@ -147,6 +152,10 @@ wsi_configure_image(const struct wsi_swapchain *chain,
 void
 wsi_destroy_image_info(const struct wsi_swapchain *chain,
                        struct wsi_image_info *info);
+VkResult
+wsi_create_image(const struct wsi_swapchain *chain,
+                 const struct wsi_image_info *info,
+                 struct wsi_image *image);
 void
 wsi_destroy_image(const struct wsi_swapchain *chain,
                   struct wsi_image *image);



More information about the mesa-commit mailing list