Shader float mode (IEEE_MODE, DX10_CLAMP, FLOAT_MODE) is per shader; the recompiler assumes one #981
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 adriadam10 on 2026-10-06T21:33:31Z.
The recompiler doesn't read the shader's float mode, and every float semantic we've added so far was measured in one fixed mode. Which mode is right depends on the shader, so some results are wrong for some titles.
What the hardware does with the mode
Each shader carries its mode in
RSRC1(COMPUTE_PGM_RSRC10x212,SPI_SHADER_PGM_RSRC1_PS/GS/HS0x00A/0x08A/0x10A), and the wave starts in that mode:IEEE_MODEDX10_CLAMPFLOAT_MODEFP16_OVFLA shader can also change the mode at run time with
s_setreg*,s_denorm_modeors_round_mode.What titles use
eboot.bin:IEEE_MODE=0in all of them.FLOAT_MODE=0xc0(f32 denormals flushed, f16/f64 kept, RNE) withDX10_CLAMP=1in 2932;0x00withDX10_CLAMP=0in 10. No run-time mode changes.float_mode == 0xc0,dx10_clampand noieee_mode(src/graphics/shader/shader.cpp), and reads the f32 denormal bit of compute shaders.FLOAT_MODE=0x04in pixel shaders (f64 round toward +inf, KytyPS5/KytyPS5#884). Gran Turismo 7 (PS4) needs its own f64 denormal mode in its compute shaders (shadps4-emu/shadPS4#5126).What's wrong on our side
mainfollow IEEE=0 (output modifier), others IEEE=1 (v_mullit_f32). Both are recorded in TechnicalDebt.IEEE=1with f32 denormals kept, the opposite of what Astro's Playroom uses. Anything measured without passing the flags was measured in the wrong mode for it. Example: #533 (ours) matched the hardware in all 512 cells with IEEE=1, but 114 differed with IEEE=0.SignedZeroInfNanPreserveis declared, so f32 denormal results differ between host GPUs, except in the ops that handle them on the bits.What we'd do
DX10_CLAMP, rounding andFP16_OVFL. Document it inHW_ORACLE.md.RSRC1for compute and every graphics stage into theRecompileRequest, include it in the shader cache key and the request serializer, no behaviour change.DenormFlushToZero/DenormPreserve,RoundingModeRTE/RTZ) where the device reports support. Throw where it doesn't, and for RTP/RTN, which Vulkan has no execution mode for.Questions
RecompileRequestand the cache key, which #639 is reworking. Where should the mode go so it fits #639: a field of the request, or part of whatRegisterShaderkeeps?0x00/DX10_CLAMP=0would throw until DX10_CLAMP and f16 denormals are done). Is that the behaviour you want, or should those run and only be listed in TechnicalDebt?Until this is settled we've stopped our shader work: no new shader PRs from us, and we're pausing our reviews/merges of float-related shader PRs. Integer, memory and decoding PRs don't depend on the mode. Our open #533 is on hold until it can be done for both IEEE values.
cc @oneandonlydean
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T05:50:52Z.
Open shader PRs on hold until this is settled, because their results depend on the float mode:
v_fma_f64with subnormal operands (f64 denormals)v_interp_*_f16(f16 denormals/rounding, NaN)ds_{add,min,max}_src2_f32(float ops in LDS)Integer, memory and decoding shader PRs are reviewed and merged as usual.
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-07T19:20:31Z.
Data point for the f16/f64 denormal half of
FLOAT_MODE, from a host GPU that flushes f16 denormals when no mode is declared.Intel Raptor Lake-S Mobile Graphics, Windows driver 32.0.101.6790, current main:
agc_driver_vopc_compare: 26 mismatches, all with an f16 denormal operand. Example: thread 0, f16a = 0x8000,b = 0x0001, where compares 36, 37, 40, 43, 46 and 47 are wrong (compare 36 is 0, expected 1).agc_driver_sdwa_float_selectors: 11 mismatches. Example:lane 6 min_f16 BYTE_0/WORD_1 -> WORD_0 is 0xfda00047, expected 0xfda00000.UnpackHalf2x16and computes in f32. Vulkan lets the driver flush denormals produced by unpacking unless the entry point declaresDenormPreservefor that width (Vulkan spec, "Precision and Operation of SPIR-V Instructions"). OnlySignedZeroInfNanPreserve 32is declared, so this driver's result is allowed.OpCapability DenormPreserveandOpExecutionMode %main DenormPreserve 16to the emitted modules makes both tests pass on the Intel GPU and on the RTX 4070.DenormPreserve 32alone changes nothing.VkPhysicalDeviceFloatControlsPropertieson the two devices:denormBehaviorIndependenceshaderDenormPreserveFloat16/32/64So for the common
FLOAT_MODE = 0xc0(f16/f64 denormals kept), both devices can honour the f16 part throughDenormPreserve 16. The f32 flush part has no portable equivalent on the RTX 4070 (shaderDenormFlushToZeroFloat32 = 0).No PR, since float-mode PRs are on hold here. The patched modules were tested in a local harness that loads the emitted SPIR-V before dispatch. Found with AI assistance (Claude Code); the numbers above were measured on the hardware listed.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T20:00:22Z.
Picking this up now that #639 is in. Plan, one PR each:
IEEE_MODE,DX10_CLAMP,FLOAT_MODE(denormals + rounding) andFP16_OVFL, andHW_ORACLE.mddocuments them.RSRC1of compute and every graphics stage intoGuestContextin theRecompileRequest, and include it in the shader cache key and the request serializer.IEEE_MODE=0: NaN rules of min/max/med3, signaling NaN quieting and omod, both values measured on hardware.Modes we don't model yet keep running as today and are listed in TechnicalDebt; only ops whose result we know depends on the mode will throw. That answers the second question in the issue the less disruptive way. @boykopovar, say if you'd rather they throw.
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T20:34:18Z.
Hardware on offer for this plan: a Ryzen 7950X3D iGPU (Raphael, gfx1036, RDNA2) running
tools/hw-oracleunder hsa-rocr 7.2.4 on Linux, in the same machine as an RTX 3080 (NVIDIA) and the RADV iGPU as Vulkan hosts. On the NVIDIA hostshaderDenormPreserveFloat32,shaderDenormFlushToZeroFloat32andshaderDenormFlushToZeroFloat16are false and onlyshaderDenormPreserveFloat16is true; the RADV host reports all four true with 32-bit-only independence.Unless someone has it in hand, I'll take the audit step: replay the execution tests' ALU kernels on the oracle in the titles' mode (IEEE 0, f32 denormals flushed, f16/f64 kept, DX10_CLAMP 1, RNE) and in the old default (IEEE 1, f32 denormals kept), plus the other IEEE × denormal × DX10_CLAMP combinations, and post here the cells that depend on the mode or were pinned in the wrong one, with the script. After that I can take one family, FLOAT_MODE denormals if nobody has started it, since the f32 flush needs SPIR-V emulation on NVIDIA and that can be checked against both hosts here; say if you'd rather I take DX10_CLAMP or FP16_OVFL instead.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T21:23:36Z.
Audit of the execution tests' pinned rows against the hardware under the float modes, as offered above. Measured on 2026-10-08 on a Ryzen 7950X3D iGPU (Raphael, gfx1036, RDNA2) with
tools/hw-oracleunder hsa-rocr 7.2.4 on Linux (CachyOS, kernel 7.2.9), onmain4b6ab6bb's test sources; the PS5's gfx1013 is not measured.Method. Of the 186 execution tests, 56 kernels (in 48 tests) load their inputs into
v4..v7and store fromv10on, so their ALU words run on the oracle unchanged as.longwords; 47 of those (from 41 tests) could be driven automatically, since their rows are tables in the source. Each kernel's rows ran in seven modes: the titles' mode (IEEE_MODE=0, f32 denormals flushed, f16/f64 kept,DX10_CLAMP=1, RNE,FP16_OVFL=0), the oracle's former default (IEEE_MODE=1, f32 denormals kept), and the titles' mode with one field changed at a time (IEEE 1, f32 kept, f16/f64 flushed, DX10_CLAMP 0, FP16_OVFL 1). The same kernels, whole, ran through the recompiler on an RTX 3080 (NVIDIA) and on the RADV iGPU; the 48 tests pass on both hosts. 27,652 result cells. The comparison that matters is bit-exact against the test's ownExpectedtable, honouring itsCheckedmasks, for the 36 kernels that have one (the other 11, the DPP, DsSwizzle, Permlane16 and FmaLegacy kernels, compute their expectation in code and have no mode-dependent cells); a NaN-tolerant comparison hides 68 of the cells below per 32-bit word, or 125 if f16 halves are compared the same way.Asserted cells whose pinned value differs from the hardware in the titles' mode: 217. On all of them both hosts return the pinned value bit-exact.
v_min_f64/v_max_f64(14), f64 add/mul/fma/ldexp quiet bit (21)IEEE_MODE=1v_ldexp_f16_sdwaquiet bit, 3 columnsIEEE_MODE=1v_cvt_f32_f64 mul:2IEEE_MODE=1, or f32 denormals keptv_div_fixup_f16quiet bit, all 8 formsIEEE_MODE=1IEEE_MODE=1IEEE_MODE=1v_mul_lo_i32The quiet-bit cells all have the same shape: with
IEEE_MODE=0the hardware passes a signalling NaN through f32, f64 and f16 results unquieted (0x7f800001,0x7ff0000000000001and0x7c01stay); withIEEE_MODE=1it is returned quieted, which is what the tables hold. For min/max withIEEE_MODE=0a NaN operand, signalling or not, loses to the other operand (v_min_f64(1.0, sNaN)is 1.0); withIEEE_MODE=1the sNaN is returned quieted. F32MinMaxNan is pinned in the titles' mode and matches; F64Arithmetic's min/max are pinned in IEEE 1, so the recompiler's f32 and f64 min/max follow different modes today.One output-modifier deviation from the recompiler's own omod rule.
v_cvt_f32_f64 mul:2of 1.0 gives0x40000000on the hardware in the titles' mode and0x3f800000with IEEE 1 or with f32 denormals kept.Translation/src/Float64Instructions.cppclearsomodon every f64-family result (lines 30 and 37), following #446's "omod is ignored by every f64 op (cvt_f32_f64too)", measured in a mode where it is. The rule the data supports, with every IEEE × denormal combination run for each result type: the output modifier applies only whenIEEE_MODE=0and the denormal field of the result's own type says flush. An f32 result follows the f32 field, socvt_f32_f64applies it in the titles' mode. An f64 or f16 result follows the f16/f64 field, so both ignore it in the titles' mode and apply it withIEEE_MODE=0and that field at 0:v_mul_f64 div:2of 2.5 gives0x3ff4000000000000there and0x4004000000000000in every other combination,v_add_f16 mul:2of 1.0+1.0 gives0x4400there and0x4000otherwise. An applied modifier also turns -0 into +0 (v_mul_f32(-0, 1) mul:2is +0). TechnicalDebt's output-modifier line records the f32 rule and the f16 one; the f64 half andcvt_f32_f64are not recorded.Cells the tests do not assert, where both hosts differ from the hardware in the titles' mode: 19, all masked on purpose (#511: results that depend on the denormal mode; #498: underflowing products). In 14 SdwaFloatSelectors cells the hosts return the f32-denormals-kept value, which is also the pinned one (row 4 column 7,
v_max_f32_sdwa sext(v4) WORD_1, v5 clamp: hardware0, hosts and table0x00001a0e). Row 3 of the same column matches no mode: hardware0, hosts0x000005c2, table0x00470047(the denormals-kept value). Row 4 column 11 is an f16 sNaN: hardware0x7cde, RADV0x7ede, NVIDIA0x7fff. Vop2ModifierForms rows 17, 18 and 21 column 4 (v_mul_legacy_f32_dpp): hardware+0, since the input is flushed before the legacy zero rule; hosts-0; the table holds-0in row 21 and the denormals-kept0x80000001/0x80002000in rows 17 and 18.Host differences: 95 cells, all NVIDIA's canonical NaN (
0x7fffffff, f160x7fff) on f32 and f16 results and through SDWA selectors. RADV returns the titles'-mode hardware value in 94 of them; the exception is SdwaFloatSelectors row 4 column 11 above. Every affected test masks or NaN-compares those cells.Which field changes which result, over the 1,907 cells whose bits depend on the mode (1,691 ignoring NaN payloads; a cell can depend on several fields)
IEEE_MODEv_ldexp_f16,v_pack_b32_f16,v_div_fixup_f16v_mul_legacy_f32's zero ruleDX10_CLAMPFP16_OVFLv_div_fixup_f16's infinity caseThe per-kernel breakdown (
mode-sensitivity.txt), the per-cell data for the flagged cells (audit.json, with the seven mode values and both hosts), the pinned-versus-hardware listing and the scripts are at https://gist.github.com/SleglJan/30456e5687240f0b639a78e5477f2f91. The remaining 59 partially replayable kernels (results stored outsidev10..v25or more than 16, prologue address setup or register initialisation, branches outside the ALU words, EXEC changes, user-data SGPRs) are being adapted for a second pass; the memory and image tests are out of the oracle's reach. If wanted, the replay driver can go in undertools/and the harness, which runs any kernel's words through the recompiler on the hostANYPS5_GPUselects, as an execution-test target, so the audit reruns on any RDNA2 machine.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T22:11:35Z.
Second pass of the audit above, covering the kernels that needed adapting (results outside
v10..v25, more than 16 results, prologue setup, user-data SGPRs, computed inputs), plus the Division kernels and the four whose code arrays hold a named constant. Same GPU, oracle and seven modes;main4b6ab6bb's test sources and recompiler; upstream has since changed F32MinMaxNan.cpp and added ImagePckN, InterpolationF16, InterpolationModes, LdsSrc2 and PackedAlu, which this pass does not cover. 221 adapters run (43 whole kernels, 168 parts of 16 kernels split by result columns, store-free word ranges or input groups, 4 single test cases, 6 wave64), 11 skipped: five branch cases whose path runs through a store (BranchPastEndpgm, LoopEndingExits), and six kernels that need more than the oracle's 4 KiB of LDS (four), eight inputs per lane, or an opcode with no gfx103x encoding. 62 kernels, 69,504 cells; a second oracle run of every adapter reproduced all 486,528 values except ShaderClock's masked clock columns. 18 kernels with table inputs also ran through the recompiler on both hosts; the 42 with computed inputs and the two that take user-data SGPRs did not.Asserted cells whose pinned value differs from the hardware in the titles' mode: 163, every one a signalling NaN kept unquieted by the hardware with
IEEE_MODE=0and quieted in the table, reproduced byIEEE_MODE=1only, as in the first pass.v_div_fmas_f32,v_div_fixup_f32v_ldexp_f16,v_frexp_mant_f16,v_mul_legacy_f32v_add_f16,v_mul_f16The other 14 kernels with a pin table (13 tests) match in all 16,960 asserted cells. Both hosts return the pinned value in 147 of the 163 cells; in the other 16, all in the NaN-tolerant tests, NVIDIA returns its canonical NaN, and RADV the hardware value in Float16Misc's four. So Vop1FloatUnary's and Division's sNaN rows assert the IEEE 1 result exactly, and the recompiler at
4b6ab6bbgives it in every mode. Unasserted cells whose pin differs: 82, all captured with f32 denormals kept (72v_mul_legacy_f32lanes with an f32 denormal, where the hosts return the hardware's +0 in 35, -0 in 19 and the pin in 13, and differ from each other in 5; and 10 masked Vop1FloatUnary cells).Host versus hardware on the 18 host-run kernels: 358 of 22,944 cells, none outside what the test's own check accepts; the sources are the quiet bit above, NVIDIA's canonical NaN, f32 denormal inputs the hosts do not flush (unasserted
v_mul_legacy_f32lanes and Vop1FloatUnary row 0), and differences within the tolerance of the transcendental columns. In every cell of an integer, scalar or LDS instruction the oracle and both hosts agree, which is the check that those 18 adapters reproduce their kernels; RelativeIndexing is checked by its table alone, and the other 43 kernels compute their expectation in code and are compared across modes only.Which field changes which result, over the 1,224 cells whose bits depend on the mode
IEEE_MODEv_cvt_f32_f16 mul:4,v_cvt_f32_ubyte0 mul:2,v_cvt_f32_ubyte1 div:2(188, with f32 denormals: the output-modifier rule)v_mul_legacy_f32with a denormal lane (72); the LDS float atomics' columns (54); 10 masked Vop1FloatUnary cellsFP16_OVFLv_ldexp_f16,v_cvt_f16_f32(also withdiv:2),v_cvt_f16_u16, f16 add and mul, f16 mul, fma and rcp withmul:2, f16 exp, log, rcp, rsqDX10_CLAMPv_sqrt_f16 clamp mul:2Not measurable here: FmaRounding columns 4 to 7 and 9 and Float16Misc column 10, whose instructions exist only on gfx10.1; Float16Misc word 36 decodes as
v_mac_legacy_f32on gfx1013 and as the fusedv_fmac_legacy_f32on gfx1036, so its column is excluded. Over both passes: 330 asserted cells in 13 tests whose pinned value is theIEEE_MODE=1result or, in F64Rounding, the ignored output modifier, and 50 Vop3PackLdexp cells of an opcode the oracle cannot run. The adapters, the driver, every run's body and raw output, the per-cell data and the listings for both passes are on a data branch of the fork: https://github.com/SleglJan/AnyPS5/tree/audit/oracle-2026-10-08/oracle-audit.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T07:04:11Z.
Data for "only ops whose result we know depends on the mode will throw": which ALU ops change with the
FLOAT_MODErounding bits. Measured on 2026-10-09 withtools/hw-oracleon a Radeon 610M (gfx1036, RDNA2), every control explicit (IEEE 0, DX10_CLAMP 1, f32 denormals flushed, f16/f64 kept), each case run in round to nearest and in the three other modes, and compared withmainf1451396on NVIDIA (615.71.09) and RADV (Mesa 26.2.4). On every row below both drivers give the round-to-nearest result, so the lowering ignores the mode, not the driver.v_add/sub/mul/fma_f32and their fmac/fmaak/fmamk forms,v_fma_mix_f32v_add_f3292 / 35 / 41 of 576,v_fma_f32199 / 162 / 135 of 2,744add(1, FLT_MAX)+inf:7f800000,7f7fffffv_cvt_f32_i32/u32/f64v_cvt_f32_f6414 / 14 / 18 of 32cvt_f32_u32(0x7fffffff)zero:4effffff,4f000000v_cvt_f16_f32/i16/u16v_cvt_f16_f3231 / 31 / 32 of 72cvt_f16_f32(FLT_MAX)zero:7bff,7c00v_add/mul/fma/ldexp_f64v_add_f64118 / 59 / 61 of 625add_f64(1, 1/3)+inf:3ff55555_55555556,..._55555555v_add/sub/mul/fma_f16,v_fma_mixlo/hi_f16,v_ldexp_f16,v_div_fixup_f16v_fma_f16241 / 110 / 122 of 2,221fma_f16(1, 1, 2^-24)+inf:3c01,3c00v_fract_f32/f16/f64v_fract_f325 / 2 / 2 of 72fract(-0.1)+inf:3f666667,3f666666v_cvt_pk_u8_f32cvt_pk_u8(1/3)+inf:00000001,00000000v_div_fixup/div_fmas/div_scale/mullit/cubema/ldexp_f32v_div_fmas_f32503 / 415 / 411 of 5,488div_fixup(inf, 1, 1)zero:7f7fffff,7f800000Packed f16 (
v_pk_add/mul/fma_f16) also follows round16 on hardware, butmainalready refuses those shaders.v_pk_min/max_f16do not change with the rounding bits. Both drivers reportshaderRoundingModeRTZFloat32and Float64; NVIDIA lacksRTZFloat16. I can attach the raw rows per op if that helps the throw list.Imported from boykopovar/AnyPS5. Originally posted by iDiesIrae-Req on 2026-10-13T03:50:27Z.
A title that changes MODE at run time: vkQuake (PPSA99010, catalog homebrew, with the Quake shareware
id1/pak0.pak) on Windows,mainc13dc7e6b. In 7 of 9 runs on an RTX 4070 it aborts about 7 s into its first demo:The shader is produced at run time by the title's own RADV port (
radv/ps5, cache inapp0/radv-shader-cache), not shipped ineboot.bin. Mesa's ACO emitss_round_modewhen a shader needs a rounding mode other than the wave's initial one, so other titles built on that RADV port may reach this too. The other two runs stopped earlier on a GPU stall, so the stop is not deterministic.Details: https://github.com/boykopovar/AnyPS5/issues/1578.
Measured with Claude Code assistance.