From 172b0bd6202b8ec184b81f2c34ea6ffc8715b9d0 Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Sat, 28 Nov 2026 03:54:12 +0000 Subject: [PATCH] D3D12.X: console device slots for the *1 / *2 resource methods use the console's descriptions The console device has the PC's newer device methods at fixed distances from their PC slots (#86, #108 and #127 are handled there already). Its resource and heap variants fell into the console-extension stub, which answers S_OK with the out pointer untouched, so a title got a NULL resource or heap, or no size, back: #92 CreateCommittedResource1 #93 CreateHeap1 #94 CreateReservedResource1 #95 GetResourceAllocationInfo1 #109 CreateCommittedResource2 #110 CreatePlacedResource1 #112 GetCopyableFootprints1 #128 CreatePlacedResource2 #129 CreateReservedResource2 Each now hands its console description to the console method of its base form (#27, #28, #30, #25, #29, #38): a DESC1's first 0x38 bytes are the console resource desc, a barrier layout becomes the state it starts in (as #127 / #133), and a protected session or castable formats are dropped. #95 shares #108's per-description loop, with its own stride (0x38 rather than 0x48). The identities are from a console API audit; no log yet shows a title calling these. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/device_x.rs | 85 ++++++++++++++++++++++++++- crates/xcl/src/hle/d3d12x/real.rs | 60 +++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/d3d12x/device_x.rs b/crates/xcl/src/hle/d3d12x/device_x.rs index f51d923633..84c4d2f529 100644 --- a/crates/xcl/src/hle/d3d12x/device_x.rs +++ b/crates/xcl/src/hle/d3d12x/device_x.rs @@ -1042,10 +1042,24 @@ fn allocation_of(parts: impl IntoIterator, mut placed: impl F /// each resource's {offset, alignment, size} goes to the last argument when there is one. pub(super) unsafe extern "system" fn get_resource_allocation_info2_x(a: *mut c_void, b: *mut c_void, mask: u32, n: u32, descs: *const [u8; 0x48], infos: *mut [u64; 3]) -> *mut [u64; 2] { real::note_newer_device_method(108); + allocation_info_each::<0x48>(a, b, mask, n, descs as *const u8, infos) +} + +/// device #95 GetResourceAllocationInfo1 (PC #56): as #108, with D3D12_RESOURCE_DESCs (0x38 +/// bytes each) rather than DESC1s. +pub(super) unsafe extern "system" fn get_resource_allocation_info1_x(a: *mut c_void, b: *mut c_void, mask: u32, n: u32, descs: *const [u8; 0x38], infos: *mut [u64; 3]) -> *mut [u64; 2] { + real::note_newer_device_method(95); + allocation_info_each::<0x38>(a, b, mask, n, descs as *const u8, infos) +} + +/// #95 / #108: each description (`STRIDE` bytes apart, the console resource desc first) asked +/// of #25 on its own, and where each goes in the whole written to `infos` ({offset, alignment, +/// size}). +unsafe fn allocation_info_each(a: *mut c_void, b: *mut c_void, mask: u32, n: u32, descs: *const u8, infos: *mut [u64; 3]) -> *mut [u64; 2] { let ret = if real::this_first(a, b) { b } else { a } as *mut [u64; 2]; let parts = (0..n as usize).map(|k| { let mut r = [0u64; 2]; - let d = if descs.is_null() { std::ptr::null() } else { descs.add(k) as *const [u8; 0x38] }; + let d = if descs.is_null() { std::ptr::null() } else { descs.add(k * STRIDE) as *const [u8; 0x38] }; let (x, y) = if real::this_first(a, b) { (a, &mut r as *mut _ as *mut c_void) } else { (&mut r as *mut _ as *mut c_void, b) }; get_resource_allocation_info_x(x, y, mask, 1, d); (r[0], r[1]) @@ -1276,6 +1290,25 @@ pub(super) fn layout_state(layout: u32) -> u32 { } } +/// device #112 GetCopyableFootprints1 (PC #72): #38 with a D3D12_RESOURCE_DESC1, whose first 0x38 +/// bytes are the console resource desc (the sampler-feedback mip region after them does not +/// change the footprints) +#[allow(clippy::too_many_arguments)] +pub(super) unsafe extern "system" fn get_copyable_footprints1_x( + this: *mut c_void, + desc: *const u8, + first: u32, + num: u32, + base: u64, + layouts: *mut c_void, + rows: *mut u32, + row_sizes: *mut u64, + total: *mut u64, +) { + real::note_newer_device_method(112); + get_copyable_footprints_x(this, desc, first, num, base, layouts, rows, row_sizes, total) +} + /// device #38 GetCopyableFootprints: a console resource desc the PC rejects (total stays /// UINT64_MAX) is asked again as the PC desc XCL creates for it #[allow(clippy::too_many_arguments)] @@ -1768,6 +1801,56 @@ mod tests { } } + /// #95 (D3D12_RESOURCE_DESCs, 0x38 bytes apart) and #108 (DESC1s, 0x48) ask #25 for each + /// description and lay the results out one after another. (The helper is called directly: + /// the slots also note the newer layout, a global the queue tests set.) + #[test] + fn newer_allocation_info_reads_each_description_at_its_stride() { + use windows::Win32::Foundation::LUID; + #[repr(C)] + struct FakeDev { vt: *const usize, luid: LUID, widths: Vec } + unsafe extern "system" fn check_feature(_: *mut c_void, _: D3D12_FEATURE, _: *mut c_void, _: u32) -> HRESULT { S_OK } + unsafe extern "system" fn adapter_luid(this: *mut c_void, out: *mut LUID) { *out = (*(this as *const FakeDev)).luid; } + unsafe extern "system" fn info(this: *mut c_void, ret: *mut [u64; 2], _: u32, _: u32, desc: *const [u8; 0x38]) -> *mut [u64; 2] { + let w = u64::from_le_bytes(desc.read_unaligned()[0x10..0x18].try_into().unwrap()); + (*(this as *mut FakeDev)).widths.push(w); + *ret = [w, 0x10000]; + ret + } + let mut orig_vt = [0usize; 44]; + (orig_vt[13], orig_vt[25], orig_vt[43]) = (check_feature as usize, info as usize, adapter_luid as usize); + let mut ext_buf = [0usize; 45]; + ext_buf[0] = orig_vt.as_ptr() as usize; + ext_buf[1..].copy_from_slice(&orig_vt); + let luid = LUID { LowPart: 0xD120_0095, HighPart: 0x5A17_0095 }; + let mut dev = FakeDev { vt: unsafe { ext_buf.as_ptr().add(1) }, luid, widths: Vec::new() }; + let this = &mut dev as *mut FakeDev as *mut c_void; + // two buffers, 0x1000 and 0x3000 bytes, at each stride + fn descs() -> [[u8; S]; 2] { + let mut d = [[0u8; S]; 2]; + for (k, w) in [0x1000u64, 0x3000].into_iter().enumerate() { + d[k][0] = 1; + d[k][0x10..0x18].copy_from_slice(&w.to_le_bytes()); + (d[k][0x18], d[k][0x1C], d[k][0x1E], d[k][0x24]) = (1, 1, 1, 1); + } + d + } + let want = ([0x20000u64, 0x10000], vec![[0u64, 0x10000, 0x1000], [0x10000, 0x10000, 0x3000]]); + unsafe { + let d1 = descs::<0x38>(); + let (mut ret, mut infos) = ([0u64; 2], vec![[0u64; 3]; 2]); + allocation_info_each::<0x38>(&mut ret as *mut _ as *mut c_void, this, 0, 2, d1.as_ptr() as *const u8, infos.as_mut_ptr()); + assert_eq!((ret, infos, std::mem::take(&mut dev.widths)), (want.0, want.1.clone(), vec![0x1000, 0x3000]), "#95: descs 0x38 apart"); + let d2 = descs::<0x48>(); + let (mut ret, mut infos) = ([0u64; 2], vec![[0u64; 3]; 2]); + allocation_info_each::<0x48>(&mut ret as *mut _ as *mut c_void, this, 0, 2, d2.as_ptr() as *const u8, infos.as_mut_ptr()); + assert_eq!((ret, infos, std::mem::take(&mut dev.widths)), (want.0, want.1, vec![0x1000, 0x3000]), "#108: descs 0x48 apart"); + } + if let Some(m) = UAV_FORMAT_SUPPORT.lock().unwrap().as_mut() { + m.retain(|k, _| k.0 != (luid.LowPart, luid.HighPart)); + } + } + #[test] fn get_copyable_footprints_x_strips_device_unsupported_uav_on_retry() { use windows::Win32::Foundation::LUID; diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 9238c582dc..eece67f4ae 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -1388,8 +1388,17 @@ fn console_slots(kind: Kind) -> Vec<(usize, usize)> { (80, super::frame::wait_frame_event_x as usize), (81, super::frame::frame_statistics_x as usize), (86, x::create_pipeline_state_x as usize), + (92, dev_create_committed_resource1_x as usize), + (93, dev_create_heap1_x as usize), + (94, dev_create_reserved_resource1_x as usize), + (95, x::get_resource_allocation_info1_x as usize), (108, x::get_resource_allocation_info2_x as usize), + (109, dev_create_committed_resource2_x as usize), + (110, dev_create_placed_resource1_x as usize), + (112, x::get_copyable_footprints1_x as usize), (127, dev_create_committed_resource_layout_x as usize), + (128, dev_create_placed_resource2_x as usize), + (129, dev_create_reserved_resource2_x as usize), (133, x::create_placed_resource_layout_x as usize), ] } @@ -3254,6 +3263,57 @@ unsafe extern "system" fn dev_create_committed_resource_layout_x( dev_create_committed_resource_x(this, props, flags as usize, desc, state, clear, riid, ppv) } +// The console device's *1 / *2 variants of the resource and heap methods (PC order, `console_remap`): +// the console description goes to the console method of the base form; a protected session and +// castable formats have no console meaning here and are dropped, a barrier layout becomes the +// resource state it starts in (as #127 / #133). + +/// device #92 CreateCommittedResource1 (PC #53) +#[allow(clippy::too_many_arguments)] +unsafe extern "system" fn dev_create_committed_resource1_x(this: *mut c_void, props: usize, flags: usize, desc: usize, state: usize, clear: usize, _session: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + note_newer_device_method(92); + dev_create_committed_resource_x(this, props, flags, desc, state, clear, riid, ppv) +} + +/// device #109 CreateCommittedResource2 (PC #69): a D3D12_RESOURCE_DESC1, the console desc first +#[allow(clippy::too_many_arguments)] +unsafe extern "system" fn dev_create_committed_resource2_x(this: *mut c_void, props: usize, flags: usize, desc: usize, state: usize, clear: usize, _session: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + note_newer_device_method(109); + dev_create_committed_resource_x(this, props, flags, desc, state, clear, riid, ppv) +} + +/// device #93 CreateHeap1 (PC #54) +unsafe extern "system" fn dev_create_heap1_x(this: *mut c_void, desc: usize, _session: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + note_newer_device_method(93); + dev_create_heap(this, desc, riid, ppv) +} + +/// device #94 CreateReservedResource1 (PC #55) +unsafe extern "system" fn dev_create_reserved_resource1_x(this: *mut c_void, desc: usize, state: usize, clear: usize, _session: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + note_newer_device_method(94); + dev_create_reserved_resource(this, desc, state, clear, riid, ppv) +} + +/// device #129 CreateReservedResource2 (PC #78) +#[allow(clippy::too_many_arguments)] +unsafe extern "system" fn dev_create_reserved_resource2_x(this: *mut c_void, desc: usize, layout: u32, clear: usize, _session: usize, _castable: u32, _formats: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + note_newer_device_method(129); + dev_create_reserved_resource(this, desc, super::device_x::layout_state(layout) as usize, clear, riid, ppv) +} + +/// device #110 CreatePlacedResource1 (PC #70): a D3D12_RESOURCE_DESC1, the console desc first +unsafe extern "system" fn dev_create_placed_resource1_x(this: *mut c_void, heap: usize, offset: usize, desc: usize, state: usize, clear: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + note_newer_device_method(110); + dev_create_placed_resource_x(this, heap, offset, desc, state, clear, riid, ppv) +} + +/// device #128 CreatePlacedResource2 (PC #77) +#[allow(clippy::too_many_arguments)] +unsafe extern "system" fn dev_create_placed_resource2_x(this: *mut c_void, heap: usize, offset: usize, desc: usize, layout: u32, clear: usize, _castable: u32, _formats: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { + note_newer_device_method(128); + dev_create_placed_resource_x(this, heap, offset, desc, super::device_x::layout_state(layout) as usize, clear, riid, ppv) +} + /// A display target: its console memory comes from the title's allocation hook, as the console /// runtime's does (a retail game gives its back buffers one block and asserts that it is used up); on the /// PC it is a resource of its own.