Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining available video memory

Tags:

memory

opengl

When developing an OpenGL program, is there a way to poll from the system to find out just how many megabytes are available to store textures, etc?

Or is the standard approach these days just allocate memory and forget about everything?

like image 689
kamziro Avatar asked Dec 29 '10 07:12

kamziro


People also ask

How do I find my usable VRAM?

Here's where to look. On the Windows search bar, type dxdiag. Wait for it to open then click either Display 1 or Display 2 to view your other GPU. Under Display Memory, you'll be able to see how much dedicated VRAM the GPU has.

What should my video memory be?

Our recommendation is to go with a GPU with at least 6GB of graphics memory if you plan on playing games at 1080p, high quality and reasonable framerates. Most graphics cards with this VRAM capacity will run most modern games, even demanding ones above 60 fps at high quality.


2 Answers

Although the official stance remains "you don't need to know, you don't want to know, and it would not help you anyway", luckily at least two IHVs have shown a little more insight lately and offer extensions to query that information:

  • NVX_gpu_memory_info
  • ATI_meminfo

One nice thing about these extensions is that they have a least common denominator which is just what most people need, and you don't need to query extension support or do anything special, as they both work via glGetIntegerv.

In the easiest case, you can just initialize an array of 4 integers to zero (or some minimum default value that you'll assume in case the extensions don't work), then you call glGetIntegerv twice (with GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX and TEXTURE_FREE_MEMORY_ATI, respectively), and finally call glGetError to clear the error state. glGetIntegerv does not modify the pointed-to memory if it fails, nor does it crash or any other bad thing -- it merely sets the error state to GL_INVALID_ENUM.

Both extensions return a value in the first array position, the ATI one returns some values in the other 3 too.

n.b.: glAreTexturesResident has not been supported for almost a decade on mainstream hardware, in the same manner as texture priorities. The common mantra is that the driver writer knows much better than you anyway.

like image 176
Damon Avatar answered Sep 24 '22 15:09

Damon


OpenGL doesn't give you this information. And frankly: There's only little benefit, simply because today we have multitasking operating systems. The OpenGL driver is responsible for swapping in texture data to/from system memory, if there's demand for it.

What OpenGL can do for you, is tell, if the textures you've uploaded are still resident in fast memory. The function is called "glAreTexturesResident". You can use this to gradually upload stuff to the GPU until you've filled up the GPU's memory. But keep in mind that you're not the only user of the GPU.

like image 29
datenwolf Avatar answered Sep 25 '22 15:09

datenwolf