[SDL] CSDL with quad-buffering and a seperate flip-thread
David Olofson
david.olofson at reologica.se
Wed Mar 13 13:03:01 PST 2002
On Wednesday 13 March 2002 21:26, Martijn Melenhorst wrote:
> >2) leads people to think that retrace sync can only be implemented by
> >busy-waiting once per frame, which is *not* the case.
>
> Well, I can still remember the Commodore 64, which had an interrupt for
> it. You just set addresses $0314 and $0315 to the address of your
> vsync'ed routine, et voila! Oh, those good old days... So, interrupts
> should be able to deliver a nice non-busy-wait solution?
Yes - but as there seems to be many cards that don't have retrace IRQ, an
alternative solution is required.
Basically, from the kernel perspective, to avoid busy-waiting, you must
have *some* IRQ source to wake up sleepers. (A "sleeper" here would be -
directly or indirectly - an application that needs another buffer to
render into, while all buffers are enqueued for display.)
My first approach will be to use the RTC device (*) to wake the "page
flipping thread" of the driver up some time before the "next" retrace,
and after the "previous" retrace.
To figure out which timer IRQs are to be used, I'll use a PLL that locks
on the video refresh rate. Input to the PLL will be provided by a thread
that runs at very low priority, polling for the retrace event, and
passing timestamps to the PLL whenever a retrace is detected.
I've already implemented a primitive version of this (without the RTC
thread), which I hacked into a Utah-GLX OpenGL driver. Even without
hitting *any* retraces, the "PLL" would only drift in the order of
percents of a frame per *minute* - so having a real PLL lock on the
occasional "hit" that a low level polling thread can get shouldn't be a
problem.
Besides, with h/w pageflipping, I only need to ensure that the flip
occurs somewhere in between the right two retraces - starting a top-down
blit right before the raster beam leaves the bottom of the screen, to
avoid tearing (as in my Utah-GLX hack) is not required.
Even an old standard Linux kernel should hit every frame most of the
time. A Linux/lowlatency kernel would not miss a frame, ever.
(*) The "Real Time Clock" - a hardware timer that can generate interrupts
at 64, 128, 256, 512 etc Hz, among other things, and is present on
virtually anything that Linux runs on.
> >There *will* be retrace sync and pageflipping on all properly
> > supported video cards on Linux eventually, if I can help it. I
> > frankly don't care if some people consider tearing and jittering
> > acceptable. I do not, and I intend to figure out a way to fix it,
> > unless someone beats me to it.
>
> Now THAT's a "I won't give up" attitide I like :)
Well, you know, my world collapsed when I left the Amiga for the PC, and
it didn't get any better when DOS was totally obsoleted.
Now that I've found an OS that has great potential, already does most of
what I want, and can be modified as needed if all else fails, I'm not
going anywhere! :-)
//David Olofson --- Programmer, Reologica Instruments AB
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`-------------------------------------> http://olofson.net -'
More information about the SDL
mailing list