d3d12-gpu: prime a draw's tested depth before its picked textures are read #2965
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2965"
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 ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T21:55:56Z.
Re-created from the original #2866.
aznohonza/mandy-contribwas 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 onmainat913b88b90; current headc62d57344(the two commits on top of main). The original review thread is at #2866.State::bindbrings the textures picked by index up to date at its start, and those views go throughreadable(heap_textures, andflush_for_bakebefore it).readableis what notes that a draw reads a view of the depth target it only tests: it setsTESTED_DEPTH's read bit, and a read-only depth target then keepsSHADER_RESOURCEin the stateState::prepare_forgives it (DEPTH_READ | SHADER_RESOURCE).TESTED_DEPTHwas 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 inSHADER_RESOURCEalone, andprepare_forthen moved it toDEPTH_READalone while the shader samples it.This moves the priming before
early_textures; the state decision inprepare_forand the statesreadablepicks are unchanged. Reads found by the table walk later inbindwere 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.rsindirect-batch changes;cargo xwin test --target x86_64-pc-windows-msvc -p leonida-gpu --lib --no-runbuilds and the suite under Wine (no device here) gives 641 passed / 3 failed / 59 ignored. The three failures arewatch::*tests that fail identically on unmodifiedmainunder Wine (ran those three frommainto confirm). The pass itself could only be read-verified here; thed3d12CI job builds and runs the workspace's tests. No game data, no new switches.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T22:19:25Z.
Review: COMMENTED
Identical to #2866 (
31e64fcf0), which I reviewed: the depth-prime ordering is right and the suite is green, andmerge-treeis 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 changeddraw.rs(indirect batches), so a rebase plus a re-run of the lib suite is worth doing before merge.Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T22:28:19Z.
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.
mainhas also moveddraw.rssince 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.
Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T23:16:33Z.
Rebased on
main(913b88b90), so it now sits over the indirect-batch changes indraw.rs; head is4d637c357.cargo xwin test -p leonida-gpu --lib --no-runbuilds, and the suite under Wine here gives 641 passed / 3 failed / 59 ignored — the three arewatch::*tests that fail identically on unmodifiedmainunder Wine (ran those frommain).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 liveHostList(the transition goes throughlist.transition/ResourceBarrier);readableis 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.Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T11:25:20Z.
VERIFY-2965 — Linux, Fedora 45, Rust 1.98.1, cross-compiled for x86_64-pc-windows-gnu, Wine 11.21, no GPU device (only a VMware SVGA virtual adapter; Wine's D3D12 sees only the llvmpipe CPU device and the runtime still makes no host device), no game files
Verdict: PASS. The depth target a draw only tests is now primed into
TESTED_DEPTHbeforeearly_textures, so a heap-indexed read of that target by the draw's own shaders is recognised and the target keepsSHADER_RESOURCEin the stateprepare_forgives it. The move is the whole fix, it is at the root cause (the priming was after the pass that needs it), the statesreadablepicks and theprepare_fordecision are unchanged, and the bake pass — which runs the sameearly_textures→heap_textureson its own list — now records the combined-state barrier too. No test in the crate regresses: 703 tests on each side, 0 regressions; the only red→green is awatchflake. The standing caveat, which the author and the reviewer both state, is that there is no regression test: the ordering is a state decision a device-free suite cannot see, so reverting the change stays green.head
c62d57344132b8e7511e8748464b4faa763ecc80("d3d12-gpu: the bake pass records the same combined-state barrier too" on "d3d12-gpu: prime a draw's tested depth before its picked textures are read"), baseorigin/main=a917c54d6aff8c9ef5dda2d8ebf938cb5c693902, merge base913b88b9054de123a78fae0aea5ee24e10b7cb1d(134 commits behindmain). One file, +15/−8:d3d12/crates/leonida-gpu/src/draw.rs.1. What it changes
State::bind(draw.rs:3096) prepares a draw's host list. The draw's tested depth target is carried in the thread-localTESTED_DEPTH: Cell<(usize, bool)>(draw.rs:191-196) — the target the draw only tests (0: none or one it writes) and whether a view its shaders read is of that same texture.readable(draw.rs:7747) consults it: when a view's source is the tested target it sets the read bit and returns the combined stateDEPTH_READ | SHADER_RESOURCE(draw.rs:7778-7781 and 7815-7818); otherwiseSHADER_RESOURCE. Afterbindreturns,prepare_for's depth block (draw.rs:3074-3084) reads the same cell:if read && tested == self.depth { DEPTH_READ | SHADER_RESOURCE } else { DEPTH_READ }.The change moves the priming from after
early_texturesto before it (draw.rs:3123-3128 now, 3177 before):The block itself is identical (
let tested = if !compute && self.depth_state == DEPTH_READ { self.depth } else { 0 }; TESTED_DEPTH.set((tested, false));), and the second commit (c62d5734) only adds the bake-path comment at draw.rs:3119-3122.2. The claims, checked
State::bindbrings the textures picked by index up to date at its start, and those views go throughreadable." — Confirmed.bindcallsearly_texturesat draw.rs:3130, which callsheap_textures(draw.rs:4126) and reachesreadablefor the views it brings up to date.readableis what notes that a draw reads a view of the depth target it only tests: it setsTESTED_DEPTH's read bit." — Confirmed. draw.rs:7778-7781 (the aliased-cast arm) and 7815-7818 (the placed/host-copy arm) both doTESTED_DEPTH.set((tested, true))whentested == *resource, and returnDEPTH_READ | SHADER_RESOURCE.TESTED_DEPTHwas primed for the draw after that pass, so during it the cell still held the previous draw's target." — Confirmed. In the merge-base code the priming was at draw.rs:3177, andearly_texturesran at 3115 — before it. So duringearly_textures,TESTED_DEPTHheld the previous draw's(tested, read). The merge-base depth block (draw.rs:3074-3084, which runs afterbind) then read that stale pair:tested == self.depthwas false for the new draw, so it gaveDEPTH_READalone.SHADER_RESOURCEalone, andprepare_forthen moved it toDEPTH_READalone while the shader samples it." — Confirmed by the same trace.readablefor a view of the draw's own target returnedSHADER_RESOURCE(it did not match the staletested), andprepare_for's depth block then calledensure_state(list, self.depth, DEPTH_READ)(draw.rs:3084) — so the target ended inDEPTH_READalone, withSHADER_RESOURCEremoved, while a shader of this draw samples it. That is the wrong barrier state for a shader read.prepare_forand the statesreadablepicks are unchanged." — Confirmed. The move changes only when the priming runs, not thetestedexpression or either state choice.bindwere already covered, since that walk is after the priming." — Confirmed. The table walk is thefor stage in &p.stagesloop (draw.rs:3213), and in the merge base it was at 3206 — after the priming at 3177. So onlyearly_textures(before the old priming) was uncovered, and the move covers it. The fix is exactly scoped.early_textures→heap_texturesonbake_list), so it can now record the combined-state barrier for this target too." — Confirmed.early_texturesrunsheap_textures(bake_list, ...)at draw.rs:3941 when aBakeListis in use, on the same thread, so with the priming beforeearly_texturesthe bake pass'sreadablecalls see this draw'stestedand record the combined state on the bake list as well. This is the second commit's point, and it is a consequence of the same move, not a separate code change.3. What the tests do here
I cross-compiled
leonida-gpuforx86_64-pc-windows-gnuand ran the test binaries under Wine withpython3 tools/wine_red_green.py 2965 --crate leonida-gpu(from/home/shangli/oc-workspace/gta6). The pull request changes only source, so the verifier's red side is the merge base and the green side is the head.913b88b90(merge base)c62d5734(PR head)The tool printed "red then green", but its 1 red→green is a
watchflake:watch::tests::a_block_just_written_restsfailed on the base and passed on the head. The PR touches onlydraw.rs;watchis a different module, and the same threewatchtests fail on the base and the head (holes_are_known_until_the_runtime_tells,no_mapping_is_lost_between_askers,what_is_left_alone_is_no_known_hole). So the real result is 0 regressions; the "red then green" verdict is the flakywatchguard-page machinery under Wine without a real GPU. 640 tests pass on both sides, 59 areignored, and everydraw::test isokon both sides.State::bind/prepare_forneed a liveHostListandHostPipeline, i.e. a host device. On this machinehost()isNone(Wine's D3D12 finds only the llvmpipe CPU device —Found device: llvmpipe (LLVM 23.1.5, 256 bits)— butHost::create()still fails, so the ignoreddump_buffer_view_descriptor_bytesprobe panics with "an active D3D12 device" anddepth_bounds_pipeline_loads_and_filters_drawsreturns at itshost()guard). Thereplayintegration tests that would driveState::bindend-to-end are# and the verifier runs without--features diagnostics, so they are not compiled. So the wine_red_green run confirms only that the reordering does not regress the device-free suite, not that it fixes the state decision. The reviewers and the author say the same ("the ordering is a state decision a GPU-less suite cannot see, so reverting it stays green").4. Any failure I saw and why it is not this PR
watchfailures (§3) fail on the merge base too and are environment failures of the guard-page/exception machinery under Wine without a real GPU; the PR touches none ofwatch.rs. The 1 red→green flake is the same class (a differentwatchtest than in the #2823 run, so the flakiness is not a fixed set).5. One thing worth the author's attention (not a defect, already on record)
State::bind→early_textures→heap_textures, which need a liveHostList(the transition goes throughlist.transition/ResourceBarrier). The author plans a seam test "only if a device-free shape exists". So the fix rests on the ordering analysis and the reviewers' agreement, not on a test. This is the one substantive caveat; it does not change the verdict, but it means the change would not be caught if the ordering were re-broken.6. What I did not check
early_textures→heap_texturesonbake_list(draw.rs:3913-3975) and that the same thread runs it, but did not observe a bake pass record the combined barrier.913b88b90, 134 commits behind today'smain(a917c54d). The red/green run is against the merge base; I did not check the change still applies tomain(the author rebased on913b88b90and reports the indirect-batch changes are covered).cargo test --target x86_64-pc-windows-gnuunder Wine 11.21 on Fedora 45; a real Windows driver/ABI is not exercised.replayintegration tests (--features diagnostics) were not run — they need the diagnostics feature (and a device), and the verifier passes neither.leonida-hle,leonida-loader) and the repository's Python suite were not run; the change is confined toleonida-gpu.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T12:33:12Z.
This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).
Could you, or anyone with a working setup, post a run report on the current head merged onto current
main:mainSHA it was merged onto;mainalone for comparison, if you can.Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T15:09:16Z.
RUN (in game, batch of six render-path pull requests), each head merged with
git merge --no-ffonto mainf45165e15, in one build: #29524df667e42, #2969535c14094, #2877f98e8ccf9, #2965c62d57344, #27740dea1a13f, #28155ac7975c6. RTX 4060 8 GB, driver 610.88, Windows 11. Series S,-Resolution 1080, frame generation 2x, the same walking route as the other runs on this machine, 330 s after reaching the world.For reference, the same machine and route rendered 13.3 to 15.2 fps today on main with single pull requests. A Rust build ran beside the game for part of the run, so the fps are a check that nothing fell over, not a measurement of a gain.
Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch. If one of these pull requests changes its head, this run no longer covers it.
Limits: one run; free system memory was low (median 1.1 GB); arrival in the world was driven by keys and not checked on pictures. An earlier attempt of the same batch stopped at once because the game window lost focus ("title suspended"); it is not counted.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T15:56:50Z.
RUN (independent run on Windows, #2965 head
c62d57344, merged locally intomainf45165e15withgit merge --no-ff, as part of a batch of six)The in-game run of the batch is already posted on this pull request; this comment is the test side only (no game data, no game files).
Red: the PR adds no test, and none fails when it is removed.
TESTED_DEPTHback afterearly_textures): leonida-gpu lib 690 passed plus one of the intermittent failures listed below.if false && !compute && ...atdraw.rs:3123): same 690 / 1.Nothing in the suite reads the state
prepare_forpicks after a heap-indexed read of a read-only depth target.Green (whole batch, one tree, Windows 11, debug profile as
d3d12.ymlruns it):cargo test --workspace --exclude xtask --locked: 1708 passed, 0 failed, 75 ignored (leonida-gpu lib 691 / 59 ignored, leonida-shader lib 248 / 2 ignored, leonida app 44, leonida-formats 47, leonida-menu 48, leonida-pe 36).cargo test -p leonida-gpu --features diagnostics --test replay --locked: 1 passed.cargo test -p xtask --locked: 7 passed.texture::alias_cast_tests::committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers,watch::tests::a_write_opens_the_view_it_goes_through,pipeline::make::tests::overlapping_waits_cost_the_frame_its_budget_once); each passes alone, a later full run was 691/0, andmainf45165e15alone failed the alias_cast test in 2 of 3 runs.Mutations: revert of the move, not killed;
testedalways 0, not killed. Only a test with a depth target tested by a draw and read through a heap index would kill them.Review: the move reads as safe.
self.depthandself.depth_stateare only written in the set-target code (draw.rs:2668-2673), never between the old and the new place, sotestedhas the same value.TESTED_DEPTHis athread_local!Cell<(usize, bool)>withconstinit and no destructor, so thethread_localdestructor trap ofgta6rt.exedoes not apply (and this is leonida-gpu).bind, before the pass, so the read bitearly_texturesnow sets reachesprepare_for(draw.rs:3075) and the next bind clears it.bake_listand can now record the combined-state barrier for the tested target there. The new comment says so and states are tracked per list, but this can only be judged on a device. Withearly_budgets()at zero the pass returns at once, so default behaviour is unchanged.Not covered: the state transition itself (needs a device and a draw with such a read), and the bake-list barrier.
Verdict: PARTIAL. The code reads correct and the in-game run is the only evidence; no test pins it.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:02:45Z.
Code review only, not built (Windows-only
leonida-gpu). Ready.c62d57344, merge base913b88b90, 313 behind currentmain45dc41f95. A trial merge is clean. CI on the head: all 6 checks pass.Review of
d3d12/crates/leonida-gpu/src/draw.rs:TESTED_DEPTH.set(..)from after the root-signature and heap block to beforeself.early_textures(list, p, compute).early_texturesreachesheap_textures, which reads a picked view of the tested depth target throughreadable. Priming it first is the root-cause fix: otherwise that pass sees0and leaves the target out ofSHADER_RESOURCE.!compute && depth_state == DEPTH_READ) is unchanged, and nothing between the old and new positions changesself.depthorself.depth_state. So the only behaviour change is that the early pass now sees it.early_textures, so it now records the combined-state barrier for this target too. The new comment states this.TESTED_DEPTHis set whenearly_texturesruns would pin it. It is not required for the fix.Verdict: ready.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T21:35:06Z.
RUN (independent run on Windows, head
c62d57344132b8e7511e8748464b4faa763ecc80, merged intomain8877be372bac025153488fc56c2b6122f98ec44dwithgit merge --no-ff)The merge is clean (auto-merge of
d3d12/crates/leonida-gpu/src/draw.rs, no conflict). The PR is one file, +15/-8. This is the test side and a code read only: no game data, no game files, no GPU run.Green (Windows 11, release profile,
CARGO_TARGET_DIRoutside the checkout):cargo test -p leonida-gpu --release --locked --libon the merged tree: 703 passed, 0 failed, 59 ignored.--features diagnostics --libnot run: the PR touches no diagnostics code. No Python test is touched.leonida-gpufailures MoonEyes saw on an earlier batch did not show up in this run.Red: the PR adds no test, so I mutated the new code instead. All three survive (703 passed, 0 failed each time):
main(priming ofTESTED_DEPTHafterearly_textures, i.e. the pre-PR order): survives.testedforced to 0 (if false && ...): survives.!computeguard dropped from thetestedexpression: survives.So nothing in the suite reads the state
prepare_forpicks after a heap-indexed read of a read-only depth target. This matches the author's and KelboLive's remark that there is no device-free seam, and the earlier red run of MoonEyes.Review:
TESTED_DEPTHmoves from after the root-signature/heap block to beforeself.early_textures(list, p, compute). The expression is unchanged. In the diff nothing between the old and the new place writesself.depthorself.depth_state, so the value is the same and the early pass now sees this draw's target instead of the previous draw's. The table walk is still after the priming. Reads as correct.docs/switches.mddoes not need to be regenerated. The early pass only acts when the early-texture budget is on, so default behaviour is not expected to change.TESTED_DEPTHis a plainCellthread-local and is still reset once perbind, so no stale read bit survives into the next draw. No newthread_localwith a destructor.bake_listand can now record the combinedDEPTH_READ | SHADER_RESOURCEbarrier for the tested target there. The new comment says states are tracked per list; this can only be judged on a device.finding: read-only depth plus a heap-indexed read ...) and re-creates the closed #2866. It names no item ID from the coordination issue and noissues/14or 1608 link; the #2570 link is the claim.leonida-gpu/src/draw.rs: #3164, #3128, #2958, #2915, #2834, #2801, #2661, #2580. None of them is about the depth priming. Textual overlap withbindwas not checked beyond this PR merging cleanly into currentmain.c62d57344(RTX 4060, 330 s in the world, 0 device lost, median 14.9 fps, as part of a batch of six onmainf45165e15). Thatmainis not the current one (8877be372), and the head has not changed since.Not covered:
--features diagnosticsreplay test, the other crates, the Python suite.Verdict: PARTIAL. Tests are green on the merge and the move reads as the right root-cause fix, but no test pins it (three mutations survive). The in-game gate is already posted on this head (batch run on an older
main), so no new in-game run is strictly required unless the head changes; a device-gated test would close the gap.AI-assisted (Claude Code), models: Claude Opus 5.5 (checker), separate Claude Opus 5.5 judge.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T22:17:45Z.
Merging. Head
c62d57344merges cleanly withmainf3865cae8and does not force a rebase of #2566. In-game run on this head by MoonEyes (RTX 4060 8 GB, driver 610.88, Windows 11, 330 s in the world, 0 device lost: https://github.com/ProjectLeonida/mandy/pull/2965#issuecomment-7349821392) and an independent red/green on this head, both checked by a separate judge. Merged by MoonEyes.AI-assisted (Claude Code).