diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index bb576efd..29d4e22a 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -341,9 +341,11 @@ fn round16(p: &crate::ir::Program) -> Vec> { /// its data says; data the host has not mirrored yet (a null view reads /// zeros) can make that four billion iterations, which hangs the host GPU /// until the driver resets it. A lane that reaches the limit leaves the -/// program as killed (a pixel discards). +/// program as killed (a pixel discards). The limit is also what such a loop +/// costs: a dispatch lasts as long as its slowest lane, and one lane's 2^20 +/// passes took 60 to 195 ms on an Apple M5 GPU, where 2^14 take 1 to 3 ms. // shortcut: a genuine loop of more iterations than this is cut short too. -pub(super) const LOOP_LIMIT: u32 = 1 << 20; +pub(super) const LOOP_LIMIT: u32 = 1 << 14; /// Lane masks read as numbers (`s_bcnt1`, `s_ff1`, `v_mbcnt`, scalar /// compares, bit tests) are ballots of the lanes' booleans, taken where the diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index ca41f8fc..e3d5aba8 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -234,7 +234,7 @@ pub use shader::{ VIEW_WRITES_BYTES, }; -/// The loop limit without an override: 2^20. +/// The loop limit without an override: 2^14. pub const DEFAULT_LOOP_LIMIT: u32 = lower::LOOP_LIMIT; /// The iteration count after which a translated loop is left, per lane and @@ -242,10 +242,11 @@ pub const DEFAULT_LOOP_LIMIT: u32 = lower::LOOP_LIMIT; /// /// With the `diagnostics` feature, `VICTORY_SHADER_LOOP_LIMIT` (decimal or /// `0x` hex, at least 1) sets it instead. A loop that hits the limit in -/// every lane of a full-screen pass still runs for seconds (2^20 times a -/// 4K screen is about 10^13 iterations); a much lower limit shows whether -/// such loops are what makes a frame slow. The value is part of the -/// translation, so the shader cache must key on it (`victory-gpu`'s does). +/// every lane of a full-screen pass is still slow (2^14 times a 4K screen +/// is about 10^11 iterations); a lower limit shows whether such loops are +/// what makes a frame slow, a higher one whether the limit cuts a genuine +/// loop short. The value is part of the translation, so the shader cache +/// must key on it (`victory-gpu`'s does). pub fn loop_limit() -> u32 { static LIMIT: std::sync::OnceLock = std::sync::OnceLock::new(); *LIMIT.get_or_init(|| {