I'm writing a framework which needs to offer a few functions defined on the image2D type.
But it seems a bit difficult to get this right and I can't find any documentation on passing an image2D
to a function.
Here is a minimal example of my problem:
#version 440
layout (local_size_x = 16, local_size_y = 16) in;
struct Test
{
bool empty;
};
// Version 1:
// fails with 0:11: '' : imageLoad function cannot access the image defined
// without layout format qualifier or with writeonly memory qualifier
float kernel1(image2D x, Test arg1){
return imageLoad(x, ivec2(1, 1)).x;
}
// Version 2:
// fails with ERROR: 0:16: 'Test' : syntax error syntax error
// doesn't fail without the Test struct at second argument
float kernel2(layout (r32f) image2D x, Test arg2){
return imageLoad(x, ivec2(1, 1)).x;
}
layout (binding=0, r32f) readonly uniform image2D globalvar_A;
const Test globalvar_f = Test(false);
void main(){
// works when other function are commented out
imageLoad(globalvar_A, ivec2(1, 1)).x;
//kernel1(globalvar_A, globalvar_f);
//kernel2(globalvar_A, globalvar_f);
}
This fails on my intel onboard (hd4400) windows 10.
A more complex version generates a no overloaded function found
error when calling the function.
On nvidia hardware I got around this by typing img
with image2D1x32_bindless
, but that seems to be undocumented nvidia specific name wrangling.
Can anyone point me into the right direction with this seemingly simple task?
Update:
I took an example directly from the GLSL 4.3 specs, section 4.10:
#version 430
layout (local_size_x = 16, local_size_y = 16) in;
// this works fine without the imageLoad
vec4 funcA(restrict image2D a){ return imageLoad(a, ivec2(1, 1));}
layout(rgba32f) coherent uniform image2D img2;
void main(){
funcA(img1); // OK, adding "restrict" is allowed
}
and get imageLoad function cannot access the image defined without layout format qualifier.
Which I can get rid of with adding: layout(rgba32f)
.
But then I can't pass additional structs to that function, because it results in a syntax error.
So I can conclude:
for imageLoad
you must have an image with layout qualifier,
but declaring this for a function argument is broken/ ill defined.
A parser error is very likely, since inbuilt types work, which indicate more robust parser support for those.