Skip to content

startup: accept output modifiers on float-result conversions - #1707

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
triggered02:startup/vcvt-omod
Nov 24, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
triggered02:startup/vcvt-omod

Conversation

@triggered02

Copy link
Copy Markdown
Contributor

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:2 did not translate even though set_vf() already implements those modifiers.

They are now their own table (VEC_U_TO_F) holding the float expression, dispatched through the float path:

v_cvt_f32_i32_e64 v1, v1          -> v1 = U(float(int(v1)));            (unchanged)
v_cvt_f32_i32_e64 v1, v1 mul:2    -> v1 = U((float(int(v1))) * 2.0);
v_cvt_f32_i32_e64 v1, v1 mul:4    -> U(... * 4.0)
v_cvt_f32_i32_e64 v1, v1 div:2    -> U(... * 0.5)
v_cvt_f32_i32_e64 v1, v1 clamp    -> U(saturate(float(int(v1))))

Boundaries kept: only clamp, mul:2, mul:4, div:2 are accepted — op_sel and 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_omod builds VOP1-as-VOP3 encodings from the checked-in decoder's layout (0b110101 prefix, opcode 0x180 + n, omod w1[28:27], clamp w0[15], neg w1[31:29]), decodes them, then translates — no game-derived bytes.

dev:     startup_gfx2hlsl_vcvt_omod Passed 0.14 s; all 7 startup_gfx2hlsl tests pass
release: startup_gfx2hlsl_vcvt_omod Passed 0.14 s

Fail-first: removing the VEC_U_TO_F dispatch fails the test with Unsupported: v_cvt_f32_i32.

Census A/B (local, aggregates only)

With the change, refusals grouped as v_cvt_f32_i32 go 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 export off form 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

  • That the loading screen gets further — needs a run that visibly reaches it; the counts above are local aggregates.
  • op_sel/abs/neg on conversions stay refused, and the SDWA variants of these conversions are their own slice.

AI-assisted (Claude Code).

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T17:33:44.812955Z ceccbca PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread tools/startup/gfx2hlsl.py Resolved

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=gfx1030 assembled v_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's encode_vop1_e64 builds, so the constructed fixtures are real encodings.
  • Mutations on tools/startup/gfx2hlsl.py (restored with git checkout -- .):
    • v_cvt_f32_f16 text f16tof32({0}) -> f16tof32({0} >> 16): FAILED, as intended.
    • v_cvt_f32_ubyte1 shift 8 -> 16: PASSED, not caught.
    • v_cvt_f32_ubyte3 shift 24 -> 16: PASSED, not caught.
    • the modifier whitelist if any(m not in (...)) replaced by if False: PASSED, not caught (an op_sel would then fall into set_vf, which silently ignores it).
    • v_cvt_f32_u32 lowered as float(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..3 have no case, so a wrong shift or mask there is not detected; v_cvt_f32_u32 is checked only for the * 2.0 wrapper, 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 passes op_sel or 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.
@triggered02

Copy link
Copy Markdown
Contributor Author

Correct — fixed in d7346d7e.

The order was following the disassembler's text, which prints clamp before the omod, so set_vf() saturated and then multiplied. It now accumulates the scale, applies it, and saturates last:

v_cvt_f32_i32_e64 v1, v1 clamp mul:2   -> U(saturate((float(int(v1))) * 2.0))     (was: U(saturate(float(int(v1))) * 2.0))
v_cvt_f32_i32_e64 v1, v1 clamp div:2   -> U(saturate((float(int(v1))) * 0.5))

Single-modifier output is byte-identical to before (* 2.0, * 4.0, * 0.5), so this does not change the cases the PR already covered. The helper is shared by the other float operations, so a VOP3 float op carrying both modifiers was getting the same wrong order before this — that path is now correct too, not just conversions.

The test adds the two combined cases; swapping the blocks back fails it:

fail-first exit: 1 | clamp applies after the halving

All 7 startup_gfx2hlsl tests pass in dev and the new test passes in release. Thanks for catching it — the allow-list was the visible change but the operation order was the thing that would have silently disagreed with the hardware.

AI-assisted (Claude Code).

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..3 and v_cvt_f32_f16 are in VEC_U (base lines 1046-1050). This PR moves them to VEC_U_TO_F. sdwa() at line 392 only accepts names in VEC_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_u32 with src0_sel:WORD_0, v_cvt_f32_i32 with src0_sel:BYTE_0, v_cvt_f32_f16 with src0_sel:WORD_0, v_cvt_f32_ubyte0 with src0_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 with Unsupported('SDWA form of v_cvt_f32_i32') and the matching messages.
  • No test catches it: startup_gfx2hlsl_sdwa_check only checks float SDWA is refused, and startup_gfx2hlsl_vcvt_omod_check has no SDWA case. Fix: let sdwa() also accept VEC_U_TO_F (wrapping in U(...)) 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:2 from the allowed tuple is caught; v_cvt_f32_i32 text changed to float({0}) is caught. NOT caught: v_cvt_f32_ubyte1 shift 8 -> 9, v_cvt_f32_ubyte3 shift 24 -> 23, v_cvt_f32_u32 -> float(int({0})), and replacing the modifier check with if 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, _e32 spellings, or clamp combined with mul, 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_U only 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.

@R0Y00

R0Y00 commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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.

@triggered02

Copy link
Copy Markdown
Contributor Author

Thanks — the P1 is real and it is a regression I introduced, so it gets a follow-up rather than a note: #1730.

sdwa() now accepts VEC_U_TO_F as well, wrapping the float result in U(...) before the destination selection writes its bit pattern, so the four forms you reproduced translate again:

v_cvt_f32_u32_sdwa v0, v1 src0_sel:WORD_0 -> v0 = U(float(((v1 >> 0u) & 0xffffu)));
v_cvt_f32_i32_sdwa v0, v1 src0_sel:BYTE_0 -> v0 = U(float(int(((v1 >> 0u) & 0xffu))));

The test builds the SDWA encodings (SRC0 = 249 marks the form, control word in the next dword) and decodes them before translating, covers the destination selections and UNUSED_PRESERVE, keeps the uint-result conversion on the uint path, and fails if the new branch is removed. All 9 startup_gfx2hlsl tests pass in dev and the new one in release.

Your P2 (op_sel claimed refused but silently ignored by set_vf) is not bundled into that fix: making set_vf raise touches every float path that uses it, so it needs a sweep of the existing tests rather than a ride-along on a regression fix. It is queued as its own slice, along with the unexercised v_cvt_f32_ubyte* shifts you noted.

I should have run startup_gfx2hlsl_sdwa_check against the change rather than only the new test — the SDWA path was exactly the caller I did not check.

AI-assisted (Claude Code).

R0Y00 pushed a commit that referenced this pull request Nov 24, 2026
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.
denn0x added a commit to denn0x/Xbox2Windows that referenced this pull request Nov 25, 2026
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.
denn0x added a commit to denn0x/Xbox2Windows that referenced this pull request Nov 25, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

startup: float-result conversions refuse output modifiers (5 of 29 loading-screen shader refusals)

3 participants