Repository navigation
fix(shader): apply the f32 output modifier and denormal flush to v_cvt_f32_f64 - #5159
Closed
nikowolf123 wants to merge 1 commit into
Closed
nikowolf123 wants to merge 1 commit into
nikowolf123 wants to merge 1 commit into
Conversation
This was referenced Oct 13, 2026
…t_f32_f64 v_cvt_f32_f64 has an f32 result but went through the f16/f64 result rule: its VOP3 mul:2, mul:4 and div:2 were dropped with IEEE mode off and f16/f64 denormals kept, and the translation threw with f16/f64 denormals flushed. The f32 result now goes through the f32 result modifiers, as measured on RDNA2 (gfx1036) for mul:2 in the boykopovar#981 audit and as LLVM (SIFoldOperands) and ACO (apply_output_mul) fold an f32 multiply by 2, 4 or 0.5 into it. The mode with f32 output denormals kept and f16/f64 output denormals flushed is not measured and still throws. A denormal result is flushed to a zero of the same sign in the f32 flush modes, as the other f32-result instructions, following the RDNA2 ISA single-precision denormal field and LLVM's and ACO's treatment of the converted value as already flushed. Denormal modes 1 and 2 now throw for it as for the others. F64Rounding's v_cvt_f32_f64 mul:2 column is pinned to the hardware values in the titles' mode, and a new execution test covers the modifier and the flush in each float mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nikowolf123
force-pushed
the
fix/shader-cvt-f32-f64-result-modes
branch
from
October 13, 2026 15:56
d176ede to
8c257b1
Compare
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
|
This was referenced Oct 13, 2026
RINNECODER
added a commit
to RINNECODER/AnyPS5
that referenced
this pull request
Oct 14, 2026
…t) (#481) * fix(recompiler): give vertex-path shaders the NGG group info Ported from upstream PR boykopovar#5081 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): put the compute wave index in TG_SIZE[11:6] Ported from upstream PR boykopovar#5214 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): take the 32_AR export alpha from channel 1 as GFX10 does Ported from upstream PR boykopovar#5110 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): order buffer and image memory at s_barrier Ported from upstream PR boykopovar#5117 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): decode GFX10 scratch offsets as one dword Ported from upstream PR boykopovar#5426 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): accept MIMG sampler tuples ending in VCC Ported from upstream PR boykopovar#4996 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(recompiler): name the attribute of an out-of-range interpolation reference Ported from upstream PR boykopovar#5450 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): decode the high-half result of v_interp_p2_f16 Ported from upstream PR boykopovar#5471. The Vop3InterpDecode unit-test hunk is not ported (that test file is not on main); the execution test InterpolationF16 carries the coverage. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): clear the bits of inactive lanes in VALU carry-out and v_div_scale masks Ported from upstream PR boykopovar#5162 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): apply the f32 output modifier and denormal flush to v_cvt_f32_f64 Ported from upstream PR boykopovar#5159 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): update per-invocation LDS without atomics Ported from upstream PR boykopovar#5160. Conflicts resolved against main: kept main's barrier condition for non-LDS shared atomics; the unit-test hunk for SRT read patching (a different upstream change, not on main) is dropped. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): flush ds_add_f32 denormals and NaNs as the hardware does Ported from upstream PR boykopovar#5492 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(shader): run DS src2 lanes one at a time in lane order Ported from upstream PR boykopovar#5498 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(agc): compare NOT_EQUAL unordered, reject TRUNC_COORD point sampling and round the array layer half to even in color compare emulation Ported from upstream PR boykopovar#907 (follow-up to its predecessor). Hand-applied to main's reworked emitter: NOT_EQUAL uses OpFUnordNotEqual, the array layer is clamp(roundEven(z)), and ResourceMaterializer rejects TRUNC_COORD with point filtering. The upstream execution-test rewrite is not ported (it targets a diverged test file). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * chore(shader): bump ShaderDiskCache FormatVersion to 35 The ported DS fixes add MemoryInfo::flushDenormalResults (now encoded in the plan) and new IR opcodes, so cached payloads from format 34 must not load. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(shader): run ported upstream execution tests on Metal through a device shim The upstream execution tests for the ported fixes compile unchanged against a Metal stand-in for the Vulkan test device (guest buffer descriptors are mirrored into shared MTLBuffers). Covers boykopovar#5162 (VALU carry-out masks), boykopovar#5159 (v_cvt_f32_f64 result modes), boykopovar#5492 (ds_add_f32) and boykopovar#5498 (DS src2 lane order). The LdsSrc2 and LdsSrc2Wide tests use device-memory LDS, which the Metal bridge rejects, and are not registered. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(shader): run ported decoder and collector unit tests in the Metal build Registers the upstream tests for boykopovar#4996, boykopovar#5426 and boykopovar#5450 (already on main's tree but not built for Metal) and a high-half decode check for boykopovar#5471. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(shader): check per-invocation LDS updates without atomics on the Metal recompiler Standalone copy of the boykopovar#5160 verifyFunctionLdsUpdates check. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(shader): check the TG_SIZE wave index on Metal Buffer-store variant of the boykopovar#5214 execution test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(shader): run the s_barrier memory-order execution test on Metal Registers boykopovar#5117's upstream test through the device shim. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(shader): draw a 32_AR export on Metal Guest-replay draw for boykopovar#5110: alpha comes from export channel 1. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(shader): draw an NGG vertex shader that reads the group info Guest-replay draw for boykopovar#5081. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(shader): reject TRUNC_COORD point sampling in the color compare emulation Recompile-level check for boykopovar#907. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * test(shader): run the src2 lane-order test without the Metal debug layer Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * docs(shader): port upstream debt entries and add the FormatVersion 35 history line Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Collaborator
|
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
v_cvt_f32_f64writes an f32 result, but the recompiler treated that result like an f64 result in two places.float64Operationchecked the VOP3mul:2,mul:4anddiv:2against the f16/f64 denormal field and then cleared it. In the titles' float mode (IEEE=0,FLOAT_MODE0xc0, which is also how shaders without a known mode are translated) the modifier was silently dropped. With f16/f64 denormals flushed (for example 0x00) the translation threw. The hardware applies the modifier in both modes. Example:v_cvt_f32_f64_e64 v22, v[4:5] mul:2of 1.0 gives 0x40000000 on gfx1036 in the titles' mode, andmaingave 0x3f800000.f32DenormalFlushForhad no case forv_cvt_f32_f64, so a result below 2^-126 was whatever the host returned. In the f32 flush modes, 2^-130 must give +0. On lavapipemaingave 0x00080000.Sources:
tools/hw-oracle. The data is in gist SleglJan/30456e5687240f0b639a78e5477f2f91 (revision 1d26d816),audit.json, F64Rounding column 12 (v_cvt_f32_f64_e64 v22, v[4:5] mul:2). In all 28 finite rows the modifier is applied in the titles' mode (IEEE=0, f32 denormals flushed, f16/f64 kept). It is also applied with f16/f64 denormals flushed. It is ignored with IEEE=1 or with f32 denormals kept. The ±inf and NaN rows are the same in every mode. I checked all 28 cells against the model this change implements (round, flush, then raise the exponent by one) and found no mismatch.FP_DENORMbits [5:4] are the single-precision mode and bits [7:6] the double/half-precision mode. Mode 0 flushes input and output denormals, mode 1 flushes output only, and mode 2 flushes input only.V_CVT_F32_F64, "D.f = (float)S0.d", and denormals are supported.llvm/lib/Target/AMDGPU/VOP1Instructions.td:281-282definesV_CVT_F32_F64withVOP_F32_F64, which has an f32 destination (SIInstrInfo.td:3137).SIInstrInfo.td:2903(HasOMod = !if(IsVOP3P, 0, DstVT.isFP)) gives it an omod operand.SIFoldOperands.cpp:2491-2509:isOModtreats aV_MUL_F32by 2, 4 or 0.5 as an output modifier only when f32 output denormals arePreserveSign.SIFoldOperands.cpp:2625-2687:tryFoldOModfolds that multiply into the instruction that defines its operand when that instruction has an unset omod.SIFoldOperands.cpp:3181-3185and3236-3239: it does not fold with IEEE mode on.fptruncfollowed by a multiply by 2.0 compiles tov_cvt_f32_f64 ... mul:2under the f32 flush mode, whatever the f64 mode.llvm/lib/Target/AMDGPU/SIISelLowering.cpp:16312-16324:isCanonicalizedlistsISD::FP_ROUNDunder "These will flush denorms if required."llvm/test/CodeGen/AMDGPU/fcanonicalize-elimination.ll:237-251(test_fold_canonicalize_fpround_value_f32_f64, RUN lines 1-4 include-denormal-fp-math-f32=preserve-sign) expects nov_mul/v_maxcanonicalize afterv_cvt_f32_f64_e32.src/amd/compiler/aco_optimizer.cpp:3905-3980(apply_output_mul, called forv_mul_f32at 3995-4001) takes the denormal mode from the result type:denorm32for an f32 result (3913). It folds only underfp_denorm_flushand when signed zeros need not be preserved (3954-3956), and only into a parent with output modifiers (3960).aco_opcodes.py:1040defines("v_cvt_f32_f64", dst(F32), ...).F32hasmods=True(aco_opcodes.py:260), whichaco_opcodes_cpp.py:81turns intooutput_modifiers.aco_optimizer.cpp:1658-1717(gather_canonicalized) marks every float VALU result, this one included, as canonicalized. Lines 2198-2204 then turn a canonicalize of such a value into a plain move, so withdenorm32at flush ACO relies on the conversion having flushed its result.What changed:
Float64Instructions.cpp,float64Operation: the f32 result (onlyConvertF32F64has one) is written with its modifiers.writeOperandthen applies the existing f32 result rule:applyF32ResultModifiers, withoutputModifierAppliesreadingFLOAT_MODEbits 5:4 and IEEE. The f16/f64 refusal stays only where the f32 rule ignores the modifier but the f16/f64 rule would apply it. That is f32 output denormals kept with f16/f64 flushed at IEEE=0, for example 0x30. Nobody has measured that mode, so translating it still throws. U32 and U64 results are unchanged.VectorInstructions.cpp,f32DenormalFlushFor:VCvtF32F64joins the group that flushes inputs and result (flush = 3u). The source is read withreadF64, so only the result flush takes effect. As for every instruction in that group, f32 denormal modes 1 and 2 now throw, because they are not measured. Before, mode 1 was translated without the output flush the ISA describes for it, and mode 2, which keeps output denormals, needed no flush and was translated.docs/dev/debt/shader.md: the f32 denormals entry and the output modifier entry now say which parts are measured, which come from the sources, and which are not measured. The unmeasured parts are scaling before rounding near the f32 denormal and overflow boundaries,mul:4anddiv:2, mode 0x30, and tininess detection just below 2^-126.F64Rounding.cpp: column 12 (cvt f32, themul:2instruction above) runs with no float mode, that is, in the titles' mode. Its 28 finite cells held the value without the modifier, which is what the hardware returns with IEEE=1 or with f32 denormals kept. They now hold the measured titles'-mode value fromaudit.json, which is the old value times 2. Row: old → new:Rows 3, 5, 6 and 8 (±inf, NaN) do not change, as measured.
New test
VCvtF32F64ResultModes.cpp(agc_driver_vcvt_f32_f64_result_modes): 32 f64 sources over 64 lanes, run in wave32 and wave64. Each source is converted plain and withmul:2,mul:4anddiv:2.What each row rests on:
mul:2of finite values, ±inf and NaN matches the Shader float mode (IEEE_MODE, DX10_CLAMP, FLOAT_MODE) is per shader; the recompiler assumes one #981 measurement. 1.0, -2.5, -2^-60 and 0x4153959f_c5f99476 are rows of the measured kernel.mul:4anddiv:2of normal values are exact multiplications by 4 and 0.5 (section 6.2.2).div:2give the same result whether scaling comes before or after rounding. So none of these rows depends on the unmeasured order.No title is known to use this encoding.
Tested
Linux (WSL2 Ubuntu), GCC, Release, configured like CI (
-DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON). Tests ran on lavapipe (llvmpipe, LLVM 21.1.8) withVK_ICD_FILENAMES=<lvp_icd>.json ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx.agc_driver_vcvt_f32_f64_result_modes: "wave32 no float mode lane 0 v_cvt_f32_f64 mul:2 is 0x3f800000, expected 0x40000000"agc_driver_f64_rounding: "lane 0 cvt f32 is 0xa1800000, expected 0xa2000000"VCvtF32F64removed fromf32DenormalFlushFor: "lane 24 v_cvt_f32_f64 is 0x00080000, expected 0x00000000"mul:2ctest -j4 -R 'agc_shader|agc_driver|shader|recompiler': 384 tests, none fail, 36 skip on lavapipe. Unmodifiedmainin the same tree runs 383 tests with none failing and the same 36 skipped. The only per-test difference is the new test.ctest -j4: 1050 tests, none fail, 43 skip (the 36 above and 7 video out tests). In the run on unmodifiedmain(1049 tests),guest_video_out_wqhd_detectionfailed andguest_video_out_output_modeandguest_video_out_resolution_statuswere skipped. All three pass when rerun onmain's recompiler and with this change, so there is no per-test regression.tools/check_conventions.py --base origin/main(main's checker) andgit diff --check: clean.This was not measured on AMD hardware for this PR. Only the #981 data above was. A gfx103x reviewer can check every row of the new test with the oracle, from the repository root:
What each mode should print:
Expectedrows.Expectedin all four outputs.Kept.These extra rows settle the unmeasured items in the debt entries:
Run
edges.txtwith the same loop. The rows are, in order:mul:2of 1.5 * 2^-127 andmul:4of 1.5 * 2^-128 (scaling before or after the flush)div:2div:2of a value that rounds to infinityNative Windows 11, WinLibs GCC 15.2.0, NVIDIA GeForce RTX 5080 (driver 616.92), on this branch rebased onto
main0f2683c (d176ede):agc_driver_vcvt_f32_f64_result_modesandagc_driver_f64_roundingpass 3 of 3 runs, andctest -R 'agc_shader|agc_driver|shader|recompiler'passes 383 of 383.Rebased onto
mainfdefd76. The only conflict wasdocs/dev/debt/shader.md, wheremainadded the patch-constants entry above the output-modifier entry this PR edits; both are kept. The code change is unchanged. WSL2 Ubuntu 26.04, lavapipe (Mesa 26.0.8), CI configuration:agc_driver_vcvt_f32_f64_result_modesandagc_driver_f64_roundingpass, andctest -R 'agc_shader|agc_driver|shader|recompiler'passes 390 of 390.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code