GPU: buffer lookups also look through the buffers over 1 MiB when the 64 entries below an address hold none of it #2618

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

@⁠101Leafy on GitHub · 2026-11-29 14:59 UTC · original
101Leafy:nv/lookup-big-buffers → main · +102 −19 · 1 files · 1 commits · open

Lookups in the shadow buffer map walk the 64 entries below an address. A parent buffer with many placed buffers inside it has more than 64 entries between its start and the address, so the walk stops short, the parent is never found, and the range falls through to a loose copy.

This keeps the 64-entry walk and, when it finds nothing, walks a second index that holds only the buffers over 1 MiB (again 64 entries below the address). Parents with many children are almost always that big, and there are few of them, so the second walk is short. A hit from the big index is checked against the buffer map's own end, so a buffer registered again shorter cannot be found at its old length. extent, peek, lookup, and in_buffer use it. VICTORY_LOOKUP_SPAN=0 turns the second walk off (back to the 64 entries only).

The stale entry is why the earlier take on this (b73bb8b473) was reverted: when a key was registered again with a smaller length, the big index still held the old length. Registering at or under 1 MiB now removes the key from it, and there is a test for that case.

#2556 bounds the walk by the largest registered size instead. On a miss that walk goes through every entry in that span; in the opening we counted about 480 entries per miss on average, up to 2,842, at about 330k misses every 5 seconds.

Numbers from the opening, game time 60 to 80 s, measured on our tree (which carries this change on top of a lot of other work), same PC, warm shader cache:

fps guard wait
64 entries, then big buffers (this PR) 7.04 22.2 ms
wide walk, as in #2556 6.87 22.7 ms
64 entries only 6.62 26.1 ms

It is also a picture fix. With 64 entries only, the faces in the coffee shop scene go solid blue and green/red. With this change (or the wide walk) those solid faces are gone:

Coffee shop faces, 64 entries only on top, this change below

Top: 64 entries only. Bottom: this change. The frames are from separate runs, so they are not the same moment. The red specks still left on the right face show up in every mode, so they come from something else.

**@⁠101Leafy** on GitHub · 2026-11-29 14:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2618) `101Leafy:nv/lookup-big-buffers` → `main` · +102 −19 · 1 files · 1 commits · open Lookups in the shadow buffer map walk the 64 entries below an address. A parent buffer with many placed buffers inside it has more than 64 entries between its start and the address, so the walk stops short, the parent is never found, and the range falls through to a loose copy. This keeps the 64-entry walk and, when it finds nothing, walks a second index that holds only the buffers over 1 MiB (again 64 entries below the address). Parents with many children are almost always that big, and there are few of them, so the second walk is short. A hit from the big index is checked against the buffer map's own end, so a buffer registered again shorter cannot be found at its old length. `extent`, `peek`, `lookup`, and `in_buffer` use it. `VICTORY_LOOKUP_SPAN=0` turns the second walk off (back to the 64 entries only). The stale entry is why the earlier take on this (b73bb8b473) was reverted: when a key was registered again with a smaller length, the big index still held the old length. Registering at or under 1 MiB now removes the key from it, and there is a test for that case. #2556 bounds the walk by the largest registered size instead. On a miss that walk goes through every entry in that span; in the opening we counted about 480 entries per miss on average, up to 2,842, at about 330k misses every 5 seconds. Numbers from the opening, game time 60 to 80 s, measured on our tree (which carries this change on top of a lot of other work), same PC, warm shader cache: | | fps | guard wait | |---|---|---| | 64 entries, then big buffers (this PR) | 7.04 | 22.2 ms | | wide walk, as in #2556 | 6.87 | 22.7 ms | | 64 entries only | 6.62 | 26.1 ms | It is also a picture fix. With 64 entries only, the faces in the coffee shop scene go solid blue and green/red. With this change (or the wide walk) those solid faces are gone: ![Coffee shop faces, 64 entries only on top, this change below](https://raw.githubusercontent.com/101Leafy/VIctory-NVIDIA/pr-shots/lookup-faces-w0076.jpg) Top: 64 entries only. Bottom: this change. The frames are from separate runs, so they are not the same moment. The red specks still left on the right face show up in every mode, so they come from something else.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 15:03:27 +00:00
Author
Owner

@⁠dyshay on GitHub · 2026-11-29 15:40 UTC · original

Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.

**@⁠dyshay** on GitHub · 2026-11-29 15:40 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2618#issuecomment-7258272134) Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.
Author
Owner

@⁠dyshay on GitHub · 2026-11-29 20:28 UTC · original

A measurement from our integration branch (RTX 4090, house scene, cache warm, 300 s, same exe with and without VICTORY_LOOKUP_SPAN=0):

median with this PR with VICTORY_LOOKUP_SPAN=0 before the PR
Series X 42.0 ms 38.8 ms 37.8 ms
Series S with ray tracing 51.5 ms 46.6 ms 47.8 ms

Both profiles show the same ~4 ms extra frame time, all on the CPU side (the card time is unchanged). I've taken the PR out of our branch for now. Did you measure the extra lookup cost when it was written? A narrower search, for example only for parents already known to be larger than 1 MiB, might keep the fix without the cost.

**@⁠dyshay** on GitHub · 2026-11-29 20:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2618#issuecomment-7262109141) A measurement from our integration branch (RTX 4090, house scene, cache warm, 300 s, same exe with and without `VICTORY_LOOKUP_SPAN=0`): | | median with this PR | with `VICTORY_LOOKUP_SPAN=0` | before the PR | |---|---|---|---| | Series X | 42.0 ms | 38.8 ms | 37.8 ms | | Series S with ray tracing | 51.5 ms | 46.6 ms | 47.8 ms | Both profiles show the same ~4 ms extra frame time, all on the CPU side (the card time is unchanged). I've taken the PR out of our branch for now. Did you measure the extra lookup cost when it was written? A narrower search, for example only for parents already known to be larger than 1 MiB, might keep the fix without the cost.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/shadow.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2618'
git switch 'github-bot/gh-2618'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2618'
git switch 'github-bot/gh-2618'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2618'
git switch 'main'
git merge --squash 'github-bot/gh-2618'
git switch 'main'
git merge --ff-only 'github-bot/gh-2618'
git switch 'main'
git merge 'github-bot/gh-2618'
git push origin 'main'
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!2618
No description provided.