Developing Games on Intel Graphics
If you are gaming on graphics integrated in your Intel Processor, this is the place for you! Find answers to your questions or post your issues with PC games
507 Discussions

programmatic query of video memory?

heppe
Beginner
1,945 Views

We need to know the amount of video memory on the graphics card. That allows us to calibrate the cumulative size of all device objects (vertex buffers, index buffers, frame buffers and textures) that we cansafely allocating before we run into stability and performance issues. We have some code that does it on XP, but need to come up with something for vista. An ATI developer guy recommended using the opengl command,

glgetintegerv(GL_VBO_FREE_MEMORY_ATI)
Is that supported on Intel express chipsets?  Can it be trusted?  If not (on either question), what alternatives are available?  Is there anything that can be pulled out of the windows registry?
Thanks,
Travis
0 Kudos
8 Replies
Chuck_De_Sylva
Beginner
1,945 Views
Do you have to use Ogl? Because there are Dx calls to easily do this.
0 Kudos
heppe
Beginner
1,945 Views

We can't (yet) assume that dx10 will be available, so IDXGIAdapter::GetDesc() is out, and

IDirect3DDevice9::GetAvailableTextureMem() lumps system memory in as well, making it less than useful.  
If it were available somewhere in the windows registry (as it is on XP), that would be ideal.
We can switch back and forth from ogl and d3d at our users' option, so we need a solution for both.
-Travis
0 Kudos
Chuck_De_Sylva
Beginner
1,945 Views
Can you use Device.GetAvailableVideoMemory(SurfaceCaps, Int32, Int32) Method from Dx10?
0 Kudos
levicki
Valued Contributor I
1,945 Views

Since when Intel IGP supports DX10 API? By the way, that is a horrible way to find out the amount of video memory — it takes a lot of time to initialize DirectX and they are clearly using OpenGL so why should they require two APIs for the application to work?

If this is a Windows application perhaps this would work:

#include 
#include 

const char *str_key1 = { "HARDWAREDEVICEMAPVIDEO" };
const char *str_key2 = { "DeviceVideo0" };
const char *str_key3 = { "systemcurrentcontrolset" };
const char *str_key4 = { "HardwareInformation.MemorySize" };

DWORD GetVideoMemorySizeBytes(void)
{
	LONG	s;
	HKEY	key;
	DWORD	type, buf_size, rv = 0;
	LPBYTE	buf;
	char	*ptr;

	s = RegOpenKeyEx(HKEY_LOCAL_MACHINE, str_key1, 0, KEY_READ, &key);

	if (s != ERROR_SUCCESS) {
		goto bail_out;
	}

	type = REG_SZ;

	s = RegQueryValueEx(key, str_key2, NULL, &type, NULL, &buf_size);

	if (s != ERROR_SUCCESS) {
		goto bail_out;
	}

	buf = (LPBYTE)malloc(buf_size);

	if (buf == NULL) {
		goto bail_out;
	}

	s = RegQueryValueEx(key, str_key2, NULL, &type, buf, &buf_size);

	if (s != ERROR_SUCCESS) {
		goto bail_out;
	}

	RegCloseKey(key);

	ptr = strstr(strlwr((char*)buf), str_key3);

	s = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ptr, 0, KEY_READ, &key);

	if (s != ERROR_SUCCESS) {
		goto bail_out;
	}

	type = REG_BINARY;
	buf_size = 4;

	s = RegQueryValueEx(key, str_key4, NULL, &type, (LPBYTE)&rv, &buf_size);

bail_out:
	if (buf != NULL) {
		free(buf);
	}
	if (key != NULL) {
		RegCloseKey(key);
	}

	return rv;
}

int main(int argc, char *argv[])
{
	printf("Video memory size : %ld bytes
", GetVideoMemorySizeBytes());
}
0 Kudos
7oby
New Contributor II
1,945 Views
IgorLevicki:
Since when Intel IGP supports DX10 API?


Since 15.9 (v7.15.10.1472) released 04/25/2008 or the former non-public 15.9 beta.

0 Kudos
levicki
Valued Contributor I
1,945 Views

I see, nice to know that.

Still, using DX10 API just to query video memory size would limit the application use only to those systems running Vista, so it is a pretty senseless suggestion anyway.

0 Kudos
heppe1
Beginner
1,945 Views

In addition to OpenGL, we also support dx9 and plan to start a dx10 (or perhaps dx11) implementation soon. When dx9 or dx10 is already in use, we can use such calls. Pulling in another API (dx10, or even dx9 for that matter) just to query video memory size is not a good solution. We'll hardcode a budget for ourselves rather than do something like that.

Of course, if we can get a solution within OpenGL, that would be the best solution of all.

-Travis

0 Kudos
jc_denton
Beginner
1,945 Views
Quoting - Igor Levicki

Since when Intel IGP supports DX10 API? By the way, that is a horrible way to find out the amount of video memory - it takes a lot of time to initialize DirectX and they are clearly using OpenGL so why should they require two APIs for the application to work?

If this is a Windows application perhaps this would work:

#include 
#include 

const char *str_key1 = { "HARDWAREDEVICEMAPVIDEO" };
const char *str_key2 = { "DeviceVideo0" };
const char *str_key3 = { "systemcurrentcontrolset" };
const char *str_key4 = { "HardwareInformation.MemorySize" };

DWORD GetVideoMemorySizeBytes(void)
{
	LONG	s;
	HKEY	key;
	DWORD	type, buf_size, rv = 0;
	LPBYTE	buf;
	char	*ptr;

......
......
......

Thanks for the post first of all. My goal was to gain performance improvement & stability, by making system specific resource caching decisions in our game. Above code snippet turned out really helpful. However, I had to modify it a little to get working since there could be more than one REG_DWORDs that you need to iterate through to get the location of hardware information section. I posting the modified version of above code snippet that has been tested to work with vista as welll as with XP.



#include
#include

const char *strConstHwDeviceMapVideo = { "HARDWARE\DEVICEMAP\VIDEO" };
const char *strConstMaxObjectNumber = { "MaxObjectNumber" };
const char *strConstSystemCurrentControlSet = { "system\currentcontrolset" };
const char *strConstHwInfoMemSize = { "HardwareInformation.MemorySize" };

DWORD GetVideoMemorySizeBytes(void)
{
LONG s;
HKEY key, key2 = NULL;
DWORD type, buf_size, rv = 0, iMaxObjectNumber = 0;
LPBYTE buf = NULL;
char *ptr = NULL;
char strDeviceVideo[20] = { "\Device\Video0" };

s = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strConstHwDeviceMapVideo, 0, KEY_READ, &key);


if (s != ERROR_SUCCESS) {
goto bail_out;
}

// Find total number of obects to be queried
type = REG_DWORD;
buf_size = 4;

s = RegQueryValueEx(key, strConstMaxObjectNumber, NULL, &type, ( LPBYTE )&iMaxObjectNumber, &buf_size );

if (s != ERROR_SUCCESS) {
goto bail_out;
}

for( int i = 0; i <= (int)iMaxObjectNumber; i++ )
{
strDeviceVideo[ 13 ] = '0' + i;
type = REG_SZ;

s = RegQueryValueEx(key, strDeviceVideo, NULL, &type, NULL, &buf_size);

if (s != ERROR_SUCCESS) {
goto bail_out;
}


if( NULL != buf ) {
free( buf );
}

buf = (LPBYTE)malloc(buf_size);

if (buf == NULL) {
goto bail_out;
}

s = RegQueryValueEx(key, strDeviceVideo, NULL, &type, buf, &buf_size);

if (s != ERROR_SUCCESS) {
goto bail_out;
}

ptr = strstr( _strlwr((char*)buf), strConstSystemCurrentControlSet );

if( NULL == ptr )
continue;

s = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ptr, 0, KEY_READ, &key2);

if (s != ERROR_SUCCESS) {
goto bail_out;
}

type = REG_BINARY;
buf_size = 4;

s = RegQueryValueEx(key2, strConstHwInfoMemSize, NULL, &type, (LPBYTE)&rv, &buf_size);

if ( ERROR_SUCCESS == s ) {
break;
}

if (key != NULL) {
RegCloseKey(key2);
}
}

bail_out:
if (buf != NULL) {
free(buf);
}

if (key != NULL) {
RegCloseKey(key);
}

if (key != NULL) {
RegCloseKey(key2);
}

return rv;
}


int _tmain(int argc, _TCHAR* argv[])
{
printf("Video memory size : %ld bytes", GetVideoMemorySizeBytes());
return 0;
}

0 Kudos
Reply