Skip to content
Open
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
6 changes: 4 additions & 2 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ pub fn compact_mode() -> Option<bool> {
}
}

/// Non-default `XCL_DIRECT_COMPACT_NEST` cache tag for the translated cache identity.
/// Non-default `XCL_DIRECT_COMPACT_NEST` and a set `XCL_WAVE64_LANE_LOOP` as cache tags for the translated cache identity.
pub fn compact_nest_tag() -> Option<String> {
super::compact::nest_mode().cache_tag()
let tags: Vec<String> = [super::compact::nest_mode().cache_tag(), super::lane_loop::cache_tag()].into_iter().flatten().collect();
(!tags.is_empty()).then(|| tags.join("-"))
}

/// `translate_full` in the compact form (`compact = true`) or the plain one.
Expand Down Expand Up @@ -760,6 +761,7 @@ impl Lw {
mask_override: None,
local_masks: false,
writes_lds: split && crate::gpu::recomp::emit::lds_order_wanted() && crate::gpu::recomp::emit::writes_lds(insts),
lane_loop: None,
exchange_error: None,
pc: 0,
};
Expand Down
633 changes: 633 additions & 0 deletions crates/xcl/src/gpu/dxil/lane_loop.rs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions crates/xcl/src/gpu/dxil/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,9 @@ impl Lw {

/// The program's ballot of `cond` → (lo, hi) mask words.
pub fn ballot(&mut self, cond: Value) -> (Value, Value) {
if self.lane_loop.is_some() {
return self.lane_loop_ballot(cond);
}
if self.is_pixel() {
return self.ballot_ps(cond);
}
Expand Down Expand Up @@ -971,6 +974,9 @@ impl Lw {
/// of the reader's own quad through quad reads (they see helper lanes, wave reads do
/// not), and a helper lane of another quad through a live lane of that quad.
pub fn rla(&mut self, v: Value, l: Value) -> Value {
if self.lane_loop.is_some() {
return self.lane_loop_read(v, l);
}
let h = self.hw_lane(l);
let w = self.s.wave_read_lane_at(v, h);
if !self.is_pixel() {
Expand Down
2 changes: 2 additions & 0 deletions crates/xcl/src/gpu/dxil/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ pub struct Lw {
/// split form: the program writes LDS (`recomp::emit::writes_lds`), so its LDS reads and
/// atomics keep the console wave's order (`VAR_XLW`)
pub writes_lds: bool,
/// one thread runs the console wave's 64 lanes in turn (`lane_loop`)
pub lane_loop: Option<super::lane_loop::LaneLoop>,
}

impl Lw {
Expand Down
1 change: 1 addition & 0 deletions crates/xcl/src/gpu/dxil/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod container;
pub mod coverage;
pub mod graphics;
pub mod kernel;
pub(crate) mod lane_loop;
mod lanes;
mod mask_exchange;
pub mod lower;
Expand Down
6 changes: 5 additions & 1 deletion crates/xcl/src/gpu/recomp/pso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,11 @@ pub(crate) fn direct_compute(blob: &[u8], sampler_base: u32, windows: u32, split
}
}
}
let k = crate::gpu::dxil::kernel::translate_compute_rodata(code, o, &cs, &rodata)?;
let lane_loop = crate::gpu::dxil::lane_loop::choose(code, o, &cs, &rodata, crate::gpu::dxil::lane_loop::mode());
let k = match lane_loop {
Some(k) => k,
None => crate::gpu::dxil::kernel::translate_compute_rodata(code, o, &cs, &rodata)?,
};
dump_direct(blob, &k.dxil);
Ok(Compiled { dispatch_chain: k.dispatch_chain, dxil: k.dxil, samplers: k.static_samplers, dispatch_remap: None })
}
Expand Down
10 changes: 9 additions & 1 deletion crates/xcl/src/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn semantic_pipeline_setting(name: &str) -> bool {
"XCL_HEAP_WINDOWS" | "XCL_LDS_TOP" | "XCL_LINK_MEM" | "XCL_MEM_ACCESSORS" |
"XCL_MW" | "XCL_PAGE_ALIAS" | "XCL_PER_LANE" | "XCL_PIXEL" |
"XCL_RECOMP_DXIL" | "XCL_RECOMP_NO_STRUCTURED" | "XCL_SAFE_BARRIER" |
"XCL_SPLIT_WAVE64" | "XCL_WAVE64_SPIN" | "XCL_WT" | "XCL_X64_ALL_MASKS" |
"XCL_SPLIT_WAVE64" | "XCL_WAVE64_LANE_LOOP" | "XCL_WAVE64_SPIN" | "XCL_WT" | "XCL_X64_ALL_MASKS" |
"XCL_XC" | "XCL_XS" | "XCL_XW" | "XCL_X_FAIL" | "XCL_X_LDS_ORDER" |
"XCL_X_LDS_TOP" | "XCL_X_SLOT" | "XCL_X_SPIN" | "XCL_X_THREADS" | "XCL_X_WAVES")
}
Expand Down Expand Up @@ -140,6 +140,14 @@ fn warm_settings_ignore_waits_watchdogs_and_traces_but_keep_pipeline_switches()
assert_eq!(plain, key(&[("XCL_DIRECT_DXIL", "1"), ("XCL_TRACEX", "1")]), "unknown diagnostics stay cache-neutral until reviewed");
}

#[cfg(test)]
#[test]
fn warm_settings_keep_the_wave64_lane_loop_switch_on_both_backends() {
let key = |entries: &[(&str, &str)]| warm_settings(entries.iter().map(|(k, v)| ((*k).into(), (*v).into())));
assert_ne!(key(&[]), key(&[("XCL_WAVE64_LANE_LOOP", "1")]));
assert_ne!(key(&[("XCL_DIRECT_DXIL", "1")]), key(&[("XCL_DIRECT_DXIL", "1"), ("XCL_WAVE64_LANE_LOOP", "1")]));
}

#[cfg(test)]
#[test]
fn warm_settings_are_canonical_and_only_hash_semantic_switches() {
Expand Down
24 changes: 24 additions & 0 deletions docs/wave64-on-wave32.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,30 @@ What is left is readlane / readfirstlane, `ds_bpermute`, coherent scalar loads a
read whole. Not measured on real compute shaders (none on that machine); Minecraft's 273
wave64 programs, translated as compute, have 38 mask writes, all only read lane by lane.

## The lane loop

A split compute program can instead run with nothing to synchronise (`gpu/dxil/lane_loop.rs`):
one thread executes a whole console wave. A group of N threads is declared as `ceil(N / 64)`
threads, thread `x` being console wave `x`; each VGPR the program names is 64 dwords local to
the thread, EXEC / VCC and the other masks are the scalars they already were, and a vector
instruction is a loop over the 64 lanes around its ordinary lowering, with the lane's bit of
EXEC as the guard. A mask is gathered bit by bit and a lane read (`v_readlane`,
`v_readfirstlane`, DPP, `ds_swizzle`, `v_permlane(x)16`, `ds_bpermute`) reads the register's
array, so both are whole once the last lane has run, and the scalar results are taken there.
An instruction that reads other lanes of a register it writes keeps its results aside until
every lane has read. Lanes past the group's threads or the dispatch's thread limits never run,
whatever the program does to EXEC. LDS stays group-shared and its accesses are in the console's
order, instruction by instruction, with no meeting.

It costs up to 64 lanes of arithmetic in one thread and 256 bytes of thread-local memory per
VGPR, so it is a fallback, and off unless asked for: with `XCL_WAVE64_LANE_LOOP=1`
`direct_compute` (`recomp/pso.rs`) takes it for a split program of at most
`lane_loop::MAX_WORDS` (512) code dwords, with `=all` for every one the form takes. The form
refuses, and the split form runs: `s_barrier` in a group of several console waves (the wave
threads would need a barrier that survives a wave leaving early), `v_movrel*`, scratch memory,
image stores and atomics, and a lane read of anything but a VGPR as the instruction found it.
Not measured on a GPU yet.

## Vertex and pixel shaders

The driver picks the wave size of a VS or PS (HLSL has no `[WaveSize]` for them), and on a
Expand Down
Loading