shader: lower v_cvt_pk_u16_u32 and v_cvt_pk_i16_i32 in the direct C++ compute path #2996
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2996"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T03:44:41Z.
Change
The direct compute frontend now lowers
v_cvt_pk_u16_u32andv_cvt_pk_i16_i32. Before, it refused them withdirect DXIL lowering for <name>. Refs #2995, part of the integer-ALU coverage in #2935.Following the
gfx2hlsl.pyVOP3 table, each saturates S0 and S1 to 16 bits and packs S0 into the low half:v_cvt_pk_u16_u32v_cvt_pk_i16_i32Refused by name:
gfx2hlsl.py;As
docs/experiments.mdnotes for the Python path, the RDNA 2 ISA text does not defineu32_to_u16/i32_to_i16. The saturation follows Mesa and the existing translators and is not measured on the console.Verification
Commit
3e7de7a4oncpp-migration4ff5e36d, Windows 10.0.26100.9711,devpreset. GPU: NVIDIA Quadro M1000M, driver 32.0.15.7371, debug layer unavailable.ctest --preset dev --no-tests=error -R '^native_cvt_pk16_|^native_direct_container$': 2 passed, 1 skipped.native_cvt_pk16_controlspassed. It compiles the program and refuses SRC2 = 3 and an op_sel bit. It also checks that the truncating and unsigned-bound references differ.native_cvt_pk16_hardwareskipped (77). It needs shader model 6.6 with wave32, so the readback is not measured here.gfx2hlsl.pytable expressions, evaluated in Python, for all eight pairs. I checked this once.python -B tests/docs_links_check.py: ok.Evidence and follow-up
Eight operand pairs are set by
v_movliterals and converted by both instructions. Each of 64 lanes stores the 16 results. The pairs include 0, 0xffff, 0x10000, 0xffffffff, -32768, -32769, 32767, 32768, 0x7fffffff and 0x80000000.The VOP3 words were assembled with LLVM 15.0.7. I checked the whole program with
tools/disasm_rdna2.py --hex. The note isdocs/experiments/native-direct-cvt-pk16.md.Checklist
AI-assisted.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T03:58:38Z.
Rebased onto
cpp-migratione0d83759after #2990 and #2994 merged; they insert at the same place in the integer-ALU chain, and both blocks are kept. The controls andnative_direct_containerpass again on the rebased head. The readback still skips here (77).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T04:15:10Z.
Review: COMMENTED
Clean implementation of the saturating pack instructions — correct semantics for both unsigned and signed forms, and the operand checks (SRC2, op_sel, modifiers) are consistent with
gfx2hlsl.py.Findings
✅ What works well
select(ugt(x, "65535"), "65535", x)is the correctmin(S, 0xFFFF)for unsigned 32-bit values.select(slt(x, -32768), -32768, x)thenand(select(sgt(low, 32767), 32767, low), 65535)) correctly clamps to [-32768, 32767]:and 0xFFFF.or(narrow(a), shl(narrow(b), 16))packs S0 low, S1 high — correct per the VOP3 encoding.i.src[2] != 0matches thegfx2hlsl.pyrefusal for non-zero unused SRC2 field.i.a & 0x7800catches bits 11-15 of the VOP3 operand register — correct for op_sel field detection.⚠️ Minor observations
Signed saturation simplification: The two-step approach works correctly but could be simplified conceptually to three comparisons (
clamped = min(max(x, -32768), 32767)) if the IR builder supports it. The current approach is fine and avoids IR combinatorics — no action needed.Mesa reference: The PR notes that "the RDNA 2 ISA text does not define u32_to_u16/i32_to_i16" and that saturation follows Mesa. This is honest and useful context. One tiny addition: if the specific Mesa commit or source file could be cited in a comment, it would help maintainers trace the decision if behavior ever needs to change.
Test operand pairs: The 8 pairs are well-chosen to cross both bounds of both forms. The
(0xFFFF8000, 0xFFFF7FFF)pair tests the signed negative range. Good coverage.Recommendation
Ready to land. Clean, well-tested, and consistent with the project's existing patterns.
🏷 None — this is a textbook example of the pattern established by previous PRs in this series.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T04:35:51Z.
Review: APPROVED
Review of head
78ef2da5. CI on the head is green. This is the wave32 SM 6.6 readback you asked for. Approving and merging.Code read:
min(S, 0xffff).0x7800).Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), plus WARP, release. This was tested together with #2986, #2998, #3003 and #2975 merged onto
cpp-migratione0d83759; all five merge cleanly with each other.ctest --preset release --no-tests=error -R '^(native_.*|startup_compute_dispatch(_.*)?_(warp|hardware)|startup_slot67_indirect_dispatch_warp|startup_compute_translate_e2e_warp|startup_stream_draw.*|startup_native_graphics.*)$'gives 94 tests, 90 passed and 4 skipped (77, WARP has no 32-lane waves).native_cvt_pk16_hardwareandnative_cvt_pk16_controlspassed.Mutation here: truncating the signed form to its low 16 bits instead of clamping fails
native_cvt_pk16_hardware, for example(9, '0xffff0000', '0x7fff0000'). With it restored, it passes.As you note, the saturation follows Mesa and the existing translators and is not measured on the console. I will close #2995 by hand.
AI-assisted; the commands above were run locally.