![]() |
|
Semaphores w/ Vsync, or Semaphores w/ Triple Buffering? |
Falciase
Member #10,908
April 2009
![]() |
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. 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. ____________________________________ |
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
![]() |
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. -- |
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
![]() |
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. -- |
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. |
|