Module: Mesa
Branch: main
Commit: b38c776690c9c39b04c57d74f9b036de56995aff
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b38c776690c9c39b04c57d74f9b036de56995aff

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>

---

 src/amd/common/ac_nir.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/amd/common/ac_nir.c b/src/amd/common/ac_nir.c
index a8e5f270453..23a2cbd854a 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++;

Reply via email to