GPU: a heap sync leaves out the slots past the host heap #3512
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!3512
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3512"
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?
@neonbyte1 on GitHub · 2026-11-27 12:04 UTC · original
neonbyte1:pr/heap-sync-cap→main· +66 −5 · 2 files · 2 commits · openWhat's wrong
descriptor::sync_heaps(crates/victory-gpu/src/descriptor.rs:169onmain) takes each dirty64 KiB page of a shader-visible heap the title writes as bytes and clamps its last slot at the
title's descriptor count only:
HostHeap::sync_slots(host.rs:695) then reads every record infirst..last(host.rs:699),compares each against the slot's
madekey, and callsself.mirrorfor the ones that differ(
host.rs:714).HostHeap::mirrorrefuses every index at or past the host heap's count before itreads anything at all (
host.rs:723).The host heap has fewer slots than the title's whenever the host caps its heaps
(
host.rs:145-171): on NVIDIACreateDescriptorHeaprefusescount + DYNAMICand thencount + MIN_DYNAMIC, and the cap branch (host.rs:164) keepscount = PORTABLE_VIEWS - MIN_DYNAMIC= 934,464 slots, while the title's heap is1,245,184 slots (#2121, #3475). The last 310,720 title slots have no host slot, and the
sync reads them and calls
mirroron every one it finds stale, every frame.Measured on the same sync code on the
perf/bestlineage (run0763-heapdirty1; the host counted762,920 slots there): of the 222 dirty pages a world frame marks (455,597 slots), 98 pages —
200,704 slots, 44 % — lay past the host's count, and every one of the ~200,000
mirrorcalls madenothing (216,049 slots were stale; of the 254,608 scanned below the count, 15,345 — 6 % — needed
making).
mainhas no split heap: onehost: OnceLock<Option<host::HostHeap>>per title heap(
descriptor.rs:59), made with the title's count (descriptor.rs:100), sohost.count()is thewhole bound and there is no per-split arithmetic to redo.
The fix
Both places stop at
HostHeap::count():sync_heapsclamps the page's slot range withhost::host_slots(host.count(), first, last)before
sync_slotsreads anything, and theSyncSlotsdiagnostics counter counts the slotsactually scanned instead of the title's.
sync_slotsclamps again, and returns before the record read when a range is entirely past thecount: the invariant does not depend on the caller.
host_slotsis the one expression both use, and what the test pins.No behaviour change:
mirrornever made such a slot. The heap's highest title slot still goes tomirroronce per heap per sync, so thetitle slot past the host heapwarning (host.rs:728)keeps firing exactly as it does now (once per new highest index); what goes away is the record read
and the refused
mirrorcall for the other 310,719 slots.Tests
a_heap_sync_stops_at_the_host_heaps_count(descriptor/host.rs, CPU only): a page below thecount keeps the caller's range, one straddling it stops at the count, one past it is empty and
sync_slotsreturns before reading a record; pinned withmain's capped numbers (934,464 of1,245,184). The existing
heap_syncs_make_the_slots_whose_records_changedcovers the below-countpath unchanged (needs a device, as it already does).
Clippy
-p victory-gpu --all-targets -- -D warningsclean with and without--features diagnostics(x86_64-pc-windows-msvc),
cargo xtask policyok, no formatting-only hunks againstorigin/main.A device is needed to run the sync itself, so the clamp is pinned by a unit test of the range and
by the run below, not by a GPU test.
In game
Measured on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, warm caches, diagnostics build, 420 s runs, medians of the last 30 frame-rate lines. The measured build is the same clamp on our test stack (
mainplus the unmerged PRs we need on NVIDIA under Wine; listed in #3425), where the host heap counts 762,920 slots; candidate and control alternated A-B-A-B.mirrorper frameSyncHeapsUs) per frameThe frame-time difference is inside our run-to-run spread, so the counters are the claim: the sync does about 40 % less reading and 93 % fewer refused
mirrorcalls. The remaining heap-sync time is mostly waiting on theSHADER_HEAPSlock rather than per-slot work, which this PR doesn't touch. On that build thetitle slot past the host heapwarning stopped appearing; the version here keeps one past-countmirrorper sync on purpose, so onmainit keeps firing as before.Overlap with open PRs
gh pr list -R Marvisak/VIctory --state open --search "heap count" / "sync_slots" / "past the host heap": nothing open makesmain's sync stop at the host's count as its own change.sync_slotsintosync_rangesandclamps each range at
self.countthere, keeping one past-capmirrorcall for the warning. ThisPR is the same two clamps on
main's code without the batching rewrite: it composes with#3139/#3055 rather than conflicting with them.
warning into counted statistics; #3052 clamps the read-mark scan, not the heap sync.
AI-assisted (Claude); measured on my machine, no game data shared.
@KainanP on GitHub · 2026-11-27 12:31 UTC · original
@neonbyte1, contention numbers for this PR (
1b11a72) against63bcca4. The bench is the one from #3425; it would also fit your per-16-page-chunk version.No views were lost or stale. The full
victory-gpusuite on RTX fails only the two tests thatmainalso fails here. #3055 has the same clamp in itssync_ranges(thepast_capmirror of the highest slot), so whichever of the two lands second will conflict there.Bench:
sync_contention_bench(#[ignore]d; commitf34bcfb8, cherry-picks onto any tree). A placed, write-watched view heap of 2^20 slots (the host heap caps it at 934,464 here). Each frame, one thread rewrites 200 random 64 KiB pages (50 changed records each) and runs onesync_heaps, while 5 title threads write a placed-buffer SRV every 20 µs into pages of their own. "Wait" is the title threads' time in view writes beyond the uncontended 2–3 µs, summed per frame. Release build, RTX 4060 Laptop, runs interleaved with the base, medians of 30 frames per run. The bench also checks that every view written before a sync is the slot's view address after it, and that every slot is right after a final quiet sync.AI use: Claude Code (Claude Opus 5.5).
@cloph-dsp on GitHub · 2026-11-27 12:35 UTC · original
Independent CPU-only verification of PR #3512 (Windows, Rust 1.100.0/MSVC, worktree-local
CARGO_TARGET_DIR=D:\Victory-Contrib\target-3512-watch,CARGO_BUILD_JOBS=2, no game data).1b11a72119ff16068b153d5a06895e646eefef04; merge base:63bcca43c6a00a758510398fa43096ce7e4f7df0.cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::a_heap_sync_stops_at_the_host_heaps_count --exact --test-threads=1 --quiet→test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 232 filtered out, exit 0 (2 pre-existingfetch_updatedeprecation warnings inobject.rs).git grep -F -c a_heap_sync_stops_at_the_host_heaps_count 63bcca43 -- crates/victory-gpu/src/descriptor/host.rs→ 0 hits, exit 1 (test is genuinely new).git diff --check 63bcca43 HEAD→ exit 0 (clean).Only the named synthetic pure-CPU test was replayed; the actual
sync_heapsdevice path was not exercised here. GPU/driver: N/A for this CPU test. AI-assisted (Hy4 flash). No game data, assets, shaders or DRM involved.@neonbyte1 on GitHub · 2026-11-27 12:43 UTC · original
@cloph-dsp thanks for your feedback but Hy4 Flash likes to hallucinate and I don't want to verify every cheep model claim. Could you do that maybe with a better one?
@passerbyyhx on GitHub · 2026-11-27 18:56 UTC · original
Windows synthetic verification at
1b11a72119ff16068b153d5a06895e646eefef04.On an RTX 4090 Laptop (621.14), a synthetic placed title heap of 1,245,184 slots naturally capped at 934,464. Using a freshly dirtied 64-KiB page at a time, the number of records actually visited on parent → head was 2048→2048 below the cap, 2048→576 on a straddling page and 2048→0 wholly past the cap. The diagnostic scan count agreed with the read loop. A byte-copied texture descriptor in the last valid slot (934,463) gave the expected 64/64 output words on both revisions. WARP with an injected cap of 3,073 in an 8,192-slot title heap gave 2048/1025/0 on head and the same 64/64 readback.
One diagnostic detail: after draining the initial dirty state and before any new page writes, head already reported slot 1,245,183 on the clean sync. Parent had no high-water warning there and subsequently reported 935,935 and 940,031 for the selected dirty pages. The head warning describes the heap extent and cannot on its own establish that the title wrote/read that high slot. This fixture measures work counts and pixel correctness, not frame time.
Reproducible fixture. GTA-VI-3/EIGHT-20261127. AI-assisted with Codex.
@neonbyte1 on GitHub · 2026-11-27 19:23 UTC · original
@passerbyyhx thanks for the verification, and good catch on the warning. You're right: after the change the sync called
mirrorwith the heap's last slot whenever the title heap is larger than the host's, so the warning described the heap's extent, not a write.Fixed in
004185a3: the sync now remembers the highest slot of a page the title actually wrote past the host heap's count, and only reports that one (nothing when no such page was synced). The resolution is a page: the slot reported is the last one of a written 64 KiB page, the same granularity the parent's high-water mark had. Clippy (-D warnings, with and withoutdiagnostics), formatting anddescriptor::tests (23/23) are clean; I haven't rerun your fixture.AI-assisted (Claude); no game data shared.
View 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.