Skip to content

shader: lower v_and_or_b32 and v_cvt_f16_f32 in the mesh frontend - #3743

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
lambirou:codex/mesh-vector-alu
Dec 2, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
lambirou:codex/mesh-vector-alu

Conversation

@lambirou

@lambirou lambirou commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

After the scalar bit operations, the forced slot 86 mesh path still refused
v_cvt_f16_f32 in 357 requests and v_and_or_b32 in 331, ahead of the
control-flow, heap-provenance and pixel blocks.

v_and_or_b32 (VOP3 0x371) joins the mesh vector list that already handles
v_or3_b32 and v_add3_u32, so it takes the three-source
alu_rules entry and lowers to (S0 & S1) | S2. The shared operand gate
still refuses abs, neg, clamp and omod. v_cvt_f16_f32 (VOP1 0x0A) joins
the same list and reuses the compute frontend's integer round-to-nearest-even
narrowing: the sign comes from bit 31, binary32 subnormals become signed
zeros, binary16 subnormals are kept, overflow including the 65520 tie gives
0x7c00, and a NaN keeps its quiet bit. The encoding goes into the low half
and the reaching destination value keeps the high half, so an unproven
destination still refuses and the merged word is not declared uniform.

Validation (Windows, Release; AMD Radeon RX 9060 XT for the hardware run):

  • cmake --build --preset release --target compile_dxil — 7/7 steps.
  • python -B tests/native_direct_mesh_check.py out\\build\\release\\compile_dxil.exe "<DXC dir>"
    — pass, including the v_and_or_b32 and v_cvt_f16_f32 programs and the
    unbound/unproven-source controls.
  • ctest --preset release --no-tests=error -R '^native_direct' — 2/2 pass.

Refs #3703

@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 baa40780 by reading the diff; not built or run.

Verdict: approve. Both ops join the mesh VALU list and lower through the shared ALU, with uniformity handled correctly. No MUST.

  • Overlap with #3666. #3666 (Kawiu, open) also adds v_cvt_f16_f32 to this list. It goes through the same shared narrowing (gfx1013_direct_compute.inl:2102), so the behaviour is identical and only the list entry is duplicated. Whichever lands second can drop its entry on rebase. v_and_or_b32 here, and v_cvt_f32_f16 plus the two CMPX forms in #3666, are not duplicated. For context: on main + #3760, six slot 86 programs from our own capture now stop first at v_cvt_f16_f32, so either PR clears that wall for them.
  • Rebase. The branch is on e1161e43, and only tests/native_direct_mesh_check.py conflicts with main 158ef794, where both sides appended cases. The source hunk merges cleanly.
  • Checked, no finding:
    • Source counts. v_and_or_b32 has an alu_rules entry of arity 3, so a result is uniform only when all three sources are. v_cvt_f16_f32 has no rule and is not in the hard-coded arity lists, so sources is 0 and the merged word is never declared uniform. That matches the new comment, since the high half comes from the destination.
    • Modifiers. Abs, neg, clamp and omod still go through the shared operand gate, so they refuse as before.

Tests:

  • v-and-or-b32 traces (S0 & S1) | S2 to the export, and -unproven refuses an unbound source.
  • The v_cvt_f16_f32 cases match the NaN/infinity select chain of the narrowing and export the low half.
  • -unproven-source and -unproven-destination pin both refusals. The second covers the kept high half.

CI ran native_direct_mesh (pr preset filter) green at this head, on the old base.

After the scalar bit operations, the forced slot 86 mesh path refused
v_cvt_f16_f32 in 357 requests and v_and_or_b32 in 331, ahead of the
control-flow, heap-provenance and pixel blocks.

- v_and_or_b32 (VOP3 0x371) joins the mesh vector list that already handles
  v_or3_b32 and v_add3_u32, so it takes the three-source alu_rules entry and
  lowers to (S0 & S1) | S2. The shared operand gate still refuses abs, neg,
  clamp and omod.
- v_cvt_f16_f32 (VOP1 0x0A) joins the same list and reuses the compute
  frontend's integer round-to-nearest-even narrowing: the sign comes from bit
  31, binary32 subnormals become signed zeros, binary16 subnormals are kept,
  overflow including the 65520 tie gives 0x7c00, and a NaN keeps its quiet bit.
  The encoding goes into the low half and the reaching destination value keeps
  the high half, as the compute frontend does, so an unproven destination still
  refuses and the merged word is not treated as uniform.

tests/native_direct_mesh_check.py adds source-built programs with the run
helper: v_and_or_b32 with s20 = 0x0000ffff and s21 = 0x00ff0000 exports
(and v0, 65535) | 0x00ff0000, and v_cvt_f16_f32 exports the narrowed word for
1.0f, 0.0f and -2.0f. Controls reject an unbound third source and an unproven
conversion source or destination.

Observed IR:
- %t8 = and i32 %v0, 65535 ; %t9 = or i32 %t8, 16711680
- v_cvt_f16_f32: lshr <bits>, 16 / and ... 32768 for the sign,
  and <bits>, 2147483647, lshr ... 23, and ... 8388607, the nearest-even
  narrowing with icmp ugt %exp, 142 -> 31744 and icmp ugt %mag, 2139095040 ->
  32256 | quiet bits, then or %narrow, %sign, and %destination, -65536 and the
  final or.

Verified:
- cmake --build --preset release --target compile_dxil (7/7 steps,
  compile_dxil.exe linked)
- python -B tests/native_direct_mesh_check.py <compile_dxil.exe> <dxc dir>:
  exit 0, "mesh allocation, indexed outputs, group exchange and negative
  controls passed"
- ctest --preset release --no-tests=error -R '^native_direct'
  2/2 passed: native_direct_container 15.04 s, native_direct_mesh 13.78 s
- python -B tests/docs_links_check.py: 210 files, 807 links

Refs R0Y00#3703
@lambirou
lambirou force-pushed the codex/mesh-vector-alu branch from baa4078 to 816ab82 Compare December 1, 2026 23:02
@lambirou

lambirou commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto origin/main 158ef794 after #3762, resolving the native_direct_mesh_check.py helper conflict by keeping both assert_export_column and the _sop2/_sopc/_sop1_literal helpers.

Head 816ab821. Validation:

  • cmake --build --preset release --target compile_dxil — 17/17.
  • python -B tests/native_direct_mesh_check.py ... — pass.
  • ctest --preset release --no-tests=error -R '^native_direct' — 2/2 passed.

AI-assisted.

@R0Y00
R0Y00 merged commit 6dade96 into R0Y00:main Dec 2, 2026
5 checks passed
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