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 on both planes with the PC state it was made in, and a barrier from the undefined layout starts 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); that series needs each texture's creation state for its first move, which this record gives.

What is in it (one commit)

  • crates/xcl/src/hle/d3d12x/barrier_groups.rs: LAST is the one record per texture. note_created seeds it on 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. Barrier groups and legacy transitions move it per plane; a legacy transition of all subresources sets both planes, so a known state comes back after a partial one (legacy_moved). forget drops it on release. Barriers from the undefined layout that ask for D3D12_TEXTURE_BARRIER_FLAG_DISCARD are counted and logged by kind of texture (log only; nothing sent changes).
  • device_x.rs, real.rs: note_created at the creation points that call depth_uav::note_created, and the CreatePlacedResource the PC accepts on the first try.
  • 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, a partial then a whole legacy move, depth then stencil, release and reuse of the pointer; it fails with the old gate on creation), a_legacy_move_of_some_subresources_then_of_all_leaves_a_known_state, and the updated a_new_texture_leaves_the_undefined_layout_from_the_state_it_was_made_in.

Tested

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

  • cargo test --workspace --no-fail-fast -- --test-threads=4 (the change on main 493dbd3d): 2903 passed, 0 failed, 51 ignored; SKIPPED: 27 (no wave64 on this 32-lane GPU, no heap windows, no D3D12 debug layer at the time).

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

  • The retail title with XCL_D3D12_DEBUG=1, XCL_PREPARE=0, 300 s, the same input script on both (XCL logs the first 8 messages of each id, so 8 means 8 or more):

    debug layer error main 493dbd3 this PR, run 1 run 2
    538, Draw into a render target in COMMON (~17 s) 1 0 0
    538, ClearDepthStencilView in COMMON 3 0 0
    527, before-state RENDER_TARGET, texture in COMMON 1 0 0
    538, ClearRenderTargetView in COMMON (83-113 s) 4 2 7
    538, ClearRenderTargetView in a shader-resource state 0 0 1
    527, a buffer promoted to vertex/index use (not tracked here) 7 8 8

    A third run with a log line for any barrier from the undefined layout that finds no record of its texture logged none: the ClearRenderTargetView errors left are on recorded textures whose recorded state differs from the GPU's. Two are on subresource 3 (the record has one state per plane, not per level, as before); the others fit the recording-order limit above. The counter shows the title asks for a discard on most of its moves from the undefined layout (run 2: render targets 19,582 of 24,393, depth 1,251 of 2,256, unordered access 44,717 of 44,717); XCL sends no discard for them, which is not changed here.

  • PR run 1 ended at 122 s with an access violation in D3D12Core.dll under the debug layer, in SetPipelineState (bind.rs ~4642), not in barrier code; it did not happen in the next two runs of this head or in the main run.

Regression run

main:

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

this PR:

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

Not tested

  • The world: neither debug-layer run reached it in 300 s with XCL_PREPARE=0 (menus and loading screens); errors that only happen there are not counted.
  • Whether the missing discards cause visible errors.
  • The cost of recording every texture from creation (one table lookup per legacy transition, one GetDesc per texture made) beyond the smoke run.
  • AMD and Intel GPUs.

AI use

  • Claude Code with Claude Opus 5.5: wrote the code, the tests, the commit message and this description, ran the tests and the title runs. Reviewed by me.

🤖 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

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

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.

…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 on
both planes 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). 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. Barrier groups and legacy transitions
move it per plane; a legacy transition of all subresources sets both
planes, so a known state comes back after a partial one. Release drops
it. Buffers are not recorded.

Barriers from the undefined layout that ask for a discard
(D3D12_TEXTURE_BARRIER_FLAG_DISCARD) are counted and logged by kind of
texture. XCL sends no discard for them; the count shows whether the
title relies on it.

Fixes xcl-dev#3489.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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
Contributor

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

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)

6 participants