anv: Allocate BO in appropriate region
authorSagar Ghuge <sagar.ghuge@intel.com>
Fri, 3 Apr 2020 03:16:08 +0000 (20:16 -0700)
committerMarge Bot <eric+marge@anholt.net>
Thu, 24 Jun 2021 16:14:38 +0000 (16:14 +0000)
Signed-off-by: Sagar Ghuge <sagar.ghuge@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5599>

src/intel/vulkan/anv_allocator.c
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_private.h

index 0cf0e15..2bdc3dd 100644 (file)
@@ -1649,7 +1649,29 @@ anv_device_alloc_bo(struct anv_device *device,
       ccs_size = align_u64(DIV_ROUND_UP(size, INTEL_AUX_MAP_GFX12_CCS_SCALE), 4096);
    }
 
-   uint32_t gem_handle = anv_gem_create(device, size + ccs_size);
+   uint32_t gem_handle;
+
+   /* If we have vram size, we have multiple memory regions and should choose
+    * one of them.
+    */
+   if (device->physical->vram.size > 0) {
+      struct drm_i915_gem_memory_class_instance regions[2];
+      uint32_t nregions = 0;
+
+      if (alloc_flags & ANV_BO_ALLOC_LOCAL_MEM) {
+         /* For vram allocation, still use system memory as a fallback. */
+         regions[nregions++] = device->physical->vram.region;
+         regions[nregions++] = device->physical->sys.region;
+      } else {
+         regions[nregions++] = device->physical->sys.region;
+      }
+
+      gem_handle = anv_gem_create_regions(device, size + ccs_size,
+                                          nregions, regions);
+   } else {
+      gem_handle = anv_gem_create(device, size + ccs_size);
+   }
+
    if (gem_handle == 0)
       return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
 
index c101fed..fb69b65 100644 (file)
@@ -4021,6 +4021,12 @@ VkResult anv_AllocateMemory(
       goto success;
    }
 
+   /* Set ALLOC_LOCAL_MEM flag if heap has device local bit set and requested
+    * memory property flag has DEVICE_LOCAL_BIT set.
+    */
+   if (mem_type->propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
+      alloc_flags |= ANV_BO_ALLOC_LOCAL_MEM;
+
    /* Regular allocate (not importing memory). */
 
    result = anv_device_alloc_bo(device, "user", pAllocateInfo->allocationSize,
index 5202d43..abfa488 100644 (file)
@@ -1404,6 +1404,9 @@ enum anv_bo_alloc_flags {
 
    /** This buffer has implicit CCS data attached to it */
    ANV_BO_ALLOC_IMPLICIT_CCS = (1 << 9),
+
+   /** This buffer is allocated from local memory */
+   ANV_BO_ALLOC_LOCAL_MEM = (1 << 10),
 };
 
 VkResult anv_device_alloc_bo(struct anv_device *device,