There's more...

This is a straightforward example of the use of local shared memory. It is only slightly complicated by the fact that we need to deal with the extra row/column of pixels. In general, however, local shared data can be used for any type of communication between invocations within a work group. In this case, the data is not used for communication, but is instead used to increase efficiency by decreasing the global number of reads from the image.

Note that there are (sometimes stringent) limits on the size of shared memory. We can use GL_MAX_COMPUTE_SHARED_MEMORY_SIZE (via glGetInteger*) to query the maximum size available on the current hardware. The minimum required by the OpenGL specification is 32 KB.

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.