shader: emit V_CMP_CLASS with a class index or range tests #1554
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!1554
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1554"
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?
@Nawid3333 on GitHub · 2026-10-16 12:12 UTC · original
Nawid3333:shader/cmp-class-ranges→main· +99 −68 · 3 files · 5 commits · openFollowing up on the idea in #1534. V_CMP_CLASS_F32/F16 and the CMPX forms built all ten class tests and OR-ed them under the mask: about 70 SPIR-V instructions per compare, also for a literal mask.
Games: in the shaders our runs decoded (3016 distinct shaders of four games), V_CMP_CLASS_F32 occurs 4241 times in 594 shaders: Demon's Souls 2477, Ghost of Yōtei 1307, Assassin's Creed Black Flag 450, ASTRO BOT 7; V_CMPX_CLASS_F32 129 more.
Tested in Ghost of Yōtei (PPSA26344, Radeon RX 9070 XT, empty Kyty shader store, with #1967, #1758, #1878, #2062 and #2090 to get this far): with this change the game compiles shaders with 2013 V_CMP_CLASS_F32 instructions, reaches the same screen as without it (the Digital Deluxe Bonus screen, which waits for a button press), and logs no error. The first run with the new SPIR-V stayed black longer only while the driver compiled every pipeline for the first time (its own pipeline cache already held the old modules); the second run matches.
Change (
spirvEmitterAluHelpers.cpp,spirvEmitterInternal.h)ConstantPropagation.The emitted code is integer-only (ANDs, compares, adds and subtracts, selects, one shift by 0-9), so it doesn't depend on host float behaviour. All four opcodes go through
FPCmpClass32/16, so CMPX gets the same code.Size
Same results
shader_cfg_testspass.VectorCompareClassF32ImmediateAndDynamicMasksnow also uses masks 1 and 2 (signaling vs. quiet NaN) and the canonical quiet NaN0x7fc00000, with literal and register masks. Before, no case told the two NaN classes apart at that boundary. Main gives the same results, but its 32-lane shader for this case is 70,147 SPIR-V words, over the test's size limit (56,400); with this change it is 34,575 (RX 9070 XT).291ead892: the Windows, Linux and macOS builds pass.Written with Claude Code (AI): it wrote the change and ran the tests and measurements on my PC (Windows 11; driver 26.8.1 for the measurements above, 26.10.1 for the Ghost of Yōtei runs). I reviewed the diff and this description before opening the PR.
🤖 Generated with Claude Code
906d2556into shader/cmp-class-ranges 53ee5f392f@coderabbitai[bot] on GitHub · 2026-10-16 12:16 UTC · original · edited 2026-11-03 20:14 UTC
No actionable comments were generated in the recent review.
Walkthrough
The SPIR-V emitter now accepts
IR::Valuemasks for F32 and F16 class checks. It evaluates dynamic masks with a class-index bit lookup. For immediate masks, it groups selected classes into magnitude ranges and handles sign-dependent selections. The test data uses a quiet-NaN value and includes individual masks for the first two architectural class bits.Suggested reviewers:
nmzikChange: Refactor
Merge Risk:
Minimal · up to
291eaThis change makes V_CMP_CLASS shader generation smaller by using a class-index lookup for register masks and range tests for literal masks. The supplied evidence shows no concrete defect, and the author reports exhaustive F32 and F16 checks and passing test suites. The residual uncertainty is routine and does not block merge.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.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 3 functions across 2 files. (1 skipped: 1 too large.)
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
9518051c-cdbe-4a88-a7a1-07f1a9d956b1Reviewing files that changed from the base of the PR and between
447fe2077band291ead8922.src/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.