shader: keep V_FRACT results below 1.0 #1212

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

@⁠Nawid3333 on GitHub · 2026-10-08 13:58 UTC · original
Nawid3333:shader/fract-below-one → main · +70 −7 · 6 files · 2 commits · closed without merging

This is the change proposed in #1209. If the edge values you captured on hardware say otherwise, tell me and
I'll change it or close it.

Problem

RDNA2's V_FRACT_F16/F32/F64 follow the DX definition of fract (ISA guide 12.8), which returns a value in
[+0, 1) for every finite input. Kyty emits GLSLstd450Fract, i.e. x - floor(x), which rounds to 1.0 for
tiny negative inputs: every input in [-2^-54, 0) in double precision, in [-2^-25, 0) in single precision, and
every half in [-2^-12, 0).
On the AMD driver I tested, the result is already the largest value below 1.0 (consistent with it using the
hardware v_fract); a driver that computes x - floor(x) returns 1.0. On main,
VectorFractF64CapturedAndEdges and VectorFractF16CapturedAndEdges expect 1.0 at those edges (details in
#1209).

Fix

V_FRACT_* now clamps the fract result to the largest value below 1.0 in the instruction's precision, with an
ordered >= compare and a select, so NaN results stay NaN. The f16 form is computed in f32 and rounded to
half later, so its clamp value is the f32 value of the half 0x3bff (0x3f7fe000), which keeps the rounding
from reaching 1.0. A new SelectF64 IR operation (OpSelect) handles the double case. Sources, output modifiers and the f16 write go
through the same ReadOperand/WriteOperand/ReadF16AsF32/WriteF16 calls as before.

The two tests now expect 0x3fefffffffffffff for -2^-1074 and 0x3bff for the halves 0x8001, 0x83ff
and 0x8c00. The f64 test also counts the clamp in the IR (SelectF64 per V_FRACT_F64), because on the
AMD driver I tested the readback is already the clamped value. The f16 readback catches a missing clamp on
drivers whose half packing rounds to nearest (and on AMD once #1204 is in). A new VectorFractF32Edges (run
by --fract-f16-only) checks -2^-24, -2^-25 and -2^-26, which must all give 0x3f7fffff (x - floor(x) gives
1.0 for the last two), and counts SelectF32 in the IR for the same reason as the f64 test.

Testing

Windows 11, clang-cl 19.1.5, Release, AMD RX 9070 XT, this branch on main aa3b2cd5:

  • --cmp-eq-f64-only and --fract-f16-only fail on main and pass with this change. With the five changed
    source files reset to main (tests kept), --cmp-eq-f64-only fails again at the IR count
    (SelectF64 count=0, expected=18), and --fract-f16-only at VectorFractF32Edges
    (SelectF32 count=0, expected=5).
  • All --*-only modes against main (first commit, on 4865dd92): 93/110 pass instead of 91/110; only
    these two change. shader_cfg passes.
  • CI (Windows, Linux, macOS, with tests): green, https://github.com/KytyPS5/KytyPS5/actions/runs/37792144096

Not tested on NVIDIA or Intel, where the readback values themselves change from 1.0 to the clamped values.

AI use (per the README's AI policy): Claude (Anthropic) wrote the change and the test updates and ran the
tests above on my machine.

🤖 Generated with Claude Code

**@⁠Nawid3333** on GitHub · 2026-10-08 13:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1212) `Nawid3333:shader/fract-below-one` → `main` · +70 −7 · 6 files · 2 commits · closed without merging This is the change proposed in #1209. If the edge values you captured on hardware say otherwise, tell me and I'll change it or close it. ## Problem RDNA2's `V_FRACT_F16/F32/F64` follow the DX definition of fract (ISA guide 12.8), which returns a value in [+0, 1) for every finite input. Kyty emits `GLSLstd450Fract`, i.e. `x - floor(x)`, which rounds to 1.0 for tiny negative inputs: every input in [-2^-54, 0) in double precision, in [-2^-25, 0) in single precision, and every half in [-2^-12, 0). On the AMD driver I tested, the result is already the largest value below 1.0 (consistent with it using the hardware `v_fract`); a driver that computes `x - floor(x)` returns 1.0. On `main`, `VectorFractF64CapturedAndEdges` and `VectorFractF16CapturedAndEdges` expect 1.0 at those edges (details in #1209). ## Fix `V_FRACT_*` now clamps the fract result to the largest value below 1.0 in the instruction's precision, with an ordered `>=` compare and a select, so NaN results stay NaN. The f16 form is computed in f32 and rounded to half later, so its clamp value is the f32 value of the half `0x3bff` (`0x3f7fe000`), which keeps the rounding from reaching 1.0. A new `SelectF64` IR operation (`OpSelect`) handles the double case. Sources, output modifiers and the f16 write go through the same `ReadOperand`/`WriteOperand`/`ReadF16AsF32`/`WriteF16` calls as before. The two tests now expect `0x3fefffffffffffff` for -2^-1074 and `0x3bff` for the halves `0x8001`, `0x83ff` and `0x8c00`. The f64 test also counts the clamp in the IR (`SelectF64` per `V_FRACT_F64`), because on the AMD driver I tested the readback is already the clamped value. The f16 readback catches a missing clamp on drivers whose half packing rounds to nearest (and on AMD once #1204 is in). A new `VectorFractF32Edges` (run by `--fract-f16-only`) checks -2^-24, -2^-25 and -2^-26, which must all give `0x3f7fffff` (`x - floor(x)` gives 1.0 for the last two), and counts `SelectF32` in the IR for the same reason as the f64 test. ## Testing Windows 11, clang-cl 19.1.5, Release, AMD RX 9070 XT, this branch on `main` `aa3b2cd5`: - `--cmp-eq-f64-only` and `--fract-f16-only` fail on `main` and pass with this change. With the five changed source files reset to `main` (tests kept), `--cmp-eq-f64-only` fails again at the IR count (`SelectF64 count=0, expected=18`), and `--fract-f16-only` at `VectorFractF32Edges` (`SelectF32 count=0, expected=5`). - All `--*-only` modes against `main` (first commit, on `4865dd92`): 93/110 pass instead of 91/110; only these two change. `shader_cfg` passes. - CI (Windows, Linux, macOS, with tests): green, https://github.com/KytyPS5/KytyPS5/actions/runs/37792144096 Not tested on NVIDIA or Intel, where the readback values themselves change from 1.0 to the clamped values. **AI use** (per the README's AI policy): Claude (Anthropic) wrote the change and the test updates and ran the tests above on my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
RDNA2's V_FRACT_F16/F32/F64 follow the DX definition of fract (ISA guide
12.8), whose result is in [+0, 1) for finite inputs. GLSL Fract computes
x - floor(x), which rounds to 1.0 for tiny negative inputs on drivers
that don't lower it to AMD's clamped v_fract. Clamp the result to the
largest value below 1.0 in the instruction's precision (for f16 before
packing) with an ordered compare and a select, so NaN stays NaN, and add
SelectF64 for the double case.

The fract tests now expect the clamped values, and the f64 test counts
the clamp in the IR, so it fails without it on every host, including
AMD, whose driver already clamps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
In f32, 1 - 2^-25 (a tie) and 1 - 2^-26 round to 1.0, so V_FRACT_F32 of
-2^-25 and -2^-26 needs the clamp too. Add these with -2^-24 (exact) and
two ordinary values, and count the clamp in the IR, since AMD drivers may
already return the clamped value.

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

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

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6e382e8b-9aae-4750-959b-a516844215b9
📥 Commits

Reviewing files that changed from the base of the PR and between 796da6f7834bca301b4d1d62e85228394f79cb94 and ce48db78a3.

📒 Files selected for processing (2)
  • src/graphics/shader/recompiler/frontend/translate/Translator.h
  • tests/ShaderRecompilerComputeTests.cpp

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


📝 Walkthrough

Walkthrough

The change adds FloatFract translation for F16, F32, and F64 vector instructions. It applies precision-specific caps to fractional results and uses SelectF64 for F64 selection. The change also adds the corresponding SPIR-V emitter alias and updates compute test expectations.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to ce48d

The reviewed changes preserve the precision-specific fract behavior, and the apparent resource-tracking gap cannot be reached by supported resource or SRT expressions. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❓ 1

❌ 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. Analyzed 7 functions across 4 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: keeping V_FRACT results below 1.0.
Description check ✅ Passed The description directly explains the V_FRACT clamping fix, implementation details, test changes, and validation results.
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. Analyzed 7 functions across 4 files. (1 skipped: 1 too large.)

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 14:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1212#issuecomment-6061687474) · edited 2026-10-08 14:47 UTC <!-- 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/1212?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `6e382e8b-9aae-4750-959b-a516844215b9` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 796da6f7834bca301b4d1d62e85228394f79cb94 and ce48db78a32ec92f8b2dea953feae2d5d9d05947. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/graphics/shader/recompiler/frontend/translate/Translator.h` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The change adds `FloatFract` translation for F16, F32, and F64 vector instructions. It applies precision-specific caps to fractional results and uses `SelectF64` for F64 selection. The change also adds the corresponding SPIR-V emitter alias and updates compute test expectations. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"ce48db78a32ec92f8b2dea953feae2d5d9d05947" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **⚪ Minimal** · up to `ce48d` <!-- final_review_risk_coverage:{"sourceCommitId":"ce48db78a32ec92f8b2dea953feae2d5d9d05947","coveredCommitId":"ce48db78a32ec92f8b2dea953feae2d5d9d05947","kind":"reviewed"} --> The reviewed changes preserve the precision-specific fract behavior, and the apparent resource-tracking gap cannot be reached by supported resource or SRT expressions. No merge-blocking risk remains. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❓ 1</summary> ### ❌ 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. Analyzed 7 functions across 4 files. (1 skipped: 1 … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------ | :------- | :------------------------------------------------------------------------------------------------------------------------ | | 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. | | Title check | ✅ Passed | The title clearly and concisely describes the main change: keeping V_FRACT results below 1.0. | | Description check | ✅ Passed | The description directly explains the V_FRACT clamping fix, implementation details, test changes, and validation results. | </details> <details> <summary>Full details: Docstring Coverage</summary> **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. Analyzed 7 functions across 4 files. (1 skipped: 1 too large.) </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1212)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [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) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

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

🧹 Nitpick comments (1)
src/graphics/shader/recompiler/frontend/translate/Float.cpp (1)

121-146: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add an F32 boundary case for V_FRACT_F32.

-2^-25 (0xb3000000) produces 1 - 2^-25, which rounds to 1.0 in F32. The expected result is the predecessor 0x3f7fffff. Add this case and assert the F32 SelectF32 clamp in IR. The IR assertion is required because the GPU fract operation may already return a capped value.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b9f024c6-8b98-4935-992a-b4fd16dc6667
📥 Commits

Reviewing files that changed from the base of the PR and between aa3b2cd57f and 796da6f7834bca301b4d1d62e85228394f79cb94.

📒 Files selected for processing (6)
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h
  • src/graphics/shader/recompiler/frontend/translate/Float.cpp
  • src/graphics/shader/recompiler/frontend/translate/Translator.h
  • src/graphics/shader/recompiler/frontend/translate/Vector.cpp
  • src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc
  • 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-08 14:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1212#pullrequestreview-5457876526) · **reviewed** <details> <summary>🧹 Nitpick comments (1)</summary><blockquote> <details> <summary>src/graphics/shader/recompiler/frontend/translate/Float.cpp (1)</summary><blockquote> `121-146`: **🎯 Functional Correctness** | **🔵 Trivial** | **⚡ Quick win** **Add an F32 boundary case for `V_FRACT_F32`.** `-2^-25` (`0xb3000000`) produces `1 - 2^-25`, which rounds to `1.0` in F32. The expected result is the predecessor `0x3f7fffff`. Add this case and assert the F32 `SelectF32` clamp in IR. The IR assertion is required because the GPU `fract` operation may already return a capped value. <!-- cr-comment:v1:b1ff10c9f163832eebb57b58 --> </blockquote></details> </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b9f024c6-8b98-4935-992a-b4fd16dc6667` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between aa3b2cd57f84e414a4af0ccbc42d7eb35a8af17b and 796da6f7834bca301b4d1d62e85228394f79cb94. </details> <details> <summary>📒 Files selected for processing (6)</summary> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h` * `src/graphics/shader/recompiler/frontend/translate/Float.cpp` * `src/graphics/shader/recompiler/frontend/translate/Translator.h` * `src/graphics/shader/recompiler/frontend/translate/Vector.cpp` * `src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc` * `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=16c7f60f-b9d0-4d9e-a070-41623cd25c03 attempt=8de39eaa-2893-4323-bab9-d97fc16434ff batch=1/1 -->

Pull request closed

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