From 27ddd39a22058b28cf057ed5aae9433278670b81 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 9 Sep 2016 09:30:38 -0700 Subject: [PATCH] PR comments --- libraries/gpu-gl/src/gpu/gl/GLShared.cpp | 21 +++++++++++++++++++ libraries/gpu-gl/src/gpu/gl/GLShared.h | 6 ++++++ .../gpu-gl/src/gpu/gl/GLTextureTransfer.cpp | 4 ++-- .../src/gpu/gl45/GL45BackendTexture.cpp | 19 ----------------- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLShared.cpp b/libraries/gpu-gl/src/gpu/gl/GLShared.cpp index fd6857c4c0..d59be0d9de 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLShared.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLShared.cpp @@ -9,6 +9,8 @@ #include +#include + #include #include #include @@ -933,9 +935,28 @@ void makeProgramBindings(ShaderObject& shaderObject) { (void)CHECK_GL_ERROR(); } +void serverWait() { + auto fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + assert(fence); + glWaitSync(fence, 0, GL_TIMEOUT_IGNORED); + glDeleteSync(fence); +} + +void clientWait() { + auto fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + assert(fence); + auto result = glClientWaitSync(fence, GL_SYNC_FLUSH_COMMANDS_BIT, 0); + while (GL_TIMEOUT_EXPIRED == result || GL_WAIT_FAILED == result) { + // Minimum sleep + QThread::usleep(1); + result = glClientWaitSync(fence, 0, 0); + } + glDeleteSync(fence); +} } } + using namespace gpu; diff --git a/libraries/gpu-gl/src/gpu/gl/GLShared.h b/libraries/gpu-gl/src/gpu/gl/GLShared.h index 676d3910ff..7ec6deeb9d 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLShared.h +++ b/libraries/gpu-gl/src/gpu/gl/GLShared.h @@ -18,6 +18,12 @@ Q_DECLARE_LOGGING_CATEGORY(gpugllogging) namespace gpu { namespace gl { +// Create a fence and inject a GPU wait on the fence +void serverWait(); + +// Create a fence and synchronously wait on the fence +void clientWait(); + gpu::Size getDedicatedMemory(); ComparisonFunction comparisonFuncFromGL(GLenum func); State::StencilOp stencilOpFromGL(GLenum stencilOp); diff --git a/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.cpp b/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.cpp index 0f64ea1182..ae8739bb3b 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTextureTransfer.cpp @@ -146,7 +146,7 @@ bool GLTextureTransferHelper::process() { gltexture->finishTransfer(); glNamedFramebufferTexture(_readFramebuffer, GL_COLOR_ATTACHMENT0, gltexture->_id, 0); glBlitNamedFramebuffer(_readFramebuffer, _drawFramebuffer, 0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST); - glFinish(); + clientWait(); gltexture->_contentStamp = gltexture->_gpuObject.getDataStamp(); gltexture->updateSize(); gltexture->setSyncState(gpu::gl::GLSyncState::Transferred); @@ -161,7 +161,7 @@ bool GLTextureTransferHelper::process() { if (!_transferringTextures.empty()) { // Don't saturate the GPU - glFinish(); + clientWait(); } else { // Don't saturate the CPU QThread::msleep(1); diff --git a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp index db8186221c..871a2c8a03 100644 --- a/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl45/GL45BackendTexture.cpp @@ -32,25 +32,6 @@ GLTexture* GL45Backend::syncGPUObject(const TexturePointer& texture, bool transf return GL45Texture::sync(*this, texture, transfer); } -void serverWait() { - auto fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); - assert(fence); - glWaitSync(fence, 0, GL_TIMEOUT_IGNORED); - glDeleteSync(fence); -} - -void clientWait() { - auto fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); - assert(fence); - auto result = glClientWaitSync(fence, GL_SYNC_FLUSH_COMMANDS_BIT, 0); - while (GL_TIMEOUT_EXPIRED == result || GL_WAIT_FAILED == result) { - // Minimum sleep - QThread::usleep(1); - result = glClientWaitSync(fence, 0, 0); - } - glDeleteSync(fence); -} - TransferState::TransferState(GLTexture& texture) : _texture(texture) { }