0

In my compute shader i try to calculate the texel coordinate of each local invocation based on the gl_GlobalInvocation variable inside a rectangle of my image. For large values of gl_GlobalInvocation.x up to 262144 i get strange results. (gl_WorkGroupSize=1024 (1024,1,1), gl_NumWorkGroups=256 (256,1,1), width <= 512, height <= 512) Maybe its because glsl modulo cannot handle uint datatypes in OpenGL ES 3.1.

Is there alternative way to calc coordinates for uint range?

ivec2 coords;
uint width = uint(rectPos.z-rectPos.x); 
uint height = uint(rectPos.w-rectPos.y);
coords.x = int(gl_GlobalInvocationID.x % width) + rectPos.x;
coords.y = int(gl_GlobalInvocationID.x / height) + rectPos.y;
... 
vec4 color = imageLoad(texture, coords)
...
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Meldryt
  • 99
  • 1
  • 9
  • this is fragment or vertex or different shader? I occasionaly hit a wall when some math functions does not work correctly outside fragment shader ... for example I once had `floor` not working in vertex shader but computing fine in fragment ... and I beleave `%` did similar havoc when I was trying to use it instead of floor to do the same ... – Spektre Sep 11 '19 at 11:51
  • 1
    @Spektre: I assume it is a compute shader. – BDL Sep 11 '19 at 11:57
  • @BDL hmm never used those so I am in dark if the case ... its worth trying to output some results for constant like `12345%123` etc ... if it computes what it should ... but how to output is a question (texture maybe?) in fragment I usually use this [GLSL debug prints](https://stackoverflow.com/a/44797902/2521214) – Spektre Sep 11 '19 at 11:59
  • @Meldryt: What exactly are you trying to compute? Are you just using 1D sizes (1024x1x1)? What is the value of width? What are the results you are getting? – BDL Sep 11 '19 at 12:01
  • 1
    yes its a compute shader. i load the pixel color with imageLoad(texture, coords). i do this for two textures and compare the color. if the color is different i increment a counter (atomic counter). – Meldryt Sep 11 '19 at 12:42
  • Are you using highp or mediump? – Andrea Dec 05 '19 at 21:11
  • I ask because I think with typical 16-bit implementations, mediump floats and ints can't represent 262144 – Andrea Dec 06 '19 at 18:18

0 Answers0