Skip to content

D3D12.X: XCL_DEPTH_PLANE_NOW and XCL_TWIN_TRACE for depth twins in UAV - #3481

Draft
Foniass wants to merge 2 commits into
xcl-dev:mainfrom
Foniass:d3d12x-depth-twin-trace
Draft

Foniass wants to merge 2 commits into
xcl-dev:mainfrom
Foniass:d3d12x-depth-twin-trace

Conversation

@Foniass

@Foniass Foniass commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Draft, stacked on #3480; only the top commit (ae2976f6) belongs here.

The switch and the trace that came with raylitebull's amd-dev 0e68d606, split from #3480 because CONTRIBUTING wants diagnostics and env switches on their own:

What is in it

  • crates/xcl/src/hle/d3d12x/depth_uav.rs, list_x.rs, real.rs: the switch and the trace lines (the R24G8 copy pass's lines are left out, as main has no R24G8 twin)

Tested

  • NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • cargo test -p xcl --lib depth_uav: 23 passed, 0 failed
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on ae2976f, rebased on main 86e86fc (5070 Ti): 2893 passed, 0 failed, 51 ignored. SKIPPED: 28 notices, almost all no wave64 (the others: no D3D12 debug layer, heap windows off, driver cache needs Developer Mode). The narrower runs listed here are from before the rebase.
  • Retail title: 60 s smoke run below, both switches unset

Regression run

main:

xcl-smoke v1
commit: 86e86fcb33f94fa5d0c809d9b50af7b84bf49cce
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1608 (PresentX 1608)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15766 MB

this PR:

xcl-smoke v1
commit: ae2976f6e6924ec4f15d52232f61d46e1837abe8
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1604 (PresentX 1604)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17611 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5: split the switch and trace out of the port, ran the tests and the smoke runs, wrote this description.
  • Original code: raylitebull's amd-dev 0e68d606.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 30, 2026
raylitebull and others added 2 commits November 30, 2026 22:43
A depth buffer that shaders write keeps those writes in a twin, which
depth_uav copies into the depth plane only where the title moves the
buffer out of UNORDERED_ACCESS. A draw that tests against the buffer
before that, with the title leaving it in UNORDERED_ACCESS, tests the
plane as it was before the shaders wrote the twin.

VIctory-Neo (7da5c9d, "the depth image a pixel program wrote is brought
up to date before the draws that test against it") found this in a
retail title's mirrors: a pixel program (PS_Prepass_StencilCulling)
writes the depth of the mirror's view through unordered access, and the
draws of that view, in the same list, test against it. With the copy
left for later every one of them tested the old plane and the mirror
showed the sky. Neo does the copy (its plane pass) right before such a
draw and sets the title's state again after it.

Here, for a stretch that begins with a transition of all of a buffer
into UNORDERED_ACCESS on a DIRECT list (the twin then holds the plane),
the list follows which side was written last and copies it into the
other before the work that uses that one (depth_uav::before_work):

- a draw whose depth target names the buffer: the twin into the plane
  first, once until other work may have written the twin again;
- any other draw or dispatch (it may write the twin: XCL does not see
  which views a translated shader reaches): the plane into the twin
  first when such a draw tested (and may have written) the plane;
- the way out of UNORDERED_ACCESS after such draws does not copy the
  twin over the plane.

These are whole-plane CopyTextureRegion calls between states XCL knows
(the buffer rests in PARK, the twin in UNORDERED_ACCESS), so nothing
bound on the list changes and nothing needs to be set again. A stretch
without such a draw copies exactly as before. A list that did not see
the stretch begin follows it from its first draw that tests against the
buffer.

Not seen in an XCL run yet: whether the title leaves the mirror's depth
in UNORDERED_ACCESS for those draws (Neo follows uses, not transitions).

Port onto main (depth twins on by default, stencil twins, parked D24S8):
no R24G8 depth twin here, so its exclusion and copy pass are gone (a
D24S8 never starts a stretch); the work is seen at the PC DrawInstanced /
DrawIndexedInstanced hooks, the title's Dispatch/DispatchX, ExecuteIndirect
and DispatchMesh (which go past those hooks) and the UAV clears, not at
set_compute_pipeline (XCL's own passes) nor the PC ExecuteIndirect hook
(XCL's split dispatches would count as draws there); copies name the
object the list saw go into PARK; a buffer leaving UNORDERED_ACCESS in
parts after a draw wrote its plane keeps the plane for every part. The
XCL_DEPTH_PLANE_NOW and XCL_TWIN_TRACE switches are in the next commit.

(cherry picked from commit 77dfb95595855fca9c8360f73031e45061faee72)
(cherry picked from commit 0e68d60)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The switch and the trace that came with "draws that test a depth buffer
left in UAV get its twin first" (raylitebull, 0e68d60 on amd-dev), split
from it as CONTRIBUTING asks for diagnostics and env-var switches.

XCL_DEPTH_PLANE_NOW=0 turns the following of draws inside a stretch in
UNORDERED_ACCESS off (on by default): no stretch begins, so the copies
are made around the title's transitions only, as before it.
XCL_TWIN_TRACE=<height> logs, for depth buffers of that height (736: a
mirror's view in a retail title), the title's transitions into and out
of UNORDERED_ACCESS, the UAVs made on twins, the twin copies, the DSV
binds and the draws that test against them (first 600 lines), so a game
run shows which of these the title does.

Port onto main: the trace lines of the R24G8 copy pass are gone (main
has no R24G8 depth twin); the rest is as in the original.

(cherry picked from commit 77dfb95595855fca9c8360f73031e45061faee72)
(cherry picked from commit 0e68d60)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants