From 9ec4e8aa4797708ab000804700fb2e11b4553d76 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: (cherry picked from commit 0e1862a2ab4c28ff0b4afb9c040023cbf4354664) --- .pick_status.json | 2 +- src/panfrost/compiler/bifrost_compile.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 3b57f79db54..62689687c40 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -24,7 +24,7 @@ "description": "panfrost: protect alpha calculation from accessing non-existent component", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/panfrost/compiler/bifrost_compile.c b/src/panfrost/compiler/bifrost_compile.c index 90020640329..07ca3fba859 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); }