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

Author: Faith Ekstrand <[email protected]>
Date:   Fri Dec  1 11:56:58 2023 -0600

nak: Fix scheduling for control barriers

OpBar and OpBSync both stall the thread until other threads get to that
point.  These instructions must have .yld set.  Also, warp barrier ops
don't support the usual instruction barrier mechanism so they should be
marked as having a fixed latency.  It's unclear if the barrier file is
internally scoreboarded or if warp barrier ops just stall the whole
thread.  In either case, this seems necessary.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26463>

---

 src/nouveau/compiler/nak_calc_instr_deps.rs | 4 ++++
 src/nouveau/compiler/nak_from_nir.rs        | 2 +-
 src/nouveau/compiler/nak_ir.rs              | 9 ++++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/nouveau/compiler/nak_calc_instr_deps.rs 
b/src/nouveau/compiler/nak_calc_instr_deps.rs
index 6fe1d41e3d7..63acac02e5c 100644
--- a/src/nouveau/compiler/nak_calc_instr_deps.rs
+++ b/src/nouveau/compiler/nak_calc_instr_deps.rs
@@ -227,6 +227,10 @@ fn assign_barriers(f: &mut Function) {
                 wait_mask &= !(1 << bar);
             }
 
+            if instr.needs_yield() {
+                instr.deps.set_yield(true);
+            }
+
             if instr.has_fixed_latency() {
                 continue;
             }
diff --git a/src/nouveau/compiler/nak_from_nir.rs 
b/src/nouveau/compiler/nak_from_nir.rs
index ba6bb0650d5..c7fd2523c21 100644
--- a/src/nouveau/compiler/nak_from_nir.rs
+++ b/src/nouveau/compiler/nak_from_nir.rs
@@ -2126,7 +2126,7 @@ impl<'a> ShaderFromNir<'a> {
                     SCOPE_NONE => (),
                     SCOPE_WORKGROUP => {
                         if self.nir.info.stage() == MESA_SHADER_COMPUTE {
-                            b.push_op(OpBar {}).deps.yld = true;
+                            b.push_op(OpBar {});
                             b.push_op(OpNop { label: None });
                         }
                     }
diff --git a/src/nouveau/compiler/nak_ir.rs b/src/nouveau/compiler/nak_ir.rs
index 230d817c7da..a26a95b4262 100644
--- a/src/nouveau/compiler/nak_ir.rs
+++ b/src/nouveau/compiler/nak_ir.rs
@@ -4735,7 +4735,7 @@ impl Instr {
             | Op::MemBar(_) => false,
 
             // Control-flow ops
-            Op::BClear(_) | Op::Break(_) | Op::BSSy(_) | Op::BSync(_) => false,
+            Op::BClear(_) | Op::Break(_) | Op::BSSy(_) | Op::BSync(_) => true,
             Op::Bra(_) | Op::Exit(_) => true,
             Op::WarpSync(_) => false,
 
@@ -4778,6 +4778,13 @@ impl Instr {
         }
     }
 
+    pub fn needs_yield(&self) -> bool {
+        match &self.op {
+            Op::Bar(_) | Op::BSync(_) => true,
+            _ => false,
+        }
+    }
+
     fn fmt_pred(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         if !self.pred.is_true() {
             write!(f, "@{} ", self.pred)?;

Reply via email to