Why do GLSL arithmetic functions give different results on an iPad than on a simulator?

I am currently pursuing some bugs in my shader code for the OpenGL ES 2.0 fragment that works on iOS devices. The code works fine in the simulator, but it has huge problems on the iPad, and some of the calculations give completely different results, for example, I had t20> on the iPad and 4013.17 on the simulator, so I'm not talking about small differences that may be the result of some rounding errors.

One of the things that I noticed is that on the iPad,

 float1 = pow(float2, 2.0); 

can give results that are very different from the results

 float1 = float2 * float2; 

In particular, when using pow(x, 2.0) for a variable containing a larger negative number, for example -8 , it returned a value that met the condition if (powResult <= 0.0) .

In addition, the result of both operations ( pow(x, 2.0) , as well as x*x ) gives different results in the simulator than on the iPad.

The floats used are mediump , but I get the same with highp .

Is there a simple explanation for these differences?

I judge the problem, but it takes a lot of time, so maybe someone can help me here with a simple explanation.

+6
source share
3 answers

GLSL ES documentation says pow is undefined if x <0 or if x = 0 and y ≤ 0.

+15
source

The simulator uses x86 floating point numerical libraries and Mac OS X numerical libraries. The iPad uses either the ARM FPU.

Also, pow () is a library that uses an approximation algorithm.

+1
source

GLSL pow implements the function exp2 and exp2 . Since the logarithm function is not defined for negative real numbers, pow() also not.

See GLSL ES 3.0 Specification , or GLSL Specification 4.4 p. 88.

pow (x, y) Inherited from exp2 (x * log2 (y))

Also from the specification:

genType pow (genType x, genType y)

  • Returns x raised in y, i.e. x ^ y
  • The results are undefined if x <0.
  • The results are undefined if x = 0 and y <= 0.
+1
source

Source: https://habr.com/ru/post/924315/


All Articles