Determine free video RAM?

Started by
3 comments, last by V-man 13 years, 11 months ago
I have searched a lot for this but I cannot find anything on how to do something so apparently trivial: How can I determine the total amount of video RAM and more importantly how much video RAM is actually free? By video RAM I mean the physical memory that is on the graphics card -- i.e. the memory that I will allocate when I use VBOs and do glBufferData() which allocates VRAM. Why do I want to know this? Because I have 1.4 GiB of data that I want to copy, but my graphics card cannot contain it all simultaneously; as such, I want to know how much is free and copy as much as I can at a time.
Advertisement
I don't believe there is an easy way to query this. It is the responsibility of the video driver to manage the ram, and it will page data to and from system memory as needed, so I don't think this is something you need to concern yourself with.

I believe just because you call glBufferData doesn't even guarantee that your data is stored in VRAM.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
If you're using SDL there is SDL_VideoInfo. I don't know anything about what you're trying to do though.
There are NVX/ATI extensions for that. The downside is that since they're extensions, they're not necessarily present on your computer. The positive side is that unlike most extensions, you need not care. You can just do two glGetIntegerv calls with the respective constants (GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX and TEXTURE_FREE_MEMORY_ATI).

If either of the functions fails, it doesn't modify the receiving variable and sets GL_INVALID_ENUM, but your program won't crash or anything.
You already know that one of the two functions will fail anyway (unless you have both an ATI and nVidia card in your computer!). Thus, you best follow up with a glGetError() call to reset the error flags.

Initialize retval[0] with a conservative default value (such as 128M) in case neither extension is present.
It's an impossible to answer question. Even if you use the suggested methods there's still little you can do with the answer.

How much space your textures actually take up is not simply a factor of their dimensions. Mip levels might be put into spaced-out page boundaries, non-pow2 stuff might have all sorts of things happening to it, etc. Even if every texture is the same size and pow2, it's not guaranteed that they'll take up exactly the memory your expect.

I suggest you write a general streaming routine that assumes a worst case of say 128Mb and scales up accordingly. Not sure how you'd do that tbh, but it's worth thinking about. Naievely uploading everything and letting the driver sort it out might even work better than you expect - things generally only get paged in once they're in use.
------------------------------Great Little War Game
I agree with Rubicon + here is some info from the Wiki since it is a popular question
http://www.opengl.org/wiki/Common_Mistakes#glAreTexturesResident_and_Video_Memory
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement