PDA

View Full Version : EXT_shader_image_load_store and "const" keyword



RobertC
06-29-2011, 09:34 AM
Hi,

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.

layout(size4x32) const uniform image2D imageVariable;

I use the (almost) same definition in my shader:


#version 410
#extension GL_EXT_shader_image_load_store : require
#extension GL_ARB_gpu_shader5 : enable
layout(size4x32) const uniform image1D imageVariable;


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.


layout(size4x32) const uniform image1D restrict imageVar1; // error C7522
layout(size4x32) uniform image1D restrict imageVar2; // OK


As a workaround, I have just removed the const keyword and hope the compiler notices that I never use imageWrite() with the variable.

malexander
06-29-2011, 06:37 PM
Perhaps you need to move the const keyword after the image type:


layout(size4x32) uniform image2D const imageVariable;

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.

RobertC
07-08-2011, 03:37 AM
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