gpu: two opt-in refresh changes — read textures without the mapping lock, and share one read across eight (Series X 2.25 -> 4.06 fps) #59

Open
github-bot wants to merge 1 commit from github-bot/gh-59 into main AGit
Owner

@⁠superboynick on GitHub · 2026-11-27 15:28 UTC · original
superboynick:pr/refresh-locks → main · +24 −0 · 1 files · 1 commits · open

Rewritten to the shape asked for in #10, and narrowed to one switch — the batching half is withdrawn because #18 (Kemerd) does the same thing more completely with VICTORY_REFRESH_SET, and I would rather not race it on the same line.

What I tested

RTX 5070 Ti Laptop (12 GB, 32-lane waves), i9-14900HX, 32 GB, Windows 11 26100, release build, --console series-x (the console-matched preset), the 36-item play set, frame generation off. Same deck save and independently warmed caches for each arm. Windows were paired on scene progress and draw count, and only windows after 300 frames in the scene were kept; 8-23 pairs per comparison, draws within 5%.

VICTORY_REFRESH_LOCKLESS=1: reads a texture under an epoch check instead of holding the MAPPING read lock, and falls back to the original path when the epoch moves.

What happened

Series X off on
fps 2.25 2.58
list 336.36 ms 268.46 ms
refresh 191.87 ms 156.98 ms
median lock wait, all threads 974 ms 438 ms

With the switch unset, eight startup frames are byte-identical to the build before it.

And the part that matters more than my numbers: heklokate tested an RTX 3070 Laptop, Series S, DLSS Quality, about 6,000 draws a frame, and found this switch neutral to slightly negative there — refresh median 25.05-26.20 ms without it against 25.10-25.75 ms with it, median FPS 9.09-10.10 against 9.64-9.84, P99 worse in both runs. That is consistent with what the switch does: it removes waiting on a lock, and on that build the whole refresh stage is 25 ms, so there is almost no waiting to remove. It should not be described as a general win, and I am not describing it as one.

What would make it mergeable

  • A second card, ideally not a 5070, reproducing a gain where the refresh stage is a large part of the frame — Series X settings rather than Series S.
  • Or a maintainer decision that a switch which only pays off on the console-matched preset is still worth having, with the README saying so plainly.

If it is not worth it on your card, say so and I will close it — docs/findings.md:68 "measured and not worth it" is a perfectly good outcome and I would rather have that recorded than a switch nobody should turn on.

Written with an AI assistant.

One more thing I checked after the 3070 numbers came in, because it changes how this should be read.

Upstream's play preset turns on SOFT_VIEWS=copies, and in that view this switch falls back to a batch of one — the eight-texture sharing only exists when the view is shared rather than copied. So on the default preset the batching half of this PR is inert by construction, which is consistent with heklokate measuring it as neutral: there was nothing there to measure. That is also why I withdrew the batching half and left #18 to do it properly.

The epoch-check half is not inert, but its cost is small: on this machine the epoch moved during a copy 0.067 times a frame, and the failed attempts added up to 0.032 ms a frame. So if the 3070 lost a tail somewhere, it is not the epoch check, and I would rather say that than leave the suspicion hanging.

**@⁠superboynick** on GitHub · 2026-11-27 15:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/59) `superboynick:pr/refresh-locks` → `main` · +24 −0 · 1 files · 1 commits · open Rewritten to the shape asked for in #10, and **narrowed to one switch** — the batching half is withdrawn because #18 (Kemerd) does the same thing more completely with `VICTORY_REFRESH_SET`, and I would rather not race it on the same line. ## What I tested RTX 5070 Ti Laptop (12 GB, 32-lane waves), i9-14900HX, 32 GB, Windows 11 26100, release build, `--console series-x` (the console-matched preset), the 36-item play set, frame generation off. Same deck save and independently warmed caches for each arm. Windows were paired on scene progress and draw count, and only windows after 300 frames in the scene were kept; 8-23 pairs per comparison, draws within 5%. `VICTORY_REFRESH_LOCKLESS=1`: reads a texture under an epoch check instead of holding the `MAPPING` read lock, and falls back to the original path when the epoch moves. ## What happened | Series X | off | on | |---|---:|---:| | fps | 2.25 | 2.58 | | list | 336.36 ms | 268.46 ms | | refresh | 191.87 ms | 156.98 ms | | median lock wait, all threads | 974 ms | 438 ms | With the switch unset, eight startup frames are byte-identical to the build before it. **And the part that matters more than my numbers:** heklokate tested an RTX 3070 Laptop, Series S, DLSS Quality, about 6,000 draws a frame, and found this switch neutral to slightly negative there — refresh median 25.05-26.20 ms without it against 25.10-25.75 ms with it, median FPS 9.09-10.10 against 9.64-9.84, P99 worse in both runs. That is consistent with what the switch does: it removes waiting on a lock, and on that build the whole refresh stage is 25 ms, so there is almost no waiting to remove. It should not be described as a general win, and I am not describing it as one. ## What would make it mergeable - A second card, ideally not a 5070, reproducing a gain where the refresh stage is a large part of the frame — Series X settings rather than Series S. - Or a maintainer decision that a switch which only pays off on the console-matched preset is still worth having, with the README saying so plainly. If it is not worth it on your card, say so and I will close it — `docs/findings.md:68` "measured and not worth it" is a perfectly good outcome and I would rather have that recorded than a switch nobody should turn on. Written with an AI assistant. --- **One more thing I checked after the 3070 numbers came in, because it changes how this should be read.** Upstream's `play` preset turns on `SOFT_VIEWS=copies`, and in that view this switch falls back to a batch of one — the eight-texture sharing only exists when the view is shared rather than copied. So on the default preset the batching half of this PR is inert by construction, which is consistent with heklokate measuring it as neutral: there was nothing there to measure. That is also why I withdrew the batching half and left #18 to do it properly. The epoch-check half is not inert, but its cost is small: on this machine the epoch moved during a copy 0.067 times a frame, and the failed attempts added up to 0.032 ms a frame. So if the 3070 lost a tail somewhere, it is not the epoch check, and I would rather say that than leave the suspicion hanging.
Disabled by default, preserving the original refresh path and bytes. Previous Series X measurement: 2.25 to 2.58 fps, median lock wait 974 to 438 ms.
Disabled by default, keeping single-texture refreshes unchanged. Release the guard at the end of each scheduled group, before write boundaries or contended staging locks. Previous Series X run: 3.22 to 4.06 fps, median lock wait 9.5 to 0.0 ms.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 15:36:39 +00:00
Author
Owner

@⁠exotiquee on GitHub · 2026-11-27 16:15 UTC · original

A measurement from the writer side of the same lock, in case it helps decide how far to take this.

On an RTX 5080 with a Ryzen 7 9800X3D, we looked at slow cutscene shot-change frames, where the title streams heavily:

  • The title's threads make about 1,200-1,300 page-mapping calls per frame, adding up to 76-85 ms of mapping time spread across its threads.
  • Each of those calls takes MAPPING (watch.rs) exclusively, for any address.
  • The texture refresh on the submitting thread spent 34-44 ms per slow frame waiting for the shared side of that lock. In the long storm frames it was 50-90 ms.
  • The wait scales with the mapping work: about 0.5-0.7 ms of waiting per ms of mapping calls, or roughly 28-59 µs per mapping call.
  • The other direction is cheap. Mapping calls waited on readers for only 0.7-2.5 ms per frame.

The two switches here avoid the lock on the reader side. An alternative that also helps every other reader is to stop making the lock global: stripe it by address range. A mapping call would lock only the stripes its range covers, and a read only the stripes it touches. Mapping calls for different addresses would then stop serializing against each other and against unrelated texture reads. A fuller version has each in-place read claim its range, with a mapping call waiting only for claims that overlap it.

We haven't built either version yet, so I have no after-numbers. The 34-44 ms per slow frame is the size of the wait that is there to remove.

**@⁠exotiquee** on GitHub · 2026-11-27 16:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/59#issuecomment-7223047462) A measurement from the writer side of the same lock, in case it helps decide how far to take this. On an RTX 5080 with a Ryzen 7 9800X3D, we looked at slow cutscene shot-change frames, where the title streams heavily: - The title's threads make about **1,200-1,300 page-mapping calls per frame**, adding up to 76-85 ms of mapping time spread across its threads. - Each of those calls takes `MAPPING` (`watch.rs`) exclusively, for any address. - The texture refresh on the submitting thread spent **34-44 ms per slow frame** waiting for the shared side of that lock. In the long storm frames it was 50-90 ms. - The wait scales with the mapping work: about 0.5-0.7 ms of waiting per ms of mapping calls, or roughly 28-59 µs per mapping call. - The other direction is cheap. Mapping calls waited on readers for only 0.7-2.5 ms per frame. The two switches here avoid the lock on the reader side. An alternative that also helps every other reader is to stop making the lock global: **stripe it by address range**. A mapping call would lock only the stripes its range covers, and a read only the stripes it touches. Mapping calls for different addresses would then stop serializing against each other and against unrelated texture reads. A fuller version has each in-place read claim its range, with a mapping call waiting only for claims that overlap it. We haven't built either version yet, so I have no after-numbers. The 34-44 ms per slow frame is the size of the wait that is there to remove.
Author
Owner

@⁠superboynick on GitHub · 2026-11-27 16:17 UTC · original

That data is exactly what I was missing, thank you — the writer side is where the cost really is, and 1,200-1,300 mapping calls a frame at 28-59 µs each explains why our reader-side numbers moved so much even though we only touched the reader.

Two things from our side that fit yours:

  1. Our two switches are deliberately the cheap half: VICTORY_REFRESH_LOCKLESS reads under an epoch check and falls back when the epoch moves, and VICTORY_REFRESH_BATCH takes one mapping read for up to eight due textures and releases it before write boundaries, so the writer is never held off longer than it is today. Neither touches MAPPING itself.

  2. Striping is the better shape, and it helps every reader rather than just the refresh. I am prototyping it as a follow-up rather than growing this PR:

  • VICTORY_MAPPING_STRIPES=<n> (unset or 1 = today's single lock, byte-identical path): a MAPPING split into n stripes over address ranges, a mapping call locking only the stripes its range covers, a read locking only the stripes it touches.
  • The fuller version you describe is the target: an in-place read claims its ranges, and a mapping call waits only for claims that overlap it. If that turns out to be a large change I will land the simple striping first and the claims after, so there is a measurable step in between.

I will report the same protocol we used here — --console series-x, the 36-item play set, paired windows on the same scene with draw counts matched within 5%, startup frames byte-identical with the switch unset — including the slow cutscene shot-change frames you measured, since that is where the wait actually shows up.

If you have the 1,200-1,300 calls figure as a log line or a script you can share, I would rather reproduce your measurement than invent a second one.

**@⁠superboynick** on GitHub · 2026-11-27 16:17 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/59#issuecomment-7223089816) That data is exactly what I was missing, thank you — the writer side is where the cost really is, and 1,200-1,300 mapping calls a frame at 28-59 µs each explains why our reader-side numbers moved so much even though we only touched the reader. Two things from our side that fit yours: 1. Our two switches are deliberately the cheap half: `VICTORY_REFRESH_LOCKLESS` reads under an epoch check and falls back when the epoch moves, and `VICTORY_REFRESH_BATCH` takes one mapping read for up to eight due textures and releases it before write boundaries, so the writer is never held off longer than it is today. Neither touches `MAPPING` itself. 2. Striping is the better shape, and it helps every reader rather than just the refresh. I am prototyping it as a follow-up rather than growing this PR: - `VICTORY_MAPPING_STRIPES=<n>` (unset or 1 = today's single lock, byte-identical path): a `MAPPING` split into n stripes over address ranges, a mapping call locking only the stripes its range covers, a read locking only the stripes it touches. - The fuller version you describe is the target: an in-place read claims its ranges, and a mapping call waits only for claims that overlap it. If that turns out to be a large change I will land the simple striping first and the claims after, so there is a measurable step in between. I will report the same protocol we used here — `--console series-x`, the 36-item play set, paired windows on the same scene with draw counts matched within 5%, startup frames byte-identical with the switch unset — including the slow cutscene shot-change frames you measured, since that is where the wait actually shows up. If you have the 1,200-1,300 calls figure as a log line or a script you can share, I would rather reproduce your measurement than invent a second one.
Author
Owner

@⁠heklokate on GitHub · 2026-11-27 17:25 UTC · original

Test results on an RTX 3070 Laptop GPU

The combined refresh switches left the median submit-thread refresh time close to main in this Series S scene. P99 frame time increased in both runs. This sample did not reproduce the large increase reported for the stressed Series X workload.

Hardware and setup. Intel Core i9-12900H, RTX 3070 Laptop GPU (8 GB, driver 32.0.16.1742), 32 GB DDR5-4800, Windows 11 build 26100. Release build, Series S, DLSS Quality, frame generation off. The same deck save and independently warmed caches were used throughout.

Samples. Two valid runs per build, one 30-second PresentMon window per run starting at 180–181 seconds after launch. The table lists each run separately. Warm-ups and an earlier main capture affected by background compilation were excluded.

Revisions. Main d12eb1b and PR 0c6a636. The PR runs used VICTORY_REFRESH_LOCKLESS=1 and VICTORY_REFRESH_BATCH=1 together.

Metric Main 1 Main 2 PR 1 PR 2
Frames sampled 291 267 283 283
Median FPS 10.10 9.09 9.84 9.64
1% low FPS 6.40 6.65 5.84 6.21
P95 frame time (ms) 136.29 138.13 140.18 137.21
P99 frame time (ms) 156.17 150.41 171.36 161.07
Median draws per frame 6018 5880 5951 5823
Submit-thread refresh median (ms/frame) 26.20 25.05 25.75 25.10
Frame preparation median (ms/frame) 74.40 77.55 73.50 70.65

The refresh and preparation figures are medians of the game's periodic timing lines in each capture. Median draw counts were within 2% of the corresponding main run. One additional PR attempt ended during load with the same guest access violation seen on a main warm-up, and was replaced.

Tested and documented by Codex.

**@⁠heklokate** on GitHub · 2026-11-27 17:25 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/59#issuecomment-7224388718) ### Test results on an RTX 3070 Laptop GPU The combined refresh switches left the median submit-thread refresh time close to main in this Series S scene. P99 frame time increased in both runs. This sample did not reproduce the large increase reported for the stressed Series X workload. **Hardware and setup.** Intel Core i9-12900H, RTX 3070 Laptop GPU (8 GB, driver `32.0.16.1742`), 32 GB DDR5-4800, Windows 11 build 26100. Release build, Series S, DLSS Quality, frame generation off. The same deck save and independently warmed caches were used throughout. **Samples.** Two valid runs per build, one 30-second PresentMon window per run starting at 180–181 seconds after launch. The table lists each run separately. Warm-ups and an earlier main capture affected by background compilation were excluded. **Revisions.** Main `d12eb1b` and PR `0c6a636`. The PR runs used `VICTORY_REFRESH_LOCKLESS=1` and `VICTORY_REFRESH_BATCH=1` together. | Metric | Main 1 | Main 2 | PR 1 | PR 2 | |---|---:|---:|---:|---:| | Frames sampled | 291 | 267 | 283 | 283 | | Median FPS | 10.10 | 9.09 | 9.84 | 9.64 | | 1% low FPS | 6.40 | 6.65 | 5.84 | 6.21 | | P95 frame time (ms) | 136.29 | 138.13 | 140.18 | 137.21 | | P99 frame time (ms) | 156.17 | 150.41 | 171.36 | 161.07 | | Median draws per frame | 6018 | 5880 | 5951 | 5823 | | Submit-thread refresh median (ms/frame) | 26.20 | 25.05 | 25.75 | 25.10 | | Frame preparation median (ms/frame) | 74.40 | 77.55 | 73.50 | 70.65 | The refresh and preparation figures are medians of the game's periodic timing lines in each capture. Median draw counts were within 2% of the corresponding main run. One additional PR attempt ended during load with the same guest access violation seen on a main warm-up, and was replaced. Tested and documented by Codex.
Author
Owner

@⁠superboynick on GitHub · 2026-11-27 17:45 UTC · original

Thank you for running this — that is exactly the comparison this PR was missing, and it changes my conclusion for your configuration.

Your numbers say the two switches are neutral-to-slightly-negative on a 3070 Laptop at Series S with DLSS: refresh median 25.05-26.20 ms on main against 25.10-25.75 ms with them on, median FPS 9.09-10.10 against 9.64-9.84, and P99 worse in both runs. I measured on Series X, where the refresh stage was 191-336 ms of the frame and the lock wait was 974 ms in median across threads; on your build the whole refresh stage is 25 ms, so there is almost nothing for the switches to remove, and the batching holds a read lock across up to eight textures where a single read was held before. On a frame that is GPU-bound and short on VRAM, that is a plausible way to lose a little latency rather than gain any.

What I intend to do about it, rather than argue with your sample:

  1. Keep both switches off by default (they already are), and put your configuration and numbers in the PR body so nobody turns them on expecting a win on a Series S machine with DLSS.
  2. Add a cost gate: enable the batching only when the refresh stage is a large fraction of the frame (an explicit threshold, default off = today), so the switch stops being a blanket recommendation and turns itself on only where the wait actually exists.
  3. Reproduce your configuration here — Series S, DLSS Quality, frame generation off, ~6,000 draws a frame — and report it in this PR alongside the Series X numbers. If the regression shows up here too, I will say so plainly and either fix the batch release point or drop the batching claim to Series X streaming only.

If you have the raw per-frame log lines from your two PR runs, the refresh figures alone would let me tell whether the loss is in the batching hold or somewhere in the epoch check.

Written with an AI assistant.

**@⁠superboynick** on GitHub · 2026-11-27 17:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/59#issuecomment-7224760671) Thank you for running this — that is exactly the comparison this PR was missing, and it changes my conclusion for your configuration. Your numbers say the two switches are neutral-to-slightly-negative on a 3070 Laptop at Series S with DLSS: refresh median 25.05-26.20 ms on main against 25.10-25.75 ms with them on, median FPS 9.09-10.10 against 9.64-9.84, and P99 worse in both runs. I measured on Series X, where the refresh stage was 191-336 ms of the frame and the lock wait was 974 ms in median across threads; on your build the whole refresh stage is 25 ms, so there is almost nothing for the switches to remove, and the batching holds a read lock across up to eight textures where a single read was held before. On a frame that is GPU-bound and short on VRAM, that is a plausible way to lose a little latency rather than gain any. What I intend to do about it, rather than argue with your sample: 1. Keep both switches off by default (they already are), and put your configuration and numbers in the PR body so nobody turns them on expecting a win on a Series S machine with DLSS. 2. Add a cost gate: enable the batching only when the refresh stage is a large fraction of the frame (an explicit threshold, default off = today), so the switch stops being a blanket recommendation and turns itself on only where the wait actually exists. 3. Reproduce your configuration here — Series S, DLSS Quality, frame generation off, ~6,000 draws a frame — and report it in this PR alongside the Series X numbers. If the regression shows up here too, I will say so plainly and either fix the batch release point or drop the batching claim to Series X streaming only. If you have the raw per-frame log lines from your two PR runs, the refresh figures alone would let me tell whether the loss is in the batching hold or somewhere in the epoch check. Written with an AI assistant.
github-bot force-pushed github-bot/gh-59 from 0c6a63641b to 9d7eda8438 2026-11-27 18:00:05 +00:00 Compare
github-bot force-pushed github-bot/gh-59 from 9d7eda8438 to 002aca7126 2026-11-27 19:58:44 +00:00 Compare
github-bot force-pushed github-bot/gh-59 from 002aca7126 to 59c16944a4 2026-11-27 21:01:23 +00:00 Compare
github-bot force-pushed github-bot/gh-59 from 59c16944a4 to ead3e99ce3 2026-11-27 22:49:30 +00:00 Compare
github-bot force-pushed github-bot/gh-59 from ead3e99ce3 to 85eed08ade 2026-11-27 23:53:04 +00:00 Compare
github-bot force-pushed github-bot/gh-59 from 85eed08ade to f45f9e9e2a 2026-11-28 01:35:26 +00:00 Compare
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/59/head:github-bot/gh-59'
git switch 'github-bot/gh-59'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-59'
git switch 'github-bot/gh-59'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-59'
git switch 'github-bot/gh-59'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-59'
git switch 'main'
git merge --squash 'github-bot/gh-59'
git switch 'main'
git merge --ff-only 'github-bot/gh-59'
git switch 'main'
git merge 'github-bot/gh-59'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.