Mesa (main): anv: Allocate BO in appropriate region

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jun 24 16:52:04 UTC 2021


Module: Mesa
Branch: main
Commit: 6352371ff64d9e1c5c456dbcbf31092f39609418
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6352371ff64d9e1c5c456dbcbf31092f39609418

Author: Sagar Ghuge <sagar.ghuge at intel.com>
Date:   Thu Apr  2 20:16:08 2020 -0700

anv: Allocate BO in appropriate region

Signed-off-by: Sagar Ghuge <sagar.ghuge at intel.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5599>

---

 src/intel/vulkan/anv_allocator.c | 24 +++++++++++++++++++++++-
 src/intel/vulkan/anv_device.c    |  6 ++++++
 src/intel/vulkan/anv_private.h   |  3 +++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index 0cf0e15c539..2bdc3dd62de 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -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);
 
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index c101fedd0a6..fb69b653003 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -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,
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 5202d43f257..abfa488321f 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -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,



More information about the mesa-commit mailing list