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

Author: Faith Ekstrand <[email protected]>
Date:   Sat Dec  9 00:51:57 2023 -0600

nak: Handle negative cbuf offset immediates

This can happen with indirect UBO pulls because we just try go find an
iadd in NIR and one side may be negative.

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

---

 src/nouveau/compiler/nak/from_nir.rs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/nouveau/compiler/nak/from_nir.rs 
b/src/nouveau/compiler/nak/from_nir.rs
index 63150ab426c..24ebb041604 100644
--- a/src/nouveau/compiler/nak/from_nir.rs
+++ b/src/nouveau/compiler/nak/from_nir.rs
@@ -2190,13 +2190,22 @@ impl<'a> ShaderFromNir<'a> {
                 let size_B =
                     (intrin.def.bit_size() / 8) * intrin.def.num_components();
                 let idx = srcs[0];
+
                 let (off, off_imm) = self.get_io_addr_offset(&srcs[1], 16);
+                let (off, off_imm) =
+                    if let Ok(off_imm_u16) = u16::try_from(off_imm) {
+                        (off, off_imm_u16)
+                    } else {
+                        (self.get_src(&srcs[1]), 0)
+                    };
+
                 let dst = b.alloc_ssa(RegFile::GPR, size_B.div_ceil(4));
 
                 if let Some(idx_imm) = idx.as_uint() {
+                    let idx_imm: u8 = idx_imm.try_into().unwrap();
                     let cb = CBufRef {
-                        buf: CBuf::Binding(idx_imm.try_into().unwrap()),
-                        offset: off_imm.try_into().unwrap(),
+                        buf: CBuf::Binding(idx_imm),
+                        offset: off_imm,
                     };
                     if off.is_zero() {
                         for (i, comp) in dst.iter().enumerate() {

Reply via email to