From 6dbaae77d9b92f33ba7aab0ee633e154f8ee5a58 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 2 Jun 2021 18:30:30 -0400 Subject: [PATCH] pan/bi: Emit a dummy ATEST if needed Match what the blob does, since Bifrost has so many random errata we'd be fools not to. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 31 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index c2ed98e794d..fee43f356dd 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -474,6 +474,17 @@ bi_skip_atest(bi_context *ctx, bool emit_zs) return (ctx->inputs->is_blit && !emit_zs) || ctx->inputs->is_blend; } +static void +bi_emit_atest(bi_builder *b, bi_index alpha) +{ + bi_index coverage = bi_register(60); + bi_instr *atest = bi_atest_to(b, coverage, coverage, alpha); + b->shader->emitted_atest = true; + + /* Pseudo-source to encode in the tuple */ + atest->src[2] = bi_fau(BIR_FAU_ATEST_PARAM, false); +} + static void bi_emit_fragment_out(bi_builder *b, nir_intrinsic_instr *instr) { @@ -537,12 +548,7 @@ bi_emit_fragment_out(bi_builder *b, nir_intrinsic_instr *instr) if (nir_src_num_components(instr->src[0]) < 4) alpha = bi_imm_f32(1.0); - bi_instr *atest = bi_atest_to(b, bi_register(60), - bi_register(60), alpha); - b->shader->emitted_atest = true; - - /* Pseudo-source to encode in the tuple */ - atest->src[2] = bi_fau(BIR_FAU_ATEST_PARAM, false); + bi_emit_atest(b, alpha); } if (emit_zs) { @@ -3389,6 +3395,19 @@ bifrost_compile_shader_nir(nir_shader *nir, block->base.name = block_source_count++; } + /* If the shader doesn't write any colour or depth outputs, it may + * still need an ATEST at the very end! */ + bool need_dummy_atest = + (ctx->stage == MESA_SHADER_FRAGMENT) && + !ctx->emitted_atest && + !bi_skip_atest(ctx, false); + + if (need_dummy_atest) { + pan_block *end = list_last_entry(&ctx->blocks, pan_block, link); + bi_builder b = bi_init_builder(ctx, bi_after_block((bi_block *) end)); + bi_emit_atest(&b, bi_zero()); + } + /* Runs before constant folding */ bi_lower_swizzle(ctx);