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
7 changes: 7 additions & 0 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ fn translate_on_this_thread(code: &[u8], o: KernelOptions, entry: Entry, compact
None => Cfg::build(code)?,
};
let kernel = matches!(entry, Entry::Kernel);
let follow_loads = matches!(entry, Entry::Kernel | Entry::Compute(_));
let gfx = matches!(entry, Entry::Vertex(_) | Entry::Pixel(_));
let compute = matches!(entry, Entry::Compute(_));
let split = o.wave64 && o.split && !gfx;
Expand Down Expand Up @@ -288,6 +289,9 @@ fn translate_on_this_thread(code: &[u8], o: KernelOptions, entry: Entry, compact
lw.edge(Block(0), h0);
}
let switch = if two_phase { Some(lw.block(None)) } else { None };
// scalar loads the program repeats keep their first values (compute programs and kernels:
// the other stages enter their code by edges the CFG does not hold)
let reloads = if follow_loads { super::reload::analyze(&cfg) } else { Default::default() };
let mut gs_entry: Option<usize> = None;
if let Some(p) = &plan {
super::compact::emit(&mut lw, &cfg, p, h0, exit)?;
Expand Down Expand Up @@ -318,8 +322,10 @@ fn translate_on_this_thread(code: &[u8], o: KernelOptions, entry: Entry, compact
lw.wr(VAR_BUDGET, l);
}
for &i in &cfg.blocks[b].insts {
lw.reload = reloads.get(b, i);
lw.inst(&cfg.insts[i])?;
}
lw.reload = None;
match cfg.blocks[b].term {
Term::Jump(t) if es_block && in_gs(t) => {
// the ES's s_setpc_b64 into the GS: through the phase switch
Expand Down Expand Up @@ -466,6 +472,7 @@ impl Lw {
fmt_table: None,
fmt_desc_cache: HashMap::new(),
fmt_comp1_cache: HashMap::new(),
reload: None,
uma_base_val: None,
ntmp: 0,
scratch: None,
Expand Down
3 changes: 3 additions & 0 deletions crates/xcl/src/gpu/dxil/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ pub struct Lw {
pub uma_base_val: Option<Value>,
/// temporaries handed out (`lower_mem::VAR_TMP`)
pub ntmp: u32,
/// the `s_load_dword*` being lowered repeats an earlier one (`reload`): set by the
/// translator's loop for that instruction
pub reload: Option<super::reload::Reload>,
/// the lane's scratch array (an alloca in the entry block)
pub scratch: Option<Value>,
/// MIMG instructions (pc) whose S# is built from constants in the code: the HLSL
Expand Down
15 changes: 15 additions & 0 deletions crates/xcl/src/gpu/dxil/lower_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,15 @@ impl Lw {
})
.collect::<Vec<_>>()
} else {
// a repeat of a load nothing has changed since: its values (`reload`)
let slot = self.reload.map(|r| super::reload::VAR_RELOAD + 16 * r.slot);
if let (Some(var), Some(true)) = (slot, self.reload.map(|r| r.available)) {
for i in 0..count {
let v = self.rd(var + i);
self.write32(&Dst::S(sdata + i as u64), v);
}
return Ok(());
}
let imm = ((imm << 11) as i32 >> 11) as u32;
let b = self.sreg(sbase);
let hi = self.sreg(sbase + 1);
Expand Down Expand Up @@ -1122,6 +1131,12 @@ impl Lw {
*v = self.sel(up, o, *v);
}
}
// (only an `s_load_dword*` without GLC / DLC has a slot)
if let Some(r) = self.reload {
for (i, &v) in vals.iter().enumerate() {
self.wr(super::reload::VAR_RELOAD + 16 * r.slot + i as u32, v);
}
}
for (i, v) in vals.into_iter().enumerate() {
self.write32(&Dst::S(sdata + i as u64), v);
}
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 @@ -32,6 +32,7 @@ pub mod module;
pub mod ops;
pub mod ops_core;
mod prelude;
pub mod reload;
pub mod shader;
pub mod ssa;
pub mod validate;
Expand Down
Loading
Loading