Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/victory-shader/src/emit/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,11 @@ fn round16(p: &crate::ir::Program) -> Vec<Option<u8>> {
/// 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
Expand Down
11 changes: 6 additions & 5 deletions crates/victory-shader/src/emit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,19 @@ 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
/// per entry into the loop: [`DEFAULT_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<u32> = std::sync::OnceLock::new();
*LIMIT.get_or_init(|| {
Expand Down