From 0da61c6b206b2c73adb8aa0ed06de2ea4bf4d65d Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Sat, 28 Nov 2026 05:08:26 +0000 Subject: [PATCH] D3D12.X: the console's acceleration-structure resource flag becomes UAV, not a video flag The console's resource flag 0x80 is a raytracing acceleration-structure buffer; the PC's 0x80 is a video-encode reference. pc_resource_desc and sanitize_coherent_buffer kept the low byte (flags & 0xFF), so a console acceleration-structure buffer reached the PC as a video-encode buffer, which the PC refuses for a buffer or treats as a video resource. pc_resource_flags keeps 0x1-0x20, maps 0x80 to ALLOW_UNORDERED_ACCESS (an acceleration-structure buffer needs it for its state on the PC) and never forwards 0x40, 0x80, 0x100, 0x200 or the console-only bits above. Not confirmed on a title: whether the creations fail or are accepted as video buffers (the handoff's logging step). Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/device_x.rs | 23 ++++++++++++++++++++++- crates/xcl/src/hle/d3d12x/real.rs | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/device_x.rs b/crates/xcl/src/hle/d3d12x/device_x.rs index 4221fe40bf..83ebb677c7 100644 --- a/crates/xcl/src/hle/d3d12x/device_x.rs +++ b/crates/xcl/src/hle/d3d12x/device_x.rs @@ -870,10 +870,18 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] { d[8..16].fill(0); // alignment: the driver's let layout = if dim == D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32 { D3D12_TEXTURE_LAYOUT_ROW_MAJOR.0 } else { D3D12_TEXTURE_LAYOUT_UNKNOWN.0 }; d[0x2C..0x30].copy_from_slice(&(layout as u32).to_le_bytes()); - d[0x30..0x34].copy_from_slice(&(flags & 0xFF).to_le_bytes()); + d[0x30..0x34].copy_from_slice(&pc_resource_flags(flags).to_le_bytes()); d } +/// The PC resource flags of a console desc's `flags`: 0x1-0x20 as they are; the console's 0x80 is +/// a raytracing acceleration-structure buffer (the PC's 0x80 is a video-encode reference), which +/// the PC wants as ALLOW_UNORDERED_ACCESS; 0x40 and the texture-compatibility flags (0x100, +/// 0x200) and above are console-only and dropped. +pub fn pc_resource_flags(flags: u32) -> u32 { + (flags & 0x3F) | if flags & 0x80 != 0 { 4 } else { 0 } +} + /// The PC initial state of a resource the console creates in `state` with resource flags /// `flags`: the PC's state bits only (console-only ones made the PC refuse it, E_INVALIDARG), /// and a depth buffer created for unordered access – no longer one on the PC @@ -1460,6 +1468,19 @@ pub(super) unsafe extern "system" fn create_command_signature_x(this: *mut c_voi #[cfg(test)] mod tests { + #[test] + fn console_resource_flags_map_to_pc_ones() { + use super::pc_resource_flags; + assert_eq!(pc_resource_flags(0x80), 0x4, "console acceleration structure: UAV, not a video flag"); + assert_eq!(pc_resource_flags(0x84), 0x4); + assert_eq!((pc_resource_flags(0x100), pc_resource_flags(0x200)), (0, 0)); + assert_eq!(pc_resource_flags(0x40), 0); + for f in 0x1..=0x20u32 { + assert_eq!(pc_resource_flags(f), f); + } + assert_eq!(pc_resource_flags(0x10_0000 | 0x2), 0x2); + } + use super::*; #[test] diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index fc78555403..287cda4047 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -2128,7 +2128,7 @@ fn uma_shadowed() -> bool { /// cross-adapter UMA heap (`OpenExistingHeapFromAddress`). fn sanitize_coherent_buffer(desc: &D3D12_RESOURCE_DESC, state: usize, cross_adapter: bool) -> (D3D12_RESOURCE_DESC, u32) { let mut d = *desc; - d.Flags = D3D12_RESOURCE_FLAGS(d.Flags.0 & 0xFF); + d.Flags = D3D12_RESOURCE_FLAGS(super::device_x::pc_resource_flags(d.Flags.0 as u32) as i32); // a shadowed window's heap is video memory, not a cross-adapter heap over process memory; // nor is a driver heap (`uma_driver`) if cross_adapter && !uma_shadowed() {