D3D12.X: depth UAV twins on by default, stencil twins copied with the plane #3290
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3290"
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?
Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T05:51:08Z.
A title's tiled lighting tests depth EQUAL against a class buffer (a console D16S8 depth buffer, R24G8 on the PC) that only compute writes, through a UAV of that depth buffer. The PC has no UAV of a depth format, so
depth_uavgives such a buffer a twin the shaders write instead, copied to and from the depth plane around the title's transitions. That was opt-in (XCL_DEPTH_UAV_TWIN=1) and covered the depth plane only.XCL_DEPTH_UAV_TWIN=0turns them off).StencilCopy,list_x::stencil_copies_on). No colour format shares a family with a depth-stencil one, but the PC copies between a buffer and one plane.This is one of the two pieces amd-dev used to light the retail world; the other, barrier groups (#146: #3287 / #3299), turns the title's enhanced barriers into the transitions that reach
plan_barriers. This PR does not depend on it: without it, the title's legacy barriers still reachplan_barriers.Review fixes (throny, andrewDoing):
plan_barriersas it came: only buffers whose depth plane can have a twin were taken, so its stencil twin was never copied, and its UNORDERED_ACCESS transition went to the PC, where a depth-stencil buffer cannot be in that state (andrewDoing's run:Closefailed withE_INVALIDARG). Its transitions are now parked like the others (parked): its depth plane is not copied, its stencil twin is.entered: after a way in on a compute list, or with a twin made since, it would write stale or empty twin contents over the plane. It now copies back only after a copied way in (Cell::stencil_entered).kept()is back to tests only, and the module comment no longer namesbarrier_groups, which main does not have.a_stencil_twin_is_copied_around_unordered_access_after_a_copied_way_in(console D16S8 and D32S8), and the D24S8 case inonly_depth_plane_subresources_are_copied_and_other_buffers_go_as_they_came(now parked; before, it went as it came).What is in it
crates/xcl/src/hle/d3d12x/depth_uav.rs:DEFAULT_ON = true, the stencil twin's buffer (through),StencilCopy, the stencil part ofplan_barriers(parked,stencil_entered); with the underflow fix of amd-deva46703b6(then_some(sub - n)evaluatedsub - nfor every subresource, a panic in debug builds whensub < n)crates/xcl/src/hle/d3d12x/list_x.rs:stencil_copies_onand its two calls aroundplane_copies_onTested
cargo test --workspace --no-fail-fast -- --test-threads=4on4dd049f6: 2605 passed, 4 failed, 49 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(E_OUTOFMEMORYfromCreateComputePipelineState, seeds 70 / 545 / 1019 / 1507). They fail the same way on this branch's base, mainfa204595, on this machine, and pass here on newer main (#3264, rebased onto0fe06eb0, has 0 failures). SKIPPED GPU tests: 44 distinct notices, almost allno wave64.depth UAV twin #1...). I did not check which scenes a 60 s run reaches, so it does not show whether the tiled lighting changed.Regression run
main:
this PR:
Not tested
AI use
a68f609fand the fix ofa46703b6to main, resolved the conflicts, made the review fixes and their tests, ran the tests and the smoke run, wrote this description.a68f609fanda46703b6(raylitebull, written with Claude Code).🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T06:11:58Z.
On
3370d35f, the DIRECT-list planner skips the stencil copy for console D16S8 (118), which becomes R24G8_TYPELESS (44). A test on an RTX 5070, driver 616.92, created the R8 stencil UAV twin successfully. With the stock planner predicate, recording two alternating stencil-plane updates produced zero stencil-copy messages and command-list Close returned E_INVALIDARG (0x80070057). The fixture stopped before submitting that list.In
depth_uav::plan_with,filter(plane_twinnable)admits formats 19, 39 and 53. The later stencil branch explicitly handles 19 and 44, so 44 cannot reach it. I repeated the same synthetic fixture in a fresh process with one test-only change to admit format 44 for stencil subresource 1 of this single-mip, single-slice resource. That recorded two copies in each direction, completed the fence, and matched both planes on all 256 texels after each round:The fixture used the guest stencil UAV creation, legacy ResourceBarrier and ClearUnorderedAccessViewUint paths, and read back the original depth/stencil resource. This points to separating stencil-copy eligibility from depth-plane-twin eligibility. The narrow diagnostic covered plane-specific DIRECT transitions on one resource. Whole-resource transitions, enhanced barriers and retail lighting remain untested here.
AI disclosure: OpenAI Codex prepared and ran the fixture and drafted this report.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T07:54:00Z.
merge-check
base:
fa204595head:
3370d35fverdict: safe to merge
Merged cleanly onto
origin/main(fa204595) in a 5-PR batch (#3288,#3290,#3292,#3294,#3300) and verified on NVIDIA GeForce RTX 5070 Ti with DXC 1.9.2609.5:gpu_a_stencil_uav_of_a_console_depth_buffer_is_a_view_of_its_twin,gpu_clear_uav_of_a_stencil_uav_clears_the_twin,gpu_a_stencil_uav_by_address_is_a_view_of_the_placed_buffers_twin): all passed on RTX 5070 Ti.gpu::: 853 passed, 0 failed, 24 ignored (10.45 s, includingfuzz_validate_and_gpu_0..3).hle::d3d12x::(--test-threads=1, skipping 2 knownmain#3187uma_drivermixed-window tests): 1144 passed, 0 failed, 3 ignored (30.21 s).xcl --lib(--test-threads=1): 0 failed.-p xcl --test e2e(after rebuildingxcl-testtitle): 5 passed, 0 failed (including D3D12 debug layer + DRED).Build and test (Windows, no GPU)andPR description): green.Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:21:17Z.
merge-check claim
head:
3370d35f36Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:36:08Z.
merge-check
base:
d8bd9a38head:
3370d35f36merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2618 passed, 0 failed, 49 ignored: the same count as the base, so the suite runs no new test for this change (27 SKIPPED lines). Base alone at
d8bd9a38: 2618 passed, 0 failed, 49 ignored.review: three findings from reading the diff against main
d8bd9a38. (1) The new stencil copy is selected withmatches!(key.format, 19 | 44), but it runs only for objects that passplane_twinnable, which on main accepts formats 19, 39 and 53. Format 44 never gets there, so its stencil twin is never copied although the code reads as if it were. (2) The copy from the stencil twin back into the plane on the way out of UNORDERED_ACCESS has no guard like the depth path'sentered; on a compute list, or before the twin exists, the way in copies nothing, so the way out can write stale or empty twin contents over the plane's stencil. The missing guard is confirmed by reading; the effect is my reading of it, not a run. (3)kept()loses#[cfg(test)]and the module comment names a callerbarrier_groups, which does not exist on main or in this diff, so this looks stacked on work that is not merged. On top of that the switch goes on by default while the new stencil copies and the staging buffer have no test (the existing tests only gainthrough: None). Cost when on: one twin per depth buffer the title gives unordered access (an R8 texture and a staging buffer more for a stencil twin), and for a depth-stencil target two copies and two to three barrier calls per subresource in each direction, never skipped.XCL_DEPTH_UAV_TWIN=0turns it off.performance: not measured.
verdict: not yet: fix (1) and (2) with a test of the stencil path, say what
kept()is for on main (or stack the PR on its base), and show a title run with the default on.hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T17:18:58Z.
Thanks throny and andrewDoing, both findings were right. Fixed in
4dd049f6:parked). Their transitions into and out of UNORDERED_ACCESS go to COPY_SOURCE like the others, so no depth-stencil buffer is left in UNORDERED_ACCESS on the PC. Their depth plane is not copied (it has no twin), and their stencil twin is. This is andrewDoing's change of admitting 44 for the stencil plane, without giving 44 a depth twin.Cell::stencil_entered, likeenteredfor the depth plane). After a way in on a compute list, or with a twin made since the way in, nothing is copied back.kept()is back to#[cfg(test)], and the module comment no longer namesbarrier_groups. This PR does not depend on #3287 / #3299.a_stencil_twin_is_copied_around_unordered_access_after_a_copied_way_in(console D16S8 and D32S8: no twin, twin made since, direct way in, compute way in, the stencil subresource alone). The existing D24S8 case now expects "parked".About a title run with the default on: the smoke run in the description has it on, and the title makes depth twins there (R16 twins of D16 buffers, from its log). It makes no stencil twin in that run, so the stencil copies were only exercised by the planner tests. The PR says so under Not tested.
(Written with Claude Code, Claude Opus 5.5.)
Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T18:23:20Z.
Note for the maintainers: this PR and #3089 (imnicho) both change
hle/d3d12x/depth_uav.rsand conflict with each other: a test merge of both onto main gives a content conflict there. Each merges cleanly on its own.They also both handle R24G8 (console D16S8 / D24S8) depth buffers, in different ways:
XCL_DEPTH_UAV_TWIN=1, gives the depth plane of an R24G8 buffer a twin and draws it into the plane before the buffer's DSV is bound.parked), and copies its stencil plane's twin around them. The depth plane is not copied, because here it has no twin.Whichever merges second needs a rebase, and its author should check that the two R24G8 paths fit together: with both, an R24G8 buffer would have a depth twin, so this PR's depth-plane copies would apply to it as well.
(Written with Claude Code, Claude Opus 5.5.)