job refactor progress

This commit is contained in:
jacob 2025-08-05 13:08:34 -05:00
parent 46bf8f5ca4
commit 0d8531e740
16 changed files with 104 additions and 87 deletions

5
.gitignore vendored
View File

@ -7,8 +7,9 @@
*.tracy *.tracy
*.pdb *.pdb
*.exe *.exe
.vs/* *.vs/*
.vscode/* *.vscode/*
*.log
imgui.ini imgui.ini

View File

@ -1,4 +1,4 @@
SharedScratchCtx shared_scratch_ctx = ZI; SharedArenaCtx shared_arena_ctx = ZI;
/* NOTE: Application will exit if arena fails to reserve or commit initial memory. */ /* NOTE: Application will exit if arena fails to reserve or commit initial memory. */
Arena *AllocArena(u64 reserve) Arena *AllocArena(u64 reserve)

View File

@ -24,24 +24,25 @@ Struct(TempArena) {
}; };
//////////////////////////////// ////////////////////////////////
//~ Scratch types //~ Per-fiber arena ctx types
#define ScratchArenasPerCtx 2 #define ScratchArenasPerCtx 2
Struct(ScratchCtx) Struct(ArenaCtx)
{ {
Arena *arenas[ScratchArenasPerCtx]; Arena *scratch_arenas[ScratchArenasPerCtx];
Arena *perm_arena;
}; };
//////////////////////////////// ////////////////////////////////
//~ Shared state //~ Shared state
Struct(SharedScratchCtx) Struct(SharedArenaCtx)
{ {
ScratchCtx scratch_contexts[MaxFibers]; ArenaCtx arena_contexts[MaxFibers];
}; };
extern SharedScratchCtx shared_scratch_ctx; extern SharedArenaCtx shared_arena_ctx;
//////////////////////////////// ////////////////////////////////
//~ Arena push/pop //~ Arena push/pop
@ -139,7 +140,7 @@ Inline void ResetArena(Arena *arena)
} }
//////////////////////////////// ////////////////////////////////
//~ Temp arena //~ Temp arena operations
Inline TempArena BeginTempArena(Arena *arena) Inline TempArena BeginTempArena(Arena *arena)
{ {
@ -155,20 +156,24 @@ Inline void EndTempArena(TempArena temp)
} }
//////////////////////////////// ////////////////////////////////
//~ Scratch //~ Arena ctx from operations
Inline ScratchCtx *ScratchCtxFromFiberId(i16 fiber_id) Inline ArenaCtx *ArenaCtxFromFiberId(i16 fiber_id)
{ {
SharedScratchCtx *shared = &shared_scratch_ctx; SharedArenaCtx *shared = &shared_arena_ctx;
ScratchCtx *ctx = &shared->scratch_contexts[fiber_id]; ArenaCtx *ctx = &shared->arena_contexts[fiber_id];
if (!ctx->arenas[0]) { if (!ctx->scratch_arenas[0]) {
for (i32 i = 0; i < (i32)countof(ctx->arenas); ++i) { for (i32 i = 0; i < (i32)countof(ctx->scratch_arenas); ++i) {
ctx->arenas[i] = AllocArena(Gibi(64)); ctx->scratch_arenas[i] = AllocArena(Gibi(64));
} }
ctx->perm_arena = AllocArena(Gibi(64));
} }
return ctx; return ctx;
} }
////////////////////////////////
//~ Scratch helpers
/* Any parameterized arenas in the caller's scope should be passed into this /* Any parameterized arenas in the caller's scope should be passed into this
* function as a potential "conflict". This is to prevent friction in case the * function as a potential "conflict". This is to prevent friction in case the
* passed arena is itself a scratch arena from another scope (since * passed arena is itself a scratch arena from another scope (since
@ -187,10 +192,10 @@ Inline TempArena _BeginScratch(Arena *potential_conflict)
/* Use `BeginScratchNoConflict` if no conflicts are present */ /* Use `BeginScratchNoConflict` if no conflicts are present */
Assert(potential_conflict != 0); Assert(potential_conflict != 0);
ScratchCtx *ctx = ScratchCtxFromFiberId(FiberId()); ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId());
Arena *scratch_arena = ctx->arenas[0]; Arena *scratch_arena = ctx->scratch_arenas[0];
if (potential_conflict && scratch_arena == potential_conflict) { if (potential_conflict && scratch_arena == potential_conflict) {
scratch_arena = ctx->arenas[1]; scratch_arena = ctx->scratch_arenas[1];
} }
TempArena temp = BeginTempArena(scratch_arena); TempArena temp = BeginTempArena(scratch_arena);
return temp; return temp;
@ -210,8 +215,8 @@ Inline TempArena _BeginScratch(Arena *potential_conflict)
Inline TempArena BeginScratchNoConflict_(void) Inline TempArena BeginScratchNoConflict_(void)
{ {
ScratchCtx *ctx = ScratchCtxFromFiberId(FiberId()); ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId());
Arena *scratch_arena = ctx->arenas[0]; Arena *scratch_arena = ctx->scratch_arenas[0];
TempArena temp = BeginTempArena(scratch_arena); TempArena temp = BeginTempArena(scratch_arena);
return temp; return temp;
} }
@ -220,3 +225,12 @@ Inline void EndScratch(TempArena scratch_temp)
{ {
EndTempArena(scratch_temp); EndTempArena(scratch_temp);
} }
////////////////////////////////
//~ Perm arena helpers
Inline Arena *GetPermArena(void)
{
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId());
return ctx->perm_arena;
}

View File

@ -551,7 +551,7 @@ ForceInline void UnlockTicketMutex(TicketMutex *tm)
//////////////////////////////// ////////////////////////////////
//~ Fibers //~ Fibers
#define MaxFibers 4096 #define MaxFibers 1024
#if !LanguageIsGpu #if !LanguageIsGpu
# if PlatformIsWindows # if PlatformIsWindows
@ -564,6 +564,8 @@ ForceInline i16 FiberId(void)
#endif #endif
return *v; return *v;
} }
# else
# error FiberId not implemented
# endif # endif
StaticAssert(MaxFibers < I16Max); /* Fiber id type should fit max fibers */ StaticAssert(MaxFibers < I16Max); /* Fiber id type should fit max fibers */
#endif #endif

View File

@ -3,33 +3,33 @@
/* Work pools contain their own worker threads with their own thread priority /* Work pools contain their own worker threads with their own thread priority
* affinity based on the intended context of the pool. */ * affinity based on the intended context of the pool. */
typedef i32 PoolKind; enum typedef i32 JobPool; enum
{ {
PoolKind_Inherit = -1, JobPool_Inherit = -1,
/* The floating pool contains a large number of lower priority worker /* The floating pool contains a large number of lower priority worker
* threads that have affinity over the entire CPU. Other pools should push * threads that have affinity over the entire CPU. Other pools should push
* jobs that only block and do no work here so that they can yield on the * jobs that only block and do no work here so that they can yield on the
* blocking job rather than blocking themselves. */ * blocking job rather than blocking themselves. */
PoolKind_Floating = 0, JobPool_Floating = 0,
PoolKind_Background = 1, JobPool_Background = 1,
PoolKind_Audio = 2, JobPool_Audio = 2,
PoolKind_User = 3, JobPool_User = 3,
PoolKind_Sim = 4, JobPool_Sim = 4,
PoolKind_Count JobPool_Count
}; };
/* Job execution order within a pool is based on priority. */ /* Job execution order within a pool is based on priority. */
typedef i32 PriorityKind; enum typedef i32 JobPriority; enum
{ {
PriorityKind_Inherit = -1, JobPriority_Inherit = -1,
PriorityKind_High = 0, JobPriority_High = 0,
PriorityKind_Normal = 1, JobPriority_Normal = 1,
PriorityKind_Low = 2, JobPriority_Low = 2,
PriorityKind_Count JobPriority_Count
}; };
//////////////////////////////// ////////////////////////////////
@ -57,27 +57,27 @@ Struct(GenericJobDesc)
void *sig; void *sig;
GenericJobFunc *func; GenericJobFunc *func;
i32 count; i32 count;
PoolKind pool; JobPool pool;
PriorityKind priority; JobPriority priority;
Counter *counter; Counter *counter;
}; };
Struct(JobDescParams) Struct(JobDescParams)
{ {
i32 count; i32 count;
PoolKind pool; JobPool pool;
PriorityKind priority; JobPriority priority;
Counter *counter; Counter *counter;
}; };
#define JobDecl(job, sigdef) \ #define JobDecl(job, sigdef) \
typedef struct job##_Sig sigdef job##_Sig; \ typedef struct job##_Sig sigdef job##_Sig; \
Struct(job##_Desc) { Arena *arena; job##_Sig *sig; GenericJobFunc *func; i32 count; PoolKind pool; PriorityKind priority; Counter *counter; }; \ Struct(job##_Desc) { Arena *arena; job##_Sig *sig; GenericJobFunc *func; i32 count; JobPool pool; JobPriority priority; Counter *counter; }; \
void job(job##_Sig *, i32); \ void job(job##_Sig *, i32); \
inline void job##_Generic(void *sig, i32 id) { job((job##_Sig *)sig, id); } \ inline void job##_Generic(void *sig, i32 id) { job((job##_Sig *)sig, id); } \
StaticAssert(1) StaticAssert(1)
#define PushJobDesc(job, ...) (job##_Desc *)PushJobDesc_(sizeof(job##_Sig), alignof(job##_Sig), job##_Generic, (JobDescParams) { .count = 1, .pool = PoolKind_Inherit, .priority = PriorityKind_Inherit, .counter = 0, __VA_ARGS__ }) #define PushJobDesc(job, ...) (job##_Desc *)PushJobDesc_(sizeof(job##_Sig), alignof(job##_Sig), job##_Generic, (JobDescParams) { .count = 1, .pool = JobPool_Inherit, .priority = JobPriority_Inherit, .counter = 0, __VA_ARGS__ })
GenericJobDesc *PushJobDesc_(u64 sig_size, u64 sig_align, GenericJobFunc *func, JobDescParams params); GenericJobDesc *PushJobDesc_(u64 sig_size, u64 sig_align, GenericJobFunc *func, JobDescParams params);
#define JobDef(job, sig_arg, id_arg) void job(job##_Sig *sig_arg, i32 id_arg) #define JobDef(job, sig_arg, id_arg) void job(job##_Sig *sig_arg, i32 id_arg)

View File

@ -47,12 +47,12 @@ void StartupBaseJobs(void)
g->wait_lists_arena = AllocArena(Gibi(64)); g->wait_lists_arena = AllocArena(Gibi(64));
/* Init job pools */ /* Init job pools */
for (PoolKind pool_kind = 0; pool_kind < (i32)countof(g->job_pools); ++pool_kind) for (JobPool pool_kind = 0; pool_kind < (i32)countof(g->job_pools); ++pool_kind)
{ {
W32_JobPool *pool = &g->job_pools[pool_kind]; W32_JobPool *pool = &g->job_pools[pool_kind];
/* Init queues */ /* Init queues */
for (PriorityKind priority = 0; priority < (i32)countof(pool->job_queues); ++priority) for (JobPriority priority = 0; priority < (i32)countof(pool->job_queues); ++priority)
{ {
W32_JobQueue *queue = &pool->job_queues[priority]; W32_JobQueue *queue = &pool->job_queues[priority];
queue->arena = AllocArena(Gibi(64)); queue->arena = AllocArena(Gibi(64));
@ -71,7 +71,7 @@ void StartupBaseJobs(void)
/* TODO: Heuristic worker counts & affinities */ /* TODO: Heuristic worker counts & affinities */
{ {
__profn("Start job workers"); __profn("Start job workers");
for (PoolKind pool_kind = 0; pool_kind < (i32)countof(g->job_pools); ++pool_kind) for (JobPool pool_kind = 0; pool_kind < (i32)countof(g->job_pools); ++pool_kind)
{ {
W32_JobPool *pool = &g->job_pools[pool_kind]; W32_JobPool *pool = &g->job_pools[pool_kind];
String name_fmt = ZI; String name_fmt = ZI;
@ -80,7 +80,7 @@ void StartupBaseJobs(void)
{ {
default: Assert(0); break; default: Assert(0); break;
case PoolKind_Sim: case JobPool_Sim:
{ {
name_fmt = Lit("Sim worker #%F"); name_fmt = Lit("Sim worker #%F");
pool->num_worker_threads = 4; pool->num_worker_threads = 4;
@ -88,7 +88,7 @@ void StartupBaseJobs(void)
pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL; pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL;
} break; } break;
case PoolKind_User: case JobPool_User:
{ {
name_fmt = Lit("User worker #%F"); name_fmt = Lit("User worker #%F");
pool->num_worker_threads = 4; pool->num_worker_threads = 4;
@ -96,7 +96,7 @@ void StartupBaseJobs(void)
pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL; pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL;
} break; } break;
case PoolKind_Audio: case JobPool_Audio:
{ {
name_fmt = Lit("Audio worker #%F"); name_fmt = Lit("Audio worker #%F");
pool->num_worker_threads = 2; pool->num_worker_threads = 2;
@ -105,14 +105,14 @@ void StartupBaseJobs(void)
pool->thread_is_audio = 1; pool->thread_is_audio = 1;
} break; } break;
case PoolKind_Background: case JobPool_Background:
{ {
name_fmt = Lit("Background worker #%F"); name_fmt = Lit("Background worker #%F");
pool->num_worker_threads = 2; pool->num_worker_threads = 2;
pool->thread_affinity_mask = 0x0000000000000C00ull; pool->thread_affinity_mask = 0x0000000000000C00ull;
} break; } break;
case PoolKind_Floating: case JobPool_Floating:
{ {
name_fmt = Lit("Floating worker #%F"); name_fmt = Lit("Floating worker #%F");
pool->num_worker_threads = 8; pool->num_worker_threads = 8;
@ -145,7 +145,7 @@ void ShutdownJobs(void)
if (!Atomic32Fetch(&g->panicking)) if (!Atomic32Fetch(&g->panicking))
{ {
Atomic32FetchSet(&g->shutdown, 1); Atomic32FetchSet(&g->shutdown, 1);
for (PoolKind pool_kind = 0; pool_kind < (i32)countof(g->job_pools); ++pool_kind) for (JobPool pool_kind = 0; pool_kind < (i32)countof(g->job_pools); ++pool_kind)
{ {
W32_JobPool *pool = &g->job_pools[pool_kind]; W32_JobPool *pool = &g->job_pools[pool_kind];
LockTicketMutex(&pool->workers_wake_tm); LockTicketMutex(&pool->workers_wake_tm);
@ -161,7 +161,7 @@ void ShutdownJobs(void)
/* Wait on worker threads */ /* Wait on worker threads */
if (!Atomic32Fetch(&g->panicking)) if (!Atomic32Fetch(&g->panicking))
{ {
for (PoolKind pool_kind = 0; pool_kind < (i32)countof(g->job_pools); ++pool_kind) for (JobPool pool_kind = 0; pool_kind < (i32)countof(g->job_pools); ++pool_kind)
{ {
W32_JobPool *pool = &g->job_pools[pool_kind]; W32_JobPool *pool = &g->job_pools[pool_kind];
for (i32 i = 0; i < pool->num_worker_threads; ++i) for (i32 i = 0; i < pool->num_worker_threads; ++i)
@ -520,11 +520,11 @@ void W32_WakeLockedFibers(i32 num_fibers, W32_Fiber **fibers)
/* Resume jobs */ /* Resume jobs */
/* TODO: Batch submit waiters based on queue kind rather than one at a time */ /* TODO: Batch submit waiters based on queue kind rather than one at a time */
i32 job_counts_per_pool[PoolKind_Count] = ZI; i32 job_counts_per_pool[JobPool_Count] = ZI;
for (i32 i = 0; i < num_fibers; ++i) for (i32 i = 0; i < num_fibers; ++i)
{ {
W32_Fiber *fiber = fibers[i]; W32_Fiber *fiber = fibers[i];
PoolKind pool_kind = fiber->job_pool; JobPool pool_kind = fiber->job_pool;
++job_counts_per_pool[pool_kind]; ++job_counts_per_pool[pool_kind];
W32_JobPool *pool = &g->job_pools[pool_kind]; W32_JobPool *pool = &g->job_pools[pool_kind];
W32_JobQueue *queue = &pool->job_queues[fiber->job_priority]; W32_JobQueue *queue = &pool->job_queues[fiber->job_priority];
@ -563,7 +563,7 @@ void W32_WakeLockedFibers(i32 num_fibers, W32_Fiber **fibers)
/* Wake workers */ /* Wake workers */
if (num_fibers > 0) if (num_fibers > 0)
{ {
for (PoolKind pool_kind = 0; pool_kind < (i32)countof(job_counts_per_pool); ++pool_kind) for (JobPool pool_kind = 0; pool_kind < (i32)countof(job_counts_per_pool); ++pool_kind)
{ {
i32 job_count = job_counts_per_pool[pool_kind]; i32 job_count = job_counts_per_pool[pool_kind];
if (job_count > 0) if (job_count > 0)
@ -900,7 +900,7 @@ W32_ThreadDef(W32_JobWorkerEntryFunc, worker_ctx_arg)
{ {
W32_SharedCtx *g = &W32_shared_ctx; W32_SharedCtx *g = &W32_shared_ctx;
W32_WorkerCtx *ctx = worker_ctx_arg; W32_WorkerCtx *ctx = worker_ctx_arg;
PoolKind pool_kind = ctx->pool_kind; JobPool pool_kind = ctx->pool_kind;
W32_JobPool *pool = &g->job_pools[pool_kind]; W32_JobPool *pool = &g->job_pools[pool_kind];
LAX ctx; LAX ctx;
@ -958,7 +958,7 @@ W32_ThreadDef(W32_JobWorkerEntryFunc, worker_ctx_arg)
while (!shutdown) while (!shutdown)
{ {
//- Pull job from queue //- Pull job from queue
PriorityKind job_priority = 0; JobPriority job_priority = 0;
i16 job_fiber_id = 0; i16 job_fiber_id = 0;
i32 job_id = 0; i32 job_id = 0;
GenericJobFunc *job_func = 0; GenericJobFunc *job_func = 0;
@ -966,7 +966,7 @@ W32_ThreadDef(W32_JobWorkerEntryFunc, worker_ctx_arg)
Counter *job_counter = 0; Counter *job_counter = 0;
{ {
//__profnc("Pull job", Rgb32F(0.75, 0.75, 0)); //__profnc("Pull job", Rgb32F(0.75, 0.75, 0));
for (PriorityKind priority = 0; priority < (i32)countof(pool->job_queues) && !job_func; ++priority) for (JobPriority priority = 0; priority < (i32)countof(pool->job_queues) && !job_func; ++priority)
{ {
W32_JobQueue *queue = &pool->job_queues[priority]; W32_JobQueue *queue = &pool->job_queues[priority];
if (queue) if (queue)
@ -1422,8 +1422,8 @@ void RunJobEx(GenericJobDesc *desc)
struct W32_SharedCtx *g = &W32_shared_ctx; struct W32_SharedCtx *g = &W32_shared_ctx;
i32 count = desc->count; i32 count = desc->count;
Counter *counter = desc->counter; Counter *counter = desc->counter;
PoolKind pool_kind = desc->pool; JobPool pool_kind = desc->pool;
PriorityKind priority = desc->priority; JobPriority priority = desc->priority;
GenericJobFunc *func = desc->func; GenericJobFunc *func = desc->func;
void *sig = desc->sig; void *sig = desc->sig;
if (count > 0) if (count > 0)
@ -1433,8 +1433,8 @@ void RunJobEx(GenericJobDesc *desc)
AddCounter(counter, count); AddCounter(counter, count);
} }
W32_Fiber *fiber = W32_FiberFromId(FiberId()); W32_Fiber *fiber = W32_FiberFromId(FiberId());
priority = ClampI32(priority, fiber->job_priority, PriorityKind_Count - 1); /* A job cannot create a job with a higher priority than itself */ priority = ClampI32(priority, fiber->job_priority, JobPriority_Count - 1); /* A job cannot create a job with a higher priority than itself */
if (pool_kind == PoolKind_Inherit) if (pool_kind == JobPool_Inherit)
{ {
pool_kind = fiber->job_pool; pool_kind = fiber->job_pool;
} }

View File

@ -146,7 +146,7 @@ StaticAssert(offsetof(W32_Fiber, wake_lock) % 4 == 0); /* Atomic must be aligne
//- Worker ctx //- Worker ctx
AlignedStruct(W32_WorkerCtx, 64) AlignedStruct(W32_WorkerCtx, 64)
{ {
PoolKind pool_kind; JobPool pool_kind;
i32 id; i32 id;
}; };
@ -181,7 +181,7 @@ AlignedStruct(W32_JobQueue, 64)
AlignedStruct(W32_JobPool, 64) AlignedStruct(W32_JobPool, 64)
{ {
/* Jobs */ /* Jobs */
W32_JobQueue job_queues[PriorityKind_Count]; W32_JobQueue job_queues[JobPriority_Count];
TicketMutex free_fibers_tm; TicketMutex free_fibers_tm;
i16 first_free_fiber_id; i16 first_free_fiber_id;
@ -246,7 +246,7 @@ Struct(W32_SharedCtx)
W32_WaitBin wait_time_bins[W32_NumWaitTimeBins]; W32_WaitBin wait_time_bins[W32_NumWaitTimeBins];
//- Job pools //- Job pools
W32_JobPool job_pools[PoolKind_Count]; W32_JobPool job_pools[JobPool_Count];
}; };
extern W32_SharedCtx W32_shared_ctx; extern W32_SharedCtx W32_shared_ctx;

View File

@ -113,7 +113,7 @@ AC_Asset *F_LoadAsset(String path, f32 point_size, b32 wait)
if (is_first_touch) if (is_first_touch)
{ {
AC_MarkLoading(asset); AC_MarkLoading(asset);
F_LoadJob_Desc *desc = PushJobDesc(F_LoadJob, .pool = PoolKind_Background, .priority = PriorityKind_Low); F_LoadJob_Desc *desc = PushJobDesc(F_LoadJob, .pool = JobPool_Background, .priority = JobPriority_Low);
desc->sig->asset = asset; desc->sig->asset = asset;
desc->sig->path = PushString(desc->arena, path); desc->sig->path = PushString(desc->arena, path);
desc->sig->point_size = point_size; desc->sig->point_size = point_size;

View File

@ -71,7 +71,7 @@ void GPU_StartupCore(void)
P_OnExit(GPU_D12_Shutdown); P_OnExit(GPU_D12_Shutdown);
/* Start evictor job */ /* Start evictor job */
RunJob(1, GPU_D12_EvictorJob, PoolKind_Background, PriorityKind_Low, &g->evictor_job_counter, 0); RunJob(1, GPU_D12_EvictorJob, JobPool_Background, JobPriority_Low, &g->evictor_job_counter, 0);
} }
P_ExitFuncDef(GPU_D12_Shutdown) P_ExitFuncDef(GPU_D12_Shutdown)
@ -324,7 +324,7 @@ void GPU_D12_InitObjects(void)
}; };
{ {
Counter counter = ZI; Counter counter = ZI;
RunJob(DX12_NUM_QUEUES, GPU_D12_AllocCommandQueueJob, PoolKind_Inherit, PriorityKind_Low, &counter, .descs_in = params, .cqs_out = g->command_queues); RunJob(DX12_NUM_QUEUES, GPU_D12_AllocCommandQueueJob, JobPool_Inherit, JobPriority_Low, &counter, .descs_in = params, .cqs_out = g->command_queues);
WaitOnCounter(&counter); WaitOnCounter(&counter);
} }
#if ProfilingIsEnabled #if ProfilingIsEnabled
@ -416,7 +416,7 @@ void GPU_InitPipelines(void)
{ {
__profn("Allocate pipelines"); __profn("Allocate pipelines");
Counter counter = ZI; Counter counter = ZI;
RunJob(num_pipelines, GPU_D12_AllocPipelineJob, PoolKind_Inherit, PriorityKind_Inherit, &counter, .descs_in = descs, .pipelines_out = pipelines); RunJob(num_pipelines, GPU_D12_AllocPipelineJob, JobPool_Inherit, JobPriority_Inherit, &counter, .descs_in = descs, .pipelines_out = pipelines);
WaitOnCounter(&counter); WaitOnCounter(&counter);
} }
for (u32 i = 0; i < num_pipelines; ++i) for (u32 i = 0; i < num_pipelines; ++i)
@ -496,7 +496,7 @@ void GPU_D12_InitNoise(void)
/* Upload texture */ /* Upload texture */
{ {
Counter counter = ZI; Counter counter = ZI;
RunJob(1, GPU_D12_UploadJob, PoolKind_Inherit, PriorityKind_Low, &counter, .resource = r, .data = data.text); RunJob(1, GPU_D12_UploadJob, JobPool_Inherit, JobPriority_Low, &counter, .resource = r, .data = data.text);
WaitOnCounter(&counter); WaitOnCounter(&counter);
} }
} }
@ -1169,7 +1169,7 @@ W_CallbackFuncDef(GPU_D12_WatchPipelineCallback, name)
GPU_D12_Pipeline **pipelines = PushStructs(scratch.arena, GPU_D12_Pipeline *, num_pipelines); GPU_D12_Pipeline **pipelines = PushStructs(scratch.arena, GPU_D12_Pipeline *, num_pipelines);
{ {
Counter counter = ZI; Counter counter = ZI;
RunJob(num_pipelines, GPU_D12_AllocPipelineJob, PoolKind_Inherit, PriorityKind_Low, &counter, .descs_in = pipeline_descs, .pipelines_out = pipelines); RunJob(num_pipelines, GPU_D12_AllocPipelineJob, JobPool_Inherit, JobPriority_Low, &counter, .descs_in = pipeline_descs, .pipelines_out = pipelines);
WaitOnCounter(&counter); WaitOnCounter(&counter);
} }
{ {
@ -2086,7 +2086,7 @@ GPU_Resource *GPU_AllocTexture(GPU_TextureFormat format, u32 flags, Vec2I32 size
{ {
/* TODO: Make wait optional */ /* TODO: Make wait optional */
Counter counter = ZI; Counter counter = ZI;
RunJob(1, GPU_D12_UploadJob, PoolKind_Inherit, PriorityKind_Inherit, &counter, .resource = r, .data = initial_data); RunJob(1, GPU_D12_UploadJob, JobPool_Inherit, JobPriority_Inherit, &counter, .resource = r, .data = initial_data);
WaitOnCounter(&counter); WaitOnCounter(&counter);
} }
@ -2199,7 +2199,7 @@ JobDef(GPU_D12_UploadJob, sig, UNUSED id)
if (ID3D12Fence_GetCompletedValue(cq->submit_fence) < fence_target) if (ID3D12Fence_GetCompletedValue(cq->submit_fence) < fence_target)
{ {
Counter counter = ZI; Counter counter = ZI;
RunJob(1, GPU_D12_WaitOnFenceJob, PoolKind_Floating, PriorityKind_Inherit, &counter, .fence = cq->submit_fence, .target = fence_target); RunJob(1, GPU_D12_WaitOnFenceJob, JobPool_Floating, JobPriority_Inherit, &counter, .fence = cq->submit_fence, .target = fence_target);
WaitOnCounter(&counter); WaitOnCounter(&counter);
} }
@ -3354,7 +3354,7 @@ JobDef(GPU_D12_EvictorJob, UNUSED sig, UNUSED id)
__profn("Wait on fence"); __profn("Wait on fence");
{ {
Counter counter = ZI; Counter counter = ZI;
RunJob(1, GPU_D12_WaitOnFenceJob, PoolKind_Floating, PriorityKind_Inherit, &counter, .fence = cq->submit_fence, .target = targets[i]); RunJob(1, GPU_D12_WaitOnFenceJob, JobPool_Floating, JobPriority_Inherit, &counter, .fence = cq->submit_fence, .target = targets[i]);
WaitOnCounter(&counter); WaitOnCounter(&counter);
} }
} }

View File

@ -12,5 +12,5 @@ void P_Main(void)
RunOnce(); RunOnce();
P_StartupDeps(); P_StartupDeps();
/* FIXME: Logfile path */ /* FIXME: Logfile path */
P_StartupLog(Lit("log.txt")); P_StartupLog(Lit("log.log"));
} }

View File

@ -2230,7 +2230,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
/* Run app start job */ /* Run app start job */
if (!Atomic32Fetch(&g->panicking)) if (!Atomic32Fetch(&g->panicking))
{ {
RunJob(1, P_W32_AppStartupJob, 0, PoolKind_Floating, PriorityKind_High, 0); RunJob(1, P_W32_AppStartupJob, 0, JobPool_Floating, JobPriority_High, 0);
} }
/* Wait for startup end or panic */ /* Wait for startup end or panic */
@ -2258,7 +2258,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
/* Run exit callbacks job */ /* Run exit callbacks job */
if (!Atomic32Fetch(&g->panicking)) if (!Atomic32Fetch(&g->panicking))
{ {
RunJob(1, P_W32_AppShutdownJob, 0, PoolKind_Floating, PriorityKind_High, 0); RunJob(1, P_W32_AppShutdownJob, 0, JobPool_Floating, JobPriority_High, 0);
} }
/* Wait for exit end or panic */ /* Wait for exit end or panic */

View File

@ -15,7 +15,7 @@ void PB_StartupCore(void)
PB_WSP_SharedState *g = &PB_WSP_shared_state; PB_WSP_SharedState *g = &PB_WSP_shared_state;
PB_WSP_InitializeWasapi(); PB_WSP_InitializeWasapi();
/* Start playback job */ /* Start playback job */
RunJob(1, PB_WSP_PlaybackJob, 0, PoolKind_Audio, PriorityKind_High, &g->PB_WSP_PlaybackJob_counter); RunJob(1, PB_WSP_PlaybackJob, 0, JobPool_Audio, JobPriority_High, &g->PB_WSP_PlaybackJob_counter);
P_OnExit(&PB_WSP_Shutdown); P_OnExit(&PB_WSP_Shutdown);
} }

View File

@ -44,8 +44,8 @@ void StartupUser(void)
P_ShowWindow(g->window); P_ShowWindow(g->window);
/* Start jobs */ /* Start jobs */
RunJob(1, UpdateUserJob, 0, PoolKind_User, PriorityKind_High, &g->shutdown_job_counters); RunJob(1, UpdateUserJob, 0, JobPool_User, JobPriority_High, &g->shutdown_job_counters);
RunJob(1, SimJob, 0, PoolKind_Sim, PriorityKind_High, &g->shutdown_job_counters); RunJob(1, SimJob, 0, JobPool_Sim, JobPriority_High, &g->shutdown_job_counters);
P_OnExit(&ShutdownUser); P_OnExit(&ShutdownUser);
} }

View File

@ -101,7 +101,7 @@ AC_Asset *SND_LoadAsset(String path, SND_SoundFlag flags, b32 wait)
if (is_first_touch) if (is_first_touch)
{ {
AC_MarkLoading(asset); AC_MarkLoading(asset);
SND_LoadJob_Desc *desc = PushJobDesc(SND_LoadJob, .pool = PoolKind_Background, .priority = PriorityKind_Low, .counter = &asset->counter); SND_LoadJob_Desc *desc = PushJobDesc(SND_LoadJob, .pool = JobPool_Background, .priority = JobPriority_Low, .counter = &asset->counter);
desc->sig->path = PushString(desc->arena, path); desc->sig->path = PushString(desc->arena, path);
desc->sig->asset = asset; desc->sig->asset = asset;
desc->sig->flags = flags; desc->sig->flags = flags;

View File

@ -42,7 +42,7 @@ void S_StartupCore(void)
g->scopes_arena = AllocArena(Gibi(64)); g->scopes_arena = AllocArena(Gibi(64));
RunJob(1, S_EvictorJob, PoolKind_Background, PriorityKind_Low, &g->shutdown_counter, 0); RunJob(1, S_EvictorJob, JobPool_Background, JobPriority_Low, &g->shutdown_counter, 0);
P_OnExit(&S_Shutdown); P_OnExit(&S_Shutdown);
#if RESOURCE_RELOADING #if RESOURCE_RELOADING
@ -440,7 +440,7 @@ JobDef(S_LoadSpriteJob, sig, UNUSED id)
void S_PushLoadJob(S_CacheEntryRef ref, S_Tag tag) void S_PushLoadJob(S_CacheEntryRef ref, S_Tag tag)
{ {
S_LoadSpriteJob_Desc *desc = PushJobDesc(S_LoadSpriteJob, .pool = PoolKind_Background, .priority = PriorityKind_Inherit); S_LoadSpriteJob_Desc *desc = PushJobDesc(S_LoadSpriteJob, .pool = JobPool_Background, .priority = JobPriority_Inherit);
desc->sig->scope = S_BeginScope(); /* Scope ended by job */ desc->sig->scope = S_BeginScope(); /* Scope ended by job */
desc->sig->ref = S_EnsureRefFromRef(desc->sig->scope, ref)->ref; desc->sig->ref = S_EnsureRefFromRef(desc->sig->scope, ref)->ref;
desc->sig->tag = tag; desc->sig->tag = tag;

View File

@ -10,8 +10,8 @@ void W_StartupCore(void)
g->watch_events_arena = AllocArena(Gibi(64)); g->watch_events_arena = AllocArena(Gibi(64));
RunJob(1, W_MonitorJob, PoolKind_Floating, PriorityKind_Low, &g->watch_jobs_counter, 0); RunJob(1, W_MonitorJob, JobPool_Floating, JobPriority_Low, &g->watch_jobs_counter, 0);
RunJob(1, W_DispatcherJob, PoolKind_Background, PriorityKind_Low, &g->watch_jobs_counter, 0); RunJob(1, W_DispatcherJob, JobPool_Floating, JobPriority_Low, &g->watch_jobs_counter, 0);
P_OnExit(&W_Shutdown); P_OnExit(&W_Shutdown);
} }
@ -197,7 +197,7 @@ JobDef(W_DispatcherJob, UNUSED sig, UNUSED job_id)
if (!skip) if (!skip)
{ {
Counter counter = ZI; Counter counter = ZI;
RunJob(num_callbacks, W_RunCallbacksJob, PoolKind_Background, PriorityKind_Low, &counter, .name = e->name, .callbacks = callbacks); RunJob(num_callbacks, W_RunCallbacksJob, JobPool_Background, JobPriority_Low, &counter, .name = e->name, .callbacks = callbacks);
WaitOnCounter(&counter); WaitOnCounter(&counter);
} }
} }