Shaders/Lower: dense Value tables, FxHash maps, lazy get() mask checks, O(1) valu16 reject, and zero-alloc buffer/mask helpers #2942
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2942
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2942"
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?
@RVZO6 on GitHub · 2026-11-26 00:57 UTC · original
RVZO6:rvzo/lower-hot-fast→main· +344 −82 · 3 files · 1 commits · openSummary
Optimizes hot lowering paths in
crates/victory-shader/src/emit/lower.rsacross all shaders while emitting 100% bit-identical DXIL (and keepinglower.rsbelow the 512 KiBxtask policylimit by placing helper tables and tests incrates/victory-shader/src/emit/lower/tables.rs):Valuetables &FxMap/FxSet(emit/lower/tables.rs): replaces SipHashHashMaps forvals,floats, andphi_atwithDenseMap<T>(Vec<Option<T>>indexed byValue.0), and usesFxMap/FxSetfor internal pure-lookup maps/sets (leavingdef_block/#2210,user_at/#2207, sub-dword stores/#2208,memory/#2167,counters, anduser_readsuntouched).is_maskcheck inLower::get(): defers the twost.masks/st.highsSipHash lookups into theMissing/Nonemask_okfallback instead of executing them unconditionally on every operand read.Lower::valu16(): skips scanning all 44 16-bit opcode names on every 32-bit VALU op when!name.ends_with("16") && name != "v_cvt_f16_f32".effectscan & encoding-gated checks inLower::inst(): movescontains("store")/contains("atomic")into theErr(why)arm only, and gatesmask_okstring checks onEncoding.round16,discards, andsectionschecks: skipsround16RPO/dataflow when nos_round_mode/s_setreg*exists, gatesround16_afteronSopp | Sopk, and hoists!discards.is_empty()andsections.contains_key(&b)outside per-instruction loops.reads_mask_as_data()&Lower::buffer(): borrows&[Operand]directly instead of collectingVec<&Operand>, and matchesformat_d16_*suffixes directly instead of allocatingname.replace("_format_d16_", "_format_")per buffer instruction.Measured (
--release bench_lower_hot_paths, median of 3 runs, 2,821-inst CS on63bcca4)emit::lower: 2,053.6 → 1,115.0 µs/run (1.84×, -45.7%)15,632 B, FNV-1a0x8b22c9b628d798d0before and after.Verification
emit::lower::tables::tests::dense_map_and_round16_fast_path_behave_identically.windows-latestMSVC + WARP SM 6.6 CI (clippy,xtask policy192 files ok, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45730729035Not run: the title; any hardware GPU.
AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Speed up emit::lower hot paths across all shaders with 100% bit-identical DXIL: - emit/lower/tables.rs: DenseMap<T> (Vec<Option<T>> indexed by Value.0) for vals, floats, and phi_at, plus FxMap/FxSet for internal lookup maps. - Lower::get: defer st.masks/st.highs SipHash lookups into the Missing/None mask_ok fallback instead of running them on every operand read. - Lower::valu16: fast-reject !name.ends_with("16") && name != "v_cvt_f16_f32" before scanning the 44 16-bit opcode names on every 32-bit VALU op. - Lower::inst: defer effect substring scans (contains("store"/"atomic")) to Err(why); gate mask_ok checks on Encoding. - Lower::run / round16: skip round16 RPO/dataflow when no s_round_mode or s_setreg* exists; gate round16_after on Sopp|Sopk; hoist !discards.is_empty() and sections.contains_key(&b) outside instruction loops. - reads_mask_as_data / Lower::buffer: eliminate per-call Vec<&Operand> and String replace("_format_d16_") heap allocations. Measured (--release bench_lower_hot_paths, median of 3 runs, 2,821-inst CS): - emit::lower: 2,053.6 -> 1,115.0 us/run (1.84x, -45.7%) - Identical DXIL: 15,632 B, FNV-1a 0x8b22c9b628d798d0 before and after. Assisted-by: T3 Code (Antigravity, gemini-4-neon)1569277a45to08efa8e07b@fuzeofficlal on GitHub · 2026-11-26 01:11 UTC · original
Code review and RTX 5090 + WARP + DXIL + release benchmark verification at head
1569277a4533merged cleanly ontomain(63bcca43c6a0;emit/lower.rs=522,163B,2,125B under the 512 KiB cap thanks toemit/lower/tables.rs):DenseMap<T>(emit/lower/tables.rs) pre-sizes fromvalue_count(p)and safely resizes on demand ininsert/entry, with no stale-slot reuse acrossvals/floats/phi_at.gfx10/opcodes.rs:round16(Sopk/Soppcoverss_setreg_b32,s_setreg_imm32_b32,s_round_mode),mask_ok(Sop1 | Sopc | Vop3),valu16(!ends_with("16") && != "v_cvt_f16_f32"), deferredeffectonErr, and_format_d16_allocation removal are all behaviorally equivalent.dxil.dll10.0.26100.0,VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:192 files ok;cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default +--features diagnostics): 0 warningstables::tests: 1/1 passed (dense_map_and_round16_fast_path_behave_identically, 1 ignored bench)emit::tests(17/17) andemit::semantics_tests(34/34, 1 ignored): passed on both RTX 5090 and WARP--releasebench_lower_hot_paths:lower_hot (2821 insts): 699.0 us/run, dxil=15632 B, fnv1a=0x8b22c9b628d798d0.Clean and well-tested; LGTM.
@Marvisak on GitHub · 2026-11-26 04:28 UTC · original · edited 2026-11-26 07:24 UTC
Automated triage for the maintainers.
Merge candidate. Both requested changes are in
08efa8e:emit/lower/tables.rsuses the sharedstructure::Fx.round16now callsround16_after(i, Some(0)), so the list of MODE writers is in one place.The fast path gives
Some(0)exactly for the blocks inreverse_postorderandNonefor the others, which matches the slow fixpoint when nothing changes MODE. TheSopp/Sopkgate inround16_aftercoverss_round_modeand boths_setregforms.lower.rsis 522,251 bytes, under the policy limit. The gain is in translation time.CI: passing.
Generated by Claude Code
@RVZO6 on GitHub · 2026-11-26 05:42 UTC · original
Addressed both triage items in
08efa8e:Fxhasher (pub(crate) struct Fxinstructure.rs) instead of duplicating it inemit/lower/tables.rs.round16(): the fast path now callsround16_after(i, Some(0)) != Some(0)directly as the single source of truth (and preservesNonefor unreachable blocks viareverse_postorder).Verified green on
windows-latestMSVC + WARP SM 6.6 CI (clippy default +--all-features,xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45762903919AI-assisted: T3 Code (Antigravity, gemini-4-neon)
@Dukestar69 on GitHub · 2026-11-26 07:47 UTC · original · approved these changes
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 +dxil.dll):cargo test -p victory-shader emit::lower::tests: 33 passed, 0 failed.cargo test -p victory-shader emit::tests -- --test-threads=1: 17 passed, 0 failed.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 09:48 UTC · original · reviewed
The dense
Valuetables, lazyget()mask checks,valu16fast-reject, deferredeffectscan,round16fast path, and zero-allocreads_mask_as_data/bufferhelpers preserve the local semantics I checked, andemit/lower.rsstays under the 512 KiB policy limit (522,251bytes).One gap remains in the "100% bit-identical DXIL across all shaders" claim:
read_phisswitched toFxSet, andlive_edges()seeds its LIFOworkstack fromself.read_phis.iter(). BecauseKnowncaps tracked conditions atMAX_KNOWN = 4(dropping the oldest condition on overflow) whileseenprunes subsets (d.get().iter().all(|c| known.get().contains(c))), changingread_phisiteration order can alter traversal order and potentially yield a different conservative live-edge set infill_phis(). The 2,821-instruction benchmark is straight-line and does not exercise this path. Could you compare base and head DXIL on a branch-heavy phi case with a missing incoming value (or qualify the claim accordingly)?Verified locally on Windows 11 x64 (RTX 5090 + WARP +
dxil.dll,08efa8e0):cargo run --locked -p xtask -- policy: passed (192 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanemit::lower::tables::tests: 1 passed, 0 failed (1 ignored bench)emit::lower::tests: 33 passed, 0 failedemit::tests -- --test-threads=1(RTX 5090 andVICTORY_WARP=1): 17 passed, 0 failed on bothView 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.