anv: Enable implicit CCS for external images
authorRenato Pereyra <renatopereyra@google.com>
Thu, 6 Jan 2022 02:27:23 +0000 (18:27 -0800)
committerRenato Pereyra <renatopereyra@google.com>
Thu, 20 Jan 2022 19:37:15 +0000 (11:37 -0800)
AUX and clear state is stored in the VkDevice private binding

Signed-off-by: Renato Pereyra <renatopereyra@google.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14416>

src/intel/vulkan/anv_allocator.c
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_image.c
src/intel/vulkan/genX_cmd_buffer.c

index f4e0328..db78b27 100644 (file)
@@ -1825,9 +1825,8 @@ anv_device_import_bo_from_host_ptr(struct anv_device *device,
                            ANV_BO_ALLOC_SNOOPED |
                            ANV_BO_ALLOC_FIXED_ADDRESS)));
 
-   /* We can't do implicit CCS with an aux table on shared memory */
-   if (!device->physical->has_implicit_ccs || device->info.has_aux_map)
-       assert(!(alloc_flags & ANV_BO_ALLOC_IMPLICIT_CCS));
+   assert(!(alloc_flags & ANV_BO_ALLOC_IMPLICIT_CCS) ||
+          (device->physical->has_implicit_ccs && device->info.has_aux_map));
 
    struct anv_bo_cache *cache = &device->bo_cache;
    const uint32_t bo_flags =
@@ -1916,9 +1915,8 @@ anv_device_import_bo(struct anv_device *device,
                            ANV_BO_ALLOC_SNOOPED |
                            ANV_BO_ALLOC_FIXED_ADDRESS)));
 
-   /* We can't do implicit CCS with an aux table on shared memory */
-   if (!device->physical->has_implicit_ccs || device->info.has_aux_map)
-       assert(!(alloc_flags & ANV_BO_ALLOC_IMPLICIT_CCS));
+   assert(!(alloc_flags & ANV_BO_ALLOC_IMPLICIT_CCS) ||
+          (device->physical->has_implicit_ccs && device->info.has_aux_map));
 
    struct anv_bo_cache *cache = &device->bo_cache;
    const uint32_t bo_flags =
index d696148..8feae31 100644 (file)
@@ -3654,13 +3654,6 @@ VkResult anv_AllocateMemory(
        (host_ptr_info && host_ptr_info->handleType)) {
       /* Anything imported or exported is EXTERNAL */
       alloc_flags |= ANV_BO_ALLOC_EXTERNAL;
-
-      /* We can't have implicit CCS on external memory with an AUX-table.
-       * Doing so would require us to sync the aux tables across processes
-       * which is impractical.
-       */
-      if (device->info.has_aux_map)
-         alloc_flags &= ~ANV_BO_ALLOC_IMPLICIT_CCS;
    }
 
    /* Check if we need to support Android HW buffer export. If so,
index a50bb4c..9a24e65 100644 (file)
@@ -536,8 +536,14 @@ add_aux_state_tracking_buffer(struct anv_device *device,
    enum anv_image_memory_binding binding =
       ANV_IMAGE_MEMORY_BINDING_PLANE_0 + plane;
 
-   if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID)
+   /* Ensure that AUX state is stored outside the buffer memory for any images
+    * externally sharable. This prevents corruptions arising due to disjoint
+    * processes working with the same image.
+    */
+   if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID ||
+       image->vk.external_handle_types != 0) {
        binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE;
+   }
 
    /* We believe that 256B alignment may be sufficient, but we choose 4K due to
     * lack of testing.  And MI_LOAD/STORE operations require dword-alignment.
@@ -944,9 +950,15 @@ check_memory_bindings(const struct anv_device *device,
       if (anv_surface_is_valid(&plane->aux_surface)) {
          enum anv_image_memory_binding binding = primary_binding;
 
-         if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID &&
-             !isl_drm_modifier_has_aux(image->vk.drm_format_mod))
+         /* Ensure that AUX state is stored outside the buffer memory for any
+          * images externally sharable. This prevents corruptions arising due
+          * to disjoint processes working with the same image.
+          */
+         if ((image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID &&
+              !isl_drm_modifier_has_aux(image->vk.drm_format_mod)) ||
+             (image->vk.external_handle_types != 0)) {
             binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE;
+         }
 
          /* Display hardware requires that the aux surface start at
           * a higher address than the primary surface. The 3D hardware
@@ -962,8 +974,14 @@ check_memory_bindings(const struct anv_device *device,
       if (plane->fast_clear_memory_range.size > 0) {
          enum anv_image_memory_binding binding = primary_binding;
 
-         if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID)
+         /* Ensure that clear state is stored outside the buffer memory for any
+          * images externally sharable. This prevents corruptions arising due
+          * to disjoint processes working with the same image.
+          */
+         if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID ||
+             image->vk.external_handle_types != 0) {
             binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE;
+         }
 
          /* We believe that 256B alignment may be sufficient, but we choose 4K
           * due to lack of testing.  And MI_LOAD/STORE operations require
index fda86b3..73692c1 100644 (file)
@@ -1214,16 +1214,18 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer,
     * image has a DRM format modifier because we store image data in
     * a driver-private bo which is inaccessible to the external queue.
     */
-   const bool mod_acquire =
+   const bool private_binding_acquire =
       src_queue_external &&
-      image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT;
+      (image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT ||
+       image->vk.external_handle_types != 0);
 
-   const bool mod_release =
+   const bool private_binding_release =
       dst_queue_external &&
-      image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT;
+      (image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT ||
+       image->vk.external_handle_types != 0);
 
    if (initial_layout == final_layout &&
-       !mod_acquire && !mod_release) {
+       !private_binding_acquire && !private_binding_release) {
       /* No work is needed. */
        return;
    }
@@ -1267,7 +1269,7 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer,
        */
       must_init_fast_clear_state = true;
       must_init_aux_surface = true;
-   } else if (mod_acquire) {
+   } else if (private_binding_acquire) {
       /* The fast clear state lives in a driver-private bo, and therefore the
        * external/foreign queue is unaware of it.
        *
@@ -1426,9 +1428,9 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer,
    /* We must override the anv_layout_to_* functions because they are unaware of
     * acquire/release direction.
     */
-   if (mod_acquire) {
+   if (private_binding_acquire) {
       initial_aux_usage = isl_mod_info->aux_usage;
-   } else if (mod_release) {
+   } else if (private_binding_release) {
       final_aux_usage = isl_mod_info->aux_usage;
    }