GPU: cut per-slot lock churn, self-requeueing, and duplicate shadow lookups in sync_heaps and heap_buffers #1043
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/fxceless--victory-fork!1043
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1043"
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?
@UwUCammie on GitHub · 2026-11-25 17:15 UTC · original
UwUCammie:pr/sync-heaps-heap-buffers-opt→main· +393 −105 · 3 files · 1 commits · openWhile profiling frame time on RX 7900 XT under Wine,
sync_heapswas taking ~48–64 ms/frame on the submit thread andheap_bufferswas taking ~82–147 ms/frame on the recording thread. Tracing the two loops turned up several pieces of redundant per-slot work:What changed
heap_buffersfrom re-queuing itself (mirror_heap_buffer):heap_bufferspoppedhost.buffer_changes()and calledhost.mirror(index, handle, true), which callednote_bufferand inserted every mirrored slot right back intoself.changedfor the next frame (~17k–19k unchanged slots/frame on our runs). AddedHostHeap::mirror_heap_bufferpassingrecord_change = falseso the pass doesn't feed itself.sync_heapsandnote_buffer:AtomicU8flag array (SLOT_IN_TEXTURES,SLOT_IN_PLACED,SLOT_IN_BUFFERS) onHostHeapso buffer slots don't lockself.textures,self.placed, orself.bufferswhen they aren't in those sets (or are already inbuffers).self.madeandself.changedlocks once per page inmirror_copied_pageinstead of once per mirrored slot (~42k/frame).view_at(0, 0)(which acquiredVIEWS.read()) and skippednull_for+keep(index, None)whenlater && made[index] == 0(the slot is already null fromfill_null).page_bytesbuffer and onedue: Vecacross pages insync_heapsinstead of zero-filling and allocating per page.shadow::findlookups inheap_buffersandbuffer_copy:buffer_copynow computesbuffer_extentandshadow::find(base, width)once instead of twice whenown_bytesdoesn't match.buffer_srv/buffer_uavreturn the resolvedBufferCopydirectly frommake, somirror_heap_bufferhands it straight back toheap_bufferswithout callingbuffer_copyorhost.showsa second time for freshly-made views.heap_buffersupdatesrangesin place viaget_mutinstead ofremove+insert, and pre-sizesspans.Tested
sync_heaps:48.4 ms→24.0–25.6 ms(~24 ms/frame saved on the submit thread).heap_buffers:102–147 ms(50k slots, ~18k unchanged churn) →58.6–60.8 ms(29k slots, ~110 unchanged).VICTORY_RELAY=2moved from136–144 ms(~7.1 fps) down to116–117 ms(8.5 fps,97 msshortest) alongside465b94f+ #1007, with 0 device removals and identical frame captures.diag+victory-gputests) on465b94f.@Ym1r1710 on GitHub · 2026-11-25 17:48 UTC · original
Ran this on Windows, RTX 5080 + 7800X3D, on top of
ca8829f(RELAY=2, QUEUE2, ASYNC_SUBMIT, INDIRECT_WINDOW, TEXTURE_NO_WAIT, COPY_PLAIN). The "heap buffers" pass time on the frame line went from about 27-36 ms to 12-16 ms per frame. Overall frame time didn't move here though (median ~126 ms vs ~122 ms before, inside my run-to-run noise), so the recording thread isn't what holds my frames back. Picture at world+250 and +400 is the same as before, no missing or wrong surfaces. Keeping it in my build.@UwUCammie on GitHub · 2026-11-25 18:09 UTC · original
Thanks for testing it on Windows! Good to see
heap buffersdrop by more than half there too (27-36 -> 12-16 ms). Makes sense total frame time didn't move yet if the submit/landing thread is still the critical path inRELAY=2—heap buffersruns on the recording side.@Proudnoob4 on GitHub · 2026-11-25 18:28 UTC · original
Tested on Windows 10 (i5-13600K + RTX 4080 16 GB, driver 621.01, Series X, warm shader cache) bundled on top of
Xeltax/VIckyvicky/rt(3fbc9cb8, live BVH RT) alongside #1014, #1015, #1029, #1044, #1058, and #1059 (so the delta is the combined stack, not #1043 in isolation).RTX 4080 live-RT A/B (
3fbc9cb8warm 300s vs stacked 420s)3.3 -> 5.05 fps(mean2.46 -> 4.12, max4.6 -> 5.7, steady tail4.8–5.7 fps)framelogusual frame:278 ms -> 176–180 msover last 64 (shortest 155 ms)submit thread:237.0 ms (user 187.5) -> 175.9–179.6 ms (user 97.2–114.2);card idle188.8 -> 116.7–119.2 msheap buffers:162.9–172.3 ms(on3fbc9cb8)-> 120.6 ms(14.6–17.5 msin the texture pass;63,960–128,787buffer slots looked at)VICTORY_BVH_BUILDER=1+VICTORY_BVH_COPY=skip.Porting note for
HEAP_MAPforks: when rebasing #1043 ontoSlotMap(Xeltax/VIcky),slot_flagsshould be sized totitled(matchingtabled) rather thancount,empty_slot/reclaim/mirror_with_madeshould keep routing descriptor slot writes throughhost = made.host(index), andView::NullConstantinmake()becomesSome((None, None)).cargo test -p victory-gpu descriptorpassed locally with that adaptation.AI-assisted benchmark and analysis (Gemini 4 Hydrogen).
@LeonardoS11 on GitHub · 2026-11-25 19:06 UTC · original
Numbers for this from an RTX 3080 Ti on Windows — it helps here too.
Windows 11, RTX 3080 Ti 12 GB, 64 GB RAM,
diagbuild withdiagnostics, Series X profile, a still scene in the prologue (the room with the window onto the yard, about 4,800 draws), 300 s a run, averages of the last 8 frame-rate lines. Same switches in every run:VICTORY_LEVELS_ON_DEMAND=1 VICTORY_INDIRECT_WINDOW=1 VICTORY_COPY_PLAIN=1 VICTORY_BACK_OWN_VIEW=1 VICTORY_JOIN_PARTS=1 VICTORY_INDIRECT_GATHER=1. Runs interleaved, after one warm-up run of each build.465b94f465b94f+ this PR (5acc7c5)So about 13 ms a frame, and the heap pass roughly halved. The picture was complete in all of them (walls, the mesh in the window, the lit shirt), no device loss.
cargo test --workspacewith the PR: 577 passed, 12 ignored, 0 failed.Two notes from our side, where we had been working on the same pass:
madelock as contended on this machine — found taken 12,000 to 16,000 times a frame, 76 to 115 ms waited in sum across threads — and replaced it with an atomic key per slot plus striped locks for making. On top of this PR (your page batch rewritten over that, so it takes no lock) the lock is found taken 6 to 26 times a frame, but the frame time is the same within noise: 184 and 169 ms. So your batching already removes what mattered; I mention it only in case the lock shows up on a machine with more recording threads. The branch isLeonardoS11/victory-forkport/v9history if anyone wants it; I will not open a competing PR.record_change = falsetaken into that branch, the first run shows 9,800 slots looked at; I will post the rest on #467.(Runs by me on the hardware above; written with Claude Code.)
@UwUCammie on GitHub · 2026-11-25 19:12 UTC · original
Thanks for the detailed runs @LeonardoS11 and @Proudnoob4!
Really nice to see the −13 ms/frame drop and 577/577 workspace tests on Windows 11 too, and glad the
record_change = falsefix helped #467's slot count as well. Good to know the atomicmadefast path only matters once you have heavier concurrent recording — I've been testing that +CopyDescriptorsnull batching locally too and will keep follow-ups small and separate after this one.@rafaconvaitis on GitHub · 2026-11-25 19:45 UTC · original
Isolated follow-up on the self-requeue part of this PR, on Flamingo
63d976b, RTX 4070 (616.64), Ryzen 9 5900X, 32 GB, native Windows/D3D12. Series S, Relay 1, async submit off, plain copies, warm pipeline cache. I adapted just the already-described self-requeue suppression to Flamingo's existing slot-generation/stripe path. New writes, snapshot mismatches, failed makes and unresolved buffer copies retain their notifications.Same executable and process, 20 s alternating intervals, with four whole intervals per mode in each fixed-camera scene. I excluded the first second and any sample crossing a boundary.
The reduction in inspected slots replicates the direction of the 3080 Ti self-requeue-only report. It reduced the inspection time materially in the common room, with a small effect on overall frame throughput. Raw descriptor sync still took roughly 20.6–20.8 ms/frame, and typical frame summaries still spent about 110–123 ms in submit calls. Opposite-phase captures showed the same scene and the number of refreshed copies was steady. The focused tests also covered preserving a separate producer's dirty mark, invalidation, and retry of an unresolved buffer.
@rafaconvaitis on GitHub · 2026-11-25 20:26 UTC · original
Follow-up to my RTX 4070/Windows result above, with finer timers on the same Flamingo
63d976bline. Same Series S checkpoint, warm cache, Relay 1, async submit off, in-world fixed camera. Instrumentation and theREFRESH_ONCEcomparison were armed after entering the controllable scene.For the unoptimized control (69 matched per-second samples), the raw descriptor sync interval measured 22.07 ms/frame median: 2.40 ms finding dirty ranges, 1.91 ms reading pages, 3.05 ms scanning/fingerprinting records under the copied-record lock, and 14.24 ms applying the due records. Outer heap-lock acquisition rounded to 0.00 ms. Typical work was about 257k records inspected and 11.8k due records/frame. These are nested timings and the medians do not sum exactly. The application loop, rather than page reads or fingerprints, was the largest part of descriptor sync on this particular workload.
For context, the independent
VICTORY_REFRESH_ONCE=alttest in the same process (four complete intervals per mode) recorded 1,432 reused refresh requests/frame when on, but actual refresh calls fell only from 5,861 to 5,539, and effective FPS was 7.71 vs 7.76, P95 174 vs 177 ms. The raw descriptor breakdown barely moved. This is a baseline for choosing which of the isolated changes here to measure next, not a test of the remaining changes in this PR.@UwUCammie on GitHub · 2026-11-25 20:49 UTC · original
The RX 7900 XT shows the same ordering as the RTX 4070 report above. In the prison scene, my local stack with #1043, parallel heap scanning and batched null descriptors spent a median 12.71 ms/frame applying due records, 4.89 ms scanning pages in parallel and sorting the results, 2.46 ms collecting dirty ranges, and 0.51 ms acquiring the outer heap locks. The scan timer includes worker setup and join. Total descriptor sync was 21.64 ms/frame at roughly 356k inspected slots and 32k mirrored slots. The phase medians were taken separately.
CachyOS, Wine 11.22, vkd3d-proton, RADV 26.3.1. These are 23 reporting intervals from seconds 270–390 of a scripted run with relay 2 and async submit. Separately,
watch::writesworkers spent 127 ms/frame in aggregate acquiring the journal lock. That measures overlapping worker waits and can’t be subtracted from frame time. This run profiles the stack; it doesn’t isolate the effect of #1043.@rafaconvaitis on GitHub · 2026-11-25 22:20 UTC · original
I measured the typed-null descriptor reuse opportunity on the pinned Flamingo 63d976b base, native D3D12 on an RTX 4070 (616.64), Series S. This isolates replacing fresh deferred CBV/raw SRV/typed UAV nulls with copies from an immutable CPU heap. A native debug-layer readback test confirmed identical null behavior and restoration of the live descriptors.
Once the prison checkpoint loaded and the camera responded, I alternated modes every 20 seconds in one process with fixed camera and the same cache. Four complete windows per mode yielded 413 presents off and 415 on in intervals entirely contained in their windows. The median on-mode rate was 5,004.8 typed-null copies per frame. Effective FPS was 8.187 off and 8.188 on. Per-frame medians were 12.98 and 12.81 ms for applying descriptor records, and 20.66 and 20.05 ms for overall descriptor sync. P95 frame time was 162 and 165 ms. Draw count medians were 4,357 and 4,529, so the workload still had natural variation.
This implementation is local and opt-in. The fixed-scene data suggests this part of driver descriptor creation alone has little leverage on this scene's frame rate.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.