GPU/draw+descriptor: prevent full-card queue starvation and support mip-stream reuploads #676

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

@⁠AscilCH on GitHub · 2026-11-25 04:20 UTC · original
AscilCH:fix/gpu-heap-textures-full-card-starvation-and-mip-reupload → main · +310 −21 · 2 files · 1 commits · open

Summary

Fixes three bugs in crates/victory-gpu/src/draw.rs and crates/victory-gpu/src/descriptor/host.rs affecting indexed texture streaming when VRAM is full (targeting the reupload_when_full path added in 310c6eb):

  1. Full-card queue starvation behind refused > 256 (descriptor/host.rs, draw.rs):

    • When !room, refused uncreated slots previously remained untouched at the front of again (or ends of fresh) with unchanged due <= frame and write. Once 257 uncreated slots accumulated, every pass hit refused > 256 on the exact same 257 slots and breaked — permanently starving remapped (changed) on-card textures, older recheck slots, middle-of-fresh slots, and streamed-out (mapped == 0) slots needed to reclaim VRAM via texture_slot_gone.
    • Added TextureQueue::due_for(frame, max, room) and TextureQueue::full() (via a separate refused_until field that does not modify due or looks). While !room, already-uploaded (recheck/partly) and fresh/remapped slots are prioritized ahead of unuploaded again slots, and refused slots yield with capped backoff (2..=most frames) so passes advance through the queue. The instant room becomes true, refused_until is ignored so waiting slots are immediately eligible.
  2. reupload_when_full refusing mip-streaming updates and sibling slots (draw.rs):

    • When sharper mips arrive, the title writes a new view record (key_new != key_old); keep_views() intentionally leaves made[index] == key_old, causing texture_slot_made_from(index, handle) to return false even though the underlying ID3D12Resource is already resident on the card (0 bytes of new VRAM needed).
    • Added view_has_live_host_texture() checking resource::placed_known / View::Shader + resource::copy_state == 2 alongside texture_slot_made_from so mip-streaming updates and sibling views of resident textures still refresh when full.
  3. same_placed_texture comparing uninitialized stack garbage (descriptor/host.rs):

    • Zeroed padding words [1] and [13] before comparing resource == other (matching resource::texture_at and resource::placed_known) so differing stack garbage on a view rewrite does not defeat keep_views().

(Orthogonal to open PR #632 — texture_slot_gone is untouched.)

Verification

  • cargo test -p victory-gpu --lib --locked descriptor::host::tests — 15 passed, 0 failed (including extended views_of_one_placed_texture_are_told_by_address_and_description and new full_card_queue_does_not_starve_recheck_remapped_or_later_slots)
  • cargo test -p victory-gpu --lib --locked draw::full_card_tests — 1 passed, 0 failed (mip_stream_view_rewrite_recognizes_existing_live_host_texture)
  • cargo clippy -p victory-gpu --all-targets --all-features --locked — 0 warnings in modified code (only pre-existing 310c6eb warnings in untouched draw.rs:2339 and indirect.rs:1322)
  • cargo xtask policy — asset policy: 169 files ok

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 04:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/676) `AscilCH:fix/gpu-heap-textures-full-card-starvation-and-mip-reupload` → `main` · +310 −21 · 2 files · 1 commits · open ### Summary Fixes three bugs in `crates/victory-gpu/src/draw.rs` and `crates/victory-gpu/src/descriptor/host.rs` affecting indexed texture streaming when VRAM is full (targeting the `reupload_when_full` path added in `310c6eb`): 1. **Full-card queue starvation behind `refused > 256` (`descriptor/host.rs`, `draw.rs`)**: - When `!room`, refused uncreated slots previously remained untouched at the front of `again` (or ends of `fresh`) with unchanged `due <= frame` and `write`. Once 257 uncreated slots accumulated, every pass hit `refused > 256` on the exact same 257 slots and `break`ed — permanently starving remapped (`changed`) on-card textures, older `recheck` slots, middle-of-`fresh` slots, and streamed-out (`mapped == 0`) slots needed to reclaim VRAM via `texture_slot_gone`. - Added `TextureQueue::due_for(frame, max, room)` and `TextureQueue::full()` (via a separate `refused_until` field that does not modify `due` or `looks`). While `!room`, already-uploaded (`recheck`/`partly`) and fresh/remapped slots are prioritized ahead of unuploaded `again` slots, and refused slots yield with capped backoff (`2..=most` frames) so passes advance through the queue. The instant `room` becomes true, `refused_until` is ignored so waiting slots are immediately eligible. 2. **`reupload_when_full` refusing mip-streaming updates and sibling slots (`draw.rs`)**: - When sharper mips arrive, the title writes a new view record (`key_new != key_old`); `keep_views()` intentionally leaves `made[index] == key_old`, causing `texture_slot_made_from(index, handle)` to return `false` even though the underlying `ID3D12Resource` is already resident on the card (0 bytes of new VRAM needed). - Added `view_has_live_host_texture()` checking `resource::placed_known` / `View::Shader` + `resource::copy_state == 2` alongside `texture_slot_made_from` so mip-streaming updates and sibling views of resident textures still refresh when full. 3. **`same_placed_texture` comparing uninitialized stack garbage (`descriptor/host.rs`)**: - Zeroed padding words `[1]` and `[13]` before comparing `resource == other` (matching `resource::texture_at` and `resource::placed_known`) so differing stack garbage on a view rewrite does not defeat `keep_views()`. *(Orthogonal to open PR `#632` — `texture_slot_gone` is untouched.)* ### Verification - `cargo test -p victory-gpu --lib --locked descriptor::host::tests` — **15 passed, 0 failed** (including extended `views_of_one_placed_texture_are_told_by_address_and_description` and new `full_card_queue_does_not_starve_recheck_remapped_or_later_slots`) - `cargo test -p victory-gpu --lib --locked draw::full_card_tests` — **1 passed, 0 failed** (`mip_stream_view_rewrite_recognizes_existing_live_host_texture`) - `cargo clippy -p victory-gpu --all-targets --all-features --locked` — **0 warnings in modified code** (only pre-existing `310c6eb` warnings in untouched `draw.rs:2339` and `indirect.rs:1322`) - `cargo xtask policy` — **asset policy: 169 files ok** *(AI-assisted; synthetic unit tests only, no game data.)*
Three fixes for indexed texture updates when the card is full (targeting
commit 310c6eb's `reupload_when_full` path):

1. `TextureQueue` starvation behind `refused > 256` (`descriptor/host.rs`,
   `draw.rs`):
   When `!room`, refused uncreated slots previously remained untouched in
   `again`/`fresh` with the same `due <= frame` and `write`. Once >256
   uncreated slots accumulated in `again` (or at the ends of `fresh`), every
   pass hit `refused > 256` on the exact same 257 slots and broke out —
   permanently starving remapped (`changed`) slots, older `recheck` slots,
   and streamed-out (`mapped == 0`) slots needed to reclaim VRAM.
   Add `TextureQueue::due_for(frame, max, room)` and `TextureQueue::full()`:
   while `!room`, prioritize already-uploaded (`recheck`/`partly`) slots and
   fresh/remapped slots ahead of unuploaded `again` slots, and record a
   separate `refused_until` backoff on refused slots without altering `due`
   or `looks`. As soon as `room` becomes true, `refused_until` is ignored so
   waiting slots are immediately eligible.

2. `reupload_when_full` rejecting mip-streaming view rewrites (`draw.rs`):
   When a title streams in sharper mips and rewrites a slot with a new
   descriptor record (`key_new != key_old`), `keep_views()` leaves
   `made[index] == key_old`, so `texture_slot_made_from(index, handle)`
   returned false under `!room` even though the texture's `ID3D12Resource`
   is already alive on the card (zero new VRAM needed). Fall back to
   `view_has_live_host_texture` (`placed_known` / `View::Shader` with
   `copy_state == 2`) so mip-streaming updates and sibling views of live
   textures still refresh when full.

3. `same_placed_texture` comparing uninitialized filler words
   (`descriptor/host.rs`):
   Zero struct-padding words `[1]` and `[13]` before comparing resource
   descriptions (matching `resource::texture_at` and `placed_known`) so
   differing title stack garbage does not defeat `keep_views()`.

Extend `views_of_one_placed_texture_are_told_by_address_and_description` and
add `full_card_queue_does_not_starve_recheck_remapped_or_later_slots` and
`draw::full_card_tests::mip_stream_view_rewrite_recognizes_existing_live_host_texture`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:48:46 +00:00
Author
Owner

@⁠cafeoh on GitHub · 2026-11-25 07:14 UTC · original

Tested parts 2 and 3 on an RTX 2080 Ti (11 GB) + Windows 10, in the prologue up to the prison cell scene (character at the window).

Setup: fork main 8dd30ab plus #683, #644, #487, #606, #559, #701, #687. Part 1 did not merge cleanly with main's own full-card hold/room code, so I left it out and applied parts 2 and 3 by hand. The card is full (room=false) a few scenes earlier. Same switches in every run (VICTORY_DEBUG_NULL_VIEWS=1, VICTORY_SKIP_BINK=1).

Run Change Cell scene
A without this PR yard visible through the window, some magenta on the right wall
B part 3 only about the same as A
C, D parts 2 + 3 window shows a wrong texture (pink dot pattern, not debug magenta), much more magenta on the walls, the character nearly black

C and D gave the same picture, so it repeats. With part 2 on, a local counter also showed thousands of first uploads stuck for 32–128 frames, with only 40–190 slots handed out per frame (A/B: thousands per frame).

My guess, not checked: placed_known finds a live host copy by address, but when memory is reused that copy can belong to a different texture than the one the new view describes. Part 2 then lets the slot refresh onto it, so it shows the wrong texture.

Tested: the cell scene, 4 runs. Not tested: part 1, later scenes, the unit tests.

AI use: tested and written with Claude Code.

**@⁠cafeoh** on GitHub · 2026-11-25 07:14 UTC · [original](https://github.com/fxceless/victory-fork/pull/676#issuecomment-7155635920) Tested parts 2 and 3 on an RTX 2080 Ti (11 GB) + Windows 10, in the prologue up to the prison cell scene (character at the window). Setup: fork main `8dd30ab` plus #683, #644, #487, #606, #559, #701, #687. Part 1 did not merge cleanly with main's own full-card hold/room code, so I left it out and applied parts 2 and 3 by hand. The card is full (`room=false`) a few scenes earlier. Same switches in every run (`VICTORY_DEBUG_NULL_VIEWS=1`, `VICTORY_SKIP_BINK=1`). | Run | Change | Cell scene | |---|---|---| | A | without this PR | yard visible through the window, some magenta on the right wall | | B | part 3 only | about the same as A | | C, D | parts 2 + 3 | window shows a wrong texture (pink dot pattern, not debug magenta), much more magenta on the walls, the character nearly black | C and D gave the same picture, so it repeats. With part 2 on, a local counter also showed thousands of first uploads stuck for 32–128 frames, with only 40–190 slots handed out per frame (A/B: thousands per frame). My guess, not checked: `placed_known` finds a live host copy by address, but when memory is reused that copy can belong to a different texture than the one the new view describes. Part 2 then lets the slot refresh onto it, so it shows the wrong texture. Tested: the cell scene, 4 runs. Not tested: part 1, later scenes, the unit tests. AI use: tested and written with Claude Code.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • 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/676/head:github-bot/gh-676'
git switch 'github-bot/gh-676'

Merge

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