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,