dxil/shader: integer gather4_l/_o, native FP16 v_med3_f16, pure SLOT_MEMORY_VAS, and sound is_nan/bitcast folding #182

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

@⁠Zalthor on GitHub · 2026-12-05 21:36 UTC · original
Zalthor:shader/gather4-fp16-med3-and-dxil-folds → main · +552 −50 · 9 files · 1 commits · draft

Summary

Targets high-cost instructions across hot shaders while avoiding overlap with upstream PRs (#162 SLOT_STRIDES/VIEW_SIZES pure reads and #169 SLOT_MEMORY page-directory pure reads) and rebased onto merged #96:

  1. Integer Bounds in image_gather4_l / image_gather4_l_o (crates/victory-shader/src/emit/lower/image_buf.rs):
    • Replaces float offset and border-clamp arithmetic with [-64, 65536] pre-clamped FpToSi + shared integer bounds and IMax / IMin.
  2. Native SM 6.2 FP16 v_med3_f16 (crates/victory-shader/src/emit/lower/operands.rs, valu.rs, emit/mod.rs):
    • Adds is_nan_f16, f16_bits_to_f32, and med3_f16 to emit native FP16 med3 (plus two-constant clamp min/max lowering under rdna::MED3) when native_f16_on() is enabled, and honors lower::TEST_NATIVE_FP16 in emit::native_fp16() for unit tests.
  3. Pure SLOT_MEMORY_VAS Descriptor Loads (crates/victory-shader/src/emit/lower/intersect.rs):
    • Marks immutable SLOT_MEMORY_VAS loads in pure_reads for cross-block / cross-UAV-write CSE (complementary to #162 and #169).
  4. Sound DXIL is_nan_f32 & Bitcast(Select) Folding (crates/victory-dxil/src/bitcode/opt.rs, opt_tests.rs):
    • Adds swap_int_pred, half_k (for native FP16 constant-clamp lowering), try_bitcast_value + generalized Bitcast(Select) folding across mixed constants/bitcasts, and folds 32-bit is_nan_f32 checks in either operand order (abs > 0x7F80_0000 / 0x7F80_0000 < abs / <=) strictly when bounded_late(src) proves the 32-bit float finite (preserving is_nan guards on data loads, Trunc/ZExt/Shl/LShr integer patterns, and non-finite math).
  5. Cache Bump: Increments TRANSLATOR_VERSION in crates/victory-shader/src/lib.rs.

Note: Deliberately omits memory.rs SLOT_STRIDES/VIEW_SIZES/SLOT_MEMORY pure reads to avoid conflicting with open PRs #162 and #169, and leaves lower/mod.rs finite_reads untouched so NaN checks in BVH disabled boxes, v_div_fixup_f32, v_cvt_{i,u}32_f32, VICTORY_NAN_SCRUB, and VICTORY_HDR_CLAMP stay intact. Shares opt.rs, opt_tests.rs, lower/tests.rs, and TRANSLATOR_VERSION with companion PR #181 — kept in draft until #181 merges so it can rebase cleanly afterward.

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 (25 passed; 0 failed, including bitcast_select_mixed_const_folds, is_nan_f32_folds_for_finite_med3, is_nan_f32_preserved_for_nonfinite, and is_nan_f16_preserved_for_data_loads_and_nonfinite), victory-shader (271 passed; 0 failed; 2 ignored; 55 filtered out + 5 passed; 0 failed runnable non-SM-6.6 valu_tests/intersect_tests, including f16_bits_to_f32_decodes_special_and_subnormal_values, native_fp16_med3_lowers_and_validates with rdna::MED3 clamp size check, and image_gather4_l_o_lowers_and_validates; the remaining SM 6.6 tests require a newer D3D12 runtime than Win10 LTSC inbox), and xtask (9 passed; 0 failed).
  • Pre-Review Historical Combined Cycle 6 Corpus & Live Telemetry (prior to dropping lower/mod.rs finite_reads during review, RX 9070 XT RDNA 4 Wave64):
    • 25,889 / 25,889 shaders emitted & validated by dxil.dll (0 errors); 3,950 / 3,950 used PSOs warmed cleanly.
    • Combined Cycle 6 DXIL delta (25,888 shaders): -1,354,407 ops (-1.67%).
    • Live C6_OPT_GPUTIME vs C5_OPT_GPUTIME (builtin:cruise, VICTORY_FSR_FRAMEGEN=0 real frames only): [compute 34fb51b8a0312e82] 0.780 -> 0.620 ms (-20.5%), [compute 5cf00dc39042edaf] 0.217 -> 0.173 ms (-20.3%), [compute 764ca63daec9c616] 14.8 -> 12.9 us/dispatch (-12.7%).
**@⁠Zalthor** on GitHub · 2026-12-05 21:36 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/181) `Zalthor:shader/gather4-fp16-med3-and-dxil-folds` → `main` · +552 −50 · 9 files · 1 commits · draft ## Summary Targets high-cost instructions across hot shaders while avoiding overlap with upstream PRs (#162 `SLOT_STRIDES`/`VIEW_SIZES` pure reads and #169 `SLOT_MEMORY` page-directory pure reads) and rebased onto merged #96: 1. **Integer Bounds in `image_gather4_l` / `image_gather4_l_o` (`crates/victory-shader/src/emit/lower/image_buf.rs`):** - Replaces float offset and border-clamp arithmetic with `[-64, 65536]` pre-clamped `FpToSi` + shared integer bounds and `IMax` / `IMin`. 2. **Native SM 6.2 FP16 `v_med3_f16` (`crates/victory-shader/src/emit/lower/operands.rs`, `valu.rs`, `emit/mod.rs`):** - Adds `is_nan_f16`, `f16_bits_to_f32`, and `med3_f16` to emit native FP16 `med3` (plus two-constant clamp `min`/`max` lowering under `rdna::MED3`) when `native_f16_on()` is enabled, and honors `lower::TEST_NATIVE_FP16` in `emit::native_fp16()` for unit tests. 3. **Pure `SLOT_MEMORY_VAS` Descriptor Loads (`crates/victory-shader/src/emit/lower/intersect.rs`):** - Marks immutable `SLOT_MEMORY_VAS` loads in `pure_reads` for cross-block / cross-UAV-write CSE (complementary to #162 and #169). 4. **Sound DXIL `is_nan_f32` & `Bitcast(Select)` Folding (`crates/victory-dxil/src/bitcode/opt.rs`, `opt_tests.rs`):** - Adds `swap_int_pred`, `half_k` (for native FP16 constant-clamp lowering), `try_bitcast_value` + generalized `Bitcast(Select)` folding across mixed constants/bitcasts, and folds 32-bit `is_nan_f32` checks in either operand order (`abs > 0x7F80_0000` / `0x7F80_0000 < abs` / `<=`) strictly when `bounded_late(src)` proves the 32-bit float finite (preserving `is_nan` guards on data loads, `Trunc`/`ZExt`/`Shl`/`LShr` integer patterns, and non-finite math). 5. **Cache Bump:** Increments `TRANSLATOR_VERSION` in `crates/victory-shader/src/lib.rs`. > **Note:** Deliberately omits `memory.rs` `SLOT_STRIDES`/`VIEW_SIZES`/`SLOT_MEMORY` pure reads to avoid conflicting with open PRs #162 and #169, and leaves `lower/mod.rs` `finite_reads` untouched so NaN checks in BVH disabled boxes, `v_div_fixup_f32`, `v_cvt_{i,u}32_f32`, `VICTORY_NAN_SCRUB`, and `VICTORY_HDR_CLAMP` stay intact. Shares `opt.rs`, `opt_tests.rs`, `lower/tests.rs`, and `TRANSLATOR_VERSION` with companion PR #181 — **kept in draft until #181 merges** so it can rebase cleanly afterward. ## 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` (`25 passed; 0 failed`, including `bitcast_select_mixed_const_folds`, `is_nan_f32_folds_for_finite_med3`, `is_nan_f32_preserved_for_nonfinite`, and `is_nan_f16_preserved_for_data_loads_and_nonfinite`), `victory-shader` (`271 passed; 0 failed; 2 ignored; 55 filtered out` + `5 passed; 0 failed` runnable non-SM-6.6 `valu_tests`/`intersect_tests`, including `f16_bits_to_f32_decodes_special_and_subnormal_values`, `native_fp16_med3_lowers_and_validates` with `rdna::MED3` clamp size check, and `image_gather4_l_o_lowers_and_validates`; the remaining SM 6.6 tests require a newer D3D12 runtime than Win10 LTSC inbox), and `xtask` (`9 passed; 0 failed`). - **Pre-Review Historical Combined Cycle 6 Corpus & Live Telemetry (prior to dropping `lower/mod.rs` `finite_reads` during review, RX 9070 XT RDNA 4 Wave64):** - `25,889 / 25,889` shaders emitted & validated by `dxil.dll` (`0` errors); `3,950 / 3,950` used PSOs warmed cleanly. - Combined Cycle 6 DXIL delta (`25,888` shaders): `-1,354,407` ops (`-1.67%`). - Live `C6_OPT_GPUTIME` vs `C5_OPT_GPUTIME` (`builtin:cruise`, `VICTORY_FSR_FRAMEGEN=0` real frames only): `[compute 34fb51b8a0312e82]` `0.780 -> 0.620 ms` (`-20.5%`), `[compute 5cf00dc39042edaf]` `0.217 -> 0.173 ms` (`-20.3%`), `[compute 764ca63daec9c616]` `14.8 -> 12.9 us/dispatch` (`-12.7%`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 21:39:10 +00:00
github-bot changed title from dxil/shader: integer gather4_l/_o, native FP16 v_med3_f16, legacy-mul finite_reads, and is_nan/bitcast folding to dxil/shader: integer gather4_l/_o, native FP16 v_med3_f16, pure SLOT_MEMORY_VAS, and sound is_nan/bitcast folding 2026-12-05 22:36:39 +00:00
github-bot force-pushed github-bot/gh-181 from 3962d6f564 to 85eb2953ec 2026-12-05 22:36:52 +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/182/head:github-bot/gh-181'
git switch 'github-bot/gh-181'

Merge

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