nir: allow passing alpha-ref state to lowering-code
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 3 Oct 2019 20:22:58 +0000 (16:22 -0400)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 17 Oct 2019 08:41:36 +0000 (10:41 +0200)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/broadcom/compiler/vir.c
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_alpha_test.c
src/gallium/drivers/panfrost/pan_assemble.c
src/gallium/drivers/vc4/vc4_program.c

index 802448b1e035056f07a3b2be7350742422fe8227..5d929c2412a5a43f84f2e627a1d3d6969f608c83 100644 (file)
@@ -846,7 +846,7 @@ v3d_nir_lower_fs_late(struct v3d_compile *c)
         if (c->fs_key->alpha_test) {
                 NIR_PASS_V(c->s, nir_lower_alpha_test,
                            c->fs_key->alpha_test_func,
-                           false);
+                           false, NULL);
         }
 
         if (c->key->ucp_enables)
index fd7f3635cbee75266b39457ee0b82507eb38a6e0..3732b03863021eb991c9f784e7ff9a155a7dbed1 100644 (file)
@@ -3683,7 +3683,8 @@ bool nir_lower_constant_initializers(nir_shader *shader,
 bool nir_move_vec_src_uses_to_dest(nir_shader *shader);
 bool nir_lower_vec_to_movs(nir_shader *shader);
 void nir_lower_alpha_test(nir_shader *shader, enum compare_func func,
-                          bool alpha_to_one);
+                          bool alpha_to_one,
+                          const gl_state_index16 *alpha_ref_state_tokens);
 bool nir_lower_alu(nir_shader *shader);
 
 bool nir_lower_flrp(nir_shader *shader, unsigned lowering_mask,
index ddd815765bdd410a496793c932330a33a4f825c1..b652fb796be71cc427c6c1dca30a019d92dcb4ae 100644 (file)
@@ -37,7 +37,8 @@
 
 void
 nir_lower_alpha_test(nir_shader *shader, enum compare_func func,
-                     bool alpha_to_one)
+                     bool alpha_to_one,
+                     const gl_state_index16 *alpha_ref_state_tokens)
 {
    assert(shader->info.stage == MESA_SHADER_FRAGMENT);
 
@@ -93,9 +94,23 @@ nir_lower_alpha_test(nir_shader *shader, enum compare_func func,
                                       3);
                }
 
+               nir_ssa_def *alpha_ref;
+               if (alpha_ref_state_tokens) {
+                  nir_variable *var = nir_variable_create(shader,
+                                                          nir_var_uniform,
+                                                          glsl_float_type(),
+                                                          "gl_AlphaRefMESA");
+                  var->num_state_slots = 1;
+                  var->state_slots = ralloc_array(var, nir_state_slot, 1);
+                  memcpy(var->state_slots[0].tokens,
+                         alpha_ref_state_tokens,
+                         sizeof(var->state_slots[0].tokens));
+                  alpha_ref = nir_load_var(&b, var);
+               } else
+                  alpha_ref = nir_load_alpha_ref_float(&b);
+
                nir_ssa_def *condition =
-                  nir_compare_func(&b, func,
-                                   alpha, nir_load_alpha_ref_float(&b));
+                  nir_compare_func(&b, func, alpha, alpha_ref);
 
                nir_intrinsic_instr *discard =
                   nir_intrinsic_instr_create(b.shader,
index afd16abb2d21d23789f7bc3afee61a753b25db74..8c3690c8e8c809e4accf2b466db07c35b2809749 100644 (file)
@@ -63,7 +63,8 @@ panfrost_shader_compile(
                 /* Inject the alpha test now if we need to */
 
                 if (state->alpha_state.enabled) {
-                        NIR_PASS_V(s, nir_lower_alpha_test, state->alpha_state.func, false);
+                        NIR_PASS_V(s, nir_lower_alpha_test,
+                                   state->alpha_state.func, false, NULL);
                 }
         }
 
index 79edc6b1c2f60b96a2d5e3ee43ffe8110dcf794b..08487bea3a64fc6e89e82dc0c0e1729e19f52acf 100644 (file)
@@ -2258,7 +2258,8 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage,
                         NIR_PASS_V(c->s, nir_lower_alpha_test,
                                    c->fs_key->alpha_test_func,
                                    c->fs_key->sample_alpha_to_one &&
-                                   c->fs_key->msaa);
+                                   c->fs_key->msaa,
+                                   NULL);
                 }
                 NIR_PASS_V(c->s, vc4_nir_lower_blend, c);
         }