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 };
VoidLambda _transferLambda;
VoidLambda _bufferingLambda;
static ThreadPointer _bufferThread;
#if THREADED_TEXTURE_BUFFERING
static Mutex _mutex;
static VoidLambdaQueue _bufferLambdaQueue;
static ThreadPointer _bufferThread;
static std::atomic<bool> _shutdownBufferingThread;
static void bufferLoop();
#endif
public:
TransferJob(const TransferJob& other) = delete;
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);
bool tryTransfer();
#if THREADED_TEXTURE_BUFFERING
static void startTransferLoop();
static void stopTransferLoop();
#endif
private:
#if THREADED_TEXTURE_BUFFERING
void startBuffering();
#endif
void transfer();
};

View file

@ -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<std::thread> TransferJob::_bufferThread { nullptr };
std::atomic<bool> 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();