perf(gpu): batch constant_slots under one SHADER_HEAPS lock, skip Does::Refresh without copies, and zero-clone prelude_uploads #4042

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

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


Summary

Cuts submitting-thread and sending-thread CPU overhead in card_steps and prelude_uploads:

  1. Batched descriptor::constant_slots_batch & constant_slots_shown (descriptor.rs, descriptor/host.rs, host/card_steps.rs):
    • Holds SHADER_HEAPS.read() once outside the worker pool instead of ~11,000 contended RwLock acquisitions/frame across 8 threads.
    • Pre-resolves distinct &HostHeap targets once, pre-buckets ops by worker (index / 4 % parts) so workers do not scan the full slice 8x, and passes precomputed buffer_gpu via HostHeap::constant_at_with_base to eliminate ~11,000 COM GetGPUVirtualAddress() calls/frame.
  2. Skip Does::Refresh in card_steps::does_of when no Step::Copy exists:
    • Does::Refresh is only consulted by elsewhere() when evaluating Does::Copy; skipping refreshes when !has_copy shrinks does/steps/taken/given by ~5-10x on copy-free submissions.
  3. Zero-clone HostList::prelude_uploads fast path (texture.rs, host.rs):
    • Adds lock-free PreludeUpload::needs_finish_refresh() so prelude_uploads avoids cloning the entire Vec (and 3 Arcs per entry) for the ~99% of textures already uploaded and clean, while still releasing self.deferred() before calling finish_refresh().

Verification

  • cargo check -p victory-gpu --all-targets --all-features --locked: exit 0.
  • cargo test -p victory-gpu --lib --locked -- descriptor:: host::card_steps:: --test-threads=1: 125 passed, 0 failed.
  • git merge-tree --write-tree 41adb551 HEAD: clean merge.
  • 90s in-game runs (RTX 4070 Ti, 1440p DLSS Balanced Native & FG 2x, 0 WARNs / 0 ERRORs): sending-thread heaps + slots down to 0.2 ms.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5567863192 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4042). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-30T15:05:11Z. --- ## Summary Cuts submitting-thread and sending-thread CPU overhead in `card_steps` and `prelude_uploads`: 1. **Batched `descriptor::constant_slots_batch` & `constant_slots_shown` (`descriptor.rs`, `descriptor/host.rs`, `host/card_steps.rs`)**: - Holds `SHADER_HEAPS.read()` once outside the worker pool instead of ~11,000 contended `RwLock` acquisitions/frame across 8 threads. - Pre-resolves distinct `&HostHeap` targets once, pre-buckets ops by worker (`index / 4 % parts`) so workers do not scan the full slice 8x, and passes precomputed `buffer_gpu` via `HostHeap::constant_at_with_base` to eliminate ~11,000 COM `GetGPUVirtualAddress()` calls/frame. 2. **Skip `Does::Refresh` in `card_steps::does_of` when no `Step::Copy` exists**: - `Does::Refresh` is only consulted by `elsewhere()` when evaluating `Does::Copy`; skipping refreshes when `!has_copy` shrinks `does`/`steps`/`taken`/`given` by ~5-10x on copy-free submissions. 3. **Zero-clone `HostList::prelude_uploads` fast path (`texture.rs`, `host.rs`)**: - Adds lock-free `PreludeUpload::needs_finish_refresh()` so `prelude_uploads` avoids cloning the entire `Vec` (and 3 `Arc`s per entry) for the ~99% of textures already uploaded and clean, while still releasing `self.deferred()` before calling `finish_refresh()`. ## Verification - `cargo check -p victory-gpu --all-targets --all-features --locked`: exit 0. - `cargo test -p victory-gpu --lib --locked -- descriptor:: host::card_steps:: --test-threads=1`: 125 passed, 0 failed. - `git merge-tree --write-tree 41adb551 HEAD`: clean merge. - 90s in-game runs (RTX 4070 Ti, 1440p DLSS Balanced Native & FG 2x, 0 WARNs / 0 ERRORs): sending-thread `heaps + slots` down to `0.2 ms`.
trustno1-coder commented 2026-12-01 18:46:51 +00:00 (Migrated from github.com)

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


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:7321530335 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4042#issuecomment-7321530335). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:46:51Z. --- 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!4042
No description provided.