From 66cf9a41fb51346eaa23173ae9a12eec04a434ae Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 26 Mar 2014 14:34:07 +0100 Subject: [PATCH] Changed: Detect available video memory with OpenGL extensions --- .../driver/opengl/driver_opengl_extension.cpp | 80 +++++++++++++++++++ .../driver/opengl/driver_opengl_extension.h | 18 +++++ 2 files changed, 98 insertions(+) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp index 9ee14ea6b..3ded67d62 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp @@ -1474,6 +1474,22 @@ static bool setupPackedDepthStencil(const char *glext) return true; } +// *************************************************************************** +static bool setupNVXGPUMemoryInfo(const char *glext) +{ + H_AUTO_OGL(setupNVXGPUMemoryInfo); + CHECK_EXT("GL_NVX_gpu_memory_info"); + return true; +} + +// *************************************************************************** +static bool setupATIMeminfo(const char *glext) +{ + H_AUTO_OGL(setupATIMeminfo); + CHECK_EXT("GL_ATI_meminfo"); + return true; +} + // *************************************************************************** // Extension Check. void registerGlExtensions(CGlExtensions &ext) @@ -1689,6 +1705,35 @@ void registerGlExtensions(CGlExtensions &ext) ext.ATIMapObjectBuffer = false; ext.ATIVertexAttribArrayObject = false; } + +#ifndef USE_OPENGLES + ext.NVXGPUMemoryInfo = setupNVXGPUMemoryInfo(glext); + + if (ext.NVXGPUMemoryInfo) + { +// GPU_MEMORY_INFO_EVICTION_COUNT_NVX; +// GPU_MEMORY_INFO_EVICTED_MEMORY_NVX; + + GLint nDedicatedMemoryInKB = 0; + glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &nDedicatedMemoryInKB); + + GLint nTotalMemoryInKB = 0; + glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &nTotalMemoryInKB); + + GLint nCurAvailMemoryInKB = 0; + glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &nCurAvailMemoryInKB); + + nlinfo("Memory: total: %d available: %d dedicated: %d", nTotalMemoryInKB, nCurAvailMemoryInKB, nDedicatedMemoryInKB); + } + + ext.ATIMeminfo = setupATIMeminfo(glext); + + if (ext.ATIMeminfo) + { + GLint nCurAvailMemoryInKB = 0; + glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, &nCurAvailMemoryInKB); + } +#endif } @@ -1708,6 +1753,27 @@ static bool setupWGLEXTSwapControl(const char *glext) return true; } +// *************************************************************************** +static bool setupWGLAMDGPUAssociation(const char *glext) +{ + H_AUTO_OGL(setupWGLAMDGPUAssociation); + CHECK_EXT("WGL_AMD_gpu_association"); + +#if !defined(USE_OPENGLES) && defined(NL_OS_WINDOWS) + CHECK_ADDRESS(PFNWGLGETGPUIDSAMDPROC, wglGetGPUIDsAMD); + CHECK_ADDRESS(PFNWGLGETGPUINFOAMDPROC, wglGetGPUInfoAMD); + CHECK_ADDRESS(PFNWGLGETCONTEXTGPUIDAMDPROC, wglGetContextGPUIDAMD); + CHECK_ADDRESS(PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC, wglCreateAssociatedContextAMD); + CHECK_ADDRESS(PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC, wglCreateAssociatedContextAttribsAMD); + CHECK_ADDRESS(PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC, wglDeleteAssociatedContextAMD); + CHECK_ADDRESS(PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC, wglMakeAssociatedContextCurrentAMD); + CHECK_ADDRESS(PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC, wglGetCurrentAssociatedContextAMD); + CHECK_ADDRESS(PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC, wglBlitContextFramebufferAMD); +#endif + + return true; +} + // ********************************* static bool setupGLXEXTSwapControl(const char *glext) { @@ -1820,6 +1886,20 @@ bool registerWGlExtensions(CGlExtensions &ext, HDC hDC) // Check for swap control ext.WGLEXTSwapControl= setupWGLEXTSwapControl(glext); + ext.WGLAMDGPUAssociation = setupWGLAMDGPUAssociation(glext); + + if (ext.WGLAMDGPUAssociation) + { + GLuint uNoOfGPUs = nwglGetGPUIDsAMD(0, 0); + GLuint *uGPUIDs = new GLuint[uNoOfGPUs]; + nwglGetGPUIDsAMD(uNoOfGPUs, uGPUIDs); + + GLuint uTotalMemoryInMB = 0; + nwglGetGPUInfoAMD(uGPUIDs[0], WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(GLuint), &uTotalMemoryInMB); + + delete [] uGPUIDs; + } + return true; } #elif defined(NL_OS_MAC) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_extension.h b/code/nel/src/3d/driver/opengl/driver_opengl_extension.h index 7a20d6896..938473029 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_extension.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl_extension.h @@ -109,6 +109,17 @@ struct CGlExtensions bool OESDrawTexture; bool OESMapBuffer; + // extensions to get memory info + + // GL_NVX_gpu_memory_info + bool NVXGPUMemoryInfo; + + // GL_ATI_meminfo + bool ATIMeminfo; + + // WGL_AMD_gpu_association + bool WGLAMDGPUAssociation; + public: /// \name Disable Hardware feature. False by default. setuped by IDriver @@ -175,6 +186,10 @@ public: OESDrawTexture = false; OESMapBuffer = false; + NVXGPUMemoryInfo = false; + ATIMeminfo = false; + WGLAMDGPUAssociation = false; + /// \name Disable Hardware feature. False by default. setuped by IDriver DisableHardwareVertexProgram= false; DisableHardwarePixelProgram= false; @@ -224,12 +239,15 @@ public: result += NVOcclusionQuery ? "NVOcclusionQuery " : ""; result += NVStateVARWithoutFlush ? "NVStateVARWithoutFlush " : ""; result += ARBMultisample ? "ARBMultisample " : ""; + result += NVXGPUMemoryInfo ? "NVXGPUMemoryInfo " : ""; + result += ATIMeminfo ? "ATIMeminfo " : ""; #ifdef NL_OS_WINDOWS result += "\n WindowsGL: "; result += WGLARBPBuffer ? "WGLARBPBuffer " : ""; result += WGLARBPixelFormat ? "WGLARBPixelFormat " : ""; result += WGLEXTSwapControl ? "WGLEXTSwapControl " : ""; + result += WGLAMDGPUAssociation ? "WGLAMDGPUAssociation " : ""; #elif defined(NL_OS_MAC) #elif defined(NL_OS_UNIX) result += "\n GLX: ";