From d8050634f6eb325ff5b361f359a06da60d894c0c Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Thu, 7 Jul 2016 22:02:10 +0200 Subject: [PATCH] gsdx ogl: plug GL_NVX_gpu_memory_info and GL_ATI_meminfo to query available memory on the GPU Requirement * dedicated GPU (ofc!) * proprietary driver. Free driver supports r600, radeonsi --- plugins/GSdx/GLLoader.cpp | 5 +++++ plugins/GSdx/GLLoader.h | 2 ++ plugins/GSdx/GSDeviceOGL.cpp | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/plugins/GSdx/GLLoader.cpp b/plugins/GSdx/GLLoader.cpp index 7f5badecf7..ff4b49b171 100644 --- a/plugins/GSdx/GLLoader.cpp +++ b/plugins/GSdx/GLLoader.cpp @@ -208,6 +208,9 @@ namespace GLLoader { bool found_GL_ARB_gpu_shader5 = false; // Require IvyBridge bool found_GL_ARB_shader_image_load_store = false; // Intel IB. Nvidia/AMD miss Mesa implementation. bool found_GL_ARB_viewport_array = false; // Intel IB. AMD/NVIDIA DX10 + // Bonus to monitor the VRAM + bool found_GL_NVX_gpu_memory_info = false; + bool found_GL_ATI_meminfo = false; // Mandatory bool found_GL_ARB_buffer_storage = false; @@ -305,6 +308,8 @@ namespace GLLoader { string ext((const char*)glGetStringi(GL_EXTENSIONS, i)); // Bonus if (ext.compare("GL_EXT_texture_filter_anisotropic") == 0) found_GL_EXT_texture_filter_anisotropic = true; + if (ext.compare("GL_NVX_gpu_memory_info") == 0) found_GL_NVX_gpu_memory_info = true; + if (ext.compare("GL_ATI_meminfo") == 0) found_GL_ATI_meminfo = true; // GL4.0 if (ext.compare("GL_ARB_gpu_shader5") == 0) found_GL_ARB_gpu_shader5 = true; if (ext.compare("GL_ARB_draw_buffers_blend") == 0) found_GL_ARB_draw_buffers_blend = true; diff --git a/plugins/GSdx/GLLoader.h b/plugins/GSdx/GLLoader.h index 0bde209d4c..f53215a788 100644 --- a/plugins/GSdx/GLLoader.h +++ b/plugins/GSdx/GLLoader.h @@ -354,4 +354,6 @@ namespace GLLoader { extern bool found_GL_ARB_clear_texture; extern bool found_GL_ARB_direct_state_access; extern bool found_GL_EXT_texture_filter_anisotropic; + extern bool found_GL_NVX_gpu_memory_info; + extern bool found_GL_ATI_meminfo; } diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 9328ecc8cd..bab9834723 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -486,6 +486,25 @@ bool GSDeviceOGL::Create(GSWnd* wnd) PboPool::Init(); } + // **************************************************************** + // Get Available Memory + // **************************************************************** + GLint vram[4] = {0}; + if (GLLoader::found_GL_NVX_gpu_memory_info) { + glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, vram); + } else if (GLLoader::found_GL_ATI_meminfo) { + // Why openGL is always that complicated ! + //glGetIntegerv(GL_RENDERBUFFER_FREE_MEMORY_ATI, vram); + glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, vram); + } else { + fprintf(stdout, "No extenstion supported to get available memory. Use default value !\n"); + } + + if (vram[0] > 0) + GLState::available_vram = (uint64)vram[0] * 1024ul; + + fprintf(stdout, "Available VRAM:%lluMB\n", GLState::available_vram >> 20u); + // **************************************************************** // Finish window setup and backbuffer // ****************************************************************