Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Capmare:fix/shader-frontend-call-analysis-wave-size
Oct 23, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Capmare:fix/shader-frontend-call-analysis-wave-size

Conversation

@Capmare

@Capmare Capmare commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

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 c4c2b3a 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 408455b. 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

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6612 core/shader/recompiler/Recompiler.cpp L171-172

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4072 core/shader/recompiler/Recompiler.cpp
PR 5021 core/shader/recompiler/Recompiler.cpp
PR 5371 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 5609 core/shader/recompiler/Recompiler.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 6539 core/shader/recompiler/Recompiler.cpp
PR 6924 core/shader/recompiler/Recompiler.cpp
PR 7201 core/shader/recompiler/Recompiler.cpp
PR 7410 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 7484 core/shader/recompiler/Recompiler.cpp
PR 7642 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 7684 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 8077 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 8429 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 8489 core/shader/recompiler/Recompiler.cpp
PR 8564 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 8792 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 9020 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9335 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9356 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9387 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9508 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9748 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
PR 9897 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 10193 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp

@Capmare

Capmare commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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

Capmare commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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

AcquireFrontend built the frontend's SwappcInfo with a wave size of 0, while the
driver's LinkUserDataCallees passes the dispatch's wave size. A wave64 v_cmp_e64
that reuses a call's link pair after the return, followed by a v_cndmask_b32_e64
that reads it, was refused as escaping the call/return model. The frontend now
receives the dispatch's wave size, and a frontend built for one wave size is not
reused for another.
@Capmare
Capmare force-pushed the fix/shader-frontend-call-analysis-wave-size branch from f976e22 to 9863f8b Compare October 21, 2026 12:13
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@adriadam10
adriadam10 merged commit 68810f6 into boykopovar:main Oct 23, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the wave size wiring against LinkUserDataCallees and SwappcInfo, the Matches change and the updated/new ShaderMemory checks (they fail without the change, as confirmed by @savvaniss on AMD and Intel Windows); merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants