GPU: cap a refused sampler heap and remap its past-cap tables #74

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

@⁠WallasSCRIPTS on GitHub · 2026-11-24 00:14 UTC · original
WallasSCRIPTS:gpu/sampler-heap-cap → main · +76 −11 · 1 files · 2 commits · closed without merging

Relates to #65.

What

A sampler heap larger than D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE
(2,048) that the host refused made HostHeap::new return None. The generic
error arm had no fallback, unlike view heaps which cap at 1,000,000.

Losing the heap is worse than losing the slots: draw::State::bind builds
SetDescriptorHeaps with filter_map(...host()), so a heap without a host
is dropped and the heap indices the translated root signature expects shift.

This PR:

  1. Retries a refused sampler heap at 2,048 slots, logging what the title
    asked for, what the host made, and what was lost. The heap stays bound.
  2. Reserves 256 scratch slots only in a capped sampler heap, and lets
    HostHeap::dynamic/release use them. State::tables already remakes a
    table with an entry past host.count(), so sampler tables past the cap
    now take that path instead of being skipped. An uncapped sampler heap
    keeps all 2,048 slots for the title.

count.saturating_add(extra) keeps a title asking for u32::MAX on the cap
path rather than overflowing in a debug build.

Driver note

Some drivers accept a 2,049-slot sampler heap — the RX 7600 here does. The
test forces the refusal with u32::MAX so the path is exercised on any host.

Verification

  • cargo test -p victory-gpu: 41 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets: clean.
  • Changed hunks are rustfmt --edition 2024 clean. The file has
    pre-existing formatting drift elsewhere, untouched here.
  • Allocation and scratch-slot behaviour are tested on a real D3D12 device;
    no title was run.
**@⁠WallasSCRIPTS** on GitHub · 2026-11-24 00:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/74) `WallasSCRIPTS:gpu/sampler-heap-cap` → `main` · +76 −11 · 1 files · 2 commits · closed without merging Relates to #65. ## What A sampler heap larger than `D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE` (2,048) that the host refused made `HostHeap::new` return `None`. The generic error arm had no fallback, unlike view heaps which cap at 1,000,000. Losing the heap is worse than losing the slots: `draw::State::bind` builds `SetDescriptorHeaps` with `filter_map(...host())`, so a heap without a host is dropped and the heap indices the translated root signature expects shift. This PR: 1. Retries a refused sampler heap at 2,048 slots, logging what the title asked for, what the host made, and what was lost. The heap stays bound. 2. Reserves 256 scratch slots **only in a capped sampler heap**, and lets `HostHeap::dynamic`/`release` use them. `State::tables` already remakes a table with an entry past `host.count()`, so sampler tables past the cap now take that path instead of being skipped. An uncapped sampler heap keeps all 2,048 slots for the title. `count.saturating_add(extra)` keeps a title asking for `u32::MAX` on the cap path rather than overflowing in a debug build. ## Driver note Some drivers accept a 2,049-slot sampler heap — the RX 7600 here does. The test forces the refusal with `u32::MAX` so the path is exercised on any host. ## Verification - `cargo test -p victory-gpu`: 41 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets`: clean. - Changed hunks are `rustfmt --edition 2024` clean. The file has pre-existing formatting drift elsewhere, untouched here. - Allocation and scratch-slot behaviour are tested on a real D3D12 device; no title was run.
A sampler heap the host refused made HostHeap::new return None. The heap
was then dropped from SetDescriptorHeaps by filter_map, which also shifts
the heap indices the translated root signature expects — worse than
losing the sampler slots alone.

Retry with D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE (2,048) slots and
report what the title asked for, what was made, and what was lost. The
first 2,048 samplers keep working and the bound heap order is unchanged.

The test uses u32::MAX to force the refused path on every host: a
2,049-slot heap is accepted on some drivers, including the RX 7600 here.

Samplers past the cap still need a copy path: HostHeap::dynamic is
view-only, so State::tables cannot remake their tables. Issue #65 stays
open for that part.

Verified with cargo test -p victory-gpu (40 passed), clippy clean, and
rustfmt --edition 2024 clean on the changed hunks.
Capping the heap kept the first 2,048 samplers, but State::tables could not
remake a table past the cap: HostHeap::dynamic was view-only and sampler
heaps had no scratch area. Those tables were simply not made.

Reserve 256 slots in a sampler heap only when it had to be capped, and let
dynamic()/release() use them like a view heap's. An uncapped sampler heap
keeps all its slots for the title. Use saturating_add for the requested
size so a title asking for u32::MAX reaches the cap instead of overflowing.

Two tests cover the capped heap's scratch area and the uncapped heap's
absence of one. cargo test -p victory-gpu: 41 passed, clippy clean.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:16 +00:00
github-bot closed this pull request 2026-11-26 03:49:16 +00:00
Author
Owner

@⁠WallasSCRIPTS on GitHub · 2026-11-24 00:25 UTC · original

Closing in favour of #86, which is the better design and covers the same
ground. #74 only capped when the host refused an over-limit sampler heap;
the RX 7600 here accepts one, so behaviour depended on the driver. #86 caps
at the spec limit up front and gives the capped heap its 256 scratch slots,
so State::tables remaps past-cap sampler tables on every host. It also
fixes the null-sampler fallback and reports an oversized table instead of
dropping it. One PR for #65 is enough.

One suggestion if it helps: the cap warning currently logs only count.
Reporting wanted, made and lost like the view-heap warning in #35
makes a tester's log self-explanatory without a second diagnostic run.

Verified on my branch before closing: cargo test -p victory-gpu 41 passed,
clippy clean. No title run.

**@⁠WallasSCRIPTS** on GitHub · 2026-11-24 00:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/74#issuecomment-7118046705) Closing in favour of #86, which is the better design and covers the same ground. #74 only capped when the host *refused* an over-limit sampler heap; the RX 7600 here accepts one, so behaviour depended on the driver. #86 caps at the spec limit up front and gives the capped heap its 256 scratch slots, so `State::tables` remaps past-cap sampler tables on every host. It also fixes the null-sampler fallback and reports an oversized table instead of dropping it. One PR for #65 is enough. One suggestion if it helps: the cap warning currently logs only `count`. Reporting `wanted`, `made` and `lost` like the view-heap warning in #35 makes a tester's log self-explanatory without a second diagnostic run. Verified on my branch before closing: `cargo test -p victory-gpu` 41 passed, clippy clean. No title run.

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!74
No description provided.