Skip to content

d3d12-gpu: prime a draw's tested depth before its picked textures are read - #2965

Open
aznohonza wants to merge 2 commits into
ProjectLeonida:mainfrom
aznohonza:gpu/draw-depth-read
Open

aznohonza wants to merge 2 commits into
ProjectLeonida:mainfrom
aznohonza:gpu/draw-depth-read

Conversation

@aznohonza

@aznohonza aznohonza commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Re-created from the original #2866. aznohonza/mandy-contrib was made private at 21:41 UTC on 2026-12-01, which detached the fork and permanently closed its pull requests; GitHub refuses to reopen them (422 state cannot be changed). Same branch, rebased on main at 913b88b90; current head c62d57344 (the two commits on top of main). The original review thread is at #2866.


State::bind brings the textures picked by index up to date at its start, and those views go through readable (heap_textures, and flush_for_bake before it). readable is what notes that a draw reads a view of the depth target it only tests: it sets TESTED_DEPTH's read bit, and a read-only depth target then keeps SHADER_RESOURCE in the state State::prepare_for gives it (DEPTH_READ | SHADER_RESOURCE).

TESTED_DEPTH was primed for the draw after that pass, so during it the cell still held the previous draw's target. A heap-indexed read of this draw's own depth target was therefore not marked, the pass left the target in SHADER_RESOURCE alone, and prepare_for then moved it to DEPTH_READ alone while the shader samples it.

This moves the priming before early_textures; the state decision in prepare_for and the states readable picks are unchanged. Reads found by the table walk later in bind were already covered, since that walk is after the priming.

Reported in #2570 by @zmasi (finding: read-only depth plus a heap-indexed read gets DEPTH_READ without SHADER_RESOURCE, pointing at this call).

Verification: rebased over main's draw.rs indirect-batch changes; cargo xwin test --target x86_64-pc-windows-msvc -p leonida-gpu --lib --no-run builds and the suite under Wine (no device here) gives 641 passed / 3 failed / 59 ignored. The three failures are watch::* tests that fail identically on unmodified main under Wine (ran those three from main to confirm). The pass itself could only be read-verified here; the d3d12 CI job builds and runs the workspace's tests. No game data, no new switches.

AI-assisted.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical to #2866 (31e64fcf0), which I reviewed: the depth-prime ordering is right and the suite is green, and merge-tree is clean. Two things from there still stand: there is still no regression test (reverting the ordering stays green), and the bake-path comment is missing. Main has since changed draw.rs (indirect batches), so a rebase plus a re-run of the lib suite is worth doing before merge.

@aznohonza

Copy link
Copy Markdown
Contributor Author

Thanks — both points are accurate: the ordering is a state decision a GPU-less suite cannot see, so reverting it stays green, and the bake-path comment is missing. main has also moved draw.rs since this head, so a rebase and a lib run are needed before merge. I will leave the code as reviewed until the rebase, and add the seam test only if a device-free shape exists — a test that passes on the revert would prove nothing.

AI-assisted.

… read

A read-only depth target that a draw's shaders read through a heap-indexed
view could be left in DEPTH_READ without SHADER_RESOURCE. The textures
picked by index are brought up to date at the start of `State::bind`,
before `TESTED_DEPTH` was set for the draw; their views go through
`readable`, which marks the depth read (and keeps SHADER_RESOURCE in the
state) only when the target it holds is this draw's. It held the previous
draw's, so the read was not marked, and `State::prepare_for` then moved the
target to DEPTH_READ alone.

Set the draw's tested depth before `early_textures`, so the pass reads it
with the draw it belongs to. The state decision in `prepare_for` and the
states `readable` picks are unchanged.
@aznohonza
aznohonza force-pushed the gpu/draw-depth-read branch from 31e64fc to 4d637c3 Compare December 1, 2026 23:16
@aznohonza

Copy link
Copy Markdown
Contributor Author

Rebased on main (913b88b90), so it now sits over the indirect-batch changes in draw.rs; head is 4d637c357. cargo xwin test -p leonida-gpu --lib --no-run builds, and the suite under Wine here gives 641 passed / 3 failed / 59 ignored — the three are watch::* tests that fail identically on unmodified main under Wine (ran those from main).

On the regression test: there is no honest device-free seam. The ordering only matters inside State::bind → early_textures → heap_textures, and all of those need a live HostList (the transition goes through list.transition/ResourceBarrier); readable is already exercised only by device tests, and the failure also needs the early-textures budget and a heap-indexed read of the tested depth. A test that asserted the cell before calling any of that would pass with the ordering reverted too, so it would prove nothing. If you want a device-gated one that drives a real bind with the budget on, say so and I will write it; otherwise I would leave this as reviewed.

KelboLive's review of ProjectLeonida#2866: with the prime in place, `early_textures` runs
`heap_textures` on the separate `bake_list`, so that upload list can also record
the combined-state barrier for the depth target. It is harmless (same state,
tracked per list; the draw's own list gets its transition in `prepare_for`), but
the comment now says so.

AI-assisted: yes
@aznohonza
aznohonza force-pushed the gpu/draw-depth-read branch from 4d637c3 to c62d573 Compare December 1, 2026 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants