Merge pull request #8770 from jherico/textures_tweak

Fix GPU texture counter, better logging for memory pressure
This commit is contained in:
Brad Hefta-Gaub 2016-10-11 21:36:03 -07:00 committed by GitHub
commit 8e8eba5e0c
2 changed files with 23 additions and 7 deletions

View file

@ -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();
}
}

View file

@ -20,9 +20,20 @@ std::shared_ptr<GLTextureTransferHelper> 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) {
@ -115,21 +127,26 @@ 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;
}
}
}
#endif
}
// Allow 50% of all available GPU memory to be consumed by textures
// FIXME overly conservative?
availableTextureMemory = (totalGpuMemory >> 1);
availableTextureMemory = static_cast<gpu::Size>(totalGpuMemory * MAX_CONSUMED_TEXTURE_MEMORY_PERCENTAGE);
}
// 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;
}