Jump to content
  • Advertisement

Compute shaders on images, confused

Recommended Posts

I'm a bit overwhelmed learning this stuff, but i was looking at a piece of code and was super confused how the compute shader was executing over the data.

On the CPU side they had:

	public void render()
		glBindImageTexture(0, texture.getHandle(), 0, false, 0, GL_WRITE_ONLY, GL_RGBA32F);

Then the compute shader in simple terms has:

void main(void)
	vec2 x = gl_GlobalInvocationID.xy;
    imageStore(texture, ivec2(x),vec4(0,1,0.25,1) );

So how does the compute shader know how many invocation Ids to run for this image? Does it just instinctively know that it has to do it for the full image dimensions ? But if that is true what if you had multiple images ? Does it just then go up to what ever the largest image is... but that would then cause accessing invalid pixels on smaller images...

What if you only wanted the top quarter of the image to change... i am very confused how the Global ID is working here to coincide with image pixels.

In short is the vector2 ranging from [0,0] to [imageWidth-1, imageHeight-1] ? If not how are they informing the compute shader how many pixels to process on the image?

Hope you can clear up my confusions here, thanks.

Share this post

Link to post
Share on other sites

The work group size will be defined in the compute shader itself, something like this:

layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;

Then the dispatch call from C/C++ has this prototype:

void glDispatchCompute(GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z);

So when you call the dispatch function, it will make 'num_groups_x * num_groups_y * num_groups_z' groups, and the size of the group (number of threads) is 'local_size_x * local_size_y * local_size_z'.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!