Skip to content

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

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

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

Conversation

@faultzonsol

Copy link
Copy Markdown

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 (Marvisak#21).
Dynamic slots are counted per heap, and a table larger than them is
reported once instead of dropped silently.

Fixes Marvisak#65

Co-authored-by: Cursor <cursoragent@cursor.com>
@WallasSCRIPTS

Copy link
Copy Markdown

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.

@lordon1a

Copy link
Copy Markdown
Contributor

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.

@WallasSCRIPTS

Copy link
Copy Markdown

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.

@DaviTostes

Copy link
Copy Markdown

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

@Luislariosss

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…ys inside the heap)

Vaximous's Marvisak#483: every descriptor-heap index the lowering computes is
bounded by the bound heap's guard slot (an index at or above it reads
it), which the host passes in a user-data dword of its own.

Conflict resolutions:
- crates/victory-gpu/src/descriptor/host.rs: this tree's sizing is kept
  (Marvisak#86/Marvisak#83/Marvisak#251, and 2^18 dynamic slots on a capped heap); a view heap
  is made one slot larger, the guard slot, after its dynamic slots and
  outside the pool HostHeap::dynamic hands out (`spare` does not count
  it). On a capped heap that is 737,855 title slots, 262,144 dynamic
  ones and the guard at slot 999,999. Marvisak#483 had the guard at
  `count + DYNAMIC` with the pool sized by a constant; here the pool is
  sized by `spare` (Marvisak#86), so guard_slot() is `count + spare`.
- A sampler heap's guard is its last slot, dynamic ones included
  (`count + spare - 1`), not Marvisak#483's `count - 1`: Marvisak#86 makes sampler
  tables afresh in a capped sampler heap's dynamic slots, which
  `count - 1` would have clamped away.
- crates/victory-shader/src/emit/lower.rs, Lower::new: both fields are
  kept (`dead`, `guard_slots`).
- crates/victory-shader/src/emit/valu_tests.rs: this tree's tests and
  Marvisak#483's new one are both kept.

Changes beyond the PR:
- emit/lower.rs, fetched_index (Marvisak#307's per-lane heap index, which
  Marvisak#483 did not know): it goes through heap_guard too. It is an address
  from a lane's data, as heap_index's.
- emit/image_tests.rs (Marvisak#160's harness): the user data it fills gets the
  guard entries (host::guard).
- descriptor/host.rs: tests the_guard_slot_is_past_every_dynamic_slot,
  and the guard's place in a_capped_view_heap_keeps_its_dynamic_slots.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…Marvisak#358 Marvisak#89 Marvisak#331 Marvisak#86 Marvisak#83 Marvisak#211 Marvisak#260 Marvisak#275)

Conflict in crates/victory-gpu/src/descriptor/host.rs: gpu-state (Marvisak#251)
moved the dynamic-slot search into free_table(); gpu-draw (Marvisak#86) bounds
the search by the heap's spare slots instead of DYNAMIC. free_table() works
over taken.len(), which is the spare count, so the helper is kept with
gpu-draw's spare-based cursor wrap. Both sides' tests kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 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 Marvisak closed this Nov 25, 2026
PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
Code tree of fxceless/victory-fork 4e17478 (all rendering work by its author and
the VIctory contributors) with, on top:
- AMD fixes: skip of 39f0e9aeb156a61c, 32-lane programs per half wave and NaN/Inf
  filter, configurable texture upload queue, VIctory Marvisak#1599
- upstream VIctory Marvisak#334 (buffer-state tracking) and Marvisak#1271 (globally coherent glc UAVs)
- fork PRs Marvisak#95, Marvisak#71, Marvisak#32, Marvisak#86; VIctory Marvisak#1696, Marvisak#1338, Marvisak#1291, Marvisak#1732
- DirectStorage page lists read at the title's submit (analysis by JappertjeV, klbf-lab#3)
- offline pipeline pre-build that saves as it goes and skips driver-crashing pipelines
- Series S plane composition, VICTORY_FFX_SIMPLE, scripted keys in release builds
- docs/klbf/skip-amd.txt: AMD skip list used for our runs
PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
…K 2.4 DLLs (VICTORY_FFX_DIR) (fxceless/victory-fork Marvisak#86)
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

6 participants