video memory usage

Posted By: pegamode

video memory usage - 09/20/10 06:50

Hi,

is there a way to get the overall video memory usage?

I know there are some d3d_ commands, but:

1) d3d_texfree

I'm not sure if it's a bug, but even when starting just an empty main.c "d3d_textfree" always returns a negative value (e.g. -19532830) though in the manual is said that the value should be higher than 0. (I've tested it with the latest A7 Pro and A8 Pro)

2) d3d_texbmaps, d3d_texskins, d3d_texsmaps, d3d_texsurfs

The manual says:

"Due to swapping and compression, the total value can be remarkably higher than the amount of video memory available on the 3D card."

Hmm ... so how can I interpret those values?

Is there any chance to get NVIDIA PerfHud running using lite-c? (http://developer.nvidia.com/object/nvperfhud_home.html) I haven't found the time to get a closer look at PerfHud, but I'm not sure if the binding code can be used in lite-c.

Regards,
Pegamode.
Posted By: jcl

Re: video memory usage - 09/20/10 07:05

A variable gets a negative value when the var range is exceeded. So as long as d3d_texfree is below 0, you have at least 1 GB video memory left.

We'll probably replace it with a long variable in a future version, as well as other memory variables.
Posted By: pegamode

Re: video memory usage - 09/20/10 07:11

Is there any way to get the "real" value (e.g. read something from directX into a string)?

Currently it would be hard to do something like this:

Code:
if (d3d_texfree < 10000) {
 // do something
}



I could do it like this:

Code:
if (d3d_texfree < 10000 && d3d_texfree >= 0) {
 // do something
}



But it's not a nice code.

But it would be more interesting to get the value how much video memory is in use instead of the value how much video memory is left, because this value would be independent from the gfx-card.

Is there any way to get good values? Maybe from DirectX?

Posted By: jcl

Re: video memory usage - 09/20/10 07:50

Sure:

long mem = ((LPDIRECT3DDEVICE9)pd3ddev)->GetAvailableTextureMem();
printf("Memory at start: %i",mem);
...
long mem_used = mem - ((LPDIRECT3DDEVICE9)pd3ddev)->GetAvailableTextureMem();
printf("Memory used: %i",mem_used);

GetAvailableTextureMem() is the same as d3d_texfree.
Posted By: pegamode

Re: video memory usage - 09/20/10 09:36

Thanks ... that will help a lot.
Posted By: MCKiller

Re: video memory usage - 09/20/10 11:37

I tried that with the following code:

Code:
#include <acknex.h>
#include <d3d9.h>


FONT* standard_font 	= "Arial#20b";
STRING* memo 		= "not available";

TEXT* dx =
{
  layer = 1;
  pos_x = 400;
  pos_y = 100;
  font  = standard_font;
  string = memo;
  flags = CENTER_X | TRANSLUCENT | SHOW;
	
}

void main() {

	video_mode 	=  8;	
	video_depth 	= 32;		
	fps_max		= 60;
	d3d_texdepth 	=  4;	
	
	
	STRING* tmp	="0";
	
	level_load(NULL);
		
	while(1){
		
		LPDIRECT3DDEVICE9 pd3dDev;
     	        pd3dDev = (LPDIRECT3DDEVICE9)draw_begin();
   
     	        if (!pd3dDev) return;
	
		long mem = (LPDIRECT3DDEVICE9)pd3dDev)->GetAvailableTextureMem();
		
		//printf("freeTextureMem: %i",mem);
	
		str_for_int(tmp,mem);
		str_cpy(memo,tmp);
	
		wait(1);	
	}
	
}



The result is: -1360003072

MSDN says that GetAvailableTextureMem() returns the values in Megabytes?!?

So maybe there is something strange....
Posted By: pegamode

Re: video memory usage - 09/20/10 19:32

I overworked MCKiller's code a bit, but I also get this negative value (btw. the same as if I use d3d_texfree).

The code I use:

Code:
#include <acknex.h>
#include <d3d9.h>

void main() {
	video_mode 	 =  8;	
	video_depth  = 32;		
	fps_max		 = 60;
	d3d_texdepth =  4;			
	
	level_load(NULL);
	wait(1);
		
	LPDIRECT3DDEVICE9 pd3dDev = (LPDIRECT3DDEVICE9)draw_begin();   
    if (!pd3dDev) sys_exit("-1");
				
	while(1){					
		long mem = pd3dDev->GetAvailableTextureMem();				
		draw_text(str_printf(NULL, "freemem: %d",mem),10,10,COLOR_RED);				
		wait(1);	
	}	
}



Any hint???

Regards,
Pegamode.
Posted By: pegamode

Re: video memory usage - 09/20/10 19:43

I changed the draw_text line from

Code:
draw_text(str_printf(NULL, "freemem: %d",mem),10,10,COLOR_RED);



to

Code:
draw_text(str_printf(NULL, "freemem: %u",mem),10,10,COLOR_RED);



The value I see now could be the right one ... I will check it out a little further.
Posted By: MCKiller

Re: video memory usage - 09/20/10 20:01

For me, too.
That make sense. In the MSDN for directx they use an UINT.
© 2024 lite-C Forums