tombox-xshader: f16 omod in denorm mode 1 and underflow flush after the scale, from gfx1036 measurements #363

Closed
github-bot wants to merge 1 commit from gh-pr/363/head into gh-pr/363/base
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-24 14:35 UTC · original
SchmashinPrunes:rdna2-f16-omod → main · +193 −1 · 5 files · 1 commits · closed without merging

This follows up on the BLOCKERS entry "f16 output modifiers depend on the initial MODE". It said "the other f16 results follow the same output stage, but that is not measured". This PR measures all of them on RDNA2 and fixes two gaps the measurement shows.

Library / area: tombox-xshader (hlsl/mode.rs hres_mode, tests/exec.rs), tools/rdna2-hwprobe/omod_probe.py, docs/BLOCKERS.md

Exports changed (exports.txt rows): none

Source of the behaviour:

  • Results recorded on a gfx1036 iGPU (Ryzen 5 9600X, ROCm/HIP 5.7.1) with the new omod_probe.py, which uses the existing verify_runner.
  • That is RDNA2, not the console's gfx1013.
  • No game or console files.

Measurement

  • Ops: all 29 f16-result VALU ops that take an omod:
    • v_add, sub, subrev, mul, max, min, ldexp, fma, fmac, div_fixup, min3, max3 and med3_f16;
    • v_rcp, sqrt, rsq, log, exp, frexp_mant, floor, ceil, trunc, rndne, fract, sin and cos_f16;
    • v_cvt_f16_f32, _u16 and _i16.
  • Inputs: 8,192 per op, each without an omod and with mul:2, mul:4 and div:2.
  • MODEs: all 8 combinations of IEEE 0/1 and f16/f64 denorm mode 0–3.
  • Runs were repeated and the f16 results were identical.

omod_probe.py check reproduces every result: 1,021,365 scaled, 3,095,433 unchanged, 0 differences. The rule:

  1. When it acts: the omod acts only when IEEE is 0 and f16 output denormals are flushed (MODE bit 7 clear), so in f16 denorm modes 0 and 1. With IEEE 1, or output denormals kept, it never changes the result, for any of the 29 ops.
  2. Zero or denormal input: when it acts, a pre-omod result of ±0 or an f16 denormal becomes +0. Main's tb_om0 already does this for −0.
  3. Underflow after the scale: otherwise the value is scaled, and a scaled value below 2^-14 is flushed to a zero of its sign. The test is on the exact value, before rounding: 0x07ff div:2 gives 0, not 0x0400.

Change

  • The gate. hres_mode tested (tb_hw1 & 0x2c0) == 0, which needs both f16 denorm bits clear. A shader that sets denorm mode 1 (inputs kept, outputs flushed) lost its omod. The gate is now & 0x280.
  • The underflow flush. After the scale, the result is flushed when below 2^-14 (new helper tb_omh). Before, 0x0400 div:2 stored the denormal 0x0200 where the hardware gives 0.
  • Not affected: denormal pre-omod results (rule 2) only come from ops that pass an input through (min/max/med3, div_fixup), and those aren't in the MODE-owned op list. The ops in the list already have their outputs flushed in these modes.

Tests

f16_omod_follows_mode gains:

  • for every existing case, a mode-1 row (omod acts) and a mode-2 row (it doesn't);
  • four underflow cases: 0x0400 div:2 → 0, 0x8400 div:2 → 0x8000, 0x07ff div:2 → 0, and 0x0400 mul:2 → 0x0800.
run (Windows 11, DXC 1.9.2609, on f89e410) result
--test exec f16_omod on WARP 3 mnemonics verified, 0 failing, 32 cases (and with runtime inputs)
the same test on main's lowering (mutation check) 7 failing: the mode-1 rows and 0x0400 div:2
cargo test --locked -p tombox-xshader --release --no-fail-fast all pass (exec 128 passed, 2 ignored; lib 116 passed, 3 ignored)

With TOMBOX_EXEC_HW=1 on an RX 9060 XT, one case fails in the runtime-input rerun: v_add_f16(-0, -0) in the default MODE, which gives +0 there. That's the existing row #4 from main, it fails on main the same way, and it isn't touched by this change.

Related: #309 passes the initial MODE from PGM_RSRC1. With it, a title shader that starts in denorm mode 1 would reach this gate without writing MODE.

tools/rdna2-hwprobe/README.txt gets a section with the commands. #360 and #361 also append to that file, so whichever lands later needs a trivial merge there.

  • cargo test -p tombox-xshader passes
  • No game or console files and no binaries included
  • No fake success

🤖 Generated with Claude Code

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 14:35 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/363) `SchmashinPrunes:rdna2-f16-omod` → `main` · +193 −1 · 5 files · 1 commits · closed without merging This follows up on the BLOCKERS entry "f16 output modifiers depend on the initial MODE". It said "the other f16 results follow the same output stage, but that is not measured". This PR measures all of them on RDNA2 and fixes two gaps the measurement shows. **Library / area:** `tombox-xshader` (`hlsl/mode.rs` `hres_mode`, `tests/exec.rs`), `tools/rdna2-hwprobe/omod_probe.py`, `docs/BLOCKERS.md` **Exports changed (exports.txt rows):** none **Source of the behaviour:** - Results recorded on a gfx1036 iGPU (Ryzen 5 9600X, ROCm/HIP 5.7.1) with the new `omod_probe.py`, which uses the existing `verify_runner`. - That is RDNA2, not the console's gfx1013. - No game or console files. ### Measurement - **Ops:** all 29 f16-result VALU ops that take an omod: - `v_add`, `sub`, `subrev`, `mul`, `max`, `min`, `ldexp`, `fma`, `fmac`, `div_fixup`, `min3`, `max3` and `med3_f16`; - `v_rcp`, `sqrt`, `rsq`, `log`, `exp`, `frexp_mant`, `floor`, `ceil`, `trunc`, `rndne`, `fract`, `sin` and `cos_f16`; - `v_cvt_f16_f32`, `_u16` and `_i16`. - **Inputs:** 8,192 per op, each without an omod and with `mul:2`, `mul:4` and `div:2`. - **MODEs:** all 8 combinations of IEEE 0/1 and f16/f64 denorm mode 0–3. - Runs were repeated and the f16 results were identical. `omod_probe.py check` reproduces every result: 1,021,365 scaled, 3,095,433 unchanged, 0 differences. The rule: 1. **When it acts:** the omod acts **only** when IEEE is 0 and f16 **output** denormals are flushed (MODE bit 7 clear), so in f16 denorm modes 0 and 1. With IEEE 1, or output denormals kept, it never changes the result, for any of the 29 ops. 2. **Zero or denormal input:** when it acts, a pre-omod result of ±0 or an f16 denormal becomes **+0**. Main's `tb_om0` already does this for −0. 3. **Underflow after the scale:** otherwise the value is scaled, and a scaled value below 2^-14 is flushed to a zero **of its sign**. The test is on the exact value, before rounding: `0x07ff div:2` gives 0, not `0x0400`. ### Change - **The gate.** `hres_mode` tested `(tb_hw1 & 0x2c0) == 0`, which needs both f16 denorm bits clear. A shader that sets denorm mode 1 (inputs kept, outputs flushed) lost its omod. The gate is now `& 0x280`. - **The underflow flush.** After the scale, the result is flushed when below 2^-14 (new helper `tb_omh`). Before, `0x0400 div:2` stored the denormal `0x0200` where the hardware gives 0. - **Not affected:** denormal pre-omod results (rule 2) only come from ops that pass an input through (min/max/med3, div_fixup), and those aren't in the MODE-owned op list. The ops in the list already have their outputs flushed in these modes. ### Tests `f16_omod_follows_mode` gains: - for every existing case, a mode-1 row (omod acts) and a mode-2 row (it doesn't); - four underflow cases: `0x0400 div:2 → 0`, `0x8400 div:2 → 0x8000`, `0x07ff div:2 → 0`, and `0x0400 mul:2 → 0x0800`. | run (Windows 11, DXC 1.9.2609, on f89e410) | result | |---|---| | `--test exec f16_omod` on WARP | 3 mnemonics verified, 0 failing, 32 cases (and with runtime inputs) | | the same test on main's lowering (mutation check) | 7 failing: the mode-1 rows and `0x0400 div:2` | | `cargo test --locked -p tombox-xshader --release --no-fail-fast` | all pass (exec 128 passed, 2 ignored; lib 116 passed, 3 ignored) | With `TOMBOX_EXEC_HW=1` on an RX 9060 XT, one case fails in the runtime-input rerun: `v_add_f16(-0, -0)` in the default MODE, which gives +0 there. That's the existing row #4 from main, it fails on main the same way, and it isn't touched by this change. **Related:** #309 passes the initial MODE from PGM_RSRC1. With it, a title shader that starts in denorm mode 1 would reach this gate without writing MODE. `tools/rdna2-hwprobe/README.txt` gets a section with the commands. #360 and #361 also append to that file, so whichever lands later needs a trivial merge there. - [x] `cargo test -p tombox-xshader` passes - [x] No game or console files and no binaries included - [x] No fake success 🤖 Generated with [Claude Code](https://claude.com/claude-code)
omod_probe.py records all 29 f16-result VALU ops with mul:2, mul:4 and
div:2 under the 8 IEEE x f16/f64 denorm-mode combinations on gfx1036 and
checks them against one rule: the omod acts only with IEEE 0 and f16
output denormals flushed; a +-0 or denormal pre-omod result becomes +0,
and a scaled value below 2^-14 becomes a zero of its sign.

hres_mode gated on both f16 denorm bits (tb_hw1 & 0x2c0), so a shader in
denorm mode 1 (inputs kept, outputs flushed) lost its omod; the gate is
now & 0x280. After the scale the result is flushed when below 2^-14
(tb_omh), so 0x0400 div:2 gives 0 as on hardware instead of 0x0200.
f16_omod_follows_mode gains mode 1 and mode 2 rows and four underflow
cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:20:19 +00:00
github-bot closed this pull request 2026-11-26 06:20:19 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:50 UTC · original

Applied on main in 5ad807c (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:50 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/363#issuecomment-7164376381) Applied on main in 5ad807c (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.