GPU/tiles: fix failed card_wrote poisoning, 2D-array/MinLOD SRV clamping, and make/floor overflow #747

Open
AscilCH wants to merge 1 commit from upstream-pr/747 into main
AscilCH commented 2026-11-25 06:09:47 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T06:09:47Z.


Summary

Fixes four bugs in the levels-on-demand tiled texture manager (crates/victory-gpu/src/tiles.rs):

  1. Failed card_wrote_on tile allocation poisoning self.card (Tiled::card_wrote_on, Tiled::uploaded_on):
    • card_wrote_on() previously called self.card.fetch_or(levels) before give_on(), and only cleared self.claimed (unclaim) when without != 0. If heap/tile allocation failed, the unbacked level stayed permanently set in self.card, causing later uploaded_on(..., room = false) calls to bypass the full-card budget (may = card), back an unheld level whose staging data is zeros, and expose that black mip via first_shown().
    • uploaded_on() and card_wrote_on() now mask levels/held to self.every_level(), perform the mapping and state updates under the self.given lock (give_locked/without_locked), and only set bits in self.card for levels that actually have tiles.
  2. 2D-array SRVs, MipLevels bounds, and ResourceMinLODClamp in show_from():
    • show_from() previously ignored D3D12_SRV_DIMENSION_TEXTURE2DARRAY (allowing 1-layer 2D array SRVs to sample unmapped mip 0), did not clamp reduced MipLevels to levels - first, and left ResourceMinLODClamp unadjusted after raising MostDetailedMip (double-clamping the effective minimum LOD by an extra first - MostDetailedMip).
    • show_from() now handles both TEXTURE2D and TEXTURE2DARRAY, clamps finite MipLevels into 1..=(levels - first), and reduces positive ResourceMinLODClamp by fewer as f32 (clamped at 0.0).
  3. Tiled::make() overflow & zero packed-tile guard:
    • Uses checked multiplication for WidthInTiles * HeightInTiles * DepthInTiles and rejects NumPackedMips > 0 when NumTilesForPackedMips == 0 (which would otherwise leave packed mips permanently unbackable).
  4. VICTORY_LEVELS_MIN_KB overflow (floor()):
    • Uses kb.max(64).saturating_mul(1024) instead of kb.max(64) << 10, preventing huge values from wrapping to 0.

Verification

  • cargo test -p victory-gpu --locked tiles::tests — 3 passed, 0 failed, 1 ignored (new floor_saturates_instead_of_wrapping, show_from_clamps_2d_and_2d_array_and_adjusts_min_lod, card_wrote_failure_does_not_poison_card_mask)
  • cargo test -p victory-gpu --locked -- --ignored levels_on_demand_on_the_card --nocapture — 1 passed, 0 failed on WARP software adapter (tiled resources tier 3, Graphics Tools debug layer not installed on host)
  • cargo clippy -p victory-gpu --all-targets --all-features --locked — 0 warnings in tiles.rs (only pre-existing upstream warnings in untouched files draw.rs and indirect.rs)
  • cargo xtask policy — asset policy: 171 files ok

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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6598394317 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/747). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T06:09:47Z. --- ## Summary Fixes four bugs in the levels-on-demand tiled texture manager (`crates/victory-gpu/src/tiles.rs`): 1. **Failed `card_wrote_on` tile allocation poisoning `self.card` (`Tiled::card_wrote_on`, `Tiled::uploaded_on`)**: - `card_wrote_on()` previously called `self.card.fetch_or(levels)` *before* `give_on()`, and only cleared `self.claimed` (`unclaim`) when `without != 0`. If heap/tile allocation failed, the unbacked level stayed permanently set in `self.card`, causing later `uploaded_on(..., room = false)` calls to bypass the full-card budget (`may = card`), back an unheld level whose staging data is zeros, and expose that black mip via `first_shown()`. - `uploaded_on()` and `card_wrote_on()` now mask `levels`/`held` to `self.every_level()`, perform the mapping and state updates under the `self.given` lock (`give_locked`/`without_locked`), and only set bits in `self.card` for levels that actually have tiles. 2. **2D-array SRVs, `MipLevels` bounds, and `ResourceMinLODClamp` in `show_from()`**: - `show_from()` previously ignored `D3D12_SRV_DIMENSION_TEXTURE2DARRAY` (allowing 1-layer 2D array SRVs to sample unmapped mip 0), did not clamp reduced `MipLevels` to `levels - first`, and left `ResourceMinLODClamp` unadjusted after raising `MostDetailedMip` (double-clamping the effective minimum LOD by an extra `first - MostDetailedMip`). - `show_from()` now handles both `TEXTURE2D` and `TEXTURE2DARRAY`, clamps finite `MipLevels` into `1..=(levels - first)`, and reduces positive `ResourceMinLODClamp` by `fewer as f32` (clamped at `0.0`). 3. **`Tiled::make()` overflow & zero packed-tile guard**: - Uses checked multiplication for `WidthInTiles * HeightInTiles * DepthInTiles` and rejects `NumPackedMips > 0` when `NumTilesForPackedMips == 0` (which would otherwise leave packed mips permanently unbackable). 4. **`VICTORY_LEVELS_MIN_KB` overflow (`floor()`)**: - Uses `kb.max(64).saturating_mul(1024)` instead of `kb.max(64) << 10`, preventing huge values from wrapping to 0. ## Verification - `cargo test -p victory-gpu --locked tiles::tests` — `3 passed, 0 failed, 1 ignored` (new `floor_saturates_instead_of_wrapping`, `show_from_clamps_2d_and_2d_array_and_adjusts_min_lod`, `card_wrote_failure_does_not_poison_card_mask`) - `cargo test -p victory-gpu --locked -- --ignored levels_on_demand_on_the_card --nocapture` — `1 passed, 0 failed` on WARP software adapter (`tiled resources tier 3`, Graphics Tools debug layer not installed on host) - `cargo clippy -p victory-gpu --all-targets --all-features --locked` — 0 warnings in `tiles.rs` (only pre-existing upstream warnings in untouched files `draw.rs` and `indirect.rs`) - `cargo xtask policy` — `asset policy: 171 files ok` *(AI-assisted; synthetic unit tests only, no game data.)*
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/747:upstream-pr/747'
git switch 'upstream-pr/747'

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