I expected to be able to use both imageLoad and imageStore on the same image to read and modify it from within a compute shader.
Trying with a declaration of: layout(r32f, binding=0) uniform highp image2D x;Produces "Shader error: Image has to be qualified as 'readonly', 'writeonly' or both."
layout(r32f, binding=0) uniform highp image2D x;
I haven't been able to find yet how to specify "both" as the error implies is possible. Is there a keyword for this I've missed?
I'm using a Mali-T720 with GLES 3.1 v1.r7p0-02
That looks like a bug in the driver you have; specifying neither is valid. To specify both you literally specify "readonly writeonly", but that means you can't read or write to it and can therefore only use it for metadata operations such as imageSize(), which probably isn't what you want. I don't have an r7p0 device to hand, but I've tried all DDK versions that the offline compiler supports, and all of those seem to accept specifying neither qualifier all the way back to r5p0 which was the first release supporting compute shaders. 1) What exact device are you using so I can try and hunt down what is causing problems? 2) Can you share the complete shader causing the problem, just so we are sure we are looking at the right thing? Cheers, Pete
1) It is an Amazon Fire HD 8" (6th Gen)2) Minimal repro and notes below
#version 310 esprecision highp image2D;layout(rgba32f, binding=0) uniform image2D x;layout(local_size_x=8, local_size_y=8) in;void main () { ivec2 i = ivec2(gl_GlobalInvocationID.xy); imageStore(x, i, imageLoad(x, i));}Shader error:0:3: S0001: Image has to be qualified as 'readonly', 'writeonly' or both.
After my initial post I found I could work around the error by declaring the image2D twice. Once as readonly, then again as writeonly and both using the same binding number. So that is what I'm doing now to work around things on the shaders where this is triggering.
Just to add an appendix to this one, as this post seems to get found in web searches for a related issue, which isn't a Mali bug.
There was a bug a long time ago, impacting r32* bindings, which was fixed in 2017 drivers.
You will still get this error for other binding formats because the OpenGL ES shader language spec requires this behavior:
Except for image variables qualified with the format qualifiers r32f, r32i, and r32ui, image variables must specify either memory qualifier readonly or the memory qualifier writeonly.
If you want read+write images you must make two separate variable definitions, one readonly and one writeonly, which can be bound to the same binding location.
Cheers,Pete