[Mesa-dev] [PATCH 07/13] anv/image: use stored format to figure out plane from aspect

Lionel Landwerlin lionel.g.landwerlin at intel.com
Mon Nov 5 15:36:01 UTC 2018


Now that we have aspects stored into anv_format_plane we can just go
through the list of planes of a given format and figure which one
matches the aspect we're interested in.

This will come handy as when we introduce 2 different view of the same
buffer for YCbCr formats.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 src/intel/vulkan/anv_blorp.c       |  9 +++--
 src/intel/vulkan/anv_device.c      |  4 +--
 src/intel/vulkan/anv_dump.c        |  2 +-
 src/intel/vulkan/anv_formats.c     | 18 +++++++++-
 src/intel/vulkan/anv_image.c       | 18 +++++-----
 src/intel/vulkan/anv_private.h     | 53 +++++++++++-------------------
 src/intel/vulkan/genX_cmd_buffer.c | 10 +++---
 7 files changed, 58 insertions(+), 56 deletions(-)

diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index 478b8e7a3db..29bddc46bda 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -197,7 +197,7 @@ get_blorp_surf_for_anv_image(const struct anv_device *device,
                              enum isl_aux_usage aux_usage,
                              struct blorp_surf *blorp_surf)
 {
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
 
    if (layout != ANV_IMAGE_LAYOUT_EXPLICIT_AUX)
       aux_usage = anv_layout_to_aux_usage(&device->info, image, aspect, layout);
@@ -1296,7 +1296,7 @@ static enum isl_aux_usage
 fast_clear_aux_usage(const struct anv_image *image,
                      VkImageAspectFlagBits aspect)
 {
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
    if (image->planes[plane].aux_usage == ISL_AUX_USAGE_NONE)
       return ISL_AUX_USAGE_CCS_D;
    else
@@ -1554,8 +1554,7 @@ anv_image_hiz_op(struct anv_cmd_buffer *cmd_buffer,
 {
    assert(aspect == VK_IMAGE_ASPECT_DEPTH_BIT);
    assert(base_layer + layer_count <= anv_image_aux_layers(image, aspect, level));
-   assert(anv_image_aspect_to_plane(image->aspects,
-                                    VK_IMAGE_ASPECT_DEPTH_BIT) == 0);
+   assert(anv_format_aspect_to_plane(image->format, VK_IMAGE_ASPECT_DEPTH_BIT) == 0);
 
    struct blorp_batch batch;
    blorp_batch_init(&cmd_buffer->device->blorp, &batch, cmd_buffer, 0);
@@ -1749,7 +1748,7 @@ anv_image_ccs_op(struct anv_cmd_buffer *cmd_buffer,
    assert(base_layer + layer_count <=
           anv_image_aux_layers(image, aspect, level));
 
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
    uint32_t width_div = image->format->planes[plane].denominator_scales[0];
    uint32_t height_div = image->format->planes[plane].denominator_scales[1];
    uint32_t level_width = anv_minify(image->extent.width, level) / width_div;
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index ee35e013329..8fcb44370dd 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -2682,8 +2682,8 @@ void anv_GetImageMemoryRequirements2(
          struct anv_physical_device *pdevice = &device->instance->physicalDevice;
          const VkImagePlaneMemoryRequirementsInfoKHR *plane_reqs =
             (const VkImagePlaneMemoryRequirementsInfoKHR *) ext;
-         uint32_t plane = anv_image_aspect_to_plane(image->aspects,
-                                                    plane_reqs->planeAspect);
+         uint32_t plane = anv_format_aspect_to_plane(image->format,
+                                                     plane_reqs->planeAspect);
 
          assert(image->planes[plane].offset == 0);
 
diff --git a/src/intel/vulkan/anv_dump.c b/src/intel/vulkan/anv_dump.c
index 160c18c4f17..8d91111dd87 100644
--- a/src/intel/vulkan/anv_dump.c
+++ b/src/intel/vulkan/anv_dump.c
@@ -439,7 +439,7 @@ anv_dump_add_framebuffer(struct anv_cmd_buffer *cmd_buffer,
          char *filename = ralloc_asprintf(dump_ctx, "framebuffer%04d-%d%s.ppm",
                                           dump_idx, i, suffix);
 
-         unsigned plane = anv_image_aspect_to_plane(iview->image->aspects, aspect);
+         unsigned plane = anv_format_aspect_to_plane(iview->image->format, aspect);
          dump_add_image(cmd_buffer, (struct anv_image *)iview->image, aspect,
                         iview->planes[plane].isl.base_level,
                         iview->planes[plane].isl.base_array_layer,
diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c
index d3a7c2be85c..90b34093820 100644
--- a/src/intel/vulkan/anv_formats.c
+++ b/src/intel/vulkan/anv_formats.c
@@ -445,7 +445,7 @@ anv_get_format_plane(const struct gen_device_info *devinfo, VkFormat vk_format,
    if (format == NULL)
       return unsupported;
 
-   uint32_t plane = anv_image_aspect_to_plane(vk_format_aspects(vk_format), aspect);
+   uint32_t plane = anv_format_aspect_to_plane(format, aspect);
    struct anv_format_plane plane_format = format->planes[plane];
    if (plane_format.isl_format == ISL_FORMAT_UNSUPPORTED)
       return unsupported;
@@ -490,6 +490,22 @@ anv_get_format_plane(const struct gen_device_info *devinfo, VkFormat vk_format,
    return plane_format;
 }
 
+uint32_t
+anv_format_aspect_to_plane(const struct anv_format *format, VkImageAspectFlags _aspect)
+{
+   VkImageAspectFlags aspects = 0;
+   for (uint32_t p = 0; p < format->n_planes; p++)
+      aspects |= format->planes[p].aspect;
+
+   VkImageAspectFlags aspect = anv_expand_aspects(aspects, _aspect);
+   for (uint32_t p = 0; p < format->n_planes; p++) {
+      if (format->planes[p].aspect & aspect)
+         return p;
+   }
+
+   unreachable("invalid format/aspect");
+}
+
 // Format capabilities
 
 static VkFormatFeatureFlags
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 4fa44aa8704..b2ca1fdacbd 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -128,7 +128,7 @@ choose_isl_tiling_flags(const struct anv_image_create_info *anv_info,
 static struct anv_surface *
 get_surface(struct anv_image *image, VkImageAspectFlagBits aspect)
 {
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
    return &image->planes[plane].surface;
 }
 
@@ -315,7 +315,7 @@ make_surface(const struct anv_device *dev,
    image->extent = anv_sanitize_image_extent(vk_info->imageType,
                                              vk_info->extent);
 
-   const unsigned plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   const unsigned plane = anv_format_aspect_to_plane(image->format, aspect);
    const  struct anv_format_plane plane_format =
       anv_get_format_plane(&dev->info, image->vk_format, aspect, image->tiling);
    struct anv_surface *anv_surf = &image->planes[plane].surface;
@@ -700,7 +700,7 @@ VkResult anv_BindImageMemory(
    uint32_t aspect_bit;
    anv_foreach_image_aspect_bit(aspect_bit, image, image->aspects) {
       uint32_t plane =
-         anv_image_aspect_to_plane(image->aspects, 1UL << aspect_bit);
+         anv_format_aspect_to_plane(image->format, 1UL << aspect_bit);
       anv_image_bind_memory_plane(device, image, plane, mem, memoryOffset);
    }
 
@@ -738,7 +738,7 @@ VkResult anv_BindImageMemory2(
       uint32_t aspect_bit;
       anv_foreach_image_aspect_bit(aspect_bit, image, aspects) {
          uint32_t plane =
-            anv_image_aspect_to_plane(image->aspects, 1UL << aspect_bit);
+            anv_format_aspect_to_plane(image->format, 1UL << aspect_bit);
          anv_image_bind_memory_plane(device, image, plane,
                                      mem, bind_info->memoryOffset);
       }
@@ -819,7 +819,7 @@ anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
 
    /* Determine the optimal buffer. */
 
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
 
    /* If there is no auxiliary surface allocated, we must use the one and only
     * main buffer.
@@ -948,7 +948,7 @@ anv_layout_to_fast_clear_type(const struct gen_device_info * const devinfo,
    /* The aspect must be exactly one of the image aspects. */
    assert(util_bitcount(aspect) == 1 && (aspect & image->aspects));
 
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
 
    /* If there is no auxiliary surface allocated, there are no fast-clears */
    if (image->planes[plane].aux_surface.isl.size_B == 0)
@@ -1048,7 +1048,7 @@ anv_image_fill_surface_state(struct anv_device *device,
                              struct anv_surface_state *state_inout,
                              struct brw_image_param *image_param_out)
 {
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
 
    const struct anv_surface *surface = &image->planes[plane].surface,
       *aux_surface = &image->planes[plane].aux_surface;
@@ -1345,7 +1345,7 @@ anv_CreateImageView(VkDevice _device,
    uint32_t iaspect_bit, vplane = 0;
    anv_foreach_image_aspect_bit(iaspect_bit, image, expanded_aspects) {
       uint32_t iplane =
-         anv_image_aspect_to_plane(image->aspects, 1UL << iaspect_bit);
+         anv_format_aspect_to_plane(image->format, 1UL << iaspect_bit);
       VkImageAspectFlags vplane_aspect =
          anv_plane_to_aspect(iview->aspect_mask, vplane);
       struct anv_format_plane format =
@@ -1632,6 +1632,6 @@ anv_image_get_surface_for_aspect_mask(const struct anv_image *image,
        return NULL;
    }
 
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, sanitized_mask);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, sanitized_mask);
    return &image->planes[plane].surface;
 }
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 8f8cbb4415e..621f65ff33f 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -2561,28 +2561,8 @@ struct anv_format {
    bool can_ycbcr;
 };
 
-static inline uint32_t
-anv_image_aspect_to_plane(VkImageAspectFlags image_aspects,
-                          VkImageAspectFlags aspect_mask)
-{
-   switch (aspect_mask) {
-   case VK_IMAGE_ASPECT_COLOR_BIT:
-   case VK_IMAGE_ASPECT_DEPTH_BIT:
-   case VK_IMAGE_ASPECT_PLANE_0_BIT:
-      return 0;
-   case VK_IMAGE_ASPECT_STENCIL_BIT:
-      if ((image_aspects & VK_IMAGE_ASPECT_DEPTH_BIT) == 0)
-         return 0;
-      /* Fall-through */
-   case VK_IMAGE_ASPECT_PLANE_1_BIT:
-      return 1;
-   case VK_IMAGE_ASPECT_PLANE_2_BIT:
-      return 2;
-   default:
-      /* Purposefully assert with depth/stencil aspects. */
-      unreachable("invalid image aspect");
-   }
-}
+uint32_t
+anv_format_aspect_to_plane(const struct anv_format *format, VkImageAspectFlags aspect);
 
 static inline VkImageAspectFlags
 anv_plane_to_aspect(VkImageAspectFlags image_aspects,
@@ -2699,7 +2679,7 @@ struct anv_image {
     * Image subsurfaces
     *
     * For each foo, anv_image::planes[x].surface is valid if and only if
-    * anv_image::aspects has a x aspect. Refer to anv_image_aspect_to_plane()
+    * anv_image::aspects has a x aspect. Refer to anv_format_aspect_to_plane()
     * to figure the number associated with a given aspect.
     *
     * The hardware requires that the depth buffer and stencil buffer be
@@ -2794,7 +2774,7 @@ static inline uint8_t
 anv_image_aux_levels(const struct anv_image * const image,
                      VkImageAspectFlagBits aspect)
 {
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
    return image->planes[plane].aux_surface.isl.size_B > 0 ?
           image->planes[plane].aux_surface.isl.levels : 0;
 }
@@ -2816,7 +2796,7 @@ anv_image_aux_layers(const struct anv_image * const image,
        */
       return 0;
    } else {
-      uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+      uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
       return MAX2(image->planes[plane].aux_surface.isl.logical_level0_px.array_len,
                   image->planes[plane].aux_surface.isl.logical_level0_px.depth >> miplevel);
    }
@@ -2829,7 +2809,7 @@ anv_image_get_clear_color_addr(const struct anv_device *device,
 {
    assert(image->aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV);
 
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
    return anv_address_add(image->planes[plane].address,
                           image->planes[plane].fast_clear_state_offset);
 }
@@ -2856,7 +2836,7 @@ anv_image_get_compression_state_addr(const struct anv_device *device,
 {
    assert(level < anv_image_aux_levels(image, aspect));
    assert(array_layer < anv_image_aux_layers(image, aspect, level));
-   UNUSED uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   UNUSED uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
    assert(image->planes[plane].aux_usage == ISL_AUX_USAGE_CCS_E);
 
    struct anv_address addr =
@@ -2976,17 +2956,24 @@ anv_get_levelCount(const struct anv_image *image,
 }
 
 static inline VkImageAspectFlags
-anv_image_expand_aspects(const struct anv_image *image,
-                         VkImageAspectFlags aspects)
+anv_expand_aspects(VkImageAspectFlags image_aspects,
+                   VkImageAspectFlags selected_aspects)
 {
    /* If the underlying image has color plane aspects and
     * VK_IMAGE_ASPECT_COLOR_BIT has been requested, then return the aspects of
     * the underlying image. */
-   if ((image->aspects & VK_IMAGE_ASPECT_PLANES_BITS_ANV) != 0 &&
-       aspects == VK_IMAGE_ASPECT_COLOR_BIT)
-      return image->aspects;
+   if ((image_aspects & VK_IMAGE_ASPECT_PLANES_BITS_ANV) != 0 &&
+       selected_aspects == VK_IMAGE_ASPECT_COLOR_BIT)
+      return image_aspects;
+
+   return selected_aspects;
+}
 
-   return aspects;
+static inline VkImageAspectFlags
+anv_image_expand_aspects(const struct anv_image *image,
+                         VkImageAspectFlags aspects)
+{
+   return anv_expand_aspects(image->aspects, aspects);
 }
 
 static inline bool
diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index ed88157170d..0446d704e6d 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -490,7 +490,7 @@ set_image_compressed_bit(struct anv_cmd_buffer *cmd_buffer,
                          uint32_t base_layer, uint32_t layer_count,
                          bool compressed)
 {
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
 
    /* We only have compression tracking for CCS_E */
    if (image->planes[plane].aux_usage != ISL_AUX_USAGE_CCS_E)
@@ -742,7 +742,7 @@ anv_cmd_predicated_ccs_resolve(struct anv_cmd_buffer *cmd_buffer,
                                enum isl_aux_op resolve_op,
                                enum anv_fast_clear_type fast_clear_supported)
 {
-   const uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   const uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
 
 #if GEN_GEN >= 9
    anv_cmd_compute_resolve_predicate(cmd_buffer, image,
@@ -958,7 +958,7 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer,
    if (initial_layout == final_layout)
       return;
 
-   uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
+   uint32_t plane = anv_format_aspect_to_plane(image->format, aspect);
 
    if (image->planes[plane].shadow_surface.isl.size_B > 0 &&
        final_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
@@ -3447,7 +3447,7 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
 
    if (image && (image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT)) {
       uint32_t depth_plane =
-         anv_image_aspect_to_plane(image->aspects, VK_IMAGE_ASPECT_DEPTH_BIT);
+         anv_format_aspect_to_plane(image->format, VK_IMAGE_ASPECT_DEPTH_BIT);
       const struct anv_surface *surface = &image->planes[depth_plane].surface;
 
       info.depth_surf = &surface->isl;
@@ -3480,7 +3480,7 @@ cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer)
 
    if (image && (image->aspects & VK_IMAGE_ASPECT_STENCIL_BIT)) {
       uint32_t stencil_plane =
-         anv_image_aspect_to_plane(image->aspects, VK_IMAGE_ASPECT_STENCIL_BIT);
+         anv_format_aspect_to_plane(image->format, VK_IMAGE_ASPECT_STENCIL_BIT);
       const struct anv_surface *surface = &image->planes[stencil_plane].surface;
 
       info.stencil_surf = &surface->isl;
-- 
2.19.1



More information about the mesa-dev mailing list