From 1e7dd7db6408fa9f2020f239e9ea28ebd8022334 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 10 Oct 2016 12:57:58 -0700 Subject: [PATCH 1/2] Fix GPU texture counter, better logging for memory pressure --- libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 1 - libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index c082c00609..3c34765011 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -666,7 +666,6 @@ void GLBackend::recycle() const { for (auto pair : externalTexturesTrash) { auto fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); pair.second(pair.first, fence); - decrementTextureGPUCount(); } } diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index 649065ab84..25c92b513a 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -115,7 +115,7 @@ float GLTexture::getMemoryPressure() { if (freeGpuMemory != lastFreeGpuMemory) { lastFreeGpuMemory = freeGpuMemory; if (freePercentage < MIN_FREE_GPU_MEMORY_PERCENTAGE) { - qDebug() << "Exceeded max GPU memory"; + qCDebug(gpugllogging) << "Exceeded min free GPU memory " << freePercentage; return OVER_MEMORY_PRESSURE; } } @@ -129,7 +129,13 @@ float GLTexture::getMemoryPressure() { // Return the consumed texture memory divided by the available texture memory. auto consumedGpuMemory = Context::getTextureGPUMemoryUsage(); - return (float)consumedGpuMemory / (float)availableTextureMemory; + float memoryPressure = (float)consumedGpuMemory / (float)availableTextureMemory; + static Context::Size lastConsumedGpuMemory = 0; + if (memoryPressure > 1.0f && lastConsumedGpuMemory != consumedGpuMemory) { + lastConsumedGpuMemory = consumedGpuMemory; + qCDebug(gpugllogging) << "Exceeded max allowed texture memory: " << consumedGpuMemory << " / " << availableTextureMemory; + } + return memoryPressure; } From 8f42e564b4eb7ec51614f85cea52a428b8ec9d3d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 11 Oct 2016 16:34:54 -0700 Subject: [PATCH 2/2] Disable 'min free GPU memory', bump max texture memory 65% --- libraries/gpu-gl/src/gpu/gl/GLTexture.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp index 25c92b513a..1caecb0b72 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLTexture.cpp @@ -20,9 +20,20 @@ std::shared_ptr GLTexture::_textureTransferHelper; // FIXME placeholder for texture memory over-use #define DEFAULT_MAX_MEMORY_MB 256 -#define MIN_FREE_GPU_MEMORY_PERCENTAGE 0.25f #define OVER_MEMORY_PRESSURE 2.0f +// FIXME other apps show things like Oculus home consuming large amounts of GPU memory +// which causes us to blur textures needlessly (since other app GPU memory usage will likely +// be swapped out and not cause any actual impact +//#define CHECK_MIN_FREE_GPU_MEMORY +#ifdef CHECK_MIN_FREE_GPU_MEMORY +#define MIN_FREE_GPU_MEMORY_PERCENTAGE 0.25f +#endif + +// Allow 65% of all available GPU memory to be consumed by textures +// FIXME overly conservative? +#define MAX_CONSUMED_TEXTURE_MEMORY_PERCENTAGE 0.65f + const GLenum GLTexture::CUBE_FACE_LAYOUT[6] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, @@ -107,6 +118,7 @@ float GLTexture::getMemoryPressure() { // If we can't query the dedicated memory just use a fallback fixed value of 256 MB totalGpuMemory = MB_TO_BYTES(DEFAULT_MAX_MEMORY_MB); } else { +#ifdef CHECK_MIN_FREE_GPU_MEMORY // Check the global free GPU memory auto freeGpuMemory = getFreeDedicatedMemory(); if (freeGpuMemory) { @@ -120,11 +132,10 @@ float GLTexture::getMemoryPressure() { } } } +#endif } - // Allow 50% of all available GPU memory to be consumed by textures - // FIXME overly conservative? - availableTextureMemory = (totalGpuMemory >> 1); + availableTextureMemory = static_cast(totalGpuMemory * MAX_CONSUMED_TEXTURE_MEMORY_PERCENTAGE); } // Return the consumed texture memory divided by the available texture memory.