perf(gpu): offload bury() COM drops off relay thread and batch dynamic slot releases #1358

Merged
qlfu merged 1 commit from upstream-pr/1358 into main 2026-11-30 14:12:04 +00:00
qlfu commented 2026-11-28 17:57:42 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-28T17:57:42Z.


Summary

Reduces relay-thread landing stalls and descriptor-heap lock contention by:

  1. Offloading bury() COM object drops to a dedicated victory-bury worker thread (crates/victory-gpu/src/host.rs):
    • relay_land() calls bury(last) right before clearing line.settling and notifying LINE_MOVED / LINE_LANDED, synchronously dropping ~20,000 retired ID3D12Resource COM references and freed D3D12 objects per frame (~3.75–8.75 ms/frame on the relay thread).
    • bury() now drains the ready prefix from RETIRED and hands the Vec to a lazily spawned victory-bury thread with bounded backpressure (MAX_PENDING_BATCHES = 64; falls back to inline drop if full or if thread spawn fails).
  2. Batching dynamic descriptor slot releases (crates/victory-gpu/src/descriptor.rs, crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/draw.rs):
    • Replaces per-table release_dynamic() calls (~12,500 calls/frame from State::tables_done() and Drop for State) with release_dynamic_many() + HostHeap::release_many().
    • Acquires SHADER_HEAPS.read() once per command list and groups consecutive ranges sharing (heap, id) under a single HostHeap::next lock, updating free and too_long once per batch.

Verification

  • cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- --test-threads=1 --quiet: 456 passed, 0 failed, 36 ignored (including new tests host::bury_tests::bury_drops_retired_objects_asynchronously and descriptor::host::tests::dynamic_release_many_frees_disjoint_ranges_and_ignores_wrong_id).
  • cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --locked (default and --all-features): 0 warnings in modified files.
  • cargo +1.98.1-x86_64-pc-windows-msvc build --release --locked -p victory: exit 0.

Clean Idle-PC A/B Benchmark (Ryzen 7 5700X + RTX 4070 Ti 12 GB, 1440p Series X, DLSS Quality, -FrameGen, 90s steady gameplay)

Metric main (9ce3cf9, BASE_9ce3cf9_fg_clean) This PR (PR7_bury_fg_clean) Delta
Relay the rest (bury) median / mean / max 3.75 / 4.10 / 8.75 ms 0.73 / 0.72 / 1.10 ms -80.5% / -82.4% / -87.4%
Relay read-backs and lists median / mean 3.04 / 3.04 ms 2.46 / 2.66 ms -19.1% / -12.5%
Relay landing in all median / mean 24.75 / 23.70 ms 19.90 / 18.67 ms -19.6% / -21.2%
VICTORY_THIN translation median 257.5 ms 242.4 ms -5.9%
Median FPS / GPU busy 18.6 / 71.0% 18.8 / 76% +1.1% / +5 pp
WARNs / ERRORs 0 / 0 0 / 0 clean
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5543058545 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1358). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-28T17:57:42Z. --- ### Summary Reduces relay-thread landing stalls and descriptor-heap lock contention by: 1. **Offloading `bury()` COM object drops to a dedicated `victory-bury` worker thread** (`crates/victory-gpu/src/host.rs`): - `relay_land()` calls `bury(last)` right before clearing `line.settling` and notifying `LINE_MOVED` / `LINE_LANDED`, synchronously dropping ~20,000 retired `ID3D12Resource` COM references and freed D3D12 objects per frame (~3.75–8.75 ms/frame on the relay thread). - `bury()` now drains the ready prefix from `RETIRED` and hands the `Vec` to a lazily spawned `victory-bury` thread with bounded backpressure (`MAX_PENDING_BATCHES = 64`; falls back to inline drop if full or if thread spawn fails). 2. **Batching dynamic descriptor slot releases** (`crates/victory-gpu/src/descriptor.rs`, `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/draw.rs`): - Replaces per-table `release_dynamic()` calls (~12,500 calls/frame from `State::tables_done()` and `Drop for State`) with `release_dynamic_many()` + `HostHeap::release_many()`. - Acquires `SHADER_HEAPS.read()` once per command list and groups consecutive ranges sharing `(heap, id)` under a single `HostHeap::next` lock, updating `free` and `too_long` once per batch. ### Verification - `cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- --test-threads=1 --quiet`: **456 passed, 0 failed, 36 ignored** (including new tests `host::bury_tests::bury_drops_retired_objects_asynchronously` and `descriptor::host::tests::dynamic_release_many_frees_disjoint_ranges_and_ignores_wrong_id`). - `cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --locked` (default and `--all-features`): **0 warnings in modified files**. - `cargo +1.98.1-x86_64-pc-windows-msvc build --release --locked -p victory`: exit `0`. ### Clean Idle-PC A/B Benchmark (Ryzen 7 5700X + RTX 4070 Ti 12 GB, 1440p Series X, DLSS Quality, `-FrameGen`, 90s steady gameplay) | Metric | `main` (`9ce3cf9`, `BASE_9ce3cf9_fg_clean`) | This PR (`PR7_bury_fg_clean`) | Delta | |---|---:|---:|---:| | Relay `the rest` (`bury`) median / mean / max | `3.75 / 4.10 / 8.75 ms` | **`0.73 / 0.72 / 1.10 ms`** | **-80.5% / -82.4% / -87.4%** | | Relay `read-backs and lists` median / mean | `3.04 / 3.04 ms` | **`2.46 / 2.66 ms`** | **-19.1% / -12.5%** | | Relay `landing in all` median / mean | `24.75 / 23.70 ms` | **`19.90 / 18.67 ms`** | **-19.6% / -21.2%** | | `VICTORY_THIN` translation median | `257.5 ms` | **`242.4 ms`** | **-5.9%** | | Median FPS / GPU busy | `18.6` / `71.0%` | **`18.8`** / **`76%`** | +1.1% / +5 pp | | WARNs / ERRORs | `0 / 0` | **`0 / 0`** | clean |
qlfu commented 2026-11-29 10:14:27 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-29T10:14:27Z.


Rebased onto current \main\ (\829188e9): dropped the
elease_dynamic_batch\ hunks that already landed upstream, leaving a focused 1-file change (+72 lines in \host.rs) that offloads \ury()\ COM drops off the relay landing thread (preserving inline timing when \VICTORY_RELAY_TIMING=1). Verified in a clean 90s gameplay run on \829188e9: \land_rest\ dropped from 6.19 ms/frame to 1.48 ms/frame (-4.71 ms/frame on the relay thread), \ury_drops_retired_objects_asynchronously\ passes.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7254301637 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1358#issuecomment-7254301637). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-29T10:14:27Z. --- Rebased onto current \main\ (\829188e9\): dropped the \ elease_dynamic_batch\ hunks that already landed upstream, leaving a focused 1-file change (+72 lines in \host.rs\) that offloads \ury()\ COM drops off the relay landing thread (preserving inline timing when \VICTORY_RELAY_TIMING=1\). Verified in a clean 90s gameplay run on \829188e9\: \land_rest\ dropped from 6.19 ms/frame to 1.48 ms/frame (-4.71 ms/frame on the relay thread), \ury_drops_retired_objects_asynchronously\ passes.
elsi06 commented 2026-11-29 18:49:52 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by elsi06 on 2026-11-29T18:49:52Z.


We tested the same bury() change independently in the Belobug fork, using one binary with a runtime toggle (Ryzen 7 5800X, RTX 4070 SUPER, 32 GiB RAM, FSR 3.1.5 Performance at 1080p, frame generation off). Our release worker allows one batch pending and one in progress, with inline fallback when full. These measurements apply to that implementation.

Across two walking segments, eight readback waits of at least 2 ms began with the render fence already signaled in the inline run (226.98 ms total). With the worker there was one such wait (12.28 ms). In one inline case, releasing an older submission overlapped 83.44 ms of an 87.25 ms wait for a 384-byte upload. With the worker, eight native Presents completed during a single 411.06 ms release. The queue was full for about 2.7% of batches.

The second walk had comparable draw counts (3,003 vs 2,967 per frame). Moving releases to the worker reduced frames ≥100 ms from 6 to 1 and native P99 from 70.61 to 67.13 ms. Mean FPS fell from 24.50 to 23.87. Peak sampled working set across the walks rose by 355 MiB and private bytes by 647 MiB. The first walk differed substantially in draw count, so we excluded it from the frame-rate comparison.

The clearest gain on this machine was allowing Presents and readbacks to continue during long releases. Tracking waits that start with the fence already signaled, alongside queue-full fallbacks and peak memory, may help evaluate the queue bound on this PR.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7260793038 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1358#issuecomment-7260793038). Originally posted by [elsi06](https://github.com/elsi06) on 2026-11-29T18:49:52Z. --- We tested the same `bury()` change independently in the Belobug fork, using one binary with a runtime toggle (Ryzen 7 5800X, RTX 4070 SUPER, 32 GiB RAM, FSR 3.1.5 Performance at 1080p, frame generation off). Our release worker allows one batch pending and one in progress, with inline fallback when full. These measurements apply to that implementation. Across two walking segments, eight readback waits of at least 2 ms began with the render fence already signaled in the inline run (226.98 ms total). With the worker there was one such wait (12.28 ms). In one inline case, releasing an older submission overlapped 83.44 ms of an 87.25 ms wait for a 384-byte upload. With the worker, eight native Presents completed during a single 411.06 ms release. The queue was full for about 2.7% of batches. The second walk had comparable draw counts (3,003 vs 2,967 per frame). Moving releases to the worker reduced frames ≥100 ms from 6 to 1 and native P99 from 70.61 to 67.13 ms. Mean FPS fell from 24.50 to 23.87. Peak sampled working set across the walks rose by 355 MiB and private bytes by 647 MiB. The first walk differed substantially in draw count, so we excluded it from the frame-rate comparison. The clearest gain on this machine was allowing Presents and readbacks to continue during long releases. Tracking waits that start with the fence already signaled, alongside queue-full fallbacks and peak memory, may help evaluate the queue bound on this PR.
upipibi commented 2026-11-29 23:31:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by upipibi on 2026-11-29T23:31:45Z.


Test note for #1358 (head 1b4b50c9), merged onto main 41adb551, on RTX 30. Synthetic tests only: no title run, no game files.

Setup: RTX 3070 8 GB, driver 621.40, Windows 11 (10.0.26100), rustc 1.98.1.

The new test passes, and it also passes with the change taken out. host::bury_tests::bury_drops_retired_objects_asynchronously is a CPU-only test (it makes no device). As a negative control I changed one line of bury so that a batch is never handed to the victory-bury thread (if false && timing.is_none() && let Some(pool) = bury_pool()), which leaves the old inline drop:

Tree bury_drops_retired_objects_asynchronously
PR ok
PR with the hand-off to the thread disabled ok

The test waits until the object's Drop has run, and an inline drop satisfies that at once. So it shows that bury still drops what is retired, but not that the drop left the calling thread. If the Drop in the test recorded the name of the thread it ran on, the test could assert it is victory-bury and would then fail on the inline path.

cargo test -p victory-gpu --lib --locked on the card, PR tree, two runs: 922 passed, 1 failed, 60 ignored both times. The one failure is shader_cache::tests::every_switch_of_the_translator_is_in_the_key (VICTORY_SCALAR_SPLITS is not read by the translator any more), which fails the same way on main 41adb551 without this PR.

Not tested: the frame-time effect, which needs a title run.

Tested with the help of Claude Code (Claude Fable 5.2).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7264528574 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1358#issuecomment-7264528574). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-29T23:31:45Z. --- Test note for #1358 (head 1b4b50c9), merged onto main 41adb551, on RTX 30. Synthetic tests only: no title run, no game files. **Setup:** RTX 3070 8 GB, driver 621.40, Windows 11 (10.0.26100), rustc 1.98.1. **The new test passes, and it also passes with the change taken out.** `host::bury_tests::bury_drops_retired_objects_asynchronously` is a CPU-only test (it makes no device). As a negative control I changed one line of `bury` so that a batch is never handed to the `victory-bury` thread (`if false && timing.is_none() && let Some(pool) = bury_pool()`), which leaves the old inline drop: | Tree | `bury_drops_retired_objects_asynchronously` | |---|---| | PR | ok | | PR with the hand-off to the thread disabled | ok | The test waits until the object's `Drop` has run, and an inline drop satisfies that at once. So it shows that `bury` still drops what is retired, but not that the drop left the calling thread. If the `Drop` in the test recorded the name of the thread it ran on, the test could assert it is `victory-bury` and would then fail on the inline path. **`cargo test -p victory-gpu --lib --locked` on the card, PR tree, two runs:** 922 passed, 1 failed, 60 ignored both times. The one failure is `shader_cache::tests::every_switch_of_the_translator_is_in_the_key` (`VICTORY_SCALAR_SPLITS is not read by the translator any more`), which fails the same way on main 41adb551 without this PR. Not tested: the frame-time effect, which needs a title run. *Tested with the help of Claude Code (Claude Fable 5.2).*
DoubleD17 commented 2026-11-30 07:58:28 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-11-30T07:58:28Z.


We ran a test of this PR on current main (41adb551 with this PR merged), on a CPU-bound machine.

We compare only the seconds where the idle camera shows the same lighter views (about 7,500 draws a frame). Its heavier view (about 15,000 draws, half the frame rate) takes 10 to 60 s of each 150 s run, and it moved whole-run means by several ms.

CPU prep (ms/frame) main at that point fps main at that point
round 1 60.0 60.9 15.1 14.4
round 2 61.6 59.9 14.8 15.2
mean difference +0.4 ms +1.1 %

No difference we can measure. The five main runs of the session agreed within 1.3 ms on these seconds. But we also ran main again, built in another folder, eight times: it ranged from 57.5 to 65.5 ms. Its first four runs were 2.4 ms slower than main on average, and the last four 4.2 ms faster. All nine PRs we tested in this session came out 0.4 to 3.9 ms slower than main, and fps moved with it. So we read the difference as a newly built executable, not as this PR.

The relay thread was landing 32.5 and 35.6 ms a frame, against 30.9 to 38.0 on main. That is the lowest of the PRs we tested, but inside main's own spread.

Picture: 0 defects in 160 frames.

Setup:

  • Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11;
  • Series X, 1440p with DLAA (DLSS at native resolution; corrected, this line said DLSS Performance at first), frame generation and ray tracing off;
  • the PR merged locally onto main 41adb551 (only its own commits on top), against 41adb551 itself;
  • a warm-up run per build, then 150 s runs in two rounds (the second in reverse order), with five main runs spread through the session;
  • every run starts from the same save, restored before each run;
  • CPU prep is the median of the submitting thread's 5 s lines, fps the median of the host's 5 s lines, on the light-view seconds after the first 20 s; each run is compared with main's runs interpolated in time.

Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame.

AI Assisted

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7272337691 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1358#issuecomment-7272337691). Originally posted by [DoubleD17](https://github.com/DoubleD17) on 2026-11-30T07:58:28Z. --- We ran a test of this PR on current main (41adb551 with this PR merged), on a CPU-bound machine. We compare only the seconds where the idle camera shows the same lighter views (about 7,500 draws a frame). Its heavier view (about 15,000 draws, half the frame rate) takes 10 to 60 s of each 150 s run, and it moved whole-run means by several ms. | | CPU prep (ms/frame) | main at that point | fps | main at that point | |---|---|---|---|---| | round 1 | 60.0 | 60.9 | 15.1 | 14.4 | | round 2 | 61.6 | 59.9 | 14.8 | 15.2 | | **mean difference** | **+0.4 ms** | | **+1.1 %** | | No difference we can measure. The five main runs of the session agreed within 1.3 ms on these seconds. But we also ran main again, built in another folder, eight times: it ranged from 57.5 to 65.5 ms. Its first four runs were 2.4 ms slower than main on average, and the last four 4.2 ms faster. All nine PRs we tested in this session came out 0.4 to 3.9 ms slower than main, and fps moved with it. So we read the difference as a newly built executable, not as this PR. The relay thread was landing 32.5 and 35.6 ms a frame, against 30.9 to 38.0 on main. That is the lowest of the PRs we tested, but inside main's own spread. **Picture:** 0 defects in 160 frames. **Setup:** - Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11; - Series X, 1440p with DLAA (DLSS at native resolution; corrected, this line said DLSS Performance at first), frame generation and ray tracing off; - the PR merged locally onto main 41adb551 (only its own commits on top), against 41adb551 itself; - a warm-up run per build, then 150 s runs in two rounds (the second in reverse order), with five main runs spread through the session; - every run starts from the same save, restored before each run; - CPU prep is the median of the submitting thread's 5 s lines, fps the median of the host's 5 s lines, on the light-view seconds after the first 20 s; each run is compared with main's runs interpolated in time. Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame. AI Assisted
remijn commented 2026-11-30 12:38:41 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by remijn on 2026-11-30T12:38:41Z.


Tested on an RTX 3080 / Ryzen 9 7900X3D (32 GB), Series S profile, DLSS Quality, FSR 3 frame generation, ray tracing off, the same save every run, diagnostics build. The PR's commit was cherry-picked onto a tree based on 41adb551. For an A/B in one binary I added a local switch that makes bury_pool() return None, which drops inline as before. Three pairs, 30 s each, run order alternated:

fps (median) relay landing per frame p99 frame
inline (before) 18.5 / 19.75 / 19.6 → 19.3 24.8 / 27.1 / 23.3 → 25.1 ms 85 / 107 / 78 → 90 ms
victory-bury thread (this PR) 20.65 / 19.7 / 20.2 → 20.2 22.1 / 19.1 / 20.5 → 20.6 ms 77 / 89 / 77 → 81 ms

The relay thread's landing time ("was … ms landing in all" in the relay line) went down by about 4.5 ms a frame in every pair. fps rose in two of the three pairs and was unchanged in the third, about +4.7 % on average, and p99 improved in every pair. No problems seen in these runs.

Merges cleanly here. A switch for the inline path would make A/B tests like this easier for others.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7278725275 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1358#issuecomment-7278725275). Originally posted by [remijn](https://github.com/remijn) on 2026-11-30T12:38:41Z. --- Tested on an RTX 3080 / Ryzen 9 7900X3D (32 GB), Series S profile, DLSS Quality, FSR 3 frame generation, ray tracing off, the same save every run, diagnostics build. The PR's commit was cherry-picked onto a tree based on 41adb551. For an A/B in one binary I added a local switch that makes `bury_pool()` return `None`, which drops inline as before. Three pairs, 30 s each, run order alternated: | | fps (median) | relay landing per frame | p99 frame | |---|---|---|---| | inline (before) | 18.5 / 19.75 / 19.6 → **19.3** | 24.8 / 27.1 / 23.3 → **25.1 ms** | 85 / 107 / 78 → **90 ms** | | `victory-bury` thread (this PR) | 20.65 / 19.7 / 20.2 → **20.2** | 22.1 / 19.1 / 20.5 → **20.6 ms** | 77 / 89 / 77 → **81 ms** | The relay thread's landing time ("was … ms landing in all" in the relay line) went down by about 4.5 ms a frame in every pair. fps rose in two of the three pairs and was unchanged in the third, about +4.7 % on average, and p99 improved in every pair. No problems seen in these runs. Merges cleanly here. A switch for the inline path would make A/B tests like this easier for others.
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!1358
No description provided.