Game Development Reference
In-Depth Information
TaskDecl AnimateModel(TaskId, NumberOfTasksInSet)
{
ComputeBoneMatricies(
ModelList[ TaskId ],
Time,
OutputBones[ TaskId ] );
}
TaskSetHandle = CreateTaskSet(
AnimateModel ,
NumberOfModels ,
NoDependecies);
// Other processing on the main thread.
WaitForTaskSet( TaskSetHandle );
// Consume data produced by taskset.
Listing 17.1. Pseudocode for creating a taskset.
We can extract parallelism with threads by separating the loop into another
thread. We can write code to use all the threads on the machine that would detect
the number of threads and try to distribute the work. Each game would have to
implement its own thread scheduling as well as any interoperation between the dif-
ferent systems. All middleware used by the game would have to be compatible with
the game's custom scheduling for maximal e ciency. Scheduling code is di cult
to debug since deadlock or timing bugs can be harder than average to find. Game
developers want to spend time making great games, not working on infrastructure
code.
With a task-based implementation, the scheduling of tasks is delegated to the
tasking system. The programmer only needs to specify the task function. The
AnimateModel function in Listing 17.1 is a task. The game animates the models
in the frame by creating a taskset. When the animation data are needed, the main
thread can wait for the taskset to complete.
The tasking system abstracts the scheduling of tasks and the number of hard-
ware threads on the machine. The programmer can divide up the work into tasks
based on the workload and create tasksets. Task sets from multiple game systems
are scheduled cooperatively by the tasking system. The tasking system maintains
a list of all tasksets in the game and executes only tasksets that are ready to run.
There is no execution overhead from tasksets that are not ready to run. Task sets
are ready to run when all of their dependent tasksets have completed. Consider
the case where taskset B requires the output of taskset A. The main thread can
specify to the tasking system that taskset B depends on the completion of taskset A
Search WWH ::




Custom Search