Repository navigation
Conversation
5 tasks
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>
Foniass
force-pushed
the
d3d12x-depth-twin-before-draws
branch
from
November 30, 2026 23:07
032d205 to
4a6f61b
Compare
This was referenced Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_uavcopies 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:
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).
DrawInstanced/DrawIndexedInstancedhooks, plus the title'sDispatch/DispatchX,ExecuteIndirect,DispatchMeshand UAV clears.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.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-listdepth_owedcrates/xcl/src/hle/d3d12x/real.rs,bind.rs: the calls before draws, dispatches and UAV clearsTested
cargo test -p xcl --lib depth_uav: 23 passed, 0 failed. Two of the new tests fail with theplan_withchanges taken out.cargo test --workspace --no-fail-fast -- --test-threads=4on 4a6f61b, rebased on main 86e86fc (5070 Ti): 2893 passed, 0 failed, 51 ignored. SKIPPED: 28 notices, almost allno 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.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:
this PR:
Not tested
XCL_TWIN_TRACE=736shows it in a world run.XCL_TWO_PASS_BATCH=2;AI use
0e68d606.🤖 Generated with Claude Code