freedreno/ir3: ignore unused inputs
authorRob Clark <robdclark@gmail.com>
Tue, 21 Aug 2018 12:33:39 +0000 (08:33 -0400)
committerRob Clark <robdclark@gmail.com>
Wed, 5 Sep 2018 17:38:43 +0000 (13:38 -0400)
We could end up w/ inputs larger than vec4, simply because unused inputs
are not split.

Fixes things like dEQP-GLES31.functional.separate_shader.random.77 (and
probably a handful of others)

Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c

index e4979a60a02b24b5e9a7dfb245423a6c13e4741b..005e043a63b84f56771e70dafa125050c0e2df9e 100644 (file)
@@ -3233,6 +3233,25 @@ create_frag_coord(struct ir3_context *ctx, unsigned comp)
        }
 }
 
+static uint64_t
+input_bitmask(struct ir3_context *ctx, nir_variable *in)
+{
+       unsigned ncomp = glsl_get_components(in->type);
+       unsigned slot = in->data.location;
+
+       /* let's pretend things other than vec4 don't exist: */
+       ncomp = MAX2(ncomp, 4);
+
+       if (ctx->so->type == SHADER_FRAGMENT) {
+               /* see st_nir_fixup_varying_slots(): */
+               if (slot >= VARYING_SLOT_VAR9)
+                       slot -= 9;
+       }
+
+       /* Note that info.inputs_read is in units of vec4 slots: */
+       return ((1ull << (ncomp/4)) - 1) << slot;
+}
+
 static void
 setup_input(struct ir3_context *ctx, nir_variable *in)
 {
@@ -3247,6 +3266,15 @@ setup_input(struct ir3_context *ctx, nir_variable *in)
 
        /* let's pretend things other than vec4 don't exist: */
        ncomp = MAX2(ncomp, 4);
+
+       /* skip unread inputs, we could end up with (for example), unsplit
+        * matrix/etc inputs in the case they are not read, so just silently
+        * skip these.
+        *
+        */
+       if (!(ctx->s->info.inputs_read & input_bitmask(ctx, in)))
+               return;
+
        compile_assert(ctx, ncomp == 4);
 
        so->inputs[n].slot = slot;
@@ -3264,7 +3292,7 @@ setup_input(struct ir3_context *ctx, nir_variable *in)
                                so->frag_coord = true;
                                instr = create_frag_coord(ctx, i);
                        } else if (slot == VARYING_SLOT_PNTC) {
-                               /* see for example st_get_generic_varying_index().. this is
+                               /* see for example st_nir_fixup_varying_slots().. this is
                                 * maybe a bit mesa/st specific.  But we need things to line
                                 * up for this in fdN_program:
                                 *    unsigned texmask = 1 << (slot - VARYING_SLOT_VAR0);