Repository navigation
fix(shader): wave-wide exec and vcc branch conditions - #608
Conversation
s_cbranch_execz/execnz/vccz/vccnz test the whole wave mask on hardware, but the single-lane path branched on each lane's own bit, so inactive lanes took the other side and diverged in scalar state. Branch on a wave ballot instead, and execute the untested SOPP ops (cdbg branches, s_clause, s_inst_prefetch, s_setprio, s_waitcnt_depctr, s_ttracedata) against values measured on hardware. Co-Authored-By: Claude <noreply@anthropic.com>
|
Thanks, this is a real bug and the fix matches the ISA. I disassembled both kernels with In the single-lane path the branch now goes on a ballot of the wave (through Two notes for the merge order rather than the code:
CI was still running when I looked. Ready to merge from my side once it's green and that check is done. |
|
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.
|
|
Gated on PPSA21564 three times plus a warm-up, since most of its shaders take these branches: no visual or FPS change. |
Conflicts resolved: - libSceAudioPropagation/Export.cpp: upstream's boykopovar#482 + boykopovar#489 version taken; it is the same no-propagation model as astrobot's stand-in, with SourceRender and the handle-only UnregisterMaterial already in it. - State.cpp (boykopovar#453): astrobot's resident depth model kept; it already skips the tests of an absent plane (boykopovar#453's test is on astrobot since e087a4f). - Graphics.cpp, State.hpp, ShaderResources.cpp: astrobot's DepthTarget model kept (exportIndex, no DepthSurface.hpp), upstream's ThreadOwned include added. - BdaResources.cpp: astrobot's form with boykopovar#390's message. - VulkanDevice.cpp, Context.hpp, PacketExecution.cpp: both sides kept (calibrated timestamps, host query reset, GDS, memory budget; pipeline stats). - Spirv: astrobot's split-wave rules first, then boykopovar#608's wave-mask ballot and boykopovar#587's host subgroup lane; astrobot's function LDS sizing and boykopovar#573's LDS lock both kept; conditionalDepth kept in the atomic update loops; upstream's buffer atomics (boykopovar#321 boykopovar#332 boykopovar#594) and 64-bit LDS atomics taken. - TechnicalDebt.md: both sides, duplicate lines dropped. Build fixes folded in: the upstream boykopovar#453 test block duplicated next to astrobot's adapted copy removed; a lost closing brace after the host query reset block restored; lookupLog() is a function since boykopovar#590; the duplicate MUTEX_TYPE_ADAPTIVE constant (astrobot's 93b2d0e equals boykopovar#156) removed; the ops boykopovar#596 drops removed from the masked-select list and the BDA test message updated (the gate-batch-2 integ commits 559e4fab6 and 2ec968fb5).
What
Bug:
s_cbranch_execz,s_cbranch_execnz,s_cbranch_vcczands_cbranch_vccnztest the whole wave mask on hardware (RDNA2 ISA: "if (EXEC == 0) then PC = ..."), but the single-lane SPIR-V path (wave32, and wave64 on a 64-lane subgroup) branched on each invocation's own EXEC/VCC bit. With a partial mask, the inactive lanes took the other side of the branch, ran the scalar code there and came back with different "scalar" registers, so lanes that HW leaves alone saw wrong SGPR values once EXEC was restored. Example:s_and_saveexec_b32 s14, vcc_lo+s_cbranch_execnzwith 5 of 32 lanes active: HW skips the fall-through for the whole wave, AnyPS5 ran it for the 27 inactive lanes.The fix branches on a ballot of the wave in that path (
EmitWaveBallot, so a wave32 inside a 64-lane subgroup only sees its own 32 lanes): non-zero kinds = any lane set, zero kinds = no lane clear. The two-half wave64 path already did this and is unchanged. The analysis now requestsGroupNonUniformBallotfor these branches: without it, a shader whose only cross-lane op is the branch failsspirv-val("OpGroupNonUniformBallot requires one of these capabilities: GroupNonUniformBallot"; checked withs_mov_b32 exec_lo, 0x1f+s_cbranch_execz).Test
agc_driver_scalar_program_flowalso executes the SOPP ops that no test ran yet, all matching HW with main's translation (no change there):s_cbranch_execnz,s_cbranch_cdbgsys,s_cbranch_cdbguser,s_cbranch_cdbgsys_or_user,s_cbranch_cdbgsys_and_user(not taken),s_clause,s_inst_prefetch,s_setprio,s_waitcnt_depctr,s_ttracedata.s_trapis left out on purpose: main treats it as a no-op, and what it should do without a trap handler is a separate question.Behaviour measured on HW
gfx1035 oracle, wave32 and wave64, 3 random seeds each, 0 mismatches against the model: EXEC from bit k of each lane's input (random, only lane 40 = upper wave64 half only, only lane 5), then execnz/execz/vccnz/vccz with scalar code on the skipped side. All lanes read the same SGPR result, decided by "any lane set" for the whole wave. cdbg branches are never taken. The expected values in the test are the HW results.
Tested
Linux, RADV (Mesa 26.2), local lavapipe and CI's lavapipe (Mesa 25.2.8, cold: 0 s). The test runs wave32, wave64 native and wave64 split (
ComputeTarget(32)). With main'sEmitBranchConditionit fails (program flow wave32: lane 0 execnz_partial is 0x51c9e72a, expected 0x51c9bd70); restricting the fix to EXEC only fails onvccnz_partial, ignoring the ballot's high word fails onexecnz_upper_half(wave64), treating zero kinds as "any" fails onexecz_partial. On lavapipe (8-lane subgroups, narrower than a wave) only the cdbg/hint columns are checked; the branch columns skip there, like the other cross-lane tests. Full Release ctest: all pass exceptagc_driver_pixel_helper_lanes, which fails the same way on main on RADV.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)