Repository navigation
startup: accept output modifiers on float-result conversions - #1707
Conversation
Fixes R0Y00#1705. The float-result conversions were in the uint-result table, whose dispatch refused every modifier before looking at the instruction, so v_cvt_f32_i32_e64 v1, v1 mul:2 did not translate - 5 of the 29 refused shaders in the loading-screen cache (R0Y00#870). They now have their own table and go through the float path, accepting exactly clamp, mul:2, mul:4 and div:2; without a modifier the emitted text is unchanged. op_sel and source modifiers stay refused on a conversion, and uint-result conversions keep refusing output modifiers. Test builds VOP1-as-VOP3 encodings from the decoder layout, decodes, then translates; both presets pass; fail-first removes the dispatch and the test fails.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ceccbcaece
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
tedin7
left a comment
There was a problem hiding this comment.
Review of head ceccbcaece12b41f03938379d28b5e24906a7e5a. Verdict: 0 P1, 1 P2 (clamp together with an output modifier), plus test gaps.
Linux limits. Linux x86_64, llvm-mc-19, Python 3.14. No Windows, no DXC, no GPU. Python-level translation only; nothing was compiled to DXIL or drawn.
What I ran
python3 -B tests/startup_gfx2hlsl_vcvt_omod_check.py: PASS.git diff --check,docs_links_check,bidi_controls_check: clean.llvm-mc-19 -mcpu=gfx1030assembledv_cvt_f32_i32_e64 ... mul:2 / clamp / clamp mul:2,v_cvt_f32_u32_e64 mul:2,v_cvt_f32_f16_e64 mul:2,v_cvt_f32_ubyte1_e64 div:2,v_cvt_f16_f32_e64 mul:2. The opcodes (0x185, 0x186, 0x18b, 0x18a) and omod bits (mul:2 = 1, div:2 = 3) match the bytes the PR'sencode_vop1_e64builds, so the constructed fixtures are real encodings.- Mutations on
tools/startup/gfx2hlsl.py(restored withgit checkout -- .):v_cvt_f32_f16textf16tof32({0})->f16tof32({0} >> 16): FAILED, as intended.v_cvt_f32_ubyte1shift 8 -> 16: PASSED, not caught.v_cvt_f32_ubyte3shift 24 -> 16: PASSED, not caught.- the modifier whitelist
if any(m not in (...))replaced byif False: PASSED, not caught (anop_selwould then fall intoset_vf, which silently ignores it). v_cvt_f32_u32lowered asfloat(int(x))(signed): PASSED, not caught.
P2: clamp with an output modifier is applied in the wrong order. For v_cvt_f32_i32_e64 v1, v1 clamp mul:2 the translator emits v1 = U((saturate(float(int(v1)))) * 2.0); (and * 0.5 for div:2), i.e. clamp first, then scale. As I read the RDNA 2 ISA reference, the output modifier scales the result first and clamp saturates after it, so this should be saturate((float(int(v1))) * 2.0). For an input of 1 the hardware gives 1.0 and this lowering gives 2.0. The order comes from Stage.set_vf, which walks the modifiers in the order the decoder prints them (clamp mul:2); that is pre-existing for the VEC_F operations, but this PR is what makes the combination reachable for the seven conversions, and no case in the new test combines the two. Suggest applying omod first, then clamp, in set_vf, with a case for clamp mul:2 and clamp div:2.
Test gaps (not blocking)
v_cvt_f32_ubyte0..3have no case, so a wrong shift or mask there is not detected;v_cvt_f32_u32is checked only for the* 2.0wrapper, not its text.- The whitelist is exercised only by the uint-result refusal and a source negation (which is refused earlier as
Unsupported operand '-v1'); no case passesop_selor another modifier to a float-result conversion, so dropping the guard goes unnoticed. - The docs say issue #1705, the test docstring says #1696; the test file ends without a final newline.
Not approving (comment only).
AI-assisted; commands listed were executed locally.
Review on R0Y00#1707: the two were applied in the order the disassembler prints them, which is clamp first, so a conversion with both scaled the saturated result. The hardware applies the output modifier first and clamps the result. set_vf now accumulates the scale, applies it, then saturates; single-modifier output is byte-identical to before (2.0/4.0/0.5). The test adds the two combined cases and fails if the order is swapped back.
|
Correct — fixed in The order was following the disassembler's text, which prints Single-modifier output is byte-identical to before ( The test adds the two combined cases; swapping the blocks back fails it: All 7 AI-assisted (Claude Code). |
tedin7
left a comment
There was a problem hiding this comment.
Review of head d7346d7 (comment only, not an approval).
Verdict: 1 P1, 1 P2. Update: the head moved from ceccbca to d7346d7 ("apply the output modifier before the clamp") while I was reviewing. That commit changes only set_vf() (scale first, saturate last) and one test; both findings below still hold at the new head. sdwa() still has if base not in VEC_U: (line 401), the conversions are only in VEC_U_TO_F, and set_vf() still has elif m.startswith('op_sel'): pass. The two test files pass at the new head. The SDWA reproduction and the mutation list below were run at ceccbca; I did not repeat them at the new head.
P1: the SDWA forms of the moved conversions stop translating (tools/startup/gfx2hlsl.py, sdwa() near line 392 and VEC_U_TO_F near line 1052)
- On the base,
v_cvt_f32_u32,v_cvt_f32_i32,v_cvt_f32_ubyte0..3andv_cvt_f32_f16are inVEC_U(base lines 1046-1050). This PR moves them toVEC_U_TO_F.sdwa()at line 392 only accepts names inVEC_U(if base not in VEC_U: raise Unsupported('SDWA form of ...')) and never looks at the new table. - Reproduction with a small stand-in stage, base versus head:
v_cvt_f32_u32withsrc0_sel:WORD_0,v_cvt_f32_i32withsrc0_sel:BYTE_0,v_cvt_f32_f16withsrc0_sel:WORD_0,v_cvt_f32_ubyte0withsrc0_sel:BYTE_1. All four translate on the base (e.g.v1 = U(float(int(((v2 >> 0u) & 0xffu))));) and all four are refused at this head withUnsupported('SDWA form of v_cvt_f32_i32')and the matching messages. - No test catches it:
startup_gfx2hlsl_sdwa_checkonly checks float SDWA is refused, andstartup_gfx2hlsl_vcvt_omod_checkhas no SDWA case. Fix: letsdwa()also acceptVEC_U_TO_F(wrapping inU(...)) and add a test that translates an SDWA conversion.
P2: the op_sel refusal is claimed but unguarded. The code comment and PR body say op_sel is refused; set_vf() ignores it silently, and the test covers only source negation (neg0=1), which is refused anyway because u() cannot parse -v1. Mutation D below confirms nothing guards it. Add refused() cases for op_sel:[1,0] and abs.
Run
python3 -B tests/startup_gfx2hlsl_vcvt_omod_check.py,startup_gfx2hlsl_sdwa_check.py,bit_alu,capture,smem_offset: pass. docs_links_check (17 files, 364 links) and bidi_controls_check: pass.- Mutations in gfx2hlsl.py (restored, green again): removing
div:2from the allowed tuple is caught;v_cvt_f32_i32text changed tofloat({0})is caught. NOT caught:v_cvt_f32_ubyte1shift 8 -> 9,v_cvt_f32_ubyte3shift 24 -> 23,v_cvt_f32_u32->float(int({0})), and replacing the modifier check withif False:(the P2).
Non-blocking
- The test docstring says "issue #1696"; the issue is #1705 and #1696 is an unrelated PR.
- The test never exercises
v_cvt_f32_ubyte0..3,_e32spellings, orclampcombined withmul, and builds words from the decoder's own layout. - tests/startup_gfx2hlsl_vcvt_omod_check.py has no trailing newline.
- #1703, #1706 and #1708 touch
VEC_Uonly in docs and tests; #1708's conversion draw test may need updating after this merges.
Not run: ctest, the DXC/FXC/D3D12 draw tests, the PR's release numbers and the census figures.
Linux limits: no Windows, MSVC, DXC or D3D12 device here; LLVM 19 only. Anything that needs them was not run.
AI-assisted; commands listed were executed locally.
|
Independently verified d7346d7 with a source-built flat-parameter pixel draw for v_cvt_f32_f16 clamp div:2. FXC and DXC both produced 3f800000,3f000000,00000000,3e000000 from half inputs 2, 1, -2, 0.25 on RTX 4060 Laptop (32.0.16.1656) and WARP (10.0.26100.9818). A clamp-before-scale mutation read 3f000000 in the first lane on all four runs and failed the comparison. The debug layer was enabled with zero errors and warnings. Please keep the #1708 draw coverage separate; its old blanket refusal for this float-result modifier will need to be adjusted once this lands. |
|
Thanks — the P1 is real and it is a regression I introduced, so it gets a follow-up rather than a note: #1730.
The test builds the SDWA encodings ( Your P2 ( I should have run AI-assisted (Claude Code). |
Regression from #1707, found in review by tedin7 after the merge (P1): moving the float-result conversions into VEC_U_TO_F left sdwa() looking only at VEC_U, so every v_cvt_f32_*_sdwa was refused with 'SDWA form of <name>'. sdwa() now accepts both tables and wraps a float result in U(...) before the destination selection writes its bit pattern; integer-result conversions keep the uint path unchanged. Test builds VOP1 SDWA encodings (SRC0=249 marks SDWA, control word in the next dword), decodes, then translates: u32/i32/f16 conversions, DWORD and BYTE selections, dst_sel masking and UNUSED_PRESERVE, the unchanged uint path, and an omod still refused. Fail-first removing the new branch fails the test. Both presets pass, all 9 startup_gfx2hlsl tests pass.
Brings R0Y00#1707 (output modifiers on float conversions, VEC_U_TO_F), R0Y00#1716 (operand-count guard), R0Y00#1697 (triage slot-133 counts) and test/tool PRs. Conflict: gfx2hlsl.py set_vf, took upstream's combined scale-then-clamp (same result as the local comment described). Semantic fixes: the local op_v_cvt_f16_f32 handler bypasses VEC_U, so it now applies R0Y00#1716's operand-count rule itself; the local coverage check expects R0Y00#1707's U((float(int(v0))) * 2.0) form for v_cvt_f32_i32 mul:2.
…0Y00#1707 moved them out of VEC_U) R0Y00#1707 (startup/vcvt-omod, in the integration branch) moved v_cvt_f32_{u32,i32,ubyte0..3,f16} from VEC_U to VEC_U_TO_F so output modifiers apply. sdwa() only looks in VEC_U, so every SDWA form of those conversions became "SDWA form of v_cvt_f32_u32". On the live request corpus that turned 391 of the 1164 published translations (and 711 requests in all) into refusals at the integration tip. sdwa() now takes them from VEC_U_TO_F with the old bit expression, U(<float expression>), so the output is byte-identical to before R0Y00#1707. SDWA output modifiers stay refused as before. tests/startup_sdwa_cvt_check.py: synthetic VOP1 SDWA words; passes on the pre-merge translator and on this commit, fails on the integration tip 0fde543.
Fixes #1705. Third group from the loading-screen refusal census (#870): 5 of 29 shaders.
Change
The float-result conversions sat in the uint-result table, whose dispatch refused every modifier before looking at the instruction, so
v_cvt_f32_i32_e64 v1, v1 mul:2did not translate even thoughset_vf()already implements those modifiers.They are now their own table (
VEC_U_TO_F) holding the float expression, dispatched through the float path:Boundaries kept: only
clamp,mul:2,mul:4,div:2are accepted —op_seland source modifiers are refused rather than silently ignored (which would change the operand), and a uint-result conversion (v_cvt_f16_f32) keeps refusing output modifiers.Test
startup_gfx2hlsl_vcvt_omodbuilds VOP1-as-VOP3 encodings from the checked-in decoder's layout (0b110101prefix, opcode0x180 + n, omodw1[28:27], clampw0[15], negw1[31:29]), decodes them, then translates — no game-derived bytes.Fail-first: removing the
VEC_U_TO_Fdispatch fails the test withUnsupported: v_cvt_f32_i32.Census A/B (local, aggregates only)
With the change, refusals grouped as
v_cvt_f32_i32go 16 → 0 in the annotated re-run, and the affected shaders now progress to the next refusal in their stream —export target mrtz,v_cvt_f32_u32_sdwa, negative operands, and the exportoffform that #1674 tracks. That is forward motion, not new failures: every group that appears after the change is one the shader previously never reached.What this does not establish
op_sel/abs/negon conversions stay refused, and the SDWA variants of these conversions are their own slice.AI-assisted (Claude Code).