Repository navigation
Conversation
…R_HEAPS Assisted-by: T3 Code (Antigravity, gemini-4-neon)
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib dirty_page_sync_leaves_shader_heaps_unlocked_and_skips_unchanged— passedcargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean per-dirty-page batching in sync_heaps without holding SHADER_HEAPS, skipping unchanged views cleanly. Looks great.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Descriptor sync_heaps batched per dirty page — sync batching perf work.
…sync Port of Marvisak/VIctory#2170 by RVZO6 (GPL-3.0-or-later). sync_heaps collected dirty ranges, then mirrored every slot while still holding SHADER_HEAPS, so recorders waited on the sync. It now takes the ranges and an Arc of each host heap under that lock, drops it, and makes each readable page's slots after. A page's slots are classified in one pass under one VIEWS lock, unchanged populated slots are checked by generation only (no clone), and a repeat scan emits no updates. Shortcut: the page is still re-read for every dirty range covering it; fine for the 1,300-14,400 slots a frame, upgrade if a wider heap is written wholly each frame. Tests: dirty_page_sync_leaves_shader_heaps_unlocked_and_skips_unchanged, classify_range_matches_per_slot_mirror_across_pages.
|
Audited head Baseline
(Proposed / uncompiled fix direction:) replace the 4-byte AI-assisted; synthetic tests only, no game files, dumps, or captures used. |
|
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 AI-assisted (Claude Code); no game data. |
… and serialize mirror with VIEWS Addresses all three review findings on Marvisak#2170: - Replace the 4-byte read_into probe + raw pointer dereferences in classify_range with a single safe full-page read_into into a reusable scratch Vec<u8> (falling back to 4 KiB OS-page and per-slot 12-byte read_into slices on partial MEM_DECOMMIT holes or unaligned boundary straddles) and safe byte-slice scan_bytes/classify_bytes. - Add an Arc<AtomicBool> alive guard on Heap (cleared under SHADER_HEAPS in Heap::drop) so in-flight sync_heaps_with stops before touching freed pages. - Lock self.made before reading the title slot (via safe read_into) in HostHeap::mirror so mirror and mirror_bytes serialize strictly on self.made, and apply changed views under VIEWS directly in both mirror and mirror_bytes (zero View::clone in mirror_bytes and no stale Resource* window against concurrent Drop for Resource). - Add regression tests sync_heaps_handles_partial_4k_decommit_and_unaligned_straddle and sync_heaps_aborts_when_heap_drops_concurrently. Assisted-by: T3 Code (Antigravity, gemini-4-neon)
… and serialize mirror with VIEWS Addresses all three review findings on Marvisak#2170: - Replace the 4-byte read_into probe + raw pointer dereferences in classify_range with a single safe full-page read_into into a reusable scratch Vec<u8> (falling back to 4 KiB OS-page and per-slot 12-byte read_into slices on partial MEM_DECOMMIT holes or unaligned boundary straddles) and safe byte-slice scan_bytes/classify_bytes. - Add an Arc<AtomicBool> alive guard on Heap (cleared under SHADER_HEAPS in Heap::drop) so in-flight sync_heaps_with stops before touching freed pages. - Lock self.made before reading the title slot (via safe read_into) in HostHeap::mirror so mirror and mirror_bytes serialize strictly on self.made, and apply changed views under VIEWS directly in both mirror and mirror_bytes (zero View::clone in mirror_bytes and no stale Resource* window against concurrent Drop for Resource). - Add regression tests sync_heaps_handles_partial_4k_decommit_and_unaligned_straddle and sync_heaps_aborts_when_heap_drops_concurrently. Assisted-by: T3 Code (Antigravity, gemini-4-neon)
|
Thanks @nathanbzrr for the RX 7600 audit and crash repro — all three findings are fixed in
Verified on fork AI-assisted: T3 Code (Antigravity, gemini-4-neon) |
|
Live check of this PR (head
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):
The world loaded and the run lasted the full 300 s with no stall, device removal or panic. AI-assisted check (Claude Code); Windows 11 / RTX 5090. |
At 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)