From e9d08c33bdfb3a25fcc07cf9abaa8198a5019fac Mon Sep 17 00:00:00 2001 From: Francisco Zurita Date: Sun, 23 May 2021 16:56:37 -0400 Subject: [PATCH] Temporary fix for NVidia shaking on Windows --- .../ThreadedOpenGl/RingBufferPool.cpp | 25 ++++++++++++------- .../ThreadedOpenGl/RingBufferPool.h | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Graphics/OpenGLContext/ThreadedOpenGl/RingBufferPool.cpp b/src/Graphics/OpenGLContext/ThreadedOpenGl/RingBufferPool.cpp index 44cd4da4..d0ed15e1 100644 --- a/src/Graphics/OpenGLContext/ThreadedOpenGl/RingBufferPool.cpp +++ b/src/Graphics/OpenGLContext/ThreadedOpenGl/RingBufferPool.cpp @@ -64,10 +64,11 @@ RingBufferPool::RingBufferPool(size_t _poolSize) : PoolBufferPointer RingBufferPool::createPoolBuffer(const char* _buffer, size_t _bufferSize) { size_t realBufferSize = _bufferSize; - const size_t remainder = _bufferSize % 4; + const int byteAlignment = 8; + const size_t remainder = _bufferSize % byteAlignment; if (remainder != 0) - realBufferSize = _bufferSize + 4 - remainder; + realBufferSize = _bufferSize + byteAlignment - remainder; const size_t tempInUseStart = m_inUseStartOffset; @@ -116,23 +117,29 @@ PoolBufferPointer RingBufferPool::createPoolBuffer(const char* _buffer, size_t _ } std::unique_lock lock(m_mutex); + size_t poolBufferSize = m_poolBuffer.size(); if (m_poolBuffer.size() < realBufferSize) { - std::stringstream errorString; - errorString << " Increasing buffer size from " << m_poolBuffer.size() << " to " << realBufferSize; - LOG(LOG_VERBOSE, errorString.str().c_str()); - - m_poolBuffer.resize(realBufferSize); + std::stringstream logString; + logString << " Increasing buffer size from " << m_poolBuffer.size() << " to " << realBufferSize; + LOG(LOG_VERBOSE, logString.str().c_str()); + poolBufferSize = realBufferSize; } - m_condition.wait(lock, [this, realBufferSize] { + m_condition.wait(lock, [this, realBufferSize, poolBufferSize] { const size_t tempInUseStartLocal = m_inUseStartOffset; const size_t remainingLocal = tempInUseStartLocal > m_inUseEndOffset || m_full ? static_cast( tempInUseStartLocal - m_inUseEndOffset) : - m_poolBuffer.size() - m_inUseEndOffset + tempInUseStartLocal; + poolBufferSize - m_inUseEndOffset + tempInUseStartLocal; return remainingLocal >= realBufferSize; }); + + // Resize afterwards, we don't want to lose the validity of pointers + // pointing at the old data + if (m_poolBuffer.size() < realBufferSize) { + m_poolBuffer.resize(realBufferSize); + } } return createPoolBuffer(_buffer, _bufferSize); diff --git a/src/Graphics/OpenGLContext/ThreadedOpenGl/RingBufferPool.h b/src/Graphics/OpenGLContext/ThreadedOpenGl/RingBufferPool.h index 6c1598d6..b14c9432 100644 --- a/src/Graphics/OpenGLContext/ThreadedOpenGl/RingBufferPool.h +++ b/src/Graphics/OpenGLContext/ThreadedOpenGl/RingBufferPool.h @@ -55,7 +55,7 @@ private: std::atomic m_full; std::condition_variable_any m_condition; size_t m_maxBufferPoolSize; - static const size_t m_startBufferPoolSize = 1024 * 100; + static const size_t m_startBufferPoolSize = 1024 * 1024 * 10; }; } \ No newline at end of file