The point is to allow the game to keep running at a high and
steady frame rate, forcing the procedural texture animation to
slow down when the polygon pumping occasionally gets too heavy.
(Similar to what a caching engine would do if the disk is too
slow to cope with the sector changes; tell the rasterizer to use
smaller mip-map versions until the right ones have been loaded.)I don’t think this is a good argument for thread priorities. If
the frame rate drops, then set a flag somewhere telling the
procedural texture thread to sleep instead of processing.
If the frame rate drops, you’re too late to fix anything, as the
damage is already done…
Maybe
that thread needs to check the flag after every row generated or
something (if it’s a really CPU intensive calculation). Again,
that should give much more reliable results than hinting the
scheduler.
Yes, but only if you do all processing cooperatively in a single
thread. Who’s going to update the flag while the procedural texture
generator is hogging the only CPU? (Obviously, this is one case where
SMP systems are significantly different.)
Note that there will be no timesharing switches here, as there are at
best around 1.7 “jiffies” per frame on the average OS, so the threads
essentially run until they sleep, or a higher priority thread wakes
up.
If it had the same priority as the rendering and audio
threads, the timesharing scheduler would eventually give it
higher priority, resulting in massive audio drop-outs and
lots of dropped frames.There’s an easy workaround: have the background threads sleep
most of the time when they get ahead of the main thread.
That’s basically an end-run around the scheduler, but the
results should be much more direct and predictable than doing
it indirectly by mucking around with thread priorities.It doesn’t work, unless the thread that’s supposed to have higher
priority can live with being starved for “extended” amounts of
time when the “low priority” thread eventually needs to do some
work.For example, in real time audio applications, audio latency
should preferably be less than 3 ms (no problems with
Linux/lowlatency), whereas graphics usually deals with frame
periods in excess of 10 ms. Without priorities the only way to do
heavy video rendering (ie using more than a fraction of the CPU
power for video) while processing audio would require partial
rendering or similar hacks.Audio is a lot different than graphics, no argument here. With
audio you really do have a hard real-time constraint, and the
thread that feeds the audio FIFO may indeed need higher priority.
That can be buried in SDL somewhere though, if necessary.
For
graphics I really don’t see the need for application-level thread
priorities.
It’s virtually impossible to implement perfect full frame rate
animation with more than one thread without priorities, as you cannot
take a single dropped frame without clearly visible jerking.
Of course, one could just argue that anything that’s sufficiently
“simple” to run full frame rate cannot be multithreaded, or that
constant full frame isn’t possible on computer hardware (a lie) or
whatnot, but the problem doesn’t go away just because it’s ignored.
The question is just if we should stick to single
threaded/cooperative threading engines, require MP machines, or
implement coarse priority control.
//David
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |
--------------------------------------> david at linuxdj.com -'On Tuesday 13 March 2001 03:46, Thatcher Ulrich wrote: