GPU: cap a sampler heap past the host's limit, with dynamic slots for tables past it #86

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

@⁠faultzonsol on GitHub · 2026-11-24 00:21 UTC · original
faultzonsol:fix/sampler-heap-cap → main · +103 −13 · 2 files · 1 commits · closed without merging

Fixes #65. Covers the half #74 leaves open; the two conflict in HostHeap::new, so one of them should go in.

What

A title sampler heap larger than D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE (2,048) made HostHeap::new return None, which Descriptor::host() cached for good.

Such a heap is now capped at 2,048 host slots up front: the title's first 1,792 and 256 dynamic ones. Tables reaching past the kept title slots go through the existing State::tables path (#21) and are made afresh in the dynamic slots, as tables past a capped view heap already are.

  • HostHeap counts its dynamic slots per heap (spare): DYNAMIC for view heaps, SAMPLER_DYNAMIC for capped sampler heaps, none for sampler heaps within the limit. dynamic/release use it instead of DYNAMIC.
  • A table larger than the dynamic slots is reported once instead of dropped silently.
  • make_at on a sampler heap falls back to a null sampler, not a null view, when the host cannot make the slot (same guard mirror already has).
  • The constructor's common tail moves into HostHeap::with.

Difference from #74

#74 retries at 2,048 only when the host refuses the bigger heap, and keeps no dynamic slots, so sampler tables past the cap still read past the heap. Here the cap is applied whenever the title asks for more than the spec limit, so behaviour does not depend on whether a driver accepts an out-of-spec heap (the RX 7600 in #74 does).

#83 (null-fill staging heap sized for samplers) is independent and still applies on top.

Verification

  • New tests: large_sampler_heap_is_capped (count, dynamic allocation up to SAMPLER_DYNAMIC, release and reuse) and small_sampler_heap_has_no_dynamic_slots. They run on the host device (RX 6700 XT, Windows 11) and skip without one.
  • cargo test --workspace: all pass. cargo clippy -p victory-gpu --all-targets: nothing new. cargo xtask policy: ok.
  • Changed hunks only; the file's existing formatting is left as is.
  • No title was run: I have no game files, so whether the title actually asks for more than 2,048 samplers is still unconfirmed (the new warning logs the requested count).
**@⁠faultzonsol** on GitHub · 2026-11-24 00:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/86) `faultzonsol:fix/sampler-heap-cap` → `main` · +103 −13 · 2 files · 1 commits · closed without merging Fixes #65. Covers the half #74 leaves open; the two conflict in `HostHeap::new`, so one of them should go in. ## What A title sampler heap larger than `D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE` (2,048) made `HostHeap::new` return `None`, which `Descriptor::host()` cached for good. Such a heap is now capped at 2,048 host slots up front: the title's first 1,792 and 256 dynamic ones. Tables reaching past the kept title slots go through the existing `State::tables` path (#21) and are made afresh in the dynamic slots, as tables past a capped view heap already are. - `HostHeap` counts its dynamic slots per heap (`spare`): `DYNAMIC` for view heaps, `SAMPLER_DYNAMIC` for capped sampler heaps, none for sampler heaps within the limit. `dynamic`/`release` use it instead of `DYNAMIC`. - A table larger than the dynamic slots is reported once instead of dropped silently. - `make_at` on a sampler heap falls back to a null sampler, not a null view, when the host cannot make the slot (same guard `mirror` already has). - The constructor's common tail moves into `HostHeap::with`. ## Difference from #74 #74 retries at 2,048 only when the host refuses the bigger heap, and keeps no dynamic slots, so sampler tables past the cap still read past the heap. Here the cap is applied whenever the title asks for more than the spec limit, so behaviour does not depend on whether a driver accepts an out-of-spec heap (the RX 7600 in #74 does). #83 (null-fill staging heap sized for samplers) is independent and still applies on top. ## Verification - New tests: `large_sampler_heap_is_capped` (count, dynamic allocation up to `SAMPLER_DYNAMIC`, release and reuse) and `small_sampler_heap_has_no_dynamic_slots`. They run on the host device (RX 6700 XT, Windows 11) and skip without one. - `cargo test --workspace`: all pass. `cargo clippy -p victory-gpu --all-targets`: nothing new. `cargo xtask policy`: ok. - Changed hunks only; the file's existing formatting is left as is. - No title was run: I have no game files, so whether the title actually asks for more than 2,048 samplers is still unconfirmed (the new warning logs the requested count).
A title sampler heap larger than D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE
(2,048) made HostHeap::new return None, which Descriptor::host() cached for
good: the heap was left out of SetDescriptorHeaps and every draw through it
read no samplers.

Such a heap is now capped at 2,048 slots: the title's first 1,792 and 256
dynamic ones. Tables reaching past the title slots kept are made afresh in
the dynamic slots, as tables past a capped view heap already are (#21).
Dynamic slots are counted per heap, and a table larger than them is
reported once instead of dropped silently.

Fixes #65

Co-authored-by: Cursor <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:43 +00:00
github-bot closed this pull request 2026-11-26 03:49:43 +00:00
Author
Owner

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

You got there first and the design is better than mine in #74: capping at
the spec limit up front avoids the driver-dependent behaviour my retry-on-
refusal had (the RX 7600 here accepts an out-of-spec 2,049-slot heap). I am
closing #74 so #65 has one PR.

Small suggestion from my branch: the cap warning logs only count. Adding
wanted, made and lost fields, as the view-heap warning does in #35,
makes the log self-explanatory. Purely optional.

My branch also used saturating_add for the requested size so a title
asking for u32::MAX reaches the cap instead of overflowing in a debug
build — worth checking in your constructor.

**@⁠WallasSCRIPTS** on GitHub · 2026-11-24 00:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/86#issuecomment-7118046281) You got there first and the design is better than mine in #74: capping at the spec limit up front avoids the driver-dependent behaviour my retry-on- refusal had (the RX 7600 here accepts an out-of-spec 2,049-slot heap). I am closing #74 so #65 has one PR. Small suggestion from my branch: the cap warning logs only `count`. Adding `wanted`, `made` and `lost` fields, as the view-heap warning does in #35, makes the log self-explanatory. Purely optional. My branch also used `saturating_add` for the requested size so a title asking for `u32::MAX` reaches the cap instead of overflowing in a debug build — worth checking in your constructor.
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 00:38 UTC · original

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

  • cargo xtask policy: 150 files ok
  • cargo test -p victory-gpu: 41 passed, 0 failed (including both new tests large_sampler_heap_is_capped and small_sampler_heap_has_no_dynamic_slots).

Important finding in crates/victory-gpu/src/draw.rs (State::tables)

The heap-side changes in descriptor/host.rs look clean (including the self.sampler branch in make_at), but State::tables in draw.rs still hardcodes the 32-byte (8-dword) view descriptor stride when remaking tables into dynamic slots:

  • draw.rs:664: u.table_offset_dwords / 8 + 1 (sampler descriptors are 16 bytes / 4 dwords, per descriptor.rs:4, so n is half the required sampler slot count)
  • draw.rs:672 & draw.rs:699: table + u64::from(k) * 32 (skips every odd sampler slot in title memory)
  • draw.rs:698: u.table_offset_dwords / 8 == k
  • draw.rs:685 & draw.rs:722: made.push((slot, first * 32)) (hands the shader double the byte offset for a sampler table, which would index out of bounds in the 2,048-slot sampler heap)

Using let stride_dwords = if heap.samplers() { 4 } else { 8 }; and let stride_bytes = u64::from(stride_dwords) * 4; across draw.rs:662-723 would make the capped sampler table remapping path actually match the 16-byte sampler layout.

AI-assisted.

**@⁠lordon1a** on GitHub · 2026-11-24 00:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/86#issuecomment-7118272894) Verified `a80eb17c4` on Windows 11 (`x86_64-pc-windows-gnullvm`, `rustc 1.100.0`, applied cleanly to `main@35b054ec0`): - `cargo xtask policy`: 150 files ok - `cargo test -p victory-gpu`: **41 passed, 0 failed** (including both new tests `large_sampler_heap_is_capped` and `small_sampler_heap_has_no_dynamic_slots`). ### Important finding in `crates/victory-gpu/src/draw.rs` (`State::tables`) The heap-side changes in `descriptor/host.rs` look clean (including the `self.sampler` branch in `make_at`), **but `State::tables` in `draw.rs` still hardcodes the 32-byte (8-dword) view descriptor stride** when remaking tables into dynamic slots: - `draw.rs:664`: `u.table_offset_dwords / 8 + 1` (sampler descriptors are 16 bytes / **4 dwords**, per `descriptor.rs:4`, so `n` is half the required sampler slot count) - `draw.rs:672` & `draw.rs:699`: `table + u64::from(k) * 32` (skips every odd sampler slot in title memory) - `draw.rs:698`: `u.table_offset_dwords / 8 == k` - `draw.rs:685` & `draw.rs:722`: `made.push((slot, first * 32))` (hands the shader double the byte offset for a sampler table, which would index out of bounds in the 2,048-slot sampler heap) Using `let stride_dwords = if heap.samplers() { 4 } else { 8 };` and `let stride_bytes = u64::from(stride_dwords) * 4;` across `draw.rs:662-723` would make the capped sampler table remapping path actually match the 16-byte sampler layout. AI-assisted.
Author
Owner

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

Verified on Windows 11 with an AMD RX 7600 (driver 32.0.32029.2010), Rust 1.98.1:

  • cargo test -p victory-gpu: 41 passed, including large_sampler_heap_is_capped and small_sampler_heap_has_no_dynamic_slots.
  • cargo clippy -p victory-gpu --all-targets: clean.

This driver accepts an out-of-spec 2,049-slot sampler heap, so the up-front cap handles a case the retry-on-refusal approach missed. The tests do not exercise table remapping. Static inspection confirms the review finding: State::tables still divides offsets by 8 and steps 32 bytes, while sampler descriptors are 4 dwords / 16 bytes. That path needs correction before the capped sampler-table remapping is validated.

**@⁠WallasSCRIPTS** on GitHub · 2026-11-24 00:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/86#issuecomment-7118334150) Verified on Windows 11 with an AMD RX 7600 (driver 32.0.32029.2010), Rust 1.98.1: - `cargo test -p victory-gpu`: 41 passed, including `large_sampler_heap_is_capped` and `small_sampler_heap_has_no_dynamic_slots`. - `cargo clippy -p victory-gpu --all-targets`: clean. This driver accepts an out-of-spec 2,049-slot sampler heap, so the up-front cap handles a case the retry-on-refusal approach missed. The tests do not exercise table remapping. Static inspection confirms the review finding: `State::tables` still divides offsets by 8 and steps 32 bytes, while sampler descriptors are 4 dwords / 16 bytes. That path needs correction before the capped sampler-table remapping is validated.
Author
Owner

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

Tested a80eb17 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, same baseline (36) plus this PR's two new tests:
    • descriptor::host::tests::large_sampler_heap_is_capped — ok
    • descriptor::host::tests::small_sampler_heap_has_no_dynamic_slots — ok
  • The three failures are the environment-only ones that also fail on main: Wine's d3dcompiler_47 cannot compile the indirect clamp shader, vkd3d-proton returns E_INVALIDARG when creating an empty pipeline library, and #128 (VirtualQuery reports vkd3d-mapped memory as MEM_FREE, so the deferred texture upload is skipped).
  • So the cap + dynamic-slot path does run against a real D3D12 implementation here (vkd3d-proton), not only in mocks.

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

**@⁠DaviTostes** on GitHub · 2026-11-24 00:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/86#issuecomment-7118442748) Tested `a80eb17` 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**, same baseline (36) plus this PR's two new tests: - `descriptor::host::tests::large_sampler_heap_is_capped` — **ok** - `descriptor::host::tests::small_sampler_heap_has_no_dynamic_slots` — **ok** - The three failures are the environment-only ones that also fail on `main`: Wine's `d3dcompiler_47` cannot compile the indirect clamp shader, vkd3d-proton returns `E_INVALIDARG` when creating an empty pipeline library, and #128 (`VirtualQuery` reports vkd3d-mapped memory as `MEM_FREE`, so the deferred texture upload is skipped). - So the cap + dynamic-slot path does run against a real D3D12 implementation here (vkd3d-proton), not only in mocks. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

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

Two small things from reading this against #100 and the note from @⁠WallasSCRIPTS, both about the constructor.

1. count + extra can still overflow on the view path. The cap you add for samplers is exact, but a view heap still reaches make(count + extra) and PORTABLE_VIEWS through the bare sum, as on main:

let extra = if sampler { 0 } else { DYNAMIC };
let (heap, count) = match make(count + extra) {

A title that asks for u32::MAX descriptors overflows there in a debug build before the cap can answer. saturating_add on the requested total (and on the PORTABLE_VIEWS comparison) is enough, and it keeps every other answer identical: my version of this change does let requested = count.saturating_add(extra); and let total = count.saturating_add(extra); in the cap decision, and the two cap tests below pass either way.

2. The cap warning logs only count. @⁠WallasSCRIPTS suggested wanted / made / lost, matching the view-heap warning in #35; I agree, it makes a log line self-explanatory when a title loses slots.

What #100 has that is worth folding in here

  • cap_for(sampler, count, extra) -> Option<(total, mirrored)>, pure, with two unit tests: sampler at 2,048 / 2,049 / 100,000, view under / at / over PORTABLE_VIEWS with extra subtracted, and u32::MAX for both. No device needed, so they run everywhere.
  • In State::bind, a one-shot warn! when a bound heap has no host heap at all, instead of dropping it from SetDescriptorHeaps silently.

I would rather send both as a patch on top of your branch than keep a second PR open for them. Say the word and I will post the diff here; if you would rather keep the change single-authored, that is fine too and I will close #100 - your design with the 256 dynamic sampler slots is the better one, and I said so on #100.

Verified here on a80eb17c4, AMD Radeon RX 9060 XT (RDNA4, gfx1200), Adrenalin 26.10.1 (Windows driver 32.0.32015.7029), Windows 11 26200, MSVC 2022:

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

No game files. AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/86#issuecomment-7118503085) Two small things from reading this against #100 and the note from @⁠WallasSCRIPTS, both about the constructor. **1. `count + extra` can still overflow on the view path.** The cap you add for samplers is exact, but a view heap still reaches `make(count + extra)` and `PORTABLE_VIEWS` through the bare sum, as on `main`: ``` let extra = if sampler { 0 } else { DYNAMIC }; let (heap, count) = match make(count + extra) { ``` A title that asks for `u32::MAX` descriptors overflows there in a debug build before the cap can answer. `saturating_add` on the requested total (and on the `PORTABLE_VIEWS` comparison) is enough, and it keeps every other answer identical: my version of this change does `let requested = count.saturating_add(extra);` and `let total = count.saturating_add(extra);` in the cap decision, and the two cap tests below pass either way. **2. The cap warning logs only `count`.** @⁠WallasSCRIPTS suggested `wanted` / `made` / `lost`, matching the view-heap warning in #35; I agree, it makes a log line self-explanatory when a title loses slots. ## What #100 has that is worth folding in here - `cap_for(sampler, count, extra) -> Option<(total, mirrored)>`, pure, with two unit tests: sampler at 2,048 / 2,049 / 100,000, view under / at / over `PORTABLE_VIEWS` with `extra` subtracted, and `u32::MAX` for both. No device needed, so they run everywhere. - In `State::bind`, a one-shot `warn!` when a bound heap has no host heap at all, instead of dropping it from `SetDescriptorHeaps` silently. I would rather send both as a patch on top of your branch than keep a second PR open for them. Say the word and I will post the diff here; if you would rather keep the change single-authored, that is fine too and I will close #100 - your design with the 256 dynamic sampler slots is the better one, and I said so on #100. Verified here on `a80eb17c4`, AMD Radeon RX 9060 XT (RDNA4, gfx1200), Adrenalin 26.10.1 (Windows driver 32.0.32015.7029), Windows 11 26200, MSVC 2022: ``` cargo test -p victory-gpu test descriptor::host::tests::large_sampler_heap_is_capped ... ok test result: ok. 41 passed; 0 failed ``` No game files. AI-assisted.
Author
Owner

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

Independent full-suite run on an AMD RDNA4 Windows machine, since #86 has no AMD run yet.

Head a80eb17c4, no local changes Machine AMD Radeon RX 9060 XT (RDNA4, gfx1200), Adrenalin 26.10.1 (Windows driver 32.0.32015.7029) Windows 11 26200, MSVC 2022, Windows SDK 10.0.26100.0 Command cargo test --workspace Result 229 passed, 0 failed, 3 ignored

The 3 ignored are the BCPack/XMA cases that want reference data outside the repository. For comparison, main gives the same 229 / 0 / 3 here, so this PR costs nothing in the suite. No game files were used and no title was run.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 00:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/86#issuecomment-7118505272) Independent full-suite run on an AMD RDNA4 Windows machine, since #86 has no AMD run yet. ` Head a80eb17c4, no local changes Machine AMD Radeon RX 9060 XT (RDNA4, gfx1200), Adrenalin 26.10.1 (Windows driver 32.0.32015.7029) Windows 11 26200, MSVC 2022, Windows SDK 10.0.26100.0 Command cargo test --workspace Result 229 passed, 0 failed, 3 ignored ` The 3 ignored are the BCPack/XMA cases that want reference data outside the repository. For comparison, main gives the same 229 / 0 / 3 here, so this PR costs nothing in the suite. No game files were used and no title was run. 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 issue (#65, title sampler heap past 2,048) as #1032, with extra dynamic-slot machinery for sampler tables; no test title has a sampler heap past 2,048 (Grand Theft Auto VI's are 128), so the 15-line cap is enough.

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/86#issuecomment-7148025381) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1032. Same issue (#65, title sampler heap past 2,048) as #1032, with extra dynamic-slot machinery for sampler tables; no test title has a sampler heap past 2,048 (Grand Theft Auto VI's are 128), so the 15-line cap is enough. 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!86
No description provided.