Shaders: cache USER_DATA CBV rows and extracted dwords in Lower::user_at #2205
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2207"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-25T07:59:20Z.
Lower::user_atincrates/victory-shader/src/emit/lower.rscurrently emits a freshdx.op.cbufferLoadLegacy.i32+extractvalueevery time a shader reads aUSER_DATAdword, 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:USER_DATACBV rows (user_rows: HashMap<u32, V>, keyed byindex / 4) and extracted dwords (user_vals: HashMap<u32, V>, keyed byindex) 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.dxil.dllvalidation testuser_data_cbv_rows_and_dwords_are_cached_in_entry_blockproving repeated and same-rowuser_atreads emit onecbufferLoadLegacy.i32per distinct 4-dword row in block 0 and reuse extracted dwords across branches.Not a duplicate of
No open PR or
CLAIMS.mdentry cachesUSER_DATACBV rows or extracted dwords inLower::user_at.Tested
windows-latestMSVC + Windows WARP SM 6.6 CI run45570823602(Clippyclean,Clippy, diagnostics buildclean,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 ... okNot run: the title; any hardware GPU. The title was not used in these tests.
AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T08:03:34Z.
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::— 22 passed, 0 failedcargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean caching of
USER_DATACBV rows and extracted dwords inLower::user_at. Looks good.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:17:45Z.
Review: APPROVED
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.
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T10:51:59Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
b8e04e90ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 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).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:29:56Z.
Automated triage for the maintainers.
Merge candidate. It is rebased onto current
main(one commit,2d14add) and merges cleanly. The tests moved toemit/lower/user_data_tests.rs, and the bitcode reader was replaced by a small#[cfg(test)]helper,Module::cbuf_load_stats.Lower::user_atinemit/lower.rsnow reuses onecbufferLoadLegacy.i32per 4-dword row (user_rows) and oneextractvalueper dword (user_vals). This is safe becausemainalready emits both into the fixed entry block (self.s.entry), so the cached values dominate every use. The pattern is the same as theuser_datahandle thatmainalready 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
Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-25T17:43:26Z.
Rebased cleanly onto
13f91caand addressed triage feedback:#[cfg(test)] Module::cbuf_load_statshook onModule(matchingModule::written_calls), shrinking the PR to2 files changed, +235/-16.13f91ca(--release emit::lower::tests::bench_user_data_cache, 32 user-data dwords / 8 CBV rows read 4× = 128 reads):4,460 B -> 2,616 B(-41.3%)cbufferLoadLegacy.i32calls:128 -> 8(-93.8%)extractvalueops:128 -> 32(-75.0%)411.7 -> 306.3 µs/run(1.34×,-25.6%)windows-latestMSVC + WARP SM 6.6 CI (both clippy-D warningsprofiles,xtask6/6,victory-shader281/281 includingdxil.dllvalidation): https://github.com/RVZO6/VIctory/actions/runs/45666985023Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T00:21:04Z.
Rebased onto current
main(63bcca4, head2d14add). Moved unit tests intocrates/victory-shader/src/emit/lower/user_data_tests.rssolower.rsstays below the 512 KiB asset-policy limit. Verified green onwindows-latestMSVC + WARP SM 6.6 CI (clippy, xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45727774760.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:19:54Z.
Review: APPROVED
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=0andVICTORY_WARP=1) — 33 passed, 0 failedcargo test --locked -p victory-shader --lib user_data— 1 passed, 1 ignored (user_data_cbv_rows_and_dwords_are_cached_in_entry_blockok;bench_user_data_cacheignored benchmark)cargo test --locked -p victory-shader --lib constant_color_validates— 1 passed, 0 failedcargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features) — 0 warningscargo xtask policy— ok (192 files ok);emit/lower.rssize is 521,618 B (< 524,288 B)Review notes
Lower::user_at(crates/victory-shader/src/emit/lower.rs:1751-1763): bothShader::user_data_handle()(createHandleFromBinding+annotateHandle) and the cachedcbufferLoadLegacy.i32/extractinstructions are emitted intoself.s.entryrather thanself.cur, so cached values safely dominate all downstream uses across diverging control-flow paths.rustfmt --edition 2024 --checkflags comment alignment incrates/victory-shader/src/emit/lower/user_data_tests.rs.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.