radeonsi: allocate and resize global_buffers as needed
authorMarek Olšák <marek.olsak@amd.com>
Mon, 12 Aug 2019 17:50:00 +0000 (13:50 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 19 Aug 2019 21:23:38 +0000 (17:23 -0400)
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
src/gallium/drivers/radeonsi/si_compute.c
src/gallium/drivers/radeonsi/si_compute.h

index 624b99022cd771e8a2e6f57f4ffe01415cf1536b..ad211ec0a41534365220fbc8cdea9a98c4e1a660 100644 (file)
@@ -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);
index 86021178533a5bc66c3c581d489fe3358ff6d480..5e2883d9e8370b0ec51ac4962aabb0d7ea85cc4a 100644 (file)
@@ -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;
 };