perf(descriptor): batch TextureQueue writes across CopyDescriptors, sync_heaps, mirror_range, and heap_buffer_pass #1675

Manually merged
github merged 1 commit from github-bot/gh-1675 into main 2026-11-29 08:21:05 +00:00 AGit
Owner

@⁠qlfu on GitHub · 2026-11-28 23:21 UTC · original
qlfu:pr/batch-descriptor-queue-writes → main · +485 −68 · 3 files · 1 commits · merged 2026-11-29 08:16 UTC

What it changes

Enables concurrency-safe TextureQueue write batching (QueueBatch / QueueFlusher) across bulk descriptor mirroring paths and removes per-call allocations in CopyDescriptors:

  • crates/victory-gpu/src/descriptor/host.rs:
    • Adds per-slot slot_state: Box<[AtomicU32]> ((seq << 1) | keeps) bumped on queue state transitions (queue_texture_inner, tabled_in_as, stale eviction in note_buffer_inner, and texture_slot_sampled_again) so deferred QueueBatch flushes can safely run on already-published heaps without resurrecting stale or tabled slots.
    • Uses a two-pass Dekker verification inside QueueBatch::apply with a single fence(SeqCst) per batch, keeping QueueMarks::set/get on Release/Acquire under the TextureQueue mutex.
    • Replaces QueueFlusher::new_unpublished(&mut HostHeap) with QueueFlusher::new(&HostHeap).
    • Adds multi-threaded consistency stress test queue_batch_concurrent_published_writes_and_removes_stay_consistent.
  • crates/victory-gpu/src/descriptor.rs:
    • Enables QueueFlusher::new(host) in Heap::host, mirror_range, and sync_heaps (before and make parallel chunks).
    • Rewrites copy (ID3D12Device::CopyDescriptors) to walk source/destination range pointers directly without temporary Vec allocations and mirror all destination ranges under a single hoisted SHADER_HEAPS.read() + QueueFlusher (mirror_ranges).
    • Adds unit test copy_multi_range_preserves_bytes_and_mirrors_single_slot_ranges and overlap regression coverage in mirror_range_overlap_falls_back_per_slot.
  • crates/victory-gpu/src/draw.rs:
    • Uses a per-chunk QueueFlusher::new(host) inside heap_buffer_pass's parallel each_view workers.

How it was tested

  • GPU and profile: RTX 4070 Ti 12 GB + Ryzen 7 5700X, Series X (game_scarlett_master.exe), 1440p DLSS Balanced, -NoFrameGenReady, VICTORY_PORT_CONSTANTS=1, VICTORY_WAIT_RESIDENT=textures, clean 90s gameplay runs (0 WARNs / 0 ERRORs).
  • Before (stack7 without this PR):
    • TextureQueue WRITE lock takes: 58,530 / 5s median (59,375 mean)
    • Frame times: med 44.2 ms, p95 65.4 ms, p99 74.6 ms, >100 ms: 16/2484 (0.6%)
    • Submitting thread sub_all: 38.65 ms median, VICTORY_THIN: 248.25 ms, title present-wait: 10.70 ms
  • After (stack8v2 with this PR):
    • TextureQueue WRITE lock takes: 44,418 / 5s median (45,784 mean, -24.1%)
    • Frame times: med 43.7 ms, p95 63.0 ms (-2.4 ms), p99 72.9 ms (-1.7 ms), >100 ms: 8/2417 (0.3%) (-50%)
    • Submitting thread sub_all: 36.25 ms median (-2.4 ms), VICTORY_THIN: 237.30 ms (-11.0 ms), title present-wait: 5.90 ms (-4.8 ms)
  • cargo clippy -p victory-gpu --lib --tests --locked (default & --all-features): 0 new warnings.
  • cargo test passed for the crates it touches: yes (552 passed; 0 failed in cargo test -p victory-gpu --lib --locked -- --test-threads=1).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1616 (also removes temporary allocations in single-range CopyDescriptors; this PR additionally batches multi-range CopyDescriptors and enables concurrency-safe QueueBatch across sync_heaps, mirror_range, and heap_buffer_pass).
**@⁠qlfu** on GitHub · 2026-11-28 23:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1675) `qlfu:pr/batch-descriptor-queue-writes` → `main` · +485 −68 · 3 files · 1 commits · merged 2026-11-29 08:16 UTC ## What it changes Enables concurrency-safe `TextureQueue` write batching (`QueueBatch` / `QueueFlusher`) across bulk descriptor mirroring paths and removes per-call allocations in `CopyDescriptors`: - **`crates/victory-gpu/src/descriptor/host.rs`**: - Adds per-slot `slot_state: Box<[AtomicU32]>` (`(seq << 1) | keeps`) bumped on queue state transitions (`queue_texture_inner`, `tabled_in_as`, stale eviction in `note_buffer_inner`, and `texture_slot_sampled_again`) so deferred `QueueBatch` flushes can safely run on already-published heaps without resurrecting stale or tabled slots. - Uses a two-pass Dekker verification inside `QueueBatch::apply` with a single `fence(SeqCst)` per batch, keeping `QueueMarks::set`/`get` on `Release`/`Acquire` under the `TextureQueue` mutex. - Replaces `QueueFlusher::new_unpublished(&mut HostHeap)` with `QueueFlusher::new(&HostHeap)`. - Adds multi-threaded consistency stress test `queue_batch_concurrent_published_writes_and_removes_stay_consistent`. - **`crates/victory-gpu/src/descriptor.rs`**: - Enables `QueueFlusher::new(host)` in `Heap::host`, `mirror_range`, and `sync_heaps` (`before` and `make` parallel chunks). - Rewrites `copy` (`ID3D12Device::CopyDescriptors`) to walk source/destination range pointers directly without temporary `Vec` allocations and mirror all destination ranges under a single hoisted `SHADER_HEAPS.read()` + `QueueFlusher` (`mirror_ranges`). - Adds unit test `copy_multi_range_preserves_bytes_and_mirrors_single_slot_ranges` and overlap regression coverage in `mirror_range_overlap_falls_back_per_slot`. - **`crates/victory-gpu/src/draw.rs`**: - Uses a per-chunk `QueueFlusher::new(host)` inside `heap_buffer_pass`'s parallel `each_view` workers. ## How it was tested - GPU and profile: RTX 4070 Ti 12 GB + Ryzen 7 5700X, Series X (`game_scarlett_master.exe`), 1440p DLSS Balanced, `-NoFrameGenReady`, `VICTORY_PORT_CONSTANTS=1`, `VICTORY_WAIT_RESIDENT=textures`, clean 90s gameplay runs (`0 WARNs / 0 ERRORs`). - Before (`stack7` without this PR): - `TextureQueue` `WRITE` lock takes: `58,530 / 5s` median (`59,375` mean) - Frame times: `med 44.2 ms`, `p95 65.4 ms`, `p99 74.6 ms`, `>100 ms: 16/2484 (0.6%)` - Submitting thread `sub_all`: `38.65 ms` median, `VICTORY_THIN`: `248.25 ms`, title `present-wait`: `10.70 ms` - After (`stack8v2` with this PR): - `TextureQueue` `WRITE` lock takes: `44,418 / 5s` median (`45,784` mean, **-24.1%**) - Frame times: `med 43.7 ms`, `p95 63.0 ms` (**-2.4 ms**), `p99 72.9 ms` (**-1.7 ms**), `>100 ms: 8/2417 (0.3%)` (**-50%**) - Submitting thread `sub_all`: `36.25 ms` median (**-2.4 ms**), `VICTORY_THIN`: `237.30 ms` (**-11.0 ms**), title `present-wait`: `5.90 ms` (**-4.8 ms**) - `cargo clippy -p victory-gpu --lib --tests --locked` (default & `--all-features`): 0 new warnings. - `cargo test` passed for the crates it touches: yes (`552 passed; 0 failed` in `cargo test -p victory-gpu --lib --locked -- --test-threads=1`). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1616 (also removes temporary allocations in single-range `CopyDescriptors`; this PR additionally batches multi-range `CopyDescriptors` and enables concurrency-safe `QueueBatch` across `sync_heaps`, `mirror_range`, and `heap_buffer_pass`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 23:24:39 +00:00
Author
Owner

@⁠amazedturnip on GitHub · 2026-11-29 05:38 UTC · original

Tested on 9800X3D + RTX 5070 Ti 16 GB in a combined perf stack across 20+ min gameplay sessions. Zero descriptor glitches or lockups; TextureQueue lock waits stayed low and combined stack moved ~4.2k-draw scenes from ~23 fps to ~31.6-33.5 fps.

**@⁠amazedturnip** on GitHub · 2026-11-29 05:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1675#issuecomment-7251375775) Tested on 9800X3D + RTX 5070 Ti 16 GB in a combined perf stack across 20+ min gameplay sessions. Zero descriptor glitches or lockups; TextureQueue lock waits stayed low and combined stack moved ~4.2k-draw scenes from ~23 fps to ~31.6-33.5 fps.
github manually merged commit 558d65f89c into main 2026-11-29 08:21:05 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!1675
No description provided.