Skip to content

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

Closed
Calvix2k wants to merge 3 commits into
Marvisak:mainfrom
Calvix2k:codex/gpu-null-cbv-descriptor-016
Closed

Calvix2k wants to merge 3 commits into
Marvisak:mainfrom
Calvix2k:codex/gpu-null-cbv-descriptor-016

Conversation

@Calvix2k

Copy link
Copy Markdown
Contributor

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

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Clear descriptors for null constant buffers: null-CBV descriptor clearing — pairs with #1629's null CBV work.

@Calvix2k
Calvix2k force-pushed the codex/gpu-null-cbv-descriptor-016 branch 2 times, most recently from b380544 to 3734f7b Compare November 25, 2026 02:17
@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I ran a CBV clear through the host shader path on your current head 3734f7b. 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.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

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.
@Calvix2k

Copy link
Copy Markdown
Contributor Author

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

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

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 andrewpozdnakov7-jpg@users.noreply.github.com

@Calvix2k

Copy link
Copy Markdown
Contributor Author

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

zhaibingye added a commit to zhaibingye/VIctory that referenced this pull request Nov 25, 2026
Keep empty and populated constants the same raw SRV kind in heap metadata.
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@Marvisak

Copy link
Copy Markdown
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants