Texture queue notes no longer wait for its lock (−95 % lock waits); retired D3D12 objects are released on a thread of their own #3476

Closed
nyxctura wants to merge 3 commits from upstream-pr/3476 into main
nyxctura commented 2026-11-29 23:44:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nyxctura on 2026-11-29T23:44:18Z.


What it changes

The texture queue's lock line showed ~2 s of waiting every 5 s, 1.6 s of it in "noting a slot's record": 60–95k short takes queuing behind the pass that takes the slots due. And "copying back" cost ~10 ms a frame for ~1 MB, mostly bury() releasing ~20,000 retired D3D12 objects a frame on the landing thread.

  1. VICTORY_QUEUE_POST (descriptor/host.rs): a note that finds the lock busy leaves its change for the holder, who applies it before releasing; the next taker applies any left over first. While a slot has a change waiting, the lock-free reads fall back to the locked path, so every reader sees the same results as before.
  2. VICTORY_BURY_ASIDE (host.rs): retired objects are handed to a "victory-burial" thread. The title is still told the card is done only after the data has landed.

Both are on by default; =0 restores the old path.

How it was tested

  • PC: RTX 5070 12 GB, Ryzen 7 7800X3D, 32 GB RAM, Windows 11 25H2. Series S, 1080p → 1440p, DLSS Ultra Performance, frame generation 2x.
  • Before: texture queue lock waited 2,046 ms per 5 s on average over 16.7 min (1,612 ms of it noting slot records); copying back 9.9 ms a frame.
  • After: 93–119 ms per 5 s over three runs; copying back 6.1–7.7 ms.
  • A/B: the same build with VICTORY_QUEUE_POST=0 went back to 600–2,200 ms of waiting per 5 s, with identical rendering.
  • New unit tests: notes made while the lock is held, and six threads noting against one taking the lock in a loop; both match the old path exactly.
  • Played on the v2026.11.29.01 base. On current main the branch builds and the victory-gpu lib suite passes (apart from every_switch_of_the_translator_is_in_the_key, which fails the same way on main without this PR).
  • cargo test passed for the crates it touches: yes.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: none found for the texture queue lock.

Charts

Texture queue lock, ms waited per 5 s:
lock waits

Copying back, ms per frame:
copy back

All three PRs at a glance:
scorecard

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5556438581 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476). Originally posted by [nyxctura](https://github.com/nyxctura) on 2026-11-29T23:44:18Z. --- ## What it changes The texture queue's lock line showed ~2 s of waiting every 5 s, 1.6 s of it in "noting a slot's record": 60–95k short takes queuing behind the pass that takes the slots due. And "copying back" cost ~10 ms a frame for ~1 MB, mostly `bury()` releasing ~20,000 retired D3D12 objects a frame on the landing thread. 1. **`VICTORY_QUEUE_POST`** (`descriptor/host.rs`): a note that finds the lock busy leaves its change for the holder, who applies it before releasing; the next taker applies any left over first. While a slot has a change waiting, the lock-free reads fall back to the locked path, so every reader sees the same results as before. 2. **`VICTORY_BURY_ASIDE`** (`host.rs`): retired objects are handed to a "victory-burial" thread. The title is still told the card is done only after the data has landed. Both are on by default; `=0` restores the old path. ## How it was tested - **PC:** RTX 5070 12 GB, Ryzen 7 7800X3D, 32 GB RAM, Windows 11 25H2. Series S, 1080p → 1440p, DLSS Ultra Performance, frame generation 2x. - **Before:** texture queue lock waited 2,046 ms per 5 s on average over 16.7 min (1,612 ms of it noting slot records); copying back 9.9 ms a frame. - **After:** 93–119 ms per 5 s over three runs; copying back 6.1–7.7 ms. - **A/B:** the same build with `VICTORY_QUEUE_POST=0` went back to 600–2,200 ms of waiting per 5 s, with identical rendering. - New unit tests: notes made while the lock is held, and six threads noting against one taking the lock in a loop; both match the old path exactly. - Played on the v2026.11.29.01 base. On current `main` the branch builds and the `victory-gpu` lib suite passes (apart from `every_switch_of_the_translator_is_in_the_key`, which fails the same way on `main` without this PR). - `cargo test` passed for the crates it touches: yes. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: none found for the texture queue lock. ## Charts **Texture queue lock, ms waited per 5 s:** ![lock waits](https://raw.githubusercontent.com/nyxctura/VIctory-NVIDIA/pr-images/7-pr3-lock-waits.png) **Copying back, ms per frame:** ![copy back](https://raw.githubusercontent.com/nyxctura/VIctory-NVIDIA/pr-images/8-pr3-copy-back.png) **All three PRs at a glance:** ![scorecard](https://raw.githubusercontent.com/nyxctura/VIctory-NVIDIA/pr-images/11-scorecard.png) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Kitrae commented 2026-11-30 00:15:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Kitrae on 2026-11-30T00:15:29Z.


I tested the background resource cleanup in e3a0285 on an RTX 4090 at 3840×1080, with DLSS Performance and native 2× frame generation. I used one build with the same local ultrawide and scene-entry changes on top of 41adb551. VICTORY_QUEUE_POST=0 and the memory diagnostics were held fixed. I replayed the same post-prologue save four times in off/on/on/off order, running for 36 seconds after the first frame with at least 500 draws.

VICTORY_BURY_ASIDE Frames over 100 ms at 1–7 s Frames over 100 ms at 8–34 s Median copy-back time per frame at 8–34 s Peak process VRAM
Off, run 1 6 8 18.0 ms 14,179 MiB
On, run 2 6 2 15.9 ms 13,421 MiB
On, run 3 4 2 13.3 ms 14,550 MiB
Off, run 4 5 13 17.7 ms 15,858 MiB

Copy-back values are medians of the periodic per-frame averages in the log. Peak VRAM is the highest sampled DXGI local-memory usage for the game process over the run.

The enabled runs both had fewer long frames after scene entry. Scene-entry hitch counts were similar across all four runs. The later workload varied, with median draw counts of about 9,610, 9,244, 6,483, and 10,480 in run order, so a controlled FPS gain would need a more repeatable scene. All four replays completed without a GPU failure, and the logs showed the cleanup worker active only in the enabled runs.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7265106992 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7265106992). Originally posted by [Kitrae](https://github.com/Kitrae) on 2026-11-30T00:15:29Z. --- I tested the background resource cleanup in `e3a0285` on an RTX 4090 at 3840×1080, with DLSS Performance and native 2× frame generation. I used one build with the same local ultrawide and scene-entry changes on top of `41adb551`. `VICTORY_QUEUE_POST=0` and the memory diagnostics were held fixed. I replayed the same post-prologue save four times in off/on/on/off order, running for 36 seconds after the first frame with at least 500 draws. | `VICTORY_BURY_ASIDE` | Frames over 100 ms at 1–7 s | Frames over 100 ms at 8–34 s | Median copy-back time per frame at 8–34 s | Peak process VRAM | | --- | ---: | ---: | ---: | ---: | | Off, run 1 | 6 | 8 | 18.0 ms | 14,179 MiB | | On, run 2 | 6 | 2 | 15.9 ms | 13,421 MiB | | On, run 3 | 4 | 2 | 13.3 ms | 14,550 MiB | | Off, run 4 | 5 | 13 | 17.7 ms | 15,858 MiB | Copy-back values are medians of the periodic per-frame averages in the log. Peak VRAM is the highest sampled DXGI local-memory usage for the game process over the run. The enabled runs both had fewer long frames after scene entry. Scene-entry hitch counts were similar across all four runs. The later workload varied, with median draw counts of about 9,610, 9,244, 6,483, and 10,480 in run order, so a controlled FPS gain would need a more repeatable scene. All four replays completed without a GPU failure, and the logs showed the cleanup worker active only in the enabled runs.
DoubleD17 commented 2026-11-30 01:01:37 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-11-30T01:01:37Z.


We ran a test of this PR on an 8-core Zen 3: no gain on this machine, and two frames with vegetation missing.

Setup:

  • Ryzen 7 5800X (8 cores), RTX 5070 12 GB, 64 GB RAM, Windows 11;
  • Series X, 1440p, DLSS Performance, frame generation and ray tracing off;
  • this PR merged locally onto main 41adb551 (the merge only adds this PR's own commits), against 41adb551 itself;
  • a warm-up run per build, then 150 s runs alternating base / PR, two rounds;
  • every run starts from the same save, restored before each run;
  • figures are medians of the 5 s host lines.

We also ran a picture check: a burst of 10 captures a second at the end of each run, looked at frame by frame.

preparing refresh fps (mean) one-frame defects
base 41adb551 62.7 / 62.1 ms 21.2 / 20.9 ms 13.4 / 13.7 0 / 0 of 80
this PR 71.5 / 65.5 ms 22.9 / 22.5 ms 12.1 / 14.0 1 / 1 of 80
  • Preparing: +3 to +9 ms; fps mixed. No improvement here, if anything a little slower.
  • Vegetation missing for one frame, once in each PR run: palm trees and a potted plant near the camera, and in the other run the palms, a flag and trees on an island, each gone for a single frame. We haven't seen that in any base run: 0 in 160 frames here, and 0 in about 1,400 frames of main runs today. It might fit VICTORY_BURY_ASIDE: if retired objects are released on the burial thread while a later list still references them, something drawn from them would drop out for a frame.

We can run VICTORY_BURY_ASIDE=0 and VICTORY_QUEUE_POST=0 separately on this machine to tell which part does what, if that helps.

AI Assisted

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7265778019 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7265778019). Originally posted by [DoubleD17](https://github.com/DoubleD17) on 2026-11-30T01:01:37Z. --- We ran a test of this PR on an 8-core Zen 3: no gain on this machine, and two frames with vegetation missing. **Setup:** - Ryzen 7 5800X (8 cores), RTX 5070 12 GB, 64 GB RAM, Windows 11; - Series X, 1440p, DLSS Performance, frame generation and ray tracing off; - this PR merged locally onto main 41adb551 (the merge only adds this PR's own commits), against 41adb551 itself; - a warm-up run per build, then 150 s runs alternating base / PR, two rounds; - every run starts from the same save, restored before each run; - figures are medians of the 5 s host lines. We also ran a picture check: a burst of 10 captures a second at the end of each run, looked at frame by frame. | | preparing | refresh | fps (mean) | one-frame defects | |---|---|---|---|---| | base 41adb551 | 62.7 / 62.1 ms | 21.2 / 20.9 ms | 13.4 / 13.7 | 0 / 0 of 80 | | this PR | 71.5 / 65.5 ms | 22.9 / 22.5 ms | 12.1 / 14.0 | 1 / 1 of 80 | - **Preparing:** +3 to +9 ms; fps mixed. No improvement here, if anything a little slower. - **Vegetation missing for one frame, once in each PR run:** palm trees and a potted plant near the camera, and in the other run the palms, a flag and trees on an island, each gone for a single frame. We haven't seen that in any base run: 0 in 160 frames here, and 0 in about 1,400 frames of main runs today. It might fit VICTORY_BURY_ASIDE: if retired objects are released on the burial thread while a later list still references them, something drawn from them would drop out for a frame. We can run VICTORY_BURY_ASIDE=0 and VICTORY_QUEUE_POST=0 separately on this machine to tell which part does what, if that helps. AI Assisted
nyxctura commented 2026-11-30 01:24:40 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nyxctura on 2026-11-30T01:24:40Z.


Pushed a fix, testing in a moment.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7266112838 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7266112838). Originally posted by [nyxctura](https://github.com/nyxctura) on 2026-11-30T01:24:40Z. --- Pushed a fix, testing in a moment.
nyxctura commented 2026-11-30 01:42:24 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nyxctura on 2026-11-30T01:42:24Z.


Tested on my side: I pushed a fix for a real race in VICTORY_QUEUE_POST (a reader could skip the texture pass for one frame while posted changes were being applied; a test reproduces it and passes with the fix). I can't confirm the dropouts are gone yet: my build carries other changes that cause their own one-frame artifacts, so it doesn't isolate this PR. Could you rerun your picture check on the updated branch? If they're still there, a run with VICTORY_QUEUE_POST=0 and one with VICTORY_BURY_ASIDE=0 would tell which half it is.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7266370711 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7266370711). Originally posted by [nyxctura](https://github.com/nyxctura) on 2026-11-30T01:42:24Z. --- Tested on my side: I pushed a fix for a real race in VICTORY_QUEUE_POST (a reader could skip the texture pass for one frame while posted changes were being applied; a test reproduces it and passes with the fix). I can't confirm the dropouts are gone yet: my build carries other changes that cause their own one-frame artifacts, so it doesn't isolate this PR. Could you rerun your picture check on the updated branch? If they're still there, a run with VICTORY_QUEUE_POST=0 and one with VICTORY_BURY_ASIDE=0 would tell which half it is.
Yoruiopz commented 2026-11-30 12:36:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Yoruiopz on 2026-11-30T12:36:21Z.


Independent same-binary comparison on an RTX 5070 Laptop GPU (8 GB), using exact PR head 8bd0f8a8 on .05. Two fresh starts from the same copied Series S porch checkpoint and seeded cache. Stage 3, four landing threads, frame generation off, and VICTORY_BURY_ASIDE=0 in both runs. The only switch was VICTORY_QUEUE_POST. Timing windows started 26.9 s after the first world frame and stayed in the foreground for 28 s each.

Posting off Posting on
Median queue mutex wait, per complete 5 s interval 526.5 ms 79 ms
Median wait to note a slot record, same intervals 417.5 ms 4 ms
Rendered frames 624 608
Rendered FPS 22.26 21.70
Frame time p95 61.69 ms 63.54 ms
Frame time p99 89.59 ms 89.85 ms
Median draws 5,229.5 5,237

In the five complete enabled buckets, all 602,255 accepted operations were counted by the drain, including 102,486 handed to the current holder. The drain counter includes entries it can reject as stale. Wait values sum worker time on the original texture queue mutex and exclude the posting mailbox mutex.

This confirms the mutex contention reduction on an 8 GB laptop. Frame pacing did not improve in this single pair. I also saw the known intermittent black forearms in both runs. The visual samples caught different idle poses, so they can confirm the defect still occurs and do not measure its frequency.

I also tested a small follow-up that avoids allocating a temporary vector for singleton posts. The mailbox still takes a copy of each operation and preserves the existing counter, publication and drain order. The descriptor-host suite ran on the hardware adapter with posting on and off. Each run had 83 passes, zero failures and one ignored test. I haven't measured a frame-time effect from this follow-up. Single-commit follow-up

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7278670189 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7278670189). Originally posted by [Yoruiopz](https://github.com/Yoruiopz) on 2026-11-30T12:36:21Z. --- Independent same-binary comparison on an RTX 5070 Laptop GPU (8 GB), using exact PR head `8bd0f8a8` on .05. Two fresh starts from the same copied Series S porch checkpoint and seeded cache. Stage 3, four landing threads, frame generation off, and `VICTORY_BURY_ASIDE=0` in both runs. The only switch was `VICTORY_QUEUE_POST`. Timing windows started 26.9 s after the first world frame and stayed in the foreground for 28 s each. | | Posting off | Posting on | | --- | ---: | ---: | | Median queue mutex wait, per complete 5 s interval | 526.5 ms | 79 ms | | Median wait to note a slot record, same intervals | 417.5 ms | 4 ms | | Rendered frames | 624 | 608 | | Rendered FPS | 22.26 | 21.70 | | Frame time p95 | 61.69 ms | 63.54 ms | | Frame time p99 | 89.59 ms | 89.85 ms | | Median draws | 5,229.5 | 5,237 | In the five complete enabled buckets, all 602,255 accepted operations were counted by the drain, including 102,486 handed to the current holder. The drain counter includes entries it can reject as stale. Wait values sum worker time on the original texture queue mutex and exclude the posting mailbox mutex. This confirms the mutex contention reduction on an 8 GB laptop. Frame pacing did not improve in this single pair. I also saw the known intermittent black forearms in both runs. The visual samples caught different idle poses, so they can confirm the defect still occurs and do not measure its frequency. I also tested a small follow-up that avoids allocating a temporary vector for singleton posts. The mailbox still takes a copy of each operation and preserves the existing counter, publication and drain order. The descriptor-host suite ran on the hardware adapter with posting on and off. Each run had 83 passes, zero failures and one ignored test. I haven't measured a frame-time effect from this follow-up. [Single-commit follow-up](https://github.com/Yoruiopz/VIctory-NVIDIA/commit/19079ca376eb6aa177645f45429229e88125c471)
trustno1-coder commented 2026-12-01 18:51:55 +00:00 (Migrated from github.com)

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


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