From f76e7d8e625fa627bd62a60b594dd23b4fc763f5 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sat, 11 Apr 2026 14:38:35 +0200 Subject: [PATCH] nak: add scalar tex encoding support Reviewed-by: Mel Henning Part-of: --- src/nouveau/compiler/nak/from_nir.rs | 5 +++++ src/nouveau/compiler/nak/ir.rs | 12 ++++++++++++ src/nouveau/compiler/nak/nvdisasm_tests.rs | 3 +++ src/nouveau/compiler/nak/sm70_encode.rs | 3 +++ src/nouveau/compiler/nak_private.h | 3 ++- 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/nouveau/compiler/nak/from_nir.rs b/src/nouveau/compiler/nak/from_nir.rs index 7a9c229bdab..dee2d320f03 100644 --- a/src/nouveau/compiler/nak/from_nir.rs +++ b/src/nouveau/compiler/nak/from_nir.rs @@ -1950,6 +1950,7 @@ impl<'a> ShaderFromNir<'a> { assert!(lod_mode == TexLodMode::Auto); assert!(offset_mode != TexOffsetMode::PerPx); assert!(!flags.has_z_cmpr()); + assert!(!flags.scalar()); b.push_op(OpTxd { dsts: dsts, fault: fault.into(), @@ -1964,6 +1965,7 @@ impl<'a> ShaderFromNir<'a> { } else if tex.op == nir_texop_lod { assert!(lod_mode == TexLodMode::Auto); assert!(offset_mode == TexOffsetMode::None); + assert!(!flags.scalar()); b.push_op(OpTmml { dsts: dsts, tex: tex_ref, @@ -1987,6 +1989,7 @@ impl<'a> ShaderFromNir<'a> { mem_eviction_priority: MemEvictionPriority::Normal, nodep: flags.nodep(), channel_mask, + scalar: flags.scalar(), }); } else if tex.op == nir_texop_tg4 { b.push_op(OpTld4 { @@ -2001,6 +2004,7 @@ impl<'a> ShaderFromNir<'a> { mem_eviction_priority: MemEvictionPriority::Normal, nodep: flags.nodep(), channel_mask, + scalar: flags.scalar(), }); } else { assert!(offset_mode != TexOffsetMode::PerPx); @@ -2017,6 +2021,7 @@ impl<'a> ShaderFromNir<'a> { mem_eviction_priority: MemEvictionPriority::Normal, nodep: flags.nodep(), channel_mask, + scalar: flags.scalar(), }); } } diff --git a/src/nouveau/compiler/nak/ir.rs b/src/nouveau/compiler/nak/ir.rs index f4d5e03abed..4065c72c667 100644 --- a/src/nouveau/compiler/nak/ir.rs +++ b/src/nouveau/compiler/nak/ir.rs @@ -5448,6 +5448,7 @@ pub struct OpTex { pub mem_eviction_priority: MemEvictionPriority, pub nodep: bool, pub channel_mask: ChannelMask, + pub scalar: bool, } impl DisplayOp for OpTex { @@ -5461,6 +5462,9 @@ impl DisplayOp for OpTex { write!(f, ".dc")?; } write!(f, "{}", self.mem_eviction_priority)?; + if self.scalar { + write!(f, ".scr")?; + } if self.nodep { write!(f, ".nodep")?; } @@ -5488,6 +5492,7 @@ pub struct OpTld { pub mem_eviction_priority: MemEvictionPriority, pub nodep: bool, pub channel_mask: ChannelMask, + pub scalar: bool, } impl DisplayOp for OpTld { @@ -5497,6 +5502,9 @@ impl DisplayOp for OpTld { write!(f, ".ms")?; } write!(f, "{}", self.mem_eviction_priority)?; + if self.scalar { + write!(f, ".scr")?; + } if self.nodep { write!(f, ".nodep")?; } @@ -5524,6 +5532,7 @@ pub struct OpTld4 { pub mem_eviction_priority: MemEvictionPriority, pub nodep: bool, pub channel_mask: ChannelMask, + pub scalar: bool, } impl DisplayOp for OpTld4 { @@ -5533,6 +5542,9 @@ impl DisplayOp for OpTld4 { write!(f, ".dc")?; } write!(f, "{}", self.mem_eviction_priority)?; + if self.scalar { + write!(f, ".scr")?; + } if self.nodep { write!(f, ".nodep")?; } diff --git a/src/nouveau/compiler/nak/nvdisasm_tests.rs b/src/nouveau/compiler/nak/nvdisasm_tests.rs index e2cc03cde91..00c4487e17e 100644 --- a/src/nouveau/compiler/nak/nvdisasm_tests.rs +++ b/src/nouveau/compiler/nak/nvdisasm_tests.rs @@ -506,6 +506,7 @@ pub fn test_texture() { mem_eviction_priority: MemEvictionPriority::First, nodep: true, channel_mask: ChannelMask::for_comps(3), + scalar: false, }; c.push( instr, @@ -530,6 +531,7 @@ pub fn test_texture() { mem_eviction_priority: MemEvictionPriority::First, nodep: true, channel_mask: ChannelMask::for_comps(3), + scalar: false, }; c.push( instr, @@ -562,6 +564,7 @@ pub fn test_texture() { mem_eviction_priority: MemEvictionPriority::First, nodep: true, channel_mask: ChannelMask::for_comps(3), + scalar: false, }; c.push( instr, diff --git a/src/nouveau/compiler/nak/sm70_encode.rs b/src/nouveau/compiler/nak/sm70_encode.rs index 63de8e2a5c2..06432d27a79 100644 --- a/src/nouveau/compiler/nak/sm70_encode.rs +++ b/src/nouveau/compiler/nak/sm70_encode.rs @@ -2614,6 +2614,7 @@ impl SM70Op for OpTex { e.set_ureg_src(48..56, &Src::ZERO); // offset } + e.set_bit(60, self.scalar); e.set_tex_dim(61..64, self.dim); e.set_tex_channel_mask(72..76, self.channel_mask); if e.sm >= 100 { @@ -2694,6 +2695,7 @@ impl SM70Op for OpTld { } else { e.set_bit(76, self.offset_mode == TexOffsetMode::AddOffI); } + e.set_bit(60, self.scalar); e.set_tex_dim(61..64, self.dim); e.set_tex_channel_mask(72..76, self.channel_mask); @@ -2757,6 +2759,7 @@ impl SM70Op for OpTld4 { e.set_ureg_src(48..56, &Src::ZERO); // offset } + e.set_bit(60, self.scalar); e.set_tex_dim(61..64, self.dim); e.set_tex_channel_mask(72..76, self.channel_mask); e.set_field( diff --git a/src/nouveau/compiler/nak_private.h b/src/nouveau/compiler/nak_private.h index d6b2f7e976d..588eb897eb4 100644 --- a/src/nouveau/compiler/nak_private.h +++ b/src/nouveau/compiler/nak_private.h @@ -181,7 +181,8 @@ struct nak_nir_tex_flags { bool has_z_cmpr:1; bool is_sparse:1; bool nodep:1; - uint32_t pad:22; + bool scalar:1; + uint32_t pad:21; }; PRAGMA_DIAGNOSTIC_POP static_assert(sizeof(struct nak_nir_tex_flags) == 4,