2

I can't get a SSBO working using Qt3D. I'm also unable to find a single example displaying how it is supposed to be done. Here are the main parts of my code:

Buffer init:

QByteArray ssboData;
ssboData.resize(1000);
ssboData.fill(0);

mySSBOBuffer = new Qt3DRender::QBuffer(this);
mySSBOBuffer->setUsage(Qt3DRender::QBuffer::DynamicRead);
mySSBOBuffer->setAccessType(Qt3DRender::QBuffer::AccessType::ReadWrite);
mySSBOBuffer->setData(ssboData);

QByteArray atomicCounterData;
atomicCounterData.resize(4);
atomicCounterData.fill(0);

myAtomicCounterBuffer = new Qt3DRender::QBuffer(this);
myAtomicCounterBuffer->setUsage(Qt3DRender::QBuffer::DynamicRead);
myAtomicCounterBuffer->setAccessType(Qt3DRender::QBuffer::AccessType::ReadWrite);
myAtomicCounterBuffer->setData(atomicCounterData);

Passing the buffers as QParameters to the shader.

myMaterial->addParameter(new Qt3DRender::QParameter("acCountFrags", QVariant::fromValue(myAtomicCounterBuffer->id()), myMaterial));
myMaterial->addParameter(new Qt3DRender::QParameter("ssboBuffer", QVariant::fromValue(mySSBOBuffer->id()), myMaterial));

I also tried

myMaterial->addParameter(new Qt3DRender::QParameter("acCountFrags", QVariant::fromValue(myAtomicCounterBuffer), myMaterial));
myMaterial->addParameter(new Qt3DRender::QParameter("ssboBuffer", QVariant::fromValue(mySSBOBuffer), myMaterial));

Fragment Shader (color has no use, just to check shader is working):

#version 430 core

layout(binding = 0, offset = 0) uniform atomic_uint acCountFrags;

layout (std430) buffer ssboBuffer
{
    uint fragIds[];
};

out vec4 color;

void main()
{
    uint index = atomicCounterIncrement(acCountFrags);
    fragIds[index] = 5;

    color = vec4(0.2, 0.2, 0.2, 1.0);
}

In all of my tries, nothing is written to the buffers after rendering. They are still full of 0 like after init. Does anybody know if i'm doing something wrong ? Or somewhere I could find a working example ?

Thank you.

FredFred
  • 41
  • 2
  • Are you adding the shader code correctly? You have to add it using a QShaderProgram to a QRenderPass, which you have to add to a QTechnique, which you have to add to a QEffect, which in turn you have to add to your material. – Florian Blume May 31 '18 at 07:09
  • @HappyFeet Thank you for your reply. Everything is added as you explained, and the rendering is working fine (I can display color on screen, or render to a texture etc.). I'm just not getting anything written to the Buffer. – FredFred May 31 '18 at 07:13
  • Ok, sorry I read your question wrong! The Qt3D documentation is a pain in the ass. I assume you googled a lot already, but did you have a look at https://github.com/qt/qt3d/tree/5.11/tests/manual/buffercapture-qml? – Florian Blume May 31 '18 at 07:27
  • @HappyFeet I got that example working. Thank you so much :-) I will post here when/if I find my mistake. – FredFred May 31 '18 at 07:55
  • I'm glad I could help :) I assume you need to connect the buffer's onDataChanged method like they do in the main.cpp in the example. Good luck! – Florian Blume May 31 '18 at 07:58
  • My god I was missing a BufferCapture component in my FrameGraph... That component is totally invisible in the documentation. I don't know if i'm happy or sad. I found it in the example you gave me. Thanks again... – FredFred May 31 '18 at 08:27
  • Wow that component IS invisible :D I've doubted my whole life so many times while programming with Qt3D, so I feel you. – Florian Blume May 31 '18 at 08:34

1 Answers1

2

The answer was a missing BufferCapture component in my FrameGraph. Found it thanks to the example given by HappyFeet in the comments.

FredFred
  • 41
  • 2