Add compile time toggle for threaded buffering

This commit is contained in:
Brad Davis 2017-02-22 15:42:51 -08:00
parent 61ba2dd11e
commit 05efac9ddf
2 changed files with 25 additions and 10 deletions

View file

@ -115,22 +115,29 @@ public:
bool _bufferingCompleted { false }; bool _bufferingCompleted { false };
VoidLambda _transferLambda; VoidLambda _transferLambda;
VoidLambda _bufferingLambda; VoidLambda _bufferingLambda;
static ThreadPointer _bufferThread; #if THREADED_TEXTURE_BUFFERING
static Mutex _mutex; static Mutex _mutex;
static VoidLambdaQueue _bufferLambdaQueue; static VoidLambdaQueue _bufferLambdaQueue;
static ThreadPointer _bufferThread;
static std::atomic<bool> _shutdownBufferingThread; static std::atomic<bool> _shutdownBufferingThread;
static void bufferLoop(); static void bufferLoop();
#endif
public: public:
TransferJob(const TransferJob& other) = delete; TransferJob(const TransferJob& other) = delete;
TransferJob(const GL45VariableAllocationTexture& parent, std::function<void()> transferLambda); TransferJob(const GL45VariableAllocationTexture& parent, std::function<void()> transferLambda);
TransferJob(const GL45VariableAllocationTexture& parent, uint16_t sourceMip, uint16_t targetMip, uint8_t face, uint32_t lines = 0, uint32_t lineOffset = 0); TransferJob(const GL45VariableAllocationTexture& parent, uint16_t sourceMip, uint16_t targetMip, uint8_t face, uint32_t lines = 0, uint32_t lineOffset = 0);
bool tryTransfer(); bool tryTransfer();
#if THREADED_TEXTURE_BUFFERING
static void startTransferLoop(); static void startTransferLoop();
static void stopTransferLoop(); static void stopTransferLoop();
#endif
private: private:
#if THREADED_TEXTURE_BUFFERING
void startBuffering(); void startBuffering();
#endif
void transfer(); void transfer();
}; };

View file

@ -52,6 +52,7 @@ using TransferJob = GL45VariableAllocationTexture::TransferJob;
static const uvec3 MAX_TRANSFER_DIMENSIONS { 1024, 1024, 1 }; 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; static const size_t MAX_TRANSFER_SIZE = MAX_TRANSFER_DIMENSIONS.x * MAX_TRANSFER_DIMENSIONS.y * 4;
#if THREADED_TEXTURE_BUFFERING
std::shared_ptr<std::thread> TransferJob::_bufferThread { nullptr }; std::shared_ptr<std::thread> TransferJob::_bufferThread { nullptr };
std::atomic<bool> TransferJob::_shutdownBufferingThread { false }; std::atomic<bool> TransferJob::_shutdownBufferingThread { false };
Mutex TransferJob::_mutex; Mutex TransferJob::_mutex;
@ -76,6 +77,7 @@ void TransferJob::stopTransferLoop() {
_bufferThread.reset(); _bufferThread.reset();
_shutdownBufferingThread = false; _shutdownBufferingThread = false;
} }
#endif
TransferJob::TransferJob(const GL45VariableAllocationTexture& parent, uint16_t sourceMip, uint16_t targetMip, uint8_t face, uint32_t lines, uint32_t lineOffset) TransferJob::TransferJob(const GL45VariableAllocationTexture& parent, uint16_t sourceMip, uint16_t targetMip, uint8_t face, uint32_t lines, uint32_t lineOffset)
: _parent(parent) { : _parent(parent) {
@ -123,14 +125,7 @@ TransferJob::TransferJob(const GL45VariableAllocationTexture& parent, std::funct
bool TransferJob::tryTransfer() { bool TransferJob::tryTransfer() {
// Disable threaded texture transfer for now // Disable threaded texture transfer for now
#if 1 #if THREADED_TEXTURE_BUFFERING
if (!_bufferingCompleted) {
_bufferingLambda();
_bufferingCompleted = true;
}
_transferLambda();
return true;
#else
// Are we ready to transfer // Are we ready to transfer
if (_bufferingCompleted) { if (_bufferingCompleted) {
_transferLambda(); _transferLambda();
@ -139,9 +134,18 @@ bool TransferJob::tryTransfer() {
startBuffering(); startBuffering();
return false; return false;
#else
if (!_bufferingCompleted) {
_bufferingLambda();
_bufferingCompleted = true;
}
_transferLambda();
return true;
#endif #endif
} }
#if THREADED_TEXTURE_BUFFERING
void TransferJob::startBuffering() { void TransferJob::startBuffering() {
if (_bufferingStarted) { if (_bufferingStarted) {
return; return;
@ -172,6 +176,7 @@ void TransferJob::bufferLoop() {
} }
} }
} }
#endif
void GL45VariableAllocationTexture::addMemoryManagedTexture(const TexturePointer& texturePointer) { void GL45VariableAllocationTexture::addMemoryManagedTexture(const TexturePointer& texturePointer) {
@ -318,6 +323,7 @@ void GL45VariableAllocationTexture::updateMemoryPressure() {
} }
if (newState != _memoryPressureState) { if (newState != _memoryPressureState) {
#if THREADED_TEXTURE_BUFFERING
if (MemoryPressureState::Transfer == _memoryPressureState) { if (MemoryPressureState::Transfer == _memoryPressureState) {
TransferJob::stopTransferLoop(); TransferJob::stopTransferLoop();
} }
@ -325,7 +331,9 @@ void GL45VariableAllocationTexture::updateMemoryPressure() {
if (MemoryPressureState::Transfer == _memoryPressureState) { if (MemoryPressureState::Transfer == _memoryPressureState) {
TransferJob::startTransferLoop(); TransferJob::startTransferLoop();
} }
#else
_memoryPressureState = newState;
#endif
// Clear the existing queue // Clear the existing queue
_transferQueue = WorkQueue(); _transferQueue = WorkQueue();
_promoteQueue = WorkQueue(); _promoteQueue = WorkQueue();