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

Open
AscilCH wants to merge 1 commit from upstream-pr/676 into main
AscilCH commented 2026-11-25 04:20:49 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T04:20:49Z.


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.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6597134074 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/676). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T04:20:49Z. --- ### 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.)*
cafeoh commented 2026-11-25 08:08:58 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by cafeoh on 2026-11-25T07:14:08Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7155635920 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/676#issuecomment-7155635920). Originally posted by [cafeoh](https://github.com/cafeoh) on 2026-11-25T07:14:08Z. --- 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 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/676:upstream-pr/676'
git switch 'upstream-pr/676'

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/676'
git switch 'upstream-pr/676'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/676'
git switch 'upstream-pr/676'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/676'
git switch 'main'
git merge --squash 'upstream-pr/676'
git switch 'main'
git merge --ff-only 'upstream-pr/676'
git switch 'main'
git merge 'upstream-pr/676'
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
fxceless/victory-fork!676
No description provided.