GPU: use non-zero NumElements for null raw pairs in HostHeap::raw_pair_at #2542

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

@⁠reeledMarek on GitHub · 2026-11-25 15:33 UTC · original
reeledMarek:fix/gpu-raw-pair-null-and-kept → main · +38 −2 · 1 files · 1 commits · open

Problem

  1. HostHeap::raw_pair_at computed elements = (bytes / 4).min(1 << 27), which produces NumElements = 0 for null raw pairs (raw_pair_at(slot, None, 0), called by memory::Shared::new and Shared::rewrite) and sub-4-byte copies. D3D12 rejects NumElements = 0 on raw SRV/UAV descriptors.
  2. HostHeap::kept was sized to (count + extra) slots, while pair() allocates slots at count + extra..pairs_end. Calls to self.keep(index, ...) in raw_pair_at always missed kept.get_mut(index) and silently dropped the resource instead of retaining and retiring it across in-flight GPU work.

Fix

  • Size HostHeap::kept to total as usize so pair slots retain and retire resources like regular and dynamic slots.
  • Match raw_view_at in raw_pair_at: use (bytes / 4).clamp(1, 1 << 27) when buffer.is_some(), and 1 for null descriptors.

Testing

  • Added raw_pair_null_is_valid_and_pair_slots_retire_resources in crates/victory-gpu/src/descriptor/host.rs.
  • Verified cargo test -p xtask --locked passes asset policy.
**@⁠reeledMarek** on GitHub · 2026-11-25 15:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2542) `reeledMarek:fix/gpu-raw-pair-null-and-kept` → `main` · +38 −2 · 1 files · 1 commits · open ### Problem 1. `HostHeap::raw_pair_at` computed `elements = (bytes / 4).min(1 << 27)`, which produces `NumElements = 0` for null raw pairs (`raw_pair_at(slot, None, 0)`, called by `memory::Shared::new` and `Shared::rewrite`) and sub-4-byte copies. D3D12 rejects `NumElements = 0` on raw SRV/UAV descriptors. 2. `HostHeap::kept` was sized to `(count + extra)` slots, while `pair()` allocates slots at `count + extra..pairs_end`. Calls to `self.keep(index, ...)` in `raw_pair_at` always missed `kept.get_mut(index)` and silently dropped the resource instead of retaining and retiring it across in-flight GPU work. ### Fix - Size `HostHeap::kept` to `total as usize` so pair slots retain and retire resources like regular and dynamic slots. - Match `raw_view_at` in `raw_pair_at`: use `(bytes / 4).clamp(1, 1 << 27)` when `buffer.is_some()`, and `1` for null descriptors. ### Testing - Added `raw_pair_null_is_valid_and_pair_slots_retire_resources` in `crates/victory-gpu/src/descriptor/host.rs`. - Verified `cargo test -p xtask --locked` passes asset policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:44 +00:00
github-bot force-pushed github-bot/gh-2542 from fc1274156d to 9a4721ab31 2026-11-26 06:31:12 +00:00 Compare
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:34 UTC · original · edited 2026-11-26 07:22 UTC

Automated triage for the maintainers.

Merge candidate. Thanks for the rebase. HostHeap::raw_pair_at in crates/victory-gpu/src/descriptor/host.rs now takes NumElements from raw_pair_elements. That gives 1 for a null pair and clamps a real buffer to 1..=2^27. It is the same rule raw_view_at already uses in main, so the null pairs that memory.rs writes no longer carry NumElements = 0. The HostHeap::kept sizing change is dropped, as asked. The device test is weak, because removal on an invalid descriptor shows up only with the debug layer, but it is harmless.

CI: check passing; merges cleanly.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2542#issuecomment-7171095162) · edited 2026-11-26 07:22 UTC <!-- victory-triage v1 head=9a4721ab31e7a03a2ba88fde96812b06580076c8 verdict=merge-candidate at=2026-11-26T07:22:34Z --> Automated triage for the maintainers. **Merge candidate.** Thanks for the rebase. `HostHeap::raw_pair_at` in `crates/victory-gpu/src/descriptor/host.rs` now takes `NumElements` from `raw_pair_elements`. That gives 1 for a null pair and clamps a real buffer to `1..=2^27`. It is the same rule `raw_view_at` already uses in `main`, so the null pairs that `memory.rs` writes no longer carry `NumElements = 0`. The `HostHeap::kept` sizing change is dropped, as asked. The device test is weak, because removal on an invalid descriptor shows up only with the debug layer, but it is harmless. CI: `check` passing; merges cleanly. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-25 20:05 UTC · original

Updated to address the triage feedback:

  • Kept only the raw_pair_at non-zero NumElements fix (raw_pair_elements, matching raw_view_at so D3D12 does not reject NumElements = 0 on null raw SRV/UAV descriptors).
  • Dropped the HostHeap::kept sizing change to avoid the 32 MiB allocation and HostHeap::evict walk overhead.
  • Added a pure CPU unit test raw_pair_elements_never_returns_zero that runs unconditionally, alongside the device-backed raw_pair_null_descriptor_is_accepted_by_device test.
**@⁠reeledMarek** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2542#issuecomment-7173176548) Updated to address the triage feedback: - Kept only the `raw_pair_at` non-zero `NumElements` fix (`raw_pair_elements`, matching `raw_view_at` so D3D12 does not reject `NumElements = 0` on null raw SRV/UAV descriptors). - Dropped the `HostHeap::kept` sizing change to avoid the 32 MiB allocation and `HostHeap::evict` walk overhead. - Added a pure CPU unit test `raw_pair_elements_never_returns_zero` that runs unconditionally, alongside the device-backed `raw_pair_null_descriptor_is_accepted_by_device` test.
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-26 05:56 UTC · original

Rebased cleanly onto current main (63bcca4, resolving the test-append conflict in descriptor/host.rs).

**@⁠reeledMarek** on GitHub · 2026-11-26 05:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2542#issuecomment-7183936685) Rebased cleanly onto current `main` (`63bcca4`, resolving the test-append conflict in `descriptor/host.rs`).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 12:21 UTC · original · approved these changes

Reviewed and verified at head 9a4721ab against origin/main (63bcca43) on Windows 11 (RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1):

  • Design & correctness:
    • Extracting raw_pair_elements (crates/victory-gpu/src/descriptor/host.rs:627-633, 1827-1833) brings HostHeap::raw_pair_at into exact parity with HostHeap::raw_view_at (descriptor/host.rs:483-487), yielding NumElements = 1 for null raw SRV/UAV pairs and (bytes / 4).clamp(1, 1 << 27) for live buffers.
    • Under D3D12 null-descriptor semantics (pResource == NULL), reads return zero and writes are discarded regardless of NumElements, while non-zero NumElements satisfies strict descriptor validation. Both the pure unit test (descriptor/host.rs:2478-2486) and device test (:2488-2501) are clean.
    • Note for maintainers: #2542 and #2543 have no production-code overlap (only a trivial test-append conflict at the bottom of crates/victory-gpu/src/descriptor/host.rs).
  • Verification:
    • Clean git merge-tree against origin/main (63bcca43); cargo xtask policy (191 files ok); cargo clippy -p victory-gpu --all-targets -- -D warnings clean with default features and --all-features.
    • RTX 5090 (default): raw_pair_elements_never_returns_zero and raw_pair_null_descriptor_is_accepted_by_device 2/2 passed.
    • RTX 5090 + VICTORY_D3D12_DEBUG=1 (--features diagnostics): descriptor::host::tests + memory::tests 23/23 passed (skipping the two pre-existing NVIDIA 1M view-heap cap tests); WARP (VICTORY_D3D12_WARP=1) + VICTORY_D3D12_DEBUG=1: 25/25 passed.
    • Verified directly via D3D12 InfoQueue (host.log_messages() after draining startup messages): raw_pair_at(slot, None, 0) produces zero debug-layer warnings or errors on both RTX 5090 and WARP.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 12:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2542#pullrequestreview-6074035889) · **approved these changes** Reviewed and verified at head `9a4721ab` against `origin/main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`): - **Design & correctness**: - Extracting `raw_pair_elements` (`crates/victory-gpu/src/descriptor/host.rs:627-633, 1827-1833`) brings `HostHeap::raw_pair_at` into exact parity with `HostHeap::raw_view_at` (`descriptor/host.rs:483-487`), yielding `NumElements = 1` for null raw SRV/UAV pairs and `(bytes / 4).clamp(1, 1 << 27)` for live buffers. - Under D3D12 null-descriptor semantics (`pResource == NULL`), reads return zero and writes are discarded regardless of `NumElements`, while non-zero `NumElements` satisfies strict descriptor validation. Both the pure unit test (`descriptor/host.rs:2478-2486`) and device test (`:2488-2501`) are clean. - Note for maintainers: `#2542` and `#2543` have no production-code overlap (only a trivial test-append conflict at the bottom of `crates/victory-gpu/src/descriptor/host.rs`). - **Verification**: - Clean `git merge-tree` against `origin/main` (`63bcca43`); `cargo xtask policy` (`191 files ok`); `cargo clippy -p victory-gpu --all-targets -- -D warnings` clean with default features and `--all-features`. - RTX 5090 (default): `raw_pair_elements_never_returns_zero` and `raw_pair_null_descriptor_is_accepted_by_device` **2/2** passed. - RTX 5090 + `VICTORY_D3D12_DEBUG=1` (`--features diagnostics`): `descriptor::host::tests` + `memory::tests` **23/23** passed (skipping the two pre-existing NVIDIA 1M view-heap cap tests); WARP (`VICTORY_D3D12_WARP=1`) + `VICTORY_D3D12_DEBUG=1`: **25/25** passed. - Verified directly via D3D12 InfoQueue (`host.log_messages()` after draining startup messages): `raw_pair_at(slot, None, 0)` produces **zero** debug-layer warnings or errors on both RTX 5090 and WARP. LGTM.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 18:49 UTC · original · approved these changes

LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Clamping NumElements to 1..=2^27 (and 1 for null descriptors) in raw_pair_at avoids D3D12 rejecting NumElements = 0 on null raw SRV/UAV pairs, matching raw_view_at.
  • cargo test -p victory-gpu --lib descriptor::host::tests::raw_pair_ -- --test-threads=1: 2 passed, 0 failed (raw_pair_elements_never_returns_zero and raw_pair_null_descriptor_is_accepted_by_device).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 18:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2542#pullrequestreview-6079168755) · **approved these changes** LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Clamping `NumElements` to `1..=2^27` (and `1` for null descriptors) in `raw_pair_at` avoids D3D12 rejecting `NumElements = 0` on null raw SRV/UAV pairs, matching `raw_view_at`. - `cargo test -p victory-gpu --lib descriptor::host::tests::raw_pair_ -- --test-threads=1`: 2 passed, 0 failed (`raw_pair_elements_never_returns_zero` and `raw_pair_null_descriptor_is_accepted_by_device`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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/2542/head:github-bot/gh-2542'
git switch 'github-bot/gh-2542'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2542'
git switch 'github-bot/gh-2542'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2542'
git switch 'github-bot/gh-2542'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2542'
git switch 'main'
git merge --squash 'github-bot/gh-2542'
git switch 'main'
git merge --ff-only 'github-bot/gh-2542'
git switch 'main'
git merge 'github-bot/gh-2542'
git push origin 'main'
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!2542
No description provided.