D3D12.X: draws that test a depth buffer left in UAV get its twin first #3480

Closed
Foniass wants to merge 1 commit from upstream-pr/3480 into main
Foniass commented 2026-11-30 00:01:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-30T00:01:01Z.


Draft: this needs raylitebull's check (it is his amd-dev commit 0e68d606, adapted to main), and a run that reaches the case.

A depth buffer that shaders write keeps those writes in a twin. depth_uav copies the twin into the depth plane only when the title moves the buffer out of UNORDERED_ACCESS. A draw that tests against the buffer before that, while the title leaves it in UNORDERED_ACCESS, tests the plane as it was before the shaders wrote. In a retail title's mirrors on amd-dev, the mirror showed the sky because of this.

For a stretch that begins with a transition of the whole buffer into UNORDERED_ACCESS on a DIRECT list, the list now follows which side was written last and copies it into the other before the work that uses it:

  • before a draw whose depth target is the buffer: the twin into the plane;
  • before any other draw or dispatch, after such a draw: the plane into the twin.

These are whole-plane copies between states XCL already knows, so nothing bound on the list changes. A stretch without such a draw copies exactly as before.

Port onto main
Main now has depth twins on by default, stencil twins and parked D24S8 buffers (#3290).

  • R24G8 twin dropped: main has no R24G8 depth twin, so its exclusion and copy pass are gone.
  • Where work is seen: the PC DrawInstanced / DrawIndexedInstanced hooks, plus the title's Dispatch / DispatchX, ExecuteIndirect, DispatchMesh and UAV clears.
  • Hook removed: not set_compute_pipeline. On amd-dev that was the only hook, and only XCL's own passes call it, so the title's dispatches were never seen. Combined with the "plane is newer" mark after a draw, that would have dropped a later dispatch's twin writes.
  • Copy target: copies name the object the list saw go into PARK.

The switch and trace that came with it (XCL_DEPTH_PLANE_NOW, XCL_TWIN_TRACE) are in the stacked follow-up.

What is in it

  • crates/xcl/src/hle/d3d12x/depth_uav.rs: Owed / before_work / step, the plan changes, 4 new tests (3 from the original, adapted, and one for a buffer leaving UNORDERED_ACCESS in parts)
  • crates/xcl/src/hle/d3d12x/list_x.rs: depth_twins_before_work, per-list depth_owed
  • crates/xcl/src/hle/d3d12x/real.rs, bind.rs: the calls before draws, dispatches and UAV clears

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. Two of the new tests fail with the plan_with changes taken out.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 4a6f61bf, rebased on main 86e86fcb (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. The title makes depth twins in that run (13 depth UAV twin # lines), but the new copies did not fire (none of their log lines), so the run is only a regression check.

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: 4a6f61bf6619a3a392ec284acfa9e7e039d22a2c
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1616 (PresentX 1616)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18579 MB

Not tested

  • The case itself: nobody has seen yet whether the title leaves the mirror's depth in UNORDERED_ACCESS for those draws. The follow-up's XCL_TWIN_TRACE=736 shows it in a world run.
  • Draws against a depth buffer in COPY_SOURCE: main already draws against the parked buffer in that state, which D3D12 does not allow. This change now relies on those draws seeing what was copied in.
  • Work XCL does not see:
    • bundles;
    • compute queues;
    • draws deferred by XCL_TWO_PASS_BATCH=2;
    • GPU execution order, since sides are followed in recording order;
    • the stencil plane;
    • predication.
  • Cost: each switch between depth-testing draws and other work costs a whole-plane copy; not measured.
  • AMD GPUs; whether the image looks right.

AI use

  • Claude Code with Claude Opus 5.5: ported the commit to main, found and closed the hook gap above, wrote the extra test, ran the tests and the smoke runs, wrote this description.
  • Original code: raylitebull's amd-dev 0e68d606.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5556576814 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3480). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-30T00:01:01Z. --- Draft: this needs raylitebull's check (it is his amd-dev commit `0e68d606`, adapted to main), and a run that reaches the case. A depth buffer that shaders write keeps those writes in a twin. `depth_uav` copies the twin into the depth plane only when the title moves the buffer out of UNORDERED_ACCESS. A draw that tests against the buffer before that, while the title leaves it in UNORDERED_ACCESS, tests the plane as it was before the shaders wrote. In a retail title's mirrors on amd-dev, the mirror showed the sky because of this. For a stretch that begins with a transition of the whole buffer into UNORDERED_ACCESS on a DIRECT list, the list now follows which side was written last and copies it into the other before the work that uses it: - **before a draw whose depth target is the buffer:** the twin into the plane; - **before any other draw or dispatch, after such a draw:** the plane into the twin. These are whole-plane copies between states XCL already knows, so nothing bound on the list changes. A stretch without such a draw copies exactly as before. **Port onto main** Main now has depth twins on by default, stencil twins and parked D24S8 buffers (#3290). - **R24G8 twin dropped:** main has no R24G8 depth twin, so its exclusion and copy pass are gone. - **Where work is seen:** the PC `DrawInstanced` / `DrawIndexedInstanced` hooks, plus the title's `Dispatch` / `DispatchX`, `ExecuteIndirect`, `DispatchMesh` and UAV clears. - **Hook removed:** not `set_compute_pipeline`. On amd-dev that was the only hook, and only XCL's own passes call it, so the title's dispatches were never seen. Combined with the "plane is newer" mark after a draw, that would have dropped a later dispatch's twin writes. - **Copy target:** copies name the object the list saw go into PARK. The switch and trace that came with it (`XCL_DEPTH_PLANE_NOW`, `XCL_TWIN_TRACE`) are in the stacked follow-up. **What is in it** - `crates/xcl/src/hle/d3d12x/depth_uav.rs`: `Owed` / `before_work` / `step`, the plan changes, 4 new tests (3 from the original, adapted, and one for a buffer leaving UNORDERED_ACCESS in parts) - `crates/xcl/src/hle/d3d12x/list_x.rs`: `depth_twins_before_work`, per-list `depth_owed` - `crates/xcl/src/hle/d3d12x/real.rs`, `bind.rs`: the calls before draws, dispatches and UAV clears **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. Two of the new tests fail with the `plan_with` changes taken out. - `cargo test --workspace --no-fail-fast -- --test-threads=4` on 4a6f61bf, rebased on main 86e86fcb (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. The title makes depth twins in that run (13 `depth UAV twin #` lines), but the new copies did not fire (none of their log lines), so the run is only a regression check. **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: 4a6f61bf6619a3a392ec284acfa9e7e039d22a2c gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1616 (PresentX 1616) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18579 MB ``` **Not tested** - **The case itself:** nobody has seen yet whether the title leaves the mirror's depth in UNORDERED_ACCESS for those draws. The follow-up's `XCL_TWIN_TRACE=736` shows it in a world run. - **Draws against a depth buffer in COPY_SOURCE:** main already draws against the parked buffer in that state, which D3D12 does not allow. This change now relies on those draws seeing what was copied in. - **Work XCL does not see:** - bundles; - compute queues; - draws deferred by `XCL_TWO_PASS_BATCH=2`; - GPU execution order, since sides are followed in recording order; - the stencil plane; - predication. - **Cost:** each switch between depth-testing draws and other work costs a whole-plane copy; not measured. - AMD GPUs; whether the image looks right. **AI use** - Claude Code with Claude Opus 5.5: ported the commit to main, found and closed the hook gap above, wrote the extra test, ran the tests and the smoke runs, wrote this description. - Original code: raylitebull's amd-dev `0e68d606`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Foniass commented 2026-12-02 08:05:59 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T08:05:59Z.


Closing: the case this fixes (a draw testing a depth buffer left in UAV before its twin is copied back) has not been seen on main; the copies never fired in the smoke run. Reopen with #3481 if a title is found to take this path (XCL_TWIN_TRACE on #3481 is the tool to show it).

AI-assisted: Claude Code (Claude Opus 5.5), posted by Foniass.

<!-- greyfinch-sync:ivall/xcl:comment:7339001717 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3480#issuecomment-7339001717). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T08:05:59Z. --- Closing: the case this fixes (a draw testing a depth buffer left in UAV before its twin is copied back) has not been seen on main; the copies never fired in the smoke run. Reopen with #3481 if a title is found to take this path (`XCL_TWIN_TRACE` on #3481 is the tool to show it). AI-assisted: Claude Code (Claude Opus 5.5), posted by Foniass.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3480
No description provided.