mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-11 03:54:48 +00:00
Changed: Add getTotalVideoMemory to IDriver to query total video memory
This commit is contained in:
parent
f57f90d455
commit
7ece7353e1
10 changed files with 136 additions and 50 deletions
|
@ -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.
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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" )
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -520,6 +520,8 @@ public:
|
|||
|
||||
virtual const char* getVideocardInformation ();
|
||||
|
||||
virtual sint getTotalVideoMemory() const;
|
||||
|
||||
virtual bool isActive ();
|
||||
|
||||
virtual uint8 getBitPerPixel ();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue