Skip to content
Open
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 @@ -150,7 +150,7 @@ A gamepad is recommended ([Controls](#controls)). The game folder is never modif
| **Shader recompiler** | ✅ | RDNA2 → HLSL → DXIL: VS, PS, CS, mesh (NGG), GS; atomics, LDS, scratch, images, samplers incl. static ones, wave ops, ray-tracing instructions; structured control flow; parallel DXC, disk cache | 26 698 / 26 698 programs of the retail pack; 0 DXC errors on random samples; per-instruction GPU tests |
| **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 |
| **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 (including tile copies with console-placed buffers), 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 |
| **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
19 changes: 19 additions & 0 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const PC_RESET: usize = 10;
const PC_COPY_BUFFER_REGION: usize = 15;
const PC_COPY_TEXTURE_REGION: usize = 16;
const PC_COPY_RESOURCE: usize = 17;
const PC_COPY_TILES: usize = 18;
const PC_SET_PIPELINE_STATE: usize = 25;
const PC_RESOURCE_BARRIER: usize = 26;
const PC_IA_SET_INDEX_BUFFER: usize = 43;
Expand Down Expand Up @@ -4258,6 +4259,24 @@ pub(super) unsafe extern "system" fn copy_buffer_region_x(this: *mut c_void, dst
pc::<unsafe extern "system" fn(*mut c_void, usize, u64, usize, u64, u64)>(this, PC_COPY_BUFFER_REGION)(this, dst, dst_off + real::buffer_delta(dst), src, src_off + real::buffer_delta(src), n)
}

/// CopyTiles uses a byte offset into its linear buffer in either copy direction.
pub(super) unsafe extern "system" fn copy_tiles_x(
this: *mut c_void,
tiled: usize,
start: *const D3D12_TILED_RESOURCE_COORDINATE,
size: *const D3D12_TILE_REGION_SIZE,
buffer: usize,
buffer_offset: u64,
flags: D3D12_TILE_COPY_FLAGS,
) {
type CopyTiles = unsafe extern "system" fn(
*mut c_void, usize, *const D3D12_TILED_RESOURCE_COORDINATE, *const D3D12_TILE_REGION_SIZE,
usize, u64, D3D12_TILE_COPY_FLAGS,
);
let offset = buffer_offset.saturating_add(real::buffer_delta(buffer));
pc::<CopyTiles>(this, PC_COPY_TILES)(this, tiled, start, size, buffer, offset, flags);
}

/// `XCL_TRACE_FRAME` with a watched target (`present::watch_rt`): copies out of it – that
/// object, or another at its title address (the first 16)
unsafe fn trace_watched_copy(what: &str, dst: usize, src: usize) {
Expand Down
98 changes: 93 additions & 5 deletions crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,9 @@ unsafe fn class_for(obj: *mut c_void, orig: usize, kind: Kind) -> usize {
fn console_remap(kind: Kind) -> Vec<(usize, usize)> {
match kind {
Kind::CommandList => (28..=31).map(|x| (x, x + 24)).chain((32..=55).map(|x| (x, x - 4))).chain((104..=109).map(|x| (x, x - 44))).chain([(124, 77), (125, 78)]).collect(),
// the DMA list: Close / Reset, then the copy methods (XDefiant calls #12 with
// CopyTextureRegion's arguments): 11–14 = PC 15–18 (CopyBufferRegion, CopyTextureRegion,
// CopyResource, CopyTiles); what follows is not known yet (`console_extensions`)
Kind::DmaList => (11..=14).map(|x| (x, x + 4)).collect(),
// The DMA list: Close / Reset, then 11–13 = PC 15–17 (CopyBufferRegion,
// CopyTextureRegion, CopyResource). CopyTiles at #14 is handled in `console_slots`.
Kind::DmaList => (11..=13).map(|x| (x, x + 4)).collect(),
_ => Vec::new(),
}
}
Expand Down Expand Up @@ -983,7 +982,7 @@ fn console_slots(kind: Kind) -> Vec<(usize, usize)> {
Kind::CommandQueue => QUEUE_SLOTS.iter().enumerate().map(|(k, &f)| (QUEUE_FIRST + k, f as usize)).collect(),
Kind::DmaList => {
use super::list_x as l;
vec![(9, l::dma_close_x as usize), (10, l::reset_x as usize), (11, l::copy_buffer_region_x as usize), (12, l::copy_texture_region_x as usize), (13, l::copy_resource_x as usize)]
vec![(9, l::dma_close_x as usize), (10, l::reset_x as usize), (11, l::copy_buffer_region_x as usize), (12, l::copy_texture_region_x as usize), (13, l::copy_resource_x as usize), (14, l::copy_tiles_x as usize)]
}
Kind::CommandList => {
use super::bind as b;
Expand All @@ -994,6 +993,7 @@ fn console_slots(kind: Kind) -> Vec<(usize, usize)> {
(15, l::copy_buffer_region_x as usize),
(16, l::copy_texture_region_x as usize),
(17, l::copy_resource_x as usize),
(18, l::copy_tiles_x as usize),
(19, l::resolve_subresource_x as usize),
(51, l::clear_depth_stencil_x as usize),
(53, l::clear_uav_uint_x as usize),
Expand Down Expand Up @@ -7971,6 +7971,94 @@ mod readback_routing_tests {
assert!(slots.contains(&(54, l::clear_uav_float_x as usize)));
}

#[test]
fn console_copy_tiles_adjusts_only_the_linear_buffer_offset() {
type CopyTiles = unsafe extern "system" fn(
*mut c_void, usize, *const D3D12_TILED_RESOURCE_COORDINATE, *const D3D12_TILE_REGION_SIZE,
usize, u64, D3D12_TILE_COPY_FLAGS,
);

#[repr(C)]
struct FakeList {
vtable: *const usize,
copies: Vec<(usize, usize, usize, usize, u64, i32)>,
dispatch: Option<(u32, u32, u32)>,
}

unsafe extern "system" fn no_interface(_: *mut c_void, _: *const GUID, _: *mut *mut c_void) -> HRESULT {
E_NOINTERFACE
}
unsafe extern "system" fn release(_: *mut c_void) -> u32 { 0 }
unsafe extern "system" fn dispatch(list: *mut c_void, x: u32, y: u32, z: u32) {
(*list.cast::<FakeList>()).dispatch = Some((x, y, z));
}
unsafe extern "system" fn record_copy(
list: *mut c_void, tiled: usize, start: *const D3D12_TILED_RESOURCE_COORDINATE,
size: *const D3D12_TILE_REGION_SIZE, buffer: usize, offset: u64, flags: D3D12_TILE_COPY_FLAGS,
) {
(*list.cast::<FakeList>()).copies.push((tiled, start as usize, size as usize, buffer, offset, flags.0));
}

// The adopted class stores the original table beyond the lifetime of the fake list.
static NATIVE: OnceLock<[usize; 128 + MAX_SCAN]> = OnceLock::new();
let native = NATIVE.get_or_init(|| {
let mut vtable = [0; 128 + MAX_SCAN];
vtable[0] = no_interface as usize;
vtable[2] = release as usize;
vtable[14] = dispatch as usize;
vtable[18] = record_copy as usize;
vtable
});
let resources = [0u32; 3];
let [tiled, prefixed, plain] = [&resources[0], &resources[1], &resources[2]].map(|p| p as *const u32 as usize);
let start = D3D12_TILED_RESOURCE_COORDINATE::default();
let size = D3D12_TILE_REGION_SIZE { NumTiles: 1, ..Default::default() };
let to_tile = D3D12_TILE_COPY_FLAG_LINEAR_BUFFER_TO_SWIZZLED_TILED_RESOURCE;
let to_buffer = D3D12_TILE_COPY_FLAG_SWIZZLED_TILED_RESOURCE_TO_LINEAR_BUFFER;
let offset = 0x1000;
let delta = 0x1000;

// A delta on the tiled resource must never change the other resource's byte offset.
set_test_buffer_delta(tiled, Some(0x4000));
set_test_buffer_delta(prefixed, Some(delta));
let mut observed = Vec::new();
for (kind, slot) in [(Kind::CommandList, 18), (Kind::DmaList, 14)] {
let mut list = FakeList { vtable: native.as_ptr(), copies: Vec::new(), dispatch: None };
let ptr = (&mut list as *mut FakeList).cast::<c_void>();
unsafe {
adopt(ptr, kind);
// Select the console side of the split without registering a game code image.
let console = console_slots(kind).into_iter().find(|&(s, _)| s == slot).map(|(_, f)| f)
.unwrap_or_else(|| {
let pc = console_remap(kind).into_iter().find(|&(s, _)| s == slot).map_or(slot, |(_, p)| p);
orig_fn(ptr, pc)
});
let console: CopyTiles = std::mem::transmute(console);
console(ptr, tiled, &start, &size, prefixed, offset, to_tile);
console(ptr, tiled, &start, &size, prefixed, offset, to_buffer);
console(ptr, tiled, &start, &size, plain, offset, to_tile);
let host: CopyTiles = std::mem::transmute(*vt(ptr).add(18));
host(ptr, tiled, &start, &size, prefixed, offset, to_tile);
let host_dispatch: unsafe extern "system" fn(*mut c_void, u32, u32, u32) = std::mem::transmute(*vt(ptr).add(14));
host_dispatch(ptr, 1, 2, 3);
}
observed.push((kind, list.copies, list.dispatch));
}
set_test_buffer_delta(prefixed, None);
set_test_buffer_delta(tiled, None);

let args = |buffer, off, flags: D3D12_TILE_COPY_FLAGS| (tiled, &start as *const _ as usize, &size as *const _ as usize, buffer, off, flags.0);
for (kind, copies, dispatch) in observed {
assert_eq!(copies, [
args(prefixed, offset + delta, to_tile),
args(prefixed, offset + delta, to_buffer),
args(plain, offset, to_tile),
args(prefixed, offset, to_tile),
], "{kind:?}");
assert_eq!(dispatch, Some((1, 2, 3)), "{kind:?} host Dispatch");
}
}

/// Bug #6: `Kind::DmaList` must install `cl_release` so releasing a DMA command list removes
/// its entry from `list_x::LISTS`.
#[test]
Expand Down
Loading
Loading