freedreno/ir3: add view_zero to shader key
authorJonathan Marek <jonathan@marek.ca>
Thu, 9 Jul 2020 20:15:18 +0000 (16:15 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 15 Sep 2020 16:18:45 +0000 (16:18 +0000)
Does the same thing as layer_zero, but for VARYING_SLOT_VIEWPORT.

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5832>

src/freedreno/ir3/ir3_nir.c
src/freedreno/ir3/ir3_shader.c
src/freedreno/ir3/ir3_shader.h

index 46c1d1c..f10ec8b 100644 (file)
@@ -320,17 +320,18 @@ ir3_nir_post_finalize(struct ir3_compiler *compiler, nir_shader *s)
 }
 
 static bool
-ir3_nir_lower_layer_id(nir_shader *nir)
+ir3_nir_lower_view_layer_id(nir_shader *nir, bool layer_zero, bool view_zero)
 {
-       unsigned layer_id_loc = ~0;
+       unsigned layer_id_loc = ~0, view_id_loc = ~0;
        nir_foreach_shader_in_variable(var, nir) {
-               if (var->data.location == VARYING_SLOT_LAYER) {
+               if (var->data.location == VARYING_SLOT_LAYER)
                        layer_id_loc = var->data.driver_location;
-                       break;
-               }
+               if (var->data.location == VARYING_SLOT_VIEWPORT)
+                       view_id_loc = var->data.driver_location;
        }
 
-       assert(layer_id_loc != ~0);
+       assert(!layer_zero || layer_id_loc != ~0);
+       assert(!view_zero || view_id_loc != ~0);
 
        bool progress = false;
        nir_builder b;
@@ -350,7 +351,7 @@ ir3_nir_lower_layer_id(nir_shader *nir)
                                        continue;
 
                                unsigned base = nir_intrinsic_base(intrin);
-                               if (base != layer_id_loc)
+                               if (base != layer_id_loc && base != view_id_loc)
                                        continue;
 
                                b.cursor = nir_before_instr(&intrin->instr);
@@ -417,12 +418,15 @@ ir3_nir_lower_variant(struct ir3_shader_variant *so, nir_shader *s)
                if (so->key.vclamp_color)
                        progress |= OPT(s, nir_lower_clamp_color_outputs);
        } else if (s->info.stage == MESA_SHADER_FRAGMENT) {
+               bool layer_zero = so->key.layer_zero && (s->info.inputs_read & VARYING_BIT_LAYER);
+               bool view_zero = so->key.view_zero && (s->info.inputs_read & VARYING_BIT_VIEWPORT);
+
                if (so->key.ucp_enables)
                        progress |= OPT(s, nir_lower_clip_fs, so->key.ucp_enables, false);
                if (so->key.fclamp_color)
                        progress |= OPT(s, nir_lower_clamp_color_outputs);
-               if (so->key.layer_zero && (s->info.inputs_read & VARYING_BIT_LAYER))
-                       progress |= OPT(s, ir3_nir_lower_layer_id);
+               if (layer_zero || view_zero)
+                       progress |= OPT(s, ir3_nir_lower_view_layer_id, layer_zero, view_zero);
        }
        if (so->key.color_two_side) {
                OPT_V(s, nir_lower_two_sided_color, true);
index 519fafe..b29a66a 100644 (file)
@@ -356,6 +356,10 @@ ir3_setup_used_key(struct ir3_shader *shader)
                        key->layer_zero = true;
                }
 
+               if (info->inputs_read & VARYING_BIT_VIEWPORT) {
+                       key->view_zero = true;
+               }
+
                if ((info->outputs_written & ~(FRAG_RESULT_DEPTH |
                                                                FRAG_RESULT_STENCIL |
                                                                FRAG_RESULT_SAMPLE_MASK)) != 0) {
index db94e4f..b87b9b4 100644 (file)
@@ -318,6 +318,9 @@ struct ir3_shader_key {
 
                        /* Whether gl_Layer must be forced to 0 because it isn't written. */
                        unsigned layer_zero : 1;
+
+                       /* Whether gl_ViewportIndex must be forced to 0 because it isn't written. */
+                       unsigned view_zero : 1;
                };
                uint32_t global;
        };