[Mesa-dev] [PATCH 07/14] anv/image: Refactor how tiling is chosen (v2)

Chad Versace chad at kiwitree.net
Thu Sep 28 00:11:53 UTC 2017


The code that restricts the VkImage's tiling flags, extract it into
a new function named choose_isl_tiling_flags().  This reduces the diff
in upcoming patches for VK_ANDROID_native_buffer.

v2:
  - Rebase onto 'needs_shadow' changes on master.
  - Assert that choose_isl_tiling_flags() chooses at least one tiling.
---
 src/intel/vulkan/anv_image.c | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 6f6bd59e89d..795badd27fd 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -107,6 +107,28 @@ get_surface(struct anv_image *image, VkImageAspectFlags aspect)
    }
 }
 
+static VkResult
+choose_isl_tiling_flags(const struct anv_image_create_info *anv_info,
+                        bool needs_shadow,
+                        isl_tiling_flags_t *restrict flags)
+{
+   *flags = ISL_TILING_ANY_MASK;
+
+   if (anv_info->isl_tiling_flags)
+      *flags &= anv_info->isl_tiling_flags;
+
+   if (needs_shadow)
+      *flags &= ISL_TILING_LINEAR_BIT;
+
+   if (anv_info->vk_info->tiling == VK_IMAGE_TILING_LINEAR)
+      *flags = ISL_TILING_LINEAR_BIT;
+
+   /* Only invalid Vulkan usage can filter out all tiling formats. */
+   assert(*flags != 0);
+
+   return VK_SUCCESS;
+}
+
 static void
 add_surface(struct anv_image *image, struct anv_surface *surf)
 {
@@ -239,6 +261,7 @@ make_surface(const struct anv_device *dev,
              VkImageAspectFlags aspect)
 {
    const VkImageCreateInfo *base_info = anv_info->vk_info;
+   VkResult result;
    bool ok UNUSED;
 
    static const enum isl_surf_dim vk_to_isl_surf_dim[] = {
@@ -247,18 +270,6 @@ make_surface(const struct anv_device *dev,
       [VK_IMAGE_TYPE_3D] = ISL_SURF_DIM_3D,
    };
 
-   /* Translate the Vulkan tiling to an equivalent ISL tiling, then filter the
-    * result with an optionally provided ISL tiling argument.
-    */
-   isl_tiling_flags_t tiling_flags =
-      (base_info->tiling == VK_IMAGE_TILING_LINEAR) ?
-      ISL_TILING_LINEAR_BIT : ISL_TILING_ANY_MASK;
-
-   if (anv_info->isl_tiling_flags)
-      tiling_flags &= anv_info->isl_tiling_flags;
-
-   assert(tiling_flags);
-
    struct anv_surface *anv_surf = get_surface(image, aspect);
 
    image->extent = anv_sanitize_image_extent(base_info->imageType,
@@ -279,10 +290,14 @@ make_surface(const struct anv_device *dev,
        (base_info->flags & VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR) &&
        base_info->tiling == VK_IMAGE_TILING_OPTIMAL) {
       assert(isl_format_is_compressed(format));
-      tiling_flags = ISL_TILING_LINEAR_BIT;
       needs_shadow = true;
    }
 
+   isl_tiling_flags_t tiling_flags;
+   result = choose_isl_tiling_flags(anv_info, needs_shadow, &tiling_flags);
+   if (result != VK_SUCCESS)
+      return result;
+
    ok = isl_surf_init(&dev->isl_dev, &anv_surf->isl,
       .dim = vk_to_isl_surf_dim[base_info->imageType],
       .format = format,
-- 
2.13.5



More information about the mesa-dev mailing list