From b362b71c68d285e4f807fc7ea25a5d8a0018888b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Briano?= Date: Wed, 25 Sep 2024 11:49:47 -0700 Subject: [PATCH] anv: allocate sparse descriptor buffers from the correct heap When allocating a buffer normally, this flag gets to the allocator from the memory requirements, but when sparse bindings are created we were checking for them but never setting them. Fixes sparse descriptor buffers on Xe2. Makes the failure on TRTT more obvious. Fixes: c6a91f16952 ("anv: add new heap/pool for descriptor buffers") Fixes: 692e1ab2c1e ("anv: get rid of the second dynamic state heap") Reviewed-by: Lionel Landwerlin Part-of: (cherry picked from commit a4cbc903a80f31d303e4bb4d0f1a0bc76d957d95) --- .pick_status.json | 2 +- src/intel/vulkan/anv_device.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index 5ffde43683a..7e1fb16c180 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -574,7 +574,7 @@ "description": "anv: allocate sparse descriptor buffers from the correct heap", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "c6a91f16952cfe9f685cc6a0a185161364fdcdcf", "notes": null diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 4f3b38d6d1c..b704a147de6 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -5178,6 +5178,16 @@ VkResult anv_CreateBuffer( fprintf(stderr, "=== %s %s:%d flags:0x%08x\n", __func__, __FILE__, __LINE__, pCreateInfo->flags); + if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && + device->physical->sparse_type == ANV_SPARSE_TYPE_TRTT) { + VkBufferUsageFlags2KHR usages = get_buffer_usages(pCreateInfo); + if (usages & (VK_BUFFER_USAGE_2_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT | + VK_BUFFER_USAGE_2_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT)) { + return vk_errorf(device, VK_ERROR_UNKNOWN, + "Cannot support sparse descriptor buffers with TRTT."); + } + } + /* Don't allow creating buffers bigger than our address space. The real * issue here is that we may align up the buffer size and we don't want * doing so to cause roll-over. However, no one has any business @@ -5215,6 +5225,14 @@ VkResult anv_CreateBuffer( client_address = *((const uint64_t *)opaque_info->opaqueCaptureDescriptorData); } + /* If this buffer will be used as a descriptor buffer, make sure we + * allocate it on the correct heap. + */ + if (buffer->vk.usage & (VK_BUFFER_USAGE_2_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT | + VK_BUFFER_USAGE_2_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT)) { + alloc_flags |= ANV_BO_ALLOC_DYNAMIC_VISIBLE_POOL; + } + VkResult result = anv_init_sparse_bindings(device, buffer->vk.size, &buffer->sparse_data, alloc_flags, client_address,