![]() |
vkmEngine 1.0.15
A C++ game engine · vkmengine.com
|
The engine has one thread pool, for data-parallel work inside a system and for background jobs (asset decodes, bakes). Systems run one after another, never against each other (architecture.md); a system scales by splitting its own loop with parallelFor.
A free function in platform/threading/thread_pool.h, the call most code wants:
The callback takes the index. An overload parallelFor(count, grain, function) sets the chunk size; without it, a range below MIN_PARALLEL items runs serially on the caller, and a larger one is cut into several chunks per thread so a preempted thread's share goes to the others.
ThreadPool::get() is the singleton. It spawns one worker fewer than the physical cores (SMT siblings counted once), because the calling thread runs work too and the driver, audio and OS need room (a row in engine.md).
Waiting is per batch, never global. The pool is shared with background decodes, and a barrier on everything in flight would park a frame behind a file read.
Batches go first. Batches and tasks sit in two queues, and a worker drains the batch queue before the task queue: a batch has the frame blocked on it, a task does not.
The main parallelFor users are VisibilitySystem, HierarchySystem, AnimationSystem, SkeletalAnimationSystem and PhysicsSystem's narrowphase (physics.md). GLShadowData::cullCasters forks a batch by hand (one index per cascade, spot and cube face) and GLShadowData::finishCull waits on it just before the first pass, so the rest of the backend's frame build runs beside the cull.