View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Help, I've optimized too much!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

15 replies to this topic

### #1wizardpc  Members

Posted 15 January 2013 - 12:59 PM

So my game was running around 50 FPS, but then I reworked my terrain by implimenting GeoMipMapping, and sending my entity draw calls to a frustrum check instead of just rendering all entities.

I'm now pushing 170 fps, and my laptops fan ramps up and gets loud.  I'm assuming this will cook the GPU after a while.

Is there a way to figure out how much to sleep given the FPS? I want to get it back down to 60ish fps (or some lower value).

### #2HAM  Members

Posted 15 January 2013 - 01:07 PM

Probably just waiting on VSync would do it.

If you are using DirectX lookup the present parameters and something like D3DPRESENT_INTERVAL_ONE.

So if your monitors refresh rate is 60hz.  Then your FPS will be 60 at most.

That would be a pretty straight forward way to limit your FPS.

For lower values there is D3DPRESENT_INTERVAL_TWO and THREE i think.

For sleep times you could just track your frame and sleep until 1/60th of second as passed; That sounds kinda weird to me though.

Edited by HAM, 15 January 2013 - 01:10 PM.

### #3wizardpc  Members

Posted 15 January 2013 - 01:26 PM

Ah I should have mentioned I"m using OpenGL.

### #4HAM  Members

Posted 15 January 2013 - 01:30 PM

Well the concept is the same.  Just wait on vsync.  I'm sure there is a way to do it in openGL.

A quick google search shows wglSwapIntervalEXT as an extension.  Unsure if that is what you should use.  But I'm sure you can figure it out.

### #5BaneTrapper  Members

Posted 15 January 2013 - 01:39 PM

So my game was running around 50 FPS, but then I reworked my terrain by implimenting GeoMipMapping, and sending my entity draw calls to a frustrum check instead of just rendering all entities.

I'm now pushing 170 fps, and my laptops fan ramps up and gets loud.  I'm assuming this will cook the GPU after a while.

Is there a way to figure out how much to sleep given the FPS? I want to get it back down to 60ish fps (or some lower value).

Really? they didn't buzz before. I mean before rework... The CPU usage would be the same with or without optimization with your description so strange...

### #6HAM  Members

Posted 15 January 2013 - 01:48 PM

So my game was running around 50 FPS, but then I reworked my terrain by implimenting GeoMipMapping, and sending my entity draw calls to a frustrum check instead of just rendering all entities.

I'm now pushing 170 fps, and my laptops fan ramps up and gets loud.  I'm assuming this will cook the GPU after a while.

Is there a way to figure out how much to sleep given the FPS? I want to get it back down to 60ish fps (or some lower value).

Really? they didn't buzz before. I mean before rework... The CPU usage would be the same with or without optimization with your description so strange...

I'm not sure why you would assume his CPU load would be the same when he runs at 50 FPS vs 170 FPS, but it is not relevant.  He asked how to limit his FPS.

### #7wizardpc  Members

Posted 15 January 2013 - 01:57 PM

So my game was running around 50 FPS, but then I reworked my terrain by implimenting GeoMipMapping, and sending my entity draw calls to a frustrum check instead of just rendering all entities.

I'm now pushing 170 fps, and my laptops fan ramps up and gets loud.  I'm assuming this will cook the GPU after a while.

Is there a way to figure out how much to sleep given the FPS? I want to get it back down to 60ish fps (or some lower value).

Really? they didn't buzz before. I mean before rework... The CPU usage would be the same with or without optimization with your description so strange...

I'm not sure why you would assume his CPU load would be the same when he runs at 50 FPS vs 170 FPS, but it is not relevant.  He asked how to limit his FPS.

Thanks HAM, i'll take a look at what you said earlier.  Yea, I'm not multithreaded, so my update and render functions are right after eachother.  Now that I'm pushing 200 FPS, the fan gets really really loud, so I just read up on it, and basically you gave me some good keywords to google search.  I'm wasting cycles drawing the scene that aren't going to matter anways since I'm limited by the refresh rate.

So If I limit my frames to 60 per second, should I only be limiting my Render function (that renders the scene) or both update and render functions.  Update functions handles all game updates, moving objects, AI, etc......  I'm also single threaded.  This is a small game really.  I'm just kinda asking what the best advice is when limiting FPS.

### #8HAM  Members

Posted 15 January 2013 - 02:11 PM

So If I limit my frames to 60 per second, should I only be limiting my Render function (that renders the scene) or both update and render functions.  Update functions handles all game updates, moving objects, AI, etc......  I'm also single threaded.  This is a small game really.  I'm just kinda asking what the best advice is when limiting FPS.

Well since you can run at 200 FPS that means you are not CPU bound.  And for simplicity sake why not just keep it like you have it.

Lock to vsync.   This will lock you state updates, input, and rendering.  If you start wanting to run at lower than 60 that is when it might become a concern for your input timings.    But you'll create more input woes if you want to start threading anyway, so why not keep it as simple as possible until you need something more.

### #9Geometrian  Members

Posted 15 January 2013 - 02:57 PM

http://blogs.msdn.com/b/oldnewthing/archive/2010/12/03/10097861.aspx

And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.

### #10wizardpc  Members

Posted 15 January 2013 - 03:06 PM

So If I limit my frames to 60 per second, should I only be limiting my Render function (that renders the scene) or both update and render functions.  Update functions handles all game updates, moving objects, AI, etc......  I'm also single threaded.  This is a small game really.  I'm just kinda asking what the best advice is when limiting FPS.

Well since you can run at 200 FPS that means you are not CPU bound.  And for simplicity sake why not just keep it like you have it.

Lock to vsync.   This will lock you state updates, input, and rendering.  If you start wanting to run at lower than 60 that is when it might become a concern for your input timings.    But you'll create more input woes if you want to start threading anyway, so why not keep it as simple as possible until you need something more.

Yes thanks, I've learned a bit with this thread.  I'll keep things the way it is, and try to reduce the fps to 60.  I'm at work at the moment, so I'll have to give it a go tonight.

### #11wizardpc  Members

Posted 15 January 2013 - 03:11 PM

http://blogs.msdn.com/b/oldnewthing/archive/2010/12/03/10097861.aspx

I was asking about the Loud fan on my laptop.  i'm guessing it's more GPU related then CPU.  The thing spins up and gets REALLY REALLY loud.  Only when I've got lots of visual apps going on at the same time.

Youtube, face time, and maybe a game.  But no where as loud as when my game launches.  I'm sure it has has to do with me trying to flip the backbuffer as many times as I can with each cycle.

### #12BaneTrapper  Members

Posted 15 January 2013 - 03:52 PM

So my game was running around 50 FPS, but then I reworked my terrain by implimenting GeoMipMapping, and sending my entity draw calls to a frustrum check instead of just rendering all entities.

I'm now pushing 170 fps, and my laptops fan ramps up and gets loud.  I'm assuming this will cook the GPU after a while.

Is there a way to figure out how much to sleep given the FPS? I want to get it back down to 60ish fps (or some lower value).

Really? they didn't buzz before. I mean before rework... The CPU usage would be the same with or without optimization with your description so strange...

I'm not sure why you would assume his CPU load would be the same when he runs at 50 FPS vs 170 FPS, but it is not relevant.  He asked how to limit his FPS.

I assumed his program without leash (no VSync, sleep etc...) had 50FPS before optimization and 170 after optimization.

The CPU usage is same in this case, therefore his fan screaming is result of something other.

i merely misunderstood.

Regarding topic:

I have no experience in OpenGL delay mechanism, there fore i am unable to help.

Going down to 60 fps:

Is there a way to figure out how much to sleep given the FPS? I want to get it back down to 60ish fps (or some lower value).

1000 / 60 = 1.66... per loop

second / FPS = amount time for one loop

This_Loop_Time = (how much time did program take to execute this loop);
Max_Loop_Time = 1000/60;// (second / FPS)
if(This_Loop_Time < Max_Loop_Time)
Delay(Max_Loop_Time - This_Loop_Time)

For sleep, i suggest Google for "c++ Sleep" and find what suits your needs

### #13MarkS  Members

Posted 15 January 2013 - 04:15 PM

So my game was running around 50 FPS, but then I reworked my terrain by implimenting GeoMipMapping, and sending my entity draw calls to a frustrum check instead of just rendering all entities.

I'm now pushing 170 fps, and my laptops fan ramps up and gets loud.  I'm assuming this will cook the GPU after a while.

Is there a way to figure out how much to sleep given the FPS? I want to get it back down to 60ish fps (or some lower value).

I think I need to put something to rest right now that no one else has mentioned. You will NOT cook your GPU because the fan goes up! You would only cook the GPU if the fan dies. Modern GPUs (and CPUs for that matter) have built in heat profiles that adjust fan speed based on core temperature. There is a cut off point that varies by manufacturer and once the temperature passes this point, the hardware will shut down to prevent damage.

Your hardware is doing what it is supposed to and there is nothing wrong. You are wanting to limit performance based on lack of knowledge. Focus your energy on other tasks and be grateful that you can push 170 FPS on a laptop.

Edited by MarkS, 15 January 2013 - 04:19 PM.

### #140r0d  Members

Posted 15 January 2013 - 06:10 PM

So my game was running around 50 FPS, but then I reworked my terrain by implimenting GeoMipMapping, and sending my entity draw calls to a frustrum check instead of just rendering all entities.

I'm now pushing 170 fps, and my laptops fan ramps up and gets loud.  I'm assuming this will cook the GPU after a while.

Is there a way to figure out how much to sleep given the FPS? I want to get it back down to 60ish fps (or some lower value).

So you were running at 50fps, then implemented rendering-related optimizations, and now run much faster.  So, it sounds like you were (or still are) GPU-bound, which means that previously your CPU was sitting around waiting for the GPU to finish.  Now that the GPU does less work, the CPU waits less, and so it does more work.  More work means it gets hotter, so the fan ramps up.

Options:

1. wait for vsync, which should automatically limit it to 60fps

2. put in code at the beginning of each frame to determine the frametime, and sleep until it reaches your target max framerate.

3. dont do anything and let it run as fast as it can.

Running the CPU as fast as possible should not be an issue.  If it is then you need to look at options like underclocking, or maybe open it up and make sure the heatsync isnt clogged with dust, or stuff like that.

BTW for mobile games, limiting the framerate of your game might be a good idea in order to save battery life.  You could even make it an option that the user can select.  Just something to think about.

### #15Vilem Otte  GDNet+

Posted 15 January 2013 - 07:09 PM

Just a little post on OpenGL and VSync topic - look at OpenGL wiki http://www.opengl.org/wiki/Swap_Interval - VSync how-to for more platforms and description (along with Adaptive VSync implementation - which seems like the thing you're looking for).

Edited by Vilem Otte, 15 January 2013 - 07:10 PM.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

### #16jeff8j  Members

Posted 16 January 2013 - 06:55 PM

Set vsync for opengl windows

void System_Set_VSync(bool sync){
</p><div>typedef bool (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int);</div>
<div>PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0;</div>
<div> </div>
<div> </div>
<div>if (wglSwapIntervalEXT)</div>
<div>wglSwapIntervalEXT(sync);</div>
<div>}