Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1bab757
Recompiler: per-lane lane-mask analysis for a direct DXIL backend
gefydev Nov 24, 2026
9b8db83
Recompiler: assemble and sign a DXIL module from LLVM IR text
Sr-0w Nov 24, 2026
b3c0b37
Recompiler: lower kernel programs to DXIL-shaped IR on the lane masks
gefydev Nov 24, 2026
430f0a3
Recompiler: scalar and vector memory in the direct lowering
gefydev Nov 24, 2026
f33f640
Recompiler: compute mode in the direct lowering
gefydev Nov 24, 2026
511eadd
Recompiler: write the direct lowering through gpu::dxil's module builder
gefydev Nov 24, 2026
ac34cb6
Recompiler: refuse scalar values a lane kept from before a write it s…
gefydev Nov 24, 2026
13ac196
Recompiler: report both halves of a stale wave64 mask in the lowering
Frtuchinno Nov 24, 2026
f90033c
Recompiler: cross-lane operations in the lowering
Sr-0w Nov 24, 2026
ac8f8b6
Recompiler: lane reads and bit counts through gpu::dxil in the direct…
gefydev Nov 24, 2026
f5d3e05
Recompiler: per-lane coverage survey and the first coverage gaps
gefydev Nov 24, 2026
45025eb
Recompiler: half-local wave operations in the lowering's Ir
Sr-0w Nov 24, 2026
fbb3a7b
Recompiler: name the hardware register of a refused s_setreg in the c…
gefydev Nov 24, 2026
a5311f7
Recompiler: thread ids of any compute group shape in the lowering's Ir
Sr-0w Nov 24, 2026
9816a85
Recompiler: drop trivial phis through Module::replace_all_uses in the…
gefydev Nov 24, 2026
6bdef80
Tests: the IR assemble test skips without dxil.dll; survey sizes in KB
gefydev Nov 24, 2026
8593700
Recompiler: survey every per-lane refusal, and the mesh pass both ways
Kalmarv Nov 24, 2026
f9be7cc
Recompiler: an unsupported VALU opcode is refused before its sources …
gefydev Nov 24, 2026
acdf922
Recompiler: whole-wave mask reads need every lane where an Ir meets a…
upipibi Nov 24, 2026
9231d48
Tests: f32 programs for the per-lane lowering, on the HLSL path and p…
vladbondarenko97 Nov 24, 2026
ad39e4d
Direct DXIL: Lw::new and Lw::finish out of the kernel translator
Sr-0w Nov 24, 2026
77db49c
Recompiler: the DXIL adapter holds #1426's Lw; 2-D / 3-D compute groups
Sr-0w Nov 24, 2026
878afda
Recompiler: the per-lane form lowers unknown instructions with #1426'…
gefydev Nov 24, 2026
ddfbf39
Recompiler: the per-lane form in the runtime behind XCL_PER_LANE=1
gefydev Nov 24, 2026
5963c26
Recompiler: far jumps in the per-lane form
gefydev Nov 24, 2026
bc0d77c
Recompiler: xcl shaders --direct --lanes measures the per-lane form
gefydev Nov 24, 2026
372be9d
Recompiler: s_cselect, s_wqm and v_cmpx in the per-lane form
gefydev Nov 24, 2026
77a5eee
Recompiler: the split wave64 form in the direct lowering, through #14…
upipibi Nov 24, 2026
d2cc6ff
Recompiler: the lane-mask analysis can start from an unknown EXEC
teidenzero Nov 24, 2026
27d28ce
Recompiler: lane masks follow s_wqm of the launch EXEC
teidenzero Nov 24, 2026
a24899e
Recompiler: VS / PS stages in the per-lane lowering
teidenzero Nov 24, 2026
5d2d65c
Recompiler: s_wqm in a VS / PS keeps the launch-EXEC rule
gefydev Nov 24, 2026
b1bfd1e
Tests: the f32 reference keeps signed zeros on every driver
gefydev Nov 24, 2026
3aea7a9
Tests: f64 programs for the per-lane lowering, on the HLSL path and p…
vladbondarenko97 Nov 24, 2026
82c875d
Tests: integer programs for the per-lane lowering, on the HLSL path a…
vladbondarenko97 Nov 24, 2026
188ee17
Recompiler: carry-ins and v_cndmask through #1426 read the right lane…
gefydev Nov 24, 2026
fe8dc84
Recompiler: f16 products stay on the fallback until #1426 rounds them
gefydev Nov 24, 2026
27751a0
Tests: f16 and packed programs for the per-lane lowering, on the HLSL…
vladbondarenko97 Nov 24, 2026
3827fb5
Recompiler: coalesce straight-line guarded runs in the per-lane lowering
MiguelMachado-dev Nov 24, 2026
a23b6ff
Recompiler: a value copied where some lanes are elsewhere is that blo…
gefydev Nov 24, 2026
dd566c0
Recompiler: no r - 1 for s0 in the mask-pair check of cross-lane ops
gefydev Nov 24, 2026
fdb4c10
Recompiler: --lanes runs the per-lane form under the sweep's timeout
gefydev Nov 24, 2026
e40ac38
Recompiler: the runtime's split compute programs ask for 32-lane waves
gefydev Nov 24, 2026
14e367e
Recompiler: a VS starts with every lane in EXEC in the per-lane form
teidenzero Nov 24, 2026
29eccc0
Recompiler: replace the per-lane form's trivial phis in one pass
Itsmetibo Nov 24, 2026
f251762
Recompiler: the per-lane form takes heap memory windows
gefydev Nov 24, 2026
4e057cb
Tests: cover split wave64 coalesced runs on the GPU
MiguelMachado-dev Nov 24, 2026
9e27370
Tests: the per-lane GPU tests skip on adapters without 32-lane waves
gefydev Nov 24, 2026
66879ef
Recompiler: the per-lane form refuses whole-wave mask decisions and m…
gefydev Nov 24, 2026
9dcf2f6
Recompiler: a mask op's SCC carried around a loop stays a lane's
gefydev Nov 24, 2026
bfb8133
Recompiler: per-lane cache entries change when the per-lane sources do
gefydev Nov 24, 2026
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
19 changes: 19 additions & 0 deletions crates/xcl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ const TRANSLATOR_SOURCES: &[&str] = &[
"src/gpu/xbox.rs",
];

/// The per-lane form's sources (`XCL_PER_LANE`): part of only its own cache entries' identity,
/// so editing them does not invalidate the HLSL path's.
const PER_LANE_SOURCES: &[&str] = &[
"src/gpu/recomp/lane_masks.rs",
"src/gpu/recomp/lower.rs",
"src/gpu/recomp/lower/wave.rs",
"src/gpu/recomp/lower_dxil.rs",
"src/gpu/recomp/ssa.rs",
];

fn add(h: &mut u64, bytes: &[u8]) {
for &byte in bytes {
*h ^= byte as u64;
Expand Down Expand Up @@ -48,4 +58,13 @@ fn main() {
add(&mut h, &[0]);
}
println!("cargo:rustc-env=XCL_TRANSLATOR_SOURCE_ID={h:016x}");
let mut p = 0xcbf2_9ce4_8422_2325u64;
for relative in PER_LANE_SOURCES {
println!("cargo:rerun-if-changed={relative}");
add(&mut p, relative.as_bytes());
add(&mut p, &[0]);
add(&mut p, &std::fs::read(root.join(relative)).expect("read per-lane source"));
add(&mut p, &[0]);
}
println!("cargo:rustc-env=XCL_PER_LANE_SOURCE_ID={p:016x}");
}
293 changes: 161 additions & 132 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use super::lower::{ComputeInit, Init, Lw, Partner, VAR_BUDGET, VAR_SCC, VAR_VGPR
use super::module::{Block, Pred, Value};
use super::shader::{RawUav, Shader};
use super::ssa::Ssa;
use crate::gpu::rdna2::Decoded;
use crate::gpu::recomp::{CsInterface, MsInterface, PsInterface, VsInterface, KERNEL_SCC_SLOT, KERNEL_SGPRS, KERNEL_VGPRS, MESH_HEADER};

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -87,7 +88,7 @@ pub fn translate_pixel(code: &[u8], o: KernelOptions, ps: &PsInterface) -> Resul

/// The entry ABI.
#[derive(Clone)]
enum Entry {
pub enum Entry {
Kernel,
Compute(CsInterface),
Mesh(MsInterface),
Expand Down Expand Up @@ -132,123 +133,14 @@ fn mem_windows(s: &mut Shader, mem_windows: u32, coherent: bool) -> (Vec<RawUav>

fn translate_on_this_thread(code: &[u8], o: KernelOptions, entry: Entry) -> Result<Kernel, String> {
let cfg = Cfg::build(code)?;
let split = o.wave64 && o.split;
let kernel = matches!(entry, Entry::Kernel);
let cs = match &entry {
Entry::Compute(cs) => Some(cs.clone()),
_ => None,
};
let ms = match &entry {
Entry::Mesh(ms) => Some(ms.clone()),
_ => None,
};
let gfx = matches!(entry, Entry::Vertex(_) | Entry::Pixel(_));
let split = split && !gfx;
let stage = match &entry {
Entry::Vertex(_) => Stage::Vertex,
Entry::Pixel(_) => Stage::Pixel,
_ => Stage::Compute,
};
let mut s = Shader::new(stage, (6, 6));
let io = s.raw_uav(0, 0);
let res = if kernel || ms.is_some() { Some(s.raw_uav(1, 0)) } else { None };
let (mems, heap_mem) = mem_windows(&mut s, o.mem_windows, cs.is_some());
let i32 = s.m.i32();
let z = s.m.i32c(0);
let mut lw = Lw {
s,
ssa: Ssa::new(i32),
init: Init { io: Some(io), compute: None, vgpr_base: None, entry: Block(0), touched: BTreeSet::new() },
wave64: o.wave64,
split,
lane: z,
lane31: z,
upper: z,
half: z,
mems,
heap_mem,
res,
fmt_table: None,
fmt_desc_cache: HashMap::new(),
fmt_comp1_cache: HashMap::new(),
uma_base_val: None,
ntmp: 0,
scratch: None,
static_samplers: Default::default(),
static_used: Vec::new(),
sampler_base: o.sampler_base,
dyn_rm: false,
has_f64_round_op: false,
exec_cache: HashMap::new(),
xs: None,
xw: None,
xc: None,
waves: 1,
cw: z,
xn: z,
xslot: 1,
lds: None,
lds_top: 8191,
dpp_enable: None,
partner: Partner::Present,
mesh: None,
gfx: None,
gfx_half: None,
whole_live: Default::default(),
guard_override: None,
mask_override: None,
exchange_error: None,
pc: 0,
};
{
let Lw { s, ssa, init, .. } = &mut lw;
ssa.expect_preds(s, Block(0), 0, &mut |s, v| init.load(s, v));
}
// LDS and the split form's exchange slot size (16 words for a coherent s_load_dwordx16,
// 32 for ds_bpermute), as the HLSL kernel sizes them
let mut uses_lds = false;
let mut slot = 1u32;
for d in &cfg.insts {
let n = d.inst.name;
if d.enc.name == "ENC_DS" && !matches!(n, "DS_SWIZZLE_B32" | "DS_BPERMUTE_B32" | "DS_PERMUTE_B32" | "DS_NOP") {
uses_lds = true;
}
if n == "DS_BPERMUTE_B32" {
slot = slot.max(32);
}
if d.enc.name == "ENC_SMEM" && ["GLC", "DLC"].iter().any(|f| crate::gpu::rdna2::field_value(d.enc, &d.words, f) == Some(1)) {
let w = match n.rsplit('_').next().unwrap_or("") {
"DWORDX2" => 2,
"DWORDX4" => 4,
"DWORDX8" => 8,
"DWORDX16" => 16,
_ => 1,
};
slot = slot.max(w);
}
}
let split = o.wave64 && o.split && !gfx;
let leaders: BTreeSet<u64> = cfg.blocks.iter().filter_map(|b| b.insts.first().map(|&i| cfg.insts[i].pc)).collect();
lw.static_samplers = crate::gpu::recomp::constant_samplers(&cfg.insts, &leaders);
let group_threads: Option<u32> = match &entry {
Entry::Vertex(_) | Entry::Pixel(_) => None,
Entry::Kernel => None,
Entry::Compute(cs) => Some(cs.threads.iter().product()),
Entry::Mesh(ms) => Some(ms.threads),
};
if let (Some(t), true) = (group_threads, split) {
lw.waves = t.div_ceil(64).max(1);
}
if split && std::env::var_os("XCL_X64_ALL_MASKS").is_none() {
lw.whole_live = crate::gpu::recomp::x64_masks::by_pc(&cfg.insts, kernel);
}
lw.setup_storage(uses_lds, if split { slot } else { 1 });
if let (Some(t), true) = (group_threads, split) {
lw.partner = match t {
0..=32 => Partner::Missing,
33..=64 => Partner::Present,
_ => Partner::Spin,
};
}
let mut lw = Lw::new(&cfg.insts, &leaders, o, &entry);
let uses_lds = lw.lds.is_some();
let res = lw.res;
let io = lw.init.io.expect("the I/O buffer");
let numthreads = match &entry {
Entry::Kernel => {
lw.setup_lanes();
Expand Down Expand Up @@ -364,25 +256,162 @@ fn translate_on_this_thread(code: &[u8], o: KernelOptions, entry: Entry) -> Resu
lw.s.m.ret();
lw.s.m.set_block(Block(0));
lw.s.m.br(h0);
if let Some(e) = lw.exchange_error.take() {
return Err(e);
}
let hw = if split || !o.wave64 { 32 } else { 64 };
let c = if gfx {
let g = lw.gfx.take().ok_or("graphics entry without graphics I/O")?;
let info = if stage == Stage::Pixel { super::graphics::StageInfo::Pixel { early_depth_stencil: false } } else { super::graphics::StageInfo::Vertex };
lw.s.try_finish_graphics(g.io, info)
} else {
lw.s.try_finish(numthreads, Some(hw))
lw.finish(numthreads, hw)
}

impl Lw {
/// The translator's state for a program (`insts`, its blocks starting at `leaders`) at
/// `entry`: the shader with its buffers,
/// the SSA's entry block, the program's LDS and the split form's exchange storage and
/// partner. The caller then sets up the lanes for its entry (`setup_lanes*`), lowers the
/// program's blocks, branches from `Block(0)` to the first of them and ends with
/// [`Lw::finish`]. #1426's block walk (`translate_on_this_thread`) and the recompiler's
/// per-lane lowering (`recomp::lower_dxil`) both build their `Lw` here.
pub fn new(insts: &[Decoded], leaders: &BTreeSet<u64>, o: KernelOptions, entry: &Entry) -> Lw {
let split = o.wave64 && o.split;
let kernel = matches!(entry, Entry::Kernel);
let cs = match entry {
Entry::Compute(cs) => Some(cs.clone()),
_ => None,
};
let ms = match entry {
Entry::Mesh(ms) => Some(ms.clone()),
_ => None,
};
let gfx = matches!(entry, Entry::Vertex(_) | Entry::Pixel(_));
let split = split && !gfx;
let stage = match entry {
Entry::Vertex(_) => Stage::Vertex,
Entry::Pixel(_) => Stage::Pixel,
_ => Stage::Compute,
};
let mut s = Shader::new(stage, (6, 6));
let io = s.raw_uav(0, 0);
let res = if kernel || ms.is_some() { Some(s.raw_uav(1, 0)) } else { None };
let (mems, heap_mem) = mem_windows(&mut s, o.mem_windows, cs.is_some());
let i32 = s.m.i32();
let z = s.m.i32c(0);
let mut lw = Lw {
s,
ssa: Ssa::new(i32),
init: Init { io: Some(io), compute: None, vgpr_base: None, entry: Block(0), touched: BTreeSet::new() },
wave64: o.wave64,
split,
lane: z,
lane31: z,
upper: z,
half: z,
mems,
heap_mem,
res,
fmt_table: None,
fmt_desc_cache: HashMap::new(),
fmt_comp1_cache: HashMap::new(),
uma_base_val: None,
ntmp: 0,
scratch: None,
static_samplers: Default::default(),
static_used: Vec::new(),
sampler_base: o.sampler_base,
dyn_rm: false,
has_f64_round_op: false,
exec_cache: HashMap::new(),
xs: None,
xw: None,
xc: None,
waves: 1,
cw: z,
xn: z,
xslot: 1,
lds: None,
lds_top: 8191,
dpp_enable: None,
partner: Partner::Present,
mesh: None,
gfx: None,
gfx_half: None,
whole_live: Default::default(),
guard_override: None,
mask_override: None,
exchange_error: None,
pc: 0,
};
{
let Lw { s, ssa, init, .. } = &mut lw;
ssa.expect_preds(s, Block(0), 0, &mut |s, v| init.load(s, v));
}
// LDS and the split form's exchange slot size (16 words for a coherent s_load_dwordx16,
// 32 for ds_bpermute), as the HLSL kernel sizes them
let mut uses_lds = false;
let mut slot = 1u32;
for d in insts {
let n = d.inst.name;
if d.enc.name == "ENC_DS" && !matches!(n, "DS_SWIZZLE_B32" | "DS_BPERMUTE_B32" | "DS_PERMUTE_B32" | "DS_NOP") {
uses_lds = true;
}
if n == "DS_BPERMUTE_B32" {
slot = slot.max(32);
}
if d.enc.name == "ENC_SMEM" && ["GLC", "DLC"].iter().any(|f| crate::gpu::rdna2::field_value(d.enc, &d.words, f) == Some(1)) {
let w = match n.rsplit('_').next().unwrap_or("") {
"DWORDX2" => 2,
"DWORDX4" => 4,
"DWORDX8" => 8,
"DWORDX16" => 16,
_ => 1,
};
slot = slot.max(w);
}
}
lw.static_samplers = crate::gpu::recomp::constant_samplers(insts, leaders);
let group_threads: Option<u32> = match entry {
Entry::Vertex(_) | Entry::Pixel(_) => None,
Entry::Kernel => None,
Entry::Compute(cs) => Some(cs.threads.iter().product()),
Entry::Mesh(ms) => Some(ms.threads),
};
if let (Some(t), true) = (group_threads, split) {
lw.waves = t.div_ceil(64).max(1);
}
if split && std::env::var_os("XCL_X64_ALL_MASKS").is_none() {
lw.whole_live = crate::gpu::recomp::x64_masks::by_pc(insts, kernel);
}
lw.setup_storage(uses_lds, if split { slot } else { 1 });
if let (Some(t), true) = (group_threads, split) {
lw.partner = match t {
0..=32 => Partner::Missing,
33..=64 => Partner::Present,
_ => Partner::Spin,
};
}
lw
}
.map_err(|e| format!("direct DXIL builder error: {e}"))?;
if cfg!(any(test, debug_assertions)) {
if let Err(e) = super::validate::validate(&c) {
let dis = super::validate::disassemble(&c).unwrap_or_else(|d| d);
return Err(format!("direct DXIL failed validation: {e}\n--- disassembly ---\n{dis}"));

/// The finished container and the static samplers the program bound, once every block
/// is closed: `numthreads` and the hardware wave size `hw` for a compute-like entry, the
/// stage's I/O for a VS / PS.
pub fn finish(mut self, numthreads: [u32; 3], hw: u32) -> Result<Kernel, String> {
if let Some(e) = self.exchange_error.take() {
return Err(e);
}
let stage = self.s.stage;
let c = if matches!(stage, Stage::Vertex | Stage::Pixel) {
let g = self.gfx.take().ok_or("graphics entry without graphics I/O")?;
let info = if stage == Stage::Pixel { super::graphics::StageInfo::Pixel { early_depth_stencil: false } } else { super::graphics::StageInfo::Vertex };
self.s.try_finish_graphics(g.io, info)
} else {
self.s.try_finish(numthreads, Some(hw))
}
.map_err(|e| format!("direct DXIL builder error: {e}"))?;
if cfg!(any(test, debug_assertions)) {
if let Err(e) = super::validate::validate(&c) {
let dis = super::validate::disassemble(&c).unwrap_or_else(|d| d);
return Err(format!("direct DXIL failed validation: {e}\n--- disassembly ---\n{dis}"));
}
}
Ok(Kernel { dxil: c, static_samplers: self.static_used.iter().map(|&(w, c, _)| (w, c)).collect() })
}
Ok(Kernel { dxil: c, static_samplers: lw.static_used.iter().map(|&(w, c, _)| (w, c)).collect() })
}

/// The kernel's epilogue: SGPRs and SCC from lane 0, every touched VGPR per lane.
Expand Down Expand Up @@ -415,7 +444,7 @@ fn store_registers(lw: &mut Lw, res: super::shader::RawUav) {

/// The compute entry's fixed registers (the HLSL compute mode's prologue): group ids
/// after the user SGPRs, TG_SIZE, SCC = 0, EXEC = the wave's threads, v0..v2 = thread id.
fn compute_init(lw: &mut Lw, cs: &CsInterface, tid: Value, gtid: [Value; 3]) {
pub fn compute_init(lw: &mut Lw, cs: &CsInterface, tid: Value, gtid: [Value; 3]) {
let mut sgpr = HashMap::new();
let mut next = cs.user_sgprs;
for k in 0..3 {
Expand Down Expand Up @@ -453,7 +482,7 @@ fn compute_init(lw: &mut Lw, cs: &CsInterface, tid: Value, gtid: [Value; 3]) {
/// The mesh entry's registers (the HLSL mesh mode's prologue): SGPRs from `io` with the
/// wave index in s3[27:24], SCC 0, EXEC = the wave's threads, v5 = group · threads + slot,
/// other VGPRs 0; and the record slots.
fn mesh_init(lw: &mut Lw, ms: &MsInterface, tid: Value, io: super::shader::RawUav) {
pub fn mesh_init(lw: &mut Lw, ms: &MsInterface, tid: Value, io: super::shader::RawUav) {
let lanes: u32 = if lw.wave64 { 64 } else { 32 };
let l = lw.c(lanes);
let wave = lw.bin(super::module::BinOp::UDiv, tid, l);
Expand Down
14 changes: 12 additions & 2 deletions crates/xcl/src/gpu/dxil/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,19 @@ impl Module {
/// Replaces every use of `old` by `new` in the entry's instructions and in
/// metadata (e.g. to drop a trivial phi). `old` itself stays in its block.
pub fn replace_all_uses(&mut self, old: Value, new: Value) {
self.replace_uses(&HashMap::from([(old, new)]));
}

/// `replace_all_uses` for every `old → new` of `map` in one pass over the module: a use
/// becomes the end of its chain (`a → b`, `b → c`: a use of `a` becomes `c`), as the same
/// calls one at a time in order would leave it.
pub fn replace_uses(&mut self, map: &HashMap<Value, Value>) {
if map.is_empty() {
return;
}
let r = |v: &mut Value| {
if *v == old {
*v = new;
while let Some(&n) = map.get(v) {
*v = n;
}
};
for inst in &mut self.insts {
Expand Down
Loading
Loading