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

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

@⁠AscilCH on GitHub · 2026-11-24 23:25 UTC · original
AscilCH:fix/gpu-null-cbv-handling → main · +40 −5 · 3 files · 1 commits · open

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.)

**@⁠AscilCH** on GitHub · 2026-11-24 23:25 UTC · [original](https://github.com/fxceless/victory-fork/pull/304) `AscilCH:fix/gpu-null-cbv-handling` → `main` · +40 −5 · 3 files · 1 commits · open ## 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.)*
Fix three null-CBV bugs across `descriptor.rs`, `descriptor/host.rs`, and
`draw.rs`:

1. `descriptor::create_cbv` returned without calling `record()` when
   `desc == NULL`, leaving whatever previous view occupied the slot alive.
   Record `View::Constant(0, 0)` on null `desc`.
2. `descriptor::host::make` called `shadow::find(address, size)` even when
   `address == 0 || size == 0`, allocating a bogus 4 MiB loose shadow at
   VA `0x0` and emitting an invalid CBV `{ BufferLocation: non_zero, SizeInBytes: 0 }`.
   Return `None` so callers emit the canonical null CBV via `null_for`.
3. `draw::State::tables` called `list.scratch(0)` + `defer_fill(to, NULL, 0)`
   for null CBVs and fell back to `host.make_null(index)` (a null 2D texture
   SRV) on scratch exhaustion. Emit `host.constant_at(index, 0, 0)` directly
   for null CBVs and on scratch fallback.

Add unit tests in `descriptor::tests` and `descriptor::host::tests`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:40:21 +00:00
Author
Owner

@⁠gmankab on GitHub · 2026-11-26 10:46 UTC · original

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

**@⁠gmankab** on GitHub · 2026-11-26 10:46 UTC · [original](https://github.com/fxceless/victory-fork/pull/304#issuecomment-7189813587) 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
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/304/head:github-bot/gh-304'
git switch 'github-bot/gh-304'

Merge

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