Sparse tile sweep drains in-flight GPU work before unmapping and retires swept tiles behind a fence #194
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!194
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-194"
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?
@eIBart0 on GitHub · 2026-11-25 20:34 UTC · original
sweep-fix→main· +278 −54 · 2 files · 1 commits · closed without mergingProblem
With
VICTORY_SWEEP_TILES=2, the host GPU is removed withDXGI_ERROR_DEVICE_HUNG(0x887A0006, "host GPU device removed after a submission of N lists"). It happens 64-90 s after the world starts drawing, when the first cinematic hands over to the cell.On a Radeon RX 9070 XT (Windows 11 26220, Ryzen 7 5800X3D), standing in the cell:
VICTORY_SWEEP_TILES=2Cause
shadow::sweepruns fromqueue::show.Timeline::stepdrains in-flight work beforeOp::Work, but releaseshost.submittedbeforeshow()runs. That leaves three gaps:sweep()then queuesUpdateTileMappings(..., D3D12_TILE_RANGE_FLAG_NULL)without holdinghost.submittedor drainingin_flight.Tiles went straight back toTILES.freewith no fence. The nextnew_tile()could map them elsewhere and write them from the CPU while the GPU was still using the old mapping.sweep()removed tiles froms.tiles, dropped the lock, and only then unmapped them. A concurrentShadow::tilecould map the same address in between. The unmap then landed after that map, so the GPU read zeros whiles.tilesstill listed the tile as mapped.Shadow::sparse_on_elementhad the same window aroundmap_tiles.Changes
host.rs: addedHost::completed_fence()andHost::drain_and_signal().drain_and_signal()takessubmitted, drains in-flight work, runs the callback, and signals the fence when it queued work.shadow.rs:sweep()still looks for candidates outside the locks, so a frame with nothing to sweep costs nothing extra. When it finds some, it does the removal, the unmap of the buffer and its aliases, and the cleanup oflooks,copiedandunwatchedinsidedrain_and_signal().take_and_unmap, holdss.tilesacross both steps.sparse_on_elementnow holdss.tilesacrossmap_tiles.host::retireinto a fence-gated free list (TileFreeList,RetiredTiles). A tile is reused only oncecompleted_fence >= unmap_fence.host.submitted→s.tiles→s.kept/s.aliases→TILES.Shadow::tile,map_tiles,new_tileandsparse_on_elementnever takehost.submitted, so thein_parallelworkers inside a submission can't deadlock on it.Tests
shadow::tests:swept_tiles_wait_for_their_unmap_fence_before_reusereinserted_tile_is_not_unmapped_by_sweepconcurrent_reinsert_waits_for_sweep_unmap_before_mappingcargo test -p victory-gpu --lib shadow::testspasses (8 tests).cargo check -p victory, with and withoutdiagnostics, adds no new warning.000ffdd.@MamaLeVrai on GitHub · 2026-11-26 00:18 UTC · original
Tested on an RX 6950 XT (RDNA2), Windows 11 build 26300, Rust 1.98.1, release lib tests with this PR (
c1b2efd) merged onmain4f62c2a:victory-gpu: 115 passed, 1 failed. Onmain: 112 passed, 1 failed. The 3 newshadow::testspass. The one failure islist::tests::lists_are_cut_at_waits_that_follow_work, which fails in every release run onmain(#210).victory-shaderandvictory-hle: the same asmain.I did not run with
VICTORY_SWEEP_TILES=2. Not run in the game.harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300
AI-assisted (Claude Code); no game data.
@adrianmjim on GitHub · 2026-11-26 19:45 UTC · original
Tested natively on Windows 11 26300, RX 7900 XT (RDNA3, driver 32.0.32029.2010). Head
c1b2efd, base000ffdd. I also merged it locally into current main4f62c2a: the merge is clean.What I ran:
cargo test -p victory-gpu --lib, interleaved: 26 runs of the PR, 25 of000ffdd, 15 of4f62c2aand 15 of4f62c2a+ this PR. The machine was busy with other jobs.shadow::testspassed in every run that completed.000ffdd:frame::tests::waits_end_on_ticks_and_count_frames, thewatch::testsgroup and, once,depth_bounds_control_a_title_draw.cargo check -p victoryon4f62c2a+ this PR, with and withoutdiagnostics: same warning count as4f62c2a.Do the new tests fail without the fix? They don't compile on
000ffdd, so I put back the old behaviour inside the PR tree instead:s.tilesbefore the unmap intake_and_unmap, as the old code did:concurrent_reinsert_waits_for_sweep_unmap_before_mappingfails 3 of 3 (order is map, then unmap).TileFreeList::deferput tiles straight intofree, ignoring the fence:swept_tiles_wait_for_their_unmap_fence_before_reusefails 3 of 3.reinserted_tile_is_not_unmapped_by_sweeppasses with both changes put back. The old code already re-checkedusedandkeptunder the lock, so this test protects that re-check, not the new fix.One small thing in
sweep(): ifqueue.Signalfails,unmap_fenceisNoneandoldis dropped. Those tiles never go back toTILES, andSHADOWSis not decremented. Before this PR they always went back to the free list.Not tested: the in-game hang with
VICTORY_SWEEP_TILES=2. I did not run the game, so I can't confirm the fix on RDNA3.Pull request closed