GPU: clear descriptors for null constant buffers (re-lands #1522) #1916

Closed
github-bot wants to merge 3 commits from gh-pr/1916/head into gh-pr/1916/base
Owner

@⁠Calvix2k on GitHub · 2026-11-25 00:52 UTC · original
Calvix2k:codex/gpu-null-cbv-descriptor-016 → main · +86 −2 · 3 files · 3 commits · closed without merging

Re-lands #1522 (closed as part of the audit batch; it cannot be reopened because the branch was force-pushed during the rebase).

What

descriptor::create_cbv only records a view when the description is non-null, so a descriptor slot reused after a null CreateConstantBufferView keeps the previous CBV instead of the unbound descriptor the D3D spec defines. main (4118f33) still behaves that way.

  • View::NullConstant records the null description.
  • descriptor/host.rs mirrors it as an unbound host CBV (CreateConstantBufferView(None, slot)), which clears a reused slot without removing the device.
  • Regression test: a valid CBV in a slot, then a null CBV, then the slot holds NullConstant; a host-device test creates the null CBV on a real device.

Addresses VIC-BT-016 from #1242.

Verification (Windows 10, Ryzen 7 5800X / RX 7800 XT)

  • cargo test -p victory-gpu --locked views_survive_copies — 1 passed
  • cargo test -p victory-gpu --locked null_constant_buffer_view_is_accepted_by_the_device — 1 passed (host device)
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings — clean
  • cargo xtask policy — 182 files ok
**@⁠Calvix2k** on GitHub · 2026-11-25 00:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1916) `Calvix2k:codex/gpu-null-cbv-descriptor-016` → `main` · +86 −2 · 3 files · 3 commits · closed without merging Re-lands #1522 (closed as part of the audit batch; it cannot be reopened because the branch was force-pushed during the rebase). ## What descriptor::create_cbv only records a view when the description is non-null, so a descriptor slot reused after a null CreateConstantBufferView keeps the previous CBV instead of the unbound descriptor the D3D spec defines. main (4118f33) still behaves that way. - View::NullConstant records the null description. - descriptor/host.rs mirrors it as an unbound host CBV (CreateConstantBufferView(None, slot)), which clears a reused slot without removing the device. - Regression test: a valid CBV in a slot, then a null CBV, then the slot holds NullConstant; a host-device test creates the null CBV on a real device. Addresses VIC-BT-016 from #1242. ## Verification (Windows 10, Ryzen 7 5800X / RX 7800 XT) - cargo test -p victory-gpu --locked views_survive_copies — 1 passed - cargo test -p victory-gpu --locked null_constant_buffer_view_is_accepted_by_the_device — 1 passed (host device) - cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings — clean - cargo xtask policy — 182 files ok
Translated shaders read constant buffers in heap slots as raw buffers, so
the null that replaces a cleared CBV slot has to be the raw null buffer
view, not an unbound constant-buffer view: on WARP with GPU-based
validation the slot then read as the sentinel instead of zeros.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:48:42 +00:00
github-bot closed this pull request 2026-11-26 04:48:42 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 02:27 UTC · original

I ran a CBV clear through the host shader path on your current head 3734f7b574. Translated table and heap constant views use raw buffer SRVs. Creating a native null CBV in that slot leaves it the wrong descriptor kind for the shader.

1eff62e is one commit directly on your head. It reuses the existing raw null SRV and adds a dispatch that reads the same descriptor slot before and after clearing. On WARP with GPU-based validation, both builds read 0x11223344 before the clear. The original head left the output sentinel 0xdeadbeef after it. The fixed build wrote 0.

The full WARP GPU suite passed with 148 tests and 2 ignored. Strict GPU Clippy and asset policy passed.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 02:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1916#issuecomment-7150736819) I ran a CBV clear through the host shader path on your current head 3734f7b57417765dc3a497c3e1df501987e17488. Translated table and heap constant views use raw buffer SRVs. Creating a native null CBV in that slot leaves it the wrong descriptor kind for the shader. [1eff62e](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/1eff62ef4976680196e9beee151161e289561075) is one commit directly on your head. It reuses the existing raw null SRV and adds a dispatch that reads the same descriptor slot before and after clearing. On WARP with GPU-based validation, both builds read 0x11223344 before the clear. The original head left the output sentinel 0xdeadbeef after it. The fixed build wrote 0. The full WARP GPU suite passed with 148 tests and 2 ignored. Strict GPU Clippy and asset policy passed.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:18 UTC · original · edited 2026-11-25 12:28 UTC

Automated triage for the maintainers.

Merge candidate. At 725a352, andrewpozdnakov7-jpg's shader-read fixture is cherry-picked as its own commit with their authorship. It is cleared_constant_view_reads_zero_as_a_raw_buffer, a test-only addition in crates/victory-gpu/src/draw.rs. It reads 0x11223344 through the slot before the clear and 0 after. On the earlier head (3734f7b) it shows the sentinel, so it tests the descriptor kind and not only that the device survives.

The host-side fix is unchanged from the last review and right. In descriptor/host.rs, make turns View::NullConstant into null_buffer_view(at), so the slot stays a raw buffer SRV, the kind translated shaders read constant views through. descriptor::create_cbv records the null description, and views_survive_copies covers the recording. CI check passes at 725a352.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 08:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1916#issuecomment-7156856300) · edited 2026-11-25 12:28 UTC <!-- victory-triage v1 head=725a352eff9f50da84dfeed45201d0eb422c609f verdict=merge-candidate at=2026-11-25T13:04:00Z --> Automated triage for the maintainers. **Merge candidate.** At `725a352`, andrewpozdnakov7-jpg's shader-read fixture is cherry-picked as its own commit with their authorship. It is `cleared_constant_view_reads_zero_as_a_raw_buffer`, a test-only addition in `crates/victory-gpu/src/draw.rs`. It reads `0x11223344` through the slot before the clear and 0 after. On the earlier head (`3734f7b`) it shows the sentinel, so it tests the descriptor kind and not only that the device survives. The host-side fix is unchanged from the last review and right. In `descriptor/host.rs`, `make` turns `View::NullConstant` into `null_buffer_view(at)`, so the slot stays a raw buffer SRV, the kind translated shaders read constant views through. `descriptor::create_cbv` records the null description, and `views_survive_copies` covers the recording. CI `check` passes at `725a352`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 08:34 UTC · original

The host-side half is fixed in 734d85a: View::NullConstant now calls the existing null_buffer_view(at) and returns Some(None), so the slot keeps a raw SRV like every other buffer read through the heap.

On the test half I tried to build the shader-read fixture and could not get it to produce a nonzero "before" value here: a View::Constant over a title buffer created with create_committed makes make return None (buffer_srv cannot find a host copy for that range), and a host buffer's VA is not title memory. Rather than commit a test that reads zeros twice and proves nothing, I left the device test as it is and am asking:

  • Is there an existing fixture that registers a title buffer with a host copy for a CBV (placed memory? shadow::register?) that I can use, or
  • would you take the before/after shader read from 1eff62e as part of this PR?

The record side is covered by views_survive_copies (it asserts the slot becomes View::NullConstant).

**@⁠Calvix2k** on GitHub · 2026-11-25 08:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1916#issuecomment-7157215419) The host-side half is fixed in `734d85a`: `View::NullConstant` now calls the existing `null_buffer_view(at)` and returns `Some(None)`, so the slot keeps a raw SRV like every other buffer read through the heap. On the test half I tried to build the shader-read fixture and could not get it to produce a nonzero "before" value here: a `View::Constant` over a title buffer created with `create_committed` makes `make` return `None` (`buffer_srv` cannot find a host copy for that range), and a host buffer's VA is not title memory. Rather than commit a test that reads zeros twice and proves nothing, I left the device test as it is and am asking: - Is there an existing fixture that registers a title buffer with a host copy for a CBV (placed memory? `shadow::register`?) that I can use, or - would you take the `before`/`after` shader read from 1eff62e as part of this PR? The `record` side is covered by `views_survive_copies` (it asserts the slot becomes `View::NullConstant`).
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 08:47 UTC · original

Yes. I put the shader-read fixture in a2cc866, directly on your 734d85ab072884d274a8e69ac261fd4107026474. The change adds only the test.

The nonzero control uses resource::test_buffer(16) and takes the title address from buffer_bytes. That committed buffer is registered by the normal resource creation path, and the test holds it through both dispatches. It calls readable before dispatch to refresh the buffer's host copy.

With WARP GPU-based validation, the same fixture reads 0x11223344 before the clear on both heads. On 3734f7b, the clear leaves 0xdeadbeef in the output. On 734d85a, your raw null SRV writes zero. The full WARP GPU suite passed with 148 tests, 2 ignored. Strict GPU Clippy and staged asset policy passed.

Please preserve the test commit's Git author if you cherry-pick it. If you fold the test into another commit, please add:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 08:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1916#issuecomment-7157464217) Yes. I put the shader-read fixture in [a2cc866](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/a2cc866ed8310bfac890c15cfab72b83bb244577), directly on your `734d85ab072884d274a8e69ac261fd4107026474`. The change adds only the test. The nonzero control uses `resource::test_buffer(16)` and takes the title address from `buffer_bytes`. That committed buffer is registered by the normal resource creation path, and the test holds it through both dispatches. It calls `readable` before dispatch to refresh the buffer's host copy. With WARP GPU-based validation, the same fixture reads `0x11223344` before the clear on both heads. On `3734f7b`, the clear leaves `0xdeadbeef` in the output. On `734d85a`, your raw null SRV writes zero. The full WARP GPU suite passed with 148 tests, 2 ignored. Strict GPU Clippy and staged asset policy passed. Please preserve the test commit's Git author if you cherry-pick it. If you fold the test into another commit, please add: Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 12:19 UTC · original

@⁠andrewpozdnakov7-jpg — cherry-picked as its own commit, 725a352, so your authorship stays (Author: andrewpozdnakov7-jpg, date and message unchanged); no Co-authored-by needed since it is not folded into anything.

Ran here after the pick: cargo test -p victory-gpu --features diagnostics --lib on Windows 10 19045 / RX 7800 XT — 147 passed, 2 ignored, and the only failure is the known placed-view test on a runtime without ID3D12Device10 (#1999, identical on main). Your cleared_constant_view_reads_zero_as_a_raw_buffer passes on the AMD card as well as it did on WARP.

Thanks for taking the fixture over — that was the one part of this PR I could not write honestly myself (the control needs a committed buffer and the dispatch ordering you describe).

**@⁠Calvix2k** on GitHub · 2026-11-25 12:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1916#issuecomment-7162226984) @⁠andrewpozdnakov7-jpg — cherry-picked as its own commit, `725a352`, so your authorship stays (`Author: andrewpozdnakov7-jpg`, date and message unchanged); no `Co-authored-by` needed since it is not folded into anything. Ran here after the pick: `cargo test -p victory-gpu --features diagnostics --lib` on Windows 10 19045 / RX 7800 XT — **147 passed**, 2 ignored, and the only failure is the known placed-view test on a runtime without `ID3D12Device10` (#1999, identical on `main`). Your `cleared_constant_view_reads_zero_as_a_raw_buffer` passes on the AMD card as well as it did on WARP. Thanks for taking the fixture over — that was the one part of this PR I could not write honestly myself (the control needs a committed buffer and the dispatch ordering you describe).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:04 UTC · original

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing in favour of #2449, which makes the same fix in 33 lines by recording Constant(0, 0), the representation main already uses for a zeroed description, without a new enum variant. The change here is correct for D3D12 and its tests pass on main.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 22:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/1916#issuecomment-7175896431) Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing in favour of #2449, which makes the same fix in 33 lines by recording `Constant(0, 0)`, the representation `main` already uses for a zeroed description, without a new enum variant. The change here is correct for D3D12 and its tests pass on `main`. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1916
No description provided.