GPU and shaders: keep clamp and null views within capped heaps (rebased #2177) #2680

Closed
SinisterRob wants to merge 2 commits from upstream-pr/2682 into main
SinisterRob commented 2026-11-25 18:05:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SinisterRob on 2026-11-25T18:05:24Z.


Current main fails the missing-buffer shader test on an RX 7900 GRE under Wine/RADV. The test asks for 2,097,152 shader-visible views and the device rejects that allocation. The device accepts 1,000,000. The translated shader's clamp and null-buffer indices also assume the larger heap.

This carries #2177 at d15c68b onto current main and preserves its author and commit. I resolved the conflict in descriptor/host.rs by budgeting the title slots, dynamic slots and view pairs against the same probed limit used by translation. Both dynamic ranges leave room for view pairs and the three slots reserved at the end of the heap. The host keeps a separate shader cache for the probed limit.

The allocation regression exercises 800,000 and 1,245,184 requested title views and checks the actual heap size, first view pair and null-view boundary. On the RX 7900 GRE:

Requested Allocated Title slots Dynamic slots First view pair Null SRV
800,000 1,000,000 800,000 65,536 865,536 999,998
1,245,184 1,000,000 844,349 131,072 975,421 999,998

On this branch, 22 descriptor, title-memory and shader-cache tests passed under Wine 11.22 with RADV and vkd3d-proton. The missing-buffer shader returned all 32 expected zeros on hardware. The capped layout still mirrors only the title slots that fit. No title run or game data. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6610650415 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2682). Originally posted by [SinisterRob](https://github.com/SinisterRob) on 2026-11-25T18:05:24Z. --- Current main fails the missing-buffer shader test on an RX 7900 GRE under Wine/RADV. The test asks for 2,097,152 shader-visible views and the device rejects that allocation. The device accepts 1,000,000. The translated shader's clamp and null-buffer indices also assume the larger heap. This carries #2177 at `d15c68b` onto current main and preserves its author and commit. I resolved the conflict in `descriptor/host.rs` by budgeting the title slots, dynamic slots and view pairs against the same probed limit used by translation. Both dynamic ranges leave room for view pairs and the three slots reserved at the end of the heap. The host keeps a separate shader cache for the probed limit. The allocation regression exercises 800,000 and 1,245,184 requested title views and checks the actual heap size, first view pair and null-view boundary. On the RX 7900 GRE: | Requested | Allocated | Title slots | Dynamic slots | First view pair | Null SRV | |---:|---:|---:|---:|---:|---:| | 800,000 | 1,000,000 | 800,000 | 65,536 | 865,536 | 999,998 | | 1,245,184 | 1,000,000 | 844,349 | 131,072 | 975,421 | 999,998 | On this branch, 22 descriptor, title-memory and shader-cache tests passed under Wine 11.22 with RADV and vkd3d-proton. The missing-buffer shader returned all 32 expected zeros on hardware. The capped layout still mirrors only the title slots that fit. No title run or game data. AI-assisted.
Vedoxdev123 commented 2026-11-25 19:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Vedoxdev123 on 2026-11-25T18:14:58Z.


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

  • cargo test -p victory-gpu --lib: 196 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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7170648215 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2682#issuecomment-7170648215). Originally posted by [Vedoxdev123](https://github.com/Vedoxdev123) on 2026-11-25T18:14:58Z. --- **RTX 4060 test (AI-assisted)** Windows 64-bit, Ryzen 5 5600X, GeForce RTX 4060 (8 GB). - `cargo test -p victory-gpu --lib`: **196 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.
kotekompotek commented 2026-11-25 19:06:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T18:46:20Z.


Well-constructed: the probe is cached (OnceLock), hostless paths (offline translate, no-GPU tests) fall back to HEAP_VIEWS so their output keeps today's key, and the shader-cache key covers heap_views only when it differs - so cached translates stay valid on 2M-capable hosts while 1M hosts retranslate with their own clamp. Ordering is safe too: host_shader() settles build() before translating, so the atomic is set before any translation that would bake the wrong constant.

Note the overlap with #2683: same root fix (clamp must not exceed the heap). This one is more general (probing, explicit CAPPED_PAIRS budget, bigger capped dynamic), that one is a small constant change; they rewrite the same HostHeap::new block so whichever lands second needs a rebase. One edge in the probe: [2M, 1<<20, 1M] returns 1M even if the host could only take, say, 500K - such hosts don't exist for shader-visible CBV_SRV_UAV on any shipping tier, so fine, but the fallback after all-probes-fail could equally return a smaller safe number.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171376352 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2682#issuecomment-7171376352). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T18:46:20Z. --- Well-constructed: the probe is cached (OnceLock), hostless paths (offline translate, no-GPU tests) fall back to HEAP_VIEWS so their output keeps today's key, and the shader-cache key covers heap_views only when it differs - so cached translates stay valid on 2M-capable hosts while 1M hosts retranslate with their own clamp. Ordering is safe too: host_shader() settles build() before translating, so the atomic is set before any translation that would bake the wrong constant. Note the overlap with #2683: same root fix (clamp must not exceed the heap). This one is more general (probing, explicit CAPPED_PAIRS budget, bigger capped dynamic), that one is a small constant change; they rewrite the same HostHeap::new block so whichever lands second needs a rebase. One edge in the probe: [2M, 1<<20, 1M] returns 1M even if the host could only take, say, 500K - such hosts don't exist for shader-visible CBV_SRV_UAV on any shipping tier, so fine, but the fallback after all-probes-fail could equally return a smaller safe number.
Mericas77 commented 2026-11-25 19:06:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Mericas77 on 2026-11-25T18:51:08Z.


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

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:

  • victory-gpu: 196 passed, 0 failed. Both heap-cap failures are gone, and larger_heaps_leave_room_for_pairs_and_null_views passes.
  • victory-shader: 267 passed, 2 failed. a_heap_buffer_read_where_no_buffer_view_is_reads_zeros now passes on NVIDIA hardware (no more E_INVALIDARG at dispatch).
  • The two left are unchanged from main and outside this PR: a_heap_buffer_read_by_element_takes_the_views_stride (hardware reads [101, 104, 107, …, 131, then 0s] instead of [200..231], the structured-view stride, #2178) and gathers_at_a_level_match_the_hardware.

So on NVIDIA this fixes 3 of the 5 known hardware failures, which complements the AMD/Wine numbers in the description. #2683 goes after the same problem with a fixed HEAP_VIEWS = 1,000,000. I ran it on the same machine and it fixes the same three tests, so this branch's runtime probe gives the same result on NVIDIA while keeping the 2^21 heap on hosts that accept it. No game data; the title was not run.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171490891 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2682#issuecomment-7171490891). Originally posted by [Mericas77](https://github.com/Mericas77) on 2026-11-25T18:51:08Z. --- Tested on NVIDIA: RTX 4070 (the only adapter), driver 621.01, Windows 11, rustc 1.98.1. Head `b53e4c6`. `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: - `victory-gpu`: **196 passed, 0 failed**. Both heap-cap failures are gone, and `larger_heaps_leave_room_for_pairs_and_null_views` passes. - `victory-shader`: 267 passed, **2 failed**. `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` now **passes on NVIDIA hardware** (no more `E_INVALIDARG` at dispatch). - The two left are unchanged from `main` and outside this PR: `a_heap_buffer_read_by_element_takes_the_views_stride` (hardware reads `[101, 104, 107, …, 131, then 0s]` instead of `[200..231]`, the structured-view stride, #2178) and `gathers_at_a_level_match_the_hardware`. So on NVIDIA this fixes 3 of the 5 known hardware failures, which complements the AMD/Wine numbers in the description. #2683 goes after the same problem with a fixed `HEAP_VIEWS = 1,000,000`. I ran it on the same machine and it fixes the same three tests, so this branch's runtime probe gives the same result on NVIDIA while keeping the 2^21 heap on hosts that accept it. No game data; the title was not run. AI-assisted.
Vedoxdev123 commented 2026-11-25 19:06:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Vedoxdev123 on 2026-11-25T18:57:48Z.


RTX 4060 test (AI-assisted)
Windows 64-bit, Ryzen 5 5600X, GeForce RTX 4060 (8 GB), on main 13f91ca + this PR (b53e4c6).

  • emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros: fails on main (hardware: dispatch failed: The parameter is incorrect.), passes with this PR.
  • cargo test -p victory-gpu --lib: 196 passed, 0 failed, 1 ignored (main: 193 passed, 2 failed).
  • cargo test -p victory-shader --lib with --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index (it crashes the process on main, #2571): 267 passed, 2 failed, 3 ignored (main: 266 passed, 3 failed). The 2 left are a_heap_buffer_read_by_element_takes_the_views_stride and gathers_at_a_level_match_the_hardware.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7171637606 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2682#issuecomment-7171637606). Originally posted by [Vedoxdev123](https://github.com/Vedoxdev123) on 2026-11-25T18:57:48Z. --- **RTX 4060 test (AI-assisted)** Windows 64-bit, Ryzen 5 5600X, GeForce RTX 4060 (8 GB), on `main` `13f91ca` + this PR (`b53e4c6`). - `emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`: fails on `main` (`hardware: dispatch failed: The parameter is incorrect.`), **passes with this PR**. - `cargo test -p victory-gpu --lib`: **196 passed, 0 failed, 1 ignored** (`main`: 193 passed, 2 failed). - `cargo test -p victory-shader --lib` with `--skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index` (it crashes the process on `main`, #2571): **267 passed, 2 failed, 3 ignored** (`main`: 266 passed, 3 failed). The 2 left are `a_heap_buffer_read_by_element_takes_the_views_stride` and `gathers_at_a_level_match_the_hardware`.
fuzeofficlal commented 2026-11-25 20:06:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:19:16Z.


Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + dxil.dll verification and code review of b53e4c6 (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 (1M view-heap cap): cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1 -> 199 passed, 0 failed, 1 ignored. Fixes both pre-existing #1744 baseline failures (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views); larger_heaps_leave_room_for_pairs_and_null_views confirmed slots 1000000, title slots 844349, dynamic 131072, first pair 975421, null SRV 999998.
  • WARP (VICTORY_D3D12_WARP=1): 199 passed, 0 failed, 1 ignored (slots 2097152, title slots 1245184, dynamic 262144, first pair 1507328, null SRV 2097150).
  • victory-shader: emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros passes on both RTX 5090 and WARP with dxil.dll active.

Code Review Notes

  • Bindless index collision with dynamic / pair slots on capped heaps: when a title heap exceeds 909_885 slots (e.g. 1_245_184) on a 1M-capped host, kept = 844_349, live dynamic table slots occupy [844_349..975_421), and live title-memory pairs occupy [975_421..999_997). Because translated shaders clamp heap indices to views - 1 = 999_999, any bindless title index in [844_349..999_997) will not clamp to a null descriptor — it will read live dynamic descriptors or title-memory pairs (whose non-zero stride also bypasses buffer_guard). In addition, HostHeap::view_addresses still allocates self.count * 16 bytes rather than covering up to views.
  • Minor notes: HOST_HEAP_VIEWS is a process-global atomic (rather than #[cfg(test)] thread_local, so stride_tests sets it once from Host::new(false) across the hardware+WARP loop); and dynamic-slot allocation is non-monotonic around the cap (count = 900_000 gets 65_536 dynamic slots while count = 910_000 truncates to 844_349 and gets 131_072).
  • Comparison with #2650 / #2683: all three are mutually exclusive (git merge-tree conflicts in descriptor/host.rs and emit/shader.rs). #2682 preserves full 2M support on Tier-3/WARP (unlike #2683), while #2650's sparse VIEW_BLOCKS table also isolates dynamic/pair slots and reaches sparse title views past 844K (once its sync_slots bug is fixed).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7172133717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2682#issuecomment-7172133717). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T19:19:16Z. --- Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + `dxil.dll` verification and code review of `b53e4c6` (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 (1M view-heap cap):** `cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1` -> **199 passed, 0 failed, 1 ignored**. Fixes both pre-existing #1744 baseline failures (`dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`); `larger_heaps_leave_room_for_pairs_and_null_views` confirmed `slots 1000000, title slots 844349, dynamic 131072, first pair 975421, null SRV 999998`. - **WARP (`VICTORY_D3D12_WARP=1`):** **199 passed, 0 failed, 1 ignored** (`slots 2097152, title slots 1245184, dynamic 262144, first pair 1507328, null SRV 2097150`). - **`victory-shader`:** `emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` passes on both RTX 5090 and WARP with `dxil.dll` active. ### Code Review Notes - **Bindless index collision with dynamic / pair slots on capped heaps:** when a title heap exceeds `909_885` slots (e.g. `1_245_184`) on a 1M-capped host, `kept = 844_349`, live dynamic table slots occupy `[844_349..975_421)`, and live title-memory `pairs` occupy `[975_421..999_997)`. Because translated shaders clamp heap indices to `views - 1 = 999_999`, any bindless title index in `[844_349..999_997)` will not clamp to a null descriptor — it will read live dynamic descriptors or title-memory pairs (whose non-zero stride also bypasses `buffer_guard`). In addition, `HostHeap::view_addresses` still allocates `self.count * 16` bytes rather than covering up to `views`. - **Minor notes:** `HOST_HEAP_VIEWS` is a process-global atomic (rather than `#[cfg(test)] thread_local`, so `stride_tests` sets it once from `Host::new(false)` across the hardware+WARP loop); and dynamic-slot allocation is non-monotonic around the cap (`count = 900_000` gets `65_536` dynamic slots while `count = 910_000` truncates to `844_349` and gets `131_072`). - **Comparison with #2650 / #2683:** all three are mutually exclusive (`git merge-tree` conflicts in `descriptor/host.rs` and `emit/shader.rs`). #2682 preserves full 2M support on Tier-3/WARP (unlike #2683), while #2650's sparse `VIEW_BLOCKS` table also isolates dynamic/pair slots and reaches sparse title views past `844K` (once its `sync_slots` bug is fixed).
pablogonz12 commented 2026-11-25 20:06:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-25T19:41:19Z.


AMD/RADV offline check of the head commit (no game run).

  • Hardware / stack: RX 9070 XT, Mesa 26.3.1 RADV, GE-Proton11-14; base = origin/main 13f91caee.
  • Method: the 751-program world-shader dump, translated by each tree's own victory-shader --example retranslate, then dxil-spirv (master), spirv-val --target-env vulkan1.3, and a real vkCreateCompute/GraphicsPipelines on RADV (vkpipe, one process per program, so a driver crash or hang is recorded per program rather than stopping the batch).
  • Offline only: pipelines are created, never bound or drawn, so wrong pixels and ISA-level miscompiles are out of reach here.
    Result, base 13f91caee vs head b53e4c6ce: both translate 749 / 751 (the same 2 refused in both: a lane mask read as data is not supported). 0 of the 751 programs' DXIL bytes change, no pipeline result or time differs.

The capped-heap and null-view paths are descriptor-side, and the dump set does not hit them (all 751 keep their DXIL), so offline translation cannot tell main and this branch apart. The unit tests are the evidence; victory-shader's test target does not build on Linux here (Windows validator module), and victory-gpu needs Direct3D, so I could not run them. No objection from this side.

Not tested in a game run; not tested on NVIDIA.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172636081 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2682#issuecomment-7172636081). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-25T19:41:19Z. --- AMD/RADV offline check of the head commit (no game run). - Hardware / stack: RX 9070 XT, Mesa 26.3.1 RADV, GE-Proton11-14; base = `origin/main` 13f91caee. - Method: the 751-program world-shader dump, translated by each tree's own `victory-shader --example retranslate`, then dxil-spirv (master), `spirv-val --target-env vulkan1.3`, and a real `vkCreateCompute/GraphicsPipelines` on RADV (`vkpipe`, one process per program, so a driver crash or hang is recorded per program rather than stopping the batch). - Offline only: pipelines are created, never bound or drawn, so wrong pixels and ISA-level miscompiles are out of reach here. **Result, base 13f91caee vs head b53e4c6ce:** both translate **749 / 751** (the same 2 refused in both: `a lane mask read as data is not supported`). **0 of the 751** programs' DXIL bytes change, no pipeline result or time differs. The capped-heap and null-view paths are descriptor-side, and the dump set does not hit them (all 751 keep their DXIL), so offline translation cannot tell main and this branch apart. The unit tests are the evidence; `victory-shader`'s test target does not build on Linux here (Windows validator module), and `victory-gpu` needs Direct3D, so I could not run them. No objection from this side. Not tested in a game run; not tested on NVIDIA.
Marvisak commented 2026-11-25 23:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:15:17Z.


Automated triage for the maintainers.

Needs rebase. This branch no longer merges cleanly into main: the conflict is in crates/victory-gpu/src/descriptor/host.rs. No content review was done yet; it will be reviewed once it is rebased onto current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176130374 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2682#issuecomment-7176130374). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:15:17Z. --- <!-- victory-triage v1 head=b53e4c6ce87eefc3ab50504853d385877913568d verdict=needs-rebase at=2026-11-25T22:15:09Z --> Automated triage for the maintainers. **Needs rebase.** This branch no longer merges cleanly into `main`: the conflict is in `crates/victory-gpu/src/descriptor/host.rs`. No content review was done yet; it will be reviewed once it is rebased onto current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-26 06:02:40 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2680
No description provided.