Skip to content

gpu/descriptor: 2-level 64-bit bitmap DynamicSlots allocator and batched reclamation - #704

Open
mint17 wants to merge 1 commit into
trustno1-coder:mainfrom
mint17:perf/dynamic-slots-bitmap-batch-release
Open

mint17 wants to merge 1 commit into
trustno1-coder:mainfrom
mint17:perf/dynamic-slots-bitmap-batch-release

Conversation

@mint17

@mint17 mint17 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Replaces the byte-per-slot Vec<bool> linear scan in HostHeap::dynamic and per-range release_dynamic lock loops in State::tables_done / Drop for State with a pure-Rust 2-level 64-bit bitmap allocator and batched reclamation (zero conflict with #646, #666, or #693).

Changes

  • 2-level 64-bit bitmap DynamicSlots (slots.rs): Level-0 u64 occupancy words + Level-1 summary bitmap skipping completely full 64-word (4,096-slot) chunks in one instruction, O(log n) bit-parallel within-word run search, O(1) cross-word fast path for n <= 64, exact next-fit cursor / wraparound / too_long watermark parity, and overflow-clamped release_batch.
  • Batched reclamation (descriptor.rs, descriptor/host.rs, draw.rs): release_dynamic_batch takes SHADER_HEAPS.read() once per command list (zero-alloc fast path for single-heap batches, sorted chunk_by for multi-heap batches, filtering stale heap IDs and title-slot indices < host.count()). Preserves PORTABLE_VIEWS, VICTORY_DYNAMIC_SLOTS, slot_evict, and diagnostics copystat counters verbatim.

Release Microbenchmark (cargo test --release --locked -p victory-gpu --lib bench_dynamic_slots_vs_vec_bool -- --ignored --nocapture)

Capacity Regime (30,000 alloc+release) Baseline (Vec<bool> + per-range) New (DynamicSlots + batch) Speedup
262,144 Normal 3,121 µs 1,100 µs 2.8×
262,144 Fragmented 18,915 µs 1,062 µs 17.8×
262,144 High occupancy 3,993 µs 1,054 µs 3.8×
1,048,576 Normal 2,529 µs 1,042 µs 2.4×
1,048,576 Fragmented 18,798 µs 1,083 µs 17.4×
1,048,576 High occupancy 3,999 µs 1,041 µs 3.8×

Verification

  • cargo test --locked -p victory-gpu --lib -- descriptor::slots dynamic_slots descriptor::host::tests -- --test-threads=1 (52 passed, 0 failed — includes 127,500+ op randomized Vec<bool> oracle parity tests across 13 capacities, wraparound / too_long tests, and multi-heap / wrong-ID / title-slot batch reclamation tests).
  • cargo test --locked -p victory-gpu --lib --features diagnostics -- descriptor::slots dynamic_slots -- --test-threads=1 (8 passed, 0 failed).
  • Zero Clippy warnings across all added/modified files (default + --all-features) and cargo test --locked -p xtask passed (6 passed, 0 failed, including asset policy).
  • Verified with synthetic unit tests, oracle tests, and microbenchmarks only (no game files).

…hed reclamation

Replace the byte-per-slot Vec<bool> linear scan in HostHeap::dynamic and
per-range release_dynamic lock loops in State::tables_done / Drop with a
pure-Rust 2-level 64-bit bitmap allocator and batched reclamation:

- Add crates/victory-gpu/src/descriptor/slots.rs (L0 u64 occupancy words +
  L1 non-full summary words, O(log n) bit-parallel within-word scan, O(1)
  cross-word fast path for n <= 64, next-fit cursor & too_long watermark,
  clamped release_batch).
- Add descriptor::release_dynamic_batch (single SHADER_HEAPS.read() lock,
  zero-alloc fast path for single-heap batches, sorted chunk_by multi-heap
  path, wrong/stale heap ID and title-slot bounds filtering) and switch
  State::tables_done / Drop for State to use it.
- Preserve VIctory-NVIDIA's PORTABLE_VIEWS, VICTORY_DYNAMIC_SLOTS,
  slot_evict, and diagnostics copystat counters verbatim.
- Add 127,500+ op Vec<bool> oracle parity tests across 13 capacities,
  wraparound/too_long tests, multi-heap batch reclamation tests, and an
  opt-in release microbenchmark (17.8x fragmented speedup at 262K slots,
  17.4x at 1M slots).

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — verified on Windows (RTX 5090):

  • cargo test -p victory-gpu --lib descriptor:: passed (67/67, including oracle_parity_randomized_all_capacities_and_edge_cases, find_zero_run_in_word_matches_naive_exhaustive_patterns, wrap_across_cursor_and_no_physical_wrap_parity, and release_dynamic_batch_handles_empty_single_multi_wrong_id_and_stale)
  • 0 new compiler warnings in touched files
  • cargo xtask policy passed (295 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

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.

2 participants