nir/texcoord_replace: add a yinvert param
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 17 Feb 2021 14:48:34 +0000 (09:48 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 24 Feb 2021 23:25:01 +0000 (23:25 +0000)
vulkan needs to invert the y coord in order to handle PIPE_SPRITE_COORD_LOWER_LEFT

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9115>

src/compiler/nir/nir.h
src/compiler/nir/nir_lower_texcoord_replace.c
src/mesa/state_tracker/st_program.c

index 7ce8484..fd35676 100644 (file)
@@ -4941,7 +4941,7 @@ void nir_lower_mediump_outputs(nir_shader *nir);
 bool nir_lower_point_size(nir_shader *shader, float min, float max);
 
 void nir_lower_texcoord_replace(nir_shader *s, unsigned coord_replace,
-                                bool point_coord_is_sysval);
+                                bool point_coord_is_sysval, bool yinvert);
 
 typedef enum {
    nir_lower_interpolation_at_sample = (1 << 1),
index f0a03e8..d448673 100644 (file)
@@ -60,7 +60,8 @@ get_io_index(nir_builder *b, nir_deref_instr *deref)
 static void
 nir_lower_texcoord_replace_impl(nir_function_impl *impl,
                                 unsigned coord_replace,
-                                bool point_coord_is_sysval)
+                                bool point_coord_is_sysval,
+                                bool yinvert)
 {
    nir_builder b;
 
@@ -90,8 +91,11 @@ nir_lower_texcoord_replace_impl(nir_function_impl *impl,
     */
    nir_ssa_def *zero = nir_imm_zero(&b, 1, new_coord->bit_size);
    nir_ssa_def *one = nir_imm_floatN_t(&b, 1.0, new_coord->bit_size);
+   nir_ssa_def *y = nir_channel(&b, new_coord, 1);
+   if (yinvert)
+      y = nir_fsub(&b, nir_imm_float(&b, 1.0), y);
    new_coord = nir_vec4(&b, nir_channel(&b, new_coord, 0),
-                            nir_channel(&b, new_coord, 1),
+                            y,
                             zero, one);
 
    nir_foreach_block(block, impl) {
@@ -134,7 +138,7 @@ nir_lower_texcoord_replace_impl(nir_function_impl *impl,
 
 void
 nir_lower_texcoord_replace(nir_shader *s, unsigned coord_replace,
-                           bool point_coord_is_sysval)
+                           bool point_coord_is_sysval, bool yinvert)
 {
    assert(s->info.stage == MESA_SHADER_FRAGMENT);
    assert(coord_replace != 0);
@@ -142,6 +146,6 @@ nir_lower_texcoord_replace(nir_shader *s, unsigned coord_replace,
    nir_foreach_function(function, s) {
       if (function->impl)
          nir_lower_texcoord_replace_impl(function->impl, coord_replace,
-                                         point_coord_is_sysval);
+                                         point_coord_is_sysval, yinvert);
    }
 }
index ae05224..376490e 100644 (file)
@@ -1315,7 +1315,7 @@ st_create_fp_variant(struct st_context *st,
       if (key->lower_texcoord_replace) {
          bool point_coord_is_sysval = st->ctx->Const.GLSLPointCoordIsSysVal;
          NIR_PASS_V(state.ir.nir, nir_lower_texcoord_replace,
-                    key->lower_texcoord_replace, point_coord_is_sysval);
+                    key->lower_texcoord_replace, point_coord_is_sysval, false);
          finalize = true;
       }