shader: output modifiers turn -0 into +0 #1620

Closed
github-bot wants to merge 7 commits from gh-pr/1620/head into gh-pr/1620/base
Owner

@⁠Nawid3333 on GitHub · 2026-10-17 20:56 UTC · original
Nawid3333:shader/omod-signed-zero → main · +37 −0 · 2 files · 7 commits · closed without merging

What is wrong

Many RDNA float instructions can scale their result by 2, 4 or 0.5 in the same instruction. This is the output modifier (OMOD), shown as mul:2, mul:4 or div:2 in disassembly. The RDNA2 ISA (section 6.2.2, "Instruction Outputs") says: "Output modifiers are not IEEE compatible: -0 is flushed to +0."

Kyty applies OMOD as a plain multiply, and a plain multiply keeps the sign of zero (-0 × 2 = -0). So where the hardware writes +0, Kyty writes -0. It only shows when later code depends on the sign of zero, for example 1/x (-inf instead of +inf), atan2, a sign test or a bit comparison. LLVM's AMDGPU backend relies on the same hardware rule: it only folds a multiply into OMOD when the sign of zero doesn't matter (SIFoldOperands.cpp: "omod is ignored by hardware if IEEE bit is enabled. omod also does not correctly handle signed zeros.").

What changes

Before the OMOD multiply, Kyty adds +0.0 to the result. -0 + (+0) = +0, and x + 0 = x for every other number (a NaN stays a NaN), so only a -0 going into the modifier changes. The module already declares SignedZeroInfNanPreserve 32, which doesn't allow the driver to remove the add. Clamp still comes after it. Instructions without OMOD are not affected.

The add comes before the multiply, not after it, because the hardware keeps the sign of a zero that the modifier itself produces. I measured this on an RDNA2 GPU (Ryzen 7600X iGPU, gfx1036, AMD driver 26.10.1) with AnyPS5's tools/hw-oracle, IEEE mode off, f32 denormals flushed, round to nearest:

input × 1.0 mul:2 div:2 mul:4 no OMOD
-0 (0x80000000) 0x00000000 0x00000000 0x00000000 0x80000000
-2^-126 (0x80800000) 0x81000000 0x80000000 0x81800000 0x80800000
denormal 0x80400000 0x00000000 0x00000000 0x00000000 0x80000000
0x80ffffff 0x817fffff 0x80000000 0x81ffffff 0x80ffffff
-0.5 (0xbf000000) 0xbf800000 0xbe800000 0xc0000000 0xbf000000

A -0 (or a flushed denormal) going into the modifier becomes +0, but -2^-126 with div:2 gives -0. With the add after the multiply, Kyty turned that -0 into +0 too; with the add before it, the -0 the multiply produces stays. AnyPS5's RDNA2 (gfx1035) test pins the same row (core/libs/prx/libSceAgcDriver/tests/execution/F32OutputModifier.cpp).

What doesn't change

The same ISA section says OMOD does nothing at all when IEEE mode is set or when output denormals are enabled. Kyty doesn't look at those two bits today (IEEE_MODE isn't passed to the recompiler, FLOAT_MODE only for compute shaders), so in those modes it already applies OMOD to every value, before and after this change. Compilers only emit OMOD when both bits are off, as LLVM does.

Tests

  • Vop3OutputModifierFlushesNegativeZero: -0.0 × 1.0 with mul:2 and -0.0 + -0.0 with div:2 give +0, -0.5 × 1.0 with mul:4 gives -2.0, -0.0 × 1.0 without OMOD stays -0, -0.0 × 1.0 with mul:2 in the SDWA encoding gives +0, and -2^-126 × 1.0 with div:2 has the same sign as the same underflow without OMOD (-2^-126 × 0.5 as a plain multiply). Kyty selects no f32 denormal mode, so a device may keep the denormal or flush it, and the spec doesn't fix the sign of a flushed denormal (KhronosGroup/SPIRV-Registry#430); comparing with the plain multiply holds either way. A last row checks that clamp still comes after the modifier: 2.0 × 1.0 with div:2 and clamp gives 1.0 (measured the same way on the iGPU; clamping first would give 0.5).
  • On current main (eecd98219) with #2038 (needed to start the compute tests on this GPU, see #2036), RX 9070 XT, AMD driver 26.10.1: this test, CvtPkrtzF16F32SdwaAndOutputModifiers and VectorFloatArithmeticOps pass. With the add after the multiply (this PR's first commit) the div:2 row fails: the modifier gives +0 while the plain multiply gives -0. With main's code the -0 rows fail.
  • The compute harness has unrelated failures on this GPU on main (for example IndirectImageQueryDimensions), so I ran the three output-modifier cases by name.
  • shader_cfg_tests (not run by CI) passes.
  • Fork CI on 477386b88: the Windows, Linux and macOS builds pass.

If you'd like this done differently, tell me and I'll change it.

Written with Claude Code (AI): it wrote the change and the test, ran the tests and the hardware measurement on my PC (Windows 11, RX 9070 XT and Ryzen 7600X iGPU).

🤖 Generated with Claude Code

**@⁠Nawid3333** on GitHub · 2026-10-17 20:56 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620) `Nawid3333:shader/omod-signed-zero` → `main` · +37 −0 · 2 files · 7 commits · closed without merging **What is wrong** Many RDNA float instructions can scale their result by 2, 4 or 0.5 in the same instruction. This is the output modifier (OMOD), shown as `mul:2`, `mul:4` or `div:2` in disassembly. The RDNA2 ISA (section 6.2.2, "Instruction Outputs") says: "Output modifiers are not IEEE compatible: -0 is flushed to +0." Kyty applies OMOD as a plain multiply, and a plain multiply keeps the sign of zero (-0 × 2 = -0). So where the hardware writes +0, Kyty writes -0. It only shows when later code depends on the sign of zero, for example `1/x` (-inf instead of +inf), `atan2`, a sign test or a bit comparison. LLVM's AMDGPU backend relies on the same hardware rule: it only folds a multiply into OMOD when the sign of zero doesn't matter (`SIFoldOperands.cpp`: "omod is ignored by hardware if IEEE bit is enabled. omod also does not correctly handle signed zeros."). **What changes** Before the OMOD multiply, Kyty adds +0.0 to the result. -0 + (+0) = +0, and x + 0 = x for every other number (a NaN stays a NaN), so only a -0 going into the modifier changes. The module already declares `SignedZeroInfNanPreserve 32`, which doesn't allow the driver to remove the add. Clamp still comes after it. Instructions without OMOD are not affected. The add comes before the multiply, not after it, because the hardware keeps the sign of a zero that the modifier itself produces. I measured this on an RDNA2 GPU (Ryzen 7600X iGPU, gfx1036, AMD driver 26.10.1) with AnyPS5's `tools/hw-oracle`, IEEE mode off, f32 denormals flushed, round to nearest: | input × 1.0 | `mul:2` | `div:2` | `mul:4` | no OMOD | |---|---|---|---|---| | -0 (0x80000000) | 0x00000000 | 0x00000000 | 0x00000000 | 0x80000000 | | -2^-126 (0x80800000) | 0x81000000 | **0x80000000** | 0x81800000 | 0x80800000 | | denormal 0x80400000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x80000000 | | 0x80ffffff | 0x817fffff | **0x80000000** | 0x81ffffff | 0x80ffffff | | -0.5 (0xbf000000) | 0xbf800000 | 0xbe800000 | 0xc0000000 | 0xbf000000 | A -0 (or a flushed denormal) going into the modifier becomes +0, but -2^-126 with `div:2` gives -0. With the add after the multiply, Kyty turned that -0 into +0 too; with the add before it, the -0 the multiply produces stays. AnyPS5's RDNA2 (gfx1035) test pins the same row (`core/libs/prx/libSceAgcDriver/tests/execution/F32OutputModifier.cpp`). **What doesn't change** The same ISA section says OMOD does nothing at all when IEEE mode is set or when output denormals are enabled. Kyty doesn't look at those two bits today (`IEEE_MODE` isn't passed to the recompiler, `FLOAT_MODE` only for compute shaders), so in those modes it already applies OMOD to every value, before and after this change. Compilers only emit OMOD when both bits are off, as LLVM does. **Tests** - `Vop3OutputModifierFlushesNegativeZero`: -0.0 × 1.0 with `mul:2` and -0.0 + -0.0 with `div:2` give +0, -0.5 × 1.0 with `mul:4` gives -2.0, -0.0 × 1.0 without OMOD stays -0, -0.0 × 1.0 with `mul:2` in the SDWA encoding gives +0, and -2^-126 × 1.0 with `div:2` has the same sign as the same underflow without OMOD (-2^-126 × 0.5 as a plain multiply). Kyty selects no f32 denormal mode, so a device may keep the denormal or flush it, and the spec doesn't fix the sign of a flushed denormal (KhronosGroup/SPIRV-Registry#430); comparing with the plain multiply holds either way. A last row checks that clamp still comes after the modifier: 2.0 × 1.0 with `div:2` and clamp gives 1.0 (measured the same way on the iGPU; clamping first would give 0.5). - On current main (eecd98219) with #2038 (needed to start the compute tests on this GPU, see #2036), RX 9070 XT, AMD driver 26.10.1: this test, `CvtPkrtzF16F32SdwaAndOutputModifiers` and `VectorFloatArithmeticOps` pass. With the add after the multiply (this PR's first commit) the `div:2` row fails: the modifier gives +0 while the plain multiply gives -0. With main's code the -0 rows fail. - The compute harness has unrelated failures on this GPU on main (for example `IndirectImageQueryDimensions`), so I ran the three output-modifier cases by name. - `shader_cfg_tests` (not run by CI) passes. - Fork CI on 477386b88: the Windows, Linux and macOS builds pass. If you'd like this done differently, tell me and I'll change it. Written with Claude Code (AI): it wrote the change and the test, ran the tests and the hardware measurement on my PC (Windows 11, RX 9070 XT and Ryzen 7600X iGPU). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
RDNA2 ISA 6.2.2: "Output modifiers are not IEEE compatible: -0 is flushed to +0." Add +0 after the
omod multiply.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A -0 result becomes +0 under an output modifier, but a negative result that
div:2 scales below the smallest normal keeps its sign (RDNA2: -2^-126 * 1.0
div:2 = -0). Adding +0 after the multiply turned that -0 into +0; adding it
before keeps it.
The emitted SPIR-V selects no f32 denormal mode, so -2^-126 * 1.0 with div:2
is -0 on a device that flushes f32 denormals and -2^-127 on one that keeps
them. Both are negative; +0 is the wrong result.
RDNA2 applies OMOD before clamp: 2.0 * 1.0 with div:2 and clamp gives 1.0
(clamping first would give 0.5).
A device may flush the denormal result to either zero, so the check now only requires both results to
have the same sign.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:01:47 +00:00
github-bot closed this pull request 2026-11-26 10:01:47 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 21:10 UTC · original · edited 2026-11-03 23:44 UTC

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

ApplyF32ResultModifiers now adds 0.0f before multiplying an F32 result by the selected output modifier. A new compute test assembles instructions with multiple output modifier settings and related VOP2 and SDWA operations. It stores results and checks expected output words and opcodes. The test is registered with the compute test suite.

Suggested reviewers: nmzik

Change: Bug fix

Merge Risk: Moderate · previous review 58b3d

The new shader test can reject permitted results on some Vulkan devices. Make the assertion portable before merging.

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 and concisely describes the main change: output modifiers convert negative zero to positive zero.
Description check Passed The description is directly related to the changeset. It explains the OMOD behavior, implementation, test coverage, and validation results.
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 1 functions across 1 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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
**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 21:10 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#issuecomment-6241143501) · edited 2026-11-03 23:44 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/1620?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 --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: 58b3d0747f9d1adf3edd6d928d80c504a8e572fc > - Latest commit, not reviewed: 477386b88635c2e758857e5282e89ca042e75f6a > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> `ApplyF32ResultModifiers` now adds `0.0f` before multiplying an F32 result by the selected output modifier. A new compute test assembles instructions with multiple output modifier settings and related VOP2 and SDWA operations. It stores results and checks expected output words and opcodes. The test is registered with the compute test suite. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"58b3d0747f9d1adf3edd6d928d80c504a8e572fc" --> <!-- change_assessment_priority:{"version":1,"urgency":"p3","manual":false} --> **Change:** Bug fix <!-- 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-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Moderate</strong> · previous review <code>58b3d</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟡 Moderate** · up to `58b3d` --> <!-- final_review_risk_coverage:{"sourceCommitId":"58b3d0747f9d1adf3edd6d928d80c504a8e572fc","coveredCommitId":"58b3d0747f9d1adf3edd6d928d80c504a8e572fc","kind":"reviewed"} --> The new shader test can reject permitted results on some Vulkan devices. Make the assertion portable before merging. <!-- 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 and concisely describes the main change: output modifiers convert negative zero to positive zero. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is directly related to the changeset. It explains the OMOD behavior, implementation, test coverage, and validation results. | | 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 1 functions across 1 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 --> <!-- announcements_start --> > [!TIP] > <details> > <summary><strong>🎯 Customize your risk assessments</strong></summary> > <dl> > <dd> > > Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using **Merge Risk Instructions** and **Security Risk Instructions** in your review settings. Security architecture risk assessments require the **Advanced plan or above**. > > </dd> > </dl> > </details> > > <details> > <summary><strong>✅ Automatic approvals, with your rules</strong></summary> > <dl> > <dd> > > Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable **Automatic approvals** in review settings, with overrides for teams or file paths. > > </dd> > </dl> > </details> <!-- announcements_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1620)! 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 -->
@ -369,6 +369,7 @@ IR::F32 Translator::ApplyF32ResultModifiers(const Decoder::Operand& operand, IR:
case 2u: multiplier = 4.0f; break;
default: break;
}
value = IR::F32(ir.Emit(IR::ValueOpcode::FPAdd32, {value, IR::Value::F32(0.0f)}));
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 21:10 UTC · original · edited 2026-10-17 21:14 UTC

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Trace whether floating-point mode settings reach OMOD handling.
rg -n 'ApplyF32ResultModifiers|float_mode|denorm|IEEE|output_denorm' \
  src/graphics/shader/recompiler

Repository: KytyPS5/KytyPS5

Length of output: 4652


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- Translate.cpp helper and callers ---'
sed -n '330,400p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
sed -n '430,475p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
sed -n '1385,1430p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
printf '%s\n' '--- Float.cpp ---'
sed -n '1,115p' src/graphics/shader/recompiler/frontend/translate/Float.cpp
printf '%s\n' '--- Convert.cpp ---'
sed -n '110,160p' src/graphics/shader/recompiler/frontend/translate/Convert.cpp
printf '%s\n' '--- Translator declarations/constructor context ---'
sed -n '1,90p' src/graphics/shader/recompiler/frontend/translate/Translator.h
rg -n -F -- 'float_mode' src/graphics/shader/recompiler/frontend src/graphics/shader/recompiler/ShaderRecompiler.cpp src/graphics/shader/recompiler/backend/spirv

Repository: KytyPS5/KytyPS5

Length of output: 20842


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- translator construction and input-info propagation ---'
sed -n '500,555p' src/graphics/shader/recompiler/ShaderRecompiler.cpp
sed -n '790,840p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
printf '%s\n' '--- float_mode declarations and comments ---'
rg -n -F --glob '*.{h,cpp,md,txt}' -e 'float_mode' -e 'FloatMode' -e 'IEEE' -e 'denorm' src | head -200
printf '%s\n' '--- relevant input-info type declarations ---'
rg -n -F --glob '*.{h,cpp}' -e 'struct Compute' -e 'ComputeInput' -e 'InputInfo' src/graphics/shader/recompiler src/graphics | head -100

Repository: KytyPS5/KytyPS5

Length of output: 23559


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- shader input structs and compute propagation ---'
sed -n '145,175p' src/graphics/shader/shader.h
sed -n '375,405p' src/graphics/shader/shader.cpp
sed -n '985,1020p' src/graphics/guest_gpu/command_processor/pm4Handlers.cpp
printf '%s\n' '--- recompiler entry and translation scope ---'
sed -n '180,245p' src/graphics/shader/recompiler/ShaderRecompiler.cpp
rg -n -F -- 'Frontend::Translator' src/graphics/shader/recompiler

Repository: KytyPS5/KytyPS5

Length of output: 8222


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- FLOAT_MODE field definitions ---'
sed -n '900,925p' src/graphics/guest_gpu/pm4.h
rg -n -F -- 'COMPUTE_PGM_RSRC1_FLOAT_MODE_SHIFT' src/graphics/guest_gpu
printf '%s\n' '--- enclosing compute translation function ---'
sed -n '430,545p' src/graphics/shader/recompiler/ShaderRecompiler.cpp
printf '%s\n' '--- compute register structure fields ---'
sed -n '600,630p' src/graphics/guest_gpu/hardwareContext.h

Repository: KytyPS5/KytyPS5

Length of output: 7664


🌐 Web query:

official AMD RDNA2 ISA output modifier OMOD IEEE mode output denormals ignored

💡 Result:

The **official AMD RDNA 2 ISA Reference Guide** says OMOD is ignored in either of these cases:

- **IEEE mode bit = 1:** output modifiers are ignored.
- **Output denormals are enabled:** output modifiers are ignored. If output denormals are disabled, OMOD is applied and denormals are flushed to zero.

It also notes OMOD is not IEEE-compatible because it flushes −0 to +0. ([amd.com](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf?utm_source=openai))

AMD’s guide is Document 70648, released November 30, 2020. ([amd.com](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf))

Citations:

- 1: https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf?utm_source=openai
- 2: https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf

Gate OMOD on the active floating-point modes.

PrepareCallTarget passes only an input-denormal flag to Translator; it does not pass ieee_mode or the complete float_mode. ApplyF32ResultModifiers then applies FPMul32 and FPAdd32 for every nonzero operand.omod. When IEEE mode or output denormals are enabled, this can change results such as -0.0f to +0.0f, although RDNA2 ignores OMOD in those modes.

Pass the relevant mode settings into Translator and skip both OMOD operations when OMOD is inactive. Keep clamp handling unchanged.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 21:10 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#discussion_r4304519626) · edited 2026-10-17 21:14 UTC **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash set -euo pipefail # Trace whether floating-point mode settings reach OMOD handling. rg -n 'ApplyF32ResultModifiers|float_mode|denorm|IEEE|output_denorm' \ src/graphics/shader/recompiler ``` Repository: KytyPS5/KytyPS5 Length of output: 4652 --- 🏁 Script executed: ```bash set -euo pipefail printf '%s\n' '--- Translate.cpp helper and callers ---' sed -n '330,400p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp sed -n '430,475p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp sed -n '1385,1430p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp printf '%s\n' '--- Float.cpp ---' sed -n '1,115p' src/graphics/shader/recompiler/frontend/translate/Float.cpp printf '%s\n' '--- Convert.cpp ---' sed -n '110,160p' src/graphics/shader/recompiler/frontend/translate/Convert.cpp printf '%s\n' '--- Translator declarations/constructor context ---' sed -n '1,90p' src/graphics/shader/recompiler/frontend/translate/Translator.h rg -n -F -- 'float_mode' src/graphics/shader/recompiler/frontend src/graphics/shader/recompiler/ShaderRecompiler.cpp src/graphics/shader/recompiler/backend/spirv ``` Repository: KytyPS5/KytyPS5 Length of output: 20842 --- 🏁 Script executed: ```bash set -euo pipefail printf '%s\n' '--- translator construction and input-info propagation ---' sed -n '500,555p' src/graphics/shader/recompiler/ShaderRecompiler.cpp sed -n '790,840p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp printf '%s\n' '--- float_mode declarations and comments ---' rg -n -F --glob '*.{h,cpp,md,txt}' -e 'float_mode' -e 'FloatMode' -e 'IEEE' -e 'denorm' src | head -200 printf '%s\n' '--- relevant input-info type declarations ---' rg -n -F --glob '*.{h,cpp}' -e 'struct Compute' -e 'ComputeInput' -e 'InputInfo' src/graphics/shader/recompiler src/graphics | head -100 ``` Repository: KytyPS5/KytyPS5 Length of output: 23559 --- 🏁 Script executed: ```bash set -euo pipefail printf '%s\n' '--- shader input structs and compute propagation ---' sed -n '145,175p' src/graphics/shader/shader.h sed -n '375,405p' src/graphics/shader/shader.cpp sed -n '985,1020p' src/graphics/guest_gpu/command_processor/pm4Handlers.cpp printf '%s\n' '--- recompiler entry and translation scope ---' sed -n '180,245p' src/graphics/shader/recompiler/ShaderRecompiler.cpp rg -n -F -- 'Frontend::Translator' src/graphics/shader/recompiler ``` Repository: KytyPS5/KytyPS5 Length of output: 8222 --- 🏁 Script executed: ```bash set -euo pipefail printf '%s\n' '--- FLOAT_MODE field definitions ---' sed -n '900,925p' src/graphics/guest_gpu/pm4.h rg -n -F -- 'COMPUTE_PGM_RSRC1_FLOAT_MODE_SHIFT' src/graphics/guest_gpu printf '%s\n' '--- enclosing compute translation function ---' sed -n '430,545p' src/graphics/shader/recompiler/ShaderRecompiler.cpp printf '%s\n' '--- compute register structure fields ---' sed -n '600,630p' src/graphics/guest_gpu/hardwareContext.h ``` Repository: KytyPS5/KytyPS5 Length of output: 7664 --- 🌐 Web query: `official AMD RDNA2 ISA output modifier OMOD IEEE mode output denormals ignored` 💡 Result: ``` The **official AMD RDNA 2 ISA Reference Guide** says OMOD is ignored in either of these cases: - **IEEE mode bit = 1:** output modifiers are ignored. - **Output denormals are enabled:** output modifiers are ignored. If output denormals are disabled, OMOD is applied and denormals are flushed to zero. It also notes OMOD is not IEEE-compatible because it flushes −0 to +0. ([amd.com](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf?utm_source=openai)) AMD’s guide is Document 70648, released November 30, 2020. ([amd.com](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf)) Citations: - 1: https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf?utm_source=openai - 2: https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf ``` --- </details> **Gate OMOD on the active floating-point modes.** `PrepareCallTarget` passes only an input-denormal flag to `Translator`; it does not pass `ieee_mode` or the complete `float_mode`. `ApplyF32ResultModifiers` then applies `FPMul32` and `FPAdd32` for every nonzero `operand.omod`. When IEEE mode or output denormals are enabled, this can change results such as `-0.0f` to `+0.0f`, although RDNA2 ignores OMOD in those modes. Pass the relevant mode settings into `Translator` and skip both OMOD operations when OMOD is inactive. Keep clamp handling unchanged. <!-- fingerprinting:phantom:triton:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:578163597462cb9c741f6650 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 21:10 UTC · original · reviewed


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 221b2489-fd4b-4f8a-a49c-8facdcfb93be
📥 Commits

Reviewing files that changed from the base of the PR and between 763d3be3a9 and 04cc9924fd.

📒 Files selected for processing: 2
  • src/graphics/shader/recompiler/frontend/translate/Translate.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 21:10 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#pullrequestreview-5560109678) · **reviewed** <!-- coderabbit-ai-generated:v1 --> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `221b2489-fd4b-4f8a-a49c-8facdcfb93be` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 763d3be3a9bc4e5a068d7cf52015030d6c03308f and 04cc9924fdad501344b83e5bb3bd4f51510a492d. </details> <details> <summary>📒 Files selected for processing: 2</summary> * `src/graphics/shader/recompiler/frontend/translate/Translate.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=4b5d2946-d692-4f2f-aa71-775b65eed555 attempt=068acfbb-0eb2-4a80-9c03-7bde9c597d6f batch=1/1 -->
@ -369,6 +369,7 @@ IR::F32 Translator::ApplyF32ResultModifiers(const Decoder::Operand& operand, IR:
case 2u: multiplier = 4.0f; break;
default: break;
}
value = IR::F32(ir.Emit(IR::ValueOpcode::FPAdd32, {value, IR::Value::F32(0.0f)}));
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-17 21:14 UTC · original

Agreed that OMOD should be skipped when IEEE mode or output denormals are on, but that gap is older than this PR: in those modes Kyty already applies the OMOD multiply to every value, and the description says so under "What doesn't change". Doing it properly needs IEEE_MODE and FLOAT_MODE for every shader stage in the recompiler; today only compute shaders get FLOAT_MODE and no stage gets IEEE_MODE. That's a separate change, so I'd keep this PR to the -0 rule. Compilers only emit OMOD when both bits are off, so the -0 case in those modes doesn't come up in compiled shaders.

**@⁠Nawid3333** on GitHub · 2026-10-17 21:14 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#discussion_r4304535102) Agreed that OMOD should be skipped when IEEE mode or output denormals are on, but that gap is older than this PR: in those modes Kyty already applies the OMOD multiply to every value, and the description says so under "What doesn't change". Doing it properly needs `IEEE_MODE` and `FLOAT_MODE` for every shader stage in the recompiler; today only compute shaders get `FLOAT_MODE` and no stage gets `IEEE_MODE`. That's a separate change, so I'd keep this PR to the -0 rule. Compilers only emit OMOD when both bits are off, so the -0 case in those modes doesn't come up in compiled shaders.
@ -369,6 +369,7 @@ IR::F32 Translator::ApplyF32ResultModifiers(const Decoder::Operand& operand, IR:
case 2u: multiplier = 4.0f; break;
default: break;
}
value = IR::F32(ir.Emit(IR::ValueOpcode::FPAdd32, {value, IR::Value::F32(0.0f)}));
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 21:15 UTC · original

@⁠Nawid3333 Thanks for the clarification. The OMOD mode-gating gap predates this PR and is documented in its scope. I withdraw the request to add mode gating here. This PR can remain focused on the -0 rule.

Would you like me to open a follow-up issue for IEEE_MODE and FLOAT_MODE propagation across all shader stages and the corresponding OMOD gating?


✏️ Learnings added
Learnt from: Nawid3333
Repo: KytyPS5/KytyPS5 PR: 1620
File: src/graphics/shader/recompiler/frontend/translate/Translate.cpp:368-368
Timestamp: 2026-10-17T21:14:55.430Z
Learning: In KytyPS5 shader recompiler reviews, compiler-generated shaders emit OMOD only when IEEE mode and output denormals are both disabled, as clarified by the maintainer. Account for this compiler constraint when assessing OMOD behavior in those modes.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 21:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#discussion_r4304536591) @⁠Nawid3333 Thanks for the clarification. The OMOD mode-gating gap predates this PR and is documented in its scope. I withdraw the request to add mode gating here. This PR can remain focused on the `-0` rule. Would you like me to open a follow-up issue for `IEEE_MODE` and `FLOAT_MODE` propagation across all shader stages and the corresponding OMOD gating? --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: Nawid3333 Repo: KytyPS5/KytyPS5 PR: 1620 File: src/graphics/shader/recompiler/frontend/translate/Translate.cpp:368-368 Timestamp: 2026-10-17T21:14:55.430Z Learning: In KytyPS5 shader recompiler reviews, compiler-generated shaders emit OMOD only when IEEE mode and output denormals are both disabled, as clarified by the maintainer. Account for this compiler constraint when assessing OMOD behavior in those modes. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> <!-- <review_comment_withdrawn> --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-03 18:13 UTC · original · edited 2026-11-03 18:24 UTC
On tests/ShaderRecompilerComputeTests.cpp line 28974 (outdated):

@@ -28948,6 +28948,33 @@ TestCase CvtPkrtzF16F32RuntimeEdges() {
   return test;
 }
 
+TestCase Vop3OutputModifierFlushesNegativeZero() {
+  using O = ShaderOpcode;
+
+  std::vector<u32> code;
+  AppendVMovLiteral(&code, 0, 0x80000000u);
+  AppendVMovLiteral(&code, 1, 0x3f800000u);
+  AppendVMovLiteral(&code, 2, 0xbf000000u);
+  AppendVMovLiteral(&code, 3, 0x80800000u);
+  AppendVop3(&code, 0x108, 10, Vgpr(0), Vgpr(1), 0, 0, 0, false, 1);
+  AppendVop3(&code, 0x103, 11, Vgpr(0), Vgpr(0), 0, 0, 0, false, 3);
+  AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2);
+  AppendVop3(&code, 0x108, 13, Vgpr(0), Vgpr(1));
+  code.push_back(EncodeVop2(0x08, 14, 249, 1));
+  code.push_back(EncodeVop2Sdwa(0, 6, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
+  AppendVop3(&code, 0x108, 15, Vgpr(3), Vgpr(1), 0, 0, 0, false, 3);
+  for (u32 dst = 10; dst <= 15; dst++) {
+    AppendStoreVgpr(&code, dst, dst - 10);
+  }
+  AppendEnd(&code);
+
+  return {"Vop3OutputModifierFlushesNegativeZero",
+          code,
+          {},
+          {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u},

Major · Functional Correctness · Quick win

Supported by static analysis

Script executed:

rg -n -C 3 'ApplyF32ResultModifiers|DenormFlushToZero|DenormPreserve|flush_f32' \
  src/graphics/shader/recompiler tests/ShaderRecompilerComputeTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 12576


Script executed:

set -o pipefail
printf '%s\n' '--- diff for cited test and modifier implementation ---'
git diff --no-ext-diff --unified=30 dfec14aa8c59f8ea2bc4d87eba9854fc370161c6 15d500be44e170edd81e1c2655fd0f0c9b41851d -- tests/ShaderRecompilerComputeTests.cpp src/graphics/shader/recompiler/frontend/translate/Translate.cpp
printf '%s\n' '--- complete ApplyF32ResultModifiers and surrounding helpers ---'
sed -n '350,410p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
printf '%s\n' '--- SPIR-V module execution-mode setup ---'
sed -n '790,865p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
printf '%s\n' '--- all F32 denormal-related backend references ---'
rg -n -C 5 'Denorm|denorm|SignedZeroInfNanPreserve|FlushToZero|Preserve' src/graphics/shader/recompiler/backend src/graphics/shader/recompiler/frontend/translate
printf '%s\n' '--- test declaration and complete test body around the cited line ---'
rg -n -C 15 'Vop3OutputModifierFlushesNegativeZero|0x80400000|0x80000000' tests/ShaderRecompilerComputeTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 41961


Script executed:

git diff --no-ext-diff --unified=20 dfec14aa8c59f8ea2bc4d87eba9854fc370161c6 15d500be44e170edd81e1c2655fd0f0c9b41851d -- tests/ShaderRecompilerComputeTests.cpp src/graphics/shader/recompiler/frontend/translate/Translate.cpp
sed -n '350,410p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
sed -n '820,860p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
rg -n -C 8 'Vop3OutputModifierFlushesNegativeZero|0x80400000|0x80000000' tests/ShaderRecompilerComputeTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 41590


Make the subnormal assertion independent of Vulkan’s F32 denormal mode.

The final case computes -2^-126 * 0.5. A device that preserves F32 denormals produces 0x80400000, while a device that flushes them produces 0x80000000. The emitted SPIR-V does not select either F32 denormal mode.

Accept both permitted results, but do not accept +0.0. This retains the check that zero normalization occurs before OMOD rather than after it.

✅ Addressed in commit 2891c72

**@⁠coderabbitai[bot]** on GitHub · 2026-11-03 18:13 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#discussion_r4458689261) · edited 2026-11-03 18:24 UTC On `tests/ShaderRecompilerComputeTests.cpp` line 28974 (outdated): ```diff @@ -28948,6 +28948,33 @@ TestCase CvtPkrtzF16F32RuntimeEdges() { return test; } +TestCase Vop3OutputModifierFlushesNegativeZero() { + using O = ShaderOpcode; + + std::vector<u32> code; + AppendVMovLiteral(&code, 0, 0x80000000u); + AppendVMovLiteral(&code, 1, 0x3f800000u); + AppendVMovLiteral(&code, 2, 0xbf000000u); + AppendVMovLiteral(&code, 3, 0x80800000u); + AppendVop3(&code, 0x108, 10, Vgpr(0), Vgpr(1), 0, 0, 0, false, 1); + AppendVop3(&code, 0x103, 11, Vgpr(0), Vgpr(0), 0, 0, 0, false, 3); + AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2); + AppendVop3(&code, 0x108, 13, Vgpr(0), Vgpr(1)); + code.push_back(EncodeVop2(0x08, 14, 249, 1)); + code.push_back(EncodeVop2Sdwa(0, 6, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); + AppendVop3(&code, 0x108, 15, Vgpr(3), Vgpr(1), 0, 0, 0, false, 3); + for (u32 dst = 10; dst <= 15; dst++) { + AppendStoreVgpr(&code, dst, dst - 10); + } + AppendEnd(&code); + + return {"Vop3OutputModifierFlushesNegativeZero", + code, + {}, + {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u}, ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Quick win** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details.svg" width="16" height="16" align="absmiddle" alt=""></picture> Supported by static analysis</summary> <dl> <dd> Script executed: ```bash rg -n -C 3 'ApplyF32ResultModifiers|DenormFlushToZero|DenormPreserve|flush_f32' \ src/graphics/shader/recompiler tests/ShaderRecompilerComputeTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 12576 --- Script executed: ```bash set -o pipefail printf '%s\n' '--- diff for cited test and modifier implementation ---' git diff --no-ext-diff --unified=30 dfec14aa8c59f8ea2bc4d87eba9854fc370161c6 15d500be44e170edd81e1c2655fd0f0c9b41851d -- tests/ShaderRecompilerComputeTests.cpp src/graphics/shader/recompiler/frontend/translate/Translate.cpp printf '%s\n' '--- complete ApplyF32ResultModifiers and surrounding helpers ---' sed -n '350,410p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp printf '%s\n' '--- SPIR-V module execution-mode setup ---' sed -n '790,865p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp printf '%s\n' '--- all F32 denormal-related backend references ---' rg -n -C 5 'Denorm|denorm|SignedZeroInfNanPreserve|FlushToZero|Preserve' src/graphics/shader/recompiler/backend src/graphics/shader/recompiler/frontend/translate printf '%s\n' '--- test declaration and complete test body around the cited line ---' rg -n -C 15 'Vop3OutputModifierFlushesNegativeZero|0x80400000|0x80000000' tests/ShaderRecompilerComputeTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 41961 --- Script executed: ```bash git diff --no-ext-diff --unified=20 dfec14aa8c59f8ea2bc4d87eba9854fc370161c6 15d500be44e170edd81e1c2655fd0f0c9b41851d -- tests/ShaderRecompilerComputeTests.cpp src/graphics/shader/recompiler/frontend/translate/Translate.cpp sed -n '350,410p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp sed -n '820,860p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp rg -n -C 8 'Vop3OutputModifierFlushesNegativeZero|0x80400000|0x80000000' tests/ShaderRecompilerComputeTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 41590 --- </dd> </dl> </details> **Make the subnormal assertion independent of Vulkan’s F32 denormal mode.** The final case computes `-2^-126 * 0.5`. A device that preserves F32 denormals produces `0x80400000`, while a device that flushes them produces `0x80000000`. The emitted SPIR-V does not select either F32 denormal mode. Accept both permitted results, but do not accept `+0.0`. This retains the check that zero normalization occurs before OMOD rather than after it. <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:46184ebcc69ae633addb056a --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 2891c72
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-03 18:13 UTC · original · reviewed

**@⁠coderabbitai[bot]** on GitHub · 2026-11-03 18:13 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#pullrequestreview-5757317314) · **reviewed** <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=19b61a0b-dc31-45f0-a9ce-ba456f799d03 attempt=402e1761-9c9c-4b63-92b7-a941cadae716 batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-03 18:37 UTC · original · reviewed

Nitpick comments: 1
tests/ShaderRecompilerComputeTests.cpp: 1

28955-28966: Trivial · Functional Correctness · Quick win

Exercise the OMOD and clamp ordering.

Every OMOD instruction in this test disables clamping. The test therefore cannot detect a regression that moves clamping before OMOD multiplication. Change the OMOD-2 case to use 1.0f with clamp=true; OMOD-2 produces 4.0f, so the correct post-multiply clamp stores 1.0f, while pre-multiply clamping stores 4.0f.

Suggested fix
-  AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2);
+  AppendVop3(&code, 0x108, 12, Vgpr(1), Vgpr(1), 0, 0, 0, true, 2);
...
-          {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u},
+          {0x00000000u, 0x00000000u, 0x3f800000u, 0x80000000u, 0x00000000u, 0x80000000u},
Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 15d500be44 and 2891c72766.

Files selected for processing: 1
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-03 18:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#pullrequestreview-5757611221) · **reviewed** <!-- coderabbit-ai-generated:v1 --> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning.svg" width="16" height="16" align="absmiddle" alt=""></picture> Nitpick comments: 1</summary><blockquote> <dl> <dd> <details> <summary>tests/ShaderRecompilerComputeTests.cpp: 1</summary><blockquote> <dl> <dd> `28955-28966`: **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/neutral-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Trivial** · **Functional Correctness** · **Quick win** **Exercise the OMOD and clamp ordering.** Every OMOD instruction in this test disables clamping. The test therefore cannot detect a regression that moves clamping before OMOD multiplication. Change the OMOD-2 case to use `1.0f` with `clamp=true`; OMOD-2 produces `4.0f`, so the correct post-multiply clamp stores `1.0f`, while pre-multiply clamping stores `4.0f`. <details> <summary>Suggested fix</summary> <dl> <dd> ```diff - AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2); + AppendVop3(&code, 0x108, 12, Vgpr(1), Vgpr(1), 0, 0, 0, true, 2); ... - {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u}, + {0x00000000u, 0x00000000u, 0x3f800000u, 0x80000000u, 0x00000000u, 0x80000000u}, ``` </dd> </dl> </details> <!-- cr-comment:v1:e854c82243a654cc90a9f152 --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <details> <summary><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</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/dfec14aa8c59f8ea2bc4d87eba9854fc370161c6/.coderabbit.yaml>) - **Commit**: [dfec14a](<https://github.com/KytyPS5/KytyPS5/commit/dfec14aa8c59f8ea2bc4d87eba9854fc370161c6>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `40e71613-5d40-4a9c-9924-517d52d57d49` </dd> </dl> </details> <details> <summary><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</summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 15d500be44e170edd81e1c2655fd0f0c9b41851d and 2891c72766b68c5cbeafc098b9753ddbb6c575ed. </dd> </dl> </details> <details> <summary><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: 1</summary> <dl> <dd> * `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; 8 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=72187520-fa41-462e-a13d-fbef91b960f3 attempt=8fdee7d1-b9df-419a-9a57-f26e468eb95d batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-03 23:24 UTC · original · edited 2026-11-03 23:45 UTC
On tests/ShaderRecompilerComputeTests.cpp line 29061 (outdated):

@@ -29032,6 +29032,37 @@ TestCase CvtPkrtzF16F32RuntimeEdges() {
   return test;
 }
 
+TestCase Vop3OutputModifierFlushesNegativeZero() {
+  using O = ShaderOpcode;
+
+  std::vector<u32> code;
+  AppendVMovLiteral(&code, 0, 0x80000000u);
+  AppendVMovLiteral(&code, 1, 0x3f800000u);
+  AppendVMovLiteral(&code, 2, 0xbf000000u);
+  AppendVMovLiteral(&code, 3, 0x80800000u);
+  AppendVMovLiteral(&code, 4, 0x40000000u);
+  AppendVop3(&code, 0x108, 10, Vgpr(0), Vgpr(1), 0, 0, 0, false, 1);
+  AppendVop3(&code, 0x103, 11, Vgpr(0), Vgpr(0), 0, 0, 0, false, 3);
+  AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2);
+  AppendVop3(&code, 0x108, 13, Vgpr(0), Vgpr(1));
+  code.push_back(EncodeVop2(0x08, 14, 249, 1));
+  code.push_back(EncodeVop2Sdwa(0, 6, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
+  AppendVop3(&code, 0x108, 15, Vgpr(3), Vgpr(1), 0, 0, 0, false, 3);
+  code.insert(code.end(), {EncodeVop2(0x1b, 15, 255, 15), 0x80000000u});
+  AppendVop3(&code, 0x108, 16, Vgpr(4), Vgpr(1), 0, 0, 0, true, 3);
+  for (u32 dst = 10; dst <= 16; dst++) {
+    AppendStoreVgpr(&code, dst, dst - 10);
+  }
+  AppendEnd(&code);
+
+  return {"Vop3OutputModifierFlushesNegativeZero",
+          code,
+          {},
+          {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u,

Major · Functional Correctness · Quick win

Verify the sign of a flushed denormal.

The v15 assertion requires a negative sign even if the OMOD result flushes to zero. The SPIR-V specification does not clearly require that flush to preserve the sign. A device that flushes to +0 would fail this test despite producing a permitted result. (github.com)

Verify the applicable Vulkan contract. If the sign is not guaranteed, avoid requiring it for this underflow case.

Can a Vulkan SPIR-V shader using SignedZeroInfNanPreserve 32 and no denormal execution mode flush a negative subnormal multiplication result to positive zero?

✅ Addressed in commit 477386b

**@⁠coderabbitai[bot]** on GitHub · 2026-11-03 23:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#discussion_r4461669338) · edited 2026-11-03 23:45 UTC On `tests/ShaderRecompilerComputeTests.cpp` line 29061 (outdated): ```diff @@ -29032,6 +29032,37 @@ TestCase CvtPkrtzF16F32RuntimeEdges() { return test; } +TestCase Vop3OutputModifierFlushesNegativeZero() { + using O = ShaderOpcode; + + std::vector<u32> code; + AppendVMovLiteral(&code, 0, 0x80000000u); + AppendVMovLiteral(&code, 1, 0x3f800000u); + AppendVMovLiteral(&code, 2, 0xbf000000u); + AppendVMovLiteral(&code, 3, 0x80800000u); + AppendVMovLiteral(&code, 4, 0x40000000u); + AppendVop3(&code, 0x108, 10, Vgpr(0), Vgpr(1), 0, 0, 0, false, 1); + AppendVop3(&code, 0x103, 11, Vgpr(0), Vgpr(0), 0, 0, 0, false, 3); + AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2); + AppendVop3(&code, 0x108, 13, Vgpr(0), Vgpr(1)); + code.push_back(EncodeVop2(0x08, 14, 249, 1)); + code.push_back(EncodeVop2Sdwa(0, 6, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); + AppendVop3(&code, 0x108, 15, Vgpr(3), Vgpr(1), 0, 0, 0, false, 3); + code.insert(code.end(), {EncodeVop2(0x1b, 15, 255, 15), 0x80000000u}); + AppendVop3(&code, 0x108, 16, Vgpr(4), Vgpr(1), 0, 0, 0, true, 3); + for (u32 dst = 10; dst <= 16; dst++) { + AppendStoreVgpr(&code, dst, dst - 10); + } + AppendEnd(&code); + + return {"Vop3OutputModifierFlushesNegativeZero", + code, + {}, + {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u, ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Quick win** **Verify the sign of a flushed denormal.** The `v15` assertion requires a negative sign even if the OMOD result flushes to zero. The SPIR-V specification does not clearly require that flush to preserve the sign. A device that flushes to `+0` would fail this test despite producing a permitted result. ([github.com](https://github.com/KhronosGroup/SPIRV-Registry/issues/430?utm_source=openai)) Verify the applicable Vulkan contract. If the sign is not guaranteed, avoid requiring it for this underflow case. ```web_search Can a Vulkan SPIR-V shader using SignedZeroInfNanPreserve 32 and no denormal execution mode flush a negative subnormal multiplication result to positive zero? ``` <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:ba64d55d68a1631bbf6fa1f2 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 477386b
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-03 23:24 UTC · original · reviewed

Actionable comments posted: 1

Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 870c40063a and 58b3d0747f.

Files selected for processing: 2
  • src/graphics/shader/recompiler/frontend/translate/Translate.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-03 23:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#pullrequestreview-5760919937) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <details> <summary><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</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**: `c74ed8b7-f8c5-4058-89c1-2c7c110e6d8c` </dd> </dl> </details> <details> <summary><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</summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 870c40063a07f652c4f1e8f6a40dcffc481ddaea and 58b3d0747f9d1adf3edd6d928d80c504a8e572fc. </dd> </dl> </details> <details> <summary><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: 2</summary> <dl> <dd> * `src/graphics/shader/recompiler/frontend/translate/Translate.cpp` * `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; 8 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=053ae703-0c06-45c2-8fca-4d5f1ccac443 attempt=9f1206de-cefe-49b8-a7f5-ee6021401acb batch=1/1 -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-03 23:44 UTC · original
On tests/ShaderRecompilerComputeTests.cpp line 29061 (outdated):

@@ -29032,6 +29032,37 @@ TestCase CvtPkrtzF16F32RuntimeEdges() {
   return test;
 }
 
+TestCase Vop3OutputModifierFlushesNegativeZero() {
+  using O = ShaderOpcode;
+
+  std::vector<u32> code;
+  AppendVMovLiteral(&code, 0, 0x80000000u);
+  AppendVMovLiteral(&code, 1, 0x3f800000u);
+  AppendVMovLiteral(&code, 2, 0xbf000000u);
+  AppendVMovLiteral(&code, 3, 0x80800000u);
+  AppendVMovLiteral(&code, 4, 0x40000000u);
+  AppendVop3(&code, 0x108, 10, Vgpr(0), Vgpr(1), 0, 0, 0, false, 1);
+  AppendVop3(&code, 0x103, 11, Vgpr(0), Vgpr(0), 0, 0, 0, false, 3);
+  AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2);
+  AppendVop3(&code, 0x108, 13, Vgpr(0), Vgpr(1));
+  code.push_back(EncodeVop2(0x08, 14, 249, 1));
+  code.push_back(EncodeVop2Sdwa(0, 6, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
+  AppendVop3(&code, 0x108, 15, Vgpr(3), Vgpr(1), 0, 0, 0, false, 3);
+  code.insert(code.end(), {EncodeVop2(0x1b, 15, 255, 15), 0x80000000u});
+  AppendVop3(&code, 0x108, 16, Vgpr(4), Vgpr(1), 0, 0, 0, true, 3);
+  for (u32 dst = 10; dst <= 16; dst++) {
+    AppendStoreVgpr(&code, dst, dst - 10);
+  }
+  AppendEnd(&code);
+
+  return {"Vop3OutputModifierFlushesNegativeZero",
+          code,
+          {},
+          {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u,

Good point: the spec doesn't pin down the sign of a flushed denormal (KhronosGroup/SPIRV-Registry#430 is still open). Changed in 477386b88: the test now computes the same underflow a second time without the output modifier (-2^-126 × 0.5 as a plain v_mul_f32) and only requires both results to have the same sign. That holds whether a device keeps f32 denormals or flushes them to a zero of either sign.

The row still fails for the order this PR fixes. On an RX 9070 XT, flushing -0 after the modifier (this PR's first commit) gives +0 for the div:2 row while the plain multiply gives -0. With the current order both are -0. Main fails earlier, at the -0 rows.

**@⁠Nawid3333** on GitHub · 2026-11-03 23:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#discussion_r4461811489) On `tests/ShaderRecompilerComputeTests.cpp` line 29061 (outdated): ```diff @@ -29032,6 +29032,37 @@ TestCase CvtPkrtzF16F32RuntimeEdges() { return test; } +TestCase Vop3OutputModifierFlushesNegativeZero() { + using O = ShaderOpcode; + + std::vector<u32> code; + AppendVMovLiteral(&code, 0, 0x80000000u); + AppendVMovLiteral(&code, 1, 0x3f800000u); + AppendVMovLiteral(&code, 2, 0xbf000000u); + AppendVMovLiteral(&code, 3, 0x80800000u); + AppendVMovLiteral(&code, 4, 0x40000000u); + AppendVop3(&code, 0x108, 10, Vgpr(0), Vgpr(1), 0, 0, 0, false, 1); + AppendVop3(&code, 0x103, 11, Vgpr(0), Vgpr(0), 0, 0, 0, false, 3); + AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2); + AppendVop3(&code, 0x108, 13, Vgpr(0), Vgpr(1)); + code.push_back(EncodeVop2(0x08, 14, 249, 1)); + code.push_back(EncodeVop2Sdwa(0, 6, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); + AppendVop3(&code, 0x108, 15, Vgpr(3), Vgpr(1), 0, 0, 0, false, 3); + code.insert(code.end(), {EncodeVop2(0x1b, 15, 255, 15), 0x80000000u}); + AppendVop3(&code, 0x108, 16, Vgpr(4), Vgpr(1), 0, 0, 0, true, 3); + for (u32 dst = 10; dst <= 16; dst++) { + AppendStoreVgpr(&code, dst, dst - 10); + } + AppendEnd(&code); + + return {"Vop3OutputModifierFlushesNegativeZero", + code, + {}, + {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u, ``` Good point: the spec doesn't pin down the sign of a flushed denormal (KhronosGroup/SPIRV-Registry#430 is still open). Changed in 477386b88: the test now computes the same underflow a second time without the output modifier (-2^-126 × 0.5 as a plain `v_mul_f32`) and only requires both results to have the same sign. That holds whether a device keeps f32 denormals or flushes them to a zero of either sign. The row still fails for the order this PR fixes. On an RX 9070 XT, flushing -0 after the modifier (this PR's first commit) gives +0 for the `div:2` row while the plain multiply gives -0. With the current order both are -0. Main fails earlier, at the -0 rows.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-03 23:46 UTC · original
On tests/ShaderRecompilerComputeTests.cpp line 29061 (outdated):

@@ -29032,6 +29032,37 @@ TestCase CvtPkrtzF16F32RuntimeEdges() {
   return test;
 }
 
+TestCase Vop3OutputModifierFlushesNegativeZero() {
+  using O = ShaderOpcode;
+
+  std::vector<u32> code;
+  AppendVMovLiteral(&code, 0, 0x80000000u);
+  AppendVMovLiteral(&code, 1, 0x3f800000u);
+  AppendVMovLiteral(&code, 2, 0xbf000000u);
+  AppendVMovLiteral(&code, 3, 0x80800000u);
+  AppendVMovLiteral(&code, 4, 0x40000000u);
+  AppendVop3(&code, 0x108, 10, Vgpr(0), Vgpr(1), 0, 0, 0, false, 1);
+  AppendVop3(&code, 0x103, 11, Vgpr(0), Vgpr(0), 0, 0, 0, false, 3);
+  AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2);
+  AppendVop3(&code, 0x108, 13, Vgpr(0), Vgpr(1));
+  code.push_back(EncodeVop2(0x08, 14, 249, 1));
+  code.push_back(EncodeVop2Sdwa(0, 6, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
+  AppendVop3(&code, 0x108, 15, Vgpr(3), Vgpr(1), 0, 0, 0, false, 3);
+  code.insert(code.end(), {EncodeVop2(0x1b, 15, 255, 15), 0x80000000u});
+  AppendVop3(&code, 0x108, 16, Vgpr(4), Vgpr(1), 0, 0, 0, true, 3);
+  for (u32 dst = 10; dst <= 16; dst++) {
+    AppendStoreVgpr(&code, dst, dst - 10);
+  }
+  AppendEnd(&code);
+
+  return {"Vop3OutputModifierFlushesNegativeZero",
+          code,
+          {},
+          {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u,
Analysis chain

Script executed:

#!/bin/bash
set -euo pipefail
ast-grep outline tests/ShaderRecompilerComputeTests.cpp --match Vop3OutputModifierFlushesNegativeZero --view expanded
rg -n -A85 -B3 '^TestCase Vop3OutputModifierFlushesNegativeZero\(' tests/ShaderRecompilerComputeTests.cpp

Length of output: 4495


@Nawid3333 Verified the revised assertion in tests/ShaderRecompilerComputeTests.cpp. The test now XORs the OMOD result with the plain multiply result, masks the sign bit, and expects zero. It no longer requires a fixed sign for the flushed denormal.

This addresses the finding. Your reported RX 9070 XT comparison also confirms that the test still detects the incorrect modifier order. I inspected the code but did not run GPU tests.


📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings.


Learnings used
Learnt from: Nawid3333
Repo: KytyPS5/KytyPS5 PR: 1620
File: src/graphics/shader/recompiler/frontend/translate/Translate.cpp:368-368
Timestamp: 2026-10-17T21:15:00.072Z
Learning: In KytyPS5 shader recompiler reviews, compiler-generated shaders emit OMOD only when IEEE mode and output denormals are both disabled, as clarified by the maintainer. Account for this compiler constraint when assessing OMOD behavior in those modes.

If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-03 23:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1620#discussion_r4461821488) On `tests/ShaderRecompilerComputeTests.cpp` line 29061 (outdated): ```diff @@ -29032,6 +29032,37 @@ TestCase CvtPkrtzF16F32RuntimeEdges() { return test; } +TestCase Vop3OutputModifierFlushesNegativeZero() { + using O = ShaderOpcode; + + std::vector<u32> code; + AppendVMovLiteral(&code, 0, 0x80000000u); + AppendVMovLiteral(&code, 1, 0x3f800000u); + AppendVMovLiteral(&code, 2, 0xbf000000u); + AppendVMovLiteral(&code, 3, 0x80800000u); + AppendVMovLiteral(&code, 4, 0x40000000u); + AppendVop3(&code, 0x108, 10, Vgpr(0), Vgpr(1), 0, 0, 0, false, 1); + AppendVop3(&code, 0x103, 11, Vgpr(0), Vgpr(0), 0, 0, 0, false, 3); + AppendVop3(&code, 0x108, 12, Vgpr(2), Vgpr(1), 0, 0, 0, false, 2); + AppendVop3(&code, 0x108, 13, Vgpr(0), Vgpr(1)); + code.push_back(EncodeVop2(0x08, 14, 249, 1)); + code.push_back(EncodeVop2Sdwa(0, 6, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); + AppendVop3(&code, 0x108, 15, Vgpr(3), Vgpr(1), 0, 0, 0, false, 3); + code.insert(code.end(), {EncodeVop2(0x1b, 15, 255, 15), 0x80000000u}); + AppendVop3(&code, 0x108, 16, Vgpr(4), Vgpr(1), 0, 0, 0, true, 3); + for (u32 dst = 10; dst <= 16; dst++) { + AppendStoreVgpr(&code, dst, dst - 10); + } + AppendEnd(&code); + + return {"Vop3OutputModifierFlushesNegativeZero", + code, + {}, + {0x00000000u, 0x00000000u, 0xc0000000u, 0x80000000u, 0x00000000u, 0x80000000u, ``` <!-- coderabbit-ai-generated:v1 --> <details> <summary>Analysis chain</summary> <dl> <dd> Script executed: ```shell #!/bin/bash set -euo pipefail ast-grep outline tests/ShaderRecompilerComputeTests.cpp --match Vop3OutputModifierFlushesNegativeZero --view expanded rg -n -A85 -B3 '^TestCase Vop3OutputModifierFlushesNegativeZero\(' tests/ShaderRecompilerComputeTests.cpp ``` Length of output: 4495 --- </dd> </dl> </details> `@Nawid3333` Verified the revised assertion in `tests/ShaderRecompilerComputeTests.cpp`. The test now XORs the OMOD result with the plain multiply result, masks the sign bit, and expects zero. It no longer requires a fixed sign for the flushed denormal. This addresses the finding. Your reported RX 9070 XT comparison also confirms that the test still detects the incorrect modifier order. I inspected the code but did not run GPU tests. --- > 📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings. --- <details> <summary>Learnings used</summary> <dl> <dd> ``` Learnt from: Nawid3333 Repo: KytyPS5/KytyPS5 PR: 1620 File: src/graphics/shader/recompiler/frontend/translate/Translate.cpp:368-368 Timestamp: 2026-10-17T21:15:00.072Z Learning: In KytyPS5 shader recompiler reviews, compiler-generated shaders emit OMOD only when IEEE mode and output denormals are both disabled, as clarified by the maintainer. Account for this compiler constraint when assessing OMOD behavior in those modes. ``` </dd> </dl> </details> --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Don%E2%80%99t%20assume%20a%20flushed%20denormal%20preserves%20its%20sign.%20Compare%20OMOD%20output%20with%20a%20plain%20multiply%20to%20catch%20sign-order%20bugs%20across%20devices.%20Try%20%40coderabbitai!%20%F0%9F%94%8D&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1620%23discussion_r4461669338)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> Review thread resolved. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.