D3D12.X: barriers from the undefined layout can start from UNDEFINED natively #3558
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3558"
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 ivall/xcl. Originally posted by KDenKC on 2026-12-01T03:07:45Z.
barrier_groups(list call #146) turns a title's enhanced barrier from the undefined layout into a legacy transition whose before-state is the last state it recorded for the texture (LAST). It records those states in the order the title records its lists, but the GPU runs them in the order they are submitted. A title that records on several threads therefore gets before-states the texture is not in when the list runs (the debug layer's errors 527/538), and what the GPU does with them is undefined. thehollowedone found this first, on #3094 (point 2 and the two-list regression); imnicho's answer there is that it needs a fix outside that PR.A barrier with a layout before it names its own state, so the moves from the undefined layout are the only place
barrier_groupsdepends on recording order.XCL_BARRIER_UNDEFINED_NATIVE=1(default off) sends them as enhanced texture barriers withLayoutBefore = UNDEFINED, which need no before-state at all. With the switch on and enhanced barriers on the device,barrier_groupsno longer depends on the order lists are recorded in. A state with no single layout, or a device without enhanced barriers, goes out as before.Scope. This does not resolve states at submission. A complete fix keeps each recording's transitions private until submission and resolves them at the list's exact place in the queue's order,
KickoffXand repeat submissions included, because the barriers of a closed list cannot be rewritten atExecuteCommandLists(thehollowedone, #3094). This change only takes the moves from the undefined layout out of that dependency: they are the one placebarrier_groupsuses a before-state it recorded itself rather than one the title named.alias_copy's own record of states (#3094) keeps the same limit.Related: #3489, #3094, #3527 (seeds texture states at creation; it should land first)
Based on
main9dfbe3ea(it merges into currentmainwithout conflicts): see Regression run.What is in it (one commit)
barrier_groups.rs: theFROM_UNDEFINEDmark on moves from the undefined layout when the switch is on (native_undefined),native_layout(a state's one enhanced layout and access), and a marked move made even when the last state is unknown or already the target.list_x.rs:resource_barrier_x's flag filter keeps the mark only forbarrier_groups' own call (a thread-local scope,as_groups);send_barrierssends marked runs throughID3D12GraphicsCommandList7::Barrierand falls back to legacy transitions (as_legacy: the mark off, the moves with no before-state of their own left out);a_no_opkeeps marked same-state words.depth_uav.rs:plan_withkeeps a marked move that parking turns into the same state before and after.a_barrier_from_undefined_starts_from_the_state_in_submission_order(two lists recorded out of submission order: the legacy before-state is the recording-order one; after thehollowedone's two-list regression and their discriminator on #3094, one recording read under two submission orders),a_native_move_from_undefined_is_kept_without_a_before_state,a_state_from_the_undefined_layout_has_one_enhanced_layout,the_from_undefined_mark_passes_the_flag_filter_only_for_barrier_groups,a_marked_move_with_no_before_state_goes_natively_or_not_at_all,a_marked_move_into_unordered_access_of_a_parked_buffer_stays. All CPU-only.Tested
cac8b6ad):test result: FAILED. 140 passed; 3 failed; 0 ignored; 0 measured; 2632 filtered out; green with it (3731d0e7):test result: ok. 143 passed; 0 failed; 0 ignored; 0 measured; 2632 filtered out(the tests ofbarrier_groups,list_x,depth_uav).cargo test --workspace --no-fail-fast -- --test-threads=4(leaving out the 3uma_drivertests that need a GPU upload segment this VM does not have): the same commit onmaind0832e61(42946bf8): 2888 passed, 5 failed, 51 ignored (a first run lost the lib test binary to an access violation in the parallel run; these counts are from its complete rerun);maind0832e61on the same machine: 2882 passed, 5 failed, 51 ignored. This headbd888cf7(the same commit onmain9dfbe3ea): running, its counts will be added here. The same 5 fail on both (title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, the 3title_textures::tests::stream_recheck_*,test_title_runs_and_game_folder_is_untouched). SKIPPED: 28 on both, the same tests (22 no wave64, 2 no heap windows, 3 no debug layer, 1 driver cache cannot be disabled).Regression run
Pending: one run of this head, paired with a
main9dfbe3earun of the same recipe (held Enter, 600 s, the retail title) that entered the world.maind0832e61stays in the title's menus with held Enter on our rig (both runs of this change on it, and one ofmaind0832e61alone; no device removal), so the pair uses9dfbe3ea.Not tested
AI use
🤖 Generated with Claude Code
https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-01T03:27:38Z.
Source review on head
bd888cf7: the opt-in native path setsSyncBefore = NONEfor every marked texture barrier. The title's before-sync value is available inbarrier_groups, but only its split marker is used. For example, a direct list can clear a render target, then requestUNDEFINED → COPY_DESTwithSyncBefore = RENDER_TARGETbefore overwriting that texture. The emitted barrier drops the clear's synchronization. Microsoft's enhanced-barrier specification permitsSyncBefore = NONEonly when there has been no earlier access or barrier to the subresource in thatExecuteCommandListsscope. The global UAV barrier emitted before this path does not change that requirement.Please carry the title's before-sync scope into the native barrier, or conservatively use
SYNC_ALLwhile keepingAccessBefore = NO_ACCESSfor the undefined layout. Add a regression that inspects the final PCD3D12_TEXTURE_BARRIERfor a clear followed by this transition; the current tests check the intermediate marked words and cannot catch this field.This is a source and API-contract finding. I have not run the opt-in path on a GPU or title. AI use: Codex (GPT-6.2 Sol) and Codex (GPT-6.2 Astra) traced the path against Microsoft's specification.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-01T03:56:19Z.
Source review on head
bd888cf7: the opt-in path also needs to account for legacy/enhanced barrier interop on the same texture. In the PR's two-transition example, list A moves one textureUNDEFINED → RENDER_TARGET → SHADER_RESOURCE.send_barrierssends the first move through enhancedBarrierand the second through legacyResourceBarrier, with noRENDER_TARGET → COMMONenhanced handoff. This remains a problem even if the already reportedSyncBefore = NONEis corrected.Microsoft's enhanced-barrier interop contract requires a texture in an enhanced layout to be placed in
D3D12_BARRIER_LAYOUT_COMMON, with preceding accesses finished and flushed, before a legacyResourceBarrierreferences it. The reverse crossing also needs a legacy transition toD3D12_RESOURCE_STATE_COMMONbefore an enhanced barrier; the example starts with a prior legacy shader-resource state. Please keep a subresource in one barrier model across these moves, or perform the requiredCOMMONhandoffs in execution order. A recording-order state guess would reintroduce the problem this PR addresses.A deterministic regression can use a fresh ordinary texture and capture the final PC calls, not only the intermediate marked words: on a direct list with enhanced barriers supported, issue
UNDEFINED → RENDER_TARGET → SHADER_RESOURCEfor the same subresource and assert that no enhanced-to-legacy crossing occurs without a synchronizedCOMMONhandoff. Also cover a preceding explicit legacy non-COMMONstate before an enhanced move. I traced the source and API contract; I have not run this path on a GPU or title.AI use: Codex (GPT-6.2 Sol) checked the emitted sequence and Microsoft specification; Codex (GPT-6.2 Astra) independently checked the interop invariant.
Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-01T03:59:45Z.
@thehollowedone thank you for both reviews; both are right on the API contract.
SyncBefore = NONEfor every marked barrier, so a clear followed by a move from the undefined layout lost the clear's sync.Rather than keep patching this opt-in path, the fixes go into the submit-time series announced on #3094 (resolving barrier states at submission): the title's before-sync carried into each barrier, one barrier model per subresource with the COMMON hand-offs placed in execution order, and XCL's own copies around title textures (depth twins, alias copies) following the same rule. Its part A (the harness for submission-order regressions, test-only) opens shortly, and your cases will be among its regressions.
This PR stays a draft with its switch off until then, and will be closed in favour of that series, with credit to you, once it covers this.
AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 3.8 Flash.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:07:12Z.
Review (head
bd888cf7, diff read, not a merge-check; draft withPR descriptionred, so not built or run here):barrier_groups::transitionsstill ends itsretain_mutwithw[5] != w[6](barrier_groups.rs~478), so the marked same-state barrierstransitions_ofnow produces (last state unknown, or already the target) are dropped there and never reachresource_barrier_x. A never-seen texture, or one whose recording-order state already equals the target, still gets no barrier, as on main. The new tests calltransitions_of,a_no_opandplan_withdirectly, nevertransitions(), so they don't catch it.barrier_groups.rs~50 still reads "LOCAL, not for a PR".thread_local!atlist_x.rs~6503 sits betweenstencil_copies_on's doc comment and the function, giving a newunused doc commentwarning (~6498) in CI; at ~7506 the doc comment ofthe_from_undefined_mark_passes_the_flag_filter_only_for_barrier_groupsis attached to the test before it.XCL_BARRIER_UNDEFINED_NATIVE=1, a debug-layer run with enhanced and legacy barriers mixed on one resource, this head's suite counts, and the regression run.Fine: with the switch off the barriers sent are unchanged (one unmarked run goes to the same legacy call, plus one small Vec per call). Native barriers are gated on
EnhancedBarriersSupportedwith a legacy fallback,Barrieris slot 80 ofID3D12GraphicsCommandList7, thenative_layouttable is right, a title's own flags can't carry the marker, runs keep their order, and there's no overlap with #3238 / #839 (they changedevice_x::layout_state).AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:15:57Z.
Triage (#1607) – head
bd888cfNo open PR makes the same change. #3527 also deals with barrier_groups' moves from the undefined layout (#3489), but it starts them from the texture's creation state, by default. This PR sends them as enhanced barriers from LAYOUT_UNDEFINED behind XCL_BARRIER_UNDEFINED_NATIVE=1, which also removes the dependency on recording order. These are different approaches. #3559 is the same author's test harness for that plan, not an overlap.
One problem in the diff: the doc comment of
barrier_groups::FROM_UNDEFINEDstarts with "LOCAL, not for a PR", left over from a local branch. The slot used for ID3D12GraphicsCommandList7::Barrier (80) is right.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by gut0to on 2026-12-01T13:54:00Z.
Code review location:
crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 77The values returned here are passed directly as
D3D12_BARRIER_LAYOUTinfrom_undefined_natively, but they do not match the SDK enum values. For example,RENDER_TARGETis 4 (not 2, which isPRESENT), andUNORDERED_ACCESSis 5 (not 3). WithXCL_BARRIER_UNDEFINED_NATIVE=1, these transitions can be recorded with the wrong layout. Could this mapping use the SDK constants and add a test for each supported state? AI-assisted static review: I used an AI assistant to inspect this code; I checked the values against https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_barrier_layout.Imported from ivall/xcl. Originally posted by gut0to on 2026-12-01T13:54:00Z.
Review: COMMENTED
AI-assisted static review: I used an AI assistant to inspect this diff and checked the enum values against Microsoft documentation.
Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-01T13:57:16Z.
@gut0to thanks for checking the layouts so closely; that mapping is exactly where a mistake would void every run with the switch on. I compared it against the SDK, and the values match: in
d3d12.h(and thewindowscrate 0.62.2 that XCL builds with)D3D12_BARRIER_LAYOUT_COMMONand_PRESENTare both 0,_GENERIC_READ1,_RENDER_TARGET2,_UNORDERED_ACCESS3,_DEPTH_STENCIL_WRITE4,_DEPTH_STENCIL_READ5,_SHADER_RESOURCE6,_COPY_SOURCE7,_COPY_DEST8,_RESOLVE_SOURCE9,_RESOLVE_DEST10 (and_UNDEFINED-1), and the access bits used next to them are_RENDER_TARGET0x8,_UNORDERED_ACCESS0x10,_DEPTH_STENCIL_WRITE0x20,_DEPTH_STENCIL_READ0x40,_SHADER_RESOURCE0x80,_COPY_DEST0x400,_COPY_SOURCE0x800,_RESOLVE_DEST0x1000,_RESOLVE_SOURCE0x2000, which is whatnative_layoutreturns. Writing them as literals invites exactly this doubt, though: this PR stays frozen (the work moved into the submit-time series, #3559 and after), and where the native route enters that series it uses the SDK constants by name, with a test that pins each state's (layout, access) pair to them.AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.