Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Semaphores w/ Vsync, or Semaphores w/ Triple Buffering?

This thread is locked; no one can reply to it. rss feed Print
Semaphores w/ Vsync, or Semaphores w/ Triple Buffering?
Falciase
Member #10,908
April 2009
avatar

Hello all. I am currently using semaphores on my game to ensure it runs the same speed on all computers, and also runs efficiently with the CPU. At the moment, my game will run using about 3% of my CPU, ~100MHz.

This is the reference I have for semaphore usage in my game.
http://wiki.allegro.cc/index.php?title=Timers

It runs at 60 updates a second with simple double buffering, and works well. I am looking for a way to eliminate the occasional visible tearing, however.

I've done a bit of research, and have found that simply putting vsync() right before my blit of the buffer to the screen completely eliminates the tearing problem. However, doing so puts the CPU usage right back through the roof at 25% of my quad core 3.2 GHz processor, taking up an entire core.

Is there a way to get vsync to work with semaphores? Vsync apparently completely overrides the semaphore, as omitting the semaphore parts of my code has no effect whatsoever on game performance or CPU usage. Perhaps I should look into switching to triple buffering? I've read that triple buffering eliminates the need for vsync, but does triple buffering work with semaphores as well?

Any answers or comments would be fantastic. Thank you for your help. ;D

____________________________________
Falcon Five's Development Site

Bainemo
Member #11,031
June 2009

From what I understand, Vsync will max out your CPU (or, in multicore situations, one core) no matter what you do. Triple buffering is definitely your best bet. In fact, most 3D games nowadays use it (as you've no doubt noticed).

You MAY be able to lower your CPU usage by adding rest(0) to your program, but I'm not sure. I've never tried it myself. Apparently what that does is allow your CPU to do things other than run your game when it wants to, whereas without rest() the game takes up as much CPU power as it wants. Like I said, though, that may be untrue with vsync.

Thomas Fjellstrom
Member #476
June 2000
avatar

A proper vsync will NOT max out a core. Normally a vsync call makes your program sleep till the gfx card returns a vsync interrupt.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Bainemo
Member #11,031
June 2009

I based my "100% CPU" advice on the first couple posts in this thread. I glanced through it a couple days ago while looking for timer advice, but never finished it since they mostly started talking about semaphores and missed frames and various other problems I don't have. It may help you, Falciase, since the creator of that topic seemed to have been having the same issue you do now.

Thomas Fjellstrom
Member #476
June 2000
avatar

what vsync will do if used improperly will manage to steal over half of your rendering time from you, which generally causes your code to spend too much time, miss a vsync, which causes tearing. Mucho fun.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Bob Keane
Member #7,342
June 2006

By reading this sig, I, the reader, agree to render my soul to Bob Keane. I, the reader, understand this is a legally binding contract and freely render my soul.
"Love thy neighbor as much as you love yourself means be nice to the people next door. Everyone else can go to hell. Missy Cooper.
The advantage to learning something on your own is that there is no one there to tell you something can't be done.

Go to: