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
github-bot wants to merge 3 commits from github-bot/gh-3476 into main AGit
Owner

@⁠nyxctura on GitHub · 2026-11-29 23:44 UTC · original
nyxctura:pr-locks → main · +440 −11 · 4 files · 3 commits · closed without merging

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

**@⁠nyxctura** on GitHub · 2026-11-29 23:44 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476) `nyxctura:pr-locks` → `main` · +440 −11 · 4 files · 3 commits · closed without merging ## 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)
- VICTORY_QUEUE_POST (default on; =0 as before): a note of a slot's record
  (the queue's "noting a slot's record" place, 1.6-3.2 s of waits per 5 s in
  play) that finds the lock held leaves its change, as a batch op checked
  against the slot's state, for the holder; the lock's next taker (and the
  holder before letting go) makes them first. While a slot has a change
  waiting its marks are not read and a new note of it takes the lock, so
  every answer the queue gives is as if the change had been made at once.
  The lock line counts posted / left for the holder / made.
- VICTORY_BURY_ASIDE (default on; =0 as before): bury() hands the ~20,000
  objects a frame it releases to a "victory-burial" thread instead of
  dropping them on the landing (the "copying back" time's "the rest") or
  submitting thread. New relay line reports objects and the thread's ms.
- Tests: posted notes under a held lock and from six threads match notes
  that wait; card_steps late tests forget pages a freed allocation of another
  test left learned (they failed with the new tests' allocations).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 23:49:12 +00:00
Author
Owner

@⁠Kitrae on GitHub · 2026-11-30 00:15 UTC · original

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.

**@⁠Kitrae** on GitHub · 2026-11-30 00:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7265106992) 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.
Author
Owner

@⁠DoubleD17 on GitHub · 2026-11-30 01:01 UTC · original

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

**@⁠DoubleD17** on GitHub · 2026-11-30 01:01 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7265778019) 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
make_posted set posted_len to 0 before applying the taken changes. In that
window texture_news and texture_slots_room, which skip the lock when nothing
is posted, read the marks without those changes: the texture pass could see
no news and pass over a slot for one frame (reported as vegetation missing
for a single frame with VICTORY_QUEUE_POST on). The count is now set from
what is still posted only after the apply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A test-only pause between taking and making the posted changes; a reader of
texture_news in that window must see the change (it fails on the previous
commit's parent: the reader got the marks from before the change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠nyxctura on GitHub · 2026-11-30 01:24 UTC · original

Pushed a fix, testing in a moment.

**@⁠nyxctura** on GitHub · 2026-11-30 01:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7266112838) Pushed a fix, testing in a moment.
Author
Owner

@⁠nyxctura on GitHub · 2026-11-30 01:42 UTC · original

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.

**@⁠nyxctura** on GitHub · 2026-11-30 01:42 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7266370711) 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.
Author
Owner

@⁠Yoruiopz on GitHub · 2026-11-30 12:36 UTC · original · edited 2026-11-30 12:42 UTC

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

**@⁠Yoruiopz** on GitHub · 2026-11-30 12:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3476#issuecomment-7278670189) · edited 2026-11-30 12:42 UTC 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)
github-bot closed this pull request 2026-12-01 18:58:33 +00:00

Pull request closed

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!3476
No description provided.