Page 1 of 2

Frame rate, vsync and CPU usage

Posted: Wed Aug 20, 2008 11:50 am
by muku
Hi there, just recently discovered Löve and I think it's lövely.

There's something about CPU usage that's bugging me though. There has been a thread about this a while back, but the thread has since turned to other topics, so I figured I'd start a new one. Take the following code:

Code: Select all

function load()
	love.graphics.setFont(love.graphics.newFont(love.default_font, 12))
end

function draw()
	love.graphics.draw(love.timer.getFPS() .. ' fps', 100, 100)
end
If I run this with vsync disabled in my conf file, I get ~800 fps with full CPU usage; that's about what I would have expected, so no worries there. Now, when I enable vsync, I get a pretty steady 75 fps (which is my monitor's refresh rate), but still full CPU usage! That's definitely not what I would expect.

If I insert a function

Code: Select all

function update(dt)
	love.timer.sleep(10)
end
then, with vsync disabled, I get ~90 fps with almost no CPU use. If I enable vsync, I get my 75 fps again, but with ~20% CPU use. Does the vsync code actually busy-wait for the vertical retrace? This is Win2k with a Radeon 9500. Might this be a driver issue?

Re: Frame rate, vsync and CPU usage

Posted: Wed Aug 20, 2008 3:08 pm
by muku
Hmm. After some digging, it seems that ATI drivers actually run a busy loop while they're waiting for vsync, which seems pretty stupid to me, especially since NVidia seems to get along just fine without that.

To confirm that, I would appreciate it if other people (both with ATI and NVidia cards) could run the sample program with vsync on and off and report what CPU use they get.

Re: Frame rate, vsync and CPU usage

Posted: Wed Aug 20, 2008 3:38 pm
by qubodup
How to enable vsync?

(ideally, prepare two individual love files so that the laziest can test too.)

Re: Frame rate, vsync and CPU usage

Posted: Wed Aug 20, 2008 4:24 pm
by muku
Good idea. I guess we only really need to test the version with VSync on because without it it's going to eat 100% CPU anyway. I'm attaching the VSync version, so all you have to do is run it and report framerate and CPU usage (from Task Manager or equivalent); also mention video card make and whether you are running single- or multi-core.

Also, since you asked, here's the configuration file for turning VSync on:

Code: Select all

title = "VSync test"
author = "muku"
width = 640
height = 480
fullscreen = false
vsync = true
fsaa = 0
love_version = "0.3.2"

Re: Frame rate, vsync and CPU usage

Posted: Wed Aug 20, 2008 6:11 pm
by qubodup
no 100% cpu usage (no real increase really), one core, geforce fx 5200 (nvidia), proprietary driver, debian linux

76fps

Re: Frame rate, vsync and CPU usage

Posted: Wed Aug 20, 2008 6:19 pm
by muku
Thanks. That supports my ATI/NVidia theory.

Anyone else?

Re: Frame rate, vsync and CPU usage

Posted: Wed Aug 20, 2008 6:21 pm
by emonk
GeForce 7300GS on WinXP at 60fps. Task manager shows mostly 0% for Love running the sample, occasionally going as high as 3%.

I think that shows that NVIDIA drivers at least are ok. Now we need some results from other card types to compare.

Re: Frame rate, vsync and CPU usage

Posted: Thu Aug 21, 2008 2:28 pm
by rude
  • GeForce 7950GT
  • Windows XP SP3
  • 60 FPS
  • 100% of one CPU core.
Seems like my setup is busy-waiting as well, but I know it didn't use to back in the days.

Re: Frame rate, vsync and CPU usage

Posted: Thu Aug 21, 2008 3:28 pm
by muku
Hm. That's interesting. So the ATI/NVidia divide doesn't seem to be as clear cut as I thought.

Re: Frame rate, vsync and CPU usage

Posted: Thu Aug 21, 2008 10:03 pm
by amnesiasoft
The VSync test gives me 100% on a core. Vista Ultimate x86, GeForce 8800 GTS 320 (177.83), and a Q6600.