rdna2spirv: a v_interp_p2_f16 destination op_sel bit is ignored #1729

Closed
github-bot wants to merge 1 commit from gh-pr/1729/head into gh-pr/1729/base
Owner

@⁠Undefined3301 on GitHub · 2026-11-25 09:55 UTC · original
vinterp-p2-f16-op-sel → main · +25 −1 · 3 files · 1 commits · closed without merging

What and why

same_encoding refused a v_interp_p2_f16 whose destination op_sel bit (word 0 bit 14) is set in the blob, with "the blob holds ..., LLVM printed ...". The game's compiler stores the bit; llvm-mc re-encodes its 0 default. The op keeps the high half of vdst (measured on gfx1036 with tools/hw_oracle: a preset 0xdead high half survived every case), so the bit changes nothing; the high bit in byte 5 selects the attribute half and the translator reads it. The rule accepts that one bit and nothing else.

On a 1.0.2.1 copy this translated 194 of the 1,923 pipeline-library graphics programs missing at c7e82e26e (spirv/fspx_gfx 16,914 -> 17,108). The rest still stop at a fall-through into undecodable words or have no container.

Tests

  • python -m unittest discover -s tests/semantic -p test_printed_encoding.py -> 9 tests, OK.
  • python -I scripts/run_semantic_tests.py tests/semantic -> 487 files, 6,280 tests, 0 files failed (on c7e82e26e + this change).
  • The new case translates a hand-written listing with the bit and checks that v_interp_p1_f16 still refuses it. The contract row is in docs/design.md ("v_interp_p2_f16 destination op_sel").

Claimed in the coordination issue as SHADER-VINTERP-P2-F16-OP-SEL: #1608

AI-assisted (Claude Code).

**@⁠Undefined3301** on GitHub · 2026-11-25 09:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1729) `vinterp-p2-f16-op-sel` → `main` · +25 −1 · 3 files · 1 commits · closed without merging ### What and why `same_encoding` refused a `v_interp_p2_f16` whose destination `op_sel` bit (word 0 bit 14) is set in the blob, with "the blob holds ..., LLVM printed ...". The game's compiler stores the bit; llvm-mc re-encodes its 0 default. The op keeps the high half of `vdst` (measured on gfx1036 with `tools/hw_oracle`: a preset `0xdead` high half survived every case), so the bit changes nothing; the `high` bit in byte 5 selects the attribute half and the translator reads it. The rule accepts that one bit and nothing else. On a 1.0.2.1 copy this translated 194 of the 1,923 pipeline-library graphics programs missing at `c7e82e26e` (`spirv/fspx_gfx` 16,914 -> 17,108). The rest still stop at a fall-through into undecodable words or have no container. ### Tests - `python -m unittest discover -s tests/semantic -p test_printed_encoding.py` -> 9 tests, OK. - `python -I scripts/run_semantic_tests.py tests/semantic` -> 487 files, 6,280 tests, 0 files failed (on `c7e82e26e` + this change). - The new case translates a hand-written listing with the bit and checks that `v_interp_p1_f16` still refuses it. The contract row is in `docs/design.md` ("`v_interp_p2_f16` destination op_sel"). Claimed in the coordination issue as `SHADER-VINTERP-P2-F16-OP-SEL`: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 AI-assisted (Claude Code).
The compiler stores VOP3 destination op_sel (word 0 bit 14) set on v_interp_p2_f16 and llvm-mc re-encodes its 0 default, so same_encoding refused every pipeline-library PS build that used one. The op keeps the high half of vdst (measured on gfx1036 with tools/hw_oracle: a preset 0xdead high half survived every case), so the bit changes nothing; the high bit in byte 5 selects the attribute half and is read. Ignore the bit for this op only. 194 more of the 1,923 native graphics programs missing at c7e82e26e translate (17,108 against 16,914 in spirv/fspx_gfx).

Test: tests/semantic/test_printed_encoding.py::test_interp_p2_f16_op_sel_hi_bit_is_ignored (v_interp_p1_f16 still refuses). Contract row in docs/design.md.

AI-assisted (Claude Code).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:02:48 +00:00
github-bot closed this pull request 2026-11-26 10:02:48 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 10:33 UTC · original

Tested 4be07cb1c on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 57ba40bd6 (translator-only PR; binaries from the build at 66d4f5aa3):

  • tests/semantic/test_printed_encoding.py: OK at this head; copied onto main it errors 1 — the v_interp_p2_f16 destination op_sel case is refused there.
  • GPU smoke on the interpolation fixtures, --filter ps_interp on MoltenVK 1.4.2: 3/3 PASS (ps_interp_f16_high f16 low/high halves within 2e-3, ps_interp_f32_mods 4096/4096 exact, ps_interp_mov_mods 4096/4096 exact).
  • Not run: the corpus translation count (needs the game data); the semantic fixture is the evidence for the encoding rule.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 10:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1729#issuecomment-7159861010) Tested `4be07cb1c` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `57ba40bd6` (translator-only PR; binaries from the build at `66d4f5aa3`): - `tests/semantic/test_printed_encoding.py`: **OK** at this head; copied onto `main` it errors **1** — the `v_interp_p2_f16` destination `op_sel` case is refused there. - GPU smoke on the interpolation fixtures, `--filter ps_interp` on **MoltenVK 1.4.2**: **3/3 PASS** (`ps_interp_f16_high` f16 low/high halves within 2e-3, `ps_interp_f32_mods` 4096/4096 exact, `ps_interp_mov_mods` 4096/4096 exact). - Not run: the corpus translation count (needs the game data); the semantic fixture is the evidence for the encoding rule. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠lixonik on GitHub · 2026-11-25 10:34 UTC · original · reviewed

Independent A/B at 4be07cb1 against merge base 3de22a19. With LLVM 21.1.8 under WSL targeting gfx1013, the two synthetic instruction encodings that differ at word-0 bit 14 produced identical disassembly and identical printed bytes. I also flipped all 64 bits one at a time in the same instruction: the base accepted none of the mutations, and the PR accepted only bit 14. The nine printed-encoding tests passed on the PR, and the new case raised the expected encoding mismatch when run against the base.

AI-assisted. CPU-only checks using a synthetic instruction, no shader corpus or GPU run.

**@⁠lixonik** on GitHub · 2026-11-25 10:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1729#pullrequestreview-6055948068) · **reviewed** Independent A/B at `4be07cb1` against merge base `3de22a19`. With LLVM 21.1.8 under WSL targeting gfx1013, the two synthetic instruction encodings that differ at word-0 bit 14 produced identical disassembly and identical printed bytes. I also flipped all 64 bits one at a time in the same instruction: the base accepted none of the mutations, and the PR accepted only bit 14. The nine printed-encoding tests passed on the PR, and the new case raised the expected encoding mismatch when run against the base. AI-assisted. CPU-only checks using a synthetic instruction, no shader corpus or GPU run.
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 10:53 UTC · original · approved these changes

### Clean-Room & Technical Verification

  • Mergeability: 3-way merge against upstream main (bcaa13dad) is 100% clean with zero merge conflicts.
  • Clean-Room Compliance: 100% clean-room. Synthetic instruction encodings and unit test cases only; zero retail files, game data, or keys (check_no_game_data.py clean).
  • Technical Correctness & Hardware Alignment:
    • same_encoding() in tools/rdna2spirv.py masks out diff &= ~(1 << 14) specifically when op == "v_interp_p2_f16".
    • For v_interp_p2_f16, the compiler sets VOP3 destination op_sel (bit 14), while llvm-mc re-encodes to default 0. Because v_interp_p2_f16 preserves the high 16 bits of vdst (verified on hardware via tools/hw_oracle), bit 14 does not alter runtime execution; the attribute half selection is governed by the high bit in byte 5.
    • Contract updated with full rationale in docs/design.md.
  • Test Coverage:
    • tests/semantic/test_printed_encoding.py: Passes with test_interp_p2_f16_op_sel_hi_bit_is_ignored.
    • Confirmed v_interp_p1_f16 strictly continues to refuse the bit, keeping the exception tightly scoped.

LGTM! Approved.

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 10:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1729#pullrequestreview-6056240587) · **approved these changes** ### Clean-Room & Technical Verification - **Mergeability**: 3-way merge against upstream `main` (`bcaa13dad`) is 100% clean with zero merge conflicts. - **Clean-Room Compliance**: 100% clean-room. Synthetic instruction encodings and unit test cases only; zero retail files, game data, or keys (`check_no_game_data.py` clean). - **Technical Correctness & Hardware Alignment**: - `same_encoding()` in `tools/rdna2spirv.py` masks out `diff &= ~(1 << 14)` specifically when `op == "v_interp_p2_f16"`. - For `v_interp_p2_f16`, the compiler sets VOP3 destination `op_sel` (bit 14), while `llvm-mc` re-encodes to default 0. Because `v_interp_p2_f16` preserves the high 16 bits of `vdst` (verified on hardware via `tools/hw_oracle`), bit 14 does not alter runtime execution; the attribute half selection is governed by the `high` bit in byte 5. - Contract updated with full rationale in `docs/design.md`. - **Test Coverage**: - `tests/semantic/test_printed_encoding.py`: Passes with `test_interp_p2_f16_op_sel_hi_bit_is_ignored`. - Confirmed `v_interp_p1_f16` strictly continues to refuse the bit, keeping the exception tightly scoped. LGTM! Approved.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 12:00 UTC · original

A data point on LLVM's side of the dispute, plus two small test notes. This is from llvm-mc 23.1.5 on Windows; the RX 7900 XT here is gfx1100, which has no VOP3 v_interp_p2_f16, so I can't measure the hardware. No game files.

What llvm-mc 23.1.5 does with the bit (word 0 bit 14 of v_interp_p2_f16 v16, v1, attr2.z, v15 high):

  • Disassembling 10 40 5a d7 82 03 3e 04 for gfx1030, gfx1013 and gfx1036 gives the same text as 10 00 ..., and it re-encodes as [0x10,0x00,0x5a,0xd7,...]. The bit is dropped without any op_sel in the output.
  • Assembling v_interp_p2_f16 v16, v1, attr2.z, v15 high op_sel:[0,0,0,1] for gfx1030 is refused: error: not a valid operand.

So LLVM models no operand there on gfx10, which fits treating it as ignored. It is LLVM's model, though, not a hardware measurement. The gfx1036 measurement the description quotes is SHADER-430's (the comment around tools/rdna2spirv.py 11456). That probe (tools/interp_hw_probe.py) assembles v_interp_p2_f16 v5, v21, attrN.c, v3 [high] from text with no op_sel, so the bit was presumably clear in what it ran. It shows that the high half of vdst is kept, not what the bit itself does.

Two notes on test_interp_p2_f16_op_sel_hi_bit_is_ignored:

  • Naming. The test calls bit 14 op_sel_hi[2] and says it names the third source's half. That is VOP3P naming. v_interp_p2_f16 is VOP3 (byte 3 = 0xd7), where bit 14 is OPSEL[3], the destination select. The code comment and the docs/design.md row in this PR call it the destination op_sel, so the test's explanation contradicts the change.
  • Negative check. same_encoding(raw, printed, "v_interp_p1_f16", 4) uses a name RDNA2 doesn't have; the f16 pair is v_interp_p1ll_f16 / v_interp_p1lv_f16. It returns False for any name other than the exempt one, so it doesn't show that real neighbours still refuse the bit. v_interp_p1ll_f16, or v_fma_f16 with a destination op_sel, would make it a real check.
**@⁠adrianmjim** on GitHub · 2026-11-25 12:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1729#issuecomment-7161802374) A data point on LLVM's side of the dispute, plus two small test notes. This is from llvm-mc 23.1.5 on Windows; the RX 7900 XT here is gfx1100, which has no VOP3 `v_interp_p2_f16`, so I can't measure the hardware. No game files. **What llvm-mc 23.1.5 does with the bit** (word 0 bit 14 of `v_interp_p2_f16 v16, v1, attr2.z, v15 high`): - Disassembling `10 40 5a d7 82 03 3e 04` for gfx1030, gfx1013 and gfx1036 gives the same text as `10 00 ...`, and it re-encodes as `[0x10,0x00,0x5a,0xd7,...]`. The bit is dropped without any `op_sel` in the output. - Assembling `v_interp_p2_f16 v16, v1, attr2.z, v15 high op_sel:[0,0,0,1]` for gfx1030 is refused: `error: not a valid operand`. So LLVM models no operand there on gfx10, which fits treating it as ignored. It is LLVM's model, though, not a hardware measurement. The gfx1036 measurement the description quotes is SHADER-430's (the comment around `tools/rdna2spirv.py` 11456). That probe (`tools/interp_hw_probe.py`) assembles `v_interp_p2_f16 v5, v21, attrN.c, v3 [high]` from text with no `op_sel`, so the bit was presumably clear in what it ran. It shows that the high half of `vdst` is kept, not what the bit itself does. **Two notes on `test_interp_p2_f16_op_sel_hi_bit_is_ignored`:** - **Naming.** The test calls bit 14 `op_sel_hi[2]` and says it names the third source's half. That is VOP3P naming. `v_interp_p2_f16` is VOP3 (byte 3 = `0xd7`), where bit 14 is `OPSEL[3]`, the destination select. The code comment and the `docs/design.md` row in this PR call it the destination op_sel, so the test's explanation contradicts the change. - **Negative check.** `same_encoding(raw, printed, "v_interp_p1_f16", 4)` uses a name RDNA2 doesn't have; the f16 pair is `v_interp_p1ll_f16` / `v_interp_p1lv_f16`. It returns False for any name other than the exempt one, so it doesn't show that real neighbours still refuse the bit. `v_interp_p1ll_f16`, or `v_fma_f16` with a destination op_sel, would make it a real check.
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-25 15:19 UTC · original

Independent verification of head 4be07cb1c (Windows 11 Pro 26300, Python 3.14.4).

  • python -m unittest discover -s tests/semantic -p test_printed_encoding.py: 9/9 OK at this head.
  • The same file against main's tools/rdna2spirv.py: 1 error, test_interp_p2_f16_op_sel_hi_bit_is_ignored (the stored bit 14 is refused there).
  • Full suite at this head, python -I scripts/run_semantic_tests.py -j 4 tests/semantic: 487 files, 6280 tests, 0 files failed.
  • On the negative-check note above: I called same_encoding directly with the test's stored/printed pair (bit 14 set vs clear). It returns True only for v_interp_p2_f16, and False for the real RDNA2 neighbours v_interp_p1ll_f16, v_interp_p1lv_f16 and v_fma_f16. So the exemption is scoped to the one op; swapping the test's v_interp_p1_f16 (not an RDNA2 name) for one of those would make that assertion actually test it. The test comment's op_sel_hi[2] naming point also still stands at this head.

No game files. AI-assisted (Claude Code).

**@⁠Tyrannys** on GitHub · 2026-11-25 15:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1729#issuecomment-7166672625) **Independent verification** of head `4be07cb1c` (Windows 11 Pro 26300, Python 3.14.4). - `python -m unittest discover -s tests/semantic -p test_printed_encoding.py`: **9/9 OK** at this head. - The same file against `main`'s `tools/rdna2spirv.py`: **1 error**, `test_interp_p2_f16_op_sel_hi_bit_is_ignored` (the stored bit 14 is refused there). - Full suite at this head, `python -I scripts/run_semantic_tests.py -j 4 tests/semantic`: **487 files, 6280 tests, 0 files failed**. - On the negative-check note above: I called `same_encoding` directly with the test's stored/printed pair (bit 14 set vs clear). It returns `True` only for `v_interp_p2_f16`, and `False` for the real RDNA2 neighbours `v_interp_p1ll_f16`, `v_interp_p1lv_f16` and `v_fma_f16`. So the exemption is scoped to the one op; swapping the test's `v_interp_p1_f16` (not an RDNA2 name) for one of those would make that assertion actually test it. The test comment's `op_sel_hi[2]` naming point also still stands at this head. No game files. AI-assisted (Claude Code).
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-25 17:37 UTC · original · reviewed

The bit this PR accepts is VOP3 OPSEL[3], the destination half, and AMD documents it for this op. In the
"RDNA 2" Instruction Set Architecture guide (30 November 2020): Table 82 (VOP3A) gives OPSEL [14:11] with
"[14] = dest", Table 21 in 6.2.5 lists V_INTERP_P2_F16 among the opcodes usable with OPSEL, and the
V_INTERP_P2_F16 entry says: "If op_sel[3] is 1 Result is written to 16 MSBs of destination VGPR and lo 16
bits are preserved." So the bit is not a no-op: it moves the result to the high half.

The corpus agrees. Counts over the 194 pipeline-library programs this PR unblocks (1.0.2.1, 5e95fa2f4,
aggregate counts only, listing order):

  • 352 v_interp_p2_f16 carry word-0 bit 14, at least one in each of the 194 programs.
  • For 334 of them, the previous write to the same VGPR is another v_interp_p2_f16 with the bit clear and no
    read in between. With the bit ignored, that first interpolation would be dead code 334 times.
  • The first reader is a texture sample with 16-bit coordinates 148 times (140 of the 194 programs), a plain
    register copy 184 times, and an f16 read of the high half 18 times.

So each pair packs two f16 results low/high. With the bit ignored, these programs translate and pass
spirv-val, but the second result overwrites the first and the high half stays stale.

On the evidence quoted in the description: tools/interp_hw_probe.py assembles the op from text, and llvm-mc
cannot emit the bit (21.1.8 rejects op_sel:[0,0,0,1] on this op for gfx1013 and gfx1030), so the SHADER-430
measurement ran with the bit clear, as adrianmjim noted. The synthetic draw ecox982745 reported in #1608
(translator output on an RTX 4090, not RDNA2 hardware) matches the high-half reference on 0 of 4,096 pixels.

Suggested change: restore the bit from the blob as op_sel:[0,0,0,1] on this op only (in
check_printed_encodings and both re-anchor loops), then write the result with
write_half16(a[0], ..., dhi), which keeps the low half. Source selects (bits 11 to 13) should stay refused.

I have a local prototype with a synthetic test, no game data: a low/high pair packs 0x48803f00, where the
rule in this PR gives 0xdead4880. With it the same 194 programs translate. Happy to push it to your branch
or open it as a follow-up, whichever you prefer. I have not measured the bit on gfx10 hardware; a hand-encoded
word through tools/hw_oracle would confirm the documented behaviour.

AI-assisted: yes (Claude Code read the ISA guide, counted the corpus and wrote the prototype; a second agent checked this text; I reviewed it).

**@⁠MoonEyes** on GitHub · 2026-11-25 17:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1729#pullrequestreview-6062197382) · **reviewed** The bit this PR accepts is VOP3 `OPSEL[3]`, the destination half, and AMD documents it for this op. In the "RDNA 2" Instruction Set Architecture guide (30 November 2020): Table 82 (VOP3A) gives `OPSEL [14:11]` with "[14] = dest", Table 21 in 6.2.5 lists `V_INTERP_P2_F16` among the opcodes usable with OPSEL, and the `V_INTERP_P2_F16` entry says: "If op_sel[3] is 1 Result is written to 16 MSBs of destination VGPR and lo 16 bits are preserved." So the bit is not a no-op: it moves the result to the high half. The corpus agrees. Counts over the 194 pipeline-library programs this PR unblocks (1.0.2.1, `5e95fa2f4`, aggregate counts only, listing order): - 352 `v_interp_p2_f16` carry word-0 bit 14, at least one in each of the 194 programs. - For 334 of them, the previous write to the same VGPR is another `v_interp_p2_f16` with the bit clear and no read in between. With the bit ignored, that first interpolation would be dead code 334 times. - The first reader is a texture sample with 16-bit coordinates 148 times (140 of the 194 programs), a plain register copy 184 times, and an f16 read of the high half 18 times. So each pair packs two f16 results low/high. With the bit ignored, these programs translate and pass `spirv-val`, but the second result overwrites the first and the high half stays stale. On the evidence quoted in the description: `tools/interp_hw_probe.py` assembles the op from text, and llvm-mc cannot emit the bit (21.1.8 rejects `op_sel:[0,0,0,1]` on this op for gfx1013 and gfx1030), so the SHADER-430 measurement ran with the bit clear, as adrianmjim noted. The synthetic draw ecox982745 reported in #1608 (translator output on an RTX 4090, not RDNA2 hardware) matches the high-half reference on 0 of 4,096 pixels. Suggested change: restore the bit from the blob as `op_sel:[0,0,0,1]` on this op only (in `check_printed_encodings` and both re-anchor loops), then write the result with `write_half16(a[0], ..., dhi)`, which keeps the low half. Source selects (bits 11 to 13) should stay refused. I have a local prototype with a synthetic test, no game data: a low/high pair packs `0x48803f00`, where the rule in this PR gives `0xdead4880`. With it the same 194 programs translate. Happy to push it to your branch or open it as a follow-up, whichever you prefer. I have not measured the bit on gfx10 hardware; a hand-encoded word through `tools/hw_oracle` would confirm the documented behaviour. AI-assisted: yes (Claude Code read the ISA guide, counted the corpus and wrote the prototype; a second agent checked this text; I reviewed it).
Author
Owner

@⁠Undefined3301 on GitHub · 2026-11-25 21:00 UTC · original

Closing to free the single open-PR slot that accounts without 2 merged PRs are limited to. The op_sel premise was questioned in review; the branch stays available. The V# 48-bit range fix goes first.

**@⁠Undefined3301** on GitHub · 2026-11-25 21:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1729#issuecomment-7174473054) Closing to free the single open-PR slot that accounts without 2 merged PRs are limited to. The op_sel premise was questioned in review; the branch stays available. The V# 48-bit range fix goes first.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.