GPU: batch descriptor sync_heaps per dirty page without holding SHADER_HEAPS #2170
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2170
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2170/head"
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?
@RVZO6 on GitHub · 2026-11-25 06:50 UTC · original
RVZO6:rvzo/descriptor-sync→main· +476 −59 · 2 files · 2 commits · closed without mergingAt every submission,
descriptor::sync_heaps()currently holds the globalSHADER_HEAPSmutex while scanning every dirty 64 KiB page of every shader-visible heap and callingHostHeap::mirror()slot by slot. Each 32-byte slot (2,048 slots per dirty page) separately locksself.made, locks globalVIEWS, clonesView, and touches D3D12 — blocking parallel command-list recording threads onSHADER_HEAPSand doing ~4,096 mutex acquisitions per dirty page even when most slots are empty or unchanged.The change
crates/victory-gpu/src/descriptor.rs:Arc<host::HostHeap>inHeap::host(OnceLock<Option<Arc<host::HostHeap>>>) sosync_heaps()snapshots(Arc<HostHeap>, dirty_ranges, start, step, count)underSHADER_HEAPSand releasesSHADER_HEAPSimmediately before scanning dirty pages or updating host descriptor heaps.Views::matches(i, generation)andViews::get(i, generation)helpers (valid packed keys are always non-zero becausegeneration >= 1).descriptor::tests::dirty_page_sync_leaves_shader_heaps_unlocked_and_skips_unchangedprovingSHADER_HEAPS.try_lock()succeeds inside the sync callback and unchanged ranges are skipped.crates/victory-gpu/src/descriptor/host.rs:HostHeap::mirror_range(first, last, start, step)andclassify_range(made, first, end, start, step):self.madeonce per dirty page andVIEWSat most once per dirty page.key == 0 && made[slot] == 0) without touchingVIEWSor D3D12.made[slot] == key) viaviews.matches(idx, gen)with zeroView::clone()and zero D3D12 descriptor copies.Viewand updates the host descriptor heap (apply_view) for added, changed, or invalidated slots, releasingVIEWSbefore calling D3D12.descriptor::host::tests::classify_range_matches_per_slot_mirror_across_pagesproving slot-for-slot equivalence withmirror()across empty, unchanged, changed, invalidated, and page-spanning ranges.Not a duplicate of
#840targets 256-byte aligned CBV table mirroring without dynamic slots, and#2121/#2128target view-heap paging and unbound null descriptors. No other open PR removes theSHADER_HEAPShold across dirty-page scans or batchesHostHeap::mirror_rangeper dirty page.Tested
windows-latestMSVC + Windows WARP SM 6.6 CI on fork integration stack (Run 45562558052):cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.cargo test --workspace --locked: 712 passed, 0 failed, 10 ignored, includingvictory-gpu152 passed, 0 failed, 2 ignored (both newdescriptor/descriptor::hosttests and all existing descriptor tests) andxtask(6 passed, 0 failed,repository_passes_policy).b42604b:cargo clippy(default &--all-features)-D warningsclean; Wine-10.0 passeddescriptortests (12 passed, 0 failed).Not run: the title; any hardware GPU (CI ran on Windows WARP only). The title was not used in these tests.
AI-assisted: T3 Code (Antigravity, gemini-4-neon)
@nathanbzrr on GitHub · 2026-11-25 08:40 UTC · original
Audited head
b42604b6ca8800b8ce9d0a63c0a626802f893eb0onmain(940d32f69b) on Windows 11 x64 / AMD Radeon RX 7600.Baseline
descriptor::testspass (12/12), but removing theread_intosafety boundary and droppingSHADER_HEAPSbefore raw pointer reads causes a deterministic single-threaded crash and multiple concurrency hazards:Live Repro — Deterministic
STATUS_ACCESS_VIOLATION(0xC0000005) on partial 4 KiB decommits / boundary straddles (descriptor.rs:185-197,descriptor/host.rs:290-298):sync_heaps_withprobes only 4 bytes (read_into(page, &mut [0u8; 4])), whereasclassify_rangereads 12 bytes per slot via raw(start + index * step) as *const [u32; 3].page..page+4096) is committed and OS page 1 (page+4096..page+8192) isMEM_DECOMMIT,read_into(page, 4)succeeds andclassify_rangefaults at slot 128 (page + 4096).repro_sync_heaps_partial_4k_hole_must_not_crash) terminated the test process immediately:step = 32,start = P + 24,P + 65536unmapped) haslast = 2048, reading[P + 65528 .. P + 65540)(4 bytes past the 64 KiB boundary into unmapped memory).Source-level — TOCTOU
STATUS_ACCESS_VIOLATIONafter releasingSHADER_HEAPS(descriptor.rs:82-99):Dropping
SHADER_HEAPSbefore scanning lets a concurrent title thread executeHeap::drop()(Release()) andVirtualFree/XMemUnmapPhysicalPagesbetweenread_intoandclassify_range's raw pointer reads (whilesync_heaps_withholdsself.madeandVIEWS).Source-level — Stale slot overwrite race in
HostHeap::mirror& widenedResource*UAF (descriptor/host.rs:265-275, 650-660,resource.rs:1428):HostHeap::mirrorreads[tag, i, generation]before lockingself.made. Now thatmirrorandsync_heaps_withno longer shareSHADER_HEAPS,mirrorcan overwrite a newer descriptor synced bysync_heaps_withwith a stale local read.Views past theVIEWSunlock widens theResource*UAF window insidemake_markedagainst concurrentDrop for Resource.(Proposed / uncompiled fix direction:) replace the 4-byte
read_intoprobe with a single full-pageread_intointo a reusable scratchVec<u8>+ safeclassify_bytes(same syscall count, per-slot 12-byte fallback on partial reads, zero raw pointer dereferences), add anArc<AtomicBool>liveness guard, lockself.madebefore reading the title slot inHostHeap::mirror, and re-validate/holdVIEWSaroundResource*dereferences inapply_view.AI-assisted; synthetic tests only, no game files, dumps, or captures used.
@MamaLeVrai on GitHub · 2026-11-25 08:52 UTC · original
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head
b42604b6intomain940d32fin a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with--all-features: clean.cargo test --workspace --locked: first run 703 passed, 0 failed, 10 ignored. In the second run one test failed, and it is one this PR adds:descriptor::tests::dirty_page_sync_leaves_shader_heaps_unlocked_and_skips_unchangedpanicked atdescriptor.rs:896with "SHADER_HEAPS held during scan".SHADER_HEAPSis a global lock, so I suspect another test of the crate takes it at the same moment (tests of one crate run in parallel); I have not confirmed which. That makes the test race when the suite runs concurrently; it passed in the first run. The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
@RVZO6 on GitHub · 2026-11-25 09:19 UTC · original
Thanks @nathanbzrr for the RX 7600 audit and crash repro — all three findings are fixed in
cf9c011:read_intofull-page copy + 4 KiB / per-slot fallback (descriptor.rs,descriptor/host.rs):classify_rangewith a single full-pageread_intointo a reusable scratchVec<u8>(same 1 syscall per committed dirty 64 KiB page) and safe byte-slice parsing (scan_bytes/classify_bytes).read_intofails (partial 4 KiBMEM_DECOMMIThole or unaligned boundary straddle), falls back to 4 KiB OS-page reads and per-slot 12-byte reads across 4 KiB boundaries with zero raw pointer dereferences.descriptor.rs):alive: Arc<AtomicBool>onHeap(set tofalseunderSHADER_HEAPSinHeap::drop) checked before reading/mirroring each page insync_heaps_with.HostHeap::mirror&VIEWS-heldapply_view(descriptor/host.rs):HostHeap::mirrornow locksself.madebefore reading the title slot (via saferead_into) somirrorandmirror_bytesserialize strictly onself.made.mirrorandmirror_bytesapply changed slots directly underVIEWS(zeroView::cloneinmirror_bytesand closing theResource*UAF window against concurrentDrop for Resource).descriptor::tests::sync_heaps_handles_partial_4k_decommit_and_unaligned_straddleanddescriptor::tests::sync_heaps_aborts_when_heap_drops_concurrently.Verified on fork
windows-latestMSVC + Windows WARP SM 6.6 CI (Run45581807630): bothclippy -D warningsbuilds clean,716 passed; 0 failed; 10 ignored,xtask6/6.AI-assisted: T3 Code (Antigravity, gemini-4-neon)
@wbkepler on GitHub · 2026-11-25 12:40 UTC · original
Live check of this PR (head
cf9c011) on Windows 11 / RTX 5090, merged into our integration build, which also carries #1779 (view heaps on hosts capped at 1M descriptors, through a 1,024-slot view-block remap). The two conflict indescriptor/host.rs. This is how I resolved it, in case it helps once either one lands:mirror_bytescompares each title slot with what its host slot holds now (through the block map; a slot whose view is not made yet still counts as held, so it gets visited and given back).mirrorand the bulk path share oneset_slot, so a block left without views still goes back.VIEWS. An earlier resolution made the changed slots inside thewith_viewsscan, and it stalled the title before the world in a live run: on our build, making a view can reach code that takesVIEWSagain, and std mutexes don't re-enter. The scan now only collects the changed slots underVIEWS(cloning just those) and makes them after the lock is released. It might be worth checking whether anymake_markedpath onmaincan reachVIEWStoo.Measured on the same build and settings, 300 s runs, averaged over the last 12 five-second windows in the world (~5,000 draws/frame):
sync_heapsper framemirror)The world loaded and the run lasted the full 300 s with no stall, device removal or panic.
cargo test -p victory-gpu --lib descriptorpasses 19/19, including the new tests. The scan itself is no longer the cost. Per frame it reads about 212 dirty pages and 434k slots, but about 103k of those slots really changed (the title rewrites them), so what's left is making those views, not finding them.AI-assisted check (Claude Code); Windows 11 / RTX 5090.
@Marvisak on GitHub · 2026-11-25 13:28 UTC · original · edited 2026-11-25 16:01 UTC
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-gpu/src/descriptor.rs,crates/victory-gpu/src/descriptor/host.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (needs-work) was for an older state ofmain.Generated by Claude Code
@RVZO6 on GitHub · 2026-11-25 17:13 UTC · original
Closing as superseded by
main(f809521per-page single-lock heap sync and56f75f8/cea278c/ab2e2b2out-of-lock texture creation). Thanks to @nathanbzrr, @MamaLeVrai, and @wbkepler for the reviews!Pull request closed