D3D12.X: Xbox D16S8 depth formats and depth buffers that are also UAVs #163

Closed
github-bot wants to merge 3 commits from gh-pr/163/head into gh-pr/163/base
Owner

@⁠Sr-0w on GitHub · 2026-11-23 18:03 UTC · original
Sr-0w:xbox-depth-uav → main · +180 −4 · 2 files · 3 commits · closed without merging

Problem

The retail title (retail, GDK) stops on two assertions while creating its render targets:

  • +0x344196: its 2560x1440 depth buffer is DXGI_FORMAT_D16_UNORM_S8_UINT (118, console only) with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS. GetResourceAllocationInfo returned no size, because the PC driver refuses both the format and the depth + UAV pair.
  • +0x14a6390: its 768x768x6 shadow maps (D16, depth + UAV) are placed with the UNORDERED_ACCESS initial state, and the PC refuses that state (0x80070057).

Change

  • pc_format: 118 / 119 / 120 (D16S8 family) → 45 / 46 / 47 (D24S8 family). Applied in pc_resource_desc and in pc_topology_type (pipelines' DSV/RTV formats; the driver refused the retail title's pipelines with DSV 118).
  • pc_resource_desc: a depth-stencil resource drops ALLOW_UNORDERED_ACCESS (a plain UAV texture keeps it).
  • create_placed_resource_x: such a depth buffer's UNORDERED_ACCESS initial state becomes DEPTH_WRITE.
  • Logs: descs that still get no allocation size, and the state / clear format / PC desc of a refused placed resource.

Overlaps with the format part of #150 (D16S8 → D24S8). Whichever lands first, I'll rebase the other.

Result

The retail title goes past both assertions. On top of 956a476 it then runs at 30 fps like main (checked: main + this PR, 600 frames at 29.4 fps after 36 s).

Test plan

  • cargo test --release -p xcl --lib: new console_depth_buffers_become_pc_ones passes; only gpu_wave64_ps_whole_wave_reductions fails, as on main
  • Retail title: no more assertions at +0x344196 / +0x14a6390

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-23 18:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/163) `Sr-0w:xbox-depth-uav` → `main` · +180 −4 · 2 files · 3 commits · closed without merging ## Problem The retail title (retail, GDK) stops on two assertions while creating its render targets: - `+0x344196`: its 2560x1440 depth buffer is `DXGI_FORMAT_D16_UNORM_S8_UINT` (**118**, console only) with `ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS`. `GetResourceAllocationInfo` returned no size, because the PC driver refuses both the format and the depth + UAV pair. - `+0x14a6390`: its 768x768x6 shadow maps (D16, depth + UAV) are placed with the `UNORDERED_ACCESS` initial state, and the PC refuses that state (`0x80070057`). ## Change - `pc_format`: 118 / 119 / 120 (D16S8 family) → 45 / 46 / 47 (D24S8 family). Applied in `pc_resource_desc` and in `pc_topology_type` (pipelines' DSV/RTV formats; the driver refused the retail title's pipelines with DSV 118). - `pc_resource_desc`: a depth-stencil resource drops `ALLOW_UNORDERED_ACCESS` (a plain UAV texture keeps it). - `create_placed_resource_x`: such a depth buffer's `UNORDERED_ACCESS` initial state becomes `DEPTH_WRITE`. - Logs: descs that still get no allocation size, and the state / clear format / PC desc of a refused placed resource. Overlaps with the format part of #150 (D16S8 → D24S8). Whichever lands first, I'll rebase the other. ## Result The retail title goes past both assertions. On top of 956a476 it then runs at 30 fps like `main` (checked: `main` + this PR, 600 frames at 29.4 fps after 36 s). ## Test plan - [x] `cargo test --release -p xcl --lib`: new `console_depth_buffers_become_pc_ones` passes; only `gpu_wave64_ps_whole_wave_reductions` fails, as on `main` - [x] Retail title: no more assertions at `+0x344196` / `+0x14a6390` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The console's DXGI_FORMAT_D16_UNORM_S8_UINT family (118, 119, 120) does not exist on the PC: it
becomes the D24_UNORM_S8_UINT family (45, 46, 47) in resource descs and in pipelines' DSV / RTV
formats (pc_format). The console allows a depth-stencil resource that is also a UAV; the PC
refuses that pair, so pc_resource_desc keeps the depth flag and drops unordered access, and a
placed depth buffer's UNORDERED_ACCESS initial state becomes DEPTH_WRITE.

GTA VI stopped on assertions at +0x344196 (its 2560x1440 D16S8 depth buffer got no size from
GetResourceAllocationInfo) and +0x14a6390 (its 768x768x6 shadow maps, placed with the UAV state,
were refused). Resources that still get no size or are refused are logged with their PC desc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XTYmP6vKUQKatSiA2PC95B
pc_resource_desc drops ALLOW_UNORDERED_ACCESS from a console depth buffer that is also a UAV.
GTA VI still creates UAVs of its 768x768 shadow maps: the driver was handed an invalid view
(debug layer: "CreateUnorderedAccessView … did not specify ALLOW_UNORDERED_ACCESS") and the
device was removed once a dispatch used it. The PC descriptor is now a null view of the same
dimension; the console descriptor XCL writes for translated shaders is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XTYmP6vKUQKatSiA2PC95B
#163 makes the console's D16S8 depth buffers D24S8 on the PC; what refers to them kept the
console's formats and the PC refused them (GTA VI, with the D3D12 debug layer):
- a clear value of format 118 on a D24S8 resource: E_INVALIDARG, then the title's assertion;
- CreateDepthStencilView with format 118 (now hooked): the device was removed (~55 s in);
- SRVs of depth / stencil planes as R16_UNORM, R8_UINT, and of a D32S8 (R32G8X24_TYPELESS)
  as R32_FLOAT – also the SRV XCL makes next to a texture UAV: now
  R24_UNORM_X8_TYPELESS / X24_TYPELESS_G8_UINT / R32_FLOAT_X8X24_TYPELESS /
  X32_TYPELESS_G8X24_UINT with the matching plane slice (`depth_srv_format`);
- the null UAV of a depth buffer kept the console view's plane slice 1.
RTVs and SRVs with 118–120 go through `pc_format` too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SKtJseucqXR6iuAE6HBtiA
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:12 +00:00
github-bot closed this pull request 2026-11-26 04:13:12 +00:00
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-23 19:19 UTC · original

New commit 634c423: a null UAV for a resource the PC has without unordered access. GTA VI still creates UAVs of its 768x768 D16 shadow maps (whose UAV flag this PR drops). The driver was handed an invalid view (debug layer: CreateUnorderedAccessView … did not specify ALLOW_UNORDERED_ACCESS, id 340), and the device was removed (0x887a0001) once a dispatch used it. The console descriptor XCL writes for translated shaders is unchanged; only the PC descriptor becomes a null view of the same dimension.

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-23 19:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/163#issuecomment-7111437887) New commit 634c423: a **null UAV** for a resource the PC has without unordered access. GTA VI still creates UAVs of its 768x768 D16 shadow maps (whose UAV flag this PR drops). The driver was handed an invalid view (debug layer: `CreateUnorderedAccessView … did not specify ALLOW_UNORDERED_ACCESS`, id 340), and the device was removed (`0x887a0001`) once a dispatch used it. The console descriptor XCL writes for translated shaders is unchanged; only the PC descriptor becomes a null view of the same dimension. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠YeetSkillet on GitHub · 2026-11-23 19:48 UTC · original

At 634c423, a non-null optimized clear can still make depth-buffer creation fail. The resource description maps Xbox D16S8 (118) to PC D24S8 (45), but the address-based placement and its committed fallback both pass the original D3D12_CLEAR_VALUE.Format. Call sites

I tested a synthetic 16×16 texture with both CreatePlacedResource and CreateCommittedResource on an RTX 3060 Ti and on WARP. Both APIs and both adapters gave the same results. The depth and stencil values were 0.625 and 0x5a throughout the depth tests.

Resource format Optimized clear format Result
D24S8 (45) Xbox D16S8 (118) E_INVALIDARG (0x80070057)
D24S8 (45) D24S8 (45) S_OK
D24S8 (45) null clear S_OK
R24G8 typeless (44) D24S8 (45) S_OK
D24S8 (45) D32_FLOAT (40) E_INVALIDARG
RGBA8 typeless (27) RGBA8 sRGB (29) S_OK

The downstream fork already maps the clear on its address-based and committed paths. The attached patch for this PR also covers the heap-and-offset placement retry and its committed fallback. It maps the clear’s own view format, which preserves valid typed clears on typeless resources. Downstream change · D3D12 clear format rules

The patch applies cleanly to 634c423 and includes a Rust regression test. The Python probe ran all 24 native checks using the Windows system libraries. The Rust test and the effect on in-game rendering still need verification.

**@⁠YeetSkillet** on GitHub · 2026-11-23 19:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/163#issuecomment-7112138428) At `634c423`, a non-null optimized clear can still make depth-buffer creation fail. The resource description maps Xbox D16S8 (118) to PC D24S8 (45), but the address-based placement and its committed fallback both pass the original `D3D12_CLEAR_VALUE.Format`. [Call sites](https://github.com/ivall/xcl/blob/634c4238b3b4a640ad137674aa53db2f954d517b/crates/xcl/src/hle/d3d12x/device_x.rs#L803-L813) I tested a synthetic 16×16 texture with both `CreatePlacedResource` and `CreateCommittedResource` on an RTX 3060 Ti and on WARP. Both APIs and both adapters gave the same results. The depth and stencil values were 0.625 and 0x5a throughout the depth tests. | Resource format | Optimized clear format | Result | | --- | --- | --- | | D24S8 (45) | Xbox D16S8 (118) | E_INVALIDARG (0x80070057) | | D24S8 (45) | D24S8 (45) | S_OK | | D24S8 (45) | null clear | S_OK | | R24G8 typeless (44) | D24S8 (45) | S_OK | | D24S8 (45) | D32_FLOAT (40) | E_INVALIDARG | | RGBA8 typeless (27) | RGBA8 sRGB (29) | S_OK | The downstream fork already maps the clear on its address-based and committed paths. The attached patch for this PR also covers the heap-and-offset placement retry and its committed fallback. It maps the clear’s own view format, which preserves valid typed clears on typeless resources. [Downstream change](https://github.com/theaustinayers/xcl/commit/7fc267af80f8fd3a9c5495ca8d4a612f0834cb98) · [D3D12 clear format rules](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_clear_value#members) The patch applies cleanly to `634c423` and includes a Rust regression test. The Python probe ran all 24 native checks using the Windows system libraries. The Rust test and the effect on in-game rendering still need verification. - Apply with `git apply xcl-163-optimized-clear.patch.txt`. [xcl-163-optimized-clear.patch.txt](https://github.com/user-attachments/files/35296485/xcl-163-optimized-clear.patch.txt) - Reproduce on Windows x64 with `python check-d3d12-clear.py.txt`. [check-d3d12-clear.py.txt](https://github.com/user-attachments/files/35296486/check-d3d12-clear.py.txt)
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-23 20:00 UTC · original

New commit: the PC's formats for everything that refers to a console depth buffer, not only the resource. With the D3D12 debug layer, GTA VI showed each of these, each followed by a device removal:

  • clear value 118 on the D24S8 resource → E_INVALIDARG, then the title's assertion;
  • CreateDepthStencilView with format 118 (now hooked) → removal ~55 s in;
  • SRVs of a depth/stencil plane as R16_UNORM / R8_UINT, and of a D32S8 (R32G8X24_TYPELESS) as R32_FLOAT, including the SRV XCL makes next to a texture UAV → now R24_UNORM_X8 / X24_G8_UINT / R32_FLOAT_X8X24 / X32_G8X24_UINT with the right plane slice (depth_srv_format, unit test added);
  • the null UAV kept plane slice 1.

Overlap note: #169 also remaps DSV format 118 → 45. The two can be combined; #169's version covers PSOs, this one covers resources, clear values and views.

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-23 20:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/163#issuecomment-7112425167) New commit: the PC's formats for **everything that refers to** a console depth buffer, not only the resource. With the D3D12 debug layer, GTA VI showed each of these, each followed by a device removal: - clear value 118 on the D24S8 resource → `E_INVALIDARG`, then the title's assertion; - `CreateDepthStencilView` with format 118 (now hooked) → removal ~55 s in; - SRVs of a depth/stencil plane as R16_UNORM / R8_UINT, and of a D32S8 (`R32G8X24_TYPELESS`) as R32_FLOAT, including the SRV XCL makes next to a texture UAV → now R24_UNORM_X8 / X24_G8_UINT / R32_FLOAT_X8X24 / X32_G8X24_UINT with the right plane slice (`depth_srv_format`, unit test added); - the null UAV kept plane slice 1. Overlap note: #169 also remaps DSV format 118 → 45. The two can be combined; #169's version covers PSOs, this one covers resources, clear values and views. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠gw1337x on GitHub · 2026-11-23 20:20 UTC · original

Setup: AMD Radeon RX 7800 XT (RDNA3, 16 GB), driver 32.0.32015.7029, 32 GB RAM, Windows 11 Pro 26200, GTA VI retail, XCL_NETWORK=0, release build.
Test branch: main 956a476 + #170 (incl. #163 @ 634c423) + #162 @ 641f551 + #168 @ 070a737 + xg.rs of #169 + #176 + #164.

Tested 634c423 with the D3D12 debug layer (Agility SDK 1.620.2, XCL_D3D12_DEBUG=1). The resources become D24S8, but views of them still carry the console formats, and that is what removed the device on this machine (0x887a0001, ~33–50 s):

CreateDepthStencilView: The Format (0x76, Unrecognized) is invalid when creating a View; it is not a fully qualified format within the same family as the Format of the Resource (0x2d, D24_UNORM_S8_UINT).
CreateShaderResourceView: The format (0x78, Unrecognized) cannot be used with a ShaderResource view.
CreateShaderResourceView: For the resource format D24_UNORM_S8_UINT, ... the format name for the view can't be R16_UNORM.   (also R8_UINT)
CreateShaderResourceView: For the resource format R32G8X24_TYPELESS, ... the format name for the view can't be R32_FLOAT.
CreateUnorderedAccessView: The PlaneSlice 1 is invalid when the resource format is R32_UINT ... Only Plane Slice 0 is valid ...

What fixed each (all only on the copy handed to the PC driver; the console descriptor XCL writes is unchanged):

  1. CreateDepthStencilView isn't overridden, so the game's DSV in 118 goes straight to the driver. Added a CreateDepthStencilView override, and pass SRV / UAV / RTV / DSV descs through pc_format (the DXGI format is the first field of all four).
  2. The console reads depth / stencil of a depth buffer through plain formats. On the PC's D24S8 / D32S8 resource: depth → R24_UNORM_X8_TYPELESS / R32_FLOAT_X8X24_TYPELESS (plane 0), stencil (R8_UINT) → X24_TYPELESS_G8_UINT / X32_TYPELESS_G8X24_UINT (plane 1). Needed in dev_create_srv_x and in the SRV that dev_create_uav_x writes for dim == 4.
  3. The null UAV from 634c423 copies the game's desc, PlaneSlice: 1 included (a stencil-plane UAV). A null view has one plane, so plane 0.

Also confirming @⁠YeetSkillet's finding: the clear value has to go through pc_format too. Here a 1024x1024 D16S8 placed resource with an optimized clear in 118 came back E_INVALIDARG and the game stopped on its assertion at +0x131a2ad. Fixed by mapping the clear value's format at the top of create_placed_resource_x.

With 1–3 the debug layer shows none of these, and the "invalid call" removal is gone.

Patch (real.rs, ~100 lines)
@@ dev_create_srv_x
-    let Some(slot) = super::console_heap::slot(cpu) else { return f(this, res, desc, cpu) };
+    let mut keep = std::mem::MaybeUninit::uninit();
+    let desc_pc = pc_view(desc, &mut keep);
+    let mut keep2 = std::mem::MaybeUninit::uninit();
+    let desc_pc = pc_depth_srv(res, desc_pc, &mut keep2);
+    let Some(slot) = super::console_heap::slot(cpu) else { return f(this, res, desc_pc, cpu) };
@@
-    f(this, res, desc, slot.pc_srv);
+    f(this, res, desc_pc, slot.pc_srv);
@@ dev_create_uav_x
         _ => (res, counter, desc),
     };
+    let mut keep = std::mem::MaybeUninit::uninit();
+    let desc_pc = pc_view(desc_pc, &mut keep);
+    let mut keep2 = std::mem::MaybeUninit::uninit();
+    let desc_pc = pc_uav_plane(res_pc, desc_pc, &mut keep2);
     let Some(slot) = super::console_heap::slot(cpu) else { return f(this, res_pc, counter, desc_pc, cpu) };
@@ dev_create_uav_x, the SRV for dim == 4
-        g(this, res, &srv, slot.pc_srv);
+        let (mut keep, mut keep2) = (std::mem::MaybeUninit::uninit(), std::mem::MaybeUninit::uninit());
+        g(this, res, pc_depth_srv(res, pc_view(&srv, &mut keep), &mut keep2), slot.pc_srv);
@@ overrides(Kind::Device)
             ("CreateRenderTargetView", dev_create_rtv as usize),
+            ("CreateDepthStencilView", dev_create_dsv as usize),
@@ new helpers
+/// A view desc (SRV / UAV / RTV / DSV: the DXGI format comes first) with the console-only
+/// formats as the PC's (`device_x::pc_format`, D16S8 118/119/120 → 45/46/47) for the PC driver;
+/// the console descriptor XCL writes keeps the title's.
+unsafe fn pc_view<T: Copy>(desc: *const T, keep: &mut std::mem::MaybeUninit<T>) -> *const T {
+    if desc.is_null() {
+        return desc;
+    }
+    let mut d = desc.read_unaligned();
+    let f = &mut *(&mut d as *mut T as *mut u32);
+    let pc = super::device_x::pc_format(*f);
+    if pc == *f {
+        return desc;
+    }
+    *f = pc;
+    keep.write(d);
+    keep.as_ptr()
+}
+
+/// An SRV of a depth buffer as the PC wants it: the console reads a depth buffer's depth or
+/// stencil through plain formats; the PC needs the plane formats and plane slice.
+unsafe fn pc_depth_srv(res: *mut c_void, desc: *const D3D12_SHADER_RESOURCE_VIEW_DESC, keep: &mut std::mem::MaybeUninit<D3D12_SHADER_RESOURCE_VIEW_DESC>) -> *const D3D12_SHADER_RESOURCE_VIEW_DESC {
+    use windows::Win32::Graphics::Dxgi::Common::*;
+    let (Some(v), Some(r)) = (desc.as_ref(), ID3D12Resource::from_raw_borrowed(&res)) else { return desc };
+    let rf = r.GetDesc().Format;
+    let d24 = rf == DXGI_FORMAT_D24_UNORM_S8_UINT || rf == DXGI_FORMAT_R24G8_TYPELESS;
+    let d32 = rf == DXGI_FORMAT_D32_FLOAT_S8X24_UINT || rf == DXGI_FORMAT_R32G8X24_TYPELESS;
+    if !d24 && !d32 {
+        return desc;
+    }
+    let stencil = matches!(v.Format, DXGI_FORMAT_R8_UINT | DXGI_FORMAT_R8_TYPELESS | DXGI_FORMAT_X24_TYPELESS_G8_UINT | DXGI_FORMAT_X32_TYPELESS_G8X24_UINT);
+    let format = match (d24, stencil) {
+        (true, false) => DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
+        (true, true) => DXGI_FORMAT_X24_TYPELESS_G8_UINT,
+        (false, false) => DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS,
+        (false, true) => DXGI_FORMAT_X32_TYPELESS_G8X24_UINT,
+    };
+    if format == v.Format {
+        return desc;
+    }
+    let mut d = *v;
+    d.Format = format;
+    let plane = stencil as u32;
+    match d.ViewDimension {
+        D3D12_SRV_DIMENSION_TEXTURE2D => d.Anonymous.Texture2D.PlaneSlice = plane,
+        D3D12_SRV_DIMENSION_TEXTURE2DARRAY => d.Anonymous.Texture2DArray.PlaneSlice = plane,
+        _ => {}
+    }
+    keep.write(d);
+    keep.as_ptr()
+}
+
+/// A UAV of plane 1 of a resource the PC has with one plane (a stencil plane on the console)
+/// as plane 0.
+unsafe fn pc_uav_plane(res: *mut c_void, desc: *const D3D12_UNORDERED_ACCESS_VIEW_DESC, keep: &mut std::mem::MaybeUninit<D3D12_UNORDERED_ACCESS_VIEW_DESC>) -> *const D3D12_UNORDERED_ACCESS_VIEW_DESC {
+    use windows::Win32::Graphics::Dxgi::Common::*;
+    let Some(v) = desc.as_ref() else { return desc };
+    // (no resource: a null view, which has one plane)
+    let rf = ID3D12Resource::from_raw_borrowed(&res).map_or(DXGI_FORMAT_UNKNOWN, |r| r.GetDesc().Format);
+    if matches!(rf, DXGI_FORMAT_D24_UNORM_S8_UINT | DXGI_FORMAT_R24G8_TYPELESS | DXGI_FORMAT_D32_FLOAT_S8X24_UINT | DXGI_FORMAT_R32G8X24_TYPELESS) {
+        return desc;
+    }
+    let mut d = *v;
+    match d.ViewDimension {
+        D3D12_UAV_DIMENSION_TEXTURE2D if d.Anonymous.Texture2D.PlaneSlice != 0 => d.Anonymous.Texture2D.PlaneSlice = 0,
+        D3D12_UAV_DIMENSION_TEXTURE2DARRAY if d.Anonymous.Texture2DArray.PlaneSlice != 0 => d.Anonymous.Texture2DArray.PlaneSlice = 0,
+        _ => return desc,
+    }
+    keep.write(d);
+    keep.as_ptr()
+}
+
+/// CreateDepthStencilView: as on the PC, with the view's console format as the PC's (`pc_view`)
+unsafe extern "system" fn dev_create_dsv(this: *mut c_void, res: *mut c_void, desc: *const D3D12_DEPTH_STENCIL_VIEW_DESC, handle: usize) {
+    type F = unsafe extern "system" fn(*mut c_void, *mut c_void, *const D3D12_DEPTH_STENCIL_VIEW_DESC, usize);
+    let f: F = std::mem::transmute(orig_fn(this, slot_of(this, "CreateDepthStencilView")));
+    let mut keep = std::mem::MaybeUninit::uninit();
+    f(this, res, pc_view(desc, &mut keep), handle);
+}
@@ dev_create_rtv
-    f(this, res, desc, handle);
+    let mut keep = std::mem::MaybeUninit::<D3D12_RENDER_TARGET_VIEW_DESC>::uninit();
+    f(this, res, pc_view(desc as *const D3D12_RENDER_TARGET_VIEW_DESC, &mut keep) as *const c_void, handle);

🤖 Generated with Claude Code

**@⁠gw1337x** on GitHub · 2026-11-23 20:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/163#issuecomment-7112926158) **Setup:** AMD Radeon RX 7800 XT (RDNA3, 16 GB), driver 32.0.32015.7029, 32 GB RAM, Windows 11 Pro 26200, GTA VI retail, `XCL_NETWORK=0`, release build. Test branch: `main` 956a476 + #170 (incl. #163 @ 634c423) + #162 @ 641f551 + #168 @ 070a737 + `xg.rs` of #169 + #176 + #164. Tested 634c423 with the D3D12 debug layer (Agility SDK 1.620.2, `XCL_D3D12_DEBUG=1`). The resources become D24S8, but **views of them** still carry the console formats, and that is what removed the device on this machine (`0x887a0001`, ~33–50 s): ``` CreateDepthStencilView: The Format (0x76, Unrecognized) is invalid when creating a View; it is not a fully qualified format within the same family as the Format of the Resource (0x2d, D24_UNORM_S8_UINT). CreateShaderResourceView: The format (0x78, Unrecognized) cannot be used with a ShaderResource view. CreateShaderResourceView: For the resource format D24_UNORM_S8_UINT, ... the format name for the view can't be R16_UNORM. (also R8_UINT) CreateShaderResourceView: For the resource format R32G8X24_TYPELESS, ... the format name for the view can't be R32_FLOAT. CreateUnorderedAccessView: The PlaneSlice 1 is invalid when the resource format is R32_UINT ... Only Plane Slice 0 is valid ... ``` What fixed each (all only on the copy handed to the PC driver; the console descriptor XCL writes is unchanged): 1. `CreateDepthStencilView` isn't overridden, so the game's DSV in 118 goes straight to the driver. Added a `CreateDepthStencilView` override, and pass SRV / UAV / RTV / DSV descs through `pc_format` (the DXGI format is the first field of all four). 2. The console reads depth / stencil of a depth buffer through plain formats. On the PC's D24S8 / D32S8 resource: depth → `R24_UNORM_X8_TYPELESS` / `R32_FLOAT_X8X24_TYPELESS` (plane 0), stencil (`R8_UINT`) → `X24_TYPELESS_G8_UINT` / `X32_TYPELESS_G8X24_UINT` (plane 1). Needed in `dev_create_srv_x` and in the SRV that `dev_create_uav_x` writes for `dim == 4`. 3. The null UAV from 634c423 copies the game's desc, `PlaneSlice: 1` included (a stencil-plane UAV). A null view has one plane, so plane 0. Also confirming @⁠YeetSkillet's finding: the clear value has to go through `pc_format` too. Here a 1024x1024 D16S8 placed resource with an optimized clear in 118 came back `E_INVALIDARG` and the game stopped on its assertion at `+0x131a2ad`. Fixed by mapping the clear value's format at the top of `create_placed_resource_x`. With 1–3 the debug layer shows none of these, and the "invalid call" removal is gone. <details><summary>Patch (real.rs, ~100 lines)</summary> ```diff @@ dev_create_srv_x - let Some(slot) = super::console_heap::slot(cpu) else { return f(this, res, desc, cpu) }; + let mut keep = std::mem::MaybeUninit::uninit(); + let desc_pc = pc_view(desc, &mut keep); + let mut keep2 = std::mem::MaybeUninit::uninit(); + let desc_pc = pc_depth_srv(res, desc_pc, &mut keep2); + let Some(slot) = super::console_heap::slot(cpu) else { return f(this, res, desc_pc, cpu) }; @@ - f(this, res, desc, slot.pc_srv); + f(this, res, desc_pc, slot.pc_srv); @@ dev_create_uav_x _ => (res, counter, desc), }; + let mut keep = std::mem::MaybeUninit::uninit(); + let desc_pc = pc_view(desc_pc, &mut keep); + let mut keep2 = std::mem::MaybeUninit::uninit(); + let desc_pc = pc_uav_plane(res_pc, desc_pc, &mut keep2); let Some(slot) = super::console_heap::slot(cpu) else { return f(this, res_pc, counter, desc_pc, cpu) }; @@ dev_create_uav_x, the SRV for dim == 4 - g(this, res, &srv, slot.pc_srv); + let (mut keep, mut keep2) = (std::mem::MaybeUninit::uninit(), std::mem::MaybeUninit::uninit()); + g(this, res, pc_depth_srv(res, pc_view(&srv, &mut keep), &mut keep2), slot.pc_srv); @@ overrides(Kind::Device) ("CreateRenderTargetView", dev_create_rtv as usize), + ("CreateDepthStencilView", dev_create_dsv as usize), @@ new helpers +/// A view desc (SRV / UAV / RTV / DSV: the DXGI format comes first) with the console-only +/// formats as the PC's (`device_x::pc_format`, D16S8 118/119/120 → 45/46/47) for the PC driver; +/// the console descriptor XCL writes keeps the title's. +unsafe fn pc_view<T: Copy>(desc: *const T, keep: &mut std::mem::MaybeUninit<T>) -> *const T { + if desc.is_null() { + return desc; + } + let mut d = desc.read_unaligned(); + let f = &mut *(&mut d as *mut T as *mut u32); + let pc = super::device_x::pc_format(*f); + if pc == *f { + return desc; + } + *f = pc; + keep.write(d); + keep.as_ptr() +} + +/// An SRV of a depth buffer as the PC wants it: the console reads a depth buffer's depth or +/// stencil through plain formats; the PC needs the plane formats and plane slice. +unsafe fn pc_depth_srv(res: *mut c_void, desc: *const D3D12_SHADER_RESOURCE_VIEW_DESC, keep: &mut std::mem::MaybeUninit<D3D12_SHADER_RESOURCE_VIEW_DESC>) -> *const D3D12_SHADER_RESOURCE_VIEW_DESC { + use windows::Win32::Graphics::Dxgi::Common::*; + let (Some(v), Some(r)) = (desc.as_ref(), ID3D12Resource::from_raw_borrowed(&res)) else { return desc }; + let rf = r.GetDesc().Format; + let d24 = rf == DXGI_FORMAT_D24_UNORM_S8_UINT || rf == DXGI_FORMAT_R24G8_TYPELESS; + let d32 = rf == DXGI_FORMAT_D32_FLOAT_S8X24_UINT || rf == DXGI_FORMAT_R32G8X24_TYPELESS; + if !d24 && !d32 { + return desc; + } + let stencil = matches!(v.Format, DXGI_FORMAT_R8_UINT | DXGI_FORMAT_R8_TYPELESS | DXGI_FORMAT_X24_TYPELESS_G8_UINT | DXGI_FORMAT_X32_TYPELESS_G8X24_UINT); + let format = match (d24, stencil) { + (true, false) => DXGI_FORMAT_R24_UNORM_X8_TYPELESS, + (true, true) => DXGI_FORMAT_X24_TYPELESS_G8_UINT, + (false, false) => DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, + (false, true) => DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, + }; + if format == v.Format { + return desc; + } + let mut d = *v; + d.Format = format; + let plane = stencil as u32; + match d.ViewDimension { + D3D12_SRV_DIMENSION_TEXTURE2D => d.Anonymous.Texture2D.PlaneSlice = plane, + D3D12_SRV_DIMENSION_TEXTURE2DARRAY => d.Anonymous.Texture2DArray.PlaneSlice = plane, + _ => {} + } + keep.write(d); + keep.as_ptr() +} + +/// A UAV of plane 1 of a resource the PC has with one plane (a stencil plane on the console) +/// as plane 0. +unsafe fn pc_uav_plane(res: *mut c_void, desc: *const D3D12_UNORDERED_ACCESS_VIEW_DESC, keep: &mut std::mem::MaybeUninit<D3D12_UNORDERED_ACCESS_VIEW_DESC>) -> *const D3D12_UNORDERED_ACCESS_VIEW_DESC { + use windows::Win32::Graphics::Dxgi::Common::*; + let Some(v) = desc.as_ref() else { return desc }; + // (no resource: a null view, which has one plane) + let rf = ID3D12Resource::from_raw_borrowed(&res).map_or(DXGI_FORMAT_UNKNOWN, |r| r.GetDesc().Format); + if matches!(rf, DXGI_FORMAT_D24_UNORM_S8_UINT | DXGI_FORMAT_R24G8_TYPELESS | DXGI_FORMAT_D32_FLOAT_S8X24_UINT | DXGI_FORMAT_R32G8X24_TYPELESS) { + return desc; + } + let mut d = *v; + match d.ViewDimension { + D3D12_UAV_DIMENSION_TEXTURE2D if d.Anonymous.Texture2D.PlaneSlice != 0 => d.Anonymous.Texture2D.PlaneSlice = 0, + D3D12_UAV_DIMENSION_TEXTURE2DARRAY if d.Anonymous.Texture2DArray.PlaneSlice != 0 => d.Anonymous.Texture2DArray.PlaneSlice = 0, + _ => return desc, + } + keep.write(d); + keep.as_ptr() +} + +/// CreateDepthStencilView: as on the PC, with the view's console format as the PC's (`pc_view`) +unsafe extern "system" fn dev_create_dsv(this: *mut c_void, res: *mut c_void, desc: *const D3D12_DEPTH_STENCIL_VIEW_DESC, handle: usize) { + type F = unsafe extern "system" fn(*mut c_void, *mut c_void, *const D3D12_DEPTH_STENCIL_VIEW_DESC, usize); + let f: F = std::mem::transmute(orig_fn(this, slot_of(this, "CreateDepthStencilView"))); + let mut keep = std::mem::MaybeUninit::uninit(); + f(this, res, pc_view(desc, &mut keep), handle); +} @@ dev_create_rtv - f(this, res, desc, handle); + let mut keep = std::mem::MaybeUninit::<D3D12_RENDER_TARGET_VIEW_DESC>::uninit(); + f(this, res, pc_view(desc as *const D3D12_RENDER_TARGET_VIEW_DESC, &mut keep) as *const c_void, handle); ``` </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠Kalmarv on GitHub · 2026-11-23 20:28 UTC · original

The stencil-plane alias still reaches the PC with plane 0. I tested PR head 595b2b7a8446d9bf912ae602547476adcb21ef50 directly against main at 956a476bf738a098f39df4f4c8acef682e43030f. Windows x64 MSVC, Rust 1.99.0, RTX 5070 Ti, driver 610.74, debug-profile lib tests, synthetic inputs.

Check main PR head
Existing hle::d3d12x:: tests, including PR tests where present 54 pass 55 pass
pc_resource_desc on format 118 with flags 6 (118, 6) (45, 2)
Stencil SRV, format and plane sent to PC slot 18 (120, 0) (47, 0), expected (47, 1)

The SRV probe creates a real 16×16 R24G8_TYPELESS depth resource, calls dev_create_srv_x with an explicit Texture2D view (format 120, PlaneSlice 0), and captures the descriptor at the native call boundary. At crates/xcl/src/hle/d3d12x/real.rs:1631, pc_view_desc has already changed 120 to 47. At line 3898, depth_srv_format(44, 47) returns None, so the caller skips the plane assignment. Deriving format and plane from the original descriptor, or assigning the plane even when the format already matches, would cover this case.

The two tests copied verbatim from the PR cannot compile on main because their new helpers are absent. The last two rows use the same independently compiled probes on both revisions. The SRV probe captures arguments only. GPU sampling, retail content and merge-onto-main were outside this run. AI-assisted review.

**@⁠Kalmarv** on GitHub · 2026-11-23 20:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/163#issuecomment-7113109394) **The stencil-plane alias still reaches the PC with plane 0.** I tested PR head `595b2b7a8446d9bf912ae602547476adcb21ef50` directly against `main` at `956a476bf738a098f39df4f4c8acef682e43030f`. Windows x64 MSVC, Rust 1.99.0, RTX 5070 Ti, driver 610.74, debug-profile lib tests, synthetic inputs. | Check | main | PR head | |---|---:|---:| | Existing `hle::d3d12x::` tests, including PR tests where present | 54 pass | 55 pass | | `pc_resource_desc` on format 118 with flags 6 | (118, 6) | (45, 2) | | Stencil SRV, format and plane sent to PC slot 18 | (120, 0) | (47, 0), expected (47, 1) | The SRV probe creates a real 16×16 `R24G8_TYPELESS` depth resource, calls `dev_create_srv_x` with an explicit Texture2D view (format 120, PlaneSlice 0), and captures the descriptor at the native call boundary. At `crates/xcl/src/hle/d3d12x/real.rs:1631`, `pc_view_desc` has already changed 120 to 47. At line 3898, `depth_srv_format(44, 47)` returns `None`, so the caller skips the plane assignment. Deriving format and plane from the original descriptor, or assigning the plane even when the format already matches, would cover this case. The two tests copied verbatim from the PR cannot compile on main because their new helpers are absent. The last two rows use the same independently compiled probes on both revisions. The SRV probe captures arguments only. GPU sampling, retail content and merge-onto-main were outside this run. AI-assisted review.
Author
Owner

@⁠ivall on GitHub · 2026-11-23 20:57 UTC · original

Closing as covered on main - thanks, this chain is what got the title to its menu. On main (38b05b7, eaa36b6) the retail game now reaches its first menu at 30 fps with ~19 GB of commit, checked on an RX 9070; cargo test --workspace is green (548 unit tests). What main has: the D16S8 family (118-120) as R24G8_TYPELESS resources with the console's XG layouts; depth buffers in a typed depth format made typeless; no UAV flag on depth buffers (UAV initial state -> DEPTH_WRITE) and a null UAV for a resource without ALLOW_UNORDERED_ACCESS; clear values, DSVs and pipeline DSV formats mapped. The open point from the review is fixed there too: a stencil SRV gets plane 1 (device_x::pc_shader_view_format / stencil_view, unit test console_depth_buffers_and_their_views_are_the_pcs). Also, a D24S8 format in an SRV, or R16_UNORM of the D16S8 buffer, removed the device too, and so did a B5G5R5A1 UAV of a target the PC makes R8G8B8A8 (found with the debug layer).

**@⁠ivall** on GitHub · 2026-11-23 20:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/163#issuecomment-7113790555) Closing as covered on main - thanks, this chain is what got the title to its menu. On main (38b05b7, eaa36b6) the retail game now reaches its first menu at 30 fps with ~19 GB of commit, checked on an RX 9070; `cargo test --workspace` is green (548 unit tests). What main has: the D16S8 family (118-120) as R24G8_TYPELESS resources with the console's XG layouts; depth buffers in a typed depth format made typeless; no UAV flag on depth buffers (UAV initial state -> DEPTH_WRITE) and a null UAV for a resource without ALLOW_UNORDERED_ACCESS; clear values, DSVs and pipeline DSV formats mapped. The open point from the review is fixed there too: a stencil SRV gets plane 1 (`device_x::pc_shader_view_format` / `stencil_view`, unit test `console_depth_buffers_and_their_views_are_the_pcs`). Also, a D24S8 format in an SRV, or R16_UNORM of the D16S8 buffer, removed the device too, and so did a B5G5R5A1 UAV of a target the PC makes R8G8B8A8 (found with the debug layer).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.