[PROGRAMMING TIPS] How to Know the Graphics Memory Size and Usage In OpenGL
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:
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, 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 ]