CSDL with quad-buffering and a seperate flip-thread

[…]

The solution I made actually works, by the way, and it will on every
graphics card, as long a it is running Windows, I guess, since those
drivers do have a vsync functionality…

Yes! I don’t know of any video card that doesn’t have some way of
implementing “retrace sync” - and it seems that all Windows drivers make
use of that feature of it’s respective card.

The only real problems with Linux are:

1) Driver architectures are lacking support for
   hardware pageflipping.

2) Most cards support only polling. (Or so it
   seems...)
  1. is a result of obsolete design - nothing else. Seems like this is in
    the process of being fixed in XFree86 4.x, unless I’m missing something.

  2. leads people to think that retrace sync can only be implemented by
    busy-waiting once per frame, which is not the case.

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.

//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 -'On Wednesday 13 March 2002 20:03, Martijn Melenhorst wrote:

  1. 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?

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 :slight_smile:

Hi Bob,

Bob Pendleton wrote:

If you really want to you can go get Amiga OS 4.0 and use it. I recently
signed their developer NDA got their SDK. Very nice, very much alive.

I could be wrong, but don’t most NDA’s actually prohibit you from saying
that you are actually testing a product. And as so by saying that you
have signed one you have effectively broken your NDA?
Maybe this NDA is different. All the oned I have signed, always stop the
signer from saying anythiing about the new product.

Dominique.–
http://www.DelphiGamer.com := for all your Object Pascal game
development needs;
http://www.delphi-jedi.org/Jedi:TEAM_SDL_HOME := Home of JEDI-SDL;
Cross-platform game development with Pascal, has never been easier.

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.

Cheer

So are you joining the Xfree86 project then? :slight_smile: Or do you have other ideas
for doing this?

  1. 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 :slight_smile:

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! :slight_smile:

//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 -'On Wednesday 13 March 2002 21:26, Martijn Melenhorst wrote:

David Olofson wrote:

[…]

If you really want to you can go get Amiga OS 4.0 and use it. I
recently signed their developer NDA got their SDK. Very nice, very much
alive.

“developer NDA”? Oh, well…

You don’t have to sign the NDA to be a developer. It does get you access
to private information, as it should. I really don’t understand why so
many people have an aversion of signing NDAs…> On Wednesday 13 March 2002 18:35, Bob Pendleton wrote:

Still, good to hear that it’s alive.

//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 -’


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


±-----------------------------------+

  • Bob Pendleton is seeking contract +
  • and consulting work. Find out more +
  • at http://www.jump.net/~bobp +
    ±-----------------------------------+

| to private information, as it should. I really don’t understand why so
| many people have an aversion of signing NDAs…

Well in the Linux/free software world, it’s kind of totally against the
whole idea of sharing your code and makes it completely impossible to
release your source.

Also… once you sign the NDA, and you see the code, should you happen
to “invent” similar code yourself (without attempting to rip off the
code you’ve seen, the code just happens to be logical to anyone trying
to do that particular task) the people you signed the NDA with will quite
probably attempt to sue you. I believe this is why RMS refused to look
at proprietary UNIX code when he was creating GCC, etc.On Wed, Mar 13, 2002 at 03:07:34PM -0600, Bob Pendleton wrote:


I will not send lard through the mail
6AD6 865A BF6E 76BB 1FC2 | www.piku.org.uk/public-key.asc
E4C4 DEEA 7D08 D511 E149 | www.piku.org.uk wnzrf at cvxh.bet.hx (rot13’d)

David Olofson wrote:> On Wednesday 13 March 2002 18:32, Bob Pendleton wrote:

[…]

Most of the discussion, has imho, been pretty pointless since the
solutions depend on the behavior of specific, hardware, drivers, and
OSes… There hasn’t been a portable way to synch to vertical retrace
since the first svga cards came out.

Some where around here I have a nice modex triple buffer renderer that
I wrote back in '93 or '94. It was obsolete by the end of '95 and so
was this whole line of argument…

So, tearing and “jittering” is state-of-the-art these days?

Nope, very simple timer based loops will give you smooth animation. What
I hope is obsolete is spending time developing programs that depend on
special features of a single OS or class of video cards. Life is too
short to spend it writing code that is going to break on the next
machine it is run on.

This is a pet peeve of mine. You are of course allowed to disagree with
me and I accept that. Just don’t expect me to ever agree with you.

Can you stand a story? If not, hit delete now.

A long time ago I was trying to hire a couple of game programmers. And,
of course, the advertisment yielded a lot of resumes and a stack of
demos. I was going through the demos testing them when I came to one
that required a 3 botton mouse. Now I have nothing against 3 button
mice. I have used one for many years under UNIX/Linux and prefer them to
any other kind of mouse. But, this was a DOS/Windows programming job and
those mice have 2 buttons and so did my test machine. So I threw the
demo away and went on with my testing.

At that point I would have said that the moral of the story is that “the
code has to work on the customers machine.”

Turns out the guy who wrote the code was amazed that I wasn’t impressed
by his cleverness at having written his own 3 button mouse driver for
DOS. He was even more amazed that I wouldn’t go out an buy his specific
make and model of mouse so that I could run his demo. He never did seem
to understand that the stupidity of writing a demo that would only run
on his computer far out weighed the cleverness needed to code a mouse
driver. Moral of the story and back to the topic: I, personally, am much
more impressed by the programmer who can do the data and code designed
well enough that the program works well across a wide range of systems
than I am with the programmer who can get a machine/video card/OS
specific quad-buffering system to work. You need to know where to spend
you resources.

	Bob P.

P.S.

I know I never should have opened my mouth on this subject and here by
apologize to everyone I have offended and promise not to say another
thing about this subject again.

Dominique Louis wrote:

Hi Bob,

Bob Pendleton wrote:

If you really want to you can go get Amiga OS 4.0 and use it. I
recently signed their developer NDA got their SDK. Very nice, very
much alive.

I could be wrong, but don’t most NDA’s actually prohibit you from saying
that you are actually testing a product. And as so by saying that you
have signed one you have effectively broken your NDA?

This one doesn’t stop me from saying I signed the NDA and I never ever
said that I was testing anything. Nor, did I say that I had to sign the
NDA to get the SDK, anyone can buy the SDK. Don’t read more into it than
what I said. If you want to read the NDA and find out what signing it
gets you go to www.amigadev.net and down load a copy.

Maybe this NDA is different. All the oned I have signed, always stop the
signer from saying anythiing about the new product.

Actually for most of the product testing I have done the organizations I
worked for were more worried about keeping the product manufacturer from
telling people we were testing it than the manufacturer was about our
telling people we were testing it.

Everyone’s experiences are different.

	Bob Pendleton> 

Dominique.


±-----------------------------------+

  • Bob Pendleton is seeking contract +
  • and consulting work. Find out more +
  • at http://www.jump.net/~bobp +
    ±-----------------------------------+

David Olofson wrote:

[…]

If you really want to you can go get Amiga OS 4.0 and use it. I
recently signed their developer NDA got their SDK. Very nice, very
much alive.

“developer NDA”? Oh, well…

You don’t have to sign the NDA to be a developer.

Ok.

It does get you
access to private information, as it should. I really don’t understand
why so many people have an aversion of signing NDAs…

Probably because they are usually incompatible with Free/Open Source
software…

//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 -'On Wednesday 13 March 2002 22:07, Bob Pendleton wrote:

On Wednesday 13 March 2002 18:35, Bob Pendleton wrote:

Well, it depends on how things turn out, but I’d guess the scale of it is
more in the order of a some contributed code. The only issue that might
require deep hacks in XFree86 is the actual pageflipping. The other stuff
should be fairly trivial, possibly except for testing for retrace on SMP
machines with some video cards…

//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 -'On Wednesday 13 March 2002 21:47, Jason Hoffoss wrote:

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.

Cheer

So are you joining the Xfree86 project then? :slight_smile: Or do you have other
ideas for doing this?

James wrote:

| to private information, as it should. I really don’t understand why so
| many people have an aversion of signing NDAs…

Well in the Linux/free software world, it’s kind of totally against the
whole idea of sharing your code and makes it completely impossible to
release your source.

What did I say that made you think I get to look at any source code? Why
do you think this has anything to do with source code?

Also… once you sign the NDA, and you see the code, should you happen
to “invent” similar code yourself (without attempting to rip off the
code you’ve seen, the code just happens to be logical to anyone trying
to do that particular task) the people you signed the NDA with will quite
probably attempt to sue you. I believe this is why RMS refused to look
at proprietary UNIX code when he was creating GCC, etc.

You really need to read something on patent and copyright law. When you
are trying to clone a complete system then you have to work with clean
room rules. On the other hand, the law completely understands that
similar function can result in similar structure with no implication of
copying.

BTW, I can be sued whether or not you have signed and NDA or looked at
the code. They can sue even if there is no reason to believe that you
did anything wrong. (Look up SLAPP.) They can win a suite even if you
have never signed an NDA or looked at the code, they just have to prove
that you could have looked at the code.> On Wed, Mar 13, 2002 at 03:07:34PM -0600, Bob Pendleton wrote:

David Olofson wrote:

[…]

Most of the discussion, has imho, been pretty pointless since the
solutions depend on the behavior of specific, hardware, drivers, and
OSes… There hasn’t been a portable way to synch to vertical
retrace since the first svga cards came out.

Some where around here I have a nice modex triple buffer renderer
that I wrote back in '93 or '94. It was obsolete by the end of '95
and so was this whole line of argument…

So, tearing and “jittering” is state-of-the-art these days?

Nope, very simple timer based loops will give you smooth animation.

I don’t see how you can ever get smooth animation without rendering
exactly one frame per refresh…

What I hope is obsolete is spending time developing programs that
depend on special features of a single OS or class of video cards.

This is a feature that’s been available in some form on every video
card for ages. I don’t know of any Windows driver that does not support
it.

Life
is too short to spend it writing code that is going to break on the
next machine it is run on.

Doesn’t seem to break on any Windows machines, unless retrace sync has
been explicitly turned off by the user…

In fact, it wouldn’t break anyway. There would just be some tearing.

This is a pet peeve of mine. You are of course allowed to disagree with
me and I accept that. Just don’t expect me to ever agree with you.

Likewise. :slight_smile:

Can you stand a story? If not, hit delete now.

A long time ago I was trying to hire a couple of game programmers. And,
of course, the advertisment yielded a lot of resumes and a stack of
demos. I was going through the demos testing them when I came to one
that required a 3 botton mouse. Now I have nothing against 3 button
mice. I have used one for many years under UNIX/Linux and prefer them
to any other kind of mouse. But, this was a DOS/Windows programming job
and those mice have 2 buttons and so did my test machine. So I threw
the demo away and went on with my testing.

At that point I would have said that the moral of the story is that
"the code has to work on the customers machine."

Turns out the guy who wrote the code was amazed that I wasn’t impressed
by his cleverness at having written his own 3 button mouse driver for
DOS. He was even more amazed that I wouldn’t go out an buy his specific
make and model of mouse so that I could run his demo. He never did seem
to understand that the stupidity of writing a demo that would only run
on his computer far out weighed the cleverness needed to code a mouse
driver. Moral of the story and back to the topic: I, personally, am
much more impressed by the programmer who can do the data and code
designed well enough that the program works well across a wide range of
systems than I am with the programmer who can get a machine/video
card/OS specific quad-buffering system to work. You need to know where
to spend you resources.

I see your point, but I don’t see how it applies to something that’s
available on basically every DirectX compatible video card…

//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 -'On Wednesday 13 March 2002 22:36, Bob Pendleton wrote:

On Wednesday 13 March 2002 18:32, Bob Pendleton wrote:

At 21:26 13.03.2002 +0100, you wrote:

  1. 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?
I don’t want to say something bad, bad using $314++ was the
lamer-sort-of-irq … if you needed a sync, you shouldn’t have to wait for
the system to pass the IRQ on to you … sorry, I think I know how it
really works on a Z?hVieh (sorry, broken German) - use $FFFE/$FFFF for
IRQ’s … and you’ll be sure the delay is only what’s actually needed (a
max of 7+3 cycles for the IRQ and quitting previously running commands +
maybe the badline-delay of 20 cycles, but who generates an IRQ in a
BadLine?) … OK, you see, it’s been just a year since I’ve been coding
C=64 …
St0fF.

BTW, I can be sued whether or not you have signed and NDA or looked at
the code. They can sue even if there is no reason to believe that you
did anything wrong. (Look up SLAPP.) They can win a suite even if you
have never signed an NDA or looked at the code, they just have to prove
that you could have looked at the code.

Wouldn’t they need to prove beyond a resonable doubt that you did look at
their code? Seems like that’s what they would need to do. Just because one
could have looked at the code doesn’t mean they did.

-Jason

----- Original Message -----
From: bob@pendleton.com (Bob Pendleton)
To:
Sent: Wednesday, March 13, 2002 5:11 PM
Subject: Re: [SDL] CSDL with quad-buffering and a seperate flip-thread

I don’t see how you can ever get smooth animation without rendering
exactly one frame per refresh…

I think your definitions of smooth animation might be different. It’s
something of a subjective thing, after all. You could render 1 frame ever 2
refreshes, and some would say it’s smooth, while others wouldn’t. Sounds
like your definition is at the high end to me.

What I hope is obsolete is spending time developing programs that
depend on special features of a single OS or class of video cards.

This is a feature that’s been available in some form on every video
card for ages. I don’t know of any Windows driver that does not support
it.

Then I say it’s long overdue that it’s added to X. :slight_smile:

-Jason

----- Original Message -----
From: david.olofson@reologica.se (David Olofson)
To:
Sent: Wednesday, March 13, 2002 5:18 PM
Subject: Re: [SDL] CSDL with quad-buffering and a seperate flip-thread

I see your point, but I don’t see how it applies to something that’s
available on basically every DirectX compatible video card…

And once again, David, I second that :slight_smile: If I ever want to make money developing games, I have to write an engine for myself that promises smooth
animation and same-speed game logics on EVERY system out there, no matter how slow the graphics card, no matter how fast the CPU.

So, in Torsten’s perspective, I have done a great job, actually. If Torsten just keeps throwing out frames without caring for the vsync, his games will
move very irratically, basically, and mine won’t. That’s the whole point. If Linux can’t even give me vsync-control, I can not, notice this sentence, I
can not EVER write a same-performance, same-smooth games on these systems. So: I drop Linux support for now. Fact is, most games-people
aren’t using it anyway, sorry about that. And also, I don’t think using Linux for gaming is a wise idea anyway, it a server OS, let’s please use it as
that and make it great in that aspect (and finally throw Windows out of THAT area since it really sucks there :slight_smile: It’s clear to me now, more than ever,
that it wasn’t designed to use for games anyway.

I think your definitions of smooth animation might be different. It’s
something of a subjective thing, after all. You could render 1 frame ever 2
refreshes, and some would say it’s smooth, while others wouldn’t. Sounds
like your definition is at the high end to me.

But: If you start rendering this 1 frame while the screen has JUST started to render the frame to the screen (or if you flip a drawn frame at this
point), the screen will start drawing your new frame, with old frame-content already on-screen. This is the tearing effect you want to avoid at all
times. Especially when full-screen: People will get sick, almost, by playing your game then :frowning:

I don’t see how you can ever get smooth animation without rendering
exactly one frame per refresh…

I think your definitions of smooth animation might be different.

Most probably, yes.

It’s
something of a subjective thing, after all. You could render 1 frame
ever 2 refreshes, and some would say it’s smooth, while others
wouldn’t. Sounds like your definition is at the high end to me.

My definition is brutally simple:

1) One frame per CRT refresh.

2) "Constant speed" means that an object moves N pixels
   every frame, where...

3a) ...N is the nearest integer number for each frame,
    that would accumulate to the exact speed, OR...

3b) ...N is the "exact" (speed / frame rate), which
    requires sub-pixel accurate rendering.

If those conditions aren’t met, it’s not smooth animation, as I see it.
(Well, at least, that’s how my eyes see it - regardless of my opinion.)

What I hope is obsolete is spending time developing programs that
depend on special features of a single OS or class of video cards.

This is a feature that’s been available in some form on every video
card for ages. I don’t know of any Windows driver that does not
support it.

Then I say it’s long overdue that it’s added to X. :slight_smile:

Really!? :wink:

//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 -'On Thursday 14 March 2002 07:15, Jason Hoffoss wrote:

----- Original Message -----
From: “David Olofson” <david.olofson at reologica.se>
To:
Sent: Wednesday, March 13, 2002 5:18 PM
Subject: Re: [SDL] CSDL with quad-buffering and a seperate flip-thread

Tearing doesn’t happen with hardware pageflipping, even if you miss
frames.

Hardware pageflipping is one thing - retrace sync is another. For
absolutely smooth animation without tearing, you need both.

//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 -'On Thursday 14 March 2002 07:58, Martijn Melenhorst wrote:

I think your definitions of smooth animation might be different. It’s
something of a subjective thing, after all. You could render 1 frame
ever 2 refreshes, and some would say it’s smooth, while others
wouldn’t. Sounds like your definition is at the high end to me.

But: If you start rendering this 1 frame while the screen has JUST
started to render the frame to the screen (or if you flip a drawn frame
at this point), the screen will start drawing your new frame, with old
frame-content already on-screen. This is the tearing effect you want to
avoid at all times. Especially when full-screen: People will get sick,
almost, by playing your game then :frowning: