Sign in to follow this  
okonomiyaki

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

Recommended Posts

okonomiyaki    548
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]

Share this post


Link to post
Share on other sites
HellRaiZer    1001
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

Share this post


Link to post
Share on other sites
okonomiyaki    548
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?

Share this post


Link to post
Share on other sites
_the_phantom_    11250
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]

Share this post


Link to post
Share on other sites
Trienco    2555
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).

Share this post


Link to post
Share on other sites
okonomiyaki    548
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.

Share this post


Link to post
Share on other sites
_the_phantom_    11250
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]

Share this post


Link to post
Share on other sites
Trienco    2555
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.

Share this post


Link to post
Share on other sites
okonomiyaki    548
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.

Share this post


Link to post
Share on other sites
Trienco    2555
Quote:
Original post by _the_phantom_
yeah, I'd have thought that would fall back into AGP/system ram at that point as well... hmmm intresting...


especially since having to fall back to vertex arrays for the remaining data creates an ugly mess and the constant need to check if vbo needs to be disabled (not to mention that vbo index buffers dont play nice with va vertex data). i wouldnt mind if vbo could completely replace va and become a single solution, but with all the little issues they seem to be more complicated than one would have expected.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now