I have difficulty declaring a read-only image variable for the use with the EXT_shader_image_load_store extension.
My data is not aliased and read-only, so I am trying to tell this to the compiler in order to help him optimize my code (uncoherently reorder, cache, and coalesce all read operations).
According to the spec, the following should be legal and specify an image whose content is constant and read-only.
However, I get the following compiler error (GeForce 460, driver version 275.33):
error C7522: OpenGL requires constants to be initialized
Is this a bug in the nVidia compiler or did I miss something? Does anyone have experience with such an declaration with the AMD compiler?
The compiler seems to understand the restrict keyword which was introduced with the extension, so it is strange it does not understand the extended meaning of the const keyword.
From the EXT_shader_image_load_store extension docs, you can have the const before or after the image type, and it affects which data is const:
Memory accesses to image variables declared using the "const" storage qualifier may only read the underlying memory, which is treated as read-only. It is an error to pass an image variable qualified with "const" to imageStore() or imageAtomic*().
In image variable declarations, the "coherent", "volatile", "restrict", and "const" qualifiers can be positioned anywhere in the declaration, either before or after the data type of the variable being qualified. Qualifiers before the type name apply to the image data referenced by the image variable; qualifiers after the type name apply to the image variable itself. It is an error to specify "restrict" prior to the type name, as "restrict" can only qualify the image variable itself.
Since imageStore() and imageAtomic() throw errors on ‘const image variables’, it sounds like the const needs to come after the image type.
From the EXT_shader_image_load_store extension docs, you can have the const before or after the image type, and it affects which data is const
Yes, that’s why I need it to be before the variable. I want the content of the image to be constant, not the image handle. Of course, imageStore() will not work on such data, but I am only reading the image using imageLoad().
By the way, writing const after “image2D” generates the following two errors (again, with nVidia drivers):
error C7537: OpenGL does not allow 'const' after a type specifier
error C7522: OpenGL requires constants to be initialized