GPU/descriptor: handle null CBVs without leaving stale views or VA-0 shadows #304

Open
AscilCH wants to merge 1 commit from upstream-pr/304 into main
AscilCH commented 2026-11-24 23:25:41 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-24T23:25:41Z.


Problem

Three bugs when a title creates a null constant buffer view (CreateConstantBufferView(NULL, handle) or SizeInBytes == 0 / BufferLocation == 0):

  1. Stale descriptor left in slot (crates/victory-gpu/src/descriptor.rs): create_cbv skipped record() when desc was null, leaving whatever previous CBV/SRV/UAV occupied the handle active.
  2. Bogus 4 MiB shadow at VA 0x0 + invalid D3D12 CBV (crates/victory-gpu/src/descriptor/host.rs): make() called shadow::find(address, size) even when address == 0 || size == 0, creating a 4 MiB loose shadow buffer for VA 0x0 and passing { BufferLocation: non_zero_gpu_va, SizeInBytes: 0 } to CreateConstantBufferView instead of returning None for null_for (which writes the canonical null CBV D3D12_CONSTANT_BUFFER_VIEW_DESC::default()).
  3. Invalid dynamic CBV / wrong null descriptor type (crates/victory-gpu/src/draw.rs): State::tables called list.scratch(0) + defer_fill(to, NULL, 0) and emitted { BufferLocation: non_zero_gpu_va, SizeInBytes: 0 }; on scratch failure it wrote host.make_null(index) (a null 2D Texture SRV) into a CBV slot.

Fix

  • Record View::Constant(0, 0) in descriptor::create_cbv when desc is null.
  • Return None early in descriptor::host::make when address == 0 || size == 0 so null_for writes a canonical null CBV without calling shadow::find.
  • Emit host.constant_at(index, 0, 0) in draw::State::tables when address == 0 || size == 0 or when list.scratch returns None.
  • Add unit tests descriptor::tests::null_cbv_overwrites_previous_descriptor and descriptor::host::tests::null_cbv_does_not_allocate_shadow_at_zero.

Verification

  • rustfmt --edition 2024 --check (changed hunks): clean
  • cargo test -p victory-gpu --locked descriptor -- --test-threads=1: 17 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean

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

<!-- greyfinch-sync:fxceless/victory-fork:issue:5482057795 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/304). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-24T23:25:41Z. --- ## Problem Three bugs when a title creates a null constant buffer view (`CreateConstantBufferView(NULL, handle)` or `SizeInBytes == 0` / `BufferLocation == 0`): 1. **Stale descriptor left in slot (`crates/victory-gpu/src/descriptor.rs`)**: `create_cbv` skipped `record()` when `desc` was null, leaving whatever previous CBV/SRV/UAV occupied the handle active. 2. **Bogus 4 MiB shadow at VA `0x0` + invalid D3D12 CBV (`crates/victory-gpu/src/descriptor/host.rs`)**: `make()` called `shadow::find(address, size)` even when `address == 0 || size == 0`, creating a 4 MiB loose shadow buffer for VA `0x0` and passing `{ BufferLocation: non_zero_gpu_va, SizeInBytes: 0 }` to `CreateConstantBufferView` instead of returning `None` for `null_for` (which writes the canonical null CBV `D3D12_CONSTANT_BUFFER_VIEW_DESC::default()`). 3. **Invalid dynamic CBV / wrong null descriptor type (`crates/victory-gpu/src/draw.rs`)**: `State::tables` called `list.scratch(0)` + `defer_fill(to, NULL, 0)` and emitted `{ BufferLocation: non_zero_gpu_va, SizeInBytes: 0 }`; on scratch failure it wrote `host.make_null(index)` (a null 2D Texture SRV) into a CBV slot. ## Fix - Record `View::Constant(0, 0)` in `descriptor::create_cbv` when `desc` is null. - Return `None` early in `descriptor::host::make` when `address == 0 || size == 0` so `null_for` writes a canonical null CBV without calling `shadow::find`. - Emit `host.constant_at(index, 0, 0)` in `draw::State::tables` when `address == 0 || size == 0` or when `list.scratch` returns `None`. - Add unit tests `descriptor::tests::null_cbv_overwrites_previous_descriptor` and `descriptor::host::tests::null_cbv_does_not_allocate_shadow_at_zero`. ## Verification - `rustfmt --edition 2024 --check` (changed hunks): clean - `cargo test -p victory-gpu --locked descriptor -- --test-threads=1`: 17 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic unit tests only, no game data.)*
gmankab commented 2026-11-26 11:05:32 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by gmankab on 2026-11-26T10:46:17Z.


I independently tested this fix in the Wine-free Victory runtime on Fedora Linux 45. Both null-CBV regressions failed before the port. On the corresponding native PR branch, all seven descriptor tests passed on RX 6800 RADV and Lavapipe with Vulkan validation.

In a 460-second Lavapipe Series S loading comparison, the control logged 22 zero-byte CBV calls and nine Vulkan zero-range validation messages. With the fix, both counts were zero. The title still timed out on the illustrated loading screen.

The native port preserves AscilCH’s authorship. https://github.com/spidercraft/VIctory/pull/27

Tested-on: RX 6800, Fedora Linux 45, RADV and Lavapipe
Assisted-by: gpt-6.2 sol xhigh

<!-- greyfinch-sync:fxceless/victory-fork:comment:7189813587 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/304#issuecomment-7189813587). Originally posted by [gmankab](https://github.com/gmankab) on 2026-11-26T10:46:17Z. --- I independently tested this fix in the Wine-free Victory runtime on Fedora Linux 45. Both null-CBV regressions failed before the port. On the corresponding native PR branch, all seven descriptor tests passed on RX 6800 RADV and Lavapipe with Vulkan validation. In a 460-second Lavapipe Series S loading comparison, the control logged 22 zero-byte CBV calls and nine Vulkan zero-range validation messages. With the fix, both counts were zero. The title still timed out on the illustrated loading screen. The native port preserves AscilCH’s authorship. https://github.com/spidercraft/VIctory/pull/27 Tested-on: RX 6800, Fedora Linux 45, RADV and Lavapipe Assisted-by: gpt-6.2 sol xhigh
CwWwWwW commented 2026-11-27 09:14:32 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T09:14:32Z.


Independent check of current main (9a9091d, 2026-11-27): all three problems described here are still present, so this PR is still needed.

  1. crates/victory-gpu/src/descriptor.rs:1220 - create_cbv still only calls record() when words(desc) is Some, so a null description leaves the slot's previous view recorded.
  2. crates/victory-gpu/src/descriptor/host.rs:3631 - make() still calls crate::shadow::find(address, u64::from(size)) for View::Constant without an address == 0 || size == 0 early return.
  3. crates/victory-gpu/src/draw.rs:4153 and :4202 - the CBV-table path still falls back to host.make_null(index), i.e. a null 2D texture SRV in a CBV slot.

Note that the PR is currently mergeable=False (it conflicts with main - descriptor.rs/draw.rs/host.rs have moved since its base). A rebase preserving the three fixes and the two tests should still apply; the discussion here remains relevant.

(Offline code check only; no game data. This fork also has the same class fixed upstream as VIctory #2449, but this PR additionally covers the VA-0 shadow and dynamic-CBV parts.)

<!-- greyfinch-sync:fxceless/victory-fork:comment:7214447519 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/304#issuecomment-7214447519). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T09:14:32Z. --- Independent check of current main (`9a9091d`, 2026-11-27): all three problems described here are still present, so this PR is still needed. 1. `crates/victory-gpu/src/descriptor.rs:1220` - `create_cbv` still only calls `record()` when `words(desc)` is `Some`, so a null description leaves the slot's previous view recorded. 2. `crates/victory-gpu/src/descriptor/host.rs:3631` - `make()` still calls `crate::shadow::find(address, u64::from(size))` for `View::Constant` without an `address == 0 || size == 0` early return. 3. `crates/victory-gpu/src/draw.rs:4153` and `:4202` - the CBV-table path still falls back to `host.make_null(index)`, i.e. a null 2D texture SRV in a CBV slot. Note that the PR is currently `mergeable=False` (it conflicts with main - `descriptor.rs`/`draw.rs`/`host.rs` have moved since its base). A rebase preserving the three fixes and the two tests should still apply; the discussion here remains relevant. (Offline code check only; no game data. This fork also has the same class fixed upstream as VIctory #2449, but this PR additionally covers the VA-0 shadow and dynamic-CBV parts.)
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/304:upstream-pr/304'
git switch 'upstream-pr/304'

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