[GLSL 420] Problem with imageLoad and imageStore functions

Hi, I’m trying to store the z and the colors of every fragments in a 2D image array, to sort my fragments and applying the alpha blending in this order : bottom to top layer.

So the code looks lile this :


#version 420 core
#extension GL_EXT_shader_image_load_store : enable
uniform layout(size1x32) uimage2D abufferCounterImg;
uniform layout(size1x32) image2DArray adepthbufferImg;
uniform layout(size4x32) image2DArray abufferImg;
inout vec4 color;
vec4 backgroundColor = vec4(0, 0, 0, 1);
void main() {	
	ivec2 coords = ivec2 (gl_FragCoord.xy);
        float z = gl_FragCoord.z;
        int nbFrag = int(imageLoad(abufferCounterImg, coords).r);
        int fragPos = 0;        
        while (fragPos < nbFrag && z >= imageLoad(adepthbufferImg, vec3(coords, fragPos)).r)
		fragPos++;
	int i = nbFrag;
	while(i > fragPos) {
		float adepthbuffervalue = imageLoad(adepthbufferImg, vec3(coords, i-1)).r;
		vec4 abuffervalue = imageLoad(abufferImg, vec3(coords, i-1));
		imageStore(adepthbufferImg, vec3(coords, i), adepthbuffervalue);
		imageStore(abufferImg, vec3(coords, i), abuffervalue);
		i--;
	}	
	imageStore(adepthbufferImg, vec3(coords, fragPos), z); 
    	imageStore(abufferImg, vec3(coords, fragPos), color);
	nbFrag++;
	imageStore(abufferCounterImg, coords, nbFrag);
	vec4 finalColor = backgroundColor;
	for (i = 0; i < nbFrag; i++) {
            vec4 currentColor = imageLoad(abufferImg, vec3(coords, i));
            finalColor = currentColor * currentColor.a + finalColor * (1 - currentColor.a);
	}
	color = finalColor;
}

But I’v a bunch of errors that tells me that the functions imageLoad and imageStore doesn’t exists :

error(#202) No matching overload function found imageLoad.
error(#202) No matching overload function found imageStore.

I really don’t understand, I’m sure my driver support opengl 4.2 (AMD drivers on windows) and my image’s declarations are correct so why he can’t find the corresponding function ?

No, it’s telling you that the specific overloads which you’re trying to use don’t exist. The only imageLoad() overloads which accept an image2DArray parameter take an ivec3 parameter for the coordinates, but you’re passing a vec3. Similarly for imageStore().

Ok, I’ve corrected the code so and now it’s ok. :slight_smile:
There is only overload function to write vec4 with imageStore.


#version 420 core
#extension GL_EXT_shader_image_load_store : enable
uniform layout(size1x32) uimage2D abufferCounterImg;
uniform layout(size1x32) image2DArray adepthbufferImg;
uniform layout(size4x32) image2DArray abufferImg;
out vec4 color;
vec4 backgroundColor = vec4(0, 0, 0, 1);
void main() {	
	ivec2 coords = ivec2 (gl_FragCoord.xy);
        float z = gl_FragCoord.z;
        int nbFrag = int(imageLoad(abufferCounterImg, coords).r);
        int fragPos = 0;        
        while (fragPos < nbFrag && z >= imageLoad(adepthbufferImg, ivec3(coords, fragPos)).r)
		fragPos++;
	int i = nbFrag;
	while(i > fragPos) {
		float adepthbuffervalue = imageLoad(adepthbufferImg, ivec3(coords, i-1)).r;
		vec4 abuffervalue = imageLoad(abufferImg, ivec3(coords, i-1));
		imageStore(adepthbufferImg, ivec3(coords, i), vec4(adepthbuffervalue, 0, 0, 0));
		imageStore(abufferImg, ivec3(coords, i), abuffervalue);
		i--;
	}	
	imageStore(adepthbufferImg, ivec3(coords, fragPos), vec4(z, 0, 0, 0)); 
    	imageStore(abufferImg, ivec3(coords, fragPos), vec4(1, 0, 0, 1));
	nbFrag++;
	imageStore(abufferCounterImg, coords, ivec4(nbFrag, 0, 0, 0));
	vec4 finalColor = backgroundColor;
	for (i = 0; i < nbFrag; i++) {
            vec4 currentColor = imageLoad(abufferImg, ivec3(coords, i));
            finalColor = currentColor * currentColor.a + finalColor * (1 - currentColor.a);
	}
	color = finalColor;
}

For imageStore(), the type of the [var]data[/var] argument (the value to be written to the image) is related to the image type: vec4 for an image2D, ivec4 for an iimage2D, uvec4 for a uimage2D, etc.

For imageLoad(), the return type is similarly related to the image type (but unlike parameter types, the return type doesn’t affect overload selection).

For both imageLoad() and imageStore(), the coordinates are always integers (int, ivec2, or ivec3).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.