GPU: replace stale descriptors on null CBV writes #1298

Open
EatCodeSleep2 wants to merge 1 commit from upstream-pr/1298 into main
EatCodeSleep2 commented 2026-11-24 17:14:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by EatCodeSleep2 on 2026-11-24T17:14:36Z.


Summary

Write a null constant-buffer record when the title passes a null CBV description. This overwrites the previous record and uses the existing typed-null CBV path on the host, including for transient descriptor tables. A zero-address view never needs a scratch upload.

Refs #1242, finding VIC-BT-016. D3D12 CreateConstantBufferView

Verification

  • The new synthetic regression retains the old view on main and sees a null constant-buffer record with this patch.
  • GPU library tests passed in both configurations (51 default, 54 with diagnostics, one ignored in each).
  • GPU all-targets Clippy with diagnostics and warnings denied passed.

The regression checks the guest descriptor update. It does not read back a null CBV in a shader. AI-assisted. No game files used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587362954 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1298). Originally posted by [EatCodeSleep2](https://github.com/EatCodeSleep2) on 2026-11-24T17:14:36Z. --- ## Summary Write a null constant-buffer record when the title passes a null CBV description. This overwrites the previous record and uses the existing typed-null CBV path on the host, including for transient descriptor tables. A zero-address view never needs a scratch upload. Refs #1242, finding VIC-BT-016. [D3D12 CreateConstantBufferView](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device-createconstantbufferview) ## Verification - The new synthetic regression retains the old view on main and sees a null constant-buffer record with this patch. - GPU library tests passed in both configurations (51 default, 54 with diagnostics, one ignored in each). - GPU all-targets Clippy with diagnostics and warnings denied passed. The regression checks the guest descriptor update. It does not read back a null CBV in a shader. AI-assisted. No game files used.
geiyiliyabumo commented 2026-11-24 18:05:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T17:24:41Z.


Independent verification of \df8f906\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-gpu --lib: 51 passed, 0 failed, 1 ignored (including \_null_cbv_overwrites_the_previous_descriptor)
  • \cargo clippy -p victory-gpu --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

Code audit looks clean and minimal: recording \View::Constant(0, 0)\ on null \CreateConstantBufferView\ clears stale entries while both \descriptor/host.rs\ (\View::Constant(0, _) => None) and \draw.rs\ (\if address != 0) route address-0 CBVs cleanly to typed null descriptors.

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139153609 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1298#issuecomment-7139153609). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T17:24:41Z. --- Independent verification of \df8f906\ on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200\) / Rust 1.98.1 MSVC**: - Merge check vs \main\ (\ fe310e\): clean - \cargo test -p victory-gpu --lib\: **51 passed, 0 failed, 1 ignored** (including \_null_cbv_overwrites_the_previous_descriptor\) - \cargo clippy -p victory-gpu --all-targets -- -D warnings\ (default and \--all-features\): clean - \cargo xtask policy\: 154 files ok Code audit looks clean and minimal: recording \View::Constant(0, 0)\ on null \CreateConstantBufferView\ clears stale entries while both \descriptor/host.rs\ (\View::Constant(0, _) => None\) and \draw.rs\ (\if address != 0\) route address-0 CBVs cleanly to typed null descriptors. *AI-assisted; synthetic tests only, no game files.*
adamdotpy commented 2026-11-24 19:04:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by adamdotpy on 2026-11-24T18:44:55Z.


Reviewed at head df8f906 (worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:

1. The bug and the fix are both right. create_cbv with a null desc (the title unbinding a CBV) used to skip record, so the heap slot kept the previous View::Constant — a stale descriptor. Now a null desc records View::Constant(0, 0) (words(desc).unwrap_or_default()), which every consumer treats as null: make returns None for View::Constant(0, _) (host.rs:631), so make_at/null_for write a typed null CBV (zero location, the Constant arm of null_for); the root-table fill in draw.rs:744 guards address != 0 so a null CBV goes through make_at → null instead of scratch-allocating a copy of address 0; the remaining View::Constant consumer (draw.rs:1180) is debug formatting and is unaffected (size 0 < 16). I checked all four View::Constant sites — no stale path left.

2. Red/green proven here. Reverting just the create_cbv hunk in the worktree makes the new a_null_cbv_overwrites_the_previous_descriptor fail (slot still reads Constant(0x1000, 256) after the null write); on df8f906 it passes with Constant(0, 0). So the branch changes exactly the null-overwrite case.

3. Checks on df8f906: cargo test -p victory-gpu 51 passed / 0 failed / 1 ignored (new test included); cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings clean; cargo build --release -p victory builds; rustfmt --edition 2024 --check on all three changed files shows exactly the same hunks main has (host.rs shifted by the +2 lines) — no new fmt diffs.

4. Note, not a defect: a non-null desc with BufferLocation == 0 and nonzero size now also lands in the Constant(0, _) null arm of make (previously it would try shadow::find(0, size) and fail to null anyway). Address 0 is not a valid title CBV, so treating it as null is the safer reading; the recorded view keeps the real size for diagnostics.

Nothing found that would block this.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141095676 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1298#issuecomment-7141095676). Originally posted by [adamdotpy](https://github.com/adamdotpy) on 2026-11-24T18:44:55Z. --- Reviewed at head `df8f906` (worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked: **1. The bug and the fix are both right.** `create_cbv` with a null `desc` (the title unbinding a CBV) used to skip `record`, so the heap slot kept the previous `View::Constant` — a stale descriptor. Now a null desc records `View::Constant(0, 0)` (`words(desc).unwrap_or_default()`), which every consumer treats as null: `make` returns `None` for `View::Constant(0, _)` (`host.rs:631`), so `make_at`/`null_for` write a typed null CBV (zero location, the `Constant` arm of `null_for`); the root-table fill in `draw.rs:744` guards `address != 0` so a null CBV goes through `make_at` → null instead of scratch-allocating a copy of address 0; the remaining `View::Constant` consumer (`draw.rs:1180`) is debug formatting and is unaffected (size 0 < 16). I checked all four `View::Constant` sites — no stale path left. **2. Red/green proven here.** Reverting just the `create_cbv` hunk in the worktree makes the new `a_null_cbv_overwrites_the_previous_descriptor` fail (slot still reads `Constant(0x1000, 256)` after the null write); on `df8f906` it passes with `Constant(0, 0)`. So the branch changes exactly the null-overwrite case. **3. Checks on `df8f906`:** `cargo test -p victory-gpu` 51 passed / 0 failed / 1 ignored (new test included); `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings` clean; `cargo build --release -p victory` builds; `rustfmt --edition 2024 --check` on all three changed files shows exactly the same hunks `main` has (host.rs shifted by the +2 lines) — no new fmt diffs. **4. Note, not a defect:** a *non-null* desc with `BufferLocation == 0` and nonzero size now also lands in the `Constant(0, _)` null arm of `make` (previously it would try `shadow::find(0, size)` and fail to null anyway). Address 0 is not a valid title CBV, so treating it as null is the safer reading; the recorded view keeps the real size for diagnostics. Nothing found that would block this.
Marvisak commented 2026-11-25 02:05:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:21:44Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/draw.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149467864 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1298#issuecomment-7149467864). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:21:44Z. --- <!-- victory-triage v1 head=df8f906b1e595f1c9b60b0080927e1c5e634f5c9 verdict=needs-rebase at=2026-11-25T01:21:42Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/draw.rs`). It will be reviewed once it is rebased onto the current `main`. --- _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/1298:upstream-pr/1298'
git switch 'upstream-pr/1298'

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