Skip to content

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

Closed
Luislariosss wants to merge 1 commit into
Marvisak:mainfrom
Luislariosss:fix/sampler-heap-cap
Closed

Luislariosss wants to merge 1 commit into
Marvisak:mainfrom
Luislariosss:fix/sampler-heap-cap

Conversation

@Luislariosss

Copy link
Copy Markdown
Contributor

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 Marvisak#65.
@Luislariosss

Copy link
Copy Markdown
Contributor Author

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.

@DaviTostes

Copy link
Copy Markdown

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 Wine/vkd3d: deferred uploads are skipped because VirtualQuery() reports mapped memory as MEM_FREE #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).

@Luislariosss

Copy link
Copy Markdown
Contributor Author

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.

sahajiscoding added a commit to sahajiscoding/VIctory that referenced this pull request Nov 24, 2026
… & shader ops

- Prefer high-performance discrete GPU via IDXGIFactory6::EnumAdapterByGpuPreference
  and VICTORY_ADAPTER (index or name substring) in victory-gpu and victory-shader (Marvisak#208/Marvisak#1132)
- Cap shader-visible sampler heaps at D3D12's 2,048 architectural limit instead of
  failing heap creation (Marvisak#100/Marvisak#86)
- Fall back to the in-memory translated shader if shader-cache disk write fails (Marvisak#358)
- Add F11 / Alt+Enter borderless fullscreen toggle and clean WM_CLOSE handling to
  both title windows (lifecycle.rs) and VIctory's fallback window (host.rs); clamp
  fit_into() dimensions to >= 1 (Marvisak#451)
- Enhance PC keyboard+mouse fallback gamepad with Space/LShift/R/LCtrl aliases,
  LMB/RMB/MMB triggers, and RMB/F9 mouse camera look; support null-device
  cross-device previous/next reading walk (Marvisak#361)
- Fall back to a no-op display deferral when PowerSetRequest returns ERROR_NOT_SUPPORTED
- Clamp short virtual-drive '..' paths at the virtual drive root (Marvisak#182)
- Wake and cancel sleeping delayed callbacks immediately on XTaskQueueTerminate (Marvisak#132)
- Cache XMA IMDCT rotation sin/cos tables across subframes (Marvisak#172)
- Lower additional RDNA2 VALU instructions (v_mul_hi_{u,i}32_{u,i}24, v_mad_{u,i}32_{u,i}16,
  v_lerp_u8, v_sad_u{8,16,32}, v_cvt_pk_{u,i}16_{u,i}32, v_dot{2,4}_{i,u}32_{i,u}{16,8})
  with DXIL validation and conditional INT64 feature flagging (Marvisak#157)
- Add portable victory.toml lookup next to victory.exe, interactive [S] Setup wizard
  and [K] Controls guide in victory.exe, and scripts/build-windows.ps1 release packager

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@Marvisak

Copy link
Copy Markdown
Owner

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU: a sampler heap over 2,048 loses the host heap entirely

3 participants