Game Development Reference
In-Depth Information
Figure 17.2. Example Task-based game engine.
process data from the
N
+ 1 frame. When the worker threads complete, the main
thread will submit frame
+1.
To take parallelism to the next step, we need to break up the systems across
threads. The first step is to decompose the work of each system into data-independ-
ent logical tasks. A task is a unit of work for a system that can execute asyn-
chronously. To complete the work of the system, the task function is executed
multiple times. The set of task executions needed to complete the work of a system
is called a taskset. A task can access thread-specific data, but cannot synchro-
nize data between itself and other task instantiations in its taskset. At runtime,
a taskset can execute on any available thread, maximizing the use of all the CPU
cores on a machine without having to create code for the particular number of
availablethreads. Figure17.2 showshowthegamein Figure17.1 canbeconverted
to a task-based approach. The worker thread pool can scale from one thread to
one thread per CPU core.
N
17.2.1 Task-Based Animation
Animation is probably the best system to start with. Let us consider a very simple
example. We have a scene with a variable number of animated models. The models
are stationary and loop through an animation. The animation system takes the
animation data as input and produces the bone matrices as output. Pseudocode
for the animation loop in the main thread is given below (example code is available
on the website):
Foreach Model in ModelList
ComputeBoneMatrices(Model, Time, OutputBones);
 
Search WWH ::




Custom Search