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

Closed
RVZO6 wants to merge 1 commit from upstream-pr/2209 into main
RVZO6 commented 2026-11-25 07:59:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-25T07:59:28Z.


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)

<!-- greyfinch-sync:Marvisak/VIctory:issue:6599920729 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2209). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T07:59:28Z. --- 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)
DenRakEiw commented 2026-11-25 08:06:26 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • cargo test -p victory-shader --lib emit::lower::tests:: — 26 passed, 0 failed
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean dead-channel skipping in format_load and vectorized loads for memory_smem, table-CBV, and view_addresses. Looks great.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6053841072 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2209#pullrequestreview-6053841072). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T08:03:31Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib emit::lower::tests::` — **26 passed, 0 failed** - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean dead-channel skipping in `format_load` and vectorized loads for `memory_smem`, table-CBV, and `view_addresses`. Looks great. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 09:05:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:17:46Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

148 passed / 0 failed. Dead channel loads/conversions skipped in format_load (+4 tests) — dead-code elimination in format loads.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054007186 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2209#pullrequestreview-6054007186). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:17:46Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 148 passed / 0 failed. Dead channel loads/conversions skipped in format_load (+4 tests) — dead-code elimination in format loads.
sinan-cmyk commented 2026-11-25 11:05:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T10:47:30Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160177937 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2209#issuecomment-7160177937). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T10:47:30Z. --- ### 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).
Marvisak commented 2026-11-25 14:07:20 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163851297 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2209#issuecomment-7163851297). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:29:25Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-25 18:01:51 +00:00
RVZO6 commented 2026-11-25 18:02:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-25T17:30:16Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169597302 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2209#issuecomment-7169597302). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T17:30:16Z. --- 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

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