fix(shader): write a GCN v_cmpx result to its VCC or SDST as well as EXEC #9671
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9671"
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 ntamas94 on 2026-10-22T07:44:59Z.
What
The GCN decoder refused every
v_cmpx_*("writes both VCC and EXEC"), so a PS4 shader with one threw at recompilation. On GCN av_cmpxis av_cmpwhose mask also lands in EXEC: the VOPC (_e32) form writes VCC, the VOP3 (_e64) form writes its SDST field and leaves VCC alone, and both destinations get the mask ANDed with the EXEC the compare ran under (inactive lane = 0), exactly like EXEC. RDNA'sv_cmpxwrites EXEC only, which is what the translator emitted.The decoder now keeps the RDNA
v_cmpxopcode, so every analysis that treatsv_cmpxas an EXEC writer is unchanged, and carries the GCN destination (VCC for VOPC, the SDST field for VOP3) in the instruction'sdestination2, as the VOP3B carry-out forms already do.emitCompareResultwrites that destination throughwriteMaskwith the same masked value it puts into EXEC; an RDNA-decodedv_cmpxhas nodestination2and behaves as before. No new opcode or tag is needed.This moves Get-fix/AnyPS5#16 (opened against
ps4/limbo-gpu) tomain, as Get-fix asked there. It was stacked on #9430, which is merged; the branch now has currentmainmerged in.Behaviour measured on HW
PS4 Pro CUH-7016B, firmware 10.71 (Sony CP firmware, real GPU), a wave64 compute dispatch submitted with
sceGnmSubmitCommandBuffersfrom homebrew. v0 = lane id; before every casevcc = 0x2222222211111111,s[8:9] = 0x4444444433333333; EXEC, VCC and s[8:9] are sampled afters_nop 4.v_cmpx_lt_u32_e32 vcc, v0, 3200000000ffffffff00000000ffffffffv_cmpx_lt_u32_e64 s[8:9], v0, 3200000000ffffffff00000000ffffffffv_cmpx_eq_f32_e32 vcc, 4.0, f32(v0)00000000000000100000000000000010v_cmpx_lt_u32_e32 vcc, v0, 64(all true)0000ffff0000ffff0000ffff0000ffff0000ffff0000ffffv_cmpx_lt_u32_e64 s[8:9], v0, 64(all true)0000ffff0000ffff0000ffff0000ffff0000ffff0000ffffv_cmpx_lt_u32_e64 vcc, v0, 3200000000ffffffff00000000ffffffffv_cmp_lt_u32_e64 s[8:9], v0, 32(control)ffffffffffffffff00000000ffffffffD and E show the destination holds the EXEC-masked mask, not the full compare; B and E show the VOP3 form does not touch VCC, and G is the plain
v_cmpcontrol. The shader, the submission code and the raw output are attached to Get-fix/AnyPS5#16 (shader.s, vcmpx.c, orbis-result.txt).Test
agc_driver_gcn_compare_exec_writes(tests/execution/GcnCompareExecWrites.cpp) builds the same seven cases from GCN field encodings (Sea Islands VOPC, VOP3, SOP1, SOPP, VOP1, MUBUF; the words equal whatclang -mcpu=bonaireassembles for the measured shader), decodes them as GCN shaders, runs the wave64 program on the device's own target and on the wave64-split target, and checks EXEC, VCC and s[8:9] of every case against the table above. Before the fix the recompilation throws; a fix that copies EXEC without writing the destination fails A, a fix that lets the VOP3 form write VCC fails B.docs/dev/debt/shader.md, new "GCN v_cmpx" entry: records the measured rule, that the measurement used the defaultFLOAT_MODE(the f32 denormal modes are not measured on GCN), how the decoder carries the destination, and two paths the test does not cover: a VOP3 SDST of EXEC, and a read of the SDST pair right after the compare.Tested
Windows 11 Pro (10.0.26200), WinLibs GCC, NVIDIA GeForce RTX 2080 (driver 617.14), Release build with
BUILD_TESTING=ON, on this branch withmain78becbb373merged in:agc_driver_gcn_compare_exec_writespasses (wave64 and wave64 split).agc_driver_vopc_compare,agc_driver_vopc_compare_f64,agc_driver_vopc_compare_table,agc_driver_vop3_compare_modifiers,agc_driver_f32_compare_constant,agc_driver_vcmp_f32_denormals,agc_driver_vcmp_eq_f16_clamp.tools/check_conventions.py --base mainwith this title and description: no findings.main78becbb373(100% tests passed out of 7;agc_driver_gcn_compare_exec_writesdoes not exist there) and this branch with thatmainmerged in (100% tests passed out of 8) withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andVK_LOADER_DEBUG=warn,error,ctest -V, on the NVIDIA GeForce RTX 2080, driver 617.14, Windows 11 (10.0.26200), Vulkan SDK 1.4.363.0: both logs carry the loader'sadding layers "VK_LAYER_KHRONOS_validation"line (14 and 16 times) and neither reportswas not found but was requested by env var VK_INSTANCE_LAYERS;VUID-ids onmain: 0, on this branch: 0, new on this branch: 0.tools/pr_overlap.py --branch: #9889 (adjacent lines inGcnInstructionDecoder.cppanddocs/dev/debt/shader.md, a union either way).Not yet run on a PS4 title with this branch.
Checklist
main; no other open PR implements the same functions (based on #9430's head, which this depends on; searchedcmpxandv_cmpxin open boykopovar/AnyPS5 PRs on 2026-10-22)NotImplemented_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)Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T08:54:15Z.
Verified: the x-family classification (
opcode < 0x100 && opcode & 0x10) selects exactly thev_cmpxfamilies in both forms — the GCN→RDNA opcode tables mirror plain/x at bit 4 well past the codes used (e.g.v_cmp_lt_u320xc1 vsv_cmpx_lt_u320xd1, both identity-mapped), so a plainv_cmpnever gains the second destination, and the VOP3 path routes the compare destination throughDecodeRdnaScalarDestinationwhile the VOPC form always carries VCC.One correction to a detail in the PR's own review: the
Four = 246literal is right, not a mislabel — the repo's RDNA inline-constant table is{0.5, -0.5, 1.0, -1.0, 2.0, -2.0, 4.0, -4.0}for encodings 240–247 (RdnaInstructionDecoder.cpp), so 246 is 4.0 and the case stringv_cmpx_eq_f32_e32 vcc, 4.0, f32(v0)matches what the decoder sees. The competing list (0.0/1.0/-1.0/-2.0/-4.0 at 240-244) is the pre-GCN8 chip constants and doesn't apply here.Two untested paths worth one sentence in the debt entry (the debt change covers the writes, which the seven measured cases pin):
v_cmpxwhose SDST is EXEC: it decodes toExecLoand the destination write plus the followingSetExectouch the same register twice — harmless in the current cleanup order, but the ordering is inferred rather than measured and isn't recorded.readMask/scalar-mask path that readsdestination2. If a title ever reads the compare mask straight out of the SGPR pair, that's the branch it runs and it is uncovered by the execution test.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:59:21Z.
Review: DISMISSED
The direct change records the GCN VOP3 SDST (or VOPC VCC) as the second destination and writes the EXEC-masked comparison through that destination while retaining RDNA's EXEC-only behavior. The seven-case wave64 test checks VOPC, VOP3 SGPR/VCC, partial EXEC, float compare, and a plain compare control. The PR also reports direct PS4 Pro hardware measurements, and its checklist identifies CUSA04865/#7941. Current-main
git diff --checkpasses; the hosted eligibility, conventions, intake, labels, and report checks pass. The PR is currently mergeable and declares its dependency on #9430.One required validation remains: CONTRIBUTING requires shader-recompiler changes to run the same focused tests on
mainand the change withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1, andANYPS5_REQUIRE_VULKAN=1, usingctest -Von the same machine/GPU. Please provide the paired output, confirm the layer loaded, compare for newVUID-errors, and record the GPU details on the checklist. The reported NVIDIA test run does not state that it used these settings or include the pairedmaincomparison. I could not run the Vulkan test locally in this environment.Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T10:13:48Z.
Thanks. Paired validation-layer run, now in the description:
main(100% tests passed, main build7e2ba73e4) and this branch (100% tests passed) withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andVK_LOADER_DEBUG=warn,error,ctest -V, on the NVIDIA GeForce RTX 2080, driver 617.14, Windows 11 (10.0.26200), Vulkan SDK 1.4.363.0: both logs carry the loader'sadding layers "VK_LAYER_KHRONOS_validation"line (78 and 16 times) and neither reportswas not found but was requested by env var VK_INSTANCE_LAYERS;VUID-ids onmain: 0, on this branch: 0, new on this branch: 0.On fogydes's two notes: the debt text is now its own "GCN v_cmpx" entry and records both, a VOP3 SDST of EXEC writing EXEC twice in an inferred order, and no case reading the SDST pair right after the compare; it also says the measurement used the default
FLOAT_MODE, so the f32 denormal modes stay RDNA2-only evidence.AI-assisted: yes (Claude Code)
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:32:24Z.
Review: COMMENTED
The updated report addresses the paired validation-layer request, and the debt entry now records the two unmeasured paths identified in the earlier review. The hardware measurement table and focused wave64 test are detailed and internally consistent; the current-main diff check is clean. I did not rerun the C++/Vulkan tests locally because there is no configured build tree and the filesystem is full.
The remaining limitation is the dependency stack: this branch is based on #9430/#9431 and still needs to be rebased against current main after those dependencies are refreshed. The description also says the affected title has not yet been run with this branch. Once the stack is current, please run the focused GCN path/title check on the resulting merge commit and update the bring-up thread if it changes the reported blocker or furthest point. The reported paired validation baseline is main
7e2ba73e4, which predates current main.Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T13:21:52Z.
Rebased onto #9430's new head (
a13d01bcc, onmain7e2ba73e4); the commit applied without conflicts, so the diff is unchanged apart from the debt entry round already posted. Paired validation-layer run, now in the description:main(100% tests passed, main build7e2ba73e4) and this branch (100% tests passed) withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andVK_LOADER_DEBUG=warn,error,ctest -V, on the NVIDIA GeForce RTX 2080, driver 617.14, Windows 11 (10.0.26200), Vulkan SDK 1.4.363.0: both logs carry the loader'sadding layers "VK_LAYER_KHRONOS_validation"line (78 and 16 times) and neither reportswas not found but was requested by env var VK_INSTANCE_LAYERS;VUID-ids onmain: 0, on this branch: 0, new on this branch: 0.AI-assisted: yes (Claude Code)
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T02:54:34Z.
Review: CHANGES_REQUESTED
The full Build of this head fails on Linux (lavapipe, llvmpipe LLVM 20.1.2, subgroup size 8), run 40053688535:
agc_driver_gcn_compare_exec_writesfails:AGC graphics: GCN compare EXEC writes wave64: v_cmpx_lt_u32_e32 vcc, v0, 32 left exec 0000000000000000, expected 00000000ffffffff. The test is new in this PR, so main has no such failure, and it is deterministic rather than an infra flake.SetExec/SetExecLo/SetExecHipluswriteMask(inst.destination2)sequence inemitCompareResult(CompareInstructions.cpp:88-94), or the test's expectation, differs between drivers. Please reproduce with lavapipe (Mesa 25.2.8 / LLVM 20.1.2, as in CI) and fix the translation or the test so all seven cases pass there.The rest of the diff (decoder
destination2, debt entry, RDNA path unchanged) looks fine; once the test is green on Linux this can go in.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T08:01:07Z.
Review: CHANGES_REQUESTED
@MarcZX10 your CHANGES_REQUESTED from 2026-10-22 is still active and blocks the merge queue; only you can clear it. Both points of it are now covered on the current head (
5086de260):VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1): 0VUID-on both sides, in the PR description.mainis merged into the branch (it merges cleanly against currentmain); the author's Gang Beasts (CUSA04865) run on this stack is in the 2026-10-22 15:44 comment.The only change since your last review is the skip on subgroups narrower than 32 lanes (the Linux lavapipe failure also hit the plain
v_cmpcontrol, so it is independent of this PR). Could you re-review and approve, or say what is still missing?