Shaders/Bitcode: cache Shader::op declarations, primitive types, scalar constants, and zero-copy bitcode Writer #2665
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!2665
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2665"
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-25 17:44 UTC · original
RVZO6:rvzo/bitcode-emit-fast→main· +451 −125 · 2 files · 1 commits · openClaimed in #1633: #1633
Summary
Speeds up DXIL module construction and LLVM 3.7 bitcode emission (
crates/victory-shader/src/emit/bitcode.rs,crates/victory-shader/src/emit/shader.rs,+451/-125) while emitting bit-for-bit identical bitcode (allwritten_bytes_unchangedFNV-1a hashes unchanged):Shader::op_funcscache (shader.rs): cachesdx.op.<name>declarations in an FxHash map, skipping per-callVec<Ty>/format!/type_ids/func_idslookups, and moves the argVecintoModule::callwhensampler_choicesdoes not match.Moduleinterning (bitcode.rs): switches internal type/constant/func maps to FxHash, caches primitiveTyids (void,f32,i1,i8,i32,i64), and splits scalar constant interning (int/float/undef/aggregate) to avoid cloning on lookup hits while preservingreplace_constsemantics.Writer& flatPred(bitcode.rs): writes bitstream directly into a pre-sizedVec<u8>, caches active abbreviation width, specializesvbr6, streams variable-length records/strings directly without tempVec<u64>allocations, and replacesvec![Vec::new(); blocks]predecessor lists inModule::planwith a flatPredenum.Measured on
13f91ca(--release emit::bitcode::tests::bench_write, median of 3×5 runs, bit-for-bit identical FNV-1a hashes)13f91ca)64 regs × 64 stages(4,417 insts)38,956 B,0xf0d59e83b39da635214.8 µs161.3 µs128 regs × 256 stages(33,569 insts)252,532 B,0x59610d0b12c344142.811 ms1.978 ms256 regs × 512 stages(132,865 insts)1,232,736 B,0x82d39ac2b67ccb9f21.11 ms19.32 ms(Note:
bench_writeisolatesModule::write()only and does not include theShader::op/ primitive-type / scalar-constant caching wins during lowering.)Not a duplicate of
Shader::op,Moduletype/constant interning, andWriterbitstream serialization while preserving13f91ca's exactPlan/liveness semantics and bitcode output.Verification
windows-latestMSVC + WARP SM 6.6 CI (both clippy-D warningsprofiles,xtaskpolicy 6/6,victory-shader281/281 includingwritten_bytes_unchanged,vbr6_and_str_records_match_generic_vbr,cached_primitive_types_and_constants_intern_and_replace, andop_caches_declarations_and_handles_sampler_choices): https://github.com/RVZO6/VIctory/actions/runs/45666985023AI-assisted: T3 Code (Antigravity, gemini-4-neon)
@kotekompotek on GitHub · 2026-11-25 17:57 UTC · original
Reviewed: local FxHash (same multiply-rotate constant as
structure::Fx) for the bitcode maps plus cached op declarations/types — straight perf work in the emit hot path. CI green.@oni-swr on GitHub · 2026-11-25 18:21 UTC · original
Independent verification of #2665 (bitcode: cached
Shader::opdeclarations, primitive types/constants, zero-copyWriter)PR head
8105fdcfb68ac99d79ea728847a0f555b7a41521, merges cleanly ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca.Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1,
VICTORY_WARP=1+VICTORY_D3D12_WARP=1on every run (WARP adapter only, no physical GPU created), DXC/dxil 1.8.2502.11 (Windows SDK 10.0.26100.0, viaVICTORY_DXIL),cargo ... -j 4 --locked.Tests/clippy vs baseline.
origin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca:cargo test -p victory-shader --lib --locked -- --test-threads=1= 267 passed, 3 failed, 3 ignored. The 3 failures are WARP limits and are the same 3 in every variant below:a_mask_joined_with_data_at_a_uniform_loop_is_its_numberandpermutes_read_the_lane_named_and_zero_from_lanes_left_out("no pipeline for a wave of 32"), andgathers_at_a_level_match_the_hardware(WARP gather result differs). Clippy:cargo clippy -p victory-shader --all-targets --locked= 0 warnings.With #2665: 270 passed, 3 failed (same 3), 4 ignored (+3 tests, +1 ignored benchmark). Clippy: 0 warnings.
Equivalence. Full diff read.
is_voidnow compares against the cachedty_void; that is sound becausevoid()is the only place that createsTypeDef::Void.Module::functionalready returns the existing declaration by name, so cachingdx.op.<name>inop_funcsreturns the same function (the only difference would be an unused function type no longer interned if one name were ever requested with different argument types).vbr6/record_str/record_id_strare checked against the genericvbrpath; theWriterblock-length patching and abbrev-width stack are equivalent. Allemitcallers use widths <= 32, which the newdebug_assert!(debug builds only) relies on. Output check with the throwaway hashing patch: the same 650 containers are byte-identical toorigin/main; the only difference is one extra container from this PR's own new test (op_caches_declarations_and_handles_sampler_choices).bench_writealso prints identical FNV hashes of the written bytes for 3 large synthetic modules on base and with the PRs.Perf (release, combined run vs base).
shader::op4096 calls: 2837 / 2935 us -> 559 / 531 us;bench_write64 regs x 64 stages: 309 / 306 us -> 228 / 177 us; 256 x 512: 9.8 / 8.9 ms -> 7.0 / 7.1 ms.Findings: no bugs. Nit: the new
Fxinbitcode.rsduplicatesstructure::Fx(its doc says "matching"); sharing one would avoid drift. The test module now compiles on non-Windows (#[cfg(test)]); the Windows-only helpers stay gated.Limits: no physical GPU (WARP only), no game files; the 3 WARP-limited tests above are therefore not verified on hardware. Benchmarks are synthetic, release mode, one machine, two back-to-back rounds each for base and combined; they say nothing about real-title shaders.
AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.
@oni-swr on GitHub · 2026-11-25 18:23 UTC · original
Composition check: #2662 + #2664 + #2665 together
Heads: #2662
95f56a53f8ff90f700d74d102ad79538bad68771, #2664e6ab345e7b73be37a0741a54767e061aad35239c, #26658105fdcfb68ac99d79ea728847a0f555b7a41521, merged in that order ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbcaas a local merge commit (31ed3543e4c18b978f7b0a699a71f8d18e52a81b, not pushed). No conflicts: the three touch disjoint files (structure.rs;gfx10/fields.rs+ir.rs;emit/bitcode.rs+emit/shader.rs).Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1,
VICTORY_WARP=1+VICTORY_D3D12_WARP=1(WARP only), dxil 1.8.2502.11 (SDK 10.0.26100.0),-j 4 --locked.cargo test -p victory-shader --lib --locked -- --test-threads=1: 276 passed, 3 failed, 5 ignored. That is exactly baseline 267 + 2 + 4 + 3 new tests; the 3 failures are the same WARP-limited ones as onorigin/main(wave-of-32 x2, WARP gather).cargo clippy -p victory-shader --all-targets --locked: 0 warnings.origin/main, plus one extra from #2665's new test (throwaway hashing patch, not committed).shader::op4096 calls 2.84-2.94 ms -> 0.53-0.56 ms;ir::build2048 insts 2.24-2.29 ms -> 1.80-1.84 ms; 64movrelinsts 426-456 us -> 88-103 us; bitcode writer, 256x512 synthetic module, 8.9-9.8 ms -> 7.0-7.1 ms; BDDgivenn=13 ~465 us -> ~0.45 us (synthetic).Limits: no physical GPU, no game files; synthetic benchmarks only.
AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.
@fuzeofficlal on GitHub · 2026-11-25 18:32 UTC · original
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP +
dxil.dllverification, code review, and same-machine--releasebenchmark comparison of8105fdcf(on13f91ca):Hardware + Validator Verification (
rustc 1.98.1MSVC, Windows SDK10.0.26100.0dxil.dll)cargo clippy --locked -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo clippy --locked -p victory-shader --all-targets --features host -- -D warnings: 0 warnings.cargo test --locked -p victory-shader --lib emit::bitcode::tests -- --nocapture: 14 passed, 0 failed, 1 ignored (bench_write), includingvbr6_and_str_records_match_generic_vbrandcached_primitive_types_and_constants_intern_and_replace.cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index(exercises both RTX 5090 hardware and WARP withdxil.dllactive): 269 passed, 3 failed, 4 ignored. All 3 failures are the pre-existing RTX 5090 baseline mismatches (a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware), andheap_direct_texture_reads_mark_their_heap_indexis the pre-existing RTX 50900xc0000005baseline crash (#2571); all 3 new PR tests (includingop_caches_declarations_and_handles_sampler_choices), WARP, anddxil.dllvalidation passed with 0 regressions.Same-Machine
--releaseBenchmark (13f91cavs8105fdcf, bit-identical output & FNV-1a checksums)bench_writecase13f91ca8105fdcf64 regs x 64 stages(4,417 insts)38,956 B,0xf0d59e83b39da635173.16 µs116.58 µs128 regs x 256 stages(33,569 insts)252,532 B,0x59610d0b12c344141.5255 ms888.86 µs256 regs x 512 stages(132,865 insts)1,232,736 B,0x82d39ac2b67ccb9f10.2087 ms8.2122 msemit::shader::tests::bench_op_calls(4096x):336.6 µs/run.Code Review Notes
unsafeblocks found:int_constskeys on(Ty, i64),float_constskeys on rawu32bits (preserving+0.0/-0.0and distinct NaN payloads), and all caches are strictly per-instance (Shader/Module/Writer) with no shared static state.Writerword-alignment, nested block length backpatching,emit(bits + width <= 63), andvbr6(bits + 6 <= 37) match the priorVec<u32>writer bit-for-bit.@Marvisak on GitHub · 2026-11-25 22:22 UTC · original
Automated triage for the maintainers.
Merge candidate (performance, same output). In
crates/victory-shader/src/emit/shader.rs,Shader::opcaches itsdx.op.*declarations by name. That is equivalent, becauseModule::functionalready returns the existing declaration for a name. Incrates/victory-shader/src/emit/bitcode.rs:replace_constis unchanged;Module::plankeeps one predecessor or "many" instead of lists, which is allplanreads;Writerwrites bytes directly, with a specialisedvbr6and string records.I checked that every
emitwidth stays at 32 or below, which the single-flushemitrelies on, and that block lengths are still back-patched in words. Testers report thewritten_bytes_unchangedhashes and all lib-test containers byte-identical. It merges cleanly, including together with #2657 (same file); CIcheck: passing.Nit, not blocking: the new
Fxduplicatesstructure::Fx; sharing one would avoid drift.Generated by Claude Code
@Dukestar69 on GitHub · 2026-11-26 04:28 UTC · original · approved these changes
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-shader --lib emit::bitcode::tests: 14 passed, 0 failed, 1 ignored (including newvbr6_and_str_records_match_generic_vbrandcached_primitive_types_and_constants_intern_and_replace).cargo test -p victory-shader --lib emit::lower::tests: 33 passed, 0 failed.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@rezioliver-collab on GitHub · 2026-11-26 18:01 UTC · original
Graph construction accounted for most of the gain in a synthetic compute shader that repeatedly used the same DXIL operation declaration. On Apple M1, building the largest graph went from 2.102 ms to 0.308 ms. Including
Shader::finish(), the total went from 2.988 ms to 0.998 ms.I built the same graphs on
13f91caeand8105fdcf, with eight dependent integer operations per arm, a phi at each join and a final shared-memory store. The complete DXBC containers were byte-identical for all three sizes. These are median base/PR ratios from 12 alternating release pairs on macOS 14.7, Rust 1.98.1. The timed path starts at graph construction and ends with container emission.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.