openglsuperbible / sb7code

Source code and supporting material for the 7th Edition of OpenGL SuperBible
727 stars 251 forks source link

Possible bug in prefixsum.cs.glsl file #38

Closed PrzemyslawSagalo closed 2 years ago

PrzemyslawSagalo commented 5 years ago

Hi!

Could you check prefixsum.cs.glsl shader. There could be a bug in the line 32. There is step < steps and I think it should be step <= steps, because in the first version it doesn't calculate the last step.

coding-001 commented 4 years ago

There is no bugs.

gl_WorkGroupSize.x = 1024
NUM_ELEMENTS = 2048

We can simplify it to this (like the book Figure 10.5):

gl_WorkGroupSize.x = 8
NUM_ELEMENTS = 16
const uint steps = uint(log2(gl_WorkGroupSize.x)) + 1; ==> steps = uint(log2(8)) + 1 = 3 + 1 = 4

So you need 4 steps, like what Figure 10.5 say. You will loop 5 times if you change to <=.