anv: Properly alloc buffers that will be promoted to framebuffer in Xe KMD
authorJosé Roberto de Souza <jose.souza@intel.com>
Fri, 3 Mar 2023 19:03:18 +0000 (11:03 -0800)
committerMarge Bot <emma+marge@anholt.net>
Wed, 15 Mar 2023 18:17:11 +0000 (18:17 +0000)
Xe KMD does a special caching handling for buffers that will be
scanout to display, so that is why it needs a flag set during
allocation.

Checking if VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA
is available in AllocateMemory() and marking the buffer as scanout.

All WSI code paths but one sets
VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA.
The only one that doesn't requires that WSI is initialize with
wsi_device_options.sw_device = true to be executed, what is not the
case for ANV.

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21885>

src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/xe/anv_kmd_backend.c

index 2a23bd0..d820c09 100644 (file)
@@ -3959,11 +3959,20 @@ VkResult anv_AllocateMemory(
       }
 
       default:
-         if (ext->sType != VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA)
-            /* this isn't a real enum value,
-             * so use conditional to avoid compiler warn
+         /* VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA isn't a real
+          * enum value, so use conditional to avoid compiler warn
+          */
+         if (ext->sType == VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA) {
+            /* TODO: Android, ChromeOS and other applications may need another
+             * way to allocate buffers that can be scanout to display but it
+             * should pretty easy to catch those as Xe KMD driver will print
+             * warnings in dmesg when scanning buffers allocated without
+             * proper flag set.
              */
+            alloc_flags |= ANV_BO_ALLOC_SCANOUT;
+         } else {
             anv_debug_ignored_stype(ext->sType);
+         }
          break;
       }
    }
index 278e384..ba0c80e 100644 (file)
@@ -460,6 +460,9 @@ enum anv_bo_alloc_flags {
     * Should be faster for bo pools, which write but do not read
     */
    ANV_BO_ALLOC_WRITE_COMBINE = (1 << 12),
+
+   /** This buffer will be scanout to display */
+   ANV_BO_ALLOC_SCANOUT = (1 << 13),
 };
 
 struct anv_bo {
index c530ff4..01784ee 100644 (file)
@@ -37,6 +37,7 @@ xe_gem_create(struct anv_device *device,
    struct drm_xe_gem_create gem_create = {
      .vm_id = device->vm_id,
      .size = size,
+     .flags = alloc_flags & ANV_BO_ALLOC_SCANOUT ? XE_GEM_CREATE_FLAG_SCANOUT : 0,
    };
    for (uint16_t i = 0; i < regions_count; i++)
       gem_create.flags |= BITFIELD_BIT(regions[i]->instance);