GPU: bound the null sampler staging heap #83

Open
FIocker wants to merge 1 commit from upstream-pr/83 into main
FIocker commented 2026-11-24 00:19:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by FIocker on 2026-11-24T00:19:53Z.


The heap initializer uses a CPU-only staging heap to copy null descriptors. It used the view-heap batch size (65,536 descriptors) for samplers too. A host can accept the shader-visible sampler heap and reject that temporary heap, leaving the shader-visible slots undefined.

Use the portable sampler limit to size each sampler batch. If initialization fails, report the error and stop before exposing the heap. This change is independent of the refusal-triggered sampler capacity fallback in #74 and applies to portable-sized heaps as well. Refs #65.

The new synthetic test requires successful initialization of a portable-sized sampler heap when the test has a D3D12 device. It passed on Windows WARP with VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked --features diagnostics portable_sampler_null_fill_fits_the_host_limit. The asset policy passed.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571678380 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/83). Originally posted by [FIocker](https://github.com/FIocker) on 2026-11-24T00:19:53Z. --- The heap initializer uses a CPU-only staging heap to copy null descriptors. It used the view-heap batch size (65,536 descriptors) for samplers too. A host can accept the shader-visible sampler heap and reject that temporary heap, leaving the shader-visible slots undefined. Use the portable sampler limit to size each sampler batch. If initialization fails, report the error and stop before exposing the heap. This change is independent of the refusal-triggered sampler capacity fallback in #74 and applies to portable-sized heaps as well. Refs #65. The new synthetic test requires successful initialization of a portable-sized sampler heap when the test has a D3D12 device. It passed on Windows WARP with `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked --features diagnostics portable_sampler_null_fill_fits_the_host_limit`. The asset policy passed.
lordon1a commented 2026-11-24 06:54:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T00:38:55Z.


Verified d8f063b04 on Windows 11 (x86_64-pc-windows-gnullvm, rustc 1.100.0, applied cleanly to main@35b054ec0): pass.

  • cargo xtask policy: 150 files ok
  • cargo test -p victory-gpu: 40 passed, 0 failed (including portable_sampler_null_fill_fits_the_host_limit on Intel Iris Xe).

Small edge-case note: in fill_null, if total == 0 (e.g. a zero-slot sampler heap), block_count becomes 0 and CreateDescriptorHeap(NumDescriptors: 0) will fail (E_INVALIDARG), which now causes HostHeap::new to return None due to the added return None; at line 134. Adding if total == 0 { return Ok(()); } at the top of fill_null avoids that edge case.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118287525 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/83#issuecomment-7118287525). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T00:38:55Z. --- Verified `d8f063b04` on Windows 11 (`x86_64-pc-windows-gnullvm`, `rustc 1.100.0`, applied cleanly to `main@35b054ec0`): **pass**. - `cargo xtask policy`: 150 files ok - `cargo test -p victory-gpu`: **40 passed, 0 failed** (including `portable_sampler_null_fill_fits_the_host_limit` on Intel Iris Xe). Small edge-case note: in `fill_null`, if `total == 0` (e.g. a zero-slot sampler heap), `block_count` becomes `0` and `CreateDescriptorHeap(NumDescriptors: 0)` will fail (`E_INVALIDARG`), which now causes `HostHeap::new` to return `None` due to the added `return None;` at line 134. Adding `if total == 0 { return Ok(()); }` at the top of `fill_null` avoids that edge case. AI-assisted.
martingouv commented 2026-11-24 06:54:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by martingouv on 2026-11-24T00:43:39Z.


Tested d8f063b on main on an RTX 5060 Ti (NVIDIA 621.24): tests pass. On this card the premise doesn't reproduce: a non-shader-visible sampler heap of 65,536 (and of 1,048,576) is created fine, so the existing staging block works for samplers here. Sizing the block to 2,048 is harmless either way.

One concern: the new return None when fill_null fails also applies to view heaps. Before, a heap whose null fill failed was still usable (slots undefined). Now the whole heap is dropped, and per #65 a missing host heap shifts the heap indices of everything bound with it in SetDescriptorHeaps. That seems worse than undefined slots. Could the early return be limited to sampler heaps, or dropped and the warning kept?

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118368278 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/83#issuecomment-7118368278). Originally posted by [martingouv](https://github.com/martingouv) on 2026-11-24T00:43:39Z. --- Tested `d8f063b` on `main` on an RTX 5060 Ti (NVIDIA 621.24): tests pass. On this card the premise doesn't reproduce: a **non-shader-visible sampler heap of 65,536 (and of 1,048,576) is created fine**, so the existing staging block works for samplers here. Sizing the block to 2,048 is harmless either way. One concern: the new `return None` when `fill_null` fails also applies to **view heaps**. Before, a heap whose null fill failed was still usable (slots undefined). Now the whole heap is dropped, and per #65 a missing host heap shifts the heap indices of everything bound with it in `SetDescriptorHeaps`. That seems worse than undefined slots. Could the early return be limited to sampler heaps, or dropped and the warning kept? AI-assisted (Claude Code).
DaviTostes commented 2026-11-24 06:54:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:49:17Z.


Tested d8f063b under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with cargo xwin ... --target x86_64-pc-windows-msvc: pass, no regression.

  • victory_gpu: 37 passed, 3 failed — this PR adds one test (36 → 37).
  • The 3 failures are the environment-only ones from main (argument_clamp_builds, a_rejected_blob_gives_an_empty_library, and #128's VirtualQuery upload skip), not this PR.
  • Note this touches the same sampler-heap area as #74, #86 and #100 (all for #65). I plan to test it merged with #86 next; if the two conflict, that will be worth knowing before review.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118467356 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/83#issuecomment-7118467356). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:49:17Z. --- Tested `d8f063b` under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build with `cargo xwin ... --target x86_64-pc-windows-msvc`: **pass, no regression**. - `victory_gpu`: **37 passed, 3 failed** — this PR adds one test (36 → 37). - The 3 failures are the environment-only ones from `main` (`argument_clamp_builds`, `a_rejected_blob_gives_an_empty_library`, and #128's `VirtualQuery` upload skip), not this PR. - Note this touches the same sampler-heap area as #74, #86 and #100 (all for #65). I plan to test it merged with #86 next; if the two conflict, that will be worth knowing before review. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
DaviTostes commented 2026-11-24 06:54:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:51:02Z.


Merged with #86 (a80eb17 + d8f063b): the textual merge succeeds, but the result does not compile — the two PRs disagree on HostHeap::new's return type:

error[E0308]: mismatched types
   --> crates/victory-gpu/src/descriptor/host.rs:178:20
     |     ) -> Self {
     |          ---- expected `HostHeap` because of return type
  178|             return None;
     |                    ^^^^ expected `HostHeap`, found `Option<_>`

So at least one of #83 / #86 / #74 / #100 needs to pick up the chosen HostHeap::new signature before they can coexist; on its own #83 is 37 passed / 3 environment-only failures under Wine (see above). This is the same convergence the #65 family needs anyway.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118499378 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/83#issuecomment-7118499378). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:51:02Z. --- Merged with **#86** (`a80eb17` + `d8f063b`): the textual merge succeeds, but the result **does not compile** — the two PRs disagree on `HostHeap::new`'s return type: ``` error[E0308]: mismatched types --> crates/victory-gpu/src/descriptor/host.rs:178:20 | ) -> Self { | ---- expected `HostHeap` because of return type 178| return None; | ^^^^ expected `HostHeap`, found `Option<_>` ``` So at least one of #83 / #86 / #74 / #100 needs to pick up the chosen `HostHeap::new` signature before they can coexist; on its own #83 is 37 passed / 3 environment-only failures under Wine (see above). This is the same convergence the #65 family needs anyway. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
mercuryVM commented 2026-11-24 08:21:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:21:54Z.

Review: APPROVED


Tested d8f063b on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (228 passed, 0 failed; older base). cargo test -p victory-gpu --features diagnostics --lib portable_sampler passes on the hardware adapter.

  • Capping the CPU staging block at D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE (2048) for samplers, and at total in general, means the temporary heap is never bigger than the heap it fills. The copy loops keep their doubling-then-blocks shape with the new size.
  • Returning None after a failed fill, instead of handing out a heap whose slots are undefined, is the important half. A later null-descriptor read then can't sample garbage.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6035838978 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/83#pullrequestreview-6035838978). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T08:21:54Z. **Review:** APPROVED --- Tested d8f063b on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (228 passed, 0 failed; older base). `cargo test -p victory-gpu --features diagnostics --lib portable_sampler` passes on the hardware adapter. - Capping the CPU staging block at `D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE` (2048) for samplers, and at `total` in general, means the temporary heap is never bigger than the heap it fills. The copy loops keep their doubling-then-blocks shape with the new size. - Returning `None` after a failed fill, instead of handing out a heap whose slots are undefined, is the important half. A later null-descriptor read then can't sample garbage. No issues found. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 01:07:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:16:05Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/descriptor/host.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148330116 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/83#issuecomment-7148330116). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:16:05Z. --- <!-- victory-triage v1 head=d8f063b04566e39dfa32617387e8ab60b4cf689d verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/descriptor/host.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/83:upstream-pr/83'
git switch 'upstream-pr/83'

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/83'
git switch 'upstream-pr/83'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/83'
git switch 'upstream-pr/83'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/83'
git switch 'main'
git merge --squash 'upstream-pr/83'
git switch 'main'
git merge --ff-only 'upstream-pr/83'
git switch 'main'
git merge 'upstream-pr/83'
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
Marvisak/VIctory!83
No description provided.