PDA

View Full Version : program crash in combination with compute shaders



gemsenhuber
07-09-2013, 07:24 AM
I'm playing around with compute shaders for the first time. basically, i need to calculate a texture inside a compute shader via imageStore and then display it - which sounds simple enough, yet my program crashes and I can't seem to figure out the reason for it.

the rendering code:


// compute shader pass - fills the texture
// work groups: 32 x 32, work group size: 16 x 16 -> 512 x 512 texture

glBindImageTexture( 0, tex, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F );

glUseProgram( storeProg );
glUniform1f( glGetUniformLocation( storeProg, "val" ), 0.5f );
glDispatchCompute( 32, 32, 1 );
glUseProgram( 0 );

glBindImageTexture( 0, 0, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F );

glMemoryBarrier( GL_TEXTURE_FETCH_BARRIER_BIT );

// render pass - draws fullscreen quad

glBindTexture( GL_TEXTURE_2D, tex );

glUseProgram( renderProg );
glBindBuffer( GL_ARRAY_BUFFER, vbo );
glEnableVertexAttribArray( 0 );
glVertexAttribPointer( 0, 2, GL_FLOAT, false, 2*sizeof( float ), nullptr );
glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glDisableVertexAttribArray( 0 );
glUseProgram( 0 );

glBindTexture( GL_TEXTURE_2D, 0 );

the involved shaders are straight-forward as well:

compute shader:


#version 420 core
#extension GL_ARB_compute_shader : require

layout ( binding = 0, rgba32f ) writeonly image2D img;
uniform float val = 0.0;
layout ( local_size_x = 16, local_size_y = 16 ) in;
void main()
{

imageStore( img, ivec2( gl_GlobalInvocationID.xy, vec4( val ) );
}

render pass vertex & fragment shader:


#version 330 core

layout ( location = 0 ) in vec2 position;
out vec2 uv;
void main()
{

uv = 0.5 * position.xy + vec2( 0.5 );
gl_Position = vec4( position, 0.0, 1.0 );
}

#version 330 core

in vec2 uv;
out vec4 fragColor;
layout ( binding = 0 ) uniform sampler2D tex;
void main()
{

fragColor = texture( tex, uv );
}

what's puzzling me the most is that swapping the ordering of rendering pass & compute shader pass removes the crash - so it probably has something to do with synchronization that I'm unaware of; yet changing the memory barrier to GL_ALL_BARRIER_BITS does not help me at all.
the whole program code can also be seen here: https://www.dropbox.com/s/lo2admvuexz4rpm/main.cpp

Sc4v0r
08-06-2013, 01:52 AM
Hey,

your code seems to be alright for me. How does your program crash? Which GPU are you using?
I had some very strange issues using an amd hd 5800 and compute shaders. Switching to a nvidia card did the job :-D

Greets