Skip to content

shader: lower nine uncovered integer forms in pixel_aot (carry-out, swap, 16-bit pack, SAD) - #779

Merged
R0Y00 merged 5 commits into
R0Y00:mainfrom
rasptum:shader/new-integer-forms
Nov 23, 2026
Merged

R0Y00 merged 5 commits into
R0Y00:mainfrom
rasptum:shader/new-integer-forms

Conversation

@rasptum

@rasptum rasptum commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Three small, independent additions of integer forms that no fixture covered and no open pull request adds. They are three commits, so each can be reviewed, reverted or split out on its own. They are in one PR because each one appends to the same lists (CMakeLists.txt, the mode table and fixture lists in tests/pixel_aot_check.py, tests/form_coverage_check.py, docs/experiments.md), so separate PRs would conflict with each other at every merge. If you prefer them separate, say so and I will split them.

Commit Forms CTest entries
0a9da40 v_add_co_u32, v_sub_co_u32, v_subrev_co_u32 pixel_aot_carry_out_{warp,hardware}
bed88fb v_cvt_pk_u16_u32, v_cvt_pk_i16_i32 pixel_aot_pack_int16_{warp,hardware}
732ee6b v_sad_hi_u8, v_sad_u32, v_msad_u8 pixel_aot_sad_{warp,hardware}

Merged on 2026-11-23 with two maintainer commits on top, 95c8172 (merge of main) and f16ef39, which keep #429's partial uncompressed export alongside these fixtures.

Eight forms on gfx1013. Each commit has its own draw test with its own FORM_COVERAGE_RECORD, so nothing is added to pixel_aot_hardware.

v_swap_b32 is not part of this PR. An earlier revision had a fourth commit for it. #771, now merged, lowers v_swap_b32 with the same CTest names, so that commit was dropped at the maintainer's request. This branch adds no swap code, test, CTest name, scanner entry or docs paragraph.

Fixed since the previous revision.

  • The pack commit had placed check_pack_int16_draws inside check_sdwa_integer_draws and cut off that function's run_pixel_batch call. As a result, pixel_aot_sdwa_integer_* (shader: lower SDWA forms of 32-bit integer operations in pixel_aot #758) passed without drawing. check_sdwa_integer_draws is now identical to main, and it draws all 48 cases again.
  • A duplicate _s32 helper that shadowed main's is removed.
  • The carry-out family now has scanner accept and refuse lines in tests/rdna2_tools_check.py, like the other two families.

Changed v_sad_u32 expectation: this PR moves v_sad_u32 from refused to lowered, as ABSDIFF(S0.u, S1.u) + S2.u, unsigned, modulo 2^32. The reading of the ISA text is explained in the 732ee6b section. Where the new expectation is pinned:

Verification of the combined branch

Commit 732ee6b on main at a0554e5.

  • Windows 10 Pro 22H2 (10.0.19045), Windows SDK 10.0.26100.0 DXC, LLVM 15.0.7, debug layer enabled.
  • WARP is the Microsoft Basic Render Driver 10.0.19041.5794.
  • The GPU is an NVIDIA GeForce RTX 3060 (10de:2503), driver 32.0.15.9636.

Rebasing conflicted only in shared lists: the draw-mode tuple and draw dispatch table in tests/pixel_aot_check.py (against #766, #771 and #781) and the CMake test block (against #474, #618 and #715). All of main's entries and the entries here are kept. Every top-level function from main in the touched Python files is unchanged, apart from check_controls, check_binary, main, lower and the scanner and coverage checks this change extends.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^pixel_aot_' -V
ctest --preset dev --no-tests=error -j 4

58 tests ran: 57 passed, 1 failed, 0 skipped.

Test Result
pixel_aot_carry_out_warp, pixel_aot_carry_out_hardware Passed (0.8 s, 2.1 s)
pixel_aot_pack_int16_warp, pixel_aot_pack_int16_hardware Passed (0.7 s, 1.6 s)
pixel_aot_sad_warp, pixel_aot_sad_hardware Passed (0.7 s, 1.6 s)
pixel_aot_sdwa_integer_warp, pixel_aot_sdwa_integer_hardware Passed (1.1 s, 3.0 s); 0.6 to 0.7 s, with no draws, on earlier revisions
the other 25 pixel_aot_*_warp tests, including main's pixel_aot_swap_warp Passed
24 of the other 25 pixel_aot_*_hardware tests, including pixel_aot_swap_hardware Passed
pixel_aot_blend_scalar_hardware Failed. It fails the same way with main's code (see below), and this change does not touch it; pixel_aot_blend_scalar_warp passes.

Of the forms this PR adds, each of the six new tests' coverage records lists only its own family (the three carry-out forms, the two packs, or the three SAD forms), next to fixture scaffolding such as v_mov_b32_e32 and exp.

Other checks, on 732ee6b unless the row says otherwise:

Check Result
full ctest --preset dev --no-tests=error -j 4 373 tests: 330 passed, 41 capability skips (exit 77), 2 failed (gpu_alias_lookup_writes_warp, pixel_aot_blend_scalar_hardware), on 66edfcd (same commits, one clean rebase earlier; see below)
the two failures, run with main's Python code and the same offscreen_check.exe (no C++ changes here) both fail the same way, so they predate this change (on 66edfcd, main at 8863f1f)
draw case counts, with run_pixel_batch stubbed SDWA 48 (as on main), carry-out 27, packs 19, SAD 22 (on 66edfcd)
LLVM 15.0.7 round trip (tests/pixel_aot_check.py binary, assembler stand-in below) exit 0
static controls (tests/pixel_aot_check.py with no mode) exit 0
the 23 pure-Python checks listed in AGENTS.md all exit 0
mutation check outside the PR, in a scratch copy of the translator, on 66edfcd ten wrong lowerings (for example a signed v_sad_u32 difference, a truncating or half-swapped pack, <= in the add carry, v_msad_u8 without masking): the matching WARP draw failed with a pixel mismatch for all ten; the unmodified copy passed all three draws
scanner negative control: the carry-out pattern removed from tools/scan_unsupported_shaders.py the first new accept line in rdna2_tools_check fails

The full suite ran on 66edfcd, these three commits on 8863f1f. The rebase onto a0554e5 (#621, Python-only disassembler and scanner changes) was clean, and on 732ee6b I reran the function integrity check, the 23 Python checks, the controls, the LLVM 15 round trip and the whole ^pixel_aot_ suite (the table above).

llvm-mc is not installed on this machine. Every LLVM 15 round trip quoted here, including in the per-commit sections, used a stand-in that runs LLVM 15.0.7 clang --target=amdgcn--amdpal -mcpu=<cpu> -c -x assembler, which is the same MC assembler. llvm-objcopy and LLVM-C.dll are the LLVM 15.0.7 binaries.

Overlap: checked again on 2026-11-23 (UTC), right before this push, against the titles, bodies and added diff lines of all 47 open PRs, and against main.

The per-commit sections below keep the verification each commit had on its own branch, including full CTest runs. Commit hashes, base commits, test counts and coverage numbers inside those sections are the pre-combination ones, measured before the recent main commits. The forms each commit adds are unchanged.

Commit 0a9da40: shader: lower v_add_co_u32, v_sub_co_u32 and v_subrev_co_u32 in pixel_aot

Change

One translator change and one new draw test for the three carry-out integer forms, which no fixture covered and no open pull request adds.

  • tools/pixel_aot.py: v_add_co_u32, v_sub_co_u32 and v_subrev_co_u32 lower as a 32-bit wraparound result plus a per-lane condition written to the lane mask operand. The condition is tracked the same way a comparison result is, so v_cndmask_b32 can read it. No new mechanism is introduced.
  • tests/pixel_aot_check.py: three programs, static checks of the emitted HLSL, refusal checks, and bit-exact draws.
  • tools/scan_unsupported_shaders.py, tests/rdna2_tools_check.py (scanner accept and refuse lines, added in this revision), tests/form_coverage_check.py, CMakeLists.txt and docs/experiments.md are updated to match.

Semantics and sources:

Instruction Result Mask bit is 1 when
v_add_co_u32 D, M, S0, S1 S0 + S1 modulo 2^32 the 33-bit sum does not fit in 32 bits
v_sub_co_u32 D, M, S0, S1 S0 - S1 modulo 2^32 S1 > S0, unsigned
v_subrev_co_u32 D, M, S0, S1 S1 - S0 modulo 2^32 S0 > S1, unsigned

These are taken from the LLVM 15 AMDGPU backend, read at tag llvmorg-15.0.7. In AMDGPUISelDAGToDAG.cpp, SelectUADDO_USUBO selects V_ADD_CO_U32_e64 for ISD::UADDO and V_SUB_CO_U32_e64 for ISD::USUBO on the vector path, so the mask output is the unsigned overflow of the add and the borrow of the subtract. In VOP2Instructions.td, V_SUBREV_CO_U32 is declared with v_sub_co_u32 as its reversed-operand counterpart, and the three are encoded for gfx10 as VOP3 only (VOP3beOnly_Real_gfx10, opcodes 0x30f, 0x310 and 0x319). They are not checked against an AMD ISA document, and nothing here is measured on a console.

Accepted shapes: the spelling LLVM 15 prints for gfx10 (VOP3 only, no suffix); the mask as vcc, vcc_lo, one SGPR or an SGPR pair; each source as a register, an inline constant or a literal.

Refused, each asserted by the test: an _e32 or _e64 suffix, clamp, a float modifier, exec or a VGPR as the mask, a missing or extra operand, an unwritten register, DPP controls, and the carry-in forms v_*_co_ci_u32. A lane mask written by these instructions has no reader other than v_cndmask_b32 here.

The draws export through the R32G32B32A32_UINT readback target and are compared bit for bit. A, B, C and D are constants s44 to s47. Each program computes op(A, B) with the carry in vcc_lo and op(B, A) with the carry in s60, and two v_cndmask_b32_e64 selects turn each carry into C or D.

  • Add, four rows: a carry, no carry, a zero addend (the sum equals src0 and must not carry), and a sum that wraps to exactly zero (it must carry).
  • Each subtract, three rows: a borrow in one operand order and none in the other, equal operands, and the larger operand first.
  • Both carry states are drawn for each mask register, and every input and expected result is a normal binary32 or zero (both asserted).

Negative controls: seventeen wrong references, each replacing one channel of one row, must report pixel_mismatch: subtract for add, add for subtract, reversed operands, a dropped carry or borrow on each mask register, a carry without overflow, a carry on a sum equal to src0, a dropped carry on a sum of zero, a borrow on equal operands, and the borrow of the other operand order.

That is 27 draws from 3 compiles and 3 renderer launches, registered as their own CTest entries pixel_aot_carry_out_hardware and pixel_aot_carry_out_warp (tests/pixel_aot_check.py draw-carry-out), each with its own FORM_COVERAGE_RECORD. The three programs are added to the LLVM 15 round trip.

This advances instruction-form coverage of the pixel translator by three forms.

Verification

Commit 900b1d2 on main at c426252. Windows 10 Pro 22H2 (10.0.19045.6466), Windows SDK 10.0.26100.0 DXC, debug layer enabled.

The full check set below was run on this change rebased onto main at 3cd9df3 (4a085d3). main then moved to c426252, which touches none of the pixel translator files (it changes tests/offscreen_check.cpp, tests/rdna2_tools_check.py and SPIR-V and mesh tests); the rebase was clean, and on 900b1d2 I rebuilt offscreen_check and reran the new test on both backends, pixel_aot_warp, pixel_aot_e64_integer_*, pixel_aot_sdwa_integer_*, the LLVM 15 round trip, the controls, tests/form_coverage_check.py and tests/rdna2_tools_check.py, all passing.

cmake --preset dev
cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R '^pixel_aot_'

40 tests ran. 39 passed, 1 failed, 0 skipped.

Test Adapter Result
pixel_aot_carry_out_warp Microsoft Basic Render Driver, WARP 10.0.19041.5794 Passed, 0.9 s
pixel_aot_carry_out_hardware NVIDIA GeForce RTX 3060 (10de:2503), driver 32.0.15.9636 Passed, 2.6 s
the other 19 pixel_aot_*_warp tests WARP 10.0.19041.5794 Passed
18 of the other 19 pixel_aot_*_hardware tests RTX 3060 Passed
pixel_aot_blend_scalar_hardware RTX 3060 Failed. It also fails on untouched main on this machine and this change does not touch it.

In both new tests the 10 right references report max_absolute_error=0, the 17 wrong references report mismatch, and every draw reports debug_errors=0 debug_warnings=0.

Other checks on the same commit, all passed:

  • python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll> with LLVM 15.0.7. LLVM 15 assembles and prints the three instructions as written for -mcpu=gfx1013. The first draft of the fixture was rejected by the assembler (Wave64 mask spelling, then three scalar operands on one select), which is why the fixture uses vcc_lo, s60 and a VGPR for D.
  • python -B tests/pixel_aot_check.py (controls).
  • python -B tests/pixel_aot_check.py draw <dxc> <offscreen_check.exe> warp (the full existing draw run).
  • The 22 pure-Python checks listed in AGENTS.md.
  • A local mutation check, not part of the change, run on an earlier base (37ed46d) with the same lowering: nine wrong lowerings (for example <= for < in the add carry, >= in the borrows, the borrow of the other subtract) were each substituted into the translator, and the WARP draw failed for all nine.

Evidence and follow-up

Coverage, counted with tools/form_coverage.py's matching rule from the union of the record-writing shader tests run on WARP.

gfx1013 gfx1030 (RDNA2)
main at 3cd9df3 (c426252 adds no shader translator change) 566 of 1968 560 of 1863
this change 569 of 1968 563 of 1863

The forms added are exactly v_add_co_u32, v_sub_co_u32 and v_subrev_co_u32 (VOP3) on both lists. None is removed. docs/coverage/dashboard.svg is not regenerated here.

What this does not show: that the console computes the same results (the draws run on desktop GPUs), and the round trip was run for gfx1013 only.

Overlap with open pull requests: the diffs of the 65 pull requests open when this work started were searched for the three form names on added lines; none adds them. The nearest is #423, which lowers the carry-in and carry-out forms v_*_co_ci_u32 in their DPP encodings; it uses different instructions, and this change keeps the co_ci forms refused. Like every open shader pull request, this one appends to the check_binary fixture list and the draw-mode table in tests/pixel_aot_check.py, so a small textual conflict with whichever lands first is expected.

Commit bed88fb: shader: lower v_cvt_pk_u16_u32 and v_cvt_pk_i16_i32 in pixel_aot

Change

pixel_aot refused the two integer pack conversions. This lowers v_cvt_pk_u16_u32 and v_cvt_pk_i16_i32: each saturates two 32-bit sources to 16 bits and packs them into one word, src0 in the low half and src1 in the high half.

They go through the existing INTEGER table and int_operand path. On gfx10 both exist in the VOP3 encoding only, although they take two sources, so a small list (INTEGER_VOP3_ONLY) refuses their _e32 spelling in the translator and in tools/scan_unsupported_shaders.py. tests/pso_readiness_check.py assumed every two-source integer operation has an e32 spelling; it now asserts the opposite for the forms on that list and is unchanged for the others.

Semantics and sources

Instruction Layout (AMD RDNA 2 ISA reference, 30 November 2020, VOP3 opcodes 874 and 875) Lowering
v_cvt_pk_u16_u32 D.u16_lo = u32_to_u16(S0.u32); D.u16_hi = u32_to_u16(S1.u32) min(S0, 65535) | (min(S1, 65535) << 16)
v_cvt_pk_i16_i32 D.i16_lo = i32_to_i16(S0.i32); D.i16_hi = i32_to_i16(S1.i32) each source clamped to -32768..32767 as a signed word, low 16 bits kept
  • What the AMD text pins: which source goes to which half, and the signedness of each form.
  • What it does not pin: neither the RDNA 2 nor the RDNA 3.5 reference defines u32_to_u16 or i32_to_i16, so saturation versus truncation is not stated there. LLVM 15 gives the instructions no meaning beyond their types (VOP_V2I16_I32_I32, selected only from the llvm.amdgcn.cvt.pk.u16 and llvm.amdgcn.cvt.pk.i16 intrinsics, no constant folding).
  • Where the saturation comes from: Mesa (MIT). src/compiler/nir/nir_opcodes.py documents pack_uint_2x16 as "Convert two unsigned integers into a packed unsigned short (clamp is applied)" and pack_sint_2x16 likewise for signed; its constant folding clamps each source to the unsigned or signed 16-bit range; and the ACO backend (aco_select_nir_alu.cpp) selects exactly v_cvt_pk_u16_u32 and v_cvt_pk_i16_i32 for those operations with no clamp instruction of its own. Cited, not copied.
  • This is a statement by the open source driver for this hardware family, not by the ISA document, and it is not measured on the console. If that is not a strong enough source for this project, the PR should wait for a measurement; I would rather be told than have it merged on a weak basis.

Accepted shapes

  • The plain spelling (what LLVM 15 prints) and the _e64 spelling.
  • Each source is a tracked VGPR, a tracked SGPR, an inline constant or a 32-bit literal, as for the other INTEGER operations.

Refused, each with a control

  • The _e32 spelling, with its own diagnostic ("VOP3-only operation does not support e32 encoding").
  • clamp, a float modifier, a wrong operand count, a destination above v255, an unwritten register, a literal wider than 32 bits, the SDWA spelling.
  • The float packs stay unsupported: v_cvt_pknorm_i16_f32, v_cvt_pknorm_u16_f32, v_cvt_pknorm_i16_f16, v_cvt_pknorm_u16_f16 and v_cvt_pk_u8_f32. No public source I found states their rounding, their bounds or their NaN result (the ISA text writes (snorm), (unorm) and flt32_to_uint8 without defining them; Mesa defines the NIR operation, which is not a statement about the instruction).
  • v_sat_pk_u8_i16 also stays unsupported. Its bounds are stated (RDNA 3.5 text: 0 to 255 from signed 16-bit inputs), but its result is a 16-bit value, which belongs with the low-16 tracking under review in shader: lower non-packed 16-bit integer VOP3 ops #732.

Verification

Rebased three times while main moved (37ed46d, f714d2f, 761e323, 3cd9df3), with keep-both resolutions against #755 and #758 in the shared fixture lists. Every result below was measured again on the commit named here.

Commit 045be00 on main 3cd9df3. Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207, Windows SDK 10.0.26100.0 DXC, Python 3 venv, LLVM 15.0.7.

ctest --preset dev --no-tests=error -R '^pixel_aot_pack_int16_' -V
  • pixel_aot_pack_int16_hardware: Passed (2.43 s) on NVIDIA GeForce RTX 3060, driver 32.0.15.9636.
  • pixel_aot_pack_int16_warp: Passed (0.82 s) on WARP (Microsoft Basic Render Driver 10.0.19041.5794).
  • No capability skip (exit 77) occurred on either backend.
  • Each test makes 19 draws from 2 compiles: 4 right rows that must pass and 15 wrong references that must report pixel_mismatch.
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM>
  • Passed with LLVM 15.0.7. Both new programs are in the round trip; LLVM 15 prints the two instructions without an encoding suffix.
python -B tests/pixel_aot_check.py draw <dxc> <offscreen_check.exe> warp
  • Passed (exit 0): the existing combined draw run is unchanged.
ctest --preset dev --no-tests=error -R '^pixel_aot'
  • 40 tests, 39 passed, 1 failed, 0 skipped. The failure is pixel_aot_blend_scalar_hardware, which fails the same way on untouched main on this machine and is not touched by this change; pixel_aot_blend_scalar_warp passes.

  • python -B tests/pixel_aot_check.py (controls), tests/form_coverage_check.py, tests/rdna2_tools_check.py, tests/pso_readiness_check.py and the other pure-Python checks listed in AGENTS.md: all 22 exit 0.

Evidence and follow-up

The fixtures are synthetic. Two programs export through the R32G32B32A32_UINT readback target and are compared bit for bit against a CPU reference written independently of the translator's expressions (Python integers). A and B come from constants s44 and s45.

  • A normal binary32 word is outside both 16-bit ranges, so each program first derives B >> 16, B >> 12 and the arithmetic B >> 16 in the shader, and packs those with A, a literal 0x12345 and an inline -16.
  • A word whose high half saturates is not a normal binary32, so those channels are exported through an xor with 0x40000000. Every input and every expected word is then a normal binary32 or zero (asserted), so the draw does not depend on NaN or denormal handling.
  • First row (A positive, B negative): the unsigned pack must turn the literal, B >> 12, A and the negative arithmetic shift into 0xffff; the signed pack must turn A and the zero-extended B >> 16 into 0x7fff and keep the inline -16 as 0xfff0.
  • Second row (A negative): the signed pack turns A into 0x8000, and B >> 12 is 0xfff, which both packs must keep.

Negative controls, 15 in total, each replacing one channel on the first row with the word a specific wrong lowering would give: truncation instead of saturation in either half, swapped halves, the signed bound on the unsigned pack and the reverse, a negative source clamped to zero or kept, a value above 32767 kept, and the inline constant read as unsigned. A static control asserts the exact emitted statements and the reference values at each bound and one step past it; 10 refused spellings per form and 7 unsupported neighbours are checked.

As an extra check outside the PR, I replaced each lowering in memory with nine wrong ones (truncation, swapped halves, the other form's bounds, a clamp at zero, only the upper or only the lower signed bound). The draw test failed for all nine on WARP and on the RTX 3060.

Coverage (tools/form_coverage.py rule over the record-writing shader tests, WARP run): gfx1013 566 to 568 of 1,968, gfx1030 560 to 562 of 1,863. The two new forms are exactly the difference; both are in the VOP3 block.

Measured: the translated HLSL computes the stated words on one desktop GPU and on WARP. Hypothesis: that the console saturates the same way, which rests on the Mesa statement above; the half layout rests on the ISA text.

Overlap with open PRs: neither form appears in an open PR diff (checked against the diffs of all 65 open PRs when this work started, before this PR was opened). #421 lowers the DPP form of v_sat_pk_u8_i16, a different instruction. Like every shader PR, this appends to the same fixture lists in tests/pixel_aot_check.py, so a later one needs a trivial rebase.

Commit 732ee6b: shader: lower v_sad_hi_u8, v_sad_u32 and v_msad_u8 in pixel_aot

Change

pixel_aot refused every sum-of-absolute-differences instruction. This lowers three of them, all three-source VOP3 operations on 32-bit words: v_sad_hi_u8, v_sad_u32 and v_msad_u8.

They go through the existing INTEGER table and int_operand path, so tools/scan_unsupported_shaders.py recognises them from the same table. The two byte-lane forms share one helper, sad4_u8, which is emitted only when a program uses it.

Semantics and sources

All three are taken from the AMD "RDNA 2" Instruction Set Architecture Reference Guide (30 November 2020), VOP3 opcodes 347, 349 and 369, with ABSDIFF(x, y) := (x > y ? x - y : y - x) // UNSIGNED comparison:

Instruction Definition in the ISA text Lowering
v_sad_hi_u8 D.u = (V_SAD_U8(S0, S1, 0) << 16) + S2.u (sad4_u8(S0, S1, false) << 16) + S2
v_sad_u32 D.u = ABSDIFF(S0.u, S1.u) + S2.u (max(S0, S1) - min(S0, S1)) + S2
v_msad_u8 D.u = S2.u; D.u += S1.u[31:24] == 0 ? 0 : ABSDIFF(S0.u[31:24], S1.u[31:24]); ... for the four byte lanes. "Components where the reference value in S1 is zero are not included in the sum." sad4_u8(S0, S1, true) + S2
  • The RDNA 3.5 reference (23 July 2024) gives the same three definitions.
  • LLVM 15 agrees on the dword form: SIInstructions.td selects V_SAD_U32 for umax(a, b) - umin(a, b) + c and for the equivalent setugt select.
  • Sums are taken modulo 2^32. The documents imply this through the 32-bit unsigned destination and the note "overflow into upper bits is allowed"; they do not state it in those words.
  • A note on v_sad_u32: in the text extracted from the RDNA 2 PDF each definition box sits beside the following opcode row, so the 16-bit lane box appears next to the V_SAD_U32 row and the dword definition next to opcode 350. The description sentences and the RDNA 3.5 text settle the attribution. I found no signed reading in either document. shader: lower gfx1013 byte and bit funnel VOP3 instructions in pixel_aot #531 keeps v_sad_u32 as a rejected neighbour because it reads the ISA text as abs(S0.i - S1.i), which disagrees with LLVM's unsigned pattern; shader: lower gfx1013 three-operand VOP3 integer instructions in pixel_aot #526 also lists it as a rejected neighbour. I read the RDNA 2 and RDNA 3.5 text as unsigned for the reasons above, and I would welcome a second pair of eyes on it.

Accepted shapes

  • The plain spelling (what LLVM 15 prints) and the _e64 spelling.
  • Each source is a tracked VGPR, a tracked SGPR, an inline constant or a 32-bit literal, as for the other INTEGER operations.

Refused, each with a control

  • The _e32 spelling (there is no VOP2 encoding).
  • clamp. LLVM 15 assembles the bit on these instructions, but the ISA text gives it no meaning for an integer result, so it is not guessed.
  • A float modifier (-, |x|, abs()), a wrong operand count, a destination above v255, an unwritten register, a literal wider than 32 bits.
  • The neighbours v_sad_u8, v_sad_u16, v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8 and v_mqsad_u32_u8 stay unsupported. v_sad_u8 and v_sad_u16 are in open draft shader: lower gfx1013 byte and bit funnel VOP3 instructions in pixel_aot #531.

Verification

Rebased three times while main moved (37ed46d, f714d2f, 761e323, 3cd9df3), with keep-both resolutions against #757, #755 and #758 in the shared fixture lists. Every result below was measured again on the commit named here.

Commit a3ea48c on main 3cd9df3. Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207, Windows SDK 10.0.26100.0 DXC, Python 3 venv, LLVM 15.0.7.

ctest --preset dev --no-tests=error -R '^pixel_aot_sad_' -V
  • pixel_aot_sad_hardware: Passed (1.97 s) on NVIDIA GeForce RTX 3060, driver 32.0.15.9636.
  • pixel_aot_sad_warp: Passed (0.81 s) on WARP (Microsoft Basic Render Driver 10.0.19041.5794).
  • No capability skip (exit 77) occurred on either backend.
  • Each test makes 22 draws from 2 compiles: 4 right rows that must pass and 18 wrong references that must report pixel_mismatch.
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM>
  • Passed with LLVM 15.0.7. Both new programs are in the round trip; LLVM 15 prints the three instructions without an encoding suffix.
python -B tests/pixel_aot_check.py draw <dxc> <offscreen_check.exe> warp
  • Passed (exit 0): the existing combined draw run is unchanged.
ctest --preset dev --no-tests=error -R '^pixel_aot'
  • 40 tests, 39 passed, 1 failed, 0 skipped. The failure is pixel_aot_blend_scalar_hardware, which fails the same way on untouched main on this machine and is not touched by this change; pixel_aot_blend_scalar_warp passes.

  • python -B tests/pixel_aot_check.py (controls), tests/form_coverage_check.py, tests/rdna2_tools_check.py and the other pure-Python checks listed in AGENTS.md: all 22 exit 0.

Evidence and follow-up

The fixtures are synthetic. Two programs export through the R32G32B32A32_UINT readback target and are compared bit for bit against a CPU reference written independently of the translator's expressions (Python integers, explicit byte extraction). A, B and C come from constants s44, s45 and s46.

  • Byte group: v_sad_hi_u8 with a register accumulator and with an inline zero accumulator, and v_msad_u8 in both source orders.
  • Dword group: v_sad_u32 with a register and with an inline accumulator, v_msad_u8 against a literal reference whose byte 2 is zero, and v_sad_hi_u8 with a VGPR accumulator.
  • No instruction uses more than two scalar registers and literals, the gfx10 limit LLVM 15 enforces when assembling.

Each group runs on two rows. In the first byte row A and B each have one zero byte in a different lane and bytes on both sides of 0x80, so the masked, unmasked and wrongly masked sums are 0x1c3, 0x242 and 0x17f. In the first dword row A and B differ in the sign bit and the sum with C passes 2^32. Every input and every expected word is a normal binary32 or zero (asserted), so the draw does not depend on NaN or denormal handling.

Negative controls, 18 in total, each replacing one channel on the first row with the word a specific wrong lowering would give: a sum not moved to the high half or moved when it should not be, masking applied to v_sad_hi_u8 or dropped from v_msad_u8, the mask taken from src0, signed byte lanes, a dropped top lane, a dropped or wrong accumulator, unswapped operands, a signed dword comparison, and byte lanes for the dword difference. A static control asserts the exact emitted statements and that the helper appears once and only when used; 14 refused spellings and 5 unsupported neighbours are checked.

As an extra check outside the PR, I replaced each lowering in memory with six wrong ones (signed dword difference, dropped accumulator, missing shift, masking on the wrong form, missing masking, mask from src0). The draw test failed for all six on WARP and on the RTX 3060.

Coverage (tools/form_coverage.py rule over the record-writing shader tests, WARP run): gfx1013 566 to 569 of 1,968, gfx1030 560 to 563 of 1,863. The three new forms are exactly the difference; all are in the VOP3 block.

Measured: the translated HLSL computes the stated words on one desktop GPU and on WARP. Hypothesis: that the console computes the same, which rests on the ISA text and the LLVM pattern above.

Overlap with open PRs: none of the three forms is lowered by an open PR (checked against the diffs of all 65 open PRs when this work started, before this PR was opened). #531 (draft) lowers v_sad_u8 and v_sad_u16 and lists v_sad_u32, v_sad_hi_u8 and v_msad_u8 as rejected neighbours; #526 (draft) also lists v_sad_u32 as a rejected neighbour. Whichever lands second must drop those lines from its rejected lists, and #531's sad_u8 helper and this PR's sad4_u8 could then be merged into one. Like every shader PR, this appends to the same fixture lists in tests/pixel_aot_check.py, so a later one needs a trivial rebase.

Follow-up: v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8 and v_mqsad_u32_u8 are defined in the same documents in terms of these operations, but they read and write 64-bit and 128-bit register groups, which the vector path does not model yet.

AI assistance: written with Claude (Claude Code). The commands above were run on my own machine.

🤖 Generated with Claude Code

R0Y00 commented Nov 23, 2026

Copy link
Copy Markdown
Owner

v_swap_b32 already has an earlier open implementation in #771, with the same CTest names and its own chained-swap and self-swap controls. Please leave the swap commit out of this branch while #771 is resolved. The separate commits make that easy. The carry-out, 16-bit pack and SAD changes can still be reviewed here. Please retain the per-family controls and keep the changed v_sad_u32 expectations explicit.

rasptum and others added 3 commits November 23, 2026 00:31
…_aot

The three carry-out VOP3 forms lower as a 32-bit wraparound result plus a
per-lane condition written to the lane mask operand, tracked like a
comparison result so v_cndmask_b32 can read it. Semantics from the LLVM 15
AMDGPU backend (uaddo and usubo selection, reversed-operand subrev).
Adds bit-exact draws with 17 negative controls as
pixel_aot_carry_out_{warp,hardware} with its own coverage record, the
LLVM 15 round trip, static refusals, the scanner entries with accept and
refuse checks in tests/rdna2_tools_check.py, and a docs paragraph.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two-source VOP3-only packs: src0 saturates into the low and src1 into
the high 16 bits (layout from the AMD RDNA 2 ISA reference, opcodes
874 and 875; saturation bounds as Mesa documents for the NIR
operations its ACO backend selects these instructions for). Drawn bit
for bit on WARP and hardware as pixel_aot_pack_int16_*, with 15 wrong
references, static controls, the LLVM 15 round trip, scanner and
coverage checks and a docs paragraph. The float packs stay refused.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Three-source VOP3 sums of absolute differences, defined as in the AMD
RDNA 2 ISA reference (opcodes 347, 349, 369): unsigned differences,
accumulation modulo 2^32, v_sad_hi_u8 shifted into the high half and
v_msad_u8 leaving out byte lanes whose reference (src1) byte is zero.
Drawn bit for bit on WARP and hardware as pixel_aot_sad_*, with 18
wrong references, static controls, the LLVM 15 round trip, scanner and
coverage checks and a docs paragraph.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@rasptum
rasptum force-pushed the shader/new-integer-forms branch from 60680aa to 732ee6b Compare November 23, 2026 05:46
@JB2WIN

JB2WIN commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Heads-up for the rebase: v_swap_b32 was merged through #771. It added a draw-swap mode and CTest entries with the same names, pixel_aot_swap_{hardware,warp}. So a94b42c will collide with main and can probably be dropped or reduced to whatever its fixture covers that #771's doesn't. Sorry for the overlap; I hadn't seen this PR when I claimed it. AI-assisted (Claude Code).

R0Y00 commented Nov 23, 2026

Copy link
Copy Markdown
Owner

I fast-forwarded the branch to f16ef39 to resolve the shared pixel fixture conflict. The latest author head already removed the duplicate swap commit. This merge keeps the carry-out, integer pack and SAD fixtures alongside #771's swap, #429's partial uncompressed export and the existing compressed, title-load, 16-bit and 64-bit draw modes. The merged head passed the LLVM 15 binary round trip, Python controls and all nine of those WARP draw modes. Waiting for CI on the updated commit.

@R0Y00
R0Y00 merged commit dc89393 into R0Y00:main Nov 23, 2026
5 checks passed
@rasptum

rasptum commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging, and for resolving the fixture conflict with #429. A note for the record, since this did not get posted before the merge.

Swap. The swap commit was dropped as you asked. I had not seen #771: my overlap search ran against the PRs open when this work started, and #771 opened later. I now re-run that search, plus a check against main, right before every push. The merged branch adds no v_swap_b32 code, test or CTest name; the swap support on main is #771's.

A mistake in an earlier head, fixed before the merge. The pack commit had once placed its draw function inside check_sdwa_integer_draws and cut off that function's run_pixel_batch call, so pixel_aot_sdwa_integer_* (my own #758) passed without drawing anything. bed88fb leaves that function identical to main, and on main now both tests draw all 48 cases again. Sorry about that.

The changed v_sad_u32 expectation. This PR moves v_sad_u32 from refused to lowered, as ABSDIFF(S0.u, S1.u) + S2.u, unsigned, modulo 2^32. It is pinned by the dword group in sad_group() (register and inline accumulator), the signed comparison wrong reference, which must report pixel_mismatch, check_sad_lowering(), the scanner lines in tests/rdna2_tools_check.py and tests/form_coverage_check.py. No test on main expected it to be refused. The open drafts #531 (which reads the ISA text as a signed difference) and #526 list it as a refused neighbour; they now need to drop the forms lowered here from those lists. The SAD section of the description explains the unsigned reading, which matches LLVM 15's umax(a, b) - umin(a, b) + c pattern for V_SAD_U32.

Verification on 732ee6b, Windows 10 Pro 19045, WARP 10.0.19041.5794 and an RTX 3060 (driver 32.0.15.9636), debug layer on:

  • ctest --preset dev --no-tests=error -R '^pixel_aot_': 58 tests, 57 passed, 1 failed (pixel_aot_blend_scalar_hardware, which also fails with main's code on this machine). The six new tests, pixel_aot_swap_* and both pixel_aot_sdwa_integer_* pass on WARP and the RTX 3060.
  • The full suite ran on 66edfcd, the same three commits one clean rebase earlier: 373 tests, 330 passed, 41 capability skips, 2 failed (gpu_alias_lookup_writes_warp, pixel_aot_blend_scalar_hardware, both also failing with main's code here).
  • Controls, the LLVM 15 round trip and the 23 pure-Python checks: exit 0. Ten deliberately wrong lowerings in a scratch copy of the translator each failed their WARP draw with a pixel mismatch.

I updated the description to match the merged commits. The title still says nine forms and swap; I left it because CONTRIBUTING asks not to rename pull requests.

AI-assisted (Claude Code); the commands were run on my own machine.

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.

4 participants