fix(shader): sum v_readfirstlane over the guest wave instead of shuffling it from the first lane #25609
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25609"
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 cryst4lpepsi on 2026-11-22T11:33:05Z.
What
v_readfirstlane_b32reads the first active lane's value throughOpGroupNonUniformShuffleat a lane index fromOpGroupNonUniformBallotFindLSB(EmitReadFirstLane). On AMD's Windows driver 23.19 on GCN 5, that shuffle in a pixel shader faults insidevkCreateGraphicsPipelines, at the same driver address as #18480 (amdvlk64.dll+0x21d1c24).agc_driver_pixel_helper_lanesstops there. Its pixel program runsv_readfirstlane_b32 s9, v6(0x7e120506), and it is one of the 35 tests in #3882.This reuses
EmitWaveSumfrom #24575, which is now inmain. The value is kept on the selected lane and every other lane gives 0, so anOpGroupNonUniformIAddreduction over the guest wave returns it with no lane index. The reduction reads only active invocations.ReadFirstLanevalues are 32-bit, so the sum is exact.ReadFirstLanenow requiresSubgroupLocalInvocationId, except in tessellation control programs, asLaneIddoes. Without this, programs whose other instructions did not declare it failed withSubgroupLocalInvocationId was not declared before function emission(agc_driver_table_index_validation,agc_driver_village_draw_cost).WaveSumUsableholdsEmitWaveSum's device and layout checks. It also requires the guest wave to fit in one host subgroup, so a first lane in another host subgroup never selects nothing.SubgroupLocalInvocationId, spanned waves, single-lane hosts, waves of two lanes per invocation, waves wider than the host subgroup, and devices without the subgroup operations.Tested
Windows 11 Home 22621, WinLibs GCC 15.2.0 r7, Release.
After the rebase.
main8b37b7be1fagainst this PR (dacb31af55, its three commits rebased onto thatmain).ctest -R "^agc_.*(read_?first_lane|shader_memory|helper_lanes|lds_read_modify|recorded_draw_staging|row_reduction|wave_reduction|table_index_validation|village_draw_cost|append_consume|flat_aperture_lds_bounds|readlane|subgroup|wave_sum|store_over_untracked)" -j 1 -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,APS5_NO_PIPELINE_JOURNAL=1, one GPU selected at a time withANYPS5_GPU; 3 runs without and 3 withVK_LAYER_KHRONOS_validation(1.4.369) per side and GPU. This selects 18 tests onmainand 20 with this PR, which addsagc_shader_readfirstlane_wave_sumandagc_driver_read_first_lane_shared_subgroup.mainmainagc_driver_pixel_helper_lanesmainmainagc_driver_ngg_vertex_wave_reductionskippedIn the validation runs, every test that creates a Vulkan instance logs
Insert instance layer "VK_LAYER_KHRONOS_validation".agc_shader_memory,agc_shader_memory_coherent_atomic_loads,agc_subgroup_barrier,agc_subgroup_clockandagc_shader_readfirstlane_wave_sumcreate no Vulkan instance. No run logged aVUID-orSYNC-HAZARDline.Before the rebase, on
main42120ad25cwith #24575 and this PR on top:Focused tests, with validation. Each test ran on its own (
ctest -R ^<name>$ -V) withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,APS5_NO_PIPELINE_JOURNAL=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(1.4.369) andVK_LOADER_DEBUG=layer. Every log showsInsert instance layer "VK_LAYER_KHRONOS_validation", none showswas not found, and there are noVUID-orSYNC-HAZARD-lines on either arm.mainmainagc_driver_pixel_helper_lanesagc_driver_pixel_lds_read_modify_writeagc_driver_recorded_draw_stagingagc_driver_pixel_row_reductionagc_driver_pixel_wave_reductionagc_driver_table_index_validationagc_driver_village_draw_costagc_driver_ds_append_consumeagc_driver_gds_append_consumeagc_driver_ngg_vertex_wave_reductionWhole AGC suite. All 2,037
^agc_tests ran on each GPU (-j 1, same settings without the layer) onmaina1b89f35e2with #24575 and this change before the wave-fits guard. Each failure was compared withmainunder the same settings:main.agc_driver_store_over_untracked. It then passed 10 of 10 on each GPU with the change (#22670).The guard only sends more layouts back to the shuffle. After it, the focused tests above were run again.
The failures on both arms are pre-existing:
msaa_dcc_srgb_clear_*(#14380),stencil_replay*andlook_back_scan.msaa_dcc_unwatch(#22931).538 tests did not run on either arm: their executables fail at the
objcopystep withInvalid argument, which BUILD.md attributes to Microsoft Defender.python tools/check_conventions.py --base origin/main: all checks passed.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)1002:1638), AMD proprietary driver 23.19.10.08, Windows 11 22621; NVIDIA GeForce RTX 3050 Ti Laptop GPU (10de:25a0), driver 596.36, Windows 11 22621Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T12:01:08Z.
Review: COMMENTED
Reviewed — comments
The changed shader paths appear consistent with the stated wave reduction, but the reported checks were not rerun in this review.
What I ran
Reviewed head
2c146f63cb3a2a9a7c5a0ef86e4d022324a44b2dusingrepo_read.py; no tests or builds were run.Results
Findings
Blocking
None.
Non-blocking
The reported focused and suite results are useful context, but were not independently verified in this review.
Not verified
The author-reported Windows GPU tests and convention check were not run here.
files.jsonwas not available from the review folder, so the excluded-file list could not be independently checked. The full text ofVulkanDevice.cppwas excluded by the review-folder size rule; its changed section was read throughrepo_read.py.To get this to a good state
Nothing is required. The reported test results remain author-supplied.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T16:40:21Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes at head
a862e5fbb94c6f5399eeabcf79236e8019fc8d07look consistent with the stated wave-sum and fallback behavior; the supplied test reports were not run by me.What I ran
No commands or tests were run. I inspected the prepared diff and targeted source ranges using
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read
description.md,commits.md,manifest.json,diff.patch, and targeted ranges inSpirvSubgroup.cpp,SpirvAluEmitterMath.cpp,SpirvMemoryInstructions.cpp,SpirvAnalysis.cpp,ShaderValidation.cpp, andVulkanDevice.cpp. Full text forVulkanDevice.cppandShaderMemory.cppwas excluded from the review folder; their relevant hunks were inspected in the diff, but their surrounding source was not verified. I did not run tests or verify the author-reported hardware results.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T10:05:20Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the source reviewed; the author-reported focused and suite runs are consistent with the implementation.
What I ran
Reviewed head
83006373c836d032feed2a31e9fdbf80e44439b4usingrepo_read.pyaccess to the prepared diff and pinned repository sources. No tests or build commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the review folder; their changed hunks were read indiff.patch. All other changed files markedincluded: trueinmanifest.jsonwere read at relevant ranges. Build, test execution, and the author-reported hardware results were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T10:40:22Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Read the prepared diff and targeted source at head
dacb31af55fb8a3dd44798a93aa45b9b4d6e1f09usingrepo_read.py. No build, tests, or precheck were run during this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas read only around its changed sections; its remaining contents were not read. The description's reported test runs were not independently reproduced. All other changed files listed as reviewed in the manifest were read, includingReadFirstLaneSharedSubgroup.cpp; its appearance in the execution test source listing confirms registration through the existing CMake source glob. Files excluded by the prepared review includeShaderMemory.cpp's full text because it was too large for the review folder;files.jsonwas not available through the reader.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:02:30Z.
Review: APPROVED
I read the diff at
dacb31af55. Windows 11, GCC 15.2, merged intomainat6c6b29320fetogether with other open PRs (so not an isolated build), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validationon an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).agc_driver_read_first_lane_shared_subgroup,agc_shader_readfirstlane_wave_sumandagc_shader_memory: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has aVUID-orSYNC-HAZARDline.agc_shader_memoryandagc_shader_readfirstlane_wave_sumfail, the first with "the neighbour-read test did not retain its cross-lane read".Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:31:37Z.
Review: COMMENTED
The reduction keeps only the elected lane's 32-bit contribution, and
WaveSumUsablekeeps it within a guest wave when two Wave32s share a host subgroup. The new shared-subgroup fixture is the right control for accidental cross-wave selection. Please include that fixture's execution status and selected host width in the test report, since hardware without a qualifying subgroup may skip it. The paired shader and pixel-helper tests and the new overlap fixture are queued on lavapipe.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.