You’re an OpenGL developer and you need a simple way to know graphics memory information such as the memory size or memory usage? If so, this is the right place!
Few years ago, this kind of information wasn’t available to OpenGL developers but today, the two majors in OpenGL (I mean NVIDIA and AMD/ATI) have added some useful extensions to fetch graphics card memory size and other related data.
OpenGL Memory Size with NVIDIA
NVIDIA has recently published the specs of a new extension called GL_NVX_gpu_memory_info.
Thanks to GL_NVX_gpu_memory_info you can retrieve the size of the total available GPU memory and the size of the current available GPU memory.
Here is a code snippet that shows how to use it. GL_NVX_gpu_memory_info returns sizes in KB.
#define GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX 0x9048 #define GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX 0x9049 GLint total_mem_kb = 0: glGetIntegerv(GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX, &total_mem_kb); GLint cur_avail_mem_kb = 0: glGetIntegerv(GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX, &cur_avail_mem_kb);
This extension is used in GPU Shark to get the memory usage for NVIDIA graphics cards as you can see in the following picture:
According to Geeks3D OpenGL extensions DB, GL_NVX_gpu_memory_info is available in NVIDIA display drivers since R196.xx (see R196.21).
OpenGL Memory Size with AMD/ATI
AMD has released two extensions to deal with the size of video memory:
WGL_AMD_gpu_association is an extension developed for parallel rendering: you can create a different OpenGL context on each available GPU. This extension comes with hardware query functionalities. With WGL_AMD_gpu_association you can get the amount of graphics memory available for the GPU.
Here is how to use it to get the size of GPU memory in MB:
UINT n = wglGetGPUIDsAMD(0, 0); UINT *ids = new UINT[n]; size_t total_mem_mb = 0; wglGetGPUIDsAMD(n, ids); wglGetGPUInfoAMD(ids[0], WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(size_t), &total_mem_mb);
I tested this extension in this pico tool called Radeon-Z 😉
GL_ATI_meminfo is used when you need more detailed information about the available memory for VBO (vertex buffer object) or for your textures.
Want other articles and tutorials ? Just jump here:
[ Geeks3D ARTICLES and TUTORIALS Main Index ]
Pingback: [GPU Tool] RADEON-Z 0.1.0: OpenGL Information Utility for ATI Radeon Cards - 3D Tech News, Pixel Hacking, Data Visualization and 3D Programming - Geeks3D.com
Would be great with an example of GL_ATI_meminfo as well
😀
I must say that right now I’m a bit too lazy… I’ll try to update the post with an ATI_meminfo code snippet.
It’s about time to add some mem info to any bench how hard is that…
It would be handy to know the memory a specific application is using. Hopefully this becomes part of OpenGL.
Standardizing this kind of diagnostical help is a great oppertunity to make life easier for optimization. I’m loving it.
Also for the memory sizes.
Is that in MB as in 1000000B or 1024^2B?
Same for kB: 1000 or 1024?
I’m hoping it’s 1000 and 1000000 we have KiB and MiB for the powers of two.
Use of GL_ATI_meminfo is very simple 🙂
int free_mem;
//returns in kB, so if you want MB,divide by 1024
glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI,free_mem);
//now subtract this free memory from total memory and get used memory 🙂
used_mem = total_mem – free_mem;
I’ve noticed that it doesn’t matter whether you give to this function GL_TEXTURE_FREE_MEMORY_ATI or GL_VBO_FREE_MEMORY_ATI, it returns the same numbers
Thanks jammer 😉
Would it be possible to add peak memory usage while program running in tray and playing opengl game? Like in MemStatus tool -_-
Thanks these are quite some useful tips!
AAAAAAArrrrrrghhhh.
It is working in powers of two with the WRONG PREFIX!!!
Thanks jammer, this was indeed necessary to know.
They should move to MiB and KiB notations.
And about memory for an application.
Seperate for memory that an application has resources only used by itself and resources shared for other things.
This information was prefiously already available with the tool “memstatus”. I tested it on various cards (even gtx with 197 drivers) and it worked only on quadro up to now, though.
About: Seperate for memory that an application has resources only used by itself and resources shared for other things. It would be very useful to have that distinction.
I am having a crash when I call wglGetGPUInfoAMD()… I take out that call and I have no issues?
AFAIK I don’t need a GL3+ RC I am using GL2 RC.
Thanks
GLuint gpuIDs[16] = {0};
GLuint maxGpus = wglGetGPUIDsAMD(16, gpuIDs);
GLint freeMem[4] = {0};
glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, &freeMem[0]);
availableMemory = freeMem[0] / 1024;
if(wglGetGPUInfoAMD(gpuIDs[0], WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(GLuint), &totalMemory) != 1)
totalMemory = 0;
if(wglGetGPUInfoAMD(gpuIDs[0], WGL_GPU_CLOCK_AMD, GL_UNSIGNED_INT, sizeof(GLuint), &clockSpeed) != 1)
clockSpeed = 0;
How i make this issue with FX5200 card and pyopengl ?
Thank’s
Pingback: [OpenGL] GLEW 1.5.7 Released - 3D Tech News, Pixel Hacking, Data Visualization and 3D Programming - Geeks3D.com
Pingback: Real-Time Rendering · Tools, tools, tools
Here is the complete list of accepted parameters:
GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
0x9049
GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
The final two are particularly useful.
The report on the total number of memory ‘evictions’ (swap outs) that have occurred since the last call.
From NVidia specs:
GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
– dedicated video memory, total size (in kb) of the GPU memory
GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
– total available memory, total size (in Kb) of the memory
available for allocations
GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
– current available dedicated video memory (in kb), currently unused GPU memory
GPU_MEMORY_INFO_EVICTION_COUNT_NVX
– count of total evictions seen by system
GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
– size of total video memory evicted (in kb)
PT