fix(shader): apply the output modifier to v_cvt_f32_f64 by the f32 denormal field #13847
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13847"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Deftera186 on 2026-10-31T09:23:00Z.
What
v_cvt_f32_f64writes an f32 result, butTranslationContext::float64Operationhandled its non-U64 result like an f64 result: it calledrejectHalfOrDoubleOutputModifier(which checks the f16/f64 denormal field) and then setdestination.omod = 0ubeforewriteOperand, so the output modifier was dropped or threw. Withmul:2and a known float mode (FLOAT_MODE 0xc0, IEEE=0),v_cvt_f32_f64of 1.0 returned 0x3f800000 where gfx1101 returns 0x40000000; with IEEE=0 and the f16/f64 output denormals flushed (e.g. FLOAT_MODE 0x40) the recompile threwoutput modifier on an f16 or f64 result with f16/f64 output denormals flushed is not implemented.gfx1101 applies
mul:2,mul:4anddiv:2to the converted f32 value exactly when IEEE mode is off and bit 1 of the f32 denormal field is clear (denorm32 0 or 1), for any f16/f64 field value, and ignores the modifier otherwise. That is the f32-result rule the recompiler already encodes inTranslationContext::outputModifierApplies(4u), applied bywriteOperandthroughapplyF32ResultModifiers. When the shader's float mode is known, the fix writes the result withwriteOperand(inst.destination, result)so the f32 rule andclampapply.When the float mode is not known, the fix clears
omodbeforewriteOperand, so the modifier is dropped and the plain conversion (withclamp) is written. This differs from the native f32 ops, which assume the title default (IEEE off, f32 denormals flushed) and apply the modifier under a missing mode:v_cvt_f32_f64's applicability is gated on the f32 denormal field, which a missing mode does not pin, and the existingagc_driver_f64_roundingtest measures a mode-lessv_cvt_f32_f64 mul:2writing the plain conversion (0xa1800000, not the scaled0xa2000000), a value stable across the RADV, NVIDIA and AMD-Windows GPUs the CI runs. Applying the modifier under a missing mode regressed that test; gating onfloatMode.has_value()keeps it green while preserving every measured explicit-mode result.The three U32-result opcodes that reach the same branch (
v_cvt_i32_f64,v_cvt_u32_f64,v_frexp_exp_i32_f64) are unaffected in either path: the decoder never sets an output modifier on them (they are not inisVop1FloatResultOpcode, so VOP3 clearsomod), andwriteOperandappliesapplyF32ResultModifiersonly to anIrType::F32value, so their U32 result goes straight towriteRawU32as before.Clamp is unchanged:
writeOperandalready passeddestination.clampthrough, andapplyF32ResultModifiersapplies it after the modifier, as the hardware does, under both the known-mode and missing-mode paths.A separate gap, not changed here and left for a separate pull request: when the converted value is itself an f32 denormal, gfx1101 flushes it to a signed zero whenever bit 1 of the f32 denormal field is clear (denorm32 0 or 1), in both IEEE modes.
f32DenormalFlushForreturns 0 forv_cvt_f32_f64, so the plainOpFConvertkeeps the denormal at denorm32 1 on RADV. This is the same onmainand independent of the output modifier. The test avoids inputs whose plain result is an f32 denormal; the rows wherediv:2produces a denormal are kept, becausescaleF32Resultalready collapsesdiv:2of a value below 0x01000000 to the signed zero the hardware writes.The conversion-specific provenance (gfx1101, tools/hw-oracle, not RDNA2 or gfx1013) and this deferred denormal gap are recorded as two new entries in
docs/dev/debt/shader.md, beside the existing output-modifier and clamp entries.Sources:
isVop1FloatResultOpcodelistsv_cvt_f32_f64but notv_cvt_i32_f64/v_cvt_u32_f64/v_frexp_exp_i32_f64(core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp);supportsNativeVop3ResultModifiersgatesomodon it, so VOP3 setsomod = 0for the three integer-result conversions.makeMeta("ConvertF32F64", F32, U64)versus theU32-resultConvertS32F64/ConvertU32F64/FPFrexpExp64(core/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cpp).Tested
Measured on RDNA3 (gfx1101, Radeon RX 7700 XT) with tools/hw-oracle; not measured on the PS5's gfx1013 or on RDNA2.
CvtF32F64OutputModifier.cpp(ctestagc_driver_cvt_f32_f64_output_modifier): 22 f64 inputs (normals, the f32 overflow boundary, values that round to the f32 minimum normal, values whosediv:2becomes an f32 denormal or zero, quiet and signaling NaNs, infinities, both zero signs) by eight forms (plain,mul:2,mul:4,div:2, each also withclamp). Modes: no float mode (modifier dropped, so the plain/clamped conversion, matching the missing-mode path above); FLOAT_MODE 0xc0 IEEE=0 and 0xd0 IEEE=0 (apply); 0x40 IEEE=0, which flushes the f64 output denormals and throws onmain, proving the f16/f64 field no longer matters; 0xe0 and 0xf0 IEEE=0 and 0xc0 IEEE=1 (ignore). Expected values are the gfx1101 results for the explicit modes; the three NaN inputs assert NaN-ness on the unclamped columns, every other value is asserted bit-exact. The test keeps thespv::CapabilityFloat64skip.Float64Instructions.cppreverted toorigin/mainand the test present, the first mismatch isv_cvt_f32_f64 output modifier: lane 0 0xc0 IEEE=0 v_cvt_f32_f64 mul:2 is 0x3f800000, expected 0x40000000;agc_driver_f64_roundingpasses onmain. With the fix the new test passes (0.45 s locally, 0.22 s on lavapipe) andagc_driver_f64_roundingstill passes: its mode-lessv_cvt_f32_f64 mul:2writes the plain0xa1800000, which the pre-fix no-mode-gate implementation scaled to0xa2000000.mainhas 176 mismatching results (52 at FLOAT_MODE 0xc0 IEEE=0, 76 at 0xd0 IEEE=0, and 24 in each of the two IEEE=1 denorm32 1 modes) and throws in the four IEEE=0 modes with denorm16 0. The fix's only differences from the hardware are 60 results at denorm32 1 on the three inputs whose plain conversion is an f32 denormal (plain and clamp with IEEE off; every column with IEEE on, where the modifier is ignored); they are the separate gap below and are the same onmain. The sweep programs an explicit mode on every row, so it does not cover the missing-mode path, which the recompiler translates with the modifier dropped.agc_driver_dpp_no_form,agc_driver_f64_integer_arithmetic,agc_driver_nan_quieting(the existing execution tests that runv_cvt_f32_f64),agc_driver_f64_rounding, and the f64*denormal_modestests (f64_add_mul_denormal_modes,f64_rounding_denormal_modes,div_fixup_f64_denormal_modes). State A (fix reverted, test present): only the new test fails;Insert instance layer "VK_LAYER_KHRONOS_validation"count stable, missing-layer line 0,VUID-0. State B (fix): all pass; missing-layer 0,VUID-0. B's VUID count does not exceed A's.agc_driver_f32_output_modifier, all pass onllvmpipe (LLVM 20.1.2, 256 bits); times cvt 0.24 s, div_fixup_f64 0.22 s, dpp_no_form 0.04 s, f32_output_modifier 0.39 s, f64_add_mul 0.24 s, f64_integer 1.21 s, f64_rounding 0.47 s, nan_quieting 0.64 s.Hardware results on gfx1101, FLOAT_MODE 0xc0, IEEE=0, DX10_CLAMP=1 (round to nearest even). The
maincolumn is the recompiler'smul:2result before the fix, where it differed.At FLOAT_MODE 0xe0/0xf0 IEEE=0 (f32 denormal field bit 1 set) and at 0xc0 IEEE=1 the hardware ignores the modifier: every column equals the plain result. Without a known float mode the translation also writes the plain result, matching
agc_driver_f64_rounding. Thediv:2of a value that converts to the f32 minimum normal (0x00800000 from 0x3810000000000000, 0x380fffffffffffff) is the signed zero the hardware writes.GPUs tested: AMD Radeon RX 7700 XT (gfx1101), RADV, Mesa 26.2.4, Gentoo Linux (kernel 7.2.11); llvmpipe (LLVM 20.1.2), Mesa 25.2.8, Ubuntu 24.04 container with the Linux CI configuration.
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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T09:25:00Z.
Review: APPROVED
Reviewed — looks good
At head
211d10cadc55bf85adeb311bea77b28bbf6e4eed, the change routes the f32 conversion result through the existing f32 modifier/clamp handling, and I found no blocking issue.What I ran
GitHub reports PR base
beb7ce3c4a5ff81765d438e523b1dd386d947dc8; becausemainadvanced, I also checked the exact head against currentmaind8ffa97effa1ab0113dc265d936e94322045875d. The merge preview was clean. Environment: Linux x86_64, Python 3.11.2, Git 2.39.5; no compiler was invoked.Results
main.main, #13845, and #13842.writeOperandapplies the existing f32 result-modifier/clamp path to f32 values; the new test checks plain,mul:2,mul:4,div:2, clamp combinations, and mode-dependent apply/ignore behavior.Selected unedited command output
Conventions:
Merge previews, in command order:
Negative control
Findings
Blocking
None found.
Non-blocking
The author reports the paired focused validation-layer runs on gfx1101/RADV and the lavapipe suite; I did not independently run them. The PS5 gfx1013/RDNA2 is not measured. The added code uses the existing generic f32 modifier path, so this does not block approval.
Sources
Not verified
No local build, CTest run, or negative control was performed. The hardware and lavapipe results are author-reported; no PS5 gfx1013/RDNA2 run was available. The latest hosted Windows and specialized relinker jobs had not finished.