shader: lower v_fract_f16 in direct Compute and Pixel DXIL #3271

Manually merged
github merged 2 commits from github-bot/gh-3269 into gh-pr/3269/base 2026-11-28 05:28:15 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-28 03:08 UTC · original
legacy-code-archaeologist:shader/direct-fract-f16 → main · +442 −1 · 4 files · 2 commits · merged 2026-11-28 05:26 UTC

Lowers VOP1 (0x5f) and VOP3 (0x1df) v_fract_f16 in direct Compute and Pixel DXIL.

Fixes #3269. Refs #2935.

Summary

  • src/gfx1013_direct_compute.inl:
    • Lowered v_fract_f16 in DirectCompute::float_alu() with abs, neg, clamp, op_sel[0]/op_sel[3] (high-half VGPR read and high/low destination placement preserving the other 16 bits of vdst), VGPR/SGPR/literal/inline sources, exact min(x - floor(x), 0x3bff) clamping tiny negative fractions that round to 1.0 down to 0x3bff, non-finite ±Inf/NaN -> 0x7e00 (+0.0 under clamp), and the full 0x8000ccu binary16 mode gate (half_binary = true in DirectCompute::lower()).
    • Refuses DPP (dpp_control/permuted), SDWA, omod, unused VOP3 operand/op_sel bits, high-half op_sel on non-VGPR source, special scalar sources, and non-default or unknown binary16 rounding/denormal modes.
  • tests/native_fract_f16_check.py, tests/cmake/native_fract_f16.cmake:
    • 29 cases: positive/negative fractions and exact integers (0.0, -0.0, ±1.0, ±65504.0), tiny negative inputs (-2^-11, -2^-12, -2^-24 -> 0x3bff), positive binary16 subnormals (0x0001, 0x03ff), ±Inf and NaN (-> 0x7e00 or +0.0 under clamp), VOP3 abs/neg/op_sel=0b1001 with 0xDEADCAFE other-half preservation, SGPR/literal/inline (248, 129) sources, and partial EXEC_LO (0xAAAAAAAA) lane preservation.
    • 10 refusals: omod != 0, unused op_sel[1] / s1 bits, high-half op_sel on SGPR, DPP16, SDWA, vcc_lo source, s_round_mode 0x4, s_denorm_mode 0x3, and conditional MODE write.

Verification (dev and release /O2, Windows 10.0.26100)

  • ctest --preset dev --no-tests=error -V -R '^native_fract_f16_' & ctest --preset release --no-tests=error -V -R '^native_fract_f16_':
    • native_fract_f16_ir: Passed (29 cases matched exact Fraction model; 10 refusals matched).
    • native_fract_f16_controls: Passed (29 cases compiled to DXIL; 10 refusals verified).
    • native_fract_f16_pixel_warp: Passed (Microsoft Basic Render Driver 10.0.26100.9711, 14 pixel draws / 28 cases matched; debug_layer=unavailable).
    • native_fract_f16_pixel_hardware: Passed (14 pixel draws / 28 cases matched; NVIDIA Quadro M1000M, 32.0.15.7371, debug_layer=unavailable).
    • native_fract_f16_compute_hardware: Skipped (77) (Intel(R) HD Graphics 530, vendor 8086, device 191b, driver 31.0.101.2111 lacks SM 6.6 wave32 — needs testing on a wave32-capable GPU).
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 71/71 passed (0 skips).
  • Sensitivity mutants caught (rc=8): dropping 0x3bff clamp (tiny_neg_min_subnormal), dropping non_finite override (pos_inf/neg_inf/clamped), and removing v_fract_f16 from half_binary = true (s_round_mode unhandled) all failed native_fract_f16_ir.

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-28 03:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3269) `legacy-code-archaeologist:shader/direct-fract-f16` → `main` · +442 −1 · 4 files · 2 commits · merged 2026-11-28 05:26 UTC Lowers VOP1 (`0x5f`) and VOP3 (`0x1df`) `v_fract_f16` in direct Compute and Pixel DXIL. Fixes #3269. Refs #2935. ### Summary - **`src/gfx1013_direct_compute.inl`:** - Lowered `v_fract_f16` in `DirectCompute::float_alu()` with `abs`, `neg`, `clamp`, `op_sel[0]`/`op_sel[3]` (high-half VGPR read and high/low destination placement preserving the other 16 bits of `vdst`), VGPR/SGPR/literal/inline sources, exact `min(x - floor(x), 0x3bff)` clamping tiny negative fractions that round to `1.0` down to `0x3bff`, non-finite `±Inf`/NaN -> `0x7e00` (`+0.0` under `clamp`), and the full `0x8000ccu` binary16 mode gate (`half_binary = true` in `DirectCompute::lower()`). - Refuses DPP (`dpp_control`/`permuted`), SDWA, `omod`, unused VOP3 operand/op_sel bits, high-half `op_sel` on non-VGPR source, special scalar sources, and non-default or unknown binary16 rounding/denormal modes. - **`tests/native_fract_f16_check.py`, `tests/cmake/native_fract_f16.cmake`:** - `29` cases: positive/negative fractions and exact integers (`0.0`, `-0.0`, `±1.0`, `±65504.0`), tiny negative inputs (`-2^-11`, `-2^-12`, `-2^-24` -> `0x3bff`), positive binary16 subnormals (`0x0001`, `0x03ff`), `±Inf` and NaN (`-> 0x7e00` or `+0.0` under `clamp`), VOP3 `abs`/`neg`/`op_sel=0b1001` with `0xDEADCAFE` other-half preservation, SGPR/literal/inline (`248`, `129`) sources, and partial `EXEC_LO` (`0xAAAAAAAA`) lane preservation. - `10` refusals: `omod != 0`, unused `op_sel[1]` / `s1` bits, high-half `op_sel` on SGPR, DPP16, SDWA, `vcc_lo` source, `s_round_mode 0x4`, `s_denorm_mode 0x3`, and conditional `MODE` write. ### Verification (`dev` and `release` `/O2`, Windows `10.0.26100`) - `ctest --preset dev --no-tests=error -V -R '^native_fract_f16_'` & `ctest --preset release --no-tests=error -V -R '^native_fract_f16_'`: - `native_fract_f16_ir`: **Passed** (`29` cases matched exact `Fraction` model; `10` refusals matched). - `native_fract_f16_controls`: **Passed** (`29` cases compiled to DXIL; `10` refusals verified). - `native_fract_f16_pixel_warp`: **Passed** (`Microsoft Basic Render Driver` `10.0.26100.9711`, `14` pixel draws / `28` cases matched; `debug_layer=unavailable`). - `native_fract_f16_pixel_hardware`: **Passed** (`14` pixel draws / `28` cases matched; `NVIDIA Quadro M1000M`, `32.0.15.7371`, `debug_layer=unavailable`). - `native_fract_f16_compute_hardware`: **Skipped (`77`)** (`Intel(R) HD Graphics 530`, vendor `8086`, device `191b`, driver `31.0.101.2111` lacks SM 6.6 wave32 — needs testing on a wave32-capable GPU). - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: **71/71 passed** (`0` skips). - Sensitivity mutants caught (`rc=8`): dropping `0x3bff` clamp (`tiny_neg_min_subnormal`), dropping `non_finite` override (`pos_inf`/`neg_inf`/clamped), and removing `v_fract_f16` from `half_binary = true` (`s_round_mode` unhandled) all failed `native_fract_f16_ir`. AI-assisted.
Lower VOP1 (0x5f) and VOP3 (0x1df) v_fract_f16 in DirectCompute::float_alu() with abs/neg/clamp/op_sel[0]/op_sel[3], exact binary16 min(x - floor(x), 0x3bff) clamping tiny negative fractions to 0x3bff, non-finite +-Inf/NaN -> 0x7e00 (+0.0 under clamp), destination other-half preservation, 0x8000ccu mode gate, and IR/DXIL/Pixel/Compute coverage.

Fixes #3267, Refs #2935. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 03:11:25 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-28 03:35 UTC · original · requested changes

The hardware compute result missing from the author report is now verified. At ab36ae6e plus main 0fe4cebc, Debug and Release /O2 each pass all five native_fract_f16_* cases with zero skips, including the wave32 compute readback on RTX and both WARP and RTX pixel cases. Release also passes 5/5 on main 5033d2d3, integration tree 804af877.

ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R '^native_fract_f16_'

Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, WARP 10.0.26100.9818, DXC 10.0.26100.0. Please add the direct Compute/Pixel scope and the reproduction command to the experiment documentation. That will give the public capability record a reproducible entry and keep the existing Python/DPP scope clear.

**@⁠R0Y00** on GitHub · 2026-11-28 03:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3269#pullrequestreview-6095474013) · **requested changes** The hardware compute result missing from the author report is now verified. At `ab36ae6e` plus main `0fe4cebc`, Debug and Release /O2 each pass all five `native_fract_f16_*` cases with zero skips, including the wave32 compute readback on RTX and both WARP and RTX pixel cases. Release also passes 5/5 on main `5033d2d3`, integration tree `804af877`. ```powershell ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R '^native_fract_f16_' ``` Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, WARP 10.0.26100.9818, DXC 10.0.26100.0. Please add the direct Compute/Pixel scope and the reproduction command to the experiment documentation. That will give the public capability record a reproducible entry and keep the existing Python/DPP scope clear.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-28 03:39 UTC · original

I reviewed the diff (not run). I found nothing wrong in the lowering itself. Several fixture cases do not test what their comments say, though, and some branches are not reached by any case:

  • Constants. tiny_neg_2_m11 uses 0xB000, which is -0.125, not -2^-11. Its fract is 0.875 (0x3b00), not 0x3bff. tiny_neg_2_m12 and literal_src0 use 0xAC00, which is -0.0625, not -2^-12.
    • The intended inputs are 0x9000 (-2^-11, exact 0x3bff) and 0x8C00 (-2^-12). For 0x8C00, 1 - 2^-12 is a binary16 tie that rounds to 0x3c00, so it is the input that needs the PR's clamp to 0x3bff (min(..., 0x3BFF) in the model).
    • As written, only 0x8001 reaches the clamp below 1.0.
  • Rounding. Every finite case except 0x8001 has an exactly representable result. A truncating conversion in place of packed_half_rne would still match all of them, since 0x8001 gives 0x3bff either way. 0x9500 (-5 * 2^-12) and 0x9480 (-9 * 2^-13) would tell the two apart: nearest-even gives 0x3bfe, truncation 0x3bfd.
  • abs/neg. The only modifier case is vop3_abs_neg on 0xB400 (-0.25), where -|x| equals x. Dropping both the abs and the neg handling would still pass. A positive input with neg, or a negative one with abs alone, would catch it.
  • clamp. The clamp=1 cases have results of +0 only (0xFC00 and NaN). A finite input with clamp, for example 1.25 or -0.25, would check that clamp leaves values in [0, 1) unchanged.
  • op_sel. Only op_sel=0b1001 appears, and the op_sel[0]=0 cases have zero high source halves. Swapping the source and destination selection, or testing a single bit for both, would not show. Separate 0b0001 and 0b1000 cases, with a nonzero high half in the source, would.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-28 03:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3269#issuecomment-7233257415) I reviewed the diff (not run). I found nothing wrong in the lowering itself. Several fixture cases do not test what their comments say, though, and some branches are not reached by any case: - **Constants.** `tiny_neg_2_m11` uses `0xB000`, which is -0.125, not -2^-11. Its fract is 0.875 (`0x3b00`), not `0x3bff`. `tiny_neg_2_m12` and `literal_src0` use `0xAC00`, which is -0.0625, not -2^-12. - The intended inputs are `0x9000` (-2^-11, exact `0x3bff`) and `0x8C00` (-2^-12). For `0x8C00`, 1 - 2^-12 is a binary16 tie that rounds to `0x3c00`, so it is the input that needs the PR's clamp to `0x3bff` (`min(..., 0x3BFF)` in the model). - As written, only `0x8001` reaches the clamp below 1.0. - **Rounding.** Every finite case except `0x8001` has an exactly representable result. A truncating conversion in place of `packed_half_rne` would still match all of them, since `0x8001` gives `0x3bff` either way. `0x9500` (-5 * 2^-12) and `0x9480` (-9 * 2^-13) would tell the two apart: nearest-even gives `0x3bfe`, truncation `0x3bfd`. - **abs/neg.** The only modifier case is `vop3_abs_neg` on `0xB400` (-0.25), where `-|x|` equals `x`. Dropping both the abs and the neg handling would still pass. A positive input with `neg`, or a negative one with `abs` alone, would catch it. - **clamp.** The `clamp=1` cases have results of +0 only (`0xFC00` and NaN). A finite input with `clamp`, for example 1.25 or -0.25, would check that clamp leaves values in [0, 1) unchanged. - **op_sel.** Only `op_sel=0b1001` appears, and the `op_sel[0]=0` cases have zero high source halves. Swapping the source and destination selection, or testing a single bit for both, would not show. Separate `0b0001` and `0b1000` cases, with a nonzero high half in the source, would. AI-assisted.
Add docs/experiments/native-fract-f16.md and update tests/native_fract_f16_check.py (32 cases): fix tiny negative encodings (0x9000, 0x8C00), add RNE-vs-truncation discriminators (0x9500, 0x9480), split abs/neg, add finite clamp=1 cases, split op_sel[0] and op_sel[3] cases with nonzero high halves, and enforce the 32-word per-lane compute buffer limit. Refs #3267, #2935. AI-assisted.
Author
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-28 05:17 UTC · original

Thanks @⁠R0Y00 and @⁠Leyukaka — addressed both the documentation request and the fixture feedback:

  1. Created docs/experiments/native-fract-f16.md documenting v_fract_f16 (VOP1 0x5f / VOP3 0x1df) Direct Compute and Pixel lowering, min(x - floor(x), 0x3bff) semantics, clamp=1 behavior, supported VOP3 modifiers/sources, explicit refusals/mode gate (((mode_bits ^ 0xf0u) & 0x8000ccu)), 32-case Compute / 16-draw Pixel coverage, and exact reproduction command.
  2. Updated tests/native_fract_f16_check.py (32 cases total, with assert len(cases) <= 32 in compute_program):
    • Fixed tiny negative inputs to actual binary16 -2^-11 (0x9000 exact 0x3BFF) and -2^-12 (0x8C00 on both tiny_neg_2_m12 and literal_src0)
    • Added RNE-vs-truncation discriminators tiny_neg_5_m12 (0x9500 -> 0x3BFE) and tiny_neg_9_m13 (0x9480 -> 0x3BFE)
    • Split vop3_abs_neg into separate vop3_abs (0x7BFFB400, abs_=1) and vop3_neg (0x7BFF3400, neg=1)
    • Added finite clamp=1 cases vop3_clamp_pos (0x7BFF3D00) and vop3_clamp_neg (0x7BFFB400)
    • Added separate vop3_opsel_hi_src (op_sel=0b0001) and vop3_opsel_hi_dst (op_sel=0b1000), and set nonzero high halves (0x7BFF) on op_sel[0]=0 VGPR inputs

Verification (dev and release presets):

  • python -B tests/docs_links_check.py: passed (134 Markdown files, 636 links)
  • ctest --preset dev --no-tests=error --output-on-failure -j 1 -V -R '^native_fract_f16_': native_fract_f16_ir (32 cases, 10 refusals), native_fract_f16_controls (32 cases compiled, 10 refusals), native_fract_f16_pixel_warp (16 draws / 32 cases), and native_fract_f16_pixel_hardware passed; native_fract_f16_compute_hardware skipped (77 on local Intel HD Graphics 530 31.0.101.2111 lacking SM 6.6 wave32)
  • ctest --preset release --no-tests=error --output-on-failure -j 1 -V -R '^native_fract_f16_': 4 passed, 1 skipped (77 on Intel HD Graphics 530)
  • Sensitivity mutant on dev (dropping the 0x3BFF clamp select(cmp("eq", h, "15360"), "15359", h) -> h): killed by native_fract_f16_ir on tiny_neg_2_m12, tiny_neg_min_subnormal, and literal_src0 (0xdead3c00 != 0xdead3bff)

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-28 05:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3269#issuecomment-7234581757) Thanks @⁠R0Y00 and @⁠Leyukaka — addressed both the documentation request and the fixture feedback: 1. Created `docs/experiments/native-fract-f16.md` documenting `v_fract_f16` (VOP1 `0x5f` / VOP3 `0x1df`) Direct Compute and Pixel lowering, `min(x - floor(x), 0x3bff)` semantics, `clamp=1` behavior, supported VOP3 modifiers/sources, explicit refusals/mode gate (`((mode_bits ^ 0xf0u) & 0x8000ccu)`), 32-case Compute / 16-draw Pixel coverage, and exact reproduction command. 2. Updated `tests/native_fract_f16_check.py` (32 cases total, with `assert len(cases) <= 32` in `compute_program`): - Fixed tiny negative inputs to actual binary16 `-2^-11` (`0x9000` exact `0x3BFF`) and `-2^-12` (`0x8C00` on both `tiny_neg_2_m12` and `literal_src0`) - Added RNE-vs-truncation discriminators `tiny_neg_5_m12` (`0x9500` -> `0x3BFE`) and `tiny_neg_9_m13` (`0x9480` -> `0x3BFE`) - Split `vop3_abs_neg` into separate `vop3_abs` (`0x7BFFB400`, `abs_=1`) and `vop3_neg` (`0x7BFF3400`, `neg=1`) - Added finite `clamp=1` cases `vop3_clamp_pos` (`0x7BFF3D00`) and `vop3_clamp_neg` (`0x7BFFB400`) - Added separate `vop3_opsel_hi_src` (`op_sel=0b0001`) and `vop3_opsel_hi_dst` (`op_sel=0b1000`), and set nonzero high halves (`0x7BFF`) on `op_sel[0]=0` VGPR inputs Verification (`dev` and `release` presets): - `python -B tests/docs_links_check.py`: passed (`134` Markdown files, `636` links) - `ctest --preset dev --no-tests=error --output-on-failure -j 1 -V -R '^native_fract_f16_'`: `native_fract_f16_ir` (`32` cases, `10` refusals), `native_fract_f16_controls` (`32` cases compiled, `10` refusals), `native_fract_f16_pixel_warp` (`16` draws / `32` cases), and `native_fract_f16_pixel_hardware` passed; `native_fract_f16_compute_hardware` skipped (`77` on local Intel HD Graphics 530 `31.0.101.2111` lacking SM 6.6 wave32) - `ctest --preset release --no-tests=error --output-on-failure -j 1 -V -R '^native_fract_f16_'`: `4` passed, `1` skipped (`77` on Intel HD Graphics 530) - Sensitivity mutant on `dev` (dropping the `0x3BFF` clamp `select(cmp("eq", h, "15360"), "15359", h)` -> `h`): killed by `native_fract_f16_ir` on `tiny_neg_2_m12`, `tiny_neg_min_subnormal`, and `literal_src0` (`0xdead3c00 != 0xdead3bff`) AI-assisted.
github-bot changed target branch from main to gh-pr/3269/base 2026-11-28 05:28:13 +00:00
github manually merged commit 25d4699d5f into gh-pr/3269/base 2026-11-28 05:28:15 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-28 05:26 UTC · original · approved these changes

Re-reviewed 25d4699d. The experiment note now states the Direct Compute and Pixel scope, mode/refusal coverage and complete build commands. The fixture revision covers the actual -2^-11 and -2^-12 encodings and checks the rounding bound.

I built compile_dxil, native_compute_ir_dump, native_store_replay and offscreen_check in Release and ran ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^native_fract_f16_'. All five passed, with no skips, including physical wave32 Compute and both WARP and hardware Pixel readback. Windows 11 26200.9974, DXC 10.0.26100.0, RTX 4060 Laptop driver 32.0.16.1656 and inbox WARP 10.0.26100.9818. The documentation request is resolved.

**@⁠R0Y00** on GitHub · 2026-11-28 05:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3269#pullrequestreview-6096013873) · **approved these changes** Re-reviewed `25d4699d`. The experiment note now states the Direct Compute and Pixel scope, mode/refusal coverage and complete build commands. The fixture revision covers the actual `-2^-11` and `-2^-12` encodings and checks the rounding bound. I built `compile_dxil`, `native_compute_ir_dump`, `native_store_replay` and `offscreen_check` in Release and ran `ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^native_fract_f16_'`. All five passed, with no skips, including physical wave32 Compute and both WARP and hardware Pixel readback. Windows 11 26200.9974, DXC 10.0.26100.0, RTX 4060 Laptop driver 32.0.16.1656 and inbox WARP 10.0.26100.9818. The documentation request is resolved.
This discussion has been locked. Commenting is limited to contributors.
No description provided.