diff --git a/src/nouveau/compiler/nak/calc_instr_deps.rs b/src/nouveau/compiler/nak/calc_instr_deps.rs index d5cd3494763..d54f27392e8 100644 --- a/src/nouveau/compiler/nak/calc_instr_deps.rs +++ b/src/nouveau/compiler/nak/calc_instr_deps.rs @@ -4,6 +4,7 @@ use crate::api::{GetDebugFlags, DEBUG}; use crate::dataflow::ForwardDataflow; use crate::ir::*; +use crate::opt_instr_sched_common::estimate_block_weight; use crate::reg_tracker::RegTracker; use rustc_hash::{FxHashMap, FxHashSet}; @@ -671,7 +672,8 @@ fn assign_barriers(f: &mut Function, sm: &dyn ShaderModel) { fn calc_delays(f: &mut Function, sm: &dyn ShaderModel) -> u32 { let mut min_num_static_cycles = 0; - for b in f.blocks.iter_mut().rev() { + for i in (0..f.blocks.len()).rev() { + let b = &mut f.blocks[i]; let mut cycle = 0_u32; // Vector mapping IP to start cycle @@ -772,7 +774,8 @@ fn calc_delays(f: &mut Function, sm: &dyn ShaderModel) -> u32 { cycle = min_start; } - min_num_static_cycles += cycle; + + min_num_static_cycles += cycle * estimate_block_weight(&f.blocks, i); } let max_instr_delay = sm.max_instr_delay(); diff --git a/src/nouveau/compiler/nak/opt_instr_sched_common.rs b/src/nouveau/compiler/nak/opt_instr_sched_common.rs index 7f35927bebd..bf14ba2c250 100644 --- a/src/nouveau/compiler/nak/opt_instr_sched_common.rs +++ b/src/nouveau/compiler/nak/opt_instr_sched_common.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT use crate::ir::*; +use compiler::cfg::CFG; use std::cmp::max; use std::cmp::Reverse; @@ -239,6 +240,10 @@ pub fn side_effect_type(op: &Op) -> SideEffect { } } +pub fn estimate_block_weight(cfg: &CFG, block_idx: usize) -> u32 { + 10_u32.pow(cfg.loop_depth(block_idx).try_into().unwrap()) +} + /// Try to guess how many cycles a variable latency instruction will take /// /// These values are based on the cycle estimates from ["Dissecting the NVidia diff --git a/src/nouveau/compiler/nak/opt_instr_sched_postpass.rs b/src/nouveau/compiler/nak/opt_instr_sched_postpass.rs index 7746c21eac4..c944936cb6c 100644 --- a/src/nouveau/compiler/nak/opt_instr_sched_postpass.rs +++ b/src/nouveau/compiler/nak/opt_instr_sched_postpass.rs @@ -223,13 +223,17 @@ fn sched_buffer( impl Function { pub fn opt_instr_sched_postpass(&mut self, sm: &dyn ShaderModel) -> u32 { let mut num_static_cycles = 0; - for block in &mut self.blocks { + for i in 0..self.blocks.len() { + let block = &mut self.blocks[i]; + let orig_instr_count = block.instrs.len(); let instrs = std::mem::take(&mut block.instrs); let (instrs, cycle_count) = sched_buffer(sm, instrs); block.instrs = instrs.collect(); - num_static_cycles += cycle_count; assert_eq!(orig_instr_count, block.instrs.len()); + + num_static_cycles += + cycle_count * estimate_block_weight(&self.blocks, i); } num_static_cycles }