GPU: a lost host list's heaps are not a wanted pair #3037

Open
kotekompotek wants to merge 1 commit from upstream-pr/3039 into main
kotekompotek commented 2026-11-26 04:54:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:54:29Z.


Summary

Fixes #2881. host_state_lost marked host_heaps [usize::MAX; 2], but a list that binds no heaps and reads title memory wants [MEMORY_HEAP, SAMPLERS_OURS] — the same pair. After a cut (Wait32/64BitValueX, 0–21 per world frame) or an external::record (FidelityFX), bind_heaps found them equal and bound nothing: the next directly-indexing root signature ran with no heaps bound — debug layer id 1419, the device removal on NVIDIA that #1778 was written to prevent (#1754).

host_heaps is now Option<[usize; 2]>: None marks the lost state and equals no pair wanted can make, so the next bind_heaps binds again. This removes the whole sentinel-collision class rather than picking a different one.

Test plan

  • cargo test -p victory-gpu --lib heaps — new a_lost_host_state_matches_no_wanted_heaps fails on the old [usize::MAX; 2] marker for wanted([0,0], true), passes under Option
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings clean (msvc)
  • In-game observation: none — found by code reading (as #2881 reports); a NVIDIA device removal after a cut is the signature this prevents

Generated with Devin

<!-- greyfinch-sync:Marvisak/VIctory:issue:6619801044 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3039). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:54:29Z. --- ## Summary Fixes #2881. `host_state_lost` marked `host_heaps` `[usize::MAX; 2]`, but a list that binds no heaps and reads title memory wants `[MEMORY_HEAP, SAMPLERS_OURS]` — the same pair. After a cut (`Wait32/64BitValueX`, 0–21 per world frame) or an `external::record` (FidelityFX), `bind_heaps` found them equal and bound nothing: the next directly-indexing root signature ran with no heaps bound — debug layer id 1419, the device removal on NVIDIA that #1778 was written to prevent (#1754). `host_heaps` is now `Option<[usize; 2]>`: `None` marks the lost state and equals no pair `wanted` can make, so the next `bind_heaps` binds again. This removes the whole sentinel-collision class rather than picking a different one. #### Test plan - [x] `cargo test -p victory-gpu --lib heaps` — new `a_lost_host_state_matches_no_wanted_heaps` fails on the old `[usize::MAX; 2]` marker for `wanted([0,0], true)`, passes under `Option` - [x] `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` clean (msvc) - [ ] In-game observation: none — found by code reading (as #2881 reports); a NVIDIA device removal after a cut is the signature this prevents Generated with [Devin](https://devin.ai)
fuzeofficlal commented 2026-11-26 05:04:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T04:59:27Z.

Review: APPROVED


Static review of 851b5290 against crates/victory-gpu/src/draw.rs and crates/victory-gpu/src/memory.rs.

Confirmed the root cause on main: crate::memory::OURS is usize::MAX, SAMPLERS_OURS is usize::MAX, so State::wanted([0, 0], true) returns [usize::MAX, usize::MAX], which collided with the [usize::MAX; 2] sentinel written by State::host_state_lost(). After cut() or external::record, bind_heaps treated the lost state as already matching want and skipped SetDescriptorHeaps.

Switching host_heaps to Option<[usize; 2]> is cleaner than introducing another magic sentinel:

  • State::default() initializes host_heaps to None, matching the prior behavior ([0, 0] never matched wanted's non-zero sampler slot either).
  • All four host_heaps sites in draw.rs are updated consistently, host_roots is still cleared whenever SetDescriptorHeaps runs, and the unit test covers all combinations of (views, samplers, memory_heap) after host_state_lost().

Note for maintainers: this addresses the same issue (#2881) as #2882; the Option<[usize; 2]> approach here eliminates sentinel collisions by type.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068775077 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3039#pullrequestreview-6068775077). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T04:59:27Z. **Review:** APPROVED --- Static review of `851b5290` against `crates/victory-gpu/src/draw.rs` and `crates/victory-gpu/src/memory.rs`. Confirmed the root cause on `main`: `crate::memory::OURS` is `usize::MAX`, `SAMPLERS_OURS` is `usize::MAX`, so `State::wanted([0, 0], true)` returns `[usize::MAX, usize::MAX]`, which collided with the `[usize::MAX; 2]` sentinel written by `State::host_state_lost()`. After `cut()` or `external::record`, `bind_heaps` treated the lost state as already matching `want` and skipped `SetDescriptorHeaps`. Switching `host_heaps` to `Option<[usize; 2]>` is cleaner than introducing another magic sentinel: - `State::default()` initializes `host_heaps` to `None`, matching the prior behavior (`[0, 0]` never matched `wanted`'s non-zero sampler slot either). - All four `host_heaps` sites in `draw.rs` are updated consistently, `host_roots` is still cleared whenever `SetDescriptorHeaps` runs, and the unit test covers all combinations of `(views, samplers, memory_heap)` after `host_state_lost()`. Note for maintainers: this addresses the same issue (#2881) as #2882; the `Option<[usize; 2]>` approach here eliminates sentinel collisions by type.
Dukestar69 commented 2026-11-26 07:01:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:32:42Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • Diff review: Changing State::host_heaps to Option<[usize; 2]> with None in host_state_lost() cleanly eliminates the sentinel collision with [MEMORY_HEAP, SAMPLERS_OURS] ([usize::MAX; 2], #2881) so heaps are always rebound after a lost host state.
  • cargo test -p victory-gpu draw::tests -- --test-threads=1 (RTX 5090 & WARP): 21 passed, 0 failed on both (including a_lost_host_state_matches_no_wanted_heaps).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6069536639 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3039#pullrequestreview-6069536639). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:32:42Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - Diff review: Changing `State::host_heaps` to `Option<[usize; 2]>` with `None` in `host_state_lost()` cleanly eliminates the sentinel collision with `[MEMORY_HEAP, SAMPLERS_OURS]` (`[usize::MAX; 2]`, #2881) so heaps are always rebound after a lost host state. - `cargo test -p victory-gpu draw::tests -- --test-threads=1` (RTX 5090 & WARP): 21 passed, 0 failed on both (including `a_lost_host_state_matches_no_wanted_heaps`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Marvisak commented 2026-11-26 07:01:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:14:45Z.


Automated triage for the maintainers.

I confirmed the bug on main. In crates/victory-gpu/src/draw.rs, MEMORY_HEAP (memory::OURS) and SAMPLERS_OURS are both usize::MAX. State::wanted([.., 0], true) therefore returns the same [usize::MAX; 2] that State::host_state_lost uses as its marker, so after a cut bind_heaps binds nothing. This PR makes host_heaps an Option<[usize; 2]> and uses None as the lost state. No wanted pair can equal None, so this kind of sentinel collision can no longer happen. host_heaps is touched only in host_state_lost and bind_heaps. The default None for a new State also forces the first bind, as the old [0, 0] did. The test covers every wanted combination. CI: check passing.

Note for the maintainers: #2882 fixes the same issue, #2881, by moving SAMPLERS_OURS to usize::MAX - 1, and it is also labelled as a merge candidate. Only one of the two should land. This one removes the sentinel instead of picking a different value, so I would prefer it, but that is your call.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184236197 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3039#issuecomment-7184236197). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:14:45Z. --- <!-- victory-triage v1 head=c141c1f4c571d5bf225fc180b9e17bfc73b912d1 verdict=merge-candidate at=2026-11-26T06:21:00Z --> Automated triage for the maintainers. I confirmed the bug on `main`. In `crates/victory-gpu/src/draw.rs`, `MEMORY_HEAP` (`memory::OURS`) and `SAMPLERS_OURS` are both `usize::MAX`. `State::wanted([.., 0], true)` therefore returns the same `[usize::MAX; 2]` that `State::host_state_lost` uses as its marker, so after a cut `bind_heaps` binds nothing. This PR makes `host_heaps` an `Option<[usize; 2]>` and uses `None` as the lost state. No `wanted` pair can equal `None`, so this kind of sentinel collision can no longer happen. `host_heaps` is touched only in `host_state_lost` and `bind_heaps`. The default `None` for a new `State` also forces the first bind, as the old `[0, 0]` did. The test covers every `wanted` combination. CI: `check` passing. Note for the maintainers: #2882 fixes the same issue, #2881, by moving `SAMPLERS_OURS` to `usize::MAX - 1`, and it is also labelled as a merge candidate. Only one of the two should land. This one removes the sentinel instead of picking a different value, so I would prefer it, but that is your call. --- _Generated by [Claude Code](https://claude.ai/code)_
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/3039:upstream-pr/3039'
git switch 'upstream-pr/3039'

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