fix(recompiler): accept byte source selectors on v_cvt_f16_u16 SDWA #2838

Merged
MarcZX10 merged 1 commit from upstream-pr/2838 into main 2026-10-10 23:07:03 +00:00
MarcZX10 commented 2026-10-10 16:24:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T16:24:20Z.


What

Fixes #2747. The VOP1 SDWA rule for VCvtF16U16 now accepts byte source selectors. The existing source path zero-extends the selected byte before conversion; the test checks all four byte lanes, including word destinations with preserved bits.

This carries forward the author-attributed fix from #2695, which was closed during the intake pause.

Tested

  • Linux x86-64, Debian GCC 12.2, Release on current main: built agc_driver_sdwa_cvt_f16_u16_tests; the test ran on llvmpipe (LLVM 15.0.6) and passed (1/1). All four byte selectors were exercised.
  • Red/green baseline on the rebased source: with the decoder rule reverted to upstream/main, the same test failed with the reported unsupported selector (dst selector 4, unused 2, source selector 3); restoring the rule made it pass.
  • Independent hardware evidence from fma-rc: hardware-oracle measurements on a Radeon 610M (RDNA2) matched recompiler results on both that GPU and an RTX 5080, with zero differences across 2,048 outputs from eight byte-select forms. The four PR encodings are included. Full setup, results, and limits. I have not reproduced this hardware run myself.
  • tools/check_conventions.py --base upstream/main and git diff --check passed.
  • The issue reporter reports that the fix lets Silent Hill: Townfall shaders recompile and reach first presentation on Windows/RTX 3070. That title result was not reproduced in this environment.
  • The original macOS Intel run failed on the unrelated write_watch_threads timeout. Follow-up #2846 now passes the repeated write-watch job on Intel and arm64; the original failed run remains in this PR's check history.

Checklist

  • Based on current main; no open PR implements this opcode fix
  • One topic
  • No comments added to code
  • No investigation files added
  • No third-party code added
  • Generic shader decoder behavior
  • Depends on: none
  • AI-assisted: yes (original patch co-authored with Claude; Codex assisted review and validation; MarcZX100 reviewed the carried patch)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4812700246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2838). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T16:24:20Z. --- ### What Fixes #2747. The VOP1 SDWA rule for `VCvtF16U16` now accepts byte source selectors. The existing source path zero-extends the selected byte before conversion; the test checks all four byte lanes, including word destinations with preserved bits. This carries forward the author-attributed fix from [#2695](https://github.com/boykopovar/AnyPS5/pull/2695), which was closed during the intake pause. ### Tested - Linux x86-64, Debian GCC 12.2, Release on current `main`: built `agc_driver_sdwa_cvt_f16_u16_tests`; the test ran on llvmpipe (LLVM 15.0.6) and passed (1/1). All four byte selectors were exercised. - Red/green baseline on the rebased source: with the decoder rule reverted to `upstream/main`, the same test failed with the reported unsupported selector (`dst selector 4`, `unused 2`, `source selector 3`); restoring the rule made it pass. - Independent hardware evidence from fma-rc: hardware-oracle measurements on a Radeon 610M (RDNA2) matched recompiler results on both that GPU and an RTX 5080, with zero differences across 2,048 outputs from eight byte-select forms. The four PR encodings are included. [Full setup, results, and limits](https://github.com/boykopovar/AnyPS5/pull/2838#issuecomment-6099825860). I have not reproduced this hardware run myself. - `tools/check_conventions.py --base upstream/main` and `git diff --check` passed. - The issue reporter reports that the fix lets Silent Hill: Townfall shaders recompile and reach first presentation on Windows/RTX 3070. That title result was not reproduced in this environment. - The original macOS Intel run failed on the unrelated `write_watch_threads` timeout. Follow-up [#2846](https://github.com/boykopovar/AnyPS5/pull/2846) now passes the repeated write-watch job on Intel and arm64; the original failed run remains in this PR's check history. ### Checklist - [x] Based on current `main`; no open PR implements this opcode fix - [x] One topic - [x] No comments added to code - [x] No investigation files added - [x] No third-party code added - [x] Generic shader decoder behavior - [x] Depends on: none - [x] AI-assisted: yes (original patch co-authored with Claude; Codex assisted review and validation; MarcZX100 reviewed the carried patch)
MarcZX10 commented 2026-10-10 16:34:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T16:34:56Z.


The macOS Intel write_watch_threads failure in this PR is covered by the separate test reliability follow-up #2846. Its full repeated write-watch job now passes on both macOS Intel and arm64. The current failure on this PR is from its earlier run; GitHub would not rerun that workflow. The shader changes and their Linux Vulkan regression test are unaffected.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099753923 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2838#issuecomment-6099753923). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T16:34:56Z. --- The macOS Intel `write_watch_threads` failure in this PR is covered by the separate test reliability follow-up [#2846](https://github.com/boykopovar/AnyPS5/pull/2846). Its full repeated write-watch job now passes on both macOS Intel and arm64. The current failure on this PR is from its earlier run; GitHub would not rerun that workflow. The shader changes and their Linux Vulkan regression test are unaffected.
fma-rc commented 2026-10-10 16:43:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T16:43:08Z.


Hardware measurement for this, since the PR's expected values come from a host-side model: on RDNA2 the byte selects behave as the PR assumes, and the recompiler with this PR gives the same bits.

Setup: PR head ef5221a1 merged onto main 57f96fd2. Arch Linux, GCC 16.2.1, Release. Hardware rows from tools/hw-oracle on a Radeon 610M (gfx1036, RDNA2), DX10_CLAMP=1, f32 denormals flushed, f16 denormals kept, round to nearest; IEEE=0 and IEEE=1, wave32 and wave64 all give the same bits. Recompiler runs on an RTX 5080 (615.78.08) and on the Radeon 610M (RADV, Mesa 26.1.4).

Measured: input v4 = b | (b^0x55)<<8 | (b^0xaa)<<16 | (b^0xff)<<24 for all 256 values of b, so every byte lane sees every value; destinations preloaded with 0xabcd1234.

Form b=0x00 b=0x01 b=0x7f b=0x80 b=0xff
dst_sel:WORD_0 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_3 abcd5bf8 abcd5bf0 abcd5800 abcd57f0 abcd0000
dst_sel:DWORD src0_sel:BYTE_0 00000000 00003c00 000057f0 00005800 00005bf8
dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_1 55501234 55401234 51401234 5aa81234 59501234
dst_sel:DWORD src0_sel:BYTE_2 00005950 00005958 00005aa8 00005140 00005550
dst_sel:DWORD src0_sel:BYTE_0, sext(v4) 00000000 00003c00 000057f0 00007bfc 00007c00
dst_sel:DWORD src0_sel:BYTE_3, sext(v4) 00007c00 00007c00 00007bfc 000057f0 00000000
dst_sel:WORD_0 dst_unused:UNUSED_PAD src0_sel:BYTE_1 00005550 00005540 00005140 00005aa8 00005950
dst_sel:WORD_1 dst_unused:UNUSED_SEXT src0_sel:BYTE_2 59500000 59580000 5aa80000 51400000 55500000

The first four rows are the four encodings in this PR's test. The byte is zero-extended (255 gives 0x5bf8, 255.0), and a sign-extended byte is converted as the u16 it becomes (0xff80 gives 0x7bfc, 0xffff rounds to 0x7c00).

Run RTX 5080 RADV, Radeon 610M
agc_driver_sdwa_cvt_f16_u16_tests passes passes
Temporary test: the eight forms above through the recompiler, 256 rows each, compared with the hardware bits 0 of 2,048 results differ 0 of 2,048 results differ

Not measured: the SDWA clamp bit, source selectors WORD_0/WORD_1 (not changed here), and round modes other than nearest (every byte value is exact in f16; only the sign-extended rows round).

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099825860 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2838#issuecomment-6099825860). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-10T16:43:08Z. --- Hardware measurement for this, since the PR's expected values come from a host-side model: on RDNA2 the byte selects behave as the PR assumes, and the recompiler with this PR gives the same bits. **Setup:** PR head ef5221a1 merged onto `main` 57f96fd2. Arch Linux, GCC 16.2.1, Release. Hardware rows from `tools/hw-oracle` on a Radeon 610M (gfx1036, RDNA2), DX10_CLAMP=1, f32 denormals flushed, f16 denormals kept, round to nearest; IEEE=0 and IEEE=1, wave32 and wave64 all give the same bits. Recompiler runs on an RTX 5080 (615.78.08) and on the Radeon 610M (RADV, Mesa 26.1.4). **Measured:** input `v4 = b | (b^0x55)<<8 | (b^0xaa)<<16 | (b^0xff)<<24` for all 256 values of `b`, so every byte lane sees every value; destinations preloaded with `0xabcd1234`. | Form | b=0x00 | b=0x01 | b=0x7f | b=0x80 | b=0xff | |---|---|---|---|---|---| | `dst_sel:WORD_0 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_3` | `abcd5bf8` | `abcd5bf0` | `abcd5800` | `abcd57f0` | `abcd0000` | | `dst_sel:DWORD src0_sel:BYTE_0` | `00000000` | `00003c00` | `000057f0` | `00005800` | `00005bf8` | | `dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_1` | `55501234` | `55401234` | `51401234` | `5aa81234` | `59501234` | | `dst_sel:DWORD src0_sel:BYTE_2` | `00005950` | `00005958` | `00005aa8` | `00005140` | `00005550` | | `dst_sel:DWORD src0_sel:BYTE_0`, `sext(v4)` | `00000000` | `00003c00` | `000057f0` | `00007bfc` | `00007c00` | | `dst_sel:DWORD src0_sel:BYTE_3`, `sext(v4)` | `00007c00` | `00007c00` | `00007bfc` | `000057f0` | `00000000` | | `dst_sel:WORD_0 dst_unused:UNUSED_PAD src0_sel:BYTE_1` | `00005550` | `00005540` | `00005140` | `00005aa8` | `00005950` | | `dst_sel:WORD_1 dst_unused:UNUSED_SEXT src0_sel:BYTE_2` | `59500000` | `59580000` | `5aa80000` | `51400000` | `55500000` | The first four rows are the four encodings in this PR's test. The byte is zero-extended (255 gives `0x5bf8`, 255.0), and a sign-extended byte is converted as the u16 it becomes (`0xff80` gives `0x7bfc`, `0xffff` rounds to `0x7c00`). | Run | RTX 5080 | RADV, Radeon 610M | |---|---|---| | `agc_driver_sdwa_cvt_f16_u16_tests` | passes | passes | | Temporary test: the eight forms above through the recompiler, 256 rows each, compared with the hardware bits | 0 of 2,048 results differ | 0 of 2,048 results differ | **Not measured:** the SDWA clamp bit, source selectors `WORD_0`/`WORD_1` (not changed here), and round modes other than nearest (every byte value is exact in f16; only the sign-extended rows round). AI-assisted: yes
adriadam10 commented 2026-10-10 23:07:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:07:01Z.


Checked the decoder rule against the hardware oracle (4 encodings of the test × all 256 byte values, 0 differences); the new test passes and fails without the rule change. Matches @fma-rc's measurements on RDNA2 and the RTX 5080; merging.

The red write-watch (macos-15-intel) job is the unrelated write_watch_threads timeout (#2846); it passes on arm64 and I re-ran it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103155283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2838#issuecomment-6103155283). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:07:01Z. --- Checked the decoder rule against the hardware oracle (4 encodings of the test × all 256 byte values, 0 differences); the new test passes and fails without the rule change. Matches @fma-rc's measurements on RDNA2 and the RTX 5080; merging. The red `write-watch (macos-15-intel)` job is the unrelated `write_watch_threads` timeout (#2846); it passes on arm64 and I re-ran it.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
boykopovar/AnyPS5!2838
No description provided.