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

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

@⁠AscilCH on GitHub · 2026-11-25 06:09 UTC · original
AscilCH:fix/gpu-tiles-card-wrote-failure-and-srv-clamping → main · +200 −32 · 1 files · 1 commits · open

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

**@⁠AscilCH** on GitHub · 2026-11-25 06:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/747) `AscilCH:fix/gpu-tiles-card-wrote-failure-and-srv-clamping` → `main` · +200 −32 · 1 files · 1 commits · open ## 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.)*
- `Tiled::card_wrote_on`: hold `self.given` across mapping and `card`/`claimed` updates, mask `levels` to `self.every_level()`, and only set bits in `self.card` for levels that actually have tiles. Previously `self.card.fetch_or(levels)` ran before `give_on`, so if tile/heap allocation failed the failed level remained permanently marked as card-owned and later `uploaded_on(..., room = false)` calls bypassed the full-card gate to back and expose a zeroed mip.
- `tiles::show_from`: also clamp `D3D12_SRV_DIMENSION_TEXTURE2DARRAY` views (used for 1-layer 2D textures), clamp `MipLevels` to `levels - first`, and subtract the mip shift from `ResourceMinLODClamp` (clamped at 0.0) so shifting `MostDetailedMip` does not double-clamp the effective minimum LOD.
- `Tiled::make`: use checked multiplication for per-mip tile counts and reject `NumPackedMips > 0` with `NumTilesForPackedMips == 0`.
- `tiles::floor`: use `saturating_mul(1024)` instead of unchecked `<< 10` on `VICTORY_LEVELS_MIN_KB`.

Adds synthetic unit tests covering `card_wrote` allocation failure, `show_from` on 2D and 2D-array SRVs with `ResourceMinLODClamp`, and `VICTORY_LEVELS_MIN_KB` saturation.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:11 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/tiles.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/747/head:github-bot/gh-747'
git switch 'github-bot/gh-747'

Merge

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