GPU: cap a shader-visible sampler heap at 2,048 instead of losing it #100

Closed
github-bot wants to merge 1 commit from gh-pr/100/head into gh-pr/100/base
Owner

@⁠Luislariosss on GitHub · 2026-11-24 00:30 UTC · original
Luislariosss:fix/sampler-heap-cap → main · +125 −26 · 2 files · 1 commits · closed without merging

Fixes #65.

What

HostHeap::new had a portable-limit fallback only for view heaps, guarded by !sampler. D3D12 caps a shader-visible sampler heap at D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE (2,048) on every resource binding tier, so a title asking for more failed CreateDescriptorHeap; HostHeap::new returned None, Heap::host() cached that None in its OnceLock for the rest of the run, and State::bind dropped the sampler heap from SetDescriptorHeaps without saying anything.

Changes

  • PORTABLE_SAMPLERS = 2_048 next to PORTABLE_VIEWS, naming the D3D12 constant.
  • The decision moves into a pure cap_for(sampler, count, extra) -> Option<(total, mirrored)>, and one Err arm in HostHeap::new consults it for both heap kinds. The view behaviour is unchanged (PORTABLE_VIEWS total, mirrored PORTABLE_VIEWS - extra); a sampler heap caps at 2,048 with a warning that names the request and the cap.
  • Bookkeeping uses the final total: GPU_RANGES, kept, and fill_null. A sampler heap no longer reserves an unused DYNAMIC-sized dynamic-slot vector (dynamic() already returns early for samplers).
  • fill_null sizes its null block to min(total, BLOCK) and returns early when the total is 0.
  • The title slot past the host heap diagnostic counts sampler and view slots separately instead of sharing one high-water mark.
  • State::bind warns once when a bound heap has no host heap instead of dropping it silently, and a sampler index past the host heap is not queued for a fresh copy, which could never be made.

The last two are behaviour changes rather than pure additions, so they are the part worth reviewing hardest: a sampler slot past 2,048 cannot be mirrored, and queueing it for fresh only spent work on a copy that mirror then discards.

Tested

cargo test -p victory-gpu
test result: ok. 41 passed; 0 failed; 0 ignored

cargo clippy -p victory-gpu --all-targets
Finished (0 warnings)

The two new tests cover the cap boundary for both heap kinds: sampler at 2,048 (no cap) and 2,049 / 100,000 (capped), view under, at and over PORTABLE_VIEWS, with extra subtracted for views and ignored for samplers, plus u32::MAX.

Not tested: the title itself. I do not have the game files, so I could not reproduce the original symptom or exercise a real heap over 2,048 entries; the change is verified against the host limit and by unit test only. Nothing here was run against main of this repository with a game.

I did not run cargo fmt over the tree: it already reports diffs on untouched files, and the two files here are formatted by hand to match the surrounding style.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/100) `Luislariosss:fix/sampler-heap-cap` → `main` · +125 −26 · 2 files · 1 commits · closed without merging Fixes #65. ## What `HostHeap::new` had a portable-limit fallback only for view heaps, guarded by `!sampler`. D3D12 caps a shader-visible sampler heap at `D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE` (2,048) on every resource binding tier, so a title asking for more failed `CreateDescriptorHeap`; `HostHeap::new` returned `None`, `Heap::host()` cached that `None` in its `OnceLock` for the rest of the run, and `State::bind` dropped the sampler heap from `SetDescriptorHeaps` without saying anything. ## Changes - `PORTABLE_SAMPLERS = 2_048` next to `PORTABLE_VIEWS`, naming the D3D12 constant. - The decision moves into a pure `cap_for(sampler, count, extra) -> Option<(total, mirrored)>`, and one `Err` arm in `HostHeap::new` consults it for both heap kinds. The view behaviour is unchanged (`PORTABLE_VIEWS` total, mirrored `PORTABLE_VIEWS - extra`); a sampler heap caps at 2,048 with a warning that names the request and the cap. - Bookkeeping uses the final total: `GPU_RANGES`, `kept`, and `fill_null`. A sampler heap no longer reserves an unused `DYNAMIC`-sized dynamic-slot vector (`dynamic()` already returns early for samplers). - `fill_null` sizes its null block to `min(total, BLOCK)` and returns early when the total is 0. - The `title slot past the host heap` diagnostic counts sampler and view slots separately instead of sharing one high-water mark. - `State::bind` warns once when a bound heap has no host heap instead of dropping it silently, and a sampler index past the host heap is not queued for a fresh copy, which could never be made. The last two are behaviour changes rather than pure additions, so they are the part worth reviewing hardest: a sampler slot past 2,048 cannot be mirrored, and queueing it for `fresh` only spent work on a copy that `mirror` then discards. ## Tested ``` cargo test -p victory-gpu test result: ok. 41 passed; 0 failed; 0 ignored cargo clippy -p victory-gpu --all-targets Finished (0 warnings) ``` The two new tests cover the cap boundary for both heap kinds: sampler at 2,048 (no cap) and 2,049 / 100,000 (capped), view under, at and over `PORTABLE_VIEWS`, with `extra` subtracted for views and ignored for samplers, plus `u32::MAX`. **Not tested:** the title itself. I do not have the game files, so I could not reproduce the original symptom or exercise a real heap over 2,048 entries; the change is verified against the host limit and by unit test only. Nothing here was run against `main` of this repository with a game. I did not run `cargo fmt` over the tree: it already reports diffs on untouched files, and the two files here are formatted by hand to match the surrounding style. AI-assisted.
HostHeap::new had a portable-limit fallback only for view heaps, guarded by
!sampler. D3D12 caps a shader-visible sampler heap at
D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE (2,048) on every resource binding
tier, so a title asking for more failed CreateDescriptorHeap, HostHeap::new
returned None, Heap::host() cached that None in its OnceLock for the rest of
the run, and State::bind dropped the sampler heap from SetDescriptorHeaps
without saying anything.

The decision moves into a pure cap_for(sampler, count, extra) that returns
the total and the mirrored count to use, and one Err arm consults it for both
kinds of heap, so the view behaviour is unchanged and samplers now cap at
2,048 with a warning that names the request and the cap. The bookkeeping uses
the final total (GPU_RANGES, kept, fill_null), a sampler heap no longer
reserves an unused DYNAMIC-sized dynamic-slot vector, fill_null sizes its
null block to min(total, BLOCK) and returns early for a total of 0, and the
"title slot past the host heap" diagnostic counts sampler and view slots
separately.

State::bind now warns once when a bound heap has no host heap instead of
dropping it silently, and a sampler index past the host heap is not queued
for a fresh copy, which could never be made.

cargo test -p victory-gpu: 41 passed, 0 failed. cargo clippy -p victory-gpu
--all-targets: clean. The two new tests cover the cap boundaries for both
heap kinds, including u32::MAX.

Issue #65.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:14 +00:00
github-bot closed this pull request 2026-11-26 03:50:14 +00:00
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-24 00:33 UTC · original

For completeness, the whole workspace on this branch, not just victory-gpu:

cargo test --workspace
victory            1 passed      victory-formats  17 passed, 3 ignored
victory-core       8 passed      victory-game      2 passed
victory-gpu       41 passed      victory-hle      81 passed
victory-loader     7 passed      + 2 passed (tests/)
victory-pe         5 passed      victory-pipeline   3 passed
victory-shader    57 passed      xtask              1 passed
                  --- 229 passed, 0 failed, 3 ignored (the 3 ignored are the BCPack/XMA cases
                      that want reference files outside the repository)

cargo clippy --workspace --all-targets is clean on this branch too. Still nothing here that exercises the title: the sampler heap path is covered by unit test only, as the description says.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/100#issuecomment-7118198132) For completeness, the whole workspace on this branch, not just `victory-gpu`: ``` cargo test --workspace victory 1 passed victory-formats 17 passed, 3 ignored victory-core 8 passed victory-game 2 passed victory-gpu 41 passed victory-hle 81 passed victory-loader 7 passed + 2 passed (tests/) victory-pe 5 passed victory-pipeline 3 passed victory-shader 57 passed xtask 1 passed --- 229 passed, 0 failed, 3 ignored (the 3 ignored are the BCPack/XMA cases that want reference files outside the repository) ``` `cargo clippy --workspace --all-targets` is clean on this branch too. Still nothing here that exercises the title: the sampler heap path is covered by unit test only, as the description says.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:48 UTC · original

Tested f7d08ce 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 test binary: 38 passed, 3 failed; this PR's new test descriptor::host::tests::cap_for_samplers_matches_d3d12_limit passes under a real D3D12 implementation (vkd3d-proton).
  • The 3 failures are the same environment-only ones as main: the indirect clamp shader (Wine's d3dcompiler_47), the empty pipeline library (E_INVALIDARG from vkd3d), and #128 (VirtualQuery sees vkd3d-mapped memory as MEM_FREE, skipping the deferred texture upload).

Coordination note: #74 and #86 are open for the same #65 and change the same HostHeap::new; #86's description says it covers what #74 leaves open and that the two conflict. This PR does not mention either, so three fixes for #65 are in flight — worth converging before review time is spent on all three.

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

**@⁠DaviTostes** on GitHub · 2026-11-24 00:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/100#issuecomment-7118447136) Tested `f7d08ce` 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` test binary: **38 passed, 3 failed**; this PR's new test `descriptor::host::tests::cap_for_samplers_matches_d3d12_limit` passes under a real D3D12 implementation (vkd3d-proton). - The 3 failures are the same environment-only ones as `main`: the indirect clamp shader (Wine's `d3dcompiler_47`), the empty pipeline library (`E_INVALIDARG` from vkd3d), and #128 (`VirtualQuery` sees vkd3d-mapped memory as `MEM_FREE`, skipping the deferred texture upload). Coordination note: **#74 and #86 are open for the same #65** and change the same `HostHeap::new`; #86's description says it covers what #74 leaves open and that the two conflict. This PR does not mention either, so three fixes for #65 are in flight — worth converging before review time is spent on all three. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-24 00:50 UTC · original

Thanks for the Wine/vkd3d run, and for flagging the duplication - that is worth settling before review time is spent three ways. #74 is already closed, so it is #86 against this one.

I read #86 and ran it here (AMD RX 9060 XT, RDNA4, Windows 11 26200, MSVC 2022, a80eb17c4):

cargo test -p victory-gpu
test descriptor::host::tests::large_sampler_heap_is_capped ... ok
test result: ok. 41 passed; 0 failed

Where they differ

#86 this PR
cap at D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE yes yes
dynamic slots for samplers past the cap yes, SAMPLER_DYNAMIC = 256 no, those slots are left unmapped
the constant the real D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE a local 2_048 naming it
cap decision factored out no, inline cap_for(sampler, count, extra), pure, tested at both heap kinds' boundaries and u32::MAX
warns when a bound heap has no host heap no yes (State::bind, once)
independent run by someone else no yes, yours

My reading

#86 is the better design and should be the one merged. Giving a capped sampler heap 256 dynamic slots means a table reaching past 2,048 is still made afresh, which is strictly better than my version: I only warn, and State::bind skips the fresh path for sampler slots because it could never be made. It also uses the real constant, which I should have done.

This PR has two small things #86 does not: the pure cap_for with its boundary tests, and the one-shot warning when a heap has no host heap at all. Both are worth folding into #86 rather than keeping a second PR alive for them.

So: if @⁠faultzonsol wants them, I will post the cap_for tests and the State::bind warning as a patch against #86's branch, and close this one. If you would rather take a single change under one author, close this without further comment - I will not take it personally, and the Wine result stands either way.

I have not closed it yet because the choice is yours and #86 has no independent run on AMD yet. My machine can provide one (cargo test --workspace on this card: 229 passed) if that helps decide.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/100#issuecomment-7118480160) Thanks for the Wine/vkd3d run, and for flagging the duplication - that is worth settling before review time is spent three ways. #74 is already closed, so it is #86 against this one. I read #86 and ran it here (AMD RX 9060 XT, RDNA4, Windows 11 26200, MSVC 2022, `a80eb17c4`): ``` cargo test -p victory-gpu test descriptor::host::tests::large_sampler_heap_is_capped ... ok test result: ok. 41 passed; 0 failed ``` ## Where they differ | | #86 | this PR | |---|---|---| | cap at `D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE` | yes | yes | | dynamic slots for samplers past the cap | **yes, `SAMPLER_DYNAMIC = 256`** | no, those slots are left unmapped | | the constant | the real `D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE` | a local `2_048` naming it | | cap decision factored out | no, inline | `cap_for(sampler, count, extra)`, pure, tested at both heap kinds' boundaries and `u32::MAX` | | warns when a bound heap has no host heap | no | yes (`State::bind`, once) | | independent run by someone else | no | yes, yours | ## My reading **#86 is the better design and should be the one merged.** Giving a capped sampler heap 256 dynamic slots means a table reaching past 2,048 is still made afresh, which is strictly better than my version: I only warn, and `State::bind` skips the fresh path for sampler slots because it could never be made. It also uses the real constant, which I should have done. This PR has two small things #86 does not: the pure `cap_for` with its boundary tests, and the one-shot warning when a heap has no host heap at all. Both are worth folding into #86 rather than keeping a second PR alive for them. So: if @⁠faultzonsol wants them, I will post the `cap_for` tests and the `State::bind` warning as a patch against #86's branch, and close this one. If you would rather take a single change under one author, close this without further comment - I will not take it personally, and the Wine result stands either way. I have not closed it yet because the choice is yours and #86 has no independent run on AMD yet. My machine can provide one (`cargo test --workspace` on this card: 229 passed) if that helps decide. AI-assisted.
Author
Owner

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

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1032. Same cap of oversized sampler heaps at 2,048 as #1032 in 125 lines instead of 15.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/100#issuecomment-7148026973) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1032. Same cap of oversized sampler heaps at 2,048 as #1032 in 125 lines instead of 15. If this is mistaken, reply here with what was missed (or push a change and say so) 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!100
No description provided.