计算着色器未写入缓冲区 [英] Compute Shader not writing to buffer

查看:166
本文介绍了计算着色器未写入缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找使用QOpenGLFunctions_4_3_Core OpenGL函数从Qt调用计算着色器的帮助.

I'm looking for help calling a compute shader from Qt using QOpenGLFunctions_4_3_Core OpenGL functions.

具体地说,我对glDispatchCompute(1024, 1, 1);的调用似乎对绑定到它的缓冲区没有任何影响. 如何将缓冲区绑定到QT中的计算着色器,以便可以将着色器的结果读回到C ++ ?

Specifically, my call to glDispatchCompute(1024, 1, 1); does not seem to have any effect on the buffer bound to it. How do you bind a buffer to a compute shader in QT such that the results of the shader can be read back to the C++?

我创建我的程序并将其与( Squircle.cpp ):

I create my program and bind it with (Squircle.cpp):

    computeProgram_ = new QOpenGLShaderProgram();
    computeProgram_->addShaderFromSourceFile(QOpenGLShader::Compute, "../app/shaders/pointcloud.comp");
    computeProgram_->bindAttributeLocation("Particles", 0);
    m_ParticlesLoc = 0;

    computeProgram_->link();

然后将我的QOpenGLBuffer与( Squircle.cpp ):

    // Setup our vertex buffer object.
    pointOpenGLBuffer_.create();
    pointOpenGLBuffer_.bind();
    pointOpenGLBuffer_.allocate(pointBuffer_.data(), pointBuffer_.vertexCount() * pointBuffer_.stride_);

然后,我使用( Squircle.cpp 调用计算着色器):

Then I invoke the compute shader with (Squircle.cpp):

computeProgram_->bind();

// ... 

pointOpenGLBuffer_.bind();

glDispatchCompute(1024, 1, 1);

但是当我通过read()map()'ing读取缓冲区时,这些值永远不会改变,它们就是我最初插入的.

But when I read my buffer, either with read() or by map()'ing, the values are never changed, they're just what I originally inserted.

从计算着色器的角度来看,我接受(( pointcloud.comp ):

From the compute shader perspective, I accept my input with (pointcloud.comp):

#version 430

layout(local_size_x = 1024) in;

struct ParticleData
{
    vec4 position;
};

// Particles from previous frame
layout (std430, binding = 0) coherent buffer Particles
{
    ParticleData particles[];
} data;

我可能没有正确绑定缓冲区吗?还是有另一个OpenGL命令要调用以实际分派计算?我尝试了不同的用法,等等.

Am I not binding my buffer properly maybe? Or is there another OpenGL command to call to actually dispatch the compute? I've tried different usages, etc.

我已经在此处发布了所有相关代码.

I've posted all the relevant code here.

推荐答案

问题似乎出在对缓冲区绑定的理解不正确.

It seems that problem is in wrong buffer binding understanding.

pointOpenGLBuffer_.bind(); 

仅将缓冲区绑定到OGL上下文,而不绑定到着色器缓冲区,两次调用都无济于事.

only binds your buffer to your OGL context, not to your shader buffer, calling it twice won't do the trick.

第二次而不是仅仅绑定,您需要致电

Second time instead of just bind you need to call

glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, pointOpenGLBuffer_.bufferId());

其中0来自您的布局(std430,绑定= 0)

where 0 comes from your layout (std430, binding = 0)

这篇关于计算着色器未写入缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆