Module: Mesa Branch: staging/23.3 Commit: fee825e793259c96132b7f63434e3eaf95409693 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fee825e793259c96132b7f63434e3eaf95409693
Author: Konstantin Seurer <konstantin.seu...@gmail.com> Date: Sun Dec 24 21:48:45 2023 +0100 ac/nir: Export clip distances according to clip_cull_mask Avoids a mismatch between PA_CL_VS_OUT_CNTL and what the shader exports. Outputs that are not written export zero. Fixes: f823581 ("ac/nir: add ac_nir_export_position") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9187 Reviewed-by: Samuel Pitoiset <samuel.pitoi...@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26812> (cherry picked from commit b38c776690c9c39b04c57d74f9b036de56995aff) --- .pick_status.json | 2 +- src/amd/common/ac_nir.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 1c19b74180e..c993c21fa8a 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -104,7 +104,7 @@ "description": "ac/nir: Export clip distances according to clip_cull_mask", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "f823581dd4c9bd9054a1e10d958d6e0f93f39b22", "notes": null diff --git a/src/amd/common/ac_nir.c b/src/amd/common/ac_nir.c index 3afc33e555b..e854d56fb71 100644 --- a/src/amd/common/ac_nir.c +++ b/src/amd/common/ac_nir.c @@ -352,10 +352,19 @@ ac_nir_export_position(nir_builder *b, } for (int i = 0; i < 2; i++) { - if ((outputs_written & (VARYING_BIT_CLIP_DIST0 << i)) && - (clip_cull_mask & BITFIELD_RANGE(i * 4, 4))) { + /* Do not check outputs_written to prevent unwritten clip/cull + * distance outputs by the shader, and export zero instead. + */ + if (clip_cull_mask & BITFIELD_RANGE(i * 4, 4)) { + nir_def *clip_dist[4]; + for (int j = 0; j < 4; j++) { + if (outputs[VARYING_SLOT_CLIP_DIST0 + i][j]) + clip_dist[j] = nir_u2uN(b, outputs[VARYING_SLOT_CLIP_DIST0 + i][j], 32); + else + clip_dist[j] = nir_imm_zero(b, 1, 32); + } exp[exp_num] = export( - b, get_export_output(b, outputs[VARYING_SLOT_CLIP_DIST0 + i]), row, + b, nir_vec(b, clip_dist, ARRAY_SIZE(clip_dist)), row, V_008DFC_SQ_EXP_POS + exp_num + exp_pos_offset, 0, (clip_cull_mask >> (i * 4)) & 0xf); exp_num++;