Skip to content

Compile with -ffast-math

Hanicef requested to merge Hanicef/SRB2:compile-ffast-math into next

One thing that has been bothering me for a long time is why the OpenGL renderer performs so badly in comparison to software, despite being built specifically for rendering graphics. While I'm not really an expert on the GPU or it's inner workings, I do know it works a lot with floating-point values, and it wasn't until today where it struck me that this is actually a problem.

In a nutshell, the C standard is actually really strict on what is allowed on floating-point mathematics, so much in fact that it basically renders optimizations on it nearly impossible (which is ironic since they love to abuse everything else in the name of undefined behavior). For this reason, C compilers often provide flags that allow them to violate the C standard to be able to optimize floating-point more aggressively. These flags can make a big difference, especially for applications like games where inaccuracies in calculations in exchange for performance is acceptable.

So, I decided to plop in -ffast-math into the compiler flags and got these results:

Before: srb20012

After: srb20011

It's not a massive difference, but it's a significant improvement in performance. Part of this is due to SRB2's heavy reliance on fixed-point, which is unaffected by floating-point optimizations; if SRB2 used floating-point more, it would've had a greater impact on performance. In addition, the performance gains seem to have no noticeable impact on software, primarily due to most of the floating-point arithmetic in SRB2 being isolated within the OpenGL parts of the code.

Merge request reports

Loading