2

I noticed an error in one of my compute shaders when trying to run it on my ATI HD 5770. I found out that the problems start when I access more then one SSB in the shader, despite GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS being 8.

After some fiddling I reduced the problematic shader to this MWE:

#version 430
layout(local_size_x = 1) in;

buffer A { float a[]; };
buffer B { uint b[]; };
layout(r32i) uniform iimage2D outputImage;

void main() {
  a[0] = -2;
  b.length();
  imageStore(outputImage, ivec2(gl_GlobalInvocationID.xy),
             ivec4(a[0], 0, 0, 0));
}

When I run this shader as is, I don't see any changes from imageStore. When removing b.length();, I get the desired output of -2 in the image.

The value of a[0] is changed to -2 in both cases, so the shader is definitely running.

There are no compilation/linker errors for the shader in both cases and glGetError does not return an error as well.

Am I doing something wrong here?

Is this a (driver) bug? After all, this does not happen on my other (NVidia) cards.

Just for completeness, I used this "minimal" C++ file to run the shader:

#include <cassert>
#include <QGuiApplication>
#include <QOpenGLShaderProgram>
#include <QOffscreenSurface>
#include <QOpenGLBuffer>
#include <QOpenGLContext>
#include <QOpenGLTexture>
#include <QOpenGLFunctions_4_3_Compatibility>
#include <vector>
#include <iostream>
#include <iterator>

int main(int argc, char* argv[]) {
  QGuiApplication app(argc, argv);
  QOffscreenSurface surface;
  surface.create();

  QOpenGLContext context;
  context.create();
  context.makeCurrent(&surface);

  QOpenGLShaderProgram program;
  program.addShaderFromSourceFile(QOpenGLShader::Compute, "shader.comp");
  bool programIsLinked = program.link();
  assert(programIsLinked);

  QSize size(2, 2);

  QOpenGLBuffer bufferA;
  bufferA.create();
  bufferA.bind();
  std::vector<GLfloat> valuesOfBufferA(1, 2);
  bufferA.allocate(&valuesOfBufferA.front(),
                   sizeof(valuesOfBufferA.front()) * valuesOfBufferA.size());
  bufferA.release();

  QOpenGLTexture texture(QOpenGLTexture::Target2D);
  texture.create();
  texture.setFormat(QOpenGLTexture::R32I);
  texture.setSize(size.width(), size.height());
  texture.bind();
  texture.allocateStorage();
  std::vector<GLint> data;
  data.resize(size.width() * size.height(), -1);
  texture.setData(QOpenGLTexture::Red_Integer, QOpenGLTexture::Int32,
                  data.data());
  texture.release();

  QOpenGLFunctions_4_3_Compatibility* qOGL =
      context.versionFunctions<QOpenGLFunctions_4_3_Compatibility>();
  qOGL->initializeOpenGLFunctions();

  program.bind();

  qOGL->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, bufferA.bufferId());
  qOGL->glBindImageTexture(0, texture.textureId(), 0, GL_FALSE, 0,
                           GL_WRITE_ONLY, texture.format());

  qOGL->glDispatchCompute(size.width(), size.height(), 1);

  qOGL->glMemoryBarrier(GL_ALL_BARRIER_BITS);
  // for good measure :)
  qOGL->glFinish();

  data.clear();
  data.resize(size.width() * size.height(), 0);
  glBindTexture(GL_TEXTURE_2D, texture.textureId());
  glGetTexImage(GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_INT, data.data());
  glBindTexture(GL_TEXTURE_2D, 0);

  bufferA.bind();
  bufferA.read(0, valuesOfBufferA.data(),
               sizeof(valuesOfBufferA.front()) * valuesOfBufferA.size());
  bufferA.release();

  assert(GL_NO_ERROR == glGetError());

  std::cout << valuesOfBufferA.front() << "\n";

  std::copy(data.begin(), data.end(),
            std::ostream_iterator<GLint>(std::cout, " "));
  std::cout << "\n";
}

Update

There seems to be a similar problem with imageLoad where it does always return 0 with more than 2 SSBOs being used, 3 with 2 SSBOs being used, and the correct value for less than 2 SSBOs. Both problems occur even on the newest driver (15.7, was 15.5 before).

  • Independently of an answer I would also like to see if other AMD users see the same problem. – Nobody moving away from SE Jul 15 '15 at 13:11
  • have the same problem. imageLoad() returns always vec4(0,0,0,0) or/and imageStore() doesnt store my vectors. Have you found solution? My thread: https://stackoverflow.com/questions/46160723/opengl-render-difference-between-nvidia-and-ati – Kedriik Sep 13 '17 at 12:56
  • @Kedriik No, I just assumed it is a driver bug since it depended on surrounding code. I just gave up on AMD there. – Nobody moving away from SE Sep 13 '17 at 16:05

0 Answers0