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 <lionel.g.landwerlin@intel.com> Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25570>
This commit is contained in:

committed by
Marge Bot

parent
bab344645f
commit
3e8d2617e1
@@ -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;
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user