shader: recognize wave-wide OR reductions as OpGroupNonUniformBitwiseOr (cp2077) #1964
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!1964
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1964/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?
@ArtyomZabroda on GitHub · 2026-10-28 19:55 UTC · original
ArtyomZabroda:pr/wave-wide-or-instructions→main· +31 −16 · 7 files · 1 commits · closed without mergingCyberpunk 2077 uses a material shader that loops over material layers. Each pixel has a bitmask of the layers it needs. To keep the loop uniform across the wave, the shader first computes the OR of all pixel masks in the wave and then iterates over the bits of that combined mask; each pixel only evaluates layers that are also in its own mask.
The PS5 shader compiler emits this OR as a wave64 scan: DPP row_shr 1/2/4/8 inside each 16-lane row, v_permlanex16_b32 across rows, and finally v_readlane_b32 from lanes 31 and 63. On NVIDIA the fragment subgroup size is 32, and fragment shaders are not split into two lanes per invocation, so the read from lane 63 is undefined. Lanes that are missing from a partially filled subgroup also break the scan. As a result some pixels lose a layer bit, skip that layer and write zero to the G-buffer, which shows up as black dots on textures (I haven't made any other screenshots with this bug other than from the renderdoc, so in order to see these black dot graphical artifacts you need to zoom the picture)

EliminateReadLane already rewrites this exact pattern into a subgroup reduction, but only for UMin32 and UMax32. This PR extends WaveReductionMatcher to BitwiseOr32 and adds SubgroupBitwiseOrU32, which is emitted as OpGroupNonUniformBitwiseOr (Reduce). The reduction does not depend on the host subgroup size.
Tests: added BitwiseOr and Wave32BitwiseOr cases to TestCompleteWaveReduction; WrongOperation now uses BitwiseAnd32, since OR is supported.
Verified on an RTX 4070 SUPER: the black dots are gone.
Some screenshots from gameplay after combining this pr with #1946



@coderabbitai[bot] on GitHub · 2026-10-28 20:05 UTC · original
Walkthrough
The IR reduction matcher now recognizes bitwise-OR scans and replaces matched reductions with
SubgroupBitwiseOrU32. Shader metadata collection and scalar provenance tests include the new opcode. The SPIR-V backend declares and implements its emitter and reuses the result for the second lane half.Suggested reviewers:
nmzikPriority:
Normal
Change: Bug fix
Merge Risk:
Moderate · up to
a3e3eThe new OR reduction is correct when the host subgroup size matches the guest wave. For Wave32 pixel shaders on hardware with 64-lane subgroups, it can mix lanes from two guest waves and produce wrong rendering. Address or explicitly accept this before merging.
Pre-merge checks:
4 ·
1
Full details: Title check
Explanation
The title names the main change: wave-wide OR reductions are now recognized and mapped to OpGroupNonUniformBitwiseOr. The diff matches this. It adds BitwiseOr32 support to WaveReductionMatcher, adds the SubgroupBitwiseOrU32 opcode and emitter, and updates the tests. The title also includes the game tag (cp2077), which is a minor addition and does not make it misleading.
Full details: Description check
Explanation
The description is closely related to the changeset. It explains the Cyberpunk 2077 wave OR scan problem, the extension of WaveReductionMatcher to BitwiseOr32, the new SubgroupBitwiseOrU32 opcode emitted as OpGroupNonUniformBitwiseOr, the test changes (BitwiseOr, Wave32BitwiseOr, and WrongOperation now using BitwiseAnd32), and the verification steps.
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. (1 skipped: 1 unsupported.)
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
Comment
@coderabbitai helpto get the list of available commands.@ -860,2 +860,4 @@}uint32_t EmitSubgroupBitwiseOrU32(ValueEmitContext& ctx, const IR::Inst& inst) {return EmitSubgroupReduceU32<spv::OpGroupNonUniformBitwiseOr, EmitBitwiseOr32>(ctx, inst);@coderabbitai[bot] on GitHub · 2026-10-28 20:05 UTC · original
Keep wave32 reductions within 32 lanes.
For a wave32 graphics shader on a 64-lane host subgroup, this reduction combines both 32-lane groups. If the groups contribute masks
1and2, each receives3instead of its own mask. The graphics pipeline does not request a subgroup size, and graphics shaders use one emulated lane per invocation. (raw.githubusercontent.com)Restrict the reduction to the guest wave, or require a matching host subgroup size with a fallback where that is unavailable.
@coderabbitai[bot] on GitHub · 2026-10-28 20:06 UTC · original · reviewed
Actionable comments posted: 1
81512436-2cd7-4df9-ad7c-a6a2f20cf342Reviewing files that changed from the base of the PR and between
c67352d5d6anda3e3efaf43.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; 9 remain after this review.
@ArtyomZabroda on GitHub · 2026-10-28 20:40 UTC · original
This graphical glitch is also present in a screenshot in KyTy's readme, so you may want to replace it
@Nmzik on GitHub · 2026-10-30 04:26 UTC · original
@ArtyomZabroda Credited! Thanks
Pull request closed