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

Closed
SchmashinPrunes wants to merge 1 commit from upstream-pr/363 into main
SchmashinPrunes commented 2026-11-24 14:35:08 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-24T14:35:08Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:5474199479 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/363). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-24T14:35:08Z. --- 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)
omonkeyz commented 2026-11-25 13:50:50 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:50:50Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7164376381 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/363#issuecomment-7164376381). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:50:50Z. --- 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

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
omonkeyz/xbox-emulator!363
No description provided.