GPU: dynamic descriptor slots go back only to the heap that took them #3611

Open
Ingenioeren wants to merge 1 commit from upstream-pr/3611 into main
Ingenioeren commented 2026-11-27 21:03:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-27T21:03:16Z.


What

Give each host descriptor heap a monotonic identity (NEXT_ID). Record it with every dynamic range held by State, and return slots only when the receiving host heap has that identity. Update root views, unordered-access clears, fresh tables, and releases through the runtime's own view heap.

Add draw::tests::old_state_reset_does_not_free_a_replacement_heaps_dynamic_slots. It holds a slot from heap A in an old State, unregisters and destroys A, installs heap B at exactly the same title-heap address, and gives B's same slot to a new State. Resetting the old State must leave B's slot occupied; resetting B's State must return it. The test uses the existing host-device and descriptor-heap helpers, with deterministic address reuse.

Why

An address identifies a location, but a new heap can occupy that location after the old one is destroyed. A stale State previously freed the replacement heap's live slots on reset/drop, allowing two live lists to share dynamic slots and overwrite one another's descriptors.

Ported from fxceless/victory-fork@52ac4ec (cccw), fork PR #1324. Source: GPL-3.0-or-later fork commit 52ac4ec0f8a03f103c146e60228e53612759d435, fork PR #1324. Adapted to current main with a State-level address-reuse regression.

How tested

All commands ran locally on Windows 11 with an AMD Radeon RX 6750 XT (RDNA2, native AMD D3D12 driver), without game files.

  • Before applying the fix, added the regression to unchanged origin/main code at 63bcca4 and ran cargo test --locked --offline -p victory-gpu: 231 passed, 1 failed, 1 ignored. The new regression was the only failure: after the old State reset, allocation returned Some(4) instead of None, proving that B's occupied slot had been freed. No pre-existing test failures were observed.
  • After applying the fix, cargo test --locked --offline -p victory-gpu: 232 passed, 0 failed, 1 ignored; doc tests: 0 passed, 0 failed. The same regression passed. The existing ignored test is the synthetic private-data release benchmark.
  • cargo clippy --locked --offline -p victory-gpu --all-targets -- -D warnings: passed.
  • cargo fmt --check: failed on pre-existing formatting differences. Repeated the same command in an untouched archive of 63bcca4: both runs report 925 formatting hunks across 66 files. The formatting changes requested are identical; one hunk's surrounding context reflects the updated release signature. No new formatting failures were introduced, and no formatting checks were disabled.
  • Staged the three changed Rust files with git add -- crates/victory-gpu/src/descriptor.rs crates/victory-gpu/src/descriptor/host.rs crates/victory-gpu/src/draw.rs, then ran cargo run --locked --offline -p xtask -- policy --staged: passed, asset policy: 3 files ok.
  • git diff --check: passed.

Not tested

No game run or game files were used. In-game reachability and rendering behavior were not tested. The D3D12 host-backed regression ran and failed before the fix, then passed after it; it did not take the no-device early return.

Fixes #3606

AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5533064881 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3611). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-27T21:03:16Z. --- ## What Give each host descriptor heap a monotonic identity (`NEXT_ID`). Record it with every dynamic range held by `State`, and return slots only when the receiving host heap has that identity. Update root views, unordered-access clears, fresh tables, and releases through the runtime's own view heap. Add `draw::tests::old_state_reset_does_not_free_a_replacement_heaps_dynamic_slots`. It holds a slot from heap A in an old State, unregisters and destroys A, installs heap B at exactly the same title-heap address, and gives B's same slot to a new State. Resetting the old State must leave B's slot occupied; resetting B's State must return it. The test uses the existing host-device and descriptor-heap helpers, with deterministic address reuse. ## Why An address identifies a location, but a new heap can occupy that location after the old one is destroyed. A stale State previously freed the replacement heap's live slots on reset/drop, allowing two live lists to share dynamic slots and overwrite one another's descriptors. Ported from fxceless/victory-fork@52ac4ec (cccw), fork PR #1324. Source: [GPL-3.0-or-later fork commit 52ac4ec0f8a03f103c146e60228e53612759d435](https://github.com/fxceless/victory-fork/commit/52ac4ec0f8a03f103c146e60228e53612759d435), [fork PR #1324](https://github.com/fxceless/victory-fork/pull/1324). Adapted to current main with a State-level address-reuse regression. ## How tested All commands ran locally on Windows 11 with an AMD Radeon RX 6750 XT (RDNA2, native AMD D3D12 driver), without game files. - Before applying the fix, added the regression to unchanged `origin/main` code at `63bcca4` and ran `cargo test --locked --offline -p victory-gpu`: **231 passed, 1 failed, 1 ignored**. The new regression was the only failure: after the old State reset, allocation returned `Some(4)` instead of `None`, proving that B's occupied slot had been freed. No pre-existing test failures were observed. - After applying the fix, `cargo test --locked --offline -p victory-gpu`: **232 passed, 0 failed, 1 ignored**; doc tests: **0 passed, 0 failed**. The same regression passed. The existing ignored test is the synthetic private-data release benchmark. - `cargo clippy --locked --offline -p victory-gpu --all-targets -- -D warnings`: **passed**. - `cargo fmt --check`: **failed on pre-existing formatting differences**. Repeated the same command in an untouched archive of `63bcca4`: both runs report **925 formatting hunks across 66 files**. The formatting changes requested are identical; one hunk's surrounding context reflects the updated release signature. No new formatting failures were introduced, and no formatting checks were disabled. - Staged the three changed Rust files with `git add -- crates/victory-gpu/src/descriptor.rs crates/victory-gpu/src/descriptor/host.rs crates/victory-gpu/src/draw.rs`, then ran `cargo run --locked --offline -p xtask -- policy --staged`: **passed**, `asset policy: 3 files ok`. - `git diff --check`: **passed**. ## Not tested No game run or game files were used. In-game reachability and rendering behavior were not tested. The D3D12 host-backed regression ran and failed before the fix, then passed after it; it did not take the no-device early return. Fixes #3606 AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
oni-swr commented 2026-11-27 22:03:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T22:03:45Z.


Independent verification of 26b63a03eacf1e4921daeb071a8e5f7119fb6cd1 against main at 63bcca43c6a00a758510398fa43096ce7e4f7df0. Clean merge. Native Windows x64, D3D12 WARP only, with both WARP switches set, SDK dxil.dll, and victory-gpu diagnostics enabled. Tests (passed / failed / ignored) were 246 / 0 / 1 on base and 247 / 0 / 1 on head. The backported regression freed the replacement heap’s occupied slot on base and passed on head. Clippy passed with all targets, all features, and -D warnings. Command-list releases check the allocating heap’s identity, and page-table pairs return to their owning heap. Review found no slot leaks or blocking defects.

AI-assisted (Codex, gpt-6.2-sol).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7228993627 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3611#issuecomment-7228993627). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-27T22:03:45Z. --- Independent verification of `26b63a03eacf1e4921daeb071a8e5f7119fb6cd1` against `main` at `63bcca43c6a00a758510398fa43096ce7e4f7df0`. Clean merge. Native Windows x64, D3D12 WARP only, with both WARP switches set, SDK `dxil.dll`, and `victory-gpu` diagnostics enabled. Tests (passed / failed / ignored) were **246 / 0 / 1** on base and **247 / 0 / 1** on head. The backported regression freed the replacement heap’s occupied slot on base and passed on head. Clippy passed with all targets, all features, and `-D warnings`. Command-list releases check the allocating heap’s identity, and page-table pairs return to their owning heap. Review found no slot leaks or blocking defects. AI-assisted (Codex, gpt-6.2-sol).
ColorMeBoom commented 2026-11-28 00:24:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T00:24:30Z.


Hardware run on RDNA1, to go with the RX 6750 XT run in the description: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head 26b63a0 on 63bcca4.

  • draw::tests::old_state_reset_does_not_free_a_replacement_heaps_dynamic_slots passes.
  • Full victory-gpu --lib: 232 passed, 0 failed, 1 ignored (main: 231 passed, 0 failed, 1 ignored).

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7230888138 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3611#issuecomment-7230888138). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T00:24:30Z. --- Hardware run on RDNA1, to go with the RX 6750 XT run in the description: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head `26b63a0` on `63bcca4`. - `draw::tests::old_state_reset_does_not_free_a_replacement_heaps_dynamic_slots` passes. - Full `victory-gpu --lib`: 232 passed, 0 failed, 1 ignored (`main`: 231 passed, 0 failed, 1 ignored). AI use: Claude Code (Claude Opus 5.5).
akimfomin commented 2026-11-28 01:25:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by akimfomin on 2026-11-28T01:25:20Z.


XCL #1899 covers another ownership boundary: a fresh D3D12 queue can occupy a raw pointer that held an older queue. Your monotonic heap ID fixes the analogous reuse condition at a different layer. A negative test worth adding is a stale range from retired heap A with the same index/count as a live range in heap B, followed by a real return from B. Assert B's free count changes only on the second return.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7231654449 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3611#issuecomment-7231654449). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-28T01:25:20Z. --- [XCL #1899](https://github.com/xcl-dev/xcl/pull/1899) covers another ownership boundary: a fresh D3D12 queue can occupy a raw pointer that held an older queue. Your monotonic heap ID fixes the analogous reuse condition at a different layer. A negative test worth adding is a stale range from retired heap A with the same index/count as a live range in heap B, followed by a real return from B. Assert B's free count changes only on the second return.
ColorMeBoom commented 2026-11-28 01:29:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T01:29:32Z.


@akimfomin The PR's test already covers that negative case. In old_state_reset_does_not_free_a_replacement_heaps_dynamic_slots, the old State holds heap A's range (first, 1). After A is destroyed and B takes the same address, B allocates the same (first, 1) into a new State, then every other slot is filled. The stale old.reset must then leave B's allocator full (dynamic(1) == None). Only new.reset, the real return from B, frees it (dynamic(1) == Some(first)). It measures this through allocation rather than a free count, and the effect is the same.

It passes on an RX 5700 XT along with the rest of victory-gpu (232 passed, 0 failed, run).

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7231702822 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3611#issuecomment-7231702822). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T01:29:32Z. --- @akimfomin The PR's test already covers that negative case. In `old_state_reset_does_not_free_a_replacement_heaps_dynamic_slots`, the old State holds heap A's range `(first, 1)`. After A is destroyed and B takes the same address, B allocates the same `(first, 1)` into a new State, then every other slot is filled. The stale `old.reset` must then leave B's allocator full (`dynamic(1) == None`). Only `new.reset`, the real return from B, frees it (`dynamic(1) == Some(first)`). It measures this through allocation rather than a free count, and the effect is the same. It passes on an RX 5700 XT along with the rest of `victory-gpu` (232 passed, 0 failed, [run](https://github.com/Marvisak/VIctory/pull/3611#issuecomment-7230888138)). AI use: Claude Code (Claude Opus 5.5).
Ingenioeren commented 2026-11-28 09:21:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-28T09:21:56Z.


Thanks. old_state_reset_does_not_free_a_replacement_heaps_dynamic_slots in draw.rs is that negative test: the stale list from heap A and the live list from heap B hold the same address, index and count. Resetting the stale one must leave B's slot taken (dynamic(1) == None with B full), and only B's own reset gives it back (dynamic(1) == Some(first)).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7237191313 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3611#issuecomment-7237191313). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-28T09:21:56Z. --- Thanks. `old_state_reset_does_not_free_a_replacement_heaps_dynamic_slots` in `draw.rs` is that negative test: the stale list from heap A and the live list from heap B hold the same address, index and count. Resetting the stale one must leave B's slot taken (`dynamic(1) == None` with B full), and only B's own reset gives it back (`dynamic(1) == Some(first)`).
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/3611:upstream-pr/3611'
git switch 'upstream-pr/3611'

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