shader: lower binary16 rounding and transcendental ops in gfx2hlsl (Part of #1723) #2074
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2074
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2074/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@tedin7 on GitHub · 2026-11-25 00:01 UTC · original
tedin7:x2w-b3-f16-alu-trans→main· +389 −0 · 5 files · 8 commits · closed without mergingPart of #1723
What this unblocks: shaders that round, take roots or reciprocals, or use exp/log/sin/cos on 16-bit values now translate in gfx2hlsl instead of stopping on an unsupported opcode.
Lowers
v_ceil_f16,v_floor_f16,v_trunc_f16,v_rndne_f16,v_fract_f16,v_rcp_f16,v_rsq_f16,v_sqrt_f16,v_sin_f16,v_cos_f16,v_exp_f16andv_log_f16(VOP1 and VOP3 without modifiers). The source is the low half of the operand; the result is computed in binary32, rounded to binary16 and written to the low half with the high half cleared (likev_cvt_f16_f32).v_fract_f16stops at 0x3bff. Inline constants and neg/abs source modifiers work; clamp/omod/op_sel and wrong operand counts are refused.Verification: (Win2025 was not used; commands run locally on Linux)
python3 -B tests/startup_gfx2hlsl_f16_trans_check.py->f16 transcendental checks: 0 failed(same file on origin/main: 48 failed)python3 -B tests/startup_gfx2hlsl_operand_count_check.py-> 0 failedpython3 -B tests/startup_gfx2hlsl_op_refusals_check.py-> 3 cases passedpython3 -B tests/startup_gfx2hlsl_capture_check.py-> passedstartup_gfx2hlsl_f16_transin CMakeLists.txt.AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:01 UTC · original · edited 2026-11-25 00:09 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
48dbc9bℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
@ -3032,0 +3068,4 @@'v_ceil_f16': 'ceil({0})', 'v_floor_f16': 'floor({0})', 'v_trunc_f16': 'trunc({0})', 'v_rndne_f16': 'round({0})','v_fract_f16': 'min(frac({0}), 0.99951171875)', 'v_rcp_f16': '1.0 / {0}', 'v_rsq_f16': 'rsqrt({0})','v_sqrt_f16': 'sqrt({0})', 'v_sin_f16': 'sin({0} * 6.283185307)', 'v_cos_f16': 'cos({0} * 6.283185307)','v_exp_f16': 'exp2({0})', 'v_log_f16': 'log2({0})',@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:09 UTC · original
For real shader bytecode, the new rcp/rsq/sqrt/exp/log/sin/cos lowerings are unreachable:
decode()delegates todisasm_rdna2.VOP1_OPS, and a repository-wide mnemonic search confirms that those decoder entries are absent. For example, the VOP1 bytes02a9027e(v_rcp_f16 v1, v2) decode asv_vop1_54and still raiseUnsupported; VOP3 uses the same table. The new fixture bypasses decoding by callingStage.one()with handwritten names, so its passing result hides this. Add the decoder mappings and binary-input coverage so these shaders can reach the new lowerings.Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:09 UTC · original
For a VOP3 NEG modifier on a literal,
disasm_rdna2prints, for example,-0x3800, but the digit check makesnegfalse andu()performs integer negation of the encoding. A decodedv_floor_f16_e64 v1, -0x3800consequently reads half0xc800(-8.0) and returns -8.0, whereas negating half0x3800means -0.5 and should return -1.0 (0xbc00). Recognize literal source modifiers separately from signed inline constants before passing the bit pattern tou().Useful? React with 👍 / 👎.
@ -2511,1 +2511,4 @@"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_operand_count_check.py")# gfx2hlsl lowers the binary16 rounding and transcendental operations (v_ceil_f16 ... v_log_f16).add_test(NAME startup_gfx2hlsl_f16_trans COMMAND "${INTAKE_PYTHON}" -B"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_f16_trans_check.py")@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:09 UTC · original
Root
AGENTS.mdrequires updating “the relevant README row ordocs/experiments.mdwhen a public capability, build requirement or reproduction command changes,” but this commit adds supported half-precision forms and a newstartup_gfx2hlsl_f16_transcheck without updating either document. Add a public experiment entry covering the supported/refused forms and exact validation command/result so contributors can discover and reproduce the new capability through the documented workflow.AGENTS.md reference: AGENTS.md:L211-L212
Useful? React with 👍 / 👎.
@ -3032,0 +3068,4 @@'v_ceil_f16': 'ceil({0})', 'v_floor_f16': 'floor({0})', 'v_trunc_f16': 'trunc({0})', 'v_rndne_f16': 'round({0})','v_fract_f16': 'min(frac({0}), 0.99951171875)', 'v_rcp_f16': '1.0 / {0}', 'v_rsq_f16': 'rsqrt({0})','v_sqrt_f16': 'sqrt({0})', 'v_sin_f16': 'sin({0} * 6.283185307)', 'v_cos_f16': 'cos({0} * 6.283185307)','v_exp_f16': 'exp2({0})', 'v_log_f16': 'log2({0})',@tedin7 on GitHub · 2026-11-25 01:02 UTC · original
Rebased on main: the decoder already maps the VOP1/VOP3 f16 transcendental opcodes there. 1bd402e7 adds machine-code tests (VOP1 and VOP3 words through decode) for all 12 operations.
AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/startup_gfx2hlsl_f16_trans_draw_check.py.
@tedin7 on GitHub · 2026-11-25 01:02 UTC · original
Fixed in 1bd402e7: -0x3800 is now read as the neg modifier on the half literal (result -0.5 path), with a machine-code test.
AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/startup_gfx2hlsl_f16_trans_draw_check.py.
@ -2511,1 +2511,4 @@"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_operand_count_check.py")# gfx2hlsl lowers the binary16 rounding and transcendental operations (v_ceil_f16 ... v_log_f16).add_test(NAME startup_gfx2hlsl_f16_trans COMMAND "${INTAKE_PYTHON}" -B"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_f16_trans_check.py")@tedin7 on GitHub · 2026-11-25 01:02 UTC · original
Fixed in 1bd402e7: new docs/experiments.md section lists supported/refused forms, the ctest command and the WARP result.
AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_f16_trans_check.py (0 failed), python3 -B tests/startup_gfx2hlsl_f16_trans_draw_check.py.
@thepatrickworld on GitHub · 2026-11-25 01:39 UTC · original
Independent run on AMD, and the ISA's printed examples
Their check passes here:
startup_gfx2hlsl_f16_trans_draw_check.py draw <dxc> <offscreen_check> hardware <fxc>exits 0 on an RX 9070 XT (driver 32.0.32029.2010), head1bd402e7. So the positive half of this PR holds on a third adapter and both compilers.What it does not reach is the set of literal cases the ISA prints for these instructions.
INPUTSkeepssin/cosbetween -0.35 and 1.1,expwithin ±10, and no operand is-0.0; the docstring says the inputs are chosen so that a binary32 intermediate and an exact one agree, which is exactly the property that stops the draw from seeing a divergence. I ran the printed pairs through the same fixture, with the expected words taken from the guide rather than from the model.v_fract_f16,-0.0001(0x868e).D.f16 = S0.f16 + -floor(S0.f16)gives0.9999, which rounds to1.0(0x3c00). The translation returns0x3bff, on both adapters and both compilers. The difference comes from themin(..., 0.99951171875)cap, andcontrols()states that cap as an expectation (fract stops below one) while the draw compares it against a lowering that applies the same cap, so no run of this fixture can report on it. If the cap is deliberate — the binary32 form in this translator caps too — then it is a deviation from the printed formula and should be called one where it is written, instead of being asserted as if measured.Sign of zero,
v_sin_f16andv_fract_f16. For-0.0the guide prints0x8000for both. On the card, under fxc and dxc,sinreturns0x0000andfractreturns0x0000. WARP returns0x8000forsin. This is a sign-of-zero difference rather than a magnitude one, but it is a difference, and it is the one place where a translated shader and the guide disagree on a value that is not a NaN.v_sqrt_f16(-0.0)under FXC. The guide prints0x8000. FXC returns0x8001, a binary16 denormal, on hardware and on WARP; DXC returns0x8000on the same adapter with the same translated source. Same shader, two compilers, two words. That is a property of FXC'ssqrtsequence rather than of this lowering, but it means the two compiler paths of this check do not agree on the one input whose expected result is exactly representable.For completeness, the other WARP differences I saw are NaN payloads —
0xffffwhere the guide prints0xfe00— which is a payload question, not a value one, and I do not read them as defects.Suggestion. Add the guide's printed pairs as a small control block. They cost nothing, they come from outside the lowering, and they would have caught the three cases above before the review did. Where a case is accepted as-is, saying why in the check keeps the next reader from re-deriving it.
AI-assisted; runs executed on the machine above.
@tedin7 on GitHub · 2026-11-25 10:55 UTC · original
@thepatrickworld thank you for the AMD run and for the printed-case comparison. Pushed
20fd34f4(docs and a comment only, no lowering change).v_fract_f16(-0.0001): themin(..., 0.99951171875)cap is deliberate and follows the binary32 form of this translator, so it differs from the printedS0 + -floor(S0)(which rounds to 1.0).docs/experiments.mdand thefract stops below onecheck now say it is a lowering choice, not a measurement.v_sin_f16/v_fract_f16andv_sqrt_f16(-0.0)(FXC0x8001, DXC0x8000): the draw inputs avoid these on purpose, so they are not covered. The docs now list them as uncovered instead of implying coverage. Adding the guide's printed pairs as a control block is a fair follow-up and is not in this PR.AI-assisted; commands listed were executed locally:
python3 -B tests/startup_gfx2hlsl_f16_trans_check.py(0 failed),python3 -B tests/docs_links_check.py(419 links),git diff --check.@ -3032,0 +3068,4 @@'v_ceil_f16': 'ceil({0})', 'v_floor_f16': 'floor({0})', 'v_trunc_f16': 'trunc({0})', 'v_rndne_f16': 'round({0})','v_fract_f16': 'min(frac({0}), 0.99951171875)', 'v_rcp_f16': '1.0 / {0}', 'v_rsq_f16': 'rsqrt({0})','v_sqrt_f16': 'sqrt({0})', 'v_sin_f16': 'sin({0} * 6.283185307)', 'v_cos_f16': 'cos({0} * 6.283185307)','v_exp_f16': 'exp2({0})', 'v_log_f16': 'log2({0})',@tedin7 on GitHub · 2026-11-25 11:01 UTC · original
Re-checked on current head
20fd34f4: the f16 transcendental opcodes are registered and decoded, literal negation is handled, and docs are updated. Resolving. AI-assisted; commands listed were executed locally.@Makto94 on GitHub · 2026-11-25 11:24 UTC · original
First hardware run on
20fd34f4(NVIDIA). The only other hardware run in this thread is thepatrickworld's AMD run (RX 9070 XT), which was on1bd402e7..\tools\dev.ps1; ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_f16_trans_draw_hardware$' -Vpasses. The log has 36fxclines and 36dxclines, 3 for each of the 12 ops (v_ceil_f16,v_cos_f16,v_exp_f16,v_floor_f16,v_fract_f16,v_log_f16,v_rcp_f16,v_rndne_f16,v_rsq_f16,v_sin_f16,v_sqrt_f16,v_trunc_f16). All 72debug_errors=lines readdebug_errors=0, and there were 0 capability skips (77).CPU, control and WARP tests (
startup_gfx2hlsl_f16_trans,_draw_controls,_draw_warp):100% tests passed, 0 tests failed out of 3.Environment: NVIDIA GeForce RTX 3070 Ti (
10de:2482), driver 32.0.16.2101, Windows 11 build 26300.9974, Debug build, fxc 10.0.26100.9457, dxc 1.9.2602.17, D3D12 debug layer enabled; the hardware run was serial on an idle machine.@tedin7 on GitHub · 2026-11-25 11:54 UTC · original
Thank you @Makto94 for the NVIDIA RTX 3070 Ti run at
20fd34f4:startup_gfx2hlsl_f16_trans_draw_hardwarepassed (36 fxc + 36 dxc lines, 12 ops), CPU/controls/WARP 3/3. Recorded as extra evidence for this PR.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-25 13:52 UTC · original
Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.
We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.
AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:09 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
48dbc9bde3ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Pull request closed