Computer Graphics Asked on August 27, 2021
is it worse to do for each invocation an atomicAdd on the same memory location than doing for each invocation an atomicAdd to a unique memory location? (I know, atomicAdd does not make sense when each invocation writes to another location… but this is theoretically)
I am asking, because I wrote the marching cubes algorithm and while creating the mesh I additionally want to calculate the center of mass as well.
I am doing this by having four integers in the SSBO (centerX, centerY, centerZ and countTriangles)
each of these 4 integers will be increased by the atomicAdd function within the GeometryShader.
When everything is done, I only need to divide the centerX/Y/Z variable by countTriangles and I am done.
if these atomics on one memory location would slow down my shader, I would outsource it to another maybe CPU function.
Thanks in advance
Will having all invocations incrementing the same atomic counter be slower than not doing that? Sure. How much slower? That depends on many factors, but it's hardly going to be a crippling performance issue.
The whole point of atomic memory operations is that there is some hardware mechanism that allows them to work reasonably efficiently. Not as efficiently as bumping a local variable of course, but they shouldn't be assumed to cause a massive performance penalty.
On some hardware, atomic counter operations aren't even memory operations. AMD implements them as specialized hardware within their shader system, such that atomic counter operations don't touch actual memory storage until after the rendering process that uses them is complete.
Obviously, the best thing you can do is profile on your hardware-of-choice, but failing that, I would see no reason not to use this mechanism as you see fit.
Correct answer by Nicol Bolas on August 27, 2021
0 Asked on August 27, 2021 by b1skit
1 Asked on August 27, 2021 by emil-kabirov
1 Asked on August 27, 2021 by makogan
1 Asked on March 3, 2021 by lucio-coire-galibone
2 Asked on February 10, 2021
2 Asked on January 29, 2021 by adrian
0 Asked on January 5, 2021 by bisma
0 Asked on January 2, 2021 by weichsem
2 Asked on August 12, 2020 by jheindel
0 Asked on July 23, 2020 by przemek-b
Get help from others!