xshader: add natively on hosts with doubles where MODE allows #642

Merged
NickStallman merged 3 commits from upstream-pr/642 into main 2026-12-01 23:20:45 +00:00
NickStallman commented 2026-12-01 21:44:22 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-12-01T21:44:22Z.


v_add_f64 is written as integer arithmetic on 128-bit values (tb_f64_add), which matches the card bit for bit on any host. Each inlined add costs about 250 basic blocks of DXIL. 22 recorded ProjectScarlett compute programs have 24 to 72 adds each, and in their two-lane form every add is written once per wave half. These adds make up more than half of their DXIL.

xshader --f64-host translates for a host whose shaders run doubles. There v_add_f64 becomes a precise HLSL double add wherever the result is the card's:

  • MODE. D3D12 requires doubles to round to nearest even and keep denormals. The native add is used only when MODE's f64 round field (bits 3:2) and f64 denormal field (bits 7:6) can only hold 0 and 3. MODE starts so, as the soft path assumes, and every s_round_mode, s_denorm_mode or s_setreg that reaches those bits must be an immediate that keeps them. A register written there sends every add in the program back to the helper. The f32 fields and DX10 clamp don't change v_add_f64 (native receipt: MODE bits 0x2cc).
  • NaN. The host's NaN bits are its own. A NaN source gives the first NaN source, quieted only under MODE.IEEE, and infinities of opposite sign give 0xfff8000000000000, through the same tb_f64_qnan as the helper.
  • Modifiers. abs and neg apply to the bits before the add, clamp and omod after it, as before.
  • precise keeps DXC from folding or reassociating the add (-0 + +0 stays +0).

The multiply, the fused multiply-add and everything else stay in integers. Without --f64-host the output is unchanged.

The provider

The host profile now records DoublePrecisionFloatShaderOps as doubles=yes|none, and TUXBOX_HOST_PROFILE=doubles=none takes it away. On a host with doubles, a compute program whose code decodes a v_add_f64 (tuxbox_dxbc::float64::adds_f64) is requested under keys of its own: <hash>_f64 (.f64) and, on a 32-lane host, <hash>_w32_f64 (.wave32f64). The host worker translates those with --f64-host (and --wave32-host). A host without doubles never asks for these keys, so it can't get that translation from a shared cache, and every other program keeps its key, so nothing else recompiles. The detector only picks the key: the translation is exact either way. Once any device in the process reports no doubles, the provider asks for none.

Shader preparation, slow markers, stage_baseline, shader_survey, the shader harness, triage and replay integrity know the two kinds. A program recorded as .f64 is surveyed and measured like a .dxbc one.

The GPU check

tools/native_rdna2/check_translated.py (JohnVonWells' comparison with native RDNA2 execution, #614/#615) gets --f64-host, which translates with the native add and fails if any program takes the other path than MODE says, and --edge-pairs, which adds every ordered pair of 20 edge values (signed zeros, denormals, the smallest normals, ±1, the largest finite values, infinities, quiet and signaling NaNs with payloads) ahead of the seeded records. The seeded records alone pair two infinities in no record and two zeros in one.

Native words from an AMD Raphael iGPU through HSA (gfx1036 run as gfx1030), 1024 MODE values; translated programs under the 23 MODE values of the check, nine of them native; 4,536 records per MODE value (448 edge pairs and 4,088 seeded):

Translation RTX 5090 (620.70.10) Raphael iGPU (RADV, Mesa 26.0.8)
--f64-host 0 of 104,328 words differ 0 of 104,328
soft (no flag) 0 of 104,328 0 of 104,328
--f64-host without the NaN rules (negative control) 1,052 415
native under every MODE value (negative control) – 16,063

All other forms pass as on main. Both cards report DoublePrecisionFloatShaderOps = 1 under GE-Proton11-15. The 5090's Vulkan driver reports shaderDenormPreserveFloat64 = false; vkd3d-proton still reports doubles for the NVIDIA driver, and the denormal sums above match.

Recorded programs

On 51,414 recorded ProjectScarlett .dxbc and .wave32 requests, the 22 programs with v_add_f64 change, with and without --wave32-host, and all of them compile with DXC 1.8.2505.1 and pass DXV. A seeded sample of 600 other requests translates to the same bytes, as it must: only the v_add_f64 lowering looks at the flag.

DXC CPU time and DXIL for the 22, main → --f64-host:

Flags DXC CPU time DXIL bytes Basic blocks
runtime compute flags (-O1 -disable-lifetime-markers -fnew-inlining-behavior) 573 s → 277 s 28.8 MB → 13.0 MB 797,000 → 328,000
runtime -O0 flags 618 s → 197 s 52.9 MB → 25.5 MB 1,758,000 → 684,000

The three largest (72 adds) took 60 to 64 s at the runtime flags, past COMPUTE_TIMEOUT (60 s), so the runtime compiles them at -O0; they now take 29 to 33 s. At -O3 the largest takes 237 s instead of 737 s. The NVIDIA driver's compile time for these programs was not measured, and the game was not run with this change.

Tests

  • native_f64_add_needs_a_host_with_doubles and native_f64_add_only_under_an_ieee_f64_mode (16 MODE writes) in src/tests/hlsl/float64_arith.rs; they don't build on main, which has no with_host_f64.
  • The host profile tests cover doubles=none and the new field. native_doubles tests: a host without doubles keeps <hash> and <hash>_w32, and one device without doubles settles the process.
  • finds_a_double_add_in_any_program_of_a_container (tuxbox-dxbc): a console container built in the test, with the add in either program; a multiply or an unknown container is no add.
  • test_double_requests_translate_with_native_adds_under_their_own_keys: each of the four compute kinds gets its own flags and cache entry. The survey, stage baseline and harness tests cover planning the new kinds.
  • Evidence: TuxBox check of d1fdbae544d9, no uncommitted changes, no GPU checks: 13 passed, 0 failed, 0 not run The provider's own tests build in the Windows typecheck; they run only in the GPU check.
  • Full python tuxbox.py check of d1fdbae5 (GE-Proton11-15): RTX 5090 (10de:2b85) 215 pass, AMD iGPU (1002:13c0) 214 pass; the one failure on each is lanes-selftest-texture-publication (#625, fails on main too).

Proposal and discussion: #641. Draft until that is agreed. Refs #533.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5595112691 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/642). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-12-01T21:44:22Z. --- `v_add_f64` is written as integer arithmetic on 128-bit values (`tb_f64_add`), which matches the card bit for bit on any host. Each inlined add costs about 250 basic blocks of DXIL. 22 recorded ProjectScarlett compute programs have 24 to 72 adds each, and in their two-lane form every add is written once per wave half. These adds make up more than half of their DXIL. `xshader --f64-host` translates for a host whose shaders run doubles. There `v_add_f64` becomes a `precise` HLSL `double` add wherever the result is the card's: - **MODE.** D3D12 requires doubles to round to nearest even and keep denormals. The native add is used only when MODE's f64 round field (bits 3:2) and f64 denormal field (bits 7:6) can only hold 0 and 3. MODE starts so, as the soft path assumes, and every `s_round_mode`, `s_denorm_mode` or `s_setreg` that reaches those bits must be an immediate that keeps them. A register written there sends every add in the program back to the helper. The f32 fields and DX10 clamp don't change `v_add_f64` (native receipt: MODE bits 0x2cc). - **NaN.** The host's NaN bits are its own. A NaN source gives the first NaN source, quieted only under MODE.IEEE, and infinities of opposite sign give `0xfff8000000000000`, through the same `tb_f64_qnan` as the helper. - **Modifiers.** abs and neg apply to the bits before the add, clamp and omod after it, as before. - `precise` keeps DXC from folding or reassociating the add (`-0 + +0` stays `+0`). The multiply, the fused multiply-add and everything else stay in integers. Without `--f64-host` the output is unchanged. ## The provider The host profile now records `DoublePrecisionFloatShaderOps` as `doubles=yes|none`, and `TUXBOX_HOST_PROFILE=doubles=none` takes it away. On a host with doubles, a compute program whose code decodes a `v_add_f64` (`tuxbox_dxbc::float64::adds_f64`) is requested under keys of its own: `<hash>_f64` (`.f64`) and, on a 32-lane host, `<hash>_w32_f64` (`.wave32f64`). The host worker translates those with `--f64-host` (and `--wave32-host`). A host without doubles never asks for these keys, so it can't get that translation from a shared cache, and every other program keeps its key, so nothing else recompiles. The detector only picks the key: the translation is exact either way. Once any device in the process reports no doubles, the provider asks for none. Shader preparation, slow markers, `stage_baseline`, `shader_survey`, the shader harness, triage and replay integrity know the two kinds. A program recorded as `.f64` is surveyed and measured like a `.dxbc` one. ## The GPU check `tools/native_rdna2/check_translated.py` (JohnVonWells' comparison with native RDNA2 execution, #614/#615) gets `--f64-host`, which translates with the native add and fails if any program takes the other path than MODE says, and `--edge-pairs`, which adds every ordered pair of 20 edge values (signed zeros, denormals, the smallest normals, ±1, the largest finite values, infinities, quiet and signaling NaNs with payloads) ahead of the seeded records. The seeded records alone pair two infinities in no record and two zeros in one. Native words from an AMD Raphael iGPU through HSA (gfx1036 run as gfx1030), 1024 MODE values; translated programs under the 23 MODE values of the check, nine of them native; 4,536 records per MODE value (448 edge pairs and 4,088 seeded): | Translation | RTX 5090 (620.70.10) | Raphael iGPU (RADV, Mesa 26.0.8) | |---|---:|---:| | `--f64-host` | 0 of 104,328 words differ | 0 of 104,328 | | soft (no flag) | 0 of 104,328 | 0 of 104,328 | | `--f64-host` without the NaN rules (negative control) | 1,052 | 415 | | native under every MODE value (negative control) | – | 16,063 | All other forms pass as on main. Both cards report `DoublePrecisionFloatShaderOps` = 1 under GE-Proton11-15. The 5090's Vulkan driver reports `shaderDenormPreserveFloat64 = false`; vkd3d-proton still reports doubles for the NVIDIA driver, and the denormal sums above match. ## Recorded programs On 51,414 recorded ProjectScarlett `.dxbc` and `.wave32` requests, the 22 programs with `v_add_f64` change, with and without `--wave32-host`, and all of them compile with DXC 1.8.2505.1 and pass DXV. A seeded sample of 600 other requests translates to the same bytes, as it must: only the `v_add_f64` lowering looks at the flag. DXC CPU time and DXIL for the 22, main → `--f64-host`: | Flags | DXC CPU time | DXIL bytes | Basic blocks | |---|---:|---:|---:| | runtime compute flags (`-O1 -disable-lifetime-markers -fnew-inlining-behavior`) | 573 s → 277 s | 28.8 MB → 13.0 MB | 797,000 → 328,000 | | runtime `-O0` flags | 618 s → 197 s | 52.9 MB → 25.5 MB | 1,758,000 → 684,000 | The three largest (72 adds) took 60 to 64 s at the runtime flags, past `COMPUTE_TIMEOUT` (60 s), so the runtime compiles them at `-O0`; they now take 29 to 33 s. At `-O3` the largest takes 237 s instead of 737 s. The NVIDIA driver's compile time for these programs was not measured, and the game was not run with this change. ## Tests - `native_f64_add_needs_a_host_with_doubles` and `native_f64_add_only_under_an_ieee_f64_mode` (16 MODE writes) in `src/tests/hlsl/float64_arith.rs`; they don't build on main, which has no `with_host_f64`. - The host profile tests cover `doubles=none` and the new field. `native_doubles` tests: a host without doubles keeps `<hash>` and `<hash>_w32`, and one device without doubles settles the process. - `finds_a_double_add_in_any_program_of_a_container` (tuxbox-dxbc): a console container built in the test, with the add in either program; a multiply or an unknown container is no add. - `test_double_requests_translate_with_native_adds_under_their_own_keys`: each of the four compute kinds gets its own flags and cache entry. The survey, stage baseline and harness tests cover planning the new kinds. - `Evidence: TuxBox check of d1fdbae544d9, no uncommitted changes, no GPU checks: 13 passed, 0 failed, 0 not run` The provider's own tests build in the Windows typecheck; they run only in the GPU check. - Full `python tuxbox.py check` of d1fdbae5 (GE-Proton11-15): RTX 5090 (`10de:2b85`) 215 pass, AMD iGPU (`1002:13c0`) 214 pass; the one failure on each is `lanes-selftest-texture-publication` (#625, fails on main too). Proposal and discussion: #641. **Draft** until that is agreed. Refs #533. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!642
No description provided.