From 6d7e02e37da5335d2be11ca1d4bfa002e73c5770 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Thu, 3 Oct 2019 16:22:58 -0400 Subject: [PATCH] nir: allow passing alpha-ref state to lowering-code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák --- src/broadcom/compiler/vir.c | 2 +- src/compiler/nir/nir.h | 3 ++- src/compiler/nir/nir_lower_alpha_test.c | 21 ++++++++++++++++++--- src/gallium/drivers/panfrost/pan_assemble.c | 3 ++- src/gallium/drivers/vc4/vc4_program.c | 3 ++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c index 802448b1e03..5d929c2412a 100644 --- a/src/broadcom/compiler/vir.c +++ b/src/broadcom/compiler/vir.c @@ -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) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index fd7f3635cbe..3732b038630 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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, diff --git a/src/compiler/nir/nir_lower_alpha_test.c b/src/compiler/nir/nir_lower_alpha_test.c index ddd815765bd..b652fb796be 100644 --- a/src/compiler/nir/nir_lower_alpha_test.c +++ b/src/compiler/nir/nir_lower_alpha_test.c @@ -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, diff --git a/src/gallium/drivers/panfrost/pan_assemble.c b/src/gallium/drivers/panfrost/pan_assemble.c index afd16abb2d2..8c3690c8e8c 100644 --- a/src/gallium/drivers/panfrost/pan_assemble.c +++ b/src/gallium/drivers/panfrost/pan_assemble.c @@ -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); } } diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c index 79edc6b1c2f..08487bea3a6 100644 --- a/src/gallium/drivers/vc4/vc4_program.c +++ b/src/gallium/drivers/vc4/vc4_program.c @@ -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); } -- 2.30.2