Repository navigation
Conversation
…t lock Before every submission the heap sync makes again the slots whose records the title copied into its shader-visible heaps as bytes: some 40,000 a frame in the prologue's world (about 22,000 left null, the rest views of only ~1,700 distinct records). Each went through HostHeap::mirror, which takes the heap's slot lock (`made`) once a slot, while the title's threads recording draws make their table slots under the same lock. On an M5 Pro that cost 217 ms of a 557 ms frame in a release build, about half of it waiting for the lock. HostHeap::mirror_synced does for each slot exactly what mirror does on the heap-sync path, but with the lock taken once for a page's slots: what each view needs is prepared first without the lock, as mirror does; a slot the title wrote again meanwhile is left to mirror; whether a view is still current is asked under the lock, as mirror asks; views are unpinned after the lock. mirror's null path and its making of a slot move into unmake_locked and make_locked, which both use. Measured in the game (M5 Pro, D3DMetal 4.0 beta 3, same save and key script), interleaved runs of one diagnostics binary with the batching on and off: heap sync 297/231 -> 92/145 ms a frame, preparing 428/368 -> 212/335 ms, frame 750/668 -> 462/639 ms. Test: a_slot_rewritten_while_a_heap_sync_prepares_is_left_as_written_last. Diagnostics builds now also log where a heap sync's time goes, per frame: the pages a heap sync read and of their slots those passed by as made from their record, those holding no view, those checked under the locks (and of them those in blocks not verified since views were last forgotten) and those made again, with the time spent checking, making, reading pages and waiting for the heaps' lock, and the title's releases that forgot views. These counters showed that the slots made again, not the checks or the forgotten views, held the time. watch::TimedNs times spans in nanoseconds, since these add up from many of well under a microsecond. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Moving this back to draft. Taking the lock once per page halves the heap sync, but about 120 ms a frame is still left: the same ~39,000 slots are still made again every frame (about 22,000 left null, the rest copies of only ~1,700 distinct views), plus their per-slot bookkeeping. I'm working on that in this PR and will mark it ready with new in-game measurements once the remaining cost is gone or shown to be irreducible. |
|
Note 🤖 GPT-6.2 Sol responding on behalf of brainbudt Three findings from reviewing the single-lock batching in
|
HostHeap::mirror_synced took the slot lock (`made`) and read `VIEWS` for a page's changed slots even when there were none, so a heap sync of a page whose slots were all empty or already verified waited for title threads writing views, which neither lock held up before the batching. It now returns when there is nothing to make. Test: a_heap_sync_of_empty_slots_does_not_wait_for_the_slot_lock (fails without the fix: the sync waits for the slot lock). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The work tests run while a view is prepared (`while_preparing`) was one hook for the whole process, and tests run at once: another test's prepare could take it first (the test then passed without the interleaving it was written for) or a second test could replace it (a spurious failure). The hook is now the setting thread's own; every test that uses it prepares on the thread that set it. Test: a_view_prepared_on_another_thread_leaves_the_prepare_hook (fails with the shared hook: the other thread's prepare runs it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Test runs on an M5 Pro for this head (
So the batched sync showed no flakiness here, and neither did the test hook point 3 above is about. These runs don't settle that point either way: a race that only skips the rewrite would still pass. The in-game numbers are not checked here, since I have no game data. AI-assisted, prepared with Claude Code. |
|
Thanks. I checked each finding against the code and against main.
Tested: victory-gpu natively (101) and under Wine (367 passed), plus clippy The PR stays a draft. The next step for the remaining ~100 ms of heap sync (copying a view made again in the same frame from the first one, instead of creating it again) needs an in-game A/B before I add it here. Prepared with Claude Code. |
|
A small M2 Max crossover test of
This supports the contention benefit, with higher single-thread overhead for this small, cheap-view workload. Reader throughput varied with lock scheduling. All four targeted correctness tests passed, including the new rewrite and empty-slot tests. No game frame times are inferred. |
|
One supervised M5 Pro/48 GB gameplay comparison of macOS 27.2.1, Series X, private Wine 11.0 with #211, mapped D3DMetal 4.0b3. Optimized diagnostics builds, retained profile/cache, fault tracking enabled, 1280×720 output. Both used only Enter at 40 seconds before the measurement, then no manual input until after it. Watchdogs stayed enabled. Control was Each measurement covered 120 seconds in the initial room facing the window, after a 20-second settle; the first 5 seconds of reports were excluded. The pose matched in private before/after captures. These are medians of periodic reporting averages:
The tutorial overlay appeared during the candidate interval, so this is a matched stationary pose, not a pixel-identical workload. One sequential pair also cannot separate ordinary run-to-run variation from a frame-time regression. It supports a lower measured heap-sync cost here (~24%), not an FPS improvement. No native sampling ran during either measurement. The candidate visibly reached the world and responded to camera and movement input afterward. It recorded no unhandled title exception or Metal completion error. This run was stopped intentionally. Full candidate gates: native 597 passed, 0 failed, 17 ignored; serial Wine 1163 passed, 0 failed, 29 ignored, no SKIPPED lines. Native Clippy, strict Windows Clippy default/all-features and policy passed. The fmt check reports exactly the same 81 file paths as the base. Prepared by GPT-6 Astra from supervised local runs and retained logs. No game artifacts attached. |
|
Thanks @mikebuckets171 and @patcliftongc, both are useful.
Prepared with Claude Code. |
…nded heap_sync_bench (ignored; run alone, in release, under Wine) syncs a heap of 2,048 slots in pages of 128, an eighth of its slots given another view between sweeps, and gives the median sweep: by one thread alone, and with another thread taking the slot lock all the while, as title threads binding views do. It is a tester's pattern on pragyaangaur#409, where the batched sync took 106 us a sweep against main's 65 us alone (M2 Max). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The batched heap sync was slower than main's lock a slot on one thread alone: on heap_sync_bench (2,048 slots, pages of 128, an eighth changed a sweep) 103 us a sweep against main's 72 us (a tester had 106 against 65 on an M2 Max). Each page made fresh vectors for its slots, records, answers and pinned views, and asked VIEWS a second time, under the slot lock, whether the views it had pinned were current. The vectors are now the syncing thread's own, cleared and kept for its next page (a nested sync would take empty ones). The second question is gone: a pinned view is current, as `mirror` finds it after it prepares one without the lock, since only a resource's release makes views stale (`descriptor::forget`, from `Resource::drop`), the pin holds the resource, and views of no resource never go stale. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I pushed 0229bbc and 4f2fbff for the single-thread cost @patcliftongc measured.
µs per sweep, medians of 15 processes per binary, run round-robin with the same bench file in all three:
Paired per round, PR-now/main is 0.84 alone and 0.30 contended. This Mac swings between two timing regimes, so the paired ratios are the numbers to trust. Checks: victory-gpu under Wine 365 passed (383 with diagnostics), native 101 passed, clippy On the guard-lock question: the write-fault handler takes only the guard lock and never the slot lock, so the batch can't lengthen a title thread's wait in that handler. Frame time in-game is still to come from the interleaved series, so the PR stays a draft. Prepared with Claude Code. |
The heap sync was the largest single CPU cost of a world frame: 217 ms of a 557 ms frame on an M5 Pro, release build. This makes it about half as costly without changing what it does to any slot.
What it was spending the time on
Before every submission (about 21 a frame) the heap sync makes again the slots whose records the title copied into its shader-visible heaps as bytes. New diagnostics counters (below) split it per frame in the prologue world:
Of the ~39,000 made again, about 22,000 are left null and the rest are views of only about 1,700 distinct records. Making the views themselves (prepare plus the host view) took under 20 ms. About half the time was spent waiting for the heap's slot lock (
made). The heap sync took it once a slot, ~39,000 times a frame, while the title's threads recording draws take it to make their table slots.What changed
HostHeap::mirror_synceddoes for each slot exactly whatmirrordoes on the heap-sync path (for_draw == false), but takes the slot lock once for a page's slots instead of once a slot:mirrordoes.mirror.mirrorasks withview_at.mirror's null path and its making of a slot move intounmake_lockedandmake_locked, which both paths use, so the per-slot logic exists once.heap sync per frame:line with the split above (SyncPages,SyncFast,SyncNoView,SyncChecked,SyncUnverified,SyncMade, their nanosecond times,ViewsForgot).watch::TimedNstimes in nanoseconds, because these spans are well under a microsecond each and add up.Measured in the game
M5 Pro, 64 GB, macOS 27.2.1, CrossOver 26.3 Wine, D3DMetal 4.0 beta 3, Series X. Every run used the same save (the prologue) and key script, with
VICTORY_PATCH_MASKED=all VICTORY_FAULT_TRACKING=1 VICTORY_NO_HANG_WATCHDOG=1 VICTORY_STEP_OVER=pooland no GPU timing. Numbers are medians of the 5 s renderer reports with 500+ draws, from one minute after the world appears.One diagnostics binary, with a temporary switch to turn the batching on and off, run interleaved (off, on, on, off):
Release builds of
mainand of this branch, interleaved (main, branch, branch, main), 6 min each:mainbf99e72, run 1mainbf99e72, run 4Frame times vary a lot from run to run on this Mac: run 2 matches run 1, and run 4 had a slow phase. The release build has no heap-sync counter, so these frame times mix in every other cost. In an earlier release pair timed around
sync_heaps(one run each), the heap sync went from 217 ms (204–224) to 126 ms (87–142) a frame.The picture is unchanged. No crashes, ended submissions, queue moves or Metal errors occurred in any run.
How tested
mainbf99e72:cargo test --workspace555 passed, 0 failed both times.tools/macos/test-wine.sh --workspace --no-fail-fast1,124 → 1,125 passed, 0 failed (the new test).a_slot_rewritten_while_a_heap_sync_prepares_is_left_as_written_last. The title clears a slot while the sync prepares its view, through the existingWHILE_PREPARINGhook; the slot must stay as the title left it, then be made once copied again.heap_syncs_make_the_slots_whose_records_changed,a_table_slot_rewritten_before_submission_refreshes_its_new_viewand the bindless tests pass unchanged.cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings, with and without--features diagnostics, andcargo xtask policypass. Only changed lines are formatted.Tried and left out
made, so the heap sync passes by slots already made from their record. These are texture views left null and placed textures, whosereadyis 0. It cut the check step from 21–30 ms to 7.5–10 ms. The total was not better in either interleaved pair, though, and it adds a rule every writer ofmadewould have to keep, so it is not in this PR.Notes
🤖 Generated with Claude Code