Skip to content

fix(shader): quiet v_cvt_f32_f16 NaN results in IEEE mode - #22662

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
MichonGoddijn231849:fix-cvt-f32-f16-ieee-nan
Nov 27, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
MichonGoddijn231849:fix-cvt-f32-f16-ieee-nan

Conversation

@MichonGoddijn231849

Copy link
Copy Markdown
Contributor

What

v_cvt_f32_f16 did not quiet a signalling NaN source when IEEE_MODE is set: TranslationContext::vCvtF32F16 widened the half (flushF16InputValue(readF16AsF32(...))) and wrote it unchanged, so 0x7c01 became 0x7f802000. RDNA2 hardware returns 0x7fc02000: with IEEE_MODE set the widened NaN gets the f32 quiet bit, with it clear it is left as is.

  • fix: with ieeeMode, a NaN result goes through the existing quietNan32 (bit 22 set), as the other f32 translations that quiet NaNs do; with IEEE_MODE clear nothing changes. The SDWA form shares this translation.
  • test: F16ToF32Unpack.cpp already converts all 65,536 halves with IEEE_MODE clear; it now also converts them with IEEE_MODE set and expects HalfToFloatBits(half) with bit 22 set for every NaN half. Request and Dispatch take an ieee flag (default false, so the existing passes and --verify-spirv are unchanged).

Source of the semantics: measured on RDNA2 hardware (gfx1036, AMD Windows driver 32.0.21045.16010) with tools/hw-oracle: v_cvt_f32_f16 over all 65,536 halves, f16 denormals kept, f32 flushed, round to nearest even, once with IEEE 0 and once with IEEE 1. Against HalfToFloatBits: IEEE 0 differs on 0 halves; IEEE 1 differs exactly on the NaN halves, and matches HalfToFloatBits | 0x00400000 there, 0 differences. The same mismatch first showed in a differential run of the hardware oracle against AnyPS5's agc_oracle_runner on both Vulkan devices (0x7c01, 0x7d00, 0xfdff differed with IEEE 1 only).

Tested

Windows 11 Pro 10.0.26200, ctest --test-dir build -R f16_to_f32_unpack -V (the execution test and its --verify-spirv variant) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, validation layer 1.4.363, once per GPU (ANYPS5_GPU):

GPU main's test on main this branch's test on main (fix reverted) this branch
NVIDIA GeForce RTX 5080, driver 610.74 (32.0.16.1074) 2/2 passed fails: v_cvt_f32_f16 with IEEE_MODE of 0xd9a47c01 is 0x7f802000, expected 0x7fc02000 2/2 passed (both decodes), 0 VUID-
AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010 2/2 passed fails the same way 2/2 passed (integer decode), 0 VUID-

main's test also passes with the fix on both GPUs (0 VUID-). Each log shows Insert instance layer "VK_LAYER_KHRONOS_validation" and none shows was not found but was requested by env var VK_INSTANCE_LAYERS. The full agc_driver suite on main (378945815f) on both GPUs is the baseline (its known failures are unrelated). pr_overlap.py --branch: no overlap with open pull requests.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 610.74, Windows 11 Pro 10.0.26200; AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010, Windows 11 Pro 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

MichonGoddijn231849 and others added 2 commits November 18, 2026 01:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Nov 18, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the inspected translation and regression test support the stated IEEE-mode NaN quieting behavior.

What I ran

Reviewed head 8983768a36451cdf008350cad4437711359b87e5 using the prepared review/diff.patch and the pinned repo_read.py reader. No test command was run. I read core/shader/recompiler/Translation/src/ConvertInstructions.cpp, core/libs/prx/libSceAgcDriver/tests/execution/F16ToF32Unpack.cpp, and the relevant quietNan32 implementation in core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp. Both changed files were included in the review folder; no changed files were excluded.

Results

Check Result Note
Diff and changed code review passed Both changed files read
Tests in this review not run Hardware results are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run the tests or independently verify the reported GPU, driver, operating system, hardware oracle, or CI results. The prepared review folder did not provide review/files.json; exclusion information is therefore not independently confirmed. No other repository files were needed for the reviewed behavior.

To get this to a good state

Nothing is required.

@domx4q

domx4q commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Ran the Tested set with the Khronos validation layer on Linux and an NVIDIA GPU, since CI runs the GPU tests only on lavapipe and the NVIDIA run in the Tested section is on Windows.

Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor 0x10de, device 0x2684, Ada), proprietary driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head 8983768a36 merged onto main fbaae8a79d with --no-ff (clean, as a2c1467a5f). Main baseline is a Release build of fbaae8a79d on the same machine.

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer \
ctest --test-dir build -R 'f16_to_f32_unpack' -V
main fbaae8a79d this PR
Result 2 of 2 passed 2 of 2 passed
Insert instance layer "VK_LAYER_KHRONOS_validation" 1 1
was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
VUID- none none

Every device selected the RTX 4090; agc_driver_f16_to_f32_unpack_spirv creates no device, hence one layer insertion for two tests. On main both pass with main's version of the test; on this PR both pass with the IEEE-mode NaN case.

Negative control: with main's ConvertInstructions.cpp and this PR's test, agc_driver_f16_to_f32_unpack fails with AGC graphics: f16 to f32 unpack (integer decode): v_cvt_f32_f16 with IEEE_MODE of 0xd9a47c01 is 0x7f802000, expected 0x7fc02000; agc_driver_f16_to_f32_unpack_spirv still passes. With the change restored both pass.

No new VUID- errors; both focused tests pass on Ada.

AI-assisted: yes (Claude Code)

@Colewiz7

Copy link
Copy Markdown
Contributor

Head 8983768a36 merged onto main 7c836568c8 as b905d8515a, no conflict. Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036).

No new failures and no new validation messages on either GPU.

RX 7900 XT iGPU
tests run (6206 on the 7900 XT, the 2007 GPU ones on the iGPU), new failures vs main none none
-R '^agc' (1940 tests) with the layer, new failures vs main none none
VUID- / SYNC-HAZARD lines 0 / 0 0 / 0

Layer runs used VK_LAYER_KHRONOS_validation 1.4.363.1 with VK_LOADER_DEBUG=layer and ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; the loader inserted the layer in every run, and the set of distinct validation messages matches main.

AI-assisted: yes

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 8983768a36, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#18156, #21208, #22013, #22795, #23226, #23385, #24324, #24533, #24582, #24690, #24693, #17553, #19619, #20085, #21081, #19682, #22123, #22529, #22572, #23479, #23787, #24568, #15330, #21249, #21630, #21713, #22040, #23490, #24394). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
agc_driver_f16_to_f32_unpack, agc_driver_f16_to_f32_unpack_spirv (2 tests, matched by name to the test file this PR changes) all pass all pass

Whole batch: the full ctest -j 12 (6540 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #17553 (guest_memory); none is in this PR's area. The 2143 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@Helldiverr

Copy link
Copy Markdown
Contributor

GPU run on RDNA4 (gfx1201) with the AMD Windows driver and the validation layer: the fix is correct. Over all 65,536 halves, the recompiled v_cvt_f32_f16 with IEEE_MODE set now equals gfx1201 bit for bit. main differs on all 1,022 signalling-NaN halves, and on nothing else. The new test passes 3 of 3 runs, fails on main, and catches a mutation of the NaN test. No VUID-.

What this run adds.

  • gfx1201, all halves:

    • Setup: tools/hw-oracle ran v_cvt_f32_f16 with --denorm16 3 --denorm32 0, as in the description. gfx12 has no IEEE field, so the setting is --ieee none --dx10-clamp none.
    • Results: wave32 and wave64 give the same results.
      • The 64,514 non-NaN and quiet-NaN halves widen exactly.
      • The 1,022 signalling-NaN halves come back with bit 22 set.
    • So gfx1201 always quiets, which is what the description measured on gfx1036 with IEEE_MODE set.
  • The recompiler, all halves:

    • Setup: HW_ORACLE_RUNTIME=vulkan with HW_ORACLE_TARGET=gfx1030, so the RDNA2 word runs through agc_oracle_runner on this R9700. Same denormal settings.
    recompiler --ieee 0 --ieee 1
    main exact widening for all halves exact widening for all halves: the 1,022 signalling NaNs are not quieted, and 1,022 of 65,536 differ from gfx1201
    this PR, wave32 and wave64 exact widening for all halves 0 of 65,536 differ from gfx1201
    • IEEE_MODE clear is unchanged, as the description says.
  • VOP3 source modifiers: v_cvt_f32_f16_e64 with -v4 and with |v4|, on all halves. With --ieee 1, this PR's recompiler differs from gfx1201 on 0 of 65,536 halves for each form. So the quieting comes after the modifiers, as on hardware.

Code.

  • ConvertInstructions.cpp:120-130 (at the head): with ieeeMode set, a NaN result is passed through quietNan32; with it clear, the function returns early.
  • Equivalent mutation: quietNan32 already returns its input unchanged when ieeeMode is clear (OperandAccess.cpp:368-370 on the merge). So the early return only saves the NaN test in the IR.
    • I checked this: replacing if (!ieeeMode) with if (false) changed nothing. The test passed, and the recompiler sweep with --ieee 0 still gave exact widening for every half.
    • This is not a defect. I mention it only so nobody reads the IEEE-0 rows as a guard on that gate.
  • Test: F16ToF32Unpack.cpp:168-172 (at the head) adds a second pass with IEEE_MODE set and expects bit 22 on every NaN half.
  • Checks:
    • No code comments, nothing title-specific, no debt change.
    • check_conventions.py --base 709342e209 and debt_fold.py --check pass on the merge.
  • Overlap: the pr-overlap bot could not compare perf(agc): record BDA stores in per-range granule bits and a page map instead of the note_bda_write hash table #22944 (it conflicts with the base). The merge onto 709342e209 is clean.

Evidence.

  • Native, on hardware: the gfx1201 sweeps (plain, -v4, |v4|).
  • Self-consistency:
    • The recompiler sweeps.
    • The ctest runs.
    • The mutations.
  • Not covered:
    • gfx1013.
    • IEEE_MODE clear on hardware. gfx12 cannot express it, so that side rests on the gfx1036 measurement in the description.
    • The SDWA form on hardware, since gfx12 has no SDWA.

Negative control and mutation.

  • Negative control: main 709342e209 with only the new test fails with f16 to f32 unpack (integer decode): v_cvt_f32_f16 with IEEE_MODE of 0xd9a47c01 is 0x7f802000, expected 0x7fc02000. _spirv passes.
  • Mutation, on the merge:
    • Change: the NaN test at ConvertInstructions.cpp:127 also matches infinity (0x7f800000 becomes 0x7f7fffff, r8d/22662-mutation-infinity-as-nan.patch).
    • Result: the test fails with v_cvt_f32_f16 with IEEE_MODE of 0xd9a57c00 is 0x7fc00000, expected 0x7f800000.

GPU. Head 8983768a36, merged cleanly onto main 709342e209:

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R "^agc_driver_f16_to_f32_unpack(_spirv)?$" -V
run f16_to_f32_unpack f16_to_f32_unpack_spirv total
main passed passed 1.36 s
negative: main + new test failed (0x7c01) passed 0.48 s
head 1 / 2 / 3 passed passed 0.73 / 0.52 / 0.51 s
mutation: infinity as NaN failed (0x7c00) passed 0.71 s
equivalent mutation: if (false) passed passed 0.78 s
  • GPU: every GPU test and every sweep run selected AMD Radeon AI PRO R9700 vendor=0x1002 device=0x7551 subgroup=64. Nothing skipped.
  • _spirv: agc_driver_f16_to_f32_unpack_spirv creates no device.
  • The times are not a speed measurement.

Validation.

  • ctest logs: Insert instance layer "VK_LAYER_KHRONOS_validation" appears once in every log, for the one test that opens a device.
  • Sweep logs: the eight agc_oracle_runner sweep logs ran with the same environment and show it once per dispatch.
  • No log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
  • VUID- lines: 0 in every log.

Host:

  • GPU: AMD Radeon AI PRO R9700 (gfx1201, 1002:7551), driver 32.0.31044.16, Vulkan 1.4.349, reported subgroup size 64
  • Validation layer: Khronos validation layer 1.4.363 (LunarG SDK)
  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2, Release
  • Commits: main 709342e209, head 8983768a36 (unchanged when rechecked)

AI-assisted: yes

@github-actions

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 22944 core/libs/prx/libSceAgcDriver/tests/execution/F16ToF32Unpack.cpp

@oneandonlydean
oneandonlydean merged commit 0e82d95 into boykopovar:main Nov 27, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants