[Development] Qt3D: Correct way of using QBuffer and compute shader

Esch Lorenz TU Ilmenau Lorenz.Esch at tu-ilmenau.de
Tue Jan 16 17:49:05 CET 2018


Dear Qt Community,

I am writing my first application using a compute shader based on Qt3D in C++. My question: What is the correct way of updating the data needed by the compute shader during run-time? This is what I tried so far:

I create a QBuffer object (in form of a QPointer) and fill it with data. The pointer is kept as a member in a class. I set the buffer via .data() to a QVariant and set it as data to the corresponding QParameter. The following is a code snippet showing the basic idea:



QByteArray interpolationBufferData = buildInterpolationMatrixBuffer(matInterpolationMatrix); //Builds the data array from a large Eigen Matrix

m_pInterpolationMatBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::ShaderStorageBuffer);

m_pInterpolationMatBuffer->setData(interpolationBufferData);

m_pParameter ->setValue(QVariant::fromValue(m_pInterpolationMatBuffer.data()), QStringLiteral("InterpolationMat"));

m_pInterpolationMatBuffer->setData(interpolationBufferData);

Everything works fine until here. The visualization is doing what it is supposed to do and the compute shader works fine. After a new input matrix arrives I create a new QByteArray and try to load to the QBuffer object via updateData (I also tried setData). Once I try to update the data in the QBuffer the application crashes.



QByteArray interpolationBufferData = buildInterpolationMatrixBuffer(matInterpolationMatrix); //Builds the data array from an incoming Eigen Matrix

m_pInterpolationMatBuffer->updateData(0, interpolationBufferData);

Am I missing something? Is there a better way to update data used by the compute shader? Should I pay attention to the usage type (StreamDraw, StaticDraw, etc.)? Also, is the complete QByteArray internally copied to the GPU when setting only the pointer to the QVariant? Maybe I should create a new buffer every time I receive new data? Questions over questions 😊

Best from Germany and many thanks,

Lorenz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180116/18174538/attachment.html>


More information about the Development mailing list