Sign in to follow this  
madgallagher

OpenGL Strange Video Memory Increase

Recommended Posts

madgallagher    104

Hi Guys

 

I have a weird issue on opengl. I am rendering a lot of tris (millions) using vertex arrays.

Here is the issue.

 

If I load up the tris and display as shaded with a constant color, the video memory is showing around 600MB.

 

If I then change the color array values to be varied at different vertex, the memory usage increases to around 1GB.

If I then spin the model around, the memory usage slowly decreases to around 600MB (after a couple of minutes).

 

But, if I load up the model straight away with varied shading, the memory is only 600MB.

 

This is on linux, so is it a driver issue ? Or is there something more obvious I am neglecting.

 

I am using nvidia-smi to check the graphics memory usage.

 

Cheers in advance for any help !

Share this post


Link to post
Share on other sites
jsvcycling    1222

My first question is "Are you using the Linux drivers from your graphics card manufacturer or Nouveau?" If you are Nouveau I recommend you get the official Linux drivers for you video card before moving on.

 

Once thats all set and done and it still doesn't work, they my next question is "Are you using any type of culling?" If you are, its possible that when switching from the constant color to the varied shading the culling gets reset and isn't re-called until you move the camera (spin the model) or load the model right away with the varied shading. You'll need to find way to make sure that the culler is "always active". If you are attempting to use deferred shading rendering, there could also be some issues there, but I wouldn't be able to help you much as I'm just starting to learn about using defShading with OpenGL.

 

Also, have you tried testing it with a lower-poly model (maybe in the thousands of tris)?

 

Lastly, what version of OpenGL are you using and what is your graphics card?

Share this post


Link to post
Share on other sites
madgallagher    104

Hi

 

I am using the latest linux driver from Nvidia. The card is pretty old. Its an FX3800, but we see the same issue on an FX4000.

The same routines are used for both types of shading. I'm simply changing the values in the color array. Nothing else.

 

We get the same "doubling" of memory usage on smaller models too. Its like when the color array is updated, the memory

is not re-allocated on the card properly.

Share this post


Link to post
Share on other sites
Hodgman    51234

I'm simply changing the values in the color array.

How are you doing this? Is it a VBO or a client-side vertex array? What hints was it created with?

 

the memory usage slowly decreases to around 600MB (after a couple of minutes).

Is this actually a problem? If the driver doesn't need that memory for other tasks right now, they it's ok for it to delay releasing it.

Edited by Hodgman

Share this post


Link to post
Share on other sites
madgallagher    104

OK, the render code is basically as follows:

 

glShadeModel(GL_SMOOTH);

glEnable(GL_COLOR_MATERIAL)

glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT);

glColorMaterial(GL_FRONT_AND_BACK,GL_SPECULAR);

glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);

 

glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(....);

glEnableClientState(GL_NORMAL_ARRAY);

glNormalPointer(...);

glEnableClientState(GL_COLOR_ARRAY);

glColorPointer(....);

glDrawElements(........);

 

So, I am just using arrays, not VBOs. All I do is update the values in the color array that glColorPointer points to before I come into this routine.

 

The problem is, on a 1GB graphics card, if I am using 600MB and then change the color, it swamps the card and

the system starts badly lagging because it is trying to double the memory usage.

Share this post


Link to post
Share on other sites
jsvcycling    1222

By you use of glColorPointer() and the FX3000/4000, I'm guessing your using OpenGL 2.0. I personally don't have too much experience with anything earlier than OpenGL 3.1, so please take my help as a grain of salt.

 

Do you disable client state after you are finished writing to it or at program close? If you use the later, try disabling it after you are finished drawing everything. I'm not sure weather or not it will help, but its worth a shot in my opinion.

 

Is it possible for you to use VBOs rather than arrays? My understanding is that even back in OpenGL 2, it was more efficient to use buffers rather than arrays.

Share this post


Link to post
Share on other sites
madgallagher    104

Yes, sorry I forgot to add in the glDisableClientState commands. These are all deleted after the tris are drawn each time.

 

I added in VBOs and got the same effect even when deleting the VBO. Even simply using glBegin/End for the rendering (shock horror !!) causes the same effect.

 

It is kind of driving me crazy..................

Share this post


Link to post
Share on other sites
jsvcycling    1222

It's driving me crazy that I don't know how else I can help you...blink.png

 

Just one quick question... Are you using C++ or C or another language? Also, if you are using C++ or C, are you using any libraries like GLEW or SDL?

Share this post


Link to post
Share on other sites
mhagain    13430
I suspect that this may be normal behaviour rather than a driver issue. The fact that you're seeing this kind of video RAM usage at all with client arrays indicates that the geometry is being cached in video RAM. So you specify the arrays and draw, all good. Then you change the color array and now you've got two copies cached - the original (which the driver is presumably keeping around in case you need to go back to it) and the new. After a while, if you haven't gone back to the original, the driver decides to throw out it's old copy.

You may be able to control some of this behaviour with some use of GL_EXT_compiled_vertex_array, or you may be better off not using a vertex array for your constant color case (just glColor4f it instead).

Share this post


Link to post
Share on other sites
madgallagher    104

Thanks, I'll check out the GL_EXT_compiled _vertex_array. I get the same problem when I have varied colours

at the vertex and just change the values to say RGB ->RBG. Basically, any change to the colour array causes

the problem.

 

I appreciate all your comments gentlemen.

Share this post


Link to post
Share on other sites
slicer4ever    6760

mhagain, on 28 Mar 2013 - 12:50, said:
I suspect that this may be normal behaviour rather than a driver issue. The fact that you're seeing this kind of video RAM usage at all with client arrays indicates that the geometry is being cached in video RAM. So you specify the arrays and draw, all good. Then you change the color array and now you've got two copies cached - the original (which the driver is presumably keeping around in case you need to go back to it) and the new. After a while, if you haven't gone back to the original, the driver decides to throw out it's old copy.

You may be able to control some of this behaviour with some use of GL_EXT_compiled_vertex_array, or you may be better off not using a vertex array for your constant color case (just glColor4f it instead).

Pretty much this. For the most part, the driver knows best. If your changing values in your submitted data, it's highly likely the driver is simply caching the data, without releasing the old buffer immediately.

This is not uncommon to see in windows either. In short, i'd recommend not worrying about what the driver is doing, unless it's actually causing a problem.

Share this post


Link to post
Share on other sites
jsvcycling    1222

Well I think it is a problem for him as he said that when he changes the value, his graphics card's memory usage shoots up from 600M to 1G and then it starts to lag. If the driver is caching the data, then he would need to find a way to remove the values he's editing from the cache.

Share this post


Link to post
Share on other sites
Aks9    1499
The problem is in the "idea" to store 600MB in a single vertex array and transfer it in each draw call. That is not the way to go. I guess the performace is terrible if the data is not cached. The driver is probably trying to save performance by caching data and that's the problem. It could be solved by making smaller buffers.

Share this post


Link to post
Share on other sites
mhagain    13430
The only real way to handle this that I can think of is to use two different fragment shaders, one with the constant colour as a uniform. From the looks of the OP's sample code he's not using shaders at all, but running on prehistoric hardware shouldnt be a problem here; the kind of hardware that can handle this volume of data will always have shaders available anyway.

Share this post


Link to post
Share on other sites
slicer4ever    6760

Well I think it is a problem for him as he said that when he changes the value, his graphics card's memory usage shoots up from 600M to 1G and then it starts to lag. If the driver is caching the data, then he would need to find a way to remove the values he's editing from the cache.

ah, i missed where he said it was lagging, my bad.

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 povilaslt2
      Hello. I'm Programmer who is in search of 2D game project who preferably uses OpenGL and C++. You can see my projects in GitHub. Project genre doesn't matter (except MMO's :D).
    • By ZeldaFan555
      Hello, My name is Matt. I am a programmer. I mostly use Java, but can use C++ and various other languages. I'm looking for someone to partner up with for random projects, preferably using OpenGL, though I'd be open to just about anything. If you're interested you can contact me on Skype or on here, thank you!
      Skype: Mangodoor408
    • By tyhender
      Hello, my name is Mark. I'm hobby programmer. 
      So recently,I thought that it's good idea to find people to create a full 3D engine. I'm looking for people experienced in scripting 3D shaders and implementing physics into engine(game)(we are going to use the React physics engine). 
      And,ye,no money =D I'm just looking for hobbyists that will be proud of their work. If engine(or game) will have financial succes,well,then maybe =D
      Sorry for late replies.
      I mostly give more information when people PM me,but this post is REALLY short,even for me =D
      So here's few more points:
      Engine will use openGL and SDL for graphics. It will use React3D physics library for physics simulation. Engine(most probably,atleast for the first part) won't have graphical fron-end,it will be a framework . I think final engine should be enough to set up an FPS in a couple of minutes. A bit about my self:
      I've been programming for 7 years total. I learned very slowly it as "secondary interesting thing" for like 3 years, but then began to script more seriously.  My primary language is C++,which we are going to use for the engine. Yes,I did 3D graphics with physics simulation before. No, my portfolio isn't very impressive. I'm working on that No,I wasn't employed officially. If anybody need to know more PM me. 
       
    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
  • Popular Now