From d6969336ec878219569df90f133adeaeec56929d Mon Sep 17 00:00:00 2001 From: 4TheDoctor <62601652+4TheDoctor@users.noreply.github.com> Date: Fri, 27 Nov 2026 06:45:21 +0100 Subject: [PATCH] fix(cli): translate --wave32 narrows the waves as run does under Wine Under Wine, run translates with narrow_waves on (shader_cache::narrow_waves): a group that is one console wave64 with LDS gets barriers between its 32-lane halves instead of being refused. translate --wave32 left it off, so offline checks on a Mac refused programs the game translates. Now --wave32 follows run's rule (under Wine, or VICTORY_NARROW_WAVES); without --wave32 the waves are never narrowed. --- apps/victory/src/main.rs | 5 +++- apps/victory/src/translate.rs | 39 ++++++++++++++++++++++---- crates/victory-gpu/src/shader_cache.rs | 5 ++-- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/apps/victory/src/main.rs b/apps/victory/src/main.rs index 1849a7595..2ff60c05c 100644 --- a/apps/victory/src/main.rs +++ b/apps/victory/src/main.rs @@ -98,7 +98,10 @@ enum Command { list: bool, /// Translate for a host whose waves have at most 32 lanes (NVIDIA, /// Intel), as `run` does there: wave64 compute programs in halves. - /// With `--pipelines`, set by the GPU that makes them. + /// Under Wine (D3DMetal) also as `run` does there: a group that is + /// one wave64 with LDS gets barriers between its halves + /// (`VICTORY_NARROW_WAVES=0` or `1` overrides). With `--pipelines`, + /// set by the GPU that makes them. #[arg(long, conflicts_with = "cache")] wave32: bool, /// Positive worker thread count (default: every logical core). diff --git a/apps/victory/src/translate.rs b/apps/victory/src/translate.rs index aacd1e46c..58a96446d 100644 --- a/apps/victory/src/translate.rs +++ b/apps/victory/src/translate.rs @@ -578,11 +578,8 @@ fn translate( if let (Some(r), Some(i), Some(s)) = (res, raised, structured) { let label = || format!("{} {:?}", example(), p.stage); *counter(t, p.stage, 0) += 1; - let marks = emit::Options { - view_marks: true, - host_wave32: checks.wave32, - ..Default::default() - }; + let marks = + emit_options(checks.wave32, victory_gpu::shader_cache::narrow_waves()); match emit::emit_with(&container, &p, &program, &s, &i, &r, marks) { Ok(shader) => { *counter(t, p.stage, 1) += 1; @@ -607,6 +604,21 @@ fn translate( } } +/// The emit options for one program. For 32-lane waves (`wave32`), as +/// `run` translates where its host narrows the waves (`narrow`: under Wine, +/// D3DMetal runs wave64 programs in 32-lane waves whatever `WaveSize` says; +/// `VICTORY_NARROW_WAVES` overrides): a group that is one console wave64 +/// with LDS then gets barriers between its halves instead of being refused. +/// Without them the offline check refuses programs `run` translates. +fn emit_options(wave32: bool, narrow: bool) -> emit::Options { + emit::Options { + view_marks: true, + host_wave32: wave32, + narrow_waves: wave32 && narrow, + ..Default::default() + } +} + /// Validates an emitted shader if asked to. fn check( mut shader: emit::HostShader, @@ -873,6 +885,23 @@ pub(crate) fn lock(m: &Mutex) -> std::sync::MutexGuard<'_, T> { #[cfg(test)] mod tests { + /// `--wave32` translates as `run` does on a host that narrows the waves + /// (D3DMetal under Wine), and only then; without `--wave32` the waves are + /// never narrowed, as on a host whose waves hold a whole wave64. + #[test] + fn narrow_waves_follow_wave32_and_the_host() { + let o = super::emit_options(true, true); + assert!(o.host_wave32 && o.narrow_waves); + let o = super::emit_options(true, false); + assert!( + o.host_wave32 && !o.narrow_waves, + "NVIDIA, Intel: halves only" + ); + let o = super::emit_options(false, true); + assert!(!o.host_wave32 && !o.narrow_waves); + assert!(super::emit_options(false, false).view_marks); + } + /// Shader dumps are game-derived, so a dump directory in the repo is refused. #[test] fn emit_dump_inside_repo_is_refused() { diff --git a/crates/victory-gpu/src/shader_cache.rs b/crates/victory-gpu/src/shader_cache.rs index 893dbaa53..0f3075b95 100644 --- a/crates/victory-gpu/src/shader_cache.rs +++ b/crates/victory-gpu/src/shader_cache.rs @@ -157,8 +157,9 @@ fn bias_as_gradients() -> bool { /// Whether translations take wave64 programs to run in 32-lane host waves: /// under Wine, whose D3DMetal reports 32 lanes and ignores `WaveSize(64)`. -/// `VICTORY_NARROW_WAVES=0` or `1` overrides. -fn narrow_waves() -> bool { +/// `VICTORY_NARROW_WAVES=0` or `1` overrides. Also what the offline +/// `translate --wave32` follows, so its results match `run`'s. +pub fn narrow_waves() -> bool { static ON: OnceLock = OnceLock::new(); *ON.get_or_init(|| match std::env::var("VICTORY_NARROW_WAVES").as_deref() { Ok("0") => false,