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

Open
unueberlegt wants to merge 5 commits from upstream-pr/1877 into main
unueberlegt commented 2026-11-29 01:21:47 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by unueberlegt on 2026-11-29T01:21:47Z.


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 #4634 (#4707, dup #4679), 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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5546390787 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877). Originally posted by [unueberlegt](https://github.com/unueberlegt) on 2026-11-29T01:21:47Z. --- ## 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 #4634 (#4707, dup #4679), 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)
amazedturnip commented 2026-11-29 05:38:54 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by amazedturnip on 2026-11-29T05:38:54Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7251377275 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877#issuecomment-7251377275). Originally posted by [amazedturnip](https://github.com/amazedturnip) on 2026-11-29T05:38:54Z. --- 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.
gut0to commented 2026-12-01 14:38:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by gut0to on 2026-12-01T14:38:20Z.

Code review location: crates/victory-gpu/src/draw.rs; line 4684

@@ -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));

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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4755781035 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877#discussion_r4755781035). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-01T14:38:20Z. **Code review location:** `crates/victory-gpu/src/draw.rs`; line 4684 ~~~~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)); ~~~~ --- `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 commented 2026-12-01 14:38:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by gut0to on 2026-12-01T14:38:20Z.

Review: COMMENTED


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6133473597 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877#pullrequestreview-6133473597). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-01T14:38:20Z. **Review:** COMMENTED --- AI-assisted review; I used an AI assistant to inspect this diff.
unueberlegt commented 2026-12-01 16:16:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by unueberlegt on 2026-12-01T16:16:29Z.

Code review location: crates/victory-gpu/src/draw.rs; line 4684

@@ -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 #4634 (font.rs, menu.rs, panel.rs — byte-identical to main here), with #4707 open for them (dup: #4679).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4757199759 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1877#discussion_r4757199759). Originally posted by [unueberlegt](https://github.com/unueberlegt) on 2026-12-01T16:16:29Z. **Code review location:** `crates/victory-gpu/src/draw.rs`; line 4684 ~~~~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 #4634 (font.rs, menu.rs, panel.rs — byte-identical to main here), with #4707 open for them (dup: #4679).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1877:upstream-pr/1877'
git switch 'upstream-pr/1877'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1877'
git switch 'upstream-pr/1877'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1877'
git switch 'upstream-pr/1877'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1877'
git switch 'main'
git merge --squash 'upstream-pr/1877'
git switch 'main'
git merge --ff-only 'upstream-pr/1877'
git switch 'main'
git merge 'upstream-pr/1877'
git push origin 'main'
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!1877
No description provided.