Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: EXT_shader_image_load_store and "const" keyword

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2011
    Posts
    2

    EXT_shader_image_load_store and "const" keyword

    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.
    Code :
    layout(size4x32) const uniform image2D imageVariable;

    I use the (almost) same definition in my shader:
    Code :
    #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.
    Code :
    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.

  2. #2
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    257

    Re: EXT_shader_image_load_store and "const" keyword

    Perhaps you need to move the const keyword after the image type:

    Code :
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2011
    Posts
    2

    Re: EXT_shader_image_load_store and "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
    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):
    Code :
    error C7537: OpenGL does not allow 'const' after a type specifier
    error C7522: OpenGL requires constants to be initialized

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •