Repository navigation
Conversation
…ar constants, and zero-copy bitcode Writer Speed up DXIL module construction and LLVM 3.7 bitcode emission while producing bit-for-bit identical output (all written_bytes_unchanged FNV-1a hashes unchanged): - shader.rs: cache dx.op.<name> declarations in Shader::op_funcs (FxHash), skipping per-call Vec<Ty>/format!/type_ids/func_ids work, and move the arg Vec into Module::call when sampler_choices does not match. - bitcode.rs: switch internal type/constant/func interning maps to FxHash, cache primitive Ty ids (void/f32/i1/i8/i32/i64), split scalar constant interning (int/float/undef/aggregate) to avoid cloning on lookup hits while preserving replace_const semantics. - bitcode.rs: write bitstream directly into a pre-sized Vec<u8> (zero-copy Writer::finish), cache active abbreviation width, specialize vbr6, stream variable-length records/strings directly without temp Vec<u64> buffers, and replace vec![Vec::new(); blocks] predecessor lists in Module::plan with a flat Pred enum. Measured on 13f91ca (--release emit::bitcode::tests::bench_write, median of 3x5 runs, bit-for-bit identical FNV-1a hashes): - 64x64 ( 4,417 insts, 38,956 B, 0xf0d59e83b39da635): 214.8 -> 161.3 us (1.33x) - 128x256 ( 33,569 insts, 252,532 B, 0x59610d0b12c34414): 2.811 -> 1.978 ms (1.42x) - 256x512 (132,865 insts, 1,232,736 B, 0x82d39ac2b67ccb9f): 21.11 -> 19.32 ms (1.09x) Assisted-by: T3 Code (Antigravity, gemini-4-neon)
|
Reviewed: local FxHash (same multiply-rotate constant as |
|
Independent verification of #2665 (bitcode: cached PR head Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1, Tests/clippy vs baseline. Equivalence. Full diff read. Perf (release, combined run vs base). Findings: no bugs. Nit: the new 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. |
|
Composition check: #2662 + #2664 + #2665 together Heads: #2662 Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1,
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. |
|
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + Hardware + Validator Verification (
|
bench_write case |
Output size & FNV-1a | 13f91ca |
8105fdcf |
Speedup |
|---|---|---|---|---|
64 regs x 64 stages (4,417 insts) |
38,956 B, 0xf0d59e83b39da635 |
173.16 µs |
116.58 µs |
1.49x |
128 regs x 256 stages (33,569 insts) |
252,532 B, 0x59610d0b12c34414 |
1.5255 ms |
888.86 µs |
1.72x |
256 regs x 512 stages (132,865 insts) |
1,232,736 B, 0x82d39ac2b67ccb9f |
10.2087 ms |
8.2122 ms |
1.24x |
emit::shader::tests::bench_op_calls (4096x): 336.6 µs/run.
Code Review Notes
- No bugs, cache-key collisions, or
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.
|
Automated triage for the maintainers. Merge candidate (performance, same output). In
I checked that every Nit, not blocking: the new Generated by Claude Code |
…visak#2665) Port of upstream Marvisak#2665's bitcode.rs: a local FxHash-based Map replaces std HashMaps on the interning hot path; primitive types (void/i1/i8/i32/i64/float) are cached in Option<Ty> slots; the single (Ty, Const) const map splits per kind (int/float/undef/ aggregate) so lookups skip cloning and mismatched variants; the bitstream Writer goes from Vec<u32> words to a Vec<u8> byte buffer with a cached abbrev width and an inlined vbr6 fast path, and every record/phi/call site streams operands through record_header/record_str/record_id_str instead of building temp Vecs (reused phi_ops scratch kept). Adaptation: the PR's shader.rs op_funcs cache is NOT taken: this tree already carries a fuller op_decls LRU (name+attr+ret+opcode+ arg types, move-to-front, 48 entries) which subsumes it. Took instead the PR's test-module widening (cfg(test) with windows-only items gated) plus its two cross-platform tests adapted to op_decls (op_caches_declarations_and_handles_sampler_choices, bench_op_calls). Behavior note: Module::function() already dedupes by name ignoring later signatures, and func_ty/ptr interning is value-deduped, so declaration caching cannot change which V or type IDs are produced -- only how fast. Correctness: op_caches test + full shader suite (293 passed, incl. validator + byte-exact diff tests, which pin the emitted bitcode). Microbench (release, this machine, bench_op_calls 4096 ops: 1304.6 -> 777.3 us/run (-40%). Base measured with the same bench on the parent commit.
Dukestar69
left a comment
There was a problem hiding this comment.
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).
…clarations, primitive types, scalar constants, and zero-copy bitcode Writer
|
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
I built the same graphs on |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed at 8105fdcfb68ac99d79ea728847a0f555b7a41521 — APPROVE.
Verification
cargo xtask policy(191 files ok) andcargo clippy -p victory-shader --all-targets --all-features -- -D warningspassed cleanly.- Verified primitive type slots, scalar constant interning (
(Ty, i64)separatingi1/i8/i32/i64; rawu32bits infloat_constspreserving-0.0vs+0.0and distinct NaN payloads), and zero-copyWriterbit-packing,vbr6,record_str,align, and block-length backpatching against the genericWriterpath (vbr6_and_str_records_match_generic_vbrandwritten_bytes_unchangedpass). - Targeted tests (
emit::bitcode::tests14/14,emit::shader::tests2/2,emit::lower::tests33/33) and fullvictory-shaderruns under bothVICTORY_WARP=1andVICTORY_WARP=0matchedorigin/mainbaseline parity with no regressions introduced.
Non-blocking notes
Shader::op(crates/victory-shader/src/emit/shader.rs:243) inheritsModule::function's name-only keying (crates/victory-shader/src/emit/bitcode.rs:416), so adding a debug assertion that cached declarations matchret, parameter types, andattrwould catch any accidental overload collision early.Module::replace_const(crates/victory-shader/src/emit/bitcode.rs:409) continues to leave prior intern-map entries untouched (safe today becausefix_user_data_sizeruns at finalization with no subsequent lookups of the placeholder constant).- Minor
rustfmtwrapping difference in the new ignored benchmarkshader.rs:1150, andop_caches_declarations_and_handles_sampler_choices(shader.rs:1125) only checkschosen != r1rather than verifying theselectemission directly.
Claimed in #1633: #1633 (comment)
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)