Skip to content

[upstream #1063] D3D12.X: depth buffers that shaders write get a twin for their UAVs (#970) - #88

Closed
ufoptg wants to merge 2 commits into
mainfrom
upstream-pr/1063
Closed

ufoptg wants to merge 2 commits into
mainfrom
upstream-pr/1063

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Stacked on xcl-dev#1027; only the top commit (0322514) belongs here. Part of xcl-dev#970: the second step planned there, off by default.

A console depth buffer that shaders write too has no ALLOW_UNORDERED_ACCESS on the PC, and its UAVs were null views, so what the title's shaders wrote there was lost. With XCL_DEPTH_UAV_TWINS=1, such a depth buffer of one plane (R16 / R32 typeless) gets a twin: a texture of the same format and size with unordered access and no depth, kept as the depth buffer's private data (released with it). Its UAVs are views of the twin, and at the title's enhanced barriers (#146) into the UNORDERED_ACCESS layout the depth buffer is copied to the twin, at those out of it the twin back. Without the variable nothing changes.

XCL applies none of the title's enhanced barriers, so on the PC such a depth buffer stays in the state it was made in: the copies' transitions start from that state (kept at CreatePlacedResourceX, DEPTH_WRITE when not known). Depth + stencil formats keep null views: the PC has no UAV format for them.

What is in it

  • crates/xcl/src/hle/d3d12x/depth_twin.rs (new): enabled, twin_desc, twin_for_uav / twin_of (private data), note_created / forget, twin_uav_desc (a typed view for a UAV made without a description), sync (transitions + CopyResource either way; no transition of the depth buffer when it is in the copy's state already). Tests: a_d16_or_d32_depth_buffer_gets_a_twin_with_unordered_access, a_depth_buffer_in_the_copys_state_is_not_moved_to_it, a_uav_without_a_description_is_a_typed_view_of_the_twin, a_released_depth_buffers_state_is_forgotten; GPU test gpu_a_uav_write_to_a_depth_buffer_goes_through_its_twin (a D16 depth buffer's clear reaches the twin at the barrier into UAV, a write through the twin's UAV reaches the depth buffer at the barrier out of it; fails without the twin).
  • crates/xcl/src/hle/d3d12x/real.rs: dev_create_uav_x makes the view on the twin instead of a null view (typed when the title gave no description); res_release forgets the state of a released depth buffer.
  • crates/xcl/src/hle/d3d12x/list_x.rs: note_depth_uav_barrier_groups returns the copies a [upstream #959] Tests: cover xcl shaders across files, folders, and RPF9 packs #146 call needs (twin_copy); uav_barrier_x runs them after its global UAV barrier. The barrier log says whether the UAVs are null views or views of the twin.
  • crates/xcl/src/hle/d3d12x/console_list.rs: the same for console-recorded lists, recorded in the stream (TWIN_COPY_MARKER) and run at replay.
  • crates/xcl/src/hle/d3d12x/device_x.rs: create_placed_resource_x keeps the state such a depth buffer is made in.

Tested

  • NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124); AMD Ryzen 7 7800X3D; Windows 11 25H2 (26200.9974); rustc 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, runs in release
  • cargo test --workspace --no-fail-fast -- --test-threads=4 at 0322514 with XCL_SAMPLE_RPF, _DLLS, _TTPF, _BVH4, _BK2, _AWC set: 720 passed, 3 failed, 41 ignored; SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware. The 3 failures are the Tests: placed_title_textures_share_vram_and_preserve_pixels fails now and then at its cubemap reuse check (main 9ce2070) xcl-dev/xcl#718 flake (placed_title_textures_share_vram_and_preserve_pixels, cubemap extra_pages must be reused at same va, and the two PoisonError failures after it); the run before the review fixes (3ef1119) had 720 passed, 0 failed, and four cargo test -p xcl --lib -- --test-threads=4 runs failed on the flake 2 of 4 times on this branch and 2 of 4 times on main 09940bb on the same machine.
  • The retail title of Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub xcl-dev/xcl#505, scripts/smoke.ps1, XCL_PRESS_A_AT=15:
    • the regression runs below (60 s, variable unset);
    • 85 s with XCL_DEPTH_UAV_TWINS=1 at 0322514: 256+ D16 shadow maps get twins at ~9 s (the 4 depth + stencil views stay null); the enhanced barriers into and out of UNORDERED_ACCESS from ~66 s copied depth → twin and back 1024+ times; no device removal, the run ends by itself (exit 0x0, 1320 frames); peak commit 32058 MB (main's 60 s run: 27340 MB, its 300 s run: 30308 MB).
    • 300 s with XCL_DEPTH_UAV_TWINS=1 at 3ef1119 (before the review fixes): the same twins and copies, no device removal, it ends in the title's "GPU Loc Sig" abort at 95.5 s as main does.

Regression run

main:

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1271 (PresentX 1271)
presents per 2 s (last 3): 11 10 14
device removals: 0
crashes: 0
peak commit: 27340 MB

this PR:

xcl-smoke v1
commit: 0322514d51c6dcb03e5d2bfca6d75975f837eb6c
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1280 (PresentX 1281)
presents per 2 s (last 3): 2 9 17
device removals: 0
crashes: 0
peak commit: 26560 MB

Not tested

AI use

  • Claude Code, Claude Opus 5.5: wrote the code, the tests and this description, and ran the tests and the runs above.

🤖 Generated with Claude Code


Mirror of xcl-dev#1063 (auto-synced, do not edit).

IvyNotFound and others added 2 commits November 24, 2026 11:24
…#970)

A console depth buffer that shaders write too has no ALLOW_UNORDERED_ACCESS
on the PC (pc_resource_desc drops it) and its UAVs are null views, so the
writes are lost. The title's barriers that use such a resource as a UAV are
now counted and logged (the first 8, then every power of two):
- transitions from or to UNORDERED_ACCESS and UAV barriers naming it, both
  for PC-format lists (resource_barrier_x) and console-recorded ones
  (console_list replay);
- enhanced texture barriers (#146, D3D12_BARRIER_GROUP) with the
  UNORDERED_ACCESS layout or access. XCL still turns #146 into one global
  UAV barrier; only the description is read here.
The null-view warning gives its total instead of stopping at 4.

Measured on the retail title of xcl-dev#505 (RTX 5080, 300 s runs, A at 15 s):
no legacy barrier touches these resources; enhanced barriers move D16
shadow maps (768x768x6, 1024x1024, 512x512) into or out of the
UNORDERED_ACCESS layout once the world starts loading (62-64 s; 12 in a
run with every one logged).

No behaviour change: every barrier goes to the PC as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cl-dev#970)

A console depth buffer that is also a UAV has no ALLOW_UNORDERED_ACCESS on
the PC and its UAVs were null views: what the title's shaders wrote there
was lost (the retail title of xcl-dev#505 moves its D16 shadow maps into the
UNORDERED_ACCESS layout before it renders depth into them).

With XCL_DEPTH_UAV_TWINS=1, such a depth buffer of one plane (R16 / R32
typeless) gets a twin: a texture of the same format and size with unordered
access and no depth, kept as the depth buffer's private data. Its UAVs are
views of the twin, and at the title's enhanced barriers (#146) into the
UNORDERED_ACCESS layout the depth buffer is copied to the twin, at those
out of it the twin back (in console-recorded lists the copies are recorded
in the stream). XCL applies none of the title's enhanced barriers, so the
copies' transitions start from the PC state the depth buffer was made in
(kept at CreatePlacedResourceX; DEPTH_WRITE when not known). Depth and
stencil formats keep null views: the PC has no UAV format for them.

Off by default: without the variable nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1063 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1063 branch November 25, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants