tools: record what CLAMP and OMOD do on an RDNA 2 card under every MODE value (T5) #437

Merged
JeffreyBytes merged 7 commits from upstream-pr/437 into main 2026-11-29 08:57:51 +00:00
JeffreyBytes commented 2026-11-29 03:14:05 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-29T03:14:05Z.


Summary

Second piece of T5 (#412): what VOP3 clamp and the output modifiers do on an RDNA 2 card under every MODE value. #333 left two of these open because nobody knows the console's MODE bits 8 and 9, and I offered on #334 to measure them. This doesn't tell you what the console sets, but it reduces each open case to "which of four settings".

Same route as #420: hand-written kernels through ROCm, MODE[9:0] set with s_setreg_b32. 64 forms, each under all 1,024 MODE values, on an RX 6700 XT. The model in rdna2_float.py matches every recorded word.

Forms: clamp, mul:2, mul:4, div:2 and clamp with each OMOD on v_add_f32, v_sub_f32, v_mul_f32, v_mul_legacy_f32, v_fma_f32 and v_fmac_f32 (gfx1030's VOP3 encoding); clamp on v_min_f32/v_max_f32; v_fract_f32 plain and with OMOD; v_cvt_f32_ubyte0/2/3 with modifiers; neg and abs sources on the legacy multiply and on fmac; and the VOP3P clamp bit on v_fma_mix_f32, v_fma_mixlo_f16, v_fma_mixhi_f16. The assembler takes clamp mul:2 but not mul:2 clamp, and no OMOD on VOP3P.

What the card does

MODE bits that matter behavior
CLAMP the op's own, plus 0x100 a NaN result becomes +0 only with DX10_CLAMP set, otherwise it passes as made. IEEE doesn't change the clamp. -0 and negatives give +0, 1 and above give 1.0
OMOD the op's own, plus 0x220 does nothing at all when IEEE (bit 9) is set or f32 denormal results are kept (bit 5). Otherwise it's applied after rounding and flush, before CLAMP: a zero or denormal gives +0, NaN and inf are unchanged, anything else is an exact exponent shift. Underflow gives a signed zero, overflow follows the rounding mode (MAX × 2 is inf under nearest even)
neg / abs sources none extra a legacy product with a zero operand is +0 whatever the modifiers
v_fract_f32 0x233 a result that would round to 1.0 gives 0x3f7fffff

That OMOD rule is the one tb_half_output already encodes for f16 (mode & 0x280); this is the same thing measured for f32.

Against check_float_forms_gpu.py

Where its models accept more than one candidate, this is what the card gives for MODE 0xc0 with bits 8/9 as 00, DX10 only, IEEE only, both:

candidate 00 DX10 IEEE both
NaN through a clamp (clamped) NaN 0 NaN 0
OMOD of -0 (scaled) +0 +0 -0 -0
OMOD of a finite value scaled scaled not scaled not scaled
clamped zero, legacy zero, fraction near 1, fused rounding same in all four: +0, +0, 0x3f7fffff, rounded once

The IEEE columns are the surprise: with IEEE set nothing is scaled, not just zeros, and no candidate in the check allows for that. I haven't changed the check here.

Against the translator

I haven't changed the translator either, but three things stand out:

  • float_result (hlsl/emitter/values.rs) always emits tb_omod and then saturate(). That's the card with DX10_CLAMP set and IEEE clear, MODE 0x1c0, so it's an assumption about bits 8 and 9.
  • Even under that assumption tb_omod (hlsl/text/helper_code.rs) returns a zero or denormal input with its sign kept. The card gives +0.
  • The f16 path (tb_half_output in output.rs) reads DX10_CLAMP from the mode value, where it's clear under 0xc0, while the f32 path assumes it's set. They can't both be right.

What's still open

Which of the four the console uses. Nothing in the repo settles it. s_setreg_imm32_b32 is in 28,190 recorded shaders but which fields it writes isn't recorded. One thing worth a look by someone who knows the stage descriptor: the word at +0x44 that gave 0xc0 is 0x000000c0, upper bits zero. If that word is the whole MODE register, both bits are clear, a NaN passes through a clamp and the f32 path's saturate() is wrong for NaN. I haven't verified that reading.

Limits: one card, one ROCm build. f16 OMOD isn't measured. Same GFX10.3-only caveat as #420.

Layout

  • tools/native_rdna2/float_forms.hip, check_float_forms.py; check_float.py's run loop is split out so both share it (a rerun still reproduces native-rdna2-float.json byte for byte); rdna2_float.form() models the modifiers
  • evidence/native-rdna2-float-forms.json (99 KB)
  • tests/test_native_rdna2_float_forms.py, no GPU, about 13 s
  • a CLAMP and OMOD section in docs/CONSOLE_REFERENCE.md
  • two rows in docs/REFERENCES.md for ROCm and Mesa RADV, which the native checks run through and which weren't listed

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them:

No Lanes scenario and no NVIDIA run, for the same reasons as #420: this runs native instructions outside TuxBox's providers, only on an RDNA 2 card, and changes no provider, translator or shared check code.

GPU, driver and backend: AMD Radeon RX 6700 XT (1002:73df, gfx1031), Linux 7.3.6, ROCm under /opt/rocm with HSA_OVERRIDE_GFX_VERSION=10.3.0 (set by the script). No Proton involved.

Commands run and their results:

python tools/native_rdna2/check_float_forms.py --work build/native-rdna2-float-forms --output build/native-rdna2-float-forms.json
  PASS, 0 mismatches      (3 runs, identical receipts and raw results)

python -m unittest tests.test_native_rdna2_float_forms tests.test_native_rdna2_float
  OK

python -m unittest discover -s tests -q
  Ran 609 tests, OK (skipped=21)

python tuxbox.py check --no-gpu
  passed   Build the shader compiler
  passed   Python tests
  passed   Shader compiler tests
  passed   DXBC tests
  passed   XG layout tests
  passed   Storage codec tests
  passed   D3D12 Windows typecheck

Checks

docs/RESULTS.md and docs/progress.svg don't change; the new receipt isn't a type those views count.

<!-- greyfinch-sync:brcly/TuxBox:issue:5547099324 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/437). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-11-29T03:14:05Z. --- ## Summary Second piece of T5 (#412): what VOP3 `clamp` and the output modifiers do on an RDNA 2 card under every MODE value. #333 left two of these open because nobody knows the console's MODE bits 8 and 9, and I offered on #334 to measure them. This doesn't tell you what the console sets, but it reduces each open case to "which of four settings". Same route as #420: hand-written kernels through ROCm, `MODE[9:0]` set with `s_setreg_b32`. 64 forms, each under all 1,024 MODE values, on an RX 6700 XT. The model in `rdna2_float.py` matches every recorded word. Forms: `clamp`, `mul:2`, `mul:4`, `div:2` and clamp with each OMOD on `v_add_f32`, `v_sub_f32`, `v_mul_f32`, `v_mul_legacy_f32`, `v_fma_f32` and `v_fmac_f32` (gfx1030's VOP3 encoding); clamp on `v_min_f32`/`v_max_f32`; `v_fract_f32` plain and with OMOD; `v_cvt_f32_ubyte0`/`2`/`3` with modifiers; neg and abs sources on the legacy multiply and on fmac; and the VOP3P clamp bit on `v_fma_mix_f32`, `v_fma_mixlo_f16`, `v_fma_mixhi_f16`. The assembler takes `clamp mul:2` but not `mul:2 clamp`, and no OMOD on VOP3P. ### What the card does | | MODE bits that matter | behavior | | --- | --- | --- | | CLAMP | the op's own, plus `0x100` | a NaN result becomes +0 only with DX10_CLAMP set, otherwise it passes as made. IEEE doesn't change the clamp. -0 and negatives give +0, 1 and above give 1.0 | | OMOD | the op's own, plus `0x220` | does nothing at all when IEEE (bit 9) is set or f32 denormal results are kept (bit 5). Otherwise it's applied after rounding and flush, before CLAMP: a zero or denormal gives +0, NaN and inf are unchanged, anything else is an exact exponent shift. Underflow gives a signed zero, overflow follows the rounding mode (MAX × 2 is inf under nearest even) | | neg / abs sources | none extra | a legacy product with a zero operand is +0 whatever the modifiers | | `v_fract_f32` | `0x233` | a result that would round to 1.0 gives `0x3f7fffff` | That OMOD rule is the one `tb_half_output` already encodes for f16 (`mode & 0x280`); this is the same thing measured for f32. ### Against `check_float_forms_gpu.py` Where its models accept more than one candidate, this is what the card gives for MODE `0xc0` with bits 8/9 as 00, DX10 only, IEEE only, both: | candidate | 00 | DX10 | IEEE | both | | --- | --- | --- | --- | --- | | NaN through a clamp (`clamped`) | NaN | 0 | NaN | 0 | | OMOD of -0 (`scaled`) | +0 | +0 | -0 | -0 | | OMOD of a finite value | scaled | scaled | not scaled | not scaled | | clamped zero, legacy zero, fraction near 1, fused rounding | same in all four: +0, +0, `0x3f7fffff`, rounded once | | | | The IEEE columns are the surprise: with IEEE set nothing is scaled, not just zeros, and no candidate in the check allows for that. I haven't changed the check here. ### Against the translator I haven't changed the translator either, but three things stand out: - `float_result` (`hlsl/emitter/values.rs`) always emits `tb_omod` and then `saturate()`. That's the card with DX10_CLAMP set and IEEE clear, MODE `0x1c0`, so it's an assumption about bits 8 and 9. - Even under that assumption `tb_omod` (`hlsl/text/helper_code.rs`) returns a zero or denormal input with its sign kept. The card gives +0. - The f16 path (`tb_half_output` in `output.rs`) reads DX10_CLAMP from the mode value, where it's clear under `0xc0`, while the f32 path assumes it's set. They can't both be right. ### What's still open Which of the four the console uses. Nothing in the repo settles it. `s_setreg_imm32_b32` is in 28,190 recorded shaders but which fields it writes isn't recorded. One thing worth a look by someone who knows the stage descriptor: the word at +0x44 that gave `0xc0` is `0x000000c0`, upper bits zero. If that word is the whole MODE register, both bits are clear, a NaN passes through a clamp and the f32 path's `saturate()` is wrong for NaN. I haven't verified that reading. Limits: one card, one ROCm build. f16 OMOD isn't measured. Same GFX10.3-only caveat as #420. ### Layout - `tools/native_rdna2/float_forms.hip`, `check_float_forms.py`; `check_float.py`'s run loop is split out so both share it (a rerun still reproduces `native-rdna2-float.json` byte for byte); `rdna2_float.form()` models the modifiers - `evidence/native-rdna2-float-forms.json` (99 KB) - `tests/test_native_rdna2_float_forms.py`, no GPU, about 13 s - a CLAMP and OMOD section in `docs/CONSOLE_REFERENCE.md` - two rows in `docs/REFERENCES.md` for ROCm and Mesa RADV, which the native checks run through and which weren't listed ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [x] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: No Lanes scenario and no NVIDIA run, for the same reasons as #420: this runs native instructions outside TuxBox's providers, only on an RDNA 2 card, and changes no provider, translator or shared check code. GPU, driver and backend: AMD Radeon RX 6700 XT (`1002:73df`, gfx1031), Linux 7.3.6, ROCm under `/opt/rocm` with `HSA_OVERRIDE_GFX_VERSION=10.3.0` (set by the script). No Proton involved. Commands run and their results: ```text python tools/native_rdna2/check_float_forms.py --work build/native-rdna2-float-forms --output build/native-rdna2-float-forms.json PASS, 0 mismatches (3 runs, identical receipts and raw results) python -m unittest tests.test_native_rdna2_float_forms tests.test_native_rdna2_float OK python -m unittest discover -s tests -q Ran 609 tests, OK (skipped=21) python tuxbox.py check --no-gpu passed Build the shader compiler passed Python tests passed Shader compiler tests passed DXBC tests passed XG layout tests passed Storage codec tests passed D3D12 Windows typecheck ``` ## Checks `docs/RESULTS.md` and `docs/progress.svg` don't change; the new receipt isn't a type those views count.
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
brcly/TuxBox!437
No description provided.