Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
OpenGL unsteady framerate.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
pigeon768
l33t
l33t


Joined: 02 Jan 2006
Posts: 669

PostPosted: Tue Jan 22, 2013 4:04 pm    Post subject: OpenGL unsteady framerate. Reply with quote

So I'm trying to learn OpenGL and I hit an issue with every third frame taking significantly longer to render. After cutting down and cutting down and cutting down I finally came to the conclusion that it's simply overhead: but that's an unreasonable conclusion.
Code:
 $ cat test.c
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glut.h>
#include <stdio.h>

#define BUFFER_SIZE 64

static int t;
static int count = 0;
static unsigned char diffs[BUFFER_SIZE];

void readout() {
  int i,fps;
  for(i = 0;i<BUFFER_SIZE;i++) {
    if(diffs[i])
      fps=1000/diffs[i];
    else
      fps=9999999;
    printf("%8dfps  %8ums/frame\n",fps,diffs[i]);
  }
  exit(0);
}

void display() {
  const GLuint now = glutGet(GLUT_ELAPSED_TIME);
  if(now > 1000) {
    diffs[count++] = now - t;
    if(count==BUFFER_SIZE) readout();
  }
  t = now;

  glClear(GL_COLOR_BUFFER_BIT);
  glClearColor(0.0f,0.0f,0.0f,0.0f);

  glutSwapBuffers();
  glutPostRedisplay();
}

int main(int argc, char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
  glutInitWindowSize(640,480);
  glutCreateWindow("test");

  printf("OpenGL version: %s\n",glGetString(GL_VERSION));

  glutDisplayFunc(display);
  t = glutGet(GLUT_ELAPSED_TIME);

  glutMainLoop();

  return 0;
}
As you can see, it does nothing -- just clears the buffer and shovels it onto the display.
Code:
 $ gcc -lglut test.c -march=native -O3 -o test && ./test
OpenGL version: 3.0 Mesa 9.0.1
      35fps        28ms/frame
     250fps         4ms/frame
      30fps        33ms/frame
    1000fps         1ms/frame
    1000fps         1ms/frame
      62fps        16ms/frame
      66fps        15ms/frame
      30fps        33ms/frame
     500fps         2ms/frame
    1000fps         1ms/frame
      32fps        31ms/frame
    1000fps         1ms/frame
    1000fps         1ms/frame
      32fps        31ms/frame
    1000fps         1ms/frame
     333fps         3ms/frame
      50fps        20ms/frame
     100fps        10ms/frame
      58fps        17ms/frame
      62fps        16ms/frame
      30fps        33ms/frame
     500fps         2ms/frame
    1000fps         1ms/frame
      47fps        21ms/frame
     100fps        10ms/frame
      58fps        17ms/frame
      58fps        17ms/frame
      30fps        33ms/frame
    1000fps         1ms/frame
    1000fps         1ms/frame
      32fps        31ms/frame
    1000fps         1ms/frame
    1000fps         1ms/frame
      41fps        24ms/frame
     125fps         8ms/frame
      30fps        33ms/frame
    1000fps         1ms/frame
    1000fps         1ms/frame
      66fps        15ms/frame
      58fps        17ms/frame
      30fps        33ms/frame
    1000fps         1ms/frame
    1000fps         1ms/frame
      32fps        31ms/frame
    1000fps         1ms/frame
    1000fps         1ms/frame
      47fps        21ms/frame
     100fps        10ms/frame
      29fps        34ms/frame
    1000fps         1ms/frame
    1000fps         1ms/frame
      20fps        48ms/frame
    1000fps         1ms/frame
    1000fps         1ms/frame
      32fps        31ms/frame
    1000fps         1ms/frame
      30fps        33ms/frame
     500fps         2ms/frame
     333fps         3ms/frame
      35fps        28ms/frame
      58fps        17ms/frame
    1000fps         1ms/frame
      31fps        32ms/frame
    1000fps         1ms/frame
So most frames take ~1ms to render, some take significantly longer. There's not a whole lot of CPU usage going on during this time.

What gives? Video card is intel HD4000, drivers are up to date and all that. It plays eg Trine 2 smoothly, so i know the video drivers can't be that dorked up.

If I comment out the glClear() and glClearColor() I get the same problem. With glutSwapBuffers() commented I get 0ms per frame, but that's obviously not the solution.
_________________
My political bias.
Back to top
View user's profile Send private message
eccerr0r
Advocate
Advocate


Joined: 01 Jul 2004
Posts: 3599
Location: USA

PostPosted: Wed Jan 23, 2013 1:04 am    Post subject: Reply with quote

I wish I knew more about graphics programming and hardware so all I can do is compile and run the program :)

On my G965 machine (also Intel Graphics) it seems to be a very consistent 16-17ms per frame (OpenGL 2.1/Mesa 9). So this is weird. I recently fried both my HD3000 and HD4000 machines (due to the udev thing) so I can't test them at the moment...
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed to be advocating?
Back to top
View user's profile Send private message
pigeon768
l33t
l33t


Joined: 02 Jan 2006
Posts: 669

PostPosted: Wed Jan 23, 2013 4:53 am    Post subject: Reply with quote

Well hmm. I was able to make it go away and get a steady 16/17ms per frame by disabling "TearFree" in /etc/X11/xorg.conf.d/50-intel.conf. Of course, now I have tearing. :D I think I'm going to keep TearFree disabled at least for now. There are other ways to get rid of tearing with video playback.

(note: 16.666ms is the magic number because that's the time between frames on a 60Hz monitor)
_________________
My political bias.
Back to top
View user's profile Send private message
eccerr0r
Advocate
Advocate


Joined: 01 Jul 2004
Posts: 3599
Location: USA

PostPosted: Wed Jan 23, 2013 5:50 am    Post subject: Reply with quote

Curious - what hardware do you have that needs tearfree? I've yet to run across hardware that needed tearfree, or I can't tell the difference looking at it. My HD3000 is a LCD analog monitor, my HD4000 is a LVDS laptop display, and the G965 is also analog...

hmm...hope this kernel works... Can't believe I broke so many machines with this udev thing...

Addition: I got my HD3000 and HD4000 working again, no tearfree, stable 13-14 and 16-17 ms/frame, respectively.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed to be advocating?
Back to top
View user's profile Send private message
pigeon768
l33t
l33t


Joined: 02 Jan 2006
Posts: 669

PostPosted: Wed Jan 23, 2013 10:58 am    Post subject: Reply with quote

CPU is a i5-3320M, video card is HD4000.

It doesn't strictly need it, but I get enough tearing that I can't not notice it. It's the sort of thing you might never notice until someone points it out to you, and then it bugs the hell out of you, you know?
_________________
My political bias.
Back to top
View user's profile Send private message
eccerr0r
Advocate
Advocate


Joined: 01 Jul 2004
Posts: 3599
Location: USA

PostPosted: Wed Jan 23, 2013 6:42 pm    Post subject: Reply with quote

The test platforms I have are an i5-3317U (HD4000) - LVDS laptop display, and an i7-2700K (HD3000) - actually it's HDMI to DVI LCD interface. The HD3000 is actually refreshing at 75FPS hence the higher frame rate. The G965 (Core2Duo) is hooked up via analog to a DLP display.

I will need someone to point out the tearing, I don't even notice it on any of my displays... I had a contrived test at one point that I notice some "tearing" but not sure if it's the same thing...
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed to be advocating?
Back to top
View user's profile Send private message
Mad Merlin
Veteran
Veteran


Joined: 09 May 2005
Posts: 1141

PostPosted: Wed Jan 23, 2013 7:11 pm    Post subject: Reply with quote

I get mostly 0ms/frame with a small number of 1ms/frame, video card is a GTX 670:

Code:

OpenGL version: 4.2.0 NVIDIA 304.37
    1000fps         1ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
    1000fps         1ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
 9999999fps         0ms/frame
    1000fps         1ms/frame
 9999999fps         0ms/frame


I might suggest using SDL instead of GLUT, GLUT is... not very sophisticated and yet doesn't manage to be much easier (if at all) to use than SDL.
_________________
Game! - Where the stick is mightier than the sword!
Back to top
View user's profile Send private message
eccerr0r
Advocate
Advocate


Joined: 01 Jul 2004
Posts: 3599
Location: USA

PostPosted: Thu Jan 24, 2013 5:03 pm    Post subject: Reply with quote

Anyone happen to know how to stop xorg/opengl from using the monitor refresh rate as the limit to how fast it draws screens? Seems some drivers limit to refresh rate and some just blasts it out as fast as it can to the video buffer...
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed to be advocating?
Back to top
View user's profile Send private message
Mad Merlin
Veteran
Veteran


Joined: 09 May 2005
Posts: 1141

PostPosted: Thu Jan 24, 2013 8:12 pm    Post subject: Reply with quote

eccerr0r wrote:
Anyone happen to know how to stop xorg/opengl from using the monitor refresh rate as the limit to how fast it draws screens? Seems some drivers limit to refresh rate and some just blasts it out as fast as it can to the video buffer...


That would be vsync. I believe all drivers have a way to toggle it (which is different from every other video driver) and most default to vsync on. For the Nvidia blob, it's an option in nvidia-settings, for radeon, it seems to be SwapbuffersWait or possibly EnablePageFlip in xorg.conf, not sure about the others.
_________________
Game! - Where the stick is mightier than the sword!
Back to top
View user's profile Send private message
Jean-Paul
Apprentice
Apprentice


Joined: 13 Apr 2009
Posts: 166

PostPosted: Thu Jan 24, 2013 8:59 pm    Post subject: Reply with quote

for intel I use
Quote:
Section "Device"
Identifier "Intel HD4000"
Driver "intel"
Option "AccelMethod" "sna"
Option "SwapbuffersWait" "false"
EndSection
Back to top
View user's profile Send private message
eccerr0r
Advocate
Advocate


Joined: 01 Jul 2004
Posts: 3599
Location: USA

PostPosted: Fri Jan 25, 2013 5:13 am    Post subject: Reply with quote

Ah... I wish the option was the same for all drivers, and documented... That has to be one of the most obscure options...
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed to be advocating?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum