Message-ID:
<CAGDaZ_pZnTSnLKrELeUSn35_TF_ANngC3+XQD5UzWB3aPui_XQ at mail.gmail.com>
Content-Type: text/plain; charset=“utf-8”
Are renderers actually bound to specific threads or is it just a matter of
concurrency and protecting shareable data structures from race conditions?
I would guess that you can create a renderer in one thread and use it in
another as long as you lock it so they can’t both stomp on it at the same
time, and you use memory barriers to ensure synchronization.
Is this correct?
I’m not sure about right now, but at least at one time the reason for
only rendering in the main thread was “it’s the Operating System’s
fault!”. I remember, because I used to say it fairly often. The (old)
breakdown is like this:
X Windows theoretically doesn’t care, since it conceptually marshalls
everything over a socket, but see the MS Windows case.
MS Windows used to support multi-threaded access… but everything got
routed through a single render thread anyways, so it didn’t count for
anything other than design purposes. A quick browse suggests that the
current situation is more flexible, but that thread-safe options
reduce performance, as should be expected (synchronization costs).
iOS, used on the iPhone, was spectacular: EVERY time that you tried to
render from ANY thread other than the main one, the main thread and
rendering thread were paused, and the main thread did the rendering
thread’s work. THIS is the specific reason for the “only render in the
main thread” rule: old versions of iOS (I think they might have
changed it) enforced the rule even if you didn’t notice.
So, rendering in a non-main thread? Completely possible! But don’t do
it, because it’s stupid (synchronization reduces performance, despite
the extra threads), and pointless (you can have as many threads as you
want, but rendering is done by hardware that you CANNOT create with a
call to a CreateGPU() function). Just run user I/O and rendering
through your main thread instead: it maximizes performance, while
localizing all user-facing code to a single location, thus following
the Unix Rule: “do one thing, and do it well”. Everything else (e.g.
decompressing image formats, receiving dynamic resources in an MMO
client, modelling the game world) should ideally be what your other
threads get used for.> Date: Thu, 17 Sep 2015 14:42:39 -0700
From: Raymond Jennings
To: SDL Development List
Subject: Re: [SDL] Load textures in background thread, not possible?