Shaders: cache USER_DATA CBV rows and extracted dwords in Lower::user_at #2207

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

@⁠RVZO6 on GitHub · 2026-11-25 07:59 UTC · original
RVZO6:rvzo/cache-user-data → main · +291 −16 · 3 files · 1 commits · open

Lower::user_at in crates/victory-shader/src/emit/lower.rs currently emits a fresh dx.op.cbufferLoadLegacy.i32 + extractvalue every time a shader reads a USER_DATA dword, even when multiple reads hit the same 4-dword row or the exact same dword index.

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

The change

  • crates/victory-shader/src/emit/lower.rs:
    • Cache loaded 4-dword USER_DATA CBV rows (user_rows: HashMap<u32, V>, keyed by index / 4) and extracted dwords (user_vals: HashMap<u32, V>, keyed by index) emitted in entry block 0 (emit_at_entry / cur = 0) so any later read in any block dominates all uses and reuses the existing load and extraction.
    • Add zero-GPU DXIL bitcode + dxil.dll validation test user_data_cbv_rows_and_dwords_are_cached_in_entry_block proving repeated and same-row user_at reads emit one cbufferLoadLegacy.i32 per distinct 4-dword row in block 0 and reuse extracted dwords across branches.

Not a duplicate of

No open PR or CLAIMS.md entry caches USER_DATA CBV rows or extracted dwords in Lower::user_at.

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):
    • user_data_cbv_rows_and_dwords_are_cached_in_entry_block ... ok

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/2207) `RVZO6:rvzo/cache-user-data` → `main` · +291 −16 · 3 files · 1 commits · open `Lower::user_at` in `crates/victory-shader/src/emit/lower.rs` currently emits a fresh `dx.op.cbufferLoadLegacy.i32` + `extractvalue` every time a shader reads a `USER_DATA` dword, even when multiple reads hit the same 4-dword row or the exact same dword index. Claimed on #1633 (`https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155420630`). ## The change - `crates/victory-shader/src/emit/lower.rs`: - Cache loaded 4-dword `USER_DATA` CBV rows (`user_rows: HashMap<u32, V>`, keyed by `index / 4`) and extracted dwords (`user_vals: HashMap<u32, V>`, keyed by `index`) emitted in entry block 0 (`emit_at_entry` / `cur = 0`) so any later read in any block dominates all uses and reuses the existing load and extraction. - Add zero-GPU DXIL bitcode + `dxil.dll` validation test `user_data_cbv_rows_and_dwords_are_cached_in_entry_block` proving repeated and same-row `user_at` reads emit one `cbufferLoadLegacy.i32` per distinct 4-dword row in block 0 and reuse extracted dwords across branches. ## Not a duplicate of No open PR or `CLAIMS.md` entry caches `USER_DATA` CBV rows or extracted dwords in `Lower::user_at`. ## 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`**): - `user_data_cbv_rows_and_dwords_are_cached_in_entry_block ... ok` **Not run:** the title; any hardware GPU. The title was not used in these tests. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Cache loaded 4-dword USER_DATA CBV rows (index / 4) and extracted dwords
(index) in the entry block so repeated or same-row user-data accesses
reuse the existing cbufferLoadLegacy.i32 and extractvalue instructions.

Replaces the previous hand-written bitcode reader test with a small
Module::written_calls).

Measured on 13f91ca (--release bench_user_data_cache, 32 dwords / 8 rows
read 4x = 128 reads):
- DXIL size:                 4,460 -> 2,616 B (-41.3%)
- cbufferLoadLegacy.i32 ops:   128 -> 8       (-93.8%)
- extractvalue ops:            128 -> 32      (-75.0%)
- Lowering time:             411.7 -> 306.3 us/run (1.34x, -25.6%)

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

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

Offline measurement on a retail dump

Result: no count change against main.

I merged head b8e04e90 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:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2207#issuecomment-7160276994) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head b8e04e90 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-26 01:21 UTC

Automated triage for the maintainers.

Merge candidate. It is rebased onto current main (one commit, 2d14add) and merges cleanly. The tests moved to emit/lower/user_data_tests.rs, and the bitcode reader was replaced by a small #[cfg(test)] helper, Module::cbuf_load_stats. Lower::user_at in emit/lower.rs now reuses one cbufferLoadLegacy.i32 per 4-dword row (user_rows) and one extractvalue per dword (user_vals). This is safe because main already emits both into the fixed entry block (self.s.entry), so the cached values dominate every use. The pattern is the same as the user_data handle that main already caches. The shader semantics don't change, only the amount of DXIL emitted. A retail-corpus run in the comments shows no change in what validates.

CI: passing (check). Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2207#issuecomment-7163863767) · edited 2026-11-26 01:21 UTC <!-- victory-triage v1 head=2d14add588e735968d2b229222c6003208f28189 verdict=merge-candidate at=2026-11-26T01:21:57Z --> Automated triage for the maintainers. **Merge candidate.** It is rebased onto current `main` (one commit, `2d14add`) and merges cleanly. The tests moved to `emit/lower/user_data_tests.rs`, and the bitcode reader was replaced by a small `#[cfg(test)]` helper, `Module::cbuf_load_stats`. `Lower::user_at` in `emit/lower.rs` now reuses one `cbufferLoadLegacy.i32` per 4-dword row (`user_rows`) and one `extractvalue` per dword (`user_vals`). This is safe because `main` already emits both into the fixed entry block (`self.s.entry`), so the cached values dominate every use. The pattern is the same as the `user_data` handle that `main` already caches. The shader semantics don't change, only the amount of DXIL emitted. A retail-corpus run in the comments shows no change in what validates. CI: passing (`check`). Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

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

Rebased cleanly onto 13f91ca and addressed triage feedback:

  • Replaced the ~230-line hand-written bitcode reader test with a small #[cfg(test)] Module::cbuf_load_stats hook on Module (matching Module::written_calls), shrinking the PR to 2 files changed, +235/-16.
  • Measured on 13f91ca (--release emit::lower::tests::bench_user_data_cache, 32 user-data dwords / 8 CBV rows read 4× = 128 reads):
    • DXIL size: 4,460 B -> 2,616 B (-41.3%)
    • cbufferLoadLegacy.i32 calls: 128 -> 8 (-93.8%)
    • extractvalue ops: 128 -> 32 (-75.0%)
    • Lowering time: 411.7 -> 306.3 µs/run (1.34×, -25.6%)
  • Verified on windows-latest MSVC + WARP SM 6.6 CI (both clippy -D warnings profiles, xtask 6/6, victory-shader 281/281 including dxil.dll validation): https://github.com/RVZO6/VIctory/actions/runs/45666985023
**@⁠RVZO6** on GitHub · 2026-11-25 17:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2207#issuecomment-7169908253) Rebased cleanly onto `13f91ca` and addressed triage feedback: - Replaced the ~230-line hand-written bitcode reader test with a small `#[cfg(test)] Module::cbuf_load_stats` hook on `Module` (matching `Module::written_calls`), shrinking the PR to `2 files changed, +235/-16`. - Measured on `13f91ca` (`--release emit::lower::tests::bench_user_data_cache`, 32 user-data dwords / 8 CBV rows read 4× = 128 reads): - DXIL size: `4,460 B -> 2,616 B` (**-41.3%**) - `cbufferLoadLegacy.i32` calls: `128 -> 8` (**-93.8%**) - `extractvalue` ops: `128 -> 32` (**-75.0%**) - Lowering time: `411.7 -> 306.3 µs/run` (**1.34×**, `-25.6%`) - Verified on `windows-latest` MSVC + WARP SM 6.6 CI (both clippy `-D warnings` profiles, `xtask` 6/6, `victory-shader` 281/281 including `dxil.dll` validation): https://github.com/RVZO6/VIctory/actions/runs/45666985023
Author
Owner

@⁠RVZO6 on GitHub · 2026-11-26 00:21 UTC · original

Rebased onto current main (63bcca4, head 2d14add). Moved unit tests into crates/victory-shader/src/emit/lower/user_data_tests.rs so lower.rs stays below the 512 KiB asset-policy limit. Verified green on windows-latest MSVC + WARP SM 6.6 CI (clippy, xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45727774760.

**@⁠RVZO6** on GitHub · 2026-11-26 00:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2207#issuecomment-7178663377) Rebased onto current `main` (`63bcca4`, head `2d14add`). Moved unit tests into `crates/victory-shader/src/emit/lower/user_data_tests.rs` so `lower.rs` stays below the 512 KiB asset-policy limit. Verified green on `windows-latest` MSVC + WARP SM 6.6 CI (clippy, xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45727774760.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 08:03 UTC · original · approved these changes

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

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

Clean caching of USER_DATA CBV rows and extracted dwords in Lower::user_at. Looks good.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 08:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2207#pullrequestreview-6053841601) · **approved these changes** Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib emit::lower::tests::` — **22 passed, 0 failed** - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean caching of `USER_DATA` CBV rows and extracted dwords in `Lower::user_at`. Looks good. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 08:17 UTC · original · approved these changes

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

145 passed / 0 failed. USER_DATA CBV rows and extracted dwords cached in Lower — CBV caching perf work.

**@⁠catminou4** on GitHub · 2026-11-25 08:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2207#pullrequestreview-6054006884) · **approved these changes** Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 145 passed / 0 failed. USER_DATA CBV rows and extracted dwords cached in Lower — CBV caching perf work.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 19:19 UTC · original · approved these changes

Verified locally merged onto origin/main (63bcca43, Windows 11 x64, Rust 1.98.1 MSVC, RTX 5090 & WARP + dxil.dll):

  • cargo test --locked -p victory-shader --lib emit::lower::tests:: (VICTORY_WARP=0 and VICTORY_WARP=1) — 33 passed, 0 failed
  • cargo test --locked -p victory-shader --lib user_data — 1 passed, 1 ignored (user_data_cbv_rows_and_dwords_are_cached_in_entry_block ok; bench_user_data_cache ignored benchmark)
  • cargo test --locked -p victory-shader --lib constant_color_validates — 1 passed, 0 failed
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features) — 0 warnings
  • cargo xtask policy — ok (192 files ok); emit/lower.rs size is 521,618 B (< 524,288 B)

Review notes

  • Verified SSA dominance in Lower::user_at (crates/victory-shader/src/emit/lower.rs:1751-1763): both Shader::user_data_handle() (createHandleFromBinding + annotateHandle) and the cached cbufferLoadLegacy.i32 / extract instructions are emitted into self.s.entry rather than self.cur, so cached values safely dominate all downstream uses across diverging control-flow paths.
  • Minor non-blocking formatting nit: rustfmt --edition 2024 --check flags comment alignment in crates/victory-shader/src/emit/lower/user_data_tests.rs.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 19:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2207#pullrequestreview-6079454479) · **approved these changes** Verified locally merged onto `origin/main` (`63bcca43`, Windows 11 x64, Rust 1.98.1 MSVC, RTX 5090 & WARP + `dxil.dll`): - `cargo test --locked -p victory-shader --lib emit::lower::tests::` (`VICTORY_WARP=0` and `VICTORY_WARP=1`) — **33 passed, 0 failed** - `cargo test --locked -p victory-shader --lib user_data` — **1 passed, 1 ignored** (`user_data_cbv_rows_and_dwords_are_cached_in_entry_block` ok; `bench_user_data_cache` ignored benchmark) - `cargo test --locked -p victory-shader --lib constant_color_validates` — **1 passed, 0 failed** - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`) — 0 warnings - `cargo xtask policy` — ok (`192 files ok`); `emit/lower.rs` size is **521,618 B** (< 524,288 B) ### Review notes - Verified SSA dominance in `Lower::user_at` (`crates/victory-shader/src/emit/lower.rs:1751-1763`): both `Shader::user_data_handle()` (`createHandleFromBinding` + `annotateHandle`) and the cached `cbufferLoadLegacy.i32` / `extract` instructions are emitted into `self.s.entry` rather than `self.cur`, so cached values safely dominate all downstream uses across diverging control-flow paths. - Minor non-blocking formatting nit: `rustfmt --edition 2024 --check` flags comment alignment in `crates/victory-shader/src/emit/lower/user_data_tests.rs`.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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