Shaders: vectorize wide s_buffer_load and global_load rawBufferLoad calls #1393

Open
wbkepler wants to merge 1 commit from upstream-pr/1393 into main
wbkepler commented 2026-11-24 17:41:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T17:41:43Z.


Summary

Rebased cleanly onto upstream/main (ffe310e):

Adds Lower::raw_buffer_load in crates/victory-shader/src/emit/lower.rs to coalesce contiguous dword raw-buffer loads into vectorized dx.op.rawBufferLoad.f32 calls of up to 4 dwords (mask 0x1/0x3/0x7/0xF, align 4) with extractvalue channel extraction:

  • Wired into SMEM SRV loads (s_buffer_load_dwordx2/4/8/16 -> 1/1/2/4 loads).
  • Wired into flat root-SRV loads (global_load_dwordx2/3/4 -> 1 load, preserving sub-dword and CODE paths) and format_load.

Verification

  • cargo clippy -p victory-shader --all-targets — passed
  • cargo test -p victory-shader — passed (including 3 new tests with dxil.dll validation and live hardware GPU + WARP execution covering partial-OOB zero semantics)
  • cargo xtask policy — passed
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587845290 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1393). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T17:41:43Z. --- ## Summary Rebased cleanly onto `upstream/main` (`ffe310e`): Adds `Lower::raw_buffer_load` in `crates/victory-shader/src/emit/lower.rs` to coalesce contiguous dword raw-buffer loads into vectorized `dx.op.rawBufferLoad.f32` calls of up to 4 dwords (`mask` `0x1`/`0x3`/`0x7`/`0xF`, `align` `4`) with `extractvalue` channel extraction: - Wired into SMEM SRV loads (`s_buffer_load_dwordx2`/`4`/`8`/`16` -> `1`/`1`/`2`/`4` loads). - Wired into flat root-SRV loads (`global_load_dwordx2`/`3`/`4` -> `1` load, preserving sub-dword and `CODE` paths) and `format_load`. ## Verification - `cargo clippy -p victory-shader --all-targets` — passed - `cargo test -p victory-shader` — passed (including 3 new tests with `dxil.dll` validation and live hardware GPU + WARP execution covering partial-OOB zero semantics) - `cargo xtask policy` — passed
catminou4 commented 2026-11-24 18:05:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T17:52:36Z.

Review: APPROVED


Vectorized wide raw buffer loads: raw_buffer_load issues rawBufferLoad.f32 in chunks of 4 with mask (1<<chunk)-1 and align 4, extracting per channel — OOB lanes zero-fill via the mask, matching DXIL semantics. The fast path fires only when there is no swizzle/sub-access, and the s_buffer_load SRV path is deduplicated onto the same helper. The bitcode test helper asserts the emitted masks. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host/diff_tests) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 97 passed, 0 failed (incl. the macOS lower test); valu tests Windows-gated.

<!-- greyfinch-sync:Marvisak/VIctory:review:6044528402 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1393#pullrequestreview-6044528402). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T17:52:36Z. **Review:** APPROVED --- Vectorized wide raw buffer loads: raw_buffer_load issues rawBufferLoad.f32 in chunks of 4 with mask (1<<chunk)-1 and align 4, extracting per channel — OOB lanes zero-fill via the mask, matching DXIL semantics. The fast path fires only when there is no swizzle/sub-access, and the s_buffer_load SRV path is deduplicated onto the same helper. The bitcode test helper asserts the emitted masks. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p victory-shader --locked`. Shader execution tests (valu_tests/host/diff_tests) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. 97 passed, 0 failed (incl. the macOS lower test); valu tests Windows-gated.
marquezinii commented 2026-11-24 19:04:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:33:47Z.


Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 7a780a0. cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 123 passed, 0 failed, 1 ignored. vectorizes_wide_raw_buffer_loads, s_buffer_load_wide_srv_reads_exact_dwords_and_oob_zeros and global_load_wide_srv_reads_exact_dwords all pass on the hardware adapter and WARP.

The case I'd watch most in this change is the one the second test covers: a vector rawBufferLoad that straddles the end of the view. The console checks bounds per dword, so the in-range dwords must keep their values and only the ones past the end read 0. With one load per dword that is automatic; with mask 0x3/0x7/0xF it relies on how the host driver bounds a multi-component raw load. On this NVIDIA driver and on WARP the result is per dword, as the test expects. A run on AMD hardware would cover the other vendor.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140818637 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7140818637). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T18:33:47Z. --- Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `7a780a0`. `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 123 passed, 0 failed, 1 ignored. `vectorizes_wide_raw_buffer_loads`, `s_buffer_load_wide_srv_reads_exact_dwords_and_oob_zeros` and `global_load_wide_srv_reads_exact_dwords` all pass on the hardware adapter and WARP. The case I'd watch most in this change is the one the second test covers: a vector `rawBufferLoad` that straddles the end of the view. The console checks bounds per dword, so the in-range dwords must keep their values and only the ones past the end read 0. With one load per dword that is automatic; with `mask` 0x3/0x7/0xF it relies on how the host driver bounds a multi-component raw load. On this NVIDIA driver and on WARP the result is per dword, as the test expects. A run on AMD hardware would cover the other vendor.
sinan-cmyk commented 2026-11-24 20:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T19:50:16Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 7a780a0 onto main ffe310e (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: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 123, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142659086 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7142659086). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T19:50:16Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 7a780a0 onto `main` ffe310e (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: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 123, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
aycow commented 2026-11-24 23:05:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T22:17:19Z.


I tested the analogous per-lane raw table-constant path introduced in 683ad7a on exact main 70564ae. The local experiment combines only aligned same-row dwordx2/x3/x4 reads, emitting one raw load with masks 3, 7 or 15. Dynamic and crossing cases retain scalar lowering. Baseline and candidate each passed 240 synthetic dispatches per adapter on AMD and WARP with full validation, including partial bounds, nonzero FirstElement and raw bit patterns. A 2 MiB synthetic read had medians of 52.58 → 50.68 µs on AMD and 397.70 → 261.35 µs on WARP. The AMD maximum rose slightly, so the AMD performance evidence is limited.

Is the table-constant branch already in your current-main plan? I can share the exact fixture and hunk to avoid parallel implementations.

AI-assisted using Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146043739 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7146043739). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T22:17:19Z. --- I tested the analogous per-lane raw table-constant path introduced in 683ad7a on exact main 70564ae. The local experiment combines only aligned same-row dwordx2/x3/x4 reads, emitting one raw load with masks 3, 7 or 15. Dynamic and crossing cases retain scalar lowering. Baseline and candidate each passed 240 synthetic dispatches per adapter on AMD and WARP with full validation, including partial bounds, nonzero FirstElement and raw bit patterns. A 2 MiB synthetic read had medians of 52.58 → 50.68 µs on AMD and 397.70 → 261.35 µs on WARP. The AMD maximum rose slightly, so the AMD performance evidence is limited. Is the table-constant branch already in your current-main plan? I can share the exact fixture and hunk to avoid parallel implementations. AI-assisted using Codex.
Marvisak commented 2026-11-25 02:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:25:09Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149525540 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7149525540). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:25:09Z. --- <!-- victory-triage v1 head=7a780a0ad7077b3acd1d94bbb39cedd0b5746e2a verdict=needs-rebase at=2026-11-25T01:25:08Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
ryotdev commented 2026-11-25 03:03:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ryotdev on 2026-11-25T02:33:10Z.


I found a 32-bit byte-offset wrap case in the table SRV path. On Windows WARP, the same hand-written s_buffer_load_dwordx2 fixture passed on the scalar parent ffe310e and failed on 7a780a0. The difference also survives DXIL validation and pipeline creation.

To reproduce, extend s_buffer_load_wide_srv_reads_exact_dwords_and_oob_zeros with a 24-dword SRV, a nonzero first dword, dyn_off = 0xfffffff8u32, and the existing immediate offset of 4. The first address is 0xfffffffc. The scalar parent explicitly adds four again in i32 for the second word and reads byte zero. The vector load returned zero for both words on WARP. With my synthetic buffer the readbacks were [0, 0x7fa12345] on the parent and [0, 0] on this head.

The fixture's current expectation uses a host usize. To check parity with the scalar parent at this boundary, compute each expected byte address as dyn_off.wrapping_add(4).wrapping_add(4 * k as u32) before dividing by four. An ordinary read crossing the end of a small view exercises a different case.

I also checked a conservative version that groups only known, dword-aligned offsets with a proven non-wrapping last dword and keeps scalar reads for dynamic offsets. The fixed, dynamic, partial-view and wrapping cases passed on WARP for widths 2/4/8/16. This establishes the difference from the previous translator. A console result at this boundary would settle which behavior the emulation should implement. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150869068 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7150869068). Originally posted by [ryotdev](https://github.com/ryotdev) on 2026-11-25T02:33:10Z. --- I found a 32-bit byte-offset wrap case in the table SRV path. On Windows WARP, the same hand-written `s_buffer_load_dwordx2` fixture passed on the scalar parent `ffe310e` and failed on `7a780a0`. The difference also survives DXIL validation and pipeline creation. To reproduce, extend `s_buffer_load_wide_srv_reads_exact_dwords_and_oob_zeros` with a 24-dword SRV, a nonzero first dword, `dyn_off = 0xfffffff8u32`, and the existing immediate offset of 4. The first address is `0xfffffffc`. The scalar parent explicitly adds four again in i32 for the second word and reads byte zero. The vector load returned zero for both words on WARP. With my synthetic buffer the readbacks were `[0, 0x7fa12345]` on the parent and `[0, 0]` on this head. The fixture's current expectation uses a host `usize`. To check parity with the scalar parent at this boundary, compute each expected byte address as `dyn_off.wrapping_add(4).wrapping_add(4 * k as u32)` before dividing by four. An ordinary read crossing the end of a small view exercises a different case. I also checked a conservative version that groups only known, dword-aligned offsets with a proven non-wrapping last dword and keeps scalar reads for dynamic offsets. The fixed, dynamic, partial-view and wrapping cases passed on WARP for widths 2/4/8/16. This establishes the difference from the previous translator. A console result at this boundary would settle which behavior the emulation should implement. AI-assisted.
Moon0755 commented 2026-11-26 20:52:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-26T20:52:06Z.


On the hardware question above: RDNA2 (gfx1036, measured natively in wave32 and wave64 in zDiazG/Leonida, docs/design.md@68e8b30ab) does not wrap sOFF + IMM in 32 bits for s_buffer_load* — e.g. sOFF = 0xfffffffc, IMM = 8 and sOFF = 0xfffffff0, IMM = 0x20 both return 0 past NUM_RECORDS = 0x100.

So [0, 0] is the hardware-matching result here, and main's scalar i32 wrap ([0, 0x7fa12345]) was the bug. We opened #3373 to fix the scalar path in Lower::smem so both paths agree on returning 0 on 32-bit overflow.

— Neon

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203153621 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7203153621). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-26T20:52:06Z. --- On the hardware question above: RDNA2 (`gfx1036`, measured natively in wave32 and wave64 in `zDiazG/Leonida`, `docs/design.md@68e8b30ab`) does **not** wrap `sOFF + IMM` in 32 bits for `s_buffer_load*` — e.g. `sOFF = 0xfffffffc, IMM = 8` and `sOFF = 0xfffffff0, IMM = 0x20` both return `0` past `NUM_RECORDS = 0x100`. So `[0, 0]` is the hardware-matching result here, and `main`'s scalar `i32` wrap (`[0, 0x7fa12345]`) was the bug. We opened #3373 to fix the scalar path in `Lower::smem` so both paths agree on returning `0` on 32-bit overflow. — Neon
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/1393:upstream-pr/1393'
git switch 'upstream-pr/1393'

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