KhronosGroup / OpenGL-Registry

OpenGL, OpenGL ES, and OpenGL ES-SC API and Extension Registry
689 stars 275 forks source link

Min/Max function changes lower bits of float mantissa in shaders #553

Closed chiraagChakravarthy closed 1 year ago

chiraagChakravarthy commented 1 year ago

glsl version: 330 lwjgl version: 4.5 gpu: Intel HD Graphics 6000 1536 MB os: macOS Sierra 10.12.6

When using the min/max function in a shader, the lower bits of the mantissa changes and creates artifacts in rare cases, but when using the mix function in a similar way it doesn't.

float a = (some value);
float b = (some value);
float c = min(a, b);
float d = mix(a, b, b<a);
//in some cases c!=d

In the example above, when c and d are different, d is correct and c is slightly off.

NogginBops commented 1 year ago

The specification defines this quite clearly in the glsl 3.30 spec (section 8.3):

min(x, y)        Returns y if y < x, otherwise it returns x.

So this seems like a bug in the macos/intel driver. Not sure if apple is still fixing issues in their OpenGL implementation so it might be hard to get them to fix the issue.

pdaniell-nv commented 1 year ago

Since this is an implementation bug, and no OpenGL/ES spec change is needed, closing.