freedreno/ir3: Fix sizing of the inputs/outputs array.
authorEric Anholt <eric@anholt.net>
Tue, 21 Apr 2020 22:43:03 +0000 (15:43 -0700)
committerMarge Bot <eric+marge@anholt.net>
Thu, 23 Apr 2020 18:52:46 +0000 (18:52 +0000)
If you have a struct, the var's base driver location is not the last
driver location that will be accessed in that var.  We have a shader
struct member with this number for us, already.  Fixes overflows in:

dEQP-GLES31.functional.program_interface_query.program_output.type.interface_blocks.out.named_block_explicit_location.struct.mat3x2

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4670>

src/freedreno/ir3/ir3_compiler_nir.c

index fad611c9b5f7d734461db6c4ae2bc735e50ae6e3..553b772b8ec1b04e8a3f71331ffdc1cf55734fed 100644 (file)
@@ -3236,24 +3236,13 @@ setup_output(struct ir3_context *ctx, nir_variable *out)
        }
 }
 
-static int
-max_drvloc(struct exec_list *vars)
-{
-       int drvloc = -1;
-       nir_foreach_variable (var, vars) {
-               drvloc = MAX2(drvloc, (int)var->data.driver_location);
-       }
-       return drvloc;
-}
-
 static void
 emit_instructions(struct ir3_context *ctx)
 {
        nir_function_impl *fxn = nir_shader_get_entrypoint(ctx->s);
 
-       ctx->ninputs  = (max_drvloc(&ctx->s->inputs) + 1) * 4;
-       ctx->noutputs = (max_drvloc(&ctx->s->outputs) + 1) * 4;
-
+       ctx->ninputs = ctx->s->num_inputs * 4;
+       ctx->noutputs = ctx->s->num_outputs * 4;
        ctx->inputs  = rzalloc_array(ctx, struct ir3_instruction *, ctx->ninputs);
        ctx->outputs = rzalloc_array(ctx, struct ir3_instruction *, ctx->noutputs);