fix(shader): resolve complete Wave32 VCC words at their uses #25419
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25419"
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 mihiii1337 on 2026-11-22T02:25:05Z.
What
Resolve complete Wave32 VCC words at the use site after SSA.
v_cndmask_b32uses the guest lane index on narrow compute subgroups when the low word comes from a literal or dispatch user data and its bitwise operations.S_CBRANCH_VCCZandS_CBRANCH_VCCNZcan test the whole low word, including bits for lanes outside the launched workgroup.The pass requires a proven complete word. Complete literal/user-data bitwise words are uniform, so they can also resolve after divergent control flow; the starting-lane checks remain on ballot-derived and other lane-sensitive paths. The existing lane predicate handles comparison ballots and values of unknown origin. In #25298, the separate buffer-fed
ReadFirstLanereproduction remains open. The IR opcode table also has an append in #14217 for separate operations.Tested
Windows 11, WinLibs GCC 15.2 Release. Compared
5b308313c3and321c627b06with the same ten focused CTests, three repeats per adapter. Khronos validation 1.4.369 was loaded in both builds, caches were disabled, and the logs contained no Vulkan validation or synchronization errors.request_serializerandagc_read_lane_eliminationpassed on both builds.agc_shader_disk_cachebuild on8a7ca51ed3stopped in the WinLibsobjcopypost-link step, before that executable's tests ran.bfbc52df65: added a divergent-diamond IR regression for both lane and zero resolution. Reinstating the old use-site convergence guard makes that test fail; the final source passes. The exact final files then passed request_serializer, agc_read_lane_elimination, both Wave32 scalar-VCC GPU tests, and agc_constant_bit_test in three serial rounds each on Intel A78B (driver 101.6127) and RTX 4070 Laptop (621.01), with validation 1.4.369 loaded and no reported validation, synchronization, device-loss, or output mismatches.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)Summary by CodeRabbit
Bug Fixes
Tests
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T05:51:45Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the focused tests and inspected code support the stated Wave32 VCC fix.
What I ran
Reviewed head
321c627b0686cc494a741ea404a0b35cc60d9905using the prepared diff and pinned repository reader. No build or tests were run in this review; test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No checks were executed locally. The PR description's hardware and lavapipe runs, validation logs, and stated outcomes were not independently verified. No files were excluded from the reviewed manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Helldiverr on 2026-11-23T03:22:14Z.
Review: COMMENTED
Physical AMD/Windows run of head
321c627b0686cc494a741ea404a0b35cc60d9905. Both tests pass, andbranch_matrixfails without the change.Host: AMD Radeon AI PRO R9700 (gfx1201,
1002:7551), Windows 11 Pro build 26300, Ryzen 9 9950X3D. Windows driver 32.0.31044.16, Vulkan driver 2.0.395 (26.10.44, LLPC), API 1.4.349. WinLibs GCC 15.2.0, Release, Ninja.Subgroup width: the device log reports
subgroup=64andWave32 programs run on subgroups of 32: compute 1, mesh 1. Wave32 compute therefore runs on 32-wide subgroups here, sosmallComputeSubgroupis false and the newv_cndmaskresolve is not emitted. This host exercises thes_cbranch_vcc*change only. Foruser_datait is a no-regression check.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest --test-dir build -R "^agc_driver_wave32_scalar_vcc_(branch_matrix|user_data)$" -V, 3 serial runs per tree, same build tree:branch_matrixuser_data321c627b065b308313c3+ the two test files onlyOn the base, only the two short-wave bit-31 cases fail:
vccz_partial_bit31(8 active lanes, mask0x80000000) givesfallthrough=0x00000000 taken=0x000000ff; expected is fallthrough.vccnz_partial_bit31givesfallthrough=0x000000ff taken=0x00000000; expected is taken.The full-wave
bit0cases and thepartial_zerocases already pass on the base. On the head every case matches, withwrites_outside_active=0. Everyuser_datapath (userdata_s4,userdata_xor_and,xor_ballot_guard) hasmismatches=0on both trees. No validation layer is installed on this machine, so these runs say nothing aboutVUID-output.Source review
isCompleteWave32Maskaccepts only U32 immediates andGetUserData, closed under not/and/or/xor. All of these leaves are dispatch-uniform, so every host lane computes the same word. Everything else returns false and falls back unchanged:Phi, scalar loads, scalar arithmetic, builtins, and theBallotav_cmpwrites. That makes the proof sound, if narrow.runsAllStartingLanesaccepts only blocks on the single-predecessor chain from the entry. Given the proof above, I could not find a case the guard protects. A lane's bit of a uniform word, andword == 0, do not depend on which lanes reach the block. A VCC value written in only one arm of anifreaches the merge as aPhi, which the proof already rejects. The effect is that as_cbranch_vcczorv_cndmaskon a complete word after the first diamond, or inside a loop, still takes the old per-lane path. If the guard is meant to cover something else, a test that pins the intended fallback would make that visible. Otherwise dropping it would extend the fix to those blocks. Not blocking.v_cmpresult is aBallot, so it keeps the old path. Thexor_ballot_guardpath also passes on the base on this host, as expected.VccNonZerobecomesLogicalNot(LogicalNot(GetVcc())), becauseresolveWave32VccUsesruns after the folding loop insideFold(program). It is harmless, but it stays in the IR unless a laterFoldruns. Resolving before folding, or folding the replacement, would remove it.ConstantFolder::Fold(IrProgram&). Both production paths (Recompiler.cpp,Deserialize.cpp) call it before emission. A translate-only consumer would still seeResolveWave32Vcc*, which the SPIR-V backend has no case for. The current translate-only tests (ScalarSelectMask.cpp,DppWrite.cpp, ...) do not emit, so this is only a note.AI-assisted: yes (Claude Code, run on the hardware above)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T03:52:10Z.
Review: APPROVED
Reviewed — looks good
The reviewed change at
bfbc52df6535ae70665d883dc05f7d7548c236b5adds complete-word VCC resolution for Wave32 compute shaders on narrow subgroups; no concrete defect was found in the changed paths inspected. Nothing blocks this; the points below are optional.What I ran
Read the prepared description, commits, manifest, diff, and all ten changed files at the pinned head using the
repo_read.pyreader. No tests or builds were run in this review. The Windows and GPU test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior and test results were not independently verified. The review folder listed all ten changed files as included, and all ten were read.
files.jsonwas not present in the prepared bundle listing.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Helldiverr on 2026-11-23T03:57:57Z.
Review: COMMENTED
Re-review of head
bfbc52df65: looks correct to me.Code. The only change since my last review is dropping
!runsAllStartingLanes(program, use.Parent()) ||fromresolveWave32VccUse. I think removing it is safe:isCompleteWave32Maskonly accepts a word whose leaves are dispatch-uniform. That property does not depend on whether every starting lane reaches the use.isCompleteWave32Maskstill rejects it.completeWave32MaskAfterDivergencecovers.IR test. On this head,
agc_constant_bit_test_tests.exeexits 0. I then restored the removed condition, rebuilt only that target and ran it again. It exits 1 and reportscomplete Wave32 words resolve after divergent control flow. So the new case catches the old behaviour.GPU. I ran the short gfx1201 matrix again, three times on this head:
Each log has
Wave32 programs run on subgroups of 32: compute 1, mesh 1. None of the three containsVUID-.Caveat: no Khronos validation layer is installed on this machine, so these runs had no validation. They don't cover the
VK_INSTANCE_LAYERScheck from AGENTS.md.The base comparison from my previous review still applies: on
upstream/mainwithout the fix,branch_matrixfailed 3/3 on thepartial_bit31cases.Host:
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-23T14:14:35Z.
Review: APPROVED
Reviewed exact head
bfbc52df6535ae70665d883dc05f7d7548c236b5and the ten-file diff.The complete-word proof is conservative:
isCompleteWave32Maskaccepts only U32 immediates, user data, and recursively complete bitwise NOT/AND/OR/XOR trees; anything lane-derived, merged as a Phi, or otherwise unknown falls back to the existing mask result.ResolveWave32VccLaneis emitted only for Wave32 compute on host subgroups narrower than 32, whileResolveWave32VccZerocan resolve a complete whole VCC word at the branch use and otherwise keeps the oldGetVccresult. Removing the starting-lane reachability guard at the use is therefore safe for a dispatch-uniform complete word, and the new divergent-diamond IR case specifically fails when that old guard is restored.The exact head is mergeable and its hosted Windows, Windows/Ubuntu/macOS relinker, ASan, conventions, eligibility, portability, PR, report and labels checks are green. Helldiverr also reran the exact head on physical gfx1201 and showed the short bit-31 branch cases fail on the base and pass on this head; the user-data/constant-bit cases pass as well.
No blocking finding.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T12:07:11Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the reviewed implementation and available test evidence support merging.
What I ran
Reviewed head
1efcde5fa517b1bc1c60543f830242bdf7830ddfusing the prepared diff andrepo_read.pyfor pinned source context. No tests or builds were run; this was a read-only review.Results
Negative control
Not run by this reviewer. The PR description reports that restoring the prior convergence guard makes the new divergent IR case fail.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The reported GPU runs, validation results, and negative control were not independently run. All 10 changed files in
manifest.jsonwere reviewed at their changed hunks;files.jsonlists no excluded files.Files reviewed
core/libs/prx/libSceAgcDriver/tests/ConstantBitTest.cppcore/libs/prx/libSceAgcDriver/tests/execution/Wave32ScalarVccBranchMatrix.cppcore/libs/prx/libSceAgcDriver/tests/execution/Wave32ScalarVccUserData.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrOpcode.hppcore/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cppcore/shader/recompiler/Optimization/src/ConstantFolder.cppcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/InstructionTranslator.cppcore/shader/recompiler/Translation/src/IntegerInstructions.cppcore/shader/recompiler/Translation/src/TranslationContext/ExecMask.cppTo get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T12:14:07Z.
Review: COMMENTED
Actionable comments
ca345bf1-e27b-4542-81f8-66e266bd861eReviewing files that changed from the base of the PR and between
64386d72c5and1efcde5fa5.core/libs/prx/libSceAgcDriver/tests/ConstantBitTest.cppcore/libs/prx/libSceAgcDriver/tests/execution/Wave32ScalarVccBranchMatrix.cppcore/libs/prx/libSceAgcDriver/tests/execution/Wave32ScalarVccUserData.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrOpcode.hppcore/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cppcore/shader/recompiler/Optimization/src/ConstantFolder.cppcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/InstructionTranslator.cppcore/shader/recompiler/Translation/src/IntegerInstructions.cppcore/shader/recompiler/Translation/src/TranslationContext/ExecMask.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:35:45Z.
Review: COMMENTED
The scalar Vulkan control and constant-bit compilation test passed on main at
75021708bfand the change on the same Linux llvmpipe device with Vulkan required, shader cache disabled, and validation layer 1.4.369. The logs show layer insertion and no missing-layer diagnostic or VUID entry. The change also passed both Wave32 VCC GPU fixtures covering the branch matrix and user-data case.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.