Shaders: decode GFX10 packed inline constants by operand type #637

Manually merged
github merged 1 commit from gh-pr/637/head into gh-pr/637/base 2026-11-26 04:11:00 +00:00
Owner

@⁠AlanQiang0418 on GitHub · 2026-11-24 06:02 UTC · original
AlanQiang0418:codex/gfx10-packed-inline-constants → main · +45 −21 · 2 files · 1 commits · merged 2026-11-24 08:19 UTC

A synthetic v_pk_add_f16 on main (d2a4bae) added the inline constant 1/(2π) to zero and returned 0x31183118 on the hardware adapter. GFX10's default half selectors should produce 0x00003118. The translator duplicated the FP16 bits before applying the selectors. It also used that FP16 representation for packed integer instructions, which interpret the same encoding as a full FP32 bit pattern. LLVM’s GFX10 encoding table

The change shares the existing FP16 constant decoding with packed float instructions and uses the existing 32-bit operand reader for packed integer instructions. The regression test adds the same inline constant to zero in three synthetic shaders.

Instruction Source halves selected Expected and observed after fix
v_pk_add_f16 Low, high 0x00003118
v_pk_add_f16 Low, low 0x31183118
v_pk_add_u16 Low, high 0x3e22f983

All three cases passed DXIL validation and ran on the hardware adapter and WARP on a Windows machine with an RTX 5080. cargo test --locked -p victory-shader reported 70 passed. Four differential tests skipped their comparisons because the console compiler was unavailable. I did not run the game.

Two open PRs touch this helper. #78 moves the existing half duplication into a shared helper. #465 adds dot-product callers, which will need to select the operand representation when rebasing. Mixed-precision conversion PR · Dot-product PR

**@⁠AlanQiang0418** on GitHub · 2026-11-24 06:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/637) `AlanQiang0418:codex/gfx10-packed-inline-constants` → `main` · +45 −21 · 2 files · 1 commits · merged 2026-11-24 08:19 UTC A synthetic `v_pk_add_f16` on main (`d2a4bae`) added the inline constant `1/(2π)` to zero and returned `0x31183118` on the hardware adapter. GFX10's default half selectors should produce `0x00003118`. The translator duplicated the FP16 bits before applying the selectors. It also used that FP16 representation for packed integer instructions, which interpret the same encoding as a full FP32 bit pattern. [LLVM’s GFX10 encoding table](https://github.com/llvm/llvm-project/blob/llvmorg-22.1.0/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp#L3079-L3127) The change shares the existing FP16 constant decoding with packed float instructions and uses the existing 32-bit operand reader for packed integer instructions. The regression test adds the same inline constant to zero in three synthetic shaders. | Instruction | Source halves selected | Expected and observed after fix | | --- | --- | --- | | `v_pk_add_f16` | Low, high | `0x00003118` | | `v_pk_add_f16` | Low, low | `0x31183118` | | `v_pk_add_u16` | Low, high | `0x3e22f983` | All three cases passed DXIL validation and ran on the hardware adapter and WARP on a Windows machine with an RTX 5080. `cargo test --locked -p victory-shader` reported 70 passed. Four differential tests skipped their comparisons because the console compiler was unavailable. I did not run the game. Two open PRs touch this helper. #78 moves the existing half duplication into a shared helper. #465 adds dot-product callers, which will need to select the operand representation when rebasing. [Mixed-precision conversion PR](https://git.gtahub.st/github/Marvisak--VIctory/pulls/78) · [Dot-product PR](https://git.gtahub.st/github/Marvisak--VIctory/pulls/465)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:10:58 +00:00
github manually merged commit a0efd2d377 into gh-pr/637/base 2026-11-26 04:11:00 +00:00
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-24 06:06 UTC · original

RDNA2 hardware confirmation of the table: all three expected values are what gfx1036 returns, from the hardware rather than from LLVM's encoding table.

Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) adds each inline constant to a zero VGPR. RDNA2 desktop silicon, not the console's. No game data.

Instruction Hardware Your expected
v_pk_add_f16 v, 1/(2π), 0 (default op_sel_hi) 0x00003118 0x00003118
v_pk_add_f16 v, 1/(2π), 0 op_sel_hi:[0,1] 0x31183118 0x31183118
v_pk_add_u16 v, 1/(2π), 0 0x3e22f983 0x3e22f983
v_pk_add_u16 v, 1/(2π), 0 op_sel_hi:[0,1] 0xf983f983
v_pk_add_u16 v, 1.0, 0 0x3f800000
v_pk_add_f16 v, 1.0, 0 0x00003c00
v_pk_add_u16 v, -1, 0 (integer inline) 0xffffffff
v_pk_add_u16 v, 1, 0 (integer inline) 0x00000001

So a float inline constant in a packed float op is {0x0000, f16}, in a packed integer op it is the full f32 pattern, and an integer inline constant is its 32-bit value (-1 fills both halves). That is what the new float argument gives.

The same kernel shape also shows v_fma_mix* and v_pack_b32_f16 see {0x0000, f16} (details on #78), which matches your f16_operand.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.

**@⁠Lyrnc** on GitHub · 2026-11-24 06:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/637#issuecomment-7123599245) RDNA2 hardware confirmation of the table: **all three expected values are what gfx1036 returns**, from the hardware rather than from LLVM's encoding table. **Setup.** AMD Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036 (RDNA2)**, AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) adds each inline constant to a zero VGPR. RDNA2 desktop silicon, not the console's. No game data. | Instruction | Hardware | Your expected | |---|---|---| | `v_pk_add_f16 v, 1/(2π), 0` (default `op_sel_hi`) | `0x00003118` | `0x00003118` | | `v_pk_add_f16 v, 1/(2π), 0 op_sel_hi:[0,1]` | `0x31183118` | `0x31183118` | | `v_pk_add_u16 v, 1/(2π), 0` | `0x3e22f983` | `0x3e22f983` | | `v_pk_add_u16 v, 1/(2π), 0 op_sel_hi:[0,1]` | `0xf983f983` | | | `v_pk_add_u16 v, 1.0, 0` | `0x3f800000` | | | `v_pk_add_f16 v, 1.0, 0` | `0x00003c00` | | | `v_pk_add_u16 v, -1, 0` (integer inline) | `0xffffffff` | | | `v_pk_add_u16 v, 1, 0` (integer inline) | `0x00000001` | | So a float inline constant in a packed float op is `{0x0000, f16}`, in a packed integer op it is the full f32 pattern, and an integer inline constant is its 32-bit value (-1 fills both halves). That is what the new `float` argument gives. The same kernel shape also shows `v_fma_mix*` and `v_pack_b32_f16` see `{0x0000, f16}` (details on #78), which matches your `f16_operand`. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
Author
Owner

@⁠pickles976 on GitHub · 2026-11-24 06:16 UTC · original

Cross-check result from the ivall/xcl side: this class is absent here, verified semantically rather than by grep. Our 16-bit VALU model (valu16 + code32) puts inline f16 constants (codes 240–248) in the low half with OP_SEL selecting the high half per source (which then reads 0 — matching hardware), hands integer instructions the f32 bit pattern of the same code, and the instruction spec carries f16 VALU only in the 16-bit encoding (no VOP3 dual-half packed form on gfx10), so OPSEL handling has no second path to diverge on. Noting it in your thread the same way I noted the GetModuleFileNameA one: the shared-site map only earns trust if the good news gets posted too.

**@⁠pickles976** on GitHub · 2026-11-24 06:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/637#issuecomment-7123769126) Cross-check result from the ivall/xcl side: **this class is absent here**, verified semantically rather than by grep. Our 16-bit VALU model (`valu16` + `code32`) puts inline f16 constants (codes 240–248) in the low half with `OP_SEL` selecting the high half per source (which then reads 0 — matching hardware), hands integer instructions the f32 bit pattern of the same code, and the instruction spec carries f16 VALU **only** in the 16-bit encoding (no VOP3 dual-half packed form on gfx10), so OPSEL handling has no second path to diverge on. Noting it in your thread the same way I noted the `GetModuleFileNameA` one: the shared-site map only earns trust if the good news gets posted too.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!637
No description provided.