Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bd5dbe6
DirectStorage: a queue made with AutoSubmitDisabled waits for Submit
mgrein Nov 24, 2026
3efa98d
DirectStorage: read a physical-page list again when its request runs
mgrein Nov 24, 2026
bf0369c
D3D12.X: prepare for the unified memory copy path
vakaobr Nov 24, 2026
6777e26
D3D12.X: the committed window gets a copy in video memory (#258)
vakaobr Nov 24, 2026
ea0821b
D3D12.X: a copy back after a submission does not wait for the title
Ariorh1337 Nov 25, 2026
bd6f6e2
D3D12.X: a copy back runs on the title's own queue with that queue's …
theaustinayers Nov 25, 2026
0e5aa99
D3D12.X: XCL's own fence queries do not go through the title's settle…
theaustinayers Nov 25, 2026
bb6f091
D3D12.X: a wait for the tile queue is not ended by another wait's eve…
theaustinayers Nov 25, 2026
15da968
D3D12.X: immediates into the mirrored window are stored by XCL at the…
theaustinayers Nov 25, 2026
6069ade
D3D12.X: a counter cell keeps its later value; page history for crash…
theaustinayers Nov 25, 2026
5a610a3
Tests: keep sparse readbacks on their submitting queues
Filip722 Nov 25, 2026
920205c
D3D12.X: queue progress diagnostics for sync watchdog
ZekkJJ Nov 25, 2026
ee0183f
D3D12.X: a compute pipeline's driver blob reaches the disk cache alth…
theaustinayers Nov 24, 2026
deefc37
D3D12.X: the wait-for edges of the sync graph at a GPU wait time-out …
theaustinayers Nov 25, 2026
3ce0068
D3D12.X: XCL_GPU_PROFILE logs the console programs that take GPU time
wondercrash Nov 24, 2026
8ea4c75
Recompiler: emit globallycoherent on compute memory windows only when…
certified-retart Nov 24, 2026
99300e8
D3D12.X: share pending async shader blobs (#827, preserving #1941 and…
ZekkJJ Nov 25, 2026
28da721
D3D12.X: release idle shader blobs and cancelled PSO jobs
ZekkJJ Nov 25, 2026
d0f8774
D3D12.X: test small texture packing with fence-held slots
ZekkJJ Nov 25, 2026
01b6a34
D3D12.X: preserve the NVIDIA world-streaming integration
ZekkJJ Nov 25, 2026
f614add
DirectStorage: preserve stack destination page snapshots
ZekkJJ Nov 25, 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
17 changes: 17 additions & 0 deletions crates/xcl/src/eh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ unsafe extern "system" fn unhandled_filter(info: *const EXCEPTION_POINTERS) -> i
modules::describe_address(addr)
);
crate::xlog_error!("{msg}");
// what happened lately at the title pages the registers point into
if !ctx.is_null() {
let c = &*ctx;
let mut seen: Vec<usize> = Vec::new();
for (n, v) in [("rax", c.Rax), ("rbx", c.Rbx), ("rcx", c.Rcx), ("rdx", c.Rdx), ("rsi", c.Rsi), ("rdi", c.Rdi), ("rbp", c.Rbp), ("r8", c.R8), ("r9", c.R9), ("r10", c.R10), ("r11", c.R11), ("r12", c.R12), ("r13", c.R13), ("r14", c.R14), ("r15", c.R15)] {
let p = v as usize;
if p < 0x1_0000 || seen.contains(&(p & !0xFFFF)) {
continue;
}
seen.push(p & !0xFFFF);
let d = crate::hle::kernelx::pagelog::describe(p);
if !d.is_empty() {
crate::xlog_error!("page of {n}={p:#x}: {d}");
}
}
crate::xlog_error!("page events so far: {}", crate::hle::kernelx::pagelog::counts());
}
crate::report::write_final(Some(msg));
crate::log::flush();
}
Expand Down
5 changes: 3 additions & 2 deletions crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct KernelOptions {
/// identity (`recomp::pso`): bump it when `pso::direct_compute` / `direct_graphics` change the
/// containers. An edit of `gpu/dxil` needs no bump, `XCL_DIRECT_DXIL_SOURCE_ID` is its hash
/// (the `gpu/dxil` sources are not in build.rs's translator source hash).
pub const TRANSLATOR_VERSION: u32 = 9;
pub const TRANSLATOR_VERSION: u32 = 10;

/// `XCL_DIRECT_DXIL=1`: console compute shaders (and the kernel tests) go through this
/// translator, with the HLSL path as the fallback for what it cannot translate yet.
Expand Down Expand Up @@ -447,7 +447,8 @@ impl Lw {
if stage == Stage::Pixel && uses_pops(insts) {
s.enable_rov();
}
let (mems, heap_mem) = mem_windows(&mut s, o.mem_windows, cs.is_some());
let coherent = cs.is_some() && crate::gpu::recomp::needs_coherent_mem(insts);
let (mems, heap_mem) = mem_windows(&mut s, o.mem_windows, coherent);
let i32 = s.m.i32();
let z = s.m.i32c(0);
let mut lw = Lw {
Expand Down
10 changes: 7 additions & 3 deletions crates/xcl/src/gpu/recomp/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub(super) struct Em {
/// LDS arrival barrier (`xcl_s_barrier`) so RDNA2 early `s_endpgm`, `LOOP_GUARD` exits,
/// or split-wave64 desyncs cannot permanently hang an NVIDIA SM at `bar.sync`.
safe_barrier: bool,
/// compute program needs `globallycoherent` on flat memory windows (`needs_coherent_mem`)
pub coherent_mem: bool,
}

/// Instructions without an effect in this execution model.
Expand Down Expand Up @@ -594,6 +596,7 @@ impl Em {
dynamic_f16_rm: false,
track_frexp_denorm: false,
safe_barrier: false,
coherent_mem: false,
}
}

Expand Down Expand Up @@ -4658,8 +4661,9 @@ impl Em {
h.push_str("RWByteAddressBuffer io : register(u0);\nRWByteAddressBuffer res : register(u1);\n");
// compute work across workgroups (bottom-up BVH builds: atomics, then reading what
// other groups wrote) relies on GLC / cache invalidation on the console: keep the flat
// memory coherent across the GPU there; graphics keeps the cached (faster) view
let coherent = if matches!(self.opt.mode, Mode::Compute(_)) { "globallycoherent " } else { "" };
// memory coherent across the GPU only when the program actually uses those; otherwise
// keep the cached (faster) view
let coherent = if self.coherent_mem { "globallycoherent " } else { "" };
let max_win = if self.opt.heap_windows { crate::gpu::uma::MAX_HEAP_WINDOWS as u32 } else { crate::gpu::uma::MAX_WINDOWS as u32 };
let windows = self.opt.mem_windows.clamp(1, max_win);
let _ = writeln!(h, "{coherent}RWByteAddressBuffer mem : register(u2);");
Expand Down Expand Up @@ -5127,7 +5131,7 @@ impl Em {
}
}
if windows > 1 {
let coherent = if matches!(self.opt.mode, Mode::Compute(_)) { "globallycoherent " } else { "" };
let coherent = if self.coherent_mem { "globallycoherent " } else { "" };
h = windowed(&h, windows, self.opt.heap_windows.then_some(coherent));
}
h
Expand Down
2 changes: 1 addition & 1 deletion crates/xcl/src/gpu/recomp/lower_dxil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct DxilIr {

impl DxilIr {
/// The builder state for `insts` at `entry` (a kernel or a compute program), with one memory
/// window; a compute program's is coherent, as the HLSL path declares it.
/// window; a compute program's is coherent when `needs_coherent_mem` holds, matching the HLSL path.
fn new(insts: &[Decoded], wave64: bool, entry: &Entry) -> DxilIr {
Self::with(insts, KernelOptions { wave64, split: false, mem_windows: 1, sampler_base: 0 }, entry)
}
Expand Down
29 changes: 29 additions & 0 deletions crates/xcl/src/gpu/recomp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,34 @@ pub(crate) fn constant_samplers(insts: &[Decoded], leaders: &BTreeSet<u64>) -> B
out
}

/// Does the program require `globallycoherent` flat memory windows (`mem`, `mem1`…)?
///
/// Compute work that coordinates across workgroups (e.g. bottom-up BVH builds: atomics,
/// then reading what other groups wrote) relies on `GLC`/`DLC`/`SLC`, memory atomics, or
/// cache invalidation on the console. Programs without any of those only access read-only
/// or disjointly written memory within the dispatch, so keeping their flat memory windows
/// un-qualified lets the GPU cache them in L1.
pub(crate) fn needs_coherent_mem(insts: &[Decoded]) -> bool {
insts.iter().any(|d| {
let name = d.inst.name;
if matches!(name, "S_DCACHE_INV" | "S_GL1_INV" | "BUFFER_GL0_INV" | "BUFFER_GL1_INV") {
return true;
}
if name.starts_with("BUFFER_ATOMIC_")
|| name.starts_with("GLOBAL_ATOMIC_")
|| name.starts_with("FLAT_ATOMIC_")
{
return true;
}
matches!(
d.enc.name,
"ENC_SMEM" | "ENC_MUBUF" | "ENC_MTBUF" | "ENC_FLAT" | "ENC_FLAT_GLBL"
) && ["GLC", "DLC", "SLC"]
.iter()
.any(|f| rdna2::field_value(d.enc, &d.words, f) == Some(1))
})
}

pub fn translate(code: &[u8], opt: &Options) -> Result<Translation, String> {
let program = code;
let normalized;
Expand Down Expand Up @@ -1433,6 +1461,7 @@ pub fn translate(code: &[u8], opt: &Options) -> Result<Translation, String> {
}
}
let mut em = emit::Em::new(opt.clone());
em.coherent_mem = matches!(opt.mode, Mode::Compute(_)) && needs_coherent_mem(&insts);
em.configure_round_modes(&insts, branches == 0);
em.static_ss = constant_samplers(&insts, &leaders);
// split wave64: masks only read lane by lane skip the halves' exchange (geometry mode
Expand Down
15 changes: 15 additions & 0 deletions crates/xcl/src/gpu/recomp/pso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,21 @@ pub fn compute_user_sgprs(blob: &[u8]) -> Option<u32> {
}
}

/// A console compute shader's thread group size, whether its program is wave64 and the bytes
/// of its RDNA2 code (`XCL_GPU_PROFILE` names a program by them). None: not a console compute
/// shader.
pub fn compute_shape(blob: &[u8]) -> Option<([u32; 3], bool, usize)> {
if let Some(f) = fspx(blob) {
return Some((f.threads, super::detect_wave64(f.code), f.code.len()));
}
let sh = xbox::parse(blob)?;
let f = sh.fssm.iter().find(|f| f.stages.first().is_some_and(|s| s.hw == 6))?;
let Mode::Compute(cs) = interface(blob, &sh, f)? else { return None };
let p = f.programs.first()?;
let code = f.data.get(p.offset..p.offset + p.len)?;
Some((cs.threads, super::detect_wave64(code), code.len()))
}

/// The HLSL and profile a console program compiles from at pipeline creation (for
/// `xcl shaders --export-hlsl`: compile-time investigations outside a title).
pub fn console_hlsl(blob: &[u8], stage: Stage, windows: u32, split_wave64: bool) -> Result<(String, &'static str), String> {
Expand Down
75 changes: 55 additions & 20 deletions crates/xcl/src/gpu/recomp/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,22 +1476,39 @@ fn run_in_region(dxil: &[u8], state: &KernelState, arena: &Arena) -> Result<Kern
let dev = &gpu.dev;
let dev3: ID3D12Device3 = dev.cast().map_err(e)?;
let mut bufs: Vec<ID3D12Resource> = Vec::new();
// a D3D12 without heaps over process memory (D3DMetal: E_NOTIMPL): each window is a
// buffer in video memory, filled from the window before the dispatch and copied back
// after it -- (upload, readback) per window
let mut copies: Vec<(ID3D12Resource, ID3D12Resource)> = Vec::new();
for &(base, size) in &arena.windows {
let heap: ID3D12Heap = dev3.OpenExistingHeapFromAddress(base as *const std::ffi::c_void).map_err(|x| format!("OpenExistingHeapFromAddress: {x}"))?;
let desc = D3D12_RESOURCE_DESC {
Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
Width: size as u64,
Height: 1,
DepthOrArraySize: 1,
MipLevels: 1,
SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
Flags: D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER,
..Default::default()
};
let mut mem_buf: Option<ID3D12Resource> = None;
dev.CreatePlacedResource(&heap, 0, &desc, D3D12_RESOURCE_STATE_COMMON, None, &mut mem_buf).map_err(|x| format!("CreatePlacedResource: {x}"))?;
bufs.push(mem_buf.ok_or("arena")?);
let heap: ID3D12Heap = match dev3.OpenExistingHeapFromAddress(base as *const std::ffi::c_void) {
Ok(h) => h,
Err(x) if x.code() == windows::Win32::Foundation::E_NOTIMPL => {
let up = buffer(dev, size as u64, D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ, false)?;
let mut p = std::ptr::null_mut();
up.Map(0, None, Some(&mut p)).map_err(e)?;
std::ptr::copy_nonoverlapping(base, p as *mut u8, size);
up.Unmap(0, None);
bufs.push(buffer(dev, size as u64, D3D12_HEAP_TYPE_DEFAULT, D3D12_RESOURCE_STATE_COMMON, true)?);
copies.push((up, buffer(dev, size as u64, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST, false)?));
continue;
}
Err(x) => return Err(format!("OpenExistingHeapFromAddress: {x}")),
};
let desc = D3D12_RESOURCE_DESC {
Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
Width: size as u64,
Height: 1,
DepthOrArraySize: 1,
MipLevels: 1,
SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
Flags: D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER,
..Default::default()
};
let mut mem_buf: Option<ID3D12Resource> = None;
dev.CreatePlacedResource(&heap, 0, &desc, D3D12_RESOURCE_STATE_COMMON, None, &mut mem_buf).map_err(|x| format!("CreatePlacedResource: {x}"))?;
bufs.push(mem_buf.ok_or("arena")?);
}
let mem_buf = bufs[0].clone();
let pso: ID3D12PipelineState = dev
Expand All @@ -1514,13 +1531,18 @@ fn run_in_region(dxil: &[u8], state: &KernelState, arena: &Arena) -> Result<Kern
let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).map_err(e)?;
let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &alloc, &pso).map_err(e)?;
list.CopyBufferRegion(&io_buf, 0, &upload, 0, io_bytes);
// (a buffer in COMMON takes the copy as it is)
for (b, (up, _)) in bufs.iter().zip(&copies) {
list.CopyBufferRegion(b, 0, up, 0, b.GetDesc().Width);
}
let filled = if copies.is_empty() { D3D12_RESOURCE_STATE_COMMON } else { D3D12_RESOURCE_STATE_COPY_DEST };
list.ResourceBarrier(&[
transition(&io_buf, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
transition(&res_buf, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
transition(&mem_buf, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
transition(&mem_buf, filled, D3D12_RESOURCE_STATE_UNORDERED_ACCESS),
]);
for b in &bufs[1..] {
list.ResourceBarrier(&[transition(b, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_UNORDERED_ACCESS)]);
list.ResourceBarrier(&[transition(b, filled, D3D12_RESOURCE_STATE_UNORDERED_ACCESS)]);
}
// the windows as raw UAVs at MEM_HEAP_BASE.. of a shader-visible heap
// (`Options::heap_windows`; programs with the root-UAV switch ignore it)
Expand Down Expand Up @@ -1548,18 +1570,28 @@ fn run_in_region(dxil: &[u8], state: &KernelState, arena: &Arena) -> Result<Kern
list.SetComputeRootUnorderedAccessView(2 + k as u32, bufs.get(k).unwrap_or(&mem_buf).GetGPUVirtualAddress());
}
list.Dispatch(1, 1, 1);
let after = if copies.is_empty() { D3D12_RESOURCE_STATE_COMMON } else { D3D12_RESOURCE_STATE_COPY_SOURCE };
list.ResourceBarrier(&[
transition(&res_buf, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE),
transition(&mem_buf, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COMMON),
transition(&mem_buf, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, after),
]);
for b in &bufs[1..] {
list.ResourceBarrier(&[transition(b, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COMMON)]);
list.ResourceBarrier(&[transition(b, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, after)]);
}
list.CopyBufferRegion(&readback, 0, &res_buf, 0, res_bytes);
for (b, (_, back)) in bufs.iter().zip(&copies) {
list.CopyBufferRegion(back, 0, b, 0, b.GetDesc().Width);
}
list.Close().map_err(e)?;
gpu.queue.ExecuteCommandLists(&[Some(list.cast().map_err(e)?)]);
gpu.value += 1;
wait_for_submission(dev, &gpu.queue, &gpu.fence, gpu.value, "arena dispatch")?;
for (&(base, size), (_, back)) in arena.windows.iter().zip(&copies) {
let mut q = std::ptr::null_mut();
back.Map(0, None, Some(&mut q)).map_err(e)?;
std::ptr::copy_nonoverlapping(q as *const u8, base, size);
back.Unmap(0, None);
}
let mut q = std::ptr::null_mut();
readback.Map(0, None, Some(&mut q)).map_err(e)?;
let raw = std::slice::from_raw_parts(q as *const u32, KERNEL_RES_DWORDS).to_vec();
Expand Down Expand Up @@ -1707,7 +1739,10 @@ fn dispatch_with(
list.SetComputeRootSignature(rs);
list.SetComputeRootUnorderedAccessView(0, io_buf.GetGPUVirtualAddress());
list.SetComputeRootUnorderedAccessView(1, res_buf.GetGPUVirtualAddress());
list.SetComputeRootUnorderedAccessView(2, mem_buf.GetGPUVirtualAddress());
// every window (u2..u5) is `mem`, as in the heap above
for k in 2..6 {
list.SetComputeRootUnorderedAccessView(k, mem_buf.GetGPUVirtualAddress());
}
// `reps` dispatches, each between two timestamps when `timed`
let stamps = 2 * reps as u32;
let queries = if timed {
Expand Down
Loading
Loading