etnaviv: use nir_lower_clip_halfz instead of open-coding
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Sun, 15 Dec 2019 17:09:46 +0000 (18:09 +0100)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 3 Jan 2020 22:48:19 +0000 (22:48 +0000)
We already have a helper for this, so let's use that instead of rolling
our own version.

Reviewed-by: Jonathan Marek <jonathan@marek.ca>
Tested-by: Paul Cercueil <paul@crapouillou.net>
src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c

index c481b8904567565e18ff5892860b0d4231fd9873..7934eb0490e6fd371ca39f6a097a898fcb3a8919 100644 (file)
@@ -97,26 +97,6 @@ etna_lower_io(nir_shader *shader, struct etna_shader_variant *v)
                } break;
                case nir_intrinsic_store_deref: {
                   nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
-                  if (shader->info.stage == MESA_SHADER_VERTEX &&
-                      v->shader->specs->vs_need_z_div &&
-                      deref->var->data.location == VARYING_SLOT_POS) {
-
-                     assert(deref->deref_type == nir_deref_type_var);
-
-                     b.cursor = nir_before_instr(instr);
-
-                     nir_ssa_def *out[4];
-                     out[0] = nir_channel(&b, intr->src[1].ssa, 0);
-                     out[1] = nir_channel(&b, intr->src[1].ssa, 1);
-                     out[2] = nir_fmul_imm(&b, nir_fadd(&b, nir_channel(&b, intr->src[1].ssa, 2),
-                                                        nir_channel(&b, intr->src[1].ssa, 3)),
-                                           0.5f);
-                     out[3] = nir_channel(&b, intr->src[1].ssa, 3);
-
-                     nir_instr_rewrite_src(instr, &intr->src[1],
-                                           nir_src_for_ssa(nir_vec(&b, out, 4)));
-                  }
-
                   if (shader->info.stage != MESA_SHADER_FRAGMENT || !v->key.frag_rb_swap)
                      break;
 
@@ -773,6 +753,9 @@ etna_compile_shader_nir(struct etna_shader_variant *v)
 
    OPT_V(s, etna_lower_io, v);
 
+   if (v->shader->specs->vs_need_z_div)
+      NIR_PASS_V(s, nir_lower_clip_halfz);
+
    /* lower pre-halti2 to float (halti0 has integers, but only scalar..) */
    if (c->specs->halti < 2) {
       /* use opt_algebraic between int_to_float and boot_to_float because