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. How to pass data to\from GLSL compute shaders in Qt?

How to pass data to\from GLSL compute shaders in Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 987 Views 2 Watching
  • 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.
  • C Offline
    C Offline
    Crazy Sage
    wrote on last edited by Crazy Sage
    #1

    Hello. I'm trying to port my program that is using GL compute shaders to Qt and I can't understand, what is correct way to work with buffers.
    I initialize and use buffers with following code:

        QOpenGLBuffer cull_ray_buffer;
        QOpenGLBuffer cull_face_buffer;
        QOpenGLBuffer cull_out_buffer;
    
        if(!cull_ray_buffer.create())
        {
            qDebug()<<"Can't create cull ray buffer";
            return false;
        }
        cull_ray_buffer.allocate(border_rays.size()*sizeof(QVector4D));//border_rays_ is QVector of QVector4D
    
        if(!cull_face_buffer.create())
        {
            qDebug()<<"Can't create cull face buffer";
            return false;
        }
        cull_face_buffer.allocate(faces_.data(), faces_.size()*sizeof(QVector4D));//faces_ is QVector of QVector4D
    
        if(!cull_out_buffer.create())
        {
            qDebug()<<"Can't create cull out buffer";
            return false;
        }
        cull_out_buffer.allocate(tmp_out.data(), tmp_out.size()*sizeof(int));//tmp_out_ is QVector of int
    
        ogl->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, cull_ray_buffer.bufferId());//ogl is an instance of QOpenGLFunctions_4_4_Core
        ogl->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, cull_face_buffer.bufferId());
        ogl->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, cull_out_buffer.bufferId());
    

    In my shader I have buffers declared like this:

    layout(std430, binding=0) buffer rays{
        vec4 r[];
    };
    
    layout(std430, binding=1) buffer faces{
        vec4 f[];
    };
    
    layout(std430, binding=2) buffer outputs{
        int o[];
    };
    

    I link shader before creating and binding buffers and then try to get output data by doing one of following things:

    int* b = static_cast<int*>(cull_out_buffer.map(QOpenGLBuffer::ReadOnly));
    

    or

    cull_out_buffer.read(0,tmp_out.data(), tmp_out.size()*sizeof(int))
    

    in first case I'm getting NULL pointer, in second - function returns false.
    Also I'm not even sure that shader receives input data correctly (and I don't see any way to check it, because it is console gpu-computing project without any actual rendering).

    Can someone please explain to me, what is correct way of passing data to compute shaders?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Interesting question, I haven't yet used compute shaders so I can't offer yet an answer. In the mean time, I'd recommend brining that questions to the interest mailing list. You'll find there QtOpenGL developers/maintainers.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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