shader: emit V_CMP_CLASS with a class index or range tests #1554

Open
github-bot wants to merge 5 commits from github-bot/gh-1554 into main AGit
Owner

@⁠Nawid3333 on GitHub · 2026-10-16 12:12 UTC · original
Nawid3333:shader/cmp-class-ranges → main · +99 −68 · 3 files · 5 commits · open

Following 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)

  • Register mask: compute the input's class index (0-9) from the magnitude (zero, normal, infinity and NaN thresholds), the sign and the quiet bit, then test that bit of the mask.
  • Literal mask: emit only the selected classes, as range tests on the magnitude bits (zero, denormal, normal, infinity, signaling NaN and quiet NaN are contiguous ranges). Adjacent selected classes share one test, and the sign test is skipped when the mask selects both signs alike. F32 masks 0, 0x3ff and 3 are still folded earlier by 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

before after
SPIR-V per FPCmpClass32 / FPCmpClass16, average over the compute suite 70 / 69 17.5 / 19.3
whole compute suite (680 modules) 514,842 468,380 (-9%)
AMD ISA of a GLSL copy of both versions, register mask (RX 9070 XT / 7600X iGPU) 44 / 70 16 / 17
same, literal mask 0x3fc ("not NaN") 21 / 26 3 / 3

Same results

  • Class index vs. an if-ladder over the ISA classes: 0 differences for all 2^32 f32 inputs on an RX 9070 XT (RDNA4) and a Ryzen 7600X iGPU (RDNA2). For f16, a model of both paths matches the ISA definition for all 65,536 inputs.
  • Every literal mask 0-1023 on 28 class-boundary values of both signs passes on both GPUs, for F32 (odd masks also with bits 10-31 set) and F16 (inputs with garbage in the high half).
  • The compute test suite gives the same results as before on both GPUs (same failures, same first mismatch), also in the 32-lane split mode used for 32-wide hosts; shader_cfg_tests pass.
  • VectorCompareClassF32ImmediateAndDynamicMasks now also uses masks 1 and 2 (signaling vs. quiet NaN) and the canonical quiet NaN 0x7fc00000, 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).
  • Fork CI on 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

**@⁠Nawid3333** on GitHub · 2026-10-16 12:12 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1554) `Nawid3333:shader/cmp-class-ranges` → `main` · +99 −68 · 3 files · 5 commits · open Following 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`) - Register mask: compute the input's class index (0-9) from the magnitude (zero, normal, infinity and NaN thresholds), the sign and the quiet bit, then test that bit of the mask. - Literal mask: emit only the selected classes, as range tests on the magnitude bits (zero, denormal, normal, infinity, signaling NaN and quiet NaN are contiguous ranges). Adjacent selected classes share one test, and the sign test is skipped when the mask selects both signs alike. F32 masks 0, 0x3ff and 3 are still folded earlier by `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** | | before | after | |---|---|---| | SPIR-V per FPCmpClass32 / FPCmpClass16, average over the compute suite | 70 / 69 | 17.5 / 19.3 | | whole compute suite (680 modules) | 514,842 | 468,380 (-9%) | | AMD ISA of a GLSL copy of both versions, register mask (RX 9070 XT / 7600X iGPU) | 44 / 70 | 16 / 17 | | same, literal mask 0x3fc ("not NaN") | 21 / 26 | 3 / 3 | **Same results** - Class index vs. an if-ladder over the ISA classes: 0 differences for all 2^32 f32 inputs on an RX 9070 XT (RDNA4) and a Ryzen 7600X iGPU (RDNA2). For f16, a model of both paths matches the ISA definition for all 65,536 inputs. - Every literal mask 0-1023 on 28 class-boundary values of both signs passes on both GPUs, for F32 (odd masks also with bits 10-31 set) and F16 (inputs with garbage in the high half). - The compute test suite gives the same results as before on both GPUs (same failures, same first mismatch), also in the 32-lane split mode used for 32-wide hosts; `shader_cfg_tests` pass. - `VectorCompareClassF32ImmediateAndDynamicMasks` now also uses masks 1 and 2 (signaling vs. quiet NaN) and the canonical quiet NaN `0x7fc00000`, 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). - Fork CI on 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](https://claude.com/claude-code)
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.

For a register mask, compute the input's class index (0-9) from the
magnitude (zero, normal, infinity and NaN thresholds), the sign and the
quiet bit, and test that bit of the mask. For a literal mask, emit only the
selected classes as range tests on the magnitude bits; adjacent selected
classes share one test, and the sign test is skipped when the mask selects
both signs alike. The emitted code is integer-only.

The compute suite goes from 514,842 to 468,380 SPIR-V instructions
(FPCmpClass32 70 -> 17.5, FPCmpClass16 69 -> 19.3 per compare on average).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	src/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cpp
#	src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:35 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-16 12:16 UTC · original · edited 2026-11-03 20:14 UTC

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The SPIR-V emitter now accepts IR::Value masks 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: nmzik

Change: Refactor

Merge Risk: Minimal · up to 291ea

This 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: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive 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. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: optimizing V_CMP_CLASS emission with class-index and range tests.
Description check Passed The description directly explains the implementation, performance goals, affected opcodes, and reported validation for the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 447fe2077b and 291ead8922.

Files selected for processing: 3
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-16 12:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1554#issuecomment-6215313877) · edited 2026-11-03 20:14 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1554?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> The SPIR-V emitter now accepts `IR::Value` masks 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:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"291ead8922628b8251e7d61c172f6b6649da650a" --> <!-- change_assessment_priority:{"version":1,"urgency":"p3","manual":false} --> **Change:** Refactor <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>291ea</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `291ea` --> <!-- final_review_risk_coverage:{"sourceCommitId":"291ead8922628b8251e7d61c172f6b6649da650a","coveredCommitId":"291ead8922628b8251e7d61c172f6b6649da650a","kind":"reviewed"} --> This 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. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | 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. Documentat… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------ | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly summarizes the main change: optimizing V_CMP_CLASS emission with class-index and range tests. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the implementation, performance goals, affected opcodes, and reported validation for the changeset. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **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. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1554)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end --> <!-- verify_invitation_start --> ### CodeRabbit Verify - [ ] <!-- {"checkboxId":"run-qa-agent"} --> Run CodeRabbit Verify to test the changes in this pull request. <!-- verify_invitation_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/eecd982193ba5f3df3ddec500847ea3d99b87a0c/.coderabbit.yaml>) - **Commit**: [eecd982](<https://github.com/KytyPS5/KytyPS5/commit/eecd982193ba5f3df3ddec500847ea3d99b87a0c>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `9518051c-cdbe-4a88-a7a1-07f1a9d956b1` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 447fe2077bb43a43687e691c178a40bd22d5cb37 and 291ead8922628b8251e7d61c172f6b6649da650a. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</strong></summary> <dl> <dd> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1554/head:github-bot/gh-1554'
git switch 'github-bot/gh-1554'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1554'
git switch 'github-bot/gh-1554'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1554'
git switch 'github-bot/gh-1554'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1554'
git switch 'main'
git merge --squash 'github-bot/gh-1554'
git switch 'main'
git merge --ff-only 'github-bot/gh-1554'
git switch 'main'
git merge 'github-bot/gh-1554'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.