Sleeping in a rendering thread would be good if you could control it better
than “it might sleep for 1 - 10 msec”. There is no point rendering faster
than your display device can update the screen, so either rely on vsync or
don’t sleep at all. Here’s the fun one for you guys:
src/audio/SDL_audio.c(334)
/* The audio mixing is always a high priority thread */
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
There are a few SDL_Delay()s thrown all over the code in there as well.
src/audio/windx5/SDL_dx5audio.c(156)
static void
DSOUND_ThreadInit(_THIS)
{
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
}
src/audio/windib/SDL_dibaudio.c(80)
/* Set high priority for the audio thread */
static void
WINWAVEOUT_ThreadInit(_THIS)
{
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
}
In other words, I’d be more concerned without how SDL’s audio code
synchronizes with the underlying output driver. I also don’t know why
setting a high thread priority would change anything, since it seems quite
clear it is already running at a high priority.
SDL_audio.c line 969-971 creates a thread that starts at the function
SDL_RunAudio(). First thing does it the
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH), then calls ThreadInit() for
the current audio device. On Windows, those are seen above – and they
simply (redundantly) set the thread priority to the highest possible. So it
seems setting the priority of the actual audio code may not be the problem.
SDL 1.2.14 does nearly the same thing. I’d say if anything, the problem is
in SDL_mixer. Any way you get the the thread ID of the mixer and maybe
display a list of all threads in the process + their priorities?
PatrickOn Wed, Apr 20, 2011 at 1:54 PM, Nathaniel J Fries wrote:
Forest Hale wrote:
In performance testing it is useful to disable such sleeping, to see if
you can reach 500fps on your (typically higher end) development computer and
thus have a good bet that your lowend targets will
get 50fps, but this is purely a hypothetical performance measure.
I try to develop on low-end hardware so that rather than being
hypothetical, I can be certain. I recommend this for anyone intending to
target low-end systems.
Forest Hale wrote:
There are some 120hz LCDs out there designed for stereo shutter glasses,
which are quite competent for gaming at 120hz without stereo glasses, and
the visual effect of 120hz gaming is hard to beat
(whether it’s a combination of “real” motion blur in the brain or not, it
looks completely unlike 60hz).
Maybe I should invest in one of these some time, as I’ve never heard of
that. Regardless, if you’re rendering to a 60hz display there’s no point in
notably exceeding 60 fps (same with 75 fps on a 75hz display, although the
user likely wouldn’t notice a difference of 15fps as long as its consistent
anyway).
Forest Hale wrote:
P.S. another curiosity to do with thread synchronization is that some
users have input processing apps running on their computer and this can
cause extreme “mouse lag” if your app never sleeps because
it is causing issues with the input application.
To quote a friend, "nobody truly understands concurrent programming."
The case happening here is essentially an infrequent deadlock on the
processor itself.
@OP: Another alternative to sleeping on the main thread, if you’re
completely against it, is to simply ensure that the two threads are not
running on the same processor [core]. This is easy enough on Windows, but
I’m not sure whether or not thread affinities exist in the POSIX standard.
Because basically what this bug is caused by is that the main thread is
starving the audiospec thread out of the common, shared resource of the
processor itself. However, this issue will still exist on single-core
machines.
EM3 Nathaniel Fries, U.S. Navy
http://natefries.net/
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org