anv: reduce working temporary memory for BVH builds

Part of the memory allocated (private) is a temporary working buffer
for the GRL kernels. Once the build operation is done, the buffer
becomes unused.

Rather than allocate a new buffer each time, reuse the current last
allocated one if its size fits the next build operation.

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:
Lionel Landwerlin
2023-10-05 17:09:54 +03:00
committed by Marge Bot
parent 2d3ab674ee
commit 787c29f2fc
2 changed files with 22 additions and 6 deletions

View File

@@ -3367,6 +3367,9 @@ struct anv_cmd_ray_tracing_state {
struct anv_bo *bo;
struct brw_rt_scratch_layout layout;
} scratch;
struct anv_address build_priv_mem_addr;
size_t build_priv_mem_size;
};
/** State required while building cmd buffer */

View File

@@ -742,13 +742,26 @@ cmd_build_acceleration_structures(
private_mem_binnedsah_offset = private_mem_total;
private_mem_total += align_private_size(private_mem_binnedsah_size);
/* Allocate required memory */
struct anv_cmd_alloc private_mem_alloc =
anv_cmd_buffer_alloc_space(cmd_buffer, private_mem_total, 64);
if (private_mem_total > 0 && anv_cmd_alloc_is_empty(private_mem_alloc)) {
anv_batch_set_error(&cmd_buffer->batch, VK_ERROR_OUT_OF_DEVICE_MEMORY);
goto error;
/* Allocate required memory, unless we already have a suiteable buffer */
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);
if (anv_cmd_alloc_is_empty(private_mem_alloc)) {
anv_batch_set_error(&cmd_buffer->batch, VK_ERROR_OUT_OF_DEVICE_MEMORY);
goto error;
}
cmd_buffer->state.rt.build_priv_mem_addr = private_mem_alloc.address;
cmd_buffer->state.rt.build_priv_mem_size = private_mem_alloc.size;
} else {
private_mem_alloc = (struct anv_cmd_alloc) {
.address = cmd_buffer->state.rt.build_priv_mem_addr,
.map = anv_address_map(cmd_buffer->state.rt.build_priv_mem_addr),
.size = cmd_buffer->state.rt.build_priv_mem_size,
};
}
struct anv_cmd_alloc transient_mem_alloc =
anv_cmd_buffer_alloc_space(cmd_buffer, transient_total, 64);
if (transient_total > 0 && anv_cmd_alloc_is_empty(transient_mem_alloc)) {