diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h index 29e5a59ec5..28425433c4 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h +++ b/libraries/gpu-gl/src/gpu/gl45/GL45Backend.h @@ -115,22 +115,29 @@ public: bool _bufferingCompleted { false }; VoidLambda _transferLambda; VoidLambda _bufferingLambda; - static ThreadPointer _bufferThread; +#if THREADED_TEXTURE_BUFFERING static Mutex _mutex; static VoidLambdaQueue _bufferLambdaQueue; + static ThreadPointer _bufferThread; static std::atomic _shutdownBufferingThread; static void bufferLoop(); +#endif public: TransferJob(const TransferJob& other) = delete; TransferJob(const GL45VariableAllocationTexture& parent, std::function transferLambda); TransferJob(const GL45VariableAllocationTexture& parent, uint16_t sourceMip, uint16_t targetMip, uint8_t face, uint32_t lines = 0, uint32_t lineOffset = 0); bool tryTransfer(); + +#if THREADED_TEXTURE_BUFFERING static void startTransferLoop(); static void stopTransferLoop(); +#endif private: +#if THREADED_TEXTURE_BUFFERING void startBuffering(); +#endif void transfer(); }; diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp index 92cc945a86..62f1a3c248 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendVariableTexture.cpp @@ -52,6 +52,7 @@ using TransferJob = GL45VariableAllocationTexture::TransferJob; static const uvec3 MAX_TRANSFER_DIMENSIONS { 1024, 1024, 1 }; static const size_t MAX_TRANSFER_SIZE = MAX_TRANSFER_DIMENSIONS.x * MAX_TRANSFER_DIMENSIONS.y * 4; +#if THREADED_TEXTURE_BUFFERING std::shared_ptr TransferJob::_bufferThread { nullptr }; std::atomic TransferJob::_shutdownBufferingThread { false }; Mutex TransferJob::_mutex; @@ -76,6 +77,7 @@ void TransferJob::stopTransferLoop() { _bufferThread.reset(); _shutdownBufferingThread = false; } +#endif TransferJob::TransferJob(const GL45VariableAllocationTexture& parent, uint16_t sourceMip, uint16_t targetMip, uint8_t face, uint32_t lines, uint32_t lineOffset) : _parent(parent) { @@ -123,14 +125,7 @@ TransferJob::TransferJob(const GL45VariableAllocationTexture& parent, std::funct bool TransferJob::tryTransfer() { // Disable threaded texture transfer for now -#if 1 - if (!_bufferingCompleted) { - _bufferingLambda(); - _bufferingCompleted = true; - } - _transferLambda(); - return true; -#else +#if THREADED_TEXTURE_BUFFERING // Are we ready to transfer if (_bufferingCompleted) { _transferLambda(); @@ -139,9 +134,18 @@ bool TransferJob::tryTransfer() { startBuffering(); return false; +#else + if (!_bufferingCompleted) { + _bufferingLambda(); + _bufferingCompleted = true; + } + _transferLambda(); + return true; #endif } +#if THREADED_TEXTURE_BUFFERING + void TransferJob::startBuffering() { if (_bufferingStarted) { return; @@ -172,6 +176,7 @@ void TransferJob::bufferLoop() { } } } +#endif void GL45VariableAllocationTexture::addMemoryManagedTexture(const TexturePointer& texturePointer) { @@ -318,6 +323,7 @@ void GL45VariableAllocationTexture::updateMemoryPressure() { } if (newState != _memoryPressureState) { +#if THREADED_TEXTURE_BUFFERING if (MemoryPressureState::Transfer == _memoryPressureState) { TransferJob::stopTransferLoop(); } @@ -325,7 +331,9 @@ void GL45VariableAllocationTexture::updateMemoryPressure() { if (MemoryPressureState::Transfer == _memoryPressureState) { TransferJob::startTransferLoop(); } - +#else + _memoryPressureState = newState; +#endif // Clear the existing queue _transferQueue = WorkQueue(); _promoteQueue = WorkQueue();