feat(shader): accept SDWA byte destination selectors on v_cvt_f16_u16 #18241

Open
Kikoarl wants to merge 1 commit from upstream-pr/18241 into main
Kikoarl commented 2026-11-10 23:30:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-11-10T23:30:49Z.


What

Accept Sub-Dword Addressing (SDWA) byte destination selectors on v_cvt_f16_u16 (VOP1 opcode 0x50).

Updates vop1SdwaRules for VCvtF16U16 in core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp to allow sdwaSelBytes() | sdwaSelWords() (previously restricted to sdwaSelWords()). In AMD RDNA2 ISA §13.3.7 Table 88, 16-bit destination instructions accept byte destination selectors (BYTE_0..BYTE_3) alongside word destination selectors (WORD_0, WORD_1) and destination unused modes UNUSED_PAD, UNUSED_SEXT, and UNUSED_PRESERVE.

Sources:

  • AMD RDNA2 ISA Manual §§6.8, 12.8 opcode 80, 13.3.7 Table 88
  • LLVM 19.1.0 VOP1Instructions.td and SIPeepholeSDWA.cpp destination folding
  • Technical debt documented in docs/dev/debt/shader.md under ### Functional

Tested

  • Linux x86_64 Release RAM-disk build in /tmp/anyps5_verify_build (-DBUILD_TESTING=ON), rebased cleanly onto origin/main (115a7036e2, PR head ca75d82e9b):
    • ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir /tmp/anyps5_verify_build --output-on-failure -R "^agc_driver_sdwa_cvt_f16_u16_bytes":
      • agc_driver_sdwa_cvt_f16_u16_bytes (Wave32): Passed (0.83 sec)
      • agc_driver_sdwa_cvt_f16_u16_bytes_wave64 (Wave64): Passed (0.32 sec)
    • Verifies 8 pinned input uint16_t values across 6 sub-dword destination selections (BYTE_0..BYTE_3, WORD_0, WORD_1) and 3 unused modes (UNUSED_PAD, UNUSED_SEXT, UNUSED_PRESERVE), plus negative decoder refusal checks for invalid selector 7, illegal unused mode 3, and SDWA source negate on integer source.
  • python3 tools/debt_fold.py --check, python3 tools/check_conventions.py --base origin/main, and git diff --check origin/main..HEAD: passed cleanly.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Intel(R) Graphics (RPL-S), Mesa Vulkan, Linux x86_64
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5250790353 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18241). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-11-10T23:30:49Z. --- ### What Accept Sub-Dword Addressing (SDWA) byte destination selectors on `v_cvt_f16_u16` (VOP1 opcode `0x50`). Updates `vop1SdwaRules` for `VCvtF16U16` in `core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp` to allow `sdwaSelBytes() | sdwaSelWords()` (previously restricted to `sdwaSelWords()`). In AMD RDNA2 ISA §13.3.7 Table 88, 16-bit destination instructions accept byte destination selectors (`BYTE_0`..`BYTE_3`) alongside word destination selectors (`WORD_0`, `WORD_1`) and destination unused modes `UNUSED_PAD`, `UNUSED_SEXT`, and `UNUSED_PRESERVE`. Sources: - AMD RDNA2 ISA Manual §§6.8, 12.8 opcode 80, 13.3.7 Table 88 - LLVM 19.1.0 `VOP1Instructions.td` and `SIPeepholeSDWA.cpp` destination folding - Technical debt documented in `docs/dev/debt/shader.md` under `### Functional` ### Tested - Linux x86_64 Release RAM-disk build in `/tmp/anyps5_verify_build` (`-DBUILD_TESTING=ON`), rebased cleanly onto `origin/main` (`115a7036e2`, PR head `ca75d82e9b`): - `ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir /tmp/anyps5_verify_build --output-on-failure -R "^agc_driver_sdwa_cvt_f16_u16_bytes"`: - `agc_driver_sdwa_cvt_f16_u16_bytes` (Wave32): Passed (`0.83 sec`) - `agc_driver_sdwa_cvt_f16_u16_bytes_wave64` (Wave64): Passed (`0.32 sec`) - Verifies 8 pinned input `uint16_t` values across 6 sub-dword destination selections (`BYTE_0`..`BYTE_3`, `WORD_0`, `WORD_1`) and 3 unused modes (`UNUSED_PAD`, `UNUSED_SEXT`, `UNUSED_PRESERVE`), plus negative decoder refusal checks for invalid selector `7`, illegal unused mode `3`, and SDWA source negate on integer source. - `python3 tools/debt_fold.py --check`, `python3 tools/check_conventions.py --base origin/main`, and `git diff --check origin/main..HEAD`: passed cleanly. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: Intel(R) Graphics (RPL-S), Mesa Vulkan, Linux x86_64 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-12 20:37:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T20:37:47Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head: 173dd32c3d58ec1467edd0ae52b005e18c9fe099, base main, merged-preview check not needed.
  • No build and no test run in this review. Reading only, through the repository reader at the pinned head.
  • Commands (reader calls, all at the head):
repo_read.py search VCvtF16U16
repo_read.py cat core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp 860 885
repo_read.py search sdwaSelWords
repo_read.py cat core/shader/recompiler/Translation/src/VectorInstructions.cpp 840 862
repo_read.py search explicitSdwaDst
repo_read.py cat core/shader/recompiler/Translation/src/TranslationContext/SubwordPacking.cpp 150 200
repo_read.py search vCvtF1616
repo_read.py cat core/shader/recompiler/Translation/src/ConvertInstructions.cpp 130 150
repo_read.py search writeRawU32
repo_read.py cat core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp 664 700
repo_read.py search writeF16Conversion
repo_read.py cat core/shader/recompiler/Translation/src/TranslationContext/SubwordPacking.cpp 252 272
repo_read.py search Functional docs/dev/debt/shader.md
  • The four changed files were read in full from diff.patch. The new test file is 239 lines and was read end to end.
  • Author-reported runs (Wave32 and Wave64 on Intel(R) Graphics (RPL-S), the invalid-selector checks, check_conventions.py) are not runs I performed.

Results

Check Result Note
Byte destination reaches the SDWA write path passed Traced by reading
Added debt lines under 1000 characters passed Grep over the diff, no match
New GPU execution test not run Author reports pass, Wave32 and Wave64
check_conventions.py not run Author reports 100% compliance

Findings

Blocking

None.

Non-blocking

  1. docs/dev/debt/shader.md:252 says v_cvt_f16_u16 is verified "across all source selectors (BYTE_0..BYTE_3, WORD_0, WORD_1, DWORD)". The rule table allows those sources (RdnaVectorOpDecoder.cpp:1133), but the new execution test only uses source WORD_0 (core/libs/prx/libSceAgcDriver/tests/execution/SdwaCvtF16U16Bytes.cpp:171, (4u << 16u)). Either narrow the debt entry to the source selector that is tested, or add source cases to the test.
  2. core/libs/prx/libSceAgcDriver/tests/execution/SdwaCvtF16U16Bytes.cpp:109 uses std::invalid_argument, :185 uses std::span and :190 uses std::optional, and none of <stdexcept>, <span> or <optional> is included in the file. They may come in through the other headers, but the file should not depend on that.
  3. SdwaCvtF16U16Bytes.cpp:80 loops over a one-element list (for (const auto opWord : {CvtF16U16Sdwa})). A plain block would read more clearly. Optional.

Not verified

  • The build and the new GPU test were not run here. The Wave32 and Wave64 passes on Intel(R) Graphics (RPL-S) are the author's report.
  • check_conventions.py was not run here. The 100% compliance result is the author's report.
  • Console behaviour on gfx1013 is not measured. The debt entry says so too.
  • Source selectors other than WORD_0 are not exercised by any test (see finding 1).
  • core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp was read at the changed rule table and the float-result list, not in full.
  • docs/dev/debt/shader.md was read in the diff hunk and for line length. The ### Functional heading is at line 38. The section placement of the new entry was not checked against any later heading.

Sources

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5881650173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18241#pullrequestreview-5881650173). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T20:37:47Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head: `173dd32c3d58ec1467edd0ae52b005e18c9fe099`, base `main`, merged-preview check not needed. - No build and no test run in this review. Reading only, through the repository reader at the pinned head. - Commands (reader calls, all at the head): ``` repo_read.py search VCvtF16U16 repo_read.py cat core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp 860 885 repo_read.py search sdwaSelWords repo_read.py cat core/shader/recompiler/Translation/src/VectorInstructions.cpp 840 862 repo_read.py search explicitSdwaDst repo_read.py cat core/shader/recompiler/Translation/src/TranslationContext/SubwordPacking.cpp 150 200 repo_read.py search vCvtF1616 repo_read.py cat core/shader/recompiler/Translation/src/ConvertInstructions.cpp 130 150 repo_read.py search writeRawU32 repo_read.py cat core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp 664 700 repo_read.py search writeF16Conversion repo_read.py cat core/shader/recompiler/Translation/src/TranslationContext/SubwordPacking.cpp 252 272 repo_read.py search Functional docs/dev/debt/shader.md ``` - The four changed files were read in full from `diff.patch`. The new test file is 239 lines and was read end to end. - Author-reported runs (Wave32 and Wave64 on Intel(R) Graphics (RPL-S), the invalid-selector checks, `check_conventions.py`) are not runs I performed. ## Results | Check | Result | Note | | --- | --- | --- | | Byte destination reaches the SDWA write path | passed | Traced by reading | | Added debt lines under 1000 characters | passed | Grep over the diff, no match | | New GPU execution test | not run | Author reports pass, Wave32 and Wave64 | | `check_conventions.py` | not run | Author reports 100% compliance | ## Findings **Blocking** None. **Non-blocking** 1. `docs/dev/debt/shader.md:252` says `v_cvt_f16_u16` is verified "across all source selectors (`BYTE_0`..`BYTE_3`, `WORD_0`, `WORD_1`, `DWORD`)". The rule table allows those sources ([`RdnaVectorOpDecoder.cpp:1133`](https://github.com/boykopovar/AnyPS5/blob/173dd32c3d58ec1467edd0ae52b005e18c9fe099/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp#L1133)), but the new execution test only uses source `WORD_0` (`core/libs/prx/libSceAgcDriver/tests/execution/SdwaCvtF16U16Bytes.cpp:171`, `(4u << 16u)`). Either narrow the debt entry to the source selector that is tested, or add source cases to the test. 2. `core/libs/prx/libSceAgcDriver/tests/execution/SdwaCvtF16U16Bytes.cpp:109` uses `std::invalid_argument`, `:185` uses `std::span` and `:190` uses `std::optional`, and none of `<stdexcept>`, `<span>` or `<optional>` is included in the file. They may come in through the other headers, but the file should not depend on that. 3. `SdwaCvtF16U16Bytes.cpp:80` loops over a one-element list (`for (const auto opWord : {CvtF16U16Sdwa})`). A plain block would read more clearly. Optional. ## Not verified - The build and the new GPU test were not run here. The Wave32 and Wave64 passes on Intel(R) Graphics (RPL-S) are the author's report. - `check_conventions.py` was not run here. The 100% compliance result is the author's report. - Console behaviour on gfx1013 is not measured. The debt entry says so too. - Source selectors other than `WORD_0` are not exercised by any test (see finding 1). - `core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp` was read at the changed rule table and the float-result list, not in full. - `docs/dev/debt/shader.md` was read in the diff hunk and for line length. The `### Functional` heading is at line 38. The section placement of the new entry was not checked against any later heading. ## Sources - Byte and word destination write path: [`OperandAccess.cpp#L664-L698`](https://github.com/boykopovar/AnyPS5/blob/173dd32c3d58ec1467edd0ae52b005e18c9fe099/core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp#L664-L698) - 16-bit result write selection: [`SubwordPacking.cpp#L166-L175`](https://github.com/boykopovar/AnyPS5/blob/173dd32c3d58ec1467edd0ae52b005e18c9fe099/core/shader/recompiler/Translation/src/TranslationContext/SubwordPacking.cpp#L166-L175) ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-20 10:11:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T10:11:22Z.

Review: APPROVED


Reviewed — looks good

Nothing in the reviewed change blocks merging; the implementation and its focused test are consistent with the stated selector support.

What I ran

Reviewed head afb5ff814d427090c92102278ab335c63d578749 using the pinned repo_read.py reader. No tests or build commands were run.

Results

Check Result Note
Diff and targeted source review passed Selector rule and test reviewed
Build and execution tests not run Author reports GPU test results

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read all four changed files listed in the manifest: core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_sdwa_cvt_f16_u16_bytes_tests.cmake, core/libs/prx/libSceAgcDriver/tests/execution/SdwaCvtF16U16Bytes.cpp, core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp, and docs/dev/debt/shader.md. No files were excluded. Build, test execution, and the author-reported GPU results were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5990978960 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18241#pullrequestreview-5990978960). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T10:11:22Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the reviewed change blocks merging; the implementation and its focused test are consistent with the stated selector support. ## What I ran Reviewed head `afb5ff814d427090c92102278ab335c63d578749` using the pinned `repo_read.py` reader. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Selector rule and test reviewed | | Build and execution tests | not run | Author reports GPU test results | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read all four changed files listed in the manifest: `core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_sdwa_cvt_f16_u16_bytes_tests.cmake`, `core/libs/prx/libSceAgcDriver/tests/execution/SdwaCvtF16U16Bytes.cpp`, `core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp`, and `docs/dev/debt/shader.md`. No files were excluded. Build, test execution, and the author-reported GPU results were not independently verified. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-26 11:43:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T11:43:56Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: register the new execution test target so CMake can build and run the added test.

What I ran

Reviewed head ca75d82e9b6affcda0451cf48cc407f872e4be9f; no commands or tests were run by me.

Results

Check Result Note
Decoder rule and test logic passed Byte/word selectors and destination modes are covered
New test target registration failed No target declaration found for the new test executable
Runtime checks not run The author reports Wave32 and Wave64 passes

Findings

Blocking

  • The added test source is not included in agcExecutionTests, and no other target declaration for agc_driver_sdwa_cvt_f16_u16_bytes_tests appears in the AgcDriver CMake configuration. The new CTest fragment invokes this executable, but agcTestFragments only includes CTest registration and does not create the executable. Add the source to the execution-test target list (or otherwise declare the target) so the test builds and the CTest entry can run. agc_driver_sdwa_cvt_f16_u16_bytes_tests.cmake:2

Non-blocking

None.

Sources

Not verified

No build or runtime test was performed. The author reports passing Wave32 and Wave64 execution tests and a clean build, but those results were not independently confirmed. Read all added lines in the four changed files: the CMake test fragment, execution test source, decoder rule, and shader debt entry. No changed files were excluded.

To get this to a good state

Register SdwaCvtF16U16Bytes.cpp as agc_driver_sdwa_cvt_f16_u16_bytes_tests, then rerun the build and the focused Wave32/Wave64 CTest selection.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6073560794 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18241#pullrequestreview-6073560794). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-26T11:43:56Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: register the new execution test target so CMake can build and run the added test. ## What I ran Reviewed head `ca75d82e9b6affcda0451cf48cc407f872e4be9f`; no commands or tests were run by me. ## Results | Check | Result | Note | |---|---|---| | Decoder rule and test logic | passed | Byte/word selectors and destination modes are covered | | New test target registration | failed | No target declaration found for the new test executable | | Runtime checks | not run | The author reports Wave32 and Wave64 passes | ## Findings ### Blocking - The added test source is not included in `agcExecutionTests`, and no other target declaration for `agc_driver_sdwa_cvt_f16_u16_bytes_tests` appears in the AgcDriver CMake configuration. The new CTest fragment invokes this executable, but `agcTestFragments` only includes CTest registration and does not create the executable. Add the source to the execution-test target list (or otherwise declare the target) so the test builds and the CTest entry can run. [agc_driver_sdwa_cvt_f16_u16_bytes_tests.cmake:2](https://github.com/boykopovar/AnyPS5/blob/ca75d82e9b6affcda0451cf48cc407f872e4be9f/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_sdwa_cvt_f16_u16_bytes_tests.cmake#L2) ### Non-blocking None. ## Sources - [Decoder rule](https://github.com/boykopovar/AnyPS5/blob/ca75d82e9b6affcda0451cf48cc407f872e4be9f/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp#L1169) ## Not verified No build or runtime test was performed. The author reports passing Wave32 and Wave64 execution tests and a clean build, but those results were not independently confirmed. Read all added lines in the four changed files: the CMake test fragment, execution test source, decoder rule, and shader debt entry. No changed files were excluded. ## To get this to a good state Register `SdwaCvtF16U16Bytes.cpp` as `agc_driver_sdwa_cvt_f16_u16_bytes_tests`, then rerun the build and the focused Wave32/Wave64 CTest selection.
ligmaSec commented 2026-12-03 22:33:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:33:19Z.

Review: COMMENTED


The trial merge onto c1601e56d5 was clean. The decoder accepts all four byte destinations for v_cvt_f16_u16, while the new fixture’s explicit decoded control checks BYTE_0 with UNUSED_PRESERVE. Please keep coverage for a higher byte and another unused mode, particularly UNUSED_SEXT, when validating the shared byte-write path. Move the direct shader debt edit into a fragment. Paired execution is pending.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179785249 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18241#pullrequestreview-6179785249). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:33:19Z. **Review:** COMMENTED --- The trial merge onto `c1601e56d5` was clean. The decoder accepts all four byte destinations for `v_cvt_f16_u16`, while the new fixture’s explicit decoded control checks `BYTE_0` with `UNUSED_PRESERVE`. Please keep coverage for a higher byte and another unused mode, particularly `UNUSED_SEXT`, when validating the shared byte-write path. Move the direct shader debt edit into a fragment. Paired execution is pending. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/18241:upstream-pr/18241'
git switch 'upstream-pr/18241'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/18241'
git switch 'upstream-pr/18241'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/18241'
git switch 'upstream-pr/18241'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/18241'
git switch 'main'
git merge --squash 'upstream-pr/18241'
git switch 'main'
git merge --ff-only 'upstream-pr/18241'
git switch 'main'
git merge 'upstream-pr/18241'
git push origin 'main'
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!18241
No description provided.