Proposal: native f64 adds where the host has doubles, and float literals in tb_cubeid #641

Closed
opened 2026-12-01 21:44:10 +00:00 by NickStallman · 2 comments
NickStallman commented 2026-12-01 21:44:10 +00:00 (Migrated from github.com)
Contributor

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


Two translator changes that need agreeing first under CONTRIBUTING: one is about 500 lines, and the other changes the HLSL of every program, so every cached shader recompiles once. The PRs are ready as drafts and link here.

1. Native v_add_f64 on hosts with doubles

v_add_f64 is lowered to integer arithmetic (tb_f64_add), about 250 DXIL basic blocks per inlined add. 22 recorded ProjectScarlett compute programs have 24 to 72 adds each, and the two-lane form writes each one twice, so the adds are more than half of their DXIL. The three largest take 60 to 64 s in DXC at the runtime flags, past COMPUTE_TIMEOUT, so they fall back to -O0.

The proposal is a precise HLSL double add where the result provably equals the card's:

  • only when MODE's f64 round and denormal fields can hold nothing but the IEEE settings;
  • with the card's NaN and infinity rules kept through the existing helpers;
  • only on hosts reporting DoublePrecisionFloatShaderOps;
  • requested under keys of its own (<hash>_f64, <hash>_w32_f64), so a host without doubles never receives that translation and no other program's key changes.

Measured:

  • Against native RDNA2 execution (JohnVonWells' check_translated.py, #614/#615, plus 448 edge-value pairs): 0 of 104,328 words differ on an RTX 5090 and on an AMD Raphael iGPU. Two broken variants used as negative controls differ in 415 to 16,063 words.
  • The 22 programs at the runtime flags: DXC CPU time 573 s → 277 s, DXIL 28.8 MB → 13.0 MB. The three largest take 29 to 33 s, under the timeout.
  • Full checks pass on both cards (the only failure is lanes-selftest-texture-publication, as on main).

2. tb_cubeid computes in doubles

select(z < 0.0, 5.0, 4.0) has two untyped literals, so HLSL types it double. Every program using v_cubeid_f32 is marked as using doubles, and vkd3d-proton refuses those pipelines on a host without them. The fix is f literals.

push_helpers writes the cube helpers into every program, used or not, so this one-line fix changes every translation's HLSL. A follow-up could emit the cube helpers only when called; that also changes every program once.

Question

Are these wanted, and when? If a full recompile is unwelcome now, the cube fix (and conditional helpers) could wait for the next change that touches every translation. The native adds change only the 22 programs.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:6731330557 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/641). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-12-01T21:44:10Z. --- Two translator changes that need agreeing first under CONTRIBUTING: one is about 500 lines, and the other changes the HLSL of every program, so every cached shader recompiles once. The PRs are ready as drafts and link here. ## 1. Native `v_add_f64` on hosts with doubles `v_add_f64` is lowered to integer arithmetic (`tb_f64_add`), about 250 DXIL basic blocks per inlined add. 22 recorded ProjectScarlett compute programs have 24 to 72 adds each, and the two-lane form writes each one twice, so the adds are more than half of their DXIL. The three largest take 60 to 64 s in DXC at the runtime flags, past `COMPUTE_TIMEOUT`, so they fall back to `-O0`. The proposal is a `precise` HLSL `double` add where the result provably equals the card's: - only when MODE's f64 round and denormal fields can hold nothing but the IEEE settings; - with the card's NaN and infinity rules kept through the existing helpers; - only on hosts reporting `DoublePrecisionFloatShaderOps`; - requested under keys of its own (`<hash>_f64`, `<hash>_w32_f64`), so a host without doubles never receives that translation and no other program's key changes. Measured: - Against native RDNA2 execution (JohnVonWells' `check_translated.py`, #614/#615, plus 448 edge-value pairs): 0 of 104,328 words differ on an RTX 5090 and on an AMD Raphael iGPU. Two broken variants used as negative controls differ in 415 to 16,063 words. - The 22 programs at the runtime flags: DXC CPU time 573 s → 277 s, DXIL 28.8 MB → 13.0 MB. The three largest take 29 to 33 s, under the timeout. - Full checks pass on both cards (the only failure is `lanes-selftest-texture-publication`, as on main). ## 2. `tb_cubeid` computes in doubles `select(z < 0.0, 5.0, 4.0)` has two untyped literals, so HLSL types it `double`. Every program using `v_cubeid_f32` is marked as using doubles, and vkd3d-proton refuses those pipelines on a host without them. The fix is `f` literals. `push_helpers` writes the cube helpers into every program, used or not, so this one-line fix changes every translation's HLSL. A follow-up could emit the cube helpers only when called; that also changes every program once. ## Question Are these wanted, and when? If a full recompile is unwelcome now, the cube fix (and conditional helpers) could wait for the next change that touches every translation. The native adds change only the 22 programs. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
brcly commented 2026-12-01 23:13:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by brcly on 2026-12-01T23:13:03Z.


@NickStallman both, now, please. Thanks for asking first.

  • #642 (native f64 adds): yes. The CI failure was a rustdoc link from the public with_host_f64 to the private native_add_mode; I pushed a51a5147 to your branch, which names it in plain text. I'll merge once CI is green.
  • #643 (tb_cubeid float literals): yes, merging now. The full recompile is accepted. The follow-up that writes the cube helpers only into programs that call them is welcome as its own PR; if it lands soon, the next preparation pays for both recompiles at once.
<!-- greyfinch-sync:brcly/TuxBox:comment:7329030522 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/641#issuecomment-7329030522). Originally posted by [brcly](https://github.com/brcly) on 2026-12-01T23:13:03Z. --- @NickStallman both, now, please. Thanks for asking first. - **#642 (native f64 adds):** yes. The CI failure was a rustdoc link from the public `with_host_f64` to the private `native_add_mode`; I pushed a51a5147 to your branch, which names it in plain text. I'll merge once CI is green. - **#643 (`tb_cubeid` float literals):** yes, merging now. The full recompile is accepted. The follow-up that writes the cube helpers only into programs that call them is welcome as its own PR; if it lands soon, the next preparation pays for both recompiles at once.
brcly commented 2026-12-02 21:35:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by brcly on 2026-12-02T21:35:41Z.


Both parts are merged: #642 (native f64 adds) and #643 (tb_cubeid float literals). Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7359502091 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/641#issuecomment-7359502091). Originally posted by [brcly](https://github.com/brcly) on 2026-12-02T21:35:41Z. --- Both parts are merged: #642 (native f64 adds) and #643 (`tb_cubeid` float literals). Thanks!
Sign in to join this conversation.
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#641
No description provided.