Sign in to follow this  
Followers 0
madgallagher

OpenGL
Strange Video Memory Increase

16 posts in this topic

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 !

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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..................

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

Its all in C baby. I am not using anything like GLEW or SDL. Its pretty basic stuff.

 

Do you think it is a driver issue which is out of my control ??

0

Share this post


Link to post
Share on other sites

It could possibly be a driver issue. Have you tried it on an AMD/ATI card? What linux distro are you using?

0

Share this post


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

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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.
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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.
0

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  
Followers 0

  • Similar Content

    • By recp
      Hi,
      I'm working on new asset importer (https://github.com/recp/assetkit) based on COLLADA specs, the question is not about COLLADA directly
      also I'm working on a new renderer to render (https://github.com/recp/libgk) imported document.
      In the future I'll spend more time on this renderer of course, currently rendering imported (implemented parts) is enough for me
      assetkit imports COLLADA document (it will support glTF too),
      importing scene, geometries, effects/materials, 2d textures and rendering them seems working
      My actual confusion is about shaders. COLLADA has COMMON profile and GLSL... profiles,
      GLSL profile provides shaders for effects so I don't need to wory about them just compile, link, group them before render

      The problem occours in COMMON profile because I need to write shaders,
      Actually I wrote them for basic matrials and another version for 2d texture
      I would like to create multiple program but I am not sure how to split this this shader into smaller ones,

      Basic material version (only colors):
      https://github.com/recp/libgk/blob/master/src/default/shader/gk_default.frag
      Texture version:
      https://gist.github.com/recp/b0368c74c35d9d6912f524624bfbf5a3
      I used subroutines to bind materials, actually I liked it,
      In scene graph every node can have different program, and it switches between them if parentNode->program != node->program
      (I'll do scene graph optimizations e.g.  view frustum culling, grouping shaders... later)

      I'm going to implement transparency but I'm considering to create separate shaders,
      because default shader is going to be branching hell
      I can't generate shader for every node because I don't know how many node can be exist, there is no limit.
      I don't know how to write a good uber-shader for different cases:

      Here material struct:
      struct Material { ColorOrTexture emission; ColorOrTexture ambient; ColorOrTexture specular; ColorOrTexture reflective; ColorOrTexture transparent; ColorOrTexture diffuse; float shininess; float reflectivEyety; float transparency; float indexOfRefraction; }; ColorOrTexture could be color or 2d texture, if there would be single colorOrTex then I could split into two programs,
      Also I'm going to implement transparency, I am not sure how many program that I needed

      I'm considering to maintain a few default shaders for COMMON profile,
      1-no-texture, 2-one of colorOrTexture contains texture, 3-........

      Any advices in general or about how to optimize/split (if I need) these shaders which I provied as link?
      What do you think the shaders I wrote, I would like to write them without branching if posible,
      I hope I don't need to write 50+ or 100+ shaders, and 100+ default programs

      PS: These default shaders should render any document, they are not specific, they are general purpose...
             I'm compiling and linking default shaders when app launched

      Thanks
    • By CircleOfLight97
      Hi guys,
      I would like to contribute to a game project as a developer (open source possibly). I have some experiences in C/C++ in game development (perso projects). I don't know either unreal or unity but I have some knowledges in opengl, glsl and shading theory as I had some courses at university regarding to that. I have some knowledges in maths and basic in physics. I know a little how to use blender to do modelling, texturing and simple game assets (no characters, no animation no skinning/rigging). I have no game preferences but I like aventure game, dungeon crawler, platformers, randomly generated things. I know these kind of projects involve a lot of time and I'd be really to work on it but if there are no cleary defined specific design goals/stories/gameplay mechanics I would like to not be part of it x) and I would rather prefer a smaller but well defined project to work on that a huge and not 'finishable' one.
      CircleOfLight97
    • By gamesthatcouldbeworse
      Hi, I finally released KILL COMMANDO on gamejolt for free. It is a retro-funsplatter-shooter with C64 style. Give it a try.
    • By phil67rpg

      void TimerFunction(int value) {  glutPostRedisplay();  glutTimerFunc(1000, TimerFunction, 1); } void drawScene() {  glClear(GL_COLOR_BUFFER_BIT);      drawScene_bug();  TimerFunction(1);  eraseScene_bug(); // drawScene_bug_two(); // eraseScene_bug_two(); drawScene_ship(); drawScene_bullet();  glutSwapBuffers(); }
  • Popular Now