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

Author: José Roberto de Souza <[email protected]>
Date:   Fri Oct 21 12:14:34 2022 -0700

hasvk: Nuke code around local memory

None of the platforms supported by this driver supports local memory.

Signed-off-by: José Roberto de Souza <[email protected]>
Reviewed-by: Ivan Briano <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19240>

---

 src/intel/vulkan_hasvk/anv_allocator.c |  33 +---------
 src/intel/vulkan_hasvk/anv_device.c    | 113 ++-------------------------------
 src/intel/vulkan_hasvk/anv_gem.c       |  29 ---------
 src/intel/vulkan_hasvk/anv_gem_stubs.c |   8 ---
 src/intel/vulkan_hasvk/anv_private.h   |  20 ------
 5 files changed, 8 insertions(+), 195 deletions(-)

diff --git a/src/intel/vulkan_hasvk/anv_allocator.c 
b/src/intel/vulkan_hasvk/anv_allocator.c
index ce64811b178..8c4ffbfb437 100644
--- a/src/intel/vulkan_hasvk/anv_allocator.c
+++ b/src/intel/vulkan_hasvk/anv_allocator.c
@@ -1686,38 +1686,7 @@ 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;
-
-   /* If we have vram size, we have multiple memory regions and should choose
-    * one of them.
-    */
-   if (anv_physical_device_has_vram(device->physical)) {
-      struct drm_i915_gem_memory_class_instance regions[2];
-      uint32_t nregions = 0;
-
-      /* This always try to put the object in local memory. Here
-       * vram_non_mappable & vram_mappable actually are the same region.
-       */
-      regions[nregions++] = device->physical->vram_non_mappable.region;
-
-      /* If the buffer is mapped on the host, add the system memory region.
-       * This ensures that if the buffer cannot live in mappable local memory,
-       * it can be spilled to system memory.
-       */
-      uint32_t flags = 0;
-      if ((alloc_flags & ANV_BO_ALLOC_MAPPED) ||
-          (alloc_flags & ANV_BO_ALLOC_LOCAL_MEM_CPU_VISIBLE)) {
-         regions[nregions++] = device->physical->sys.region;
-         if (device->physical->vram_non_mappable.size > 0)
-            flags |= I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS;
-      }
-
-      gem_handle = anv_gem_create_regions(device, size + ccs_size,
-                                          flags, nregions, regions);
-   } else {
-      gem_handle = anv_gem_create(device, size + ccs_size);
-   }
-
+   uint32_t gem_handle = anv_gem_create(device, size + ccs_size);
    if (gem_handle == 0)
       return vk_error(device, VK_ERROR_OUT_OF_DEVICE_MEMORY);
 
diff --git a/src/intel/vulkan_hasvk/anv_device.c 
b/src/intel/vulkan_hasvk/anv_device.c
index 3708013c8c1..1b195e83308 100644
--- a/src/intel/vulkan_hasvk/anv_device.c
+++ b/src/intel/vulkan_hasvk/anv_device.c
@@ -290,9 +290,7 @@ get_device_extensions(const struct anv_physical_device 
*device,
       /* Enable the extension only if we have support on both the local &
        * system memory
        */
-      .EXT_memory_budget                     = (!device->info.has_local_mem ||
-                                                
device->vram_mappable.available > 0) &&
-                                               device->sys.available,
+      .EXT_memory_budget                     = device->sys.available,
       .EXT_non_seamless_cube_map             = true,
       .EXT_pci_bus_info                      = true,
       .EXT_physical_device_drm               = true,
@@ -377,25 +375,10 @@ anv_init_meminfo(struct anv_physical_device *device, int 
fd)
 {
    const struct intel_device_info *devinfo = &device->info;
 
-   device->sys.region.memory_class = devinfo->mem.sram.mem_class;
-   device->sys.region.memory_instance = devinfo->mem.sram.mem_instance;
    device->sys.size =
       anv_compute_sys_heap_size(device, devinfo->mem.sram.mappable.size);
    device->sys.available = devinfo->mem.sram.mappable.free;
 
-   device->vram_mappable.region.memory_class = devinfo->mem.vram.mem_class;
-   device->vram_mappable.region.memory_instance =
-      devinfo->mem.vram.mem_instance;
-   device->vram_mappable.size = devinfo->mem.vram.mappable.size;
-   device->vram_mappable.available = devinfo->mem.vram.mappable.free;
-
-   device->vram_non_mappable.region.memory_class =
-      devinfo->mem.vram.mem_class;
-   device->vram_non_mappable.region.memory_instance =
-      devinfo->mem.vram.mem_instance;
-   device->vram_non_mappable.size = devinfo->mem.vram.unmappable.size;
-   device->vram_non_mappable.available = devinfo->mem.vram.unmappable.free;
-
    return VK_SUCCESS;
 }
 
@@ -407,8 +390,6 @@ anv_update_meminfo(struct anv_physical_device *device, int 
fd)
 
    const struct intel_device_info *devinfo = &device->info;
    device->sys.available = devinfo->mem.sram.mappable.free;
-   device->vram_mappable.available = devinfo->mem.vram.mappable.free;
-   device->vram_non_mappable.available = devinfo->mem.vram.unmappable.free;
 }
 
 
@@ -421,66 +402,11 @@ anv_physical_device_init_heaps(struct anv_physical_device 
*device, int fd)
 
    assert(device->sys.size != 0);
 
-   if (anv_physical_device_has_vram(device)) {
-      /* We can create 2 or 3 different heaps when we have local memory
-       * support, first heap with local memory size and second with system
-       * memory size and the third is added only if part of the vram is
-       * mappable to the host.
-       */
-      device->memory.heap_count = 2;
-      device->memory.heaps[0] = (struct anv_memory_heap) {
-         /* If there is a vram_non_mappable, use that for the device only
-          * heap. Otherwise use the vram_mappable.
-          */
-         .size = device->vram_non_mappable.size != 0 ?
-                 device->vram_non_mappable.size : device->vram_mappable.size,
-         .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
-         .is_local_mem = true,
-      };
-      device->memory.heaps[1] = (struct anv_memory_heap) {
-         .size = device->sys.size,
-         .flags = 0,
-         .is_local_mem = false,
-      };
-      /* Add an additional smaller vram mappable heap if we can't map all the
-       * vram to the host.
-       */
-      if (device->vram_non_mappable.size > 0) {
-         device->memory.heap_count++;
-         device->memory.heaps[2] = (struct anv_memory_heap) {
-            .size = device->vram_mappable.size,
-            .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
-            .is_local_mem = true,
-         };
-      }
-
-      device->memory.type_count = 3;
-      device->memory.types[0] = (struct anv_memory_type) {
-         .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
-         .heapIndex = 0,
-      };
-      device->memory.types[1] = (struct anv_memory_type) {
-         .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
-                          VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
-                          VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
-         .heapIndex = 1,
-      };
-      device->memory.types[2] = (struct anv_memory_type) {
-         .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
-                          VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
-                          VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
-         /* This memory type either comes from heaps[0] if there is only
-          * mappable vram region, or from heaps[2] if there is both mappable &
-          * non-mappable vram regions.
-          */
-         .heapIndex = device->vram_non_mappable.size > 0 ? 2 : 0,
-      };
-   } else if (device->info.has_llc) {
+   if (device->info.has_llc) {
       device->memory.heap_count = 1;
       device->memory.heaps[0] = (struct anv_memory_heap) {
          .size = device->sys.size,
          .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
-         .is_local_mem = false,
       };
 
       /* Big core GPUs share LLC with the CPU and thus one memory type can be
@@ -499,7 +425,6 @@ anv_physical_device_init_heaps(struct anv_physical_device 
*device, int fd)
       device->memory.heaps[0] = (struct anv_memory_heap) {
          .size = device->sys.size,
          .flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
-         .is_local_mem = false,
       };
 
       /* The spec requires that we expose a host-visible, coherent memory
@@ -2561,14 +2486,9 @@ anv_get_memory_budget(VkPhysicalDevice physicalDevice,
 
    anv_update_meminfo(device, device->local_fd);
 
-   VkDeviceSize total_sys_heaps_size = 0, total_vram_heaps_size = 0;
-   for (size_t i = 0; i < device->memory.heap_count; i++) {
-      if (device->memory.heaps[i].is_local_mem) {
-         total_vram_heaps_size += device->memory.heaps[i].size;
-      } else {
-         total_sys_heaps_size += device->memory.heaps[i].size;
-      }
-   }
+   VkDeviceSize total_sys_heaps_size = 0;
+   for (size_t i = 0; i < device->memory.heap_count; i++)
+      total_sys_heaps_size += device->memory.heaps[i].size;
 
    for (size_t i = 0; i < device->memory.heap_count; i++) {
       VkDeviceSize heap_size = device->memory.heaps[i].size;
@@ -2576,17 +2496,8 @@ anv_get_memory_budget(VkPhysicalDevice physicalDevice,
       VkDeviceSize heap_budget, total_heaps_size;
       uint64_t mem_available = 0;
 
-      if (device->memory.heaps[i].is_local_mem) {
-         total_heaps_size = total_vram_heaps_size;
-         if (device->vram_non_mappable.size > 0 && i == 0) {
-            mem_available = device->vram_non_mappable.available;
-         } else {
-            mem_available = device->vram_mappable.available;
-         }
-      } else {
-         total_heaps_size = total_sys_heaps_size;
-         mem_available = device->sys.available;
-      }
+      total_heaps_size = total_sys_heaps_size;
+      mem_available = device->sys.available;
 
       double heap_proportion = (double) heap_size / total_heaps_size;
       VkDeviceSize available_prop = mem_available * heap_proportion;
@@ -3648,16 +3559,6 @@ VkResult anv_AllocateMemory(
    if (device->physical->has_implicit_ccs && device->info->has_aux_map)
       alloc_flags |= ANV_BO_ALLOC_IMPLICIT_CCS;
 
-   /* If i915 reported a mappable/non_mappable vram regions and the
-    * application want lmem mappable, then we need to use the
-    * I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS flag to create our BO.
-    */
-   if (pdevice->vram_mappable.size > 0 &&
-       pdevice->vram_non_mappable.size > 0 &&
-       (mem_type->propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) &&
-       (mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
-      alloc_flags |= ANV_BO_ALLOC_LOCAL_MEM_CPU_VISIBLE;
-
    if (vk_flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT)
       alloc_flags |= ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS;
 
diff --git a/src/intel/vulkan_hasvk/anv_gem.c b/src/intel/vulkan_hasvk/anv_gem.c
index 651bc92f6d5..cabfc3a1a02 100644
--- a/src/intel/vulkan_hasvk/anv_gem.c
+++ b/src/intel/vulkan_hasvk/anv_gem.c
@@ -64,35 +64,6 @@ anv_gem_close(struct anv_device *device, uint32_t gem_handle)
    intel_ioctl(device->fd, DRM_IOCTL_GEM_CLOSE, &close);
 }
 
-uint32_t
-anv_gem_create_regions(struct anv_device *device, uint64_t anv_bo_size,
-                       uint32_t flags, uint32_t num_regions,
-                       struct drm_i915_gem_memory_class_instance *regions)
-{
-   /* Check for invalid flags */
-   assert((flags & ~I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS) == 0);
-
-   struct drm_i915_gem_create_ext_memory_regions ext_regions = {
-      .base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS },
-      .num_regions = num_regions,
-      .regions = (uintptr_t)regions,
-   };
-
-   struct drm_i915_gem_create_ext gem_create = {
-      .size = anv_bo_size,
-      .extensions = (uintptr_t) &ext_regions,
-      .flags = flags,
-   };
-
-   int ret = intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_CREATE_EXT,
-                         &gem_create);
-   if (ret != 0) {
-      return 0;
-   }
-
-   return gem_create.handle;
-}
-
 /**
  * Wrapper around DRM_IOCTL_I915_GEM_MMAP. Returns MAP_FAILED on error.
  */
diff --git a/src/intel/vulkan_hasvk/anv_gem_stubs.c 
b/src/intel/vulkan_hasvk/anv_gem_stubs.c
index b5ef9e51500..6747276877f 100644
--- a/src/intel/vulkan_hasvk/anv_gem_stubs.c
+++ b/src/intel/vulkan_hasvk/anv_gem_stubs.c
@@ -45,14 +45,6 @@ anv_gem_close(struct anv_device *device, uint32_t gem_handle)
    close(gem_handle);
 }
 
-uint32_t
-anv_gem_create_regions(struct anv_device *device, uint64_t anv_bo_size,
-                       uint32_t flags, uint32_t num_regions,
-                       struct drm_i915_gem_memory_class_instance *regions)
-{
-   return 0;
-}
-
 void*
 anv_gem_mmap(struct anv_device *device, uint32_t gem_handle,
              uint64_t offset, uint64_t size, uint32_t flags)
diff --git a/src/intel/vulkan_hasvk/anv_private.h 
b/src/intel/vulkan_hasvk/anv_private.h
index 2405d6944d4..9307e5e710d 100644
--- a/src/intel/vulkan_hasvk/anv_private.h
+++ b/src/intel/vulkan_hasvk/anv_private.h
@@ -948,12 +948,9 @@ struct anv_memory_heap {
     * Align it to 64 bits to make atomic operations faster on 32 bit platforms.
     */
    VkDeviceSize      used __attribute__ ((aligned (8)));
-
-   bool              is_local_mem;
 };
 
 struct anv_memregion {
-   struct drm_i915_gem_memory_class_instance region;
    uint64_t size;
    uint64_t available;
 };
@@ -1038,11 +1035,6 @@ struct anv_physical_device {
       bool                                      need_clflush;
     } memory;
 
-    /* Either we have a single vram region and it's all mappable, or we have
-     * both mappable & non-mappable parts. System memory is always available.
-     */
-    struct anv_memregion                        vram_mappable;
-    struct anv_memregion                        vram_non_mappable;
     struct anv_memregion                        sys;
     uint8_t                                     driver_build_sha1[20];
     uint8_t                                     
pipeline_cache_uuid[VK_UUID_SIZE];
@@ -1068,12 +1060,6 @@ struct anv_physical_device {
     struct intel_measure_device                 measure_device;
 };
 
-static inline bool
-anv_physical_device_has_vram(const struct anv_physical_device *device)
-{
-   return device->vram_mappable.size > 0;
-}
-
 struct anv_instance {
     struct vk_instance                          vk;
 
@@ -1344,9 +1330,6 @@ 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 and should be cpu visible */
-   ANV_BO_ALLOC_LOCAL_MEM_CPU_VISIBLE = (1 << 10),
 };
 
 VkResult anv_device_alloc_bo(struct anv_device *device,
@@ -1417,9 +1400,6 @@ void* anv_gem_mmap(struct anv_device *device,
 void anv_gem_munmap(struct anv_device *device, void *p, uint64_t size);
 uint32_t anv_gem_create(struct anv_device *device, uint64_t size);
 void anv_gem_close(struct anv_device *device, uint32_t gem_handle);
-uint32_t anv_gem_create_regions(struct anv_device *device, uint64_t 
anv_bo_size,
-                                uint32_t flags, uint32_t num_regions,
-                                struct drm_i915_gem_memory_class_instance 
*regions);
 uint32_t anv_gem_userptr(struct anv_device *device, void *mem, size_t size);
 int anv_gem_wait(struct anv_device *device, uint32_t gem_handle, int64_t 
*timeout_ns);
 int anv_gem_execbuffer(struct anv_device *device,

Reply via email to