Hello folks,
I need to write shaders that build per-pixel-linked lists, sort the lists (one list per pixel) and draw the result. This procedure is, in literature, known as ‘Order-Independent Transparency’.
My fragment shader that builds a list for the current pixel is:
in vec4 gl_FragCoord;
out vec4 out_col;
uniform layout(binding=0, r32i) coherent iimage2D head_buffer;
uniform layout(binding=1, r32i) coherent iimageBuffer next_buffer;
uniform layout(binding=2, rgba32f) coherent imageBuffer data_buffer;
uniform layout(binding=3, offset=0) atomic_uint ac;
void main()
{
int index = int(atomicCounterIncrement(ac));
if (index >= 1024 * 768 * 16) // this is the maximal number of elements in [head/next/data]_buffer
discard;
int indexOld = imageAtomicExchange(head_buffer, ivec2(gl_FragCoord.xy), index);
imageStore(next_buffer, index, ivec4(indexOld, 0, 0, 0));
float depth = gl_FragCoord.z;
imageStore(data_buffer, index, vec4(1.0, 1.0, 1.0, depth)); // test-wise only white pixel used for simplification
out_col = vec4(1.0, 1.0, 1.0, 1.0);
}
Actually some rather easy shader, but the performance is very poor. Executing the just shown shader needs around 120 ms. I would have expected much less!
My hardware is:
AMD Phenom 9650
4 GB DDR2 800 RAM
Palit GeForce GTX 460 with 768 MB VRAM
Ubuntu 14.04 LTS
nVidia binary driver 340.96
I tried out the never nVidia driver ‘352.63’, but that one is a catastrophe, my shader executes around two to three times slower on the newer nVidia driver.
I appreciate ANY comments, also critics - but please indulge me, I’m a beginner in what concerns GLSL