Frame rate, vsync and CPU usage

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
muku
Prole
Posts: 18
Joined: Wed Aug 20, 2008 11:35 am

Frame rate, vsync and CPU usage

Post 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?
User avatar
muku
Prole
Posts: 18
Joined: Wed Aug 20, 2008 11:35 am

Re: Frame rate, vsync and CPU usage

Post 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.
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Frame rate, vsync and CPU usage

Post by qubodup »

How to enable vsync?

(ideally, prepare two individual love files so that the laziest can test too.)
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
muku
Prole
Posts: 18
Joined: Wed Aug 20, 2008 11:35 am

Re: Frame rate, vsync and CPU usage

Post 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"
Attachments
vsync_on.love
(482 Bytes) Downloaded 413 times
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Frame rate, vsync and CPU usage

Post by qubodup »

no 100% cpu usage (no real increase really), one core, geforce fx 5200 (nvidia), proprietary driver, debian linux

76fps
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
muku
Prole
Posts: 18
Joined: Wed Aug 20, 2008 11:35 am

Re: Frame rate, vsync and CPU usage

Post by muku »

Thanks. That supports my ATI/NVidia theory.

Anyone else?
emonk
Prole
Posts: 24
Joined: Tue Aug 12, 2008 11:43 am

Re: Frame rate, vsync and CPU usage

Post 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.
Sarcasm - just one of the services I offer.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Frame rate, vsync and CPU usage

Post 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.
User avatar
muku
Prole
Posts: 18
Joined: Wed Aug 20, 2008 11:35 am

Re: Frame rate, vsync and CPU usage

Post by muku »

Hm. That's interesting. So the ATI/NVidia divide doesn't seem to be as clear cut as I thought.
User avatar
amnesiasoft
Prole
Posts: 12
Joined: Wed Aug 20, 2008 8:59 pm
Location: Denver, Colorado
Contact:

Re: Frame rate, vsync and CPU usage

Post by amnesiasoft »

The VSync test gives me 100% on a core. Vista Ultimate x86, GeForce 8800 GTS 320 (177.83), and a Q6600.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 44 guests