Skip to content
Draft
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ Fill the reusable DXIL cache ahead of a run with the read-only package wrapper.
for a `Wait32BitValueX` / `Wait64BitValueX` that nothing satisfies (2000 ms) and the
watchdog for a GPU queue wait (5000 ms). A value that is not a number above 0 keeps the
default.
- Retired two-pass mesh buffers from tracked command lists can be reused once all GPU
submissions that used them complete, even while the title still holds the command allocator.
- Direct two-pass mesh draws can reuse one smaller record buffer across several slices when
the memory cap is tight. Each slice keeps the draw's original mesh group IDs.
- Translated shaders are reused across XCL rebuilds when the translator sources and DXC
toolchain are unchanged; `XCL_TRANSLATED_CACHE=0` disables that disk cache.
- Direct compute dispatches can split large programs into pipelines built in parallel.
Expand Down
5 changes: 4 additions & 1 deletion crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,10 @@ pub fn mesh_init(lw: &mut Lw, ms: &MsInterface, tid: Value, io: super::shader::R
sgpr.insert(126, lo);
sgpr.insert(127, hi);
let kt = lw.c(ms.threads);
let g = lw.mul(gid, kt);
let group_base_offset = lw.c((crate::gpu::recomp::IO_MESH_GROUP_BASE * 4) as u32);
let group_base = lw.s.raw_load(io, group_base_offset, 1)[0];
let console_gid = lw.add(gid, group_base);
let g = lw.mul(console_gid, kt);
let v5 = lw.add(g, slot);
let mut vgpr = HashMap::new();
vgpr.insert(5, v5);
Expand Down
6 changes: 5 additions & 1 deletion crates/xcl/src/gpu/recomp/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5180,7 +5180,11 @@ static uint xcl_cap = 1u << 16;
}
let _ = writeln!(h, " uint scc = 0u;\n {{ uint2 e0 = {}(true); exec_lo = e0.x; exec_hi = e0.y; }}", self.ballot_fn());
for &v in &self.vgprs {
let init = if v == 5 { format!("gid.x * {t}u + xcl_slot") } else { "0u".into() };
let init = if v == 5 {
format!("(gid.x + io.Load({}u)) * {t}u + xcl_slot", super::IO_MESH_GROUP_BASE * 4)
} else {
"0u".into()
};
let _ = writeln!(h, " uint v{v} = {init};");
}
h.push_str(body);
Expand Down
3 changes: 3 additions & 0 deletions crates/xcl/src/gpu/recomp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ pub const CODE_ADDRESS_HI: u32 = 0xC0DE;
pub const IO_THREAD_LIMIT: [usize; 3] = [115, 116, 117];
const _: () = assert!(IO_THREAD_LIMIT[1] == IO_THREAD_LIMIT[0] + 1 && IO_THREAD_LIMIT[2] == IO_THREAD_LIMIT[0] + 2);

/// First console mesh group in this dispatch slice. Record indices always start at zero.
pub const IO_MESH_GROUP_BASE: usize = 118;

impl GsInterface {
/// bytes of one ES vertex in LDS (ESGS item: 16 per ES output register)
pub fn es_item_bytes(&self) -> u32 {
Expand Down
24 changes: 24 additions & 0 deletions crates/xcl/src/gpu/recomp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3699,6 +3699,30 @@ fn gpu_mesh_mode_two_passes() {
}
assert_eq!(r[MESH_HEADER + 128 * vd], 1 << 10 | 2 << 20, "group {g} primitive");
}
// A slice starting at group 1 must produce that group's geometry in record 0.
let mut sliced_sg = sg.clone();
sliced_sg[super::IO_MESH_GROUP_BASE] = 1;
let ref_group = &rec[rd..2 * rd];
let check_slice = |shader: &[u8]| {
let (_, record) = runner::mesh_draw(shader, &msb, &ps, 1, rd, &sliced_sg, &mem, 32, [-1.0; 4]).unwrap();
assert_eq!(&record[..2], &ref_group[..2]);
let vertices = MESH_HEADER..MESH_HEADER + 3 * vd;
assert_eq!(&record[vertices.clone()], &ref_group[vertices]);
assert_eq!(record[MESH_HEADER + 128 * vd], ref_group[MESH_HEADER + 128 * vd]);
};
check_slice(&cs);
// The direct backend rejects barriers across hardware waves. This fixture has no
// cross-wave dependency in its record writes, so it can use the same shader without it.
let direct_ops: Vec<_> = refs.iter().copied().filter(|(op, ..)| *op != "S_BARRIER").collect();
let direct = crate::gpu::dxil::kernel::translate_mesh(
&prog(&direct_ops),
crate::gpu::dxil::kernel::KernelOptions {
wave64: opt.wave64, split: opt.split_wave64 || runner::split_wave64(),
mem_windows: opt.mem_windows, sampler_base: opt.static_sampler_base,
},
&ms,
).unwrap();
check_slice(&direct.dxil);
let at = |x: usize, y: usize| px[y * 32 + x];
assert_eq!((at(3, 29)[0], at(3, 29)[3]), (0.0, 1.0), "group 0 triangle (left)");
assert_eq!((at(19, 29)[0], at(19, 29)[3]), (1.0, 1.0), "group 1 triangle (right)");
Expand Down
32 changes: 29 additions & 3 deletions crates/xcl/src/hle/d3d12x/alloc_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,23 +285,46 @@ pub fn in_flight(list: usize) -> bool {

/// `lists` were just submitted to `queue`.
pub unsafe fn executed(queue: *mut c_void, lists: &[*mut c_void]) {
if !enabled() || queue.is_null() {
if queue.is_null() {
return;
}
if !enabled() {
if !lists.is_empty() {
super::bind::two_pass_submitted(queue, None, 0, lists);
}
super::bind::poll_two_pass_feedback(queue);
return;
}
// (every submit is marked, also of lists this module does not track – the PC lists behind
// console lists – so note_resubmits sees them all)
let mut g = STATE.lock().unwrap();
let s = g.get_or_insert_with(State::default);
let Some(q) = ID3D12CommandQueue::from_raw_borrowed(&queue) else { return };
let Some(q) = ID3D12CommandQueue::from_raw_borrowed(&queue) else {
drop(g);
if !lists.is_empty() {
super::bind::two_pass_submitted(queue, None, 0, lists);
}
return;
};
let key = queue as usize;
if !s.fences.contains_key(&key) {
let mut dev: Option<ID3D12Device> = None;
let Some(f) = q.GetDevice(&mut dev).ok().and(dev).and_then(|d| d.CreateFence::<ID3D12Fence>(0, D3D12_FENCE_FLAG_NONE).ok()) else { return };
let Some(f) = q.GetDevice(&mut dev).ok().and(dev).and_then(|d| d.CreateFence::<ID3D12Fence>(0, D3D12_FENCE_FLAG_NONE).ok()) else {
drop(g);
if !lists.is_empty() {
super::bind::two_pass_submitted(queue, None, 0, lists);
}
return;
};
s.fences.insert(key, (f, 0));
}
let (fence, value) = {
let (f, v) = s.fences.get_mut(&key).unwrap();
if q.Signal(&*f, *v + 1).is_err() {
drop(g);
if !lists.is_empty() {
super::bind::two_pass_submitted(queue, None, 0, lists);
}
return;
}
*v += 1;
Expand All @@ -314,6 +337,9 @@ pub unsafe fn executed(queue: *mut c_void, lists: &[*mut c_void]) {
let recording = s.recordings.get(&(l as usize)).copied().unwrap_or(0);
s.last_submit.insert(l as usize, LastSubmit { queue: key, fence: fence.clone(), value, recording });
}
drop(g);
super::bind::two_pass_submitted(queue, Some(&fence), value, lists);
super::bind::poll_two_pass_feedback(queue);
}

/// The lists recording on the PC allocators of `alloc` hold them no more: the allocator a title
Expand Down
Loading
Loading