GPU/texture: preserve Tiled::held and update judged when on-demand detile() is skipped #765

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

@⁠AscilCH on GitHub · 2026-11-25 06:44 UTC · original
AscilCH:fix/gpu-texture-on-demand-skipped-detile-and-judged → main · +129 −4 · 1 files · 1 commits · open

Problem

Two levels-on-demand staging bugs in crates/victory-gpu/src/texture.rs:

  1. Skipped detile() wipes Tiled::held: Fresh Staging initialized detiled = 0, and upload() unconditionally queued on_demand.uploaded(staging.detiled.load(Relaxed), ...) after Step::Texture. When Staging::refresh skipped detile() — because refresh_unlocked() failed during a remapping under VICTORY_TEXTURE_NO_WAIT=1, or because a partly-mapped texture read all zeros — on_demand.uploaded(0, ...) wiped Tiled::held and reset first_shown to None, turning a previously valid tiled texture permanently black. In addition, a failed refresh_unlocked() left dirty = false after the prior deferred host closure cleared it, preventing the next draw from retrying.
  2. Infinite every-frame upload storm on all-zero partly-mapped textures: When refresh_timed() skipped detile() on an all-zero partly-mapped tiled texture, staging.judged remained [0, 0]. Because judgement() always returns limit >= HEAD or u64::MAX, judgement() != judged() evaluated true on every subsequent upload(), calling staging.forget() (wiping last.partial and last.hash) and setting dirty = true on every submission.

Fix

  • Add has_detiled: AtomicBool + Staging::detiled_levels() -> Option<u32> so upload()'s deferred host callback only calls on_demand.uploaded() after detile() has actually produced a held-level mask.
  • Set self.dirty.store(true, Relaxed) when refresh_unlocked() fails so the next draw retries.
  • Record self.judged when refresh_timed() completes the all-zero check on an on_demand texture so judgement() != judged() fires only when first_viewed or next_start changes.

Verification

  • cargo test -p victory-gpu --locked -- texture::title_memory_tests: 3 passed; 0 failed (including new test on_demand_skipped_detile_preserves_none_and_updates_judged).
  • cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 warnings in texture.rs (only pre-existing 8dd30ab warnings in draw.rs:2377 and indirect.rs:1322).
  • cargo xtask policy: 171 files ok.

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

**@⁠AscilCH** on GitHub · 2026-11-25 06:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/765) `AscilCH:fix/gpu-texture-on-demand-skipped-detile-and-judged` → `main` · +129 −4 · 1 files · 1 commits · open ### Problem Two levels-on-demand staging bugs in `crates/victory-gpu/src/texture.rs`: 1. **Skipped `detile()` wipes `Tiled::held`**: Fresh `Staging` initialized `detiled = 0`, and `upload()` unconditionally queued `on_demand.uploaded(staging.detiled.load(Relaxed), ...)` after `Step::Texture`. When `Staging::refresh` skipped `detile()` — because `refresh_unlocked()` failed during a remapping under `VICTORY_TEXTURE_NO_WAIT=1`, or because a partly-mapped texture read all zeros — `on_demand.uploaded(0, ...)` wiped `Tiled::held` and reset `first_shown` to `None`, turning a previously valid tiled texture permanently black. In addition, a failed `refresh_unlocked()` left `dirty = false` after the prior deferred host closure cleared it, preventing the next draw from retrying. 2. **Infinite every-frame upload storm on all-zero partly-mapped textures**: When `refresh_timed()` skipped `detile()` on an all-zero partly-mapped tiled texture, `staging.judged` remained `[0, 0]`. Because `judgement()` always returns `limit >= HEAD` or `u64::MAX`, `judgement() != judged()` evaluated true on every subsequent `upload()`, calling `staging.forget()` (wiping `last.partial` and `last.hash`) and setting `dirty = true` on every submission. ### Fix - Add `has_detiled: AtomicBool` + `Staging::detiled_levels() -> Option<u32>` so `upload()`'s deferred host callback only calls `on_demand.uploaded()` after `detile()` has actually produced a held-level mask. - Set `self.dirty.store(true, Relaxed)` when `refresh_unlocked()` fails so the next draw retries. - Record `self.judged` when `refresh_timed()` completes the all-zero check on an `on_demand` texture so `judgement() != judged()` fires only when `first_viewed` or `next_start` changes. ### Verification - `cargo test -p victory-gpu --locked -- texture::title_memory_tests`: `3 passed; 0 failed` (including new test `on_demand_skipped_detile_preserves_none_and_updates_judged`). - `cargo clippy -p victory-gpu --all-targets --all-features --locked`: 0 warnings in `texture.rs` (only pre-existing `8dd30ab` warnings in `draw.rs:2377` and `indirect.rs:1322`). - `cargo xtask policy`: `171 files ok`. *(AI-assisted; synthetic unit tests only, no game data.)*
Two levels-on-demand bugs in crates/victory-gpu/src/texture.rs (`Staging`):

1. Fresh `Staging` initialized `detiled = 0`, and `upload()` unconditionally
   queued `on_demand.uploaded(staging.detiled.load(Relaxed), ...)` after
   `Step::Texture`. When `Staging::refresh` skipped `detile()` (either
   because `refresh_unlocked()` failed during a remapping under
   `VICTORY_TEXTURE_NO_WAIT=1`, or because a partly-mapped texture read all
   zeros), `staging.detiled` remained `0` and `on_demand.uploaded(0, ...)`
   wiped `Tiled::held` and reset `first_shown` to `None`, turning a
   previously valid tiled texture permanently black. Track whether `detile()`
   has actually run (`has_detiled: AtomicBool`), skip calling
   `on_demand.uploaded()` when it has not, and mark `dirty = true` when
   `refresh_unlocked()` fails so the next draw retries.

2. On a partly-mapped all-zero tiled texture, `refresh_timed()` returned
   early before `detile()`, leaving `staging.judged == [0, 0]`. Because
   `judgement()` always returns `limit >= HEAD` or `u64::MAX`,
   `judgement() != judged()` evaluated true on every subsequent `upload()`,
   calling `staging.forget()` (wiping `last.partial` and `last.hash`) and
   setting `dirty = true` on every submission — causing an infinite
   every-frame full-texture read/hash/upload storm. Record `self.judged` when
   the all-zero check completes so `judgement() != judged()` fires only when
   `first_viewed` or `next_start` actually changes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:37 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/765/head:github-bot/gh-765'
git switch 'github-bot/gh-765'

Merge

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