Skip to content

D3D12.X: keep each recording's barrier states for submission order - #3599

Draft
KDenKC wants to merge 2 commits into
xcl-dev:mainfrom
KDenKC:feat/submit-states-b
Draft

KDenKC wants to merge 2 commits into
xcl-dev:mainfrom
KDenKC:feat/submit-states-b

Conversation

@KDenKC

@KDenKC KDenKC commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3559; only the top commit (D3D12.X: keep each recording's barrier states for submission order) belongs here.

Part B of the plan on #3094 (7298369429). barrier_groups and alias_copy take the state a texture is in from what was recorded last, but the GPU runs lists in the order they are submitted. This part records, without using it yet: per recording (a PC list between two resets), the state it needs each texture in when it starts (first) and the one it leaves it in (now), from the words the PC list really gets; and the state each texture is in after the recordings accepted so far, in submission order (one map for all queues: a legacy state is the resource's, whichever queue moves it), advanced only by chunks the driver accepted, from ExecuteCommandLists and from KickoffX. What D3D12 returns to COMMON when the call ends (all a copy queue's list used, a buffer, a simultaneous-access texture) is COMMON there too. What a recording needs and the queue does not have is what part C's fix-up lists put before it.

  • A texture is in one barrier model at a time (a legacy state or an enhanced layout), and the model is part of the state, so a hand-off between models is visible to part C (D3D12.X: barriers from the undefined layout can start from UNDEFINED natively #3558).
  • A split barrier's begin half leaves the texture pending, neither state, at the recording's end; as the recording's first move it gives what the recording needs at its start (its before-state).
  • A recording is forgotten when its list starts another: Reset, a new list at its address, a KickoffX that submitted it, a mid-list split's next list, a segment back in the pool, and its release.
  • A move of one subresource marks the texture mixed; a mixed texture keeps today's behaviour.
  • Off unless XCL_SUBMIT_STATES=1; with it off each hook is one atomic load.

Related: #3094 (7297382882), #3489, #3558

What is in it (one commit)

  • crates/xcl/src/hle/d3d12x/submit_states.rs (new): Recording (per-texture first / now / mixed / pending), Queued (the queue's states; apply per accepted list, fixups for part C), the hooks, and 10 unit tests (the hooks with the switch forced on and off per thread, whatever the environment says).
  • crates/xcl/src/hle/d3d12x/list_x.rs: resource_barrier_x reports the words it sends; KickoffX's submissions advance the queue's states; the recording is forgotten on Reset, list creation, KickoffX, a mid-list split, a segment back in the pool and release (one line each).
  • crates/xcl/src/hle/d3d12x/real.rs: q_execute_command_lists advances the queue's states after each accepted chunk, on its queue (one line).
  • crates/xcl/src/hle/d3d12x/mod.rs: mod submit_states;.

Tested

After the review fixes (head 04eb8071), RTX 5090, driver 621.40, Ryzen 7 9800X3D, Windows 11 Pro build 26200.9974, Rust 1.99.1, debug: cargo test -p xcl --lib -- hle::d3d12x --test-threads=4 without and with XCL_SUBMIT_STATES=1 in the environment: 1217 passed, 0 failed, 3 ignored both times.

  • NVIDIA GeForce RTX 3090 24 GB (VM), driver 621.24, Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug:
    • cargo test -p xcl --lib -- hle::d3d12x hle::d3d12x::list_x hle::d3d12x::real hle::d3d12x::submit_states --test-threads=4 (the modules the commit touches), head 04eb8071: 1213 passed, 4 failed, 3 ignored; the 4 are the title_textures tests below, which fail on main on this machine too.
    • cargo test --workspace --no-fail-fast -- --test-threads=4, head 04eb8071: 2897 passed, 5 failed, 51 ignored. main d0832e61 (the commit Tests: a harness for barrier states across submission orders #3559 is on) on the same machine: 2882 passed, 5 failed, 51 ignored. The same 5 fail on both: title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, the three title_textures::tests::stream_recheck_* tests, and test_title_runs_and_game_folder_is_untouched.
    • SKIPPED on both (28): 22 GPU tests no wave64, 2 no heap windows, 3 no D3D12 debug layer, pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off). Left out by the run on this VM (no GPU_UPLOAD heaps): 3 uma_driver tests.

Regression run

These blocks are of a7c1ddd3, before the review fixes; a pair on 04eb8071 follows.

  • RTX 5090, 600 seconds per arm. Both arms used the same translated-cache seed (main-full-d8bd), the same frozen accepted-terms profile (r18-terms: gamesave and pls/settings), and held Enter. XCL_SUBMIT_STATES was unset in the head arm. The script-made blocks below are verbatim.

Main 9dfbe3ea:

xcl-smoke v1
commit: 9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 1872 (PresentX 1873)
presents per 2 s (last 3): 2 2 1
device removals: 0
crashes: 0
peak commit: 47791 MB

Part B a7c1ddd3:

xcl-smoke v1
commit: a7c1ddd3fe788345e94279f5abd62c5a7a114523
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 1835 (PresentX 1836)
presents per 2 s (last 3): 1 2 2
device removals: 0
crashes: 0
peak commit: 49173 MB

Not tested

  • Anything with XCL_SUBMIT_STATES=1 on a title: nothing reads the records yet (part C).
  • AMD and wave32-only GPUs.

AI use

  • Claude Code (Claude Opus 5.5, Claude Sonnet 5.5), Codex (GPT-6.2-Sol), Antigravity (Gemini 4 Neon, Gemini 4 Hydrogen): an agent swarm wrote, tested, reviewed and described this change.

🤖 Generated with Claude Code

A recording is a stand-in PC list that keeps the words XCL's hooks send its
ResourceBarrier (the title's legacy barriers through resource_barrier_x,
its enhanced barriers through uav_barrier_x); a CPU model of the GPU runs
recordings in a chosen submission order and reports each transition whose
before-state is not the state the texture is in at that point, which is
what the debug layer reports as 527 / 538. The debug layer itself is not
used: it is one per process, and turning it on would remove the devices of
the tests running beside these. The textures are WARP resources (their
descriptions are read); nothing runs on the GPU.

The cases here hold on main: the model itself, two lists submitted in their
recording order (direct and compute), and a list submitted again that ends
where it starts. The cases that do not hold (a list recorded before another
but submitted after it, a list reset unsubmitted, KickoffX segments) come
with the change that makes them hold.

Part A of the plan on xcl-dev#3094 (7298369429).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head a7c1ddd, diff read, not a merge-check; draft):

  • KickoffX submissions never update the queue states. submitted is hooked only in q_execute_command_lists (real.rs ~12048). kickoff_x sends the earlier segments and the list itself through the queue's original ExecuteCommandLists (list_x.rs ~5397, ~5443, where gpu_times::executed and lut3d::submitted are called) without calling submit_states::submitted, so a texture moved by a list submitted through KickoffX keeps its old state in Queued, against the module doc (submit_states.rs ~16-19).
  • Queued::apply ignores state decay. apply (~124) stores each recording's now for every submission, but D3D12 returns resources used on a copy queue, and simultaneous-access textures, to COMMON when the ExecuteCommandLists completes. After a copy list leaves a texture in COPY_DEST, Queued holds COPY_DEST while the runtime has COMMON, so a part C fix-up built from it would use the wrong before-state. There is also one global QUEUED for all queues (~153-156), not the per-queue state the description describes.
  • A recording outlives its list. RECORDINGS is keyed by the list's address and cleared only in reset (~167), from the Reset hook. A list made by CreateCommandList starts recording without a Reset, so a new list at a released list's address adds to the old Recording, inherits its first values, and its submission writes the old list's now values into Queued. Entries of released lists are never freed.
  • fixups drops textures that end the recording in a split. split_pending describes the end of the recording, but fixups (~114) uses it to skip the move before the recording starts: a recording that does SRV→RT then BEGIN_ONLY RT→SRV on a texture the queue has in COPY_DEST gets no fix-up. a_pending_split_is_neither_state only covers a texture with a begin half alone.
  • The hooks are only tested with the switch off. a_reset_forgets_the_recording_and_only_accepted_lists_advance_the_queue (~305) only checks that nothing is recorded when XCL_SUBMIT_STATES is unset; nothing tests recorded, reset or submitted with it on, and the env assertion makes the test fail when the suite runs with XCL_SUBMIT_STATES=1.

Fine: the transition word offsets (resource +8, subresource +16, before/after +20/+24) and split flags match what resource_barrier_x sends after masking and parking; the default path is one relaxed atomic load per hook. Stacked on #3559; the top commit was reviewed.

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

Part B of the plan on xcl-dev#3094 (7298369429): recorded, not used yet.
barrier_groups and alias_copy take a texture's state from what was
recorded last, but the GPU runs lists in the order they are submitted.
submit_states keeps, per recording (a PC list between two resets), the
state it needs each texture in when it starts and the one it leaves it
in, from the words the PC list really gets; and the state each texture is
in after the recordings accepted so far, in submission order (one map for
all queues: a legacy state is the resource's, whichever queue moves it),
advanced only by chunks the driver accepted, from ExecuteCommandLists and
from KickoffX. What D3D12 returns to COMMON when the call ends (all a copy
queue's list used, a buffer, a simultaneous-access texture) is COMMON
there too. What a recording needs and the queue does not have are the
fix-ups part C puts before it.

A split barrier's begin half leaves the texture pending (neither state,
rule 8) at the recording's end; as its first move it gives what the
recording needs at its start (its before-state). A move of one
subresource makes the texture mixed, which keeps today's behaviour. A
recording is forgotten when its list starts another: Reset, a new list at
its address, a KickoffX that submitted it, a mid-list split's next list,
a segment back in the pool, its release.

Off unless XCL_SUBMIT_STATES=1: each hook is one atomic load. The tests
force the switch per thread (on and off), whatever the environment says.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KDenKC
KDenKC force-pushed the feat/submit-states-b branch from a7c1ddd to 04eb807 Compare December 1, 2026 21:15
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up review (head 04eb807, since a7c1ddd, diff read, not a merge-check; draft, checks red):

  • KickoffX submissions never update the queue states: fixed. kickoff_x now calls submit_states::submitted(q_raw, …) after each accepted chunk of earlier segments and after the list itself (list_x.rs ~5403, ~5451), then forgets those recordings (~5416, ~5454).
  • Queued::apply ignores state decay; one global QUEUED: partly fixed. apply now takes a decays predicate and stores COMMON for every resource on a copy queue and for buffers and simultaneous-access textures on any queue (submit_states.rs ~143-158, ~195, ~238), tested by decaying_resources_are_common_after_their_submission (~388). The single map for all queues is kept on purpose (module doc ~8-10, ~188-191), but the description still says "per queue".
  • A recording outlives its list: fixed. submit_states::reset is also called from on_create_with_backing (list_x.rs ~1849), on_release (~1870), clear_segment_state (~1895) and split_recording (~4728).
  • fixups drops textures that end the recording in a split: fixed. The split_pending filter is gone (~128-138), a begin half sets first only when it is the texture's first move (~82), and a_recording_that_ends_in_a_split_still_gets_its_start (~374) covers the case.
  • The hooks are only tested with the switch off: fixed. A thread-local TEST_ON override (~165-177) lets with_the_switch_on_the_hooks_record_reset_and_advance_the_queue (~404) exercise recorded, reset and submitted_on with the switch on, and the off test forces the switch off instead of asserting on the environment.

New:

  • Regression run and Tested are for the previous head. Both xcl-smoke blocks and the test counts are for a7c1ddd3, while 04eb8071 adds runtime hooks in kickoff_x, on_create_with_backing, on_release, clear_segment_state and split_recording; PR description fails on that. The description is also stale elsewhere ("7 unit tests", now 10; "one line each" in list_x.rs; "per queue").

Fine: every list lifecycle path now forgets its recording, KickoffX advances the queue, decay follows the D3D12 rules, and the default path is still one relaxed atomic load per hook.

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

@KDenKC

KDenKC commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@Foniass Thanks, all five were real. Fixed in the one commit, now 04eb8071 (force-pushed; the description is updated):

  1. KickoffX. Both submissions in kickoff_x (the earlier segments and the list itself) now call submit_states::submitted(queue, lists) after the driver accepts them, next to gpu_times::executed. Each submitted list's recording is then forgotten, as lut3d::list_reset is.
  2. State decay, and one map. Queued::apply takes a decay rule. After an accepted submission, everything a copy queue's list used, and any buffer or simultaneous-access texture on any queue, is COMMON in Queued, as D3D12 has it when the call ends. The queue type comes from the queue, the buffer and simultaneous-access facts from the resource's description. (Part C's planner applies the lists of one call without decay, since decay comes only at the call's end.) On "per queue": a legacy state is the resource's, whichever queue moves it, so the single map in submission order is intended. The description said "per queue", which was wrong; it now says what the code does.
  3. A recording outliving its list. The recording is now forgotten wherever list_x resets its own per-list state:
    • list creation (a new list at a released list's address starts empty);
    • Reset;
    • a mid-list split's next list;
    • a segment going back to the pool;
    • a KickoffX that submitted it;
    • release (so entries are freed).
  4. A recording that ends in a split. split_pending now only affects where the recording ends (apply). fixups no longer skips the texture. A begin half that is the texture's first move sets first to its before-state, so SRV→RT then BEGIN_ONLY RT→SRV on a texture the queue has in COPY_DEST gets the COPY_DEST→SRV move. Test: a_recording_that_ends_in_a_split_still_gets_its_start. a_pending_split_is_neither_state now expects the begin half's before-state as the start.
  5. Tests with the switch on. The switch can now be forced per thread, on or off, whatever XCL_SUBMIT_STATES says, and the env assertion is gone.
    • with_the_switch_on_the_hooks_record_reset_and_advance_the_queue drives recorded, submitted (also on a copy queue) and reset with the switch on, including a new recording at a reset list's address.
    • with_the_switch_off_the_hooks_keep_nothing checks the off path.
    • decaying_resources_are_common_after_their_submission covers point 2.
    • cargo test -p xcl --lib -- hle::d3d12x: 1217 passed, 0 failed, 3 ignored, both without and with XCL_SUBMIT_STATES=1 in the environment (RTX 5090).
    • The 3090 runs of 04eb8071 are queued; their results and a new smoke pair replace the old ones in the description.

The parts stacked on this (the fix-up pool and parts C2a and C2b, local drafts) are rebased onto it. In part C2a, the harness's setup() now pins the switch off for its today's-path cases, so the suite also passes with XCL_SUBMIT_STATES=1 set.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

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 area:tests Unit, integration, e2e tests, or testtitle 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.

2 participants