PDA

View Full Version : Optimisation - A general question



StevieDB
03-03-2007, 02:47 PM
Hey guys,

A general question for you regarding the efficiency of an application I'm running.

I have 40 houses lit in real time using CG shaders.

There are times I run the application that it maintains a pretty consistent 60fps. Other times I run the application it averages at 30fps without changing even one single line of code.

I'm at a total loss as to why this kind of discrepancy can occur.

Without knowing the ins and outs of my app, can anyone point me in the right direction as to where I should be looking for bottlenecks?

Thanks

k_szczech
03-03-2007, 03:20 PM
If it's either near 30 or 60fps then it's probably vertical sync that affects the framerate.
Try wglSwapIntervalEXT(0);

StevieDB
03-03-2007, 06:55 PM
Hi k_szczech

Where exactly in my code should I implement this?

i tried it in the render method and didn't get any joy.

As a side note, bizarrely, I've had a couple of runs of my program this evening, again without changing any code where the frame rate has hit 700fps. :|

k_szczech
03-03-2007, 11:56 PM
Well, you need to call it once whenever you want - it disables vsync.
Calling wglSwapIntervalEXT(1); will enable it.

Since you mentioned 30/60 fps it seemed that it is vsync indeed. But now you mentioned 700 fps, which makes me believe that you have some bug in fps measurement. You should review your code carefully.

StevieDB
03-04-2007, 03:43 AM
k_szczech

You say that there is a bug in my fps measuring code?

Possibly, but what I can tell you for sure is that at times with massive amounts of lights, the rendering is definately running super super fast with slick transition between frames and not the slightest hint of stutter.

Here is my frame updating code

INT64 freq = 0;
INT64 lastTime = 0;
INT64 currentTime = 0;
float elapsedTimeSec = 0.0f;
float timeScale = 0.0f;

QueryPerformanceFrequency(reinterpret_cast<LARG E_INTEGER*>(&freq));
QueryPerformanceCounter(reinterpret_cast<LARGE_ INTEGER*>(&lastTime));
timeScale = 1.0f / freq;


while(!done)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
{
done=TRUE;
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);

}
else
{
QueryPerformanceCounter(reinterpret_cast<LARGE_ INTEGER*>(&currentTime));
elapsedTimeSec = (currentTime - lastTime) * timeScale;
lastTime = currentTime;
fps = 1.0f/elapsedTimeSec;
UpdateFrame(elapsedTimeSec);

if ((active && !DrawGLScene()) || keys[VK_ESCAPE])
{
done=TRUE;
}
else
{
SwapBuffers(hDC);
}
}
}So as you can see my fps code is solid and is taken from many examples on the web.

I got 98fps last night for 200 lights!

Trahern
03-04-2007, 04:00 AM
Just a quick note about your FPS measurement code. From what I see, it is ok, however usually FPS is measured a little bit differently. Either by measuring how many frames do you draw in some time period (for example in one second) or by measuring time necessary to draw multiple frames (for example 50 frames) and then averaging this time.

But back to your problem. I think, that nobody here can help you much unless you give us more information. (ideally a link for your application so someone can try it).

If I understand you correctly, you are saying that your application runs on 30,60 or even 100+ FPS when you are rendering it with the exactly same settings and when rendering the exactly same scene (this means that your camera points to the same place and you are rendering the same objects). If this is true, then it really makes no sense to me.

StevieDB
03-04-2007, 07:51 AM
Trahern - it makes no sense to me either hence the reason I'm posting here.

I did think initially that the problem was with the fps code. However, the difference is so clear at times. For example the first time I ran the app with 100 houses and 100 lights, it crawled at approx 10fps. Then I ran it again about 5 mins later to get a screenshot and the fps shot up. I hadn't altered one line of code apart from the line which specifies the number of lights.

I was wondering if the load on the CPU at the time I run the application could have anything to do with it?

Screenshot here.
Screenshot (http://stockwellladsteve.myphotoalbum.com/view_photo.php?set_albumName=album01&id=100LAMPSFPS87)

Trahern
03-04-2007, 01:39 PM
Originally posted by StevieDB:

I was wondering if the load on the CPU at the time I run the application could have anything to do with it? Definitely. You should always benchmark your applications when there is nothing else running on your computer.

Graphic Remedy
03-04-2007, 11:41 PM
Hi StevieDB

You can use gDEBugger with NVIDIA's NPerfKit integration to locate your graphic pipeline bottleneck.

Additional information is available at:
- www.opengl.org/pipeline/article/vol003_8/ (http://www.opengl.org/pipeline/article/vol003_8/)
- www.opengl.org/pipeline/article/vol002_5/ (http://www.opengl.org/pipeline/article/vol002_5/)
- www.gremedy.com/screenshots.php (http://www.gremedy.com/screenshots.php)
- www.gremedy.com/webhelp (http://www.gremedy.com/webhelp)

The gDEBugger team
www.gremedy.com (http://www.gremedy.com)