Regions: clamp loose WC windows outside GPU-owned buffers and skip taken ranges in Shadow::copy #392
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/gamingwithhomie--larp!392
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-392"
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?
@Lakanya on GitHub · 2026-12-06 00:04 UTC · original
Lakanya:pr/regions-clamp-wc-windows→main· +144 −7 · 2 files · 2 commits · openUnregistered small buffer views in the write-combined heap fall through
shadow::loose(), which unconditionally expands[address, end)to a 4 MiB grid (WINDOW = 4 MiB). Because the WC heap tightly packs small CPU buffers adjacent toOwner::TakenGPU-owned buffers, the 4 MiB expansion overlaps them—triggeringERROR larp_gpu::regions(window_over_taken), allocating a 4 MiBGPU_UPLOADwindow over GPU-owned ranges, and causingstale_readrefreshes inShadow::copy().What is in it
crates/larp-gpu/src/regions.rs: addclamp_outside_taken()to clamp a candidate loose window to the maximal gap containing[address, end)that overlaps noOwner::Takenrange (preferring 64 KiB, then 4 KiB inward alignment), plustaken_in()for clipped taken sub-ranges.crates/larp-gpu/src/shadow.rs:shadow::loose(), clamp the window viaregions::clamp_outside_taken()when the 4 MiB grid touchesOwner::Taken.Shadow::copy(), skipOwner::Takensub-ranges viaoutside(from, to, regions::taken_in(from, to))so pre-existing windows (WindowBefore) never overwrite/read stale bytes over GPU-owned ranges.No rendering shortcuts, no game data.
Tested
cargo test --lib -p larp-gpu -p larp-hle -- --test-threads=4:larp-gpu24 passed / 0 failed / 6 ignored;larp-hle76 passed / 0 failed / 4 ignored.ERROR larp_gpu::regions, prep time5.9 -> 3.4 ms, p95113.8 -> 56.0 ms.AI-assisted by Antigravity (Gemini 4 Neon Medium).
@vanya890 on GitHub · 2026-12-06 00:52 UTC · original
One edge case worth making explicit:
clamp_outside_taken()returnsNonewhen the requested interval[address, end)itself intersects anOwner::Takenrange. Inshadow::loose(), the caller only replaces(start, len)onSome; onNoneit continues with the original 4 MiB window, which can still overlap the taken range and proceeds through the normalShadowcreation path.Shadow::copy()now skips taken sub-ranges, but the requested view may then contain no valid mirrored bytes for the portion that intersectsOwner::Taken.Is an ask intersecting a taken buffer impossible by invariant? If so, a focused test/assert would make that assumption clear. Otherwise, it seems worth handling the
Nonecase explicitly rather than silently retaining the original overlapping window. I haven't reproduced this edge case at runtime; this is a control-flow review question.@Lakanya on GitHub · 2026-12-06 01:02 UTC · original
Good catch, thanks for the review!
In normal operation
shadow::buffers()resolves asks inside taken WC buffers beforeshadow::loose()is reached, so an ask reachingloose()should not intersectOwner::Taken. However, if an unindexed/spanning ask ever does intersectOwner::Taken(clamp_outside_taken()returnsNone), skipping taken sub-ranges inShadow::copy()on that fallback window would indeed leave the intersecting portion unmirrored.Pushed a follow-up commit to make this explicit and safe:
skip_taken: boolonShadow:truefor windows created clean ofOwner::Taken(protecting against laterWindowBeforeoverlaps), andfalsefor fallbackwindow_over_takenwindows soShadow::copy()preserves the original fallback mirroring behavior.clamp_in_map()inregions.rsand added unit tests covering 64 KiB/4 KiB gap clamping and theNonereturn when[address, end)itself intersectsOwner::Taken.Re-tested
cargo test --lib -p larp-gpu -- --test-threads=4(26 passed, 0 failed, 6 ignored).@vanya890 on GitHub · 2026-12-06 01:09 UTC · original
Additional cross-vendor evidence from Issue #454: an RX 9070 XT user on the v1.1.6 AMD test build has the same
larp_gpu::regionswindow_over_takendiagnostic. At 00:53:46 UTC,descriptor/host.rs:2599reports a 4 MiB window (0xd76800000+0x400000) overlapping GPU-owned WC buffers, including0xd76a222c0+0x344and several adjacent allocations. About seven minutes later, D3D12 reports device removal (0x887A0006) with 5 submissions ahead of 69 command lists.This is a second GPU vendor/family showing the exact overlap class your PR addresses. The later device removal is correlated, not proof that the overlap caused the hang. The reporter's v1.1.6 build predates this PR, so it does not validate the patch; after merge, Issue #454 would be a useful AMD RDNA4 retest. If it still fails, the log explicitly recommends
LARP_D3D12_DRED=1to capture breadcrumbs and the faulting address.@TrinityForever15 on GitHub · 2026-12-06 03:17 UTC · original
Confirmed on RX 6650 XT: before this PR, car chases logged
larp_gpu::regionswindow_over_takenwith spikes up to 671 ms. With it (plus #526), those errors are gone. https://github.com/iceboerg00/larp-amd/issues/64View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.