Skip to content

shader: lower half conversions and three CMPX compares in the mesh frontend (Part of #2413) - #3666

Open
Kawiu wants to merge 1 commit into
R0Y00:mainfrom
Kawiu:shader/mesh-half-cvt-cmpx
Open

Kawiu wants to merge 1 commit into
R0Y00:mainfrom
Kawiu:shader/mesh-half-cvt-cmpx

Conversation

@Kawiu

@Kawiu Kawiu commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Change

The native mesh frontend (lower_mesh, src/gfx1013_direct_mesh.inl) now accepts four more forms:

  • v_cvt_f16_f32, v_cvt_f32_f16. Both go through the shared DirectCompute::arithmetic path, the same float_alu lowering the compute and graphics paths use. The narrowing form rounds to nearest even into the low word and keeps the destination's high word. The widening form uses legacyF16ToF32. Both join the existing lane-ALU list, so the full_exec || exec_skip rule and the partial-write merge apply unchanged. They are not counted as uniform-proving sources.
  • v_cmpx_eq_i32, v_cmpx_lt_f32. Both narrow the lane mask the same way v_cmpx_eq_u32 already does: the new lane-active predicate is the parent mask AND the lane's own compare. EQ is the same bit test signed or unsigned. LT_F32 is the ordered compare (fcmp olt), false on NaN. The existing modifier refusals stay: no DPP, SDWA, abs, neg, omod or clamp.

Other compare forms are still refused by name.

Part of #2413. This change does not overlap #3635, #3645 or #3655: they touch the same allow-list line but different instructions. Merging all four locally needed a one-line conflict resolution on that list and in the test file.

Verification

Build at this branch (base d5970858), Windows 11 26300, MSVC 19.44, dev preset.

cmake --build --preset dev --target compile_dxil d3d12_xs.dll
ctest --preset dev --no-tests=error -R '^native_direct_mesh$'

Passed.

New checks in tests/native_direct_mesh_check.py, on the existing source-built triangle:

  • v_cvt_f16_f32 v1, v2: checks the RNE exponent rebias (sub i32 …, 939524096) and that the exported X is or of the half with and v1, -65536, so the high word is kept.
  • v_cvt_f32_f16 v1, v2: the exported X is the bitcast of dx.op.legacyF16ToF32(131, …).
  • For v_cmpx_eq_u32 (existing behaviour, now covered), v_cmpx_eq_i32 and v_cmpx_lt_f32, the sequence is s_mov_b64 s[22:23], exec; the compare; s_cbranch_execz over v_mov_b32 v1, 2; s_mov_b64 exec, s[22:23]. The test checks three things:
    • the lane predicate (icmp eq i32 0, … or fcmp olt float …) is the br condition of the work block;
    • the write is select i1 <predicate>, i32 2, i32 <old v1>;
    • the join phi takes the old value from the empty edge and feeds the exported X.
  • Control: v_cmpx_le_f32 in the same sequence is still refused with unsupported mesh instruction or EXEC state: v_cmpx_le_f32.
  • Fail-first: with the source change reverted and the tests kept, native_direct_mesh fails at the first new case with unsupported mesh instruction or EXEC state: v_cvt_f16_f32. With the change restored, it passes again.

Broader run, WARP only:

ctest --preset dev --no-tests=error -R mesh -E hardware -j 6 --timeout 300

116 of 119 passed. mesh_two_exits_warp is a capability skip. Three tests did not run because their executables were not built:

  • meshlet_builder and startup_pipeline_state_mesh_shift_control passed after building meshlet_builder_check and startup_pipeline_state_check;
  • xmem_section_lease_mesh_warp (xmem shim, not touched here) was not run.

Hardware variants were not run. No draw test exercises the new forms; the checks are on DXIL text.

Local note. On this host, the dev-preset link of offscreen_check fails with LNK1104: cannot open file 'offscreen_check.exe', also under another output name. It links with /INCREMENTAL:NO. I linked it that way locally to run the draw tests above. That is a separate issue and not part of this change.

Evidence and follow-up

Local capture census, counts only.

  • Input: 392 captured slot 57 requests.
  • Command: compile_dxil --refusals <dir> --mesh-layout <generic layout>, with the layout mesh1 128 128 128 2 128 64 + validate_uint_heap_reads + guest_root.
Build Requests stopping at the four forms Complete translations
main, no opt-in v_cvt_f16_f32 7, v_cmpx_eq_i32 4, v_cmpx_lt_f32 2 —
main + #3635 + #3645 + #3655, X2W_MESH57_PARTIAL_ZERO=1 10, 7 and 6 127
Same build with this change none 127 (no change)

With this change the moved requests stop later. The most common next refusals are:

  • unsupported mesh instruction or EXEC state: s_mov_b64 (10): s_mov_b64 vcc, exec copies the narrowed mask before an if/else, which re-narrows with s_and_b64 exec, vcc, exec after the else arm;
  • mesh SAVEEXEC else arm lacks the saved-mask inverse (7).

That if/else shape is next to the SAVEEXEC diamond work in #3645/#3646, so I have not started on it.

Fixtures. The fixtures are hand-encoded gfx1013 words, written in this PR from the RDNA2 encoding. The VOP1 and VOPC opcodes were cross-checked with the project's decoder (gfx2hlsl.decode).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (No capability or build requirement changed.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

…ontend

v_cvt_f16_f32 and v_cvt_f32_f16 reuse the shared ALU (RNE rounding into
the low word with the high word kept, and legacyF16ToF32). v_cmpx_eq_i32
and v_cmpx_lt_f32 narrow the lane mask like v_cmpx_eq_u32: EQ is the same
bit test signed or unsigned, and LT_F32 is ordered.

Part of R0Y00#2413.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed bd95dc4c by reading the diff; not built or run.

Verdict: approve. Both conversions and the two compares go through the existing shared lowerings, and the new names inherit the existing modifier refusals. No MUST. It needs a rebase: it conflicts with main a3bfd019 in src/gfx1013_direct_mesh.inl and the test file, on the allow-list line #3635/#3655 also changed, as the PR body says.

  • NIT The v-cmpx-lt-f32 check accepts fcmp olt float %a, %b in either operand order (tests/native_direct_mesh_check.py, the narrowed loop). LT is the only asymmetric form here. If the lowering swapped src0 and vsrc1, the check would still pass. Pinning the first operand to the value built from the inline 0 would catch that.
  • Checked, no finding:
    • Compares: alu.comparison(i) (src/gfx1013_direct_compute.inl:3336) reads src0 then src1 and gives fcmp olt for lt_f32. The mesh branch still refuses DPP, SDWA, abs, neg, omod and clamp, and inside a diamond. v_cmpx_eq_i32 gives the same icmp eq as eq_u32.
    • Conversions: in the lane-ALU list, so partial-EXEC writes merge as before. Keeping v1's high word in v_cvt_f16_f32 matches gfx10, where 16-bit VALU results do not zero bits 31:16.
    • Test words decode as named: VOPC 0x11 v_cmpx_lt_f32, 0x13 le_f32, 0x92 eq_i32, 0xd2 eq_u32 (src0 = inline 0, vsrc1 = v1); VOP1 0x0a / 0x0b with v1 ← v2.

Tests: the new checks reach both changed lines: the CMPX name test (three compares, with the select and phi on the narrowed lane) and the two conversions in the ALU list. v_cmpx_le_f32 is the negative control. The CI run at this head (22:24 UTC) came before #3644 put native_direct_mesh into the pr filter, so only your local run covers them so far. The rebase will rerun CI with it.

@Leyukaka

Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Friendly note: this is approved, but it currently conflicts with main after the recent merges; a rebase should be all this small change needs.

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.

3 participants