1

I am not sure whether it is a driver bug but following happens:

compute-shader.glsl:

#version 320 es
precision mediump float;

layout(local_size_x = 16, local_size_y = 8, local_size_z = 1) in;
layout(rgba8ui, binding = 0) writeonly uniform mediump uimage2D image;
layout(binding = 1) uniform mediump usampler3D grid;

void main() {
    uint i = gl_GlobalInvocationID.y;
    uint j = gl_GlobalInvocationID.x;

    uvec4 val = texture(grid, vec3(float(i)/480.0,float(j)/640.0,0.5));

    imageStore(image, ivec2(j,i), val);
}

The color channels of val are completely scrambled:

  • alpha = blue
  • red = red
  • green = alpha
  • blue = green

main.cpp:

    glActiveTexture(GL_TEXTURE1);
    glEnable(GL_TEXTURE_3D);
    glBindTexture(GL_TEXTURE_3D, grid_tex_id);
    glTexStorage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 256, 256, 256);
    glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 256, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, grid.data);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Is there any reasonable explanation for this? Note: I do not want to use the hack val.ragb (if that even exists).

genpfault
  • 51,148
  • 11
  • 85
  • 139
Armen Avetisyan
  • 1,140
  • 10
  • 29

1 Answers1

2
layout(binding = 1) uniform mediump usampler3D grid;
...
glTexStorage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 256, 256, 256);

GL_RGBA8 is not an integer format; it's a normalized format. That means it is equivalent to a floating-point format. So you should use sampler3D, not usampler3D. Or you should upload your data to an integer format like GL_RGBA8UI, using the GL_RGBA_INTEGER pixel transfer format.

You probably got away with it using Image Load/Store by re-specifying the format in the shader itself. You can't do that with textures.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • just a little feedback. It seems like the ```GL_RGBA8UI```/ ```GL_RGBA_INTEGER```/ ```GL_UNSIGNED_BYTE``` is not filterable. See https://www.khronos.org/opengles/sdk/docs/man3/html/glTexStorage3D.xhtml – Armen Avetisyan Sep 12 '16 at 16:52