From 4030447dab14afb2b7ba214902ad7610e15d152b Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Tue, 16 Jul 2024 10:01:28 -0500 Subject: [PATCH] nak: gather instr count explicitly This isn't as simple as dividing so we want a real shader info property for nvk to consume. Plumb one through. Signed-off-by: Alyssa Rosenzweig Reviewed-by: M Henning Part-of: --- src/nouveau/compiler/nak.h | 3 +++ src/nouveau/compiler/nak/api.rs | 12 +++--------- src/nouveau/compiler/nak/from_nir.rs | 1 + src/nouveau/compiler/nak/ir.rs | 11 ++++++----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/nouveau/compiler/nak.h b/src/nouveau/compiler/nak.h index fcd653ef1b2..58302d0f1d3 100644 --- a/src/nouveau/compiler/nak.h +++ b/src/nouveau/compiler/nak.h @@ -103,6 +103,9 @@ struct nak_shader_info { uint8_t _pad0; + /** Number of instructions used */ + uint32_t num_instrs; + /** Size of shader local (scratch) memory */ uint32_t slm_size; diff --git a/src/nouveau/compiler/nak/api.rs b/src/nouveau/compiler/nak/api.rs index 746a3a4d872..a06ce367dac 100644 --- a/src/nouveau/compiler/nak/api.rs +++ b/src/nouveau/compiler/nak/api.rs @@ -330,7 +330,7 @@ pub extern "C" fn nak_compile_shader( eprintln!("NAK IR:\n{}", &s); } - s.gather_global_mem_usage(); + s.gather_info(); let info = nak_shader_info { stage: nir.info.stage(), @@ -342,6 +342,7 @@ pub extern "C" fn nak_compile_shader( }, num_barriers: s.info.num_barriers, _pad0: Default::default(), + num_instrs: s.info.num_instrs, slm_size: s.info.slm_size, __bindgen_anon_1: match &s.info.stage { ShaderStageInfo::Compute(cs_info) => { @@ -457,16 +458,9 @@ pub extern "C" fn nak_compile_shader( let c_name = _mesa_shader_stage_to_string(info.stage as u32); CStr::from_ptr(c_name).to_str().expect("Invalid UTF-8") }; - let instruction_count = if nak.sm >= 70 { - code.len() / 4 - } else if nak.sm >= 50 { - (code.len() / 8) * 3 - } else { - unreachable!() - }; eprintln!("Stage: {}", stage_name); - eprintln!("Instruction count: {}", instruction_count); + eprintln!("Instruction count: {}", info.num_instrs); eprintln!("Num GPRs: {}", info.num_gprs); eprintln!("SLM size: {}", info.slm_size); diff --git a/src/nouveau/compiler/nak/from_nir.rs b/src/nouveau/compiler/nak/from_nir.rs index 358f036ece9..d97dfb8d959 100644 --- a/src/nouveau/compiler/nak/from_nir.rs +++ b/src/nouveau/compiler/nak/from_nir.rs @@ -21,6 +21,7 @@ use std::ops::Index; fn init_info_from_nir(nir: &nir_shader) -> ShaderInfo { ShaderInfo { num_gprs: 0, + num_instrs: 0, num_barriers: 0, slm_size: nir.scratch_size, uses_global_mem: false, diff --git a/src/nouveau/compiler/nak/ir.rs b/src/nouveau/compiler/nak/ir.rs index 475c6262153..7b9c8590856 100644 --- a/src/nouveau/compiler/nak/ir.rs +++ b/src/nouveau/compiler/nak/ir.rs @@ -6239,6 +6239,7 @@ pub enum ShaderIoInfo { pub struct ShaderInfo { pub num_gprs: u8, pub num_barriers: u8, + pub num_instrs: u32, pub slm_size: u32, pub uses_global_mem: bool, pub writes_global_mem: bool, @@ -6294,15 +6295,14 @@ impl Shader<'_> { }) } - pub fn gather_global_mem_usage(&mut self) { - if let ShaderStageInfo::Compute(_) = self.info.stage { - return; - } - + pub fn gather_info(&mut self) { + let mut num_instrs = 0; let mut uses_global_mem = false; let mut writes_global_mem = false; self.for_each_instr(&mut |instr| { + num_instrs += 1; + if !uses_global_mem { uses_global_mem = instr.uses_global_mem(); } @@ -6312,6 +6312,7 @@ impl Shader<'_> { } }); + self.info.num_instrs = num_instrs; self.info.uses_global_mem = uses_global_mem; self.info.writes_global_mem = writes_global_mem; }