Shaders: skip dead channel loads/conversions in format_load and vectorize memory_smem, table-CBV, and view_addresses loads #2209

Closed
github-bot wants to merge 1 commit from gh-pr/2209/head into gh-pr/2209/base
Owner

@⁠RVZO6 on GitHub · 2026-11-25 07:59 UTC · original
RVZO6:rvzo/format-smem-vec → main · +865 −38 · 1 files · 1 commits · closed without merging

In crates/victory-shader/src/emit/lower.rs:

  1. format_load currently loads all dwords of a buffer format and converts every channel even when the instruction requests fewer channels (e.g., tbuffer_load_format_x / _xy), discarding the unused results afterward.
  2. format_load, memory_smem, and the table-CBV path of buffer() emit one 1-dword rawBufferLoad.f32 per dword instead of vectorizing contiguous reads up to 4 dwords.
  3. view_addresses loads each descriptor's 64-bit address as two separate 4-byte rawBufferLoad.f32 calls instead of one 8-byte-aligned 2-dword load.

Claimed on #1633 (https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155420630).

The change

  • crates/victory-shader/src/emit/lower.rs:
    • Add Lower::raw_dwords(h, off, count) emitting vectorized dx.op.rawBufferLoad.f32 calls in chunks of up to 4 dwords (align = 4).
    • In format_load: slice format bit widths to the requested channel count, load only need_bits.div_ceil(32) dwords (returning early when need_bits == 0) via raw_dwords, and convert only the requested channels while preserving missing-channel (0, 0, 0, 1) fill and d16 packing.
    • Use raw_dwords in memory_smem (which already performs a single memory() lookup for the whole access) and in the table-CBV path of buffer().
    • Coalesce consecutive (word 0, word 1) descriptor address pairs in view_addresses into a single 8-byte-aligned 2-dword rawBufferLoad.f32 (mask = 3, align = 8).
    • Add zero-GPU DXIL bitcode + dxil.dll validation tests (format_load_skips_dead_channels_and_loads, table_cbv_buffer_load_vectorizes_to_single_raw_load, memory_smem_vectorizes_loads_into_four_dword_chunks, view_addresses_coalesces_consecutive_address_pairs) plus GPU/WARP execution test format_load_xy_and_table_cbv_x4_execute_on_gpu.

Not a duplicate of

No open PR or CLAIMS.md entry skips dead channels in format_load, vectorizes memory_smem / table-CBV rawBufferLoads, or coalesces view_addresses pairs.

Tested

  • Fork windows-latest MSVC + Windows WARP SM 6.6 CI run 45570823602 (Clippy clean, Clippy, diagnostics build clean, Tests: 731 passed; 0 failed; 10 ignored, victory-shader: 262 passed; 0 failed; 3 ignored, xtask: 6 passed; 0 failed):
    • format_load_skips_dead_channels_and_loads ... ok
    • table_cbv_buffer_load_vectorizes_to_single_raw_load ... ok
    • memory_smem_vectorizes_loads_into_four_dword_chunks ... ok
    • view_addresses_coalesces_consecutive_address_pairs ... ok
    • format_load_xy_and_table_cbv_x4_execute_on_gpu ... ok (executed on Windows WARP SM 6.6)

Not run: the title; any hardware GPU. The title was not used in these tests.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

**@⁠RVZO6** on GitHub · 2026-11-25 07:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2209) `RVZO6:rvzo/format-smem-vec` → `main` · +865 −38 · 1 files · 1 commits · closed without merging In `crates/victory-shader/src/emit/lower.rs`: 1. `format_load` currently loads all dwords of a buffer format and converts every channel even when the instruction requests fewer channels (e.g., `tbuffer_load_format_x` / `_xy`), discarding the unused results afterward. 2. `format_load`, `memory_smem`, and the table-CBV path of `buffer()` emit one 1-dword `rawBufferLoad.f32` per dword instead of vectorizing contiguous reads up to 4 dwords. 3. `view_addresses` loads each descriptor's 64-bit address as two separate 4-byte `rawBufferLoad.f32` calls instead of one 8-byte-aligned 2-dword load. Claimed on #1633 (`https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155420630`). ## The change - `crates/victory-shader/src/emit/lower.rs`: - Add `Lower::raw_dwords(h, off, count)` emitting vectorized `dx.op.rawBufferLoad.f32` calls in chunks of up to 4 dwords (`align = 4`). - In `format_load`: slice format bit widths to the requested channel count, load only `need_bits.div_ceil(32)` dwords (returning early when `need_bits == 0`) via `raw_dwords`, and convert only the requested channels while preserving missing-channel `(0, 0, 0, 1)` fill and `d16` packing. - Use `raw_dwords` in `memory_smem` (which already performs a single `memory()` lookup for the whole access) and in the table-CBV path of `buffer()`. - Coalesce consecutive `(word 0, word 1)` descriptor address pairs in `view_addresses` into a single 8-byte-aligned 2-dword `rawBufferLoad.f32` (`mask = 3, align = 8`). - Add zero-GPU DXIL bitcode + `dxil.dll` validation tests (`format_load_skips_dead_channels_and_loads`, `table_cbv_buffer_load_vectorizes_to_single_raw_load`, `memory_smem_vectorizes_loads_into_four_dword_chunks`, `view_addresses_coalesces_consecutive_address_pairs`) plus GPU/WARP execution test `format_load_xy_and_table_cbv_x4_execute_on_gpu`. ## Not a duplicate of No open PR or `CLAIMS.md` entry skips dead channels in `format_load`, vectorizes `memory_smem` / table-CBV `rawBufferLoad`s, or coalesces `view_addresses` pairs. ## Tested - Fork `windows-latest` MSVC + Windows WARP SM 6.6 CI run [`45570823602`](https://github.com/RVZO6/VIctory/actions/runs/45570823602) (`Clippy` clean, `Clippy, diagnostics build` clean, `Tests`: **`731 passed; 0 failed; 10 ignored`**, `victory-shader`: **`262 passed; 0 failed; 3 ignored`**, `xtask`: **`6 passed; 0 failed`**): - `format_load_skips_dead_channels_and_loads ... ok` - `table_cbv_buffer_load_vectorizes_to_single_raw_load ... ok` - `memory_smem_vectorizes_loads_into_four_dword_chunks ... ok` - `view_addresses_coalesces_consecutive_address_pairs ... ok` - `format_load_xy_and_table_cbv_x4_execute_on_gpu ... ok` (executed on Windows WARP SM 6.6) **Not run:** the title; any hardware GPU. The title was not used in these tests. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Skip dead channels in format_load by slicing bits to the requested channel count, loading only need_bits.div_ceil(32) dwords when total >= 32 (and returning early when need_bits == 0), and converting only used channels while preserving missing-channel (0, 0, 0, 1) fill and d16 packing.

Add Lower::raw_dwords to emit vectorized rawBufferLoad.f32 calls in chunks of up to 4 dwords (align 4), and use it in format_load, memory_smem (which already performs one memory() lookup for the whole access), and the table-CBV path of buffer(). Coalesce consecutive (word 0, word 1) descriptor address pairs in view_addresses into a single 8-byte-aligned 2-dword rawBufferLoad.f32 (mask 3, align 8).

Add unit tests decoding emitted DXIL bitcode + validating with dxil.dll, plus a GPU/WARP execution test for tbuffer_load_format_xy and table-CBV buffer_load_dwordx4.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:29 +00:00
github-bot closed this pull request 2026-11-26 04:58:29 +00:00
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 10:47 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head fa12c2cb 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** on GitHub · 2026-11-25 10:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2209#issuecomment-7160177937) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head fa12c2cb 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:29 UTC · original · edited 2026-11-25 16:03 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2209#issuecomment-7163851297) · edited 2026-11-25 16:03 UTC <!-- victory-triage v1 head=fa12c2cb281c7cfffbf2cb0ac7d53b1026bb3851 verdict=needs-rebase at=2026-11-25T16:13:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠RVZO6 on GitHub · 2026-11-25 17:30 UTC · original

Closing to keep the queue clean: 286a00e already drops unread ReadOnly loads in bitcode.rs, and this PR bundled four changes + a large bitcode reader that now conflicts in lower.rs.

**@⁠RVZO6** on GitHub · 2026-11-25 17:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2209#issuecomment-7169597302) Closing to keep the queue clean: `286a00e` already drops unread `ReadOnly` loads in `bitcode.rs`, and this PR bundled four changes + a large bitcode reader that now conflicts in `lower.rs`.

Pull request closed

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!2209
No description provided.