dxil/shader: dominator-scoped LDS range bounds coalescing and split-reciprocal format_load #181

Open
github-bot wants to merge 1 commit from github-bot/gh-180 into main AGit
Owner

@⁠Zalthor on GitHub · 2026-12-05 21:33 UTC · original
Zalthor:shader/lds-range-bounds-and-format-load → main · +959 −201 · 8 files · 1 commits · open

Summary

Cuts DXIL instruction count and shader bounds/conversion overhead without disabling safety checks:

  1. Dominator-Scoped Integer Range & LDS Bounds Coalescing (crates/victory-dxil/src/bitcode.rs, opt.rs, opt_tests.rs, crates/victory-shader/src/emit/shader.rs, lds_gs.rs, tests.rs):
    • Adds sound unsigned integer range tracking (IntRange { max, may_one }) and dominator-scoped Facts::max_u propagation in DXIL opt.rs to fold provably in-bounds integer comparisons and eliminate redundant LDS guard branches safely.
    • Evaluates Op::Phi incoming operands with &Facts::default() so loop-body branch guards cannot leak across loop backedges, uses DXIL opcodes 135 (WaveAllBitCount, 0..=w) and 136 (WavePrefixBitCount, 0..=w-1) for wave bit-count bounds, respects operand int_bits in Countbits (31), and uses checked u128 arithmetic for flattenedThreadIdInGroup (96).
    • Coalesces multi-dword ds_read / ds_write bounds checks and simplifies dword indexing via dword_index().
    • Adds 6 int_range_* unit tests in opt_tests.rs and lds_b128_coalesced_read_and_write_lower_and_validate in lower/tests.rs (verifying lds_blocks = 2 shrinks DXIL below the clamped lds_blocks = 1 fallback).
  2. Bit-Exact Split-Reciprocal norm_f32_split for format_load (crates/victory-shader/src/emit/lower/memory.rs):
    • Replaces multi-op normalized UNORM / SNORM (1..=16-bit) integer division sequences in format_load with bit-exact IEEE-754 split-reciprocal multiplies (norm_f32_split), exhaustively tested over all normalized codes (split_reciprocal_is_bit_exact_for_all_normalized_codes).
  3. Cache Bump: Increments TRANSLATOR_VERSION in crates/victory-shader/src/lib.rs.

Note: Shares opt.rs, opt_tests.rs, lower/tests.rs, and TRANSLATOR_VERSION with companion draft PR #182. Sequenced ahead of #182 (PR #182 remains in draft until #181 merges, then rebases cleanly on top).

Verification

  • Rebased Checks (on origin/main ca49e25, post-review):
    • cargo clippy --workspace --all-targets --locked -- -D warnings and cargo clippy --workspace --all-targets --all-features --locked -- -D warnings pass (0 warnings).
    • Default and --all-features -- --test-threads=1 tests pass across victory-dxil (27 passed; 0 failed), victory-shader (270 passed; 0 failed; 2 ignored; 55 filtered out + 5 passed; 0 failed runnable non-SM-6.6 valu_tests/intersect_tests; the remaining SM 6.6 tests require a newer D3D12 runtime than Win10 LTSC inbox), and xtask (9 passed; 0 failed).
  • Pre-Review Full Shader Corpus DXIL Validation & Census (prior to review fixes, victory.exe translate --validate --list + VICTORY_SHADER_CENSUS, RDNA 4 Wave64):
    • 25,889 / 25,889 shaders emitted and validated cleanly by dxil.dll (0 validation errors).
    • Corpus (25,887 common shaders): 84,791,842 -> 81,140,547 total DXIL instructions (-3,651,295, -4.31%):
      • arith -2,619,151 (-7.59%), select -593,213 (-6.58%), bitcast -349,898 (-3.13%), cast -127,697 (-4.86%), blocks -15,514 (-0.50%)
      • Stage deltas: Mesh -12.15% (8,765 shrank), Vertex -10.02%, Compute -3.50%, Pixel -0.64%.
  • Pre-Review Live GPU PSO Impact (builtin:cruise, VICTORY_GPU_TIMINGS=1, VICTORY_FSR_FRAMEGEN=0 real frames only):
    • Hot patched shaders matched or outperformed diagnostic unsafe VICTORY_LDS_BOUNDS=0 while remaining 100% bounds-safe:
      • [compute 87bf9e3f2bf2f052] (-271 op / -84 blk): 0.142 -> 0.090 ms (cruise_back), 0.230 vs 0.290 ms unsafe LDS0 (spawn_idle)
      • [compute f8425d3c03df62a0] (-400 op / -32 blk): 0.213 -> 0.180 ms (spawn_idle), 0.204 -> 0.158 ms (cruise_out)
      • [mesh fd08d25a8c755b78, pixel 11f05e25425baf60] (-500 op): 0.257 -> 0.205 ms (spawn_idle)
      • [mesh 244ca58c13650317, pixel 73644c6a0b7b5b35] (-1,083 op): 0.150 -> 0.090 ms (cruise_back)
**@⁠Zalthor** on GitHub · 2026-12-05 21:33 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/180) `Zalthor:shader/lds-range-bounds-and-format-load` → `main` · +959 −201 · 8 files · 1 commits · open ## Summary Cuts DXIL instruction count and shader bounds/conversion overhead without disabling safety checks: 1. **Dominator-Scoped Integer Range & LDS Bounds Coalescing (`crates/victory-dxil/src/bitcode.rs`, `opt.rs`, `opt_tests.rs`, `crates/victory-shader/src/emit/shader.rs`, `lds_gs.rs`, `tests.rs`):** - Adds sound unsigned integer range tracking (`IntRange { max, may_one }`) and dominator-scoped `Facts::max_u` propagation in DXIL `opt.rs` to fold provably in-bounds integer comparisons and eliminate redundant LDS guard branches safely. - Evaluates `Op::Phi` incoming operands with `&Facts::default()` so loop-body branch guards cannot leak across loop backedges, uses DXIL opcodes `135` (`WaveAllBitCount`, `0..=w`) and `136` (`WavePrefixBitCount`, `0..=w-1`) for wave bit-count bounds, respects operand `int_bits` in `Countbits` (`31`), and uses checked `u128` arithmetic for `flattenedThreadIdInGroup` (`96`). - Coalesces multi-dword `ds_read` / `ds_write` bounds checks and simplifies dword indexing via `dword_index()`. - Adds 6 `int_range_*` unit tests in `opt_tests.rs` and `lds_b128_coalesced_read_and_write_lower_and_validate` in `lower/tests.rs` (verifying `lds_blocks = 2` shrinks DXIL below the clamped `lds_blocks = 1` fallback). 2. **Bit-Exact Split-Reciprocal `norm_f32_split` for `format_load` (`crates/victory-shader/src/emit/lower/memory.rs`):** - Replaces multi-op normalized `UNORM` / `SNORM` (`1..=16`-bit) integer division sequences in `format_load` with bit-exact IEEE-754 split-reciprocal multiplies (`norm_f32_split`), exhaustively tested over all normalized codes (`split_reciprocal_is_bit_exact_for_all_normalized_codes`). 3. **Cache Bump:** Increments `TRANSLATOR_VERSION` in `crates/victory-shader/src/lib.rs`. > **Note:** Shares `opt.rs`, `opt_tests.rs`, `lower/tests.rs`, and `TRANSLATOR_VERSION` with companion draft PR #182. **Sequenced ahead of #182** (PR #182 remains in draft until #181 merges, then rebases cleanly on top). ## Verification - **Rebased Checks (on `origin/main` `ca49e25`, post-review):** - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` pass (`0` warnings). - Default and `--all-features -- --test-threads=1` tests pass across `victory-dxil` (`27 passed; 0 failed`), `victory-shader` (`270 passed; 0 failed; 2 ignored; 55 filtered out` + `5 passed; 0 failed` runnable non-SM-6.6 `valu_tests`/`intersect_tests`; the remaining SM 6.6 tests require a newer D3D12 runtime than Win10 LTSC inbox), and `xtask` (`9 passed; 0 failed`). - **Pre-Review Full Shader Corpus DXIL Validation & Census (prior to review fixes, `victory.exe translate --validate --list` + `VICTORY_SHADER_CENSUS`, RDNA 4 Wave64):** - **`25,889 / 25,889`** shaders emitted and validated cleanly by `dxil.dll` (`0` validation errors). - Corpus (`25,887` common shaders): **`84,791,842 -> 81,140,547` total DXIL instructions (`-3,651,295`, `-4.31%`)**: - `arith -2,619,151 (-7.59%)`, `select -593,213 (-6.58%)`, `bitcast -349,898 (-3.13%)`, `cast -127,697 (-4.86%)`, `blocks -15,514 (-0.50%)` - Stage deltas: Mesh **`-12.15%`** (`8,765` shrank), Vertex **`-10.02%`**, Compute **`-3.50%`**, Pixel **`-0.64%`**. - **Pre-Review Live GPU PSO Impact (`builtin:cruise`, `VICTORY_GPU_TIMINGS=1`, `VICTORY_FSR_FRAMEGEN=0` real frames only):** - Hot patched shaders matched or outperformed diagnostic unsafe `VICTORY_LDS_BOUNDS=0` while remaining 100% bounds-safe: - `[compute 87bf9e3f2bf2f052]` (`-271 op / -84 blk`): `0.142 -> 0.090 ms` (`cruise_back`), `0.230` vs `0.290 ms` unsafe `LDS0` (`spawn_idle`) - `[compute f8425d3c03df62a0]` (`-400 op / -32 blk`): `0.213 -> 0.180 ms` (`spawn_idle`), `0.204 -> 0.158 ms` (`cruise_out`) - `[mesh fd08d25a8c755b78, pixel 11f05e25425baf60]` (`-500 op`): `0.257 -> 0.205 ms` (`spawn_idle`) - `[mesh 244ca58c13650317, pixel 73644c6a0b7b5b35]` (`-1,083 op`): `0.150 -> 0.090 ms` (`cruise_back`)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 21:39:02 +00:00
github-bot force-pushed github-bot/gh-180 from 4e9c5f8d61 to 19fdb32159 2026-12-05 22:31:18 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/181/head:github-bot/gh-180'
git switch 'github-bot/gh-180'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-180'
git switch 'github-bot/gh-180'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-180'
git switch 'github-bot/gh-180'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-180'
git switch 'main'
git merge --squash 'github-bot/gh-180'
git switch 'main'
git merge --ff-only 'github-bot/gh-180'
git switch 'main'
git merge 'github-bot/gh-180'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.