diff options
author | Erik Faye-Lund <[email protected]> | 2019-10-03 16:22:58 -0400 |
---|---|---|
committer | Erik Faye-Lund <[email protected]> | 2019-10-17 10:41:36 +0200 |
commit | 6d7e02e37da5335d2be11ca1d4bfa002e73c5770 (patch) | |
tree | 11ec3d42693df45d342601ad70a9d28c4dd31b1f | |
parent | fdc4450c285d21251a6a1de3f0765a934ea0567c (diff) |
nir: allow passing alpha-ref state to lowering-code
Reviewed-by: Marek Olšák <[email protected]>
-rw-r--r-- | src/broadcom/compiler/vir.c | 2 | ||||
-rw-r--r-- | src/compiler/nir/nir.h | 3 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_alpha_test.c | 21 | ||||
-rw-r--r-- | src/gallium/drivers/panfrost/pan_assemble.c | 3 | ||||
-rw-r--r-- | 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); } |