fix(shader): read lane 63 of a wave64 v_max_f32/v_min_f32 half-wave scan #2451
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2451"
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-09T21:28:00Z.
What
#1268 reads lanes 31 and 63 of a wave64 DPP row scan as half-wave reductions, but only for integer steps (UMin/UMax/SMin/SMax/IAdd/AND/OR). A wave64 vertex program does the same scan with
v_max_f32:row_shrDPP steps andv_permlanex16_b32follow;v_readlane_b32of lanes 31 and 63, combined by one morev_max_f32.On a 32-lane host subgroup the read of lane 63 threw:
The matcher now also accepts
FPMax32andFPMin32steps, with theirBitCasts, and identities -inf and +inf. It also looks through the f32 denormal flush the float mode adds around each operand and result ((x & 0x7f800000) == 0 ? x & 0x80000000 : x, #1850); the flush leaves -inf and +inf unchanged.The emission adds no float arithmetic. Once the entry EXEC proves that lanes 32-63 hold the constant key, every step there combines the constant with itself. Main's
v_max_f32/v_min_f32lowering (EmitMinMaxF32Value) returns the operand for equal operands, NaN included. So lane 63 is exactly that constant, and the read returns it.Everything else keeps its existing lowering, so NaN and signed-zero results are the ones the shader already computes:
v_max_f32.No
OpGroupNonUniformFMax/FMinis emitted, because their NaN and signed-zero results are not defined to matchv_max_f32.Touches
core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp.The level in the test below needs this and "fix(shader): match half-wave reductions in vertex programs" together; the two are independent and either can go in first.
This and #2450 add a test at the same place in
tests/ShaderMemory.cpp, so whichever lands second needs a small rebase of that file; the code changes merge cleanly.Tested
maina8b032b236: ctest 495/495.tools/check_conventions.pypasses.agc_shader_memory,verifyHalfWaveReduction:v_max_f32and av_min_f32scan build on 32 lanes with no subgroup arithmetic, and on 64 lanes. Onmainthe 32-lane case throws the line above.v_max_f32scan joined byv_min_f32, and av_max_f32scan of 0 outside the live lanes.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)Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T22:50:13Z.
Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at
5435cb28:/tmp/anyps5_build) with zero warnings/errors.python3 tools/check_conventions.py --base origin/main --head HEAD-> PASS (0 errors).v_max_f32/v_min_f32half-wave scan inSpirvAluEmitterMath.cppandShaderMemory.cpp. Correctly incorporates lane 63 boundary value during 64-lane reductions.LGTM!
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T22:52:30Z.
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
5435cb28, merged ontomain09a3462ewith #2473, which currentmainneeds to build on Windows, and #2470.agc_shader_memory, which passes, as doesagc_shader_bindless.ShaderMemory.cppwith #2450 (which passes in a separate build), so those two can't be merged together as they stand.No title was run.
🤖 Addressed by Claude Code