freedreno/ir3: make input/output iterators declare cursor ptr
[mesa.git] / src / freedreno / ir3 / ir3_compiler_nir.c
index 4dff42c824681267849b19723ddd9f4def88f43f..b3e23db243ede0c4b6050481d1ed1dfe950a9536 100644 (file)
@@ -2963,7 +2963,7 @@ setup_input(struct ir3_context *ctx, nir_variable *in)
                        ctx->inputs[idx] = instr;
                }
        } else if (ctx->so->type == MESA_SHADER_VERTEX) {
-               struct ir3_instruction *input = NULL, *in;
+               struct ir3_instruction *input = NULL;
                struct ir3_instruction *components[4];
                unsigned mask = (1 << (ncomp + frac)) - 1;
 
@@ -3362,7 +3362,6 @@ fixup_binning_pass(struct ir3_context *ctx)
                        so->outputs[j] = so->outputs[i];
 
                        /* fixup outidx to point to new output table entry: */
-                       struct ir3_instruction *out;
                        foreach_output (out, ir) {
                                if (out->collect.outidx == i) {
                                        out->collect.outidx = j;
@@ -3426,6 +3425,7 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
        struct ir3_context *ctx;
        struct ir3 *ir;
        int ret = 0, max_bary;
+       bool progress;
 
        assert(!so->ir);
 
@@ -3522,28 +3522,6 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
                }
        }
 
-       /* at this point, for binning pass, throw away unneeded outputs: */
-       if (so->binning_pass && (ctx->compiler->gpu_id < 600))
-               fixup_binning_pass(ctx);
-
-       ir3_debug_print(ir, "AFTER: nir->ir3");
-
-       ir3_cf(ir);
-
-       ir3_debug_print(ir, "AFTER: ir3_cf");
-
-       ir3_cp(ir, so);
-
-       ir3_debug_print(ir, "AFTER: ir3_cp");
-
-       /* at this point, for binning pass, throw away unneeded outputs:
-        * Note that for a6xx and later, we do this after ir3_cp to ensure
-        * that the uniform/constant layout for BS and VS matches, so that
-        * we can re-use same VS_CONST state group.
-        */
-       if (so->binning_pass && (ctx->compiler->gpu_id >= 600))
-               fixup_binning_pass(ctx);
-
        /* for a6xx+, binning and draw pass VS use same VBO state, so we
         * need to make sure not to remove any inputs that are used by
         * the nonbinning VS.
@@ -3570,21 +3548,40 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
                }
        }
 
+       /* at this point, for binning pass, throw away unneeded outputs: */
+       if (so->binning_pass && (ctx->compiler->gpu_id < 600))
+               fixup_binning_pass(ctx);
+
+       ir3_debug_print(ir, "AFTER: nir->ir3");
 
-       ir3_sched_add_deps(ir);
+       do {
+               progress = false;
 
-       ir3_debug_print(ir, "AFTER: ir3_sched_add_deps");
+               progress |= IR3_PASS(ir, ir3_cf);
+               progress |= IR3_PASS(ir, ir3_cp, so);
+               progress |= IR3_PASS(ir, ir3_dce, so);
+       } while (progress);
 
-       /* Group left/right neighbors, inserting mov's where needed to
-        * solve conflicts:
+       /* at this point, for binning pass, throw away unneeded outputs:
+        * Note that for a6xx and later, we do this after ir3_cp to ensure
+        * that the uniform/constant layout for BS and VS matches, so that
+        * we can re-use same VS_CONST state group.
         */
-       ir3_group(ir);
+       if (so->binning_pass && (ctx->compiler->gpu_id >= 600)) {
+               fixup_binning_pass(ctx);
+               /* cleanup the result of removing unneeded outputs: */
+               while (IR3_PASS(ir, ir3_dce, so)) {}
+       }
 
-       ir3_debug_print(ir, "AFTER: ir3_group");
+       IR3_PASS(ir, ir3_sched_add_deps);
 
-       ir3_dce(ir, so);
+       /* Group left/right neighbors, inserting mov's where needed to
+        * solve conflicts:
+        */
+       IR3_PASS(ir, ir3_group);
 
-       ir3_debug_print(ir, "AFTER: ir3_dce");
+       /* At this point, all the dead code should be long gone: */
+       assert(!IR3_PASS(ir, ir3_dce, so));
 
        ret = ir3_sched(ir);
        if (ret) {
@@ -3640,7 +3637,7 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
                ret = ir3_ra(so, precolor, ARRAY_SIZE(precolor));
        } else if (so->num_sampler_prefetch) {
                assert(so->type == MESA_SHADER_FRAGMENT);
-               struct ir3_instruction *instr, *precolor[2];
+               struct ir3_instruction *precolor[2];
                int idx = 0;
 
                foreach_input (instr, ir) {
@@ -3664,13 +3661,10 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
                goto out;
        }
 
-       ir3_postsched(ctx);
-       ir3_debug_print(ir, "AFTER: ir3_postsched");
+       IR3_PASS(ir, ir3_postsched);
 
        if (compiler->gpu_id >= 600) {
-               if (ir3_a6xx_fixup_atomic_dests(ir, so)) {
-                       ir3_debug_print(ir, "AFTER: ir3_a6xx_fixup_atomic_dests");
-               }
+               IR3_PASS(ir, ir3_a6xx_fixup_atomic_dests, so);
        }
 
        if (so->type == MESA_SHADER_FRAGMENT)
@@ -3690,7 +3684,6 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
        for (unsigned i = 0; i < so->outputs_count; i++)
                so->outputs[i].regid = INVALID_REG;
 
-       struct ir3_instruction *out;
        foreach_output (out, ir) {
                assert(out->opc == OPC_META_COLLECT);
                unsigned outidx = out->collect.outidx;
@@ -3699,7 +3692,6 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
                so->outputs[outidx].half  = !!(out->regs[0]->flags & IR3_REG_HALF);
        }
 
-       struct ir3_instruction *in;
        foreach_input (in, ir) {
                assert(in->opc == OPC_META_INPUT);
                unsigned inidx = in->input.inidx;
@@ -3725,9 +3717,7 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
        /* We need to do legalize after (for frag shader's) the "bary.f"
         * offsets (inloc) have been assigned.
         */
-       ir3_legalize(ir, so, &max_bary);
-
-       ir3_debug_print(ir, "AFTER: ir3_legalize");
+       IR3_PASS(ir, ir3_legalize, so, &max_bary);
 
        /* Set (ss)(sy) on first TCS and GEOMETRY instructions, since we don't
         * know what we might have to wait on when coming in from VS chsh.