From afea49e83d50121788ee6e365219399d885b5e4b Mon Sep 17 00:00:00 2001 From: kaetemi Date: Thu, 5 Jun 2014 21:39:03 +0200 Subject: [PATCH] GL3: Manual syncing --HG-- branch : opengl3 --- .../opengl3/driver_opengl_vertex_buffer.cpp | 42 +++++++++++++++++-- .../opengl3/driver_opengl_vertex_buffer.h | 2 + 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.cpp index 25943edc9..2939827fb 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.cpp @@ -54,7 +54,8 @@ IVertexBufferGL3::~IVertexBufferGL3() CVertexBufferGL3::CVertexBufferGL3(CDriverGL3 *drv, uint size, uint numVertices, CVertexBuffer::TPreferredMemory preferred, CVertexBuffer *vb) : IVertexBufferGL3(drv, vb, IVertexBufferGL3::GL3), m_VertexPtr(NULL), - m_VertexObjectId(0) + m_VertexObjectId(0), + m_FenceId(0) { H_AUTO_OGL(CVertexBufferGLARB_CVertexBufferGLARB) @@ -174,11 +175,29 @@ void *CVertexBufferGL3::lock() case CVertexBuffer::RAMPreferred: // m_VertexPtr = nglMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_WRITE_BIT | GL_MAP_READ_BIT | GL_MAP_PERSISTENT | GL_MAP_COHERENT); // NOTE: Persistent / Coherent is only available in OpenGL 4.4 (2013/2014 hardware with recent drivers) - m_VertexPtr = nglMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); + // m_VertexPtr = nglMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); + if (m_FenceId) + { + GLenum result = nglClientWaitSync(m_FenceId, GL_SYNC_FLUSH_COMMANDS_BIT, 0); + nlassert(result != GL_TIMEOUT_EXPIRED); + nlassert(result != GL_WAIT_FAILED); + nglDeleteSync(m_FenceId); + m_FenceId = NULL; + } + m_VertexPtr = nglMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_WRITE_BIT | GL_MAP_READ_BIT | GL_MAP_UNSYNCHRONIZED_BIT); break; default: // m_VertexPtr = nglMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_WRITE_BIT); - m_VertexPtr = nglMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + // m_VertexPtr = nglMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + if (m_FenceId) + { + GLenum result = nglClientWaitSync(m_FenceId, GL_SYNC_FLUSH_COMMANDS_BIT, 0); + nlassert(result != GL_TIMEOUT_EXPIRED); + nlassert(result != GL_WAIT_FAILED); + nglDeleteSync(m_FenceId); + m_FenceId = NULL; + } + m_VertexPtr = nglMapBufferRange(GL_ARRAY_BUFFER, 0, size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); break; } @@ -302,7 +321,22 @@ void CVertexBufferGL3::setFence() { H_AUTO_OGL(CVertexBufferGLARB_setFence) - // no-op + // Set the fence + switch (m_MemType) + { + case CVertexBuffer::AGPVolatile: + case CVertexBuffer::RAMVolatile: + break; + default: + if (m_FenceId) + { + nglDeleteSync(m_FenceId); + m_FenceId = 0; + } + m_FenceId = nglFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + nlassert(m_FenceId); + break; + } } // *************************************************************************** diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.h b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.h index 3950444f0..6f60a98e2 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.h +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_vertex_buffer.h @@ -103,6 +103,8 @@ private: std::list::iterator m_IteratorInLostVBList; uint m_VertexObjectId; + + GLsync m_FenceId; }; // ***************************************************************************