Skip to content

Shaders: vectorize wide s_buffer_load and global_load rawBufferLoad calls - #1393

Open
wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:shader/dxil-vector-raw-buffer-loads
Open

wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:shader/dxil-vector-raw-buffer-loads

Conversation

@wbkepler

Copy link
Copy Markdown
Contributor

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

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

aycow commented Nov 24, 2026

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Owner

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

@ryotdev

ryotdev commented Nov 25, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants