Shaders/Bitcode: cache Shader::op declarations, primitive types, scalar constants, and zero-copy bitcode Writer #2663

Open
RVZO6 wants to merge 1 commit from upstream-pr/2665 into main
RVZO6 commented 2026-11-25 17:44:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-25T17:44:06Z.


Claimed in #1633: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7158204478

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 (all written_bytes_unchanged FNV-1a hashes unchanged):

  1. Shader::op_funcs cache (shader.rs): caches dx.op.<name> declarations in an FxHash map, skipping per-call Vec<Ty> / format! / type_ids / func_ids lookups, and moves the arg Vec into Module::call when sampler_choices does not match.
  2. Fast Module interning (bitcode.rs): switches internal type/constant/func maps to FxHash, caches primitive Ty ids (void, f32, i1, i8, i32, i64), and splits scalar constant interning (int/float/undef/aggregate) to avoid cloning on lookup hits while preserving replace_const semantics.
  3. Zero-copy Writer & flat Pred (bitcode.rs): writes bitstream directly into a pre-sized Vec<u8>, caches active abbreviation width, specializes vbr6, streams variable-length records/strings directly without temp Vec<u64> allocations, and replaces 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 3×5 runs, bit-for-bit identical FNV-1a hashes)

Synthetic module Size & FNV-1a hash (unchanged) Before (13f91ca) After Speedup
64 regs × 64 stages (4,417 insts) 38,956 B, 0xf0d59e83b39da635 214.8 µs 161.3 µs 1.33×
128 regs × 256 stages (33,569 insts) 252,532 B, 0x59610d0b12c34414 2.811 ms 1.978 ms 1.42×
256 regs × 512 stages (132,865 insts) 1,232,736 B, 0x82d39ac2b67ccb9f 21.11 ms 19.32 ms 1.09×

(Note: bench_write isolates Module::write() only and does not include the Shader::op / primitive-type / scalar-constant caching wins during lowering.)

Not a duplicate of

  • Checked #2657 (scopes liveness to reachable blocks / live phi edges) and #2640 (avoids quadratic planning on empty-block chains). This PR is orthogonal: it optimizes Shader::op, Module type/constant interning, and Writer bitstream serialization while preserving 13f91ca's exact Plan/liveness semantics and bitcode output.

Verification

  • Verified on windows-latest MSVC + WARP SM 6.6 CI (both clippy -D warnings profiles, xtask policy 6/6, victory-shader 281/281 including written_bytes_unchanged, vbr6_and_str_records_match_generic_vbr, cached_primitive_types_and_constants_intern_and_replace, and op_caches_declarations_and_handles_sampler_choices): https://github.com/RVZO6/VIctory/actions/runs/45666985023
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

<!-- greyfinch-sync:Marvisak/VIctory:issue:5496255045 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T17:44:06Z. --- Claimed in #1633: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7158204478 ### 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** (all `written_bytes_unchanged` FNV-1a hashes unchanged): 1. **`Shader::op_funcs` cache (`shader.rs`):** caches `dx.op.<name>` declarations in an FxHash map, skipping per-call `Vec<Ty>` / `format!` / `type_ids` / `func_ids` lookups, and moves the arg `Vec` into `Module::call` when `sampler_choices` does not match. 2. **Fast `Module` interning (`bitcode.rs`):** switches internal type/constant/func maps to FxHash, caches primitive `Ty` ids (`void`, `f32`, `i1`, `i8`, `i32`, `i64`), and splits scalar constant interning (`int`/`float`/`undef`/`aggregate`) to avoid cloning on lookup hits while preserving `replace_const` semantics. 3. **Zero-copy `Writer` & flat `Pred` (`bitcode.rs`):** writes bitstream directly into a pre-sized `Vec<u8>`, caches active abbreviation width, specializes `vbr6`, streams variable-length records/strings directly without temp `Vec<u64>` allocations, and replaces `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 3×5 runs, bit-for-bit identical FNV-1a hashes) | Synthetic module | Size & FNV-1a hash (unchanged) | Before (`13f91ca`) | After | Speedup | |---|---|---:|---:|---:| | `64 regs × 64 stages` (4,417 insts) | `38,956 B`, `0xf0d59e83b39da635` | `214.8 µs` | `161.3 µs` | **1.33×** | | `128 regs × 256 stages` (33,569 insts) | `252,532 B`, `0x59610d0b12c34414` | `2.811 ms` | `1.978 ms` | **1.42×** | | `256 regs × 512 stages` (132,865 insts) | `1,232,736 B`, `0x82d39ac2b67ccb9f` | `21.11 ms` | `19.32 ms` | **1.09×** | *(Note: `bench_write` isolates `Module::write()` only and does not include the `Shader::op` / primitive-type / scalar-constant caching wins during lowering.)* ### Not a duplicate of - Checked #2657 (scopes liveness to reachable blocks / live phi edges) and #2640 (avoids quadratic planning on empty-block chains). This PR is orthogonal: it optimizes `Shader::op`, `Module` type/constant interning, and `Writer` bitstream serialization while preserving `13f91ca`'s exact `Plan`/liveness semantics and bitcode output. ### Verification - Verified on `windows-latest` MSVC + WARP SM 6.6 CI (both clippy `-D warnings` profiles, `xtask` policy 6/6, `victory-shader` 281/281 including `written_bytes_unchanged`, `vbr6_and_str_records_match_generic_vbr`, `cached_primitive_types_and_constants_intern_and_replace`, and `op_caches_declarations_and_handles_sampler_choices`): https://github.com/RVZO6/VIctory/actions/runs/45666985023 - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
kotekompotek commented 2026-11-25 18:02:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:57:12Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170231280 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#issuecomment-7170231280). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T17:57:12Z. --- 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 commented 2026-11-25 19:06:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T18:21:51Z.


Independent verification of #2665 (bitcode: cached Shader::op declarations, primitive types/constants, zero-copy Writer)

PR head 8105fdcfb68ac99d79ea728847a0f555b7a41521, merges cleanly onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca.

Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1, VICTORY_WARP=1 + VICTORY_D3D12_WARP=1 on every run (WARP adapter only, no physical GPU created), DXC/dxil 1.8.2502.11 (Windows SDK 10.0.26100.0, via VICTORY_DXIL), cargo ... -j 4 --locked.

Tests/clippy vs baseline. origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca: 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_number and permutes_read_the_lane_named_and_zero_from_lanes_left_out ("no pipeline for a wave of 32"), and gathers_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_void now compares against the cached ty_void; that is sound because void() is the only place that creates TypeDef::Void. Module::function already returns the existing declaration by name, so caching dx.op.<name> in op_funcs returns 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_str are checked against the generic vbr path; the Writer block-length patching and abbrev-width stack are equivalent. All emit callers use widths <= 32, which the new debug_assert! (debug builds only) relies on. Output check with the throwaway hashing patch: the same 650 containers are byte-identical to origin/main; the only difference is one extra container from this PR's own new test (op_caches_declarations_and_handles_sampler_choices). bench_write also 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::op 4096 calls: 2837 / 2935 us -> 559 / 531 us; bench_write 64 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 Fx in bitcode.rs duplicates structure::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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170805559 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#issuecomment-7170805559). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T18:21:51Z. --- **Independent verification of #2665** (bitcode: cached `Shader::op` declarations, primitive types/constants, zero-copy `Writer`) PR head `8105fdcfb68ac99d79ea728847a0f555b7a41521`, merges cleanly onto `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca`. **Environment:** Windows 11 Pro 10.0.26200, rustc 1.98.1, `VICTORY_WARP=1` + `VICTORY_D3D12_WARP=1` on every run (WARP adapter only, no physical GPU created), DXC/dxil 1.8.2502.11 (Windows SDK 10.0.26100.0, via `VICTORY_DXIL`), `cargo ... -j 4 --locked`. **Tests/clippy vs baseline.** `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca`: `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_number` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out` ("no pipeline for a wave of 32"), and `gathers_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_void` now compares against the cached `ty_void`; that is sound because `void()` is the only place that creates `TypeDef::Void`. `Module::function` already returns the existing declaration by name, so caching `dx.op.<name>` in `op_funcs` returns 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_str` are checked against the generic `vbr` path; the `Writer` block-length patching and abbrev-width stack are equivalent. All `emit` callers use widths <= 32, which the new `debug_assert!` (debug builds only) relies on. Output check with the throwaway hashing patch: the same **650 containers are byte-identical to `origin/main`**; the only difference is one extra container from this PR's own new test (`op_caches_declarations_and_handles_sampler_choices`). `bench_write` also 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::op` 4096 calls: 2837 / 2935 us -> 559 / 531 us; `bench_write` 64 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 `Fx` in `bitcode.rs` duplicates `structure::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 commented 2026-11-25 19:06:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T18:23:08Z.


Composition check: #2662 + #2664 + #2665 together

Heads: #2662 95f56a53f8ff90f700d74d102ad79538bad68771, #2664 e6ab345e7b73be37a0741a54767e061aad35239c, #2665 8105fdcfb68ac99d79ea728847a0f555b7a41521, merged in that order onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca as 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 on origin/main (wave-of-32 x2, WARP gather).
  • cargo clippy -p victory-shader --all-targets --locked: 0 warnings.
  • Emitted containers over the lib test run: 650 byte-identical to origin/main, plus one extra from #2665's new test (throwaway hashing patch, not committed).
  • Perf (release, combined vs base, 2 rounds each): shader::op 4096 calls 2.84-2.94 ms -> 0.53-0.56 ms; ir::build 2048 insts 2.24-2.29 ms -> 1.80-1.84 ms; 64 movrel insts 426-456 us -> 88-103 us; bitcode writer, 256x512 synthetic module, 8.9-9.8 ms -> 7.0-7.1 ms; BDD given n=13 ~465 us -> ~0.45 us (synthetic).
  • No interaction bugs found. The merge order does not matter (disjoint files).

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170834685 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#issuecomment-7170834685). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T18:23:08Z. --- **Composition check: #2662 + #2664 + #2665 together** Heads: #2662 `95f56a53f8ff90f700d74d102ad79538bad68771`, #2664 `e6ab345e7b73be37a0741a54767e061aad35239c`, #2665 `8105fdcfb68ac99d79ea728847a0f555b7a41521`, merged in that order onto `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca` as 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 on `origin/main` (wave-of-32 x2, WARP gather). - `cargo clippy -p victory-shader --all-targets --locked`: 0 warnings. - Emitted containers over the lib test run: 650 byte-identical to `origin/main`, plus one extra from #2665's new test (throwaway hashing patch, not committed). - Perf (release, combined vs base, 2 rounds each): `shader::op` 4096 calls 2.84-2.94 ms -> 0.53-0.56 ms; `ir::build` 2048 insts 2.24-2.29 ms -> 1.80-1.84 ms; 64 `movrel` insts 426-456 us -> 88-103 us; bitcode writer, 256x512 synthetic module, 8.9-9.8 ms -> 7.0-7.1 ms; BDD `given` n=13 ~465 us -> ~0.45 us (synthetic). - No interaction bugs found. The merge order does not matter (disjoint files). 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 commented 2026-11-25 19:06:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T18:32:52Z.


Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + dxil.dll verification, code review, and same-machine --release benchmark comparison of 8105fdcf (on 13f91ca):

Hardware + Validator Verification (rustc 1.98.1 MSVC, Windows SDK 10.0.26100.0 dxil.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), including vbr6_and_str_records_match_generic_vbr and cached_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 with dxil.dll active): 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), and heap_direct_texture_reads_mark_their_heap_index is the pre-existing RTX 5090 0xc0000005 baseline crash (#2571); all 3 new PR tests (including op_caches_declarations_and_handles_sampler_choices), WARP, and dxil.dll validation passed with 0 regressions.

Same-Machine --release Benchmark (13f91ca vs 8105fdcf, bit-identical output & FNV-1a checksums)

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 unsafe blocks found: int_consts keys on (Ty, i64), float_consts keys on raw u32 bits (preserving +0.0/-0.0 and distinct NaN payloads), and all caches are strictly per-instance (Shader/Module/Writer) with no shared static state.
  • Writer word-alignment, nested block length backpatching, emit (bits + width <= 63), and vbr6 (bits + 6 <= 37) match the prior Vec<u32> writer bit-for-bit.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7171057123 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#issuecomment-7171057123). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T18:32:52Z. --- Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + `dxil.dll` verification, code review, and same-machine `--release` benchmark comparison of `8105fdcf` (on `13f91ca`): ### Hardware + Validator Verification (`rustc 1.98.1` MSVC, Windows SDK `10.0.26100.0` `dxil.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`), including `vbr6_and_str_records_match_generic_vbr` and `cached_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 with `dxil.dll` active): **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`), and `heap_direct_texture_reads_mark_their_heap_index` is the pre-existing RTX 5090 `0xc0000005` baseline crash (#2571); all 3 new PR tests (including `op_caches_declarations_and_handles_sampler_choices`), WARP, and `dxil.dll` validation passed with 0 regressions. ### Same-Machine `--release` Benchmark (`13f91ca` vs `8105fdcf`, bit-identical output & FNV-1a checksums) | `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 `unsafe` blocks found: `int_consts` keys on `(Ty, i64)`, `float_consts` keys on raw `u32` bits (preserving `+0.0`/`-0.0` and distinct NaN payloads), and all caches are strictly per-instance (`Shader`/`Module`/`Writer`) with no shared static state. - `Writer` word-alignment, nested block length backpatching, `emit` (`bits + width <= 63`), and `vbr6` (`bits + 6 <= 37`) match the prior `Vec<u32>` writer bit-for-bit.
Marvisak commented 2026-11-25 23:06:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:22:57Z.


Automated triage for the maintainers.

Merge candidate (performance, same output). In crates/victory-shader/src/emit/shader.rs, Shader::op caches its dx.op.* declarations by name. That is equivalent, because Module::function already returns the existing declaration for a name. In crates/victory-shader/src/emit/bitcode.rs:

  • the type, constant and function maps use an Fx hasher;
  • primitive types are cached and constants are interned per kind; replace_const is unchanged;
  • Module::plan keeps one predecessor or "many" instead of lists, which is all plan reads;
  • Writer writes bytes directly, with a specialised vbr6 and string records.

I checked that every emit width stays at 32 or below, which the single-flush emit relies on, and that block lengths are still back-patched in words. Testers report the written_bytes_unchanged hashes and all lib-test containers byte-identical. It merges cleanly, including together with #2657 (same file); CI check: passing.

Nit, not blocking: the new Fx duplicates structure::Fx; sharing one would avoid drift.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176292011 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#issuecomment-7176292011). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:22:57Z. --- <!-- victory-triage v1 head=8105fdcfb68ac99d79ea728847a0f555b7a41521 verdict=merge-candidate at=2026-11-25T22:27:00Z --> Automated triage for the maintainers. **Merge candidate** (performance, same output). In `crates/victory-shader/src/emit/shader.rs`, `Shader::op` caches its `dx.op.*` declarations by name. That is equivalent, because `Module::function` already returns the existing declaration for a name. In `crates/victory-shader/src/emit/bitcode.rs`: - the type, constant and function maps use an Fx hasher; - primitive types are cached and constants are interned per kind; `replace_const` is unchanged; - `Module::plan` keeps one predecessor or "many" instead of lists, which is all `plan` reads; - `Writer` writes bytes directly, with a specialised `vbr6` and string records. I checked that every `emit` width stays at 32 or below, which the single-flush `emit` relies on, and that block lengths are still back-patched in words. Testers report the `written_bytes_unchanged` hashes and all lib-test containers byte-identical. It merges cleanly, including together with #2657 (same file); CI `check`: passing. Nit, not blocking: the new `Fx` duplicates `structure::Fx`; sharing one would avoid drift. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 04:28:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:28:22Z.

Review: APPROVED


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 new vbr6_and_str_records_match_generic_vbr and cached_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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068556257 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#pullrequestreview-6068556257). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T04:28:22Z. **Review:** APPROVED --- 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 new `vbr6_and_str_records_match_generic_vbr` and `cached_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 commented 2026-11-26 18:01:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by rezioliver-collab on 2026-11-26T18:01:37Z.


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.

Branch-and-join stages Graph construction speedup Build + finish speedup
4 4.41× 2.44×
32 6.59× 2.98×
256 6.83× 2.98×

I built the same graphs on 13f91cae and 8105fdcf, 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7199968364 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#issuecomment-7199968364). Originally posted by [rezioliver-collab](https://github.com/rezioliver-collab) on 2026-11-26T18:01:37Z. --- 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**. | Branch-and-join stages | Graph construction speedup | Build + finish speedup | |---:|---:|---:| | 4 | 4.41× | 2.44× | | 32 | 6.59× | 2.98× | | 256 | 6.83× | 2.98× | I built the same graphs on `13f91cae` and `8105fdcf`, 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.
fuzeofficlal commented 2026-11-27 02:41:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:41:27Z.

Review: APPROVED


Reviewed at 8105fdcfb68ac99d79ea728847a0f555b7a41521 — APPROVE.

Verification

  • cargo xtask policy (191 files ok) and cargo clippy -p victory-shader --all-targets --all-features -- -D warnings passed cleanly.
  • Verified primitive type slots, scalar constant interning ((Ty, i64) separating i1/i8/i32/i64; raw u32 bits in float_consts preserving -0.0 vs +0.0 and distinct NaN payloads), and zero-copy Writer bit-packing, vbr6, record_str, align, and block-length backpatching against the generic Writer path (vbr6_and_str_records_match_generic_vbr and written_bytes_unchanged pass).
  • Targeted tests (emit::bitcode::tests 14/14, emit::shader::tests 2/2, emit::lower::tests 33/33) and full victory-shader runs under both VICTORY_WARP=1 and VICTORY_WARP=0 matched origin/main baseline parity with no regressions introduced.

Non-blocking notes

  • Shader::op (crates/victory-shader/src/emit/shader.rs:243) inherits Module::function's name-only keying (crates/victory-shader/src/emit/bitcode.rs:416), so adding a debug assertion that cached declarations match ret, parameter types, and attr would 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 because fix_user_data_size runs at finalization with no subsequent lookups of the placeholder constant).
  • Minor rustfmt wrapping difference in the new ignored benchmark shader.rs:1150, and op_caches_declarations_and_handles_sampler_choices (shader.rs:1125) only checks chosen != r1 rather than verifying the select emission directly.
<!-- greyfinch-sync:Marvisak/VIctory:review:6082786171 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#pullrequestreview-6082786171). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T02:41:27Z. **Review:** APPROVED --- Reviewed at `8105fdcfb68ac99d79ea728847a0f555b7a41521` — **APPROVE**. ### Verification - `cargo xtask policy` (`191 files ok`) and `cargo clippy -p victory-shader --all-targets --all-features -- -D warnings` passed cleanly. - Verified primitive type slots, scalar constant interning (`(Ty, i64)` separating `i1`/`i8`/`i32`/`i64`; raw `u32` bits in `float_consts` preserving `-0.0` vs `+0.0` and distinct NaN payloads), and zero-copy `Writer` bit-packing, `vbr6`, `record_str`, `align`, and block-length backpatching against the generic `Writer` path (`vbr6_and_str_records_match_generic_vbr` and `written_bytes_unchanged` pass). - Targeted tests (`emit::bitcode::tests` 14/14, `emit::shader::tests` 2/2, `emit::lower::tests` 33/33) and full `victory-shader` runs under both `VICTORY_WARP=1` and `VICTORY_WARP=0` matched `origin/main` baseline parity with no regressions introduced. ### Non-blocking notes - `Shader::op` (`crates/victory-shader/src/emit/shader.rs:243`) inherits `Module::function`'s name-only keying (`crates/victory-shader/src/emit/bitcode.rs:416`), so adding a debug assertion that cached declarations match `ret`, parameter types, and `attr` would 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 because `fix_user_data_size` runs at finalization with no subsequent lookups of the placeholder constant). - Minor `rustfmt` wrapping difference in the new ignored benchmark `shader.rs:1150`, and `op_caches_declarations_and_handles_sampler_choices` (`shader.rs:1125`) only checks `chosen != r1` rather than verifying the `select` emission directly.
andrewpozdnakov7-jpg commented 2026-11-28 18:57:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T18:57:17Z.


I repeated the Windows release comparison through the full translation path on current main. Combined 64a4849 is a clean merge of the exact 8105fdc and 63bcca4. All nine generated DXIL containers passed validation and matched main byte for byte. The cases cover unary operators, float/half conversions and FMA at 16, 128 and 512 blocks.

For the 512-block cases, the two alternating process orders gave these local medians:

Generated shader First order Reverse order Allocation and reallocation calls
Unary 1.94 → 1.51 ms 1.97 → 1.60 ms 6,996 → 4,492
Conversion 9.43 → 7.20 ms 9.53 → 7.74 ms 11,609 → 8,335
FMA 2.88 → 1.86 ms 2.87 → 1.80 ms 8,407 → 5,136

The shortest unary case varied between runs. Timing excludes validation, which was performed separately on every container. The 14 active bitcode tests, strict shader Clippy and the asset policy passed on the combined tree.

RVZO6 or the maintainer can use the clean current-main comparison for review. Please retain the original Git authorship if taking the change.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7244178698 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#issuecomment-7244178698). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T18:57:17Z. --- I repeated the Windows release comparison through the full translation path on current main. [Combined 64a4849](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/64a4849aa04866f0b74833d34a96d37cd6cb62d6) is a clean merge of the exact 8105fdc and 63bcca4. All nine generated DXIL containers passed validation and matched main byte for byte. The cases cover unary operators, float/half conversions and FMA at 16, 128 and 512 blocks. For the 512-block cases, the two alternating process orders gave these local medians: | Generated shader | First order | Reverse order | Allocation and reallocation calls | | --- | ---: | ---: | ---: | | Unary | 1.94 → 1.51 ms | 1.97 → 1.60 ms | 6,996 → 4,492 | | Conversion | 9.43 → 7.20 ms | 9.53 → 7.74 ms | 11,609 → 8,335 | | FMA | 2.88 → 1.86 ms | 2.87 → 1.80 ms | 8,407 → 5,136 | The shortest unary case varied between runs. Timing excludes validation, which was performed separately on every container. The 14 active bitcode tests, strict shader Clippy and the asset policy passed on the combined tree. RVZO6 or the maintainer can use the clean current-main comparison for review. Please retain the original Git authorship if taking the change. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 20:52:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T20:52:34Z.


I combined RVZO6's exact 8105fdc with the emit-plan reuse from #3791. Combined 979e5b8 preserves both commits as direct parents.

Against #2665 on current main, nine generated full translations emitted byte-identical DXIL accepted by Microsoft's signed 1.9.2609.5 validator. The full-translation timing medians across five alternating pairs were mixed at 0.964–1.102× baseline. Four branch-heavy bitcode fixtures also emitted identical bytes and had median times of 0.778–0.808× baseline. The largest fixture emitted 185,872 bytes and went from 22 to 14 allocations and from 7 to 4 reallocations in the paired emitter harness. All 15 active bitcode tests, both strict Clippy configurations and the asset policy passed.

@RVZO6, the combined branch is available if the maintainer takes both changes. Please retain the Git authors on cherry-pick or rebase, or include Co-authored-by: andrewpozdnakov7-jpg [email protected] if folding the emit-plan change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7245607361 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2665#issuecomment-7245607361). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T20:52:34Z. --- I combined RVZO6's exact 8105fdc with the emit-plan reuse from #3791. [Combined 979e5b8](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/979e5b88e69270edd0399ead945d32ecffcfb37a) preserves both commits as direct parents. Against #2665 on current main, nine generated full translations emitted byte-identical DXIL accepted by Microsoft's signed 1.9.2609.5 validator. The full-translation timing medians across five alternating pairs were mixed at 0.964–1.102× baseline. Four branch-heavy bitcode fixtures also emitted identical bytes and had median times of 0.778–0.808× baseline. The largest fixture emitted 185,872 bytes and went from 22 to 14 allocations and from 7 to 4 reallocations in the paired emitter harness. All 15 active bitcode tests, both strict Clippy configurations and the asset policy passed. @RVZO6, the combined branch is available if the maintainer takes both changes. Please retain the Git authors on cherry-pick or rebase, or include Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the emit-plan change into another commit. AI-assisted with OpenAI Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2665:upstream-pr/2665'
git switch 'upstream-pr/2665'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2665'
git switch 'upstream-pr/2665'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2665'
git switch 'upstream-pr/2665'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2665'
git switch 'main'
git merge --squash 'upstream-pr/2665'
git switch 'main'
git merge --ff-only 'upstream-pr/2665'
git switch 'main'
git merge 'upstream-pr/2665'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2663
No description provided.