fix(shader): share wave64 VGPRs past the private ones between the two halves #7410
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7410"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-18T05:05:39Z.
What
On GFX10, a wave64 program can declare wave-shared VGPRs (RDNA2 ISA 3.6.5):
COMPUTE_PGM_RSRC3.SHARED_VGPR_CNTblocks of eight VGPRs placed after the(COMPUTE_PGM_RSRC1.VGPRS + 1) * 4private ones. Lane N and lane N + 32 share one copy of each.emit_permlane64_shared_vgpr) and to emulate a wave-wideds_bpermute_b32(emit_bpermute_shared_vgpr).-fa on -ctk q8_0 -ctv q8_0, and slightly wrong text in other configurations.Changes:
RSRC1.VGPRSandRSRC3.SHARED_VGPR_CNTfor compute dispatches intoShaderComputeStageInfo. Both are part of the cache key, the dispatch key (0x228) and request serialization (version 56).HalfSwapU32IR op.ds_bpermute_b32, is modeled while an immediates_mov_b32,s_mov_b64ors_bfm_b64earlier in the block has left one half of EXEC empty, as ACO does. With both halves possibly active the ISA gives no order, so it throws.v_writelane_b32, relative VGPR writes in such a program, wave32 programs with shared VGPRs, and host subgroups narrower than 32 lanes.SHARED_VGPR_CNTinSPI_SHADER_PGM_RSRC2for graphics stages. Graphics stages are not modeled, so a draw whose program sets it throws. No graphics program set it in Dusklight, flycast, Porpoise, PSSwanStation, PS5LM, Prospero Win, ProsperoAI or ProsperoLight.docs/dev/debt/shader.md.Sources:
VGPR_SHARED_SIZEin units of 8).be738ab0ea44cbddee6f0dcbd3cd9d16d98118ed:src/amd/compiler/aco_lower_to_hw_instr.cpp:emit_permlane64_shared_vgpr,emit_bpermute_shared_vgprandcopy_constant_sgpr.src/amd/vulkan/radv_shader.c:S_00B848_VGPRS((num_vgprs - 1) / 4)for wave64,S_00B8A0_SHARED_VGPR_CNT(num_shared_vgprs / 8), and theRSRC2SHARED_VGPR_CNTof the graphics stages.src/amd/registers/gfx10.json: field positions.Tested
Windows 11, WinLibs GCC 15.2, full build:
ctest -R "agc_|shader|recompiler|guest_|request_serializer" -E video_out(GPU tests on): 1163/1163 passed.ctest -R "^(libkernel|kernel|nid|patched_libraries|file_streams|libc)" -E "agc_|video_out": 12/12 passed.After the rebase onto
main77d2cc9b36(serializer version 56;mainskips 50 and writes 55): clean full Windows build. The serializer, shader-memory, wave-shared VGPR, dispatch, subgroup, masked-select, stencil and shader-cache set (52 entries) passes on NVIDIA and on AMD.ctest -R ^agc_on NVIDIA: 1466/1467. The one failure isagc_driver_quad_pixel_mask, open issue #14237, which also fails onmainon Windows.Linux (WSL Ubuntu 24.04, GCC 13.3): libSceAgcDriver plus the recompiler, serializer and AGC driver tests pass.
agc_driver_wave_shared_vgprsskips on llvmpipe (subgroup size 8).New tests:
agc_driver_wave_shared_vgprsruns ACO's half swap, an exec-masked low-half write and ACO's wave64 bpermute sequence word for word, and checks the rejections.main's sources it fails withlane 0 read 0x00000000, expected lane 32's 0x00201020, or withlane 6 read 0x00000000, expected lane 33's 0x00211021for the bpermute part only.agc_driver_prepared_unregistered_graphicschecks that a graphics stage withSHARED_VGPR_CNTis rejected.agc_driver_graphicscovers decodingRSRC1/RSRC3and serialization.request_serializerreplays a version 55 compute request, which has no wave-shared VGPR words. If the reader reads those words from version 37 as before, it fails withRequestSerializer: truncated data.PS5LM Plus 0.8.4 (PPSA99581) with Qwen2.5-0.5B-Instruct q4_k_m (Apache-2.0), prompt "The capital of France is", 16 tokens, temperature 0. The title is fixed on NVIDIA (RTX 5070 Ti):
main,-fa on -ctk q8_0 -ctv q8_0:orntymology. In the 19th-arthury.10(3/3).Paris. It is the largest city in Europe and the second largest in the world(3/3), the CPU backend's exact answer.-fa onwith f16 K/V, and-fa off, now give the same answer. Before, they gaveParis. It is the largest city in the world by population…andParis. It is located in the south of France….On the AMD Radeon iGPU the title is still garbage in every configuration,
-fa offincluded, both before and after this change; that is a separate bug. Only the replay of the captured flash-attention dispatch is correct there: its max relative error against a numpy reference went from 0.99 to 0.031.An independent review checked:
A regression run of Dusklight, flycast, Porpoise, PSSwanStation, PS5LM, Prospero Win, ProsperoAI and ProsperoLight (60 s each) showed no new errors.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T00:52:28Z.
Tested on Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5090 (driver 617.42), Ryzen 9 9950X3D. Head
d662988bfmerged onto currentmain(a373e85e5); the merge is clean.agc_driver_wave_shared_vgprs,agc_driver_prepared_unregistered_graphics,agc_driver_graphics,agc_shader_memory,agc_shader_bindlessandrequest_serializerall pass (6 of 6).A note for other Windows testers: in a build folder under a long path (mine was a workspace path of about 150 characters) the build of
agc_driver_prepared_unregistered_graphics_testsstopped withfatal error: opening dependency file ...PreparedUnregisteredGraphics.cpp.obj.d: No such file or directory. That is the Windows path-length limit, not this PR; the same tree built fine from a short build directory.I did not run the new test against
mainwithout the fix, did not run PS5LM Plus (PPSA99581), and did not review the 28-file change (theHalfSwapU32op, request version 33 and the cache key changes); this is a test report only, not an approval.AI-assisted: yes. Written with AI assistance and reviewed by me.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T04:24:24Z.
Rebased onto
main3ddbc4accto resolve the conflict with #4650. #4650 took request serialization version 35 for its depth-range remap fields, so the shared VGPR fields now read from version 36.RequestSerializerwrites 36 and accepts up to 36, and the test literals moved with it. The rest of the change is the same.agc|shader|spirv|recomp|serial|wave) passes 779/779 on an RTX 5070 Ti.agc_driver_wave_shared_vgprs,request_serializerandagc_shader_memoryalso pass on the AMD RDNA2 iGPU (ANYPS5_GPU=AMD).request_serializerandagc_shader_memorypass. The same 17 of 771 subset tests fail with and without this PR, because WSL lacks userfaultfd write protection ("require watched guest memory").AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T06:50:13Z.
Rebased again, onto
main46f27623c. The f32 flush-to-zero change took request serialization version 36, so the shared VGPR fields now read from version 37.TranslationContextandInstructionTranslatorkeep both setters. The rest of the change is the same.agc|shader|spirv|recomp|serial|wavesubset passes 779 of 782.agc_driver_store_pending_identitypasses 3 of 3 when run on its own.agc_driver_storage_file_writeis intermittent: 1 of 3 here, and 1 of 3 on an unmodifiedmainbuild.shader_cache_runtime_sourcesreaches its 180 s timeout with or without this PR while other builds load the machine.ANYPS5_GPU=AMD):agc_driver_wave_shared_vgprs,request_serializerandagc_shader_memorypass.request_serializerandagc_shader_memorypass. Failing here are the 17 that fail onmainin WSL (no userfaultfd write protection), plusshader_cache_runtime_sources(a nested CMake configure exceeds 15 s under load).agc_driver_storage_file_writealso failed in the full run and passes on its own.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:13:49Z.
Rebase handoff — rebased onto current
maincleanly (authorship unchanged).Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
07b75d57b.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T08:19:15Z.
One note on the handoff: an earlier full-suite run (on a stale build-tree state) showed
agc_shader_memoryandagc_driver_bda_span_readsfailing — both pass on the rebuilt branch and on cleanmain(solo and in-suite), so those were stale-binary artifacts, not this PR. The handoff stands: head07b75d57b, green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784).Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T08:24:13Z.
@blawesom thanks for rebasing it and for the RX 9070 XT run. I compared
07b75d57bwith the current head39b3e272a, which was rebased onto46f27623cearlier today: the added and removed lines of the patch are identical, so your base is the only difference. GitHub still reports this branch as mergeable, so I've left the head at39b3e272a. I'll rebase again if a conflict appears.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-19T09:16:51Z.
PS5LM Plus on an RDNA 3.5 iGPU: with this PR it gives the CPU backend's exact answer in all three configurations. Here the title isn't garbage on AMD.
AMD Radeon 860M (
1002:1114, wave64 subgroups), driver 32.0.13058.8001, Windows 11, WinLibs GCC 15.2.0, Release.mainf78675ae4, alone and with 39b3e272a merged. PS5LM Plus 0.8.4 (catalog zip, SHA-256 checked), Qwen2.5-0.5B-Instruct q4_k_m from Qwen's Hugging Face repo.app-args.txtholds the planner's arguments (-ngl 999 -c 4096 -b 256 -ub 64 -np 1 ...) with only the-fa/-ctk/-ctvpart changed. Prompt "The capital of France is",n_predict16, temperature 0, over HTTP on 8081. Three runs per cell, in the same run folder:main-fa on -ctk q8_0 -ctv q8_0orntymology. In the 19th-arthury.10(2 of 3; the first run stopped, see below)Paris. It is the largest city in Europe and the second largest in the world(3 of 3)-fa on(f16 K/V)Paris. It is the largest city in the world by population. It is also(3 of 3)Paris. It is the largest city in Europe and the second largest in the world(3 of 3)-fa offParis. It is the largest city in Europe and the second largest in the world(2 of 3)This is the same pattern you measured on the RTX 5070 Ti, with one difference: on this GPU
main's-fa offalready gave the exact answer. The garbage you see on the RDNA 2 iGPU in every configuration doesn't happen here, so whatever causes it is specific to that GPU or its driver.The new tests (
agc_driver_wave_shared_vgprs,agc_driver_prepared_unregistered_graphics,agc_driver_graphics,agc_shader_memory,request_serializer) pass 3 of 3 on this head withANYPS5_NO_SHADER_CACHE=1.A separate stop, not from this PR. In three cases, the first run of a configuration on a fresh build stopped about 11 s after start, before the server answered:
mainq8_0, and-fa offon both trees. llama.cpp logsggml_vulkan: device lost on Vulkan0, fromwaitForFences/waitSemaphoreswith aUINT64_MAXtimeout, and AnyPS5 logs no error. The second and third runs of the same configuration, with the shader cache from the first, answered normally. That looks like the title's Vulkan driver giving up on a wait while AnyPS5 is still building pipelines, as in #6118, but I haven't traced it.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T17:22:01Z.
Second AMD-on-Linux (RADV) run, this time on RDNA3, after @blawesom's RX 9070 XT (RDNA4). Merged onto
maindbac9fa15(clean merge), built in full and compared with the samemain, 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): 1639/1641 with this PR, against 1638/1640 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784).The new
agc_driver_wave_shared_vgprsruns here and passes (its only skip is the subgroup-size check, which RADV's 64-lane subgroups clear), so RADV covers the test that llvmpipe skips. No other test is skipped or removed compared withmain.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
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T18:16:43Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
maindbac9fa15(clean merge), built in full and compared with the samemain, 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) at9033a683a: 1639/1641 with this PR, against 1638/1640 onmain. The two failures are the same on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784).The PR's new ctest entry,
agc_driver_wave_shared_vgprs, runs and passes here. No other ctest entry is added, skipped or removed compared withmain.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
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T23:29:41Z.
Rebased onto
main0d8c51a54, keeping @adriadam10's two commits.dd41527cetook request serialization version 38 for the mesh barycentric flag, so the shared VGPR fields now read from version 39. TheShaderMemorytest commit became empty, becausemainhad already moved those lines to 38, so the version 39 expectations went into the serializer commit, whose message now names both versions. The rest is unchanged. Heada80f17d7c.agc|shader|spirv|recomp|serial|wavesubset passes 820 of 825. Of the five:shader_cache_runtime_sources,agc_driver_depth_clear_hleandagc_driver_sgpr_pattern_fill_keyspass when rerun on their own.agc_driver_pass_input_hazardalso fails onmain; #7954 fixes it.agc_driver_msaa_dcc_clear_4fails 3 of 3 here, and 3 of 3 on an unmodified build ofmain0d8c51a54. It passes on9127ea36d, so it is a regression inmainbetween those two commits.ANYPS5_GPU=AMD):agc_driver_wave_shared_vgprs,request_serializer,agc_shader_memory,agc_driver_graphicsand the lookup-log tests pass 16 of 16.request_serializerandagc_shader_memorypass.mainin WSL (no userfaultfd write protection).agc_driver_lookup_log_fits_buildfails 2 of 2 on an unmodifiedmainthere too.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T16:05:33Z.
Rebased onto
maind073fe6a1, keeping @adriadam10's commit.8b8219dce(#6679) took request serialization version 39 for the merged hull flag, so the shared VGPR fields now read from version 40. The test literals moved with them, and the serializer commit's message names all three versions. Heada16513746. (#6639 also mentions moving to 40, so whichever of the two lands second will need to move up one.)agc|shader|spirv|recomp|serial|wavesubset passes 843 of 845.agc_driver_image_array_window_past_layer_limitdoesn't compile with MinGW onmain(#8310 fixes it).agc_driver_sgpr_pattern_fill_keystimes out under load.agc_driver_wave_shared_vgprs,request_serializer,agc_shader_memoryandagc_driver_graphicspass, 15 of 15.mainin WSL.request_serializerandagc_shader_memorypass.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-20T16:59:15Z.
Rerun on RADV of the current head after the two rebases. Head
a16513746merged ontomain6bef96df7(clean merge), built in full and compared with the samemain, 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) at872a01fca: 1713/1714 with this PR, against 1712/1713 onmain. The one failure is the same on both, so this PR adds none:agc_driver_guest_memory_lifetime(#7784).Comparing the JUnit output with
main: the PR's new entry,agc_driver_wave_shared_vgprs, runs and passes. No other entry is added, and none is skipped or removed. With the Khronos validation layer,agc_driver_wave_shared_vgprspasses and adds no VUID (the only message isVkDeviceCreateInfo-pNext-pNext, which my older 1.3.275 layer prints for every device because it doesn't knowmaintenance8).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
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T12:14:47Z.
Rebased onto
main3e91c8edf, keeping @adriadam10's commit.mainnow writes request serialization version 42, so the shared VGPR fields read from version 43. The test literals moved with them, and the serializer commit's message lists the versions taken. Head691c10187.Windows 11, WinLibs GCC 15.2.0:
agc|shader|spirv|recomp|serial|wavesubset passes 882 of 886. The four are:agc_driver_image_array_window_past_layer_limit(MinGW build break onmain, #8310);agc_driver_sample_order*tests, which fail identically in a build ofmainwithout this PR.agc_driver_wave_shared_vgprs,request_serializer,agc_shader_memoryandagc_driver_graphicspass, 15 of 15.Thanks @DavidAmsellem for the RX 7900 XT RADV run.
AI-assisted: yes (Claude Code); results above were run on this machine.