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
5 changes: 5 additions & 0 deletions apps/victory/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ pub fn warm(paths: Vec<PathBuf>, file: &Path, jobs: Option<usize>) -> 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) {
// 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;
}
Expand Down
48 changes: 43 additions & 5 deletions crates/victory-gpu/src/shader_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,41 @@ fn build() -> [u8; 32] {
/// the run will have (`victory_shader::emit::translation_fingerprint`).
pub fn warm(container: &[u8]) -> Result<bool, String> {
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Ignored warm-up wave size override

When warm targets a different wave size, host creation overwrites VICTORY_HOST_WAVE with the local GPU’s value. The target run then misses the warmed entries.

Devin left this for you to triage: Cross-machine warm-up (warming for a different GPU's wave size) is inherently approximate: the cache key includes the local build fingerprint either way. Same-machine warm-up — the documented flow — is unaffected. Recommend documenting the limitation rather than plumbing target overrides.

Learn more

The warm-up CLI exposes VICTORY_HOST_WAVE so users can match the intended runtime host. The Translate command sets it before starting warm-up. The first host() call initializes the runtime device, whose feature query replaces that same value. The translation fingerprint keys every entry on the resulting wave size.

Example: Set VICTORY_HOST_WAVE=32 on a machine whose device reports 64 lanes, with other cache-key settings matched to the intended run. The warm-up writes entries for 64 lanes, so the 32-lane run translates them again.

Recommended fix: Resolve host capabilities once before spawning workers and apply the explicit warm-up wave override after probing, before building any cache keys. Keep the runtime's hardware-derived setting unchanged.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

// 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);
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))
}

/// 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
Expand Down Expand Up @@ -147,9 +176,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")
Expand Down