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: 4 additions & 1 deletion apps/victory/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
39 changes: 34 additions & 5 deletions apps/victory/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -873,6 +885,23 @@ pub(crate) fn lock<T>(m: &Mutex<T>) -> 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() {
Expand Down
5 changes: 3 additions & 2 deletions crates/victory-gpu/src/shader_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> = OnceLock::new();
*ON.get_or_init(|| match std::env::var("VICTORY_NARROW_WAVES").as_deref() {
Ok("0") => false,
Expand Down