Jump to content
  • Advertisement
Sign in to follow this  
MarkS

OpenGL How do I determine the maximum VBO size?

This topic is 2091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was playing around with some old maze generation code and tried to generate a maze 10000 x 10000 cells in size. The algorithm had no trouble generating the maze, but sending the VBO with 400,000,000+ vertices to the graphics card caused a crash. I didn't think of it at the time, but with 24 bytes per vertex, that totaled over 9.6 billion bytes of data. This exercise was, of course, unnecessary and a waste of time, but it did bring up something that I hadn't considered before.... How does one determine if the data being sent will fit into the graphics card's RAM prior to sending it? If sending too much data will cause a crash, then it is important to know before hand. I know that my graphics card has xx total VRAM, but not all of that space is available to me.

 

Does OpenGL provide some mechanism to get this information? I am aware that it would be dependent on the card manufacturer, but the driver should make this information available to the API, I would think. I've search OpenGL's documentation, but I cannot seem to find anything. Maybe this is something that is only available through the OS?

Share this post


Link to post
Share on other sites
Advertisement

Does OpenGL provide some mechanism to get this information? I am aware that it would be dependent on the card manufacturer, but the driver should make this information available to the API, I would think. I've search OpenGL's documentation, but I cannot seem to find anything. Maybe this is something that is only available through the OS?

There isn't really a fixed amount that is available. 

 

The card has some fixed total storage, given by the amount of video RAM. From that you need to subtract the space taken by shaders, textures, vertex buffers, and any framebuffers. And each of those is per application which shares the GPU.

Share this post


Link to post
Share on other sites

I googled this and didn't find any documentation regarding a limit on VBO size.  I also read that if there's not enough memory for a VBO, then it will be placed in system memory.  

 

Also, I wanted to ask you this, are those 400,000,000+ primitives always within your viewing frustum?  I really hope you're culling everything you're camera isn't facing! wink.png

Share this post


Link to post
Share on other sites

There are several ways to get information about memory allocation through the API. NVX_gpu_memory_info and ATI_meminfo are some of the extensions for that.

I tried to summarize main aspects of those extensions in OpenGL Insights, Chapter 38, pg.535-540.

 

There is a limit in size of objects in graphics card memory. It depends on graphics card memory size, driver policy, and probably architecture. Different vendors also expose different policies. NV, for example, won't draw objects that cannot fit into the dedicated graphics memory, while AMD allows drawing directly from the shared system memory. This shouldn't be accepted as absolute truth, but that's just the behavior of drivers and cards I had tested.

 

In any case, splitting gigantic VBOs into smaller chunks enables more efficient memory management. At the cost of reducing performance, the sum of dedicated and shared memory can be used for storing graphics objects.

Share this post


Link to post
Share on other sites
Thanks for the replies. This was me being bored and not an actual project. If it had been an actual project I would have divided up the maze into zones and only displayed the zones visible in the frustum.

I am curious why the program crashed at glBufferData with a bad_alloc exception? If the VBO could have been placed in system memory, of which I have 16 GB, there shouldn't be an issue. Odd. Maybe a driver issue?

Share this post


Link to post
Share on other sites

If it was a 32-bit program then I'd expect a failure, but definitely not a crash; even if 64-bit you should not have crashed - glBufferData is specified to generate GL_OUT_OF_MEMORY if the requested size can't be allocated.  Almost certainly a driver bug (although I don't expect that there are too many people creating > 9gb buffers so the code path for this may not be robustly tested in any driver!)

Share this post


Link to post
Share on other sites

If it was a 32-bit program then I'd expect a failure, but definitely not a crash; even if 64-bit you should not have crashed - glBufferData is specified to generate GL_OUT_OF_MEMORY if the requested size can't be allocated.  Almost certainly a driver bug (although I don't expect that there are too many people creating > 9gb buffers so the code path for this may not be robustly tested in any driver!)

That is what I was thinking. Thanks for the answer.

Share this post


Link to post
Share on other sites

Thanks for the replies. This was me being bored and not an actual project. If it had been an actual project I would have divided up the maze into zones and only displayed the zones visible in the frustum.

I am curious why the program crashed at glBufferData with a bad_alloc exception? If the VBO could have been placed in system memory, of which I have 16 GB, there shouldn't be an issue. Odd. Maybe a driver issue?

That 9GB VBO cannot be allocated by any mean. Shared system memory is not the same as system memory. Take a look at your graphics card's control panel. It is probably less than 2GB. Second, transferring data from CPU memory to GPU memory goes through two phases - copying from application memory space to driver memory space, and copying from driver memory space to device. Allocating objects that are bigger than a dedicated or shared graphics memory is nonsense by any mean. That's probably why vendors (you didn't mentioned which) have "forgotten" to catch the exception, as mhagain said.

Share this post


Link to post
Share on other sites

Well... I tried to allocate 16 million vertices, 11 floats for each, 704Mb, and my GTX 560 Ti with 1Gb failed miserably :D So I wouldn't even try with 400 million.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!