D3D12.X: depth buffers that shaders write get a twin for their UAVs (#970) #1063
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1063
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1063"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@IvyNotFound on GitHub · 2026-11-24 11:09 UTC · original
IvyNotFound:depth-uav-twins→main· +545 −4 · 6 files · 2 commits · openStacked on #1027; only the top commit (
21aa52c) belongs here. Part of #970: the second step planned there, off by default.A console depth buffer that shaders write too has no
ALLOW_UNORDERED_ACCESSon the PC, and its UAVs were null views, so what the title's shaders wrote there was lost. WithXCL_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 theUNORDERED_ACCESSlayout 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 testgpu_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_xmakes the view on the twin instead of a null view (typed when the title gave no description);res_releaseforgets the state of a released depth buffer.crates/xcl/src/hle/d3d12x/list_x.rs:note_depth_uav_barrier_groupsreturns the copies a #146 call needs (twin_copy);uav_barrier_xruns 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_xkeeps the state such a depth buffer is made in.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4at21aa52c(rebased ontomainb7aa9f3) withXCL_SAMPLE_RPF,_DLLS,_TTPF,_BVH4,_BK2,_AWCset: 777 passed, 0 failed, 41 ignored;SKIPPED(no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware. Before the rebases, at0322514, one run had the #718 flake (720 passed, 3 failed).scripts/smoke.ps1,XCL_PRESS_A_AT=15:mainb7aa9f3and this head21aa52c, after the rebase);XCL_DEPTH_UAV_TWINS=1at0322514(before the rebase, same code): 256+ D16 shadow maps get twins at ~9 s (the 4 depth + stencil views stay null); the enhanced barriers into and out ofUNORDERED_ACCESSfrom ~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).XCL_DEPTH_UAV_TWINS=1at3ef1119(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 asmaindoes.Regression run
main:
this PR:
Not tested
CreatePlacedResourceX: their copies assume DEPTH_WRITE, the state #1353 now gives them thereUNORDERED_ACCESS(#26): counted by #1027, not copied – the title of #505 does not use them for these resourcesAI use
🤖 Generated with Claude Code
@certified-retart on GitHub · 2026-11-24 11:21 UTC · original
Independent review and local GPU test of commit
3ef1119(per CONTRIBUTING.md, reviewing/testing this PR rather than opening a duplicate for #970).Confirmed code findings
MADE_INnever removes released resources (depth_twin.rs/real.rs):note_created(res, state)inserts into the globalMADE_INmap, butreal::res_releasenever forgetsreson final release. If a later depth buffer reuses the same COM pointer address (e.g. created via another path or in a different initial state),state_of(res)returns the stale state from the freed resource. Adding adepth_twin::forget(this as usize)call inreal::res_release(whenn == 0) fixes both the leak and pointer-reuse staleness.depth_twin::syncwhenmade == depth_copy:barrier(&[transition(depth, made, depth_copy), ...])and the matching restore barrier emit aStateBefore == StateAftertransition if a depth+UAV texture was created inCOPY_SOURCE(entering UAV) orCOPY_DEST(leaving UAV), which D3D12 validation rejects. Omitting the depth transition whenmade == depth_copyavoids it.pDesc == NULLon typeless twins (real.rsdev_create_uav_x):f(this, twin.as_raw(), std::ptr::null_mut(), desc, at)forwards a nulldescdirectly to the twin. Becausepc_resource_descconverts typed depth formats (D16_UNORM/D32_FLOAT) to typeless (R16_TYPELESS/R32_TYPELESS), D3D12 rejectsCreateUnorderedAccessViewwithpDesc == NULLon the twin unless a typed view desc is synthesized viapc_shader_view_format.note_createdis currently only hooked indevice_x::create_placed_resource_x, so any depth+UAV resource created viadev_create_committed_resource_xordev_create_placed_resource_xwith a non-DEPTH_WRITEinitial state falls back toDEPTH_WRITE.Tested
32.0.16.1074), Ryzen 7 9800X3D, Windows 10 Pro 19045,rustc 1.100.0(debug)cargo test -p xcl --lib depth_twin -- --nocapture: 2 passed, 0 failed, 0 ignored (gpu_a_uav_write_to_a_depth_buffer_goes_through_its_twinran on RTX 5070 and passed)cargo test -p xcl --lib a_depth_buffer_without_unordered_access -- --nocapture: 1 passed, 0 failed, 0 ignoredcargo test -p xcl --lib an_enhanced_barrier_into_or_out_of_unordered_access -- --nocapture: 1 passed, 0 failed, 0 ignoredNot tested
gpu_a_uav_write_to_a_depth_buffer_goes_through_its_twinusesD3D12CreateDevice(None, ...)), D3D12 debug layer (not installed on this host).AI use
3ef1119and the test commands were run locally on the hardware listed.@IvyNotFound on GitHub · 2026-11-24 11:47 UTC · original
Thanks for the review. Points 1–3 were right; fixed in
0322514(squashed into the PR's commit):res_releasecallsdepth_twin::forgeton the last release, so a resource made later at the same address does not take the old state (testa_released_depth_buffers_state_is_forgotten).syncleaves the depth buffer's transition out when it is in the copy's state already (depth_transitions, testa_depth_buffer_in_the_copys_state_is_not_moved_to_it).twin_uav_desc, testa_uav_without_a_description_is_a_typed_view_of_the_twin).Point 4 stays as it is in this PR: depth buffers from the other creation paths fall back to DEPTH_WRITE, listed under Not tested; the retail title's come through
CreatePlacedResourceX.At
0322514on an RTX 5080 (driver 621.24):cargo test -p xcl --lib depth_twin5 passed, 0 failed; the workspace suite and the runs are in the updated description (85 s withXCL_DEPTH_UAV_TWINS=1: 1024+ copies, no device removal).AI use: Claude Code (Claude Opus 5.5) checked the findings against the code, wrote the fixes and this reply, and ran the tests.
@eizispark on GitHub · 2026-11-24 12:02 UTC · original
Hardware test report — commit
0322514Verified clean merge with
main(47efa2e) on0322514d51c6dcb03e5d2bfca6d75975f837eb6c: pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace --no-fail-fast -- --test-threads=4:720 passed, 3 failed, 41 ignored(GPU tests skipped on this adapter:none); the 3 failures under--test-threads=4were the known concurrent global-state tests (hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels,hle::d3d12x::title_textures::tests::transitions_apply_when_their_list_is_submitted,hle::d3d12x::vram::tests::d32s8_targets_take_their_own_size_of_video_memory), each passing solo with--exact --test-threads=1(1 passed, 0 failed)cargo test -p xcl --lib depth_twin -- --nocapture:5 passed, 0 failed, 0 ignored(0 skipped), includinghle::d3d12x::depth_twin::tests::gpu_a_uav_write_to_a_depth_buffer_goes_through_its_twinexecuted on AMD Radeon RX 9070 XT (D16_UNORMclear → twin UAV write → copy-back round trip), plushle::d3d12x::list_x::tests::a_depth_buffer_without_unordered_access_is_one_with_null_uavsandan_enhanced_barrier_into_or_out_of_unordered_access_is_a_uav_use(ok)XCL_DEPTH_UAV_TWINS=1:exit: 0x0,frames shown: 1662 (PresentX 1662),presents per 2 s (last 3): 60 60 60,device removals: 0,crashes: 0,peak commit: 15028 MBRegression run
main(47efa2e):PR (
0322514):Not tested
XCL_D3D12_DEBUG=1; NVIDIA / Intel GPUsAI use: Antigravity (Google DeepMind), Gemini (exact version string not exposed in runtime environment) — ran the workspace test suite,
depth_twinGPU tests, and 60 s retail smoke checks (default andXCL_DEPTH_UAV_TWINS=1) on the hardware above and formatted this report.@juliptree on GitHub · 2026-11-24 12:56 UTC · original · edited 2026-11-24 13:21 UTC
Independently tested 0322514d51c6dcb03e5d2bfca6d75975f837eb6c on an RTX 5060 Ti with NVIDIA driver 616.92. The existing depth_twin tests passed 5/5 on the clean PR head. With a local test-only D32 extension, all 6 passed with zero skips.
After GPU fence completion, all 2,048 texels read back as 0.25 after the D32_FLOAT depth clear copied to the R32_FLOAT UAV twin, and as 0.75 after the UAV write copied back to the depth texture. I verified the actual D3D12 adapter by LUID.
The debug-layer rerun matched both values, but the debug interface returned 0x887A002D, so debug-layer messages were unavailable. I can share the synthetic D32 fixture if you’d like to include it.
The D32 round-trip fixture is available as a single test-only commit on top of 0322514. Feel free to cherry-pick it into this PR. The committed version passed all six depth_twin tests on the RTX 5060 Ti, with zero skips.
Codex (GPT-6) assisted with testing and reporting.
@JoaoPauluu on GitHub · 2026-11-24 14:21 UTC · original
A regression run under Wine on Linux, on a retail title.
Tested
x86_64-pc-windows-gnu.c1af15das it is (merge base47efa2e) andmain47efa2e, no uncommitted changes. Retail title 1.0.2.1,scripts/linux/smoke.sh(#257) for 60 s, no input withXCL_DEPTH_UAV_TWINS=1for this PR's run. Twelve runs in a row,mainfirst and last, other PRs in between.XCL_DEPTH_UAV_TWINS=1, and GTA VI reaches the change: at 39.18–39.23 s the log showsa depth buffer that shaders write (…, format 53) has a twin for its UAVs, up to(256 so far), for buffers from 128x128x6 to 2048x2048x1. There is nono twinline. The log's WARN (72),not kept in step(4) and ERROR (0) counts are the same as onmain, andbackground_pipelinesis the same[228, 0, 57595]. I did not look at the picture: under this setup it is black onmaintoo.Regression run
main (first run):
this PR:
The last
mainrun: 1425 frames,exit: 0x0, no device removal, no crash. Under Wine,peak commitreads 0 MB, so these blocks do not check memory.Not tested
AI use
@DavidM1911 on GitHub · 2026-11-25 09:05 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.