vc4: Allow dead code elimination of unused varyings.
authorEric Anholt <eric@anholt.net>
Fri, 24 Oct 2014 14:03:04 +0000 (15:03 +0100)
committerEric Anholt <eric@anholt.net>
Fri, 24 Oct 2014 17:04:26 +0000 (18:04 +0100)
total instructions in shared programs: 39022 -> 37341 (-4.31%)
instructions in affected programs:     26979 -> 25298 (-6.23%)
total uniforms in shared programs: 11242 -> 10523 (-6.40%)
uniforms in affected programs:     5836 -> 5117 (-12.32%)

src/gallium/drivers/vc4/vc4_opt_cse.c
src/gallium/drivers/vc4/vc4_opt_dead_code.c
src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qir.c
src/gallium/drivers/vc4/vc4_qir.h

index d3ef91083c61322d962d7dac33f182001a420c15..bebfb6526def64c5a6b3d1e8eb996019fd19bf3f 100644 (file)
@@ -132,7 +132,7 @@ qir_opt_cse(struct vc4_compile *c)
         foreach_s(node, t, &c->instructions) {
                 struct qinst *inst = (struct qinst *)node;
 
-                if (qir_has_side_effects(inst)) {
+                if (qir_has_side_effects(c, inst)) {
                         if (inst->op == QOP_TLB_DISCARD_SETUP)
                                 last_sf = NULL;
                         continue;
index f08818adc95c5fe498c923123214a88359433fb9..d958dcb1075063db45a4d2530c9e6fcacee5148f 100644 (file)
@@ -63,7 +63,7 @@ qir_opt_dead_code(struct vc4_compile *c)
 
                 if (inst->dst.file == QFILE_TEMP &&
                     !used[inst->dst.index] &&
-                    (!qir_has_side_effects(inst) ||
+                    (!qir_has_side_effects(c, inst) ||
                      inst->op == QOP_TEX_RESULT)) {
                         if (inst->op == QOP_TEX_RESULT) {
                                 dce_tex = true;
index 01941f88428ff58623a3b00864f7690967220995..0674e4fd01a95fdba948cc0a8863ae4160ee81eb 100644 (file)
@@ -2018,6 +2018,18 @@ vc4_get_compiled_shader(struct vc4_context *vc4, enum qstage stage,
 
         shader->program_id = vc4->next_compiled_program_id++;
         if (stage == QSTAGE_FRAG) {
+                bool input_live[c->num_input_semantics];
+                struct simple_node *node;
+
+                memset(input_live, 0, sizeof(input_live));
+                foreach(node, &c->instructions) {
+                        struct qinst *inst = (struct qinst *)node;
+                        for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
+                                if (inst->src[i].file == QFILE_VARY)
+                                        input_live[inst->src[i].index] = true;
+                        }
+                }
+
                 shader->input_semantics = ralloc_array(shader,
                                                        struct vc4_varying_semantic,
                                                        c->num_input_semantics);
@@ -2025,6 +2037,9 @@ vc4_get_compiled_shader(struct vc4_context *vc4, enum qstage stage,
                 for (int i = 0; i < c->num_input_semantics; i++) {
                         struct vc4_varying_semantic *sem = &c->input_semantics[i];
 
+                        if (!input_live[i])
+                                continue;
+
                         /* Skip non-VS-output inputs. */
                         if (sem->semantic == (uint8_t)~0)
                                 continue;
index 9c7c15e4924e7de7ca138ae8b138d8576a3b22aa..a7a4d96f7585eef6c5d75cfb7efab932efd1e322 100644 (file)
@@ -122,12 +122,23 @@ qir_get_op_nsrc(enum qop qop)
                 abort();
 }
 
+/**
+ * Returns whether the instruction has any side effects that must be
+ * preserved.
+ */
 bool
-qir_has_side_effects(struct qinst *inst)
+qir_has_side_effects(struct vc4_compile *c, struct qinst *inst)
 {
+        /* We can dead-code eliminate varyings, because we only tell the VS
+         * about the live ones at the end.  But we have to preserve the
+         * point/line coordinates reads, because they're generated by
+         * fixed-function hardware.
+         */
         for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
-                if (inst->src[i].file == QFILE_VARY)
+                if (inst->src[i].file == QFILE_VARY &&
+                    c->input_semantics[inst->src[i].index].semantic == 0xff) {
                         return true;
+                }
         }
 
         return qir_op_info[inst->op].has_side_effects;
index c2f83a7e92378dc0e86639085bee724ab01c276f..077a55ad6fcc05953188dea59fb1aeba38c5eae2 100644 (file)
@@ -309,7 +309,7 @@ void qir_emit(struct vc4_compile *c, struct qinst *inst);
 struct qreg qir_get_temp(struct vc4_compile *c);
 int qir_get_op_nsrc(enum qop qop);
 bool qir_reg_equals(struct qreg a, struct qreg b);
-bool qir_has_side_effects(struct qinst *inst);
+bool qir_has_side_effects(struct vc4_compile *c, struct qinst *inst);
 bool qir_depends_on_flags(struct qinst *inst);
 bool qir_writes_r4(struct qinst *inst);
 bool qir_reads_r4(struct qinst *inst);