From a501a840a382daa5591673c96ec9451c977c1968 Mon Sep 17 00:00:00 2001 From: Paulo Zanoni Date: Mon, 5 Feb 2024 15:33:42 -0800 Subject: [PATCH] anv/sparse: add an extra step before anv_sparse_bind_resource_memory() I need to add some sparse-related checks that require having the anv_buffer and anv_image, and putting them directly inside anv_queue_submit_sparse_bind_locked() doesn't feel like the right thing to do. Here we change the interface so now we have anv_sparse_bind_buffer() and anv_sparse_bind_image_opaque() as the main interface into anv_sparse.c, so they both can call the lower level anv_sparse_bind_resource_memory() function. In the next patch we'll be adding changing the code of the functions we just created, justifying their addition. Reviewed-by: Lionel Landwerlin Signed-off-by: Paulo Zanoni Part-of: --- src/intel/vulkan/anv_batch_chain.c | 16 ++++++---------- src/intel/vulkan/anv_private.h | 12 ++++++++---- src/intel/vulkan/anv_sparse.c | 26 +++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index 0dfdd582a4b..fee5e6d8335 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -1420,10 +1420,9 @@ anv_queue_submit_sparse_bind_locked(struct anv_queue *queue, assert(anv_buffer_is_sparse(buffer)); for (uint32_t j = 0; j < bind_info->bindCount; j++) { - result = anv_sparse_bind_resource_memory(device, - &buffer->sparse_data, - &bind_info->pBinds[j], - &sparse_submit); + result = anv_sparse_bind_buffer(device, buffer, + &bind_info->pBinds[j], + &sparse_submit); if (result != VK_SUCCESS) goto out_free_submit; } @@ -1451,14 +1450,11 @@ anv_queue_submit_sparse_bind_locked(struct anv_queue *queue, ANV_FROM_HANDLE(anv_image, image, bind_info->image); assert(anv_image_is_sparse(image)); - assert(!image->disjoint); - struct anv_sparse_binding_data *sparse_data = - &image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].sparse_data; for (uint32_t j = 0; j < bind_info->bindCount; j++) { - result = anv_sparse_bind_resource_memory(device, sparse_data, - &bind_info->pBinds[j], - &sparse_submit); + result = anv_sparse_bind_image_opaque(device, image, + &bind_info->pBinds[j], + &sparse_submit); if (result != VK_SUCCESS) goto out_free_submit; } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 74ef3f367a7..484d7070cec 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -2949,10 +2949,14 @@ VkResult anv_init_sparse_bindings(struct anv_device *device, struct anv_address *out_address); VkResult anv_free_sparse_bindings(struct anv_device *device, struct anv_sparse_binding_data *sparse); -VkResult anv_sparse_bind_resource_memory(struct anv_device *device, - struct anv_sparse_binding_data *data, - const VkSparseMemoryBind *bind_, - struct anv_sparse_submission *submit); +VkResult anv_sparse_bind_buffer(struct anv_device *device, + struct anv_buffer *buffer, + const VkSparseMemoryBind *vk_bind, + struct anv_sparse_submission *submit); +VkResult anv_sparse_bind_image_opaque(struct anv_device *device, + struct anv_image *image, + const VkSparseMemoryBind *vk_bind, + struct anv_sparse_submission *submit); VkResult anv_sparse_bind_image_memory(struct anv_queue *queue, struct anv_image *image, const VkSparseImageMemoryBind *bind, diff --git a/src/intel/vulkan/anv_sparse.c b/src/intel/vulkan/anv_sparse.c index 3d5ef026678..3f539e7eb73 100644 --- a/src/intel/vulkan/anv_sparse.c +++ b/src/intel/vulkan/anv_sparse.c @@ -991,7 +991,7 @@ vk_bind_to_anv_vm_bind(struct anv_sparse_binding_data *sparse, return anv_bind; } -VkResult +static VkResult anv_sparse_bind_resource_memory(struct anv_device *device, struct anv_sparse_binding_data *sparse, const VkSparseMemoryBind *vk_bind, @@ -1005,6 +1005,30 @@ anv_sparse_bind_resource_memory(struct anv_device *device, return anv_sparse_submission_add(device, submit, &bind); } +VkResult +anv_sparse_bind_buffer(struct anv_device *device, + struct anv_buffer *buffer, + const VkSparseMemoryBind *vk_bind, + struct anv_sparse_submission *submit) +{ + return anv_sparse_bind_resource_memory(device, &buffer->sparse_data, + vk_bind, submit); +} + +VkResult +anv_sparse_bind_image_opaque(struct anv_device *device, + struct anv_image *image, + const VkSparseMemoryBind *vk_bind, + struct anv_sparse_submission *submit) +{ + struct anv_sparse_binding_data *sparse_data = + &image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN].sparse_data; + assert(!image->disjoint); + + return anv_sparse_bind_resource_memory(device, sparse_data, + vk_bind, submit); +} + VkResult anv_sparse_bind_image_memory(struct anv_queue *queue, struct anv_image *image,