From: Marek Olšák Date: Mon, 12 Aug 2019 17:50:00 +0000 (-0400) Subject: radeonsi: allocate and resize global_buffers as needed X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=43f8b5642b14f77c4028c72e685e61feba29a3d4;p=mesa.git radeonsi: allocate and resize global_buffers as needed Reviewed-by: Pierre-Eric Pelloux-Prayer --- diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c index 624b99022cd..ad211ec0a41 100644 --- a/src/gallium/drivers/radeonsi/si_compute.c +++ b/src/gallium/drivers/radeonsi/si_compute.c @@ -318,7 +318,22 @@ static void si_set_global_binding( struct si_context *sctx = (struct si_context*)ctx; struct si_compute *program = sctx->cs_shader_state.program; - assert(first + n <= MAX_GLOBAL_BUFFERS); + if (first + n > program->max_global_buffers) { + unsigned old_max = program->max_global_buffers; + program->max_global_buffers = first + n; + program->global_buffers = + realloc(program->global_buffers, + program->max_global_buffers * + sizeof(program->global_buffers[0])); + if (!program->global_buffers) { + fprintf(stderr, "radeonsi: failed to allocate compute global_buffers\n"); + return; + } + + memset(&program->global_buffers[old_max], 0, + (program->max_global_buffers - old_max) * + sizeof(program->global_buffers[0])); + } if (!resources) { for (i = 0; i < n; i++) { @@ -912,7 +927,7 @@ static void si_launch_grid( return; /* Global buffers */ - for (i = 0; i < MAX_GLOBAL_BUFFERS; i++) { + for (i = 0; i < program->max_global_buffers; i++) { struct si_resource *buffer = si_resource(program->global_buffers[i]); if (!buffer) { @@ -952,6 +967,10 @@ void si_destroy_compute(struct si_compute *program) util_queue_fence_destroy(&sel->ready); } + for (unsigned i = 0; i < program->max_global_buffers; i++) + pipe_resource_reference(&program->global_buffers[i], NULL); + FREE(program->global_buffers); + si_shader_destroy(&program->shader); ralloc_free(program->sel.nir); FREE(program); diff --git a/src/gallium/drivers/radeonsi/si_compute.h b/src/gallium/drivers/radeonsi/si_compute.h index 86021178533..5e2883d9e83 100644 --- a/src/gallium/drivers/radeonsi/si_compute.h +++ b/src/gallium/drivers/radeonsi/si_compute.h @@ -29,8 +29,6 @@ #include "si_shader.h" -#define MAX_GLOBAL_BUFFERS 32 - struct si_compute { struct si_shader_selector sel; struct si_shader shader; @@ -40,7 +38,9 @@ struct si_compute { unsigned private_size; unsigned input_size; - struct pipe_resource *global_buffers[MAX_GLOBAL_BUFFERS]; + int max_global_buffers; + struct pipe_resource **global_buffers; + bool reads_variable_block_size; unsigned num_cs_user_data_dwords; };