vc4: Switch store_output to using nir_lower_io_to_scalar / component.
authorEric Anholt <eric@anholt.net>
Fri, 5 Aug 2016 00:31:02 +0000 (17:31 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 19 Aug 2016 20:11:36 +0000 (13:11 -0700)
src/gallium/drivers/vc4/vc4_nir_lower_io.c
src/gallium/drivers/vc4/vc4_program.c

index ad96ef5ad82880946a6e0139bcabd87d413a7791..3d08b64812584238bb22446470ee49135a37ee37 100644 (file)
@@ -29,9 +29,9 @@
  * Walks the NIR generated by TGSI-to-NIR to lower its io intrinsics into
  * something amenable to the VC4 architecture.
  *
- * Currently, it splits outputs, VS inputs, and uniforms into scalars, drops
- * any non-position outputs in coordinate shaders, and fixes up the addressing
- * on indirect uniform loads.  FS input scalarization is handled by
+ * Currently, it splits VS inputs and uniforms into scalars, drops any
+ * non-position outputs in coordinate shaders, and fixes up the addressing on
+ * indirect uniform loads.  FS input and VS output scalarization is handled by
  * nir_lower_io_to_scalar().
  */
 
@@ -319,42 +319,6 @@ vc4_nir_lower_output(struct vc4_compile *c, nir_builder *b,
                 nir_instr_remove(&intr->instr);
                 return;
         }
-
-        /* Color output is lowered by vc4_nir_lower_blend(). */
-        if (c->stage == QSTAGE_FRAG &&
-            (output_var->data.location == FRAG_RESULT_COLOR ||
-             output_var->data.location == FRAG_RESULT_DATA0 ||
-             output_var->data.location == FRAG_RESULT_SAMPLE_MASK)) {
-                nir_intrinsic_set_base(intr, nir_intrinsic_base(intr) * 4);
-                return;
-        }
-
-        /* All TGSI-to-NIR outputs are VEC4. */
-        assert(intr->num_components == 4);
-
-        /* We only accept direct outputs and TGSI only ever gives them to us
-         * with an offset value of 0.
-         */
-        assert(nir_src_as_const_value(intr->src[1]) &&
-               nir_src_as_const_value(intr->src[1])->u32[0] == 0);
-
-        b->cursor = nir_before_instr(&intr->instr);
-
-        for (unsigned i = 0; i < intr->num_components; i++) {
-                nir_intrinsic_instr *intr_comp =
-                        nir_intrinsic_instr_create(c->s, nir_intrinsic_store_output);
-                intr_comp->num_components = 1;
-                nir_intrinsic_set_base(intr_comp,
-                                       nir_intrinsic_base(intr) * 4 + i);
-
-                assert(intr->src[0].is_ssa);
-                intr_comp->src[0] =
-                        nir_src_for_ssa(nir_channel(b, intr->src[0].ssa, i));
-                intr_comp->src[1] = nir_src_for_ssa(nir_imm_int(b, 0));
-                nir_builder_instr_insert(b, &intr_comp->instr);
-        }
-
-        nir_instr_remove(&intr->instr);
 }
 
 static void
index 454202753a5d6862ebffc59772716a0021842790..5acb7a75919d6aceef37f77c8fc3bbc910a9d6c2 100644 (file)
@@ -1652,6 +1652,7 @@ ntq_emit_intrinsic(struct vc4_compile *c, nir_intrinsic_instr *instr)
                                                                i));
                         }
                 } else {
+                        offset = offset * 4 + nir_intrinsic_component(instr);
                         assert(instr->num_components == 1);
                         c->outputs[offset] =
                                 qir_MOV(c, ntq_get_src(c, instr->src[0], 0));
@@ -2063,17 +2064,24 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage,
         if (c->vs_key && c->vs_key->clamp_color)
                 NIR_PASS_V(c->s, nir_lower_clamp_color_outputs);
 
-        if (stage == QSTAGE_FRAG) {
-                NIR_PASS_V(c->s, nir_lower_clip_fs, c->key->ucp_enables);
-        } else {
-                NIR_PASS_V(c->s, nir_lower_clip_vs, c->key->ucp_enables);
+        if (c->key->ucp_enables) {
+                if (stage == QSTAGE_FRAG) {
+                        NIR_PASS_V(c->s, nir_lower_clip_fs, c->key->ucp_enables);
+                } else {
+                        NIR_PASS_V(c->s, nir_lower_clip_vs, c->key->ucp_enables);
+                        NIR_PASS_V(c->s, nir_lower_io_to_scalar,
+                                   nir_var_shader_out);
+                }
         }
 
         /* FS input scalarizing must happen after nir_lower_two_sided_color,
-         * which only handles a vec4 at a time.
+         * which only handles a vec4 at a time.  Similarly, VS output
+         * scalarizing must happen after nir_lower_clip_vs.
          */
         if (c->stage == QSTAGE_FRAG)
                 NIR_PASS_V(c->s, nir_lower_io_to_scalar, nir_var_shader_in);
+        else
+                NIR_PASS_V(c->s, nir_lower_io_to_scalar, nir_var_shader_out);
 
         NIR_PASS_V(c->s, vc4_nir_lower_io, c);
         NIR_PASS_V(c->s, vc4_nir_lower_txf_ms, c);