From 0e4a9ef721e1ca5dca38d474ae1e9aaedb59a217 Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Wed, 25 Nov 2026 15:47:36 +0000 Subject: [PATCH 1/3] gpu: a failed cache write does not drop the translated shader The disk error path returned the translation as an error, and Shader::translated remembers failures for the rest of the run: a full or read-only cache directory cost every draw of the program. The shader is now returned uncached (the same work the converter just did). Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- crates/victory-gpu/src/shader_cache.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/victory-gpu/src/shader_cache.rs b/crates/victory-gpu/src/shader_cache.rs index 9e06221..1cea1a4 100644 --- a/crates/victory-gpu/src/shader_cache.rs +++ b/crates/victory-gpu/src/shader_cache.rs @@ -147,9 +147,18 @@ fn cached( ran: AtomicBool::new(false), }; for _ in 0..2 { - let path = cache - .get_or_convert(&converter, &input) - .map_err(|e| format!("{e:#}"))?; + let path = match cache.get_or_convert(&converter, &input) { + Ok(path) => path, + Err(e) => { + // A cache that cannot write (a full or read-only disk) must + // not cost the shader: the translation is the same work the + // converter just did, returned uncached instead of dropping + // every draw of the program for the rest of the run. + tracing::debug!("shader cache write failed ({e:#}); the shader is not cached"); + MISSES.fetch_add(1, Ordering::Relaxed); + return (converter.translate)(container); + } + }; if let Some(shader) = std::fs::read(&path).ok().and_then(|b| decode(&b)) { let (counter, what) = if converter.ran.load(Ordering::Relaxed) { (&MISSES, "translated and cached") From 6a02d65a508085fdc16fd3b9b87b4d22e0361932 Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Wed, 25 Nov 2026 15:49:00 +0000 Subject: [PATCH 2/3] gpu: warm up in the host's mesh mode; stop scanning past the warm deadline Warm-up wrote only native-mesh cache entries while emulation hardware keys by the emulation mode, so mesh programs still translated on first use there. The mode now follows the machine's mesh support. And once VICTORY_WARM_SECONDS expires, the walk stops opening assets instead of scanning every remaining one for workers that break out at once. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/victory/src/translate.rs | 5 +++++ crates/victory-gpu/src/shader_cache.rs | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/victory/src/translate.rs b/apps/victory/src/translate.rs index bb0835d..d791bb2 100644 --- a/apps/victory/src/translate.rs +++ b/apps/victory/src/translate.rs @@ -200,6 +200,11 @@ pub fn warm(paths: Vec, file: &Path, jobs: Option) -> Result<()> if !entry.file_type().is_file() || entry.metadata().map_or(0, |m| m.len()) > MAX_FILE { continue; } + // Past the deadline the workers break out at once: opening and + // reading the rest of the assets would only scan for nothing. + if limit.is_some_and(|n| began.elapsed().as_secs() >= n) { + break; + } let Ok(data) = std::fs::read(entry.path()) else { continue; }; diff --git a/crates/victory-gpu/src/shader_cache.rs b/crates/victory-gpu/src/shader_cache.rs index 1cea1a4..ae8307c 100644 --- a/crates/victory-gpu/src/shader_cache.rs +++ b/crates/victory-gpu/src/shader_cache.rs @@ -88,11 +88,19 @@ fn build() -> [u8; 32] { pub fn warm(container: &[u8]) -> Result { let cache = CACHE.get().ok_or("no shader cache")?; let ran = AtomicBool::new(false); + // The mode the runtime translates with on this machine: an emulated + // mesh shader's cache entry is another key than the native one's, so a + // warm-up in only the native mode left emulation hardware (no mesh + // shader support) to translate every mesh program on first use. + let mesh = match crate::host::host() { + Some(h) if h.emulate_mesh_shaders() => MeshMode::Emulate, + _ => MeshMode::Native, + }; let translate = |c: &[u8]| { ran.store(true, Ordering::Relaxed); - victory_shader::emit::translate(c).map_err(|e| e.to_string()) + victory_shader::emit::translate_with(c, mesh).map_err(|e| e.to_string()) }; - cached(cache, &build(), MeshMode::Native, container, translate).map(|_| ran.load(Ordering::Relaxed)) + cached(cache, &build(), mesh, container, translate).map(|_| ran.load(Ordering::Relaxed)) } /// The translation of a console shader container, from the cache when From 47aabac2664e74f093d18ed7f280d4c8cc505e99 Mon Sep 17 00:00:00 2001 From: stoltembergg Date: Wed, 25 Nov 2026 15:53:51 +0000 Subject: [PATCH 3/3] gpu: warm keys by the container's stage; probe the view limit; deadline first Only a mesh program's container keys by the mesh mode at runtime: warming every container in the emulation mode on emulation hardware left vertex, pixel and compute shaders uncached there. The mode now follows the container's own stage. Warm-up also probes the view-index cap as runtime translation does, and the deadline check leads the entry loop so later roots are not walked for nothing. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/victory/src/translate.rs | 10 ++++----- crates/victory-gpu/src/shader_cache.rs | 29 ++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/apps/victory/src/translate.rs b/apps/victory/src/translate.rs index d791bb2..2e12ae9 100644 --- a/apps/victory/src/translate.rs +++ b/apps/victory/src/translate.rs @@ -197,14 +197,14 @@ pub fn warm(paths: Vec, file: &Path, jobs: Option) -> Result<()> let counts = [const { AtomicUsize::new(0) }; 5]; for root in &paths { for entry in walkdir::WalkDir::new(root).into_iter().filter_map(Result::ok) { - if !entry.file_type().is_file() || entry.metadata().map_or(0, |m| m.len()) > MAX_FILE { - continue; - } - // Past the deadline the workers break out at once: opening and - // reading the rest of the assets would only scan for nothing. + // Past the deadline the workers break out at once: walking and + // opening the rest of the assets would only scan for nothing. if limit.is_some_and(|n| began.elapsed().as_secs() >= n) { break; } + if !entry.file_type().is_file() || entry.metadata().map_or(0, |m| m.len()) > MAX_FILE { + continue; + } let Ok(data) = std::fs::read(entry.path()) else { continue; }; diff --git a/crates/victory-gpu/src/shader_cache.rs b/crates/victory-gpu/src/shader_cache.rs index ae8307c..995b58f 100644 --- a/crates/victory-gpu/src/shader_cache.rs +++ b/crates/victory-gpu/src/shader_cache.rs @@ -87,14 +87,21 @@ fn build() -> [u8; 32] { /// the run will have (`victory_shader::emit::translation_fingerprint`). pub fn warm(container: &[u8]) -> Result { let cache = CACHE.get().ok_or("no shader cache")?; + // The translation depends on the view-index cap as at runtime. + crate::descriptor::host::probe_view_limit(); let ran = AtomicBool::new(false); // The mode the runtime translates with on this machine: an emulated // mesh shader's cache entry is another key than the native one's, so a // warm-up in only the native mode left emulation hardware (no mesh - // shader support) to translate every mesh program on first use. - let mesh = match crate::host::host() { - Some(h) if h.emulate_mesh_shaders() => MeshMode::Emulate, - _ => MeshMode::Native, + // shader support) to translate every mesh program on first use. Only a + // mesh program's container keys by it: everything else translates in + // the native mode whatever the host (`pipeline::translate`). + let mesh = if container_is_mesh(container) + && crate::host::host().is_some_and(crate::host::Host::emulate_mesh_shaders) + { + MeshMode::Emulate + } else { + MeshMode::Native }; let translate = |c: &[u8]| { ran.store(true, Ordering::Relaxed); @@ -103,6 +110,20 @@ pub fn warm(container: &[u8]) -> Result { cached(cache, &build(), mesh, container, translate).map(|_| ran.load(Ordering::Relaxed)) } +/// Whether the container's program is a mesh program: the only stage the +/// mesh mode keys and translates differently. +fn container_is_mesh(container: &[u8]) -> bool { + let Ok(c) = victory_shader::Container::parse(container) else { + return false; + }; + let Some(dxil) = c.part(victory_shader::FourCC::DXIL) else { + return false; + }; + victory_shader::native_programs(dxil.data) + .map(|ps| ps.iter().any(|p| p.stage == victory_shader::HwStage::Ms)) + .unwrap_or(false) +} + /// The translation of a console shader container, from the cache when /// there is one. pub(crate) fn host_shader(container: &[u8], mesh: MeshMode) -> Result {