I am attempting to run a compute shader, but cannot get any evidence that it activates.
To debug it, I am attempting to write to a texture image. I am using nvidia 32 bit driver 330.41
The compute shader source is:
#version 440
layout( local_size_x = 16, local_size_y = 16) in;
layout (rgba8ui, binding=3) uniform uimage2D debugTex;
void main()
{
ivec2 texelcoords_2d = ivec2(gl_GlobalInvocationID.xy);
uvec4 pixel;
pixel = ivec4(0x60,0x71,0x52,0x7f);
imageStore(debugTex, texelcoords_2d, pixel);
}
To compile it:
p->fb_copy_shader_prog = glCreateShaderProgramv(GL_COMPUTE_SHADER, 1,
(const GLchar **)&shader_src);
assert(p->fb_copy_shader_prog);
free(shader_src);
glGetProgramiv(p->fb_copy_shader_prog, GL_LINK_STATUS, &status);
if(!status)
{
/* report error and exit. */
}
glGetProgramiv(p->fb_copy_shader_prog, GL_COMPUTE_WORK_GROUP_SIZE, p->work_group_size);
check_opengl_errors();
Create a debug texture for it to write to.
glGenTextures(1, (GLuint *)&p->debug_texture);
glBindTexture(GL_TEXTURE_2D, p->debug_texture);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8UI, p->glv.width, p->glv.height);
{
int i;for(i = 0; i < length/4;i++)((int *)(p->debug_buffer))[i] = 0xdeadbeef;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, p->glv.width,p->glv.height, GL_RGBA_INTEGER_EXT,
GL_UNSIGNED_INT_8_8_8_8, p->debug_buffer);
}
glBindTexture(GL_TEXTURE_2D, 0);
check_opengl_errors();
Run the shader at a certain point in the render cycle.
glUseProgram(p->fb_copy_shader_prog);
glBindImageTexture(3, p->debug_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8UI);
glDispatchCompute(p->width/p->work_group_size[0], p->height/p->work_group_size[1], 1);
glUseProgram(0);
p->fbcapture_complete = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
Then sometime later, after bufferswap and more rendering,
GLenum rtn;
rtn = glClientWaitSync(p->fbcapture_complete, GL_SYNC_FLUSH_COMMANDS_BIT, 50*1000000);
assert(rtn != GL_WAIT_FAILED);
assert(rtn != GL_TIMEOUT_EXPIRED);
glMemoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
glBindTexture(GL_TEXTURE_2D, p->debug_texture);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT_8_8_8_8, p->debug_buffer);
glBindTexture(GL_TEXTURE_2D, 0);
The data in the p->debug_buffer array is no different to what was written at texture creation time. I would like it to be the constant value set in the shader program, to prove that it is actually running, so I can start developing what I wish it to do.
If any kind person can point out errors or lines of attack, would be grateful.