nir: fix lower_wpos_ytransform in load_frag_coord case
authorRob Clark <robdclark@chromium.org>
Fri, 26 Apr 2019 18:39:42 +0000 (11:39 -0700)
committerRob Clark <robdclark@chromium.org>
Thu, 2 May 2019 18:19:22 +0000 (11:19 -0700)
Apparently we never hit this path.  Or at least haven't for a rather
long time.  But in either case (load_deref or load_frag_coord), we can
just directly use the intrinsic's ssa dest.  So stop passing the
nir_variable (which would be NULL in the load_frag_coord case) around
and instead just use &intr->dest.ssa.

(This ofc means we need to setup the cursor to insert *after* the
instruction, which seems to be another bug of the original
implementation.)

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
src/compiler/nir/nir_lower_wpos_ytransform.c

index 34a4801d66b9c172fbc0eced80deba41a7c63edf..d0a694f889b955027c56ff41e163099a2e442a98 100644 (file)
@@ -77,18 +77,18 @@ nir_cmp(nir_builder *b, nir_ssa_def *src0, nir_ssa_def *src1, nir_ssa_def *src2)
 /* see emit_wpos_adjustment() in st_mesa_to_tgsi.c */
 static void
 emit_wpos_adjustment(lower_wpos_ytransform_state *state,
-                     nir_intrinsic_instr *intr, nir_variable *fragcoord,
-                     bool invert, float adjX, float adjY[2])
+                     nir_intrinsic_instr *intr, bool invert,
+                     float adjX, float adjY[2])
 {
    nir_builder *b = &state->b;
    nir_ssa_def *wpostrans, *wpos_temp, *wpos_temp_y, *wpos_input;
 
    assert(intr->dest.is_ssa);
+   wpos_input = &intr->dest.ssa;
 
-   b->cursor = nir_before_instr(&intr->instr);
+   b->cursor = nir_after_instr(&intr->instr);
 
    wpostrans = get_transform(state);
-   wpos_input = nir_load_var(b, fragcoord);
 
    /* First, apply the coordinate shift: */
    if (adjX || adjY[0] || adjY[1]) {
@@ -139,12 +139,13 @@ emit_wpos_adjustment(lower_wpos_ytransform_state *state,
                         nir_channel(b, wpos_temp, 2),
                         nir_channel(b, wpos_temp, 3));
 
-   nir_ssa_def_rewrite_uses(&intr->dest.ssa, nir_src_for_ssa(wpos_temp));
+   nir_ssa_def_rewrite_uses_after(&intr->dest.ssa,
+                                  nir_src_for_ssa(wpos_temp),
+                                  wpos_temp->parent_instr);
 }
 
 static void
-lower_fragcoord(lower_wpos_ytransform_state *state,
-                nir_intrinsic_instr *intr, nir_variable *fragcoord)
+lower_fragcoord(lower_wpos_ytransform_state *state, nir_intrinsic_instr *intr)
 {
    const nir_lower_wpos_ytransform_options *options = state->options;
    float adjX = 0.0f;
@@ -228,7 +229,7 @@ lower_fragcoord(lower_wpos_ytransform_state *state,
       }
    }
 
-   emit_wpos_adjustment(state, intr, fragcoord, invert, adjX, adjY);
+   emit_wpos_adjustment(state, intr, invert, adjX, adjY);
 }
 
 static void
@@ -331,7 +332,7 @@ lower_wpos_ytransform_block(lower_wpos_ytransform_state *state, nir_block *block
                 (var->data.mode == nir_var_system_value &&
                  var->data.location == SYSTEM_VALUE_FRAG_COORD)) {
                /* gl_FragCoord should not have array/struct derefs: */
-               lower_fragcoord(state, intr, var);
+               lower_fragcoord(state, intr);
             } else if (var->data.mode == nir_var_system_value &&
                        var->data.location == SYSTEM_VALUE_SAMPLE_POS) {
                lower_load_sample_pos(state, intr);
@@ -341,7 +342,7 @@ lower_wpos_ytransform_block(lower_wpos_ytransform_state *state, nir_block *block
                lower_load_pointcoord(state, intr);
             }
          } else if (intr->intrinsic == nir_intrinsic_load_frag_coord) {
-            lower_fragcoord(state, intr, NULL);
+            lower_fragcoord(state, intr);
          } else if (intr->intrinsic == nir_intrinsic_load_sample_pos) {
             lower_load_sample_pos(state, intr);
          } else if (intr->intrinsic == nir_intrinsic_interp_deref_at_offset) {