Skip to content

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

Open
afpruivo wants to merge 1 commit into
xcl-dev:mainfrom
afpruivo:barrier-groups-created-state
Open

afpruivo wants to merge 1 commit into
xcl-dev:mainfrom
afpruivo:barrier-groups-created-state

Conversation

@afpruivo

@afpruivo afpruivo commented Nov 30, 2026 •

Copy link
Copy Markdown

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 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 (Runtime: CPU check at start, bounded reads in the exception logger, t… #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, 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 e671f910 (the same tree as the head 504f4e14, which only rewords the commit message), with Windows' own D3D12 (XCL_D3D12_DIR set to an empty folder, see below): 3009 passed, 0 failed, 52 ignored; SKIPPED: 26 (22 no wave64 on this 32-lane GPU, 2 no xgameruntime.dll, 2 no heap windows).

  • cargo test -p xcl --lib barrier_groups: 12 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 Tests: on an AMD RDNA2 iGPU the xcl lib test binary stops itself partway ("sparse upload preparation still failed after bounded retries") since #2959 #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 493dbd3 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: 504f4e14b33e0f1aecfa65cfc56b45a6d7d35b91
gpu: NVIDIA GeForce RTX 3090
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1592 (PresentX 1592)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 17151 MB

Not tested

  • The debug-layer comparison on this head (504f4e14); 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 real creation hooks (display targets, reserved resources, CreateCommittedResource1/2, CreatePlacedResource1): those paths need the title or are the PC's own methods; the WARP test calls note_created directly.
  • Implicit promotion and decay: not modelled here; KDenKC's D3D12.X: keep each recording's barrier states for submission order #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

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 30, 2026
@Gevroska

Copy link
Copy Markdown
Contributor

@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

Copy link
Copy Markdown
Contributor

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.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

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

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

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

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. 0d61b2c 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

afpruivo commented Dec 1, 2026

Copy link
Copy Markdown
Author

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.

@afpruivo
afpruivo marked this pull request as ready for review December 1, 2026 10:43
@Aniseto

Aniseto commented Dec 1, 2026

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 493dbd3
head: 0d61b2c
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 493dbd3 vs this merge (0d61b2c): 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.

@github-actions github-actions Bot removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@AAsobu

AAsobu commented Dec 1, 2026

Copy link
Copy Markdown

merge-check
base: b2b1f10
head: 0d61b2c
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 bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

let Some(mut cur) = LAST.get(res) else { return };
}

fn legacy_moved(mut cur: Tracked, sub: u32, after: u32) -> Tracked {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

/// 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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

@afpruivo
afpruivo force-pushed the barrier-groups-created-state branch from 0d61b2c to 7c10aff Compare December 2, 2026 15:21
@afpruivo

afpruivo commented Dec 2, 2026

Copy link
Copy Markdown
Author

@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 (Runtime: CPU check at start, bounded reads in the exception logger, t… #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.

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 7c10aff, 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 D3D12.X: barrier_groups drops UNDEFINED -> target transitions for new COMMON textures (debug layer 538, 527) #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 bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

// 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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 };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
afpruivo force-pushed the barrier-groups-created-state branch from 7c10aff to b948e19 Compare December 2, 2026 16:56
@afpruivo

afpruivo commented Dec 2, 2026

Copy link
Copy Markdown
Author

@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

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head b948e19, since 7c10aff, 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 bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

…state

A barrier group's texture barrier from the undefined layout started at
the state a barrier group last moved the texture to; a texture no group
had moved yet got no PC transition at all. A render target or depth
buffer made in COMMON then stayed there while the title drew into or
cleared it, and the title's next barrier named a state the PC texture
was not in: debug layer errors 538 and 527 on the retail title (xcl-dev#3489).

Each texture now has one record from creation to release, seeded with
the PC state it was made in, at the creation points that pass that
state to depth_uav (and the CreatePlacedResource the PC accepts on the
first try), at display targets made through the layout form of
CreateCommittedResource, at reserved resources, and at the PC's own
CreateCommittedResource1/2 and CreatePlacedResource1. It is kept
whether or not the title has used barrier groups yet, since most render
targets and depth buffers are made at load, before the first group.
Release drops it. Buffers are not recorded.

Each plane of the record is in one state, in a state per subresource
when its subresources differ, or not known. Barrier groups and legacy
transitions move it subresource by subresource, in order, and a plane
whose subresources agree again is in one state again; so a plane moved
one level at a time, or one subresource moved twice in a call, ends
where the PC's texture is. A barrier from the undefined layout starts
each subresource from its own state; one whose state is not known sends
and records nothing. Within one call a barrier starts where the ones
before it left the texture.

The record holds what the PC list gets: the state after legal() and the
depth UAV park; a move the PC would refuse, and the moves a refused
transition stands for, are not recorded (on a compute list,
SHADER_RESOURCE reaches the PC without PIXEL_SHADER_RESOURCE, and a
render target move is refused). The transitions of one ResourceBarrier
call are recorded together under one lock per texture
(Sharded::update), so a record release removed is not put back.

Fixes xcl-dev#3489.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@afpruivo
afpruivo force-pushed the barrier-groups-created-state branch from b948e19 to 504f4e1 Compare December 2, 2026 23:02
@afpruivo

afpruivo commented Dec 2, 2026

Copy link
Copy Markdown
Author

@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.

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

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 D3D12.X: barrier_groups drops UNDEFINED -> target transitions for new COMMON textures (debug layer 538, 527) #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.
  • D3D12.X: barriers from the undefined layout can start from UNDEFINED natively #3558 and D3D12.X: keep each recording's barrier states for submission order #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.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

let Some(plane) = cur.planes.get_mut((sub / stride) as usize) else { continue };
let i = (sub % stride) as usize;
match plane {
Plane::Unknown => {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

// 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)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

D3D12.X: barrier_groups drops UNDEFINED -> target transitions for new COMMON textures (debug layer 538, 527)

7 participants