This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

GLSL Compute Shader: ERROR: xxx: S0001: Function call discards 'readonly' access qualifier.

Hi, I have compute shader with following code:

...
struct CullingObjInfo {
...
    vec4 boundingSphere; // radius(float) + position(float3)
...
    vec4 lodDistance;
};
...
layout(std430, binding = 2) restrict readonly buffer CullingObjectInfo {
    CullingObjInfo cullingObjInfo[];
};
...
bool SelectLodByDistance(const CullingObjInfo cullingObjectInfo, const vec4 cameraPosition) {
    float distanceSq = dot(cullingObjectInfo.boundingSphere.xyz, cameraPosition.xyz);
    return distanceSq >= cullingObjectInfo.lodDistance.x && distanceSq <= cullingObjectInfo.lodDistance.y;
}

layout (local_size_x = 1, local_size_y = 1) in;
void main() {
    if (!SelectLodByDistance(cullingObjInfo[gl_GlobalInvocationID.x], cameraInfo.cameraPosition)) {
        return;
    }
...
}

During compiling i have got error for calling function "SelectLodByDistance": ERROR: xxx: S0001: Function call discards 'readonly' access qualifier.

But if I change code:

...
bool SelectLodByDistance(uint index, const vec4 cameraPosition) {
    float distanceSq = dot(cullingObjInfo[index].boundingSphere.xyz, cameraPosition.xyz);
    return distanceSq >= cullingObjInfo[index].lodDistance.x && distanceSq <= cullingObjInfo[index].lodDistance.y;
}

layout (local_size_x = 1, local_size_y = 1) in;
    void main() {
    if (!SelectLodByDistance(gl_GlobalInvocationID.x, cameraInfo.cameraPosition)) {
        return;
    }
...
}

It works, What do i do wrong ?

BR, Andrey

  • Hi Andrey, 

    The ESSL specification disallows the readonly qualifier from being discarded when you call a function. From ESSL 3.2 specificaiton, section 4.10:

    When calling user-defined functions, variables qualified with [...] readonly [...] may not be passed to functions whose formal parameters lack such qualifiers. (See section 6.1 “Function Definitions” for more detail on function calling.) It is legal to have any additional memory qualifiers on a formal parameter, but only restrict can be taken away from a calling argument, by a formal parameter that lacks the restrict qualifier.

    Adding the readonly modifier in the function prototype solves the issue. Note that despite one may intuitively think, the 'const' modifier does not help here.

    bool SelectLodByDistance(readonly const CullingObjInfo cullingObjectInfo, const vec4 cameraPosition) {
        ...
    }

    HTH,
    Pete

  • Thank you , could you repost your answer, i have rejected your answer today, it is my mistake.