anv: Add aux-map translation for gen12+
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 21 Oct 2019 14:17:44 +0000 (17:17 +0300)
committerJordan Justen <jordan.l.justen@intel.com>
Mon, 28 Oct 2019 07:09:14 +0000 (00:09 -0700)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_private.h

index bd00bc83e134b722f18d886493092b5a203dc2ec..84b9fde075190e3e499c34bb1d7accb59b964c76 100644 (file)
@@ -34,6 +34,8 @@
 #include "vk_util.h"
 #include "util/u_math.h"
 
+#include "common/gen_aux_map.h"
+
 #include "vk_format_info.h"
 
 static isl_surf_usage_flags_t
@@ -778,6 +780,12 @@ anv_DestroyImage(VkDevice _device, VkImage _image,
       return;
 
    for (uint32_t p = 0; p < image->n_planes; ++p) {
+      if (anv_image_plane_uses_aux_map(device, image, p) &&
+          image->planes[p].address.bo) {
+         gen_aux_map_unmap_range(device->aux_map_ctx,
+                                 image->planes[p].aux_map_surface_address,
+                                 image->planes[p].surface.isl.size_B);
+      }
       if (image->planes[p].bo_is_owned) {
          assert(image->planes[p].address.bo != NULL);
          anv_bo_cache_release(device, &device->bo_cache,
@@ -797,6 +805,12 @@ static void anv_image_bind_memory_plane(struct anv_device *device,
    assert(!image->planes[plane].bo_is_owned);
 
    if (!memory) {
+      if (anv_image_plane_uses_aux_map(device, image, plane) &&
+          image->planes[plane].address.bo) {
+         gen_aux_map_unmap_range(device->aux_map_ctx,
+                                 image->planes[plane].aux_map_surface_address,
+                                 image->planes[plane].surface.isl.size_B);
+      }
       image->planes[plane].address = ANV_NULL_ADDRESS;
       return;
    }
@@ -805,6 +819,20 @@ static void anv_image_bind_memory_plane(struct anv_device *device,
       .bo = memory->bo,
       .offset = memory_offset,
    };
+
+   if (anv_image_plane_uses_aux_map(device, image, plane)) {
+      image->planes[plane].aux_map_surface_address =
+         anv_address_physical(
+            anv_address_add(image->planes[plane].address,
+                            image->planes[plane].surface.offset));
+
+      gen_aux_map_add_image(device->aux_map_ctx,
+                            &image->planes[plane].surface.isl,
+                            image->planes[plane].aux_map_surface_address,
+                            anv_address_physical(
+                               anv_address_add(image->planes[plane].address,
+                                               image->planes[plane].aux_surface.offset)));
+   }
 }
 
 /* We are binding AHardwareBuffer. Get a description, resolve the
index 7e83db043464a79595418378cae4e898d82b6a1c..ef246e4612ef52271d37f0016b180689df0ff856 100644 (file)
@@ -3202,6 +3202,13 @@ struct anv_image {
        */
       struct anv_address address;
 
+      /**
+       * Address of the main surface used to fill the aux map table. This is
+       * used at destruction of the image since the Vulkan spec does not
+       * guarantee that the address.bo field we still be valid at destruction.
+       */
+      uint64_t aux_map_surface_address;
+
       /**
        * When destroying the image, also free the bo.
        * */
@@ -3324,6 +3331,15 @@ anv_can_sample_with_hiz(const struct gen_device_info * const devinfo,
    return image->samples == 1;
 }
 
+static inline bool
+anv_image_plane_uses_aux_map(const struct anv_device *device,
+                             const struct anv_image *image,
+                             uint32_t plane)
+{
+   return device->info.has_aux_map &&
+      isl_aux_usage_has_ccs(image->planes[plane].aux_usage);
+}
+
 void
 anv_cmd_buffer_mark_image_written(struct anv_cmd_buffer *cmd_buffer,
                                   const struct anv_image *image,