Skip to content

D3D12.X: unmap a superseded texture only once the work before it is done - #2270

Open
joeypercia wants to merge 1 commit into
xcl-dev:mainfrom
joeypercia:d3d12x-held-unmaps
Open

joeypercia wants to merge 1 commit into
xcl-dev:mainfrom
joeypercia:d3d12x-held-unmaps

Conversation

@joeypercia

@joeypercia joeypercia commented Nov 25, 2026 •

Copy link
Copy Markdown

vram::unmap_superseded NULL-maps a placed texture's tiles on the tile-mapping queue the moment a newer placement covers it. Nothing orders that against work already submitted that copies to or samples the texture. Changing a reserved texture's mappings under a copy that's running removes the device on at least one NVIDIA Blackwell card. With the probe, which copies on one queue while the mapping flips to NULL on another:

  • RTX 5070 (driver 610.88): 0x887A0006 after 1.8 s (Dezmonius).
  • RTX 3070 (616.56): all 20 rounds finish (upipibi).
  • RTX 4070 Ti (621.40): all 20 rounds finish.

Title runs on #2057 on an RTX 5080 and an RTX 3080 Ti end in a DRED page fault on a live texture inside a run of CopyTextureRegions (kanade333, dhillonjagdeep650-boop). This race is a cause that fits; whether it's the cause of those runs is not shown yet.

Update: on an RTX 5080 (driver 621.40), @kanade333 ran #2057 with and without this PR, two runs each. One run with it was still removed by the same fault (0x887a0006, DRED page fault at VA 0x0 inside a run of CopyTextureRegions), and one without it reached the 420 s limit. So this race isn't, or isn't the only, cause of that in-world fault, and the probe passes on that card with that driver. What this PR fixes is the race the probe shows on the RTX 5070.

Now unmap_superseded puts a mark (a fence signal) on every queue the title submitted to and on XCL's upload queues. The unmap, with the return of the texture's tiles to the pool, waits in a list until the CPU sees every mark done. before_execute makes the ones that are. The mapping queue never waits for a title queue. That is the cycle found in #594: a title queue waiting for work submitted later on another queue, which waits behind the mapping queue. The design is @upipibi's from #594 and the variant @Ali-AbdulHadii ran there. #594 itself (@Abdellah-Khanani) waits on the GPU and conflicts with main now. This PR replaces that approach, and I'm happy to close it in favour of an update of #594 if its authors prefer.

Part of #1773. Related: #475, #594.

What is in it (crates/xcl/src/hle/d3d12x/vram.rs, one commit)

  • Pages::mark (a reusable fence per queue), HeldUnmap and Pages::release_held. unmap_superseded holds the unmap. If a mark can't be made, the texture stays mapped, as before any unmap.
  • before_execute makes the held unmaps whose marks are done. Their textures are let go of after PAGES is unlocked, because the last reference's release comes back to forget_pages.
  • remap_if_unmapped drops a held unmap: the texture never lost its tiles.
  • GPU test a_superseded_texture_keeps_its_tiles_until_the_work_before_it_is_done. A title queue's submitted work is held behind a fence. The superseded texture keeps its tiles until that work is done and gets no NULL mapping before then, then the tiles go back. A texture mapped again before its unmap keeps its tiles, and its unmap is dropped. With the unmap made at once (as on main), the test fails at "no unmap yet".

Tested

  • NVIDIA GeForce RTX 4070 Ti (Ada), driver 621.40, and the AMD Radeon iGPU of a Ryzen 7 7800X3D (RDNA2) with XCL_ADAPTER=Radeon; Windows 11 Pro 26200; Rust 1.100.0 MSVC; DXC 1.8.2502.11; debug for the tests, release for the runs.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on b7f6b76:
    • RTX 4070 Ti: 1251 passed, 0 failed, 46 ignored.
    • RDNA2: 1250 passed, 1 failed, 46 ignored. The failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, which fails the same way on main 1a0bbe3 on this iGPU (DXIL fuzz tests: fuzz_validate_and_gpu_1 fails on AMD (seed 722 and others, RDNA2-4), so the default suite is red there #2115).
    • The new test ran on both adapters (... ok), not skipped.
    • SKIPPED: RTX 4070 Ti: the wave64 cases of the lower / lower_dxil GPU tests, gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64). RDNA2: the mesh-shader tests. Both: heap_window_out_of_memory_falls_back_to_the_switch_form, pso_measurement_compiles_an_exact_synthetic_record (no Developer Mode), test_title_draws_with_a_root_signature_under_the_debug_layer, uploads_start_from_each_subresources_state, and the lower_dxil f16 / f32 cases the direct backend refuses.

Regression run

RTX 4070 Ti (driver 621.40), release builds, 60 s each, scripts/smoke.ps1 -Game <folder> -Title retail-title on the newer retail title, one after the other from the same shell with the same settings. main 1a0bbe3 (this PR's base) and this PR's head (no uncommitted changes):

main:

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1537 (PresentX 1538)
presents per 2 s (last 3): 60 60 52
device removals: 0
crashes: 0
peak commit: 16109 MB

PR:

xcl-smoke v1
commit: b7f6b760e2ce94f68a05ed7c5aeac0360abac1b0
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1586 (PresentX 1587)
presents per 2 s (last 3): 60 60 51
device removals: 0
crashes: 0
peak commit: 16445 MB

Not tested

  • On a GPU where the race removes the device (the RTX 5070 / 5080 above). I don't have one. The fix is checked by the GPU test, not by a run that used to fail. A test of this branch on one of those cards, in the title or with the probe's r_null_during_copyq turned into XCL calls, would settle it.
  • Work submitted after the texture was superseded that still uses it. The marks only cover work submitted before. XCL's own uploads into a superseded texture stop at that point (title_textures shadows it).
  • AMD in the title (the test ran on an RDNA2 iGPU).

AI use

`unmap_superseded` NULL-mapped a placed texture's tiles on the tile-mapping
queue the moment a newer placement covered it, with nothing ordering that
against work already submitted that copies to or samples the texture. On
NVIDIA Ampere and Blackwell GPUs a reserved texture whose tiles go NULL
while a copy into it runs removes the device: the synthetic probe on xcl-dev#2057
(copies on one queue, the mapping flipped to NULL on another) gives
0x887a0006 on an RTX 5070 after 1.8 s, and passes on an RTX 4070 Ti (Ada).
Title runs on xcl-dev#2057 on those GPUs end in a DRED page fault inside a run of
CopyTextureRegion on a live texture.

A mark (a fence signal) now goes on every title queue and upload queue, and
the unmap, with the return of the texture's tiles, waits in a list until
the CPU sees every mark done; `before_execute` makes the ones that are.
The mapping queue never waits for a title queue, so the cycle found in
xcl-dev#594 (a title queue waiting for work submitted later, behind the mapping
queue) can't form. The design is upipibi's and Ali-AbdulHadii's from xcl-dev#594.
A texture mapped again before its unmap is made keeps its tiles.
@kanade333

Copy link
Copy Markdown

RTX 5080 16 GB (Blackwell), driver 621.40: two runs with this PR and two without, on #2057's head. One of each was removed and one of each ran to the 420 s limit, so on this card these runs show no difference either way. The probe passes all 13 cases here.

@joeypercia, thanks for the probe and the fix. Numbers below.

Setup: NVIDIA GeForce RTX 5080 16 GB (driver 621.40), AMD Ryzen 9 9950X, 32 GB RAM, Windows 11 Pro 26200, release. Retail title of #505, 1.0.2.1, XCL_NETWORK=0, scripted A presses.

Trees

  • "without": D3D12.X: integration branch that reaches the in-world HUD on NVIDIA (reference, not for merge) #2057 at 4df1e6e, unchanged.
  • "with": 4df1e6e + this PR's commit b7f6b76. It applies with one conflict in vram::before_execute, where main has since added the heap reclaim of 5a515f0. I kept 4df1e6e's body and added only this PR's part: release_held(now) under PAGES, and the released textures dropped after the lock. cargo test --release -p xcl --lib -- d3d12x::vram --test-threads=4 on it: 12 passed, 0 failed, 1 ignored.

Probe (b39608e, release, one process per case, before the title runs): all 13 complete with no removal. The 10 fixed-mapping cases read every mapped word right and zeros from NULL tiles. The three concurrent cases finish their 20 rounds in 0.4 s (r_null_during_copyq, 1,258 remaps), 0.1 s (r_null_during_direct, 252) and 0.4 s (r_other_tiles_during_copyq, 820). The copies end so fast on this card that the remaps have little time to land in the middle of one, so this does not show the race is harmless here.

Title runs, all with XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_UMA_SHADOW=1 XCL_COHERENT_HEAPS=sparse:16 XCL_COHERENT_MB=512 XCL_LOOK_SKIP=1 XCL_WATCH_HOT=0 XCL_DRED=1 XCL_RUN_SECONDS=420, warm caches (all 2,689 compute pipelines built ahead with this driver), one after the other:

run tree presents after 62 s end
33 without 241 0x887a0006 at 379.3 s
34 with 1,295 ran to 420 s
35 with 0 (removed before the world) 0x887a0006 at 55.6 s
36 without 2,285 ran to 420 s
  • All three removals: DRED page fault at GPU VA 0x0; allocations there: []; recently freed: [], with the list in flight inside a run of CopyTextureRegion (breadcrumbs 8 8 8 >8 8 8; 6 of 19 and 15 of 39 operations done). On driver 610.88 this morning the same tree's two DRED runs faulted at an address inside a live resource instead (my comment on D3D12.X: integration branch that reaches the in-world HUD on NVIDIA (reference, not for merge) #2057), also in CopyTextureRegions.
  • 0 GPU-wait time-outs, 0 watchdog releases, 0 failed DirectStorage requests in all four.
  • Local video memory peaked at 17.2–20.3 GB.
  • Runs 34 and 36 both have long stretches with no present and no submit (from about 235 s on in 34; 240–330 s in 36, which then picked up again). In the thread dump at 250 s in 36, the title's worker threads sit in waits called from its own code (+0x221c3c2); I have not looked further.

I could not tell from the log whether an unmap was actually held in runs 34 and 35: nothing logs it.

Not tested: more than two runs per tree; this PR on main; another Blackwell card; whether an unmap was held.

AI use: Claude Code (Claude Opus 5.5) built the trees, ran the probe and the title on this machine, and wrote this report.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent Windows verification of exact PR head b7f6b760e2ce94f68a05ed7c5aeac0360abac1b0, with a paired owned-title smoke run against its base, main 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. Isolated Cargo targets; clean PR worktree. No game files were copied or attached.

GPU regression test: XCL_ADAPTER=6800M XCL_REQUIRE_GPU=1 XCL_DIRECT_DXIL=1 cargo test --locked -p xcl --lib -j 2 a_superseded_texture_keeps_its_tiles_until_the_work_before_it_is_done -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored. The test emitted D3D12 device/queue/resource and sparse-VRAM setup logs, then completed the held-unmap assertions. This fixture calls EnumAdapters1(0) directly, so XCL_ADAPTER does not select its GPU; I did not verify the name of adapter 0. The result is a hardware-adapter test result, not a confirmed RX 6800M result.

Release and title regression run: cargo build --locked --workspace --release -j 2 passed on the clean PR head. I ran scripts/smoke.ps1 through a process and memory guard for 12 seconds per revision, with the same owned title and XCL_ADAPTER=6800M, default translation mode, and separate fresh data/cache directories. Neither run hit the guard.

Main:

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 12
exit: 0x0
frames shown: 111 (PresentX 111)
presents per 2 s (last 3): 1 50 60
device removals: 0
crashes: 0
peak commit: 8162 MB

PR head:

xcl-smoke v1
commit: b7f6b760e2ce94f68a05ed7c5aeac0360abac1b0
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 12
exit: 0x0
frames shown: 113 (PresentX 113)
presents per 2 s (last 3): 0 53 60
device removals: 0
crashes: 0
peak commit: 8230 MB

Limits: These brief startup runs do not establish whether the title exercised the superseded-texture unmap path, and frame counts are not a performance comparison. I did not run the full workspace suite on this PR head; the author reports it separately. The focused fixture's exact GPU identity remains unverified because it hard-codes DXGI adapter 0.

AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows test and release build, monitored the paired title runs, checked the clean exact head, and drafted this report. No game data was uploaded.

@joeypercia

Copy link
Copy Markdown
Author

@kanade333 thanks, that's the result that was missing. Run 35 shows the in-world copy fault still happens with this PR, so this race isn't, or isn't the only, cause of it. I've added your runs to the description and narrowed what the PR claims to the race the probe shows on the RTX 5070.

A held unmap isn't logged, as you found. A count of held and released unmaps under XCL_ACTIVITY=1 would answer that. I'll add it as its own diagnostic PR rather than here, so this one's smoke runs stay valid.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

@GustavoEllwanger

Copy link
Copy Markdown
Contributor

Independent dual-GPU Windows verification on exact PR head b7f6b760e2ce94f68a05ed7c5aeac0360abac1b0 (parent 1a0bbe3), including NVIDIA Blackwell hardware.

Tested

  • Host / toolchain: AMD Ryzen 7 7700, Windows 11, Rust 1.95.0 (59807616e 2026-04-14), DXC 1.8.2502.11, debug build.
  • NVIDIA GeForce RTX 5060 (Blackwell, driver 32.0.16.1088):
    • XCL_ADAPTER=5060 cargo test -p xcl --lib hle::d3d12x::vram:: -- --nocapture --test-threads=1: 16 passed, 0 failed, 1 ignored (churn_update_tile_mappings_timing), 0 skipped — a_superseded_texture_keeps_its_tiles_until_the_work_before_it_is_done passed with no device removal.
    • XCL_ADAPTER=5060 cargo test -p xcl --lib hle::d3d12x:: -- --test-threads=4: 212 passed, 0 failed, 2 ignored, 0 skipped.
    • XCL_ADAPTER=5060 cargo test --workspace -- --test-threads=4: 1251 passed, 0 failed, 46 ignored (27 runtime SKIPPED: 20 native-wave64 tests on wave32 NVIDIA, 3 per-lane #1426 refusals, 2 missing D3D12 debug layer, 1 Developer Mode cache-disable, 1 heap windows).
  • AMD Radeon(TM) Graphics (RDNA2 iGPU, driver 32.0.21042.62):
    • XCL_ADAPTER=Radeon cargo test -p xcl --lib hle::d3d12x::vram:: -- --nocapture --test-threads=1: 16 passed, 0 failed, 1 ignored, 0 skipped.
    • XCL_ADAPTER=Radeon cargo test -p xcl --lib hle::d3d12x:: -- --test-threads=4: 212 passed, 0 failed, 2 ignored, 1 runtime SKIPPED (passthrough_mesh_stream_accepts_a_triangle_driver_blob: no mesh shaders).

Not tested

  • Retail title run (scripts/smoke.ps1), the separate #2057 stress probe, full AMD workspace run, Intel GPUs, non-Windows hosts.

AI use

  • Antigravity (Google Gemini): checked out PR head b7f6b76, ran the focused vram/d3d12x suites on both GPUs plus the full RTX 5060 workspace suite, and wrote this report from the raw logs.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

AMD RDNA3 (native wave64) test report for exact head b7f6b760e2ce94f68a05ed7c5aeac0360abac1b0, as pushed (not merged onto current main).

Tested

  • AMD Radeon RX 7800 XT (RDNA3, native wave64), driver 32.0.31035.1003; Windows 11 Pro 10.0.26200; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.0.5512 (dxcompiler.dll)
  • cargo build --workspace: ok
  • Targeted: a_superseded_texture_keeps_its_tiles_until_the_work_before_it_is_done: 1 passed; vram filter: 18 passed, 0 failed, 1 ignored
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1250 passed, 1 failed, 46 ignored (summed over all test binaries)
  • SKIPPED: 7 lines in the full run (6 `lower_dxil` f16/f32 per-lane-form cases "refused (unsupported V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32 ... gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics)", plus `heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows`). The one failure is `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` (seed 722: res[30] = 0x1, CPU 0x7fffffff). It is not in code this PR touches, and I reproduced the same failure and seed on `main` at `1a0bbe3` with `cargo test -p xcl --lib fuzz_validate_and_gpu_1`, so it is pre-existing on RDNA3, not caused by this PR.

Not tested

  • No game title, no scripts/smoke.ps1 regression run (synthetic GPU/unit tests only)
  • Not merged onto current main; other GPUs (NVIDIA / Intel / RDNA2 / RDNA4)
  • Whether the new test fails without the fix (I did not revert it)

AI use: Claude Code (Claude Sonnet 5.5) ran the build and tests and wrote this report; the numbers are from the runs above.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2296, xcl-dev#2297, xcl-dev#2320, xcl-dev#2323, xcl-dev#2329, xcl-dev#2333

Integrates shader heap-base addresses (xcl-dev#1803), fenced superseded texture unmaps (xcl-dev#2270), cross-queue VRAM heap reclamation fencing (xcl-dev#2275, using create_raw_fence under Wine), PcCall frame clamping and orphan PSO drop (xcl-dev#2296), PSO pointer guards (xcl-dev#2297), KickoffX idle spare list switching (xcl-dev#2320, preserving UnadoptGuard), console-list descriptor heap binding (xcl-dev#2323), ClearUnorderedAccessView PC handles (xcl-dev#2329), and dispatch_chain PSO retention (xcl-dev#2333).
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
Integrates upstream PR xcl-dev#2306 (opt-in per-level texture page allocation via XCL_TEXTURE_LEVEL_PAGES=1), composed cleanly with xcl-dev#2270's HeldUnmap.
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@bstillbstill

bstillbstill commented Nov 25, 2026 •

Copy link
Copy Markdown

Test report on an RTX 3090 Ti (Ampere): with this PR on #2057 the retail title's silent 0x887a0005 at the world
load still comes, at the same time as without it.
Three runs with it, two without, same day, same settings.

Setup

run this PR world load (first 2 s with ≥ 1,000 dispatches) removed (0x887a0005) frames shown after 64 s
h1 yes 68 s 132.9 s 490
h2 yes 64 s 128.9 s 484
h3 yes 64 s 105.3 s 335
b1 no 64 s 130.3 s 468
b2 no 64 s 96.8 s 243
  • All five end the same way: no queue wait timed out, no watchdog release, then the silent removal and the title's
    0x80000003. The scene stays grey in all of them.
  • The same "without" build was removed after 11–18 s in the world the night before (g4–g6 on #2057:
    73.6 s and 83.3 s, one freeze at 82 s); here it lasts 33–66 s. Something besides this PR moves that time between days, so
    only same-day runs are compared above.
  • cargo test -p xcl --lib hle::d3d12x::vram -- --test-threads=4 on the merged tree (debug): 12 passed,
    0 failed, 1 ignored
    (churn_update_tile_mappings_timing), including
    a_superseded_texture_keeps_its_tiles_until_the_work_before_it_is_done; nothing skipped.
  • Your probe (probe/reserved-copy-faults at b39608e, debug, one process per case as in your loop): all 13
    cases pass, no removal.
    Mapped tiles read back right and NULL tiles read 0; r_null_during_copyq,
    r_null_during_direct and r_other_tiles_during_copyq ran all 20 rounds with 20,900 / 24,628 / 15,808 remaps.
    So the race doesn't remove the device on this card (as on the 3070 and 4070 Ti), which fits this PR changing
    nothing in the runs above.

Not tested: this PR on its own head or with
main merged (as in the RTX 5070 Ti run on #2057); the whole suite; AMD.

AI use: Claude Code (Claude Opus 5.5) merged the trees, ran everything above and wrote this report.

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.

8 participants