Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在计算着色器中使用两个SSBO时,imageStore不写入_C++_Opengl_Texture2d_Compute Shader_Ati - Fatal编程技术网

C++ 在计算着色器中使用两个SSBO时,imageStore不写入

C++ 在计算着色器中使用两个SSBO时,imageStore不写入,c++,opengl,texture2d,compute-shader,ati,C++,Opengl,Texture2d,Compute Shader,Ati,当我试图在ATI HD 5770上运行计算着色器时,我注意到其中一个计算着色器出现错误。 我发现,尽管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) unif

当我试图在ATI HD 5770上运行计算着色器时,我注意到其中一个计算着色器出现错误。 我发现,尽管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.长度()时,我在图像中获得所需的
-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";
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
int main(int argc,char*argv[]){
QGUI应用程序应用程序(argc、argv);
Qoffscreen表面;
surface.create();
语境;
context.create();
context.makeCurrent(&surface);
QOpenGLShaderProgram计划;
program.addShaderFromSourceFile(QOpenGLShader::Compute,“shader.comp”);
bool programIsLinked=program.link();
断言(程序链接);
QSize大小(2,2);
QOpenGLBuffer bufferA;
bufferA.create();
bufferA.bind();
std::向量值sofBuffera(1,2);
bufferA.allocate(&valuesOfBufferA.front(),
sizeof(valuesOfBufferA.front())*valuesOfBufferA.size());
bufferA.release();
QOpenGLTexture纹理(QOpenGLTexture::Target2D);
texture.create();
setFormat(QOpenGLTexture::R32I);
texture.setSize(size.width(),size.height());
texture.bind();
texture.allocatestrage();
std::矢量数据;
data.resize(size.width()*size.height(),-1);
setData(QOpenGLTexture::Red_Integer,QOpenGLTexture::Int32,
data.data());
纹理释放();
QOpenGLFunctions_4_3_兼容性*qOGL=
context.versionFunctions();
qOGL->InitializePenglFunctions();
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\u所有\u屏障\u位);
//好的措施:)
qOGL->glFinish();
data.clear();
data.resize(size.width()*size.height(),0);
glBindTexture(GL_TEXTURE_2D,TEXTURE.textureId());
glGetTexImage(GL_纹理_2D,0,GL_红色_整数,GL_INT,data.data());
glBindTexture(GL_TEXTURE_2D,0);
bufferA.bind();
bufferA.read(0,值为bufferA.data(),
sizeof(valuesOfBufferA.front())*valuesOfBufferA.size());
bufferA.release();
断言(GL_NO_ERROR==glGetError());

std::cout独立于答案,我还想看看其他AMD用户是否看到相同的问题。有相同的问题。imageLoad()始终返回vec4(0,0,0,0)或/和imageStore()没有存储我的向量。你找到解决方案了吗?我的线程:@Kedriik没有,我只是假设它是一个驱动程序错误,因为它依赖于周围的代码。我只是放弃了AMD。