120 lines
6.6 KiB
Markdown
120 lines
6.6 KiB
Markdown
------------------------ --------------------------------- --------------------
|
||
[Previous](44-06.html) [Table of Contents](index.html) [Next](45-02.html)
|
||
------------------------ --------------------------------- --------------------
|
||
|
||
Chapter 45\
|
||
Dog Hair and Dirty Rectangles {#Heading1}
|
||
------------------------------
|
||
|
||
### Different Angles on Animation {#Heading2}
|
||
|
||
We brought our pets with us when we moved to Seattle. At about the same
|
||
time, our Golden Retriever, Sam, observed his third birthday. Sam is
|
||
relatively intelligent, in the sense that he is clearly smarter than a
|
||
banana slug, although if he were in the same room with Jeff Duntemann’s
|
||
dog Mr. Byte, there’s a reasonable chance that he would mistake Mr. Byte
|
||
for something edible (a category that includes rocks, socks, and a
|
||
surprising number of things too disgusting to mention), and Jeff would
|
||
have to find a new source of things to write about.
|
||
|
||
But that’s not important now. What is important is that—and I am not
|
||
making this up—this morning I managed to find the one pair of socks Sam
|
||
hadn’t chewed holes in. And what’s even more important is that after we
|
||
moved and Sam turned three, he calmed down amazingly. We had been
|
||
waiting for this magic transformation since Sam turned one, the age at
|
||
which most puppies turn into normal dogs who lie around a lot, waking up
|
||
to eat their Science Diet (motto, “The dog food that costs more than the
|
||
average neurosurgeon makes in a year”) before licking themselves in
|
||
embarrassing places and going back to sleep. When Sam turned one and
|
||
remained hopelessly out of control we said, “Goldens take two years to
|
||
calm down,” as if we had a clue. When he turned two and remained
|
||
undeniably Sam we said, “Any day now.” By the time he turned three, we
|
||
were reduced to figuring that it was only about seven more years until
|
||
he expired, at which point we might be able to take all the fur he had
|
||
shed in his lifetime and weave ourselves some clothes without holes in
|
||
them, or quite possibly a house.
|
||
|
||
But miracle of miracles, we moved, and Sam instantly turned into the dog
|
||
we thought we’d gotten when we forked over \$500—calm, sweet, and
|
||
obedient. Weeks went by, and Sam was, if anything, better than ever.
|
||
Clearly, the change was permanent.
|
||
|
||
And then we took Sam to the vet for his annual check-up and found that
|
||
he had an ear infection. Thanks to the wonders of modern animal
|
||
medicine, a \$5 bottle of liquid restored his health in just two days.
|
||
And with his health, we got, as a bonus, the old Sam. You see, Sam
|
||
hadn’t changed. He was just tired from being sick. Now he once again
|
||
joyously knocks down any stranger who makes the mistake of glancing in
|
||
his direction, and will, quite possibly, be booked any day now on
|
||
suspicion of homicide by licking.
|
||
|
||
### Plus ça Change {#Heading3}
|
||
|
||
Okay, you give up. What exactly does this have to do with graphics? I’m
|
||
glad you asked. The lesson to be learned from Sam, The Dog With A Brain
|
||
The Size Of A Walnut, is that while things may *look* like they’ve
|
||
changed, in fact they often haven’t. Take VGA performance. If you buy a
|
||
486 with a SuperVGA, you’ll get performance that knocks your socks off,
|
||
especially if you run Windows. Things are liable to be so fast that
|
||
you’ll figure the SuperVGA has to deserve some of the credit. Well,
|
||
maybe it does if it’s a local-bus VGA. But maybe it doesn’t, even if it
|
||
is local bus—and it certainly doesn’t if it’s an ISA bus VGA, because no
|
||
ISA bus VGA can run faster than about 300 nanoseconds per access, and
|
||
VGAs capable of that speed have been common for at least a couple of
|
||
years now.
|
||
|
||
Your 486 VGA system is fast almost entirely because it has a 486 in it.
|
||
(486 systems with graphics accelerators such as the ATI Ultra or Diamond
|
||
Stealth are another story altogether.) Underneath it all, the VGA is
|
||
still painfully slow—and if you have an old VGA or IBM’s original PS/2
|
||
motherboard VGA, it’s incredibly slow. The fastest ISA-bus VGA around is
|
||
two to twenty times slower than system memory, and the slowest VGA
|
||
around is as much as 100 times slower. In the old days, the rule was,
|
||
“Display memory is slow, and should be avoided.” Nowadays, the rule is,
|
||
“Display memory is not quite so slow, but should still be avoided.”
|
||
|
||
So, as I say, sometimes things don’t change. Of course, sometimes they
|
||
do change. For example, in just 49 dog years, I fully expect to own at
|
||
least one pair of underwear without a single hole in it. Which brings
|
||
us, deus ex machina and the creek don’t rise, to yet another animation
|
||
method: dirty-rectangle animation.
|
||
|
||
### VGA Access Times {#Heading4}
|
||
|
||
Actually, before we get to dirty rectangles, I’d like to take you
|
||
through a quick refresher on VGA memory and I/O access times. I want to
|
||
do this partly because the slow access times of the VGA make
|
||
dirty-rectangle animation particularly attractive, and partly as a
|
||
public service, because even I was shocked by the results of some I/O
|
||
performance tests I recently ran.
|
||
|
||
Table 45.1 shows the results of the aforementioned I/O performance
|
||
tests, as run on two 486/33 SuperVGA systems under the Phar Lap
|
||
386|DOS-Extender. (The systems and VGAs are unnamed because this is a
|
||
not-very-scientific spot test, and I don’t want to unfairly malign, say,
|
||
a VGA whose only sin is being plugged into a lousy motherboard, or vice
|
||
versa.) Under Phar Lap, 32-bit protected-mode apps run with full I/O
|
||
privileges, meaning that the **OUT** instructions I measured had the
|
||
best official cycle times possible on the 486: 10 cycles. **OUT**
|
||
officially takes 16 cycles in real mode on a 486, and officially takes a
|
||
mind-boggling 30 cycles in protected mode if running *without* full I/O
|
||
privileges (as is normally the case for protected-mode applications).
|
||
Basically, I/O is just plain slow on a 486.
|
||
|
||
As slow as 30 or even 10 cycles is for an **OUT**, one could only wish
|
||
that VGA I/O were actually that fast. The fastest measured **OUT** to a
|
||
VGA in Table 45.1 is 26 cycles, and the slowest is 126—this for an
|
||
operation that’s *supposed* to take 10 cycles. To put this in context,
|
||
**MUL** takes only 13 to 42 cycles, and a normal **MOV** to or from
|
||
system memory takes exactly one cycle on the 486. In short, **OUT**s to
|
||
VGAs are as much as 100 times slower than normal memory accesses, and
|
||
are generally two to four times slower than even display memory
|
||
accesses, although there are exceptions.
|
||
|
||
------------------------ --------------------------------- --------------------
|
||
[Previous](44-06.html) [Table of Contents](index.html) [Next](45-02.html)
|
||
------------------------ --------------------------------- --------------------
|
||
|
||
* * * * *
|
||
|
||
Graphics Programming Black Book © 2001 Michael Abrash
|