feat(gpu): adapt the frame budget for background texture streaming #313

Open
github-bot wants to merge 11 commits from github-bot/gh-313 into main AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-03 12:21 UTC · original
tommiehansen:perf/phase3-frame-texture-budget → main · +1260 −16 · 7 files · 11 commits · open

What this does

Adapt the frame budget for background texture streaming.

Checks

  • Off-by-default and main parity: Off by default (VICTORY_TEXTURE_STREAM_FRAME=1 opts in); disabled path intended unchanged.
  • Docs move with code: Settings and F1 entry now document opt-in.
  • No unrelated cleanup: One background streaming budget subject.
  • A test must exercise the change: rejected_recent_probes_do_not_exhaust_due_selection_budget, randomized oracle and 15 portable tests; final-head rerun and explicit before failure pending.
  • Queue checked on 2026-12-04: #496 also addresses frame time for texture work; #501/#355 touch related texture pressure/sweep paths. Compare scope, not assumed dependencies.
  • Run cargo xtask policy on the final revision; no new game assets or build output intended.

Verified

Current review head: 721061a15eca94973fc682b891b4125952705751. Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review.

Cost

Synthetic queue work −99.18%; live uploads, visual parity and frame-time benefit unverified.


Detailed implementation and historical validation

Frame-budgeted background texture streaming (VICTORY_TEXTURE_STREAM_FRAME=1, opt-in; default behavior unchanged when unset).

Summary

Replaces full-slot queue scans in TextureQueue with an indexed (due_frame, slot) traversal (DueCursor) paired with bounded frame upload counts/microsecond budgets and an overdue/recency index (ReadyIndex), eliminating O(total_slots) scans per frame under sparse or backlogged queues.

Key Mechanism

  • Indexed due cursor (TextureQueue::by_due, DueCursor): Resets at the start of each new frame (DueCursor::begin_frame) to start from the earliest due (due, slot) entries instead of carrying a wrapping cursor across frame boundaries, and advances within a frame past slots currently active on another worker or already selected (wanted). Walks at most STREAM_STEP_MAX (32) entries per short lock acquisition (DueCursor::next_due).
  • Bounded backlog sampling (ReadyIndex, sample_due): Walks at most BACKLOG_THRESHOLD (1024) due entries instead of counting the entire queue, and tracks true overdue age (ReadyIndex keyed by (due.max(written), written, slot)) so rewrites cannot mask the oldest overdue item.
  • Fair recency + skipped-pass protection (DueCursor::want_recent, ReadyIndex::next_recent):
    • Interleaves recent ready writes 1:1 per pick with oldest-overdue picks (want_recent / note_recent_pick / note_due_pick, bounded by RECENT_PROBE_MAX = 8) instead of capping recent admission to one item per frame. This priority is bounded by the existing RECENT_WRITE_FRAMES = 4 / RECENT_MAX_AGE_FRAMES = 16 window (and prev_active_frame across skipped passes, starting at frame.saturating_sub(RECENT_WRITE_FRAMES) before the first active frame), so bursts inside the window interleave while bursts exceeding the window age into standard (due, slot) order.
    • Keeps recent-probe inspection cost separated from the due-selection budget: all recent_visits in next_recent count against the STREAM_STEP_MAX (32) per-lock inspection cap (reserving at least one visit for next_due), while rejected recent probes (written < floor, deferred later entries, or already-looked slots with looks != 0 || mapped != 0) no longer subtract from remaining (due_selection budget). Accepted recent picks consume 1 budget unit.

Benchmarks (CPU-Only Synthetic Suite, Apple M5 macOS)

Paired A/B/B/A (--profile standard --blocks 4 --suite textures, 8 rounds/side) using tools/benchmark-suite:

vs origin/main (45591b0 unset vs 500acac VICTORY_TEXTURE_STREAM_FRAME=1)

Benchmark origin/main (ms) 500acac (ms) Change 95% CI Key Metrics (main -> 500acac)
textures/stream_queue_lifecycle 5.141 0.865 -83.21% [-83.35%, -83.08%] slots_inspected: 1,675,620 -> 5,940 (-99.65%)
textures/stream_queue_policy 1.805 0.015 -99.18% [-99.21%, -99.15%] slots_inspected: 495,906 -> 2,028; due_sampled: 16,384 -> 204

Follow-Up Check vs Previous PR Head (a68af21 vs 500acac, both VICTORY_TEXTURE_STREAM_FRAME=1)

Benchmark a68af21 (ms) 500acac (ms) Change Equivalence Lifecycle / Policy Metrics (a68af21 -> 500acac)
textures/stream_queue_lifecycle 0.870 0.859 -0.77% (Inconclusive) identical skipped_pass_fresh_delay: 0 -> 0; fresh_burst_within_2_frames: 7 -> 7; slots_inspected: 5,940 -> 5,940
textures/stream_queue_policy 0.015 0.015 -0.53% (Inconclusive) identical slots_inspected: 3,733 -> 2,028 (recent probes no longer debit due budget)

Verification & Reproducibility

  • Unit & differential checks (500acac):
    rustc --edition 2024 --test crates/victory-gpu/src/descriptor/stream_policy.rs -o /tmp/stream_policy_dbg && /tmp/stream_policy_dbg
    rustc --edition 2024 --test -O crates/victory-gpu/src/descriptor/stream_policy.rs -o /tmp/stream_policy_rel && /tmp/stream_policy_rel
    
    15/15 tests pass in both debug (0.26s) and release (0.03s), including the 200-seed randomized queue oracle, 100-seed light-workload zero-left-behind test, rejected-recent-probe regression tests (later deferred + looks == 1 + mixed scenarios), 10-of-10 burst 1:1 interleaving, tiny-budget multi-frame burst anti-starvation, and multi-frame skipped-pass watermark tests.
  • Windows cross-check & Clippy: cargo clippy --offline -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --features blake3/pure,diagnostics clean in stream_policy.rs and stream_next.
  • Benchmark Suite commands:
    ./tools/benchmark-suite/run compare 45591b0f6daf 500acac --offline --cpu-only --profile standard --blocks 4 --suite textures --base-env VICTORY_TEXTURE_STREAM_FRAME=0 --cand-env VICTORY_TEXTURE_STREAM_FRAME=1
    ./tools/benchmark-suite/run compare a68af21 500acac --offline --cpu-only --profile standard --blocks 4 --suite textures --base-env VICTORY_TEXTURE_STREAM_FRAME=1 --cand-env VICTORY_TEXTURE_STREAM_FRAME=1
    

Known Limitations

  • Benchmarks measure CPU-side queue selection and synthetic multi-frame lifecycle dynamics on Apple M5 macOS; live Windows/D3D12 upload pacing and game frame-time impact require hardware validation.
  • Feature remains opt-in (VICTORY_TEXTURE_STREAM_FRAME=1) so default runtime behavior on main is preserved unless explicitly enabled.

Thanks to @⁠Kal0s-design for reviewing 17af52e and a68af21, surfacing the fresh-burst saturation, skipped-pass aging, rejected-recent-probe remaining charge, Clippy nits, and PR description wording issues.

**@⁠tommiehansen** on GitHub · 2026-12-03 12:21 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/313) `tommiehansen:perf/phase3-frame-texture-budget` → `main` · +1260 −16 · 7 files · 11 commits · open ## What this does Adapt the frame budget for background texture streaming. ## Checks - [ ] Off-by-default and main parity: Off by default (`VICTORY_TEXTURE_STREAM_FRAME=1` opts in); disabled path intended unchanged. - [x] Docs move with code: Settings and F1 entry now document opt-in. - [x] No unrelated cleanup: One background streaming budget subject. - [ ] A test must exercise the change: `rejected_recent_probes_do_not_exhaust_due_selection_budget`, randomized oracle and 15 portable tests; final-head rerun and explicit before failure pending. - [x] Queue checked on 2026-12-04: #496 also addresses frame time for texture work; #501/#355 touch related texture pressure/sweep paths. Compare scope, not assumed dependencies. - [ ] Run `cargo xtask policy` on the final revision; no new game assets or build output intended. ## Verified Current review head: `721061a15eca94973fc682b891b4125952705751`. Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review. ## Cost Synthetic queue work −99.18%; live uploads, visual parity and frame-time benefit unverified. --- ## Detailed implementation and historical validation Frame-budgeted background texture streaming (`VICTORY_TEXTURE_STREAM_FRAME=1`, opt-in; default behavior unchanged when unset). ## Summary Replaces full-slot queue scans in `TextureQueue` with an indexed `(due_frame, slot)` traversal (`DueCursor`) paired with bounded frame upload counts/microsecond budgets and an overdue/recency index (`ReadyIndex`), eliminating O(total_slots) scans per frame under sparse or backlogged queues. ### Key Mechanism - **Indexed due cursor (`TextureQueue::by_due`, `DueCursor`):** Resets at the start of each new frame (`DueCursor::begin_frame`) to start from the earliest due `(due, slot)` entries instead of carrying a wrapping cursor across frame boundaries, and advances within a frame past slots currently active on another worker or already selected (`wanted`). Walks at most `STREAM_STEP_MAX` (`32`) entries per short lock acquisition (`DueCursor::next_due`). - **Bounded backlog sampling (`ReadyIndex`, `sample_due`):** Walks at most `BACKLOG_THRESHOLD` (`1024`) due entries instead of counting the entire queue, and tracks true overdue age (`ReadyIndex` keyed by `(due.max(written), written, slot)`) so rewrites cannot mask the oldest overdue item. - **Fair recency + skipped-pass protection (`DueCursor::want_recent`, `ReadyIndex::next_recent`):** - Interleaves recent ready writes 1:1 per pick with oldest-overdue picks (`want_recent` / `note_recent_pick` / `note_due_pick`, bounded by `RECENT_PROBE_MAX = 8`) instead of capping recent admission to one item per frame. This priority is bounded by the existing `RECENT_WRITE_FRAMES = 4` / `RECENT_MAX_AGE_FRAMES = 16` window (and `prev_active_frame` across skipped passes, starting at `frame.saturating_sub(RECENT_WRITE_FRAMES)` before the first active frame), so bursts inside the window interleave while bursts exceeding the window age into standard `(due, slot)` order. - Keeps recent-probe inspection cost separated from the due-selection budget: all `recent_visits` in `next_recent` count against the `STREAM_STEP_MAX` (`32`) per-lock inspection cap (reserving at least one visit for `next_due`), while rejected recent probes (`written < floor`, deferred `later` entries, or already-looked slots with `looks != 0 || mapped != 0`) no longer subtract from `remaining` (`due_selection` budget). Accepted recent picks consume 1 budget unit. ## Benchmarks (CPU-Only Synthetic Suite, Apple M5 macOS) Paired A/B/B/A (`--profile standard --blocks 4 --suite textures`, 8 rounds/side) using `tools/benchmark-suite`: ### vs `origin/main` (`45591b0` unset vs `500acac` `VICTORY_TEXTURE_STREAM_FRAME=1`) | Benchmark | `origin/main` (ms) | `500acac` (ms) | Change | 95% CI | Key Metrics (`main` -> `500acac`) | |---|---:|---:|---:|---|---| | `textures/stream_queue_lifecycle` | 5.141 | 0.865 | **-83.21%** | [-83.35%, -83.08%] | `slots_inspected`: 1,675,620 -> **5,940** (-99.65%) | | `textures/stream_queue_policy` | 1.805 | 0.015 | **-99.18%** | [-99.21%, -99.15%] | `slots_inspected`: 495,906 -> **2,028**; `due_sampled`: 16,384 -> **204** | ### Follow-Up Check vs Previous PR Head (`a68af21` vs `500acac`, both `VICTORY_TEXTURE_STREAM_FRAME=1`) | Benchmark | `a68af21` (ms) | `500acac` (ms) | Change | Equivalence | Lifecycle / Policy Metrics (`a68af21` -> `500acac`) | |---|---:|---:|---:|---|---| | `textures/stream_queue_lifecycle` | 0.870 | 0.859 | -0.77% (Inconclusive) | `identical` | `skipped_pass_fresh_delay`: 0 -> **0**; `fresh_burst_within_2_frames`: 7 -> **7**; `slots_inspected`: 5,940 -> **5,940** | | `textures/stream_queue_policy` | 0.015 | 0.015 | -0.53% (Inconclusive) | `identical` | `slots_inspected`: 3,733 -> **2,028** (recent probes no longer debit due budget) | ## Verification & Reproducibility - **Unit & differential checks (`500acac`):** ```sh rustc --edition 2024 --test crates/victory-gpu/src/descriptor/stream_policy.rs -o /tmp/stream_policy_dbg && /tmp/stream_policy_dbg rustc --edition 2024 --test -O crates/victory-gpu/src/descriptor/stream_policy.rs -o /tmp/stream_policy_rel && /tmp/stream_policy_rel ``` 15/15 tests pass in both debug (`0.26s`) and release (`0.03s`), including the 200-seed randomized queue oracle, 100-seed light-workload zero-left-behind test, rejected-recent-probe regression tests (`later` deferred + `looks == 1` + mixed scenarios), 10-of-10 burst 1:1 interleaving, tiny-budget multi-frame burst anti-starvation, and multi-frame skipped-pass watermark tests. - **Windows cross-check & Clippy:** `cargo clippy --offline -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --features blake3/pure,diagnostics` clean in `stream_policy.rs` and `stream_next`. - **Benchmark Suite commands:** ```sh ./tools/benchmark-suite/run compare 45591b0f6daf 500acac --offline --cpu-only --profile standard --blocks 4 --suite textures --base-env VICTORY_TEXTURE_STREAM_FRAME=0 --cand-env VICTORY_TEXTURE_STREAM_FRAME=1 ./tools/benchmark-suite/run compare a68af21 500acac --offline --cpu-only --profile standard --blocks 4 --suite textures --base-env VICTORY_TEXTURE_STREAM_FRAME=1 --cand-env VICTORY_TEXTURE_STREAM_FRAME=1 ``` ## Known Limitations - Benchmarks measure CPU-side queue selection and synthetic multi-frame lifecycle dynamics on Apple M5 macOS; live Windows/D3D12 upload pacing and game frame-time impact require hardware validation. - Feature remains opt-in (`VICTORY_TEXTURE_STREAM_FRAME=1`) so default runtime behavior on `main` is preserved unless explicitly enabled. Thanks to @⁠Kal0s-design for reviewing `17af52e` and `a68af21`, surfacing the fresh-burst saturation, skipped-pass aging, rejected-recent-probe `remaining` charge, Clippy nits, and PR description wording issues.
Share a bounded optional-pass budget across lists and adapt it to successful render intervals, queue depth and VRAM room. Keep material priorities and bake work eligible under their original limits. Do not accumulate unused budget across frames. Inspired by Darner and mandy #3291. The targeted budget test and diagnostics Windows-target check passed. Hardware frame-time tails remain unmeasured.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 12:26:50 +00:00
Arm the real-present clock when streaming alone is enabled. Resolve material requests directly and defer the incremental queue walk until a background budget is available. Replace the full scan and sort with a persistent wrapping cursor over the existing slot index.

Charge optional scans and preparation to a 1–4 ms window, retain a floor under sustained backlog, and carry no debt across frames. Bake and priority requests keep their existing limits. Three focused portable regressions and diagnostics Windows-target checks passed. Hardware timings remain unmeasured.
Preserve every original production-code hunk and integrate the switch documentation alongside the newly added upstream settings. No behavior changes beyond the existing PR.
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-03 19:47 UTC · original

Adapted to by_due Indexed Queue & False-Backlog Fix (2da28da)

Merged origin/main (45591b0, including PR #295's by_due indexed due queue and PR #304's descriptor copy spans) and updated VICTORY_TEXTURE_STREAM_FRAME to consume by_due instead of scanning TextureQueue::slots.

Technical changes

  • Indexed by_due cursor (crates/victory-gpu/src/descriptor/stream_policy.rs, DueCursor): Replaces the previous slots full-queue cursor scan (which walked future later and u64::MAX held entries across 32-slot lock acquisitions) with a bounded by_due range cursor (..=(frame, u32::MAX)). Resets cleanly at each new frame so oldest overdue slots are served first without starvation while advancing within a frame past active / wanted slots.
  • Accurate due backlog & census (sample_due, StreamQueueStats): Samples by_due up to BACKLOG_THRESHOLD (1024) instead of treating slots.len() >= 1024 (which includes future/held entries) as an active backlog, preventing false 3x frame-budget bursts and skipping TextureStreamPass::start completely when due_sample == 0. Also populates HEAP_TEXTURES_QUEUE[1..6] and HEAP_TEXTURES_OVERDUE_PEAK telemetry in the adaptive path.
  • Cross-platform pure-Rust extraction: Moved DueCursor, sample_due, texture_stream_micros, texture_stream_spent, background_texture_pass, and present_clock_needed into crates/victory-gpu/src/descriptor/stream_policy.rs.

macOS ARM64 CPU Benchmark Results (rustc -O, A/B/B/A 8-block median, direct production stream_policy.rs)

27,000-slot TextureQueue modeled after #295's measured profile:

Scenario (27,000 queued) Previous PR #313 (slots scan) Updated (by_due index) Latency Delta
Sparse due (150 due, 4 active, select 32) 42.494 us (451 locks, 13,955 visits) 1.811 us (32 locks, 36 visits) -95.74%
Zero due (0 due, 27,000 future) 59.035 us (844 locks, 27,000 visits) 0.006 us (0 locks, 0 visits) -99.99%
Heavy backlog behind 20k future/held (4,000 due, sel 64) 42.341 us (689 locks, 20,068 visits, max_age=2) 4.585 us (64 locks, 64 visits, max_age=120) -89.17%
Full-card held queue (20k held, 150 due, sel 32) 60.055 us (871 locks, 26,884 visits) 1.953 us (32 locks, 34 visits) -96.75%
Pure front backlog (slots 1..4000 all due, sel 64) 1.378 us (68 visits, max_age=2 starved) 2.803 us (64 visits, max_age=120 oldest first) +1.4 us (sample_due + overdue priority)

Verification & Reproduction

  • Native unit tests (macOS ARM64):
    rustc --edition 2024 --test crates/victory-gpu/src/descriptor/stream_policy.rs -o /tmp/test_stream_policy && /tmp/test_stream_policy (7 passed, 0 failed).
  • Windows cross-target check:
    cargo check -p victory-gpu --lib --target x86_64-pc-windows-msvc --features blake3/pure and --features blake3/pure,diagnostics (0 errors, 0 warnings, check-only libmimalloc-sys shim), plus cargo --offline xtask policy --staged (6 files ok) and xtask -- switches (0 new errors).
  • Known limitations: Benchmarks and unit tests above ran on macOS ARM64 CPU-only against synthetic 27k queues. Live Windows/RADV GPU execution, VICTORY_TEXTURE_STREAM_FRAME=1 interaction with real gameplay streaming, and frame-time impact require external AMD hardware testing.
**@⁠tommiehansen** on GitHub · 2026-12-03 19:47 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/313#issuecomment-7390244055) ### Adapted to `by_due` Indexed Queue & False-Backlog Fix (`2da28da`) Merged `origin/main` (`45591b0`, including PR #295's `by_due` indexed due queue and PR #304's descriptor copy spans) and updated `VICTORY_TEXTURE_STREAM_FRAME` to consume `by_due` instead of scanning `TextureQueue::slots`. #### Technical changes - **Indexed `by_due` cursor (`crates/victory-gpu/src/descriptor/stream_policy.rs`, `DueCursor`):** Replaces the previous `slots` full-queue cursor scan (which walked future `later` and `u64::MAX` `held` entries across 32-slot lock acquisitions) with a bounded `by_due` range cursor (`..=(frame, u32::MAX)`). Resets cleanly at each new frame so oldest overdue slots are served first without starvation while advancing within a frame past `active` / `wanted` slots. - **Accurate due backlog & census (`sample_due`, `StreamQueueStats`):** Samples `by_due` up to `BACKLOG_THRESHOLD` (1024) instead of treating `slots.len() >= 1024` (which includes future/held entries) as an active backlog, preventing false 3x frame-budget bursts and skipping `TextureStreamPass::start` completely when `due_sample == 0`. Also populates `HEAP_TEXTURES_QUEUE[1..6]` and `HEAP_TEXTURES_OVERDUE_PEAK` telemetry in the adaptive path. - **Cross-platform pure-Rust extraction:** Moved `DueCursor`, `sample_due`, `texture_stream_micros`, `texture_stream_spent`, `background_texture_pass`, and `present_clock_needed` into `crates/victory-gpu/src/descriptor/stream_policy.rs`. #### macOS ARM64 CPU Benchmark Results (`rustc -O`, A/B/B/A 8-block median, direct production `stream_policy.rs`) 27,000-slot `TextureQueue` modeled after #295's measured profile: | Scenario (27,000 queued) | Previous PR #313 (`slots` scan) | Updated (`by_due` index) | Latency Delta | | --- | ---: | ---: | ---: | | Sparse due (150 due, 4 active, select 32) | 42.494 us (451 locks, 13,955 visits) | 1.811 us (32 locks, 36 visits) | **-95.74%** | | Zero due (0 due, 27,000 future) | 59.035 us (844 locks, 27,000 visits) | 0.006 us (0 locks, 0 visits) | **-99.99%** | | Heavy backlog behind 20k future/held (4,000 due, sel 64) | 42.341 us (689 locks, 20,068 visits, max_age=2) | 4.585 us (64 locks, 64 visits, max_age=120) | **-89.17%** | | Full-card held queue (20k held, 150 due, sel 32) | 60.055 us (871 locks, 26,884 visits) | 1.953 us (32 locks, 34 visits) | **-96.75%** | | Pure front backlog (slots 1..4000 all due, sel 64) | 1.378 us (68 visits, max_age=2 starved) | 2.803 us (64 visits, max_age=120 oldest first) | +1.4 us (`sample_due` + overdue priority) | #### Verification & Reproduction - **Native unit tests (macOS ARM64):** `rustc --edition 2024 --test crates/victory-gpu/src/descriptor/stream_policy.rs -o /tmp/test_stream_policy && /tmp/test_stream_policy` (7 passed, 0 failed). - **Windows cross-target check:** `cargo check -p victory-gpu --lib --target x86_64-pc-windows-msvc --features blake3/pure` and `--features blake3/pure,diagnostics` (0 errors, 0 warnings, check-only `libmimalloc-sys` shim), plus `cargo --offline xtask policy --staged` (6 files ok) and `xtask -- switches` (0 new errors). - **Known limitations:** Benchmarks and unit tests above ran on macOS ARM64 CPU-only against synthetic 27k queues. Live Windows/RADV GPU execution, `VICTORY_TEXTURE_STREAM_FRAME=1` interaction with real gameplay streaming, and frame-time impact require external AMD hardware testing.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-03 20:37 UTC · original

Tested 2da28da on Windows 11 with a native MSVC build (toolchain 1.98.1) and one NVIDIA desktop card for the D3D12 tests. I only ran -p victory-gpu and no game, so I can't say anything about frame times. No test goes through heap_textures or after_present, so for the draw.rs loop and the present timing change I only read the code.

With VICTORY_TEXTURE_STREAM_FRAME unset I don't see any change in behaviour. background_texture_pass is false (draw.rs:3770), so the old texture_slots_wanted path runs and the new branch of the upload loop (draw.rs:3886) is never reached. present_clock_needed(timing, adaptive, false) in host.rs:8757 comes out the same as the old timing || adaptive.

The cursor looks right to me. I ran a throwaway randomized test (not pushed) that compares next_due against a simple reference model while slots get inserted, removed and re-dued between calls, and it matched over 200 runs. Every slot it picks also goes through lease_texture again under the lock before it's used. The two breaks that leave a picked slot due (draw.rs:4168 and 4350) only happen in the 500 ms window after an out of memory error, and main stops there too.

Two things worth knowing before anyone does the A/B.

  1. The background order changes as well as the speed. The cursor goes back to the front of by_due every frame (stream_policy.rs:49), so it always takes the oldest due slot first. Main's in_order (descriptor/host.rs:1125) alternates the newest written slot with the oldest. In a local test with 2000 slots written at frame 1 and one more written at frame 49, main hands out the new one first in frame 50, and the cursor only reaches it on pick 2001. Material requests still go ahead of both, so this may be fine, but a slot written just now that no material asks for waits behind the whole backlog. Also the order is by due frame and then slot, not slot order like the description says, and "the cursor survives deferral" is only true within the same frame.

  2. With the switch on, the texture age numbers aren't comparable with main. HEAP_TEXTURES_QUEUE[4] is never written on that path (draw.rs:3804-3812), and the overdue peak only looks at by_due.first() (descriptor/host.rs:2230) where main takes the max over every due slot. changed() (descriptor/host.rs:1286) keeps the lower due but moves written up to now, so the first entry isn't always the oldest. For example slot A is due at 10 and gets changed at frame 40, and slot B is written and due at 20. At frame 50 main reports 30 and this branch reports 10.

The 8 new tests passed 20 times in a row in both debug and release. None of them read the env switch. For the full suite I skipped descriptor::tests::views_die_with_their_resource because it's known to crash on main. The PR head got 337 passed and 5 failed (338 and 4 with the switch set), and main at 0b652f8 got 338 and 5. The same four failures in indirect::tests and pipeline::host::tests show up on both. The last one is a watch::tests test that changes from run to run. Clippy shows no new warnings compared to main, and the branch still merges cleanly.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-03 20:37 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/313#issuecomment-7391518651) Tested 2da28da on Windows 11 with a native MSVC build (toolchain 1.98.1) and one NVIDIA desktop card for the D3D12 tests. I only ran `-p victory-gpu` and no game, so I can't say anything about frame times. No test goes through `heap_textures` or `after_present`, so for the draw.rs loop and the present timing change I only read the code. With `VICTORY_TEXTURE_STREAM_FRAME` unset I don't see any change in behaviour. `background_texture_pass` is false (draw.rs:3770), so the old `texture_slots_wanted` path runs and the new branch of the upload loop (draw.rs:3886) is never reached. `present_clock_needed(timing, adaptive, false)` in host.rs:8757 comes out the same as the old `timing || adaptive`. The cursor looks right to me. I ran a throwaway randomized test (not pushed) that compares `next_due` against a simple reference model while slots get inserted, removed and re-dued between calls, and it matched over 200 runs. Every slot it picks also goes through `lease_texture` again under the lock before it's used. The two `break`s that leave a picked slot due (draw.rs:4168 and 4350) only happen in the 500 ms window after an out of memory error, and main stops there too. Two things worth knowing before anyone does the A/B. 1. The background order changes as well as the speed. The cursor goes back to the front of `by_due` every frame (stream_policy.rs:49), so it always takes the oldest due slot first. Main's `in_order` (descriptor/host.rs:1125) alternates the newest written slot with the oldest. In a local test with 2000 slots written at frame 1 and one more written at frame 49, main hands out the new one first in frame 50, and the cursor only reaches it on pick 2001. Material requests still go ahead of both, so this may be fine, but a slot written just now that no material asks for waits behind the whole backlog. Also the order is by due frame and then slot, not slot order like the description says, and "the cursor survives deferral" is only true within the same frame. 2. With the switch on, the texture age numbers aren't comparable with main. `HEAP_TEXTURES_QUEUE[4]` is never written on that path (draw.rs:3804-3812), and the overdue peak only looks at `by_due.first()` (descriptor/host.rs:2230) where main takes the max over every due slot. `changed()` (descriptor/host.rs:1286) keeps the lower due but moves `written` up to now, so the first entry isn't always the oldest. For example slot A is due at 10 and gets changed at frame 40, and slot B is written and due at 20. At frame 50 main reports 30 and this branch reports 10. The 8 new tests passed 20 times in a row in both debug and release. None of them read the env switch. For the full suite I skipped `descriptor::tests::views_die_with_their_resource` because it's known to crash on main. The PR head got 337 passed and 5 failed (338 and 4 with the switch set), and main at 0b652f8 got 338 and 5. The same four failures in `indirect::tests` and `pipeline::host::tests` show up on both. The last one is a `watch::tests` test that changes from run to run. Clippy shows no new warnings compared to main, and the branch still merges cleanly. AI-assisted: yes
Give recent ready writes the first background turn on alternating admitted frames and charge the bounded probe to the existing scan budget. Index effective readiness only with adaptive streaming enabled so rewritten descriptors cannot hide the true maximum overdue age. Restore oldest-write telemetry as an explicitly sampled lower bound.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-03 22:02 UTC · original

Retested at 17af52e, same setup as before (native Windows build, -p victory-gpu only, no game).

The overdue numbers are fixed. I ran a throwaway randomized test (not pushed) through written, changed, later, done and stream_next with the switch on, 200 seeds of 500 frames. stream_ready always held exactly the entries in slots, and ages().1 matched main's census overdue value on every frame. The sampled write age never went above main's, and in that load it never came out lower either. You can get it lower on purpose. With 40 slots written at frame 10 and one written at frame 1 but pushed to due 45 by later, main says 49 at frame 50 and this branch says 40. That's what the new log field says, so I'm fine with it.

The order is better for a single fresh slot. Same scenario as last time, 2000 slots written at frame 1 and one at frame 49, picked at frame 50. Main hands out 5000, 1, 2000, 2. This head gives 5000, 1, 2, 3 when the cursor has its turn on frame 50. When frame 50 is the off turn, with 8 picks per frame it takes 1 to 8 there and gives 5000 first on frame 51. The index is only kept with the switch on, so the same test run without it still gets 5000 at pick 2001, but with the switch off this path isn't used anyway.

Two cases still fall back to the old order.

  1. More than one fresh slot. With 10 slots written at frame 49, main gives them picks 1, 3, 5 up to 19 of frame 50. Here only one of them gets the recent turn. The other nine come out last, behind all 2000 old slots, because by frame 52 they are outside the two frame window.

  2. A frame with no background pass. If frame 50 is the off turn and the streamer doesn't run at frame 51, the slot written at 49 is already out of the window at frame 52 and comes out as pick 1993.

Neither one loses anything. The oldest lane still walks by due frame and slot and nothing starved in the randomized runs. The longest any due slot waited was 2 frames, at a load where picks kept up with writes. So I'd call this a bounded nudge for new writes rather than main's alternation, and that might be all you want. The new section of the description says due frame and slot, but the older paragraph still says "slot order" and that the cursor survives deferral, so the two now disagree.

The other points hold. The recent lane returns the same (slot, write, age) tuple and goes through the same lease_texture check as before. The visit charge can't underflow because the probe leaves at least one visit for the cursor. With the switch off the only extra work is one OnceLock read per queue edit, the index stays empty, and the old path runs. The meter log line does get one more field, which is just false then.

Tests. The 10 policy and cursor tests passed 20 times in a row in debug and release, with the switch unset and with it set to 1. The host.rs cursor test now does depend on the switch, but it passes either way. Full suite, skipping descriptor::tests::views_die_with_their_resource like before. Unset gave 340 passed and 4 failed. Set to 1 gave 339 and 5. The four in indirect::tests and pipeline::host::tests are the same ones that fail on main, and the fifth with the switch set is the watch::tests test that changes from run to run. Last time it showed up on the unset run instead, so it doesn't follow the switch. Clippy shows no new warnings compared to main.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-03 22:02 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/313#issuecomment-7393659859) Retested at 17af52e, same setup as before (native Windows build, `-p victory-gpu` only, no game). The overdue numbers are fixed. I ran a throwaway randomized test (not pushed) through `written`, `changed`, `later`, `done` and `stream_next` with the switch on, 200 seeds of 500 frames. `stream_ready` always held exactly the entries in `slots`, and `ages().1` matched main's census overdue value on every frame. The sampled write age never went above main's, and in that load it never came out lower either. You can get it lower on purpose. With 40 slots written at frame 10 and one written at frame 1 but pushed to due 45 by `later`, main says 49 at frame 50 and this branch says 40. That's what the new log field says, so I'm fine with it. The order is better for a single fresh slot. Same scenario as last time, 2000 slots written at frame 1 and one at frame 49, picked at frame 50. Main hands out 5000, 1, 2000, 2. This head gives 5000, 1, 2, 3 when the cursor has its turn on frame 50. When frame 50 is the off turn, with 8 picks per frame it takes 1 to 8 there and gives 5000 first on frame 51. The index is only kept with the switch on, so the same test run without it still gets 5000 at pick 2001, but with the switch off this path isn't used anyway. Two cases still fall back to the old order. 1. More than one fresh slot. With 10 slots written at frame 49, main gives them picks 1, 3, 5 up to 19 of frame 50. Here only one of them gets the recent turn. The other nine come out last, behind all 2000 old slots, because by frame 52 they are outside the two frame window. 2. A frame with no background pass. If frame 50 is the off turn and the streamer doesn't run at frame 51, the slot written at 49 is already out of the window at frame 52 and comes out as pick 1993. Neither one loses anything. The oldest lane still walks by due frame and slot and nothing starved in the randomized runs. The longest any due slot waited was 2 frames, at a load where picks kept up with writes. So I'd call this a bounded nudge for new writes rather than main's alternation, and that might be all you want. The new section of the description says due frame and slot, but the older paragraph still says "slot order" and that the cursor survives deferral, so the two now disagree. The other points hold. The recent lane returns the same `(slot, write, age)` tuple and goes through the same `lease_texture` check as before. The visit charge can't underflow because the probe leaves at least one visit for the cursor. With the switch off the only extra work is one `OnceLock` read per queue edit, the index stays empty, and the old path runs. The meter log line does get one more field, which is just false then. Tests. The 10 policy and cursor tests passed 20 times in a row in debug and release, with the switch unset and with it set to 1. The host.rs cursor test now does depend on the switch, but it passes either way. Full suite, skipping `descriptor::tests::views_die_with_their_resource` like before. Unset gave 340 passed and 4 failed. Set to 1 gave 339 and 5. The four in `indirect::tests` and `pipeline::host::tests` are the same ones that fail on main, and the fifth with the switch set is the `watch::tests` test that changes from run to run. Last time it showed up on the unset run instead, so it doesn't follow the switch. Clippy shows no new warnings compared to main. AI-assisted: yes
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-04 00:02 UTC · original

Thanks @⁠Kal0s-design for catching both scheduling edge cases and the stale PR description text. Updated the branch to a68af21 (dd1d75f + a68af21) and refreshed the PR description to match the (due, slot) cursor and fairness rules.

Changes in dd1d75f..a68af21

  1. Multi-item fresh write bursts (DueCursor::want_recent / ReadyIndex::next_recent): Replaced the single-shot per-frame scout_recent flag with 1:1 per-pick alternation (want_recent / note_recent_pick / note_due_pick, bounded by RECENT_PROBE_MAX = 8, descending from (frame, u64::MAX, u32::MAX) via recent_last + recent_exhausted) so fresh bursts cannot saturate after one admission and fall behind an overdue backlog.
  2. Skipped / budget-exhausted background passes (DueCursor::prev_active_frame, recent_floor): Tracks the previous active selection frame (prev_active_frame, bounded by RECENT_WRITE_FRAMES = 4 and RECENT_MAX_AGE_FRAMES = 16, initialized to frame.saturating_sub(RECENT_WRITE_FRAMES) before the first active frame so initial/reset frames avoid an unnecessary 16-frame lookback). Fresh writes arriving right before deferred passes stay within recent_floor when background work resumes.

Validation (a68af21)

  • Unit & 200-seed differential tests (stream_policy.rs): 13/13 passing in both debug (0.26s) and -O release (0.04s), including burst_of_recent_writes_interleaves_one_to_one_with_backlog, multi_frame_burst_under_tiny_budget_and_continuous_stream_avoid_starvation, and skipped_background_passes_preserve_recent_write_priority_across_frames.
  • Windows cross-check: cargo check --offline -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --features blake3/pure,diagnostics clean.
  • Paired CPU Benchmark Suite (--profile standard --blocks 4 --suite textures):
    • vs origin/main (45591b0, unset vs VICTORY_TEXTURE_STREAM_FRAME=1): textures/stream_queue_lifecycle 5.183 -> 0.863 ms (-83.35%, slots_inspected: 1,675,620 -> 5,940); textures/stream_queue_policy 1.803 -> 0.015 ms (-99.18%, slots_inspected: 495,906 -> 3,733).
    • vs 17af52e (both VICTORY_TEXTURE_STREAM_FRAME=1): in textures/stream_queue_lifecycle, skipped_pass_fresh_delay dropped 32 -> 0, fresh_burst_within_2_frames improved 0 -> 7, and slots_inspected dropped 9,240 -> 5,940 (-35.7%) at parity frame time (0.875 -> 0.870 ms, -0.41%). In static textures/stream_queue_policy, 1:1 interleaving adds ~2 us (0.013 -> 0.015 ms, +19.78%, slots_inspected: 2,201 -> 3,733) vs the 1/frame scout while remaining -99.18% vs origin/main.
**@⁠tommiehansen** on GitHub · 2026-12-04 00:02 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/313#issuecomment-7396291134) Thanks @⁠Kal0s-design for catching both scheduling edge cases and the stale PR description text. Updated the branch to `a68af21` (`dd1d75f` + `a68af21`) and refreshed the PR description to match the `(due, slot)` cursor and fairness rules. ### Changes in `dd1d75f`..`a68af21` 1. **Multi-item fresh write bursts (`DueCursor::want_recent` / `ReadyIndex::next_recent`):** Replaced the single-shot per-frame `scout_recent` flag with 1:1 per-pick alternation (`want_recent` / `note_recent_pick` / `note_due_pick`, bounded by `RECENT_PROBE_MAX = 8`, descending from `(frame, u64::MAX, u32::MAX)` via `recent_last` + `recent_exhausted`) so fresh bursts cannot saturate after one admission and fall behind an overdue backlog. 2. **Skipped / budget-exhausted background passes (`DueCursor::prev_active_frame`, `recent_floor`):** Tracks the previous active selection frame (`prev_active_frame`, bounded by `RECENT_WRITE_FRAMES = 4` and `RECENT_MAX_AGE_FRAMES = 16`, initialized to `frame.saturating_sub(RECENT_WRITE_FRAMES)` before the first active frame so initial/reset frames avoid an unnecessary 16-frame lookback). Fresh writes arriving right before deferred passes stay within `recent_floor` when background work resumes. ### Validation (`a68af21`) - **Unit & 200-seed differential tests (`stream_policy.rs`):** 13/13 passing in both debug (`0.26s`) and `-O` release (`0.04s`), including `burst_of_recent_writes_interleaves_one_to_one_with_backlog`, `multi_frame_burst_under_tiny_budget_and_continuous_stream_avoid_starvation`, and `skipped_background_passes_preserve_recent_write_priority_across_frames`. - **Windows cross-check:** `cargo check --offline -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --features blake3/pure,diagnostics` clean. - **Paired CPU Benchmark Suite (`--profile standard --blocks 4 --suite textures`):** - vs `origin/main` (`45591b0`, unset vs `VICTORY_TEXTURE_STREAM_FRAME=1`): `textures/stream_queue_lifecycle` `5.183 -> 0.863 ms` (**-83.35%**, `slots_inspected`: `1,675,620 -> 5,940`); `textures/stream_queue_policy` `1.803 -> 0.015 ms` (**-99.18%**, `slots_inspected`: `495,906 -> 3,733`). - vs `17af52e` (both `VICTORY_TEXTURE_STREAM_FRAME=1`): in `textures/stream_queue_lifecycle`, `skipped_pass_fresh_delay` dropped `32 -> 0`, `fresh_burst_within_2_frames` improved `0 -> 7`, and `slots_inspected` dropped `9,240 -> 5,940` (**-35.7%**) at parity frame time (`0.875 -> 0.870 ms`, `-0.41%`). In static `textures/stream_queue_policy`, 1:1 interleaving adds `~2 us` (`0.013 -> 0.015 ms`, `+19.78%`, `slots_inspected`: `2,201 -> 3,733`) vs the 1/frame scout while remaining `-99.18%` vs `origin/main`.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 00:29 UTC · original

Rechecked at a68af21 with the same setup as before (native Windows build, -p victory-gpu only, no game).

Both order cases from last time are fixed. With 10 slots written at frame 49 behind 2000 old ones, frame 50 now hands them out at picks 1, 3, 5 up to 19, the same as main, or 2, 4 up to 20 when frame 50 starts on the old turn. At 8 picks per frame they go out 4 per frame over frames 50 to 52, frame for frame the same as main. The single slot written at 49 with one pick on the off turn at 50 and no pass at 51 is now pick 1 at frame 52 (it was 1993). The window edges behave the way the description says. After a pass at 50 the next pass keeps the alternation up to frame 62 and from 66 on the burst goes to the back, and a first ever pass still alternates at 53 and falls back at 54. Longer bursts only get part of the way. With 40 written at 49 and 8 picks per frame, 20 interleave over frames 50 to 54 and the other 20 end up behind the 2000 old slots, where main has all 40 out by frame 59. That's the bounded window doing what it says, but "cannot fall behind" is a bit strong for bursts longer than the window.

One new thing. The recent probe charges every entry it looks at against remaining, including the ones it rejects, and outside a backlog remaining is exactly the due count from sample_due. Entries in the probe range that fail written >= floor or looks == 0 && mapped == 0 use up visits, and the due cursor then runs out before it reaches them. Simple case, 10 slots written at frame 1 and put off with later to due 50, nothing else due. Main hands out all 10 at frame 50. This head gives 2 at 50, then 1 per frame, and the last 3 at 56. That's with one pass per frame. A second pass in the same frame does pick up the rest, since recent_last is already past them. Recent writes that already had one look behave the same, 5 of them took until frame 55 next to 13 other due slots that main served all at once. In a randomized run with light load, frames that had picks to spare but still left a due slot behind went from 0 at 2da28da to 1,866 at 17af52e and 10,083 (out of about 97k) at this head. With 4 times the visit budget it drops to 0, so it's only the charge. Nothing gets lost, they're out of the window after a few frames. Not counting rejected recent probes against remaining (they still count against the 32 per lock) would probably be enough.

Fairness, same throwaway randomized harness, about 300 seeds of 600 frames with writes, changed, later, removes, active slots and skipped passes. No slot was lost and picks from the oldest lane always came out in rising (due, slot) order within a frame. Longest wait of a due slot under light load was 7 frames (main 8, 17af52e 6). Under heavy load it was 28 (main 41, 17af52e 20), with p99 14 against 16 on main and 9 on 17af52e. So the 1:1 alternation costs the backlog a bit compared with the last head but it's still ahead of main. A separate 500 seed run without removes checked that the ready index always held exactly the queued slots, and it did. These loads never got to 1024 due slots, so they say nothing about the backlog path.

From reading the new state I didn't find a problem. The range can't invert because prev <= lower returns first, held slots at u64::MAX sit above the upper bound, a removed recent_last key is only used as a bound, and a frame going backwards resets everything (the host test's call at 40 after 50 covers that). A write that lands mid frame after recent_exhausted waits for the next frame, which seems fine.

Tests. The 14 policy and cursor tests passed 20 times in a row in debug and release, with the switch unset and set to 1. Full suite, skipping descriptor::tests::views_die_with_their_resource as before, gave 343 passed and 5 failed both ways, the same four indirect::tests and pipeline::host::tests failures as main plus the watch::tests one that changes from run to run. Clippy has three new manual_is_multiple_of warnings, all in the new randomized test in stream_policy.rs (rng.next() % 5 == 0 and the like), nothing in the library code. The branch still merges cleanly.

The description matches the code now, the old "slot order" and "survives deferral" lines are gone. Small thing, the sampling bullet says O(1) but it walks up to 1024 entries.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 00:29 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/313#issuecomment-7396838523) Rechecked at a68af21 with the same setup as before (native Windows build, `-p victory-gpu` only, no game). Both order cases from last time are fixed. With 10 slots written at frame 49 behind 2000 old ones, frame 50 now hands them out at picks 1, 3, 5 up to 19, the same as main, or 2, 4 up to 20 when frame 50 starts on the old turn. At 8 picks per frame they go out 4 per frame over frames 50 to 52, frame for frame the same as main. The single slot written at 49 with one pick on the off turn at 50 and no pass at 51 is now pick 1 at frame 52 (it was 1993). The window edges behave the way the description says. After a pass at 50 the next pass keeps the alternation up to frame 62 and from 66 on the burst goes to the back, and a first ever pass still alternates at 53 and falls back at 54. Longer bursts only get part of the way. With 40 written at 49 and 8 picks per frame, 20 interleave over frames 50 to 54 and the other 20 end up behind the 2000 old slots, where main has all 40 out by frame 59. That's the bounded window doing what it says, but "cannot fall behind" is a bit strong for bursts longer than the window. One new thing. The recent probe charges every entry it looks at against `remaining`, including the ones it rejects, and outside a backlog `remaining` is exactly the due count from `sample_due`. Entries in the probe range that fail `written >= floor` or `looks == 0 && mapped == 0` use up visits, and the due cursor then runs out before it reaches them. Simple case, 10 slots written at frame 1 and put off with `later` to due 50, nothing else due. Main hands out all 10 at frame 50. This head gives 2 at 50, then 1 per frame, and the last 3 at 56. That's with one pass per frame. A second pass in the same frame does pick up the rest, since `recent_last` is already past them. Recent writes that already had one look behave the same, 5 of them took until frame 55 next to 13 other due slots that main served all at once. In a randomized run with light load, frames that had picks to spare but still left a due slot behind went from 0 at 2da28da to 1,866 at 17af52e and 10,083 (out of about 97k) at this head. With 4 times the visit budget it drops to 0, so it's only the charge. Nothing gets lost, they're out of the window after a few frames. Not counting rejected recent probes against `remaining` (they still count against the 32 per lock) would probably be enough. Fairness, same throwaway randomized harness, about 300 seeds of 600 frames with writes, `changed`, `later`, removes, active slots and skipped passes. No slot was lost and picks from the oldest lane always came out in rising `(due, slot)` order within a frame. Longest wait of a due slot under light load was 7 frames (main 8, 17af52e 6). Under heavy load it was 28 (main 41, 17af52e 20), with p99 14 against 16 on main and 9 on 17af52e. So the 1:1 alternation costs the backlog a bit compared with the last head but it's still ahead of main. A separate 500 seed run without removes checked that the ready index always held exactly the queued slots, and it did. These loads never got to 1024 due slots, so they say nothing about the backlog path. From reading the new state I didn't find a problem. The range can't invert because `prev <= lower` returns first, held slots at `u64::MAX` sit above the upper bound, a removed `recent_last` key is only used as a bound, and a frame going backwards resets everything (the host test's call at 40 after 50 covers that). A write that lands mid frame after `recent_exhausted` waits for the next frame, which seems fine. Tests. The 14 policy and cursor tests passed 20 times in a row in debug and release, with the switch unset and set to 1. Full suite, skipping `descriptor::tests::views_die_with_their_resource` as before, gave 343 passed and 5 failed both ways, the same four `indirect::tests` and `pipeline::host::tests` failures as main plus the `watch::tests` one that changes from run to run. Clippy has three new `manual_is_multiple_of` warnings, all in the new randomized test in stream_policy.rs (`rng.next() % 5 == 0` and the like), nothing in the library code. The branch still merges cleanly. The description matches the code now, the old "slot order" and "survives deferral" lines are gone. Small thing, the sampling bullet says O(1) but it walks up to 1024 entries. AI-assisted: yes
- Pass max_probe (STREAM_STEP_MAX - 1) to ReadyIndex::next_recent instead of charging rejected recent probes against remaining due-selection budget
- Charge recent picks only 1 unit of remaining budget while still counting all recent_visits against STREAM_STEP_MAX per lock acquisition
- Add regression tests for deferred entries, already-looked recent writes, and 100-seed light workloads
- Fix 3 clippy manual_is_multiple_of warnings in randomized stream_policy test
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-04 00:49 UTC · original

@⁠Kal0s-design Thank you for re-checking a68af21 and pinpointing the rejected-probe remaining charge — that was a clear accounting bug. Fixed in 500acac with a minimal change:

  1. Separated recent-probe inspection limits from the remaining due-selection budget:
    • ReadyIndex::next_recent (crates/victory-gpu/src/descriptor/stream_policy.rs) now takes max_probe (STREAM_STEP_MAX - 1, capped by RECENT_PROBE_MAX = 8) instead of remaining, leaving at least one per-lock visit for next_due.
    • TextureQueue::stream_next (crates/victory-gpu/src/descriptor/host.rs) counts all recent_visits against STREAM_STEP_MAX (STREAM_STEP_MAX - recent_visits passed to next_due), returns 1 against remaining on an accepted recent pick, and passes full remaining (not remaining - recent_visits) to next_due so rejected recent entries (written < floor, deferred later entries, or looks != 0 || mapped != 0) do not exhaust the pass budget.
  2. Regression tests & Clippy:
    • Added rejected_recent_probes_do_not_exhaust_due_selection_budget covering both exact failure cases you described (10 later-deferred entries due at frame 50, 5 already-looked recent writes next to 13 older due entries, plus a mixed fresh/looked/old 1:1 interleaving case — all complete in a single pass with recent_visits + due_visits <= STREAM_STEP_MAX) and light_workload_leaves_no_eligible_due_slots_behind_across_frames (100 seeds × 200 frames, 0 left-behind eligible slots).
    • Replaced % 5 == 0, % 8 == 0, and % 4 == 0 in the randomized test with .is_multiple_of(...) (0 warnings in stream_policy.rs and stream_next under Windows cargo clippy --all-targets).
  3. PR description wording: Corrected bounded sampling (<= 1024 entries, not O(1)) and clarified that recent-write priority is bounded by the RECENT_WRITE_FRAMES = 4 / RECENT_MAX_AGE_FRAMES = 16 window.
  4. Verification (500acac):
    • stream_policy.rs standalone tests: 15/15 pass in debug (0.26s) and release (0.03s).
    • Windows victory-gpu --all-targets cargo clippy: clean on modified code.
    • Paired A/B/B/A texture benchmarks (--profile standard --blocks 4 --suite textures):
      • vs origin/main (45591b0 unset vs 500acac VICTORY_TEXTURE_STREAM_FRAME=1): textures/stream_queue_lifecycle 5.141 -> 0.865 ms (-83.21%, slots_inspected 1,675,620 -> 5,940); textures/stream_queue_policy 1.805 -> 0.015 ms (-99.18%, slots_inspected 495,906 -> 2,028, due_sampled 16,384 -> 204).
      • vs a68af21 (a68af21 vs 500acac, both enabled): textures/stream_queue_lifecycle 0.870 -> 0.859 ms (-0.77%, identical, skipped_pass_fresh_delay = 0, fresh_burst_within_2_frames = 7); textures/stream_queue_policy 0.015 -> 0.015 ms (-0.53%, identical, slots_inspected 3,733 -> 2,028).
**@⁠tommiehansen** on GitHub · 2026-12-04 00:49 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/313#issuecomment-7397205458) @⁠Kal0s-design Thank you for re-checking `a68af21` and pinpointing the rejected-probe `remaining` charge — that was a clear accounting bug. Fixed in `500acac` with a minimal change: 1. **Separated recent-probe inspection limits from the `remaining` due-selection budget:** - `ReadyIndex::next_recent` (`crates/victory-gpu/src/descriptor/stream_policy.rs`) now takes `max_probe` (`STREAM_STEP_MAX - 1`, capped by `RECENT_PROBE_MAX = 8`) instead of `remaining`, leaving at least one per-lock visit for `next_due`. - `TextureQueue::stream_next` (`crates/victory-gpu/src/descriptor/host.rs`) counts all `recent_visits` against `STREAM_STEP_MAX` (`STREAM_STEP_MAX - recent_visits` passed to `next_due`), returns `1` against `remaining` on an accepted recent pick, and passes full `remaining` (not `remaining - recent_visits`) to `next_due` so rejected recent entries (`written < floor`, deferred `later` entries, or `looks != 0 || mapped != 0`) do not exhaust the pass budget. 2. **Regression tests & Clippy:** - Added `rejected_recent_probes_do_not_exhaust_due_selection_budget` covering both exact failure cases you described (10 `later`-deferred entries due at frame 50, 5 already-looked recent writes next to 13 older due entries, plus a mixed fresh/looked/old 1:1 interleaving case — all complete in a single pass with `recent_visits + due_visits <= STREAM_STEP_MAX`) and `light_workload_leaves_no_eligible_due_slots_behind_across_frames` (100 seeds × 200 frames, 0 left-behind eligible slots). - Replaced `% 5 == 0`, `% 8 == 0`, and `% 4 == 0` in the randomized test with `.is_multiple_of(...)` (0 warnings in `stream_policy.rs` and `stream_next` under Windows `cargo clippy --all-targets`). 3. **PR description wording:** Corrected bounded sampling (`<= 1024` entries, not O(1)) and clarified that recent-write priority is bounded by the `RECENT_WRITE_FRAMES = 4` / `RECENT_MAX_AGE_FRAMES = 16` window. 4. **Verification (`500acac`):** - `stream_policy.rs` standalone tests: 15/15 pass in debug (`0.26s`) and release (`0.03s`). - Windows `victory-gpu --all-targets` `cargo clippy`: clean on modified code. - Paired A/B/B/A texture benchmarks (`--profile standard --blocks 4 --suite textures`): - vs `origin/main` (`45591b0` unset vs `500acac` `VICTORY_TEXTURE_STREAM_FRAME=1`): `textures/stream_queue_lifecycle` `5.141 -> 0.865 ms` (`-83.21%`, `slots_inspected` `1,675,620 -> 5,940`); `textures/stream_queue_policy` `1.805 -> 0.015 ms` (`-99.18%`, `slots_inspected` `495,906 -> 2,028`, `due_sampled` `16,384 -> 204`). - vs `a68af21` (`a68af21` vs `500acac`, both enabled): `textures/stream_queue_lifecycle` `0.870 -> 0.859 ms` (`-0.77%`, `identical`, `skipped_pass_fresh_delay = 0`, `fresh_burst_within_2_frames = 7`); `textures/stream_queue_policy` `0.015 -> 0.015 ms` (`-0.53%`, `identical`, `slots_inspected` `3,733 -> 2,028`).
github-bot changed title from draw: adapt the frame budget for background texture streaming to feat(gpu): adapt the frame budget for background texture streaming 2026-12-04 22:19:51 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/313/head:github-bot/gh-313'
git switch 'github-bot/gh-313'

Merge

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