Draw: a held slot does not walk the pages first (part of #1521) #1877

Open
github-bot wants to merge 5 commits from github-bot/gh-1877 into main AGit
Owner

@⁠unueberlegt on GitHub · 2026-11-29 01:21 UTC · original
unueberlegt:perf/1521-first-upload-walk → main · +155 −38 · 2 files · 5 commits · open

What it changes

The pass over the textures picked by index (the heap's buffer views and friends) walked a placed view's pages with mapped_bytes() — VirtualQuery over whole textures — before it asked whether the card's fullness holds the slot. A held slot's answer (nothing mapped, or mapped in part) was thrown away: the slot is told Held and looked at again in about four seconds, or as soon as the card has room.

Now the held decision runs first (it needs only the view and texture_slot_made_from), and a held slot never walks. A counter (HEAP_TEXTURES_HELD_SKIP) in the 5-second line says how many slots skipped the walk:

textures picked by index: … uploaded so far (… MB), … waiting, … passed over unmapped, N held for the card's fullness without a walk of their pages

Behavior delta (said plainly)

Under !room, an ineligible slot that streamed out is now told Held instead of Away — the walk was the only way to see that its memory is gone, and held slots do not walk. texture_slot_gone for such a slot runs on the next pass with room (the slot's tell re-checks then); nothing leaks, the host copy's bytes are still resident.

Why

Point 4 of #1521: on a full card the walks cost 87–281 ms of every 5 s plus recording-thread lock contention behind mapped_bytes. On our machine (RTX 5070 12 GB, Ryzen 9 9950X3D, 31 GB, Series X 2560x1440, prologue) the pass stands under !room almost constantly: 3,716,941 held slots skipped the walk in one ~10-minute run (and 3.4M in a second). The skip is the pass's own answer: its walk exists only for slots that go up.

How it was tested

  • GPU and profile: NVIDIA RTX 5070 12 GB (driver 610.88), AMD Ryzen 9 9950X3D, 31 GB RAM, Windows 11 26300; Series X profile, 2560x1440, prologue runs of ~10 minutes, five runs (baseline + one per change of #1521's points, steady windows, medians).
  • For shader changes, the wave sizes tested: N/A (no shader changes; the translated DXIL is byte-identical).
  • cargo test passed for the crates it touches: victory-gpu 590 passed / 0 failed (and 644 with --features diagnostics); clippy --all-features at the base's warning count (10, none new).
  • New test: held_for_fullness_with_nothing_going_up_is_said_before_the_walk (the held predicate over a room/made/reupload/first-room/window matrix).
  • Review fix (gut0to, 2026-12-01): the first-upload window is asked only for a texture sampled on screen (window_asked); new test an_unsampled_first_upload_does_not_ask_the_window. cargo test -p victory-gpu --lib: 1097 passed / 0 failed; both clippy gates show only main's own five findings from #4635 (#4708, dup #4680), none from this branch.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. #614, #1133, #1556, #1676, #1637 take points 1–3 of #1521 (refreshes/journal/ahead) — none of them touches draw.rs or the texture pass. 0174844 (the shadow copy state lock) is merged and takes #1521's second point.

The other three points of #1521 are left to those PRs and 0174844; this one takes the fourth.

🤖 Generated with Claude Code

**@⁠unueberlegt** on GitHub · 2026-11-29 01:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877) `unueberlegt:perf/1521-first-upload-walk` → `main` · +155 −38 · 2 files · 5 commits · open ## What it changes The pass over the textures picked by index (the heap's buffer views and friends) walked a placed view's pages with `mapped_bytes()` — VirtualQuery over whole textures — **before** it asked whether the card's fullness holds the slot. A held slot's answer (nothing mapped, or mapped in part) was thrown away: the slot is told `Held` and looked at again in about four seconds, or as soon as the card has room. Now the held decision runs first (it needs only the view and `texture_slot_made_from`), and a held slot never walks. A counter (`HEAP_TEXTURES_HELD_SKIP`) in the 5-second line says how many slots skipped the walk: ``` textures picked by index: … uploaded so far (… MB), … waiting, … passed over unmapped, N held for the card's fullness without a walk of their pages ``` ### Behavior delta (said plainly) Under `!room`, an ineligible slot that streamed out is now told `Held` instead of `Away` — the walk was the only way to see that its memory is gone, and held slots do not walk. `texture_slot_gone` for such a slot runs on the next pass with room (the slot's tell re-checks then); nothing leaks, the host copy's bytes are still resident. ## Why Point 4 of #1521: on a full card the walks cost **87–281 ms of every 5 s** plus recording-thread lock contention behind `mapped_bytes`. On our machine (RTX 5070 12 GB, Ryzen 9 9950X3D, 31 GB, Series X 2560x1440, prologue) the pass stands under `!room` almost constantly: **3,716,941 held slots skipped the walk in one ~10-minute run** (and 3.4M in a second). The skip is the pass's own answer: its walk exists only for slots that go up. ## How it was tested - GPU and profile: NVIDIA RTX 5070 12 GB (driver 610.88), AMD Ryzen 9 9950X3D, 31 GB RAM, Windows 11 26300; Series X profile, 2560x1440, prologue runs of ~10 minutes, five runs (baseline + one per change of #1521's points, steady windows, medians). - For shader changes, the wave sizes tested: N/A (no shader changes; the translated DXIL is byte-identical). - `cargo test` passed for the crates it touches: `victory-gpu` 590 passed / 0 failed (and 644 with `--features diagnostics`); `clippy --all-features` at the base's warning count (10, none new). - New test: `held_for_fullness_with_nothing_going_up_is_said_before_the_walk` (the held predicate over a room/made/reupload/first-room/window matrix). - Review fix (gut0to, 2026-12-01): the first-upload window is asked only for a texture sampled on screen (`window_asked`); new test `an_unsampled_first_upload_does_not_ask_the_window`. `cargo test -p victory-gpu --lib`: 1097 passed / 0 failed; both clippy gates show only main's own five findings from #4635 (#4708, dup #4680), none from this branch. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. #614, #1133, #1556, #1676, #1637 take points 1–3 of #1521 (refreshes/journal/ahead) — none of them touches `draw.rs` or the texture pass. 0174844 (the shadow copy state lock) is merged and takes #1521's second point. The other three points of #1521 are left to those PRs and 0174844; this one takes the fourth. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The pass over the textures picked by index walked a placed view's pages
(VirtualQuery, whole textures at a time) before it asked whether the
card's fullness holds the slot: held ones threw the answer away. The
held decision is made first now, and held ones are counted where they
skip the walk (HEAP_TEXTURES_HELD_SKIP, in the 5 s line).

What changes besides the order: a held slot that streamed out is told
Held without the walk (it was told Away), and its host copy is not let
go until a pass with room walks it again — about four seconds, or as
soon as the card has room.

Point 4 of #1521; the issue's other three are covered by 0174844 (the
shadow copy state lock, merged) and the open #614, #1133, #1556, #1637.

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

@⁠amazedturnip on GitHub · 2026-11-29 05:38 UTC · original

Tested on 9800X3D + RTX 5070 Ti 16 GB across 20+ min sessions (including under heavy texture churn). Skipping VirtualQuery on held slots ran cleanly with zero faults or stale views.

**@⁠amazedturnip** on GitHub · 2026-11-29 05:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877#issuecomment-7251377275) Tested on 9800X3D + RTX 5070 Ti 16 GB across 20+ min sessions (including under heavy texture churn). Skipping VirtualQuery on held slots ran cleanly with zero faults or stale views.
Keeps the held decision before the walk of the pages, and takes the
line's new company along: the descriptor-only sizing of what the slot
holds (is_texture, placed_len for placed textures and shader objects,
placed buffers out of the walk and the held decision both), and the
sampled-on-screen ask in the first upload's admission (the window is
still asked only where the room said yes). The meter line keeps the
held-without-a-walk count beside the new descriptor-table drops.

Co-Authored-By: Claude Code <[email protected]>
The held-skip keeps its place, before the walk of the pages: on the new
main it waits behind the WindowAdmission answer (a commit deferral stops
the pass rather than skipping) and behind #2493's small levels (a small
upload is the slot's something going up, so it is walked). The held-read
becomes main's prepare_texture_slot pair, and the test module carries
both the held truth table and the commit-deferral admission test.

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

@⁠gut0to on GitHub · 2026-12-01 14:38 UTC · original · reviewed

AI-assisted review; I used an AI assistant to inspect this diff.

**@⁠gut0to** on GitHub · 2026-12-01 14:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877#pullrequestreview-6133473597) · **reviewed** AI-assisted review; I used an AI assistant to inspect this diff.
@ -4650,3 +4684,1 @@
match first_upload_reserve(reserve, memory, has_commit) {
WindowAdmission::Admitted => first_upload = true,
WindowAdmission::Full => {}
let has_commit = first_room && rest(6, || crate::residency::admit_texture_pass(required));
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 14:38 UTC · original

visible is computed above but no longer gates first_window, so an unsampled first texture can consume the five-second first-upload allowance whenever the room and reserve checks pass. That can spend the budget on off-screen textures and defer visible faces; the previous condition required visible here. Could you include visible in this admission condition and add a regression test that an unsampled first upload does not consume the window? AI-assisted review; I traced the admission path and compared it with the previous gating in this diff.

**@⁠gut0to** on GitHub · 2026-12-01 14:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877#discussion_r4755781035) `visible` is computed above but no longer gates `first_window`, so an unsampled first texture can consume the five-second first-upload allowance whenever the room and reserve checks pass. That can spend the budget on off-screen textures and defer visible faces; the previous condition required `visible` here. Could you include `visible` in this admission condition and add a regression test that an unsampled first upload does not consume the window? AI-assisted review; I traced the admission path and compared it with the previous gating in this diff.
The held decision above the walk needs the window's answer, and the
consult lost its `visible &&` on the way: an unsampled first texture
then spent the five-second budget on faces nobody sees and deferred the
visible ones, and its CommitDeferred could stop the pass for a face
that is not on screen. The gate is back (`window_asked`, the walk had
it before), asked before `admit_texture_pass` and `first_upload_reserve`
so an unsampled slot books neither; a truth-table test says an
unsampled first upload does not ask the window. The unused `visible`
also failed the check job (unused_variables under -D warnings).

The check job stays red on five findings that are main's own, from
#4634's merge (font.rs, menu.rs, panel.rs; the files are byte-identical
to main on this branch): #4707 fixes those on main.

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

@⁠unueberlegt on GitHub · 2026-12-01 16:16 UTC · original
On crates/victory-gpu/src/draw.rs line 4684 (outdated):

@@ -4644,23 +4670,38 @@ impl State {
                     // number of first uploads just over the line, up to the
                     // hard 80% ceiling that keeps the target/buffer reserves.
                     let reserve = placed_len;
+                    let reupload = reupload_when_full();
+                    let first_room = rest(6, || crate::resource::room_for_first_upload(memory, reserve));
+                    // The window is asked only where the room says yes and
+                    // the texture is sampled on screen (its spend is the
+                    // upload's bytes, and a refused upload spends none).
+                    // Both checks use the bytes this upload actually takes.
+                    // The old 64 MiB floor let only two small faces through
+                    // per window and could refuse a face while hundreds of
+                    // MiB were still under the hard ceiling. The window
+                    // bounds the total per 5 s.
                     let visible = crate::sampled::sampled_lately(index, 120).unwrap_or(true);
-                    if visible && rest(6, || crate::resource::room_for_first_upload(memory, reserve)) {
-                        let has_commit = rest(6, || crate::residency::admit_texture_pass(required));
-                        match first_upload_reserve(reserve, memory, has_commit) {
-                            WindowAdmission::Admitted => first_upload = true,
-                            WindowAdmission::Full => {}
+                    let has_commit = first_room && rest(6, || crate::residency::admit_texture_pass(required));

Fixed on the branch (09c3aea7): the gate is back. window_asked(visible, first_room) sits before the commit consult and first_upload_reserve, so an unsampled first upload books neither the commit nor the five-second window, and its CommitDeferred can no longer stop the pass. With nothing of it going up the slot is held before the walk, like every held slot — the caller passes first_window = false there, so held_and_nothing_goes_up's truth table is unchanged, and an_unsampled_first_upload_does_not_ask_the_window pins the gate. The unused visible was this PR's check failure; the five findings left in that run are main's own from #4635 (font.rs, menu.rs, panel.rs — byte-identical to main here), with #4708 open for them (dup: #4680).

**@⁠unueberlegt** on GitHub · 2026-12-01 16:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877#discussion_r4757199759) On `crates/victory-gpu/src/draw.rs` line 4684 (outdated): ```diff @@ -4644,23 +4670,38 @@ impl State { // number of first uploads just over the line, up to the // hard 80% ceiling that keeps the target/buffer reserves. let reserve = placed_len; + let reupload = reupload_when_full(); + let first_room = rest(6, || crate::resource::room_for_first_upload(memory, reserve)); + // The window is asked only where the room says yes and + // the texture is sampled on screen (its spend is the + // upload's bytes, and a refused upload spends none). + // Both checks use the bytes this upload actually takes. + // The old 64 MiB floor let only two small faces through + // per window and could refuse a face while hundreds of + // MiB were still under the hard ceiling. The window + // bounds the total per 5 s. let visible = crate::sampled::sampled_lately(index, 120).unwrap_or(true); - if visible && rest(6, || crate::resource::room_for_first_upload(memory, reserve)) { - let has_commit = rest(6, || crate::residency::admit_texture_pass(required)); - match first_upload_reserve(reserve, memory, has_commit) { - WindowAdmission::Admitted => first_upload = true, - WindowAdmission::Full => {} + let has_commit = first_room && rest(6, || crate::residency::admit_texture_pass(required)); ``` Fixed on the branch (09c3aea7): the gate is back. `window_asked(visible, first_room)` sits before the commit consult and `first_upload_reserve`, so an unsampled first upload books neither the commit nor the five-second window, and its `CommitDeferred` can no longer stop the pass. With nothing of it going up the slot is held before the walk, like every held slot — the caller passes `first_window = false` there, so `held_and_nothing_goes_up`'s truth table is unchanged, and `an_unsampled_first_upload_does_not_ask_the_window` pins the gate. The unused `visible` was this PR's `check` failure; the five findings left in that run are main's own from #4635 (font.rs, menu.rs, panel.rs — byte-identical to main here), with #4708 open for them (dup: #4680).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.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/1877/head:github-bot/gh-1877'
git switch 'github-bot/gh-1877'

Merge

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