From 0e1862a2ab4c28ff0b4afb9c040023cbf4354664 Mon Sep 17 00:00:00 2001 From: "Eric R. Smith" Date: Wed, 6 Mar 2024 08:17:37 -0400 Subject: [PATCH] panfrost: protect alpha calculation from accessing non-existent component We had a "Don't read out-of-bounds" sanity check for creating an alpha when ATEST was needed, but that check happened only after we already did a bi_extract(), which meant that the bi_extract could get into trouble and assert() when there weren't enough components. Fixed by re-arranging the calculation. Signed-off-by: Eric R. Smith Reviewed-by: Boris Brezillon Reviewed-by: Erik Faye-Lund @collabora.com> Cc: mesa-stable Part-of: --- src/panfrost/compiler/bifrost_compile.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/panfrost/compiler/bifrost_compile.c b/src/panfrost/compiler/bifrost_compile.c index 5f2f3a971a1..1fe8d30de2c 100644 --- a/src/panfrost/compiler/bifrost_compile.c +++ b/src/panfrost/compiler/bifrost_compile.c @@ -837,15 +837,18 @@ bi_emit_fragment_out(bi_builder *b, nir_intrinsic_instr *instr) nir_alu_type T = nir_intrinsic_src_type(instr); bi_index rgba = bi_src_index(&instr->src[0]); - bi_index alpha = (T == nir_type_float16) - ? bi_half(bi_extract(b, rgba, 1), true) - : (T == nir_type_float32) ? bi_extract(b, rgba, 3) - : bi_dontcare(b); + bi_index alpha; - /* Don't read out-of-bounds */ - if (nir_src_num_components(instr->src[0]) < 4) + if (nir_src_num_components(instr->src[0]) < 4) { + /* Don't read out-of-bounds */ alpha = bi_imm_f32(1.0); - + } else if (T == nir_type_float16) { + alpha = bi_half(bi_extract(b, rgba, 1), true); + } else if (T == nir_type_float32) { + alpha = bi_extract(b, rgba, 3); + } else { + alpha = bi_dontcare(b); + } bi_emit_atest(b, alpha); }