0

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

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++?

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();

And then bind my QOpenGLBuffer with (Squircle.cpp):

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

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

computeProgram_->bind();

// ... 

pointOpenGLBuffer_.bind();

glDispatchCompute(1024, 1, 1);

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.

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;

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.

0

1 Answer 1

2

It seems that problem is in wrong buffer binding understanding.

pointOpenGLBuffer_.bind(); 

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());

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

Sign up to request clarification or add additional context in comments.

1 Comment

It worked! I had read that function last last night too, but didn't try it for some reason. I also think my attention got caught on what Format I was using (I specify Core4.3, but the current buffer uses Compatibility4.5) But yeah, thanks! ~16 hours of my own toiling missed that solution. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.