fix(shader): reduce whole-wave integer additions #2008
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2008
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2008/head"
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?
@bobrass on GitHub · 2026-10-30 22:48 UTC · original
bobrass:codex/kytyps5-issue1944-subgroup-add→main· +21 −7 · 7 files · 3 commits · closed without mergingSummary
IAdd32scan in the existing read-lane elimination pass.OpGroupNonUniformIAdd, and include the new opcode in subgroup capability tracking and the existing half-wave emission guard.This targets the add/count pattern reported in issue #1944. It does not change the existing UMin, UMax, or OR matchers.
Validation
git show --checkandgit diff --checkare clean.@coderabbitai[bot] on GitHub · 2026-10-30 22:57 UTC · original · edited 2026-11-03 14:03 UTC
No actionable comments were generated in the recent review.
Walkthrough
The change adds an unsigned 32-bit subgroup integer-add opcode. The IR maps matching
IAdd32wave reductions to this opcode and records it as subgroup arithmetic. The SPIR-V backend emits the reduction withOpGroupNonUniformIAddand reuses its result for the second lane half. The tests cover addition as a successful reduction and use bitwise XOR for the wrong-operation case.Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Minimal · up to
50bceThe change is mergeable with no established blocking correctness or stability risk.
Pre-merge checks:
4 ·
1
Full details: Title check
Explanation
The title "fix(shader): reduce whole-wave integer additions" matches the main change. The PR recognizes a whole-wave IAdd32 scan in the read-lane elimination pass and lowers it to a subgroup integer-add reduction (SubgroupIAddU32 / OpGroupNonUniformIAdd). The title is short, specific, and names the affected area (shader) and the change type (fix).
Full details: Description check
Explanation
The description states the change clearly. It lists the matcher change in the read-lane elimination pass, the lowering to OpGroupNonUniformIAdd, the capability tracking and half-wave guard updates, and the updated negative matcher test. It also links issue
#1944and states what validation was and was not run. This is related to the changeset and is not off-topic.Full details: Docstring Coverage
Explanation
Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 6 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
CodeRabbit Verify
017e22b8-93b4-4bea-a946-9f1344f4c9dfReviewing files that changed from the base of the PR and between
c50559ec3band50bce2bfe0.tests/ScalarProvenanceTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-30 22:57 UTC · original · reviewed
9bb0a79e-b123-4882-a17b-e26df0875b88Reviewing files that changed from the base of the PR and between
4919fdb6e6andc50559ec3b.src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cppsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.incsrc/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cppsrc/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpptests/ScalarProvenanceTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@Nawid3333 on GitHub · 2026-10-31 02:27 UTC · original
Build test of #2008 at
c50559ec(main4919fdb6+ this commit), with the four cases from #1944. Each case ran 4 times on #2008 and on4919fdb6with the same cases. RX 9070 XT, Windows 11, AMD 26.10.1. 32 lanes are forced the same way as in the issue. The table counts runs where every pixel is (1, 0, 0, 1), i.e. sum == count:v_readlane31 + 63v_readlane0 + 32s_bcnt1_i32_b64of exec also sees only the subgroup's 32 lanes. That's the unsplit wave64 pixel shader from the first paragraph of #1944, not this PR.Tests.
scalar_provenance_tests,shader_cfg_testsandresource_materialization_testspass on both. A fullshader_recompiler_compute_testsrun stops atGpuSelectedFormattedRgba16Storeon both, so that one says nothing about this change.No unit test checks that an
IAdd32scan is actually rewritten: the PR only movesWrongOperationoffIAdd32. AnAddcase next toOrinTestCompleteWaveReductionpasses with #2008:In games. I searched the shader listings in our logs of Demon's Souls, ASTRO BOT and Assassin's Creed Black Flag Resynced (255 distinct shaders with
v_permlanex16) for this idiom. The add form (row_shr,v_readlane31 + 63,s_add_i32) is in compute shaders of Demon's Souls (11) and Assassin's Creed (10), not in any pixel shader, and no game shader there uses the row_xmask shape. In Demon's Souls, #2008 changes two of the 135 shaders that runs of both builds compiled, each 13 SPIR-V words shorter. With #2008 on top of my test build (main with thread-priority changes, where the game gets to character creation), it reaches character creation as before, at the same or a slightly higher frame rate.Coverage. In these logs, every integer whole-wave reduction (row_shr, both
v_readlaneends combined) is now matched: min, max and OR on main, add with #2008. The remaining integer add scans read only lane 31 or use the per-lane values (prefix sums), which the matcher rightly leaves alone. No matcher covers the float forms yet:v_add_f32,v_min_f32andv_max_f32whole-wave reductions in compute shaders of Demon's Souls (64) and Assassin's Creed (20), and in ASTRO BOT vertex shaders (2).@bobrass on GitHub · 2026-11-02 20:18 UTC · original
Thanks for the thorough validation across both subgroup sizes and the half-wave case. This confirms the
row_shrwhole-wave add pattern, including the 32-lane runs. Therow_xmasklane-0/lane-32 pattern remains outside this matcher and still fails, so I’ll keep that limitation explicit. The positiveIAdd32test case you outlined is useful; I’ll add it as a regression test. The fullshader_recompiler_compute_testsfailure atGpuSelectedFormattedRgba16Storereproducing on both builds is noted as unrelated to this change.@bobrass on GitHub · 2026-11-03 14:33 UTC · original
Follow-up: the current PR head now includes the positive
IAdd32case you suggested. It checks that the scan is rewritten toSubgroupIAddU32with the zero-neutral masked input. I haven’t run the test locally; your GPU runs remain the only reported runtime validation so far. Thanks again for the detailed results.@Nmzik on GitHub · 2026-11-04 08:09 UTC · original
Duplicate: #1570
@bobrass on GitHub · 2026-11-04 22:47 UTC · original
Thanks for flagging #1570. I checked its description: it includes the same IAdd32 lowering and says the overlapping lines can be dropped from whichever PR lands second. I’ll defer to whichever PR lands first and keep the overlap in mind.
Pull request closed