I want to access atomic counter value in my code. My shader is
#version 430
#extension GL_EXT_compute_shader : enable
layout (local_size_x = 16, local_size_y = 16) in;
layout (binding = 0) uniform atomic_uint atRed;
layout(std140,binding = 0) buffer myBuffer
{
uint red;
uint inc_red;
}g_out;
void main() {
g_out.inc_red=0;
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.inc_red+=atomicCounterIncrement(atRed);
g_out.red=atomicCounterIncrement(atRed);
}
In my access i am accessing these values using following code
GLuint* counter=NULL;
glGenBuffers(1, &shaderStorageBufferID);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBufferID);
glBufferData(GL_SHADER_STORAGE_BUFFER, 2*sizeof(GLuint), NULL ,GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0,shaderStorageBufferID );
glUseProgram(tdk_ShaderObject.cpsId);
glDispatchCompute(16,16,1);
counter = (GLuint*) glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0,2*sizeof(GLuint), GL_MAP_READ_BIT );
printf("counter %d %d",*counter,*(counter+1));
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
It is giving counter values as 0 0.
Is there anything wrong in above code?