PDA

View Full Version : multi threaded Persistent mapping



galbrz
08-18-2015, 06:18 PM
Hi,
I have written an app that uses the persistent mapping technique.
I use 2 different threads on the app - upload thread and drawing thread.
The upload thread uploads the data to the mapped buffer using the std:copy command, while the drawing thread displays the data using the openGL commands.
when I try to upload a big amount of data that is changing fast (e.g. ~5000 triangle every 5 milliseconds), the display shows sometime garbage.

I tried to perform the same code synchronously, e.g upload and draw on the same thread, and everything looks good.
I used debug printings and it seems that the same offsets and data I upload on one thread is what I read and display on the other thread.

The mapping is like this:

glBindBuffer(m_bufferDataType, m_glBufferId);
const GLbitfield flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
glBufferStorage(m_bufferDataType, m_bufferSize, NULL, flags);
m_glBufferDataPtr = (char*)glMapBufferRange(m_bufferDataType, 0, m_bufferSize, flags);
glBindBuffer(m_bufferDataType, 0);

The upload looks like that:

std::copy(_data.begin(), _data.end(), (T*)(m_glBufferDataPtr + m_uploadOffset));

I use fences to sync the buffer for not uploading data the a section while it is in use of the GPU.

Does anyone have an idea why it is happening?
Thanks.

galbrz
08-19-2015, 07:17 AM
Ok... I found the problem, I had a problem on my code.
Now everything works great.

Dark Photon
08-19-2015, 06:09 PM
So what was the problem? I think you have a number of us curious.

galbrz
08-20-2015, 02:59 AM
I have put the glfence before the draw call by mistake, and it caused the fence to be released right after the draw,
and when the upload occurd the range seemed to be released even though the GPU still used it.

Dark Photon
08-20-2015, 05:36 AM
Ah! That makes sense. Thanks!