Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the precision of highp floats in GLSL ES 2.0 (for iPhone/iPod touch/iPad)?

I have a shader that ideally needs 28 bits of mantissa, though I can use less and degrade performance. How can I determine what the precision of 'highp' is in OpenGL ES? It's probably an FP24, with 16bits mantissa, but I cannot figure out for sure or how to ask OpenGL. Any ideas?

like image 214
gonzojive Avatar asked Dec 10 '10 22:12

gonzojive


3 Answers

From the OpenGL ES Shading Language reference:

  • highp - 16-bit, floating point range: -2^62 to 2^62, integer range: -2^16 to 2^16
  • mediump - 10 bit, floating point range: -2^14 to 2^14, integer range: -2^10 to 2^10
  • lowp - 8 bit, floating point range: -2 to 2, integer range: -2^8 to 2^8
like image 131
Brad Larson Avatar answered Nov 11 '22 07:11

Brad Larson


In my testing on my line of expensive toys:

For both ints and floats, the precisions and ranges across fragment and vertex shaders are the same.

So I will not list all combinations exhaustively.

Also note that precision of ints is defined to be always 0.

PowerVR SGX543MP3 (iPhone 5):

  • Floats
    • Low: precision = 8, range = 0 to 0 (Not sure, but I think this means that we cannot expect a lowp to actually be able to represent a value reaching exactly 2 or -2, I don't really know of a great way to test this, nor should we over-concern ourselves with these limitations, just use mediump when this could ever be an issue)
    • Medium: precision = 10, range = 15 to 15 (meets spec)
    • High: precision = 23, range = 127 to 127 (exceeds spec)
  • Ints
    • Low: range = 23 to 23 (exceeds spec)
    • Medium: range = 23 to 23 (exceeds spec)
    • High: range = 23 to 23 (exceeds spec)

A7 & PowerVR G6430 (iPad Air):

  • Floats
    • Low: precision = 10, range = 15 to 15 (exceeds spec)
    • Medium: precision = 10, range = 15 to 15 (meets spec)
    • High: precision = 23, range = 127 to 127 (exceeds ES 2.0 spec, meets 3.0 spec)
  • Ints
    • Low: range = 15 to 14 (exceeds spec)
    • Medium: range = 15 to 14 (exceeds ES 2.0 spec, meets ES 3.0 spec)
    • High: range = 31 to 30 (exceeds ES 2.0 spec, meets ES 3.0 spec)

A8 & PowerVR GX6450 (iPhone 6 Plus):

  • Floats
    • Low: precision = 10, range = 15 to 15 (exceeds spec)
    • Medium: precision = 10, range = 15 to 15 (meets spec)
    • High: precision = 23, range = 127 to 127 (exceeds ES 2.0 spec, meets 3.0 spec)
  • Ints
    • Low: range = 15 to 14 (exceeds spec)
    • Medium: range = 15 to 14 (exceeds ES 2.0 spec, meets ES 3.0 spec)
    • High: range = 31 to 30 (exceeds ES 2.0 spec, meets ES 3.0 spec)

Here is an example of how you might query the values.

int range[2], precision;
glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, range, &precision);
NSLog(@"Fragment shader high precision float range: %d %d precision: %d", range[0], range[1], precision);
glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, range, &precision);
NSLog(@"Fragment shader medium precision float range: %d %d precision: %d", range[0], range[1], precision);
glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_LOW_FLOAT, range, &precision);
NSLog(@"Fragment shader low precision float range: %d %d precision: %d", range[0], range[1], precision);

glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_INT, range, &precision);
NSLog(@"Fragment shader high precision int range: %d %d precision: %d", range[0], range[1], precision);
glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_MEDIUM_INT, range, &precision);
NSLog(@"Fragment shader medium precision int range: %d %d precision: %d", range[0], range[1], precision);
glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_LOW_INT, range, &precision);
NSLog(@"Fragment shader low precision int range: %d %d precision: %d", range[0], range[1], precision);

glGetShaderPrecisionFormat(GL_VERTEX_SHADER, GL_HIGH_FLOAT, range, &precision);
NSLog(@"Vertex shader high precision float range: %d %d precision: %d", range[0], range[1], precision);
glGetShaderPrecisionFormat(GL_VERTEX_SHADER, GL_MEDIUM_FLOAT, range, &precision);
NSLog(@"Vertex shader medium precision float range: %d %d precision: %d", range[0], range[1], precision);
glGetShaderPrecisionFormat(GL_VERTEX_SHADER, GL_LOW_FLOAT, range, &precision);
NSLog(@"Vertex shader low precision float range: %d %d precision: %d", range[0], range[1], precision);

glGetShaderPrecisionFormat(GL_VERTEX_SHADER, GL_HIGH_INT, range, &precision);
NSLog(@"Vertex shader high precision int range: %d %d precision: %d", range[0], range[1], precision);
glGetShaderPrecisionFormat(GL_VERTEX_SHADER, GL_MEDIUM_INT, range, &precision);
NSLog(@"Vertex shader medium precision int range: %d %d precision: %d", range[0], range[1], precision);
glGetShaderPrecisionFormat(GL_VERTEX_SHADER, GL_LOW_INT, range, &precision);
NSLog(@"Vertex shader low precision int range: %d %d precision: %d", range[0], range[1], precision);

It is not clear to me yet whether you can expect tangible performance improvements by choosing a lower-precision type (Even on some phones that are now 3 years old).

It's clear that the trend is towards convergence with desktop hardware as it can be seen that the recent GPU's have completely eliminated the 8 bit types and are recycling the mediump ones for lowp.

like image 17
Steven Lu Avatar answered Nov 11 '22 06:11

Steven Lu


You want GetShaderPrecisionFormat to query the range and precision of of shader types

int range[2], precision;
glGetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, range, &precision);

will give you the range and precision of highp float.

like image 13
Chris Dodd Avatar answered Nov 11 '22 06:11

Chris Dodd