Module: Mesa Branch: main Commit: f5ba0751e27b52683f2e3b99044b87c2741e68e0 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=f5ba0751e27b52683f2e3b99044b87c2741e68e0
Author: Faith Ekstrand <[email protected]> Date: Wed Nov 8 10:52:40 2023 -0600 nak: Make encode_sm75 a method of Shader Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26181> --- src/nouveau/compiler/nak.rs | 2 +- src/nouveau/compiler/nak_encode_sm75.rs | 56 +++++++++++++++++---------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/nouveau/compiler/nak.rs b/src/nouveau/compiler/nak.rs index 4569250f9a0..6a4ea1ffef8 100644 --- a/src/nouveau/compiler/nak.rs +++ b/src/nouveau/compiler/nak.rs @@ -375,7 +375,7 @@ pub extern "C" fn nak_compile_shader( }; let code = if nak.sm >= 75 { - nak_encode_sm75::encode_shader(&s) + s.encode_sm75() } else { panic!("Unsupported shader model"); }; diff --git a/src/nouveau/compiler/nak_encode_sm75.rs b/src/nouveau/compiler/nak_encode_sm75.rs index 3bec7363aa6..d4d7cb26da7 100644 --- a/src/nouveau/compiler/nak_encode_sm75.rs +++ b/src/nouveau/compiler/nak_encode_sm75.rs @@ -1870,38 +1870,40 @@ impl SM75Instr { } } -pub fn encode_shader(shader: &Shader) -> Vec<u32> { - let mut encoded = Vec::new(); - assert!(shader.functions.len() == 1); - let func = &shader.functions[0]; - - let mut ip = 0_usize; - let mut labels = HashMap::new(); - for b in &func.blocks { - labels.insert(b.label, ip); - for instr in &b.instrs { - match &instr.op { - Op::Nop(op) => { - if let Some(label) = op.label { - labels.insert(label, ip); +impl Shader { + pub fn encode_sm75(&self) -> Vec<u32> { + assert!(self.functions.len() == 1); + let func = &self.functions[0]; + + let mut ip = 0_usize; + let mut labels = HashMap::new(); + for b in &func.blocks { + labels.insert(b.label, ip); + for instr in &b.instrs { + match &instr.op { + Op::Nop(op) => { + if let Some(label) = op.label { + labels.insert(label, ip); + } } + _ => (), } - _ => (), + ip += 4; } - ip += 4; } - } - for b in &func.blocks { - for instr in &b.instrs { - let e = SM75Instr::encode( - instr, - shader.info.sm, - encoded.len(), - &labels, - ); - encoded.extend_from_slice(&e[..]); + let mut encoded = Vec::new(); + for b in &func.blocks { + for instr in &b.instrs { + let e = SM75Instr::encode( + instr, + self.info.sm, + encoded.len(), + &labels, + ); + encoded.extend_from_slice(&e[..]); + } } + encoded } - encoded }
