Message: 13Date: Fri, 31 May 2002 16:44:43 +0200
From: David Olofsondavid.olofson@reologica.se
To: sdl at libsdl.org
Subject: Re: Re: minimum timeslice fun (was Re: [SDL]
semaphores and
mutexes)
Reply-To: sdl at libsdl.org
On Fri, 31 May 2002 16:44:43 , David Olofson<david.olofson at reologica.se> wrote:
On Fri, 31/05/2002 02:51:10 , Loren Osborn <@Loren_Osborn> wrote:
I think the main concern here seems to be not
burning cycles rendering extra unused (or unusable)
frames… For software surfaces I think the answer
seems to be obvious: Delay by the remainder of the
inverse of the frame rate each time SDL_Flip() is
called…Well, that’s exactly what a proper retrace sync’ed
implementation of the driver’s “flip” operation
does.
With the exception of the actual snycronization that
you mentioned below:
i.e. query the video system to find that the
surface is displayed on a screen running at (let’s
say) 80 Hz… 80 Hz == 12.5 ms per frame. So
every time SDL_Flip() is called on a software
surface, SDL could save the tick-count. If 12
ticks haven’t elapsed since the previous SDL_Flip,
then sleep until they had…Comments?
The first problem with that is that you can’t do it
without proper real time scheduling and high
resolution timers. It could be done on most
platforms, though. (Multimedia timers or Win32, RTC
driver on Linux etc.)
This is indeed true, but there are several cleaver
workarounds to this proposed the last week on this
list…
first, there is the posibility that (at a fairly slow
scan rate) we have a significant time to wait, and we
can request a sleep for a small amount less than that,
and busy wait for the rest… (not ideal or
guarenteed, but a reasonably portable solution)
also someone mentioned tracking how long sleep(0)
takes, and use that to determine if we should busy
wait or not…
another posibility is to query the OS for the amount
of time remaining in this timeslice… The biggest
problem here is also protablity, but it might allow
us to better guess if a sleep(0) is likely to return
in a particular length of time.
The second problem is the big one: Since there’s no
synchronization between the actual refesh rate and
your loop, you’ll have terrible tearing that
slowly drifts over the screen. Seen that during some
experiments, and I’d say it looks a lot worse than
normal, “random” tearing.
I am aware of this issue, but for SOFTWARE surfaces
(which I did specify) the ACTUAL syncronization
SHOULD be handled by the thing that is doing the
actual HARDWARE BLITS… (X server, SDL library,
whatever)… Maybe this is my opinion, but when you
tell a software surface to update a rect, it should be
obvious that you don’t have access to the V-retrace,
and to wait an apropriate time before doing the
Update… either that, or GIVE you access to the
V-retrace position so you can do the checking… (A
big problem with this would be the X server message
round-trip time…
Turn it into a PLL that locks on the refresh rate by
occasionally looking for the retrace, and we’re in
business. This is what I’m trying to do on Linux,
for use with various drivers. (Drivers will need
to occasionally timestamp retraces and pass the
data to a daemon, which will then keep track of
video timing using a real time thread driven by
the RTC, or other suitable IRQ source.)//David
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup