From 2f6cec1ed6301a251f590d8c118071669a7622d3 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 15 Apr 2024 12:36:07 -0400 Subject: [PATCH] brw/lower_a2c: fix for scalarized fs outputs it's legal for a fs to write xyzw components separately, and this pass should handle such cases cc: mesa-stable Reviewed-by: Ivan Briano Part-of: (cherry picked from commit 042b8a65d33d94e24ef037d0b1550ad70b6b4517) --- .pick_status.json | 2 +- .../brw_nir_lower_alpha_to_coverage.c | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 52088ca6b86..5b824fd80be 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -704,7 +704,7 @@ "description": "brw/lower_a2c: fix for scalarized fs outputs", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/intel/compiler/brw_nir_lower_alpha_to_coverage.c b/src/intel/compiler/brw_nir_lower_alpha_to_coverage.c index eb13698b536..99c8855d43c 100644 --- a/src/intel/compiler/brw_nir_lower_alpha_to_coverage.c +++ b/src/intel/compiler/brw_nir_lower_alpha_to_coverage.c @@ -58,8 +58,7 @@ static nir_def * build_dither_mask(nir_builder *b, nir_def *color) { - assert(color->num_components == 4); - nir_def *alpha = nir_channel(b, color, 3); + nir_def *alpha = nir_channel(b, color, color->num_components - 1); nir_def *m = nir_f2i32(b, nir_fmul_imm(b, nir_fsat(b, alpha), 16.0)); @@ -130,6 +129,11 @@ brw_nir_lower_alpha_to_coverage(nir_shader *shader, if (location == FRAG_RESULT_COLOR || location == FRAG_RESULT_DATA0) { + uint32_t mask = nir_intrinsic_write_mask(intrin) << + nir_intrinsic_component(intrin); + /* need the w component */ + if (!(mask & BITFIELD_BIT(3))) + continue; assert(color0_write == NULL); color0_write = intrin; } @@ -137,22 +141,19 @@ brw_nir_lower_alpha_to_coverage(nir_shader *shader, } /* It's possible that shader_info may be out-of-date and the writes to - * either gl_SampleMask or the first color value may have been removed. + * either gl_SampleMask, or the first color value may have been removed, + * or that the w component is not written. * This can happen if, for instance a nir_undef is written to the * color value. In that case, just bail and don't do anything rather * than crashing. + * It's also possible that the color value isn't actually a vec4. In this case, + * assuming an alpha of 1.0 and letting the sample mask pass through + * unaltered seems like the kindest thing to do to apps. */ if (color0_write == NULL || sample_mask_write == NULL) goto skip; - /* It's possible that the color value isn't actually a vec4. In this case, - * assuming an alpha of 1.0 and letting the sample mask pass through - * unaltered seems like the kindest thing to do to apps. - */ nir_def *color0 = color0_write->src[0].ssa; - if (color0->num_components < 4) - goto skip; - nir_def *sample_mask = sample_mask_write->src[0].ssa; if (sample_mask_write_first) {