Skip to content

pixel_aot: lower 13 SDWA cvt, frexp_exp, and pkrtz forms - #2571

Open
KomaGuy wants to merge 2 commits into
R0Y00:mainfrom
KomaGuy:shader/sdwa-cvt-f32-pkrtz-frexp
Open

KomaGuy wants to merge 2 commits into
R0Y00:mainfrom
KomaGuy:shader/sdwa-cvt-f32-pkrtz-frexp

Conversation

@KomaGuy

@KomaGuy KomaGuy commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Lowers 13 SDWA conversion, exponent, and packed-RTZ forms in tools/pixel_aot.py (counted in both docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv), with static refusal controls, pixel_aot_sdwa_cvt_{warp,hardware} draw tests, LLVM 15 check_binary fixtures, and form_coverage_check coverage assertions:

  • Binary32 to int32 & exponent (5): v_cvt_i32_f32_sdwa, v_cvt_u32_f32_sdwa, v_cvt_flr_i32_f32_sdwa, v_cvt_rpi_i32_f32_sdwa, v_frexp_exp_i32_f32_sdwa
  • Integer / byte / nibble to binary32 (7): v_cvt_f32_i32_sdwa, v_cvt_f32_u32_sdwa, v_cvt_f32_ubyte0_sdwa, v_cvt_f32_ubyte1_sdwa, v_cvt_f32_ubyte2_sdwa, v_cvt_f32_ubyte3_sdwa, v_cvt_off_f32_i4_sdwa
  • Packed RTZ export conversion (1): v_cvt_pkrtz_f16_f32_sdwa

Contracts & Semantics

  • Float-source forms (f32->int32, frexp_exp, pkrtz): Require whole-dword VGPR/SGPR sources (src0_sel:DWORD, plus src1_sel:DWORD and dst_sel:DWORD for pkrtz) with optional bit-31 abs/neg modifiers (|reg|, abs(reg), -reg, -|reg|), refusing sext(), clamp, and omod. f32->int32 and frexp_exp reuse the IEEE-754 saturating/special-value bit helpers (cvt_{i32,u32,flr_i32,rpi_i32}_f32, dpp_frexp_exp_i32_f32) with SDWA destination placement (BYTE_0..3, WORD_0..1, DWORD + UNUSED_PAD/UNUSED_PRESERVE); v_cvt_pkrtz_f16_f32_sdwa produces the (lo, hi) compressed-export pair and remains exempt from HALF_RTZ refusal.
  • Integer-source forms (int->f32): Accept VGPR/SGPR sources with BYTE_0..3, WORD_0..1, or DWORD selection, optional sext(), optional clamp (saturate(...)), and SDWA destination placement, refusing float modifiers and omod.
  • Shared refusals: All 13 refuse UNUSED_SEXT, UNUSED_PRESERVE on untracked/non-numeric destinations, pending scalar loads, outstanding samples, and non-entry EXEC masks.

Verification

  • Ran locally on Linux:
    • python3 tests/pixel_aot_check.py (including new check_sdwa_cvt_controls)
    • form_coverage_check: check_sdwa_cvt_forms (+13 forms in gfx1013.tsv and rdna2.tsv, unlowered neighbours excluded, single-opcode removal control), check_shader_records, check_sdwa_f16_forms, check_sdwa_int_extra_forms, check_sdwa_cmp_coverage
    • Independent Python simulation across all 3 integer-export fixtures (9 runtime rows, 13 mutations) + pkrtz RTZ discrimination check + manual inspection of generated HLSL
    • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, python3 tests/rdna2_tools_check.py (156 tests OK)
    • git merge-tree --write-tree --name-only origin/main HEAD and git diff --check origin/main
  • Runs in CI:
    • LLVM 15 pixel_aot_binary assembly/disassembly round-trips for all 4 SDWA_CVT_* fixtures
    • Windows D3D12 pixel_aot_sdwa_cvt_warp / pixel_aot_sdwa_cvt_hardware draws and all 16 mutations

@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 3bf6dd1 (comment only, Linux checks; the WARP draw test is run separately on Win2025).

Result: sound on code and fixtures, no blocking findings.

  • Change: 13 SDWA forms lowered in tools/pixel_aot.py (5 float-to-int/frexp_exp, 7 int-to-float, 1 pkrtz). The float-source forms reuse the existing e64/DPP bit helpers and SDWA destination placement; refusals cover src0_sel other than DWORD, sext on float sources, UNUSED_SEXT, clamp/omod on the float forms, pending loads and non-entry EXEC.
  • Test quality: draw-sdwa-cvt (pixel_aot_sdwa_cvt_{warp,hardware}) draws the translated shader and compares the readback with sdwa_cvt_reference, an independent Python model (not the lowering's own helpers), plus per-group mutations that must change the result. This is the readback-vs-CPU-reference test the repo asks for. check_sdwa_cvt_controls covers the static refusals.
  • I checked v_cvt_off_f32_i4 (signed nibble times 0.0625: -8 -> -0.5, 15 -> -0.0625) and the ubyte byte selection by hand against the reference.
  • Sibling tables: coverage tsv counts and form_coverage_check assertions are extended, with a single-opcode removal control. No other open or merged PR covers these opcodes (searched SDWA cvt frexp_exp pkrtz).

Commands run locally:

  • python3 tests/pixel_aot_check.py -> pass
  • python3 tests/docs_links_check.py -> ok (489 links); python3 tests/bidi_controls_check.py -> ok; git diff --check origin/main...HEAD -> clean
  • tests/form_coverage_check.py could not run on this Linux box (missing iced_x86); it is left to the Win2025 run.
  • Mutations: dropping the src0_sel:DWORD refusal fails check_sdwa_cvt_controls; dropping the float-source modifier refusal fails it too; dropping the UNUSED_SEXT refusal fails the existing movrel control.

AI-assisted; commands listed were executed locally.

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.

2 participants