From eaeda2107ef0c1ecf27b92c244da9f4ea244538a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Mon, 6 Feb 2023 08:41:08 -0800 Subject: [PATCH] anv: Use DRM_IOCTL_I915_GEM_CREATE_EXT in all supported kernels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_allocator.c | 14 +++++-------- src/intel/vulkan/anv_gem.c | 35 ++++++++++++-------------------- src/intel/vulkan/anv_gem_stubs.c | 24 ++++++++-------------- src/intel/vulkan/anv_private.h | 1 - 4 files changed, 27 insertions(+), 47 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,8 +27,16 @@ #include "util/anon_file.h" #include "anv_private.h" +void +anv_gem_close(struct anv_device *device, uint32_t gem_handle) +{ + close(gem_handle); +} + uint32_t -anv_gem_create(struct anv_device *device, uint64_t 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) { int fd = os_create_anonymous_file(size, "fake bo"); if (fd == -1) @@ -39,20 +47,6 @@ anv_gem_create(struct anv_device *device, uint64_t size) return fd; } -void -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, - const struct intel_memory_class_instance **regions) -{ - return 0; -} - void* anv_gem_mmap(struct anv_device *device, struct anv_bo *bo, uint64_t offset, uint64_t size, uint32_t flags) 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,