Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Qt3D] Using a SSBO in Qt3D

[Qt3D] Using a SSBO in Qt3D

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 562 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FredFred
    wrote on last edited by
    #1

    Hello,

    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.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      Oeystein
      wrote on last edited by Oeystein
      #2

      Hi,

      I just got SSBO working with Qt3D. This might be too late for you, but it might help somebody else. Change you shader to something like:

      #version 430 core
      
      layout(binding = 0, offset = 0) uniform atomic_uint acCountFrags;
      
      layout (std430) buffer ssboBuffer
      {
          uint fragIds[];
      } myssbo;
      
      out vec4 color;
      
      void main()
      {
          uint index = atomicCounterIncrement(acCountFrags);
          myssbo.fragIds[index] = 5;
      
          color = vec4(0.2, 0.2, 0.2, 1.0);
      }
      

      I have had success passing data from compute shaders into vertex and fragment shaders.

      Best regards,
      Øystein

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved