Mesa (main): venus: get rid of #ifdef's in vn_CreateImage

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed May 12 22:46:26 UTC 2021


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

Author: Chia-I Wu <olvaffe at gmail.com>
Date:   Wed May 12 13:50:56 2021 -0700

venus: get rid of #ifdef's in vn_CreateImage

No real change after compiler optimizations.

Signed-off-by: Chia-I Wu <olvaffe at gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei at chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10779>

---

 src/virtio/vulkan/vn_android.h | 45 +++++++++++++++++++++++++++++++-----------
 src/virtio/vulkan/vn_image.c   | 22 +++++++--------------
 src/virtio/vulkan/vn_wsi.h     | 24 +++++++++++++++++++++-
 3 files changed, 64 insertions(+), 27 deletions(-)

diff --git a/src/virtio/vulkan/vn_android.h b/src/virtio/vulkan/vn_android.h
index 0d53656214c..64a7d7333eb 100644
--- a/src/virtio/vulkan/vn_android.h
+++ b/src/virtio/vulkan/vn_android.h
@@ -19,9 +19,6 @@
 /* venus implements VK_ANDROID_native_buffer up to spec version 7 */
 #define VN_ANDROID_NATIVE_BUFFER_SPEC_VERSION 7
 
-struct vn_device;
-struct vn_image;
-
 struct vn_android_wsi {
    /* command pools, one per queue family */
    VkCommandPool *cmd_pools;
@@ -31,14 +28,8 @@ struct vn_android_wsi {
    uint32_t *queue_family_indices;
 };
 
-VkResult
-vn_image_from_anb(struct vn_device *dev,
-                  const VkImageCreateInfo *image_info,
-                  const VkNativeBufferANDROID *anb_info,
-                  const VkAllocationCallbacks *alloc,
-                  struct vn_image **out_img);
-
 #ifdef ANDROID
+
 VkResult
 vn_android_wsi_init(struct vn_device *dev,
                     const VkAllocationCallbacks *alloc);
@@ -46,7 +37,22 @@ vn_android_wsi_init(struct vn_device *dev,
 void
 vn_android_wsi_fini(struct vn_device *dev,
                     const VkAllocationCallbacks *alloc);
+
+static inline const VkNativeBufferANDROID *
+vn_android_find_native_buffer(const VkImageCreateInfo *create_info)
+{
+   return vk_find_struct_const(create_info->pNext, NATIVE_BUFFER_ANDROID);
+}
+
+VkResult
+vn_image_from_anb(struct vn_device *dev,
+                  const VkImageCreateInfo *image_info,
+                  const VkNativeBufferANDROID *anb_info,
+                  const VkAllocationCallbacks *alloc,
+                  struct vn_image **out_img);
+
 #else
+
 static inline VkResult
 vn_android_wsi_init(UNUSED struct vn_device *dev,
                     UNUSED const VkAllocationCallbacks *alloc)
@@ -60,6 +66,23 @@ vn_android_wsi_fini(UNUSED struct vn_device *dev,
 {
    return;
 }
-#endif
+
+static inline const VkNativeBufferANDROID *
+vn_android_find_native_buffer(const VkImageCreateInfo *create_info)
+{
+   return NULL;
+}
+
+static inline VkResult
+vn_image_from_anb(struct vn_device *dev,
+                  const VkImageCreateInfo *image_info,
+                  const VkNativeBufferANDROID *anb_info,
+                  const VkAllocationCallbacks *alloc,
+                  struct vn_image **out_img)
+{
+   return VK_ERROR_OUT_OF_HOST_MEMORY;
+}
+
+#endif /* ANDROID */
 
 #endif /* VN_ANDROID_H */
diff --git a/src/virtio/vulkan/vn_image.c b/src/virtio/vulkan/vn_image.c
index 23172ce71f6..1c4b830bd0f 100644
--- a/src/virtio/vulkan/vn_image.c
+++ b/src/virtio/vulkan/vn_image.c
@@ -290,28 +290,20 @@ vn_CreateImage(VkDevice device,
    struct vn_image *img;
    VkResult result;
 
-#ifdef VN_USE_WSI_PLATFORM
    const struct wsi_image_create_info *wsi_info =
-      vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA);
+      vn_wsi_find_wsi_image_create_info(pCreateInfo);
+   const VkNativeBufferANDROID *anb_info =
+      vn_android_find_native_buffer(pCreateInfo);
+
    if (wsi_info) {
       assert(wsi_info->scanout);
       result = vn_wsi_create_scanout_image(dev, pCreateInfo, alloc, &img);
-      goto out;
-   }
-#endif
-
-#ifdef ANDROID
-   const VkNativeBufferANDROID *anb_info =
-      vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID);
-   if (anb_info) {
+   } else if (anb_info) {
       result = vn_image_from_anb(dev, pCreateInfo, anb_info, alloc, &img);
-      goto out;
+   } else {
+      result = vn_image_create(dev, pCreateInfo, alloc, &img);
    }
-#endif
-
-   result = vn_image_create(dev, pCreateInfo, alloc, &img);
 
-out:
    if (result != VK_SUCCESS)
       return vn_error(dev->instance, result);
 
diff --git a/src/virtio/vulkan/vn_wsi.h b/src/virtio/vulkan/vn_wsi.h
index bea026049f1..f63e2d4e2ab 100644
--- a/src/virtio/vulkan/vn_wsi.h
+++ b/src/virtio/vulkan/vn_wsi.h
@@ -23,6 +23,13 @@ vn_wsi_init(struct vn_physical_device *physical_dev);
 void
 vn_wsi_fini(struct vn_physical_device *physical_dev);
 
+static inline const struct wsi_image_create_info *
+vn_wsi_find_wsi_image_create_info(const VkImageCreateInfo *create_info)
+{
+   return vk_find_struct_const(create_info->pNext,
+                               WSI_IMAGE_CREATE_INFO_MESA);
+}
+
 VkResult
 vn_wsi_create_scanout_image(struct vn_device *dev,
                             const VkImageCreateInfo *create_info,
@@ -42,6 +49,21 @@ vn_wsi_fini(UNUSED struct vn_physical_device *physical_dev)
 {
 }
 
-#endif
+static inline const struct wsi_image_create_info *
+vn_wsi_find_wsi_image_create_info(const VkImageCreateInfo *create_info)
+{
+   return NULL;
+}
+
+static inline VkResult
+vn_wsi_create_scanout_image(struct vn_device *dev,
+                            const VkImageCreateInfo *create_info,
+                            const VkAllocationCallbacks *alloc,
+                            struct vn_image **out_img)
+{
+   return VK_ERROR_OUT_OF_HOST_MEMORY;
+}
+
+#endif /* VN_USE_WSI_PLATFORM */
 
 #endif /* VN_WSI_H */



More information about the mesa-commit mailing list