Module: Mesa Branch: main Commit: 3e8d2617e18503809ac69307b319b3c3bc472fb6 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=3e8d2617e18503809ac69307b319b3c3bc472fb6
Author: Lionel Landwerlin <[email protected]> Date: Thu Oct 5 17:54:35 2023 +0300 anv: use buffer pools for BVH build buffers Private memory for BVH builds doesn't need to be mapped on the host, it's purely for use by the GPU. So it can be put into a different buffer pool that can put into VRAM only buffers. Signed-off-by: Lionel Landwerlin <[email protected]> Reviewed-by: Tapani Pälli <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25570> --- src/intel/vulkan/anv_batch_chain.c | 16 +++++++++------- src/intel/vulkan/anv_cmd_buffer.c | 4 +++- src/intel/vulkan/anv_device.c | 6 ++++++ src/intel/vulkan/anv_private.h | 7 ++++++- src/intel/vulkan/genX_acceleration_structure.c | 6 ++++-- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index 2f03c67ba51..14290c32341 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -743,7 +743,8 @@ anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer, */ struct anv_cmd_alloc anv_cmd_buffer_alloc_space(struct anv_cmd_buffer *cmd_buffer, - size_t size, uint32_t alignment) + size_t size, uint32_t alignment, + bool mapped) { /* Below 16k, source memory from dynamic state, otherwise allocate a BO. */ if (size < 16 * 1024) { @@ -764,12 +765,10 @@ anv_cmd_buffer_alloc_space(struct anv_cmd_buffer *cmd_buffer, struct anv_bo *bo = NULL; VkResult result = - anv_device_alloc_bo(cmd_buffer->device, - "cmd-buffer-space", - align(size, 4096), - ANV_BO_ALLOC_MAPPED, - 0, - &bo); + anv_bo_pool_alloc(mapped ? + &cmd_buffer->device->batch_bo_pool : + &cmd_buffer->device->bvh_bo_pool, + align(size, 4096), &bo); if (result != VK_SUCCESS) { anv_batch_set_error(&cmd_buffer->batch, VK_ERROR_OUT_OF_DEVICE_MEMORY); return ANV_EMPTY_ALLOC; @@ -779,6 +778,9 @@ anv_cmd_buffer_alloc_space(struct anv_cmd_buffer *cmd_buffer, u_vector_add(&cmd_buffer->dynamic_bos); if (bo_entry == NULL) { anv_batch_set_error(&cmd_buffer->batch, VK_ERROR_OUT_OF_HOST_MEMORY); + anv_bo_pool_free(bo->map != NULL ? + &cmd_buffer->device->batch_bo_pool : + &cmd_buffer->device->bvh_bo_pool, bo); return ANV_EMPTY_ALLOC; } *bo_entry = bo; diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 259abbcb4a4..e8a9d61f186 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -213,7 +213,9 @@ destroy_cmd_buffer(struct anv_cmd_buffer *cmd_buffer) while (u_vector_length(&cmd_buffer->dynamic_bos) > 0) { struct anv_bo **bo = u_vector_remove(&cmd_buffer->dynamic_bos); - anv_device_release_bo(cmd_buffer->device, *bo); + anv_bo_pool_free((*bo)->map != NULL ? + &cmd_buffer->device->batch_bo_pool : + &cmd_buffer->device->bvh_bo_pool, *bo); } u_vector_finish(&cmd_buffer->dynamic_bos); diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index c2c89e53941..99bb3cb1829 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -3232,6 +3232,10 @@ VkResult anv_CreateDevice( ANV_BO_ALLOC_MAPPED | ANV_BO_ALLOC_SNOOPED | ANV_BO_ALLOC_CAPTURE); + if (device->vk.enabled_extensions.KHR_acceleration_structure) { + anv_bo_pool_init(&device->bvh_bo_pool, device, "bvh build", + 0 /* alloc_flags */); + } /* Because scratch is also relative to General State Base Address, we leave * the base address 0 and start the pool memory at an offset. This way we @@ -3602,6 +3606,7 @@ VkResult anv_CreateDevice( fail_general_state_pool: anv_state_pool_finish(&device->general_state_pool); fail_batch_bo_pool: + anv_bo_pool_finish(&device->bvh_bo_pool); anv_bo_pool_finish(&device->batch_bo_pool); anv_bo_cache_finish(&device->bo_cache); fail_queue_cond: @@ -3707,6 +3712,7 @@ void anv_DestroyDevice( anv_state_pool_finish(&device->dynamic_state_pool); anv_state_pool_finish(&device->general_state_pool); + anv_bo_pool_finish(&device->bvh_bo_pool); anv_bo_pool_finish(&device->batch_bo_pool); anv_bo_cache_finish(&device->bo_cache); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index b0c98c271c7..b664f223fa9 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1511,8 +1511,12 @@ struct anv_device { /** List of anv_image objects with a private binding for implicit CCS */ struct list_head image_private_objects; + /** Memory pool for batch buffers */ struct anv_bo_pool batch_bo_pool; + /** Memory pool for utrace timestamp buffers */ struct anv_bo_pool utrace_bo_pool; + /** Memory pool for BVH build buffers */ + struct anv_bo_pool bvh_bo_pool; struct anv_bo_cache bo_cache; @@ -3748,7 +3752,8 @@ anv_cmd_alloc_is_empty(struct anv_cmd_alloc alloc) struct anv_cmd_alloc anv_cmd_buffer_alloc_space(struct anv_cmd_buffer *cmd_buffer, - size_t size, uint32_t alignment); + size_t size, uint32_t alignment, + bool private); VkResult anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer); diff --git a/src/intel/vulkan/genX_acceleration_structure.c b/src/intel/vulkan/genX_acceleration_structure.c index f43221846b1..acc8d7caeb4 100644 --- a/src/intel/vulkan/genX_acceleration_structure.c +++ b/src/intel/vulkan/genX_acceleration_structure.c @@ -746,7 +746,8 @@ cmd_build_acceleration_structures( struct anv_cmd_alloc private_mem_alloc; if (private_mem_total > cmd_buffer->state.rt.build_priv_mem_size) { private_mem_alloc = - anv_cmd_buffer_alloc_space(cmd_buffer, private_mem_total, 64); + anv_cmd_buffer_alloc_space(cmd_buffer, private_mem_total, 64, + false /* mapped */); if (anv_cmd_alloc_is_empty(private_mem_alloc)) { anv_batch_set_error(&cmd_buffer->batch, VK_ERROR_OUT_OF_DEVICE_MEMORY); goto error; @@ -763,7 +764,8 @@ cmd_build_acceleration_structures( } struct anv_cmd_alloc transient_mem_alloc = - anv_cmd_buffer_alloc_space(cmd_buffer, transient_total, 64); + anv_cmd_buffer_alloc_space(cmd_buffer, transient_total, 64, + true /* mapped */); if (transient_total > 0 && anv_cmd_alloc_is_empty(transient_mem_alloc)) { anv_batch_set_error(&cmd_buffer->batch, VK_ERROR_OUT_OF_DEVICE_MEMORY); goto error;
