Skip to content

perf(gpu): stripe HostHeap slot locks and scope bindless heap sweeps to bound heaps - #404

Open
gdemontalivet wants to merge 1 commit into
pragyaangaur:mainfrom
gdemontalivet:perf/macos-striped-heap-mirror
Open

gdemontalivet wants to merge 1 commit into
pragyaangaur:mainfrom
gdemontalivet:perf/macos-striped-heap-mirror

Conversation

@gdemontalivet

Copy link
Copy Markdown
Contributor

Building on #279's fast-skip bitset and forget-epoch cache in sync_slots_bytes, two sources of descriptor-heap lock contention and redundant submission work remain on HostHeap:

  1. HostHeap::mirror and HostHeap::kept global mutexes: Even when ready[index] matches on the mirror fast path, needs_remake locks the heap-wide kept: Mutex<Paged<Held>> on every draw-bound texture view, and slow-path descriptor updates serialize all recording threads on the single made and kept mutexes while calling host::retire under the lock. Candidate checks in sync_slots_bytes, evict, unmade_placed, and stamp_read likewise acquire those heap-wide locks.
  2. Unscoped submission-time heap sweeps: Every GPU submission walks all registered shader-visible heaps in SHADER_HEAPS—even copy/upload-only submissions or heaps not bound by any submitted command list—and run_deferred re-sweeps the same Viewed heap when multiple command lists in a batch reference it without an intervening title write.

Changes

  • Lock-free mirror cache hits and candidate checks: Store HostHeap::made as Box<[AtomicU64]> and track each title slot's raw resource pointer in kept_raw: Box<[AtomicUsize]>, so mirror cache hits, needs_remake, unmade_placed, stamp_read, and sync_slots_bytes candidate comparisons take zero mutexes.
  • 256 cache-aligned StripeLocks for slow-path updates and Paged<Held>: Shard slow-path slot updates and sparse Paged<Held> storage across 256 64-byte-aligned stripes, and retire displaced ID3D12Resource objects outside all heap locks.
  • Command-list lifetime retention for view_addresses: Expose view_addresses_resource so draw.rs retains the upload buffer via list.keep(buffer) until command-list reset.
  • Submission-scoped bindless sweeps (sync_heaps_for & Batch::swept_heaps): Record shader-visible heaps bound on each HostList (note_bound_heap) and sync only heaps bound or referenced by the submitted lists, preserving dirty ranges on unbound heaps until a submission binds them. Deduplicate Step::Heap sweeps in host::execute and across Batch until a title write invalidates swept_heaps.

Synthetic Benchmarks (CrossOver Preview + D3DMetal on M5 Max)

  • concurrent_striped_mirror_and_fast_path_benchmark (8 threads, 4,096 slots): 270–411 Kviews/s concurrent striped Create*View updates and 7.8–10.7 Mops/s lock-free mirror cache hits, with zero D3D12 debug or device-removal messages.
  • submissions_only_sync_bound_heaps: verifies unbound placed heaps are skipped during unrelated submissions while retaining their dirty page marks until bound.

Live M5 Max Verification (Combined Build on CrossOver Preview + D3DMetal)

  • In a combined warm-cache 720p opening-sequence run on Apple M5 Max (CrossOver Preview + D3DMetal, wave32=true), the runtime reached and sustained the 3D world through +8, +24, +48, +90 at 1.5–1.8 FPS (549.7–672.1 ms/frame on 1,021–1,258 draws/frame, 1.275 FPS overall across +8..+90) with 0 2.48 s allocation stalls, 7.2–9.0 ms/frame GUARDS lock hold time (down from 4,887 ms/frame before unlocking GUARDS), 149–154 MB/frame buffer copy volume, 0 DirectStorage decompression or access-violation failures, and 38/38 over-32 KiB aligned mesh/pixel pairs linked with 0 host mesh refusals.

Verification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant