VRAM with VBO's and VAR's (or D3D equivalent)

Started by
9 comments, last by Trienco 19 years, 9 months ago
I'm reading up on exactly how the system and video card interacts in terms of memory. I'm trying to figure how to decide when to upload data to VRAM, how to do it, etc. I have a pretty good grasp on vertex buffer objects. I've never really worried about memory, but I want to start building a game that might need to manage it a little. Tell if this is a bad idea. With VBO's, you can figure out if you've ran out of memory by detecting the OUT_OF_MEMORY error from the BufferDataARB call. However, it seems risky to wait until you totally filled up the memory. Anyway, I guess you could detect that when you run out, delete the least recently used buffer, and try to upload the data again. But that seems inefficient and risky. You could get a kind of thrashing if you have a big buffer that is constantly deleted and reuploaded, which would make many other things reupload as well. That kind of takes that point out of the vertex buffer object, where you can upload data once and not worry about it again. What's a simple uploading/caching scheme? Do you usually use vertex arrays in combination with vertex buffer objects? What exactly happens in VRAM with vertex arrays? You upload the data once, and then is it cached at all? If so, how do you detect it, or does the system do that for you so that when you call a {Vertex}Pointer() function it finds the cached data? edit: I just realized that I'm talking about OpenGL structures. I hope this is still applicable in this forum. I guess I just wanted a general answer as to how you decide when/how to upload data to VRAM (all of it once at the beginning, if it all fits? how do you know if it fits?) [Edited by - okonomiyaki on July 7, 2004 11:47:59 AM]
Advertisement
Hi...

Quote:
With VBO's, you can figure out if you've ran out of memory by detecting the OUT_OF_MEMORY error from the BufferDataARB call.


I'm not really sure that this is true. If BufferDataARB can't allocate the requested buffer on Video Memory, it will try AGP Memory and if it fails again it will try to allocate it on system memory. Don't take this too seriously though, because there is sometime since i read the specs. But i think this is the behavior for VBO at least.
With VAR it can be different because of the frequency and priority flags.

Any feedback on this?

Quote:
However, it seems risky to wait until you totally filled up the memory. Anyway, I guess you could detect that when you run out, delete the least recently used buffer, and try to upload the data again.


What happens if the 90% of the memory is allocated by textures, display lists, and other things that go to the Video/AGP memory? When you are at this situation, how can you be sure that deallocating the LRU vertex buffer will solve the problem?

What i thought for preventing situation like these, is precalculate the maximum texture/vbo/index etc. memory a certain level will use, and try to minimize the requirements "a priori" (e.g. compress textures to free some memory, use 16-bit indices where applicable, etc.). Or, if we are talking for really big levels (from the memory point of view), try to calculate the mean memory usage for some positions in it, and try to minimize this. This stands for situations where you stream data (almost) continuesly from the HD. Something like FarCry's terrain renderer (it keeps unloading and loading terrain chunks all the time, when you move fast of course (see editor)). BUT, what happens if you can't minimize memory requirements? Then you need somekind of memory manager for that. But, don't wait running out of memory to start unloading data. Because in OGL, i don't there is anyway for requesting availiable mem of any type (Vid/AGP).

Quote:
What's a simple uploading/caching scheme? Do you usually use vertex arrays in combination with vertex buffer objects? What exactly happens in VRAM with vertex arrays? You upload the data once, and then is it cached at all? If so, how do you detect it, or does the system do that for you so that when you call a {Vertex}Pointer() function it finds the cached data?


What do you mean by caching? If your data were uploaded to the Video RAM, then (i want to believe that) they will stay there as long I don't remove them. If you mean Post TnL caching it has nothing to do with where the data is stored. It works for system memory VAs or VBOs or VAR, as long as you are using indexed arrays.

About the uploading/caching scheme you said, sorry but i can't comment. I haven't experimented with anything like this before, so...

Hope i didn't confused you, or said anything that isn't true. If something isn't true, someone please correct me.

HellRaiZer

HellRaiZer
Quote:Original post by HellRaiZer
Hi...

Quote:
With VBO's, you can figure out if you've ran out of memory by detecting the OUT_OF_MEMORY error from the BufferDataARB call.


I'm not really sure that this is true. If BufferDataARB can't allocate the requested buffer on Video Memory, it will try AGP Memory and if it fails again it will try to allocate it on system memory. Don't take this too seriously though, because there is sometime since i read the specs. But i think this is the behavior for VBO at least.
With VAR it can be different because of the frequency and priority flags.

Any feedback on this?


"OUT_OF_MEMORY may be generated if the data store of a buffer object
cannot be allocated because the <size> argument of BufferDataARB is
too large."

Maybe I misinterpreted that. Now that I think about it, you're probably right. The system would probably fall back on some kind of paging scheme. Oh well, I never liked my idea in the first place anyway.

Quote:
Quote:
However, it seems risky to wait until you totally filled up the memory. Anyway, I guess you could detect that when you run out, delete the least recently used buffer, and try to upload the data again.


What happens if the 90% of the memory is allocated by textures, display lists, and other things that go to the Video/AGP memory? When you are at this situation, how can you be sure that deallocating the LRU vertex buffer will solve the problem?

What i thought for preventing situation like these, is precalculate the maximum texture/vbo/index etc. memory a certain level will use, and try to minimize the requirements "a priori" (e.g. compress textures to free some memory, use 16-bit indices where applicable, etc.). Or, if we are talking for really big levels (from the memory point of view), try to calculate the mean memory usage for some positions in it, and try to minimize this. This stands for situations where you stream data (almost) continuesly from the HD. Something like FarCry's terrain renderer (it keeps unloading and loading terrain chunks all the time, when you move fast of course (see editor)). BUT, what happens if you can't minimize memory requirements? Then you need somekind of memory manager for that. But, don't wait running out of memory to start unloading data. Because in OGL, i don't there is anyway for requesting availiable mem of any type (Vid/AGP).


Well, I meant that in a general sense. Free a texture, free a buffer, whatever is needed.
The more I think about it though, the more I'm inclined to forget about vertex arrays altogether and use VBO's for everything. OpenGL and drivers should do memory management for me with many small buffers. I shouldn't have to really worry about it.
Though, of course it's good to minimize memory requirements. But I should be able to upload everything to VRAM and let the drivers worry about the rest, right?

Quote:
What do you mean by caching?


I meant in the sense where you upload data one frame, and then come around the next frame, and the data is still cached in memory (VRAM). Yes, you are right that it should stay there. But somewhere later on you might delete the buffer for various reasons. That's kind of what I was asking, if a typical scheme consisted of managing buffers or anything uploaded to VRAM.


I was just searching around and I found some stuff in the Materials/Shaders thread. In the described effect system, they always check to see if the data is already "cached" (uploaded to the video card). If it's not, they reupload it. That's my question, why would it ever end up not being cached?
The whole caching subject is down to the fact that you dont want to make lots of little VBOs or even one big VBO, because the driver cant manage them properly (ATI and NV both agree on this point).
Instead you can create a bunch of VBOs which are filled as need and the size taken in each one and what is allocated to it is tracked. Then, when you come to draw your model you see if its already inserted into a VBO, if it is then render away, if it isnt then upload the data to the VBO and then render.

For the most part, yes the driver will handle VBO memory management using VRAM, AGP and even System as needed, however you can help it by not allocating one huge buffer or loads and loads of little ones.

As to how big is too big and how small is too small, i asked that question in the OGL forum a while back and got some answers, although i dont recall atm what they were [smile]
Quote:Original post by _the_phantom_
For the most part, yes the driver will handle VBO memory management using VRAM, AGP and even System as needed, however you can help it by not allocating one huge buffer or loads and loads of little ones.


though that part is still more than confusing to me. as a simple question:

if i can easily allocate the required memory as chunks of system memory, shouldnt the driver be able to allocate the SAME memory as vbo? instead it just seems to fail when its out of video memory, forcing me to fall back to vertex arrays for the remaining few chunks (which will kill performance, because for a weird reason my indices are in video memory and _usually_ squeeze out a few percent more speed). i begin to wonder if there is an upper limit to how much memory can be managed by the driver for vbo (as a sum, not a big single chunk).
f@dzhttp://festini.device-zero.de
Quote:
For the most part, yes the driver will handle VBO memory management using VRAM, AGP and even System as needed, however you can help it by not allocating one huge buffer or loads and loads of little ones.


ok, if this is true, I can understand it. It's better to handle yourself. But I assume it can kind of be a loose system, where it's a simple design that isn't bulletproof, because the drivers should be able to do some management.

Quote:
if i can easily allocate the required memory as chunks of system memory, shouldnt the driver be able to allocate the SAME memory as vbo? instead it just seems to fail when its out of video memory, forcing me to fall back to vertex arrays for the remaining few chunks (which will kill performance, because for a weird reason my indices are in video memory and _usually_ squeeze out a few percent more speed). i begin to wonder if there is an upper limit to how much memory can be managed by the driver for vbo (as a sum, not a big single chunk).


That's exactly what I'm trying to figure out. The specs don't really go into it. So you've encountered the OUT_OF_MEMORY error. I suppose there could be an upper limit to the amount of memory, though I don't see how this could be hardcoded with the variable amount of memory on different systems. Maybe it doesn't try to allocate any memory other than VRAM.

In theory, yeah the driver should fall back from vram to agp and then system, however I guess that the implimentations still arent perfect.

The drivers do perform some management, but its hard for it to manage large cunks of ram allocated effectively and for small chunks the overhead of buffer switching and management out weights any gains you might have gotten anyway.

I'll have to do some experiments as to how much VBO space i can reserve etc at some point, if its silly for my setup then I guess its time to poke some driver dev people [smile]
Quote:Original post by _the_phantom_
I'll have to do some experiments as to how much VBO space i can reserve etc at some point, if its silly for my setup then I guess its time to poke some driver dev people [smile]


on my radeon about 17mb in a single chunk worked, 70mb didnt. if i allocate a bunch of chunks i can get 12 of these 17mb chunks (the remaining 4 that i would need fail). that would be about 200mb, but seeing all the textures, frame/depth/whatever buffers thats obviously where i run out of video memory. unfortunately it refuses to use anything else, even if i try a usage like stream_read.
f@dzhttp://festini.device-zero.de
yeah, I'd have thought that would fall back into AGP/system ram at that point as well... hmmm intresting...
I guess I'll just reserve a certain amount of memory for vertices and all their attributes, and when rendering, use a kind of sliding slot system. I don't think it should be that hard to implement, and I guess it gives me more control on exactly what's going on, and lets me track what's being uploaded and when, etc.
Should be fun. Question is how much to reserve :D

edit: also, I'm think I just reserve that as one big buffer and then map into it? Seems wrong for some reason. I'll try it out.

This topic is closed to new replies.

Advertisement