fix(shader): give the frontend's call analysis the dispatch's wave size #7816

Merged
Capmare merged 1 commit from upstream-pr/7816 into main 2026-10-23 15:38:04 +00:00
Capmare commented 2026-10-19 08:43:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Capmare on 2026-10-19T08:43:44Z.


What

AcquireFrontend builds the frontend's SwappcInfo with a wave size of 0u, while the driver's LinkUserDataCallees passes request.context.waveSize (ShaderRegistry.cpp). The call analysis uses that value in three places: writesScalar and overwritesScalar (how many SGPRs a VOPC or VOP3 mask write covers) and readsScalarDword (how many a v_cndmask mask read covers). With 0, a mask write is counted as one SGPR and a mask read as two. In wave64, a v_cmp_e64 that reuses a call's link pair after the return, followed by a v_cndmask_b32_e64 that reads it, is then refused as escaping the call/return model, because the second link SGPR still looks like it holds the return address.

  • AcquireFrontend now passes request.context.waveSize.
  • PreparedControlFlow::Matches compares the wave size, since the analysis depends on it. A frontend built for one wave size is not reused for another.
  • Two checks in ShaderMemory.cpp treated the wave size as translation-only state that must not change the frontend identity. They now expect a different wave size to miss (the case reported on #6191).
  • New check verifyFrontendWaveSizeCalls: a call whose link pair s[14:15] is overwritten by a v_cmp_eq_u32_e64 and then read by a v_cndmask_b32_e64, acquired as wave32 and wave64.

Marvel's Wolverine (PPSA03671), the refusal this fixes (Linux, main c4c2b3aa7 with #7395 and local patches, this change reverted):

compute shader 0x55e1dc89b100 (shader_55e1dc89b100.req): shader 0x55e1dc89b100 stage 0: ShaderRecompiler::Recompile: scalar call link register s[14] written at program counter 0x000000bc escapes the constant-offset call/return model (used at program counter 0x00000110)

Header of that request (agc_shader_replay): 816 code words, 16 user data, 2 memory regions, wave64; compute threads 64x1x1, partial groups 36x1x1.

Tested

  • Linux (Rocky Linux 10.2), Release, BUILD_TESTING=ON, on main 408455bda. The test is a CPU test, no GPU is involved. agc_shader_memory_tests --frontend-pair, run directly:
    • with this change: passes, with and without APS5_NO_PERF_FRONTEND_PAIR=1;
    • without the code change (tests kept): fails at "a different wave size reused the frontend";
    • without the code change and verifyFrontendWaveSizeCalls run first: fails with scalar call link register s[14] written at program counter 0x00000000 escapes the constant-offset call/return model (used at program counter 0x0000000c), the same refusal as the title's.
  • Marvel's Wolverine (PPSA03671), NVIDIA GeForce RTX 4070 SUPER, Linux: the refusal above occurs with the change reverted (2 lines in the log, at present 588). With the change, the refusal does not occur (0 lines in 5 runs, up to present 778). That tree also carries other local patches, so this is not a stock-branch title test.
  • Not tested: other test binaries and the full ^agc suite; AMD and Intel hardware; Windows.

Checklist

  • Based on current main (408455bda); no other open PR implements the same functions (#7413 changes the call analysis and its tests in GraphBuilder, not this wiring)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none (related: #6191)
  • Unblocks: PPSA03671 #6191
  • GPUs tested: n/a (CPU test); NVIDIA GeForce RTX 4070 SUPER for the title run, Linux
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4918242486 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7816). Originally posted by [Capmare](https://github.com/Capmare) on 2026-10-19T08:43:44Z. --- ### What `AcquireFrontend` builds the frontend's `SwappcInfo` with a wave size of `0u`, while the driver's `LinkUserDataCallees` passes `request.context.waveSize` ([ShaderRegistry.cpp](https://github.com/boykopovar/AnyPS5/blob/408455bda/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L691)). The call analysis uses that value in three places: `writesScalar` and `overwritesScalar` (how many SGPRs a VOPC or VOP3 mask write covers) and `readsScalarDword` (how many a `v_cndmask` mask read covers). With 0, a mask write is counted as one SGPR and a mask read as two. In wave64, a `v_cmp_e64` that reuses a call's link pair after the return, followed by a `v_cndmask_b32_e64` that reads it, is then refused as escaping the call/return model, because the second link SGPR still looks like it holds the return address. - `AcquireFrontend` now passes `request.context.waveSize`. - `PreparedControlFlow::Matches` compares the wave size, since the analysis depends on it. A frontend built for one wave size is not reused for another. - Two checks in `ShaderMemory.cpp` treated the wave size as translation-only state that must not change the frontend identity. They now expect a different wave size to miss (the case reported on [#6191](https://github.com/boykopovar/AnyPS5/issues/6191#issuecomment-6262034241)). - New check `verifyFrontendWaveSizeCalls`: a call whose link pair `s[14:15]` is overwritten by a `v_cmp_eq_u32_e64` and then read by a `v_cndmask_b32_e64`, acquired as wave32 and wave64. Marvel's Wolverine (PPSA03671), the refusal this fixes (Linux, `main` c4c2b3aa7 with #7395 and local patches, this change reverted): ``` compute shader 0x55e1dc89b100 (shader_55e1dc89b100.req): shader 0x55e1dc89b100 stage 0: ShaderRecompiler::Recompile: scalar call link register s[14] written at program counter 0x000000bc escapes the constant-offset call/return model (used at program counter 0x00000110) ``` Header of that request (`agc_shader_replay`): 816 code words, 16 user data, 2 memory regions, **wave64**; compute threads 64x1x1, partial groups 36x1x1. ### Tested - **Linux (Rocky Linux 10.2), Release, `BUILD_TESTING=ON`**, on `main` 408455bda. The test is a CPU test, no GPU is involved. `agc_shader_memory_tests --frontend-pair`, run directly: - with this change: passes, with and without `APS5_NO_PERF_FRONTEND_PAIR=1`; - without the code change (tests kept): fails at "a different wave size reused the frontend"; - without the code change and `verifyFrontendWaveSizeCalls` run first: fails with `scalar call link register s[14] written at program counter 0x00000000 escapes the constant-offset call/return model (used at program counter 0x0000000c)`, the same refusal as the title's. - **Marvel's Wolverine (PPSA03671)**, NVIDIA GeForce RTX 4070 SUPER, Linux: the refusal above occurs with the change reverted (2 lines in the log, at present 588). With the change, the refusal does not occur (0 lines in 5 runs, up to present 778). That tree also carries other local patches, so this is not a stock-branch title test. - **Not tested:** other test binaries and the full `^agc` suite; AMD and Intel hardware; Windows. ### Checklist - [x] Based on current `main` (408455bda); no other open PR implements the same functions (#7413 changes the call analysis and its tests in `GraphBuilder`, not this wiring) - [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) - [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 (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none (related: #6191) - [x] Unblocks: PPSA03671 #6191 - [x] GPUs tested: n/a (CPU test); NVIDIA GeForce RTX 4070 SUPER for the title run, Linux - [x] AI-assisted: yes
Capmare commented 2026-10-19 08:58:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Capmare on 2026-10-19T08:58:37Z.


About the overlap with #6679: it shares only the neighbouring condition in PreparedControlFlow::Matches. #6679 adds mergedHull == MergedHullStage(request) and this PR adds swappc.waveSize == swappcInfo.waveSize. The two do not depend on each other and neither implements the other's behaviour. Whichever merges second keeps both conditions in that expression.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6263523292 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7816#issuecomment-6263523292). Originally posted by [Capmare](https://github.com/Capmare) on 2026-10-19T08:58:37Z. --- About the overlap with #6679: it shares only the neighbouring condition in `PreparedControlFlow::Matches`. #6679 adds `mergedHull == MergedHullStage(request)` and this PR adds `swappc.waveSize == swappcInfo.waveSize`. The two do not depend on each other and neither implements the other's behaviour. Whichever merges second keeps both conditions in that expression.
savvaniss commented 2026-10-19 14:34:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T14:34:32Z.


AMD and Intel Windows data: with this PR's test changes, three ShaderMemory tests fail on main and pass with the PR, on an AMD RX 9070 XT and an Intel UHD 770.

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, with VkCache emptied first. This head f976e2202 merged into main 85029a00f. "Without" means only this PR's diff to tests/ShaderMemory.cpp, applied to main 85029a00f.

Tests, ×3 UHD 770 RX 9070 XT
This head: the 15 tests built from tests/ShaderMemory.cpp 15 of 15 pass 15 of 15 pass
Without agc_shader_frontend_pair and agc_shader_memory fail: frontend pair: a different wave size reused the frontend. agc_shader_frontend_pair_off fails: scalar call link register s[14] written at program counter 0x00000000 escapes the constant-offset call/return model (used at program counter 0x0000000c). The other 12 pass same

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6269769748 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7816#issuecomment-6269769748). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-19T14:34:32Z. --- AMD and Intel Windows data: with this PR's test changes, three `ShaderMemory` tests fail on `main` and pass with the PR, on an AMD RX 9070 XT and an Intel UHD 770. Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, `ANYPS5_NO_SHADER_CACHE=1`, serial CTest. Intel UHD Graphics 770 (`8086:a780`), driver 32.0.101.7088. AMD Radeon RX 9070 XT (`1002:7550`), driver 32.0.31041.1004, with `VkCache` emptied first. This head `f976e2202` merged into `main` `85029a00f`. "Without" means only this PR's diff to `tests/ShaderMemory.cpp`, applied to `main` `85029a00f`. | Tests, ×3 | UHD 770 | RX 9070 XT | |---|---|---| | This head: the 15 tests built from `tests/ShaderMemory.cpp` | 15 of 15 pass | 15 of 15 pass | | Without | `agc_shader_frontend_pair` and `agc_shader_memory` fail: `frontend pair: a different wave size reused the frontend`. `agc_shader_frontend_pair_off` fails: `scalar call link register s[14] written at program counter 0x00000000 escapes the constant-offset call/return model (used at program counter 0x0000000c)`. The other 12 pass | same | AI-assisted: yes (Claude Code)
Capmare commented 2026-10-19 14:42:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Capmare on 2026-10-19T14:42:47Z.


Thanks for testing this on AMD and Intel Windows. That covers the hardware and OS my description listed as not tested, and the three failures without the change match the ones I saw.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6269945731 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7816#issuecomment-6269945731). Originally posted by [Capmare](https://github.com/Capmare) on 2026-10-19T14:42:47Z. --- Thanks for testing this on AMD and Intel Windows. That covers the hardware and OS my description listed as not tested, and the three failures without the change match the ones I saw.
DavidAmsellem commented 2026-10-19 18:23:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T18:23:56Z.


First AMD-on-Linux (RADV) run of this PR. Merged onto main 8d5d4df96 (clean merge), built in full and compared with the same main, on the same machine.

AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.

Full suite (ANYPS5_REQUIRE_VULKAN=1 ctest -j8) at 8f59bf4bd: 1638/1640 with this PR, against 1638/1640 on main. The two failures are the same on both, so this PR adds none: agc_driver_image_table_vouched_lookups (#7766, fixed by #7916) and agc_driver_guest_memory_lifetime (#7784).

Comparing the JUnit output with main: this PR adds no ctest entry, and none is skipped or removed.

This checks correctness only; I did not measure performance.

GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274236476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7816#issuecomment-6274236476). Originally posted by [DavidAmsellem](https://github.com/DavidAmsellem) on 2026-10-19T18:23:56Z. --- First AMD-on-Linux (RADV) run of this PR. Merged onto `main` `8d5d4df96` (clean merge), built in full and compared with the same `main`, on the same machine. AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release. Full suite (`ANYPS5_REQUIRE_VULKAN=1 ctest -j8`) at `8f59bf4bd`: **1638/1640 with this PR**, against 1638/1640 on `main`. The two failures are the same on both, so this PR adds none: `agc_driver_image_table_vouched_lookups` (#7766, fixed by #7916) and `agc_driver_guest_memory_lifetime` (#7784). Comparing the JUnit output with `main`: this PR adds no ctest entry, and none is skipped or removed. This checks correctness only; I did not measure performance. GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38 AI-assisted: yes
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!7816
No description provided.