shader: VICTORY_SHADER_LOOP_LIMIT to find what makes world frames slow

Translated loops stop after 2^20 iterations per lane so that a loop
over not yet mirrored data (zeros) cannot run four billion times. A pass
where every lane reaches that limit still takes seconds, though: 2^20
iterations times a 4K screen's 8 million pixels is about 10^13 loop
bodies. The world's frames now take 1.5-3 s, and loops spinning to the
limit on data that reads as zeros are one candidate.

A diagnostics build now reads VICTORY_SHADER_LOOP_LIMIT (decimal or 0x
hex, at least 1). If a low value such as 4096 makes world frames much
faster, loops hitting the limit are what makes them slow. If not, they
are ruled out. The limit is part of the translation, so the shader cache
keys on it, and a run that overrides it logs a warning. Release builds
always use 2^20.
This commit is contained in:
9hvn9yt2vk-netizen committed 2026-11-24 00:45:30 +01:00
1 parent 97c78d1087
commit 15b0091e87
4 files changed
+74 -9

No files matched your search

+14 -2
View File
@@ -36,13 +36,25 @@ pub(crate) fn counts() -> (u64, u64) {
(HITS.load(Ordering::Relaxed), MISSES.load(Ordering::Relaxed))
}
/// What identifies this build: the BLAKE3 of our executable file.
/// What identifies this build: the BLAKE3 of our executable file and of
/// the translation settings it runs with (the loop limit, which a
/// diagnostics build can change at run time).
fn build() -> &'static [u8; 32] {
static BUILD: OnceLock<[u8; 32]> = OnceLock::new();
BUILD.get_or_init(|| {
let exe = std::env::current_exe().and_then(std::fs::read);
let limit = victory_shader::emit::loop_limit();
if limit != victory_shader::emit::DEFAULT_LOOP_LIMIT {
tracing::warn!(
limit,
"VICTORY_SHADER_LOOP_LIMIT: translated loops stop sooner"
);
}
match exe {
Ok(bytes) => *blake3::hash(&bytes).as_bytes(),
Ok(mut bytes) => {
bytes.extend_from_slice(&limit.to_le_bytes());
*blake3::hash(&bytes).as_bytes()
}
Err(e) => {
// Without it no entry can be trusted: a fresh key per run.
tracing::warn!(error = %e, "cannot read our executable; shader cache unused");