radeon/llvm: don't use a static array size for radeon_llvm_context::arrays (v2)
authorMarek Olšák <marek.olsak@amd.com>
Tue, 26 May 2015 13:35:10 +0000 (15:35 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 29 May 2015 09:52:44 +0000 (11:52 +0200)
v2: - don't use realloc (tgsi_shader_info provides the size)

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/drivers/radeon/radeon_llvm.h
src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c

index 8612ef8daf75bc92e8ac5e483e6d2f34ae68c71e..6a9557b0b734e4a95b7730cc0bd16d4acfda465f 100644 (file)
@@ -33,7 +33,6 @@
 
 #define RADEON_LLVM_MAX_INPUTS 32 * 4
 #define RADEON_LLVM_MAX_OUTPUTS 32 * 4
-#define RADEON_LLVM_MAX_ARRAYS 16
 
 #define RADEON_LLVM_INITIAL_CF_DEPTH 4
 
@@ -130,8 +129,7 @@ struct radeon_llvm_context {
        unsigned loop_depth;
        unsigned loop_depth_max;
 
-       struct tgsi_declaration_range arrays[RADEON_LLVM_MAX_ARRAYS];
-       unsigned num_arrays;
+       struct tgsi_declaration_range *arrays;
 
        LLVMValueRef main_fn;
 
index 863853751765ef76689da5b8cb7db60ef2a80b87..49836672dce84265289193c3b56be1cca9da169a 100644 (file)
@@ -85,8 +85,9 @@ get_array_range(struct lp_build_tgsi_context *bld_base,
                unsigned File, const struct tgsi_ind_register *reg)
 {
        struct radeon_llvm_context * ctx = radeon_llvm_context(bld_base);
+
        if (File != TGSI_FILE_TEMPORARY || reg->ArrayID == 0 ||
-            reg->ArrayID > RADEON_LLVM_MAX_ARRAYS) {
+           reg->ArrayID > bld_base->info->array_max[TGSI_FILE_TEMPORARY]) {
                struct tgsi_declaration_range range;
                range.First = 0;
                range.Last = bld_base->info->file_max[File];
@@ -252,8 +253,14 @@ static void emit_declaration(
        }
 
        case TGSI_FILE_TEMPORARY:
-               if (decl->Declaration.Array && decl->Array.ArrayID <= RADEON_LLVM_MAX_ARRAYS)
+               if (decl->Declaration.Array) {
+                       if (!ctx->arrays) {
+                               int size = bld_base->info->array_max[TGSI_FILE_TEMPORARY];
+                               ctx->arrays = MALLOC(sizeof(ctx->arrays[0]) * size);
+                       }
+
                        ctx->arrays[decl->Array.ArrayID - 1] = decl->Range;
+               }
                if (uses_temp_indirect_addressing(bld_base)) {
                        lp_emit_declaration_soa(bld_base, decl);
                        break;
@@ -1432,8 +1439,6 @@ void radeon_llvm_context_init(struct radeon_llvm_context * ctx)
        /* Allocate outputs */
        ctx->soa.outputs = ctx->outputs;
 
-       ctx->num_arrays = 0;
-
        /* XXX: Is there a better way to initialize all this ? */
 
        lp_set_default_actions(bld_base);
@@ -1622,6 +1627,8 @@ void radeon_llvm_dispose(struct radeon_llvm_context * ctx)
 {
        LLVMDisposeModule(ctx->soa.bld_base.base.gallivm->module);
        LLVMContextDispose(ctx->soa.bld_base.base.gallivm->context);
+       FREE(ctx->arrays);
+       ctx->arrays = NULL;
        FREE(ctx->temps);
        ctx->temps = NULL;
        FREE(ctx->loop);