Nebula
|
Job system allows for scheduling and execution of a parallel task.
A model context bind a ModelInstance to a model, which allows it to be rendered using an .n3 file.
The job system works as follows. First one creates a job port with a name and some threads. The threads will be named as the port but with their index appended.
The job port has a priority, meaning all jobs sent to this port will inherit said priority. The job ports are then updated every frame to schedule work packages.
A job is not single-threaded, but spreads its work by chunking its slices and scheduling an equal amount of work on several threads. If you require the jobs to execute in sequence, you can execute a sequence of jobs which will be guaranteed to run on the same thread.
To synchronize, you have to create a job synchronization primitive, and it allows for signaling, waiting on the host-side, and waiting on the threads between jobs.
How to setup a job: Create port, create a job when required, use the function context to provide the job with inputs, outputs and uniform data.
Classes | |
struct | CreateJobInfo |
struct | CreateJobPortInfo |
struct | CreateJobSyncInfo |
struct | JobContext |
struct | JobFuncContext |
This class describes the size of a workload for a single thread (can be multiple items) More... | |
struct | JobId |
struct | JobIOData |
struct | JobPortId |
struct | JobSyncId |
class | JobThread |
struct | JobUniformData |
struct | PrivateMemory |
Typedefs | |
typedef Ids::IdAllocator< Util::StringAtom, Util::FixedArray< Ptr< JobThread > >, uint > | JobPortAllocator |
typedef Ids::IdAllocator< CreateJobInfo, std::function< void()>, PrivateMemory > | JobAllocator |
typedef Ids::IdAllocator< std::function< void()>, Threading::Event *, std::atomic_uint *, bool > | JobSyncAllocator |
Enumerations | |
enum | { JobPort_Name , JobPort_Threads , JobPort_NextThreadIndex } |
enum | { Job_CreateInfo , Job_CallbackFunc , Job_ScratchMemory } |
enum | { SyncCallback , SyncCompletionEvent , SyncCompletionCounter , SyncPendingSignal } |
Functions | |
JobPortId | CreateJobPort (const CreateJobPortInfo &info) |
create a new job port | |
void | DestroyJobPort (const JobPortId &id) |
destroy job port | |
JobId | CreateJob (const CreateJobInfo &info) |
create job | |
void | DestroyJob (const JobId &id) |
delete job | |
void | JobSchedule (const JobId &job, const JobPortId &port, const JobContext &ctx, const bool cycleThreads=true) |
schedule job to be executed | |
void | JobSchedule (const JobId &job, const JobPortId &port, const JobContext &ctx, const std::function< void()> &callback, const bool cycleThreads=true) |
schedule job with callback when finished | |
void | JobSchedule (const JobId &job, const JobPortId &port) |
schedule job without a context | |
void | JobScheduleSequence (const Util::Array< JobId > &jobs, const JobPortId &port, const Util::Array< JobContext > &contexts) |
schedule a sequence of jobs | |
void | JobScheduleSequence (const Util::Array< JobId > &jobs, const JobPortId &port, const Util::Array< JobContext > &contexts, const std::function< void()> &callback) |
schedule a sequence of jobs | |
void * | JobAllocateScratchMemory (const JobId &job, const Memory::HeapType heap, const SizeT size) |
allocate memory for job | |
JobSyncId | CreateJobSync (const CreateJobSyncInfo &info) |
create job sync | |
void | DestroyJobSync (const JobSyncId id) |
destroy job sync | |
void | JobSyncHostReset (const JobSyncId id) |
reset job sync on host | |
void | JobSyncHostSignal (const JobSyncId id, bool reset=true) |
signal job sync on host | |
void | JobSyncThreadSignal (const JobSyncId id, const JobPortId port, bool reset=true) |
put job sync on port, if reset is true, reset prior to signaling | |
void | JobSyncHostWait (const JobSyncId id, bool reset=false) |
wait for job on host side, if reset is true, resets after waiting | |
void | JobSyncThreadWait (const JobSyncId id, const JobPortId port, bool reset=false) |
wait for job on thread side, if reset is true, reset after waiting | |
bool | JobSyncSignaled (const JobSyncId id) |
returns true if sync object has been signaled | |
__ImplementClass (Jobs::JobThread, 'JBTH', Threading::Thread) | |
bool | JobPortBusy (const JobPortId &id) |
check to see if port is idle | |
void | JobSchedule (const JobId &job, const JobPortId &port, void *ctx, SizeT count, SizeT groupSize, const bool cycleThreads=true) |
schedule a job with a poiunter as context and a work group size and item count | |
Variables | |
JobPortAllocator | jobPortAllocator (0xFFFF) |
JobAllocator | jobAllocator (0xFFFFFFFF) |
JobSyncAllocator | jobSyncAllocator (0xFFFFFFFF) |
typedef Ids::IdAllocator< CreateJobInfo, std::function<void()>, PrivateMemory > Jobs::JobAllocator |
typedef Ids::IdAllocator< Util::StringAtom, Util::FixedArray<Ptr<JobThread> >, uint > Jobs::JobPortAllocator |
typedef Ids::IdAllocator< std::function<void()>, Threading::Event*, std::atomic_uint*, bool > Jobs::JobSyncAllocator |
Jobs::__ImplementClass | ( | Jobs::JobThread | , |
'JBTH' | , | ||
Threading::Thread | ) |
JobId Jobs::CreateJob | ( | const CreateJobInfo & | info | ) |
create job
JobPortId Jobs::CreateJobPort | ( | const CreateJobPortInfo & | info | ) |
create a new job port
JobSyncId Jobs::CreateJobSync | ( | const CreateJobSyncInfo & | info | ) |
create job sync
void Jobs::DestroyJob | ( | const JobId & | id | ) |
delete job
void Jobs::DestroyJobPort | ( | const JobPortId & | id | ) |
destroy job port
void Jobs::DestroyJobSync | ( | const JobSyncId | id | ) |
destroy job sync
void * Jobs::JobAllocateScratchMemory | ( | const JobId & | job, |
const Memory::HeapType | heap, | ||
const SizeT | size ) |
allocate memory for job
bool Jobs::JobPortBusy | ( | const JobPortId & | id | ) |
check to see if port is idle
void Jobs::JobSchedule | ( | const JobId & | job, |
const JobPortId & | port, | ||
const JobContext & | ctx, | ||
const bool | cycleThreads ) |
schedule job to be executed
void Jobs::JobSchedule | ( | const JobId & | job, |
const JobPortId & | port, | ||
const JobContext & | ctx, | ||
const std::function< void()> & | callback, | ||
const bool | cycleThreads ) |
schedule job with callback when finished
void Jobs::JobSchedule | ( | const JobId & | job, |
const JobPortId & | port, | ||
void * | ctx, | ||
SizeT | count, | ||
SizeT | groupSize, | ||
const bool | cycleThreads = true ) |
schedule a job with a poiunter as context and a work group size and item count
void Jobs::JobScheduleSequence | ( | const Util::Array< JobId > & | jobs, |
const JobPortId & | port, | ||
const Util::Array< JobContext > & | contexts ) |
schedule a sequence of jobs
void Jobs::JobScheduleSequence | ( | const Util::Array< JobId > & | jobs, |
const JobPortId & | port, | ||
const Util::Array< JobContext > & | contexts, | ||
const std::function< void()> & | callback ) |
schedule a sequence of jobs
void Jobs::JobSyncHostReset | ( | const JobSyncId | id | ) |
reset job sync on host
void Jobs::JobSyncHostSignal | ( | const JobSyncId | id, |
bool | reset ) |
signal job sync on host
void Jobs::JobSyncHostWait | ( | const JobSyncId | id, |
bool | reset ) |
wait for job on host side, if reset is true, resets after waiting
bool Jobs::JobSyncSignaled | ( | const JobSyncId | id | ) |
returns true if sync object has been signaled
put job sync on port, if reset is true, reset prior to signaling
wait for job on thread side, if reset is true, reset after waiting
JobAllocator Jobs::jobAllocator | ( | 0xFFFFFFFF | ) |
JobPortAllocator Jobs::jobPortAllocator | ( | 0xFFFF | ) |
JobSyncAllocator Jobs::jobSyncAllocator | ( | 0xFFFFFFFF | ) |