Sign in to follow this  
posixoptions

Determine free video RAM?

Recommended Posts

posixoptions    100
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.

Share this post


Link to post
Share on other sites
karwosts    840
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
rubicondev    296
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this