perf: reduce native CPU and memory overhead #4082

Closed
igorevv wants to merge 1 commit from upstream-pr/4082 into main
igorevv commented 2026-11-30 15:42:05 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by igorevv on 2026-11-30T15:42:05Z.


# perf: reduce native CPU and memory overhead

Summary

This PR implements six native optimizations across texture queues, shared-zero buffers, held submissions, pipeline naming, pooled allocation, and XMA decoding.

Changes are intended to reduce recording/submission CPU work, allocator pressure, startup overhead, and retained VRAM without changing rendered output.

Changes

1. Enable due-frame indexing by default

VICTORY_DUE_INDEX now defaults to enabled, with VICTORY_DUE_INDEX=0 preserving the previous flat-scan behavior.

The indexed collector was kept at parity with the flat queue:

  • recently sampled held entries can still wake before their original due frame;
  • FLAG_SOON is set through the storage-independent update path;
  • streamed-out slots returning to memory retain their priority.

The streamed-out regression test now runs against both flat and indexed queues.

2. Retire outgrown shared-zero buffers

Outgrown shared-zero buffers are passed to retire_resource instead of being retained permanently.

Both shared-zero copy paths also call list.keep(&buffer), ensuring recorded but not-yet-submitted lists retain their source resource. This prevents use-after-free when a larger shared buffer replaces an older one.

Once the shared buffer reaches 256 MiB, the obsolete 4+8+16+32+64+128 MiB buffers no longer remain permanently owned: 252 MiB of historical allocations become eligible for retirement after their users finish.

3. Remove quadratic held-queue draining

QueueLine.commands now uses VecDeque<Held> and pop_front() instead of Vec<Held> and remove(0).

Submission, wait, signal, retirement, and test ordering are unchanged. Draining no longer shifts every remaining entry for each released command.

4. Borrow DXIL for pipeline-library names

pipeline::host::code_bytes now returns &[u8] rather than Vec<u8>.

This removes one allocation and a complete DXIL memcpy per shader stage when computing pipeline-library names. Hash inputs and resulting names remain byte-identical.

5. Remove temporary vectors and sorting from pool placement

Added a read-only Ranges::fits check using the same arithmetic as Ranges::take.

Pool placement now selects the fitting block in one scan:

  • fullest fitting block first, preserving index order on ties;
  • first fitting block when fullest-first is disabled;
  • oldest fitting block for the unripe fallback.

take is called only for the selected block. Temporary index vectors and O(blocks log blocks) sorting are no longer needed for each allocation.

6. Reuse XMA decode scratch

Each Voice now owns a reusable PCM scratch vector. Decode clears and reuses its capacity instead of allocating a new vector for every frame.

At 48 kHz with 512-sample frames, this targets approximately 93.75 allocation/free pairs per second per active voice. Only 1–2 KiB of scratch is retained per active voice, and decoded PCM behavior is unchanged.

Changed files

  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/pipeline/host.rs
  • crates/victory-gpu/src/pool.rs
  • crates/victory-gpu/src/queue.rs
  • crates/victory-gpu/src/texture.rs
  • crates/victory-hle/src/modules/audio.rs

Validation

Targeted tests passed:

Queue tests:                         17 passed
Pool placement/range tests:           4 passed
Due-index and streamed-slot tests:    5 passed
Pipeline host tests:                  4 passed
Audio tests:                         11 passed
                                      ---------
Total:                               41 passed

Additional checks:

  • independent code review: no remaining blockers;
  • git diff --check: passed;
  • cargo xtask policy --staged: passed for all six files.

The complete 982-test GPU run aborts with exit code 3 in device-dependent tests in this environment. Targeted tests covering the modified areas passed. No game run or real-GPU performance comparison was performed, so FPS and memory improvements still need before/after measurement on a real title workload.

Suggested runtime measurements

  • Compare VICTORY_DUE_INDEX=0 against the new default using VICTORY_AB.
  • Record median/p95/p99 frame time, submit/preparing time, and texture-queue lock waits.
  • Force shared-zero growth, drain submissions, and compare live D3D12 resources, DXGI local memory, and process commit.
  • Compare allocation counts and submit time for pool-heavy and XMA-heavy workloads.
  • Verify pipeline-library names and rendered output are unchanged.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5568523747 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4082). Originally posted by [igorevv](https://github.com/igorevv) on 2026-11-30T15:42:05Z. --- # perf: reduce native CPU and memory overhead ## Summary This PR implements six native optimizations across texture queues, shared-zero buffers, held submissions, pipeline naming, pooled allocation, and XMA decoding. Changes are intended to reduce recording/submission CPU work, allocator pressure, startup overhead, and retained VRAM without changing rendered output. ## Changes ### 1. Enable due-frame indexing by default `VICTORY_DUE_INDEX` now defaults to enabled, with `VICTORY_DUE_INDEX=0` preserving the previous flat-scan behavior. The indexed collector was kept at parity with the flat queue: - recently sampled held entries can still wake before their original due frame; - `FLAG_SOON` is set through the storage-independent update path; - streamed-out slots returning to memory retain their priority. The streamed-out regression test now runs against both flat and indexed queues. ### 2. Retire outgrown shared-zero buffers Outgrown shared-zero buffers are passed to `retire_resource` instead of being retained permanently. Both shared-zero copy paths also call `list.keep(&buffer)`, ensuring recorded but not-yet-submitted lists retain their source resource. This prevents use-after-free when a larger shared buffer replaces an older one. Once the shared buffer reaches 256 MiB, the obsolete 4+8+16+32+64+128 MiB buffers no longer remain permanently owned: **252 MiB of historical allocations become eligible for retirement** after their users finish. ### 3. Remove quadratic held-queue draining `QueueLine.commands` now uses `VecDeque<Held>` and `pop_front()` instead of `Vec<Held>` and `remove(0)`. Submission, wait, signal, retirement, and test ordering are unchanged. Draining no longer shifts every remaining entry for each released command. ### 4. Borrow DXIL for pipeline-library names `pipeline::host::code_bytes` now returns `&[u8]` rather than `Vec<u8>`. This removes one allocation and a complete DXIL memcpy per shader stage when computing pipeline-library names. Hash inputs and resulting names remain byte-identical. ### 5. Remove temporary vectors and sorting from pool placement Added a read-only `Ranges::fits` check using the same arithmetic as `Ranges::take`. Pool placement now selects the fitting block in one scan: - fullest fitting block first, preserving index order on ties; - first fitting block when fullest-first is disabled; - oldest fitting block for the unripe fallback. `take` is called only for the selected block. Temporary index vectors and `O(blocks log blocks)` sorting are no longer needed for each allocation. ### 6. Reuse XMA decode scratch Each `Voice` now owns a reusable PCM scratch vector. Decode clears and reuses its capacity instead of allocating a new vector for every frame. At 48 kHz with 512-sample frames, this targets approximately **93.75 allocation/free pairs per second per active voice**. Only 1–2 KiB of scratch is retained per active voice, and decoded PCM behavior is unchanged. ## Changed files - `crates/victory-gpu/src/descriptor/host.rs` - `crates/victory-gpu/src/pipeline/host.rs` - `crates/victory-gpu/src/pool.rs` - `crates/victory-gpu/src/queue.rs` - `crates/victory-gpu/src/texture.rs` - `crates/victory-hle/src/modules/audio.rs` ## Validation Targeted tests passed: ```text Queue tests: 17 passed Pool placement/range tests: 4 passed Due-index and streamed-slot tests: 5 passed Pipeline host tests: 4 passed Audio tests: 11 passed --------- Total: 41 passed ``` Additional checks: - independent code review: no remaining blockers; - `git diff --check`: passed; - `cargo xtask policy --staged`: passed for all six files. The complete 982-test GPU run aborts with exit code 3 in device-dependent tests in this environment. Targeted tests covering the modified areas passed. No game run or real-GPU performance comparison was performed, so FPS and memory improvements still need before/after measurement on a real title workload. ## Suggested runtime measurements - Compare `VICTORY_DUE_INDEX=0` against the new default using `VICTORY_AB`. - Record median/p95/p99 frame time, submit/preparing time, and texture-queue lock waits. - Force shared-zero growth, drain submissions, and compare live D3D12 resources, DXGI local memory, and process commit. - Compare allocation counts and submit time for pool-heavy and XMA-heavy workloads. - Verify pipeline-library names and rendered output are unchanged.
shurhundo commented 2026-11-30 15:58:54 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by shurhundo on 2026-11-30T15:58:54Z.


nit: queue.rs, a_line_in_hand_outlives_its_queue_and_is_retired: the assertion went from checking the whole deque is exactly one Held::Run (matches!(&lock(&worker.commands)[..], [Held::Run(..)])) to only checking the front element (matches!(lock(&worker.commands).front(), Some(Held::Run(..)))). Harmless today, since nothing else pushes to commands in this test, but it no longer catches a future regression that leaves a second entry behind. Since Held has no PartialEq, an assert_eq!(lock(&worker.commands).len(), 1) next to the existing check would restore that without needing one.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7283924238 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4082#issuecomment-7283924238). Originally posted by [shurhundo](https://github.com/shurhundo) on 2026-11-30T15:58:54Z. --- nit: `queue.rs`, `a_line_in_hand_outlives_its_queue_and_is_retired`: the assertion went from checking the whole deque is exactly one `Held::Run` (`matches!(&lock(&worker.commands)[..], [Held::Run(..)])`) to only checking the front element (`matches!(lock(&worker.commands).front(), Some(Held::Run(..)))`). Harmless today, since nothing else pushes to `commands` in this test, but it no longer catches a future regression that leaves a second entry behind. Since `Held` has no `PartialEq`, an `assert_eq!(lock(&worker.commands).len(), 1)` next to the existing check would restore that without needing one.
trustno1-coder commented 2026-12-01 18:46:41 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:46:41Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321524623 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4082#issuecomment-7321524623). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:46:41Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

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