i965 sin/cos accuracy

Sometime last year while working on a project where I was developing software to reproject (lat/lon to stereographic, mercator etc...) GIS vector and raster data on the i965 GPU I found that the accuracy of sin/cos was insufficient.

Basically I needed at least 7 decimal places for float and significantly more for double.

Subsequently a patch appeared that provided a partial fix. The fix has a performance hit and has to be enabled using an environment variable:
  • INTEL_PRECISE_TRIG - if set to 1, true or yes, then the driver prefers accuracy over performance in trig functions.
This fix still did not give me sufficient accuracy and in anycase could not be ported to the version of Mesa we had to use.

The fix that I developed used min/max polynomial for sin along with range reduction and knowledge about cos relationship to sin. Invariably if you want sin you also want cos when performing a projection from lat/lon to stereographic/mercator or one of the many other coordinate system projections.

Contact me (damian.dixon 'replace-at-and-spaces' gmail.com) if you need additional information on how to do this or need help with FP64 emulation.


Comments