venus: get rid of #ifdef's in vn_CreateImage
authorChia-I Wu <olvaffe@gmail.com>
Wed, 12 May 2021 20:50:56 +0000 (13:50 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 12 May 2021 22:37:05 +0000 (22:37 +0000)
No real change after compiler optimizations.

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

src/virtio/vulkan/vn_android.h
src/virtio/vulkan/vn_image.c
src/virtio/vulkan/vn_wsi.h

index 0d53656..64a7d73 100644 (file)
@@ -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 */
index 23172ce..1c4b830 100644 (file)
@@ -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);
 
index bea0260..f63e2d4 100644 (file)
@@ -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 */