Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have I found an AMD GPU integer division bug?

I've narrowed my case down to this simple GLSL code:

uniform int zeroUniform; // Always set to zero, it is there so that the code is not optimized out
out int c;

int a = 8660165;
int b = 6;
c = (a + zeroUniform) / b;

When I put this in a shader and inspect the shader with RenderDoc, it says that c is 1443361! But it should be 1443360. What the hell is happening? In hex, 8660165 is 0x8424C5, so there's a whole one byte free before the sign bit could alter the calculations. Am I missing something or is this a GPU bug?

OpenGL 4.6 core, Tested on AMD RX 5700 XT. I've also tried using uint instead of int, which works correctly.

like image 912
Danol Avatar asked Jul 27 '26 11:07

Danol


1 Answers

The result of your division is 1443360.833333333

This spec https://www.khronos.org/registry/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf

On page 144 in the section "12.33 Rounding of Integer Division" it asks if integer division should round and the answer is "RESOLUTION: The rounding mode is undefined for this version of the specification."

So the results you are seeing certainly seems valid given that spec even if not the most useful.

That spec is for GLSL ES 3.00 which likely isn't what you are using but I can't find another spec right now that mentions this, but it seems an indication at least that your results are valid given the spec, even if not what you'd hope for

like image 169
jcoder Avatar answered Jul 30 '26 10:07

jcoder