D3D12.X: barriers from the undefined layout can start from UNDEFINED natively #3558

Open
KDenKC wants to merge 1 commit from upstream-pr/3558 into main
KDenKC commented 2026-12-01 03:07:45 +00:00 (Migrated from github.com)

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_groups depends on recording order. XCL_BARRIER_UNDEFINED_NATIVE=1 (default off) sends them as enhanced texture barriers with LayoutBefore = UNDEFINED, which need no before-state at all. With the switch on and enhanced barriers on the device, barrier_groups no 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, KickoffX and repeat submissions included, because the barriers of a closed list cannot be rewritten at ExecuteCommandLists (thehollowedone, #3094). This change only takes the moves from the undefined layout out of that dependency: they are the one place barrier_groups uses 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 main 9dfbe3ea (it merges into current main without conflicts): see Regression run.

What is in it (one commit)

  • barrier_groups.rs: the FROM_UNDEFINED mark 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 for barrier_groups' own call (a thread-local scope, as_groups); send_barriers sends marked runs through ID3D12GraphicsCommandList7::Barrier and falls back to legacy transitions (as_legacy: the mark off, the moves with no before-state of their own left out); a_no_op keeps marked same-state words.
  • depth_uav.rs: plan_with keeps a marked move that parking turns into the same state before and after.
  • Tests: 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

  • NVIDIA GeForce RTX 3090 24 GB (VM), driver 621.24, Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug:
    • The three tests of the kept moves, red before that part of the change (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 of barrier_groups, list_x, depth_uav).
    • cargo test --workspace --no-fail-fast -- --test-threads=4 (leaving out the 3 uma_driver tests that need a GPU upload segment this VM does not have): the same commit on main d0832e61 (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); main d0832e61 on the same machine: 2882 passed, 5 failed, 51 ignored. This head bd888cf7 (the same commit on main 9dfbe3ea): 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 3 title_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).
  • The retail title, switch on: pending (twelve runs, six with the switch and six without, scored lit / dark: the run-to-run dark areas reported on #505 are the case this is meant for).

Regression run
Pending: one run of this head, paired with a main 9dfbe3ea run of the same recipe (held Enter, 600 s, the retail title) that entered the world. main d0832e61 stays in the title's menus with held Enter on our rig (both runs of this change on it, and one of main d0832e61 alone; no device removal), so the pair uses 9dfbe3ea.

Not tested

  • The retail title with the switch on (above): whether it changes what the title shows is not measured yet.
  • A device without enhanced barriers (the fallback is the code path of before; covered by the tests only).
  • AMD; Intel.

AI use

  • Claude Code (Claude Opus 5.5, Claude Sonnet 5.5), Codex (GPT-6.2-Sol), Antigravity (Gemini 4 Neon, Gemini 3.8 Flash): an agent swarm wrote, tested, reviewed and described this change; GPT-6.2-Sol's review found the parked-buffer case.

🤖 Generated with Claude Code
https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR

<!-- greyfinch-sync:ivall/xcl:issue:5578151187 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3558). Originally posted by [KDenKC](https://github.com/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](https://github.com/xcl-dev/xcl/pull/3094#issuecomment-7235800050) and [the two-list regression](https://github.com/xcl-dev/xcl/pull/3094#issuecomment-7246057545)); 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_groups` depends on recording order. `XCL_BARRIER_UNDEFINED_NATIVE=1` (default off) sends them as enhanced texture barriers with `LayoutBefore = UNDEFINED`, which need no before-state at all. With the switch on and enhanced barriers on the device, `barrier_groups` no 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, `KickoffX` and repeat submissions included, because the barriers of a closed list cannot be rewritten at `ExecuteCommandLists` (thehollowedone, [#3094](https://github.com/xcl-dev/xcl/pull/3094#issuecomment-7297382882)). This change only takes the moves from the undefined layout out of that dependency: they are the one place `barrier_groups` uses 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 `main` 9dfbe3ea (it merges into current `main` without conflicts): see Regression run. **What is in it** (one commit) - `barrier_groups.rs`: the `FROM_UNDEFINED` mark 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 for `barrier_groups`' own call (a thread-local scope, `as_groups`); `send_barriers` sends marked runs through `ID3D12GraphicsCommandList7::Barrier` and falls back to legacy transitions (`as_legacy`: the mark off, the moves with no before-state of their own left out); `a_no_op` keeps marked same-state words. - `depth_uav.rs`: `plan_with` keeps a marked move that parking turns into the same state before and after. - Tests: `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** - NVIDIA GeForce RTX 3090 24 GB (VM), driver 621.24, Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug: - The three tests of the kept moves, red before that part of the change (`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 of `barrier_groups`, `list_x`, `depth_uav`). - `cargo test --workspace --no-fail-fast -- --test-threads=4` (leaving out the 3 `uma_driver` tests that need a GPU upload segment this VM does not have): the same commit on `main` d0832e61 (`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); `main` `d0832e61` on the same machine: 2882 passed, 5 failed, 51 ignored. This head `bd888cf7` (the same commit on `main` 9dfbe3ea): 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 3 `title_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). - The retail title, switch on: pending (twelve runs, six with the switch and six without, scored lit / dark: the run-to-run dark areas reported on #505 are the case this is meant for). **Regression run** Pending: one run of this head, paired with a `main` 9dfbe3ea run of the same recipe (held Enter, 600 s, the retail title) that entered the world. `main` d0832e61 stays in the title's menus with held Enter on our rig (both runs of this change on it, and one of `main` d0832e61 alone; no device removal), so the pair uses 9dfbe3ea. **Not tested** - The retail title with the switch on (above): whether it changes what the title shows is not measured yet. - A device without enhanced barriers (the fallback is the code path of before; covered by the tests only). - AMD; Intel. **AI use** - Claude Code (Claude Opus 5.5, Claude Sonnet 5.5), Codex (GPT-6.2-Sol), Antigravity (Gemini 4 Neon, Gemini 3.8 Flash): an agent swarm wrote, tested, reviewed and described this change; GPT-6.2-Sol's review found the parked-buffer case. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR
thehollowedone commented 2026-12-01 03:27:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-01T03:27:38Z.


Source review on head bd888cf7: the opt-in native path sets SyncBefore = NONE for every marked texture barrier. The title's before-sync value is available in barrier_groups, but only its split marker is used. For example, a direct list can clear a render target, then request UNDEFINED → COPY_DEST with SyncBefore = RENDER_TARGET before overwriting that texture. The emitted barrier drops the clear's synchronization. Microsoft's enhanced-barrier specification permits SyncBefore = NONE only when there has been no earlier access or barrier to the subresource in that ExecuteCommandLists scope. 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_ALL while keeping AccessBefore = NO_ACCESS for the undefined layout. Add a regression that inspects the final PC D3D12_TEXTURE_BARRIER for 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.

<!-- greyfinch-sync:ivall/xcl:comment:7299727093 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3558#issuecomment-7299727093). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-12-01T03:27:38Z. --- Source review on [head `bd888cf7`](https://github.com/xcl-dev/xcl/commit/bd888cf7ec243d855c4b168dfa0d1e11ac062603): the opt-in native path [sets `SyncBefore = NONE` for every marked texture barrier](https://github.com/xcl-dev/xcl/blob/bd888cf7ec243d855c4b168dfa0d1e11ac062603/crates/xcl/src/hle/d3d12x/list_x.rs#L6599-L6608). The title's before-sync value is available in `barrier_groups`, but only its split marker is used. For example, a direct list can clear a render target, then request `UNDEFINED → COPY_DEST` with `SyncBefore = RENDER_TARGET` before overwriting that texture. The emitted barrier drops the clear's synchronization. Microsoft's [enhanced-barrier specification](https://microsoft.github.io/DirectX-Specs/d3d/D3D12EnhancedBarriers.html#d3d12_barrier_sync_none) permits `SyncBefore = NONE` only when there has been no earlier access or barrier to the subresource in that `ExecuteCommandLists` scope. 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_ALL` while keeping `AccessBefore = NO_ACCESS` for the undefined layout. Add a regression that inspects the final PC `D3D12_TEXTURE_BARRIER` for 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.
thehollowedone commented 2026-12-01 03:56:19 +00:00 (Migrated from github.com)

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 texture UNDEFINED → RENDER_TARGET → SHADER_RESOURCE. send_barriers sends the first move through enhanced Barrier and the second through legacy ResourceBarrier, with no RENDER_TARGET → COMMON enhanced handoff. This remains a problem even if the already reported SyncBefore = NONE is 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 legacy ResourceBarrier references it. The reverse crossing also needs a legacy transition to D3D12_RESOURCE_STATE_COMMON before 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 required COMMON handoffs 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_RESOURCE for the same subresource and assert that no enhanced-to-legacy crossing occurs without a synchronized COMMON handoff. Also cover a preceding explicit legacy non-COMMON state 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.

<!-- greyfinch-sync:ivall/xcl:comment:7300214296 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3558#issuecomment-7300214296). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-12-01T03:56:19Z. --- Source review on [head `bd888cf7`](https://github.com/xcl-dev/xcl/commit/bd888cf7ec243d855c4b168dfa0d1e11ac062603): the opt-in path also needs to account for **legacy/enhanced barrier interop on the same texture**. In [the PR's two-transition example](https://github.com/xcl-dev/xcl/blob/bd888cf7ec243d855c4b168dfa0d1e11ac062603/crates/xcl/src/hle/d3d12x/barrier_groups.rs#L643-L657), list A moves one texture `UNDEFINED → RENDER_TARGET → SHADER_RESOURCE`. [`send_barriers`](https://github.com/xcl-dev/xcl/blob/bd888cf7ec243d855c4b168dfa0d1e11ac062603/crates/xcl/src/hle/d3d12x/list_x.rs#L6560-L6576) sends the first move through enhanced `Barrier` and the second through legacy `ResourceBarrier`, with no `RENDER_TARGET → COMMON` enhanced handoff. This remains a problem even if the already reported `SyncBefore = NONE` is corrected. Microsoft's [enhanced-barrier interop contract](https://microsoft.github.io/DirectX-Specs/d3d/D3D12EnhancedBarriers.html#interop-with-legacy-resourcebarrier) requires a texture in an enhanced layout to be placed in `D3D12_BARRIER_LAYOUT_COMMON`, with preceding accesses finished and flushed, before a legacy `ResourceBarrier` references it. The reverse crossing also needs a legacy transition to `D3D12_RESOURCE_STATE_COMMON` before 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 required `COMMON` handoffs 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_RESOURCE` for the same subresource and assert that no enhanced-to-legacy crossing occurs without a synchronized `COMMON` handoff. Also cover a preceding explicit legacy non-`COMMON` state 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.
KDenKC commented 2026-12-01 03:59:45 +00:00 (Migrated from github.com)

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.

  1. The native path set SyncBefore = NONE for every marked barrier, so a clear followed by a move from the undefined layout lost the clear's sync.
  2. A texture moved with an enhanced barrier and then with a legacy one in the same list (or the other way round) needs a hand-off through COMMON in the order the GPU runs them, and the first move of a texture whose legacy state was set by another list cannot be known when the list is recorded.

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.

<!-- greyfinch-sync:ivall/xcl:comment:7300270238 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3558#issuecomment-7300270238). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-12-01T03:59:45Z. --- @thehollowedone thank you for both reviews; both are right on the API contract. 1. The native path set `SyncBefore = NONE` for every marked barrier, so a clear followed by a move from the undefined layout lost the clear's sync. 2. A texture moved with an enhanced barrier and then with a legacy one in the same list (or the other way round) needs a hand-off through COMMON in the order the GPU runs them, and the first move of a texture whose legacy state was set by another list cannot be known when the list is recorded. 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.
Foniass commented 2026-12-01 07:07:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:07:12Z.


Review (head bd888cf7, diff read, not a merge-check; draft with PR description red, so not built or run here):

  • Half of the change never reaches the runtime. barrier_groups::transitions still ends its retain_mut with w[5] != w[6] (barrier_groups.rs ~478), so the marked same-state barriers transitions_of now produces (last state unknown, or already the target) are dropped there and never reach resource_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 call transitions_of, a_no_op and plan_with directly, never transitions(), so they don't catch it.
  • barrier_groups.rs ~50 still reads "LOCAL, not for a PR".
  • The thread_local! at list_x.rs ~6503 sits between stencil_copies_on's doc comment and the function, giving a new unused doc comment warning (~6498) in CI; at ~7506 the doc comment of the_from_undefined_mark_passes_the_flag_filter_only_for_barrier_groups is attached to the test before it.
  • Not yet measured: a run with 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 EnhancedBarriersSupported with a legacy fallback, Barrier is slot 80 of ID3D12GraphicsCommandList7, the native_layout table 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 change device_x::layout_state).

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7303667251 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3558#issuecomment-7303667251). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:07:12Z. --- Review (head bd888cf7, diff read, not a merge-check; draft with `PR description` red, so not built or run here): - **Half of the change never reaches the runtime.** `barrier_groups::transitions` still ends its `retain_mut` with `w[5] != w[6]` (`barrier_groups.rs` ~478), so the marked same-state barriers `transitions_of` now produces (last state unknown, or already the target) are dropped there and never reach `resource_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 call `transitions_of`, `a_no_op` and `plan_with` directly, never `transitions()`, so they don't catch it. - `barrier_groups.rs` ~50 still reads "LOCAL, not for a PR". - The `thread_local!` at `list_x.rs` ~6503 sits between `stencil_copies_on`'s doc comment and the function, giving a new `unused doc comment` warning (~6498) in CI; at ~7506 the doc comment of `the_from_undefined_mark_passes_the_flag_filter_only_for_barrier_groups` is attached to the test before it. - Not yet measured: a run with `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 `EnhancedBarriersSupported` with a legacy fallback, `Barrier` is slot 80 of `ID3D12GraphicsCommandList7`, the `native_layout` table 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 change `device_x::layout_state`). AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 10:15:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:15:57Z.


Triage (#1607) – head bd888cf

No 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_UNDEFINED starts 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.

<!-- greyfinch-sync:ivall/xcl:comment:7307921870 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3558#issuecomment-7307921870). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T10:15:57Z. --- **Triage (#1607)** – head bd888cf No 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_UNDEFINED` starts 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.
gut0to commented 2026-12-01 13:54:00 +00:00 (Migrated from github.com)

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 77

@@ -47,6 +47,46 @@ const SHADING_RATE_SOURCE: u32 = 0x100_0000;
 /// D3D12_RESOURCE_BARRIER_FLAG_BEGIN_ONLY, END_ONLY
 const BEGIN_ONLY: u32 = 1;
 const END_ONLY: u32 = 2;
+/// LOCAL, not for a PR (`XCL_BARRIER_UNDEFINED_NATIVE`): a mark in a transition's flags word: it
+/// comes from the undefined layout, and its before-state is only the state the texture was last
+/// moved to in the title's RECORDING order (`LAST`). The PC list's barrier call
+/// (`list_x::send_barriers`) sends it as an enhanced barrier from LAYOUT_UNDEFINED instead, which
+/// needs no before-state; the trackers see the word as before. Related: #3489.
+pub(super) const FROM_UNDEFINED: u32 = 0x8000_0000;
+
+/// `XCL_BARRIER_UNDEFINED_NATIVE=1` (off by default): transitions from the undefined layout are
+/// marked `FROM_UNDEFINED`. With lists recorded on several threads, the recording order is not the
+/// order the GPU runs them in, so a before-state from `LAST` can be a state the texture is not in
+/// when the GPU gets there (`a_barrier_from_undefined_starts_from_the_state_in_submission_order`).
+pub(super) fn native_undefined() -> bool {
+    static ON: OnceLock<bool> = OnceLock::new();
+    *ON.get_or_init(|| {
+        let on = std::env::var("XCL_BARRIER_UNDEFINED_NATIVE").is_ok_and(|v| v.trim() == "1");
+        if on {
+            crate::xlog_info!("D3D12.X: XCL_BARRIER_UNDEFINED_NATIVE=1 – barriers of the title from the undefined layout go out as enhanced barriers from it, with no before-state");
+        }
+        on
+    })
+}
+
+/// The enhanced-barrier layout and access of a texture in legacy `state` (one this module makes),
+/// for a barrier from LAYOUT_UNDEFINED; None: no single layout stands for it.
+pub(super) fn native_layout(state: u32) -> Option<(i32, i32)> {
+    Some(match state {
+        0 => (0, 0),
+        RENDER_TARGET => (2, 0x8),

The values returned here are passed directly as D3D12_BARRIER_LAYOUT in from_undefined_natively, but they do not match the SDK enum values. For example, RENDER_TARGET is 4 (not 2, which is PRESENT), and UNORDERED_ACCESS is 5 (not 3). With XCL_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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4755187107 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3558#discussion_r4755187107). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-01T13:54:00Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 77 ~~~~diff @@ -47,6 +47,46 @@ const SHADING_RATE_SOURCE: u32 = 0x100_0000; /// D3D12_RESOURCE_BARRIER_FLAG_BEGIN_ONLY, END_ONLY const BEGIN_ONLY: u32 = 1; const END_ONLY: u32 = 2; +/// LOCAL, not for a PR (`XCL_BARRIER_UNDEFINED_NATIVE`): a mark in a transition's flags word: it +/// comes from the undefined layout, and its before-state is only the state the texture was last +/// moved to in the title's RECORDING order (`LAST`). The PC list's barrier call +/// (`list_x::send_barriers`) sends it as an enhanced barrier from LAYOUT_UNDEFINED instead, which +/// needs no before-state; the trackers see the word as before. Related: #3489. +pub(super) const FROM_UNDEFINED: u32 = 0x8000_0000; + +/// `XCL_BARRIER_UNDEFINED_NATIVE=1` (off by default): transitions from the undefined layout are +/// marked `FROM_UNDEFINED`. With lists recorded on several threads, the recording order is not the +/// order the GPU runs them in, so a before-state from `LAST` can be a state the texture is not in +/// when the GPU gets there (`a_barrier_from_undefined_starts_from_the_state_in_submission_order`). +pub(super) fn native_undefined() -> bool { + static ON: OnceLock<bool> = OnceLock::new(); + *ON.get_or_init(|| { + let on = std::env::var("XCL_BARRIER_UNDEFINED_NATIVE").is_ok_and(|v| v.trim() == "1"); + if on { + crate::xlog_info!("D3D12.X: XCL_BARRIER_UNDEFINED_NATIVE=1 – barriers of the title from the undefined layout go out as enhanced barriers from it, with no before-state"); + } + on + }) +} + +/// The enhanced-barrier layout and access of a texture in legacy `state` (one this module makes), +/// for a barrier from LAYOUT_UNDEFINED; None: no single layout stands for it. +pub(super) fn native_layout(state: u32) -> Option<(i32, i32)> { + Some(match state { + 0 => (0, 0), + RENDER_TARGET => (2, 0x8), ~~~~ --- The values returned here are passed directly as `D3D12_BARRIER_LAYOUT` in `from_undefined_natively`, but they do not match the SDK enum values. For example, `RENDER_TARGET` is 4 (not 2, which is `PRESENT`), and `UNORDERED_ACCESS` is 5 (not 3). With `XCL_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.
gut0to commented 2026-12-01 13:54:00 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:review:6132647490 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3558#pullrequestreview-6132647490). Originally posted by [gut0to](https://github.com/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.
KDenKC commented 2026-12-01 13:57:16 +00:00 (Migrated from github.com)

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 the windows crate 0.62.2 that XCL builds with) D3D12_BARRIER_LAYOUT_COMMON and _PRESENT are both 0, _GENERIC_READ 1, _RENDER_TARGET 2, _UNORDERED_ACCESS 3, _DEPTH_STENCIL_WRITE 4, _DEPTH_STENCIL_READ 5, _SHADER_RESOURCE 6, _COPY_SOURCE 7, _COPY_DEST 8, _RESOLVE_SOURCE 9, _RESOLVE_DEST 10 (and _UNDEFINED -1), and the access bits used next to them are _RENDER_TARGET 0x8, _UNORDERED_ACCESS 0x10, _DEPTH_STENCIL_WRITE 0x20, _DEPTH_STENCIL_READ 0x40, _SHADER_RESOURCE 0x80, _COPY_DEST 0x400, _COPY_SOURCE 0x800, _RESOLVE_DEST 0x1000, _RESOLVE_SOURCE 0x2000, which is what native_layout returns. 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.

<!-- greyfinch-sync:ivall/xcl:comment:7313455008 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3558#issuecomment-7313455008). Originally posted by [KDenKC](https://github.com/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 the `windows` crate 0.62.2 that XCL builds with) `D3D12_BARRIER_LAYOUT_COMMON` and `_PRESENT` are both 0, `_GENERIC_READ` 1, `_RENDER_TARGET` 2, `_UNORDERED_ACCESS` 3, `_DEPTH_STENCIL_WRITE` 4, `_DEPTH_STENCIL_READ` 5, `_SHADER_RESOURCE` 6, `_COPY_SOURCE` 7, `_COPY_DEST` 8, `_RESOLVE_SOURCE` 9, `_RESOLVE_DEST` 10 (and `_UNDEFINED` -1), and the access bits used next to them are `_RENDER_TARGET` 0x8, `_UNORDERED_ACCESS` 0x10, `_DEPTH_STENCIL_WRITE` 0x20, `_DEPTH_STENCIL_READ` 0x40, `_SHADER_RESOURCE` 0x80, `_COPY_DEST` 0x400, `_COPY_SOURCE` 0x800, `_RESOLVE_DEST` 0x1000, `_RESOLVE_SOURCE` 0x2000, which is what `native_layout` returns. 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3558:upstream-pr/3558'
git switch 'upstream-pr/3558'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3558'
git switch 'upstream-pr/3558'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3558'
git switch 'upstream-pr/3558'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3558'
git switch 'main'
git merge --squash 'upstream-pr/3558'
git switch 'main'
git merge --ff-only 'upstream-pr/3558'
git switch 'main'
git merge 'upstream-pr/3558'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
xcl-dev/xcl!3558
No description provided.