Skip to content

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

Open
AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-heap-textures-full-card-starvation-and-mip-reupload
Open

AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-heap-textures-full-card-starvation-and-mip-reupload

Conversation

@AscilCH

@AscilCH AscilCH commented Nov 25, 2026

Copy link
Copy Markdown

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

…ip-stream reuploads

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`.
@cafeoh

cafeoh commented Nov 25, 2026

Copy link
Copy Markdown

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.

zhaibingye added a commit to zhaibingye/VIctory that referenced this pull request Nov 25, 2026
Adapt the low-VRAM scheduling goal of fxceless/victory-fork#676 to our
on-demand placed resources. Existing backing stays available, genuine
D3D12 OOM temporarily pauses new textures, and a refused placement or
its null descriptor can retry after the bounded wait.

Co-authored-by: ryotdev <360374475+ryotdev@users.noreply.github.com>
triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
…to shared memory past the card's share

From fxfork fxceless#601 (DiogoPCastelos) as PalmVIDev fxceless#185 took it: once the card's
share is reached, host copies of textures picked by index may go on into
the PC memory the system shares with the card, up to half of its budget;
the reserve for card copies counts as used in both rules. On a 6 GB card the
share was reached in the world's first frames and skin, walls and clothes
sampled black; with the spill the same shots had their colours. On by
default, as shipped there; VICTORY_TEXTURE_SPILL=0 turns it off.

This tree has no render-target room (PalmVIDev fxceless#170's targets_room_kept),
so the reserve here is shadow::card_reserve alone.

Not taken from fxceless#185: the full-card texture queue starvation fix and mip
stream reuse (fxfork fxceless#676, 256 lines in descriptor/host.rs and draw.rs,
over the size limit; draw.rs is the fps thread's).

Co-authored-by: DiogoPCastelos <100236600+DiogoPCastelos@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants