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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ A gamepad is recommended ([Controls](#controls)). The game folder is never modif
| **Pipelines** | ✅ | PSOs from console shaders: VS+PS, CS, MS+PS, VS+GS+PS; root signature with the shaders' static samplers; non-blocking creation – a pipeline whose shaders are not compiled yet gets a stand-in at once and is built in the background | GPU tests drawing the game's own VS / PS pairs, also built in the background |
| **D3D12.X compute** | ✅ | console device slots, console descriptor heaps (T# / V# / S#), buffers at their console addresses, compute command lists recorded in the console format and replayed (tables, barriers, clears, copies) | the game's BVH builder and FSR 4 record and run through XCL |
| **D3D12.X graphics** | ✅ | device, resources and heaps (also placed in title memory), pipelines; the title's graphics command lists – draws, indirect draws, graphics root arguments, barriers, copies, clears – and command lists recorded by console code, replayed; `PresentX` and frame pacing into an XCL window | Minecraft Preview plays its worlds (millions of draws, none skipped); Fortnite and XDefiant draw their screens |
| **Textures** | ✅ | GFX10 tiling (all 14 2D swizzle modes, the 6 3D thick modes, linear), mip chains with mip tail, arrays, cubes and 3D textures → PC textures | 912 / 912 entries detiled in the tested retail archive; GPU upload bit exact in test fixtures |
| **Textures** | ✅ | GFX10 tiling (all 14 2D swizzle modes, the 6 3D thick modes, linear), mip chains with mip tail, arrays, cubes and 3D textures → PC textures; supported GPU-written title subresources copy back before their writer queue's title fence becomes visible | 912 / 912 entries detiled in the tested retail archive; GPU upload bit exact in test fixtures |
| **Ray tracing** | ✅ | BLAS / TLAS built on the GPU by the game's own XboxBvhBuilder; RDNA2 BVH node format; BVH intersection instructions emulated in shaders | GPU traversal = brute force reference; the game's builder output checked on the GPU |
| **Upscaling** | ✅ | the game's AMD FSR 4 console DLL (`amd_fidelityfx_upscaler_xbox.dll`): context, the 29 pipelines in the console driver's own container (FSPX) translated, a frame's 20 passes recorded and run on the GPU | end-to-end with the real DLL: a 1280×720 → 1920×1080 frame on an RX 9070, the input's gradient in the output |

Expand Down
9 changes: 8 additions & 1 deletion crates/xcl/src/hle/d3d12x/fence_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ impl FenceTable {
return;
}
if let Some(v) = unsafe { borrowed(fence, |f| f.GetCompletedValue()) } {
mirror.cell.0.store(v, Ordering::Release);
if super::title_textures::complete_fence_downloads(fence, v) {
mirror.cell.0.store(v, Ordering::Release);
}
}
}

Expand Down Expand Up @@ -153,6 +155,7 @@ fn event() -> usize {
let e = th::CreateEventW(std::ptr::null(), 0, 0, std::ptr::null()) as usize;
let spawned = std::thread::Builder::new().name("xcl-fences".into()).spawn(move || loop {
th::WaitForSingleObject(e as _, th::INFINITE);
super::title_textures::poll_fence_downloads();
table().refresh();
});
if let Err(err) = spawned {
Expand All @@ -162,6 +165,10 @@ fn event() -> usize {
})
}

pub(super) fn wake_event() -> HANDLE {
HANDLE(event() as *mut c_void)
}

unsafe fn borrowed<R>(fence: usize, f: impl FnOnce(&ID3D12Fence) -> R) -> Option<R> {
let p = fence as *mut c_void;
ID3D12Fence::from_raw_borrowed(&p).map(f)
Expand Down
2 changes: 1 addition & 1 deletion crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ fn new_queue_id(raw: usize) -> super::title_textures::WriterQueueId {
super::title_textures::WriterQueueId { raw, generation }
}

fn queue_identity(raw: usize) -> Option<super::title_textures::WriterQueueId> {
pub(super) fn queue_identity(raw: usize) -> Option<super::title_textures::WriterQueueId> {
LIVE_QUEUES.lock().unwrap().iter().find(|q| q.queue == raw).map(|q| q.id)
}

Expand Down
82 changes: 64 additions & 18 deletions crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,14 @@ pub(crate) unsafe fn native_queue_wait(queue: &ID3D12CommandQueue, fence: &ID3D1
})
}

pub(crate) unsafe fn native_fence_completed(fence: &ID3D12Fence) -> u64 {
let raw = fence.as_raw();
let slot = std::mem::offset_of!(ID3D12Fence_Vtbl, GetCompletedValue) / std::mem::size_of::<usize>();
type F = unsafe extern "system" fn(*mut c_void) -> u64;
let f: F = std::mem::transmute(if is_ext(vt(raw) as usize) { orig_fn(raw, slot) } else { *vt(raw).add(slot) });
f(raw)
}

#[cfg(test)]
pub(super) fn register_test_queue_vtable(ext: usize, add: bool) {
let mut tables = EXTS.lock().unwrap();
Expand Down Expand Up @@ -3043,7 +3051,7 @@ fn overrides(kind: Kind) -> Vec<(&'static str, usize)> {
Kind::PipelineState => v.push(("Release", pso_release as usize)),
Kind::DescriptorHeap => v.push(("Release", heap_release as usize)),
Kind::Heap => v.push(("Release", mem_heap_release as usize)),
Kind::Fence => v.push(("Signal", fence_signal as usize)),
Kind::Fence => v.extend_from_slice(&[("GetCompletedValue", fence_completed as usize), ("Signal", fence_signal as usize)]),
_ => {}
}
v
Expand Down Expand Up @@ -8830,21 +8838,40 @@ unsafe fn queue_dispatch(slot: usize, this: *mut c_void, a1: usize, a2: usize, a
let older = if shifted && slot >= 16 { slot - 2 } else if shifted { usize::MAX } else { slot };
let pc = |s: usize| orig_fn(this, s);
match older {
// Signal / Wait take a fence: anything else is not one of them
14 | 15 if is_fence(a1) => super::queue_submit::with(this as usize, || {
if older == 14 {
// Signal takes a fence: prepare outside the turn, then validate/insert atomically with it.
14 if is_fence(a1) => loop {
let prepared = super::title_textures::prepare_downloads(this);
let attempt = super::queue_submit::with(this as usize, || {
let downloads = match super::title_textures::submit_prepared_downloads(this, prepared) {
Ok(downloads) => downloads,
Err(super::title_textures::SubmitDownloadsError::Stale) => return Err(None),
Err(super::title_textures::SubmitDownloadsError::Failed(error)) => return Err(Some(error)),
};
super::list_x::break_cycles_before_title_signal(this as usize, a1, a2 as u64);
}
let f: unsafe extern "system" fn(*mut c_void, usize, usize) -> i32 = std::mem::transmute(pc(if older == 14 { PC_SIGNAL } else { PC_WAIT }));
let hr = f(this, a1, a2);
if hr >= 0 {
if older == 14 {
super::title_textures::tie_downloads(a1 as *mut c_void, a2 as u64, downloads);
let f: unsafe extern "system" fn(*mut c_void, usize, usize) -> i32 = std::mem::transmute(pc(PC_SIGNAL));
let hr = f(this, a1, a2);
if hr >= 0 {
super::fence_x::note_queue_signal(a1, a2 as u64);
super::list_x::note_title_queue_signal(this as usize, a1, a2 as u64);
} else {
super::fence_x::note_queue_wait(a1, a2 as u64);
super::list_x::note_title_queue_wait(this as usize, a1, a2 as u64);
}
Ok(hr as u32 as usize)
});
match attempt {
Ok(hr) => break hr,
Err(None) => continue,
Err(Some(error)) => {
crate::xlog_warn!("D3D12.X: {error}; title queue Signal not submitted");
break crate::util::E_FAIL as u32 as usize;
}
}
},
15 if is_fence(a1) => super::queue_submit::with(this as usize, || {
let f: unsafe extern "system" fn(*mut c_void, usize, usize) -> i32 = std::mem::transmute(pc(PC_WAIT));
let hr = f(this, a1, a2);
if hr >= 0 {
super::fence_x::note_queue_wait(a1, a2 as u64);
super::list_x::note_title_queue_wait(this as usize, a1, a2 as u64);
}
hr as u32 as usize
}),
Expand Down Expand Up @@ -8927,22 +8954,39 @@ queue_slots!(14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
/// nothing left Fortnite's render fences pending: its render thread waited, textures were
/// never released, and the garbage collector ended the game after 10 s.)
unsafe extern "system" fn q_signal_x(this: *mut c_void, fence: *mut c_void, value: u64, _flags: u32) -> HRESULT {
super::queue_submit::with(this as usize, || q_signal_x_serialized(this, fence, value))
loop {
let prepared = super::title_textures::prepare_downloads(this);
match super::queue_submit::with(this as usize, || q_signal_x_serialized(this, fence, value, prepared)) {
Ok(hr) => return hr,
Err(super::title_textures::SubmitDownloadsError::Stale) => continue,
Err(super::title_textures::SubmitDownloadsError::Failed(error)) => {
crate::xlog_warn!("D3D12.X: {error}; title queue SignalX not submitted");
return crate::util::E_FAIL;
}
}
}
}

unsafe fn q_signal_x_serialized(this: *mut c_void, fence: *mut c_void, value: u64) -> HRESULT {
unsafe fn q_signal_x_serialized(this: *mut c_void, fence: *mut c_void, value: u64, prepared: super::title_textures::PreparedDownloads) -> Result<HRESULT, super::title_textures::SubmitDownloadsError> {
const PC_SIGNAL: usize = 14;
let downloads = super::title_textures::submit_prepared_downloads(this, prepared)?;
super::list_x::break_cycles_before_title_signal(this as usize, fence as usize, value);
super::title_textures::tie_downloads(fence, value, downloads);
let f: unsafe extern "system" fn(*mut c_void, *mut c_void, u64) -> HRESULT = std::mem::transmute(orig_fn(this, PC_SIGNAL));
let hr = f(this, fence, value);
if hr >= 0 {
super::fence_x::note_queue_signal(fence as usize, value);
super::list_x::note_title_queue_signal(this as usize, fence as usize, value);
}
hr
Ok(hr)
}

/// Fence::Signal (CPU)
unsafe extern "system" fn fence_completed(this: *mut c_void) -> u64 {
let f: unsafe extern "system" fn(*mut c_void) -> u64 = std::mem::transmute(orig_fn(this, slot_of(this, "GetCompletedValue")));
super::title_textures::safe_fence_value(this as usize, f(this))
}

unsafe extern "system" fn fence_signal(this: *mut c_void, value: u64) -> HRESULT {
let f: unsafe extern "system" fn(*mut c_void, u64) -> HRESULT = std::mem::transmute(orig_fn(this, slot_of(this, "Signal")));
let hr = f(this, value);
Expand Down Expand Up @@ -9603,7 +9647,7 @@ mod readback_routing_tests {
mod queue_tests {
use super::*;
use std::mem::{offset_of, size_of};
use windows::Win32::Graphics::Direct3D12::ID3D12Fence_Vtbl;
use windows::Win32::Graphics::Direct3D12::{ID3D12CommandQueue_Vtbl, ID3D12Fence_Vtbl};

// a fake adopted queue: the extension vtable's word before slot 0 points at the PC table
unsafe extern "system" fn get_desc(_: *mut c_void, out: usize) -> usize {
Expand Down Expand Up @@ -9647,8 +9691,10 @@ mod queue_tests {
let mut pc = [0usize; 32];
pc[14] = signal as usize;
pc[18] = get_desc as usize;
let ext = [pc.as_ptr() as usize, 0];
let vtbl = ext.as_ptr() as usize + 8;
let mut ext = [0usize; 1 + size_of::<ID3D12CommandQueue_Vtbl>() / SLOT];
ext[0] = pc.as_ptr() as usize;
ext[1 + offset_of!(ID3D12CommandQueue_Vtbl, GetDesc) / SLOT] = get_desc as usize;
let vtbl = unsafe { ext.as_ptr().add(1) } as usize;
let mut obj = [vtbl];
let this = obj.as_mut_ptr() as *mut c_void;
// A valid minimal ID3D12Fence COM object while registered: if a parallel test inspects
Expand Down
Loading