ttn: Make FRAG_RESULT_DEPTH be a float variable to match gtn and ptn.
authorEric Anholt <eric@anholt.net>
Tue, 26 Jul 2016 23:19:15 +0000 (16:19 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 19 Aug 2016 20:11:36 +0000 (13:11 -0700)
This lets TTN-using drivers handle FRAG_RESULT_DEPTH the same between all
their source paths.

Reviewed-by: Rob Clark <robdclark@gmail.com>
src/gallium/auxiliary/nir/tgsi_to_nir.c
src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
src/gallium/drivers/freedreno/ir3/ir3_shader.c
src/gallium/drivers/vc4/vc4_program.c

index 65eca6f9e864c0e9fd10990070afa9b6a0088067..3d80ef06f13dd84b6f2db72904e7bc20103e0ec8 100644 (file)
@@ -1918,9 +1918,22 @@ ttn_add_output_stores(struct ttn_compile *c)
          nir_intrinsic_instr *store =
             nir_intrinsic_instr_create(b->shader, nir_intrinsic_store_output);
          unsigned loc = var->data.driver_location + i;
-         store->num_components = 4;
-         store->src[0].reg.reg = c->output_regs[loc].reg;
-         store->src[0].reg.base_offset = c->output_regs[loc].offset;
+
+         nir_src src = nir_src_for_reg(c->output_regs[loc].reg);
+         src.reg.base_offset = c->output_regs[loc].offset;
+
+         if (c->build.shader->stage == MESA_SHADER_FRAGMENT &&
+             var->data.location == FRAG_RESULT_DEPTH) {
+            /* TGSI uses TGSI_SEMANTIC_POSITION.z for the depth output, while
+             * NIR uses a single float FRAG_RESULT_DEPTH.
+             */
+            src = nir_src_for_ssa(nir_channel(b, nir_ssa_for_src(b, src, 4), 2));
+            store->num_components = 1;
+         } else {
+            store->num_components = 4;
+         }
+         store->src[0] = src;
+
          nir_intrinsic_set_base(store, loc);
          nir_intrinsic_set_write_mask(store, 0xf);
          store->src[1] = nir_src_for_ssa(nir_imm_int(b, 0));
index 2331901ceba26fd59f91b22aec448774606c563d..63235663ffe36063ad554779b25252580cbbe872 100644 (file)
@@ -2498,12 +2498,6 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
        /* fixup input/outputs: */
        for (i = 0; i < so->outputs_count; i++) {
                so->outputs[i].regid = ir->outputs[i*4]->regs[0]->num;
-               /* preserve hack for depth output.. tgsi writes depth to .z,
-                * but what we give the hw is the scalar register:
-                */
-               if (so->shader->from_tgsi && (so->type == SHADER_FRAGMENT) &&
-                               (so->outputs[i].slot == FRAG_RESULT_DEPTH))
-                       so->outputs[i].regid += 2;
        }
 
        /* Note that some or all channels of an input may be unused: */
index 87bdcf91a674e6094175caa78ee5de58eadbfacf..ac48132026c43d044799de75ee3565b3fa031f25 100644 (file)
@@ -294,7 +294,6 @@ ir3_shader_create(struct ir3_compiler *compiler,
                        tgsi_dump(cso->tokens, 0);
                }
                nir = ir3_tgsi_to_nir(cso->tokens);
-               shader->from_tgsi = true;
        }
        /* do first pass optimization, ignoring the key: */
        shader->nir = ir3_optimize_nir(shader, nir, NULL);
index 030643a1ca25ce2f117a99fa29a2a484158ba378..33721f16c72d06db16e420d1b4c48d255ce6f8da 100644 (file)
@@ -1223,7 +1223,7 @@ emit_frag_end(struct vc4_compile *c)
                 if (c->output_position_index != -1) {
                         qir_FTOI_dest(c, qir_reg(QFILE_TLB_Z_WRITE, 0),
                                       qir_FMUL(c,
-                                               c->outputs[c->output_position_index + 2],
+                                               c->outputs[c->output_position_index],
                                                qir_uniform_f(c, 0xffffff)))->cond = discard_cond;
                 } else {
                         qir_MOV_dest(c, qir_reg(QFILE_TLB_Z_WRITE, 0),