diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 8e2eb8409..52bda8576 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -865,6 +865,12 @@ public: * get the official name of the driver */ virtual const char *getVideocardInformation () = 0; + + /** + * Get total video memory. + * get the amount of video memory of current adapter, result is in KiB, -1 if unable to determine + */ + virtual sint getTotalVideoMemory () const = 0; // @} @@ -1342,6 +1348,7 @@ public: uint32 DeviceId; uint32 SubSysId; uint32 Revision; + sint32 VideoMemory; // video memory in KiB, -1 if unable to determine }; // Get the number of hardware renderer available on the client platform. diff --git a/code/nel/include/nel/3d/driver_user.h b/code/nel/include/nel/3d/driver_user.h index 761a03114..62c6fd6db 100644 --- a/code/nel/include/nel/3d/driver_user.h +++ b/code/nel/include/nel/3d/driver_user.h @@ -412,6 +412,7 @@ public: virtual uint32 getImplementationVersion () const; virtual const char* getDriverInformation (); virtual const char* getVideocardInformation (); + virtual sint getTotalVideoMemory () const; virtual uint getNbTextureStages(); virtual void getWindowSize (uint32 &width, uint32 &height); virtual uint getWindowWidth (); diff --git a/code/nel/include/nel/3d/u_driver.h b/code/nel/include/nel/3d/u_driver.h index f880c9f47..0500192ad 100644 --- a/code/nel/include/nel/3d/u_driver.h +++ b/code/nel/include/nel/3d/u_driver.h @@ -505,6 +505,12 @@ public: */ virtual const char* getVideocardInformation () = 0; + /** + * Get total video memory. + * get the amount of video memory of current adapter, result is in KiB, -1 if unable to determine + */ + virtual sint getTotalVideoMemory () const = 0; + /// Get the number of texture stage available, for multitexturing (Normal material shaders). Valid only after setDisplay(). virtual uint getNbTextureStages() = 0; diff --git a/code/nel/src/3d/driver.cpp b/code/nel/src/3d/driver.cpp index f6fa074f0..9bd23f815 100644 --- a/code/nel/src/3d/driver.cpp +++ b/code/nel/src/3d/driver.cpp @@ -32,7 +32,7 @@ namespace NL3D { // *************************************************************************** -const uint32 IDriver::InterfaceVersion = 0x6f; // getters for anisotropic filter +const uint32 IDriver::InterfaceVersion = 0x70; // total video memory // *************************************************************************** IDriver::IDriver() : _SyncTexDrvInfos( "IDriver::_SyncTexDrvInfos" ) diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp index fb310bd7d..23ed1bedc 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -2381,6 +2381,7 @@ bool CDriverD3D::getAdapter(uint adapter, IDriver::CAdapter &desc) const desc.Revision = identifier.Revision; desc.SubSysId = identifier.SubSysId; desc.VendorId = identifier.VendorId; + desc.VideoMemory = _Adapter == _adapter ? getTotalVideoMemory():-1; return true; } } @@ -2874,6 +2875,17 @@ const char *CDriverD3D::getVideocardInformation () // *************************************************************************** +sint CDriverD3D::getTotalVideoMemory () const +{ + H_AUTO_D3D(CDriverD3D_getTotalVideoMemory); + + // Can't use _DeviceInterface->GetAvailableTextureMem() because it's not reliable + // Returns 4 GiB instead of 2 with my GPU + return -1; +} + +// *************************************************************************** + void CDriverD3D::getBuffer (CBitmap &bitmap) { H_AUTO_D3D(CDriverD3D_getBuffer); diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index 830694a42..4dd215c9b 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -900,6 +900,7 @@ public: virtual uint32 getImplementationVersion () const; virtual const char* getDriverInformation (); virtual const char* getVideocardInformation (); + virtual sint getTotalVideoMemory () const; virtual CVertexBuffer::TVertexColorType getVertexColorFormat() const; // Textures diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 3539948ac..d1e1446e5 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1199,6 +1199,105 @@ const char *CDriverGL::getVideocardInformation () return name; } +sint CDriverGL::getTotalVideoMemory() const +{ + H_AUTO_OGL(CDriverGL_getTotalVideoMemory); + + if (_Extensions.NVXGPUMemoryInfo) + { + GLint memoryInKiB = 0; + glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &memoryInKiB); + + nlinfo("3D: GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX returned %d KiB", memoryInKiB); + return memoryInKiB; + } + + if (_Extensions.ATIMeminfo) + { + GLint memoryInKiB = 0; + glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, &memoryInKiB); + + nlinfo("3D: GL_TEXTURE_FREE_MEMORY_ATI returned %d KiB", memoryInKiB); + return memoryInKiB; + } + +#if defined(NL_OS_WINDOWS) + if (_Extensions.WGLAMDGPUAssociation) + { + GLuint uNoOfGPUs = nwglGetGPUIDsAMD(0, 0); + GLuint *uGPUIDs = new GLuint[uNoOfGPUs]; + nwglGetGPUIDsAMD(uNoOfGPUs, uGPUIDs); + + GLuint memoryInMiB = 0; + nwglGetGPUInfoAMD(uGPUIDs[0], WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(GLuint), &memoryInMiB); + + delete [] uGPUIDs; + + nlinfo("3D: WGL_GPU_RAM_AMD returned %d MiB", memoryInMiB); + return memoryInMiB * 1024; + } +#elif defined(NL_OS_MAC) + GLint rendererID; + + // get current renderer ID + CGLError error = CGLGetParameter([_ctx CGLContextObj], kCGLCPCurrentRendererID, &rendererID); + + if (error == kCGLNoError) + { + GLint nrend = 0; + CGLRendererInfoObj rend; + + // get renderer info for all renderers + error = CGLQueryRendererInfo(0xffffffff, &rend, &nrend); + + if (error == kCGLNoError) + { + for (GLint i = 0; i < nrend; ++i) + { + GLint thisRendererID; + error = CGLDescribeRenderer(rend, i, kCGLRPRendererID, &thisRendererID); + + if (error == kCGLNoError) + { + // see if this is the one we want + if (thisRendererID == rendererID) + { + GLint memoryInMiB = 0; + CGLError error = CGLDescribeRenderer(rend, i, kCGLRPVideoMemoryMegabytes, &memoryInMiB); + + if (error == kCGLNoError) + { + // convert in KiB + return memoryInMiB * 1024; + } + else + { + nlerror("3D: Unable to get video memory (%s)", CGLErrorString(error)); + } + } + } + else + { + nlerror("3D: Unable to get renderer ID (%s)", CGLErrorString(error)); + } + } + + CGLDestroyRendererInfo(rend); + } + else + { + nlerror("3D: Unable to get renderers info (%s)", CGLErrorString(error)); + } + } + else + { + nlerror("3D: Unable to get current renderer ID (%s)", CGLErrorString(error)); + } +#endif + + return -1; +} + bool CDriverGL::clipRect(NLMISC::CRect &rect) { H_AUTO_OGL(CDriverGL_clipRect) @@ -2546,6 +2645,7 @@ bool CDriverGL::getAdapter(uint adapter, CAdapter &desc) const desc.Revision = 0; desc.SubSysId = 0; desc.VendorId = 0; + desc.VideoMemory = getTotalVideoMemory(); return true; } return false; diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index 6affa6929..cb4b00b46 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -520,6 +520,8 @@ public: virtual const char* getVideocardInformation (); + virtual sint getTotalVideoMemory() const; + virtual bool isActive (); virtual uint8 getBitPerPixel (); 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 7342b3efc..700780077 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp @@ -1790,44 +1790,7 @@ void registerGlExtensions(CGlExtensions &ext) #ifndef USE_OPENGLES ext.NVXGPUMemoryInfo = setupNVXGPUMemoryInfo(glext); - - if (ext.NVXGPUMemoryInfo) - { - GLint nEvictionCount = 0; -#ifdef GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX, &nEvictionCount); -#endif - - GLint nEvictionMemory = 0; -#ifdef GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX, &nEvictionMemory); -#endif - - GLint nDedicatedMemoryInKB = 0; -#ifdef GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &nDedicatedMemoryInKB); -#endif - - GLint nTotalMemoryInKB = 0; -#ifdef GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &nTotalMemoryInKB); -#endif - - GLint nCurAvailMemoryInKB = 0; -#ifdef GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &nCurAvailMemoryInKB); -#endif - - 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 } @@ -1999,18 +1962,6 @@ bool registerWGlExtensions(CGlExtensions &ext, HDC hDC) 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; - } - ext.WGLNVGPUAffinity = setupWGLNVGPUAssociation(glext); if (ext.WGLNVGPUAffinity) diff --git a/code/nel/src/3d/driver_user.cpp b/code/nel/src/3d/driver_user.cpp index 457197d70..812bb52a9 100644 --- a/code/nel/src/3d/driver_user.cpp +++ b/code/nel/src/3d/driver_user.cpp @@ -1534,6 +1534,12 @@ const char* CDriverUser::getVideocardInformation () return _Driver->getVideocardInformation (); } +sint CDriverUser::getTotalVideoMemory () const +{ + NL3D_HAUTO_UI_DRIVER; + + return _Driver->getTotalVideoMemory (); +} uint CDriverUser::getNbTextureStages() { NL3D_HAUTO_UI_DRIVER;