D3D12.X: serialize tile unmapping with texture uploads #799
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!799
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-799"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wayward-tail on GitHub · 2026-11-24 05:36 UTC · original
wayward-tail:pr/upload-unmap-sync→main· +87 −6 · 2 files · 1 commits · draftSuperseded 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
Tested
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 --workspaceandcargo 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.64b3f35: 700 passed, 1 failed, 41 ignored.gpu_clamp_and_omod_per_instructionfails atv_pk_add_i16 clampon unmodified main on this GPU.Regression run
Main:
This branch:
Not tested
XCL_SAMPLE_*game-data variables: unset, so those bodies were not exercised.AI use
@futurepro62 on GitHub · 2026-11-24 07:06 UTC · original
Full-suite run, since this PR has no test report yet. Tested exact head
c9633c6(on its base64b3f35).Tested
cargo build --workspace, thenXCL_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.superseded_unmap_waits_for_in_flight_refresh.Not tested
AI use
@iggyvilla on GitHub · 2026-11-24 07:34 UTC · original
Code read of head
c9633c6(static read only; nothing built or run). The locking itself holds up:refreshkeepsREFRESHacrossupload_batch, which waits on its own fence (gpu/texture.rs), andTEXTURESis dropped beforeREFRESHis taken (title_textures.rs:399unmap_superseded_all), so I see no lock inversion with theREFRESH→PAGESorder inrefresh_once. Two things to consider:The creating thread now waits for a whole refresh.
registerandretire_overlappingrun on the title'sCreatePlacedResourceXpath (device_x.rs:892,:911).unmap_superseded_allmakes that thread wait for the dirty-page scan, the hashes andupload_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 ofrefresh_oncewhileREFRESHis held, which keeps the ordering and does not stall resource creation. Is the stall measured or ruled out on the retail title?Other unmaps are not covered. #640 and #782 add
evict_lru, which callsself.unmap(res, total)underPAGESand not underREFRESH(#782vram.rs:477, #640vram.rs:471). An upload into a texture being evicted can still be in flight onupload_queuewhen its tiles are NULLed, which is the race this PR closes for superseded textures. TakingREFRESHinsidetake_tilewould deadlock (refresh_onceholdsREFRESHand then takesPAGESinvram::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_refreshdecides 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 beforeretire_overlappingand atry_recvtimeout 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 on GitHub · 2026-11-24 23:58 UTC · original
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
mainfc14fab; I have not reproduced it in a run.track()/retire_overlapping()decide underTEXTURESto unmap A, then dropTEXTURESand callvram::unmap_superseded(A).forget(B)likewise decides underTEXTURESto bring A back, drops it, and callsvram::remap_if_unmapped(A). The two vram calls only seet.mappedunderPAGES, so this order is possible:track(B)moves A to shadowed, returnsto_unmap = [A], dropsTEXTURES.forget(B)restores A, returnsto_remap = [A], and callsremap_if_unmapped(A).t.mappedis stilltrue, so it does nothing.unmap_superseded(A)seest.mapped == trueand unmaps A, which is active again. Nothing maps it back.With this PR, the unmap sites take
REFRESHafter droppingTEXTURES. Ifforget()also heldREFRESHfrom before itsTEXTURESsection until afterremap_if_unmapped, and the unmap sites took it before theirTEXTURESsection rather than after, each decision and its vram call would happen as one step, which would close this order too. That keeps the lock orderREFRESH→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 on GitHub · 2026-11-25 10:58 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.