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



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


  • Lifetime Qt Champion

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.