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

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant