victory-shader: clamp heap indices to the largest heap a host can make (no descriptor read past the heap) #2683

Open
github-bot wants to merge 3 commits from github-bot/gh-2683 into main AGit
Owner

@⁠pes7 on GitHub · 2026-11-25 18:07 UTC · original
pes7:fix/heap-index-limit → main · +124 −10 · 2 files · 3 commits · open

Translated shaders clamped a heap index to a slot no host can have, so a descriptor read at a computed index went past the end of the heap. The clamp is now the largest heap a host may make, and a heap capped at that size keeps its top for the null slots.

victory-shader clamps every heap index it computes (HostShader::heap_handle) below HEAP_VIEWS, and NULL_BUFFER_VIEW = HEAP_VIEWS - 2 is the slot a shader reads instead of a slot that holds no buffer view. HEAP_VIEWS was 1 << 21 = 2 097 152 descriptors, which is the console-shaped heap the indices were first written for - but D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_2 is 1 000 000 (victory-gpu's PORTABLE_VIEWS), so on every D3D12 host the clamp allowed an index up to 2 097 151 against a heap of at most 1 000 000 descriptors. The code knew:

// shortcut: a host that caps its heaps below `HEAP_VIEWS` (NVIDIA)
// faults on an index past them, as before the clamp.

Measured on the title, NVIDIA, warm caches:

WARN descriptor::host: host view heap capped at 1000000 ... count=1245184
WARN descriptor::host: no room for the null buffer views: computed indices of slots
without a buffer view read what is there count=934464 total=1000000

i.e. the null slots were never made, because NULL_BUFFER_VIEW (2 097 150) is above the whole heap. What a shader reads 32 MB past the heap is whatever memory is there, and it is read as a descriptor.

The change. HEAP_VIEWS is 1 000 000, the largest heap a host may create, so any index the clamp can produce is inside the heap. NULL_BUFFER_VIEW is then 999 998, and the capped path keeps the top of its heap free for it: a heap capped at PORTABLE_VIEWS gets MIN_DYNAMIC - NULL_RESERVE dynamic slots, so the title slots plus dynamic slots end below the two null slots and no room for the null buffer views no longer happens.

What it does not do: the title asks for 1 245 184 slots and a host will never hold them (tier 2 caps the heap at 1 000 000), so slots above the capped heap's title region are still not mirrored - they read a null slot now, which is the safe answer and the one the clamp was meant to give (emit "Heap indices": "reads nothing instead of faulting the device"). Remapping the title's index space, or splitting it across heaps, is a separate change.

Reported from two machines, and both measurements agree:

  • #2671 (Intel Arc A770): with the same clamp change applied locally, the world went from 11 draws a frame and a black screen to 453-3 690 draws a frame with a frame visible; the removal that follows is the TDR in #2661.
  • this machine (NVIDIA): no room for the null buffer views no longer happens (0 in the run), host view heap capped at 1000000 count=1245184 stays because the title really does ask for more than a host holds.

Cost: HEAP_VIEWS is baked into translated shaders, so SOURCE_HASH changes and the shader cache is translated again once (the pipeline library is keyed by the title's shaders and is unaffected).

cargo test --workspace --locked, both clippy configurations with -D warnings, cargo xtask policy.

What it gives (to decide the merge): no descriptor read past the host heap: the title asks for 1 245 184 slots where D3D12 allows 1 000 000, and every draw reaching one read a descriptor ~32 MB past the heap. With the clamp the debug layer's no room for the null buffer views and the offset descriptor reads (704 x id=527, 37 x id=538) go to zero; a tester on an RTX 4070 Ti confirmed it on NVIDIA, where the heap is capped the same way.

State: MERGEABLE, CI check green, rebased onto today's main (f3578e3).

Risk: the null views stay above the title's slots in every dynamic range (extra.min(total - count - NULL_RESERVE)).

**@⁠pes7** on GitHub · 2026-11-25 18:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683) `pes7:fix/heap-index-limit` → `main` · +124 −10 · 2 files · 3 commits · open Translated shaders clamped a heap index to a slot no host can have, so a descriptor read at a computed index went past the end of the heap. The clamp is now the largest heap a host may make, and a heap capped at that size keeps its top for the null slots. `victory-shader` clamps every heap index it computes (`HostShader::heap_handle`) below `HEAP_VIEWS`, and `NULL_BUFFER_VIEW = HEAP_VIEWS - 2` is the slot a shader reads instead of a slot that holds no buffer view. `HEAP_VIEWS` was `1 << 21` = 2 097 152 descriptors, which is the console-shaped heap the indices were first written for - but `D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_2` is 1 000 000 (`victory-gpu`'s `PORTABLE_VIEWS`), so on every D3D12 host the clamp allowed an index up to 2 097 151 against a heap of at most 1 000 000 descriptors. The code knew: // shortcut: a host that caps its heaps below `HEAP_VIEWS` (NVIDIA) // faults on an index past them, as before the clamp. Measured on the title, NVIDIA, warm caches: WARN descriptor::host: host view heap capped at 1000000 ... count=1245184 WARN descriptor::host: no room for the null buffer views: computed indices of slots without a buffer view read what is there count=934464 total=1000000 i.e. the null slots were never made, because `NULL_BUFFER_VIEW` (2 097 150) is above the whole heap. What a shader reads 32 MB past the heap is whatever memory is there, and it is read as a descriptor. **The change.** `HEAP_VIEWS` is 1 000 000, the largest heap a host may create, so any index the clamp can produce is inside the heap. `NULL_BUFFER_VIEW` is then 999 998, and the capped path keeps the top of its heap free for it: a heap capped at `PORTABLE_VIEWS` gets `MIN_DYNAMIC - NULL_RESERVE` dynamic slots, so the title slots plus dynamic slots end below the two null slots and `no room for the null buffer views` no longer happens. What it does not do: the title asks for 1 245 184 slots and a host will never hold them (tier 2 caps the heap at 1 000 000), so slots above the capped heap's title region are still not mirrored - they read a null slot now, which is the safe answer and the one the clamp was meant to give (`emit` "Heap indices": "reads nothing instead of faulting the device"). Remapping the title's index space, or splitting it across heaps, is a separate change. Reported from two machines, and both measurements agree: * #2671 (Intel Arc A770): with the same clamp change applied locally, the world went from 11 draws a frame and a black screen to 453-3 690 draws a frame with a frame visible; the removal that follows is the TDR in #2661. * this machine (NVIDIA): `no room for the null buffer views` no longer happens (0 in the run), `host view heap capped at 1000000 count=1245184` stays because the title really does ask for more than a host holds. **Cost:** `HEAP_VIEWS` is baked into translated shaders, so `SOURCE_HASH` changes and the shader cache is translated again once (the pipeline library is keyed by the title's shaders and is unaffected). `cargo test --workspace --locked`, both clippy configurations with `-D warnings`, `cargo xtask policy`. --- **What it gives (to decide the merge):** no descriptor read past the host heap: the title asks for 1 245 184 slots where D3D12 allows 1 000 000, and every draw reaching one read a descriptor ~32 MB past the heap. With the clamp the debug layer's `no room for the null buffer views` and the offset descriptor reads (704 x id=527, 37 x id=538) go to zero; a tester on an RTX 4070 Ti confirmed it on NVIDIA, where the heap is capped the same way. **State:** MERGEABLE, CI `check` green, rebased onto today's `main` (`f3578e3`). **Risk:** the null views stay above the title's slots in every dynamic range (`extra.min(total - count - NULL_RESERVE)`).
Translated shaders clamp every heap index they compute below HEAP_VIEWS,
and NULL_BUFFER_VIEW = HEAP_VIEWS - 2 is the slot a shader reads instead of
a slot with no buffer view. HEAP_VIEWS was 1 << 21 = 2 097 152, the
console-shaped heap the indices were first written for, but
D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_2 is 1 000 000
(victory-gpu's PORTABLE_VIEWS): the clamp allowed an index 32 MB past the
end of any heap that can exist, and what is there is read as a descriptor.
The code knew - "a host that caps its heaps below HEAP_VIEWS (NVIDIA)
faults on an index past them" - and on the title it never got as far as
the null slots:

    host view heap capped at 1000000 count=1245184
    no room for the null buffer views: ... count=934464 total=1000000

HEAP_VIEWS is now the largest heap a host may create (1 000 000), so every
index the clamp can produce is inside the heap and NULL_BUFFER_VIEW is
999 998. A heap capped at PORTABLE_VIEWS keeps the top of itself for those
two slots (MIN_DYNAMIC - NULL_RESERVE dynamic slots), so the title slots
and the dynamic ones end below them and the warning above no longer
happens; measured on the title, warm caches: "null buffer views: 0".

The title asks for 1 245 184 slots, more than a host will hold, so slots
above the capped heap's title region are still unmirrored - they read a
null slot now, which is the safe answer the clamp was meant to give, not a
read outside the heap.

HEAP_VIEWS is baked into translated shaders, so the shader cache is
translated once more (SOURCE_HASH changes); the pipeline library is keyed
by the title's shaders and is unaffected.

cargo test --workspace --locked; both clippy configurations with -D
warnings; cargo xtask policy.
The reserve was applied in the capped path only, so the two successful
layouts (count + DYNAMIC, count + MIN_DYNAMIC) put 999 997/999 998 inside
the dynamic slots, the guard refused the null views there, and a clamp to
HEAP_VIEWS - 1 named a written slot. Every layout now stops its dynamic
range NULL_RESERVE slots below the end of the heap it got.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:57 +00:00
Author
Owner

@⁠Vedoxdev123 on GitHub · 2026-11-25 18:12 UTC · original

RTX 4060 test (AI-assisted)
Windows 64-bit, Ryzen 5 5600X, GeForce RTX 4060 (8 GB).

  • cargo test -p victory-gpu --lib: 195 passed, 0 failed, 1 ignored on this PR. main has 193 passed, 2 failed (descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views). Both pass with this PR.
  • cargo test -p victory-shader: segfaults on both main and this PR, so there is no summary line. No change from this PR.
**@⁠Vedoxdev123** on GitHub · 2026-11-25 18:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7170590521) **RTX 4060 test (AI-assisted)** Windows 64-bit, Ryzen 5 5600X, GeForce RTX 4060 (8 GB). - `cargo test -p victory-gpu --lib`: **195 passed, 0 failed, 1 ignored** on this PR. `main` has 193 passed, 2 failed (`descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`). Both pass with this PR. - `cargo test -p victory-shader`: segfaults on both `main` and this PR, so there is no summary line. No change from this PR.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 18:38 UTC · original

Correct fix for a real device-removal bug: the clamp is arithmetic (cmp+select, not a mask), so 1_000_000 is safe; every successful heap is still >= HEAP_VIEWS via the .max(views) allocation; and in the capped path NULL_RESERVE keeps the top 1,024 slots free, which is where NULL_BUFFER_VIEW = 999,998 now lands (pairs_end = null-1 = 999,997 still inside the reserve). Bonus: strides/marks buffers drop from 8+16 MiB to 4+8 MiB since they size by count.max(HEAP_VIEWS).

Heads-up on overlap: this and #2682 (rebase of #2177) fix the same out-of-heap clamp. #2682 additionally probes the real limit (tier-3 hosts could take the full 2M), reserves an explicit 24,576-slot pairs region plus the 3 reserved slots, and keys the shader cache by the probed limit since translated shaders embed the clamp constant. With HEAP_VIEWS=1_000_000 here, the clamp constant is stable so cache keying is not needed - the tradeoff is #2683's simplicity vs #2682's per-host probing and pairs budget. On a 1M-cap host both produce a 1M heap; they differ in how the capped interior is split (this: more title slots ~934K, ~1K pairs; #2682: ~844K titles, 24.5K pairs, 128K dynamic). Worth coordinating in #1633 which approach lands first since they rewrite the same block.

**@⁠kotekompotek** on GitHub · 2026-11-25 18:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7171186724) Correct fix for a real device-removal bug: the clamp is arithmetic (cmp+select, not a mask), so 1_000_000 is safe; every successful heap is still >= HEAP_VIEWS via the .max(views) allocation; and in the capped path NULL_RESERVE keeps the top 1,024 slots free, which is where NULL_BUFFER_VIEW = 999,998 now lands (pairs_end = null-1 = 999,997 still inside the reserve). Bonus: strides/marks buffers drop from 8+16 MiB to 4+8 MiB since they size by count.max(HEAP_VIEWS). Heads-up on overlap: this and #2682 (rebase of #2177) fix the same out-of-heap clamp. #2682 additionally probes the real limit (tier-3 hosts could take the full 2M), reserves an explicit 24,576-slot pairs region plus the 3 reserved slots, and keys the shader cache by the probed limit since translated shaders embed the clamp constant. With HEAP_VIEWS=1_000_000 here, the clamp constant is stable so cache keying is not needed - the tradeoff is #2683's simplicity vs #2682's per-host probing and pairs budget. On a 1M-cap host both produce a 1M heap; they differ in how the capped interior is split (this: more title slots ~934K, ~1K pairs; #2682: ~844K titles, 24.5K pairs, 128K dynamic). Worth coordinating in #1633 which approach lands first since they rewrite the same block.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 18:46 UTC · original

Correct fix for a real device-removal bug: the clamp is arithmetic (cmp+select, not a mask), so 1_000_000 is safe; every successful heap is still >= HEAP_VIEWS via the .max(views) allocation; and in the capped path NULL_RESERVE keeps the top 1,024 slots free, which is where NULL_BUFFER_VIEW = 999,998 now lands (pairs_end = null-1 = 999,997 still inside the reserve). Bonus: strides/marks buffers drop from 8+16 MiB to 4+8 MiB since they size by count.max(HEAP_VIEWS).

Heads-up on overlap: this and #2682 (rebase of #2177) fix the same out-of-heap clamp. #2682 additionally probes the real limit (tier-3 hosts could take the full 2M), reserves an explicit 24,576-slot pairs region plus the 3 reserved slots, and keys the shader cache by the probed limit since translated shaders embed the clamp constant. With HEAP_VIEWS=1_000_000 here, the clamp constant is stable so cache keying is not needed - the tradeoff is #2683's simplicity vs #2682's per-host probing and pairs budget. On a 1M-cap host both produce a 1M heap; they differ in how the capped interior is split (this: ~934K title slots, ~1K pairs; #2682: ~844K titles, 24.5K pairs, 128K dynamic). Worth coordinating in #1633 which approach lands first since they rewrite the same block.

**@⁠kotekompotek** on GitHub · 2026-11-25 18:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7171373479) Correct fix for a real device-removal bug: the clamp is arithmetic (cmp+select, not a mask), so 1_000_000 is safe; every successful heap is still >= HEAP_VIEWS via the .max(views) allocation; and in the capped path NULL_RESERVE keeps the top 1,024 slots free, which is where NULL_BUFFER_VIEW = 999,998 now lands (pairs_end = null-1 = 999,997 still inside the reserve). Bonus: strides/marks buffers drop from 8+16 MiB to 4+8 MiB since they size by count.max(HEAP_VIEWS). Heads-up on overlap: this and #2682 (rebase of #2177) fix the same out-of-heap clamp. #2682 additionally probes the real limit (tier-3 hosts could take the full 2M), reserves an explicit 24,576-slot pairs region plus the 3 reserved slots, and keys the shader cache by the probed limit since translated shaders embed the clamp constant. With HEAP_VIEWS=1_000_000 here, the clamp constant is stable so cache keying is not needed - the tradeoff is #2683's simplicity vs #2682's per-host probing and pairs budget. On a 1M-cap host both produce a 1M heap; they differ in how the capped interior is split (this: ~934K title slots, ~1K pairs; #2682: ~844K titles, 24.5K pairs, 128K dynamic). Worth coordinating in #1633 which approach lands first since they rewrite the same block.
Author
Owner

@⁠Mericas77 on GitHub · 2026-11-25 18:51 UTC · original

Tested on NVIDIA: RTX 4070 (the only adapter), driver 621.01, Windows 11, rustc 1.98.1. Head 19ef8dd.

main 13f91ca on the same machine: victory-gpu 193 passed / 2 failed (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views, the 1,000,000-view cap); victory-shader --lib (with --skip heap_direct_texture_reads_mark_their_heap_index, #2571) 266 / 3 failed (a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros with dispatch failed: E_INVALIDARG, gathers_at_a_level_match_the_hardware).

With this PR:

  • a_heap_buffer_read_where_no_buffer_view_is_reads_zeros now passes on NVIDIA hardware, and the two victory-gpu heap-cap tests pass too.
  • victory-shader: 267 passed, 2 failed. The two left are unchanged from main and outside this PR: a_heap_buffer_read_by_element_takes_the_views_stride (the structured-view stride, #2178) and gathers_at_a_level_match_the_hardware.
  • victory-gpu: 194 passed, 1 failed: frame::tests::waits_end_on_ticks_and_count_frames (frame.rs:231, left 0, right 1). This PR doesn't touch frame.rs, and the test passed on main and on other branches in the same session, so it looks like a timing flake rather than this change. I only ran it once.

So on NVIDIA this fixes 3 of the 5 known hardware failures. #2682 fixes the same three on this machine, with a runtime probe of the host's heap size instead of a fixed 1,000,000. No game data; the title was not run.

AI-assisted.

**@⁠Mericas77** on GitHub · 2026-11-25 18:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7171496602) Tested on NVIDIA: RTX 4070 (the only adapter), driver 621.01, Windows 11, rustc 1.98.1. Head `19ef8dd`. `main` `13f91ca` on the same machine: `victory-gpu` 193 passed / 2 failed (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`, the 1,000,000-view cap); `victory-shader --lib` (with `--skip heap_direct_texture_reads_mark_their_heap_index`, #2571) 266 / 3 failed (`a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` with `dispatch failed: E_INVALIDARG`, `gathers_at_a_level_match_the_hardware`). With this PR: - `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` now **passes on NVIDIA hardware**, and the two `victory-gpu` heap-cap tests pass too. - `victory-shader`: 267 passed, 2 failed. The two left are unchanged from `main` and outside this PR: `a_heap_buffer_read_by_element_takes_the_views_stride` (the structured-view stride, #2178) and `gathers_at_a_level_match_the_hardware`. - `victory-gpu`: 194 passed, 1 failed: `frame::tests::waits_end_on_ticks_and_count_frames` (`frame.rs:231`, left 0, right 1). This PR doesn't touch `frame.rs`, and the test passed on `main` and on other branches in the same session, so it looks like a timing flake rather than this change. I only ran it once. So on NVIDIA this fixes 3 of the 5 known hardware failures. #2682 fixes the same three on this machine, with a runtime probe of the host's heap size instead of a fixed 1,000,000. No game data; the title was not run. AI-assisted.
Author
Owner

@⁠welisonzika14-jpg on GitHub · 2026-11-25 19:08 UTC · original

For the limit question in @⁠DrDarkDK's review: the RTX 5070 (Blackwell, driver 621.24) has the same cap as the 4070 Ti. A standalone CreateDescriptorHeap probe (binary search 1..2^24) gives exactly 1,000,000 for a shader-visible CBV/SRV/UAV heap; 1,000,001, 1<<20 and 1<<21 return E_INVALIDARG. Non-visible heaps take every size up to 2^24, and the shader-visible sampler heap stops at 4,080. WARP takes 2^21. Full table and the probe code: #1744

So on these NVIDIA cards the raw null slots at 999,997 and 999,998 sit at the very top of the largest heap the driver allows, which is why the reserve has to hold on every allocation path.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

**@⁠welisonzika14-jpg** on GitHub · 2026-11-25 19:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7171880470) For the limit question in @⁠DrDarkDK's review: the RTX 5070 (Blackwell, driver 621.24) has the same cap as the 4070 Ti. A standalone `CreateDescriptorHeap` probe (binary search 1..2^24) gives exactly **1,000,000** for a shader-visible CBV/SRV/UAV heap; 1,000,001, 1<<20 and 1<<21 return `E_INVALIDARG`. Non-visible heaps take every size up to 2^24, and the shader-visible sampler heap stops at 4,080. WARP takes 2^21. Full table and the probe code: https://git.gtahub.st/github/Marvisak--VIctory/issues/1744 So on these NVIDIA cards the raw null slots at 999,997 and 999,998 sit at the very top of the largest heap the driver allows, which is why the reserve has to hold on every allocation path. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:19 UTC · original

Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + dxil.dll verification and code review of 19ef8dd (on 13f91ca):

Verification (rustc 1.98.1 MSVC, Windows SDK 10.0.26100.0 dxil.dll)

  • cargo clippy --locked -p victory-gpu -p victory-shader --all-targets -- -D warnings (and --features diagnostics): 0 warnings; cargo xtask policy: 184 files ok.
  • RTX 5090: cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1 -> 198 passed, 0 failed, 1 ignored (fixes the 2 pre-existing #1744 1M-cap unit tests).
  • WARP (VICTORY_D3D12_WARP=1): 198 passed, 0 failed, 1 ignored.
  • victory-shader: emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros passes with dxil.dll active.

Bugs Found in Code Review

  1. Heap sizes count ∈ [737_857, 934_464] still place NULL_BUFFER_VIEW (999_998) and shader clamp (999_999) out of bounds or inside dynamic slots on 1M-capped GPUs:
    • For e.g. count = 800_000 on RTX 5090, make((800_000 + 262_144).max(1_000_000)) fails, and the fallback make(count + MIN_DYNAMIC) (make(865_536)) succeeds without .max(views). The resulting heap has only 865_536 slots while NULL_BUFFER_VIEW = 999_998 and the shader clamp 999_999 remain past the end of the heap (no null buffer views initialized, pairs = 0, out-of-bounds descriptor access / device removal).
    • At count = 934_464 (1_000_000 - 65_536), make(1_000_000) succeeds with count + extra = 1_000_000, placing NULL_BUFFER_VIEW = 999_998 directly inside the live dynamic slot range [934_464..1_000_000).
  2. Breaks > 1M title heaps on Tier-3 GPUs and WARP (which support 2_097_152 slots):
    • Lowering the global constant HEAP_VIEWS from 1 << 21 to 1_000_000 forces shaders on Tier-3 hardware and WARP to clamp all indices to 999_999 even when HostHeap::new creates > 1M slots (e.g. 1_507_328 for a 1_245_184-slot title heap). Worse, because NULL_BUFFER_VIEW (999_998) < count + extra, null buffer views are never created at 999_997/999_998 — buffer_guard redirects guarded buffer reads straight onto live title slots 999_997/999_998!
  3. Bindless collision with dynamic slots when capped: title indices in [934_464..999_997) still land inside live dynamic/pair slots rather than a null slot, and NULL_RESERVE = 1024 leaves very little room for pairs before encroaching on the 64_512 dynamic slots.

Compare with #2682 (runtime device-limit probing) and #2650 (runtime probing + sparse VIEW_BLOCKS remapping, mutually exclusive with both #2682 and #2683).

**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7172134411) Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + `dxil.dll` verification and code review of `19ef8dd` (on `13f91ca`): ### Verification (`rustc 1.98.1` MSVC, Windows SDK `10.0.26100.0` `dxil.dll`) - `cargo clippy --locked -p victory-gpu -p victory-shader --all-targets -- -D warnings` (and `--features diagnostics`): **0 warnings**; `cargo xtask policy`: **184 files ok**. - **RTX 5090:** `cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1` -> **198 passed, 0 failed, 1 ignored** (fixes the 2 pre-existing #1744 1M-cap unit tests). - **WARP (`VICTORY_D3D12_WARP=1`):** **198 passed, 0 failed, 1 ignored**. - **`victory-shader`:** `emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` passes with `dxil.dll` active. ### Bugs Found in Code Review 1. **Heap sizes `count ∈ [737_857, 934_464]` still place `NULL_BUFFER_VIEW` (`999_998`) and shader clamp (`999_999`) out of bounds or inside dynamic slots on 1M-capped GPUs:** - For e.g. `count = 800_000` on RTX 5090, `make((800_000 + 262_144).max(1_000_000))` fails, and the fallback `make(count + MIN_DYNAMIC)` (`make(865_536)`) succeeds **without `.max(views)`**. The resulting heap has only `865_536` slots while `NULL_BUFFER_VIEW = 999_998` and the shader clamp `999_999` remain past the end of the heap (no null buffer views initialized, `pairs = 0`, out-of-bounds descriptor access / device removal). - At `count = 934_464` (`1_000_000 - 65_536`), `make(1_000_000)` succeeds with `count + extra = 1_000_000`, placing `NULL_BUFFER_VIEW = 999_998` directly inside the live dynamic slot range `[934_464..1_000_000)`. 2. **Breaks `> 1M` title heaps on Tier-3 GPUs and WARP (which support `2_097_152` slots):** - Lowering the global constant `HEAP_VIEWS` from `1 << 21` to `1_000_000` forces shaders on Tier-3 hardware and WARP to clamp all indices to `999_999` even when `HostHeap::new` creates `> 1M` slots (e.g. `1_507_328` for a `1_245_184`-slot title heap). Worse, because `NULL_BUFFER_VIEW (999_998) < count + extra`, null buffer views are never created at `999_997`/`999_998` — `buffer_guard` redirects guarded buffer reads straight onto live title slots `999_997`/`999_998`! 3. **Bindless collision with dynamic slots when capped:** title indices in `[934_464..999_997)` still land inside live dynamic/pair slots rather than a null slot, and `NULL_RESERVE = 1024` leaves very little room for `pairs` before encroaching on the `64_512` dynamic slots. Compare with #2682 (runtime device-limit probing) and #2650 (runtime probing + sparse `VIEW_BLOCKS` remapping, mutually exclusive with both #2682 and #2683).
Author
Owner

@⁠pes7 on GitHub · 2026-11-25 19:34 UTC · original

Both points are right, and the second one is a real hole in what I wrote: I reserved the top of the heap only in the capped path, so in the two successful paths (count + DYNAMIC, count + MIN_DYNAMIC) the null slots at 999 997/999 998 are inside the dynamic range - the guard null > count + extra rejects them, and the clamp at HEAP_VIEWS - 1 then names a slot that either is dynamic (a written descriptor read as a null) or, when the heap ends below 1 000 000, is outside it again. Your probe numbers (1 000 000 accepted, 1 196 608 rejected; 737 856 + 262 144 = 1 000 000) are exactly the boundary I should have handled.

Fix in progress on this branch: every successful layout keeps NULL_RESERVE slots free at the top (extra = min(extra, total - count - NULL_RESERVE)), so null > count + extra && null < total holds for all three paths, and the tests at 737 856 and 934 464 title slots assert the two raw null views are installed and that no dynamic slot reaches them. I will push it here rather than opening another PR.

**@⁠pes7** on GitHub · 2026-11-25 19:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7172478459) Both points are right, and the second one is a real hole in what I wrote: I reserved the top of the heap only in the *capped* path, so in the two successful paths (`count + DYNAMIC`, `count + MIN_DYNAMIC`) the null slots at 999 997/999 998 are inside the *dynamic* range - the guard `null > count + extra` rejects them, and the clamp at `HEAP_VIEWS - 1` then names a slot that either is dynamic (a written descriptor read as a null) or, when the heap ends below 1 000 000, is outside it again. Your probe numbers (1 000 000 accepted, 1 196 608 rejected; 737 856 + 262 144 = 1 000 000) are exactly the boundary I should have handled. Fix in progress on this branch: every successful layout keeps `NULL_RESERVE` slots free at the top (`extra = min(extra, total - count - NULL_RESERVE)`), so `null > count + extra && null < total` holds for all three paths, and the tests at 737 856 and 934 464 title slots assert the two raw null views are installed and that no dynamic slot reaches them. I will push it here rather than opening another PR.
Author
Owner

@⁠pes7 on GitHub · 2026-11-25 19:38 UTC · original

Pushed in 541a320. Every layout now keeps the top of the heap free:

let extra = extra.min(total.saturating_sub(count).saturating_sub(NULL_RESERVE));

so count + extra ends NULL_RESERVE slots below the end of the heap that was actually made, and the guard null > count + extra && null < total holds in all three paths - the capped one (which already had it) and the two you measured on the 4070 Ti (737 856 title views with DYNAMIC, 934 464 with MIN_DYNAMIC, both on a 1 000 000-slot heap: dynamic ranges now end at 998 976).

cargo build --release, cargo clippy -p victory-gpu --all-targets -- -D warnings, cargo test -p victory-gpu all clean.

Not done yet, and I would rather say it than imply otherwise: the tests at those two title-count boundaries. They need a heap of 1 000 000 descriptors and a title-count of 737 856, which is 32 MB of descriptor heap per case; descriptor::host has no test harness that makes heaps today, and I do not want to land one built in a hurry. If you want them before merge, say so and I will add a small harness (HostHeap::new with a given count and total, then assert the two raw null views are installed and that the dynamic ring never returns 999 997/999 998) - the shape of the test is clear, it is the plumbing that needs care.

**@⁠pes7** on GitHub · 2026-11-25 19:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7172575994) Pushed in 541a320. Every layout now keeps the top of the heap free: ```rust let extra = extra.min(total.saturating_sub(count).saturating_sub(NULL_RESERVE)); ``` so `count + extra` ends `NULL_RESERVE` slots below the end of the heap that was actually made, and the guard `null > count + extra && null < total` holds in all three paths - the capped one (which already had it) and the two you measured on the 4070 Ti (737 856 title views with `DYNAMIC`, 934 464 with `MIN_DYNAMIC`, both on a 1 000 000-slot heap: dynamic ranges now end at 998 976). `cargo build --release`, `cargo clippy -p victory-gpu --all-targets -- -D warnings`, `cargo test -p victory-gpu` all clean. Not done yet, and I would rather say it than imply otherwise: the tests at those two title-count boundaries. They need a heap of 1 000 000 descriptors and a title-count of 737 856, which is 32 MB of descriptor heap per case; `descriptor::host` has no test harness that makes heaps today, and I do not want to land one built in a hurry. If you want them before merge, say so and I will add a small harness (`HostHeap::new` with a given count and total, then assert the two raw null views are installed and that the dynamic ring never returns 999 997/999 998) - the shape of the test is clear, it is the plumbing that needs care.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:01 UTC · original

Checked 541a320 — extra = extra.min(total.saturating_sub(count).saturating_sub(NULL_RESERVE)) fixes the 737_856 and 934_464 exact-1M cases, but one line in the MIN_DYNAMIC fallback still leaves count ∈ [737_857, 934_463] broken on 1M-capped GPUs:

match make(count + MIN_DYNAMIC) {

Take count = 800_000 on a 1,000,000-cap host (views = HEAP_VIEWS = 1_000_000):

  1. make((800_000 + 262_144).max(1_000_000)) = make(1_062_144) fails.
  2. make(count + MIN_DYNAMIC) = make(865_536) succeeds with total = 865_536 (< 1_000_000).
  3. NULL_BUFFER_VIEW is 999_998, so null < total (999_998 < 865_536) is false: the two raw null views are skipped ("no room for the null buffer views..."), and any shader clamping an index to HEAP_VIEWS - 1 = 999_999 still reads past the end of the 865,536-slot heap.

Changing that line to match make((count + MIN_DYNAMIC).max(views)) ensures total >= 1_000_000 across the entire [737_857, 934_464] range (and at count >= 934_465, count + MIN_DYNAMIC > PORTABLE_VIEWS drops cleanly into the capped make(PORTABLE_VIEWS) arm).

Also worth keeping in mind for Tier-3 / WARP hosts (where make(> 1_000_000) succeeds): for count >= 737_857, make((count + DYNAMIC).max(views)) succeeds with count + extra > 1_000_000, so null = 999_998 falls inside [count..count + extra) (or inside [0..count) if count >= 1_000_000), tripping null > count + extra and causing HEAP_VIEWS - 1 clamps to alias a live dynamic/title slot (in addition to capping title indices below 1_000_000 on Tier-3 hardware where 1 << 21 previously worked).

**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7173074561) Checked `541a320` — `extra = extra.min(total.saturating_sub(count).saturating_sub(NULL_RESERVE))` fixes the `737_856` and `934_464` exact-1M cases, **but one line in the `MIN_DYNAMIC` fallback still leaves `count ∈ [737_857, 934_463]` broken on 1M-capped GPUs**: ```rust match make(count + MIN_DYNAMIC) { ``` Take `count = 800_000` on a 1,000,000-cap host (`views = HEAP_VIEWS = 1_000_000`): 1. `make((800_000 + 262_144).max(1_000_000))` = `make(1_062_144)` fails. 2. `make(count + MIN_DYNAMIC)` = `make(865_536)` **succeeds** with `total = 865_536` (`< 1_000_000`). 3. `NULL_BUFFER_VIEW` is `999_998`, so `null < total` (`999_998 < 865_536`) is `false`: the two raw null views are skipped (`"no room for the null buffer views..."`), and any shader clamping an index to `HEAP_VIEWS - 1 = 999_999` still reads past the end of the 865,536-slot heap. Changing that line to `match make((count + MIN_DYNAMIC).max(views))` ensures `total >= 1_000_000` across the entire `[737_857, 934_464]` range (and at `count >= 934_465`, `count + MIN_DYNAMIC > PORTABLE_VIEWS` drops cleanly into the capped `make(PORTABLE_VIEWS)` arm). Also worth keeping in mind for Tier-3 / WARP hosts (where `make(> 1_000_000)` succeeds): for `count >= 737_857`, `make((count + DYNAMIC).max(views))` succeeds with `count + extra > 1_000_000`, so `null = 999_998` falls inside `[count..count + extra)` (or inside `[0..count)` if `count >= 1_000_000`), tripping `null > count + extra` and causing `HEAP_VIEWS - 1` clamps to alias a live dynamic/title slot (in addition to capping title indices below `1_000_000` on Tier-3 hardware where `1 << 21` previously worked).
Author
Owner

@⁠qtLkz on GitHub · 2026-11-25 20:53 UTC · original

Tested on NVIDIA, where the view heap is capped at 1,000,000: RTX 4070 Ti (Ada), driver 621.01, Windows 11 Pro build 26300, Rust 1.98.1 pinned, this PR merged onto main 13f91ca (clean merge). Compared with plain 13f91ca on the same card:

main 13f91ca + this PR
cargo test -p victory-gpu --lib --locked 193 passed, 2 failed 195 passed, 0 failed
cargo test -p victory-shader --lib --locked -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index 267 passed, 3 failed 267 passed, 2 failed

Now passing on NVIDIA:

  • descriptor::host::tests::dynamic_slots_are_held_until_released (was NumDescriptors >= HEAP_VIEWS)
  • memory::tests::lists_share_a_table_and_copies_keep_their_views
  • stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros (was dispatch failed: E_INVALIDARG)

Still failing, as on main, and not touched by this PR: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride and synthetic_tests::gathers_at_a_level_match_the_hardware (#2317).

So of the 5 NVIDIA workspace failures in #2317, this PR clears 3, the heap-cap ones that #2315 was closed for. HostHeap still gets created here, so no "no view heap at all" regression on this card. (heap_direct_texture_reads_mark_their_heap_index was skipped because it crashes the NVIDIA driver on main, #2571; fix in #2596 / #2587.)

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-25 20:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7174336723) Tested on NVIDIA, where the view heap is capped at 1,000,000: RTX 4070 Ti (Ada), driver 621.01, Windows 11 Pro build 26300, Rust 1.98.1 pinned, this PR merged onto main `13f91ca` (clean merge). Compared with plain `13f91ca` on the same card: | | main `13f91ca` | + this PR | |---|---|---| | `cargo test -p victory-gpu --lib --locked` | 193 passed, **2 failed** | **195 passed, 0 failed** | | `cargo test -p victory-shader --lib --locked -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index` | 267 passed, **3 failed** | 267 passed, **2 failed** | Now passing on NVIDIA: - `descriptor::host::tests::dynamic_slots_are_held_until_released` (was `NumDescriptors >= HEAP_VIEWS`) - `memory::tests::lists_share_a_table_and_copies_keep_their_views` - `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` (was `dispatch failed: E_INVALIDARG`) Still failing, as on main, and not touched by this PR: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` and `synthetic_tests::gathers_at_a_level_match_the_hardware` (#2317). So of the 5 NVIDIA workspace failures in #2317, this PR clears 3, the heap-cap ones that #2315 was closed for. HostHeap still gets created here, so no "no view heap at all" regression on this card. (`heap_direct_texture_reads_mark_their_heap_index` was skipped because it crashes the NVIDIA driver on main, #2571; fix in #2596 / #2587.) AI-assisted (Claude).
Author
Owner

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

Automated triage for the maintainers.

Needs work. The direction is right (the clamp must not point past any heap a host can make, and the hardware runs in the comments show three NVIDIA failures going away), but at 541a320 two layouts are still wrong in HostHeap::new (crates/victory-gpu/src/descriptor/host.rs):

  • The MIN_DYNAMIC fallback can make a heap smaller than the clamp. make(count + MIN_DYNAMIC) has no .max(views), so on a 1,000,000-capped host a title count between 737,857 and 934,463 gets a heap of count + 65,536 slots (e.g. 865,536 for 800,000). NULL_BUFFER_VIEW (999,998) is then outside the heap, the null views are not installed, and an index clamped to 999,999 still reads past the end, which is the bug this PR fixes. make((count + MIN_DYNAMIC).max(views)) closes it (as fuzeofficlal pointed out).
  • Hosts that take more than 1,000,000 views (WARP, tier-3) regress. With HEAP_VIEWS = 1_000_000 a title asking for more than that (the reported 1,245,184) gets a 1.5M heap, but its indices are clamped below 1,000,000. NULL_BUFFER_VIEW then lands inside the title range, so the guard refuses the null views and a guarded read takes a live title slot instead of a null one. Either keep the reserve consistent for that case or say clearly that this trade is intended.

What would change the verdict: the fallback fix plus the small heap-layout tests you offered (the 737,856 / 800,000 / 934,464 boundaries, checking that the two null views are installed and that no dynamic slot reaches them). Also note this rewrites the same block as #2682 (now needing a rebase) and #2650; the maintainer will want one of them, not all three.

CI: check passing on this head.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7176169460) <!-- victory-triage v1 head=541a3203f8d237809d93f80ef0d6098e02285ab9 verdict=needs-work at=2026-11-25T22:17:00Z --> Automated triage for the maintainers. **Needs work.** The direction is right (the clamp must not point past any heap a host can make, and the hardware runs in the comments show three NVIDIA failures going away), but at `541a320` two layouts are still wrong in `HostHeap::new` (`crates/victory-gpu/src/descriptor/host.rs`): - **The `MIN_DYNAMIC` fallback can make a heap smaller than the clamp.** `make(count + MIN_DYNAMIC)` has no `.max(views)`, so on a 1,000,000-capped host a title count between 737,857 and 934,463 gets a heap of `count + 65,536` slots (e.g. 865,536 for 800,000). `NULL_BUFFER_VIEW` (999,998) is then outside the heap, the null views are not installed, and an index clamped to 999,999 still reads past the end, which is the bug this PR fixes. `make((count + MIN_DYNAMIC).max(views))` closes it (as fuzeofficlal pointed out). - **Hosts that take more than 1,000,000 views (WARP, tier-3) regress.** With `HEAP_VIEWS = 1_000_000` a title asking for more than that (the reported 1,245,184) gets a 1.5M heap, but its indices are clamped below 1,000,000. `NULL_BUFFER_VIEW` then lands inside the title range, so the guard refuses the null views and a guarded read takes a live title slot instead of a null one. Either keep the reserve consistent for that case or say clearly that this trade is intended. What would change the verdict: the fallback fix plus the small heap-layout tests you offered (the 737,856 / 800,000 / 934,464 boundaries, checking that the two null views are installed and that no dynamic slot reaches them). Also note this rewrites the same block as #2682 (now needing a rebase) and #2650; the maintainer will want one of them, not all three. CI: `check` passing on this head. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠qtLkz on GitHub · 2026-11-25 22:31 UTC · original

The fallback fix and the boundary test asked for in the triage, verified on a capped (1,000,000) NVIDIA heap: RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, on top of this PR's head 541a320.

One commit, cherry-pickable: https://github.com/qtLkz/VIctory/tree/pr2683-null-views

  • HostHeap::new: make(count + MIN_DYNAMIC) becomes make((count + MIN_DYNAMIC).max(views)), as fuzeofficlal suggested.
  • New test descriptor::host::tests::null_buffer_views_stay_in_the_heap_above_the_dynamic_slots: for 737,856 / 800,000 / 934,464 title views, NULL_BUFFER_VIEW is inside the heap and count + dynamic < NULL_BUFFER_VIEW - 1, so both null views get installed and no dynamic slot reaches them.

Before the fix (test only, this PR's head) the test fails on this card, as the triage predicted:

800000 views: null view 999998 past a heap of 865536
test descriptor::host::tests::null_buffer_views_stay_in_the_heap_above_the_dynamic_slots ... FAILED

(737,856 passes even before: 737,856 + DYNAMIC = 1,000,000 exactly, so it takes the first path.)

With the fix: cargo test -p victory-gpu --lib --locked gives 196 passed, 0 failed (the 195 from before plus the new test). Same result twice.

To apply it on your branch:

git fetch https://github.com/qtLkz/VIctory.git pr2683-null-views
git cherry-pick 65e96ec

Not addressed here, and left to you: the second point, about hosts above 1,000,000 (WARP, tier 3) with a title count past HEAP_VIEWS. That's a design choice (keep the reserve consistent, or document the trade), not something this card can test, since it never makes a heap that large.

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-25 22:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7176470695) The fallback fix and the boundary test asked for in the triage, verified on a capped (1,000,000) NVIDIA heap: RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, on top of this PR's head `541a320`. One commit, cherry-pickable: https://github.com/qtLkz/VIctory/tree/pr2683-null-views - `HostHeap::new`: `make(count + MIN_DYNAMIC)` becomes `make((count + MIN_DYNAMIC).max(views))`, as fuzeofficlal suggested. - New test `descriptor::host::tests::null_buffer_views_stay_in_the_heap_above_the_dynamic_slots`: for 737,856 / 800,000 / 934,464 title views, `NULL_BUFFER_VIEW` is inside the heap and `count + dynamic < NULL_BUFFER_VIEW - 1`, so both null views get installed and no dynamic slot reaches them. **Before the fix** (test only, this PR's head) the test fails on this card, as the triage predicted: ``` 800000 views: null view 999998 past a heap of 865536 test descriptor::host::tests::null_buffer_views_stay_in_the_heap_above_the_dynamic_slots ... FAILED ``` (737,856 passes even before: 737,856 + DYNAMIC = 1,000,000 exactly, so it takes the first path.) **With the fix:** `cargo test -p victory-gpu --lib --locked` gives **196 passed, 0 failed** (the 195 from before plus the new test). Same result twice. To apply it on your branch: ``` git fetch https://github.com/qtLkz/VIctory.git pr2683-null-views git cherry-pick 65e96ec ``` Not addressed here, and left to you: the second point, about hosts above 1,000,000 (WARP, tier 3) with a title count past `HEAP_VIEWS`. That's a design choice (keep the reserve consistent, or document the trade), not something this card can test, since it never makes a heap that large. AI-assisted (Claude).
Author
Owner

@⁠KainanP on GitHub · 2026-11-25 22:53 UTC · original

Measured in the #2571 comparison: with this PR, heap_direct_texture_reads_mark_their_heap_index still ends the process with 0xc0000005 on an RTX 4060, so it is not a fix for that crash (judged here only on #2571): #2571 (AI-assisted)

**@⁠KainanP** on GitHub · 2026-11-25 22:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7176914652) Measured in the #2571 comparison: with this PR, `heap_direct_texture_reads_mark_their_heap_index` still ends the process with 0xc0000005 on an RTX 4060, so it is not a fix for that crash (judged here only on #2571): https://git.gtahub.st/github/Marvisak--VIctory/issues/2571 (AI-assisted)
Translated shaders clamp heap indices below `HEAP_VIEWS` (1 000 000), so a
heap shorter than that lets the clamp name a slot the heap does not have. The
small-dynamic-range path still asked for `count + MIN_DYNAMIC` with no floor:
800 000 title views made an 865 536-slot heap, and every index in
865 536..999 999 was out of bounds (review on #2683, from a title count of
737 856..934 463).

The layout decisions are now two pure functions, so the boundaries can be
checked without a GPU:

* `capped_layout(count)` - `Some((slots, dynamic))` when the title's slots
  plus even the small dynamic range do not fit `HEAP_VIEWS`: the capped
  layout, taken on **every** host including tier-3 ones whose heaps are
  larger, so the layout (and the clamp's bound) is the same everywhere and the
  null buffer views keep the top of the heap;
* `small_request(count, views)` - `(count + MIN_DYNAMIC).max(views)`, the heap
  a host that refuses the large dynamic range is asked for: never below the
  clamp.

Tests: `the_capped_layout_and_the_small_range_fit_the_clamp_shaders_use` pins
the review's counts (737 856, 800 000, 934 464 fit; 934 465, 1 000 000,
1 050 000 take the capped layout, whose `slots + dynamic + NULL_RESERVE`
closes inside `HEAP_VIEWS`) and fails on the previous expression (checked by
putting it back: "a heap of 65536 is short of the clamp 1000000");
`a_heap_has_every_slot_shaders_clamp_to` checks the same invariants on a real
host's heap, and skips where no heap can be made.
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 18:14 UTC · original · requested changes

NULL_RESERVE only applies after both allocation attempts fail. On an RTX 4070 Ti (driver 621.01), my standalone D3D12 probe accepted 1,000,000 views and rejected 1,196,608. Those results expose two successful paths in HostHeap::new that skip installing the raw null descriptors:

Requested title views Successful path Dynamic range ends before
737,856 count + DYNAMIC 1,000,000
934,464 count + MIN_DYNAMIC 1,000,000

Both dynamic ranges include the shader’s raw null UAV/SRV slots, 999_997 and 999_998. The initialization guard skips them, and later allocations can reuse them. Could every successful layout reserve the null slots? Tests at both title-count boundaries would cover this.

I verified heap creation on hardware and traced the layout in source. I didn’t run the PR or the title.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-25 18:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#pullrequestreview-6062702575) · **requested changes** `NULL_RESERVE` only applies after both allocation attempts fail. On an RTX 4070 Ti (driver 621.01), my standalone D3D12 probe accepted 1,000,000 views and rejected 1,196,608. Those results expose two successful paths in `HostHeap::new` that skip installing the raw null descriptors: | Requested title views | Successful path | Dynamic range ends before | | ---: | --- | ---: | | 737,856 | `count + DYNAMIC` | 1,000,000 | | 934,464 | `count + MIN_DYNAMIC` | 1,000,000 | Both dynamic ranges include the shader’s raw null UAV/SRV slots, `999_997` and `999_998`. The initialization guard skips them, and later allocations can reuse them. Could every successful layout reserve the null slots? Tests at both title-count boundaries would cover this. I verified heap creation on hardware and traced the layout in source. I didn’t run the PR or the title. *AI-assisted with Codex.*
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 19:50 UTC · original · approved these changes

**@⁠DrDarkDK** on GitHub · 2026-11-25 19:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#pullrequestreview-6063999674) · **approved these changes**
Author
Owner

@⁠pes7 on GitHub · 2026-11-26 13:33 UTC · original

The review's item is done: the small-dynamic-range path asked for count + MIN_DYNAMIC with no floor, so 800 000 title views made an 865 536-slot heap while translated shaders clamp their indices below HEAP_VIEWS = 1 000 000 - every index in 865 536..999 999 was out of bounds. 595994f fixes it.

The >1M case, decided. The capped layout is now taken on every host, tier-3 ones included, as soon as count + MIN_DYNAMIC > PORTABLE_VIEWS:

  • tier-3 heaps are larger than HEAP_VIEWS, so a heap could be made for a title past 934 464 slots - but the shaders clamp to HEAP_VIEWS - 1, so the dynamic slots a list takes above that clamp would be unreachable by any shader. Making the layout uniform costs a title that large some title slots (the ones past 934 464) and keeps, everywhere, the invariant the clamp needs and the null buffer views at the top of the heap. The trade is written down beside the code ("shortcut: descriptors past the limit are left out; a title that reaches them needs remapping"), which is the same sentence the capped path had.
  • #2682/#2650 remain the alternative if runtime probing is preferred over a uniform layout; this PR is the conservative version and does not depend on probing.

The layout is now two pure functions, so the boundaries are testable without a GPU:

function
capped_layout(count) Some((slots, dynamic)) when count + MIN_DYNAMIC > PORTABLE_VIEWS, else None
small_request(count, views) (count + MIN_DYNAMIC).max(views) - the heap asked for when the host refuses the large dynamic range

Tests (cargo test --release -p victory-gpu: all green):

  • the_capped_layout_and_the_small_range_fit_the_clamp_shaders_use - the review's counts 737 856 / 800 000 / 934 464 fit and are asked for at least HEAP_VIEWS; 934 465 / 1 000 000 / 1 050 000 take the capped layout, whose slots + dynamic + NULL_RESERVE closes inside HEAP_VIEWS. Put the previous expression back and it fails with a heap of 65536 is short of the clamp 1000000, so the test does hold the bug.
  • a_heap_has_every_slot_shaders_clamp_to - the same invariants on a heap this host actually makes (every clamped slot exists, count + dynamic + NULL_RESERVE inside the heap, the pairs end inside it), skipped where no heap can be made.

No measured frame-time claim here: this is a correctness fix for capped hosts (the NVIDIA 1M case); on this AMD host the large dynamic range is taken and the capped path is never entered, which is why the host-independent test above exists.

**@⁠pes7** on GitHub · 2026-11-26 13:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7193525648) The review's item is done: the small-dynamic-range path asked for `count + MIN_DYNAMIC` with no floor, so 800 000 title views made an 865 536-slot heap while translated shaders clamp their indices below `HEAP_VIEWS` = 1 000 000 - every index in 865 536..999 999 was out of bounds. `595994f` fixes it. **The >1M case, decided.** The capped layout is now taken on **every** host, tier-3 ones included, as soon as `count + MIN_DYNAMIC > PORTABLE_VIEWS`: - tier-3 heaps are larger than `HEAP_VIEWS`, so a heap *could* be made for a title past 934 464 slots - but the shaders clamp to `HEAP_VIEWS - 1`, so the dynamic slots a list takes above that clamp would be unreachable by any shader. Making the layout uniform costs a title that large some title slots (the ones past 934 464) and keeps, everywhere, the invariant the clamp needs and the null buffer views at the top of the heap. The trade is written down beside the code ("shortcut: descriptors past the limit are left out; a title that reaches them needs remapping"), which is the same sentence the capped path had. - `#2682`/`#2650` remain the alternative if runtime probing is preferred over a uniform layout; this PR is the conservative version and does not depend on probing. **The layout is now two pure functions**, so the boundaries are testable without a GPU: | function | | |---|---| | `capped_layout(count)` | `Some((slots, dynamic))` when `count + MIN_DYNAMIC > PORTABLE_VIEWS`, else `None` | | `small_request(count, views)` | `(count + MIN_DYNAMIC).max(views)` - the heap asked for when the host refuses the large dynamic range | **Tests** (`cargo test --release -p victory-gpu`: all green): - `the_capped_layout_and_the_small_range_fit_the_clamp_shaders_use` - the review's counts 737 856 / 800 000 / 934 464 fit and are asked for at least `HEAP_VIEWS`; 934 465 / 1 000 000 / 1 050 000 take the capped layout, whose `slots + dynamic + NULL_RESERVE` closes inside `HEAP_VIEWS`. Put the previous expression back and it fails with `a heap of 65536 is short of the clamp 1000000`, so the test does hold the bug. - `a_heap_has_every_slot_shaders_clamp_to` - the same invariants on a heap this host actually makes (every clamped slot exists, `count + dynamic + NULL_RESERVE` inside the heap, the pairs end inside it), skipped where no heap can be made. No measured frame-time claim here: this is a correctness fix for capped hosts (the NVIDIA 1M case); on this AMD host the large dynamic range is taken and the capped path is never entered, which is why the host-independent test above exists.
Author
Owner

@⁠qtLkz on GitHub · 2026-11-26 15:35 UTC · original

@⁠pes7 Tested 595994f on a capped NVIDIA heap. Setup: RTX 4070 Ti (Ada), driver 621.01, Windows 11 Pro 26300, Rust 1.98.1. The PR head was tested on its own base 13f91ca, without other PRs.

Your two new tests pass on hardware:

  • descriptor::host::tests::the_capped_layout_and_the_small_range_fit_the_clamp_shaders_use ... ok
  • descriptor::host::tests::a_heap_has_every_slot_shaders_clamp_to ... ok

a_heap_has_every_slot_shaders_clamp_to silently continues when no heap can be made. To check that it really runs here, I added a temporary local eprintln! and reverted it afterwards. Every heap was made on this 1,000,000-capped host:

Title views Heap count dynamic pairs_end
737,856 1,000,000 737,856 261,120 999,997
800,000 1,000,000 800,000 65,536 999,997
934,464 1,000,000 934,464 64,512 999,997
1,050,000 1,000,000 934,464 64,512 999,997

The heap is never shorter than HEAP_VIEWS. The dynamic range always ends at or below 998,976, under both null views (999,997 and NULL_BUFFER_VIEW = 999,998). The 800,000 case, which made an 865,536-slot heap at 541a320, now gets the full 1,000,000. This covers what my test on pr2683-null-views checked, so that branch is no longer needed.

Full suites (cargo test -p <crate> --lib --locked -- --test-threads=1):

  • victory-gpu: 197 passed, 0 failed. This includes dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, which fail on this card without the PR.
  • victory-shader: 267 passed, 2 failed. a_heap_buffer_read_where_no_buffer_view_is_reads_zeros now passes, while it fails with dispatch failed without the PR. The two failures are the known NVIDIA raw-read-through-structured-view issue fixed by #2885, not this PR:
    • stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride ([101, 104, 107, ...] instead of [200, 201, ...])
    • synthetic_tests::gathers_at_a_level_match_the_hardware

emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index was skipped, because it crashes the NVIDIA driver (#2571, fixed by #2596/#2587, not by this PR).

Not tested: the tier-3 / WARP side of the uniform capped layout (this card never makes a heap above 1,000,000), and a merge with current main.

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-26 15:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2683#issuecomment-7196476280) @⁠pes7 Tested `595994f` on a capped NVIDIA heap. Setup: RTX 4070 Ti (Ada), driver 621.01, Windows 11 Pro 26300, Rust 1.98.1. The PR head was tested on its own base `13f91ca`, without other PRs. **Your two new tests pass on hardware:** - `descriptor::host::tests::the_capped_layout_and_the_small_range_fit_the_clamp_shaders_use ... ok` - `descriptor::host::tests::a_heap_has_every_slot_shaders_clamp_to ... ok` `a_heap_has_every_slot_shaders_clamp_to` silently `continue`s when no heap can be made. To check that it really runs here, I added a temporary local `eprintln!` and reverted it afterwards. Every heap was made on this 1,000,000-capped host: | Title views | Heap | `count` | `dynamic` | `pairs_end` | |---:|---:|---:|---:|---:| | 737,856 | 1,000,000 | 737,856 | 261,120 | 999,997 | | 800,000 | 1,000,000 | 800,000 | 65,536 | 999,997 | | 934,464 | 1,000,000 | 934,464 | 64,512 | 999,997 | | 1,050,000 | 1,000,000 | 934,464 | 64,512 | 999,997 | The heap is never shorter than `HEAP_VIEWS`. The dynamic range always ends at or below 998,976, under both null views (999,997 and `NULL_BUFFER_VIEW` = 999,998). The 800,000 case, which made an 865,536-slot heap at `541a320`, now gets the full 1,000,000. This covers what my test on `pr2683-null-views` checked, so that branch is no longer needed. **Full suites** (`cargo test -p <crate> --lib --locked -- --test-threads=1`): - victory-gpu: **197 passed, 0 failed**. This includes `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`, which fail on this card without the PR. - victory-shader: **267 passed, 2 failed**. `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` now passes, while it fails with `dispatch failed` without the PR. The two failures are the known NVIDIA raw-read-through-structured-view issue fixed by #2885, not this PR: - `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` (`[101, 104, 107, ...]` instead of `[200, 201, ...]`) - `synthetic_tests::gathers_at_a_level_match_the_hardware` `emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index` was skipped, because it crashes the NVIDIA driver (#2571, fixed by #2596/#2587, not by this PR). Not tested: the tier-3 / WARP side of the uniform capped layout (this card never makes a heap above 1,000,000), and a merge with current `main`. AI-assisted (Claude).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2683/head:github-bot/gh-2683'
git switch 'github-bot/gh-2683'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2683'
git switch 'github-bot/gh-2683'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2683'
git switch 'github-bot/gh-2683'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2683'
git switch 'main'
git merge --squash 'github-bot/gh-2683'
git switch 'main'
git merge --ff-only 'github-bot/gh-2683'
git switch 'main'
git merge 'github-bot/gh-2683'
git push origin 'main'
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!2683
No description provided.