#### Archived

This topic is now archived and is closed to further replies.

# Video memory usage

This topic is 5156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How to check free video memory? Thanks.

Not possible.

##### Share on other sites
Let me elaborate. It is not possible, nor is it neccessary. Whether you are using OpenGL or Direct3D, you don''t talk directly to the video card. You always talk to the driver, and it is the driver''s responsibility to make put things in the proper memory. If video memory fills up, the driver will start putting things in AGP memory. If AGP fills up or is not available, it will start looking at system memory, and so on. Your only responsibility is to keep your resources within a reasonable limit. Almost any card made within the last year or so will have at least 64 megs. So if you want to target newer machines and be in a safe limit, keep your resources at around 64 megs. If you want to support even older machines (TNT2), keep it around 32 megs.

##### Share on other sites
"Almost any card made within the last year or so will have at least 64 megs. So if you want to target newer machines and be in a safe limit, keep your resources at around 64 megs. If you want to support even older machines (TNT2), keep it around 32 megs."

not if your engine can scale itself to the hardware, in that case, it _needs_ to know..

if you just do that: "If you want to support even older machines (TNT2), keep it around 32 megs"
it will run on older hardware, but won't take any advantage of the modern hardware.

I'm interested in this too, haven't looked deeply at it yet, but I read somewhere on these boards you could use windows functions to ask the driver directly, or something similar (can't remember)

perhaps a search on msdn would help

EDIT:
no offence but this statement: "It is not possible, nor is it neccessary"
is all but true... (at least for the last part , and I'm almost sure that you _can_ gain information on the first one, at least the driver knows. and I've seen a few programs giving you these infos)

[edited by - sBibi on January 12, 2004 11:09:15 AM]

EDIT(2):
"Whether you are using OpenGL or Direct3D, you don't talk directly to the video card. You always talk to the driver, and it is the driver's responsibility to make put things in the proper memory"

but you might _not_ want the driver to put some "things" somewhere else than in vram...

[edited by - sBibi on January 12, 2004 11:11:33 AM]

##### Share on other sites
I''m pretty sure (in DX8 atleast) there was a call in either the D3D object, or the D3DDevice for querying texture memory... but it included AGP memory, and other memory. There was no call to get the video card''s actual memory size.

In DDraw however, I''m pretty sure there IS a call to get the memory... If I remember correctly, the value is shown in Caps Viewer under DDraw. (checked... yup it''s there)

People have mentioned that it''s annoying to not be able to query the amount of memory, and MS apparently has listened, and will add an appropriate call in future versions of DX (I think HerbM mentioned this a long time ago). Until then you can init DX7 DDraw, query the memory, kill DDraw, then start D3D8 or D3D9.

##### Share on other sites
I might be completely wrong but with OpenGL at least you could try the following:

int numtex=0;GLuint t[10000];GLuint t1[10000];glGenTextures(10000,t);while(numtex<10000 && glAreTexturesResident(numtex,t,t1)){  glBindTexture(GL_TEXTURE_2D,t[numtex]);// not sure if this works if not you might have to specify a fake tex image// also the GL_RGB16 and 256x256 are chosen to work on almost any hardware// down to a voodoo (at least i think so)  glTexImage2D(GL_TEXTURE_2D,0,GL_RGB16,256,256,0,GL_RGB,GL_BYTE,0);  numtex++;}glDeleteTextures(numtex,t);//each is an 256x256 texture 2 byte each (GL_RGB16)int freevidmeminbytes=numtex*256*256*2;

I think i saw a glAreTexturesResident demo on delphi3d.net once, and it worked perfectly for me, so this should give you quite exact results.

Keep in mind though that you need a valid OpenGL RC and textures enabled once calling this codepiece.

edit: sp

[edited by - LousyPhreak on January 12, 2004 12:18:09 PM]

##### Share on other sites
If you're using DirectX if I remember correctly you could call GetCaps() in the direct draw interface to get the total memory and memory free for the video card. However, don't make too many assumptions with what you can do with this memory. All of it may or may not be available for textures, vertecies, etc... i.e. it tells you that memory is free but not what type of memory it is.

[edited by - mauman on January 12, 2004 12:43:07 PM]

##### Share on other sites
What is the AGP memory?

##### Share on other sites
DirectX''s value is just an estimation and might as well be wrong.

The problem with the question, is how do you define video memory ?

If you''re thinking to texture storage, it can be spread on many types of memory, AGP (or what about integrated chipsets?), in many formats, compressed or not, 16 bits or 32 bits, you don''t know what the driver is doing. It''d be completely useless, except for a very, very, very rough estimation.

If you want your engine to scale with your video card, i''d rather base it on the type or family of video card, rather than trying to find the amount of video memory.

Y.

##### Share on other sites
I think there''s no point checking how much there is.

What if the card doesn''t use the conventional notion of VRAM, AGP RAM and System RAM, or their associated traits?

What about onboard graphics that don''t have integrated VRAM? Perhaps the driver will return the amount of system ram there is. Do you really want to fill that up?

If you want to make a scalable engine, you could try the Neverwinter Nights approach and have different texture sets for different amounts of VRAM. And ask the user which one to use.

I can''t stress that enough - ask the user.

Why you shouldn''t use iostream.h - ever! | A Good free online C++ book

##### Share on other sites
I have found no way of really knowing how much videocard memory is available, and indeed that causes a problem : there is know way of knowing when the driver resorts to slower memory. The game i''m curretly working on has many large textures, and it does not fit in 3D card memory (or even in RAM for most systems), but the textures needed for one frame do not take that big of an amount of texture memory. ideally, the best would be to keep textures in video memory for as long as possible without forcing the driver to fallback to AGP memory. But to do this, knowing how full the hightspeed memory is is crucial!
The driver cannot know you apps intent.
The next directX, DirectXNext, will have memory queries, associated with speed information.

##### Share on other sites
quote:
Original post by gmkwo
What is the AGP memory?

It is system memory that can be used by both the CPU (to put stuff in there) and by the graphics card (it gets stuff from that memory block using DMA and the AGP bus).
The size is controlled by the BIOS, the ''AGP aperture'' parameter.

##### Share on other sites
I think you''ll find this thread particularly useful - same topic, but gives Yanns take on the problem.

Its useful to determine a rough estimate of the amount of VRAM available, but the figure can only be a very rough estimate at best, due to how the card and drivers use the memory internally. Because of this, the best option seems to be to allow the user to choose the quality levels for the game, and then use this to determine a figure for VRAM. Of course how you use the VRAM should not only depend on the amount available, it should depend on the hardware set-up as a whole (different cards - different strengths/weaknesses), and this is another reason why the user should be allowed to choose.

Kyle

##### Share on other sites
In D3D9 there''s also a function called GetAvailableTextureMem() on the device. I''ve never used it, but looking at the docs it doesn''t seem to have any drawbacks other than some inaccuracy (only returns results in megabytes, and has some alignment issues and such).

Or, if you already know the total amount of memory on the card, you could keep a running total of how much memory you''re allocating on your own. It wouldn''t be perfectly accurate, but it''d give you a rough idea.

For instance, in my code I have a static variable in my Texture class that keeps track of how much texture memory I''ve allocated, and every time I create a new texture I add the approximate memory taken to that total. It''s not perfect, but it gives me a rough idea how much memory I''ve used, which is usefull because I''m trying to keep my memory usage under 64MB or so.

Anyway, just a couple of ideas there.

----------------------------------------
"Before criticizing someone, walk a mile in their shoes.
Then, when you do criticize them, you will be a mile away and have their shoes." -- Deep Thoughts
"If you have any trouble sounding condescending, find a Unix user to show you how it''s done." - Scott Adams
FaceHat Software -- Wear the hat.