d3d12-gpu: record enhanced barriers as the legacy ones they stand for #2906
Closed
github-bot
wants to merge 5 commits from
github-bot/gh-2906 into main
AGit
pull from: github-bot/gh-2906
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2906
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2906"
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?
@aznohonza on GitHub · 2026-12-01 17:12 UTC · original
aznohonza:gpu/record-enhanced-barriers→main· +447 −1 · 1 files · 5 commits · closed without mergingreplay/record.rslistedID3D12GraphicsCommandList7::Barrieras not recorded, so a stream that used enhanced barriers lost those ordering points when it was replayed. This hooks the method and records each group as the legacy barriers the runtime itself uses for the same wait:play::wait_for_allfalls back to on a device without enhanced barriers.D3D12_RESOURCE_STATESits layouts stand for (layout_state), with the subresource the range names when it names one. A same-state barrier becomes the UAV barrier it stands for, or nothing at all: a real device rejects a transition to the state it is already in (E_INVALIDARG).The wire already carries
Cmd::Barriers, and playback already issues those legacy barriers, so nothing changes inplay.rsorwire.rs. The enhanced sync/access masks order the same accesses with less; the recorded legacy barriers are the same waits, never fewer.One stated shortcut: a texture range naming more than one subresource is recorded as the whole resource, since a legacy transition carries one subresource. That is conservative; a title that keeps two subresources of one texture in different layouts at once would need the wire extended. The code says so where it happens.
Verification:
layout_statecovers every layout and both queue-specific forms;enhanced_records_its_texture_and_buffer_barriersdrivesenhanced()itself with texture and buffer groups,same_state_texture_barriers_are_a_wait_or_nothingcovers the same-state forms, andone_subresource_ranges_flatten_to_that_subresourcethe range forms.The workspace also checks with the default features (
cargo xwin check --target x86_64-pc-windows-msvc --workspace --all-targets --locked). Replay is behind thediagnosticsfeature, so that unit test runs withcargo test -p leonida-gpu --features diagnostics --lib; there is no D3D12 device on this Linux host, so the recorded-and-replayed path itself is compile/read-verified here and exercised by the crate's device tests on Windows. No game data, no new switch.Claimed in #2570 (RS-RECORD-ENHANCED-BARRIERS). AI-assisted.
@Kal0s-design on GitHub · 2026-12-01 17:30 UTC · original
Checked on native Windows 11 with a real D3D12 device (rustc 1.98.1, MSVC target), since the run in the description is under Wine.
Head
e18eeaf6emerged withmaind2a564b66(clean merge):cargo test -p leonida-gpu --features diagnostics --lib replay::: 25 passed, 0 failed.enhanced_layouts_record_as_the_states_they_stand_forpasses.21 => 6changed to21 => 1(direct-queue shader resource mapped as generic read), it fails withleft: 2755, right: 192.One case that would break playback: a texture barrier whose two layouts map to the same state.
Enhanced barriers often keep the layout and change only sync/access. Two UAV dispatches on one texture are the usual case:
LayoutBefore == LayoutAfter == UNORDERED_ACCESS. Other pairs map to the same state too:UNDEFINED -> COMMON(both0) andDIRECT_QUEUE_SHADER_RESOURCE -> SHADER_RESOURCE(both0xC0).enhanced()records each of these asBarrier::Transitionwithbefore == after, and playback issues it throughgpu::transition.I issued that legacy barrier on a real device: a 64x64 RGBA8 texture, then one
ResourceBarriertransition andClose().Close()OkE_INVALIDARGResourceBarrier: Before and after states must be different.E_INVALIDARGE_INVALIDARGE_INVALIDARGSo the replayed list fails to close even without the debug layer.
edit.rsjoinonly folds a transition into an earlier one on the same resource; a lone same-state transition goes through unchanged.A possible fix: when
layout_state(before) == layout_state(after), record no transition, and recordBarrier::Uav { res }when the layout isUNORDERED_ACCESS(the wait the barrier stands for). That matches whatjoinalready does when two transitions cancel out onUNORDERED_ACCESS. A test that runsenhanced()on a UAV -> UAV texture group would cover it.Context: on
mainI found no host code that callsBarrier/ setsLayoutBefore, so this only matters once a recorded stream contains enhanced barriers. That is the case this pull request is for, though.Not checked: a full record/replay round trip, and the game.
GPUs tested: the default hardware adapter (device-level
ResourceBarrier/Closecheck only).AI-assisted: yes (Claude Code).
@merzleckeier on GitHub · 2026-12-01 17:44 UTC · original
Recorder check for equivalent single-subresource barriers at
e18eeaf6e+d2a564b66(Win64, Wine 11.22 / VKD3D-Proton 3.1.0). The 25 existingreplay::tests passed in both adapter configurations.A separate test calls
ID3D12GraphicsCommandList7::Barrier, closes the list and decodes the captured commands. The synthetic RGBA8 texture has two mips and two array slices. It specifies mip 1, slice 1, plane 0 in two equivalent ways. WithNumMipLevels = 0, the flattened index 3 records transition subresource 3. With all three counts set to 1, the explicit range records0xffffffff(all subresources). Main emits no recorded barrier in either case. The results match on AMD Radeon (RADV 26.3.1) and GeForce RTX 4070 SUPER (620.73.4 as reported by Wine).NumMipLevels > 0selects the range form even when that range contains only one subresource. A local trial flattened the 1×1×1 range using the texture descriptor and recorded subresource 3 in both forms on both adapters. The test checks the captured commands before queue submission.MEASURED with a synthetic texture. AI-assisted (Codex). D3D12 subresource-range documentation
@KelboLive on GitHub · 2026-12-01 17:52 UTC · original · requested changes
Blocking: the texture path records a transition even when both layouts stand for the same state, and D3D12 rejects that at
Close().layout_statecollapses UAV→UAV to0x8→0x8, UNDEFINED→COMMON to0x0→0x0, and DIRECT/QUEUE SHADER_RESOURCE→SHADER_RESOURCE to0xC0→0xC0(record.rs:2359-2365), andenhanced()emits aTransitionunconditionally (:2420-2431). On a 4070 Ti SUPER I getE_INVALIDARG (0x80070057)for0x8→0x8,0x4→0x4,0x0→0x0and0xC0→0xC0, with and without the debug layer (debug says "Before and after states must be different"), while the enhanced COMMON→UAV / UAV→UAV pair closes Ok and a control0x8→0xC0is fine.play.rs'sclosepropagates the error (:2402-2414, "a list of the frame could not be recorded again"), so one such barrier aborts the whole frame's replay. Before this PR the call was merely skipped (noted_entry,hook.rs:231) and the capture still replayed — so this regresses the UAV→UAV case the PR exists for.edit::joinonly folds a pair of matching transitions (edit.rs:126-155), so a lone same-state barrier survives, andmerge_barriersis off by default anyway.Fix: emit no transition when
before == after, plusBarrier::Uavwhen the layout is UAV. And testenhanced()itself — replacingafter: layout_state(b.LayoutAfter)withb.LayoutBeforestill passes all 25replay::tests, which is exactly why CI cannot see this.Second, smaller issue: a buffer barrier becomes a UAV barrier even when its access masks are copy/vertex/index/…, and a legacy UAV barrier only orders UAV accesses — so "never fewer" does not hold there. A global alias+UAV flush would be the conservative legacy stand-in.
Minor:
from_raw_parts(ptr, 0)per group (:2403,:2418,:2436) is UB ifNumBarriers == 0with a null pointer; the new test only assertslayout_statevalues (no PRESENT/SHADING_RATE_SOURCE/video); and the "tested viacargo test --test replay" claim does not exerciseenhanced()at all —tests/replay.rsbuilds frames directly.The GLOBAL mapping is right:
Alias(NONE,NONE)+Uav(NONE)matches the non-enhanced fallback inwait_for_all(play.rs:2342-2370,:3392,:3376). Merge is clean against current main, and no other open PR touchesreplay/record.rs.@aznohonza on GitHub · 2026-12-01 18:18 UTC · original
Thanks for the device check — you were right, and that exact case is fixed in
33d9b4f61(merged withmain7fbdf8511).When
layout_state(before) == layout_state(after),enhanced()now recordsBarrier::Uav { flags: 0, res }if the state isUNORDERED_ACCESS, and records nothing otherwise. A UAV -> UAV texture group is covered bysame_state_texture_barriers_are_a_wait_or_nothing, which also checks UNDEFINED -> COMMON and DIRECT_QUEUE_SHADER_RESOURCE -> SHADER_RESOURCE record nothing. The existing test runs under Wine here; the new one passes too.AI-assisted.
@aznohonza on GitHub · 2026-12-01 18:18 UTC · original
Thanks for the captured-command check — you were right about the range form, and it is fixed in
33d9b4f61(merged withmain7fbdf8511).With
NumMipLevels > 0andNumMipLevels == NumArraySlices == NumPlanes == 1, the range now flattens tofirst_mip + first_layer * MipLevels + first_plane * MipLevels * ArraySizeusing the resource's own descriptor (array size is 1 for 3D textures). Any wider range is still recorded as the whole resource, and the index form (NumMipLevels == 0) is unchanged.one_subresource_ranges_flatten_to_that_subresourcecovers mip 1 of slice 1, plane 1 of slice 1, 2 mips, the index form including0xffffffff, and a 3D texture; it passes here under Wine.AI-assisted.
@merzleckeier on GitHub · 2026-12-01 18:27 UTC · original
Follow-up device check for both texture-barrier fixes at
33d9b4f6onmain7fbdf851(Win64, Wine 11.22 / VKD3D-Proton 3.1.0). I reran the recorder comparison on AMD Radeon (RADV 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.4 as reported by Wine).Barrier::Uavwith flags 0. A separate list containing the equivalent native legacyD3D12_RESOURCE_BARRIER_TYPE_UAVclosed successfully on both adapters.maincontrol recorded no barriers for the three inputs. The updated PR passed all 27 stockreplay::tests in each adapter configuration, including both new targeted cases.MEASURED with a synthetic texture. The scope was captured commands and command-list closure before queue submission. AI-assisted (Codex).
@KelboLive on GitHub · 2026-12-01 18:29 UTC · original · reviewed
Re-checked at
33d9b4f61(merged withmain7fbdf8511; merge-tree clean). The blocker is fixed: on a real 4070 Ti SUPER,enhanced()now recordsUavfor UAV→UAV and nothing for UNDEFINED→COMMON, DIRECT_QUEUE_SHADER_RESOURCE→SHADER_RESOURCE and RT→RT, and all fourClose()calls returnS_OK. A forced0x8→0x8control still returnsE_INVALIDARG, so the probe can still see the original defect.replay::is 27/0, and deleting thebefore == afterbranch now failssame_state_texture_barriers_are_a_wait_or_nothing— good red/green.Two from the review remain, neither the original blocker:
Uav(record.rs:2480-2489). I drove aCOPY_DEST→COPY_SOURCEbuffer barrier through the same path and it records[Uav { res }], which orders nothing for that transition. Either special-case onlyAccessAfter == UAVand use a global alias+UAV pair otherwise, or document that buffer barriers are assumed UAV-adjacent.enhanced()itself is still untested: swappinglayout_state(b.LayoutAfter)forLayoutBeforeatrecord.rs:2473leaves all 27replay::tests green — the same mutation as before. The new tests covertexture_barrier(), not its call site. A test that builds aD3D12_BARRIER_GROUPand asserts the returnedVec<Barrier>would close both this and the buffer case.Minor, unchanged:
std::slice::from_raw_parts(ptr, 0)with a null pointer for aNumBarriers == 0group (:2450,:2465,:2482).@aznohonza on GitHub · 2026-12-01 18:44 UTC · original
Both points addressed in
ba1828afe(merged withmain60f7dcd90):Uavonly whenAccessAfterisUNORDERED_ACCESS; every other access records the global alias + UAV pair thatwait_for_alluses, soCOPY_DEST -> COPY_SOURCEorders everything instead of nothing. The condition is stated inenhanced()'s comment.enhanced_records_its_texture_and_buffer_barriersbuilds realD3D12_BARRIER_GROUPs against a registered test resource and asserts the returnedVec<Barrier>: a UAV -> SRV texture at mip 1 of slice 1, a UAV -> UAV texture, and buffer barriers with and without a UAV access after. SwappingLayoutAfterforLayoutBeforeat the call site now fails that test.from_raw_partswith a possibly null array.The six
replay::record::testspass here under Wine; CI is re-running.AI-assisted.
@merzleckeier on GitHub · 2026-12-01 18:53 UTC · original
Buffer-barrier follow-up on the updated recorder at
ba1828afagainst33d9b4f6, both onmain60f7dcd9. I recordedID3D12GraphicsCommandList7::Barrieragainst a synthetic default buffer, closed the lists and decoded their commands on Radeon (RADV 26.3.1) and RTX 4070 SUPER (620.73.4 as reported by Wine).replay::selection now passes 28 tests per adapter setting, including the new recorder test.MEASURED with a synthetic buffer under Win64 Wine 11.22 / VKD3D-Proton 3.1.0. Scope is recording and list closure before queue submission. AI-assisted (Codex).
@aznohonza on GitHub · 2026-12-01 19:14 UTC · original
Thanks for checking both buffer forms on both adapters — that is the intended split: a bare UAV barrier only when the access after is UAV, the global alias + UAV pair otherwise. Good to know the stock
replay::selection is 28/28 on each.AI-assisted.
@KelboLive on GitHub · 2026-12-01 19:48 UTC · original · reviewed
Re-checked at
ba1828afe(merge-tree with current mainab374c7d5is clean). Both re-review points are fixed on native Windows (4070 Ti SUPER):COPY_DEST→COPY_SOURCEnow recordsAlias{NONE,NONE}+Uav{NONE}(and the list closesS_OK), whileUAV→UAVstill records one resource-specificUav(record.rs:2489). The old head recorded a single resourceUavfor the copy case — alsoS_OK, which is why the HRESULT alone could not show the defect; the recorded set now does.enhanced_records_its_texture_and_buffer_barriers(:3106) fails on theLayoutAfter→LayoutBeforemutation ([Uav]vs[Transition 0x8→0xC0]), andreplay::is 28/28 after reverting. That was the last unguarded wiring.from_raw_partsentirely (:2447-2449), so the null-pointer case is gone.Non-blocking, narrow: a buffer barrier with
AccessBefore = COPY_DESTandAccessAfter = UNORDERED_ACCESSstill takes the bare-Uavbranch, and a legacy UAV barrier orders UAV accesses only — not the copy. If that pair occurs in practice, it needs the global alias+UAV pair too.@lixonik on GitHub · 2026-12-01 21:40 UTC · original
Independent check of
ba1828afemerged cleanly onmain(1e3e316c5), on native Windows 10 Pro 22H2 (build 19045) + NVIDIA GeForce RTX 5070 12 GB (driver621.40, Ryzen 9 5950X):cargo test --locked -p leonida-gpu --features diagnostics --lib replay:: -- --nocapture: 28 passed, 0 failed, 0 ignored (including all four new enhanced-barrier tests:one_subresource_ranges_flatten_to_that_subresource,enhanced_layouts_record_as_the_states_they_stand_for,same_state_texture_barriers_are_a_wait_or_nothing, andenhanced_records_its_texture_and_buffer_barriers).replay/record.rs.AI-assisted: Antigravity
Pull request closed