Shaders: vectorize wide s_buffer_load and global_load rawBufferLoad calls #1393

Open
github-bot wants to merge 1 commit from github-bot/gh-1393 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-24 17:41 UTC · original
wbkepler:shader/dxil-vector-raw-buffer-loads → main · +584 −50 · 3 files · 1 commits · open

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
**@⁠wbkepler** on GitHub · 2026-11-24 17:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1393) `wbkepler:shader/dxil-vector-raw-buffer-loads` → `main` · +584 −50 · 3 files · 1 commits · open ## 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:16 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:33 UTC · original

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.

**@⁠marquezinii** on GitHub · 2026-11-24 18:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7140818637) 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.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 19:50 UTC · original

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).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 19:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7142659086) ### 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).
Author
Owner

@⁠aycow on GitHub · 2026-11-24 22:17 UTC · original

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.

**@⁠aycow** on GitHub · 2026-11-24 22:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7146043739) 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.
Author
Owner

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

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7149525540) <!-- 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)_
Author
Owner

@⁠ryotdev on GitHub · 2026-11-25 02:33 UTC · original

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.

**@⁠ryotdev** on GitHub · 2026-11-25 02:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7150869068) 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.
Author
Owner

@⁠Moon0755 on GitHub · 2026-11-26 20:52 UTC · original

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

**@⁠Moon0755** on GitHub · 2026-11-26 20:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1393#issuecomment-7203153621) 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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