Title textures: uploads start from the state the title's transitions left (#104 item 2) #135

Manually merged
github merged 1 commit from gh-pr/135/head into gh-pr/135/base 2026-11-26 04:11:56 +00:00
Owner

@⁠tiagonleal on GitHub · 2026-11-23 14:45 UTC · original
tiagonleal:fix/title-texture-states → main · +354 −18 · 6 files · 1 commits · merged 2026-11-23 21:08 UTC

#104 item 2, the state part ("a PR that tracks the title's transitions for kept-in-step textures would be welcome").

A texture kept in step with title memory (title_textures) was uploaded again with barriers from and back to the state it was created in. Once the title had moved it – COMMON → PIXEL_SHADER_RESOURCE, or one mip to COPY_SOURCE – the upload's "before" state was wrong. The D3D12 debug layer reports exactly that (from the new test):

ExecuteCommandLists: Using ResourceBarrier on Command List (…): Before state (0xC0: NON_PIXEL_SHADER_RESOURCE|PIXEL_SHADER_RESOURCE)
of resource (…) (subresource: 1) specified by transition barrier does not match with the state (0x800: COPY_SOURCE)
specified in preceding ResourceBarrier or as InitialState

Change

  • Noted as recorded: the title's transitions of textures kept in step are noted per PC command list – in resource_barrier_x (after the console → PC state masking) and in console lists' barrier replay at Close (which re-records the whole list, so its notes start over there).
  • Applied when submitted: ExecuteCommandLists (after the PC submit, on the mapped PC lists) and KickoffX apply them to the texture's state in submission order – each time a closed list runs. Reset, create and release forget a list's notes.
  • Per subresource: the state is one value while every subresource has it, one per subresource (D3D12 order) while they differ. The upload's barriers follow it: texture::record_upload_states (one barrier for all subresources when uniform, as before; else one per subresource that changes). upload_batch items carry those states; record_upload keeps its signature.
  • Only textures already kept in step are noted (title_textures::any() first, then a lookup), so lists without them cost one atomic load per ResourceBarrier call.

Implicit promotion / decay needs nothing extra: a texture promoted to a read state decays back to COMMON at the end of the ExecuteCommandLists call, which is the state still noted; a texture promoted to COPY_DEST by a copy is GPU-written and is not uploaded again (note_gpu_write).

Not in this PR: the queue sync half of #104 item 2

The upload still runs on XCL's queue without a GPU wait for title work that may still sample the texture. Fixing that by making the upload queue wait for the title's queues would make the CPU's existing wait on the upload wait for the title's frames in flight too – a stall on every refresh with a dirty texture while a game streams. Doing it without the stall means having the title's queue GPU-wait on the upload fence, with the staging buffers kept alive until it passes. That is a separate change, and it should be measured on a game, which I can't run here.

Tests

  • title_textures::tests::transitions_per_subresource_and_back_to_one_state – the state per subresource, collapsing back to one.
  • title_textures::tests::transitions_apply_when_their_list_is_submitted – notes count only once submitted, in submission order, again when a closed list runs again, not after Reset; other resources are not noted. The test entry is GPU-written, so a concurrent refresh never touches its fake pointer.
  • tests/texture_states.rs (its own process: the debug layer must be on before the first device) – a 4-mip texture in shader-resource states with mip 1 moved to COPY_SOURCE: an upload with each subresource's state gives 0 debug-layer errors and leaves them in their states; with one state for all of them (what uploads did before) the debug layer reports the mismatch above, so the check is a real one. It skips without the debug layer (Graphics Tools) or a GPU.

Run: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1742, Windows 11 Pro 26300, rustc 1.99.1. cargo test --workspace --no-fail-fast -- --test-threads=4 on main 95bda11: 551 passed, 0 failed, 37 ignored; 2 SKIPPED …: no wave64.

Not run: a game. The hooks only add notes and apply them; uploads of textures the title never transitions get the same barriers as before.

AI-assisted.

🤖 Generated with Claude Code

**@⁠tiagonleal** on GitHub · 2026-11-23 14:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/135) `tiagonleal:fix/title-texture-states` → `main` · +354 −18 · 6 files · 1 commits · merged 2026-11-23 21:08 UTC #104 item 2, the state part ("a PR that tracks the title's transitions for kept-in-step textures would be welcome"). A texture kept in step with title memory (`title_textures`) was uploaded again with barriers from and back to the state it was **created** in. Once the title had moved it – `COMMON → PIXEL_SHADER_RESOURCE`, or one mip to `COPY_SOURCE` – the upload's "before" state was wrong. The D3D12 debug layer reports exactly that (from the new test): ``` ExecuteCommandLists: Using ResourceBarrier on Command List (…): Before state (0xC0: NON_PIXEL_SHADER_RESOURCE|PIXEL_SHADER_RESOURCE) of resource (…) (subresource: 1) specified by transition barrier does not match with the state (0x800: COPY_SOURCE) specified in preceding ResourceBarrier or as InitialState ``` ### Change - **Noted as recorded:** the title's transitions of textures kept in step are noted per PC command list – in `resource_barrier_x` (after the console → PC state masking) and in console lists' barrier replay at `Close` (which re-records the whole list, so its notes start over there). - **Applied when submitted:** `ExecuteCommandLists` (after the PC submit, on the mapped PC lists) and `KickoffX` apply them to the texture's state in submission order – each time a closed list runs. `Reset`, create and release forget a list's notes. - **Per subresource:** the state is one value while every subresource has it, one per subresource (D3D12 order) while they differ. The upload's barriers follow it: `texture::record_upload_states` (one barrier for all subresources when uniform, as before; else one per subresource that changes). `upload_batch` items carry those states; `record_upload` keeps its signature. - Only textures already kept in step are noted (`title_textures::any()` first, then a lookup), so lists without them cost one atomic load per `ResourceBarrier` call. Implicit promotion / decay needs nothing extra: a texture promoted to a read state decays back to COMMON at the end of the `ExecuteCommandLists` call, which is the state still noted; a texture promoted to `COPY_DEST` by a copy is GPU-written and is not uploaded again (`note_gpu_write`). ### Not in this PR: the queue sync half of #104 item 2 The upload still runs on XCL's queue without a GPU wait for title work that may still sample the texture. Fixing that by making the upload queue wait for the title's queues would make the CPU's existing wait on the upload wait for the title's frames in flight too – a stall on every refresh with a dirty texture while a game streams. Doing it without the stall means having the title's queue GPU-wait on the upload fence, with the staging buffers kept alive until it passes. That is a separate change, and it should be measured on a game, which I can't run here. ### Tests - `title_textures::tests::transitions_per_subresource_and_back_to_one_state` – the state per subresource, collapsing back to one. - `title_textures::tests::transitions_apply_when_their_list_is_submitted` – notes count only once submitted, in submission order, again when a closed list runs again, not after `Reset`; other resources are not noted. The test entry is GPU-written, so a concurrent `refresh` never touches its fake pointer. - `tests/texture_states.rs` (its own process: the debug layer must be on before the first device) – a 4-mip texture in shader-resource states with mip 1 moved to `COPY_SOURCE`: an upload with each subresource's state gives **0** debug-layer errors and leaves them in their states; with one state for all of them (what uploads did before) the debug layer reports the mismatch above, so the check is a real one. It skips without the debug layer (Graphics Tools) or a GPU. Run: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1742, Windows 11 Pro 26300, rustc 1.99.1. `cargo test --workspace --no-fail-fast -- --test-threads=4` on `main` 95bda11: 551 passed, 0 failed, 37 ignored; 2 `SKIPPED …: no wave64`. Not run: a game. The hooks only add notes and apply them; uploads of textures the title never transitions get the same barriers as before. _AI-assisted._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A texture kept in step with title memory was uploaded again with
barriers from (and back to) the state it was created in. Once the title
had moved it (COMMON -> PIXEL_SHADER_RESOURCE, one mip to COPY_SOURCE…)
the upload's "before" state was wrong; the D3D12 debug layer reports
exactly that (before state 0xC0 of subresource 1 does not match 0x800).

The title's transitions of these textures are noted per PC command list
as they are recorded (ResourceBarrier, console lists' replay at Close)
and applied to the texture's state when the list is submitted
(ExecuteCommandLists, KickoffX), in submission order and each time a
closed list runs; Reset / create / release forget a list's notes. The
state is kept per subresource while they differ, and the upload's
barriers follow it (texture::record_upload_states).

Tests: title_textures unit tests (state per subresource; notes apply on
submit, in order, again on re-submit, not after Reset), and
tests/texture_states.rs (own process, D3D12 debug layer): per-subresource
states give no error, the creation state for all gives the mismatch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:11:54 +00:00
github manually merged commit c8d9549c88 into gh-pr/135/base 2026-11-26 04:11:56 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 21:08 UTC · original

Merged (main 6da33fa). Checked on an RX 9070 (RDNA4) with the 22 PRs merged together on main eaa36b6: cargo build --workspace && cargo test --workspace -- --test-threads=4 - 582 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed too; and the retail game still reaches its first menu (646 frames in 30 s, no device removal).

**@⁠ivall** on GitHub · 2026-11-23 21:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/135#issuecomment-7114070766) Merged (main 6da33fa). Checked on an RX 9070 (RDNA4) with the 22 PRs merged together on main eaa36b6: `cargo build --workspace && cargo test --workspace -- --test-threads=4` - 582 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed too; and the retail game still reaches its first menu (646 frames in 30 s, no device removal).
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-23 14:45 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-23 14:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/135#pullrequestreview-6023666152) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
This discussion has been locked. Commenting is limited to contributors.
No description provided.