fix(shader): take v_sin_f32 and v_cos_f32 from an exact series where the driver's result is more than 4 ulp off #3770
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3770"
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 A-Akhil on 2026-10-11T16:37:38Z.
What
agc_driver_sin_cos_near_zerofails on Intel UHD Graphics (CML GT2, Mesa 26.2.3) in every run:Lane 24 is 0.1 of a turn (sin 36°). It is outside the 2^-12 near-zero range that #2380 linearizes, so the result is the driver's
GLSLstd450Sin, 27 ulp from the hardware value on this GPU. The same failure was reported in a comment on #2114.This applies the scheme
EmitFPLog2already uses: keep the driver's value unless it is more than 4 ulp from an exact series, and take the series then.EmitTrigCycleF32is exact, so the reduction to [0, 1/8] of a turn uses only Sterbenz subtractions (0.5 - a, 0.25 - a), which are exact.SinTurnSeriesandCosTurnSeriesevaluate sin(2πx) and cos(2πx) as Taylor series in turns, with f32 coefficients of (2π)^n/n!, by FMA Horner steps marked NoContraction. Over [0, 1/8] they stay within 2 ulp (sin) and 1 ulp (cos) of the true value; at lane 24 the series gives 0x3f167918, 1 ulp from the hardware.Tested
Arch Linux (kernel 6.18.54-lts), GCC 16.2.1, Release,
BUILD_TESTING=ON,maina11c8f7f7. One laptop with two GPUs, picked withANYPS5_GPU: GeForce GTX 1650 Ti (NVIDIA 615.71.09) and Intel UHD (CML GT2, Mesa 26.2.3).mainagc_driver_sin_cos_near_zero, Intelagc_driver_sin_cos_near_zero, NVIDIAFull ctest, 832 tests per GPU, with and without the change:
agc_driver_sin_cos_near_zero, which now passes. The rest fail onmaintoo:agc_driver_emulated_color_compare(#3532),agc_driver_flat_storetimeout (#2972),agc_driver_gated_dispatch_captureand_short_timeout(#3345),agc_driver_vop1_float_unary(#2114).main; onlyagc_driver_emulated_color_compare(#3532).Windows and AMD: not tested.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:59:30Z.
Measured on the HW oracle (gfx1035, IEEE=0, f32 denormals flushed) over 243,092 inputs in [2^-13, 0.5] turns plus ±3000 ulp around 1/8, 1/4, 3/8, 1/2 and 0.1 and negatives: the series is within 2 ulp of the true sine/cosine (also with
Fmasplit into mul + add, which the spec allows), and the hardware itself is up to 9 ulp from it. With the series forced on every input and the tolerance ofagc_driver_sin_cos_near_zerocut to 1 ulp, the test passes on RADV and on CI's lavapipe (Mesa 25.2.8); both sin/cos tests pass unchanged on both.Added on your branch:
docs/dev/TechnicalDebt.md: the v_sin/v_cos line said the driver's value is always used; it now describes the series fallback and its bound (within 13 ulp of the hardware on any driver).Merging once CI is green.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T22:11:17Z.
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.
main)docs/dev/TechnicalDebt.mdL517-518