fix(shader): give f16 and f64 output modifiers +0 for a zero or denormal result #18313
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18313"
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 angrysandhill on 2026-11-11T06:49:14Z.
What
When an output modifier (
mul:2,mul:4,div:2) applies, which is with IEEE mode off and output denormals of the result's precision flushed, the hardware gives +0 for a zero or denormal result. The f32 path already does this. The f16 and f64 paths kept the result's sign instead, so for example-0 + -0withmul:2gave-0.The shader debt list called this unmeasured: "flushing a denormal to a signed zero (the f32 path gives +0) … remain unmeasured".
The change:
scaleF16Result,scaleF16BitsandscaleF64Result: a zero or denormal result now becomes+0in all three, as inscaleF32Result.div:2: where it takes a normal result below the smallest normal, the result still keeps its sign, as measured. Only that rule's zero-or-denormal branch changes.vector_half_double_output_modifiers: it asserted the old sign-keeping select. Its three checks now require the+0select.Tested
Setup: Windows 10 Home 22H2 (10.0.19045), AMD Radeon RX 6750 XT (gfx1031), AMD Software Adrenalin 26.10.1 (driver 32.0.21045.16010), WinLibs GCC 15.2.0 r7 UCRT, Release,
BUILD_TESTING=ON. Tested onmainbb520eba29. The branch is rebased onto774111474c, whose only new commit toucheslibSceNKWebKit.Hardware (hardware oracle, HIP runtime).
v_add_f16_e64,v_add_f32_e64andv_add_f64, each withmul:2,mul:4anddiv:2.v_add_f16goes throughscaleF16Result.scaleF16Bitsis reached byv_max_f16,v_min_f16andv_ldexp_f16, sov_max_f16_e64,v_min_f16_e64andv_ldexp_f16_e64were measured too. They use the same f16 operands (exponent 0 forv_ldexp_f16) and the same modes, with each modifier and without one.+0 + -0,-0 + -0,1 + -1), ±the smallest denormal, ±the smallest normal, values whosediv:2underflows, ±near-max values that overflow, ±infinity, NaNs and ±1.Results, against the recompiler on
mainwithHW_ORACLE_RUNTIME=vulkan:mul:2,mul:4,div:2-0 + -0and-denormal + -0, hardware+0, recompiler-0v_max_f168,v_min_f163,v_ldexp_f162 of 20; each is hardware+0, recompiler-0With this change no row differs in any of these combinations. So on the hardware a zero or denormal result becomes
+0at all three widths and on the f16 bit path. A normal result thatdiv:2takes below the smallest normal keeps its sign; the recompiler already matched that at all three widths.Tests:
agc_driver_f16_f64_output_modifier_zero: the 20 rows each forv_add_f16andv_add_f64, run with each modifier in FLOAT_MODE0x00,0x50and0xf0(IEEE off). The expected values are the hardware's, except in the two f16 NaN rows (0x7e01 + 0and0xfe01 + 0), which need only a NaN in the low half sinced0a24a8f8c: scalarv_add_f16returns the NaN of the device's own add, and NVIDIA's is0x7fff.mainit fails:v_add_f16 mul:2 FLOAT_MODE 0x00000000: lane 1 word 0 is 0xabcd8000, expected 0xabcd0000(lane 1 is-0 + -0).d0a24a8f8cunder the validation layer (noVUID-line).d0a24a8f8c: ifscaleF16Resultscales a NaN instead of passing it through, the test fails on them:lane 15 word 0 is 0xabcd7c00, expected a NaN in the low half.vector_half_double_output_modifiers: with the updated checks it fails onmain("v_add_f16 mul:2 did not scale a zero or denormal result to +0") and passes with this change.^(agc_|shader|vector_), 4 at a time: 1,612 tests: 1,594 passed, 17 skipped, 1 failed.main: the same run onmain(1,611 tests) gives every test the same outcome. The only extra test is the new one, which passes.agc_driver_sample_order_grid_referencefails onmaintoo, with the same message ("the exact path did not render the checkerboard bit for bit like the reference"). It is the odd-row failure that #18229 reports on an RX 6700 XT (0 of 2048 odd-row samples at the guest's locations), which #9503 fixes.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, one test at a time, on 54 tests:-R "^(agc_driver_f16_f64_output_modifier_zero|vector_half_double_output_modifiers|agc_driver_.*(modifier|omod|float16|f64|fp16|fma|division).*|shader_.*modifier.*)$" -E fmask.VUID-on this change or onmain.agc_driver_float16_unused_nan_payloadsskips on both sides, because this device has no native f16 conversions with RTE rounding.Not measured: the PS5's gfx1013, and the ordering against the
FP16_OVFLclamp, which the debt note still lists.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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:43:50Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed scaling paths and their focused regression checks are consistent with the stated +0 behavior; I found no verified blocking defect.
What I ran
Reviewed head
6311ad351d30c25a10a8d954d9fa34a16ba10037against basemain. No commands or tests were run;repo_read.pywas used to inspect the prepared review material and repository files at the pinned head.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The new execution test was inspected only at its setup, checks, and dispatch loop; the rest of its full source and the other changed test/documentation files were not read. Runtime behavior, build integration, and the author-reported hardware and test results were not independently verified. The change is narrowly limited in the inspected translation functions, but this review is incomplete across the changed files, so approval is not justified.
Files read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch,core/shader/recompiler/Translation/src/Float64Instructions.cpp,core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp, and selected ranges ofcore/libs/tests/VectorHalfDoubleOutputModifiers.cppandcore/libs/prx/libSceAgcDriver/tests/execution/F16F64OutputModifierZero.cpp. The manifest lists four changed files; all are marked included, and none are listed as excluded.To get this to a good state
Nothing is required. Optional: complete review of the new execution test and remaining changed files, and run the relevant checks on this head.