fix(gpu): admit first uploads for on-demand tiles, map coarse mips first, and count tiled sweep bytes #2986

Closed
Luca121 wants to merge 1 commit from upstream-pr/2986 into main
Luca121 commented 2026-11-29 19:13:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Luca121 on 2026-11-29T19:13:21Z.


Summary

When VICTORY_LEVELS_ON_DEMAND=1 is active and VRAM crosses the normal texture room line (resource::room_line), three bugs in tiles.rs and resource.rs prevented newly created reserved textures from receiving any tiles, caused fine-to-coarse allocation failure to leave first_shown() == None, and caused bounded idle sweeps to count 0 reclaimed bytes for tiled textures:

  1. First-upload admission skipped by OnDemand::uploaded():

    • draw.rs admits a new texture's first upload past the normal room line via resource::room_for_first_upload(video, reserve) (up to first_upload_cap, 95% of budget) so visible geometry does not draw untextured/neutral slabs.
    • However, at submission time OnDemand::uploaded() only checked room(video) (the strict room_line) and never consulted room_for_first_upload. As a result, every on-demand texture admitted over the room line was created (CreateReservedResource) and queued for upload, only for OnDemand::uploaded() to pass room = false (0 tiles mapped → first_shown() == None → neutral placeholder shown indefinitely).
    • Fix: Added Tiled::missing_bytes(held) to compute the exact unallocated tile byte footprint for the requested held levels, and updated OnDemand::uploaded() to allow tile mapping when room(video) || (reserve > 0 && room_for_first_upload(video, reserve)).
  2. Fine-to-coarse mip allocation order in Tiled::give_locked():

    • give_locked() previously pushed 0..first_packed (mip 0 first) and the packed mip tail last. If the card could not satisfy the largest mip (level 0), allocation could fail before the small packed tail and coarser mips received tiles, leaving first_shown() == None instead of falling back to a coarser valid mip.
    • Fix: Push the packed tail first, then iterate (0..first_packed).rev() (coarsest standard mip to finest mip 0) so first_shown() always has a valid coarser mip if a full card cannot allocate level 0.
  3. Bounded sweep & eviction byte accounting (host.bytes == 0 for tiled textures):

    • HostTexture::new_tiled sets host.bytes = 0 because tiles are tracked in tiles::STATS[2].
    • However, let_go_idle() (both streamed-out and bounded bytes >= most sweeps), slot_evict(), copy_state(), census(), and unmapped_holders() all added host.bytes (0) instead of the texture's actual mapped tile footprint (tiled.given_bytes()). During a bounded VRAM sweep (most != u64::MAX), evicting tiled textures never advanced bytes toward most, causing bounded sweeps to over-evict and under-report reclaimed VRAM in KINDS[3], STREAMED_OUT[1], HOST_PRESSURE[1], and SLOT_EVICT[1].
    • Fix: Added HostTexture::occupied_bytes() (self.tiled.as_ref().map_or(self.bytes, Tiled::given_bytes)) and used it across let_go_idle, slot_evict, copy_state, census, and unmapped_holders.

Hardware Telemetry (RTX 4070 Ti 12 GB, 32 GB RAM, VICTORY_LEVELS_ON_DEMAND=1)

Metric Before (aae5ac50) After (04804ef6 / this PR) Delta
uploads left a held level without memory (tiles::STATS[9]) 32,349 0 -100% (32,349 → 0)
Neutral placeholder slot shows while waiting 264,666 71,731 (avg 1.29 frames) -72.9%
Moved slots showing wrong bytes as neutral 0 0 0
Tile memory given / unallocated savings 335 MB given / 2,822 MB saved 546 MB given (5,380 levels) / 2,722 MB saved All visible mips populated
VRAM peak / budget 10,089 / 11,228 MB 10,199 / 11,025 MB 0 OOMs / 0 errors

Testing

  • Added unit test tiles::tests::missing_bytes_counts_only_unallocated_requested_levels.
  • cargo test --locked -p victory-gpu --lib passes (missing_bytes_counts_only_unallocated_requested_levels, card_wrote_failure_does_not_poison_card_mask, show_from_preserves_resource_min_lod_for_2d_and_2d_array, first_upload_decision_lets_settled_targets_stop_vetoing_faces, copies_stop_at_the_texture_line, room_line_follows_the_budget).
  • Verified in live open-world gameplay on RTX 4070 Ti (12 GB VRAM).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5554141873 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2986). Originally posted by [Luca121](https://github.com/Luca121) on 2026-11-29T19:13:21Z. --- ## Summary When `VICTORY_LEVELS_ON_DEMAND=1` is active and VRAM crosses the normal texture room line (`resource::room_line`), three bugs in `tiles.rs` and `resource.rs` prevented newly created reserved textures from receiving any tiles, caused fine-to-coarse allocation failure to leave `first_shown() == None`, and caused bounded idle sweeps to count `0` reclaimed bytes for tiled textures: 1. **First-upload admission skipped by `OnDemand::uploaded()`:** - `draw.rs` admits a new texture's first upload past the normal room line via `resource::room_for_first_upload(video, reserve)` (up to `first_upload_cap`, 95% of budget) so visible geometry does not draw untextured/neutral slabs. - However, at submission time `OnDemand::uploaded()` only checked `room(video)` (the strict `room_line`) and never consulted `room_for_first_upload`. As a result, every on-demand texture admitted over the room line was created (`CreateReservedResource`) and queued for upload, only for `OnDemand::uploaded()` to pass `room = false` (`0` tiles mapped → `first_shown() == None` → neutral placeholder shown indefinitely). - **Fix:** Added `Tiled::missing_bytes(held)` to compute the exact unallocated tile byte footprint for the requested `held` levels, and updated `OnDemand::uploaded()` to allow tile mapping when `room(video) || (reserve > 0 && room_for_first_upload(video, reserve))`. 2. **Fine-to-coarse mip allocation order in `Tiled::give_locked()`:** - `give_locked()` previously pushed `0..first_packed` (mip 0 first) and the packed mip tail last. If the card could not satisfy the largest mip (level 0), allocation could fail before the small packed tail and coarser mips received tiles, leaving `first_shown() == None` instead of falling back to a coarser valid mip. - **Fix:** Push the packed tail first, then iterate `(0..first_packed).rev()` (coarsest standard mip to finest mip 0) so `first_shown()` always has a valid coarser mip if a full card cannot allocate level 0. 3. **Bounded sweep & eviction byte accounting (`host.bytes == 0` for tiled textures):** - `HostTexture::new_tiled` sets `host.bytes = 0` because tiles are tracked in `tiles::STATS[2]`. - However, `let_go_idle()` (both streamed-out and bounded `bytes >= most` sweeps), `slot_evict()`, `copy_state()`, `census()`, and `unmapped_holders()` all added `host.bytes` (`0`) instead of the texture's actual mapped tile footprint (`tiled.given_bytes()`). During a bounded VRAM sweep (`most != u64::MAX`), evicting tiled textures never advanced `bytes` toward `most`, causing bounded sweeps to over-evict and under-report reclaimed VRAM in `KINDS[3]`, `STREAMED_OUT[1]`, `HOST_PRESSURE[1]`, and `SLOT_EVICT[1]`. - **Fix:** Added `HostTexture::occupied_bytes()` (`self.tiled.as_ref().map_or(self.bytes, Tiled::given_bytes)`) and used it across `let_go_idle`, `slot_evict`, `copy_state`, `census`, and `unmapped_holders`. --- ## Hardware Telemetry (RTX 4070 Ti 12 GB, 32 GB RAM, `VICTORY_LEVELS_ON_DEMAND=1`) | Metric | Before (`aae5ac50`) | After (`04804ef6` / this PR) | Delta | |---|---:|---:|---:| | **`uploads left a held level without memory` (`tiles::STATS[9]`)** | **32,349** | **0** | **-100% (32,349 → 0)** | | **Neutral placeholder slot shows while waiting** | **264,666** | **71,731** (avg 1.29 frames) | **-72.9%** | | **Moved slots showing wrong bytes as neutral** | 0 | **0** | 0 | | **Tile memory given / unallocated savings** | 335 MB given / 2,822 MB saved | **546 MB given (5,380 levels) / 2,722 MB saved** | All visible mips populated | | **VRAM peak / budget** | 10,089 / 11,228 MB | **10,199 / 11,025 MB** | 0 OOMs / 0 errors | --- ## Testing - Added unit test `tiles::tests::missing_bytes_counts_only_unallocated_requested_levels`. - `cargo test --locked -p victory-gpu --lib` passes (`missing_bytes_counts_only_unallocated_requested_levels`, `card_wrote_failure_does_not_poison_card_mask`, `show_from_preserves_resource_min_lod_for_2d_and_2d_array`, `first_upload_decision_lets_settled_targets_stop_vetoing_faces`, `copies_stop_at_the_texture_line`, `room_line_follows_the_budget`). - Verified in live open-world gameplay on RTX 4070 Ti (12 GB VRAM).
Luca121 commented 2026-11-30 20:11:50 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Luca121 on 2026-11-30T20:11:50Z.


Closing to keep the PR queue clean — part of this already landed on main and the rest is stale/conflicting.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7290551843 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2986#issuecomment-7290551843). Originally posted by [Luca121](https://github.com/Luca121) on 2026-11-30T20:11:50Z. --- Closing to keep the PR queue clean — part of this already landed on main and the rest is stale/conflicting.

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!2986
No description provided.