GPU: cap shader-visible sampler heaps at 2048 descriptors #744

Open
opened 2026-11-26 04:13:54 +00:00 by github-bot · 3 comments
Owner

@⁠flaxdmin199 on GitHub · 2026-11-24 09:18 UTC · original

Problem

On D3D12, shader-visible sampler descriptor heaps are strictly limited to 2048 descriptors (D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE = 2048) across all resource binding tiers.

When a title allocates a shader-visible sampler descriptor heap with count > 2048 (e.g. 4096 or more as a block allocation):

  1. HostHeap::new(true, count) invoked make(count) which failed with E_INVALIDARG.
  2. The fallback capping logic was guarded by !sampler, causing sampler heaps > 2048 to fall into the error branch and return None.
  3. Descriptor::host() cached None in OnceLock.
  4. draw::State::bind() filtered descriptor heaps via filter_map(|&h| heap(h).host()), completely dropping the sampler heap from SetDescriptorHeaps().
  5. In HostHeap::fill_null(), a hardcoded BLOCK = 1 << 16 (65,536) CPU descriptor heap was created to seed null descriptors, which also failed for sampler heaps.
  6. In draw::State::tables(), any table extending past host.count() was unconditionally added to fresh (dynamic table creation), which is specific to 32-byte view descriptors and always failed for sampler tables (host.dynamic() returns None for samplers).

Fixes #65. Refs #21.

Solution

  1. HostHeap Capping (crates/victory-gpu/src/descriptor/host.rs):
    • Defined PORTABLE_SAMPLERS: u32 = 2048.
    • In HostHeap::new(), when sampler && requested > PORTABLE_SAMPLERS, capped host heap creation to PORTABLE_SAMPLERS (2048) with a descriptive tracing::warn!, mirroring the PORTABLE_VIEWS behavior.
  2. Null Fill Bounding (crates/victory-gpu/src/descriptor/host.rs):
    • In fill_null(), capped temporary block allocation to let block_size = BLOCK.min(total). For sampler heaps, block_size is at most 2048, allowing successful creation and initialization of null point samplers.
  3. Table Remap Guard (crates/victory-gpu/src/draw.rs):
    • In State::tables(), guarded fresh.push(u.slot) with !heap.samplers() && index >= host.count() so sampler tables are not misrouted to the view dynamic-slot allocator.
  4. Synthetic Regression Tests:
    • Added descriptor::host::tests::sampler_heap_larger_than_2048_is_capped verifying that HostHeap::new(true, 4096) creates a valid heap of count 2048 and maintains device health.
    • Added descriptor::tests::sampler_heap_larger_than_2048_creates_host_heap verifying end-to-end descriptor heap creation and host heap association.

Verification

  • Environment:
    • OS: Windows 11 Pro (NT 10.0.26300.0)
    • CPU: AMD Ryzen 5 3600 6-Core Processor
    • GPU: NVIDIA GeForce RTX 5060 (Driver 32.0.16.2101, Feature Level 12_2)
    • Rust: rustc 1.98.1 (48a229cea 2026-09-01)
  • Mutation Testing:
    • Without the fix, sampler_heap_larger_than_2048_is_capped panicked with sampler heap capped at 2048 should be created (exit code 1).
    • With the fix, the test passes consistently.
  • Commands executed:
    • cargo test -p victory-gpu -> 50 passed; 0 failed
    • cargo test -p victory-gpu --features diagnostics -> 52 passed; 0 failed
    • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics -> 52 passed; 0 failed
    • cargo clippy --workspace --all-targets -> 0 warnings in changed files
    • cargo clippy -p victory --features diagnostics --all-targets -> 0 warnings
    • cargo test --workspace -> All workspace test suites passed
    • cargo xtask policy -> asset policy: 151 files ok
    • cargo build --release -p victory -> Compiled successfully
    • cargo build --profile diag -p victory --features diagnostics -> Compiled successfully

Not tested / Scope

  • Verified against hardware GPU (RTX 5060) and D3D12 WARP software rasterizer using synthetic unit tests.
  • No commercial retail game dumps were executed.

Branch

**@⁠flaxdmin199** on GitHub · 2026-11-24 09:18 UTC · [original](https://github.com/Marvisak/VIctory/issues/744) ## Problem On D3D12, shader-visible sampler descriptor heaps are strictly limited to 2048 descriptors (`D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE = 2048`) across all resource binding tiers. When a title allocates a shader-visible sampler descriptor heap with `count > 2048` (e.g. 4096 or more as a block allocation): 1. `HostHeap::new(true, count)` invoked `make(count)` which failed with `E_INVALIDARG`. 2. The fallback capping logic was guarded by `!sampler`, causing sampler heaps > 2048 to fall into the error branch and return `None`. 3. `Descriptor::host()` cached `None` in `OnceLock`. 4. `draw::State::bind()` filtered descriptor heaps via `filter_map(|&h| heap(h).host())`, completely dropping the sampler heap from `SetDescriptorHeaps()`. 5. In `HostHeap::fill_null()`, a hardcoded `BLOCK = 1 << 16` (65,536) CPU descriptor heap was created to seed null descriptors, which also failed for sampler heaps. 6. In `draw::State::tables()`, any table extending past `host.count()` was unconditionally added to `fresh` (dynamic table creation), which is specific to 32-byte view descriptors and always failed for sampler tables (`host.dynamic()` returns `None` for samplers). Fixes #65. Refs #21. ## Solution 1. **HostHeap Capping (`crates/victory-gpu/src/descriptor/host.rs`)**: - Defined `PORTABLE_SAMPLERS: u32 = 2048`. - In `HostHeap::new()`, when `sampler && requested > PORTABLE_SAMPLERS`, capped host heap creation to `PORTABLE_SAMPLERS` (2048) with a descriptive `tracing::warn!`, mirroring the `PORTABLE_VIEWS` behavior. 2. **Null Fill Bounding (`crates/victory-gpu/src/descriptor/host.rs`)**: - In `fill_null()`, capped temporary block allocation to `let block_size = BLOCK.min(total)`. For sampler heaps, `block_size` is at most 2048, allowing successful creation and initialization of null point samplers. 3. **Table Remap Guard (`crates/victory-gpu/src/draw.rs`)**: - In `State::tables()`, guarded `fresh.push(u.slot)` with `!heap.samplers() && index >= host.count()` so sampler tables are not misrouted to the view dynamic-slot allocator. 4. **Synthetic Regression Tests**: - Added `descriptor::host::tests::sampler_heap_larger_than_2048_is_capped` verifying that `HostHeap::new(true, 4096)` creates a valid heap of count 2048 and maintains device health. - Added `descriptor::tests::sampler_heap_larger_than_2048_creates_host_heap` verifying end-to-end descriptor heap creation and host heap association. ## Verification - **Environment**: - OS: Windows 11 Pro (NT 10.0.26300.0) - CPU: AMD Ryzen 5 3600 6-Core Processor - GPU: NVIDIA GeForce RTX 5060 (Driver 32.0.16.2101, Feature Level 12_2) - Rust: `rustc 1.98.1 (48a229cea 2026-09-01)` - **Mutation Testing**: - Without the fix, `sampler_heap_larger_than_2048_is_capped` panicked with `sampler heap capped at 2048 should be created` (exit code 1). - With the fix, the test passes consistently. - **Commands executed**: - `cargo test -p victory-gpu` -> `50 passed; 0 failed` - `cargo test -p victory-gpu --features diagnostics` -> `52 passed; 0 failed` - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics` -> `52 passed; 0 failed` - `cargo clippy --workspace --all-targets` -> `0 warnings` in changed files - `cargo clippy -p victory --features diagnostics --all-targets` -> `0 warnings` - `cargo test --workspace` -> All workspace test suites passed - `cargo xtask policy` -> `asset policy: 151 files ok` - `cargo build --release -p victory` -> Compiled successfully - `cargo build --profile diag -p victory --features diagnostics` -> Compiled successfully ## Not tested / Scope - Verified against hardware GPU (RTX 5060) and D3D12 WARP software rasterizer using synthetic unit tests. - No commercial retail game dumps were executed. ## Branch - Branch: [fix/sampler-heap-cap](https://github.com/flaxdmin199/VIctory/tree/fix/sampler-heap-cap) - Commit: [b07a90f](https://github.com/flaxdmin199/VIctory/commit/b07a90f39189254169f8eee2931153dc43fcb83a) - Ready for cherry-pick by maintainers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:54 +00:00
Author
Owner

@⁠Conrage on GitHub · 2026-11-24 09:54 UTC · original

For whoever reviews the fixes for #65: open PRs #86 and #100 address the same sampler-heap cap, so this branch, #86 and #100 are three versions of one fix. Still reproducible on main at 8e79c80 (crates/victory-gpu/src/descriptor/host.rs:98-105 returns None for a sampler heap the host refuses).

**@⁠Conrage** on GitHub · 2026-11-24 09:54 UTC · [original](https://github.com/Marvisak/VIctory/issues/744#issuecomment-7128054268) For whoever reviews the fixes for #65: open PRs #86 and #100 address the same sampler-heap cap, so this branch, #86 and #100 are three versions of one fix. Still reproducible on main at 8e79c80 (`crates/victory-gpu/src/descriptor/host.rs:98-105` returns `None` for a sampler heap the host refuses).
Author
Owner

@⁠LAKSHYA-cmd-tech on GitHub · 2026-11-24 10:00 UTC · original

Implemented and verified on branch:
https://github.com/LAKSHYA-cmd-tech/VIctory/tree/fix/gpu-descriptor-heaps-caps-and-dynamic-expansion

  • Defined PORTABLE_SAMPLERS: u32 = 2048 in descriptor/host.rs.
  • In HostHeap::new, sampler heaps requested above 2048 descriptors are capped at 2048 with a warning instead of failing with E_INVALIDARG.
  • In fill_null, bounded CPU block allocation size to BLOCK.min(total) so sampler heaps allocate a block of at most 2048 descriptors.
  • In draw::State::tables, guarded fresh.push(u.slot) with !heap.samplers() && index >= host.count() to prevent sampler tables from being misrouted to the view dynamic-slot allocator.
  • Added unit test sampler_heap_larger_than_2048_is_capped.
**@⁠LAKSHYA-cmd-tech** on GitHub · 2026-11-24 10:00 UTC · [original](https://github.com/Marvisak/VIctory/issues/744#issuecomment-7128195096) Implemented and verified on branch: `https://github.com/LAKSHYA-cmd-tech/VIctory/tree/fix/gpu-descriptor-heaps-caps-and-dynamic-expansion` - Defined `PORTABLE_SAMPLERS: u32 = 2048` in `descriptor/host.rs`. - In `HostHeap::new`, sampler heaps requested above 2048 descriptors are capped at 2048 with a warning instead of failing with `E_INVALIDARG`. - In `fill_null`, bounded CPU block allocation size to `BLOCK.min(total)` so sampler heaps allocate a block of at most 2048 descriptors. - In `draw::State::tables`, guarded `fresh.push(u.slot)` with `!heap.samplers() && index >= host.count()` to prevent sampler tables from being misrouted to the view dynamic-slot allocator. - Added unit test `sampler_heap_larger_than_2048_is_capped`.
Author
Owner

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

Automated triage for the maintainers.

This is the same defect as #65, which is open and confirmed. On main, HostHeap::new in crates/victory-gpu/src/descriptor/host.rs still returns None when the host refuses a sampler heap, with no capped fallback. fill_null still makes its staging heap with a fixed BLOCK of 1 << 16. The change is already in open PR #1032 ("GPU: cap oversized sampler heaps", linked to #65), and #83 bounds the null staging heap. Pull requests are open to everyone, so please compare your branch (and LAKSHYA-cmd-tech's) with #1032 and comment there, or open your own PR if yours adds something, such as the State::tables guard.

Proposed close as a duplicate of #65. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/744#issuecomment-7152280173) <!-- victory-issue-triage v1 verdict=proposed-close seen=2026-11-24T10:00:55Z at=2026-11-25T03:49:49Z --> Automated triage for the maintainers. This is the same defect as **#65**, which is open and confirmed. On `main`, `HostHeap::new` in `crates/victory-gpu/src/descriptor/host.rs` still returns `None` when the host refuses a sampler heap, with no capped fallback. `fill_null` still makes its staging heap with a fixed `BLOCK` of `1 << 16`. The change is already in open PR **#1032** ("GPU: cap oversized sampler heaps", linked to #65), and #83 bounds the null staging heap. Pull requests are open to everyone, so please compare your branch (and LAKSHYA-cmd-tech's) with #1032 and comment there, or open your own PR if yours adds something, such as the `State::tables` guard. Proposed close as a duplicate of #65. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the label. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#744
No description provided.