Module: Mesa Branch: main Commit: eaeda2107ef0c1ecf27b92c244da9f4ea244538a URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=eaeda2107ef0c1ecf27b92c244da9f4ea244538a
Author: José Roberto de Souza <[email protected]> Date: Mon Feb 6 08:41:08 2023 -0800 anv: Use DRM_IOCTL_I915_GEM_CREATE_EXT in all supported kernels As we continue to refactor the code base to support Xe KMD here I'm dropping anv_gem_create() and unifying all graphics memory allocation calls to anv_gem_create_regions(). anv_gem_create_regions() will call DRM_IOCTL_I915_GEM_CREATE_EXT for integrated platforms too only leaving DRM_IOCTL_I915_GEM_CREATE calls to kernel versions that do not support DRM_IOCTL_I915_GEM_CREATE_EXT. This can be detected by devinfo->mem.use_class_instance as DRM_I915_QUERY_MEMORY_REGIONS uAPI landed in the same kernel version as DRM_IOCTL_I915_GEM_CREATE_EXT. Signed-off-by: José Roberto de Souza <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20948> --- src/intel/vulkan/anv_allocator.c | 14 +++++--------- src/intel/vulkan/anv_gem.c | 35 +++++++++++++---------------------- src/intel/vulkan/anv_gem_stubs.c | 22 ++++++++-------------- src/intel/vulkan/anv_private.h | 1 - 4 files changed, 26 insertions(+), 46 deletions(-) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index 2569c4984ff..5796a2db4af 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -1451,15 +1451,13 @@ anv_device_alloc_bo(struct anv_device *device, ccs_size = align64(DIV_ROUND_UP(size, aux_ratio), 4096); } - uint32_t gem_handle; + const struct intel_memory_class_instance *regions[2]; + uint32_t nregions = 0, flags = 0; /* If we have vram size, we have multiple memory regions and should choose * one of them. */ if (anv_physical_device_has_vram(device->physical)) { - const struct intel_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. */ @@ -1472,7 +1470,6 @@ anv_device_alloc_bo(struct anv_device *device, * 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_NO_LOCAL_MEM) && ((alloc_flags & ANV_BO_ALLOC_MAPPED) || (alloc_flags & ANV_BO_ALLOC_LOCAL_MEM_CPU_VISIBLE))) { @@ -1480,13 +1477,12 @@ anv_device_alloc_bo(struct anv_device *device, 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); + regions[nregions++] = device->physical->sys.region; } + uint32_t gem_handle = anv_gem_create_regions(device, size + ccs_size, + flags, nregions, regions); if (gem_handle == 0) return vk_error(device, VK_ERROR_OUT_OF_DEVICE_MEMORY); diff --git a/src/intel/vulkan/anv_gem.c b/src/intel/vulkan/anv_gem.c index 1892e4e35d5..f2151ac9c3f 100644 --- a/src/intel/vulkan/anv_gem.c +++ b/src/intel/vulkan/anv_gem.c @@ -32,27 +32,6 @@ #include "anv_private.h" #include "common/intel_gem.h" -/** - * Wrapper around DRM_IOCTL_I915_GEM_CREATE. - * - * Return gem handle, or 0 on failure. Gem handles are never 0. - */ -uint32_t -anv_gem_create(struct anv_device *device, uint64_t size) -{ - struct drm_i915_gem_create gem_create = { - .size = size, - }; - - int ret = intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_CREATE, &gem_create); - if (ret != 0) { - /* FIXME: What do we do if this fails? */ - return 0; - } - - return gem_create.handle; -} - void anv_gem_close(struct anv_device *device, uint32_t gem_handle) { @@ -68,8 +47,20 @@ anv_gem_create_regions(struct anv_device *device, uint64_t anv_bo_size, uint32_t flags, uint32_t num_regions, const struct intel_memory_class_instance **regions) { - struct drm_i915_gem_memory_class_instance i915_regions[2]; + if (unlikely(!device->info->mem.use_class_instance)) { + assert(num_regions == 1 && + device->physical->sys.region == regions[0] && + flags == 0); + struct drm_i915_gem_create gem_create = { + .size = anv_bo_size, + }; + if (intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_CREATE, &gem_create)) + return 0; + return gem_create.handle; + } + + struct drm_i915_gem_memory_class_instance i915_regions[2]; /* Check for invalid flags */ assert((flags & ~I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS) == 0); assert(num_regions <= ARRAY_SIZE(i915_regions)); diff --git a/src/intel/vulkan/anv_gem_stubs.c b/src/intel/vulkan/anv_gem_stubs.c index abc6efe2e4b..f82d9873cd2 100644 --- a/src/intel/vulkan/anv_gem_stubs.c +++ b/src/intel/vulkan/anv_gem_stubs.c @@ -27,18 +27,6 @@ #include "util/anon_file.h" #include "anv_private.h" -uint32_t -anv_gem_create(struct anv_device *device, uint64_t size) -{ - int fd = os_create_anonymous_file(size, "fake bo"); - if (fd == -1) - return 0; - - assert(fd != 0); - - return fd; -} - void anv_gem_close(struct anv_device *device, uint32_t gem_handle) { @@ -46,11 +34,17 @@ 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, +anv_gem_create_regions(struct anv_device *device, uint64_t size, uint32_t flags, uint32_t num_regions, const struct intel_memory_class_instance **regions) { - return 0; + int fd = os_create_anonymous_file(size, "fake bo"); + if (fd == -1) + return 0; + + assert(fd != 0); + + return fd; } void* diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 4c1a43aeafa..bf6d93f2dee 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1345,7 +1345,6 @@ VkResult anv_queue_submit_simple_batch(struct anv_queue *queue, void* anv_gem_mmap(struct anv_device *device, struct anv_bo *bo, uint64_t offset, uint64_t size, uint32_t flags); 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,
