Skip to content

D3D12.X: serialize tile unmapping with texture uploads - #799

Draft
wayward-tail wants to merge 1 commit into
xcl-dev:mainfrom
wayward-tail:pr/upload-unmap-sync
Draft

wayward-tail wants to merge 1 commit into
xcl-dev:mainfrom
wayward-tail:pr/upload-unmap-sync

Conversation

@wayward-tail

@wayward-tail wayward-tail commented Nov 24, 2026 •

Copy link
Copy Markdown

Superseded placed textures can be unmapped on the mapping queue while an internal texture upload is still using them. Serialize those unmaps with REFRESH, acquired after releasing TEXTURES, so active uploads finish first. Related: #594 orders against title queues; this change addresses the separate internal upload queue.

What is in it

  • title_textures.rs: synchronize both superseded-unmap call sites and add a GPU regression test that holds REFRESH while a texture is retired.
  • README note describing the behavior.

Tested

  • Commit c9633c64d11761564b92357e4c06f6cf4d39c686; Windows 11 Home build 26200, AMD Ryzen 7 8845HS, NVIDIA RTX 4060 Laptop GPU (driver 32.0.15.9282), Rust 1.100.0 MSVC, DXC 1.9.2609.5. Tests debug; title smoke release with symbols. XCL_ADAPTER=rtx 4060.
  • cargo build --workspace and cargo build --release -p xcl: succeeded.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 701 passed, 1 failed, 41 ignored. The two wave64 skips below are included in Cargo's passed count.
  • Baseline 64b3f35: 700 passed, 1 failed, 41 ignored. gpu_clamp_and_omod_per_instruction fails at v_pk_add_i16 clamp on unmodified main on this GPU.
  • Branch failures: gpu::recomp::tests::gpu_clamp_and_omod_per_instruction.
  • GPU skips: SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64; SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.

Regression run
Main:

xcl-smoke v1
commit: 64b3f35599bb7102f55d640e1a791e7d6dd3b175
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 989 (PresentX 990)
presents per 2 s (last 3): 50 49 53
device removals: 0
crashes: 0
peak commit: 15068 MB

This branch:

xcl-smoke v1
commit: c9633c64d11761564b92357e4c06f6cf4d39c686
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 801 (PresentX 801)
presents per 2 s (last 3): 12 60 61
device removals: 0
crashes: 0
peak commit: 10590 MB

Not tested

  • AMD / Intel GPU behavior, wave64, gameplay and sustained streaming. The smoke runs exercise startup without menu input.
  • Tests requiring XCL_SAMPLE_* game-data variables: unset, so those bodies were not exercised.
  • Not merge-ready while the full suite has failures; retained as a draft with the upstream baseline failure disclosed.

AI use

  • OpenAI Codex (GPT-6) reconciled the existing local fix with upstream, adjusted the regression test where needed, ran validation, and prepared this description. The existing local commit's original model provenance is unknown.

When a new placement supersedes an older placed texture, register() and retire_overlapping() previously called vram::unmap_superseded() without synchronizing with refresh(). If refresh() was concurrently executing upload_batch() on upload_queue for that texture, Pages.queue could issue UpdateTileMappings(NULL) while CopyTextureRegion was still in flight on upload_queue.

Acquire REFRESH (strictly after dropping TEXTURES, matching refresh()'s lock order) before calling vram::unmap_superseded() so any active upload batch completes and waits on its fence before the superseded tiles are unmapped.
@futurepro62

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head c9633c6 (on its base 64b3f35).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 702 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: superseded_unmap_waits_for_in_flight_refresh.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@iggyvilla

Copy link
Copy Markdown
Contributor

Code read of head c9633c6 (static read only; nothing built or run). The locking itself holds up: refresh keeps REFRESH across upload_batch, which waits on its own fence (gpu/texture.rs), and TEXTURES is dropped before REFRESH is taken (title_textures.rs:399 unmap_superseded_all), so I see no lock inversion with the REFRESH → PAGES order in refresh_once. Two things to consider:

  1. The creating thread now waits for a whole refresh. register and retire_overlapping run on the title's CreatePlacedResourceX path (device_x.rs:892, :911). unmap_superseded_all makes that thread wait for the dirty-page scan, the hashes and upload_batch's fence wait (up to 10 s). The unmap has no deadline of its own (the tiles only go back to the pool), so it could instead be queued and drained at the end of refresh_once while REFRESH is held, which keeps the ordering and does not stall resource creation. Is the stall measured or ruled out on the retail title?

  2. Other unmaps are not covered. D3D12.X: an optional page budget evicts CPU-filled title textures LRU #640 and D3D12.X: the page budget sees textures in use by their T# in the view heaps #782 add evict_lru, which calls self.unmap(res, total) under PAGES and not under REFRESH (D3D12.X: the page budget sees textures in use by their T# in the view heaps #782 vram.rs:477, D3D12.X: an optional page budget evicts CPU-filled title textures LRU #640 vram.rs:471). An upload into a texture being evicted can still be in flight on upload_queue when its tiles are NULLed, which is the race this PR closes for superseded textures. Taking REFRESH inside take_tile would deadlock (refresh_once holds REFRESH and then takes PAGES in vram::before_execute), so the queue-and-drain shape from point 1 would also be the way to cover eviction.

Minor: superseded_unmap_waits_for_in_flight_refresh decides that the spawned thread is blocked by sleeping 30 ms; if the thread is not scheduled in that time the first assert passes without testing the lock. A channel signalled just before retire_overlapping and a try_recv timeout would make it deterministic.

AI use: Claude Code, Claude Sonnet 5.5, read the diff and the code of #640 / #782 at the heads named above and drafted this comment; I checked each line reference.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

A gap next to this change, reported as the second point of #1897 and not covered by #594 or here. I checked it by reading main fc14fab; I have not reproduced it in a run.

track() / retire_overlapping() decide under TEXTURES to unmap A, then drop TEXTURES and call vram::unmap_superseded(A). forget(B) likewise decides under TEXTURES to bring A back, drops it, and calls vram::remap_if_unmapped(A). The two vram calls only see t.mapped under PAGES, so this order is possible:

  1. Thread 1: track(B) moves A to shadowed, returns to_unmap = [A], drops TEXTURES.
  2. Thread 2: forget(B) restores A, returns to_remap = [A], and calls remap_if_unmapped(A). t.mapped is still true, so it does nothing.
  3. Thread 1: unmap_superseded(A) sees t.mapped == true and unmaps A, which is active again. Nothing maps it back.

With this PR, the unmap sites take REFRESH after dropping TEXTURES. If forget() also held REFRESH from before its TEXTURES section until after remap_if_unmapped, and the unmap sites took it before their TEXTURES section rather than after, each decision and its vram call would happen as one step, which would close this order too. That keeps the lock order REFRESH → TEXTURES / PAGES. I'm posting it here rather than as a separate PR because it touches the same call sites.

Written with Claude Code (Claude Opus 5.5).

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants