2

ATI HD 5770 で計算シェーダーを実行しようとしたときに、計算シェーダーの 1 つにエラーがあることに気付きました。GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS が 8 であるにもかかわらず、シェーダーで複数の SSB にアクセスすると問題が発生することがわかりました。

いくつかいじった後、問題のあるシェーダーをこの 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));
}

このシェーダをそのまま実行すると、 からの変更は見られませんimageStore。を削除すると、画像b.length();に目的の出力が得られます-2

どちらの場合もの値a[0]が に変更される-2ため、シェーダーは確実に実行されています。

どちらの場合も、シェーダーのコンパイル/リンカー エラーglGetErrorはなく、エラーも返されません。

ここで何か間違ったことをしていますか?

これは (ドライバーの) バグですか? 結局のところ、これは私の他の (NVidia) カードでは発生しません。

完全を期すために、この「最小限の」C++ ファイルを使用してシェーダーを実行しました。

#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";
}

アップデート

imageLoad2 つ以上の SSBO が使用されている場合は常に 0 を返し、2 個の SSBO が使用されている場合は 3 を返し、2 個未満の SSBO の場合は正しい値を返すという同様の問題があるようです。どちらの問題も、最新のドライバー (15.7、以前は 15.5) でも発生します。

4

0 に答える 0