startup: lower v_cvt_pknorm_u16_f32 in gfx2hlsl #1946
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!1946
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1946/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-24 21:58 UTC · original
tedin7:x2w-frontier-gfx-pknorm16→main· +209 −0 · 6 files · 6 commits · closed without mergingPart of #870 (no
Fixes). Draft.What
Lowers
v_cvt_pknorm_u16_f32intools/startup/gfx2hlsl.py. It was refused as unsupported, which stops the pair behind #1710.The instruction is VOP3 only (opcode 0x369, no e32 form). Per the public RDNA ISA description:
Lowering:
uint(round(saturate(a) * 65535.0)) | (uint(round(saturate(b) * 65535.0)) << 16).Source neg and abs reach the operands. Any output modifier (clamp, mul, div) or op_sel is refused, because it would change the packed words. This matches the refusal style of #1755 and #1778 without depending on them. No other open PR implements this instruction.
Change
op_v_cvt_pknorm_u16_f32method (the dispatch finds it by name, so no table row). Placed away from the hunks of #1755.tests/startup_gfx2hlsl_pknorm_u16_check.pyon the shared lane runner, registered inCMakeLists.txtand.github/workflows/windows.yml.Test
llvm-mc, words recorded (checked with llvm-mc-19 for gfx1010 and gfx1030, same 0x369 VOP3 word; CI uses llvm-mc-15 in binary mode).The reference rounds the binary32 product. For 1.5/65535 that product is exactly 1.5 and ties to 2, while the exact value of the nearest binary32 input is just under 1.5. No hardware run of this instruction was available, so the draw mode is what confirms it.
Commands executed locally
python3 -B tests/startup_gfx2hlsl_pknorm_u16_check.pyand... binary llvm-mc-19: okllvm-mc-19 -mcpu=gfx1010andgfx1030encodings of the instruction, plain, with neg/abs and with clampgit diff --check,tests/docs_links_check.py,tests/bidi_controls_check.py: passgit merge-treeagainstorigin/main, #1796, #1798, #1778, #1755, #1750: no conflicts. #1783 and #1747 conflict with main already (same counts as without this branch).AI-assisted; commands listed were executed locally.
Replaces closed draft #1815 (rebased cleanly on origin/main).
AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 22:04 UTC · original · edited 2026-11-24 22:08 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
1777b62ℹ️ 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.
@ChazY11 on GitHub · 2026-11-24 22:07 UTC · original
Ran it, broke it four ways, and cross-checked the reference model independently
Windows 11 build 26300.9974, device-free:
Mutations to the lowering, each reverted:
* 65535.0→* 65536.0round(...)→ truncationS0in bits 31:16)saturate(...)droppedThat is the set I would have written by hand, and each one fails a different rule the description states. Two of them — the
truncation and the off-by-one scale — are the mistakes this instruction invites.
The reference model agrees with an independent implementation
Their
unorm16()rounds a binary32 product (to_f32(x * 65535.0)) before taking the integer, which is the part that iseasy to get subtly wrong. I wrote the rule from the ISA text independently — clamp, binary32 product, round half to even, NaN
reads 0 — and compared over 200,012 words (12 chosen:
±0,±1, quiet NaN,±inf,0.5, the two neighbours of0.5,1.5,denormal minimum; plus 200,000 random 32-bit patterns):
So the model the fixture compares against is not just internally consistent, it matches the rule the description quotes. Your
comment at lines 13–14 about the product being exactly 1.5 and tying to 2 is the kind of thing that usually only shows up when
someone re-derives it — I re-derived it and got your answer.
What this still does not establish
The NaN rule is modelled as
saturate(NaN) == 0, which is D3D's documentedsaturatebehaviour, andround()is modelled ashalf-to-even, which is HLSL's. Both rest on the backend honouring those, not on anything measured here — your draft status says
as much, and the draw is presumably what closes it. I did not run DXC or WARP for this.
Small note
half = 'uint(round(saturate(%s) * 65535.0))'is applied throughself.f(...), soneg/absreach the source before theclamp — which the fixture checks. Nothing to change; mentioning it because the ordering is exactly what a later reader will ask
about when a
-v0case looks odd.Verdict
Reviewed. Every rule in the description is pinned by a mutation, and the reference matches the ISA text under an independent
implementation. Good to go once the draw lands.
Notes
@ -1084,6 +1084,17 @@ class Stage:except ValueError:return Nonedef op_v_cvt_pknorm_u16_f32(self, ops, mods):@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 22:08 UTC · original
v_cvt_pknorm_u16_f32now changes from anUnsupportedresult to emitted HLSL, but the commit updates neitherREADME.mdnordocs/experiments.md. This misses the explicitAGENTS.mdrequirement to “Update the relevant README row ordocs/experiments.mdwhen a public capability, build requirement or reproduction command changes.” Document the startup-specific support, refused modifiers, and new reproduction commands/results, distinguishing the completed Python/LLVM checks from the unverified Windows draw behavior, so contributors can discover and reproduce the added capability.AGENTS.md reference: AGENTS.md:L204-L205
Useful? React with 👍 / 👎.
@Makto94 on GitHub · 2026-11-24 23:56 UTC · original
Ran the draw fixtures on WARP and on a physical GPU, in addition to the device-less run and mutations reported above. Head
1777b62d(PR still open), Debug build, Windows 11 build 26300, D3D12 debug layer enabled.startup_gfx2hlsl_pknorm_u16_controls: passed.startup_gfx2hlsl_pknorm_u16_warp(Microsoft Basic Render Driver, driver 10.0.26100.9818): passed.startup_gfx2hlsl_pknorm_u16_hardware(NVIDIA GeForce RTX 3070 Ti, driver 32.0.16.2101): passed.debug_errors=0 debug_warnings=0in every section of both draw runs.@ -1084,6 +1084,17 @@ class Stage:except ValueError:return Nonedef op_v_cvt_pknorm_u16_f32(self, ops, mods):@tedin7 on GitHub · 2026-11-25 00:53 UTC · original
Documented in docs/experiments.md (section on v_cvt_pknorm_u16_f32 in the startup translator): refused modifiers, reproduction commands, and which checks ran (Python/LLVM) versus not yet run on Windows (WARP/GPU draw). Fix in e302e2dd on the rebased branch.
AI-assisted; commands listed were executed locally.
@ -1084,6 +1084,17 @@ class Stage:except ValueError:return Nonedef op_v_cvt_pknorm_u16_f32(self, ops, mods):@tedin7 on GitHub · 2026-11-25 11:01 UTC · original
Re-checked on current head
e0bccd7d: thev_cvt_pknorm_u16_f32section is in docs/experiments.md (added ine0bccd7d). Resolving. AI-assisted; commands listed were executed locally.@tedin7 on GitHub · 2026-11-25 11:54 UTC · original
Thank you @ChazY11 and @Makto94 for the independent runs: the device-free checks with the four lowering mutations caught, and the WARP + NVIDIA RTX 3070 Ti draw fixtures at
1777b62d(3/3 passed, 0 debug errors/warnings). Recorded as extra evidence for this PR.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-25 13:51 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-24 22:08 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
1777b62d24ℹ️ 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