Search code examples
openglglsl

Max image units in GLSL


I'm trying to define this image2D variable in my compute shader, in order to store some data needed for future rendering:

layout ( binding = 8, rgba32f) writeonly uniform image2D MyTexture ;

However, this somehow seems not be able to work, since when I compile this shader, it gives me the following error information:

Error: image binding must be less than "GL_MAX_IMAGE_UNITS" (8)

I did already defined 8 image2D textures in previous codes. It seems like there are not enough GL_IMAGE_UNIT slots on my graphics card (I'm actually using a core graphics card Intel(R) HD Graphics 620 on my computer). How I'm I supposed to fix this? Are there any way to avoid using the 8th image unit? Or I have to move to another computer to finish my work, which will be really troublesome :(


Solution

  • Use one image2DArray instead of multiple image2D. For an image2DArray you need 1 image unit. The image2DArray can contain multiple layers of 2D images of the same size and format. Therefore, you can reduce the number of image units used by bundling multiple two-dimensional images into a two-dimensional image array.