5

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.

Simon Danisch
  • 554
  • 3
  • 8
  • "*Spoiler: leaving away the layout and just typing img as image2D generates a no overloaded function found error when calling the function.*" We can't diagnose code that you haven't shown. And since `layout` qualifiers are *not* permitted in function declarations, you'll need to show us that version of the code before we can figure out the problem. – Nicol Bolas Feb 20 '17 at 20:04
  • thanks for the swift reply! I updated my question. – Simon Danisch Feb 20 '17 at 20:33
  • @NicolBolas: GLSLangSpec.4.50, *"it is a compile-time error to pass an image uniform or function parameter declared without a format layout qualifier to an image load or atomic function"* implies that layout qualifiers on function parameters are supposed to be allowed. They are allowed according to the grammar in chapter 9. Section 4.4 does not explicitly mention layout qualifiers in function declarations, but it doesn't prohibit them either. Looks like the 'Version 2' of OPs code was the intended way and it's rather an implementation bug. – Yakov Galka Feb 20 '17 at 21:41
  • @ybungalobill: And yet, section 6.1 of 4.50 says, "*Formal parameters can have parameter, precision, and memory qualifiers, but **no other qualifiers**.*" Layout qualifiers are not parameter, precision, or memory qualifiers. – Nicol Bolas Feb 20 '17 at 22:05
  • 3
    @NicolBolas: Hmm, then it's a bug in the spec... doesn't it make image parameters virtually unusable? – Yakov Galka Feb 20 '17 at 22:08
  • so... no passing of image2D to functions?? – Simon Danisch Feb 21 '17 at 15:32
  • I am seeing the same problem. I am passing an image2D to a function that performs image store and get this error: 'unable to find compatible overloaded function "imageAtomicAdd(struct iimage2D_bindless, ivec2, int)'. This is on Win32. The exact same code compiles OK on Linux as well as on GLES3.2. Wonders of OpenGL world always blow me away. – Egor Feb 19 '18 at 04:41

0 Answers0