Kohi Game Engine
job_system.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "defines.h"
4 
6 typedef b8 (*pfn_job_start)(void*, void*);
7 
9 typedef void (*pfn_job_on_complete)(void*);
10 
11 struct frame_data;
12 
14 typedef enum job_type {
20 
26 
34 
40 typedef enum job_priority {
48 
52 typedef struct job_info {
55 
58 
61 
64 
67 
69  void* param_data;
70 
73 
75  void* result_data;
76 
80 
81 typedef struct job_system_config {
90 
99 b8 job_system_initialize(u64* job_system_memory_requirement, void* state, void* config);
100 
104 void job_system_shutdown(void* state);
105 
109 b8 job_system_update(void* state, struct frame_data* p_frame_data);
110 
116 
127 KAPI job_info job_create(pfn_job_start entry_point, pfn_job_on_complete on_success, pfn_job_on_complete on_fail, void* param_data, u32 param_data_size, u32 result_data_size);
128 
140 KAPI job_info job_create_type(pfn_job_start entry_point, pfn_job_on_complete on_success, pfn_job_on_complete on_fail, void* param_data, u32 param_data_size, u32 result_data_size, job_type type);
141 
154 KAPI job_info job_create_priority(pfn_job_start entry_point, pfn_job_on_complete on_success, pfn_job_on_complete on_fail, void* param_data, u32 param_data_size, u32 result_data_size, job_type type, job_priority priority);
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:177
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
_Bool b8
8-bit boolean type
Definition: defines.h:58
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
unsigned char u8
Unsigned 8-bit integer.
Definition: defines.h:19
b8 job_system_update(void *state, struct frame_data *p_frame_data)
Updates the job system. Should happen once an update cycle.
struct job_system_config job_system_config
KAPI job_info job_create(pfn_job_start entry_point, pfn_job_on_complete on_success, pfn_job_on_complete on_fail, void *param_data, u32 param_data_size, u32 result_data_size)
Creates a new job with default type (Generic) and priority (Normal).
KAPI job_info job_create_priority(pfn_job_start entry_point, pfn_job_on_complete on_success, pfn_job_on_complete on_fail, void *param_data, u32 param_data_size, u32 result_data_size, job_type type, job_priority priority)
Creates a new job with the provided priority.
b8 job_system_initialize(u64 *job_system_memory_requirement, void *state, void *config)
Initializes the job system. Call once to retrieve job_system_memory_requirement, passing 0 to state....
job_priority
Determines which job queue a job uses. The high-priority queue is always exhausted first before proce...
Definition: job_system.h:40
@ JOB_PRIORITY_HIGH
The highest-priority job. Should be used sparingly, and only for time-critical operations.
Definition: job_system.h:46
@ JOB_PRIORITY_NORMAL
A normal-priority job. Should be used for medium-priority tasks such as loading assets.
Definition: job_system.h:44
@ JOB_PRIORITY_LOW
The lowest-priority job, used for things that can wait to be done if need be, such as log flushing.
Definition: job_system.h:42
job_type
Describes a type of job.
Definition: job_system.h:14
@ JOB_TYPE_RESOURCE_LOAD
A resource loading job. Resources should always load on the same thread to avoid potential disk thras...
Definition: job_system.h:25
@ JOB_TYPE_GENERAL
A general job that does not have any specific thread requirements. This means it matters little which...
Definition: job_system.h:19
@ JOB_TYPE_GPU_RESOURCE
Jobs using GPU resources should be bound to a thread using this job type. Multithreaded renderers wil...
Definition: job_system.h:32
KAPI void job_system_submit(job_info info)
Submits the provided job to be queued for execution.
b8(* pfn_job_start)(void *, void *)
A function pointer definition for jobs.
Definition: job_system.h:6
KAPI job_info job_create_type(pfn_job_start entry_point, pfn_job_on_complete on_success, pfn_job_on_complete on_fail, void *param_data, u32 param_data_size, u32 result_data_size, job_type type)
Creates a new job with default priority (Normal).
struct job_info job_info
Describes a job to be run.
void(* pfn_job_on_complete)(void *)
A function pointer definition for completion of a job.
Definition: job_system.h:9
void job_system_shutdown(void *state)
Shuts the job system down.
Engine-level current frame-specific data.
Definition: frame_data.h:16
Describes a job to be run.
Definition: job_system.h:52
pfn_job_on_complete on_success
A function pointer to be invoked when the job successfully completes. Optional.
Definition: job_system.h:63
u32 result_data_size
The size of the data passed to the success/fail function.
Definition: job_system.h:78
pfn_job_on_complete on_fail
A function pointer to be invoked when the job successfully fails. Optional.
Definition: job_system.h:66
void * param_data
Data to be passed to the entry point upon execution.
Definition: job_system.h:69
job_priority priority
The priority of this job. Higher priority jobs obviously run sooner.
Definition: job_system.h:57
pfn_job_start entry_point
A function pointer to be invoked when the job starts. Required.
Definition: job_system.h:60
job_type type
The type of job. Used to determine which thread the job executes on.
Definition: job_system.h:54
void * result_data
Data to be passed to the success/fail function upon execution, if exists.
Definition: job_system.h:75
u32 param_data_size
The size of the data passed to the job.
Definition: job_system.h:72
Definition: job_system.h:81
u8 max_job_thread_count
Definition: job_system.h:86
u32 * type_masks
Definition: job_system.h:88