gpu(host): step down fetch buffer allocations and retry readback creation #159

Manually merged
github merged 1 commit from gh-pr/159/head into gh-pr/159/base 2026-12-01 20:14:12 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-29 19:57 UTC · original
Androtim:feat/iter157-gpu-fetch-buffer-stepdown → main · +236 −16 · 3 files · 1 commits · merged 2026-11-29 21:27 UTC

## Summary

  • Add crates/victory-gpu/src/fetchmem.rs to step down relay and card-back fetch buffer allocations (16 MiB rounded unless under host memory pressure -> 1 MiB rounded -> minimum page-aligned byte count, plus one retry of the minimum after 5 ms) instead of aborting the title with a fatal error on allocation failure.
  • Preserve existing shared_buffer_staging residency fast-path inside Host::fetch_buffer.
  • When all stepdown attempts still fail (and VICTORY_FETCH_STEPDOWN=0 is not set), log NO MEMORY TO FETCH loudly, count skipped fetches/stale bytes, advance relay watermark or return non-fatally so later fetches recover those ranges.
  • Retry CreateCommittedResource once after 5 ms in Host::read_back_buffer when VICTORY_FETCH_STEPDOWN is active.

Test plan

  • cargo run -p xtask -- policy: passed
  • cargo test -p victory-gpu fetchmem::: 5/5 passed
  • cargo test -p victory-gpu host::: passed
  • Dual cargo clippy --workspace --all-targets (default and --features diagnostics) with -D warnings: passed
**@⁠Androtim** on GitHub · 2026-11-29 19:57 UTC · [original](https://github.com/Androtim/MiniVI/pull/159) `Androtim:feat/iter157-gpu-fetch-buffer-stepdown` → `main` · +236 −16 · 3 files · 1 commits · merged 2026-11-29 21:27 UTC ## Summary - Add `crates/victory-gpu/src/fetchmem.rs` to step down relay and card-back fetch buffer allocations (`16 MiB` rounded unless under host memory pressure -> `1 MiB` rounded -> minimum page-aligned byte count, plus one retry of the minimum after 5 ms) instead of aborting the title with a fatal error on allocation failure. - Preserve existing `shared_buffer_staging` residency fast-path inside `Host::fetch_buffer`. - When all stepdown attempts still fail (and `VICTORY_FETCH_STEPDOWN=0` is not set), log `NO MEMORY TO FETCH` loudly, count skipped fetches/stale bytes, advance relay watermark or return non-fatally so later fetches recover those ranges. - Retry `CreateCommittedResource` once after 5 ms in `Host::read_back_buffer` when `VICTORY_FETCH_STEPDOWN` is active. ## Test plan - `cargo run -p xtask -- policy`: passed - `cargo test -p victory-gpu fetchmem::`: 5/5 passed - `cargo test -p victory-gpu host::`: passed - Dual `cargo clippy --workspace --all-targets` (default and `--features diagnostics`) with `-D warnings`: passed
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:14:11 +00:00
github manually merged commit d7a62199b5 into gh-pr/159/base 2026-12-01 20:14:12 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 20:04 UTC · original

Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

Logic and safety look solid, CI is passing, and the change is cleanly scoped to crates/victory-gpu/src/fetchmem.rs, crates/victory-gpu/src/host.rs, and crates/victory-gpu/src/lib.rs.

  • Relay & card-back stepdown (Host::fetch_buffer, fetchmem::buffer, fetchmem::sizes): Dropping f.buffer / work.fetched before reallocating is safe because both paths synchronize on the prior fetch fence before reusing the buffer. Preserving shared_buffer_staging keeps the existing residency fast path intact. When allocation still fails after stepping down (16 MiB -> 1 MiB -> 64 KiB-aligned minimum + one 5 ms retry), logging via fetchmem::skipped and advancing crate::shadow::relay_fetched(after) on the relay path matches the existing pieces.is_empty() path.
  • Readback retry (Host::read_back_buffer): Retrying CreateCommittedResource once after 5 ms (resetting buffer = None) only runs on the error path and is gated by fetchmem::on().
  • Escape hatch: VICTORY_FETCH_STEPDOWN=0 cleanly restores the previous single 16 MiB attempt and fatal error behavior.

Minor Non-Blocking Notes

  • fetchmem::sizes(total, tight): If ever called with total == 0, 0u64.next_multiple_of(...) produces 0 before .max(1 << 16) produces 65536 (ascending instead of descending). Current callers guard !pieces.is_empty() with hi > lo, so total > 0 in practice, but clamping total.max(1) would make sizes total-safe.
  • Host::card_back: Returning early when work.fetched is None leaves the pieces from that CardPlan inserted in seen, so if a later CardPlan in the same settled batch references the same (shadow, lo, hi) with a smaller total that would fit, seen.insert(...) would skip it for that batch.
  • fetchmem::buffer: On a successful retry of least when least == usual (e.g., total == 1 << 20, tight == true), COUNTS[2] is incremented even though the buffer was not smaller than usual (currently test-only).

Next Step

Because this touches D3D12 host fetch/readback buffer lifecycle and residency::pressured() sizing in crates/victory-gpu/src/host.rs, a local real-GPU smoke test is recommended before merging.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-29 20:04 UTC · [original](https://github.com/Androtim/MiniVI/pull/159#issuecomment-7261781664) <!-- minivi-triage v1 head=d7a62199b55a9550f09013798c074aa25935fc65 verdict=needs-gpu-test ci=passing at=2026-11-29T20:04:47Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic and safety look solid, CI is passing, and the change is cleanly scoped to `crates/victory-gpu/src/fetchmem.rs`, `crates/victory-gpu/src/host.rs`, and `crates/victory-gpu/src/lib.rs`. - **Relay & card-back stepdown (`Host::fetch_buffer`, `fetchmem::buffer`, `fetchmem::sizes`)**: Dropping `f.buffer` / `work.fetched` before reallocating is safe because both paths synchronize on the prior fetch fence before reusing the buffer. Preserving `shared_buffer_staging` keeps the existing residency fast path intact. When allocation still fails after stepping down (`16 MiB` -> `1 MiB` -> `64 KiB`-aligned minimum + one 5 ms retry), logging via `fetchmem::skipped` and advancing `crate::shadow::relay_fetched(after)` on the relay path matches the existing `pieces.is_empty()` path. - **Readback retry (`Host::read_back_buffer`)**: Retrying `CreateCommittedResource` once after 5 ms (resetting `buffer = None`) only runs on the error path and is gated by `fetchmem::on()`. - **Escape hatch**: `VICTORY_FETCH_STEPDOWN=0` cleanly restores the previous single 16 MiB attempt and fatal error behavior. ### Minor Non-Blocking Notes - `fetchmem::sizes(total, tight)`: If ever called with `total == 0`, `0u64.next_multiple_of(...)` produces `0` before `.max(1 << 16)` produces `65536` (ascending instead of descending). Current callers guard `!pieces.is_empty()` with `hi > lo`, so `total > 0` in practice, but clamping `total.max(1)` would make `sizes` total-safe. - `Host::card_back`: Returning early when `work.fetched` is `None` leaves the pieces from that `CardPlan` inserted in `seen`, so if a later `CardPlan` in the same settled batch references the same `(shadow, lo, hi)` with a smaller `total` that would fit, `seen.insert(...)` would skip it for that batch. - `fetchmem::buffer`: On a successful retry of `least` when `least == usual` (e.g., `total == 1 << 20`, `tight == true`), `COUNTS[2]` is incremented even though the buffer was not smaller than `usual` (currently test-only). ### Next Step Because this touches D3D12 host fetch/readback buffer lifecycle and `residency::pressured()` sizing in `crates/victory-gpu/src/host.rs`, a local real-GPU smoke test is recommended before merging. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 21:27 UTC · original

Automated RTX 4060 Ti 8 GB Open-World A/B hardware verification PASSED (playtest/wave5 vs origin/main b1b6dc1, VICTORY_LEVELS_ON_DEMAND=0 play-parity):

  • Hardware cargo test (RTX 4060 Ti): 645 passed, 0 failed (victory 39/39, victory-shader emit::wave64_tests 19/19 & lower 19/19, victory-gpu 568/568).
  • 45s Open-World A/B (scripts/verify-world.ps1, DLSS Quality + open-world save):
    • FPS: median 9.4 fps vs 7.5 fps (+1.90 fps / +25%), min 8.3 fps vs 0.8 fps, preparing 53.6 ms vs 60.0 ms
    • Stability: 0 crashes / 0 DRED / 0 untranslated shaders
    • VRAM / Issue #149: max 5760 MB vs 6005 MB (-245 MB, 0 MB over budget); no room for new ones halved (9,000 vs 18,000); max_waiting dropped (36,432 vs 41,431)
    • Decoration bakes / Issue #150: 0 mismatches (other_bytes=0, showed_another_view=0, failed=0 vs 5 and 2 on baseline)
    • Residency stalls: mapped_rate 1.63 ms/s vs 6.9 ms/s (-76%, max 12.9 vs 51.9 ms)
    • Visual check: Clean open-world safehouse frames (frame-5975.png, frame-5983.png), edge_energy=4.69 vs 3.88, near_black=0.02%, magenta=0.0% (and #141 2bf6800 showed zero visual artifacts).
**@⁠Androtim** on GitHub · 2026-11-29 21:27 UTC · [original](https://github.com/Androtim/MiniVI/pull/159#issuecomment-7262889963) Automated RTX 4060 Ti 8 GB **Open-World** A/B hardware verification **PASSED** (`playtest/wave5` vs `origin/main` `b1b6dc1`, `VICTORY_LEVELS_ON_DEMAND=0` play-parity): - **Hardware `cargo test` (RTX 4060 Ti):** **645 passed, 0 failed** (`victory` 39/39, `victory-shader` `emit::wave64_tests` 19/19 & `lower` 19/19, `victory-gpu` 568/568). - **45s Open-World A/B (`scripts/verify-world.ps1`, DLSS Quality + open-world save):** - **FPS:** median **`9.4 fps`** vs `7.5 fps` (**+1.90 fps / +25%**), min **`8.3 fps`** vs **`0.8 fps`**, preparing `53.6 ms` vs `60.0 ms` - **Stability:** **0** crashes / **0** DRED / **0** untranslated shaders - **VRAM / Issue #149:** max **`5760 MB`** vs `6005 MB` (**-245 MB**, `0 MB` over budget); `no room for new ones` halved (**`9,000`** vs `18,000`); `max_waiting` dropped (`36,432` vs `41,431`) - **Decoration bakes / Issue #150:** **`0` mismatches** (`other_bytes=0, showed_another_view=0, failed=0` vs `5` and `2` on baseline) - **Residency stalls:** `mapped_rate` **`1.63 ms/s`** vs `6.9 ms/s` (**-76%**, max `12.9` vs `51.9 ms`) - **Visual check:** Clean open-world safehouse frames (`frame-5975.png`, `frame-5983.png`), `edge_energy=4.69` vs `3.88`, `near_black=0.02%`, `magenta=0.0%` (and `#141` `2bf6800` showed zero visual artifacts).
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/Androtim--MiniVI!159
No description provided.