D3D12.X: a new texture leaves the undefined layout from its creation state #3527

Open
afpruivo wants to merge 1 commit from upstream-pr/3527 into main
afpruivo commented 2026-11-30 13:54:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-11-30T13:54:34Z.


A barrier group's texture barrier from the undefined layout started at the state a barrier group last moved the texture to, so a texture no group had moved yet got no PC transition. A render target or depth buffer made in COMMON then stayed in COMMON while the title drew into or cleared it, and its next barrier named a state the PC texture was not in (debug layer 538 and 527). Each texture now has one record from creation to release, seeded with the PC state it was made in, and a barrier from the undefined layout starts each subresource there. Fixes #3489.

This is the starting state only. Barrier states still follow the order the title records its lists, not the order the GPU runs them (#3094; KDenKC's submit-time series, #3559 / #3599); that series needs each texture's creation state for its first move, which this record gives.

What is in it (one commit, on main c53e9696)

  • crates/xcl/src/hle/d3d12x/barrier_groups.rs: LAST is the one record per texture. Each of its two planes (colour or depth, stencil) is All(state), Each([state per subresource]) when the plane's subresources differ, or Unknown; apply moves it, in order, and makes a plane All again when its subresources agree. note_created seeds both planes at creation, whether or not the title has used barrier groups yet (most render targets and depth buffers are made at load, before the first group); buffers are not recorded.
    • A barrier from the undefined layout starts each subresource from its own state; one whose state is not known sends nothing and records nothing, so the record holds only states the PC's texture was moved to.
    • Within one Barrier call, a barrier starts where the barriers before it in the call left the texture.
    • The two halves of a split barrier from the undefined layout both start from the record; the move is recorded with the second half (END_ONLY), so the PC list gets both.
    • The record holds what the PC list gets: the state after legal() and the depth UAV park (pc_state). A move the PC would refuse is not recorded, and neither are the moves a refused transition stands for (same texture and subresource); the texture's other moves are.
    • The transitions of one ResourceBarrier call (the title's own, and the ones made of a barrier group) are recorded together (note_legacy_states), under one lock per texture, so a record forget removed on release is not put back.
  • device_x.rs, real.rs: note_created at the creation points that call depth_uav::note_created, the CreatePlacedResource the PC accepts on the first try, display targets made through the layout form of CreateCommittedResource (#127), CreateReservedResource/CreateReservedResource1, and CreateCommittedResource1/2 and CreatePlacedResource1 (creator!, from their initial-state argument).
  • list_x.rs: resource_barrier_x hands a call's transitions to note_legacy_states together.
  • sharded.rs: Sharded::update, a change of a value that is there, under its part's lock (nothing is made when there is none).
  • Tests: a_texture_is_tracked_from_creation_through_legacy_and_group_barriers_to_release (WARP textures through the creation, legacy, barrier-group and release hooks: creation before any group, a legacy move first, depth then stencil, release and reuse of the pointer, a compute list's legal state recorded and a refused move not, a 2-level D24S8 depth plane moved by a group one word per level, a legacy move of one level followed by a group that moves each level from where it is, and a group with one level's move refused and the other's sent), each_subresource_keeps_its_own_state_until_a_plane_is_in_one_again, a_barrier_starts_where_the_one_before_it_in_the_same_call_left_the_texture, the_halves_of_a_split_barrier_from_the_undefined_layout_start_at_the_same_state, an_update_changes_only_a_value_that_is_there, and the updated a_new_texture_leaves_the_undefined_layout_from_the_state_it_was_made_in and the_undefined_layout_moves_nothing_and_is_left_from_where_the_texture_was.

The diff is +442/-142, about half of it tests; the record and its tests are one change.

Tested

  • NVIDIA GeForce RTX 3090 24 GB (driver 621.40), Intel Core i5-13600K, 32 GB, Windows 11 build 26300, Rust 1.100.1; debug for the suite, release for the title runs.

  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 8bd724ee, with Windows' own D3D12 (XCL_D3D12_DIR set to an empty folder, see below): 3011 passed, 0 failed, 52 ignored; SKIPPED: 26 (22 no wave64 on this 32-lane GPU, 2 no xgameruntime.dll, 2 no heap windows). On f6ef500d and 1e702297: 3009 passed, 2 failed, the 2 being one test counted twice, gpu_two_pass_cache_e2e::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (#3441), which fails 3 of 6 runs on main c53e9696 on this card and is fixed by #3185.

  • cargo test -p xcl --lib barrier_groups: 13 passed.

  • With the Agility SDK 1.620 in %LOCALAPPDATA%\XCL\D3D12, the lib test binary did not finish on this machine on the earlier base 0d61b2c2 either (the #3488 stop, "sparse upload preparation still failed after bounded retries"); not caused by this PR.

  • Debug-layer runs of the retail title (on the earlier head b948e19d and main 493dbd3d, 300 s, Agility SDK 1.620, same input script; XCL logs the first 8 messages of each id). main ended at 121 s with an access violation in d3d12.dll under the debug layer, so the table compares the first 121 s:

    debug layer error, 0-121 s main 493dbd3d b948e19d
    538, Draw into a render target in COMMON 1 0
    527, before-state RENDER_TARGET, texture in COMMON 1 0
    538, ClearDepthStencilView in COMMON 3 0
    538, ClearRenderTargetView in COMMON, subresource 0 1 0
    538, ClearRenderTargetView in COMMON, subresource 3 2 2
    527, a buffer promoted to vertex/index use (not tracked here) 7 8

    The b948e19d run went on to 300 s and, after the loading screens, logged six more 538s that main did not reach. Not rerun on this head.

Regression run

main:

xcl-smoke v1
commit: c53e96960265a82477a9c98677afb0402e98d486
gpu: NVIDIA GeForce RTX 3090
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1573 (PresentX 1573)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15794 MB

this PR:

xcl-smoke v1
commit: 8bd724eedc2fe92acbaa583958bc71d9a2fc989d
gpu: NVIDIA GeForce RTX 3090
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1668 (PresentX 1668)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17592 MB

Not tested

  • The debug-layer comparison on this head (8bd724ee); the table above is from b948e19d.
  • The smoke runs stay on "press A to start" (smoke.ps1 sends no input); the title uses barrier groups there already.
  • The world: no run here reached it.
  • The cost of recording every texture from creation (one shard lock per tracked texture per ResourceBarrier call, one GetDesc and insert per texture made, a small array for a plane whose subresources differ) beyond the smoke run.
  • A test for the records made at the console-layout creation hooks (display targets through CreateCommittedResource with the console's layout, reserved resources, the CreatePlacedResource the PC accepts on the first try, and the depth_uav / device_x placement points): they take the console's descriptors and need the title. CreateCommittedResource1 / 2 and CreatePlacedResource1 are tested through the hooked device (the_device_hooks_record_a_texture_made_through_create_committed_resource1_2_and_create_placed_resource1, WARP).
  • Implicit promotion and decay: not modelled here; KDenKC's #3599 models them at submission.
  • The barriers from the undefined layout that ask for a discard: XCL sends none, as before. The counter for them is no longer in this PR; it will be its own.
  • The full suite with the Agility SDK (see Tested).
  • AMD and Intel GPUs.

AI use

  • Claude Code with Claude Opus 5.5: wrote the code, the tests, the commit message and this description, checked bmjask's and Foniass's review findings against the code and wrote the fixes, ran the tests and the title runs. The fixes for the review of b948e19d and this update were made and posted by Claude Code while I was away, under the standing approval I gave it for this session.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5566652900 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-11-30T13:54:34Z. --- A barrier group's texture barrier from the undefined layout started at the state a barrier group last moved the texture to, so a texture no group had moved yet got no PC transition. A render target or depth buffer made in COMMON then stayed in COMMON while the title drew into or cleared it, and its next barrier named a state the PC texture was not in (debug layer 538 and 527). Each texture now has one record from creation to release, seeded with the PC state it was made in, and a barrier from the undefined layout starts each subresource there. Fixes #3489. This is the starting state only. Barrier states still follow the order the title records its lists, not the order the GPU runs them (#3094; KDenKC's submit-time series, #3559 / #3599); that series needs each texture's creation state for its first move, which this record gives. **What is in it** (one commit, on `main` `c53e9696`) - `crates/xcl/src/hle/d3d12x/barrier_groups.rs`: `LAST` is the one record per texture. Each of its two planes (colour or depth, stencil) is `All(state)`, `Each([state per subresource])` when the plane's subresources differ, or `Unknown`; `apply` moves it, in order, and makes a plane `All` again when its subresources agree. `note_created` seeds both planes at creation, whether or not the title has used barrier groups yet (most render targets and depth buffers are made at load, before the first group); buffers are not recorded. - A barrier from the undefined layout starts each subresource from its own state; one whose state is not known sends nothing and records nothing, so the record holds only states the PC's texture was moved to. - Within one `Barrier` call, a barrier starts where the barriers before it in the call left the texture. - The two halves of a split barrier from the undefined layout both start from the record; the move is recorded with the second half (`END_ONLY`), so the PC list gets both. - The record holds what the PC list gets: the state after `legal()` and the depth UAV park (`pc_state`). A move the PC would refuse is not recorded, and neither are the moves a refused transition stands for (same texture and subresource); the texture's other moves are. - The transitions of one `ResourceBarrier` call (the title's own, and the ones made of a barrier group) are recorded together (`note_legacy_states`), under one lock per texture, so a record `forget` removed on release is not put back. - `device_x.rs`, `real.rs`: `note_created` at the creation points that call `depth_uav::note_created`, the `CreatePlacedResource` the PC accepts on the first try, display targets made through the layout form of `CreateCommittedResource` (#127), `CreateReservedResource`/`CreateReservedResource1`, and `CreateCommittedResource1`/`2` and `CreatePlacedResource1` (`creator!`, from their initial-state argument). - `list_x.rs`: `resource_barrier_x` hands a call's transitions to `note_legacy_states` together. - `sharded.rs`: `Sharded::update`, a change of a value that is there, under its part's lock (nothing is made when there is none). - Tests: `a_texture_is_tracked_from_creation_through_legacy_and_group_barriers_to_release` (WARP textures through the creation, legacy, barrier-group and release hooks: creation before any group, a legacy move first, depth then stencil, release and reuse of the pointer, a compute list's legal state recorded and a refused move not, a 2-level D24S8 depth plane moved by a group one word per level, a legacy move of one level followed by a group that moves each level from where it is, and a group with one level's move refused and the other's sent), `each_subresource_keeps_its_own_state_until_a_plane_is_in_one_again`, `a_barrier_starts_where_the_one_before_it_in_the_same_call_left_the_texture`, `the_halves_of_a_split_barrier_from_the_undefined_layout_start_at_the_same_state`, `an_update_changes_only_a_value_that_is_there`, and the updated `a_new_texture_leaves_the_undefined_layout_from_the_state_it_was_made_in` and `the_undefined_layout_moves_nothing_and_is_left_from_where_the_texture_was`. The diff is +442/-142, about half of it tests; the record and its tests are one change. **Tested** - NVIDIA GeForce RTX 3090 24 GB (driver 621.40), Intel Core i5-13600K, 32 GB, Windows 11 build 26300, Rust 1.100.1; debug for the suite, release for the title runs. - `cargo test --workspace --no-fail-fast -- --test-threads=4` on `8bd724ee`, with Windows' own D3D12 (`XCL_D3D12_DIR` set to an empty folder, see below): 3011 passed, 0 failed, 52 ignored; SKIPPED: 26 (22 no wave64 on this 32-lane GPU, 2 no xgameruntime.dll, 2 no heap windows). On `f6ef500d` and `1e702297`: 3009 passed, 2 failed, the 2 being one test counted twice, `gpu_two_pass_cache_e2e::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs` (#3441), which fails 3 of 6 runs on `main` `c53e9696` on this card and is fixed by #3185. - `cargo test -p xcl --lib barrier_groups`: 13 passed. - With the Agility SDK 1.620 in `%LOCALAPPDATA%\XCL\D3D12`, the lib test binary did not finish on this machine on the earlier base `0d61b2c2` either (the #3488 stop, "sparse upload preparation still failed after bounded retries"); not caused by this PR. - Debug-layer runs of the retail title (on the earlier head `b948e19d` and `main` `493dbd3d`, 300 s, Agility SDK 1.620, same input script; XCL logs the first 8 messages of each id). `main` ended at 121 s with an access violation in `d3d12.dll` under the debug layer, so the table compares the first 121 s: | debug layer error, 0-121 s | `main` 493dbd3d | `b948e19d` | |---|---|---| | 538, Draw into a render target in COMMON | 1 | 0 | | 527, before-state RENDER_TARGET, texture in COMMON | 1 | 0 | | 538, ClearDepthStencilView in COMMON | 3 | 0 | | 538, ClearRenderTargetView in COMMON, subresource 0 | 1 | 0 | | 538, ClearRenderTargetView in COMMON, subresource 3 | 2 | 2 | | 527, a buffer promoted to vertex/index use (not tracked here) | 7 | 8 | The `b948e19d` run went on to 300 s and, after the loading screens, logged six more 538s that `main` did not reach. Not rerun on this head. **Regression run** main: ``` xcl-smoke v1 commit: c53e96960265a82477a9c98677afb0402e98d486 gpu: NVIDIA GeForce RTX 3090 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1573 (PresentX 1573) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15794 MB ``` this PR: ``` xcl-smoke v1 commit: 8bd724eedc2fe92acbaa583958bc71d9a2fc989d gpu: NVIDIA GeForce RTX 3090 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1668 (PresentX 1668) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17592 MB ``` **Not tested** - The debug-layer comparison on this head (`8bd724ee`); the table above is from `b948e19d`. - The smoke runs stay on "press A to start" (`smoke.ps1` sends no input); the title uses barrier groups there already. - The world: no run here reached it. - The cost of recording every texture from creation (one shard lock per tracked texture per `ResourceBarrier` call, one `GetDesc` and insert per texture made, a small array for a plane whose subresources differ) beyond the smoke run. - A test for the records made at the console-layout creation hooks (display targets through `CreateCommittedResource` with the console's layout, reserved resources, the `CreatePlacedResource` the PC accepts on the first try, and the `depth_uav` / `device_x` placement points): they take the console's descriptors and need the title. `CreateCommittedResource1` / `2` and `CreatePlacedResource1` are tested through the hooked device (`the_device_hooks_record_a_texture_made_through_create_committed_resource1_2_and_create_placed_resource1`, WARP). - Implicit promotion and decay: not modelled here; KDenKC's #3599 models them at submission. - The barriers from the undefined layout that ask for a discard: XCL sends none, as before. The counter for them is no longer in this PR; it will be its own. - The full suite with the Agility SDK (see Tested). - AMD and Intel GPUs. **AI use** - Claude Code with Claude Opus 5.5: wrote the code, the tests, the commit message and this description, checked bmjask's and Foniass's review findings against the code and wrote the fixes, ran the tests and the title runs. The fixes for the review of `b948e19d` and this update were made and posted by Claude Code while I was away, under the standing approval I gave it for this session. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Gevroska commented 2026-11-30 15:43:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Gevroska on 2026-11-30T15:43:16Z.


@afpruivo I found a creation-order case on 94c9514d that the current test misses. I ran the same first UNDEFINED → RENDER_TARGET barrier on two synthetic textures created in COMMON. The result depended on when I created the texture:

Texture creation Result of the first barrier
Before the first texture-barrier batch No transition emitted. LAST still recorded RENDER_TARGET.
After the first batch One all-subresource COMMON → RENDER_TARGET transition emitted.

The creation hook only starts recording initial states after the first batch has been counted. The existing test seeds the creation state directly, so it covers the second case. Could you add a regression that calls the creation hook before processing any barriers?

I reproduced both outcomes in two fresh Windows CPU test processes using the state-tracking and translation functions extracted from the PR head. I didn’t run this through D3D12 or establish that the textures in #3489 were created in that order.

I used Codex GPT-6.2 Sol to build and run the fixture. A separate GPT-6.2 Sol agent reviewed the source and results. Codex GPT-6.2 Astra drafted this comment.

I reviewed and approved this comment before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7283467026 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7283467026). Originally posted by [Gevroska](https://github.com/Gevroska) on 2026-11-30T15:43:16Z. --- @afpruivo I found a creation-order case on `94c9514d` that the current test misses. I ran the same first `UNDEFINED → RENDER_TARGET` barrier on two synthetic textures created in `COMMON`. The result depended on when I created the texture: | Texture creation | Result of the first barrier | |---|---| | Before the first texture-barrier batch | No transition emitted. `LAST` still recorded `RENDER_TARGET`. | | After the first batch | One all-subresource `COMMON → RENDER_TARGET` transition emitted. | The creation hook only starts recording initial states after the first batch has been counted. The existing test seeds the creation state directly, so it covers the second case. Could you add a regression that calls the creation hook before processing any barriers? I reproduced both outcomes in two fresh Windows CPU test processes using the state-tracking and translation functions extracted from the PR head. I didn’t run this through D3D12 or establish that the textures in #3489 were created in that order. I used Codex GPT-6.2 Sol to build and run the fixture. A separate GPT-6.2 Sol agent reviewed the source and results. Codex GPT-6.2 Astra drafted this comment. I reviewed and approved this comment before posting.
thehollowedone commented 2026-12-01 03:35:37 +00:00 (Migrated from github.com)

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


Following the creation-order reproduction, I traced two more ways the starting state is lost on head 94c9514d:

  1. If a texture is created in COMMON, then an all-subresource legacy barrier moves it to COPY_DEST before the first texture-barrier batch, both hooks return while COUNTS[0] == 0. The first group UNDEFINED → RENDER_TARGET therefore emits no COPY_DEST → RENDER_TARGET transition. Moving the counter increment earlier cannot recover the state already discarded.
  2. After groups have begun, a partial legacy transition removes CREATED when LAST is absent. A later all-subresource legacy transition only restores CREATED if it already exists, so the now-known whole-resource state remains untracked. Also, after a first depth-only group, start_states selects LAST wholesale; its unset stencil plane does not fall back to the creation state.

Please track each texture's initial state from creation through final release, independent of the statistics counter. Preserve the state of each untouched plane, and let a whole-resource legacy transition reestablish a known state after a partial one. A single per-resource record seeded with both planes would keep those updates together; forget must remove it on release. A lifecycle regression should exercise the actual creation, legacy, group and release hooks, including creation before the first group, partial then whole legacy transitions, depth then stencil, and pointer reuse. The current test supplies the starting state directly, so it misses these paths.

This is a source trace; I did not run a new GPU or title test. AI use: Codex (GPT-6.2 Sol) traced the calls and drafted this note; Codex (GPT-6.2 Astra) independently checked the lifecycle.

<!-- greyfinch-sync:ivall/xcl:comment:7299865806 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7299865806). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-12-01T03:35:37Z. --- Following [the creation-order reproduction](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7283467026), I traced two more ways the starting state is lost on [head `94c9514d`](https://github.com/xcl-dev/xcl/commit/94c9514d331e5e53dcc266a1c6163fbe1c4038b7): 1. If a texture is created in `COMMON`, then an all-subresource legacy barrier moves it to `COPY_DEST` before the first texture-barrier batch, both hooks return while `COUNTS[0] == 0`. The first group `UNDEFINED → RENDER_TARGET` therefore emits no `COPY_DEST → RENDER_TARGET` transition. Moving the counter increment earlier cannot recover the state already discarded. 2. After groups have begun, a partial legacy transition removes `CREATED` when `LAST` is absent. A later all-subresource legacy transition only restores `CREATED` if it already exists, so the now-known whole-resource state remains untracked. Also, after a first depth-only group, `start_states` selects `LAST` wholesale; its unset stencil plane does not fall back to the creation state. Please track each texture's initial state from creation through final release, independent of the statistics counter. Preserve the state of each untouched plane, and let a whole-resource legacy transition reestablish a known state after a partial one. A single per-resource record seeded with both planes would keep those updates together; `forget` must remove it on release. A lifecycle regression should exercise the actual creation, legacy, group and release hooks, including creation before the first group, partial then whole legacy transitions, depth then stencil, and pointer reuse. The current test supplies the starting state directly, so it misses these paths. This is a source trace; I did not run a new GPU or title test. AI use: Codex (GPT-6.2 Sol) traced the calls and drafted this note; Codex (GPT-6.2 Astra) independently checked the lifecycle.
Foniass commented 2026-12-01 07:42:57 +00:00 (Migrated from github.com)

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


Review (head 94c9514d, diff read, not a merge-check; draft, so not built or run):

  • Textures created before the title's first barrier group are never recorded. note_created returns while COUNTS[0] is 0 (barrier_groups.rs ~283), and that counter only goes up at the end of the first barrier-group call (~458), so for render targets and depth buffers made at load a barrier from undefined still sends nothing. The unit test seeds the state map directly, so it doesn't cover the gate. (The gate exists so forget, gated the same way, drops every entry; recording unconditionally and forgetting unconditionally would fix both.)
  • The fallback is all-or-nothing (~292): after a depth-plane-only move the entry is [Some(a), None] (~427), so a later stencil-only barrier from undefined still sends nothing; a per-plane last[p].or(created) would fix that.
  • A texture CreatePlacedResource (#29) accepts on the first try returns at real.rs ~4469 without being recorded (consistent with depth_uav, but it's left out).
  • #3558 also handles barriers from undefined for #3489; they merge together and work together, but are worth reviewing side by side. #3238 / #839 change layout_state, which doesn't clash since this stores the PC's actual creation state.

Fine: the last-moved state still wins, forget and pointer reuse are handled, legacy full and partial transitions are kept in step, the smoke runs are within limits, and AI use names the model.

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

<!-- greyfinch-sync:ivall/xcl:comment:7304393300 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7304393300). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:42:57Z. --- Review (head 94c9514d, diff read, not a merge-check; draft, so not built or run): - **Textures created before the title's first barrier group are never recorded.** `note_created` returns while `COUNTS[0]` is 0 (`barrier_groups.rs` ~283), and that counter only goes up at the end of the first barrier-group call (~458), so for render targets and depth buffers made at load a barrier from undefined still sends nothing. The unit test seeds the state map directly, so it doesn't cover the gate. (The gate exists so `forget`, gated the same way, drops every entry; recording unconditionally and forgetting unconditionally would fix both.) - The fallback is all-or-nothing (~292): after a depth-plane-only move the entry is `[Some(a), None]` (~427), so a later stencil-only barrier from undefined still sends nothing; a per-plane `last[p].or(created)` would fix that. - A texture CreatePlacedResource (#29) accepts on the first try returns at `real.rs` ~4469 without being recorded (consistent with `depth_uav`, but it's left out). - #3558 also handles barriers from undefined for #3489; they merge together and work together, but are worth reviewing side by side. #3238 / #839 change `layout_state`, which doesn't clash since this stores the PC's actual creation state. Fine: the last-moved state still wins, `forget` and pointer reuse are handled, legacy full and partial transitions are kept in step, the smoke runs are within limits, and AI use names the model. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 10:09:45 +00:00 (Migrated from github.com)

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


Triage (#1607) – head 0d61b2c

#3558 works on the same barriers (#3489) differently: it sends moves from the undefined layout as enhanced barriers with no before-state (opt-in XCL_BARRIER_UNDEFINED_NATIVE), while this PR starts them from the texture's creation state. These are different approaches, not duplicates.
barrier_groups.rs::note_created now records the creation state of every texture whether or not the title has used barrier groups yet, so render targets and depth buffers made at load are covered, and forget drops the record unconditionally. 0d61b2c2 also counts and logs barriers from the undefined layout that ask for a discard, which XCL does not send.
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:7307765286 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7307765286). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T10:09:45Z. --- **Triage (#1607)** – head 0d61b2c #3558 works on the same barriers (#3489) differently: it sends moves from the undefined layout as enhanced barriers with no before-state (opt-in `XCL_BARRIER_UNDEFINED_NATIVE`), while this PR starts them from the texture's creation state. These are different approaches, not duplicates. `barrier_groups.rs::note_created` now records the creation state of every texture whether or not the title has used barrier groups yet, so render targets and depth buffers made at load are covered, and `forget` drops the record unconditionally. 0d61b2c2 also counts and logs barriers from the undefined layout that ask for a discard, which XCL does not send. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
afpruivo commented 2026-12-01 10:31:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-01T10:31:17Z.


Thank you @Gevroska, @thehollowedone and @Foniass. All of your points held up against the code, and the new head 0d61b2c2 (rebased on main 493dbd3d) addresses them:

  • Creation before the first barrier group (all three): the creation state is recorded whether or not the title has used barrier groups, and forget always drops it. The new WARP test creates a texture before any group and fails with the old gate (no transition instead of COMMON → RENDER_TARGET), as in Gevroska's reproduction.
  • One record seeded with both planes (thehollowedone, Foniass): CREATED is gone; LAST is seeded on both planes at creation, so a stencil-only barrier after a depth-only one starts from the creation state.
  • Partial then whole legacy transition (thehollowedone): a legacy transition of all subresources sets both planes, so a known state comes back; legacy moves before the first group are kept too.
  • CreatePlacedResource accepted on the first try (Foniass): recorded now (buffers are skipped).
  • Tests through the real hooks (all three): a_texture_is_tracked_from_creation_through_legacy_and_group_barriers_to_release runs creation, legacy, barrier-group and release calls on WARP textures, including pointer reuse.

On the title (RTX 3090, debug layer, 300 s): the draw and the depth clears in COMMON and the RENDER_TARGET-vs-COMMON 527 that #3489 reported are gone in both runs of this head. ClearRenderTargetView in COMMON still happens later in loading; a run that logged barriers finding no record of their texture logged none, so those are recorded textures in a different state on the GPU: the recording-order limit KDenKC's submit-time series is for, plus per-level moves. Numbers in the description.

The run also showed the title asks for D3D12_TEXTURE_BARRIER_FLAG_DISCARD on most of its moves from the undefined layout, which XCL does not send; that is outside this PR.

AI use: Claude Code (Claude Opus 5.5) wrote the change, ran the tests and the runs, and drafted this reply; I checked each point.

<!-- greyfinch-sync:ivall/xcl:comment:7308312979 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7308312979). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-01T10:31:17Z. --- Thank you @Gevroska, @thehollowedone and @Foniass. All of your points held up against the code, and the new head `0d61b2c2` (rebased on `main` `493dbd3d`) addresses them: - **Creation before the first barrier group** (all three): the creation state is recorded whether or not the title has used barrier groups, and `forget` always drops it. The new WARP test creates a texture before any group and fails with the old gate (no transition instead of `COMMON → RENDER_TARGET`), as in Gevroska's reproduction. - **One record seeded with both planes** (thehollowedone, Foniass): `CREATED` is gone; `LAST` is seeded on both planes at creation, so a stencil-only barrier after a depth-only one starts from the creation state. - **Partial then whole legacy transition** (thehollowedone): a legacy transition of all subresources sets both planes, so a known state comes back; legacy moves before the first group are kept too. - **`CreatePlacedResource` accepted on the first try** (Foniass): recorded now (buffers are skipped). - **Tests through the real hooks** (all three): `a_texture_is_tracked_from_creation_through_legacy_and_group_barriers_to_release` runs creation, legacy, barrier-group and release calls on WARP textures, including pointer reuse. On the title (RTX 3090, debug layer, 300 s): the draw and the depth clears in COMMON and the RENDER_TARGET-vs-COMMON 527 that #3489 reported are gone in both runs of this head. ClearRenderTargetView in COMMON still happens later in loading; a run that logged barriers finding no record of their texture logged none, so those are recorded textures in a different state on the GPU: the recording-order limit KDenKC's submit-time series is for, plus per-level moves. Numbers in the description. The run also showed the title asks for `D3D12_TEXTURE_BARRIER_FLAG_DISCARD` on most of its moves from the undefined layout, which XCL does not send; that is outside this PR. AI use: Claude Code (Claude Opus 5.5) wrote the change, ran the tests and the runs, and drafted this reply; I checked each point.
Aniseto commented 2026-12-01 10:43:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Aniseto on 2026-12-01T10:43:19Z.


Ran the barrier_groups tests at 0d61b2c2 on an NVIDIA Blackwell desktop part with 16 GB of VRAM. The PR is a draft; this is a synthetic check of its test group only.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, XCL_ADAPTER=NVIDIA, detached worktree at the exact PR head, no local patches.

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib barrier_groups -- --test-threads=1
11 passed; 0 failed; 0 ignored; 2775 filtered out      (exit 0)

All 11 tests pass here, the same count as the description, including the creation-to-release tracking case and the partial-then-whole legacy move case. The description's WARP fixtures and title runs were not repeated.

Not tested: the full workspace suite, a retail title, the debug-layer 538/527 symptom, WARP as a separate device, AMD adapters, Wine, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

<!-- greyfinch-sync:ivall/xcl:comment:7308610327 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7308610327). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-12-01T10:43:19Z. --- Ran the `barrier_groups` tests at `0d61b2c2` on an NVIDIA Blackwell desktop part with 16 GB of VRAM. The PR is a draft; this is a synthetic check of its test group only. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, `XCL_ADAPTER=NVIDIA`, detached worktree at the exact PR head, no local patches. ``` XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib barrier_groups -- --test-threads=1 11 passed; 0 failed; 0 ignored; 2775 filtered out (exit 0) ``` All 11 tests pass here, the same count as the description, including the creation-to-release tracking case and the partial-then-whole legacy move case. The description's WARP fixtures and title runs were not repeated. Not tested: the full workspace suite, a retail title, the debug-layer 538/527 symptom, WARP as a separate device, AMD adapters, Wine, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Foniass commented 2026-12-01 12:30:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T12:30:35Z.


merge-check
base: 493dbd3dd0
head: 0d61b2c268
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+195/-17). It fixes #3489: textures are now recorded in barrier_groups::LAST from their creation state, so a texture whose first move is a legacy barrier leaves the undefined layout correctly. All three earlier reviews are addressed: textures made before the first barrier group are recorded, both planes are seeded, a whole-texture legacy transition sets a known state again, forget always drops the record, and the placed resource accepted on the first try is recorded. Findings: (1) A diagnostic is bundled in. note_discards, the FROM_UNDEFINED counters, Texture.flags and default-on info logs (barrier_groups.rs ~126-127, ~429, ~476-513) are unrelated to #3489; CONTRIBUTING puts diagnostics in their own PR. (2) New default-path cost for every title. note_legacy_state (~307-311) used to return at once while COUNTS[0] == 0. Now every legacy transition does a LAST.get and a LAST.insert (two shard locks), every texture creation a GetDesc and an insert, and every barrier-group call runs the discard diagnostic. The smoke below is capped at 60 presents per second, so it can't show a small per-barrier cost. (3) Not covered: the title's CreateReservedResource(1) textures are still not recorded (real.rs ~4638). The WARP test calls note_created directly, so a wrong state at any of the 7 real creation hooks (real.rs ~3930, ~4487, ~4527, ~4568; device_x.rs ~1293, ~1317, ~1336) wouldn't be caught. Fine: place_console_texture goes through create_placed_resource_x, vram::place makes fresh resources, and the reserved pool reuses only textures whose final state matches the new creation state. #3558 handles the same barriers another way (opt-in) and the two compose. #3559's harness makes its WARP textures with plain CreateCommittedResource, so its workaround stays needed unless it calls note_created.
performance: 60 s smoke of a retail title, main 493dbd3d vs this merge (0d61b2c2): 1670 -> 1674 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 17254 MB, 0 device removals, 0 crashes. The first run of this merge lost the lib test binary to a misaligned-pointer abort that also hit an unrelated PR's run on a background thread, so it looks like a flake on main; this is the rerun. The discard diagnostic logged 2 lines at boot here.
verdict: not yet: the discard diagnostic and its default-on info lines (finding 1) belong in their own PR; with that split out, the fix itself passes here. The per-barrier cost on titles that never use barrier groups (finding 2) is worth a note in the description
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7311232873 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7311232873). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T12:30:35Z. --- merge-check base: 493dbd3dd0cd50b4c3e8d28f73ab9b504fcd8158 head: 0d61b2c268e7f8f650a4f0781604bcf7f249f635 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: read the whole diff (+195/-17). It fixes #3489: textures are now recorded in `barrier_groups::LAST` from their creation state, so a texture whose first move is a legacy barrier leaves the undefined layout correctly. All three earlier reviews are addressed: textures made before the first barrier group are recorded, both planes are seeded, a whole-texture legacy transition sets a known state again, `forget` always drops the record, and the placed resource accepted on the first try is recorded. Findings: (1) **A diagnostic is bundled in.** `note_discards`, the `FROM_UNDEFINED` counters, `Texture.flags` and default-on info logs (`barrier_groups.rs` ~126-127, ~429, ~476-513) are unrelated to #3489; CONTRIBUTING puts diagnostics in their own PR. (2) **New default-path cost for every title.** `note_legacy_state` (~307-311) used to return at once while `COUNTS[0] == 0`. Now every legacy transition does a `LAST.get` and a `LAST.insert` (two shard locks), every texture creation a `GetDesc` and an insert, and every barrier-group call runs the discard diagnostic. The smoke below is capped at 60 presents per second, so it can't show a small per-barrier cost. (3) **Not covered:** the title's `CreateReservedResource(1)` textures are still not recorded (`real.rs` ~4638). The WARP test calls `note_created` directly, so a wrong state at any of the 7 real creation hooks (`real.rs` ~3930, ~4487, ~4527, ~4568; `device_x.rs` ~1293, ~1317, ~1336) wouldn't be caught. Fine: `place_console_texture` goes through `create_placed_resource_x`, `vram::place` makes fresh resources, and the reserved pool reuses only textures whose final state matches the new creation state. #3558 handles the same barriers another way (opt-in) and the two compose. #3559's harness makes its WARP textures with plain `CreateCommittedResource`, so its workaround stays needed unless it calls `note_created`. performance: 60 s smoke of a retail title, main 493dbd3d vs this merge (0d61b2c2): 1670 -> 1674 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 17254 MB, 0 device removals, 0 crashes. The first run of this merge lost the lib test binary to a misaligned-pointer abort that also hit an unrelated PR's run on a background thread, so it looks like a flake on main; this is the rerun. The discard diagnostic logged 2 lines at boot here. verdict: not yet: the discard diagnostic and its default-on info lines (finding 1) belong in their own PR; with that split out, the fix itself passes here. The per-barrier cost on titles that never use barrier groups (finding 2) is worth a note in the description hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
AAsobu commented 2026-12-01 13:40:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by AAsobu on 2026-12-01T13:40:47Z.


merge-check
base: b2b1f109d2
head: 0d61b2c268
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll, 1 no GPU_UPLOAD heaps); failing: none. The PR's 3 tests ran and pass, a_texture_is_tracked_from_creation_through_legacy_and_group_barriers_to_release on WARP (not skipped).
review: read the whole diff (+195/-17: barrier_groups.rs, the note_created calls in device_x.rs and real.rs). LAST is now seeded at creation from every texture-creating path (placed GPU-owned / kept in step / own, committed, heap-placed, own memory) and kept on legacy transitions whether or not a barrier group came first, so a group's move from UNDEFINED starts from where the PC texture really is; buffers are left out; forget now always removes. Findings: (1) as Foniass noted, note_discards and its info lines are a diagnostic in the same PR as the fix; on this title it logged 25 lines in each 300 s run (bounded: the first 4, then at powers of two), e.g. render targets 5277/6412, depth 314/550, unordered access 10795/10795 barriers from UNDEFINED asking for a discard, so it is cheap but belongs in its own PR. (2) Nothing in the diff makes the recorded state follow submission order rather than recording order (the description's own limit), which afpruivo's discard experiment on this head also points at.
performance: retail title, in the world. Release builds of main b2b1f109 (A) and this merge (B), runs A, B, A, B of 300 s, xcl.exe with the #2590 profile at 2048 MB. Env: XCL_PREPARE=0 XCL_DIRECT_DXIL=1 XCL_DXC_THREADS=4 XCL_NETWORK=0 XCL_DRED=1 XCL_ACTIVITY=1 XCL_PSO_WAIT_MS=1000 XCL_TEXTURE_LEVEL_PAGES=1 XCL_HUGE_PSO_CONCURRENCY=4 XCL_HUGE_PSO_WANTED_CONCURRENCY=4, start prompt by XCL_PRESS_A_AT, no input. From world entry + 30 s: presents per 2 s A 0.83 / 1.05, B 1.03 / 1.08 (A1 was the first run of a new binary and still building driver pipelines); draws per 2 s A 3049 / 4287, B 3190 / 4088; peak process commit A 41,647 / 42,492 MB, B 41,124 / 42,134 MB; peak VRAM A 16,694 / 17,182 MB, B 16,507 / 17,108 MB; 0 device removals; skipped draws A 0 / 0, B 0 / 6. On screen (the user watched all four and took shots of the same scenes): no difference between A and B; one scene came out brighter in an A run than in a B run, but the same scene's brightness also changed between the two A runs, so I do not count it.
verdict: not yet: the discard diagnostic (finding 1) should be its own PR, as Foniass asked; the fix itself passes here with no frame-time, memory or picture change on this title
hardware / tool and model: NVIDIA GeForce RTX 3090 24 GB (driver 621.24, wave32 only), Intel Core i5-10600K, 32 GB, Windows 11 Home build 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5), results checked by me

<!-- greyfinch-sync:ivall/xcl:comment:7313004526 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7313004526). Originally posted by [AAsobu](https://github.com/AAsobu) on 2026-12-01T13:40:47Z. --- merge-check base: b2b1f109d27e746a62ec95b04dd1f9924452e682 head: 0d61b2c268e7f8f650a4f0781604bcf7f249f635 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll, 1 no GPU_UPLOAD heaps); failing: none. The PR's 3 tests ran and pass, `a_texture_is_tracked_from_creation_through_legacy_and_group_barriers_to_release` on WARP (not skipped). review: read the whole diff (+195/-17: `barrier_groups.rs`, the `note_created` calls in `device_x.rs` and `real.rs`). `LAST` is now seeded at creation from every texture-creating path (placed GPU-owned / kept in step / own, committed, heap-placed, own memory) and kept on legacy transitions whether or not a barrier group came first, so a group's move from `UNDEFINED` starts from where the PC texture really is; buffers are left out; `forget` now always removes. Findings: (1) as Foniass noted, `note_discards` and its info lines are a diagnostic in the same PR as the fix; on this title it logged 25 lines in each 300 s run (bounded: the first 4, then at powers of two), e.g. `render targets 5277/6412, depth 314/550, unordered access 10795/10795` barriers from `UNDEFINED` asking for a discard, so it is cheap but belongs in its own PR. (2) Nothing in the diff makes the recorded state follow submission order rather than recording order (the description's own limit), which afpruivo's discard experiment on this head also points at. performance: retail title, in the world. Release builds of `main` `b2b1f109` (A) and this merge (B), runs A, B, A, B of 300 s, `xcl.exe` with the #2590 profile at 2048 MB. Env: `XCL_PREPARE=0 XCL_DIRECT_DXIL=1 XCL_DXC_THREADS=4 XCL_NETWORK=0 XCL_DRED=1 XCL_ACTIVITY=1 XCL_PSO_WAIT_MS=1000 XCL_TEXTURE_LEVEL_PAGES=1 XCL_HUGE_PSO_CONCURRENCY=4 XCL_HUGE_PSO_WANTED_CONCURRENCY=4`, start prompt by `XCL_PRESS_A_AT`, no input. From world entry + 30 s: presents per 2 s A 0.83 / 1.05, B 1.03 / 1.08 (A1 was the first run of a new binary and still building driver pipelines); draws per 2 s A 3049 / 4287, B 3190 / 4088; peak process commit A 41,647 / 42,492 MB, B 41,124 / 42,134 MB; peak VRAM A 16,694 / 17,182 MB, B 16,507 / 17,108 MB; 0 device removals; skipped draws A 0 / 0, B 0 / 6. On screen (the user watched all four and took shots of the same scenes): no difference between A and B; one scene came out brighter in an A run than in a B run, but the same scene's brightness also changed between the two A runs, so I do not count it. verdict: not yet: the discard diagnostic (finding 1) should be its own PR, as Foniass asked; the fix itself passes here with no frame-time, memory or picture change on this title hardware / tool and model: NVIDIA GeForce RTX 3090 24 GB (driver 621.24, wave32 only), Intel Core i5-10600K, 32 GB, Windows 11 Home build 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5), results checked by me
bmjask commented 2026-12-02 11:18:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T11:18:27Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 313

@@ -270,37 +272,59 @@ struct Tracked {
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// The per-plane state each texture is in, in the title's recording order: seeded with the PC
+/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions.
+/// A barrier from the undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
+
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { states: [Some(state), Some(state)], plane_stride }
+}
+
+/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether
+/// or not the title has used barrier groups yet: textures made at load (most render targets
+/// and depth buffers) come before its first barrier group. A buffer is not recorded.
+pub(super) fn note_created(res: usize, state: u32) {
+    if res == 0 || !enabled() {
+        return;
+    }
+    let r = res as *mut c_void;
+    let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return };
+    if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER {
+        return;
+    }
+    let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
+    LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1)));
+}
+
 /// Texture barriers read, and transitions made of them.
 static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
 
-/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to
-/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked.
+/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all
+/// subresources sets both planes; one of some sets the plane they are in (as a barrier group's
+/// partial range does). No-op if the texture is not tracked.
 pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) {
-    if COUNTS[0].load(Ordering::Relaxed) == 0 {
-        return;
+    if let Some(cur) = LAST.get(res) {
+        LAST.insert(res, legacy_moved(cur, sub, after));
     }
-    let Some(mut cur) = LAST.get(res) else { return };
+}
+
+fn legacy_moved(mut cur: Tracked, sub: u32, after: u32) -> Tracked {

legacy_moved keeps one state per plane, so a legacy transition of one subresource (one mip or slice) moves the whole plane's recorded state, and this now runs on every texture from creation. A 4-mip render target made in COMMON gets a legacy barrier moving subresource 1 to COPY_DEST, so the record says plane 0 = COPY_DEST. A full-texture UNDEFINED->RENDER_TARGET barrier then sends one ALL_SUBRESOURCES COPY_DEST->RENDER_TARGET while mips 0, 2 and 3 are still in COMMON: 527, and those mips are never moved. That matches the PR's own leftover subresource-3 errors. Keeping per-subresource state, or dropping the record (back to untracked) when a single subresource moves, would avoid it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4768717114 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4768717114). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T11:18:27Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 313 ~~~~diff @@ -270,37 +272,59 @@ struct Tracked { plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// The per-plane state each texture is in, in the title's recording order: seeded with the PC +/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions. +/// A barrier from the undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); + +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { states: [Some(state), Some(state)], plane_stride } +} + +/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether +/// or not the title has used barrier groups yet: textures made at load (most render targets +/// and depth buffers) come before its first barrier group. A buffer is not recorded. +pub(super) fn note_created(res: usize, state: u32) { + if res == 0 || !enabled() { + return; + } + let r = res as *mut c_void; + let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return }; + if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER { + return; + } + let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; + LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1))); +} + /// Texture barriers read, and transitions made of them. static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; -/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to -/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked. +/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all +/// subresources sets both planes; one of some sets the plane they are in (as a barrier group's +/// partial range does). No-op if the texture is not tracked. pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) { - if COUNTS[0].load(Ordering::Relaxed) == 0 { - return; + if let Some(cur) = LAST.get(res) { + LAST.insert(res, legacy_moved(cur, sub, after)); } - let Some(mut cur) = LAST.get(res) else { return }; +} + +fn legacy_moved(mut cur: Tracked, sub: u32, after: u32) -> Tracked { ~~~~ --- `legacy_moved` keeps one state per plane, so a legacy transition of one subresource (one mip or slice) moves the whole plane's recorded state, and this now runs on every texture from creation. A 4-mip render target made in COMMON gets a legacy barrier moving subresource 1 to COPY_DEST, so the record says plane 0 = COPY_DEST. A full-texture UNDEFINED->RENDER_TARGET barrier then sends one ALL_SUBRESOURCES COPY_DEST->RENDER_TARGET while mips 0, 2 and 3 are still in COMMON: 527, and those mips are never moved. That matches the PR's own leftover subresource-3 errors. Keeping per-subresource state, or dropping the record (back to untracked) when a single subresource moves, would avoid it.
bmjask commented 2026-12-02 11:18:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T11:18:27Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 298

@@ -270,37 +272,59 @@ struct Tracked {
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// The per-plane state each texture is in, in the title's recording order: seeded with the PC
+/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions.
+/// A barrier from the undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
+
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { states: [Some(state), Some(state)], plane_stride }
+}
+
+/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether
+/// or not the title has used barrier groups yet: textures made at load (most render targets
+/// and depth buffers) come before its first barrier group. A buffer is not recorded.
+pub(super) fn note_created(res: usize, state: u32) {
+    if res == 0 || !enabled() {
+        return;
+    }
+    let r = res as *mut c_void;
+    let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return };
+    if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER {
+        return;
+    }
+    let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
+    LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1)));

Not certain about this one: every non-buffer texture is now seeded with its creation state and moved by legacy transitions in recording order, but D3D12's implicit promotion and decay aren't modelled, so textures that used to be untracked (nothing sent) now get a definite but wrong before-state. A sampled texture made in COMMON and written by CopyTextureRegion on a direct list with no barrier is promoted to COPY_DEST (a write state, so it doesn't decay). A texture moved COMMON->COPY_DEST on a copy queue decays back to COMMON after ExecuteCommandLists. In either case the next barrier from UNDEFINED sends the wrong before-state (527), where before nothing was sent.

<!-- greyfinch-sync:ivall/xcl:review-comment:4768717120 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4768717120). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T11:18:27Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 298 ~~~~diff @@ -270,37 +272,59 @@ struct Tracked { plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// The per-plane state each texture is in, in the title's recording order: seeded with the PC +/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions. +/// A barrier from the undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); + +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { states: [Some(state), Some(state)], plane_stride } +} + +/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether +/// or not the title has used barrier groups yet: textures made at load (most render targets +/// and depth buffers) come before its first barrier group. A buffer is not recorded. +pub(super) fn note_created(res: usize, state: u32) { + if res == 0 || !enabled() { + return; + } + let r = res as *mut c_void; + let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return }; + if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER { + return; + } + let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; + LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1))); ~~~~ --- Not certain about this one: every non-buffer texture is now seeded with its creation state and moved by legacy transitions in recording order, but D3D12's implicit promotion and decay aren't modelled, so textures that used to be untracked (nothing sent) now get a definite but wrong before-state. A sampled texture made in COMMON and written by CopyTextureRegion on a direct list with no barrier is promoted to COPY_DEST (a write state, so it doesn't decay). A texture moved COMMON->COPY_DEST on a copy queue decays back to COMMON after ExecuteCommandLists. In either case the next barrier from UNDEFINED sends the wrong before-state (527), where before nothing was sent.
bmjask commented 2026-12-02 11:18:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T11:18:27Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 307

@@ -270,37 +272,59 @@ struct Tracked {
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// The per-plane state each texture is in, in the title's recording order: seeded with the PC
+/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions.
+/// A barrier from the undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
+
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { states: [Some(state), Some(state)], plane_stride }
+}
+
+/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether
+/// or not the title has used barrier groups yet: textures made at load (most render targets
+/// and depth buffers) come before its first barrier group. A buffer is not recorded.
+pub(super) fn note_created(res: usize, state: u32) {
+    if res == 0 || !enabled() {
+        return;
+    }
+    let r = res as *mut c_void;
+    let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return };
+    if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER {
+        return;
+    }
+    let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
+    LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1)));
+}
+
 /// Texture barriers read, and transitions made of them.
 static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
 
-/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to
-/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked.
+/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all
+/// subresources sets both planes; one of some sets the plane they are in (as a barrier group's
+/// partial range does). No-op if the texture is not tracked.
 pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) {

Not certain about this one: note_legacy_state reads with LAST.get and writes with LAST.insert, taking the shard lock twice, and it's no longer behind the COUNTS gate, so it now races with forget() and other recording threads. If thread A records a legacy transition and calls LAST.get, and thread B releases the texture so forget() removes the record, then A's insert puts back a record for a freed pointer. A texture later made at that address through a path that doesn't record (display target, reserved resource) inherits the stale state, and its first barrier sends a wrong before-state. Two threads on the same texture can also lose an update. An update-if-present under one shard lock would fix both.

<!-- greyfinch-sync:ivall/xcl:review-comment:4768717130 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4768717130). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T11:18:27Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 307 ~~~~diff @@ -270,37 +272,59 @@ struct Tracked { plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// The per-plane state each texture is in, in the title's recording order: seeded with the PC +/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions. +/// A barrier from the undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); + +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { states: [Some(state), Some(state)], plane_stride } +} + +/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether +/// or not the title has used barrier groups yet: textures made at load (most render targets +/// and depth buffers) come before its first barrier group. A buffer is not recorded. +pub(super) fn note_created(res: usize, state: u32) { + if res == 0 || !enabled() { + return; + } + let r = res as *mut c_void; + let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return }; + if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER { + return; + } + let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; + LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1))); +} + /// Texture barriers read, and transitions made of them. static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; -/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to -/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked. +/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all +/// subresources sets both planes; one of some sets the plane they are in (as a barrier group's +/// partial range does). No-op if the texture is not tracked. pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) { ~~~~ --- Not certain about this one: `note_legacy_state` reads with LAST.get and writes with LAST.insert, taking the shard lock twice, and it's no longer behind the COUNTS gate, so it now races with `forget()` and other recording threads. If thread A records a legacy transition and calls LAST.get, and thread B releases the texture so `forget()` removes the record, then A's insert puts back a record for a freed pointer. A texture later made at that address through a path that doesn't record (display target, reserved resource) inherits the stale state, and its first barrier sends a wrong before-state. Two threads on the same texture can also lose an update. An update-if-present under one shard lock would fix both.
bmjask commented 2026-12-02 11:18:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T11:18:27Z.

Review: COMMENTED


Review of 0d61b2c2: 5 finding(s). 3 are inline. These are on lines outside the diff:

crates/xcl/src/hle/d3d12x/real.rs:3848: Display targets made through the layout form of CreateCommittedResource (#127 -> create_display_target), and textures from CreateReservedResource/CreateReservedResource1, never call barrier_groups::note_created, so #3489 isn't fixed for them. A title using barrier groups that creates its back-buffer targets with a barrier layout (#127, ALLOW_DISPLAY) goes through create_display_target, which calls dev_create_committed_resource and returns without recording. The first UNDEFINED->RENDER_TARGET barrier finds no record and sends nothing, so the PC texture stays in COMMON while the title draws into it: debug layer 538, then 527 on its next barrier. Recording in one place every PC resource creation passes through (the creator!/adopt(Kind::Resource) path) would cover these and any future path.

crates/xcl/src/hle/d3d12x/barrier_groups.rs:423: The moved closure stores the state before legal() adjusts it (compute lists drop PIXEL_SHADER_RESOURCE 0x80, and DEPTH_READ is removed on non-depth textures), and it also stores transitions that refused() drops. So the record differs from what was actually sent to the PC, and the next barrier from UNDEFINED uses it. A texture made in COMMON gets UNDEFINED->SHADER_RESOURCE on a compute list: the PC receives COMMON->0x40, but LAST holds 0xC0. A later UNDEFINED->RENDER_TARGET on a direct list sends 0xC0->RENDER_TARGET while the texture is in 0x40, which is debug layer 527. Since every texture is now seeded at creation, this path runs for all of them. Storing the legalized state, and nothing for refused transitions, would fix it.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6149731321 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#pullrequestreview-6149731321). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T11:18:27Z. **Review:** COMMENTED --- Review of `0d61b2c2`: 5 finding(s). 3 are inline. These are on lines outside the diff: **`crates/xcl/src/hle/d3d12x/real.rs:3848`**: Display targets made through the layout form of CreateCommittedResource (#127 -> `create_display_target`), and textures from CreateReservedResource/CreateReservedResource1, never call `barrier_groups::note_created`, so #3489 isn't fixed for them. A title using barrier groups that creates its back-buffer targets with a barrier layout (#127, ALLOW_DISPLAY) goes through `create_display_target`, which calls `dev_create_committed_resource` and returns without recording. The first UNDEFINED->RENDER_TARGET barrier finds no record and sends nothing, so the PC texture stays in COMMON while the title draws into it: debug layer 538, then 527 on its next barrier. Recording in one place every PC resource creation passes through (the creator!/adopt(Kind::Resource) path) would cover these and any future path. **`crates/xcl/src/hle/d3d12x/barrier_groups.rs:423`**: The `moved` closure stores the state before `legal()` adjusts it (compute lists drop PIXEL_SHADER_RESOURCE 0x80, and DEPTH_READ is removed on non-depth textures), and it also stores transitions that `refused()` drops. So the record differs from what was actually sent to the PC, and the next barrier from UNDEFINED uses it. A texture made in COMMON gets UNDEFINED->SHADER_RESOURCE on a compute list: the PC receives COMMON->0x40, but LAST holds 0xC0. A later UNDEFINED->RENDER_TARGET on a direct list sends 0xC0->RENDER_TARGET while the texture is in 0x40, which is debug layer 527. Since every texture is now seeded at creation, this path runs for all of them. Storing the legalized state, and nothing for refused transitions, would fix it. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
bmjask commented 2026-12-02 14:11:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:11:57Z.


@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

<!-- greyfinch-sync:ivall/xcl:comment:7348149179 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7348149179). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T14:11:57Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
afpruivo commented 2026-12-02 15:22:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T15:22:02Z.


@bmjask thank you for the review. All five findings checked against 0d61b2c2; four were right and are fixed in the one commit, now 7c10aff7 (force-pushed; description updated):

  • Display targets and reserved resources were never recorded (real.rs ~3848): right. create_display_target (#127 with ALLOW_DISPLAY) and CreateReservedResource/CreateReservedResource1 now call barrier_groups::note_created with the PC state they were made in. I kept the calls next to the existing ones at the creation points rather than moving them all into creator!/adopt, to keep this PR small; one place for all of them would be a good follow-up. No test of its own: those paths need the title; the smoke run goes through them.
  • The record stored the state before legal(), and refused transitions (barrier_groups.rs ~423): right. Your compute-list case is now in the WARP test: UNDEFINED → SHADER_RESOURCE on a compute list sends 0 → 0x40 and records 0x40; a later UNDEFINED → RENDER_TARGET on a direct list sends 0x40 → RENDER_TARGET. The moves are collected during transitions_of and recorded after the legalising pass, with the same pc_state (legal state, or the depth UAV park) the words get; a texture with a refused transition in the call keeps its old record. The test fails with the old order.

Tested on 7c10aff7: whole suite 2903 passed, 2 failed (one flaky e2e test counted twice, also flaky on the base), 51 ignored, 26 SKIPPED; smoke pair in the description (1591 vs 1494 frames, 17357 vs 16992 MB). The suite ran with Windows' own D3D12: with the Agility SDK 1.620 the lib tests do not finish on my RTX 3090, on the base as well; details in Tested.

AI use: findings checked and fixes written with Claude Code (Claude Opus 5.5), checked by me.

<!-- greyfinch-sync:ivall/xcl:comment:7350202026 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7350202026). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T15:22:02Z. --- @bmjask thank you for the review. All five findings checked against `0d61b2c2`; four were right and are fixed in the one commit, now `7c10aff7` (force-pushed; description updated): - **Display targets and reserved resources were never recorded** (`real.rs` ~3848): right. `create_display_target` (#127 with ALLOW_DISPLAY) and `CreateReservedResource`/`CreateReservedResource1` now call `barrier_groups::note_created` with the PC state they were made in. I kept the calls next to the existing ones at the creation points rather than moving them all into `creator!`/`adopt`, to keep this PR small; one place for all of them would be a good follow-up. No test of its own: those paths need the title; the smoke run goes through them. - **The record stored the state before `legal()`, and refused transitions** (`barrier_groups.rs` ~423): right. Your compute-list case is now in the WARP test: UNDEFINED → SHADER_RESOURCE on a compute list sends `0 → 0x40` and records 0x40; a later UNDEFINED → RENDER_TARGET on a direct list sends `0x40 → RENDER_TARGET`. The moves are collected during `transitions_of` and recorded after the legalising pass, with the same `pc_state` (legal state, or the depth UAV park) the words get; a texture with a refused transition in the call keeps its old record. The test fails with the old order. Tested on `7c10aff7`: whole suite 2903 passed, 2 failed (one flaky e2e test counted twice, also flaky on the base), 51 ignored, 26 SKIPPED; smoke pair in the description (1591 vs 1494 frames, 17357 vs 16992 MB). The suite ran with Windows' own D3D12: with the Agility SDK 1.620 the lib tests do not finish on my RTX 3090, on the base as well; details in **Tested**. AI use: findings checked and fixes written with Claude Code (Claude Opus 5.5), checked by me.
afpruivo commented 2026-12-02 15:22:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T15:22:03Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 313

@@ -270,37 +272,59 @@ struct Tracked {
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// The per-plane state each texture is in, in the title's recording order: seeded with the PC
+/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions.
+/// A barrier from the undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
+
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { states: [Some(state), Some(state)], plane_stride }
+}
+
+/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether
+/// or not the title has used barrier groups yet: textures made at load (most render targets
+/// and depth buffers) come before its first barrier group. A buffer is not recorded.
+pub(super) fn note_created(res: usize, state: u32) {
+    if res == 0 || !enabled() {
+        return;
+    }
+    let r = res as *mut c_void;
+    let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return };
+    if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER {
+        return;
+    }
+    let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
+    LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1)));
+}
+
 /// Texture barriers read, and transitions made of them.
 static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
 
-/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to
-/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked.
+/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all
+/// subresources sets both planes; one of some sets the plane they are in (as a barrier group's
+/// partial range does). No-op if the texture is not tracked.
 pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) {
-    if COUNTS[0].load(Ordering::Relaxed) == 0 {
-        return;
+    if let Some(cur) = LAST.get(res) {
+        LAST.insert(res, legacy_moved(cur, sub, after));
     }
-    let Some(mut cur) = LAST.get(res) else { return };
+}
+
+fn legacy_moved(mut cur: Tracked, sub: u32, after: u32) -> Tracked {

Right, and it was the subresource-3 leftover in my own debug runs. A legacy move of some of a plane's subresources now leaves that plane unknown (None) instead of moving it, so a later barrier from the undefined layout sends nothing for that plane, as for an untracked texture, until a transition of all of it; a plane with one subresource still takes the state. I chose this over per-subresource state to match #3599, which marks such a texture mixed and keeps today's behaviour. a_legacy_move_of_some_subresources_then_of_all_leaves_a_known_state covers it and fails with the old rule.

<!-- greyfinch-sync:ivall/xcl:review-comment:4771865637 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4771865637). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T15:22:03Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 313 ~~~~diff @@ -270,37 +272,59 @@ struct Tracked { plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// The per-plane state each texture is in, in the title's recording order: seeded with the PC +/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions. +/// A barrier from the undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); + +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { states: [Some(state), Some(state)], plane_stride } +} + +/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether +/// or not the title has used barrier groups yet: textures made at load (most render targets +/// and depth buffers) come before its first barrier group. A buffer is not recorded. +pub(super) fn note_created(res: usize, state: u32) { + if res == 0 || !enabled() { + return; + } + let r = res as *mut c_void; + let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return }; + if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER { + return; + } + let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; + LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1))); +} + /// Texture barriers read, and transitions made of them. static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; -/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to -/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked. +/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all +/// subresources sets both planes; one of some sets the plane they are in (as a barrier group's +/// partial range does). No-op if the texture is not tracked. pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) { - if COUNTS[0].load(Ordering::Relaxed) == 0 { - return; + if let Some(cur) = LAST.get(res) { + LAST.insert(res, legacy_moved(cur, sub, after)); } - let Some(mut cur) = LAST.get(res) else { return }; +} + +fn legacy_moved(mut cur: Tracked, sub: u32, after: u32) -> Tracked { ~~~~ --- Right, and it was the subresource-3 leftover in my own debug runs. A legacy move of some of a plane's subresources now leaves that plane unknown (`None`) instead of moving it, so a later barrier from the undefined layout sends nothing for that plane, as for an untracked texture, until a transition of all of it; a plane with one subresource still takes the state. I chose this over per-subresource state to match #3599, which marks such a texture mixed and keeps today's behaviour. `a_legacy_move_of_some_subresources_then_of_all_leaves_a_known_state` covers it and fails with the old rule.
afpruivo commented 2026-12-02 15:22:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T15:22:06Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 298

@@ -270,37 +272,59 @@ struct Tracked {
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// The per-plane state each texture is in, in the title's recording order: seeded with the PC
+/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions.
+/// A barrier from the undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
+
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { states: [Some(state), Some(state)], plane_stride }
+}
+
+/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether
+/// or not the title has used barrier groups yet: textures made at load (most render targets
+/// and depth buffers) come before its first barrier group. A buffer is not recorded.
+pub(super) fn note_created(res: usize, state: u32) {
+    if res == 0 || !enabled() {
+        return;
+    }
+    let r = res as *mut c_void;
+    let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return };
+    if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER {
+        return;
+    }
+    let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
+    LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1)));

The cases are real, but I left them out of this PR. Before it, those textures were untracked and the barrier from the undefined layout sent nothing, which is also wrong (538 instead of 527), so this trades one error for another rather than adding one. Promotion and decay depend on when a list is submitted and on which queue, which a record kept in recording order cannot know; KDenKC's #3599 models decay at submission (Queued::apply with a decay rule), and #3558 removes the before-state for these moves altogether. Listed under Not tested.

<!-- greyfinch-sync:ivall/xcl:review-comment:4771866286 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4771866286). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T15:22:06Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 298 ~~~~diff @@ -270,37 +272,59 @@ struct Tracked { plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// The per-plane state each texture is in, in the title's recording order: seeded with the PC +/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions. +/// A barrier from the undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); + +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { states: [Some(state), Some(state)], plane_stride } +} + +/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether +/// or not the title has used barrier groups yet: textures made at load (most render targets +/// and depth buffers) come before its first barrier group. A buffer is not recorded. +pub(super) fn note_created(res: usize, state: u32) { + if res == 0 || !enabled() { + return; + } + let r = res as *mut c_void; + let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return }; + if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER { + return; + } + let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; + LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1))); ~~~~ --- The cases are real, but I left them out of this PR. Before it, those textures were untracked and the barrier from the undefined layout sent nothing, which is also wrong (538 instead of 527), so this trades one error for another rather than adding one. Promotion and decay depend on when a list is submitted and on which queue, which a record kept in recording order cannot know; KDenKC's #3599 models decay at submission (`Queued::apply` with a decay rule), and #3558 removes the before-state for these moves altogether. Listed under **Not tested**.
afpruivo commented 2026-12-02 15:22:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T15:22:08Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 307

@@ -270,37 +272,59 @@ struct Tracked {
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// The per-plane state each texture is in, in the title's recording order: seeded with the PC
+/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions.
+/// A barrier from the undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
+
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { states: [Some(state), Some(state)], plane_stride }
+}
+
+/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether
+/// or not the title has used barrier groups yet: textures made at load (most render targets
+/// and depth buffers) come before its first barrier group. A buffer is not recorded.
+pub(super) fn note_created(res: usize, state: u32) {
+    if res == 0 || !enabled() {
+        return;
+    }
+    let r = res as *mut c_void;
+    let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return };
+    if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER {
+        return;
+    }
+    let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
+    LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1)));
+}
+
 /// Texture barriers read, and transitions made of them.
 static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
 
-/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to
-/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked.
+/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all
+/// subresources sets both planes; one of some sets the plane they are in (as a barrier group's
+/// partial range does). No-op if the texture is not tracked.
 pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) {

Right. note_legacy_state now uses a new Sharded::update, which changes the value only if it is there, under one shard lock, so a record forget removed is not put back and two updates of one texture cannot lose each other. an_update_changes_only_a_value_that_is_there tests the helper; the race itself has no test.

<!-- greyfinch-sync:ivall/xcl:review-comment:4771866714 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4771866714). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T15:22:08Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 307 ~~~~diff @@ -270,37 +272,59 @@ struct Tracked { plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// The per-plane state each texture is in, in the title's recording order: seeded with the PC +/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions. +/// A barrier from the undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); + +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { states: [Some(state), Some(state)], plane_stride } +} + +/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether +/// or not the title has used barrier groups yet: textures made at load (most render targets +/// and depth buffers) come before its first barrier group. A buffer is not recorded. +pub(super) fn note_created(res: usize, state: u32) { + if res == 0 || !enabled() { + return; + } + let r = res as *mut c_void; + let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return }; + if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER { + return; + } + let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; + LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1))); +} + /// Texture barriers read, and transitions made of them. static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; -/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to -/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked. +/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all +/// subresources sets both planes; one of some sets the plane they are in (as a barrier group's +/// partial range does). No-op if the texture is not tracked. pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) { ~~~~ --- Right. `note_legacy_state` now uses a new `Sharded::update`, which changes the value only if it is there, under one shard lock, so a record `forget` removed is not put back and two updates of one texture cannot lose each other. `an_update_changes_only_a_value_that_is_there` tests the helper; the race itself has no test.
Foniass commented 2026-12-02 15:28:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T15:28:14Z.


Follow-up review (head 7c10aff7, since 94c9514, diff read, not a merge-check):

  • Textures made before the first barrier group are never recorded: fixed; note_created (barrier_groups.rs ~288) and forget (~327) no longer depend on COUNTS[0], with a WARP test.
  • All-or-nothing fallback (a stencil barrier after a depth-only move sends nothing): fixed; both planes start in the creation state (created, ~281) and a group moves only the plane it touches, tested.
  • First-try CreatePlacedResource and reserved resources not recorded: fixed (real.rs ~4486, ~4653); the real creation hooks are still not covered by a test, as Not tested says.
  • Discard diagnostic bundled in: still open; Texture.flags, FROM_UNDEFINED, note_discards and its default-on info lines (~127, ~405, ~438, ~493-530) belong in their own PR.
  • Default-path cost for titles that never use barrier groups: partly fixed; a legacy transition now takes one shard lock through Sharded::update (~311), but every legacy transition still does a lookup and every texture creation a GetDesc and an insert, unmeasured.

New:

  • A barrier group's own transitions now wipe the record it just wrote. uav_barrier_x passes the words from transitions to resource_barrier_x (list_x.rs ~5036), which calls note_legacy_state for each, and the new rule in legacy_moved (~320) sets a plane to unknown for any single-subresource word when the plane has more than one subresource. A whole-plane barrier on a depth-stencil texture with mips or array slices (a D24S8 shadow-map array) goes out as one word per subresource, so the plane's record, just set at ~466, becomes None; the title's next barrier from the undefined layout on that plane then sends nothing and the texture stays in its old state while depth is written into it, the #3489 case, which main and 0d61b2c2 handled. The tests use 1-mip, 1-slice textures and never send group words through resource_barrier_x.

Fine: refused transitions are left out of the record and the legalized state is recorded (the compute-list case is tested); Sharded::update keeps a record forget removed from coming back; reserved, display-target and first-try placed textures are recorded.

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

<!-- greyfinch-sync:ivall/xcl:comment:7350378777 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7350378777). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T15:28:14Z. --- Follow-up review (head 7c10aff7, since 94c9514, diff read, not a merge-check): - **Textures made before the first barrier group are never recorded:** fixed; `note_created` (`barrier_groups.rs` ~288) and `forget` (~327) no longer depend on `COUNTS[0]`, with a WARP test. - **All-or-nothing fallback (a stencil barrier after a depth-only move sends nothing):** fixed; both planes start in the creation state (`created`, ~281) and a group moves only the plane it touches, tested. - **First-try `CreatePlacedResource` and reserved resources not recorded:** fixed (`real.rs` ~4486, ~4653); the real creation hooks are still not covered by a test, as **Not tested** says. - **Discard diagnostic bundled in:** still open; `Texture.flags`, `FROM_UNDEFINED`, `note_discards` and its default-on info lines (~127, ~405, ~438, ~493-530) belong in their own PR. - **Default-path cost for titles that never use barrier groups:** partly fixed; a legacy transition now takes one shard lock through `Sharded::update` (~311), but every legacy transition still does a lookup and every texture creation a `GetDesc` and an insert, unmeasured. New: - **A barrier group's own transitions now wipe the record it just wrote.** `uav_barrier_x` passes the words from `transitions` to `resource_barrier_x` (`list_x.rs` ~5036), which calls `note_legacy_state` for each, and the new rule in `legacy_moved` (~320) sets a plane to unknown for any single-subresource word when the plane has more than one subresource. A whole-plane barrier on a depth-stencil texture with mips or array slices (a D24S8 shadow-map array) goes out as one word per subresource, so the plane's record, just set at ~466, becomes `None`; the title's next barrier from the undefined layout on that plane then sends nothing and the texture stays in its old state while depth is written into it, the #3489 case, which `main` and `0d61b2c2` handled. The tests use 1-mip, 1-slice textures and never send group words through `resource_barrier_x`. Fine: refused transitions are left out of the record and the legalized state is recorded (the compute-list case is tested); `Sharded::update` keeps a record `forget` removed from coming back; reserved, display-target and first-try placed textures are recorded. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
bmjask commented 2026-12-02 15:45:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:45:26Z.

Review: COMMENTED


Review of 7c10aff7: 5 finding(s) (3 high, 2 medium), most severe first.

Re-review at 7c10aff7. Display targets and reserved resources are now recorded, a partially moved plane becomes unknown instead of taking the subresource's state, and moves are recorded from the legalised word. That addresses the main points of my earlier review. The new deferred recording brings these:

  1. High crates/xcl/src/hle/d3d12x/barrier_groups.rs:436: Barrier-group moves are now saved to moves and written to LAST only after the whole call, but transitions_of's last() reads LAST in the middle of the call, so a later barrier on the same texture in the same ResourceBarrier call sta.... (inline)
  2. High crates/xcl/src/hle/d3d12x/barrier_groups.rs:462: If any one transition of a texture is refused, every move for that texture in the call is dropped, yet its other transitions in the same call are still kept by retain_mut and sent to the PC, so the record stays at the old state while t.... (inline)
  3. High crates/xcl/src/hle/d3d12x/barrier_groups.rs:320: A legacy transition of one subresource on a plane with more than one subresource always sets that plane to None (unknown), even when the title moves every subresource of the plane one at a time. (inline)
  4. Medium crates/xcl/src/hle/d3d12x/barrier_groups.rs:225: see below.
  5. Medium crates/xcl/src/hle/d3d12x/real.rs:4440: see below.

On lines outside the diff:

  1. Medium crates/xcl/src/hle/d3d12x/barrier_groups.rs:225: A barrier from UNDEFINED whose plane is unknown (None) sends nothing but still records Some(after), which breaks the rule that a partially moved plane stays unknown until a transition of all of it. After a legacy move of mip 1 only to COPY_DEST (plane 0 None, PC with mip 0 in COMMON and mip 1 in COPY_DEST), a barrier group UNDEFINED -> RT sends nothing and records RT. A following UNDEFINED -> SR then sends RT -> SR with ALL_SUBRESOURCES while the PC texture is in COMMON/COPY_DEST (527). Keeping the plane None when nothing was sent would fix it.

  2. Medium crates/xcl/src/hle/d3d12x/real.rs:4440: Textures made through CreateCommittedResource2 and CreatePlacedResource1 (plain creator! hooks, real.rs:4440 and 4610), and any other creation path that doesn't call note_created, still aren't seeded, so #3489 remains for them. A render target made with CreateCommittedResource2 in COMMON whose first barrier group is UNDEFINED -> RENDER_TARGET has no record, nothing is sent, and it's drawn into in COMMON (538).


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6154172033 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#pullrequestreview-6154172033). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:45:26Z. **Review:** COMMENTED --- Review of `7c10aff7`: 5 finding(s) (3 high, 2 medium), most severe first. Re-review at `7c10aff7`. Display targets and reserved resources are now recorded, a partially moved plane becomes unknown instead of taking the subresource's state, and moves are recorded from the legalised word. That addresses the main points of my earlier review. The new deferred recording brings these: 1. **High** `crates/xcl/src/hle/d3d12x/barrier_groups.rs:436`: Barrier-group moves are now saved to `moves` and written to LAST only after the whole call, but `transitions_of`'s `last()` reads LAST in the middle of the call, so a later barrier on the same texture in the same ResourceBarrier call sta.... (inline) 2. **High** `crates/xcl/src/hle/d3d12x/barrier_groups.rs:462`: If any one transition of a texture is refused, every move for that texture in the call is dropped, yet its other transitions in the same call are still kept by `retain_mut` and sent to the PC, so the record stays at the old state while t.... (inline) 3. **High** `crates/xcl/src/hle/d3d12x/barrier_groups.rs:320`: A legacy transition of one subresource on a plane with more than one subresource always sets that plane to None (unknown), even when the title moves every subresource of the plane one at a time. (inline) 4. **Medium** `crates/xcl/src/hle/d3d12x/barrier_groups.rs:225`: see below. 5. **Medium** `crates/xcl/src/hle/d3d12x/real.rs:4440`: see below. **On lines outside the diff:** 4. **Medium** `crates/xcl/src/hle/d3d12x/barrier_groups.rs:225`: A barrier from UNDEFINED whose plane is unknown (None) sends nothing but still records `Some(after)`, which breaks the rule that a partially moved plane stays unknown until a transition of all of it. After a legacy move of mip 1 only to COPY_DEST (plane 0 None, PC with mip 0 in COMMON and mip 1 in COPY_DEST), a barrier group UNDEFINED -> RT sends nothing and records RT. A following UNDEFINED -> SR then sends RT -> SR with ALL_SUBRESOURCES while the PC texture is in COMMON/COPY_DEST (527). Keeping the plane None when nothing was sent would fix it. 5. **Medium** `crates/xcl/src/hle/d3d12x/real.rs:4440`: Textures made through CreateCommittedResource2 and CreatePlacedResource1 (plain `creator!` hooks, real.rs:4440 and 4610), and any other creation path that doesn't call `note_created`, still aren't seeded, so #3489 remains for them. A render target made with CreateCommittedResource2 in COMMON whose first barrier group is UNDEFINED -> RENDER_TARGET has no record, nothing is sent, and it's drawn into in COMMON (538). --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
bmjask commented 2026-12-02 15:45:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:45:26Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 436

@@ -394,38 +432,43 @@ pub(super) unsafe fn transitions(n: u32, groups: *const c_void, direct: bool) ->
             Some((depth, d.MipLevels as u32, array, planes))
         },
         &mut |res| LAST.get(res).map_or([None, None], |t| t.states),
-        &mut |res, plane, state, stride| {
-            let mut cur = LAST.get(res).unwrap_or_default();
-            cur.states[plane] = Some(state);
-            cur.plane_stride = stride;
-            LAST.insert(res, cur);
-        },
+        // recorded below, once the states are the ones the PC list gets
+        &mut |res, plane, state, stride| moves.push((res, plane, state, stride)),

High: Barrier-group moves are now saved to moves and written to LAST only after the whole call, but transitions_of's last() reads LAST in the middle of the call, so a later barrier on the same texture in the same ResourceBarrier call starts from the state before the call. With a texture recorded in COMMON and one call holding barrier A (RENDER_TARGET -> SHADER_RESOURCE, or UNDEFINED -> COPY_DEST) and then barrier B (UNDEFINED -> UNORDERED_ACCESS) on the same plane, B's prev is still COMMON. The word sent is COMMON -> UAV while the PC texture is in SHADER_RESOURCE/COPY_DEST after A, which is debug layer 527/538. The old code wrote LAST inside moved, and the test helper run still does, so the tests miss it. Keeping a per-call overlay that last() consults first would fix it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772202060 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4772202060). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:45:26Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 436 ~~~~diff @@ -394,38 +432,43 @@ pub(super) unsafe fn transitions(n: u32, groups: *const c_void, direct: bool) -> Some((depth, d.MipLevels as u32, array, planes)) }, &mut |res| LAST.get(res).map_or([None, None], |t| t.states), - &mut |res, plane, state, stride| { - let mut cur = LAST.get(res).unwrap_or_default(); - cur.states[plane] = Some(state); - cur.plane_stride = stride; - LAST.insert(res, cur); - }, + // recorded below, once the states are the ones the PC list gets + &mut |res, plane, state, stride| moves.push((res, plane, state, stride)), ~~~~ --- **High**: Barrier-group moves are now saved to `moves` and written to LAST only after the whole call, but `transitions_of`'s `last()` reads LAST in the middle of the call, so a later barrier on the same texture in the same ResourceBarrier call starts from the state before the call. With a texture recorded in COMMON and one call holding barrier A (RENDER_TARGET -> SHADER_RESOURCE, or UNDEFINED -> COPY_DEST) and then barrier B (UNDEFINED -> UNORDERED_ACCESS) on the same plane, B's `prev` is still COMMON. The word sent is COMMON -> UAV while the PC texture is in SHADER_RESOURCE/COPY_DEST after A, which is debug layer 527/538. The old code wrote LAST inside `moved`, and the test helper `run` still does, so the tests miss it. Keeping a per-call overlay that `last()` consults first would fix it.
bmjask commented 2026-12-02 15:45:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:45:26Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 462

@@ -394,38 +432,43 @@ pub(super) unsafe fn transitions(n: u32, groups: *const c_void, direct: bool) ->
             Some((depth, d.MipLevels as u32, array, planes))
         },
         &mut |res| LAST.get(res).map_or([None, None], |t| t.states),
-        &mut |res, plane, state, stride| {
-            let mut cur = LAST.get(res).unwrap_or_default();
-            cur.states[plane] = Some(state);
-            cur.plane_stride = stride;
-            LAST.insert(res, cur);
-        },
+        // recorded below, once the states are the ones the PC list gets
+        &mut |res, plane, state, stride| moves.push((res, plane, state, stride)),
     );
+    note_discards(&textures, &asked);
+    let mut refused_res: Vec<usize> = Vec::new();
     out.retain_mut(|w| {
         let res = (w[2] as u64 | (w[3] as u64) << 32) as usize;
         let Some(a) = asked.iter().find(|a| a.0 == res).map(|a| a.1) else { return false };
         if w[4] != D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES && w[4] >= a.subresources {
+            refused_res.push(res);
             return refused(w, a, "a subresource the texture does not have");
         }
-        // a depth buffer the PC gave no unordered access (`device_x::pc_resource_desc`) cannot
-        // be in UNORDERED_ACCESS: one `depth_uav` keeps is taken from there by
-        // `depth_uav::plan_barriers`, any other rests where that would park it
-        let depth_only = a.flags & 0x2 != 0 && a.flags & 0x4 == 0;
-        let kept = depth_only && super::depth_uav::kept(res);
         for i in 5..7 {
-            if depth_only && w[i] == UNORDERED_ACCESS {
-                if !kept {
-                    w[i] = super::depth_uav::PARK;
-                }
-                continue;
-            }
-            match legal(w[i], a.flags, direct) {
+            match pc_state(w[i], a.flags, res, direct) {
                 Some(s) => w[i] = s,
-                None => return refused(w, a, if direct { "a state the PC's texture cannot be in" } else { "a state a compute list cannot move a texture to or from" }),
+                None => {
+                    refused_res.push(res);
+                    return refused(w, a, if direct { "a state the PC's texture cannot be in" } else { "a state a compute list cannot move a texture to or from" });
+                }
             }
         }
         w[5] != w[6]
     });
+    // the record follows what the PC list gets: the legal state, and nothing for a texture one of
+    // whose transitions was refused (the PC's texture stays where it was)
+    for (res, plane, state, stride) in moves {
+        let Some(a) = asked.iter().find(|a| a.0 == res).map(|a| a.1) else { continue };
+        if refused_res.contains(&res) {

High: If any one transition of a texture is refused, every move for that texture in the call is dropped, yet its other transitions in the same call are still kept by retain_mut and sent to the PC, so the record stays at the old state while the PC texture has moved. On a compute list, if barrier 1 moves T COMMON -> SHADER_RESOURCE (legal, sent, so the PC is now in 0x40) and barrier 2 moves T's other subresources to a render target (refused), T goes into refused_res and the record stays COMMON. The next barrier from UNDEFINED sends COMMON -> X while the PC is in 0x40 (527). Dropping only the refused transition's move would keep the record in step.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772202068 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4772202068). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:45:26Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 462 ~~~~diff @@ -394,38 +432,43 @@ pub(super) unsafe fn transitions(n: u32, groups: *const c_void, direct: bool) -> Some((depth, d.MipLevels as u32, array, planes)) }, &mut |res| LAST.get(res).map_or([None, None], |t| t.states), - &mut |res, plane, state, stride| { - let mut cur = LAST.get(res).unwrap_or_default(); - cur.states[plane] = Some(state); - cur.plane_stride = stride; - LAST.insert(res, cur); - }, + // recorded below, once the states are the ones the PC list gets + &mut |res, plane, state, stride| moves.push((res, plane, state, stride)), ); + note_discards(&textures, &asked); + let mut refused_res: Vec<usize> = Vec::new(); out.retain_mut(|w| { let res = (w[2] as u64 | (w[3] as u64) << 32) as usize; let Some(a) = asked.iter().find(|a| a.0 == res).map(|a| a.1) else { return false }; if w[4] != D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES && w[4] >= a.subresources { + refused_res.push(res); return refused(w, a, "a subresource the texture does not have"); } - // a depth buffer the PC gave no unordered access (`device_x::pc_resource_desc`) cannot - // be in UNORDERED_ACCESS: one `depth_uav` keeps is taken from there by - // `depth_uav::plan_barriers`, any other rests where that would park it - let depth_only = a.flags & 0x2 != 0 && a.flags & 0x4 == 0; - let kept = depth_only && super::depth_uav::kept(res); for i in 5..7 { - if depth_only && w[i] == UNORDERED_ACCESS { - if !kept { - w[i] = super::depth_uav::PARK; - } - continue; - } - match legal(w[i], a.flags, direct) { + match pc_state(w[i], a.flags, res, direct) { Some(s) => w[i] = s, - None => return refused(w, a, if direct { "a state the PC's texture cannot be in" } else { "a state a compute list cannot move a texture to or from" }), + None => { + refused_res.push(res); + return refused(w, a, if direct { "a state the PC's texture cannot be in" } else { "a state a compute list cannot move a texture to or from" }); + } } } w[5] != w[6] }); + // the record follows what the PC list gets: the legal state, and nothing for a texture one of + // whose transitions was refused (the PC's texture stays where it was) + for (res, plane, state, stride) in moves { + let Some(a) = asked.iter().find(|a| a.0 == res).map(|a| a.1) else { continue }; + if refused_res.contains(&res) { ~~~~ --- **High**: If any one transition of a texture is refused, every move for that texture in the call is dropped, yet its other transitions in the same call are still kept by `retain_mut` and sent to the PC, so the record stays at the old state while the PC texture has moved. On a compute list, if barrier 1 moves T COMMON -> SHADER_RESOURCE (legal, sent, so the PC is now in 0x40) and barrier 2 moves T's other subresources to a render target (refused), T goes into `refused_res` and the record stays COMMON. The next barrier from UNDEFINED sends COMMON -> X while the PC is in 0x40 (527). Dropping only the refused transition's move would keep the record in step.
bmjask commented 2026-12-02 15:45:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:45:26Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 320

@@ -270,37 +272,60 @@ struct Tracked {
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// The per-plane state each texture is in, in the title's recording order: seeded with the PC
+/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions.
+/// A barrier from the undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
+
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { states: [Some(state), Some(state)], plane_stride }
+}
+
+/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether
+/// or not the title has used barrier groups yet: textures made at load (most render targets
+/// and depth buffers) come before its first barrier group. A buffer is not recorded.
+pub(super) fn note_created(res: usize, state: u32) {
+    if res == 0 || !enabled() {
+        return;
+    }
+    let r = res as *mut c_void;
+    let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return };
+    if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER {
+        return;
+    }
+    let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
+    LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1)));
+}
+
 /// Texture barriers read, and transitions made of them.
 static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
 
-/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to
-/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked.
+/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all
+/// subresources sets both planes, and one of a plane's only subresource sets that plane. One of
+/// some of a plane's subresources leaves that plane in no single state: it is no longer known
+/// (a barrier from the undefined layout then moves nothing there, as for an untracked texture)
+/// until a transition of all of it. No-op if the texture is not tracked; under one lock, so a
+/// record `forget` removed is not put back.
 pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) {
-    if COUNTS[0].load(Ordering::Relaxed) == 0 {
-        return;
-    }
-    let Some(mut cur) = LAST.get(res) else { return };
+    LAST.update(res, |cur| *cur = legacy_moved(*cur, sub, after));
+}
+
+fn legacy_moved(mut cur: Tracked, sub: u32, after: u32) -> Tracked {
     if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES {
-        cur.states[0] = Some(after);
-        if cur.states[1].is_some() {
-            cur.states[1] = Some(after);
-        }
+        cur.states = [Some(after), Some(after)];
     } else if cur.plane_stride > 0 {
         let p = (sub / cur.plane_stride) as usize;
         if p < 2 {
-            cur.states[p] = Some(after);
+            cur.states[p] = if cur.plane_stride == 1 { Some(after) } else { None };

High: A legacy transition of one subresource on a plane with more than one subresource always sets that plane to None (unknown), even when the title moves every subresource of the plane one at a time. Before this PR the plane was set to after. In a mip-generation loop that moves mips 0..N-1 one by one to UNORDERED_ACCESS, never ALL_SUBRESOURCES, the plane stays None. The next barrier group UNDEFINED -> RENDER_TARGET then sends nothing (the old code sent UAV -> RT), and the title draws into a texture in UAV: error 538. Tracking which subresources moved, and restoring a known state once all of them share one, would cover it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772202075 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4772202075). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:45:26Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 320 ~~~~diff @@ -270,37 +272,60 @@ struct Tracked { plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// The per-plane state each texture is in, in the title's recording order: seeded with the PC +/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions. +/// A barrier from the undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); + +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { states: [Some(state), Some(state)], plane_stride } +} + +/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether +/// or not the title has used barrier groups yet: textures made at load (most render targets +/// and depth buffers) come before its first barrier group. A buffer is not recorded. +pub(super) fn note_created(res: usize, state: u32) { + if res == 0 || !enabled() { + return; + } + let r = res as *mut c_void; + let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return }; + if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER { + return; + } + let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; + LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1))); +} + /// Texture barriers read, and transitions made of them. static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; -/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to -/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked. +/// A legacy `ResourceBarrier` moves `res`'s subresource `sub` to `after`. A transition of all +/// subresources sets both planes, and one of a plane's only subresource sets that plane. One of +/// some of a plane's subresources leaves that plane in no single state: it is no longer known +/// (a barrier from the undefined layout then moves nothing there, as for an untracked texture) +/// until a transition of all of it. No-op if the texture is not tracked; under one lock, so a +/// record `forget` removed is not put back. pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) { - if COUNTS[0].load(Ordering::Relaxed) == 0 { - return; - } - let Some(mut cur) = LAST.get(res) else { return }; + LAST.update(res, |cur| *cur = legacy_moved(*cur, sub, after)); +} + +fn legacy_moved(mut cur: Tracked, sub: u32, after: u32) -> Tracked { if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES { - cur.states[0] = Some(after); - if cur.states[1].is_some() { - cur.states[1] = Some(after); - } + cur.states = [Some(after), Some(after)]; } else if cur.plane_stride > 0 { let p = (sub / cur.plane_stride) as usize; if p < 2 { - cur.states[p] = Some(after); + cur.states[p] = if cur.plane_stride == 1 { Some(after) } else { None }; ~~~~ --- **High**: A legacy transition of one subresource on a plane with more than one subresource always sets that plane to None (unknown), even when the title moves every subresource of the plane one at a time. Before this PR the plane was set to `after`. In a mip-generation loop that moves mips 0..N-1 one by one to UNORDERED_ACCESS, never ALL_SUBRESOURCES, the plane stays None. The next barrier group UNDEFINED -> RENDER_TARGET then sends nothing (the old code sent UAV -> RT), and the title draws into a texture in UAV: error 538. Tracking which subresources moved, and restoring a known state once all of them share one, would cover it.
afpruivo commented 2026-12-02 16:56:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T16:56:36Z.


@Foniass thank you, the new one was right, and it came from my fix for bmjask's per-plane point.

  • A barrier group's own transitions wiped the record it had just written: right. Fixed in the one commit, now b948e19d (force-pushed; description updated). resource_barrier_x now collects a call's transitions and records them together (barrier_groups::note_legacy_states): one of all subresources sets both planes; a plane is set when the call moves every subresource of it to one state; only a real partial move (some subresources, or several states) leaves it unknown. So a group's one-word-per-subresource move of a whole plane keeps the state the group recorded, and a title that moves each level of a plane in one call gets a known state too. The WARP test now has your case: a 2-level D24S8 texture, a depth-plane barrier group from the undefined layout (two words), those words recorded as resource_barrier_x records them, then a second group from the undefined layout: it sends DEPTH_WRITE → SHADER_RESOURCE for both levels; with the per-word rule of 7c10aff7 it sent nothing. a_legacy_move_of_some_subresources_then_of_all_leaves_a_known_state has the all-levels and split-states cases.
  • Discard diagnostic bundled in: agreed that it is its own change. I will take it out into a separate PR after this round, so this one is only the record.
  • Default-path cost: still not measured beyond the smoke run (one shard lock per texture per ResourceBarrier call, one GetDesc and insert per texture made). Listed under Not tested.

Tested on b948e19d: cargo test --workspace --no-fail-fast -- --test-threads=4 2904 passed, 0 failed, 51 ignored, 26 SKIPPED (with Windows' own D3D12, as in the description); smoke pair in the description.

AI use: checked and fixed with Claude Code (Claude Opus 5.5), checked by me.

<!-- greyfinch-sync:ivall/xcl:comment:7352677299 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7352677299). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T16:56:36Z. --- @Foniass thank you, the new one was right, and it came from my fix for bmjask's per-plane point. - **A barrier group's own transitions wiped the record it had just written:** right. Fixed in the one commit, now `b948e19d` (force-pushed; description updated). `resource_barrier_x` now collects a call's transitions and records them together (`barrier_groups::note_legacy_states`): one of all subresources sets both planes; a plane is set when the call moves every subresource of it to one state; only a real partial move (some subresources, or several states) leaves it unknown. So a group's one-word-per-subresource move of a whole plane keeps the state the group recorded, and a title that moves each level of a plane in one call gets a known state too. The WARP test now has your case: a 2-level D24S8 texture, a depth-plane barrier group from the undefined layout (two words), those words recorded as `resource_barrier_x` records them, then a second group from the undefined layout: it sends `DEPTH_WRITE → SHADER_RESOURCE` for both levels; with the per-word rule of `7c10aff7` it sent nothing. `a_legacy_move_of_some_subresources_then_of_all_leaves_a_known_state` has the all-levels and split-states cases. - **Discard diagnostic bundled in:** agreed that it is its own change. I will take it out into a separate PR after this round, so this one is only the record. - **Default-path cost:** still not measured beyond the smoke run (one shard lock per texture per `ResourceBarrier` call, one `GetDesc` and insert per texture made). Listed under **Not tested**. Tested on `b948e19d`: `cargo test --workspace --no-fail-fast -- --test-threads=4` 2904 passed, 0 failed, 51 ignored, 26 SKIPPED (with Windows' own D3D12, as in the description); smoke pair in the description. AI use: checked and fixed with Claude Code (Claude Opus 5.5), checked by me.
Foniass commented 2026-12-02 16:58:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T16:58:15Z.


Follow-up review (head b948e19d, since 7c10aff7, diff read, not a merge-check):

  • A barrier group's own transitions wiped the record it just wrote: fixed. resource_barrier_x now collects a call's transitions and records them together (note_legacy_states, list_x.rs ~6455), and legacy_moved (barrier_groups.rs ~324-343) sets a plane when the call moves every subresource of it to one state, so a group's per-level words for a whole plane leave it known. The WARP test now sends a 2-level D24S8 depth-plane group through that path and checks the next barrier from the undefined layout starts at DEPTH_WRITE, and the unit test covers the mixed-state case.
  • Discard diagnostic bundled in; default-path cost unmeasured; real creation hooks untested: unchanged.

New: none.

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

<!-- greyfinch-sync:ivall/xcl:comment:7352715396 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7352715396). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T16:58:15Z. --- Follow-up review (head b948e19d, since 7c10aff7, diff read, not a merge-check): - **A barrier group's own transitions wiped the record it just wrote:** fixed. `resource_barrier_x` now collects a call's transitions and records them together (`note_legacy_states`, `list_x.rs` ~6455), and `legacy_moved` (`barrier_groups.rs` ~324-343) sets a plane when the call moves every subresource of it to one state, so a group's per-level words for a whole plane leave it known. The WARP test now sends a 2-level D24S8 depth-plane group through that path and checks the next barrier from the undefined layout starts at `DEPTH_WRITE`, and the unit test covers the mixed-state case. - **Discard diagnostic bundled in; default-path cost unmeasured; real creation hooks untested:** unchanged. New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
bmjask commented 2026-12-02 17:24:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T17:24:16Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 337

@@ -270,37 +272,80 @@ struct Tracked {
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// The per-plane state each texture is in, in the title's recording order: seeded with the PC
+/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions.
+/// A barrier from the undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
-/// Texture barriers read, and transitions made of them.
-static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
 
-/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to
-/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked.
-pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) {
-    if COUNTS[0].load(Ordering::Relaxed) == 0 {
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { states: [Some(state), Some(state)], plane_stride }
+}
+
+/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether
+/// or not the title has used barrier groups yet: textures made at load (most render targets
+/// and depth buffers) come before its first barrier group. A buffer is not recorded.
+pub(super) fn note_created(res: usize, state: u32) {
+    if res == 0 || !enabled() {
         return;
     }
-    let Some(mut cur) = LAST.get(res) else { return };
-    if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES {
-        cur.states[0] = Some(after);
-        if cur.states[1].is_some() {
-            cur.states[1] = Some(after);
+    let r = res as *mut c_void;
+    let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return };
+    if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER {
+        return;
+    }
+    let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
+    LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1)));
+}
+
+/// Texture barriers read, and transitions made of them.
+static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
+
+/// The transitions `(texture, subresource, after)` of one `ResourceBarrier` call, in order: the
+/// title's own, and the ones `transitions` makes of a barrier group (one per subresource when it
+/// names some of them). Each tracked texture's record moves by `legacy_moved`; untracked ones
+/// are left alone. Under one lock per texture, so a record `forget` removed is not put back.
+pub(super) fn note_legacy_states(moved: &[(usize, u32, u32)]) {
+    let mut done: Vec<usize> = Vec::new();
+    for &(res, ..) in moved {
+        if done.contains(&res) {
+            continue;
         }
-    } else if cur.plane_stride > 0 {
-        let p = (sub / cur.plane_stride) as usize;
-        if p < 2 {
-            cur.states[p] = Some(after);
+        done.push(res);
+        let mine: Vec<(u32, u32)> = moved.iter().filter(|m| m.0 == res).map(|m| (m.1, m.2)).collect();
+        LAST.update(res, |cur| *cur = legacy_moved(*cur, &mine));
+    }
+}
+
+/// `cur` after one call's transitions `(subresource, after)` of a texture. One of all
+/// subresources sets both planes. The ones of single subresources set a plane when the call
+/// moves every subresource of that plane to one state; otherwise the plane is in no single state
+/// and is no longer known (a barrier from the undefined layout then moves nothing there, as for
+/// an untracked texture) until a transition of all of it.
+fn legacy_moved(mut cur: Tracked, moved: &[(u32, u32)]) -> Tracked {
+    let mut some: [Vec<(u32, u32)>; 2] = [Vec::new(), Vec::new()];
+    for &(sub, after) in moved {
+        if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES {
+            cur.states = [Some(after), Some(after)];
+            some = [Vec::new(), Vec::new()];
+        } else if cur.plane_stride > 0 && ((sub / cur.plane_stride) as usize) < 2 {
+            some[(sub / cur.plane_stride) as usize].push((sub, after));
         }
     }
-    LAST.insert(res, cur);
+    for p in 0..2 {
+        let Some(&(_, last)) = some[p].last() else { continue };
+        let mut subs: Vec<u32> = some[p].iter().map(|m| m.0).collect();

High: legacy_moved's whole-plane test requires every entry for the plane to have the final after state, rather than checking each subresource's last state, so two transitions of the same subresource in one call make the plane unknown even though it ends wholly in one state. A 1-mip texture (plane_stride 1) given ResourceBarrier with sub 0 COMMON->COPY_DEST and then sub 0 COPY_DEST->SHADER_RESOURCE (or a BEGIN_ONLY/END_ONLY pair) in one call gets some[0] = [(0,COPY_DEST),(0,SHADER_RESOURCE)], all(m.1 == last) is false, and plane 0 becomes None. The next UNDEFINED->RENDER_TARGET then sends nothing and the texture stays in SHADER_RESOURCE (538). Keeping only each subresource's last state before the test would fix it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4773396609 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4773396609). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T17:24:16Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 337 ~~~~diff @@ -270,37 +272,80 @@ struct Tracked { plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// The per-plane state each texture is in, in the title's recording order: seeded with the PC +/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions. +/// A barrier from the undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); -/// Texture barriers read, and transitions made of them. -static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; -/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to -/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked. -pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) { - if COUNTS[0].load(Ordering::Relaxed) == 0 { +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { states: [Some(state), Some(state)], plane_stride } +} + +/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether +/// or not the title has used barrier groups yet: textures made at load (most render targets +/// and depth buffers) come before its first barrier group. A buffer is not recorded. +pub(super) fn note_created(res: usize, state: u32) { + if res == 0 || !enabled() { return; } - let Some(mut cur) = LAST.get(res) else { return }; - if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES { - cur.states[0] = Some(after); - if cur.states[1].is_some() { - cur.states[1] = Some(after); + let r = res as *mut c_void; + let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return }; + if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER { + return; + } + let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; + LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1))); +} + +/// Texture barriers read, and transitions made of them. +static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; + +/// The transitions `(texture, subresource, after)` of one `ResourceBarrier` call, in order: the +/// title's own, and the ones `transitions` makes of a barrier group (one per subresource when it +/// names some of them). Each tracked texture's record moves by `legacy_moved`; untracked ones +/// are left alone. Under one lock per texture, so a record `forget` removed is not put back. +pub(super) fn note_legacy_states(moved: &[(usize, u32, u32)]) { + let mut done: Vec<usize> = Vec::new(); + for &(res, ..) in moved { + if done.contains(&res) { + continue; } - } else if cur.plane_stride > 0 { - let p = (sub / cur.plane_stride) as usize; - if p < 2 { - cur.states[p] = Some(after); + done.push(res); + let mine: Vec<(u32, u32)> = moved.iter().filter(|m| m.0 == res).map(|m| (m.1, m.2)).collect(); + LAST.update(res, |cur| *cur = legacy_moved(*cur, &mine)); + } +} + +/// `cur` after one call's transitions `(subresource, after)` of a texture. One of all +/// subresources sets both planes. The ones of single subresources set a plane when the call +/// moves every subresource of that plane to one state; otherwise the plane is in no single state +/// and is no longer known (a barrier from the undefined layout then moves nothing there, as for +/// an untracked texture) until a transition of all of it. +fn legacy_moved(mut cur: Tracked, moved: &[(u32, u32)]) -> Tracked { + let mut some: [Vec<(u32, u32)>; 2] = [Vec::new(), Vec::new()]; + for &(sub, after) in moved { + if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES { + cur.states = [Some(after), Some(after)]; + some = [Vec::new(), Vec::new()]; + } else if cur.plane_stride > 0 && ((sub / cur.plane_stride) as usize) < 2 { + some[(sub / cur.plane_stride) as usize].push((sub, after)); } } - LAST.insert(res, cur); + for p in 0..2 { + let Some(&(_, last)) = some[p].last() else { continue }; + let mut subs: Vec<u32> = some[p].iter().map(|m| m.0).collect(); ~~~~ --- **High**: `legacy_moved`'s whole-plane test requires every entry for the plane to have the final after state, rather than checking each subresource's last state, so two transitions of the same subresource in one call make the plane unknown even though it ends wholly in one state. A 1-mip texture (plane_stride 1) given ResourceBarrier with sub 0 COMMON->COPY_DEST and then sub 0 COPY_DEST->SHADER_RESOURCE (or a BEGIN_ONLY/END_ONLY pair) in one call gets `some[0] = [(0,COPY_DEST),(0,SHADER_RESOURCE)]`, `all(m.1 == last)` is false, and plane 0 becomes None. The next UNDEFINED->RENDER_TARGET then sends nothing and the texture stays in SHADER_RESOURCE (538). Keeping only each subresource's last state before the test would fix it.
bmjask commented 2026-12-02 17:24:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T17:24:16Z.

Review: COMMENTED


Review of b948e19d: 1 finding(s) (1 high), most severe first.

Re-review at b948e19d. The points from my last review all look still open at this head: moves recorded only after the call (a later barrier in the same call starts from the old state, barrier_groups.rs ~456), one refused transition dropping every move of the texture (~482), a plane moved one subresource at a time staying unknown so the next UNDEFINED barrier sends nothing (~341, error 538), an UNDEFINED barrier on an unknown plane recording a state it never sent (~228), and CreateCommittedResource1/2 / CreatePlacedResource1 still not recorded (real.rs ~4439, ~4610). One new case:

  1. High crates/xcl/src/hle/d3d12x/barrier_groups.rs:337: legacy_moved's whole-plane test requires every entry for the plane to have the final after state, rather than checking each subresource's last state, so two transitions of the same subresource in one call make the plane unknown even th.... (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6155752791 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#pullrequestreview-6155752791). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T17:24:16Z. **Review:** COMMENTED --- Review of `b948e19d`: 1 finding(s) (1 high), most severe first. Re-review at `b948e19d`. The points from my last review all look still open at this head: moves recorded only after the call (a later barrier in the same call starts from the old state, `barrier_groups.rs` ~456), one refused transition dropping every move of the texture (~482), a plane moved one subresource at a time staying unknown so the next UNDEFINED barrier sends nothing (~341, error 538), an UNDEFINED barrier on an unknown plane recording a state it never sent (~228), and CreateCommittedResource1/2 / CreatePlacedResource1 still not recorded (`real.rs` ~4439, ~4610). One new case: 1. **High** `crates/xcl/src/hle/d3d12x/barrier_groups.rs:337`: `legacy_moved`'s whole-plane test requires every entry for the plane to have the final after state, rather than checking each subresource's last state, so two transitions of the same subresource in one call make the plane unknown even th.... (inline) --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
afpruivo commented 2026-12-02 23:02:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T23:02:21Z.


@bmjask @Foniass thank you both. I checked each point of bmjask's review of b948e19d against the code; all six were right. They share a cause: the record held one state per plane, so any move of part of a plane had no good answer. It now holds a state per subresource where a plane's subresources differ, so the fixes are one change. It is in the one commit, now 504f4e14, rebased onto main c53e9696 (force-pushed; description updated).

  • Moves recorded only after the call, so a later barrier in the same call started from the old state (barrier_groups.rs ~456): right. transitions_of's last now sees the call's moves so far (the record with the moves noted before it applied), so UNDEFINED→RENDER_TARGET then UNDEFINED→SHADER_RESOURCE in one call sends COMMON→RT, then RT→SR. Test: a_barrier_starts_where_the_one_before_it_in_the_same_call_left_the_texture.
  • One refused transition dropped every move of the texture (~482): right. Only the moves a refused word stands for are dropped (same texture and subresource, or all of them for an ALL_SUBRESOURCES word), and a move whose state after the PC refuses is never noted. WARP test: on a compute list, level 0 to RENDER_TARGET (refused) and level 1 to SHADER_RESOURCE in one group; the next group sends 0: COMMON→RT and 1: 0x40→RT.
  • A plane moved one subresource at a time stayed unknown (~341, 538): right. A plane is now All(state), Each([state per subresource]) or Unknown; a move of one subresource makes an All plane Each, and a plane whose subresources are in one state again is All again. A barrier from the undefined layout starts each subresource from its own state. WARP test: a legacy move of level 1 to COPY_DEST, then a group UNDEFINED→RT sends 0: COMMON→RT, 1: COPY_DEST→RT; the group after it is one ALL_SUBRESOURCES word again.
  • A barrier from the undefined layout on an unknown plane recorded a state it never sent (~228): right. A subresource whose state is not known sends nothing and records nothing, so the record holds only states the PC's texture was moved to. (A texture is unknown only if XCL saw no creation of it, or a part of a plane moved while it was unknown.)
  • CreateCommittedResource1/2 and CreatePlacedResource1 not recorded (real.rs ~4439, ~4610): right. The creator! wrapper records them from their fourth argument, the initial state. Not covered by a test (they are pass-throughs of the PC's own methods).
  • Two moves of the same subresource in one call left the plane unknown (new, ~337): right. Moves are applied in order, so the last one counts. Unit test: each_subresource_keeps_its_own_state_until_a_plane_is_in_one_again.

@Foniass, as promised: the discard diagnostic is out of this PR (Texture.flags, FROM_UNDEFINED, note_discards and its info lines). It will be its own PR once this one is settled. Default-path cost: unchanged in kind (one shard lock per tracked texture per ResourceBarrier call, one GetDesc and insert per texture made; a plane whose subresources differ now keeps a small array). Still not measured beyond the smoke run, as Not tested says.

Tested: cargo test --workspace --no-fail-fast -- --test-threads=4 3009 passed, 0 failed, 52 ignored, 26 SKIPPED (with Windows' own D3D12, as in the description; on e671f910, the same tree as 504f4e14); smoke pair against main c53e9696 in the description (1592 vs 1573 frames, peak commit 17151 vs 15794 MB, no removals or crashes).

AI use: checked and fixed with Claude Code (Claude Opus 5.5) while I was away; posted by it under my account with my standing approval for this session.

<!-- greyfinch-sync:ivall/xcl:comment:7361484880 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7361484880). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T23:02:21Z. --- @bmjask @Foniass thank you both. I checked each point of bmjask's review of `b948e19d` against the code; all six were right. They share a cause: the record held one state per plane, so any move of part of a plane had no good answer. It now holds a state per subresource where a plane's subresources differ, so the fixes are one change. It is in the one commit, now `504f4e14`, rebased onto `main` `c53e9696` (force-pushed; description updated). - **Moves recorded only after the call, so a later barrier in the same call started from the old state** (`barrier_groups.rs` ~456): right. `transitions_of`'s `last` now sees the call's moves so far (the record with the moves noted before it applied), so `UNDEFINED→RENDER_TARGET` then `UNDEFINED→SHADER_RESOURCE` in one call sends `COMMON→RT`, then `RT→SR`. Test: `a_barrier_starts_where_the_one_before_it_in_the_same_call_left_the_texture`. - **One refused transition dropped every move of the texture** (~482): right. Only the moves a refused word stands for are dropped (same texture and subresource, or all of them for an `ALL_SUBRESOURCES` word), and a move whose state after the PC refuses is never noted. WARP test: on a compute list, level 0 to RENDER_TARGET (refused) and level 1 to SHADER_RESOURCE in one group; the next group sends `0: COMMON→RT` and `1: 0x40→RT`. - **A plane moved one subresource at a time stayed unknown** (~341, 538): right. A plane is now `All(state)`, `Each([state per subresource])` or `Unknown`; a move of one subresource makes an `All` plane `Each`, and a plane whose subresources are in one state again is `All` again. A barrier from the undefined layout starts each subresource from its own state. WARP test: a legacy move of level 1 to COPY_DEST, then a group `UNDEFINED→RT` sends `0: COMMON→RT`, `1: COPY_DEST→RT`; the group after it is one `ALL_SUBRESOURCES` word again. - **A barrier from the undefined layout on an unknown plane recorded a state it never sent** (~228): right. A subresource whose state is not known sends nothing and records nothing, so the record holds only states the PC's texture was moved to. (A texture is unknown only if XCL saw no creation of it, or a part of a plane moved while it was unknown.) - **`CreateCommittedResource1`/`2` and `CreatePlacedResource1` not recorded** (`real.rs` ~4439, ~4610): right. The `creator!` wrapper records them from their fourth argument, the initial state. Not covered by a test (they are pass-throughs of the PC's own methods). - **Two moves of the same subresource in one call left the plane unknown** (new, ~337): right. Moves are applied in order, so the last one counts. Unit test: `each_subresource_keeps_its_own_state_until_a_plane_is_in_one_again`. @Foniass, as promised: **the discard diagnostic is out of this PR** (`Texture.flags`, `FROM_UNDEFINED`, `note_discards` and its info lines). It will be its own PR once this one is settled. **Default-path cost**: unchanged in kind (one shard lock per tracked texture per `ResourceBarrier` call, one `GetDesc` and insert per texture made; a plane whose subresources differ now keeps a small array). Still not measured beyond the smoke run, as **Not tested** says. Tested: `cargo test --workspace --no-fail-fast -- --test-threads=4` 3009 passed, 0 failed, 52 ignored, 26 SKIPPED (with Windows' own D3D12, as in the description; on `e671f910`, the same tree as `504f4e14`); smoke pair against `main` `c53e9696` in the description (1592 vs 1573 frames, peak commit 17151 vs 15794 MB, no removals or crashes). AI use: checked and fixed with Claude Code (Claude Opus 5.5) while I was away; posted by it under my account with my standing approval for this session.
afpruivo commented 2026-12-02 23:02:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T23:02:28Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 337

@@ -270,37 +272,80 @@ struct Tracked {
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// The per-plane state each texture is in, in the title's recording order: seeded with the PC
+/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions.
+/// A barrier from the undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
-/// Texture barriers read, and transitions made of them.
-static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
 
-/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to
-/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked.
-pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) {
-    if COUNTS[0].load(Ordering::Relaxed) == 0 {
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { states: [Some(state), Some(state)], plane_stride }
+}
+
+/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether
+/// or not the title has used barrier groups yet: textures made at load (most render targets
+/// and depth buffers) come before its first barrier group. A buffer is not recorded.
+pub(super) fn note_created(res: usize, state: u32) {
+    if res == 0 || !enabled() {
         return;
     }
-    let Some(mut cur) = LAST.get(res) else { return };
-    if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES {
-        cur.states[0] = Some(after);
-        if cur.states[1].is_some() {
-            cur.states[1] = Some(after);
+    let r = res as *mut c_void;
+    let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return };
+    if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER {
+        return;
+    }
+    let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
+    LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1)));
+}
+
+/// Texture barriers read, and transitions made of them.
+static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
+
+/// The transitions `(texture, subresource, after)` of one `ResourceBarrier` call, in order: the
+/// title's own, and the ones `transitions` makes of a barrier group (one per subresource when it
+/// names some of them). Each tracked texture's record moves by `legacy_moved`; untracked ones
+/// are left alone. Under one lock per texture, so a record `forget` removed is not put back.
+pub(super) fn note_legacy_states(moved: &[(usize, u32, u32)]) {
+    let mut done: Vec<usize> = Vec::new();
+    for &(res, ..) in moved {
+        if done.contains(&res) {
+            continue;
         }
-    } else if cur.plane_stride > 0 {
-        let p = (sub / cur.plane_stride) as usize;
-        if p < 2 {
-            cur.states[p] = Some(after);
+        done.push(res);
+        let mine: Vec<(u32, u32)> = moved.iter().filter(|m| m.0 == res).map(|m| (m.1, m.2)).collect();
+        LAST.update(res, |cur| *cur = legacy_moved(*cur, &mine));
+    }
+}
+
+/// `cur` after one call's transitions `(subresource, after)` of a texture. One of all
+/// subresources sets both planes. The ones of single subresources set a plane when the call
+/// moves every subresource of that plane to one state; otherwise the plane is in no single state
+/// and is no longer known (a barrier from the undefined layout then moves nothing there, as for
+/// an untracked texture) until a transition of all of it.
+fn legacy_moved(mut cur: Tracked, moved: &[(u32, u32)]) -> Tracked {
+    let mut some: [Vec<(u32, u32)>; 2] = [Vec::new(), Vec::new()];
+    for &(sub, after) in moved {
+        if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES {
+            cur.states = [Some(after), Some(after)];
+            some = [Vec::new(), Vec::new()];
+        } else if cur.plane_stride > 0 && ((sub / cur.plane_stride) as usize) < 2 {
+            some[(sub / cur.plane_stride) as usize].push((sub, after));
         }
     }
-    LAST.insert(res, cur);
+    for p in 0..2 {
+        let Some(&(_, last)) = some[p].last() else { continue };
+        let mut subs: Vec<u32> = some[p].iter().map(|m| m.0).collect();

Right, fixed in 504f4e14: moves are applied in order per subresource (apply), so the last state of each subresource counts and a 1-level texture moved COMMON→COPY_DEST→SHADER_RESOURCE in one call ends in SHADER_RESOURCE (unit test each_subresource_keeps_its_own_state_until_a_plane_is_in_one_again). Details in the reply on the PR. (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ivall/xcl:review-comment:4777360547 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4777360547). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T23:02:28Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 337 ~~~~diff @@ -270,37 +272,80 @@ struct Tracked { plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// The per-plane state each texture is in, in the title's recording order: seeded with the PC +/// state it was made in (`note_created`), then moved by barrier groups and legacy transitions. +/// A barrier from the undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); -/// Texture barriers read, and transitions made of them. -static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; -/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to -/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked. -pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) { - if COUNTS[0].load(Ordering::Relaxed) == 0 { +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { states: [Some(state), Some(state)], plane_stride } +} + +/// `res` was made in the PC state `state` (`depth_uav::note_created`'s callers). Recorded whether +/// or not the title has used barrier groups yet: textures made at load (most render targets +/// and depth buffers) come before its first barrier group. A buffer is not recorded. +pub(super) fn note_created(res: usize, state: u32) { + if res == 0 || !enabled() { return; } - let Some(mut cur) = LAST.get(res) else { return }; - if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES { - cur.states[0] = Some(after); - if cur.states[1].is_some() { - cur.states[1] = Some(after); + let r = res as *mut c_void; + let Some(d) = (unsafe { ID3D12Resource::from_raw_borrowed(&r) }).map(|r| unsafe { r.GetDesc() }) else { return }; + if d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER { + return; + } + let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; + LAST.insert(res, created(state, (d.MipLevels as u32).max(1) * array.max(1))); +} + +/// Texture barriers read, and transitions made of them. +static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; + +/// The transitions `(texture, subresource, after)` of one `ResourceBarrier` call, in order: the +/// title's own, and the ones `transitions` makes of a barrier group (one per subresource when it +/// names some of them). Each tracked texture's record moves by `legacy_moved`; untracked ones +/// are left alone. Under one lock per texture, so a record `forget` removed is not put back. +pub(super) fn note_legacy_states(moved: &[(usize, u32, u32)]) { + let mut done: Vec<usize> = Vec::new(); + for &(res, ..) in moved { + if done.contains(&res) { + continue; } - } else if cur.plane_stride > 0 { - let p = (sub / cur.plane_stride) as usize; - if p < 2 { - cur.states[p] = Some(after); + done.push(res); + let mine: Vec<(u32, u32)> = moved.iter().filter(|m| m.0 == res).map(|m| (m.1, m.2)).collect(); + LAST.update(res, |cur| *cur = legacy_moved(*cur, &mine)); + } +} + +/// `cur` after one call's transitions `(subresource, after)` of a texture. One of all +/// subresources sets both planes. The ones of single subresources set a plane when the call +/// moves every subresource of that plane to one state; otherwise the plane is in no single state +/// and is no longer known (a barrier from the undefined layout then moves nothing there, as for +/// an untracked texture) until a transition of all of it. +fn legacy_moved(mut cur: Tracked, moved: &[(u32, u32)]) -> Tracked { + let mut some: [Vec<(u32, u32)>; 2] = [Vec::new(), Vec::new()]; + for &(sub, after) in moved { + if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES { + cur.states = [Some(after), Some(after)]; + some = [Vec::new(), Vec::new()]; + } else if cur.plane_stride > 0 && ((sub / cur.plane_stride) as usize) < 2 { + some[(sub / cur.plane_stride) as usize].push((sub, after)); } } - LAST.insert(res, cur); + for p in 0..2 { + let Some(&(_, last)) = some[p].last() else { continue }; + let mut subs: Vec<u32> = some[p].iter().map(|m| m.0).collect(); ~~~~ --- Right, fixed in `504f4e14`: moves are applied in order per subresource (`apply`), so the last state of each subresource counts and a 1-level texture moved COMMON→COPY_DEST→SHADER_RESOURCE in one call ends in SHADER_RESOURCE (unit test `each_subresource_keeps_its_own_state_until_a_plane_is_in_one_again`). Details in the reply on the PR. (Claude Code, Claude Opus 5.5)
Foniass commented 2026-12-02 23:09:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:09:52Z.


Follow-up review of 504f4e14, since b948e19d (code reading only, not a merge-check) · 1 high, 1 medium

In short: Since b948e19d the PR was rebased onto c53e9696 and its record rewritten:

  • each plane holds one state, a state per subresource (Plane::Each), or unknown;
  • a barrier starts where the earlier barriers in the same call left the texture;
  • a refused transition drops only the moves of its own subresources;
  • an untracked texture leaving the undefined layout gets no record;
  • CreateCommittedResource1 / 2 and CreatePlacedResource1 are recorded;
  • the discard diagnostic is gone.

One new problem: a split barrier from the undefined layout now sends a begin half with no end half on a texture's first move.

High

  1. A split barrier from the undefined layout sends BEGIN_ONLY and never END_ONLY.

    • In transitions_of (barrier_groups.rs ~203-233), the begin half (SyncAfter = SYNC_SPLIT) starts from the record, which is now the creation state, for example COMMON. It sends COMMON -> RENDER_TARGET with BEGIN_ONLY and records the move through moved (~496).
    • The end half carries the same UNDEFINED -> RENDER_TARGET layouts. It reads the record, now RENDER_TARGET, finds s == a (~211) or before == a (~230), and sends nothing.
    • The PC list gets a begin with no end, so the texture is left mid-transition while the title draws into it: the #3489 case again. On main an untracked texture got neither half.
    • the_halves_of_a_split_barrier_are_the_pcs_begin_and_end only covers explicit before-layouts.

    Fix: record a split move from the undefined layout on its END_ONLY half, not its BEGIN_ONLY half, so both halves start from the same state. Add a test of a split barrier from the undefined layout on a created texture.

Medium

  1. The real creation hooks are still untested (still open). The WARP test calls note_created directly. A wrong state or a missed record at real.rs ~3856, ~3931, ~4367 (the new creator! hook), ~4494, ~4534, ~4575, ~4672, or at device_x.rs ~1293, ~1317, ~1336, would not be caught. Not tested says so.
Checked and fine
  • Earlier finding fixed: the discard diagnostic (Texture.flags, FROM_UNDEFINED, note_discards) is gone.
  • Earlier finding fixed: the cost of recording every texture is now stated under Not tested.
  • Recording a group's moves in transitions, and again when its words pass through resource_barrier_x, gives the same record, since each move sets an absolute state.
  • Plane::Each is indexed by sub % stride, with the stride from GetDesc at creation. A plane goes back to All when its subresources agree.
  • Sharded::update creates no record, so a legacy transition cannot undo forget. Tested.
  • A refused move drops only its own subresource's moves, or the whole texture's for an ALL word. The two-level compute-list case is tested.
  • Within one call, a barrier starts where the earlier ones left the texture. Tested.
  • The new creator! hook reads the fourth argument as the initial state, which is right for all three methods.
  • #3558 and #3599 take other approaches; neither duplicates this.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7361644384 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7361644384). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T23:09:52Z. --- **Follow-up review** of `504f4e14`, since `b948e19d` (code reading only, not a merge-check) · 1 high, 1 medium **In short:** Since `b948e19d` the PR was rebased onto `c53e9696` and its record rewritten: - each plane holds one state, a state per subresource (`Plane::Each`), or unknown; - a barrier starts where the earlier barriers in the same call left the texture; - a refused transition drops only the moves of its own subresources; - an untracked texture leaving the undefined layout gets no record; - `CreateCommittedResource1` / `2` and `CreatePlacedResource1` are recorded; - the discard diagnostic is gone. One new problem: a split barrier from the undefined layout now sends a begin half with no end half on a texture's first move. #### High 1. **A split barrier from the undefined layout sends `BEGIN_ONLY` and never `END_ONLY`.** - In `transitions_of` (`barrier_groups.rs` ~203-233), the begin half (`SyncAfter` = `SYNC_SPLIT`) starts from the record, which is now the creation state, for example `COMMON`. It sends `COMMON -> RENDER_TARGET` with `BEGIN_ONLY` and records the move through `moved` (~496). - The end half carries the same `UNDEFINED -> RENDER_TARGET` layouts. It reads the record, now `RENDER_TARGET`, finds `s == a` (~211) or `before == a` (~230), and sends nothing. - The PC list gets a begin with no end, so the texture is left mid-transition while the title draws into it: the #3489 case again. On `main` an untracked texture got neither half. - `the_halves_of_a_split_barrier_are_the_pcs_begin_and_end` only covers explicit before-layouts. Fix: record a split move from the undefined layout on its `END_ONLY` half, not its `BEGIN_ONLY` half, so both halves start from the same state. Add a test of a split barrier from the undefined layout on a created texture. #### Medium 2. **The real creation hooks are still untested (still open).** The WARP test calls `note_created` directly. A wrong state or a missed record at `real.rs` ~3856, ~3931, ~4367 (the new `creator!` hook), ~4494, ~4534, ~4575, ~4672, or at `device_x.rs` ~1293, ~1317, ~1336, would not be caught. **Not tested** says so. <details><summary>Checked and fine</summary> - Earlier finding fixed: the discard diagnostic (`Texture.flags`, `FROM_UNDEFINED`, `note_discards`) is gone. - Earlier finding fixed: the cost of recording every texture is now stated under **Not tested**. - Recording a group's moves in `transitions`, and again when its words pass through `resource_barrier_x`, gives the same record, since each move sets an absolute state. - `Plane::Each` is indexed by `sub % stride`, with the stride from `GetDesc` at creation. A plane goes back to `All` when its subresources agree. - `Sharded::update` creates no record, so a legacy transition cannot undo `forget`. Tested. - A refused move drops only its own subresource's moves, or the whole texture's for an `ALL` word. The two-level compute-list case is tested. - Within one call, a barrier starts where the earlier ones left the texture. Tested. - The new `creator!` hook reads the fourth argument as the initial state, which is right for all three methods. - #3558 and #3599 take other approaches; neither duplicates this. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
bmjask commented 2026-12-02 23:13:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T23:13:42Z.

Review: COMMENTED


Review of 504f4e14: 2 finding(s) (2 high), most severe first.

  1. High crates/xcl/src/hle/d3d12x/barrier_groups.rs:276: apply leaves a Plane::Unknown plane unknown after a move of one of its subresources, even when the plane has only that subresource (stride == 1) or when the moves together cover the whole plane, whereas the old code recorded a per-pl.... (inline)
  2. High crates/xcl/src/hle/d3d12x/barrier_groups.rs:486: The refused-move filter removes every move in the call for the same texture and subresource, plus any ALL move of that texture (r.1 == ALL || m.1 == ALL), including moves from earlier barriers whose words were sent to the PC. (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6160725595 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#pullrequestreview-6160725595). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T23:13:42Z. **Review:** COMMENTED --- Review of `504f4e14`: 2 finding(s) (2 high), most severe first. 1. **High** `crates/xcl/src/hle/d3d12x/barrier_groups.rs:276`: `apply` leaves a `Plane::Unknown` plane unknown after a move of one of its subresources, even when the plane has only that subresource (stride == 1) or when the moves together cover the whole plane, whereas the old code recorded a per-pl.... (inline) 2. **High** `crates/xcl/src/hle/d3d12x/barrier_groups.rs:486`: The refused-move filter removes every move in the call for the same texture and subresource, plus any ALL move of that texture (`r.1 == ALL || m.1 == ALL`), including moves from earlier barriers whose words were sent to the PC. (inline) --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
bmjask commented 2026-12-02 23:13:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T23:13:42Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 276

@@ -263,44 +243,94 @@ fn unknown_layout(layout: (u32, u32)) {
     }
 }
 
-/// Per-resource tracked states (plane 0 = colour/depth, plane 1 = stencil) and plane subresource stride.
-#[derive(Clone, Copy, Default)]
+/// Where a texture's planes are, and how many subresources a plane has (levels × slices).
+#[derive(Clone, Default)]
 struct Tracked {
-    states: PlaneStates,
+    planes: [Plane; 2],
     plane_stride: u32,
 }
 
-/// The per-plane state each texture was last moved to by a barrier group (the title's recording order).
+/// Where each texture is, in the title's recording order: seeded with the PC state it was made
+/// in (`note_created`), then moved by barrier groups and legacy transitions. A barrier from the
+/// undefined layout starts there.
 static LAST: Sharded<Tracked> = Sharded::new();
-/// Texture barriers read, and transitions made of them.
-static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2];
 
-/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to
-/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked.
-pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) {
-    if COUNTS[0].load(Ordering::Relaxed) == 0 {
-        return;
+/// The record a texture made in the PC state `state` starts with: both planes there.
+fn created(state: u32, plane_stride: u32) -> Tracked {
+    Tracked { planes: [Plane::All(state), Plane::All(state)], plane_stride }
+}
+
+/// `cur` after the moves `(subresource or ALL_SUBRESOURCES, state after)`, in order. A move of
+/// one subresource of a plane that is not known leaves it not known (the plane's other
+/// subresources are still not known).
+fn apply(cur: &mut Tracked, moves: impl IntoIterator<Item = (u32, u32)>) {
+    let stride = cur.plane_stride.max(1);
+    for (sub, after) in moves {
+        if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES {
+            cur.planes = [Plane::All(after), Plane::All(after)];
+            continue;
+        }
+        let Some(plane) = cur.planes.get_mut((sub / stride) as usize) else { continue };
+        let i = (sub % stride) as usize;
+        match plane {
+            Plane::Unknown => {}

High: apply leaves a Plane::Unknown plane unknown after a move of one of its subresources, even when the plane has only that subresource (stride == 1) or when the moves together cover the whole plane, whereas the old code recorded a per-plane state from any explicit move. Take a D24S8 depth buffer with no note_created record (e.g. made through dev_create_committed_resource_x with pc_full == None, or any creation path this PR doesn't hook) that the title moves per plane, DEPTH_WRITE->SHADER_RESOURCE on plane 0 and then plane 1. subresources() returns Some([0]) and Some([1]), and moved reaches apply, but the Plane::Unknown => {} arm does nothing. Every later barrier from UNDEFINED on that texture then sends no transition, so it stays SHADER_RESOURCE on the PC while the title writes depth to it (debug layer 538/527). On main this worked. Setting Plane::All(after) for stride 1, and turning Unknown into All once every subresource has been moved, would restore it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4777471718 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4777471718). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T23:13:42Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 276 ~~~~diff @@ -263,44 +243,94 @@ fn unknown_layout(layout: (u32, u32)) { } } -/// Per-resource tracked states (plane 0 = colour/depth, plane 1 = stencil) and plane subresource stride. -#[derive(Clone, Copy, Default)] +/// Where a texture's planes are, and how many subresources a plane has (levels × slices). +#[derive(Clone, Default)] struct Tracked { - states: PlaneStates, + planes: [Plane; 2], plane_stride: u32, } -/// The per-plane state each texture was last moved to by a barrier group (the title's recording order). +/// Where each texture is, in the title's recording order: seeded with the PC state it was made +/// in (`note_created`), then moved by barrier groups and legacy transitions. A barrier from the +/// undefined layout starts there. static LAST: Sharded<Tracked> = Sharded::new(); -/// Texture barriers read, and transitions made of them. -static COUNTS: [AtomicU64; 2] = [const { AtomicU64::new(0) }; 2]; -/// Keep `LAST` in sync when a legacy `ResourceBarrier` transitions a tracked texture (e.g. to -/// `COMMON` before returning to enhanced barriers). No-op if the resource is not tracked. -pub(super) fn note_legacy_state(res: usize, sub: u32, after: u32) { - if COUNTS[0].load(Ordering::Relaxed) == 0 { - return; +/// The record a texture made in the PC state `state` starts with: both planes there. +fn created(state: u32, plane_stride: u32) -> Tracked { + Tracked { planes: [Plane::All(state), Plane::All(state)], plane_stride } +} + +/// `cur` after the moves `(subresource or ALL_SUBRESOURCES, state after)`, in order. A move of +/// one subresource of a plane that is not known leaves it not known (the plane's other +/// subresources are still not known). +fn apply(cur: &mut Tracked, moves: impl IntoIterator<Item = (u32, u32)>) { + let stride = cur.plane_stride.max(1); + for (sub, after) in moves { + if sub == D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES { + cur.planes = [Plane::All(after), Plane::All(after)]; + continue; + } + let Some(plane) = cur.planes.get_mut((sub / stride) as usize) else { continue }; + let i = (sub % stride) as usize; + match plane { + Plane::Unknown => {} ~~~~ --- **High**: `apply` leaves a `Plane::Unknown` plane unknown after a move of one of its subresources, even when the plane has only that subresource (stride == 1) or when the moves together cover the whole plane, whereas the old code recorded a per-plane state from any explicit move. Take a D24S8 depth buffer with no `note_created` record (e.g. made through `dev_create_committed_resource_x` with `pc_full == None`, or any creation path this PR doesn't hook) that the title moves per plane, DEPTH_WRITE->SHADER_RESOURCE on plane 0 and then plane 1. `subresources()` returns Some([0]) and Some([1]), and `moved` reaches `apply`, but the `Plane::Unknown => {}` arm does nothing. Every later barrier from UNDEFINED on that texture then sends no transition, so it stays SHADER_RESOURCE on the PC while the title writes depth to it (debug layer 538/527). On main this worked. Setting `Plane::All(after)` for stride 1, and turning Unknown into All once every subresource has been moved, would restore it.
bmjask commented 2026-12-02 23:13:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T23:13:42Z.

Code review location: crates/xcl/src/hle/d3d12x/barrier_groups.rs; line 486

@@ -388,44 +434,72 @@ pub(super) unsafe fn transitions(n: u32, groups: *const c_void, direct: bool) ->
             let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 };
             // (two planes: the depth-stencil formats R32G8X24 and R24G8 and their views)
             let planes = if matches!(d.Format.0, 19..=22 | 44..=47) { 2 } else { 1 };
-            if !asked.iter().any(|a| a.0 == res) {
-                asked.push((res, Asked { flags: d.Flags.0 as u32, subresources: d.MipLevels as u32 * array * planes, format: d.Format.0 }));
+            if ask(res).is_none() {
+                let stride = (d.MipLevels as u32).max(1) * array.max(1);
+                asked.borrow_mut().push((res, Asked { flags: d.Flags.0 as u32, subresources: stride * planes, format: d.Format.0, stride }));
             }
             Some((depth, d.MipLevels as u32, array, planes))
         },
-        &mut |res| LAST.get(res).map_or([None, None], |t| t.states),
-        &mut |res, plane, state, stride| {
+        // where the texture is with this call's moves so far
+        &mut |res| {
             let mut cur = LAST.get(res).unwrap_or_default();
-            cur.states[plane] = Some(state);
-            cur.plane_stride = stride;
-            LAST.insert(res, cur);
+            let mine: Vec<(u32, u32)> = moves.borrow().iter().filter(|m| m.0 == res).map(|m| (m.1, m.2)).collect();
+            if !mine.is_empty() {
+                if cur.plane_stride == 0 {
+                    cur.plane_stride = ask(res).map_or(1, |a| a.stride);
+                }
+                apply(&mut cur, mine);
+            }
+            cur.planes
+        },
+        // the state the PC list gets; nothing when the PC refuses it (the texture stays)
+        &mut |res, sub, state| {
+            if let Some(s) = ask(res).and_then(|a| pc_state(state, a.flags, res, direct)) {
+                moves.borrow_mut().push((res, sub, s));
+            }
         },
     );
+    let asked = asked.into_inner();
+    let mut moves = moves.into_inner();
+    let mut refused_at: Vec<(usize, u32)> = Vec::new();
     out.retain_mut(|w| {
         let res = (w[2] as u64 | (w[3] as u64) << 32) as usize;
         let Some(a) = asked.iter().find(|a| a.0 == res).map(|a| a.1) else { return false };
         if w[4] != D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES && w[4] >= a.subresources {
+            refused_at.push((res, w[4]));
             return refused(w, a, "a subresource the texture does not have");
         }
-        // a depth buffer the PC gave no unordered access (`device_x::pc_resource_desc`) cannot
-        // be in UNORDERED_ACCESS: one `depth_uav` keeps is taken from there by
-        // `depth_uav::plan_barriers`, any other rests where that would park it
-        let depth_only = a.flags & 0x2 != 0 && a.flags & 0x4 == 0;
-        let kept = depth_only && super::depth_uav::kept(res);
         for i in 5..7 {
-            if depth_only && w[i] == UNORDERED_ACCESS {
-                if !kept {
-                    w[i] = super::depth_uav::PARK;
-                }
-                continue;
-            }
-            match legal(w[i], a.flags, direct) {
+            match pc_state(w[i], a.flags, res, direct) {
                 Some(s) => w[i] = s,
-                None => return refused(w, a, if direct { "a state the PC's texture cannot be in" } else { "a state a compute list cannot move a texture to or from" }),
+                None => {
+                    refused_at.push((res, w[4]));
+                    return refused(w, a, if direct { "a state the PC's texture cannot be in" } else { "a state a compute list cannot move a texture to or from" });
+                }
             }
         }
         w[5] != w[6]
     });
+    // a refused transition leaves the PC's subresources where they were: its moves are not recorded
+    if !refused_at.is_empty() {
+        const ALL: u32 = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+        moves.retain(|m| !refused_at.iter().any(|r| r.0 == m.0 && (r.1 == m.1 || r.1 == ALL || m.1 == ALL)));

High: The refused-move filter removes every move in the call for the same texture and subresource, plus any ALL move of that texture (r.1 == ALL || m.1 == ALL), including moves from earlier barriers whose words were sent to the PC. If one Barrier call holds UNDEFINED->RENDER_TARGET on ALL (sent) and then a barrier on the same texture with an out-of-range subresource or a state the PC refuses, refused_at holds (res, sub) and the m.1 == ALL clause drops the first, legitimately sent move. For a texture with no record yet, nothing is recorded, and the follow-up note_legacy_states uses update, which creates nothing. The PC texture is in RENDER_TARGET with no record of it, so the next barrier from UNDEFINED sends nothing (538 on draw). Removing only the moves that the refused word itself stands for (by barrier index, not by (res, sub)) would fix it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4777471739 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#discussion_r4777471739). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T23:13:42Z. **Code review location:** `crates/xcl/src/hle/d3d12x/barrier_groups.rs`; line 486 ~~~~diff @@ -388,44 +434,72 @@ pub(super) unsafe fn transitions(n: u32, groups: *const c_void, direct: bool) -> let array = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { d.DepthOrArraySize as u32 }; // (two planes: the depth-stencil formats R32G8X24 and R24G8 and their views) let planes = if matches!(d.Format.0, 19..=22 | 44..=47) { 2 } else { 1 }; - if !asked.iter().any(|a| a.0 == res) { - asked.push((res, Asked { flags: d.Flags.0 as u32, subresources: d.MipLevels as u32 * array * planes, format: d.Format.0 })); + if ask(res).is_none() { + let stride = (d.MipLevels as u32).max(1) * array.max(1); + asked.borrow_mut().push((res, Asked { flags: d.Flags.0 as u32, subresources: stride * planes, format: d.Format.0, stride })); } Some((depth, d.MipLevels as u32, array, planes)) }, - &mut |res| LAST.get(res).map_or([None, None], |t| t.states), - &mut |res, plane, state, stride| { + // where the texture is with this call's moves so far + &mut |res| { let mut cur = LAST.get(res).unwrap_or_default(); - cur.states[plane] = Some(state); - cur.plane_stride = stride; - LAST.insert(res, cur); + let mine: Vec<(u32, u32)> = moves.borrow().iter().filter(|m| m.0 == res).map(|m| (m.1, m.2)).collect(); + if !mine.is_empty() { + if cur.plane_stride == 0 { + cur.plane_stride = ask(res).map_or(1, |a| a.stride); + } + apply(&mut cur, mine); + } + cur.planes + }, + // the state the PC list gets; nothing when the PC refuses it (the texture stays) + &mut |res, sub, state| { + if let Some(s) = ask(res).and_then(|a| pc_state(state, a.flags, res, direct)) { + moves.borrow_mut().push((res, sub, s)); + } }, ); + let asked = asked.into_inner(); + let mut moves = moves.into_inner(); + let mut refused_at: Vec<(usize, u32)> = Vec::new(); out.retain_mut(|w| { let res = (w[2] as u64 | (w[3] as u64) << 32) as usize; let Some(a) = asked.iter().find(|a| a.0 == res).map(|a| a.1) else { return false }; if w[4] != D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES && w[4] >= a.subresources { + refused_at.push((res, w[4])); return refused(w, a, "a subresource the texture does not have"); } - // a depth buffer the PC gave no unordered access (`device_x::pc_resource_desc`) cannot - // be in UNORDERED_ACCESS: one `depth_uav` keeps is taken from there by - // `depth_uav::plan_barriers`, any other rests where that would park it - let depth_only = a.flags & 0x2 != 0 && a.flags & 0x4 == 0; - let kept = depth_only && super::depth_uav::kept(res); for i in 5..7 { - if depth_only && w[i] == UNORDERED_ACCESS { - if !kept { - w[i] = super::depth_uav::PARK; - } - continue; - } - match legal(w[i], a.flags, direct) { + match pc_state(w[i], a.flags, res, direct) { Some(s) => w[i] = s, - None => return refused(w, a, if direct { "a state the PC's texture cannot be in" } else { "a state a compute list cannot move a texture to or from" }), + None => { + refused_at.push((res, w[4])); + return refused(w, a, if direct { "a state the PC's texture cannot be in" } else { "a state a compute list cannot move a texture to or from" }); + } } } w[5] != w[6] }); + // a refused transition leaves the PC's subresources where they were: its moves are not recorded + if !refused_at.is_empty() { + const ALL: u32 = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + moves.retain(|m| !refused_at.iter().any(|r| r.0 == m.0 && (r.1 == m.1 || r.1 == ALL || m.1 == ALL))); ~~~~ --- **High**: The refused-move filter removes every move in the call for the same texture and subresource, plus any ALL move of that texture (`r.1 == ALL || m.1 == ALL`), including moves from earlier barriers whose words were sent to the PC. If one Barrier call holds UNDEFINED->RENDER_TARGET on ALL (sent) and then a barrier on the same texture with an out-of-range subresource or a state the PC refuses, `refused_at` holds (res, sub) and the `m.1 == ALL` clause drops the first, legitimately sent move. For a texture with no record yet, nothing is recorded, and the follow-up `note_legacy_states` uses `update`, which creates nothing. The PC texture is in RENDER_TARGET with no record of it, so the next barrier from UNDEFINED sends nothing (538 on draw). Removing only the moves that the refused word itself stands for (by barrier index, not by (res, sub)) would fix it.
afpruivo commented 2026-12-02 23:20:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T23:20:20Z.


@Foniass thank you, the split case was right.

  • A split barrier from the undefined layout sent BEGIN_ONLY and never END_ONLY: fixed in the one commit, now 1e702297 (force-pushed; description updated). In transitions_of, a barrier from the undefined layout whose first half ends in SYNC_SPLIT sends its BEGIN_ONLY word from the record but does not record the move; the END_ONLY half starts from the same state and records it. New test the_halves_of_a_split_barrier_from_the_undefined_layout_start_at_the_same_state (a texture made in COMMON: begin COMMON→RT, end COMMON→RT, then the record is RT); it fails without the change (the record is already RT after the begin half).
  • Real creation hooks untested: still open, as Not tested says.

Tested on 1e702297: cargo test --workspace --no-fail-fast -- --test-threads=4 3009 passed, 2 failed (the #3441 test, counted twice; it fails 3 of 6 on main here, #3185 fixes it), 52 ignored, 26 SKIPPED; smoke against main c53e9696: 1495 vs 1573 frames, peak commit 16997 vs 15794 MB, no removals or crashes.

AI use: Claude Code (Claude Opus 5.5) checked and fixed this and wrote the reply while I was away; posted with my standing approval for this session.

<!-- greyfinch-sync:ivall/xcl:comment:7361867089 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7361867089). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T23:20:20Z. --- @Foniass thank you, the split case was right. - **A split barrier from the undefined layout sent `BEGIN_ONLY` and never `END_ONLY`:** fixed in the one commit, now `1e702297` (force-pushed; description updated). In `transitions_of`, a barrier from the undefined layout whose first half ends in `SYNC_SPLIT` sends its `BEGIN_ONLY` word from the record but does not record the move; the `END_ONLY` half starts from the same state and records it. New test `the_halves_of_a_split_barrier_from_the_undefined_layout_start_at_the_same_state` (a texture made in COMMON: begin `COMMON→RT`, end `COMMON→RT`, then the record is RT); it fails without the change (the record is already RT after the begin half). - **Real creation hooks untested:** still open, as **Not tested** says. Tested on `1e702297`: `cargo test --workspace --no-fail-fast -- --test-threads=4` 3009 passed, 2 failed (the #3441 test, counted twice; it fails 3 of 6 on `main` here, #3185 fixes it), 52 ignored, 26 SKIPPED; smoke against `main` `c53e9696`: 1495 vs 1573 frames, peak commit 16997 vs 15794 MB, no removals or crashes. AI use: Claude Code (Claude Opus 5.5) checked and fixed this and wrote the reply while I was away; posted with my standing approval for this session.
Foniass commented 2026-12-02 23:22:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:22:21Z.


Follow-up review of 1e702297, since 504f4e14 (code reading only, not a merge-check) · 1 medium

In short: This push fixes the High finding from my last review. For a split barrier from the undefined layout, the move is now recorded with the END_ONLY half, not the BEGIN_ONLY half (transitions_of, barrier_groups.rs ~203-212). Both halves therefore start from the same recorded state, and the PC list gets a matching begin and end. A test covers it. The creation-hook test point is unchanged.

Medium

  1. The real creation hooks are still untested (still open). The WARP test calls note_created directly. A wrong state or a missed record at the real.rs creation hooks (~3856, ~3931, ~4367, ~4494, ~4534, ~4575, ~4672) or at device_x.rs ~1293, ~1317, ~1336 would not be caught. Not tested says so.
Checked and fine
  • Earlier finding fixed: a split barrier from the undefined layout sent BEGIN_ONLY and never END_ONLY. The wrapper moved skips the record when flags == BEGIN_ONLY, only on the path from the undefined layout. A split barrier with an explicit before-layout still records its move as before.
  • the_halves_of_a_split_barrier_from_the_undefined_layout_start_at_the_same_state checks the begin half sends 0 -> RENDER_TARGET with BEGIN_ONLY and leaves the record at 0, and that the end half sends 0 -> RENDER_TARGET with END_ONLY and records RENDER_TARGET.
  • The commit message says so. The rest of the commit is unchanged since 504f4e14.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7361910374 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7361910374). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T23:22:21Z. --- **Follow-up review** of `1e702297`, since `504f4e14` (code reading only, not a merge-check) · 1 medium **In short:** This push fixes the High finding from my last review. For a split barrier from the undefined layout, the move is now recorded with the `END_ONLY` half, not the `BEGIN_ONLY` half (`transitions_of`, `barrier_groups.rs` ~203-212). Both halves therefore start from the same recorded state, and the PC list gets a matching begin and end. A test covers it. The creation-hook test point is unchanged. #### Medium 1. **The real creation hooks are still untested (still open).** The WARP test calls `note_created` directly. A wrong state or a missed record at the `real.rs` creation hooks (~3856, ~3931, ~4367, ~4494, ~4534, ~4575, ~4672) or at `device_x.rs` ~1293, ~1317, ~1336 would not be caught. **Not tested** says so. <details><summary>Checked and fine</summary> - Earlier finding fixed: a split barrier from the undefined layout sent `BEGIN_ONLY` and never `END_ONLY`. The wrapper `moved` skips the record when `flags == BEGIN_ONLY`, only on the path from the undefined layout. A split barrier with an explicit before-layout still records its move as before. - `the_halves_of_a_split_barrier_from_the_undefined_layout_start_at_the_same_state` checks the begin half sends `0 -> RENDER_TARGET` with `BEGIN_ONLY` and leaves the record at 0, and that the end half sends `0 -> RENDER_TARGET` with `END_ONLY` and records `RENDER_TARGET`. - The commit message says so. The rest of the commit is unchanged since `504f4e14`. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
afpruivo commented 2026-12-02 23:33:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T23:33:01Z.


@bmjask thank you, both were right. Fixed in the one commit, now f6ef500d (force-pushed; description updated).

  • A move of part of an unknown plane was lost (apply, ~283): right. A plane that is not known now becomes known one subresource at a time: a move of one subresource makes the plane Each, with the subresources not moved yet marked not known (they still send nothing from the undefined layout), and the plane is All once every subresource has been moved to one state. A one-subresource plane is All at once, so a D24S8 buffer XCL saw no creation of, moved plane 0 and then plane 1, is known on both planes. Unit test in each_subresource_keeps_its_own_state_until_a_plane_is_in_one_again.
  • The refused-move filter dropped other barriers' sent moves (~493): right. Each move and each word now carries the index of the barrier it was made of (the word's last, padding field, cleared before the words go out), and a refused word drops only the moves of its own barrier on its subresources. WARP test: on a compute list, UNDEFINED→SHADER_RESOURCE on the whole texture (sent) and then a barrier from a render target on it (refused) in one group; the next UNDEFINED→RENDER_TARGET sends 0x40→RT. Without the change it sends COMMON→RT.

Both tests fail without the change and pass with it.

Tested on f6ef500d: cargo test --workspace --no-fail-fast -- --test-threads=4 3009 passed, 2 failed (the #3441 test, counted twice, as on the previous head), 52 ignored, 26 SKIPPED; smoke against main c53e9696: 1502 vs 1573 frames, peak commit 17034 vs 15794 MB, no removals or crashes.

AI use: Claude Code (Claude Opus 5.5) checked and fixed this and wrote the reply while I was away; posted with my standing approval for this session.

<!-- greyfinch-sync:ivall/xcl:comment:7362140578 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7362140578). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T23:33:01Z. --- @bmjask thank you, both were right. Fixed in the one commit, now `f6ef500d` (force-pushed; description updated). - **A move of part of an unknown plane was lost** (`apply`, ~283): right. A plane that is not known now becomes known one subresource at a time: a move of one subresource makes the plane `Each`, with the subresources not moved yet marked not known (they still send nothing from the undefined layout), and the plane is `All` once every subresource has been moved to one state. A one-subresource plane is `All` at once, so a D24S8 buffer XCL saw no creation of, moved plane 0 and then plane 1, is known on both planes. Unit test in `each_subresource_keeps_its_own_state_until_a_plane_is_in_one_again`. - **The refused-move filter dropped other barriers' sent moves** (~493): right. Each move and each word now carries the index of the barrier it was made of (the word's last, padding field, cleared before the words go out), and a refused word drops only the moves of its own barrier on its subresources. WARP test: on a compute list, `UNDEFINED→SHADER_RESOURCE` on the whole texture (sent) and then a barrier from a render target on it (refused) in one group; the next `UNDEFINED→RENDER_TARGET` sends `0x40→RT`. Without the change it sends `COMMON→RT`. Both tests fail without the change and pass with it. Tested on `f6ef500d`: `cargo test --workspace --no-fail-fast -- --test-threads=4` 3009 passed, 2 failed (the #3441 test, counted twice, as on the previous head), 52 ignored, 26 SKIPPED; smoke against `main` `c53e9696`: 1502 vs 1573 frames, peak commit 17034 vs 15794 MB, no removals or crashes. AI use: Claude Code (Claude Opus 5.5) checked and fixed this and wrote the reply while I was away; posted with my standing approval for this session.
Foniass commented 2026-12-02 23:35:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:35:52Z.


Follow-up review of f6ef500d, since 1e702297 (code reading only, not a merge-check) · 1 medium

In short: This push tightens the record in two places. A refused transition now drops only the moves of the barrier it was made of: each transition word carries its barrier's index in its padding dword (word 7), cleared before the word is sent. Earlier, sent moves of the same subresource in the call were dropped too. And moving one subresource of a plane that is not known now makes that subresource known, while the others stay not known. Both have tests. The creation-hook test point is unchanged.

Medium

  1. The real creation hooks are still untested (still open). The WARP test calls note_created directly. A wrong state or a missed record at the real.rs creation hooks (~3856, ~3931, ~4367, ~4494, ~4534, ~4575, ~4672) or at device_x.rs ~1293, ~1317, ~1336 would not be caught.
Checked and fine
  • Word 7 of a transition is the padding after StateAfter in D3D12_RESOURCE_BARRIER. transitions reads the index with std::mem::take(&mut w[7]) (barrier_groups.rs ~482) for every word it keeps, so the PC list gets 0 there as before.
  • moves.retain now drops a move only when its barrier index and texture match a refused word and the subresource matches (or either is ALL). The new compute-list case sends a whole-texture move, refuses a later render-target barrier on it, and records only the sent move.
  • Plane::Each uses NOT_KNOWN (u32::MAX) for subresources not moved since the plane was unknown. of filters it, and a plane whose entries are all NOT_KNOWN goes back to Unknown. A plane with stride 1 becomes All(after) directly. The tests cover one subresource moved, the whole plane moved, and a depth buffer moved a plane at a time.
  • The split-barrier fix from the last push is unchanged.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7362197462 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7362197462). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T23:35:52Z. --- **Follow-up review** of `f6ef500d`, since `1e702297` (code reading only, not a merge-check) · 1 medium **In short:** This push tightens the record in two places. A refused transition now drops only the moves of the barrier it was made of: each transition word carries its barrier's index in its padding dword (word 7), cleared before the word is sent. Earlier, sent moves of the same subresource in the call were dropped too. And moving one subresource of a plane that is not known now makes that subresource known, while the others stay not known. Both have tests. The creation-hook test point is unchanged. #### Medium 1. **The real creation hooks are still untested (still open).** The WARP test calls `note_created` directly. A wrong state or a missed record at the `real.rs` creation hooks (~3856, ~3931, ~4367, ~4494, ~4534, ~4575, ~4672) or at `device_x.rs` ~1293, ~1317, ~1336 would not be caught. <details><summary>Checked and fine</summary> - Word 7 of a transition is the padding after `StateAfter` in `D3D12_RESOURCE_BARRIER`. `transitions` reads the index with `std::mem::take(&mut w[7])` (`barrier_groups.rs` ~482) for every word it keeps, so the PC list gets 0 there as before. - `moves.retain` now drops a move only when its barrier index and texture match a refused word and the subresource matches (or either is `ALL`). The new compute-list case sends a whole-texture move, refuses a later render-target barrier on it, and records only the sent move. - `Plane::Each` uses `NOT_KNOWN` (`u32::MAX`) for subresources not moved since the plane was unknown. `of` filters it, and a plane whose entries are all `NOT_KNOWN` goes back to `Unknown`. A plane with stride 1 becomes `All(after)` directly. The tests cover one subresource moved, the whole plane moved, and a depth buffer moved a plane at a time. - The split-barrier fix from the last push is unchanged. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
afpruivo commented 2026-12-02 23:47:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T23:47:45Z.


@Foniass on the creation-hook point: a first test through the real hook is in, in the one commit, now da071dc9 (force-pushed; description updated). the_device_hook_records_a_texture_made_through_create_committed_resource1 adopts a WARP device as XCL does, makes a render target through real::dev_create_committed_resource1 in COPY_DEST, and checks that the record holds COPY_DEST on both planes. It fails with the hook's note_created taken out (left: None). The other hooks (display targets, reserved resources, CreateCommittedResource2, CreatePlacedResource1, the depth_uav points) are still not tested; Not tested says so.

Tested on da071dc9: cargo test --workspace --no-fail-fast -- --test-threads=4 3011 passed, 0 failed, 52 ignored, 26 SKIPPED; smoke against main c53e9696: 1511 vs 1573 frames, peak commit 16680 vs 15794 MB, no removals or crashes.

AI use: Claude Code (Claude Opus 5.5) wrote the test, ran these and wrote this while I was away; posted with my standing approval for this session.

<!-- greyfinch-sync:ivall/xcl:comment:7362434925 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7362434925). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T23:47:45Z. --- @Foniass on the creation-hook point: a first test through the real hook is in, in the one commit, now `da071dc9` (force-pushed; description updated). `the_device_hook_records_a_texture_made_through_create_committed_resource1` adopts a WARP device as XCL does, makes a render target through `real::dev_create_committed_resource1` in COPY_DEST, and checks that the record holds COPY_DEST on both planes. It fails with the hook's `note_created` taken out (`left: None`). The other hooks (display targets, reserved resources, `CreateCommittedResource2`, `CreatePlacedResource1`, the `depth_uav` points) are still not tested; **Not tested** says so. Tested on `da071dc9`: `cargo test --workspace --no-fail-fast -- --test-threads=4` 3011 passed, 0 failed, 52 ignored, 26 SKIPPED; smoke against `main` `c53e9696`: 1511 vs 1573 frames, peak commit 16680 vs 15794 MB, no removals or crashes. AI use: Claude Code (Claude Opus 5.5) wrote the test, ran these and wrote this while I was away; posted with my standing approval for this session.
Foniass commented 2026-12-02 23:50:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:50:12Z.


Follow-up review of da071dc9, since f6ef500d (code reading only, not a merge-check) · 1 medium

In short: This push adds a test that goes through a real device hook. On WARP, dev_create_committed_resource1 makes a render-target texture in COPY_DEST, and the test checks the record holds that state. That covers the new creator! hook. The other creation hooks are still reached only through note_created. Nothing blocks it.

Medium

  1. Most creation hooks are still untested (partly open). CreateCommittedResource1 is now covered. The others are not: CreateCommittedResource, CreatePlacedResource, CreatePlacedResource1, CreateCommittedResource2 and the console placement paths at device_x.rs ~1293, ~1317, ~1336. A wrong argument index or a missed record there would not be caught. The same WARP pattern would cover them.
Checked and fine
  • the_device_hook_records_a_texture_made_through_create_committed_resource1 skips through skip_test without a WARP device and adopts the device before calling the hook. It reads LAST for the new texture and calls forget at the end, so no record is left for other tests.
  • The test passes the initial state as the fourth argument, which is what the creator! hook reads.
  • The record changes from the last push are unchanged: per-barrier refusals, NOT_KNOWN subresources, and split barriers from the undefined layout.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7362483649 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7362483649). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T23:50:12Z. --- **Follow-up review** of `da071dc9`, since `f6ef500d` (code reading only, not a merge-check) · 1 medium **In short:** This push adds a test that goes through a real device hook. On WARP, `dev_create_committed_resource1` makes a render-target texture in `COPY_DEST`, and the test checks the record holds that state. That covers the new `creator!` hook. The other creation hooks are still reached only through `note_created`. Nothing blocks it. #### Medium 1. **Most creation hooks are still untested (partly open).** `CreateCommittedResource1` is now covered. The others are not: `CreateCommittedResource`, `CreatePlacedResource`, `CreatePlacedResource1`, `CreateCommittedResource2` and the console placement paths at `device_x.rs` ~1293, ~1317, ~1336. A wrong argument index or a missed record there would not be caught. The same WARP pattern would cover them. <details><summary>Checked and fine</summary> - `the_device_hook_records_a_texture_made_through_create_committed_resource1` skips through `skip_test` without a WARP device and adopts the device before calling the hook. It reads `LAST` for the new texture and calls `forget` at the end, so no record is left for other tests. - The test passes the initial state as the fourth argument, which is what the `creator!` hook reads. - The record changes from the last push are unchanged: per-barrier refusals, `NOT_KNOWN` subresources, and split barriers from the undefined layout. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
afpruivo commented 2026-12-03 00:34:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-03T00:34:51Z.


@Foniass thanks. The device-hook test now covers CreateCommittedResource2 and CreatePlacedResource1 too (same creator! hook, a D3D12_RESOURCE_DESC1, made in SHADER_RESOURCE, a placed one on its own heap). It is in the one commit, now 8bd724ee (force-pushed; description updated). The remaining paths (dev_create_committed_resource_x, dev_create_placed_resource_x, reserved resources and the device_x placement points) take the console's descriptor layouts and run inside the title's state, so they are still only reached through note_created. Not tested says so.

Tested on 8bd724ee: cargo test --workspace --no-fail-fast -- --test-threads=4 3011 passed, 0 failed, 52 ignored, 26 SKIPPED. Smoke against main c53e9696: 1668 vs 1573 frames, peak commit 17592 vs 15794 MB, no removals or crashes.

AI use: Claude Code (Claude Opus 5.5) extended the test, ran these and wrote this while I was away; posted with my standing approval for this session.

<!-- greyfinch-sync:ivall/xcl:comment:7363353257 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7363353257). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-03T00:34:51Z. --- @Foniass thanks. The device-hook test now covers `CreateCommittedResource2` and `CreatePlacedResource1` too (same `creator!` hook, a `D3D12_RESOURCE_DESC1`, made in SHADER_RESOURCE, a placed one on its own heap). It is in the one commit, now `8bd724ee` (force-pushed; description updated). The remaining paths (`dev_create_committed_resource_x`, `dev_create_placed_resource_x`, reserved resources and the `device_x` placement points) take the console's descriptor layouts and run inside the title's state, so they are still only reached through `note_created`. **Not tested** says so. Tested on `8bd724ee`: `cargo test --workspace --no-fail-fast -- --test-threads=4` 3011 passed, 0 failed, 52 ignored, 26 SKIPPED. Smoke against `main` `c53e9696`: 1668 vs 1573 frames, peak commit 17592 vs 15794 MB, no removals or crashes. AI use: Claude Code (Claude Opus 5.5) extended the test, ran these and wrote this while I was away; posted with my standing approval for this session.
Foniass commented 2026-12-03 00:37:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T00:37:18Z.


Follow-up review of 8bd724ee, since da071dc9 (code reading only, not a merge-check) · 1 medium

In short: This push extends the WARP test to the other two methods of the creator! hook: CreateCommittedResource2 and CreatePlacedResource1 (on an RT/DS heap). Each is checked to record the texture in the state passed as the fourth argument. All three hooks that the PR adds are now tested through the device. The older creation paths are still reached only through note_created. Nothing blocks it.

Medium

  1. The older creation hooks are still untested (partly open). CreateCommittedResource1 / 2 and CreatePlacedResource1 are now covered. CreateCommittedResource, CreatePlacedResource and the console placement paths at device_x.rs ~1293, ~1317, ~1336 are not. The same WARP pattern would cover the first two; the console paths need a placed resource through create_placed_resource_x.
Checked and fine
  • The test builds a D3D12_RESOURCE_DESC1 from the same 16x16 RGBA8 render-target desc. It creates the placed texture on a 1 MiB ALLOW_ONLY_RT_DS_TEXTURES heap, which fits a render target, and checks Plane::All(SHADER_RESOURCE) for both new resources before calling forget.
  • The CreateCommittedResource1 case from the last push is unchanged.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7363399579 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7363399579). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T00:37:18Z. --- **Follow-up review** of `8bd724ee`, since `da071dc9` (code reading only, not a merge-check) · 1 medium **In short:** This push extends the WARP test to the other two methods of the `creator!` hook: `CreateCommittedResource2` and `CreatePlacedResource1` (on an RT/DS heap). Each is checked to record the texture in the state passed as the fourth argument. All three hooks that the PR adds are now tested through the device. The older creation paths are still reached only through `note_created`. Nothing blocks it. #### Medium 1. **The older creation hooks are still untested (partly open).** `CreateCommittedResource1` / `2` and `CreatePlacedResource1` are now covered. `CreateCommittedResource`, `CreatePlacedResource` and the console placement paths at `device_x.rs` ~1293, ~1317, ~1336 are not. The same WARP pattern would cover the first two; the console paths need a placed resource through `create_placed_resource_x`. <details><summary>Checked and fine</summary> - The test builds a `D3D12_RESOURCE_DESC1` from the same 16x16 RGBA8 render-target desc. It creates the placed texture on a 1 MiB `ALLOW_ONLY_RT_DS_TEXTURES` heap, which fits a render target, and checks `Plane::All(SHADER_RESOURCE)` for both new resources before calling `forget`. - The `CreateCommittedResource1` case from the last push is unchanged. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
afpruivo commented 2026-12-03 00:41:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-03T00:41:01Z.


@Foniass on the older paths: I tried the same WARP pattern on the console CreateCommittedResource (dev_create_committed_resource_x) and CreatePlacedResource (dev_create_placed_resource_x) with a 2D texture. Both record the texture, and the placed one fails without its note_created (left: None). But which branch they take depends on process-wide state. The committed one went through place_console_texture, not the branch at ~3931, because the test binary may already have unified-memory windows open from other tests. So the test's coverage would depend on test order. I left those out of the PR rather than add an order-dependent test. They stay under Not tested. The plain PC CreateCommittedResource / CreatePlacedResource methods (the creator! slots) record nothing themselves: XCL records at the console wrappers that call them.

AI use: Claude Code (Claude Opus 5.5) tried this and wrote this while I was away; posted with my standing approval for this session.

<!-- greyfinch-sync:ivall/xcl:comment:7363468962 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3527#issuecomment-7363468962). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-03T00:41:01Z. --- @Foniass on the older paths: I tried the same WARP pattern on the console `CreateCommittedResource` (`dev_create_committed_resource_x`) and `CreatePlacedResource` (`dev_create_placed_resource_x`) with a 2D texture. Both record the texture, and the placed one fails without its `note_created` (`left: None`). But which branch they take depends on process-wide state. The committed one went through `place_console_texture`, not the branch at ~3931, because the test binary may already have unified-memory windows open from other tests. So the test's coverage would depend on test order. I left those out of the PR rather than add an order-dependent test. They stay under **Not tested**. The plain PC `CreateCommittedResource` / `CreatePlacedResource` methods (the `creator!` slots) record nothing themselves: XCL records at the console wrappers that call them. AI use: Claude Code (Claude Opus 5.5) tried this and wrote this while I was away; posted with my standing approval for this session.
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/3527:upstream-pr/3527'
git switch 'upstream-pr/3527'

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/3527'
git switch 'upstream-pr/3527'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3527'
git switch 'upstream-pr/3527'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3527'
git switch 'main'
git merge --squash 'upstream-pr/3527'
git switch 'main'
git merge --ff-only 'upstream-pr/3527'
git switch 'main'
git merge 'upstream-pr/3527'
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!3527
No description provided.