GPU, Shaders: view structured buffers raw on host for NVIDIA heap reads (FIND-11) #2885

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

@⁠jujumoneylol on GitHub · 2026-11-25 23:03 UTC · original
jujumoneylol:fix/find-11-raw-structured-buffers → main · +965 −100 · 11 files · 3 commits · open

Summary

Fixes FIND-11 (tracked in #1633 / #1744): NVIDIA GPUs misread heap-indexed structured buffers when a DXIL raw handle (ByteAddressBuffer, resource kind 11) indexes into a host D3D12 structured buffer descriptor (DXGI_FORMAT_UNKNOWN, StructureByteStride > 0).

Root Cause

In DXIL, annotateHandle(createHandleFromHeap(idx), ResourceProperties) requires a compile-time constant resource kind and StructStrideInBytes. Because heap-indexed buffers have runtime-variable strides (loaded from VIEW_STRIDES), victory-shader lowers heap-indexed buffer accesses through raw handles ((11 | u, 0)) and computes byte = index * view_stride[idx] + offset.

Previously, victory-gpu created host D3D12 structured views (StructureByteStride = S) for structured buffers. On NVIDIA hardware (verified on Turing GTX 1650, matching the RTX 5070 report in #1744), rawBufferLoad(raw_handle, byte_offset, undef) against a structured descriptor divides byte_offset / 4 and uses that as the element index at inner offset 0 — reading [101, 104, 107, 110, ...] instead of [200, 201, 202, ...] for a 12-byte stride buffer with offset:4.

Changes

  • crates/victory-gpu/src/descriptor/host.rs:
    • Represent structured buffer SRVs and UAVs (StructureByteStride > 0, 4-byte-multiple byte length fitting in u32 dwords) as host raw views (DXGI_FORMAT_R32_TYPELESS, FirstElement = offset / 4, NumElements = total_bytes / 4, StructureByteStride = 0, D3D12_BUFFER_{SRV,UAV}_FLAG_RAW), respecting D3D12's 16-byte raw-view alignment (D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT via shadow::for_view(..., 16) in both buffer_srv/buffer_uav and view_copy).
    • Keep the title's original element stride in VIEW_STRIDES via view_stride().
    • Add unit test structured_buffer_views_stay_raw_on_host_and_keep_stride_table verifying host view creation, VIEW_STRIDES preservation, and zero D3D12 debug-layer errors.
  • crates/victory-gpu/src/draw.rs:
    • Update structured_views_off_their_buffers_elements_get_their_own_copy for 16-byte raw-view alignment (2 * 456 = 912 uses the buffer's copy; 456 (8 mod 16) and 100 (4 mod 16) get exact copies).
  • crates/victory-shader/src/emit/lower.rs:
    • Lower table-bound structured buffer loads, stores, and atomics through raw handles ((11 | u, 0)) with explicit byte = index * stride + offset so descriptor kinds match the raw host views across both table-bound and heap-indexed paths.
    • Lower structured buffer getDimensions (Fields::Buffer and Fields::Smem) through raw handles ((11 | u, 0)) and divide the returned byte count by stride (UDiv) to recover the element record count.
  • crates/victory-shader/src/emit/host.rs & diff_tests.rs:
    • Update the test harness's Stride::Structured to create host raw SRVs matching victory-gpu, while adding Stride::PcStructured for DXC-compiled PC reference shaders in diff_tests.
  • crates/victory-shader/src/emit/stride_tests.rs:
    • Add heap_indexed_structured_buffers_with_distinct_strides (multiple distinct strides in one heap on hardware + WARP).
    • Add table_bound_structured_buffer_reads_by_element_and_dimensions (table-bound idxen + offset:4 + num_records via getDimensions on hardware + WARP).

Verification (NVIDIA GeForce GTX 1650 + WARP, Windows 11)

  • Before (on main f3578e3):
    • emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride FAILED on hardware: got [101, 104, 107, 110, 113, 116, 119, 122, 125, 128, 131, 0, ...] instead of [200..231].
  • After (rebased on main 842b0cb):
    • emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride: PASS on both hardware (GTX 1650) and warp.
    • emit::stride_tests::heap_indexed_structured_buffers_with_distinct_strides: PASS on both hardware and warp.
    • emit::stride_tests::table_bound_structured_buffer_reads_by_element_and_dimensions: PASS on both hardware and warp.
    • Full cargo test -p victory-shader --lib: 303 passed (only failure is the pre-existing FIND-9 NVIDIA 1M view-heap cap test a_heap_buffer_read_where_no_buffer_view_is_reads_zeros).
    • Full cargo test -p victory-gpu --lib: 227 passed including 20/20 draw::tests and structured_buffer_views_stay_raw_on_host_and_keep_stride_table with VICTORY_D3D12_DEBUG=1 (only failures are the 2 pre-existing FIND-9 1M view-heap cap tests).
    • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: 0 warnings/errors.
    • cargo check --workspace --all-targets: clean.
    • cargo xtask policy: pass (asset policy: 191 files ok).

Notes

  • Clean-room implementation and synthetic tests only; no game binaries or assets used.
  • AI-assisted (Claude/Gemini-assisted coding, reviewed and hardware-verified locally on GTX 1650 + WARP).
  • Claims coordination: FIND-11 in #1633.
**@⁠jujumoneylol** on GitHub · 2026-11-25 23:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885) `jujumoneylol:fix/find-11-raw-structured-buffers` → `main` · +965 −100 · 11 files · 3 commits · open ## Summary Fixes **FIND-11** (tracked in #1633 / #1744): NVIDIA GPUs misread heap-indexed structured buffers when a DXIL raw handle (`ByteAddressBuffer`, resource kind `11`) indexes into a host D3D12 structured buffer descriptor (`DXGI_FORMAT_UNKNOWN`, `StructureByteStride > 0`). ### Root Cause In DXIL, `annotateHandle(createHandleFromHeap(idx), ResourceProperties)` requires a compile-time constant resource kind and `StructStrideInBytes`. Because heap-indexed buffers have runtime-variable strides (loaded from `VIEW_STRIDES`), `victory-shader` lowers heap-indexed buffer accesses through raw handles (`(11 | u, 0)`) and computes `byte = index * view_stride[idx] + offset`. Previously, `victory-gpu` created host D3D12 **structured** views (`StructureByteStride = S`) for structured buffers. On NVIDIA hardware (verified on Turing GTX 1650, matching the RTX 5070 report in #1744), `rawBufferLoad(raw_handle, byte_offset, undef)` against a structured descriptor divides `byte_offset / 4` and uses that as the element index at inner offset 0 — reading `[101, 104, 107, 110, ...]` instead of `[200, 201, 202, ...]` for a 12-byte stride buffer with `offset:4`. ### Changes - **`crates/victory-gpu/src/descriptor/host.rs`**: - Represent structured buffer SRVs and UAVs (`StructureByteStride > 0`, 4-byte-multiple byte length fitting in `u32` dwords) as host **raw** views (`DXGI_FORMAT_R32_TYPELESS`, `FirstElement = offset / 4`, `NumElements = total_bytes / 4`, `StructureByteStride = 0`, `D3D12_BUFFER_{SRV,UAV}_FLAG_RAW`), respecting D3D12's 16-byte raw-view alignment (`D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT` via `shadow::for_view(..., 16)` in both `buffer_srv`/`buffer_uav` and `view_copy`). - Keep the title's original element stride in `VIEW_STRIDES` via `view_stride()`. - Add unit test `structured_buffer_views_stay_raw_on_host_and_keep_stride_table` verifying host view creation, `VIEW_STRIDES` preservation, and zero D3D12 debug-layer errors. - **`crates/victory-gpu/src/draw.rs`**: - Update `structured_views_off_their_buffers_elements_get_their_own_copy` for 16-byte raw-view alignment (`2 * 456 = 912` uses the buffer's copy; `456` (8 mod 16) and `100` (4 mod 16) get exact copies). - **`crates/victory-shader/src/emit/lower.rs`**: - Lower table-bound structured buffer loads, stores, and atomics through raw handles (`(11 | u, 0)`) with explicit `byte = index * stride + offset` so descriptor kinds match the raw host views across both table-bound and heap-indexed paths. - Lower structured buffer `getDimensions` (`Fields::Buffer` and `Fields::Smem`) through raw handles (`(11 | u, 0)`) and divide the returned byte count by `stride` (`UDiv`) to recover the element record count. - **`crates/victory-shader/src/emit/host.rs` & `diff_tests.rs`**: - Update the test harness's `Stride::Structured` to create host raw SRVs matching `victory-gpu`, while adding `Stride::PcStructured` for DXC-compiled PC reference shaders in `diff_tests`. - **`crates/victory-shader/src/emit/stride_tests.rs`**: - Add `heap_indexed_structured_buffers_with_distinct_strides` (multiple distinct strides in one heap on hardware + WARP). - Add `table_bound_structured_buffer_reads_by_element_and_dimensions` (table-bound `idxen` + `offset:4` + `num_records` via `getDimensions` on hardware + WARP). ## Verification (NVIDIA GeForce GTX 1650 + WARP, Windows 11) - **Before (on `main` `f3578e3`)**: - `emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` **FAILED** on `hardware`: got `[101, 104, 107, 110, 113, 116, 119, 122, 125, 128, 131, 0, ...]` instead of `[200..231]`. - **After (rebased on `main` `842b0cb`)**: - `emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`: **PASS** on both `hardware` (GTX 1650) and `warp`. - `emit::stride_tests::heap_indexed_structured_buffers_with_distinct_strides`: **PASS** on both `hardware` and `warp`. - `emit::stride_tests::table_bound_structured_buffer_reads_by_element_and_dimensions`: **PASS** on both `hardware` and `warp`. - Full `cargo test -p victory-shader --lib`: **303 passed** (only failure is the pre-existing `FIND-9` NVIDIA 1M view-heap cap test `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`). - Full `cargo test -p victory-gpu --lib`: **227 passed** including 20/20 `draw::tests` and `structured_buffer_views_stay_raw_on_host_and_keep_stride_table` with `VICTORY_D3D12_DEBUG=1` (only failures are the 2 pre-existing `FIND-9` 1M view-heap cap tests). - `cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings`: **0 warnings/errors**. - `cargo check --workspace --all-targets`: **clean**. - `cargo xtask policy`: **pass** (`asset policy: 191 files ok`). ## Notes - Clean-room implementation and synthetic tests only; no game binaries or assets used. - AI-assisted (Claude/Gemini-assisted coding, reviewed and hardware-verified locally on GTX 1650 + WARP). - Claims coordination: `FIND-11` in #1633.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:42 +00:00
Author
Owner

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

Verified 41773eb8 on Windows 11 (NVIDIA RTX 5090 Blackwell + WARP + dxil.dll) against main (842b0cb):

Before / After on RTX 5090 (FIND-11 confirmed fixed!)

  • Baseline main (842b0cb): emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride fails deterministically on RTX 5090 (returns [101, 104, 107, ...] instead of [200, 201, ...]).
  • With #2885 (41773eb8): a_heap_buffer_read_by_element_takes_the_views_stride, heap_indexed_structured_buffers_with_distinct_strides, and table_bound_structured_buffer_reads_by_element_and_dimensions all pass on both RTX 5090 and WARP!
  • stride_tests: 9/10 passed on RTX 5090 (only the pre-existing baseline failure a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, which also fails with E_INVALIDARG on 842b0cb on RTX 5090).

Suite & Audit Notes

  • victory-shader: emit::lower::tests 33/33, diff_tests 5/5 passed; victory-gpu: RTX 5090 descriptor::host::tests 15/15 (including structured_buffer_views_stay_raw_on_host_and_keep_stride_table) & draw::tests 20/20, WARP draw::tests 20/20 passed; cargo clippy (default & diagnostics) 0 warnings; cargo xtask policy (191 files ok; emit/lower.rs = 521,447 bytes, 2,841 bytes under 512 KiB).
  • Non-blocking notes: (1) if a table-bound structured view falls back to a native structured descriptor (total_bytes % 4 != 0), the shader side still emits a raw handle (rare in practice since structured strides/totals are almost always 4-byte multiples); (2) touches buffer_srv/buffer_uav in descriptor/host.rs alongside #2873, so landing order will need a small merge resolution.

Great fix for NVIDIA — looks ready to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7177230215) Verified `41773eb8` on Windows 11 (**NVIDIA RTX 5090 Blackwell** + WARP + `dxil.dll`) against `main` (`842b0cb`): ### Before / After on RTX 5090 (FIND-11 confirmed fixed!) - **Baseline `main` (`842b0cb`)**: `emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` fails deterministically on RTX 5090 (returns `[101, 104, 107, ...]` instead of `[200, 201, ...]`). - **With `#2885` (`41773eb8`)**: `a_heap_buffer_read_by_element_takes_the_views_stride`, `heap_indexed_structured_buffers_with_distinct_strides`, and `table_bound_structured_buffer_reads_by_element_and_dimensions` **all pass on both RTX 5090 and WARP**! - `stride_tests`: 9/10 passed on RTX 5090 (only the pre-existing baseline failure `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, which also fails with `E_INVALIDARG` on `842b0cb` on RTX 5090). ### Suite & Audit Notes - `victory-shader`: `emit::lower::tests` 33/33, `diff_tests` 5/5 passed; `victory-gpu`: RTX 5090 `descriptor::host::tests` 15/15 (including `structured_buffer_views_stay_raw_on_host_and_keep_stride_table`) & `draw::tests` 20/20, WARP `draw::tests` 20/20 passed; `cargo clippy` (default & `diagnostics`) 0 warnings; `cargo xtask policy` (`191 files ok`; `emit/lower.rs` = `521,447` bytes, `2,841` bytes under 512 KiB). - Non-blocking notes: (1) if a table-bound structured view falls back to a native structured descriptor (`total_bytes % 4 != 0`), the shader side still emits a raw handle (rare in practice since structured strides/totals are almost always 4-byte multiples); (2) touches `buffer_srv`/`buffer_uav` in `descriptor/host.rs` alongside `#2873`, so landing order will need a small merge resolution. Great fix for NVIDIA — looks ready to merge.
Author
Owner

@⁠alonso49noob on GitHub · 2026-11-26 00:52 UTC · original

RTX 5060 8 GB (Blackwell), driver 621.01, Windows 11, Rust 1.98.1. I compared main 63bcca4 with main + this PR (41773eb), which merges cleanly. Each tree was built in its own target dir. The full shader runs skip the #2571 crash test.

main 63bcca4 + this PR
stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride (x3) fails, [101, 104, 107, …] passes 3 of 3
synthetic_tests::gathers_at_a_level_match_the_hardware (x3) fails, lane 0 [0, 1, 0, 0] passes 3 of 3
the PR's two new stride_tests n/a pass
cargo test -p victory-shader --lib 298 passed, 3 failed 302 passed, 1 failed
cargo test -p victory-gpu --lib 229 passed, 2 failed 230 passed, 2 failed

The gather test is the other fixture named when #2357 was closed, and the reports above don't cover it. It passes here, and this PR doesn't change synthetic_tests.rs. The failures left are the HEAP_VIEWS cap ones, the same as on main: a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views. I saw no new failures.

Unrelated note: descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait failed in 1 of 3 full victory-gpu runs on main. It passed 6 of 6 alone and in every other full run on both trees, so it looks intermittent and not tied to this PR.

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

**@⁠alonso49noob** on GitHub · 2026-11-26 00:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7179206632) RTX 5060 8 GB (Blackwell), driver 621.01, Windows 11, Rust 1.98.1. I compared `main` `63bcca4` with `main` + this PR (`41773eb`), which merges cleanly. Each tree was built in its own target dir. The full shader runs skip the #2571 crash test. | | `main` `63bcca4` | + this PR | |---|---|---| | `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` (x3) | fails, `[101, 104, 107, …]` | **passes 3 of 3** | | `synthetic_tests::gathers_at_a_level_match_the_hardware` (x3) | fails, lane 0 `[0, 1, 0, 0]` | **passes 3 of 3** | | the PR's two new `stride_tests` | n/a | pass | | `cargo test -p victory-shader --lib` | 298 passed, 3 failed | **302 passed, 1 failed** | | `cargo test -p victory-gpu --lib` | 229 passed, 2 failed | 230 passed, 2 failed | The gather test is the other fixture named when #2357 was closed, and the reports above don't cover it. It passes here, and this PR doesn't change `synthetic_tests.rs`. The failures left are the `HEAP_VIEWS` cap ones, the same as on `main`: `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`. I saw no new failures. Unrelated note: `descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait` failed in 1 of 3 full `victory-gpu` runs on `main`. It passed 6 of 6 alone and in every other full run on both trees, so it looks intermittent and not tied to this PR. Written with AI help (Claude Code); the numbers are from runs on my machine.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 03:51 UTC · original

@⁠jujumoneylol I found a WARP regression when a shader writes through one structured view and another shader reads the same records through a view with a different starting offset. The NVIDIA fix for reading the untouched fields also showed up in this comparison.

Wrong words out of 2,400 GeForce RTX 5080, 621.40 Windows WARP, 10.0.26100.10068
Direct parent 842b0cb 2,375 0
This PR, 41773eb 544 544

On this PR, both adapters returned all 1,600 untouched fields and all 160 newly written values read through the writer's own origin. All 544 stale words were reads of a GPU-written field through a different origin. For example, a writer at byte 12 and a reader at byte 24 share 31 records. Reader lane 0 should see the 1 stored by writer lane 1. It saw the initial 0xa1700008. All 31 overlapping records were stale. The last, non-overlapping record kept its correct initial value.

The fixture places 32-element views at byte offsets 0, 12, 24, 36 and 48 in a 432-byte write-watched title GPU buffer. Every access is inside its declared view. Each writer and reader runs in a separate fence-waited submission and schedules the same heap refresh that draw::State::bind uses. There are no intervening CPU writes. Your existing descriptor/stride test still passed on both adapters. The same normal-submit comparison measured 544/2,400 wrong on each adapter on the current #2178 head 319749e. Related alignment and alias results on #2178

For the alignment fallback, the acceptance case I would keep is that the later SRV sees all 31 overlapping writes across differently aligned origins. The test-only commit directly on this PR can be run in a separate checkout with:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2885-fenced-structured-readback
git switch --detach FETCH_HEAD
foreach ($adapter in '0', '1') {
    $env:VICTORY_D3D12_WARP = $adapter
    cargo test -p victory-gpu --all-features --lib --locked gpu_writes_visible_through_overlapping_views -- --ignored --nocapture --test-threads=1
}

Synthetic D3D12 readbacks on Windows. The game and AMD hardware remain untested here. AI-assisted with Codex.

**@⁠steven-seagull27** on GitHub · 2026-11-26 03:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7182084803) @⁠jujumoneylol I found a WARP regression when a shader writes through one structured view and another shader reads the same records through a view with a different starting offset. The NVIDIA fix for reading the untouched fields also showed up in this comparison. | Wrong words out of 2,400 | GeForce RTX 5080, 621.40 | Windows WARP, 10.0.26100.10068 | |---|---:|---:| | Direct parent `842b0cb` | 2,375 | 0 | | This PR, `41773eb` | 544 | 544 | On this PR, both adapters returned all 1,600 untouched fields and all 160 newly written values read through the writer's own origin. All 544 stale words were reads of a GPU-written field through a different origin. For example, a writer at byte 12 and a reader at byte 24 share 31 records. Reader lane 0 should see the `1` stored by writer lane 1. It saw the initial `0xa1700008`. All 31 overlapping records were stale. The last, non-overlapping record kept its correct initial value. The fixture places 32-element views at byte offsets 0, 12, 24, 36 and 48 in a 432-byte write-watched title GPU buffer. Every access is inside its declared view. Each writer and reader runs in a separate fence-waited submission and schedules the same heap refresh that `draw::State::bind` uses. There are no intervening CPU writes. Your existing descriptor/stride test still passed on both adapters. The same normal-submit comparison measured 544/2,400 wrong on each adapter on the current #2178 head `319749e`. [Related alignment and alias results on #2178](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2178) For the alignment fallback, the acceptance case I would keep is that the later SRV sees all 31 overlapping writes across differently aligned origins. The [test-only commit directly on this PR](https://github.com/steven-seagull27/VIctory/commit/8c474d5fcc3f914a67a0070ddc3ec39b6e4d6a47) can be run in a separate checkout with: ```powershell git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2885-fenced-structured-readback git switch --detach FETCH_HEAD foreach ($adapter in '0', '1') { $env:VICTORY_D3D12_WARP = $adapter cargo test -p victory-gpu --all-features --lib --locked gpu_writes_visible_through_overlapping_views -- --ignored --nocapture --test-threads=1 } ``` Synthetic D3D12 readbacks on Windows. The game and AMD hardware remain untested here. AI-assisted with Codex.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:27 UTC · original · edited 2026-11-26 07:23 UTC

Automated triage for the maintainers.

Thanks for e7250c5; both points are addressed. In descriptor/host.rs, buffer_srv/buffer_uav now view structured buffers raw from the preceding 16-byte boundary of the shared copy, with alignment RAW_WORD_ALIGN. The 0-12-byte remainder goes into VIEW_STRIDES bits 28-29, and the shader adds it back (view_raw_bias in emit/lower.rs), so overlapping views share one copy. The overlap fixture shows 0 of 2,400 words wrong on both adapters. Structured views that cannot be made raw are now refused instead of falling back to a structured descriptor. VIEW_STRIDE_BITS shrinks to 28 bits, which still leaves room for any real stride.

Notes for the maintainer: every buffer handle now reads the stride table (a small per-access cost), and lower.rs is about 1.5 KiB under the policy size cap. This replaces the approach in #2178 (open, global toggle, private copies), so only one should land.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7182607857) · edited 2026-11-26 07:23 UTC <!-- victory-triage v1 head=e7250c58df935b77f405159da10413c3f23afac4 verdict=merge-candidate at=2026-11-26T07:23:14Z --> Automated triage for the maintainers. Thanks for `e7250c5`; both points are addressed. In `descriptor/host.rs`, `buffer_srv`/`buffer_uav` now view structured buffers raw from the preceding 16-byte boundary of the shared copy, with alignment `RAW_WORD_ALIGN`. The 0-12-byte remainder goes into `VIEW_STRIDES` bits 28-29, and the shader adds it back (`view_raw_bias` in `emit/lower.rs`), so overlapping views share one copy. The overlap fixture shows 0 of 2,400 words wrong on both adapters. Structured views that cannot be made raw are now refused instead of falling back to a structured descriptor. `VIEW_STRIDE_BITS` shrinks to 28 bits, which still leaves room for any real stride. Notes for the maintainer: every buffer handle now reads the stride table (a small per-access cost), and `lower.rs` is about 1.5 KiB under the policy size cap. This replaces the approach in #2178 (open, global toggle, private copies), so only one should land. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠jujumoneylol on GitHub · 2026-11-26 06:42 UTC · original

Thanks @⁠steven-seagull27, @⁠fyernald, and the triage review — pushed e7250c5 addressing both findings:

1. Overlapping structured views now share one host copy (no private copies for 4-byte-aligned starts)

  • victory-gpu (descriptor/host.rs): Structured buffer SRVs/UAVs now use 4-byte alignment (RAW_WORD_ALIGN = 4) in shadow::for_view and view_align instead of forcing 16-byte private copies. When shadow.offset(start) is 4-byte aligned (not 16-byte aligned), buffer_srv/buffer_uav round FirstElement down to the preceding 16-byte boundary (aligned = offset - bias, NumElements = (total_bytes + bias) / 4), adjust MARK to shadow.mark_entry(start - bias), and store the 0..12-byte start remainder in VIEW_STRIDES bits 28..29 (VIEW_RAW_OFFSET_SHIFT = 28, 2 bits for 0..=3 dwords; VIEW_STRIDE_BITS = (1 << 28) - 1).
  • victory-shader (emit/shader.rs, emit/lower.rs): Record all buffer handles (kinds 10..=12, SRV and UAV) in view_index, add view_raw_bias(h) ((word >> 26) & 0xC) to raw_view offsets for heap-direct and table-bound structured buffers, and subtract it before UDiv in getDimensions so element counts remain exact.
  • Carried @⁠steven-seagull27's overlapping-views fixture (crates/victory-gpu/src/descriptor/overlap_test.rs) directly into the default test suite (skipping cleanly on hosts without SM 6.6).

2. No native structured descriptor fallback behind raw shader handles

  • buffer_srv and buffer_uav now refuse structured views whose byte length is 0, not a multiple of 4, not 4-byte aligned on the host copy, or whose raw dword count overflows u32, rather than falling back to creating a native D3D12 structured descriptor. Covered in structured_buffer_views_stay_raw_on_host_and_keep_stride_table.

Verification (e7250c5, Windows 11, VICTORY_D3D12_DEBUG=1)

Test / Check GeForce GTX 1650 Windows WARP
overlap_test::gpu_writes_visible_through_overlapping_views 0 / 2,400 wrong (PASS, 0 D3D12 errors) 0 / 2,400 wrong (PASS, 0 D3D12 errors)
stride_tests::table_bound_structured_buffer_reads_by_element_and_dimensions (bias=0 & bias=12) PASS PASS
stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride + heap_indexed_structured_buffers_with_distinct_strides PASS PASS
victory-gpu descriptor::host::* + draw::tests (--test-threads=1) 36/37 PASS (only pre-existing FIND-9 dynamic_slots_are_held_until_released) 36/37 PASS (only FIND-9)
victory-shader (stride_tests, diff_tests, lower::tests, waterfall_tests, synthetic_tests) 63/64 PASS (only pre-existing FIND-9 a_heap_buffer_read_where_no_buffer_view_is_reads_zeros) —
cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings (default & --all-features) 0 warnings —
cargo xtask policy pass (192 files ok, lower.rs = 522,717 bytes) —
**@⁠jujumoneylol** on GitHub · 2026-11-26 06:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7184706946) Thanks @⁠steven-seagull27, @⁠fyernald, and the triage review — pushed `e7250c5` addressing both findings: ### 1. Overlapping structured views now share one host copy (no private copies for 4-byte-aligned starts) - **`victory-gpu` (`descriptor/host.rs`)**: Structured buffer SRVs/UAVs now use 4-byte alignment (`RAW_WORD_ALIGN = 4`) in `shadow::for_view` and `view_align` instead of forcing 16-byte private copies. When `shadow.offset(start)` is 4-byte aligned (not 16-byte aligned), `buffer_srv`/`buffer_uav` round `FirstElement` down to the preceding 16-byte boundary (`aligned = offset - bias`, `NumElements = (total_bytes + bias) / 4`), adjust `MARK` to `shadow.mark_entry(start - bias)`, and store the `0..12`-byte start remainder in `VIEW_STRIDES` bits `28..29` (`VIEW_RAW_OFFSET_SHIFT = 28`, 2 bits for `0..=3` dwords; `VIEW_STRIDE_BITS = (1 << 28) - 1`). - **`victory-shader` (`emit/shader.rs`, `emit/lower.rs`)**: Record all buffer handles (kinds `10..=12`, SRV and UAV) in `view_index`, add `view_raw_bias(h)` (`(word >> 26) & 0xC`) to `raw_view` offsets for heap-direct and table-bound structured buffers, and subtract it before `UDiv` in `getDimensions` so element counts remain exact. - Carried @⁠steven-seagull27's overlapping-views fixture (`crates/victory-gpu/src/descriptor/overlap_test.rs`) directly into the default test suite (skipping cleanly on hosts without SM 6.6). ### 2. No native structured descriptor fallback behind raw shader handles - `buffer_srv` and `buffer_uav` now refuse structured views whose byte length is `0`, not a multiple of 4, not 4-byte aligned on the host copy, or whose raw dword count overflows `u32`, rather than falling back to creating a native D3D12 structured descriptor. Covered in `structured_buffer_views_stay_raw_on_host_and_keep_stride_table`. ### Verification (`e7250c5`, Windows 11, `VICTORY_D3D12_DEBUG=1`) | Test / Check | GeForce GTX 1650 | Windows WARP | |---|---|---| | `overlap_test::gpu_writes_visible_through_overlapping_views` | **0 / 2,400 wrong** (PASS, 0 D3D12 errors) | **0 / 2,400 wrong** (PASS, 0 D3D12 errors) | | `stride_tests::table_bound_structured_buffer_reads_by_element_and_dimensions` (`bias=0` & `bias=12`) | **PASS** | **PASS** | | `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` + `heap_indexed_structured_buffers_with_distinct_strides` | **PASS** | **PASS** | | `victory-gpu` `descriptor::host::*` + `draw::tests` (`--test-threads=1`) | **36/37 PASS** (only pre-existing `FIND-9` `dynamic_slots_are_held_until_released`) | **36/37 PASS** (only `FIND-9`) | | `victory-shader` (`stride_tests`, `diff_tests`, `lower::tests`, `waterfall_tests`, `synthetic_tests`) | **63/64 PASS** (only pre-existing `FIND-9` `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`) | — | | `cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings` (default & `--all-features`) | **0 warnings** | — | | `cargo xtask policy` | **pass** (`192 files ok`, `lower.rs` = 522,717 bytes) | — |
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 23:37 UTC · original · reviewed

Correct raw-view rules: R32_TYPELESS + FLAG_RAW is the only legal representation, gated on byte-length divisibility and u32 element count, with the 16-byte FirstElement alignment pushed down into view_align so for_view reserves a conforming copy. Complements #2873's format legalization. LGTM.

**@⁠kotekompotek** on GitHub · 2026-11-25 23:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#pullrequestreview-6066498147) · **reviewed** Correct raw-view rules: R32_TYPELESS + FLAG_RAW is the only legal representation, gated on byte-length divisibility and u32 element count, with the 16-byte FirstElement alignment pushed down into view_align so for_view reserves a conforming copy. Complements #2873's format legalization. LGTM.
Author
Owner

@⁠fyernald on GitHub · 2026-11-26 02:21 UTC · original · approved these changes

Ampere data point: RTX 3080 (617.42), Windows 10 19045, main 63bcca4 + #486 (Agility runtime for the shader tests) + #2596 (#2571), --test-threads=1.

victory-shader --lib victory-gpu --lib
base 298 passed, 4 failed 226 passed, 5 failed
+ #2885 302 passed, 2 failed 227 passed, 5 failed
+ #2885 + #2461 303 passed, 1 failed 230 passed, 3 failed
  • With this PR: a_heap_buffer_read_by_element_takes_the_views_stride and gathers_at_a_level_match_the_hardware pass, along with the new stride tests and structured_buffer_views_stay_raw_on_host_and_keep_stride_table. Nothing new fails.
  • With #2461 as well: the two PRs merge cleanly onto main and with each other, and #2461 clears the heap-cap failures.
    • Shader suite: what's left is pops_wait_loop_exits_immediately_for_inactive_lanes, which needs an SM 6.6 WARP that Windows 10 doesn't have.
    • GPU suite: the three left are the Windows 10 in-box-runtime failures that an Agility opt-in for the GPU test binary removes (see #2878).

So on this card the two together leave no NVIDIA-specific failure.

One scope note: unlike the raw views in #2878, which only apply on NVIDIA, this views structured buffers raw on every host, and getDimensions divides by the stride everywhere. The runs so far are NVIDIA and WARP, so a run on AMD hardware would close that.

@⁠alonso49noob: the intermittent views_bound_while_another_slot_gets_its_texture_do_not_wait on main is a race between tests over the shared WHILE_PREPARING hook from 42ea09f. It's unrelated to this PR, and #2585 fixes it.

**@⁠fyernald** on GitHub · 2026-11-26 02:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#pullrequestreview-6067711791) · **approved these changes** Ampere data point: RTX 3080 (617.42), **Windows 10 19045**, `main` `63bcca4` + #486 (Agility runtime for the shader tests) + #2596 (#2571), `--test-threads=1`. | | `victory-shader --lib` | `victory-gpu --lib` | |---|---|---| | base | 298 passed, 4 failed | 226 passed, 5 failed | | + #2885 | 302 passed, 2 failed | 227 passed, 5 failed | | + #2885 + #2461 | **303 passed, 1 failed** | **230 passed, 3 failed** | - **With this PR:** `a_heap_buffer_read_by_element_takes_the_views_stride` and `gathers_at_a_level_match_the_hardware` pass, along with the new stride tests and `structured_buffer_views_stay_raw_on_host_and_keep_stride_table`. Nothing new fails. - **With #2461 as well:** the two PRs merge cleanly onto `main` and with each other, and #2461 clears the heap-cap failures. - Shader suite: what's left is `pops_wait_loop_exits_immediately_for_inactive_lanes`, which needs an SM 6.6 WARP that Windows 10 doesn't have. - GPU suite: the three left are the Windows 10 in-box-runtime failures that an Agility opt-in for the GPU test binary removes (see #2878). So on this card the two together leave no NVIDIA-specific failure. One scope note: unlike the raw views in #2878, which only apply on NVIDIA, this views structured buffers raw on every host, and `getDimensions` divides by the stride everywhere. The runs so far are NVIDIA and WARP, so a run on AMD hardware would close that. @⁠alonso49noob: the intermittent `views_bound_while_another_slot_gets_its_texture_do_not_wait` on `main` is a race between tests over the shared `WHILE_PREPARING` hook from 42ea09f. It's unrelated to this PR, and #2585 fixes it.
Author
Owner

@⁠fyernald on GitHub · 2026-11-26 04:25 UTC · original · requested changes

Changing my earlier approval. @⁠steven-seagull27's fixture (8c474d5) reproduces exactly on the RTX 3080 (617.42) / Windows 10. Hardware adapter, with an Agility opt-in for the GPU test binary (Windows 10's WARP has no SM 6.6, so no WARP row here):

wrong words / 2,400 RTX 3080
main 63bcca4 + fixture 2,375
#2885 41773eb + fixture 544

All 18 failing reads on this PR are the GPU-written field read through a different origin, as they describe. The pattern also shows the cause. The five origins are bytes 0, 12, 24, 36 and 48. The two that are 16-byte aligned, 0 and 48, see each other's writes: writer 0 → reader 4 and writer 4 → reader 0 are both clean. Every pair involving an origin that isn't 16-byte aligned is stale (29-31 of 32).

That matches the fallback in this PR: a raw view whose start isn't 16-byte aligned gets "a copy of its own bytes", which draw.rs's updated test now asserts for 456 = 8 mod 16. A write through one such copy never reaches another view of the same records. On hosts where structured views read correctly today (WARP: 0 wrong on main, presumably AMD too), that's a regression.

Two shapes that would keep one copy:

  • View raw from the start rounded down to 16 bytes and add the remainder in the shader (the stride table already carries per-view data).
  • Keep the native structured view where the start isn't 16-byte aligned. That still leaves NVIDIA's structured-read problem for those views, but doesn't break the others.

The fixture is a good acceptance test to carry into the PR. All 31 overlapping writes should be visible across differently aligned origins.

**@⁠fyernald** on GitHub · 2026-11-26 04:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#pullrequestreview-6068537336) · **requested changes** Changing my earlier approval. @⁠steven-seagull27's fixture (`8c474d5`) reproduces exactly on the RTX 3080 (617.42) / Windows 10. Hardware adapter, with an Agility opt-in for the GPU test binary (Windows 10's WARP has no SM 6.6, so no WARP row here): | wrong words / 2,400 | RTX 3080 | |---|---| | `main` `63bcca4` + fixture | 2,375 | | #2885 `41773eb` + fixture | 544 | All 18 failing reads on this PR are the GPU-written field read through a different origin, as they describe. The pattern also shows the cause. The five origins are bytes 0, 12, 24, 36 and 48. The two that are 16-byte aligned, **0 and 48, see each other's writes**: writer 0 → reader 4 and writer 4 → reader 0 are both clean. Every pair involving an origin that isn't 16-byte aligned is stale (29-31 of 32). That matches the fallback in this PR: a raw view whose start isn't 16-byte aligned gets "a copy of its own bytes", which `draw.rs`'s updated test now asserts for `456` = 8 mod 16. A write through one such copy never reaches another view of the same records. On hosts where structured views read correctly today (WARP: 0 wrong on `main`, presumably AMD too), that's a regression. Two shapes that would keep one copy: - View raw from the start rounded down to 16 bytes and add the remainder in the shader (the stride table already carries per-view data). - Keep the native structured view where the start isn't 16-byte aligned. That still leaves NVIDIA's structured-read problem for those views, but doesn't break the others. The fixture is a good acceptance test to carry into the PR. All 31 overlapping writes should be visible across differently aligned origins.
Author
Owner

@⁠jujumoneylol on GitHub · 2026-11-26 09:11 UTC · original

Pushed one small cleanup/fix ($sha):

  • Lower::view_raw_bias now reuses the VIEW_STRIDES dword already loaded by Lower::buffer_guard (guarded_stride) instead of reloading VIEW_STRIDES[index] via self.s.view_index.
  • This avoids a redundant root-SRV load on every heap-direct buffer access and prevents an out-of-bounds VIEW_STRIDES[null_buffer_view()] read when uffer_guard redirects a non-buffer slot to the null buffer view on a small VIEW_STRIDES table (caught when testing #2885 stacked with #2461 on GTX 1650 in _heap_buffer_read_where_no_buffer_view_is_reads_zeros, which now passes cleanly).
  • Verified cargo xtask policy (lower.rs 523,185 bytes < 512 KiB), cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings, and overlap_test + structured-buffer descriptor tests on GTX 1650 (VICTORY_D3D12_DEBUG=1).
**@⁠jujumoneylol** on GitHub · 2026-11-26 09:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7187580294) Pushed one small cleanup/fix ($sha): - Lower::view_raw_bias now reuses the VIEW_STRIDES dword already loaded by Lower::buffer_guard (guarded_stride) instead of reloading VIEW_STRIDES[index] via self.s.view_index. - This avoids a redundant root-SRV load on every heap-direct buffer access **and** prevents an out-of-bounds VIEW_STRIDES[null_buffer_view()] read when uffer_guard redirects a non-buffer slot to the null buffer view on a small VIEW_STRIDES table (caught when testing #2885 stacked with #2461 on GTX 1650 in _heap_buffer_read_where_no_buffer_view_is_reads_zeros, which now passes cleanly). - Verified cargo xtask policy (lower.rs 523,185 bytes < 512 KiB), cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings, and overlap_test + structured-buffer descriptor tests on GTX 1650 (VICTORY_D3D12_DEBUG=1).
Author
Owner

@⁠frenziedcoder on GitHub · 2026-11-26 09:13 UTC · original

RTX 5080 (Blackwell), driver 621.40, title runs: with this PR in place of #2464 in the NVIDIA stack, the interior shots draw a character that #2464's tree draws as broken spikes, with no other change in what translates and no device removal in 600 s. For the choice between this PR and #2464 the triage mentions, measured in the title rather than synthetically.

Trees: main 842b0cb + #1906, #2098, #2626, #2628, #2176 (fb99078), #2118 + the local wave32_approx change and BVH-builder hold-back from #2176's thread, and then either #2464 (b9dc4b0) or this PR (e7250c5; #2464 reverted cleanly, this PR merged cleanly). Diag build, VICTORY_D3D12_DRED=1, scripted Enter, 600 s, one run each.

with #2464 with this PR
programs refused (translate --cache) 426 426
pipelines skipped, compute / pixel shader does not translate 219 / 1 219 / 1
programs whose draws were dropped in the run 85 85
host pipelines refused 0 0
device removed in 600 s no no
world's first frame frame 1,268 (52 s) frame 1,346 (56 s)
frame 2,048 reached at 528 s 548 s
interior shot (frames ~1,500–2,048) window and room; where the character stands, spiky dark shards (frames 1,508, 1,748, 2,048) the character drawn whole in front of the window (head, hair, shoulders), room less broken (frames 1,586, 2,048)

The translation counts are identical, so the difference is in how the views are made. My guess is the unaligned structured origins this PR copies to aligned ones and #2464 leaves structured (steven-seagull27's 12/24/36-byte case), but I haven't traced which buffer the character reads.

Synthetic, same tree: emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride passes (it fails on main on this card); a_heap_buffer_read_where_no_buffer_view_is_reads_zeros still fails with dispatch failed: The parameter is incorrect, as on main (the view-heap cap of #1835). victory-gpu overlap tests: 2 passed.

Not tested: 767f228 (pushed after these runs; the view_raw_bias stride-reuse cleanup); more than one run per tree; this PR without the rest of the stack; AMD.

AI use: Claude Code (Claude Opus 5.5) built the trees, ran the title on my machine (sandboxed at Low integrity, game folder read-only), read the logs and frame captures, and wrote this report.

**@⁠frenziedcoder** on GitHub · 2026-11-26 09:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7187619353) **RTX 5080 (Blackwell), driver 621.40, title runs: with this PR in place of #2464 in the NVIDIA stack, the interior shots draw a character that #2464's tree draws as broken spikes, with no other change in what translates and no device removal in 600 s.** For the choice between this PR and #2464 the triage mentions, measured in the title rather than synthetically. **Trees:** `main` `842b0cb` + #1906, #2098, #2626, #2628, #2176 (`fb99078`), #2118 + the local `wave32_approx` change and BVH-builder hold-back from #2176's thread, and then either #2464 (`b9dc4b0`) or this PR (`e7250c5`; #2464 reverted cleanly, this PR merged cleanly). Diag build, `VICTORY_D3D12_DRED=1`, scripted `Enter`, 600 s, one run each. | | with #2464 | with this PR | |---|---|---| | programs refused (`translate --cache`) | 426 | 426 | | pipelines skipped, compute / pixel shader does not translate | 219 / 1 | 219 / 1 | | programs whose draws were dropped in the run | 85 | 85 | | host pipelines refused | 0 | 0 | | device removed in 600 s | no | no | | world's first frame | frame 1,268 (52 s) | frame 1,346 (56 s) | | frame 2,048 reached at | 528 s | 548 s | | interior shot (frames ~1,500–2,048) | window and room; where the character stands, spiky dark shards (frames 1,508, 1,748, 2,048) | **the character drawn whole in front of the window** (head, hair, shoulders), room less broken (frames 1,586, 2,048) | The translation counts are identical, so the difference is in how the views are made. My guess is the unaligned structured origins this PR copies to aligned ones and #2464 leaves structured (steven-seagull27's 12/24/36-byte case), but I haven't traced which buffer the character reads. Synthetic, same tree: `emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` passes (it fails on `main` on this card); `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` still fails with `dispatch failed: The parameter is incorrect`, as on `main` (the view-heap cap of #1835). `victory-gpu` `overlap` tests: 2 passed. **Not tested:** `767f228` (pushed after these runs; the `view_raw_bias` stride-reuse cleanup); more than one run per tree; this PR without the rest of the stack; AMD. *AI use: Claude Code (Claude Opus 5.5) built the trees, ran the title on my machine (sandboxed at Low integrity, game folder read-only), read the logs and frame captures, and wrote this report.*
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 09:48 UTC · original · approved these changes

Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-shader --lib emit::stride_tests:: -- --test-threads=1: 9/10 passed on RTX 5090 — notably a_heap_buffer_read_by_element_takes_the_views_stride now passes on RTX 5090 (fails on clean origin/main), along with both new tests (heap_indexed_structured_buffers_with_distinct_strides and table_bound_structured_buffer_reads_by_element_and_dimensions). The single remaining failure (a_heap_buffer_read_where_no_buffer_view_is_reads_zeros) reproduces identically on clean origin/main.
  • cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 16/16 passed (including overlap_test::gpu_writes_visible_through_overlapping_views and structured_buffer_views_stay_raw_on_host_and_keep_stride_table).
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed.
  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

Great NVIDIA fix (FIND-11): viewing structured buffers raw on the host makes heap-indexed structured buffer reads work cleanly on RTX 5090.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 09:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#pullrequestreview-6071828823) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib emit::stride_tests:: -- --test-threads=1`: **9/10 passed** on RTX 5090 — notably **`a_heap_buffer_read_by_element_takes_the_views_stride` now passes on RTX 5090** (fails on clean `origin/main`), along with both new tests (`heap_indexed_structured_buffers_with_distinct_strides` and `table_bound_structured_buffer_reads_by_element_and_dimensions`). The single remaining failure (`a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`) reproduces identically on clean `origin/main`. - `cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: 16/16 passed (including `overlap_test::gpu_writes_visible_through_overlapping_views` and `structured_buffer_views_stay_raw_on_host_and_keep_stride_table`). - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed. - `cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. Great NVIDIA fix (FIND-11): viewing structured buffers raw on the host makes heap-indexed structured buffer reads work cleanly on RTX 5090. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 09:51 UTC · original · requested changes

The raw-view + VIEW_STRIDES 0..12-byte bias approach works cleanly on NVIDIA hardware — verified locally on Windows 11 with an RTX 5090 and WARP (git merge-tree against 63bcca43 clean, cargo clippy --workspace --all-targets [--all-features] -- -D warnings clean, cargo xtask policy 192 files ok):

  • descriptor::host::overlap_test::gpu_writes_visible_through_overlapping_views: passed (0/2400 mismatches) on RTX 5090, RTX 5090 + VICTORY_D3D12_DEBUG=1, and WARP + VICTORY_D3D12_DEBUG=1
  • structured_buffer_views_stay_raw_on_host_and_keep_stride_table and structured_views_off_their_buffers_elements_get_their_own_copy: passed on RTX 5090, RTX 5090 Debug, and WARP Debug
  • victory-shader stride_tests:: + diff_tests:: + waterfall_tests::: 19/20 passed on RTX 5090 + WARP (including both new structured-buffer tests; the lone a_heap_buffer_read_where_no_buffer_view_is_reads_zeros failure reproduces identically on origin/main 63bcca43 due to NVIDIA's 1M heap cap in emit::host).

Two correctness bugs should be fixed before merge:

1. Out-of-bounds VIEW_STRIDES root-SRV read and silently dropped raw_bias for dynamic-slot tables (crates/victory-gpu/src/descriptor/host.rs:129-143, 511-519)

Before this PR, table-bound structured buffers used native structured handles (12 | u, stride) and did not read VIEW_STRIDES. Now every table-bound structured buffer (u.stride >= 4) loads VIEW_STRIDES[index] via view_raw_bias(h) -> view_word(index) (lower.rs:1808-1815, 4646-4652) using the unclamped heap slot index from entry_heap_index/heap_index.

However, HostHeap::new allocates self.strides for only count.max(HEAP_VIEWS) dwords (host.rs:130), and write_stride drops any write with index >= self.count.max(HEAP_VIEWS) (host.rs:513). On uncapped heaps where count + extra > count.max(HEAP_VIEWS) (e.g. a title heap with count = 1_245_184 + DYNAMIC = 262_144, or count = 900_000 + 262_144 > HEAP_VIEWS), any fresh descriptor table placed in dynamic slots at index >= count.max(HEAP_VIEWS) has its raw_bias write silently dropped and causes the shader to read past the end of the VIEW_STRIDES root SRV (no hardware bounds check — garbage bias or GPU page fault / device removal).

Allocating strides (and marks symmetrically at lines 135 & 531) after (heap, count, extra) is resolved with (count + extra).max(views) entries, and checking index >= (self.count + self.dynamic).max(HEAP_VIEWS) in write_stride / set_mark, fixes this cleanly.

2. ClearUnorderedAccessViewUint/Float on a biased (bias = 4/8/12) structured UAV clobbers 4..12 preceding bytes in the shared host copy (descriptor/host.rs:1393-1415, draw.rs:1056-1085)

buffer_uav rounds FirstElement down by bias = offset & 15 (aligned = offset - bias) and sets NumElements = (total_bytes + bias) / 4, relying on translated shaders to skip the leading bias bytes via VIEW_STRIDES.

draw.rs::clear_unordered invokes ClearUnorderedAccessViewUint/Float directly on that biased raw host UAV without shader execution (and with unshifted rects). When bias > 0, D3D12 clears [aligned, aligned + raw_count * 4), overwriting the 4..12 bytes immediately preceding start inside the shared Shadow buffer — bytes outside buffer_range(&view) that readable did not even snapshot.

For bias > 0 structured UAVs, clear_unordered needs to restrict the clear to [bias / 4 .. raw_count) (via shifted/clamped D3D12_RECTs on the raw buffer UAV, or an exact 16-byte-aligned clear path) so preceding neighbor bytes in the shared copy are never overwritten.

3. Minor: getDimensions (num_records) with idxen == false on a table-bound structured buffer (crates/victory-shader/src/emit/lower.rs:4442-4455)

When a table-bound buffer with used.stride >= 4 is accessed via buffer_load with idxen == false (div_stride == None, !is_heap_direct), line 4445 skips subtracting view_raw_bias(h), returning total_bytes + bias instead of total_bytes. Including || used.is_some_and(|u| u.stride >= 4) in that condition handles it consistently.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#pullrequestreview-6071873593) · **requested changes** The raw-view + `VIEW_STRIDES` 0..12-byte bias approach works cleanly on NVIDIA hardware — verified locally on Windows 11 with an RTX 5090 and WARP (`git merge-tree` against `63bcca43` clean, `cargo clippy --workspace --all-targets [--all-features] -- -D warnings` clean, `cargo xtask policy` `192 files ok`): - `descriptor::host::overlap_test::gpu_writes_visible_through_overlapping_views`: **passed (0/2400 mismatches)** on RTX 5090, RTX 5090 + `VICTORY_D3D12_DEBUG=1`, and WARP + `VICTORY_D3D12_DEBUG=1` - `structured_buffer_views_stay_raw_on_host_and_keep_stride_table` and `structured_views_off_their_buffers_elements_get_their_own_copy`: passed on RTX 5090, RTX 5090 Debug, and WARP Debug - `victory-shader` `stride_tests::` + `diff_tests::` + `waterfall_tests::`: 19/20 passed on RTX 5090 + WARP (including both new structured-buffer tests; the lone `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` failure reproduces identically on `origin/main` `63bcca43` due to NVIDIA's 1M heap cap in `emit::host`). Two correctness bugs should be fixed before merge: ### 1. Out-of-bounds `VIEW_STRIDES` root-SRV read and silently dropped `raw_bias` for dynamic-slot tables (`crates/victory-gpu/src/descriptor/host.rs:129-143, 511-519`) Before this PR, table-bound structured buffers used native structured handles `(12 | u, stride)` and did not read `VIEW_STRIDES`. Now every table-bound structured buffer (`u.stride >= 4`) loads `VIEW_STRIDES[index]` via `view_raw_bias(h)` -> `view_word(index)` (`lower.rs:1808-1815, 4646-4652`) using the unclamped heap slot `index` from `entry_heap_index`/`heap_index`. However, `HostHeap::new` allocates `self.strides` for only `count.max(HEAP_VIEWS)` dwords (`host.rs:130`), and `write_stride` drops any write with `index >= self.count.max(HEAP_VIEWS)` (`host.rs:513`). On uncapped heaps where `count + extra > count.max(HEAP_VIEWS)` (e.g. a title heap with `count = 1_245_184` + `DYNAMIC = 262_144`, or `count = 900_000` + `262_144 > HEAP_VIEWS`), any fresh descriptor table placed in dynamic slots at `index >= count.max(HEAP_VIEWS)` has its `raw_bias` write silently dropped and causes the shader to read **past the end of the `VIEW_STRIDES` root SRV** (no hardware bounds check — garbage bias or GPU page fault / device removal). Allocating `strides` (and `marks` symmetrically at lines 135 & 531) *after* `(heap, count, extra)` is resolved with `(count + extra).max(views)` entries, and checking `index >= (self.count + self.dynamic).max(HEAP_VIEWS)` in `write_stride` / `set_mark`, fixes this cleanly. ### 2. `ClearUnorderedAccessViewUint`/`Float` on a biased (`bias = 4/8/12`) structured UAV clobbers `4..12` preceding bytes in the shared host copy (`descriptor/host.rs:1393-1415`, `draw.rs:1056-1085`) `buffer_uav` rounds `FirstElement` down by `bias = offset & 15` (`aligned = offset - bias`) and sets `NumElements = (total_bytes + bias) / 4`, relying on translated shaders to skip the leading `bias` bytes via `VIEW_STRIDES`. `draw.rs::clear_unordered` invokes `ClearUnorderedAccessViewUint`/`Float` directly on that biased raw host UAV without shader execution (and with unshifted `rects`). When `bias > 0`, D3D12 clears `[aligned, aligned + raw_count * 4)`, overwriting the `4..12` bytes immediately preceding `start` inside the shared `Shadow` buffer — bytes outside `buffer_range(&view)` that `readable` did not even snapshot. For `bias > 0` structured UAVs, `clear_unordered` needs to restrict the clear to `[bias / 4 .. raw_count)` (via shifted/clamped `D3D12_RECT`s on the raw buffer UAV, or an exact 16-byte-aligned clear path) so preceding neighbor bytes in the shared copy are never overwritten. ### 3. Minor: `getDimensions` (`num_records`) with `idxen == false` on a table-bound structured buffer (`crates/victory-shader/src/emit/lower.rs:4442-4455`) When a table-bound buffer with `used.stride >= 4` is accessed via `buffer_load` with `idxen == false` (`div_stride == None`, `!is_heap_direct`), line 4445 skips subtracting `view_raw_bias(h)`, returning `total_bytes + bias` instead of `total_bytes`. Including `|| used.is_some_and(|u| u.stride >= 4)` in that condition handles it consistently.
Author
Owner

@⁠qtLkz on GitHub · 2026-11-26 10:07 UTC · original

Tested on NVIDIA Ada (the description has Turing): RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, this PR (767f228) on main 63bcca4, together with #2596 / #2683 / #2633 (clean merges), fixtures untouched.

cargo test -p victory-shader --lib --locked -- --test-threads=1: 313 passed, 0 failed, including the two that fail on NVIDIA on main because of raw reads through structured views:

  • stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride ... ok (on main: left: [101, 104, 107, ...], right: [200, 201, ...], the stride applied twice)
  • synthetic_tests::gathers_at_a_level_match_the_hardware ... ok

victory-gpu: 233 passed, 0 failed. Full workspace green. Details in #2317.

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-26 10:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7188930381) Tested on NVIDIA Ada (the description has Turing): RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, this PR (`767f228`) on main `63bcca4`, together with #2596 / #2683 / #2633 (clean merges), fixtures untouched. `cargo test -p victory-shader --lib --locked -- --test-threads=1`: **313 passed, 0 failed**, including the two that fail on NVIDIA on main because of raw reads through structured views: - `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride ... ok` (on main: `left: [101, 104, 107, ...]`, `right: [200, 201, ...]`, the stride applied twice) - `synthetic_tests::gathers_at_a_level_match_the_hardware ... ok` victory-gpu: 233 passed, 0 failed. Full workspace green. Details in #2317. AI-assisted (Claude).
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 10:49 UTC · original

@⁠jujumoneylol @⁠fuzeofficlal I reproduced the structured UAV clear in review item 2 on native Windows. Both the RTX 5080 and inbox WARP gave the following results in two fresh runs per adapter and revision.

Revision Cases matching both readbacks Wrong words in shared GPU buffer Wrong words in title copy
PR head 767f228 4/16 36/512 22/512
With 22f19d9 16/16 0/512 0/512

Each case starts with 32 distinct guard words in one allocated buffer. A six-record view with a 12-byte stride starts at a 0, 4, 8, or 12-byte bias. The test clears either the whole view or the relative word rectangle [2,6), with both Uint and Float. On the PR head the whole clear changed exactly one, two, or three preceding words at the respective nonzero biases. The title copy hid those changes because it only copied the logical view back. At bias 12, the rectangle was shifted three words toward the start of the buffer, giving six wrong GPU words.

The fix uses an exact R32_UINT view with zero structure stride and no RAW flag for the biased native clear, and copies that CPU descriptor into the shader-visible slot. The clear itself produced no D3D12 InfoQueue warnings or errors on either adapter, measured after heap setup through execution. Four existing overlap, structured-view and clear-slot tests also passed on each. This covers the clear item. The stride-table and getDimensions review items remain separate.

The commit applies directly to 767f228. Fork commit · Downloadable patch

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2885-structured-clear-range
git cherry-pick 22f19d9
$env:VICTORY_D3D12_DEBUG = '1'
$env:VICTORY_D3D12_WARP = '0'
cargo test -p victory-gpu --features diagnostics --lib structured_clears_preserve_neighbor_words -- --nocapture
$env:VICTORY_D3D12_WARP = '1'
cargo test -p victory-gpu --features diagnostics --lib structured_clears_preserve_neighbor_words -- --nocapture

AI-assisted patch and tests, run locally.

**@⁠steven-seagull27** on GitHub · 2026-11-26 10:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7189878332) @⁠jujumoneylol @⁠fuzeofficlal I reproduced the structured UAV clear in [review item 2](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2885) on native Windows. Both the RTX 5080 and inbox WARP gave the following results in two fresh runs per adapter and revision. | Revision | Cases matching both readbacks | Wrong words in shared GPU buffer | Wrong words in title copy | |---|---:|---:|---:| | PR head `767f228` | 4/16 | 36/512 | 22/512 | | With `22f19d9` | 16/16 | 0/512 | 0/512 | Each case starts with 32 distinct guard words in one allocated buffer. A six-record view with a 12-byte stride starts at a 0, 4, 8, or 12-byte bias. The test clears either the whole view or the relative word rectangle `[2,6)`, with both Uint and Float. On the PR head the whole clear changed exactly one, two, or three preceding words at the respective nonzero biases. The title copy hid those changes because it only copied the logical view back. At bias 12, the rectangle was shifted three words toward the start of the buffer, giving six wrong GPU words. The fix uses an exact `R32_UINT` view with zero structure stride and no RAW flag for the biased native clear, and copies that CPU descriptor into the shader-visible slot. The clear itself produced no D3D12 InfoQueue warnings or errors on either adapter, measured after heap setup through execution. Four existing overlap, structured-view and clear-slot tests also passed on each. This covers the clear item. The stride-table and `getDimensions` review items remain separate. The commit applies directly to `767f228`. [Fork commit](https://github.com/steven-seagull27/VIctory/commit/22f19d9ac966fe0deaa7f1b1a31451c51821fac6) · [Downloadable patch](https://github.com/steven-seagull27/VIctory/commit/22f19d9ac966fe0deaa7f1b1a31451c51821fac6.patch) ```powershell git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2885-structured-clear-range git cherry-pick 22f19d9 $env:VICTORY_D3D12_DEBUG = '1' $env:VICTORY_D3D12_WARP = '0' cargo test -p victory-gpu --features diagnostics --lib structured_clears_preserve_neighbor_words -- --nocapture $env:VICTORY_D3D12_WARP = '1' cargo test -p victory-gpu --features diagnostics --lib structured_clears_preserve_neighbor_words -- --nocapture ``` AI-assisted patch and tests, run locally.
Author
Owner

@⁠ThomasHFWright on GitHub · 2026-11-26 13:00 UTC · original

Proton data point for 767f228. I ported the shared raw-view approach to LinVxtory’s PR995-based renderer and tested it on CachyOS with an RTX 5090 (NVIDIA 620.73.04) and GE-Proton 11-14.

  • Buffer correctness: 9 focused GPU-crate tests and 6 shader tests passed. This included 1,536 readback values through overlapping SRV/UAV views with byte prefixes 0, 4, 8 and 12, plus per-lane descriptor selection, stores and atomics. The title log also recorded a live structured buffer bound as raw with an 8-byte prefix and 100-byte stride.
  • Room replay: One cold run per build from the same checkpoint, using the same preset and scripted camera route. In matched side and near-frontal views the hair still looked bundled, and the bunk rail was still visible through the cheek gap. The +180 to +330 second world interval measured 2.95 FPS on the control and 3.03 FPS with the port. The launch harness ended by signal after about 572 seconds, after both camera turns. The candidate log showed no device loss.
  • Review scope: The port uses a fixed stride table covering its view-heap range, clamps metadata lookups and subtracts the prefix on the dimensions path. Those are source checks. This renderer has no direct native ClearUnorderedAccessView call, so this run adds no coverage for the upstream clear issue.

Source-only faces-hair branch · Reproduction notes and results

AI-assisted port and validation. The measurements are from my machine.

**@⁠ThomasHFWright** on GitHub · 2026-11-26 13:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7192756649) Proton data point for `767f228`. I ported the shared raw-view approach to LinVxtory’s PR995-based renderer and tested it on CachyOS with an RTX 5090 (NVIDIA 620.73.04) and GE-Proton 11-14. - **Buffer correctness:** 9 focused GPU-crate tests and 6 shader tests passed. This included 1,536 readback values through overlapping SRV/UAV views with byte prefixes 0, 4, 8 and 12, plus per-lane descriptor selection, stores and atomics. The title log also recorded a live structured buffer bound as raw with an 8-byte prefix and 100-byte stride. - **Room replay:** One cold run per build from the same checkpoint, using the same preset and scripted camera route. In matched side and near-frontal views the hair still looked bundled, and the bunk rail was still visible through the cheek gap. The +180 to +330 second world interval measured 2.95 FPS on the control and 3.03 FPS with the port. The launch harness ended by signal after about 572 seconds, after both camera turns. The candidate log showed no device loss. - **Review scope:** The port uses a fixed stride table covering its view-heap range, clamps metadata lookups and subtracts the prefix on the dimensions path. Those are source checks. This renderer has no direct native `ClearUnorderedAccessView` call, so this run adds no coverage for the upstream clear issue. [Source-only faces-hair branch](https://github.com/ThomasHFWright/LinVxtory/tree/faces-hair) · [Reproduction notes and results](https://github.com/ThomasHFWright/LinVxtory/blob/0ee527c40a89f8c6d16fc30492780ecdffabe327/docs/pr995-candidate/validation.md#room-comparison-for-victory-pr2885) AI-assisted port and validation. The measurements are from my machine.
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-26 14:40 UTC · original · reviewed

RTX 4060 8 GB (Ada), driver 621.14, Windows 11 Pro 26300. --test-threads=1, skipping only heap_direct_texture_reads_mark_their_heap_index (#2571).

With #2461: main 63bcca4 + this PR (767f228) + #2461 (6544a52). The only conflict is the pub use shader::{...} list in emit/mod.rs: keep both sides and drop NULL_BUFFER_VIEW. Results: victory-gpu --lib 234 passed, 0 failed, and victory-shader --lib 303 passed, 0 failed. main fails 5 on this card, so the two PRs together clear every NVIDIA unit-test failure here.

Clear item (review 2): I ran @⁠steven-seagull27's fixture from 22f19d9 against this head. 12 of 16 cases are wrong, with 36 wrong words in the shared GPU buffer and 22 in the title copy. That matches the RTX 5080 numbers exactly. With 22f19d9 cherry-picked on top, all 16 cases are correct with 0 and 0 wrong words, and the full suites still pass (235 / 303, 0 failed). Folding 22f19d9 in would close that item.

Item 1 of the same review (out-of-bounds VIEW_STRIDES read): this doesn't look reachable to me. Shader::heap_handle clamps the index to HEAP_VIEWS - 1 before it stores it in view_index, and view_raw_bias / view_word read through that clamped index. The stride table has count.max(HEAP_VIEWS) entries, so the read stays inside it. Dynamic slots at or past HEAP_VIEWS only exist when count > HEAP_VIEWS - DYNAMIC (1,835,008), and the retail heap is 1,245,184. Shaders on main can't address those slots either, because of the same clamp. So I don't think it should block this PR.

AI-assisted (Claude). Unit tests only, no game data.

**@⁠potatoe0100** on GitHub · 2026-11-26 14:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#pullrequestreview-6076016205) · **reviewed** RTX 4060 8 GB (Ada), driver 621.14, Windows 11 Pro 26300. `--test-threads=1`, skipping only `heap_direct_texture_reads_mark_their_heap_index` (#2571). **With #2461:** `main` `63bcca4` + this PR (`767f228`) + #2461 (`6544a52`). The only conflict is the `pub use shader::{...}` list in `emit/mod.rs`: keep both sides and drop `NULL_BUFFER_VIEW`. Results: `victory-gpu --lib` 234 passed, 0 failed, and `victory-shader --lib` 303 passed, 0 failed. `main` fails 5 on this card, so the two PRs together clear every NVIDIA unit-test failure here. **Clear item (review 2):** I ran @⁠steven-seagull27's fixture from `22f19d9` against this head. 12 of 16 cases are wrong, with 36 wrong words in the shared GPU buffer and 22 in the title copy. That matches the RTX 5080 numbers exactly. With `22f19d9` cherry-picked on top, all 16 cases are correct with 0 and 0 wrong words, and the full suites still pass (235 / 303, 0 failed). Folding `22f19d9` in would close that item. **Item 1 of the same review (out-of-bounds `VIEW_STRIDES` read):** this doesn't look reachable to me. `Shader::heap_handle` clamps the index to `HEAP_VIEWS - 1` before it stores it in `view_index`, and `view_raw_bias` / `view_word` read through that clamped index. The stride table has `count.max(HEAP_VIEWS)` entries, so the read stays inside it. Dynamic slots at or past `HEAP_VIEWS` only exist when `count > HEAP_VIEWS - DYNAMIC` (1,835,008), and the retail heap is 1,245,184. Shaders on `main` can't address those slots either, because of the same clamp. So I don't think it should block this PR. AI-assisted (Claude). Unit tests only, no game data.
Author
Owner

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

@⁠steven-seagull27 @⁠jujumoneylol I reproduced the structured UAV clear result for 22f19d9 on NVIDIA Ada. Setup: RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1. Both trees were built from the PR alone, without the rest of the NVIDIA stack.

structured_clears_preserve_neighbor_words_in_the_shared_buffer (--features diagnostics, VICTORY_D3D12_DEBUG=1, one run per adapter and tree):

Tree Adapter Cases matching both readbacks Wrong words in shared GPU buffer Wrong words in title copy
767f228 + test file only RTX 4070 Ti 4/16 36/512 22/512
767f228 + test file only WARP 4/16 36/512 22/512
767f228 + 22f19d9 RTX 4070 Ti 16/16 0/512 0/512
767f228 + 22f19d9 WARP 16/16 0/512 0/512

The per-case counts on the PR head match yours exactly. Whole-view clears overwrite 1, 2 and 3 GPU words at biases 4, 8 and 12, and the title copy does not show them. The [2,6) rectangle gives 2, 4 and 6 wrong GPU words. Bias 0 is clean on every case.

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

767f228 767f228 + 22f19d9
victory-shader 302 passed, 1 failed 302 passed, 1 failed
victory-gpu 231 passed, 2 failed 232 passed (+ the new clear test), 2 failed

The same three tests fail on both trees, and all three come from the NVIDIA 1M view-heap cap (FIND-9, addressed by #2683), not from this PR:

  • emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros: dispatch failed: The parameter is incorrect
  • descriptor::host::tests::dynamic_slots_are_held_until_released: NumDescriptors >= HEAP_VIEWS
  • memory::tests::lists_share_a_table_and_copies_keep_their_views: past the dynamic slots

emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index was skipped on both trees, because it crashes the NVIDIA driver and stops the shader run (#2571, fixed by #2596/#2587). 22f19d9 introduces no new failures on Ada.

AI-assisted (Claude).

**@⁠qtLkz** on GitHub · 2026-11-26 15:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7196156021) @⁠steven-seagull27 @⁠jujumoneylol I reproduced the structured UAV clear result for `22f19d9` on NVIDIA Ada. Setup: RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1. Both trees were built from the PR alone, without the rest of the NVIDIA stack. **`structured_clears_preserve_neighbor_words_in_the_shared_buffer`** (`--features diagnostics`, `VICTORY_D3D12_DEBUG=1`, one run per adapter and tree): | Tree | Adapter | Cases matching both readbacks | Wrong words in shared GPU buffer | Wrong words in title copy | |---|---|---:|---:|---:| | `767f228` + test file only | RTX 4070 Ti | 4/16 | 36/512 | 22/512 | | `767f228` + test file only | WARP | 4/16 | 36/512 | 22/512 | | `767f228` + `22f19d9` | RTX 4070 Ti | 16/16 | 0/512 | 0/512 | | `767f228` + `22f19d9` | WARP | 16/16 | 0/512 | 0/512 | The per-case counts on the PR head match yours exactly. Whole-view clears overwrite 1, 2 and 3 GPU words at biases 4, 8 and 12, and the title copy does not show them. The `[2,6)` rectangle gives 2, 4 and 6 wrong GPU words. Bias 0 is clean on every case. **Full suites** (`cargo test -p <crate> --lib --locked -- --test-threads=1`): | | `767f228` | `767f228` + `22f19d9` | |---|---|---| | victory-shader | 302 passed, 1 failed | 302 passed, 1 failed | | victory-gpu | 231 passed, 2 failed | 232 passed (+ the new clear test), 2 failed | The same three tests fail on both trees, and all three come from the NVIDIA 1M view-heap cap (FIND-9, addressed by #2683), not from this PR: - `emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`: `dispatch failed: The parameter is incorrect` - `descriptor::host::tests::dynamic_slots_are_held_until_released`: `NumDescriptors >= HEAP_VIEWS` - `memory::tests::lists_share_a_table_and_copies_keep_their_views`: `past the dynamic slots` `emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index` was skipped on both trees, because it crashes the NVIDIA driver and stops the shader run (#2571, fixed by #2596/#2587). `22f19d9` introduces no new failures on Ada. AI-assisted (Claude).
Author
Owner

@⁠upipibi on GitHub · 2026-11-26 17:18 UTC · original · edited 2026-11-26 17:52 UTC

NVIDIA Ampere check of 767f228: RTX 3070 8 GB, driver 616.56, Windows 11, rustc 1.100.0, hardware adapter. main 63bcca4 as control, each tree in its own target dir, --locked -- --test-threads=1. Synthetic tests only.

test main 63bcca4 PR 767f228
emit::stride_tests:: 6 pass, 2 fail 9 pass, 1 fail
gathers_at_a_level_match_the_hardware, 3 runs fails 3/3 (lane 0 [0,1,0,0], want [0,0,0,0]) passes 3/3
descriptor::host::, 3 runs 14 pass, 1 fail each 16 pass, 1 fail each; overlap_test::gpu_writes_visible_through_overlapping_views passes 3/3
victory-shader --lib (skipping the #2571 test) 298 pass, 3 fail 302 pass, 1 fail
victory-gpu --lib 229 pass, 2 fail 231 pass, 2 fail
  • On main, a_heap_buffer_read_by_element_takes_the_views_stride reads [101,104,…,131,0,…] where [200..231] is wanted. It passes with the PR.
  • These still fail on both trees:
    • a_heap_buffer_read_where_no_buffer_view_is_reads_zeros. On the PR it fails with "dispatch failed: The parameter is incorrect" (stride_tests.rs:533). Searched: the test name in VIctory issues and PRs. It is the null-buffer read on a capped heap from #1835; #3235, #1943 and #2177 propose fixes.
    • dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views (the HEAP_VIEWS cap; tracked in #1744 and #3178).
  • No driver resets during the runs.
  • Not tested: the nonzero-offset structured UAV clear (22f19d9, not in this PR).

AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).

**@⁠upipibi** on GitHub · 2026-11-26 17:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7198796380) · edited 2026-11-26 17:52 UTC NVIDIA Ampere check of `767f228`: RTX 3070 8 GB, driver 616.56, Windows 11, rustc 1.100.0, hardware adapter. `main` `63bcca4` as control, each tree in its own target dir, `--locked -- --test-threads=1`. Synthetic tests only. | test | main `63bcca4` | PR `767f228` | |---|---|---| | `emit::stride_tests::` | 6 pass, 2 fail | 9 pass, 1 fail | | `gathers_at_a_level_match_the_hardware`, 3 runs | fails 3/3 (lane 0 `[0,1,0,0]`, want `[0,0,0,0]`) | passes 3/3 | | `descriptor::host::`, 3 runs | 14 pass, 1 fail each | 16 pass, 1 fail each; `overlap_test::gpu_writes_visible_through_overlapping_views` passes 3/3 | | `victory-shader --lib` (skipping the #2571 test) | 298 pass, 3 fail | 302 pass, 1 fail | | `victory-gpu --lib` | 229 pass, 2 fail | 231 pass, 2 fail | - On `main`, `a_heap_buffer_read_by_element_takes_the_views_stride` reads `[101,104,…,131,0,…]` where `[200..231]` is wanted. It passes with the PR. - These still fail on both trees: - `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`. On the PR it fails with "dispatch failed: The parameter is incorrect" (`stride_tests.rs:533`). Searched: the test name in VIctory issues and PRs. It is the null-buffer read on a capped heap from #1835; #3235, #1943 and #2177 propose fixes. - `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views` (the `HEAP_VIEWS` cap; tracked in #1744 and #3178). - No driver resets during the runs. - Not tested: the nonzero-offset structured UAV clear (`22f19d9`, not in this PR). AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).
Author
Owner

@⁠Jineggegg on GitHub · 2026-11-26 19:42 UTC · original

jujumoneylol, item 3 of the review above (the size of a table-bound structured buffer read without idxen) reproduces on 767f228, on an RTX 5090 and on WARP. 3214c40 on top of 767f228 fixes it and extends the existing test. It changes one condition in emit/lower.rs and the test in emit/stride_tests.rs, and applies with or without 22f19d9.

What happens. For a table-bound buffer the program declares with a structured stride, raw_view adds the raw start bias when the handle is heap-direct or used.stride >= 4. The size read subtracted it only when the count is divided by the stride (div_stride, an idxen access) or the handle is heap-direct. A program that reads the same view by byte (offen) gets the view's size plus the bias: 396 instead of 384 bytes for 32 records of 12 bytes that start 12 bytes past a 16-byte boundary. The commit uses the loads' condition. div_stride is only Some when used.stride >= 4, so the idxen case is unchanged.

Test. table_bound_structured_buffer_reads_by_element_and_dimensions also runs the same program with buffer_load_dword v2, v1, s[8:11], 0 offen offset:4 in place of the idxen load, at bias 0 and 12, and expects the 32 dwords after the view's start, with 32 * 12 in lane 31.

cargo test -p victory-shader --lib --locked emit::stride_tests::table_bound_structured_buffer_reads_by_element_and_dimensions:

Tree RTX 5090 VICTORY_WARP=1
767f228 + the test change only fails at bias-12, by byte: lane 31 is 396, expected 384 same failure (with VICTORY_WARP=1 the first pass also runs on WARP but is labelled hardware)
767f228 + the commit passes passes

cargo test --workspace --locked --no-fail-fast, once on the RTX 5090 (skipping heap_direct_texture_reads_mark_their_heap_index, which ends the shader test process on NVIDIA, #2571) and once with VICTORY_WARP=1 VICTORY_D3D12_WARP=1. In that second run victory-shader runs on WARP. victory-gpu still runs on the RTX 5090, because its WARP switch only exists in diagnostics builds.

RTX 5090 VICTORY_WARP=1
767f228 872 passed, 3 failed (run in two parts: four slow shader tests and two small test binaries separately) 870 passed, 6 failed
+ the commit 872 passed, 3 failed 870 passed, 6 failed

On the RTX 5090 the three failures are the view-heap cap tests (a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views). 767f228 fails the same three, as do the Ada runs above. With VICTORY_WARP=1 both trees fail the same six: the two victory-gpu cap tests, plus four shader tests (gathers_at_a_level_match_the_hardware (#3267), the two permutes_* tests, a_mask_joined_with_data_at_a_uniform_loop_is_its_number). Clippy, default and --all-features (as in ci.yml): clean. cargo xtask policy: 192 files ok.

Item 1 (stride table size). I agree with potatoe0100 that it can't be reached. Shader::heap_handle clamps every index below HEAP_VIEWS, and table-bound buffer handles go through it too (guarded_heap_handle). The stride and mark tables have count.max(HEAP_VIEWS) entries. Writes are only dropped for dynamic slots at or past count.max(HEAP_VIEWS), which no shader can address, so they don't change what shaders read. The same holds with #2121's paged heap, which caps title slots so that title and dynamic slots stay below the null buffer views. I didn't find a fixture that observes a difference, so the commit doesn't change it.

RTX 5090, driver 621.14, Windows 11 build 26300, in-box WARP 10.0.26100.9818, dxil.dll 1.9.2609.5, Rust 1.98.1.

Synthetic tests only, no game data. AI-assisted (Claude Code); the runs are from my machine.

🤖 Generated with Claude Code

**@⁠Jineggegg** on GitHub · 2026-11-26 19:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2885#issuecomment-7201884345) jujumoneylol, item 3 of [the review above](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2885) (the size of a table-bound structured buffer read without `idxen`) reproduces on `767f228`, on an RTX 5090 and on WARP. [`3214c40`](https://github.com/Jineggegg/VIctory/commit/3214c404dc7bfac5ca648c36cd1a121be87be53a) on top of `767f228` fixes it and extends the existing test. It changes one condition in `emit/lower.rs` and the test in `emit/stride_tests.rs`, and applies with or without `22f19d9`. **What happens.** For a table-bound buffer the program declares with a structured stride, `raw_view` adds the raw start bias when the handle is heap-direct or `used.stride >= 4`. The size read subtracted it only when the count is divided by the stride (`div_stride`, an `idxen` access) or the handle is heap-direct. A program that reads the same view by byte (`offen`) gets the view's size plus the bias: 396 instead of 384 bytes for 32 records of 12 bytes that start 12 bytes past a 16-byte boundary. The commit uses the loads' condition. `div_stride` is only `Some` when `used.stride >= 4`, so the `idxen` case is unchanged. **Test.** `table_bound_structured_buffer_reads_by_element_and_dimensions` also runs the same program with `buffer_load_dword v2, v1, s[8:11], 0 offen offset:4` in place of the `idxen` load, at bias 0 and 12, and expects the 32 dwords after the view's start, with `32 * 12` in lane 31. `cargo test -p victory-shader --lib --locked emit::stride_tests::table_bound_structured_buffer_reads_by_element_and_dimensions`: | Tree | RTX 5090 | `VICTORY_WARP=1` | |---|---|---| | `767f228` + the test change only | fails at `bias-12, by byte`: lane 31 is 396, expected 384 | same failure (with `VICTORY_WARP=1` the first pass also runs on WARP but is labelled `hardware`) | | `767f228` + the commit | passes | passes | `cargo test --workspace --locked --no-fail-fast`, once on the RTX 5090 (skipping `heap_direct_texture_reads_mark_their_heap_index`, which ends the shader test process on NVIDIA, #2571) and once with `VICTORY_WARP=1 VICTORY_D3D12_WARP=1`. In that second run `victory-shader` runs on WARP. `victory-gpu` still runs on the RTX 5090, because its WARP switch only exists in `diagnostics` builds. | | RTX 5090 | `VICTORY_WARP=1` | |---|---|---| | `767f228` | 872 passed, 3 failed (run in two parts: four slow shader tests and two small test binaries separately) | 870 passed, 6 failed | | + the commit | 872 passed, 3 failed | 870 passed, 6 failed | On the RTX 5090 the three failures are the view-heap cap tests (`a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`). `767f228` fails the same three, as do the Ada runs above. With `VICTORY_WARP=1` both trees fail the same six: the two `victory-gpu` cap tests, plus four shader tests (`gathers_at_a_level_match_the_hardware` (#3267), the two `permutes_*` tests, `a_mask_joined_with_data_at_a_uniform_loop_is_its_number`). Clippy, default and `--all-features` (as in `ci.yml`): clean. `cargo xtask policy`: 192 files ok. **Item 1 (stride table size).** I agree with potatoe0100 that it can't be reached. `Shader::heap_handle` clamps every index below `HEAP_VIEWS`, and table-bound buffer handles go through it too (`guarded_heap_handle`). The stride and mark tables have `count.max(HEAP_VIEWS)` entries. Writes are only dropped for dynamic slots at or past `count.max(HEAP_VIEWS)`, which no shader can address, so they don't change what shaders read. The same holds with #2121's paged heap, which caps title slots so that title and dynamic slots stay below the null buffer views. I didn't find a fixture that observes a difference, so the commit doesn't change it. RTX 5090, driver 621.14, Windows 11 build 26300, in-box WARP 10.0.26100.9818, `dxil.dll` 1.9.2609.5, Rust 1.98.1. Synthetic tests only, no game data. AI-assisted (Claude Code); the runs are from my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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/2885/head:github-bot/gh-2885'
git switch 'github-bot/gh-2885'

Merge

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