Repository navigation
Conversation
`ID3D12GraphicsCommandList7::Barrier` was in the recorder's not-recorded list, so a recorded stream lost those ordering points on replay. Hook it and record each group as the legacy barriers the runtime already uses for the same wait: a global one as the alias + UAV pair `play::wait_for_all` falls back to, a texture one as a transition between the states its layouts stand for, a buffer one as a UAV barrier on the whole buffer (D3D12 requires offset 0 and the whole size). A texture subresource range that names more than one subresource is recorded as the whole resource: a legacy transition carries one subresource. That is conservative and stated in the code, with the condition to revisit it. The mapping's test covers every layout and both queue-specific forms.
|
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
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: I issued that legacy barrier on a real device: a 64x64 RGBA8 texture, then one
So the replayed list fails to close even without the debug layer. A possible fix: when Context: on Not checked: a full record/replay round trip, and the game. GPUs tested: the default hardware adapter (device-level AI-assisted: yes (Claude Code). |
|
Recorder check for equivalent single-subresource barriers at A separate test calls
MEASURED with a synthetic texture. AI-assisted (Codex). D3D12 subresource-range documentation |
KelboLive
left a comment
There was a problem hiding this comment.
Blocking: the texture path records a transition even when both layouts stand for the same state, and D3D12 rejects that at Close().
layout_state collapses UAV→UAV to 0x8→0x8, UNDEFINED→COMMON to 0x0→0x0, and DIRECT/QUEUE SHADER_RESOURCE→SHADER_RESOURCE to 0xC0→0xC0 (record.rs:2359-2365), and enhanced() emits a Transition unconditionally (:2420-2431). On a 4070 Ti SUPER I get E_INVALIDARG (0x80070057) for 0x8→0x8, 0x4→0x4, 0x0→0x0 and 0xC0→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 control 0x8→0xC0 is fine. play.rs's close propagates 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::join only folds a pair of matching transitions (edit.rs:126-155), so a lone same-state barrier survives, and merge_barriers is off by default anyway.
Fix: emit no transition when before == after, plus Barrier::Uav when the layout is UAV. And test enhanced() itself — replacing after: layout_state(b.LayoutAfter) with b.LayoutBefore still passes all 25 replay:: 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 if NumBarriers == 0 with a null pointer; the new test only asserts layout_state values (no PRESENT/SHADING_RATE_SOURCE/video); and the "tested via cargo test --test replay" claim does not exercise enhanced() at all — tests/replay.rs builds frames directly.
The GLOBAL mapping is right: Alias(NONE,NONE)+Uav(NONE) matches the non-enhanced fallback in wait_for_all (play.rs:2342-2370, :3392, :3376). Merge is clean against current main, and no other open PR touches replay/record.rs.
A transition to the state a resource is already in is invalid (E_INVALIDARG, even with the debug layer off), and enhanced barriers often keep the layout: two UAV dispatches are the common case. Record the UAV barrier that wait stands for instead, and nothing at all when both layouts stand for the same other state. This matches what `join` does when two transitions cancel out. A range with a non-zero `NumMipLevels` can still name exactly one subresource. When all three counts are 1, flatten it to that subresource with the resource's own mip and array sizes instead of recording the whole resource. The subresource-index form is unchanged. Both rules are a pure helper, tested without a device.
|
Thanks for the device check — you were right, and that exact case is fixed in When AI-assisted. |
|
Thanks for the captured-command check — you were right about the range form, and it is fixed in With AI-assisted. |
|
Follow-up device check for both texture-barrier fixes at
MEASURED with a synthetic texture. The scope was captured commands and command-list closure before queue submission. AI-assisted (Codex). |
KelboLive
left a comment
There was a problem hiding this comment.
Re-checked at 33d9b4f61 (merged with main 7fbdf8511; merge-tree clean). The blocker is fixed: on a real 4070 Ti SUPER, enhanced() now records Uav for UAV→UAV and nothing for UNDEFINED→COMMON, DIRECT_QUEUE_SHADER_RESOURCE→SHADER_RESOURCE and RT→RT, and all four Close() calls return S_OK. A forced 0x8→0x8 control still returns E_INVALIDARG, so the probe can still see the original defect. replay:: is 27/0, and deleting the before == after branch now fails same_state_texture_barriers_are_a_wait_or_nothing — good red/green.
Two from the review remain, neither the original blocker:
- Buffer barriers with non-UAV masks are still a bare
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 a NumBarriers == 0 group (:2450, :2465, :2482).
replay/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.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: the
layout_statetest covers every layout and both queue-specific 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.