GPU+shader: back structured buffer views with raw descriptors for NVIDIA rawBufferLoad #2176

Open
n-romanovich wants to merge 5 commits from upstream-pr/2178 into main
n-romanovich commented 2026-11-25 07:06:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-25T07:06:33Z.


Summary

On NVIDIA hardware, executing DXIL rawBufferLoad (ByteAddressBuffer) against a D3D12 StructuredBuffer descriptor (StructureByteStride > 0) multiplies the byte offset by StructureByteStride, corrupting reads and returning zeros past width / stride (as exposed by stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride).

This change:

  • Converts structured buffer SRVs and UAVs (StructureByteStride > 0, 4-byte-aligned element size) to DXGI_FORMAT_R32_TYPELESS with D3D12_BUFFER_{SRV,UAV}_FLAG_RAW in buffer_srv and buffer_uav (HostHeap still records the original element stride in VIEW_STRIDES).
  • Adds set_host_raw_structured / host_raw_structured in victory_shader::emit (enabled by victory-gpu and included in shader_cache::key) so indexed/scalar-loaded structured buffers in descriptor tables also lower to raw byte-address reads, writes, atomics, and getDimensions / stride.
  • Updates stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride to pass a raw heap descriptor (Stride::Raw) alongside the VIEW_STRIDES table, matching the emit module contract.

Verification

Tested on NVIDIA GeForce RTX 5060 Ti:

  • cargo test --release -p victory-shader --lib -- stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride diff_tests: 6 passed; 0 failed
  • cargo test --release -p victory-gpu --lib -- shader_cache::tests: 3 passed; 0 failed
<!-- greyfinch-sync:Marvisak/VIctory:issue:5486818529 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-25T07:06:33Z. --- ## Summary On NVIDIA hardware, executing DXIL `rawBufferLoad` (`ByteAddressBuffer`) against a D3D12 `StructuredBuffer` descriptor (`StructureByteStride > 0`) multiplies the byte offset by `StructureByteStride`, corrupting reads and returning zeros past `width / stride` (as exposed by `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`). This change: - Converts structured buffer SRVs and UAVs (`StructureByteStride > 0`, 4-byte-aligned element size) to `DXGI_FORMAT_R32_TYPELESS` with `D3D12_BUFFER_{SRV,UAV}_FLAG_RAW` in `buffer_srv` and `buffer_uav` (`HostHeap` still records the original element stride in `VIEW_STRIDES`). - Adds `set_host_raw_structured` / `host_raw_structured` in `victory_shader::emit` (enabled by `victory-gpu` and included in `shader_cache::key`) so indexed/scalar-loaded structured buffers in descriptor tables also lower to raw byte-address reads, writes, atomics, and `getDimensions / stride`. - Updates `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` to pass a raw heap descriptor (`Stride::Raw`) alongside the `VIEW_STRIDES` table, matching the `emit` module contract. ## Verification Tested on NVIDIA GeForce RTX 5060 Ti: - `cargo test --release -p victory-shader --lib -- stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride diff_tests`: `6 passed; 0 failed` - `cargo test --release -p victory-gpu --lib -- shader_cache::tests`: `3 passed; 0 failed`
DenRakEiw commented 2026-11-25 07:24:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T07:24:31Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib shader_cache:: — 3 passed, 0 failed
  • cargo test -p victory-shader --lib emit::stride_tests:: — 5 passed, 1 failed on RTX 5090: directly fixes a_heap_buffer_read_by_element_takes_the_views_stride on NVIDIA! (The 1 remaining failure, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, is the separate NVIDIA 1M view-heap cap issue covered by #2177/#2121.)
  • cargo clippy -p victory-gpu -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean raw-descriptor backing for structured buffer views on NVIDIA with cache-key inclusion. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6053418171 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#pullrequestreview-6053418171). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T07:24:31Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib shader_cache::` — 3 passed, 0 failed - `cargo test -p victory-shader --lib emit::stride_tests::` — **5 passed, 1 failed** on RTX 5090: directly fixes `a_heap_buffer_read_by_element_takes_the_views_stride` on NVIDIA! (The 1 remaining failure, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, is the separate NVIDIA 1M view-heap cap issue covered by #2177/#2121.) - `cargo clippy -p victory-gpu -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean raw-descriptor backing for structured buffer views on NVIDIA with cache-key inclusion. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 07:30:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T07:30:06Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked (shader half; the GPU half is Windows-only).

144 passed / 0 failed / 2 ignored. Structured buffer views backed with raw descriptors — descriptor backing change; mixed gpu+shader, relates to #2128's typed null descriptors.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053477343 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#pullrequestreview-6053477343). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T07:30:06Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked` (shader half; the GPU half is Windows-only). 144 passed / 0 failed / 2 ignored. Structured buffer views backed with raw descriptors — descriptor backing change; mixed gpu+shader, relates to #2128's typed null descriptors.
sinan-cmyk commented 2026-11-25 08:06:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T07:53:40Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 9124d690 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156370972 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7156370972). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T07:53:40Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 9124d690 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
sinan-cmyk commented 2026-11-25 08:06:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:05:34Z.


Shader tests on NVIDIA Ada

I ran cargo test --locked -p victory-shader --lib on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, VICTORY_WARP unset.

Build Passed Failed
main 940d32f 244 3: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware
this PR (head 9124d690) merged onto 940d32f 245 2: stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware

So on Ada this PR fixes stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, one of the three failures #1835 tracks. #2177 fixes stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros. The two PRs conflict with each other in victory-gpu/src/shader_cache.rs (each one adds its own parameter to key) and in victory-shader/src/emit/mod.rs, so I could not test them together. synthetic_tests::gathers_at_a_level_match_the_hardware still fails with both (lane 0 gives [0, 1, 0, 0], expected [0, 0, 0, 0]).

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156596972 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7156596972). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T08:05:34Z. --- ### Shader tests on NVIDIA Ada I ran `cargo test --locked -p victory-shader --lib` on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, `VICTORY_WARP` unset. | Build | Passed | Failed | |---|---|---| | `main` 940d32f | 244 | 3: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `synthetic_tests::gathers_at_a_level_match_the_hardware` | | this PR (head 9124d690) merged onto 940d32f | 245 | 2: `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `synthetic_tests::gathers_at_a_level_match_the_hardware` | So on Ada this PR fixes `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, one of the three failures #1835 tracks. #2177 fixes `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`. **The two PRs conflict with each other** in `victory-gpu/src/shader_cache.rs` (each one adds its own parameter to `key`) and in `victory-shader/src/emit/mod.rs`, so I could not test them together. `synthetic_tests::gathers_at_a_level_match_the_hardware` still fails with both (lane 0 gives `[0, 1, 0, 0]`, expected `[0, 0, 0, 0]`). AI-assisted (Claude Code).
carlos-seiffert commented 2026-11-25 11:05:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by carlos-seiffert on 2026-11-25T10:20:20Z.


RTX 2060 6 GB (Turing), driver 621.40, Windows 11, on main ccfb029, cargo test -p victory-shader -- --test-threads=1 (hardware, then WARP) and cargo test -p victory-gpu:

build victory-shader still failing victory-gpu
this PR (pr-2178 head) 245 passed, 2 failed gathers_at_a_level_match_the_hardware, ..._no_buffer_view_is_reads_zeros (heap cap, #1779) 141 passed, 2 failed (heap cap)
this PR + #1887 246 passed, 2 failed #1887's StructuredDesc test, the heap cap 141 passed, 2 failed (heap cap)

The gather test still fails here because synthetic_tests binds its input with Stride::Structured(16), which the test host makes structured; #1887 makes the test host's view raw, and with both the gather passes. The two only conflict on one line in stride_tests.rs (this PR's Stride::Raw against #1887's read_by_element(stride) helper). #1887's StructuredDesc test reproduces the runtime's view as it is before this PR, so it should go if this lands; I'll drop it there on rebase.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159557978 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7159557978). Originally posted by [carlos-seiffert](https://github.com/carlos-seiffert) on 2026-11-25T10:20:20Z. --- RTX 2060 6 GB (Turing), driver 621.40, Windows 11, on `main` `ccfb029`, `cargo test -p victory-shader -- --test-threads=1` (hardware, then WARP) and `cargo test -p victory-gpu`: | build | victory-shader | still failing | victory-gpu | |---|---|---|---| | this PR (`pr-2178` head) | 245 passed, 2 failed | `gathers_at_a_level_match_the_hardware`, `..._no_buffer_view_is_reads_zeros` (heap cap, #1779) | 141 passed, 2 failed (heap cap) | | this PR + #1887 | 246 passed, 2 failed | #1887's `StructuredDesc` test, the heap cap | 141 passed, 2 failed (heap cap) | The gather test still fails here because `synthetic_tests` binds its input with `Stride::Structured(16)`, which the test host makes structured; #1887 makes the test host's view raw, and with both the gather passes. The two only conflict on one line in `stride_tests.rs` (this PR's `Stride::Raw` against #1887's `read_by_element(stride)` helper). #1887's `StructuredDesc` test reproduces the runtime's view as it is before this PR, so it should go if this lands; I'll drop it there on rebase. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Capi360 commented 2026-11-25 11:05:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Capi360 on 2026-11-25T10:18:50Z.


Offline A/B on an RTX 3060 Ti (8 GiB, NVIDIA 616.56), Ryzen 7 5700X3D, 32 GiB RAM, Windows 11 Pro build 26200.

Both Series X runs used the diagnostic build, one GPU list at a time, fresh caches and the default shader loop limit. The control (6934776, main 940d32f plus the NVIDIA heap bounds, packed target changes and #242) reset with 0x887A0006 at the same direct 16×16×16 compute dispatch as the packed baseline. No world-rate samples were recorded.

Adding this PR (9124d69, tested in integration commit 7f74e22) passed that point and logged seven intervals with more than 200 draws/frame, averaging 0.64 FPS. It later reset at a separate single-record indirect compute dispatch. Visible geometry and playability are still unverified. All six stride_tests passed on the integration build.

AI-assisted testing. Code-only integration branch: https://github.com/Capi360/VIctory/tree/codex/rtx-3060-ti-current-raw-views

I also tested a follow-up for structured views whose offset in the host buffer is a valid element offset but is not 16-byte aligned. This PR can leave those views structured even when the shader expects raw access. The follow-up uses the same aligned copy when creating and refreshing the view. The targeted D3D12 regression test passed on the RTX 3060 Ti. The later indirect compute reset still reproduced. Code: github.com/Capi360/VIctory@9aad41fd53

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159524020 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7159524020). Originally posted by [Capi360](https://github.com/Capi360) on 2026-11-25T10:18:50Z. --- Offline A/B on an RTX 3060 Ti (8 GiB, NVIDIA 616.56), Ryzen 7 5700X3D, 32 GiB RAM, Windows 11 Pro build 26200. Both Series X runs used the diagnostic build, one GPU list at a time, fresh caches and the default shader loop limit. The control (`6934776`, main `940d32f` plus the NVIDIA heap bounds, packed target changes and #242) reset with `0x887A0006` at the same direct `16×16×16` compute dispatch as the packed baseline. No world-rate samples were recorded. Adding this PR (`9124d69`, tested in integration commit `7f74e22`) passed that point and logged seven intervals with more than 200 draws/frame, averaging 0.64 FPS. It later reset at a separate single-record indirect compute dispatch. Visible geometry and playability are still unverified. All six `stride_tests` passed on the integration build. AI-assisted testing. Code-only integration branch: https://github.com/Capi360/VIctory/tree/codex/rtx-3060-ti-current-raw-views I also tested a follow-up for structured views whose offset in the host buffer is a valid element offset but is not 16-byte aligned. This PR can leave those views structured even when the shader expects raw access. The follow-up uses the same aligned copy when creating and refreshing the view. The targeted D3D12 regression test passed on the RTX 3060 Ti. The later indirect compute reset still reproduced. Code: https://github.com/Capi360/VIctory/commit/9aad41fd539e80ac52a45462eda8e294feb511b4
steven-seagull27 commented 2026-11-25 11:05:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-25T10:49:14Z.


On my RTX 5080, #2178 fixed the structured-buffer read at byte offset 0. I found a remaining case through the production descriptor path. With a 12-byte record stride, views starting at bytes 12, 24 and 36 returned the wrong data. A shader querying one of those 32-record views also got 10 records. Offsets 0 and 48 worked, and moving the same data from offset 12 to offset 0 restored all 32 values.

I tested on Windows 11 build 26300.10075, NVIDIA driver 621.40 and built-in WARP 10.0.26100.10068. The baseline combines this head 9124d69, #2177 at 1a3261f, and Venom2054’s heap-allocation correction. Both columns below use that same baseline. Exact integration commit

Runtime readback RTX mismatches before → after WARP mismatches before → after
Offsets, relocated input and null slot 96 → 0 of 224 0 → 0 of 224
GPU writes observed through overlapping views 1,425 → 0 of 2,400 0 → 0 of 2,400
Replacing a heap slot with different starts, strides and null views 160 → 0 of 480 0 → 0 of 480
Fixed table, record count and payload checked separately 192 → 0 of 320 0 → 0 of 320

The candidate aligns the raw SRV start down to 16 bytes, retains the original end, and records the leading dwords in the slot’s stride entry. The translated read adds that offset, and the dimensions query subtracts it. The original GPU backing stays shared. After the change, both readers saw the value 31 written by lane 31, including the offset-12 reader that previously returned zero. All tested views reported the expected 32 records. The change covers SRV reads. Displaced views whose expanded byte length exceeds the 32-bit offset range retain the previous handling. These are synthetic GPU readbacks. Game frame times remain unmeasured. Read-side fix · Four opt-in tests

The fix and tests are separate commits that can be cherry-picked onto the combined baseline. To rerun the exact published tree from a VIctory checkout in PowerShell:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/structured-srv-readbacks
git worktree add --detach ../victory-srv-readbacks FETCH_HEAD
Set-Location ../victory-srv-readbacks
$env:VICTORY_D3D12_WARP = '0'
cargo test -p victory-gpu --all-features --lib --locked structured_srv_readbacks -- --ignored --nocapture --test-threads=1
$env:VICTORY_D3D12_WARP = '1'
cargo test -p victory-gpu --all-features --lib --locked structured_srv_readbacks -- --ignored --nocapture --test-threads=1
<!-- greyfinch-sync:Marvisak/VIctory:comment:7160216350 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7160216350). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-25T10:49:14Z. --- On my RTX 5080, #2178 fixed the structured-buffer read at byte offset 0. I found a remaining case through the production descriptor path. With a 12-byte record stride, views starting at bytes 12, 24 and 36 returned the wrong data. A shader querying one of those 32-record views also got **10 records**. Offsets 0 and 48 worked, and moving the same data from offset 12 to offset 0 restored all 32 values. I tested on Windows 11 build 26300.10075, NVIDIA driver 621.40 and built-in WARP 10.0.26100.10068. The baseline combines this head `9124d69`, #2177 at `1a3261f`, and Venom2054’s heap-allocation correction. Both columns below use that same baseline. [Exact integration commit](https://github.com/steven-seagull27/VIctory/commit/7c2e21c26f1a74d0191a094fd975f6dd65152e27) | Runtime readback | RTX mismatches before → after | WARP mismatches before → after | |---|---:|---:| | Offsets, relocated input and null slot | 96 → 0 of 224 | 0 → 0 of 224 | | GPU writes observed through overlapping views | 1,425 → 0 of 2,400 | 0 → 0 of 2,400 | | Replacing a heap slot with different starts, strides and null views | 160 → 0 of 480 | 0 → 0 of 480 | | Fixed table, record count and payload checked separately | 192 → 0 of 320 | 0 → 0 of 320 | The candidate aligns the raw SRV start down to 16 bytes, retains the original end, and records the leading dwords in the slot’s stride entry. The translated read adds that offset, and the dimensions query subtracts it. The original GPU backing stays shared. After the change, both readers saw the value 31 written by lane 31, including the offset-12 reader that previously returned zero. All tested views reported the expected 32 records. The change covers SRV reads. Displaced views whose expanded byte length exceeds the 32-bit offset range retain the previous handling. These are synthetic GPU readbacks. Game frame times remain unmeasured. [Read-side fix](https://github.com/steven-seagull27/VIctory/commit/bb066b8a0a2e753efb172a0233dad18a90f2dd73) · [Four opt-in tests](https://github.com/steven-seagull27/VIctory/commit/e61603d1e12360ec978532ec7299243b66f08082) The fix and tests are separate commits that can be cherry-picked onto the combined baseline. To rerun the exact published tree from a VIctory checkout in PowerShell: ```powershell git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/structured-srv-readbacks git worktree add --detach ../victory-srv-readbacks FETCH_HEAD Set-Location ../victory-srv-readbacks $env:VICTORY_D3D12_WARP = '0' cargo test -p victory-gpu --all-features --lib --locked structured_srv_readbacks -- --ignored --nocapture --test-threads=1 $env:VICTORY_D3D12_WARP = '1' cargo test -p victory-gpu --all-features --lib --locked structured_srv_readbacks -- --ignored --nocapture --test-threads=1 ```
Qedycik commented 2026-11-25 11:05:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Qedycik on 2026-11-25T10:57:20Z.


Vendor matrix and an in-game measurement (RTX 5080, AMD RDNA2 iGPU)

We ran into the same NVIDIA behaviour independently, in our own tree (upstream f821cb9 plus local changes, not this PR's code), and measured both directions of the mismatch with a synthetic compute test (our own GFX10 words, no title data). Lane t reads the 16-byte element t of a heap SRV whose elements are (t, 1000+t, 2000+t, 3000+t) and stores what it read. The right answer is t.

Access, view RTX 5080 AMD Radeon iGPU (RDNA2)
raw read (offen, byte 16·t) of a structured view read in elements: 0, 4, 8, ...; zeros past the view right
indexed read (idxen) of a raw view read in 4-byte elements: 0, 1000, ... zeros
raw read of a raw view right right
indexed read lowered to raw (index·stride + offset) of a raw view right right

Driver at the time of writing: 616.56; the version during the 24 Nov measurements was not recorded.

What this means for the change here:

  • Once a view is made raw, every indexed access through it has to be lowered raw as well, on every vendor. AMD returns zeros for a structured declaration over a raw view, so a raw view that some shader still reads structured breaks AMD instead of fixing NVIDIA.
  • We made a structured view raw only when its start allows a raw view (byte offset a multiple of 16, D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) and kept the title's kind otherwise. That matches the remaining 12-byte-stride case reported above: views at bytes 12, 24 and 36 are wrong, 0 and 48 are right.

In the world, one compute dispatch (42683eeb) reads two sizes from small structured views (strides 20 and 16). Reading zeros, its loop bounds never ended: every group ran to the translator's loop limit and the dispatch took 780-845 ms of each world frame. With structured heap views made raw on NVIDIA, the dispatch left the slow-command list (nothing above 50 ms) and host GPU time per world frame went from about 920 ms to 80-230 ms. With indexed accesses lowered raw as well (raw views on every vendor), a 90 s world run with device-removed data on had no removal and 60-180 ms of host GPU time per frame.

Not measured: this PR's own head on our machine.

(Measurements and write-up AI-assisted, Claude Code.)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160394738 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7160394738). Originally posted by [Qedycik](https://github.com/Qedycik) on 2026-11-25T10:57:20Z. --- ### Vendor matrix and an in-game measurement (RTX 5080, AMD RDNA2 iGPU) We ran into the same NVIDIA behaviour independently, in our own tree (upstream `f821cb9` plus local changes, not this PR's code), and measured both directions of the mismatch with a synthetic compute test (our own GFX10 words, no title data). Lane `t` reads the 16-byte element `t` of a heap SRV whose elements are `(t, 1000+t, 2000+t, 3000+t)` and stores what it read. The right answer is `t`. | Access, view | RTX 5080 | AMD Radeon iGPU (RDNA2) | |---|---|---| | raw read (`offen`, byte `16·t`) of a structured view | read in elements: 0, 4, 8, ...; zeros past the view | right | | indexed read (`idxen`) of a raw view | read in 4-byte elements: 0, 1000, ... | zeros | | raw read of a raw view | right | right | | indexed read lowered to raw (`index·stride + offset`) of a raw view | right | right | Driver at the time of writing: 616.56; the version during the 24 Nov measurements was not recorded. What this means for the change here: - Once a view is made raw, every indexed access through it has to be lowered raw as well, on every vendor. AMD returns zeros for a structured declaration over a raw view, so a raw view that some shader still reads structured breaks AMD instead of fixing NVIDIA. - We made a structured view raw only when its start allows a raw view (byte offset a multiple of 16, `D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT`) and kept the title's kind otherwise. That matches the remaining 12-byte-stride case reported above: views at bytes 12, 24 and 36 are wrong, 0 and 48 are right. In the world, one compute dispatch (`42683eeb`) reads two sizes from small structured views (strides 20 and 16). Reading zeros, its loop bounds never ended: every group ran to the translator's loop limit and the dispatch took 780-845 ms of each world frame. With structured heap views made raw on NVIDIA, the dispatch left the slow-command list (nothing above 50 ms) and host GPU time per world frame went from about 920 ms to 80-230 ms. With indexed accesses lowered raw as well (raw views on every vendor), a 90 s world run with device-removed data on had no removal and 60-180 ms of host GPU time per frame. Not measured: this PR's own head on our machine. (Measurements and write-up AI-assisted, Claude Code.)
steven-seagull27 commented 2026-11-25 12:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-25T11:28:19Z.


@Qedycik, thanks for checking both vendors and measuring the slow world dispatch. Could you try the aligned-start SRV patch on your RDNA2 iGPU? The published test tree is e61603d. The four opt-in tests print the selected device. I’m particularly interested in whether views starting at bytes 12, 24 and 36 return the expected data and report all 32 records. The adapter name, driver, and any mismatch counts would help. Test commands and RTX/WARP results

If you still have that world scene handy, could you also compare the same scene on the same adapter and settings before and after the patch? The exact A/B is 7c2e21c → bb066b8. Host GPU time per frame and the time for dispatch 42683eeb (or whether it drops off the slow-command list) would let us compare with your earlier run. Either the AMD readbacks or the world timings would help on their own. Baseline · Patch

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161090818 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7161090818). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-25T11:28:19Z. --- @Qedycik, thanks for checking both vendors and measuring the slow world dispatch. Could you try the aligned-start SRV patch on your RDNA2 iGPU? The published test tree is `e61603d`. The four opt-in tests print the selected device. I’m particularly interested in whether views starting at bytes 12, 24 and 36 return the expected data and report all 32 records. The adapter name, driver, and any mismatch counts would help. [Test commands and RTX/WARP results](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7160216350) If you still have that world scene handy, could you also compare the same scene on the same adapter and settings before and after the patch? The exact A/B is `7c2e21c` → `bb066b8`. Host GPU time per frame and the time for dispatch `42683eeb` (or whether it drops off the slow-command list) would let us compare with your earlier run. Either the AMD readbacks or the world timings would help on their own. [Baseline](https://github.com/steven-seagull27/VIctory/commit/7c2e21c26f1a74d0191a094fd975f6dd65152e27) · [Patch](https://github.com/steven-seagull27/VIctory/commit/bb066b8a0a2e753efb172a0233dad18a90f2dd73)
Marvisak commented 2026-11-25 14:07:18 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs work: needs the maintainer's decision. It now merges cleanly into main. CI: check passing.

The PR makes structured buffer views raw (buffer_srv/buffer_uav in descriptor/host.rs, with 16-byte-aligned copies) and lowers structured table accesses as raw loads and stores at byte offsets (emit/lower.rs). It does this through a new process-wide flag, set_host_raw_structured, which shader_cache::build sets. A raw view read by raw loads is well defined, and the vendor matrix in this thread supports making the view and every access raw together. Four things block merging:

  • Because the toggle is global, the victory-shader tests translate with it off. a_heap_buffer_read_by_element_takes_the_views_stride in stride_tests was switched to a Stride::Raw view, so it now binds a raw view under a structured (12) handle, the very mismatch this PR is meant to remove. Either set the flag in that test or make it a field of the translation Options.
  • Every structured view that does not start on 16 bytes now gets its own copy (the draw.rs test expects that). That costs extra copies, so please measure it.
  • The commit has no description. The NVIDIA rawBufferLoad behaviour it relies on is shown by the readbacks in this thread, so summarise that in the PR.
  • This overlaps #2464 (NVIDIA-only raw structured views in the runtime) and #1887, so the maintainer should pick one approach.

Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163823848 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7163823848). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:28:15Z. --- <!-- victory-triage v1 head=319749e45737b4dd76e274a88acd0d2504fcd916 verdict=needs-work at=2026-11-25T19:45:00Z --> Automated triage for the maintainers. **Needs work: needs the maintainer's decision.** It now merges cleanly into `main`. CI: `check` passing. The PR makes structured buffer views raw (`buffer_srv`/`buffer_uav` in `descriptor/host.rs`, with 16-byte-aligned copies) and lowers structured table accesses as raw loads and stores at byte offsets (`emit/lower.rs`). It does this through a new process-wide flag, `set_host_raw_structured`, which `shader_cache::build` sets. A raw view read by raw loads is well defined, and the vendor matrix in this thread supports making the view and every access raw together. Four things block merging: - Because the toggle is global, the `victory-shader` tests translate with it off. `a_heap_buffer_read_by_element_takes_the_views_stride` in `stride_tests` was switched to a `Stride::Raw` view, so it now binds a raw view under a structured (12) handle, the very mismatch this PR is meant to remove. Either set the flag in that test or make it a field of the translation `Options`. - Every structured view that does not start on 16 bytes now gets its own copy (the `draw.rs` test expects that). That costs extra copies, so please measure it. - The commit has no description. The NVIDIA `rawBufferLoad` behaviour it relies on is shown by the readbacks in this thread, so summarise that in the PR. - This overlaps #2464 (NVIDIA-only raw structured views in the runtime) and #1887, so the maintainer should pick one approach. --- _Generated by [Claude Code](https://claude.ai/code)_
n-romanovich commented 2026-11-25 14:07:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-25T14:01:52Z.


@Marvisak, updated pr/raw-structured-buffers (e1b447c) to address the triage points:

  1. Every structured view lowered to raw is now raw on the host: buffer_srv and buffer_uav in crates/victory-gpu/src/descriptor/host.rs now request align = 16 from shadow::for_view whenever StructureByteStride > 0 && element.is_multiple_of(4). If the shared shadow copy's offset is not 16-byte aligned (e.g., byte offsets 12, 24, 36 with a 12-byte stride), shadow::for_view provides a 16-byte-aligned exact copy (offset == 0), so the host descriptor is always RAW without any shader/descriptor mismatch.
  2. Unaligned-start test: added descriptor::host::tests::unaligned_structured_buffer_views_use_aligned_raw_copy covering 12-byte stride SRV/UAV creation at unaligned byte offsets 12, 24, and 36.
  3. Coordination with #2177: this branch touches shader_cache::key and emit/mod.rs independently of #2177; whichever lands second will rebase cleanly onto the first (adding its Options field / cache key component).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7164650737 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7164650737). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-25T14:01:52Z. --- @Marvisak, updated `pr/raw-structured-buffers` (`e1b447c`) to address the triage points: 1. **Every structured view lowered to raw is now raw on the host**: `buffer_srv` and `buffer_uav` in `crates/victory-gpu/src/descriptor/host.rs` now request `align = 16` from `shadow::for_view` whenever `StructureByteStride > 0 && element.is_multiple_of(4)`. If the shared shadow copy's offset is not 16-byte aligned (e.g., byte offsets 12, 24, 36 with a 12-byte stride), `shadow::for_view` provides a 16-byte-aligned `exact` copy (`offset == 0`), so the host descriptor is always `RAW` without any shader/descriptor mismatch. 2. **Unaligned-start test**: added `descriptor::host::tests::unaligned_structured_buffer_views_use_aligned_raw_copy` covering 12-byte stride SRV/UAV creation at unaligned byte offsets 12, 24, and 36. 3. **Coordination with #2177**: this branch touches `shader_cache::key` and `emit/mod.rs` independently of #2177; whichever lands second will rebase cleanly onto the first (adding its `Options` field / cache key component).
passerbyyhx commented 2026-11-25 21:03:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-25T20:11:38Z.


I measured the alignment fallback on 319749e with a GeForce RTX 4090 Laptop GPU (621.14). For 30 fresh 48-byte SRVs per batch, median CPU creation time was 12.0–12.8 µs aligned and 74.3–82.8 µs unaligned across three independent runs. The unaligned case created 30 exact slices. Rewriting the same live windows created zero new slices and cost 13.9–14.9 µs (11.8–12.5 µs aligned).

CPU refresh at submission still took 23.6–24.4 µs unaligned versus 6.0–6.9 µs aligned, even though the unaligned case refreshed fewer bytes in this synthetic layout. All 311,040 GPU-read dwords matched. The timings exclude GPU execution and fence waits.

Benchmark, p95 values, and reproduction command. Code and hardware testing assisted by Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173316469 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7173316469). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-25T20:11:38Z. --- I measured the alignment fallback on `319749e` with a GeForce RTX 4090 Laptop GPU (621.14). For 30 fresh 48-byte SRVs per batch, median CPU creation time was 12.0–12.8 µs aligned and 74.3–82.8 µs unaligned across three independent runs. The unaligned case created 30 exact slices. Rewriting the same live windows created zero new slices and cost 13.9–14.9 µs (11.8–12.5 µs aligned). CPU refresh at submission still took 23.6–24.4 µs unaligned versus 6.0–6.9 µs aligned, even though the unaligned case refreshed fewer bytes in this synthetic layout. All 311,040 GPU-read dwords matched. The timings exclude GPU execution and fence waits. [Benchmark, p95 values, and reproduction command](https://github.com/n-romanovich/VIctory/pull/1). Code and hardware testing assisted by Codex.
davesousa commented 2026-11-25 22:04:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by davesousa on 2026-11-25T21:27:16Z.


In-game on NVIDIA Ampere, against W from #1968 (dispatch 16x16x16 [compute 00167d58cc5a78d7]): RTX 3070 Ti 8 GB, driver 621.40, Windows 11 26200, 32 GB RAM. diag build, VICTORY_D3D12_DRED=1, shader cache and pipelines rebuilt with translate --cache --pipelines for each build. Base main 13f91ca + #2319 (boot) + #1906 (program A); this PR at 319749e merges cleanly on top.

Build W per host submission Longest host submission World time End
base 10.1-11.6 s (21 submissions, average 11.3 s) 11.6 s about 5.7 min 0x887A0006, DRED stop on W
base + this PR W bound (first at frame 1371) but in no slow submission 0.68 s (92 submissions over the slow-log threshold) 13.5 min, intro cutscene with credits, up to 7,733 draws/frame none; I stopped it at 15 min. No nvlddmkm events

With this PR, world frames were 0.40-5.4 s (median 0.84 s over 79 samples, one every 10 s). Peaks were 7.6 GB of video memory and about 31 GB of Windows commit. 170 compute pipelines were still refused by the host (the WaveSize(64) set, #2220).

So on this card the structured-to-raw change is what removes W's 11 s. That fits the cause in #1968 (W's loop bound read from a structured view). Without the change, #2167 alone left W unchanged here (my comment there). I have not tried the overlapping #2464 or #1887 in-game, so this does not choose between the approaches. It also does not isolate the cost of the extra 16-byte-aligned copies: the base never got far enough for a frame-time comparison.

Tests on this card with this PR merged (base as above): victory-shader --lib (one thread): a_heap_buffer_read_by_element_takes_the_views_stride now passes; the remaining failures are the ones main has here. victory-gpu --lib: 196 passed, 2 failed (the view-heap-cap pair, as on main), plus a_slot_rewritten_while_its_view_is_prepared_views_the_new_record failing in 1 of 6 runs (it passed alone on this PR, on the base and on main).

One of the two runs of this build ended at boot with the title's own 0xc0000005 write to 0 (image+0x2215c35) before the first menu, as I saw with another PR combination (#2167). I can't attribute it.

AI-assisted (Claude Code); the runs are on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175097913 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7175097913). Originally posted by [davesousa](https://github.com/davesousa) on 2026-11-25T21:27:16Z. --- In-game on NVIDIA Ampere, against W from #1968 (`dispatch 16x16x16 [compute 00167d58cc5a78d7]`): RTX 3070 Ti 8 GB, driver 621.40, Windows 11 26200, 32 GB RAM. `diag` build, `VICTORY_D3D12_DRED=1`, shader cache and pipelines rebuilt with `translate --cache --pipelines` for each build. Base `main` `13f91ca` + #2319 (boot) + #1906 (program A); this PR at `319749e` merges cleanly on top. | Build | W per host submission | Longest host submission | World time | End | |---|---|---|---|---| | base | 10.1-11.6 s (21 submissions, average 11.3 s) | 11.6 s | about 5.7 min | `0x887A0006`, DRED stop on W | | base + this PR | W bound (first at frame 1371) but in no slow submission | 0.68 s (92 submissions over the slow-log threshold) | **13.5 min**, intro cutscene with credits, up to 7,733 draws/frame | none; I stopped it at 15 min. No `nvlddmkm` events | With this PR, world frames were 0.40-5.4 s (median 0.84 s over 79 samples, one every 10 s). Peaks were 7.6 GB of video memory and about 31 GB of Windows commit. 170 compute pipelines were still refused by the host (the WaveSize(64) set, #2220). So on this card the structured-to-raw change is what removes W's 11 s. That fits the cause in #1968 (W's loop bound read from a structured view). Without the change, #2167 alone left W unchanged here (my comment there). I have not tried the overlapping #2464 or #1887 in-game, so this does not choose between the approaches. It also does not isolate the cost of the extra 16-byte-aligned copies: the base never got far enough for a frame-time comparison. Tests on this card with this PR merged (base as above): `victory-shader --lib` (one thread): `a_heap_buffer_read_by_element_takes_the_views_stride` now passes; the remaining failures are the ones `main` has here. `victory-gpu --lib`: 196 passed, 2 failed (the view-heap-cap pair, as on `main`), plus `a_slot_rewritten_while_its_view_is_prepared_views_the_new_record` failing in 1 of 6 runs (it passed alone on this PR, on the base and on `main`). One of the two runs of this build ended at boot with the title's own `0xc0000005` write to 0 (`image+0x2215c35`) before the first menu, as I saw with another PR combination (#2167). I can't attribute it. AI-assisted (Claude Code); the runs are on my machine.
steven-seagull27 commented 2026-11-26 02:07:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T01:22:22Z.


@n-romanovich I ran the GPU-write case on 319749e with the production raw-structured shader mode enabled. Reads through the same view origin saw 160/160 values that the GPU had just written. Reads through other views of the same memory still saw stale data.

2,400 words per adapter RTX 5080, 621.40 Windows WARP, 10.0.26100.10068
Current PR, 319749e, standalone 544 wrong 544 wrong
Earlier PR, 553c1d4, standalone 1,518 wrong 1,518 wrong
Earlier shared-backing control, bb066b8, on the #2177/#2178 integration 0 wrong 0 wrong

The fixture initializes the allocation once. A translated shader writes one dword per 12-byte record through a placed UAV. After a fence, a second translated shader reads the same bytes through five placed SRVs. All 1,600 untouched field values matched on the current head. All 544 mismatches were in the field the GPU had written, through a reader with a different origin. For example, a writer at byte 12 and a reader at byte 24 share 31 records. All 31 returned their initial value. The 32nd, non-overlapping record retained its expected value. This exercises an additional case beyond CPU-initialized reads and the reported in-game timing improvement.

This test-only commit is directly on 319749e. I reran the committed test on both devices. In a clean checkout:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2178-overlapping-gpu-writes
git switch --detach ec6ea83c94ddd956b84fce4c2167ad1ead3aeae2
$env:VICTORY_D3D12_WARP = '0'
cargo test -p victory-gpu --all-features --lib --locked gpu_writes_visible_through_overlapping_views -- --ignored --nocapture --test-threads=1
$env:VICTORY_D3D12_WARP = '1'
cargo test -p victory-gpu --all-features --lib --locked gpu_writes_visible_through_overlapping_views -- --ignored --nocapture --test-threads=1

The per-view aligned copies can contain different versions of the same GPU-written bytes. The shared-backing control is one measured reference for preserving visibility. Synthetic D3D12 readbacks, AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179707925 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7179707925). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T01:22:22Z. --- @n-romanovich I ran the GPU-write case on `319749e` with the production raw-structured shader mode enabled. Reads through the same view origin saw **160/160** values that the GPU had just written. Reads through other views of the same memory still saw stale data. | 2,400 words per adapter | RTX 5080, 621.40 | Windows WARP, 10.0.26100.10068 | |---|---:|---:| | Current PR, `319749e`, standalone | 544 wrong | 544 wrong | | Earlier PR, `553c1d4`, standalone | 1,518 wrong | 1,518 wrong | | Earlier shared-backing control, `bb066b8`, on the #2177/#2178 integration | 0 wrong | 0 wrong | The fixture initializes the allocation once. A translated shader writes one dword per 12-byte record through a placed UAV. After a fence, a second translated shader reads the same bytes through five placed SRVs. All 1,600 untouched field values matched on the current head. All 544 mismatches were in the field the GPU had written, through a reader with a different origin. For example, a writer at byte 12 and a reader at byte 24 share 31 records. **All 31 returned their initial value.** The 32nd, non-overlapping record retained its expected value. This exercises an additional case beyond CPU-initialized reads and the reported in-game timing improvement. This [test-only commit](https://github.com/steven-seagull27/VIctory/commit/ec6ea83c94ddd956b84fce4c2167ad1ead3aeae2) is directly on `319749e`. I reran the committed test on both devices. In a clean checkout: ```powershell git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2178-overlapping-gpu-writes git switch --detach ec6ea83c94ddd956b84fce4c2167ad1ead3aeae2 $env:VICTORY_D3D12_WARP = '0' cargo test -p victory-gpu --all-features --lib --locked gpu_writes_visible_through_overlapping_views -- --ignored --nocapture --test-threads=1 $env:VICTORY_D3D12_WARP = '1' cargo test -p victory-gpu --all-features --lib --locked gpu_writes_visible_through_overlapping_views -- --ignored --nocapture --test-threads=1 ``` The per-view aligned copies can contain different versions of the same GPU-written bytes. The [shared-backing control](https://github.com/steven-seagull27/VIctory/commit/bb066b8a0a2e753efb172a0233dad18a90f2dd73) is one measured reference for preserving visibility. Synthetic D3D12 readbacks, AI-assisted with Codex.
ChenmouXu commented 2026-11-26 13:04:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ChenmouXu on 2026-11-26T12:58:32Z.


摘要

在 NVIDIA 硬件上,对 D3D12 描述符 () 执行 DXIL () 会将字节偏移乘以 ,导致读取损坏并返回过去的零(如 )。rawBufferLoad``ByteAddressBuffer``StructuredBuffer``StructureByteStride > 0``StructureByteStride``width / stride``stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride

这一变化:

  • 将结构化缓冲区SRV和UAV(4字节对齐元素大小)转换为带 和 (仍记录原始元素步幅)。StructureByteStride > 0``DXGI_FORMAT_R32_TYPELESS``D3D12_BUFFER_{SRV,UAV}_FLAG_RAW``buffer_srv``buffer_uav``HostHeap``VIEW_STRIDES
  • 添加 / (由 启用并包含于 ),因此描述符表中索引/标量加载的结构化缓冲区也降至原始字节地址的读写、原子等。set_host_raw_structured``host_raw_structured``victory_shader::emit``victory-gpu``shader_cache::key``getDimensions / stride
  • 更新以在表旁传递一个原始堆描述符(),与模块合同相匹配。stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride``Stride::Raw``VIEW_STRIDES``emit

验证

在NVIDIA GeForce RTX 5060 Ti上测试:

  • cargo test --release -p victory-shader --lib -- stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride diff_tests:6 passed; 0 failed
  • cargo test --release -p victory-gpu --lib -- shader_cache::tests:3 passed; 0 failed

#2178 GPU+shader: back structured buffer views with raw descriptors for NVIDIA rawBufferLoad

<!-- greyfinch-sync:Marvisak/VIctory:comment:7192706208 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7192706208). Originally posted by [ChenmouXu](https://github.com/ChenmouXu) on 2026-11-26T12:58:32Z. --- > ## 摘要 > 在 NVIDIA 硬件上,对 D3D12 描述符 () 执行 DXIL () 会将字节偏移乘以 ,导致读取损坏并返回过去的零(如 )。`rawBufferLoad``ByteAddressBuffer``StructuredBuffer``StructureByteStride > 0``StructureByteStride``width / stride``stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` > > 这一变化: > > * 将结构化缓冲区SRV和UAV(4字节对齐元素大小)转换为带 和 (仍记录原始元素步幅)。`StructureByteStride > 0``DXGI_FORMAT_R32_TYPELESS``D3D12_BUFFER_{SRV,UAV}_FLAG_RAW``buffer_srv``buffer_uav``HostHeap``VIEW_STRIDES` > * 添加 / (由 启用并包含于 ),因此描述符表中索引/标量加载的结构化缓冲区也降至原始字节地址的读写、原子等。`set_host_raw_structured``host_raw_structured``victory_shader::emit``victory-gpu``shader_cache::key``getDimensions / stride` > * 更新以在表旁传递一个原始堆描述符(),与模块合同相匹配。`stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride``Stride::Raw``VIEW_STRIDES``emit` > > ## 验证 > 在NVIDIA GeForce RTX 5060 Ti上测试: > > * `cargo test --release -p victory-shader --lib -- stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride diff_tests`:`6 passed; 0 failed` > * `cargo test --release -p victory-gpu --lib -- shader_cache::tests`:`3 passed; 0 failed` #2178 GPU+shader: back structured buffer views with raw descriptors for NVIDIA rawBufferLoad
kalberts0089-hash commented 2026-11-27 10:37:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kalberts0089-hash on 2026-11-27T10:37:39Z.


NVIDIA Ada run at the current head (RTX 4070 Ti)

Setup

  • GPU: NVIDIA GeForce RTX 4070 Ti (Ada), driver 621.01, Windows 11. Default adapter, no WARP override.
  • Head 3c1d743 (its base is 13f91ca), merged locally onto main 63bcca4 with git merge --no-commit. The merge was clean. Nothing else applied.
  • cargo test -p victory-gpu --lib -- --test-threads=1
  • cargo test -p victory-shader --lib --no-fail-fast -- --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index (that test crashes the test process on this card on main, #2571)

Confirmed

Build victory-gpu victory-shader
main 63bcca4 229 passed, 2 failed, 1 ignored 298 passed, 3 failed, 3 ignored
main + this PR (3c1d743) 230 passed, 2 failed, 1 ignored 299 passed, 2 failed, 3 ignored
  • emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride fails on main on the hardware leg (it reads [101, 104, 107, ...] then zeros, expected [200, 201, ...]) and passes with this PR: once in the full suite, once in emit::stride_tests:: run alone, and 3 of 3 with --exact.
  • The new descriptor::host::tests::unaligned_structured_buffer_views_use_aligned_raw_copy passes in the suite and 3 of 3 with --exact.
  • No test passes on main and fails with the PR, in either crate.
  • The opt-in draw::tests::alignment_cost::structured_srv_alignment_cost (release, --features diagnostics --ignored, run alone) passed 3 of 3, including its readback assertions for 12-byte-stride views starting at bytes 12, 24 and 36. CPU time per batch of 30 views, p50 over the three runs:
Case create refresh
aligned starts (0, 48), fresh 9.7-9.8 µs 4.7-4.8 µs
aligned starts, live 9.6-9.7 µs 4.4-4.5 µs
unaligned starts (12, 24, 36), fresh, 30 new slices 58.0-128.0 µs 19.7-19.9 µs
unaligned starts, live, 0 new slices 10.7-10.9 µs 19.3-19.7 µs

Failures that remain, unrelated to this PR (the same on main on this card)

  • victory-gpu: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views
  • victory-shader: emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros (hardware: dispatch failed: The parameter is incorrect.), emit::synthetic_tests::gathers_at_a_level_match_the_hardware (lane 0 gives [0.0, 1.0, 0.0, 0.0], expected zeros)

Their failure output is identical to main's, apart from one panic line number in host.rs that moved with the added code.

Question

  • Nothing in victory-shader calls set_host_raw_structured(true); only shader_cache::build in victory-gpu does. So does the stride test above pass with the raw lowering in lower.rs switched off, on a Stride::Raw view under a structured handle? If so, this run does not cover the translated raw path on hardware.

Not tested

  • The title, or any in-game behaviour.
  • The AMD path.
  • Translated shaders with host_raw_structured on (see the question).
  • The record count a shader gets from views that start at bytes 12, 24 and 36, and reads through other views of the same memory after a GPU write (the cases steven-seagull27 reported). The PR's own tests do not cover them and I did not add tests.
  • Interaction with #2177, #2464 or #1887.
  • GPU execution time: the benchmark figures are CPU time only.

Synthetic tests only, no game files. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7216112803 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7216112803). Originally posted by [kalberts0089-hash](https://github.com/kalberts0089-hash) on 2026-11-27T10:37:39Z. --- ### NVIDIA Ada run at the current head (RTX 4070 Ti) **Setup** - GPU: NVIDIA GeForce RTX 4070 Ti (Ada), driver 621.01, Windows 11. Default adapter, no WARP override. - Head `3c1d743` (its base is `13f91ca`), merged locally onto `main` `63bcca4` with `git merge --no-commit`. The merge was clean. Nothing else applied. - `cargo test -p victory-gpu --lib -- --test-threads=1` - `cargo test -p victory-shader --lib --no-fail-fast -- --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index` (that test crashes the test process on this card on `main`, #2571) **Confirmed** | Build | victory-gpu | victory-shader | |---|---|---| | `main` `63bcca4` | 229 passed, 2 failed, 1 ignored | 298 passed, 3 failed, 3 ignored | | `main` + this PR (`3c1d743`) | 230 passed, 2 failed, 1 ignored | 299 passed, 2 failed, 3 ignored | - `emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` fails on `main` on the hardware leg (it reads `[101, 104, 107, ...]` then zeros, expected `[200, 201, ...]`) and passes with this PR: once in the full suite, once in `emit::stride_tests::` run alone, and 3 of 3 with `--exact`. - The new `descriptor::host::tests::unaligned_structured_buffer_views_use_aligned_raw_copy` passes in the suite and 3 of 3 with `--exact`. - No test passes on `main` and fails with the PR, in either crate. - The opt-in `draw::tests::alignment_cost::structured_srv_alignment_cost` (release, `--features diagnostics --ignored`, run alone) passed 3 of 3, including its readback assertions for 12-byte-stride views starting at bytes 12, 24 and 36. CPU time per batch of 30 views, p50 over the three runs: | Case | create | refresh | |---|---|---| | aligned starts (0, 48), fresh | 9.7-9.8 µs | 4.7-4.8 µs | | aligned starts, live | 9.6-9.7 µs | 4.4-4.5 µs | | unaligned starts (12, 24, 36), fresh, 30 new slices | 58.0-128.0 µs | 19.7-19.9 µs | | unaligned starts, live, 0 new slices | 10.7-10.9 µs | 19.3-19.7 µs | **Failures that remain, unrelated to this PR (the same on `main` on this card)** - victory-gpu: `descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views` - victory-shader: `emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` (`hardware: dispatch failed: The parameter is incorrect.`), `emit::synthetic_tests::gathers_at_a_level_match_the_hardware` (lane 0 gives `[0.0, 1.0, 0.0, 0.0]`, expected zeros) Their failure output is identical to `main`'s, apart from one panic line number in `host.rs` that moved with the added code. **Question** - Nothing in `victory-shader` calls `set_host_raw_structured(true)`; only `shader_cache::build` in `victory-gpu` does. So does the stride test above pass with the raw lowering in `lower.rs` switched off, on a `Stride::Raw` view under a structured handle? If so, this run does not cover the translated raw path on hardware. **Not tested** - The title, or any in-game behaviour. - The AMD path. - Translated shaders with `host_raw_structured` on (see the question). - The record count a shader gets from views that start at bytes 12, 24 and 36, and reads through other views of the same memory after a GPU write (the cases steven-seagull27 reported). The PR's own tests do not cover them and I did not add tests. - Interaction with #2177, #2464 or #1887. - GPU execution time: the benchmark figures are CPU time only. Synthetic tests only, no game files. AI-assisted (Claude Code).
artor410 commented 2026-11-28 08:19:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by artor410 on 2026-11-28T08:19:12Z.


NVIDIA Ampere check of 3c1d743, merged cleanly onto main 63bcca4 (tree 9216967). RTX 3070 Ti 8 GB (Ampere, 32-lane waves, heap capped at 1,000,000), driver 610.88, Windows 11, rustc 1.98.1, hardware adapter. Synthetic tests only.

cargo test -p victory-shader --lib -- stride_tests gathers_at_a_level and cargo test -p victory-gpu --lib:

test main this PR
a_heap_buffer_read_by_element_takes_the_views_stride fail pass
a_heap_buffer_read_where_no_buffer_view_is_reads_zeros fail fail (fails on every tree here)
victory-gpu lib 229 / 2 fail 230 / same 2 (the heap-cap pair, #3178)
overlap probe (below) 2375 / 2400 mismatches 544 / 2400

Probe: overlap_test::gpu_writes_visible_through_overlapping_views from #2885 (76a13e1), copied in unchanged as a probe. It writes through one structured view and reads back through views that start at other 12-byte offsets. The private aligned copies fix the read at offset 0, but GPU writes do not reach the reads through other origins. This matches @steven-seagull27's RTX 5080 result. #2885 passes the same test with 0 mismatches.

(Claude Code, Claude Opus 5.5.)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7236505727 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7236505727). Originally posted by [artor410](https://github.com/artor410) on 2026-11-28T08:19:12Z. --- NVIDIA Ampere check of `3c1d743`, merged cleanly onto `main` `63bcca4` (tree `9216967`). RTX 3070 Ti 8 GB (Ampere, 32-lane waves, heap capped at 1,000,000), driver 610.88, Windows 11, rustc 1.98.1, hardware adapter. Synthetic tests only. `cargo test -p victory-shader --lib -- stride_tests gathers_at_a_level` and `cargo test -p victory-gpu --lib`: | test | main | this PR | |---|---|---| | `a_heap_buffer_read_by_element_takes_the_views_stride` | fail | **pass** | | `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` | fail | fail (fails on every tree here) | | victory-gpu lib | 229 / 2 fail | 230 / same 2 (the heap-cap pair, #3178) | | overlap probe (below) | 2375 / 2400 mismatches | **544 / 2400** | Probe: `overlap_test::gpu_writes_visible_through_overlapping_views` from #2885 (`76a13e1`), copied in unchanged as a probe. It writes through one structured view and reads back through views that start at other 12-byte offsets. The private aligned copies fix the read at offset 0, but GPU writes do not reach the reads through other origins. This matches @steven-seagull27's RTX 5080 result. #2885 passes the same test with 0 mismatches. (Claude Code, Claude Opus 5.5.)
passerbyyhx commented 2026-11-29 16:22:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-29T16:22:16Z.


Ran the original structured_srv_alignment_cost Release fixture at merge head 3c1d74349e9d8871971688a5ba4d8a384dfa7eb1. Its source tree matches 3d0a9d3. Both RTX 4090 Laptop (10de:2757) and Microsoft WARP (1414:008c) passed the fixture's copy-count and exact readback assertions for the aligned/unaligned, cold/live cases, with 30 structured views and 12 words per view. This confirms the merged revision on both adapters. Build activity overlapped the run, so I am reporting correctness only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7258850094 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7258850094). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-29T16:22:16Z. --- Ran the original `structured_srv_alignment_cost` Release fixture at merge head `3c1d74349e9d8871971688a5ba4d8a384dfa7eb1`. Its source tree matches `3d0a9d3`. Both RTX 4090 Laptop (10de:2757) and Microsoft WARP (1414:008c) passed the fixture's copy-count and exact readback assertions for the aligned/unaligned, cold/live cases, with 30 structured views and 12 words per view. This confirms the merged revision on both adapters. Build activity overlapped the run, so I am reporting correctness only.
axknxla commented 2026-12-01 05:08:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by axknxla on 2026-12-01T05:08:36Z.


Related measurement, not a validation of this PR: a separate source-only investigation characterized raw SRV/UAV descriptor retargeting on one NVIDIA stack:

https://github.com/axknxla/nvidia-raw-descriptor-research

The alignment-related negative result may be relevant here: scalar accesses and aligned-effective RWByteAddressBuffer.Store4 passed, while an arbitrary unaligned-effective Store4 wrote the preceding 16-byte-aligned region. The study does not test this PR’s structured-to-raw conversion or application behavior, so the result should be treated as a limited implementation-specific data point.

The package separates descriptor-byte prediction from synchronized shader consumption, includes the staged and ListViews publication routes, and records PASS_WITH_LIMITATIONS from a separate OpenAI model pass in the same T3/OpenAI toolchain—not an external human review. No compiled binaries or proprietary assets are distributed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7301464161 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2178#issuecomment-7301464161). Originally posted by [axknxla](https://github.com/axknxla) on 2026-12-01T05:08:36Z. --- Related measurement, not a validation of this PR: a separate source-only investigation characterized raw SRV/UAV descriptor retargeting on one NVIDIA stack: https://github.com/axknxla/nvidia-raw-descriptor-research The alignment-related negative result may be relevant here: scalar accesses and aligned-effective `RWByteAddressBuffer.Store4` passed, while an arbitrary unaligned-effective `Store4` wrote the preceding 16-byte-aligned region. The study does not test this PR’s structured-to-raw conversion or application behavior, so the result should be treated as a limited implementation-specific data point. The package separates descriptor-byte prediction from synchronized shader consumption, includes the staged and ListViews publication routes, and records **PASS_WITH_LIMITATIONS** from a separate OpenAI model pass in the same T3/OpenAI toolchain—not an external human review. No compiled binaries or proprietary assets are distributed.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2178:upstream-pr/2178'
git switch 'upstream-pr/2178'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2178'
git switch 'upstream-pr/2178'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2178'
git switch 'upstream-pr/2178'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2178'
git switch 'main'
git merge --squash 'upstream-pr/2178'
git switch 'main'
git merge --ff-only 'upstream-pr/2178'
git switch 'main'
git merge 'upstream-pr/2178'
git push origin 'main'
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!2176
No description provided.