computeShader2DExecuteSize

Determines optimal size of ComputeShader execution for 2-dimensional data of variable size.

Note: if the data size is not dividable by the work group size, the excessive invocations will happen and must be discarded in the compute shader:

#version 430
layout (local_size_x = 8, local_size_y = 8) in;

uniform ivec2 p_dataSize;

void main() {
ivec2 coord = int(gl_GlobalInvocationID.xy);
if (coord.x >= p_dataSize.x || coord.y >= p_dataSize.y) {
return;
}
// shader code
}

Parameters

workGroupSize

the work group size, where the x and y components should be the same as local_size_x and local_size_y respectively, as specified in the shader.

dataSize

the size of the data to process.