D3D12.X: wait for title queues before unmapping texture pages #594
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!594
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-594"
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?
@Abdellah-Khanani on GitHub · 2026-11-24 02:17 UTC · original
Abdellah-Khanani:codex/vram-unmap-after-use→main· +138 −5 · 1 files · 1 commits · openFixes #475. Order unmapping of a superseded title texture after work already submitted on the title's command queues, so its pages are not removed while GPU work may still sample it.
What is in it
crates/xcl/src/hle/d3d12x/vram.rs: signal reusable per-queue fences and make the mapping queue wait on them before unmapping. If a fence cannot be established, keep the resource mapped.Tested
cargo test -p xcl --lib superseded_texture_unmap_waits_for_title_queue_work -- --nocapture: 1 passed.cargo test --workspace --no-fail-fast -- --test-threads=4: 640 passed, 1 failed, 21 ignored. The failure isgpu_nonfused_mad_and_mac_prevent_fma_contraction(#472), also reproduced onmain.gpu_geometry_mode_es_gs_stripandgpu_mesh_mode_two_passes(no mesh shaders).Regression run
Main:
This PR:
Not tested
Reviewed by
AI use
@CryingLaughing on GitHub · 2026-11-24 02:36 UTC · original
Tested
3bb3c2fea4ee6a2e74b20e308c328a108ff548acon an RTX 4080 with NVIDIA driver 621.01, Core i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC x64, DXC 1.8.2502.11, debug. The reserved-texture fixture enumerates DXGI adapter 0 directly. The scratch run below confirmed that slot was the RTX 4080.XCL_ADAPTER=4080,XCL_REQUIRE_GPU=1, allXCL_SAMPLE_*variables unset.cargo test -p xcl --lib --locked -j 4 hle::d3d12x::vram::tests::superseded_texture_unmap_waits_for_title_queue_work -- --show-output --test-threads=1passed 1/1. The unmap fence for the synthetic reserved texture stayed pending while the title queue was gated and completed after the gate opened.self.queue.Wait(&fence, value)removed, the test failed 0/1 as expected. The mapping fence already reached the unmap value2while the title queue was still gated. The scratch fixture recorded that value, opened the gate and drained the title queue before asserting the ordering failure.cargo build --workspace --locked -j 4passed.cargo test --workspace --locked -j 4 -- --test-threads=4 --show-outputreported 681 passed, 0 failed, 41 ignored.gpu_nonfused_mad_and_mac_prevent_fma_contractionpassed on this setup. The count includes opt-in game-data tests that returned early and four explicit capability skips.gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardwarerequire native wave64.test_title_draws_with_a_root_signature_under_the_debug_layeranduploads_start_from_each_subresources_staterequire the D3D12 debug layer.Not tested
AI use
@upipibi on GitHub · 2026-11-24 04:55 UTC · original
A possible GPU deadlock in
3bb3c2f, found by reading the code (not run):unmapnow makes the mapping queue wait for a marker signalled on every title queue (vram.rs:322-346), and then raisespages.value.before_execute(:600-612) makes the next work on every title queue wait forpages.value. Together they form a cycle when a title queue is held by a signal that a later submission on another queue provides, which is the pattern #433 deals with:Q1.Wait(F, n), whereF = ncomes from work it will submit onQ2later.unmapqueuesQ1.Signal(M1, k)behind that wait,mapQ.Wait(M1, k), the NULL mapping, andmapQ.Signal(pages.fence, v + 1).Signal(F, n)onQ2.before_execute(Q2)first insertsQ2.Wait(pages.fence, v + 1).Now
Q2waits for the mapping queue, the mapping queue waits forQ1's marker, andQ1waits forF, which onlyQ2can signal. That hangs both queues (TDR / device removed). Before this PR the mapping queue never waited on title queues, so there was no cycle.One way out: don't wait on the GPU. Record each title queue's marker value at supersede time, then do the NULL mapping later from the CPU, once every marker's
GetCompletedValuehas passed (polled from the nextbefore_execute, or by the existing worker). The pages stay mapped slightly longer, but no queue ever waits for an unmap. Separately, a title queue doesn't need to wait for an unmap at all, only for maps, so unmaps could stop bumping the valuebefore_executewaits on. That alone doesn't remove the cycle if a later map is queued behind the unmap.The liveness of
known_queues()is fine:QUEUESholds a reference, as fordrain_gpu.AI-assisted (Claude Code), read-only review.
@Abdellah-Khanani on GitHub · 2026-11-24 09:47 UTC · original
Run data that fits the cycle @upipibi describes. I don't have a trace that proves this cycle is the cause.
Tested
cargo test --workspace --no-fail-fast -- --test-threads=4.3bb3c2frebased ontomaindd2ae9a, with only the new test changed so that a failure can't abort the binary:UMA import check: ... GPU fence still pending after 2000 mscame first, thenD3D12 device removed: 0x887a0007;0x887A0005(82 and 80 FAILED lines).maindd2ae9awithout the PR, the same command right after: 649 passed, 1 failed, 21 ignored in the lib (the failure is #472, which also fails onmainon RDNA1), and no hang.3bb3c2fon its own base508a0c7passed the whole suite without a hang. So the hang either needs the newermain, or it is timing-dependent and those runs were lucky.Not tested
The new test itself does what it should here: it passes with the wait, and it fails without it.
Claude Code (Claude Opus 5.5) ran the tests and wrote this comment; I checked it.
@Ali-AbdulHadii on GitHub · 2026-11-24 12:29 UTC · original
Run data and thread dumps confirming the cycle @upipibi described, plus a variant that avoids it.
Setup: Linux, RTX 5080 (NVIDIA 620.73.04), proton-cachyos-slr Wine, vkd3d-proton master
30b0eb9+ the repo patch. XCL: a local branch ofmainwith this PR merged (plus #640 and others), retail title 1.0.2.1 in its world.What happened with this PR merged: in the world, one frame every ~6 s. The fence bridge's 5 s watchdog released a
Wait64BitValueXGPU wait every ~6 s, and every present came ~0.3 s after a release (29–36 releases per run).Thread dumps (
XCL_THREAD_DUMP_AT=160,190), the same in both: the title's submitting thread is inreal::q_execute_command_lists → title_textures::refresh → texture::upload_batch → gpu::fence::wait. So the cycle is:Wait64BitValueX) for a counter that a list on the title's graphics queue writes;unmapmakes the mapping queue wait for a marker on every title queue, so it also waits for that compute queue;vram::before_executemakes the upload queue wait for the mapping queue's fence;A variant without the cycle: keep the markers, but make the CPU hold the unmap instead of the mapping queue.
unmapsignals the markers on the title queues, records(resource, total, markers)in a list holding a reference to the resource, and returns. The held unmaps whose markers have all completed are made at the nextbefore_execute, and mapping the resource again drops its held unmap. XCL's queues then never wait for a title queue. Your GPU test still holds: the unmap is not made before the gated queue passes its marker. I added a check that the mapping queue stays free meanwhile.After: 0 watchdog releases at the same point of the next run, and frames no longer stall in step with them.
Not tested: Windows, AMD.
AI use: Claude Code (Claude Opus 5.5) diagnosed this, wrote the local change and this text; the user approved posting it.
@JJAutoCompare on GitHub · 2026-11-25 06:43 UTC · original
Empirical test report (
3bb3c2fe)Hardware / environment
Commit
3bb3c2fea4ee6a2e74b20e308c328a108ff548ac. Windows 11 Enterprise Evaluation, build 26200. AMD Ryzen 7 3800X. DXGI adapter 0 was Intel Arc A770 Graphics (driver 32.0.101.9175) in a separate enumeration probe. Rust 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc), DXC 1.9.2609.5 (01b62ad47). Unoptimized Cargo test profile, debug info and incremental compilation disabled.Commands and results
cargo test --workspace --no-runexited 0 and built the test binaries.$prefixishle::d3d12x::vram::tests::.XCL_ADAPTER=NONE_CPU_ONLYexited 0. 5 passed, 0 failed, 0 ignored, 0 skipped.Invoke-ArcTest.ps1withXCL_ADAPTER=A770andRUST_TEST_NOCAPTURE=1. Each exited 0 with libtest reporting 1 passed, 0 failed, 0 ignored. Each skipped the test body. The log has one case-sensitive^SKIPPEDline from the terse rerun and one inline skip marker from the first attempt.Observed behavior
Both GPU attempts reported
no GPUat the test's capability gate. The queue-wait assertions were never reached.Not tested
GPU unmap ordering, the full GPU workspace suite, and game smoke runs.
AI use
Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr594-focused.log and published.
@Dezmonius on GitHub · 2026-11-25 11:40 UTC · original
Targeted GPU check on RTX 5070 / Windows 10. Unchanged
3bb3c2fea4ee6a2e74b20e308c328a108ff548ac, Rust 1.100.0 MSVC, release, RTX 5070 driver 610.88 (32.0.16.1088), Windows 10 build 19045.superseded_texture_unmap_waits_for_title_queue_workpassed in 3/3 fresh processes, with no skips (0.38–0.44 s per run). In this fixture, the unmap fence stayed pending while the title queue was held and completed when the gate opened.On the same adapter, I separately observed
0x887A0006in the concurrent case of the #2057 synthetic probe. The #594 result only covers the single-queue ordering assertion. The multi-queue cycle described in review, the title, and the whole suite were outside this run.AI-assisted (Codex) for running the existing test and preparing this comment. Synthetic data only.
@joeypercia on GitHub · 2026-11-25 11:55 UTC · original
@Abdellah-Khanani @upipibi @Ali-AbdulHadii #2270 implements the CPU-held variant discussed here, on current
main. A mark goes on every title queue and upload queue, and the unmap waits until the CPU sees every mark done (made inbefore_execute). The mapping queue never waits on a title queue. Credited to this thread.The new reason for it: a synthetic probe on #2057 that flips a reserved texture's tiles to NULL while copies to it run gives
0x887A0006on an RTX 5070. It passes on an RTX 3070 and an RTX 4070 Ti. If you'd rather update #594 with this, say so, and I'll close mine.AI use: Claude Code (Claude Opus 5.5) wrote this comment.
@DavidM1911 on GitHub · 2026-11-25 13:07 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.