Repository navigation
perf(gpu): lock-free view generations, synced slot cache, and batched CopyDescriptors heap sync - #439
gdemontalivet wants to merge 1 commit into
Conversation
…irroring Cut submission-time descriptor heap sync overhead (`sync_heaps` / `sync_slots_bytes`) across large dirty page ranges and repeated records: - Add a lock-free 2-level generation mirror (`VIEW_GENS`) and batched `views_at_batch()` in `descriptor.rs`, plus a thread-local reusable page read buffer in `sync_heaps()`. - Add a lock-free `synced` mirror of `made` on `HostHeap` (covering placed textures left null and evicted slots whose `ready` entry is 0), and scan `sync_slots_bytes` per 128-slot block and 64-slot `made_nonzero` word with zero lock acquisitions or heap allocations on clean slots. - Add `mirror_synced_batch()` with a lazy CPU-only staging heap (`D3D12_DESCRIPTOR_HEAP_FLAG_NONE`) pre-populated with all 17 null SRV/UAV/sampler kinds plus per-batch template slots for repeated keys, flushing descriptor copies in a single `CopyDescriptors` call per page and batching `made`, `kept` (`keep_batch` with same-resource fast path), `viewed` (`Viewed::set_batch` with pointer-keyed `Seen` dedup), `shadow::forget_reads`, and `host::retire_all` under one lock hold each. - Gate the optimized path behind `VICTORY_FAST_HEAP_SYNC` (default on; set `=0` for legacy A/B comparison). - Add unit tests covering `view_gen_current`, `views_at_batch`, placed-null lock-free skips, duplicate template copies, immediate `forget()` invalidation, concurrent rewrites during `prepare()`, and a synthetic 1.5M-slot fast-vs-legacy benchmark.
|
M2 Max measurements on
Both orders agreed on the direction. The order affects the magnitude, so these figures apply to this synthetic workload. All 41 descriptor tests passed on the original revision, including the concurrent-rewrite and invalidation checks. The CPU/GPU shared-buffer coherence test also passed separately. This is no measurement of whole-game FPS or memory footprint. |
|
M5 Pro (48 GB), Rosetta + CrossOver/Wine 11.0, D3DMetal 4.0 beta 3: an encouraging same-executable The tested integration is retained in Michael's fork, head At the initial tutorial-room pose, each launch settled for 20 seconds and then remained stationary for 120 seconds with no manual input. These are medians of paired diagnostic interval averages, not individual-frame percentiles.
In this pair, heap synchronization decreased 60.5% and total frame time 28.1%. This is one sequential off/on pair: idle animation and draw counts differ, and GPU time also moved. It supports the fast path on this workload, but does not establish a general speedup or attribute the entire frame difference to heap synchronization. The off build includes the PR's other infrastructure. After the enabled measurement I verified movement away from the starting wall, stopping on release, independent camera, more than seven unpaused world minutes, pause/resume and camera response afterwards. Both runs ended intentionally and recovered; neither logged an unhandled title exception or Metal completion error. Same-setting relaunch of the enabled variant remains unqualified. Observed world performance remains roughly 2–3 FPS in this room, with darker/washed-out surfaces and existing menu clipping; this is not comfortable playability. Integration gates: native 598 passed / 0 failed / 17 ignored; serial Wine 1,164 passed / 0 failed / 29 ignored, no SKIPPED lines. Native Clippy, strict Windows Clippy default/all-features and policy passed. Formatting still fails on the same 81 paths as the unmodified base; no fully green formatting gate is claimed. Prepared and tested by GPT-6 Astra on Michael's Mac. Game artifacts and raw logs remain local. |
|
In-game check on an M5 Pro (macOS 27.0.1, CrossOver 26.3 Wine with the repo's current patches, D3DMetal 4.0 beta 3, Series X), with #439 and #419 together on
I didn't test them separately, so I can't say how the gain splits between them. Prepared with Claude Code. |
Summary
VIEW_GENSgeneration table (descriptor.rs), lock-freeHostHeap::syncedcache covering placed-texture-left-null & evicted slots, per-128-slot-blockblock_forgotchecks, and a thread-localSYNC_PAGE_BUF.mirror_synced_batch()(VICTORY_FAST_HEAP_SYNC, default ON,0opts out for A/B testing) using a 256-slot CPU-onlyStagingHeappre-populated with null descriptors plus per-batch template slots flushed via oneCopyDescriptorscall per page, and batcheskeep_batch,Viewed::set_batch,shadow::forget_reads, andhost::retire_all.Measured M5 Max (CrossOver / D3DMetal) Impact
bench_sync_slots_1_5m_fast_vs_legacy):18.05 ms → 7.58 ms(2.38× faster uncontended).wave5-sync-allvswave3-heap-bake):heap slots the title copieddropped from63.8–67.6 ms/frame → 18.8 ms/frame(-71% / 3.5× faster)!Verification
cargo xtask policy: passcargo test -p victory-gpu: 102 passeddescriptor::): 41/41 passed (includingfast_heap_sync_handles_placed_null_duplicates_forget_and_concurrent_rewriteandbench_sync_slots_1_5m_fast_vs_legacy)cargo clippy --target x86_64-pc-windows-gnullvm --workspace --all-targets -- -D warnings(default &--features diagnostics): 0 warnings