perf(recompiler): emit wave-uniform values once for both lanes of a two-lane invocation #304
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/304"
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 oneandonlydean on 2026-10-02T00:24:27Z.
What
A wave64 compute or mesh program on a 32-wide host runs two lanes per invocation (
laneCount == 2), andEmitStructuredBlockemits every IR value once per lane. That includes the values the whole wave shares: each SGPR value, scalar memory load and loop phi exists twice in the module, which raises register pressure for every such program.Changes:
WaveUniformValues(inSpirvAnalysis) finds the values every lane of the wave computes alike. It is a fixed point over the program:ReadConst/ReadConstBuffer,Ballot,ReadLaneandReadFirstLane.LaneId, builtins other than the workgroup id, attributes and interpolation parameters, DPP/permlane/bpermute/swizzle,WriteLane, append/consume, and every buffer, shared, address or image access.ScalarAddressresource) counts as uniform when its operands are, since the wave performs it once.I checked that no emitter puts the first lane's definition inside a conditional of its own. The conditionals some emitters open (BDA reads,
EmitValueOrZeroIfCondition, BDA fault returns, storage image mip switches) close at their merge block, and the result is anOpPhithere. The per-lane loop emits each instruction unconditionally for both lanes. A forward reference that the second lane allocated earlier throughResultgets anOpCopyObjectfromDefine, as before.On my integration branch, four ray-traced lighting programs and one other wave64 compute program of PPSA21564 compile to about 12% fewer SPIR-V words with this change. On the RTX 4090, the two-lane modules of those programs had needed more than 255 registers and spilled to local memory.
Tested
agc_shader_memory_tests:verifyWaveUniformValueschecks the analysis on a small program. User data, a sum of it, an address resource, a scalar load through a uniform address, a value computed from that load and a ballot are uniform.LaneId, a sum with it, a scalar load at a lane-dependent offset, a global load, a value computed from the global load and a per-lane compare are not.verifyTwoLaneUniformValuesrecompiles a wave64 program (s_load_dwordx2,s_mul_i32,v_add_nc_u32,buffer_store_dword) for 32- and 64-wide hosts and requires the same number ofOpIMulin both. Without the emitter change it fails (a two-lane invocation computes a scalar value once per lane); with the change it passes.agc_driver_wave_uniformexecution test (tests/execution/WaveUniform.cpp, so ctest runs it like the other tests there): a 64-thread wave64 program with ans_buffer_load_dwordx2, a scalar loop whose phis feed a multiply,s_bcnt1_i32_b64of a VCC ballot and av_readfirstlane_b32checks every lane's stored result. It passes on the RTX 4090. As a check of the test itself, wrongly treating builtins as uniform makes it fail (thread 1 stored 1022, expected 1002). Like the other execution tests it exits 77 (skipped) without a Vulkan device, and it also skips on a subgroup narrower than 32 (lavapipe's is 8), where a wave64 does not fit in two lanes.agc_driver_bda_device_testsandagc_driver_mesh_testspass.agc_driver_recompiler_testsfails withmissing register at DWORD 0x207on main as well.ctest: 106/106 pass, including the execution tests.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