r600/sfn: Lower FS inputs to temps late and, and lower interpolate at
authorGert Wollny <gert.wollny@collabora.com>
Fri, 26 Feb 2021 15:14:52 +0000 (16:14 +0100)
committerGert Wollny <gert.wollny@collabora.com>
Tue, 2 Mar 2021 17:46:17 +0000 (18:46 +0100)
This fixes FS shaders where a var is loaded with two different
interpolators.

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9330>

src/gallium/drivers/r600/r600_pipe_common.c
src/gallium/drivers/r600/sfn/sfn_nir.cpp

index 9b57691..2006068 100644 (file)
@@ -1188,7 +1188,7 @@ const struct nir_shader_compiler_options r600_nir_fs_options = {
        .lower_extract_word = true,
         .lower_rotate = true,
        .max_unroll_iterations = 32,
-       .lower_all_io_to_temps = true,
+       .lower_interpolate_at = true,
        .vectorize_io = true,
        .has_umad24 = true,
        .has_umul24 = true,
index 0767f1b..3765c69 100644 (file)
@@ -902,6 +902,24 @@ int r600_shader_from_nir(struct r600_context *rctx,
    if (sel->nir->info.stage != MESA_SHADER_FRAGMENT)
       io_modes |= nir_var_shader_out;
 
+   if (sel->nir->info.stage == MESA_SHADER_FRAGMENT) {
+
+      /* Lower IO to temporaries late, because otherwise we get into trouble
+       * with the glsl 4.40 interpolateAt swizzle tests. There seems to be a bug
+       * somewhere that results in the input alweas reading from the same temp
+       * regardless of interpolation when the lowering is done early */
+      NIR_PASS_V(sel->nir, nir_lower_io_to_temporaries, nir_shader_get_entrypoint(sel->nir),
+              true, true);
+
+      /* Since we're doing nir_lower_io_to_temporaries late, we need
+       * to lower all the copy_deref's introduced by
+       * lower_io_to_temporaries before calling nir_lower_io.
+       */
+      NIR_PASS_V(sel->nir, nir_split_var_copies);
+      NIR_PASS_V(sel->nir, nir_lower_var_copies);
+      NIR_PASS_V(sel->nir, nir_lower_global_vars_to_local);
+   }
+
    NIR_PASS_V(sel->nir, nir_lower_io, io_modes, r600_glsl_type_size,
                  nir_lower_io_lower_64bit_to_32);