alloc - > acquire

This commit is contained in:
jacob 2025-08-05 15:06:06 -05:00
parent 26bff4e741
commit f0052f700e
40 changed files with 324 additions and 315 deletions

9
src/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,9 @@
{
"files.associations": {
"*.rst": "hlsl",
"*.knl": "hlsl",
"chrono": "c",
"system_error": "c",
"xlocale": "c"
}
}

View File

@ -167,7 +167,7 @@ void Startup(void)
BB_Test(); BB_Test();
#endif #endif
g->arena = AllocArena(Gibi(64)); g->arena = AcquireArena(Gibi(64));
g->write_path = InitializeAppWriteDirectory(g->arena, Lit(WRITE_DIR)); g->write_path = InitializeAppWriteDirectory(g->arena, Lit(WRITE_DIR));

View File

@ -9,7 +9,7 @@ void AC_StartupCore(void)
{ {
__prof; __prof;
AC_SharedState *g = &AC_shared_state; AC_SharedState *g = &AC_shared_state;
g->store_arena = AllocArena(Gibi(64)); g->store_arena = AcquireArena(Gibi(64));
} }
//////////////////////////////// ////////////////////////////////

View File

@ -1,7 +1,7 @@
SharedArenaCtx shared_arena_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 *AcquireArena(u64 reserve)
{ {
__prof; __prof;
reserve += ArenaHeaderSize; reserve += ArenaHeaderSize;

View File

@ -56,7 +56,7 @@ extern SharedArenaCtx shared_arena_ctx;
#define PopStruct(a, type, dst) PopBytes((a), sizeof(type), dst) #define PopStruct(a, type, dst) PopBytes((a), sizeof(type), dst)
#define PopStructs(a, type, n, dst) PopBytes((a), sizeof(type) * (n), dst) #define PopStructs(a, type, n, dst) PopBytes((a), sizeof(type) * (n), dst)
/* Returns a pointer to where the next allocation would be (at alignment of type). /* Returns a pointer to where the next push would be (at alignment of type).
* Equivalent to PushStruct but without actually allocating anything or modifying the arena. */ * Equivalent to PushStruct but without actually allocating anything or modifying the arena. */
#define PushDry(a, type) (type *)(_PushDry((a), alignof(type))) #define PushDry(a, type) (type *)(_PushDry((a), alignof(type)))
@ -107,7 +107,7 @@ Inline void *_PushDry(Arena *arena, u64 align)
//////////////////////////////// ////////////////////////////////
//~ Arena management //~ Arena management
Arena *AllocArena(u64 reserve); Arena *AcquireArena(u64 reserve);
void ReleaseArena(Arena *arena); void ReleaseArena(Arena *arena);
void CopyArena(Arena *dst, Arena *src); void CopyArena(Arena *dst, Arena *src);
@ -165,9 +165,9 @@ Inline ArenaCtx *ArenaCtxFromFiberId(i16 fiber_id)
if (!ctx->scratch_arenas[0]) { if (!ctx->scratch_arenas[0]) {
__profn("Initialize fiber arena ctx"); __profn("Initialize fiber arena ctx");
for (i32 i = 0; i < (i32)countof(ctx->scratch_arenas); ++i) { for (i32 i = 0; i < (i32)countof(ctx->scratch_arenas); ++i) {
ctx->scratch_arenas[i] = AllocArena(Gibi(64)); ctx->scratch_arenas[i] = AcquireArena(Gibi(64));
} }
ctx->perm_arena = AllocArena(Gibi(64)); ctx->perm_arena = AcquireArena(Gibi(64));
} }
return ctx; return ctx;
} }

View File

@ -3,13 +3,13 @@
//////////////////////////////// ////////////////////////////////
//~ Buddy ctx //~ Buddy ctx
BuddyCtx *AllocBuddyCtx(u64 reserve) BuddyCtx *AcquireBuddyCtx(u64 reserve)
{ {
/* TODO: Determine meta reserve dynamically */ /* TODO: Determine meta reserve dynamically */
Arena *meta_arena = AllocArena(Gibi(64)); Arena *meta_arena = AcquireArena(Gibi(64));
BuddyCtx *ctx = PushStruct(meta_arena, BuddyCtx); BuddyCtx *ctx = PushStruct(meta_arena, BuddyCtx);
ctx->meta_arena = meta_arena; ctx->meta_arena = meta_arena;
ctx->data_arena = AllocArena(reserve); ctx->data_arena = AcquireArena(reserve);
/* TODO: Minimum block size */ /* TODO: Minimum block size */
ctx->levels = PushStructs(ctx->meta_arena, BuddyLevel, 64); ctx->levels = PushStructs(ctx->meta_arena, BuddyLevel, 64);
@ -31,9 +31,9 @@ void ReleaseBuddyCtx(BuddyCtx *ctx)
} }
//////////////////////////////// ////////////////////////////////
//~ Block alloc / release //~ Block acquire / release
BuddyBlock *AllocBuddyBlock(BuddyCtx *ctx, u64 size) BuddyBlock *AcquireBuddyBlock(BuddyCtx *ctx, u64 size)
{ {
if (size > 0x00FFFFFFFFFFFFFFULL) if (size > 0x00FFFFFFFFFFFFFFULL)
{ {

View File

@ -38,14 +38,14 @@ Struct(BuddyCtx)
//////////////////////////////// ////////////////////////////////
//~ Buddy context operations //~ Buddy context operations
BuddyCtx *AllocBuddyCtx(u64 reserve); BuddyCtx *AcquireBuddyCtx(u64 reserve);
void ReleaseBuddyCtx(BuddyCtx *ctx); void ReleaseBuddyCtx(BuddyCtx *ctx);
//////////////////////////////// ////////////////////////////////
//~ Buddy block operations //~ Buddy block operations
//- Alloc / release //- Acquire / release
BuddyBlock *AllocBuddyBlock(BuddyCtx *ctx, u64 size); BuddyBlock *AcquireBuddyBlock(BuddyCtx *ctx, u64 size);
void ReleaseBuddyBlock(BuddyBlock *block); void ReleaseBuddyBlock(BuddyBlock *block);
//- Push / pop //- Push / pop

View File

@ -36,16 +36,16 @@ void StartupBaseJobs(void)
/* Init fibers */ /* Init fibers */
g->num_fibers = 1; /* Fiber at index 0 always nil */ g->num_fibers = 1; /* Fiber at index 0 always nil */
g->fiber_names_arena = AllocArena(Gibi(64)); g->fiber_names_arena = AcquireArena(Gibi(64));
/* Init job descs */ /* Init job descs */
g->job_descs_arena = AllocArena(Gibi(64)); g->job_descs_arena = AcquireArena(Gibi(64));
/* Convert main thread to fiber */ /* Convert main thread to fiber */
W32_AllocFiber(0); W32_AcquireFiber(0);
/* Init wait lists */ /* Init wait lists */
g->wait_lists_arena = AllocArena(Gibi(64)); g->wait_lists_arena = AcquireArena(Gibi(64));
/* Init job pools */ /* Init job pools */
for (JobPool 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)
@ -56,16 +56,16 @@ void StartupBaseJobs(void)
for (JobPriority 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 = AcquireArena(Gibi(64));
} }
} }
/* Init threads pool */ /* Init threads pool */
g->threads_arena = AllocArena(Gibi(64)); g->threads_arena = AcquireArena(Gibi(64));
/* Start job scheduler */ /* Start job scheduler */
Atomic64FetchSet(&g->current_scheduler_cycle_period_ns.v, W32_DefaultSchedulerPeriodNs); Atomic64FetchSet(&g->current_scheduler_cycle_period_ns.v, W32_DefaultSchedulerPeriodNs);
W32_Thread *scheduler_thread = W32_AllocThread(W32_JobSchedulerEntryFunc, 0, Lit("Scheduler thread"), PROF_THREAD_GROUP_SCHEDULER); W32_Thread *scheduler_thread = W32_AcquireThread(W32_JobSchedulerEntryFunc, 0, Lit("Scheduler thread"), PROF_THREAD_GROUP_SCHEDULER);
LAX scheduler_thread; LAX scheduler_thread;
//- Start job workers //- Start job workers
@ -120,7 +120,7 @@ void StartupBaseJobs(void)
pool->thread_affinity_mask = 0x0000000000000FFFull; pool->thread_affinity_mask = 0x0000000000000FFFull;
} break; } break;
} }
pool->worker_threads_arena = AllocArena(Gibi(64)); pool->worker_threads_arena = AcquireArena(Gibi(64));
pool->worker_threads = PushStructs(pool->worker_threads_arena, W32_Thread *, pool->num_worker_threads); pool->worker_threads = PushStructs(pool->worker_threads_arena, W32_Thread *, pool->num_worker_threads);
pool->worker_contexts = PushStructs(pool->worker_threads_arena, W32_WorkerCtx, pool->num_worker_threads); pool->worker_contexts = PushStructs(pool->worker_threads_arena, W32_WorkerCtx, pool->num_worker_threads);
for (i32 i = 0; i < pool->num_worker_threads; ++i) for (i32 i = 0; i < pool->num_worker_threads; ++i)
@ -129,7 +129,7 @@ void StartupBaseJobs(void)
ctx->pool_kind = pool_kind; ctx->pool_kind = pool_kind;
ctx->id = i; ctx->id = i;
String name = StringFormat(pool->worker_threads_arena, name_fmt, FmtSint(i)); String name = StringFormat(pool->worker_threads_arena, name_fmt, FmtSint(i));
pool->worker_threads[i] = W32_AllocThread(W32_JobWorkerEntryFunc, ctx, name, prof_group + i); pool->worker_threads[i] = W32_AcquireThread(W32_JobWorkerEntryFunc, ctx, name, prof_group + i);
} }
} }
} }
@ -209,7 +209,7 @@ void ShutdownJobs(void)
DWORD WINAPI W32_Win32ThreadProc(LPVOID vt) DWORD WINAPI W32_Win32ThreadProc(LPVOID vt)
{ {
W32_AllocFiber(0); W32_AcquireFiber(0);
W32_Thread *t = (W32_Thread *)vt; W32_Thread *t = (W32_Thread *)vt;
__profthread(t->thread_name_cstr, t->profiler_group); __profthread(t->thread_name_cstr, t->profiler_group);
@ -234,7 +234,7 @@ DWORD WINAPI W32_Win32ThreadProc(LPVOID vt)
return 0; return 0;
} }
W32_Thread *W32_AllocThread(W32_ThreadFunc *entry_point, void *thread_data, String thread_name, i32 profiler_group) W32_Thread *W32_AcquireThread(W32_ThreadFunc *entry_point, void *thread_data, String thread_name, i32 profiler_group)
{ {
__prof; __prof;
TempArena scratch = BeginScratchNoConflict(); TempArena scratch = BeginScratchNoConflict();
@ -242,7 +242,7 @@ W32_Thread *W32_AllocThread(W32_ThreadFunc *entry_point, void *thread_data, Stri
Assert(entry_point != 0); Assert(entry_point != 0);
//P_LogInfoF("Creating thread \"%F\"", FmtString(thread_name)); //P_LogInfoF("Creating thread \"%F\"", FmtString(thread_name));
/* Allocate thread object */ /* Acquire thread object */
W32_Thread *t = 0; W32_Thread *t = 0;
{ {
LockTicketMutex(&g->threads_tm); LockTicketMutex(&g->threads_tm);
@ -701,9 +701,9 @@ void W32_WakeByTime(u64 time)
//////////////////////////////// ////////////////////////////////
//~ Win32 fiber //~ Win32 fiber
//- Allocate fiber //- Acquire fiber
/* If `pool` is 0, then the currently running thread will be converted into a fiber */ /* If `pool` is 0, then the currently running thread will be converted into a fiber */
W32_Fiber *W32_AllocFiber(W32_JobPool *pool) W32_Fiber *W32_AcquireFiber(W32_JobPool *pool)
{ {
W32_SharedJobCtx *g = &W32_shared_job_ctx; W32_SharedJobCtx *g = &W32_shared_job_ctx;
i16 fiber_id = 0; i16 fiber_id = 0;
@ -1046,7 +1046,7 @@ W32_ThreadDef(W32_JobWorkerEntryFunc, worker_ctx_arg)
{ {
if (!job_fiber) if (!job_fiber)
{ {
job_fiber = W32_AllocFiber(pool); job_fiber = W32_AcquireFiber(pool);
} }
job_fiber_id = job_fiber->id; job_fiber_id = job_fiber->id;
{ {
@ -1128,7 +1128,7 @@ W32_ThreadDef(W32_JobWorkerEntryFunc, worker_ctx_arg)
wait_addr_list = tmp; wait_addr_list = tmp;
} }
} }
//- Allocate new wait addr list //- Acquire new wait addr list
if (!wait_addr_list) if (!wait_addr_list)
{ {
if (wait_addr_bin->first_free_wait_list) if (wait_addr_bin->first_free_wait_list)
@ -1182,7 +1182,7 @@ W32_ThreadDef(W32_JobWorkerEntryFunc, worker_ctx_arg)
wait_time_list = tmp; wait_time_list = tmp;
} }
} }
//- Allocate new wait time list //- Acquire new wait time list
if (!wait_time_list) if (!wait_time_list)
{ {
if (wait_time_bin->first_free_wait_list) if (wait_time_bin->first_free_wait_list)
@ -1419,7 +1419,7 @@ GenericJobDesc *PushJobDesc_(u64 sig_size, u64 sig_align, GenericJobFunc *func,
else else
{ {
result = PushStructNoZero(g->job_descs_arena, GenericJobDesc); result = PushStructNoZero(g->job_descs_arena, GenericJobDesc);
arena = AllocArena(Mebi(4)); arena = AcquireArena(Mebi(4));
} }
} }
UnlockTicketMutex(&g->job_descs_tm); UnlockTicketMutex(&g->job_descs_tm);

View File

@ -259,7 +259,7 @@ void ShutdownJobs(void);
//~ Thread operations //~ Thread operations
DWORD WINAPI W32_Win32ThreadProc(LPVOID vt); DWORD WINAPI W32_Win32ThreadProc(LPVOID vt);
W32_Thread *W32_AllocThread(W32_ThreadFunc *entry_point, void *thread_data, String thread_name, i32 profiler_group); W32_Thread *W32_AcquireThread(W32_ThreadFunc *entry_point, void *thread_data, String thread_name, i32 profiler_group);
b32 W32_TryReleaseThread(W32_Thread *thread, f32 timeout_seconds); b32 W32_TryReleaseThread(W32_Thread *thread, f32 timeout_seconds);
void W32_WaitReleaseThread(W32_Thread *thread); void W32_WaitReleaseThread(W32_Thread *thread);
@ -273,7 +273,7 @@ void W32_WakeByTime(u64 time);
//////////////////////////////// ////////////////////////////////
//~ Fiber operations //~ Fiber operations
W32_Fiber *W32_AllocFiber(W32_JobPool *pool); W32_Fiber *W32_AcquireFiber(W32_JobPool *pool);
void W32_ReleaseFiber(W32_JobPool *pool, W32_Fiber *fiber); void W32_ReleaseFiber(W32_JobPool *pool, W32_Fiber *fiber);
ForceInline W32_Fiber *W32_FiberFromId(i16 id); ForceInline W32_Fiber *W32_FiberFromId(i16 id);
ForceNoInline void W32_FiberResume(W32_Fiber *fiber); ForceNoInline void W32_FiberResume(W32_Fiber *fiber);

View File

@ -3,10 +3,10 @@
//////////////////////////////// ////////////////////////////////
//~ Buff management //~ Buff management
BB_Buff AllocBitbuff(u64 arena_reserve) BB_Buff AcquireBitbuff(u64 arena_reserve)
{ {
BB_Buff result = ZI; BB_Buff result = ZI;
result.arena = AllocArena(arena_reserve); result.arena = AcquireArena(arena_reserve);
result.is_backed_by_arena = 1; result.is_backed_by_arena = 1;
return result; return result;
} }
@ -809,7 +809,7 @@ void BB_Test(void)
String encoded = ZI; String encoded = ZI;
{ {
BB_Buff bb = AllocBitbuff(Gibi(64)); BB_Buff bb = AcquireBitbuff(Gibi(64));
BB_Writer bw = BB_WriterFromBuff(&bb); BB_Writer bw = BB_WriterFromBuff(&bb);
for (u64 i = 0; i < countof(cases); ++i) for (u64 i = 0; i < countof(cases); ++i)
{ {

View File

@ -63,7 +63,7 @@ typedef u32 BB_DebugMagicKind; enum
//////////////////////////////// ////////////////////////////////
//~ Buff management //~ Buff management
BB_Buff AllocBitbuff(u64 arena_reserve); BB_Buff AcquireBitbuff(u64 arena_reserve);
void ReleaseBitbuff(BB_Buff *bitbuff); void ReleaseBitbuff(BB_Buff *bitbuff);
BB_Buff BitbuffFromString(String s); BB_Buff BitbuffFromString(String s);

View File

@ -8,7 +8,7 @@ void D_StartupCore(void)
__prof; __prof;
D_SharedState *g = &D_shared_state; D_SharedState *g = &D_shared_state;
u32 pixel_white = 0xFFFFFFFF; u32 pixel_white = 0xFFFFFFFF;
g->solid_white_texture = GPU_AllocTexture(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(1, 1), &pixel_white); g->solid_white_texture = GPU_AcquireTexture(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(1, 1), &pixel_white);
} }
//////////////////////////////// ////////////////////////////////

View File

@ -48,9 +48,9 @@ JobDef(F_LoadJob, sig, _)
RES_CloseResource(&res); RES_CloseResource(&res);
/* Send texture to GPU */ /* Send texture to GPU */
GPU_Resource *texture = GPU_AllocTexture(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(result.image_width, result.image_height), result.image_pixels); GPU_Resource *texture = GPU_AcquireTexture(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(result.image_width, result.image_height), result.image_pixels);
/* Allocate store memory */ /* Acquire store memory */
F_Font *font = 0; F_Font *font = 0;
{ {
AC_Store store = AC_OpenStore(); AC_Store store = AC_OpenStore();

View File

@ -125,14 +125,14 @@ void GPU_ReleaseResourceFenced(GPU_Resource *resource);
//////////////////////////////// ////////////////////////////////
//~ Texture operations //~ Texture operations
GPU_Resource *GPU_AllocTexture(GPU_TextureFormat format, u32 flags, Vec2I32 size, void *initial_data); GPU_Resource *GPU_AcquireTexture(GPU_TextureFormat format, u32 flags, Vec2I32 size, void *initial_data);
Vec2I32 GPU_GetTextureSize(GPU_Resource *texture); Vec2I32 GPU_GetTextureSize(GPU_Resource *texture);
//////////////////////////////// ////////////////////////////////
//~ Render operations //~ Render operations
GPU_RenderSig *GPU_AllocRenderSig(void); GPU_RenderSig *GPU_AcquireRenderSig(void);
/* Returns a cmd id internal to the sig */ /* Returns a cmd id internal to the sig */
u32 GPU_PushRenderCmd(GPU_RenderSig *render_sig, GPU_RenderCmdDesc *desc); u32 GPU_PushRenderCmd(GPU_RenderSig *render_sig, GPU_RenderCmdDesc *desc);
@ -147,7 +147,7 @@ GPU_MemoryInfo GPU_QueryMemoryInfo(void);
//////////////////////////////// ////////////////////////////////
//~ Swapchain //~ Swapchain
GPU_Swapchain *GPU_AllocSwapchain(P_Window *window, Vec2I32 resolution); GPU_Swapchain *GPU_AcquireSwapchain(P_Window *window, Vec2I32 resolution);
void GPU_ReleaseSwapchain(GPU_Swapchain *gp_swapchain); void GPU_ReleaseSwapchain(GPU_Swapchain *gp_swapchain);

View File

@ -28,26 +28,26 @@ void GPU_StartupCore(void)
} }
/* Initialize command descriptor heaps pool */ /* Initialize command descriptor heaps pool */
g->command_descriptor_heaps_arena = AllocArena(Gibi(64)); g->command_descriptor_heaps_arena = AcquireArena(Gibi(64));
/* Initialize command buffers pool */ /* Initialize command buffers pool */
g->command_buffers_arena = AllocArena(Gibi(64)); g->command_buffers_arena = AcquireArena(Gibi(64));
g->command_buffers_dict = InitDict(g->command_buffers_arena, 4096); g->command_buffers_dict = InitDict(g->command_buffers_arena, 4096);
/* Initialize resources pool */ /* Initialize resources pool */
g->resources_arena = AllocArena(Gibi(64)); g->resources_arena = AcquireArena(Gibi(64));
/* Initialize swapchains pool */ /* Initialize swapchains pool */
g->swapchains_arena = AllocArena(Gibi(64)); g->swapchains_arena = AcquireArena(Gibi(64));
/* Initialize pipeline cache */ /* Initialize pipeline cache */
g->pipelines_arena = AllocArena(Gibi(64)); g->pipelines_arena = AcquireArena(Gibi(64));
g->pipeline_descs = InitDict(g->pipelines_arena, 1024); g->pipeline_descs = InitDict(g->pipelines_arena, 1024);
g->top_pipelines = InitDict(g->pipelines_arena, 1024); g->top_pipelines = InitDict(g->pipelines_arena, 1024);
g->top_successful_pipelines = InitDict(g->pipelines_arena, 1024); g->top_successful_pipelines = InitDict(g->pipelines_arena, 1024);
/* Initialize fenced releases queue */ /* Initialize fenced releases queue */
g->fenced_releases_arena = AllocArena(Gibi(64)); g->fenced_releases_arena = AcquireArena(Gibi(64));
/* Initialize embedded shader archive */ /* Initialize embedded shader archive */
String embedded_data = INC_GetDxcTar(); String embedded_data = INC_GetDxcTar();
@ -310,12 +310,12 @@ void GPU_D12_InitObjects(void)
g->desc_counts[D3D12_DESCRIPTOR_HEAP_TYPE_RTV] = DX12_NUM_RTV_DESCRIPTORS; g->desc_counts[D3D12_DESCRIPTOR_HEAP_TYPE_RTV] = DX12_NUM_RTV_DESCRIPTORS;
/* Create global descriptor heaps */ /* Create global descriptor heaps */
g->cbv_srv_uav_heap = GPU_D12_AllocCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); g->cbv_srv_uav_heap = GPU_D12_AcquireCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
g->rtv_heap = GPU_D12_AllocCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); g->rtv_heap = GPU_D12_AcquireCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
/* Create command queues */ /* Create command queues */
{ {
__profn("Allocate command queues"); __profn("Acquire command queues");
GPU_D12_CommandQueueDesc params[] = { GPU_D12_CommandQueueDesc params[] = {
{.type = D3D12_COMMAND_LIST_TYPE_DIRECT, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Direct queue") }, {.type = D3D12_COMMAND_LIST_TYPE_DIRECT, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Direct queue") },
{.type = D3D12_COMMAND_LIST_TYPE_COMPUTE, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Compute queue") }, {.type = D3D12_COMMAND_LIST_TYPE_COMPUTE, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Compute queue") },
@ -324,7 +324,7 @@ void GPU_D12_InitObjects(void)
}; };
{ {
Counter counter = ZI; Counter counter = ZI;
RunJob(DX12_NUM_QUEUES, GPU_D12_AllocCommandQueueJob, JobPool_Inherit, JobPriority_Low, &counter, .descs_in = params, .cqs_out = g->command_queues); RunJob(DX12_NUM_QUEUES, GPU_D12_AcquireCommandQueueJob, JobPool_Inherit, JobPriority_Low, &counter, .descs_in = params, .cqs_out = g->command_queues);
WaitOnCounter(&counter); WaitOnCounter(&counter);
DEBUGBREAKABLE; DEBUGBREAKABLE;
} }
@ -336,7 +336,7 @@ void GPU_D12_InitObjects(void)
{ {
GPU_D12_CommandQueue *cq = g->command_queues[i]; GPU_D12_CommandQueue *cq = g->command_queues[i];
String dbg_name = params[i].dbg_name; String dbg_name = params[i].dbg_name;
__prof_dx12_ctx_alloc(cq->prof, g->device, cq->cq, dbg_name.text, dbg_name.len); __prof_dx12_ctx_acquire(cq->prof, g->device, cq->cq, dbg_name.text, dbg_name.len);
LAX dbg_name; LAX dbg_name;
} }
} }
@ -415,9 +415,9 @@ void GPU_InitPipelines(void)
} }
GPU_D12_Pipeline **pipelines = PushStructs(scratch.arena, GPU_D12_Pipeline *, num_pipelines); GPU_D12_Pipeline **pipelines = PushStructs(scratch.arena, GPU_D12_Pipeline *, num_pipelines);
{ {
__profn("Allocate pipelines"); __profn("Acquire pipelines");
Counter counter = ZI; Counter counter = ZI;
RunJob(num_pipelines, GPU_D12_AllocPipelineJob, JobPool_Inherit, JobPriority_Inherit, &counter, .descs_in = descs, .pipelines_out = pipelines); RunJob(num_pipelines, GPU_D12_AcquirePipelineJob, 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)
@ -490,8 +490,8 @@ void GPU_D12_InitNoise(void)
desc.SampleDesc.Count = 1; desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0; desc.SampleDesc.Quality = 0;
GPU_D12_Resource *r = GPU_D12_AllocResource(heap_props, heap_flags, desc, D3D12_RESOURCE_STATE_COPY_DEST); GPU_D12_Resource *r = GPU_D12_AcquireResource(heap_props, heap_flags, desc, D3D12_RESOURCE_STATE_COPY_DEST);
r->srv_descriptor = GPU_D12_AllocDescriptor(g->cbv_srv_uav_heap); r->srv_descriptor = GPU_D12_AcquireDescriptor(g->cbv_srv_uav_heap);
ID3D12Device_CreateShaderResourceView(g->device, r->resource, 0, r->srv_descriptor->handle); ID3D12Device_CreateShaderResourceView(g->device, r->resource, 0, r->srv_descriptor->handle);
/* Upload texture */ /* Upload texture */
@ -568,7 +568,7 @@ JobDef(GPU_D12_CompileShaderJob, sig, id)
* Pipeline * Pipeline
* ========================== */ * ========================== */
JobDef(GPU_D12_AllocPipelineJob, sig, id) JobDef(GPU_D12_AcquirePipelineJob, sig, id)
{ {
__prof; __prof;
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
@ -936,7 +936,7 @@ GPU_D12_PipelineScope *GPU_D12_BeginPipelineScope(void)
} }
else else
{ {
arena = AllocArena(Mebi(64)); arena = AcquireArena(Mebi(64));
} }
ResetArena(arena); ResetArena(arena);
scope = PushStruct(arena, GPU_D12_PipelineScope); scope = PushStruct(arena, GPU_D12_PipelineScope);
@ -1170,7 +1170,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, JobPool_Inherit, JobPriority_Low, &counter, .descs_in = pipeline_descs, .pipelines_out = pipelines); RunJob(num_pipelines, GPU_D12_AcquirePipelineJob, JobPool_Inherit, JobPriority_Low, &counter, .descs_in = pipeline_descs, .pipelines_out = pipelines);
WaitOnCounter(&counter); WaitOnCounter(&counter);
} }
{ {
@ -1219,7 +1219,7 @@ W_CallbackFuncDef(GPU_D12_WatchPipelineCallback, name)
* Descriptor * Descriptor
* ========================== */ * ========================== */
GPU_D12_Descriptor *GPU_D12_AllocDescriptor(GPU_D12_CpuDescriptorHeap *dh) GPU_D12_Descriptor *GPU_D12_AcquireDescriptor(GPU_D12_CpuDescriptorHeap *dh)
{ {
__prof; __prof;
GPU_D12_Descriptor *d = 0; GPU_D12_Descriptor *d = 0;
@ -1268,13 +1268,13 @@ void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor)
* CPU descriptor heap * CPU descriptor heap
* ========================== */ * ========================== */
GPU_D12_CpuDescriptorHeap *GPU_D12_AllocCpuDescriptorHeap(enum D3D12_DESCRIPTOR_HEAP_TYPE type) GPU_D12_CpuDescriptorHeap *GPU_D12_AcquireCpuDescriptorHeap(enum D3D12_DESCRIPTOR_HEAP_TYPE type)
{ {
__prof; __prof;
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
GPU_D12_CpuDescriptorHeap *dh = 0; GPU_D12_CpuDescriptorHeap *dh = 0;
{ {
Arena *arena = AllocArena(Mebi(64)); Arena *arena = AcquireArena(Mebi(64));
dh = PushStruct(arena, GPU_D12_CpuDescriptorHeap); dh = PushStruct(arena, GPU_D12_CpuDescriptorHeap);
dh->arena = arena; dh->arena = arena;
} }
@ -1363,7 +1363,7 @@ void GPU_D12_ReleaseDataFenced(void *data, GPU_D12_FencedReleaseKind kind)
* Resource * Resource
* ========================== */ * ========================== */
GPU_D12_Resource *GPU_D12_AllocResource(D3D12_HEAP_PROPERTIES heap_props, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES initial_state) GPU_D12_Resource *GPU_D12_AcquireResource(D3D12_HEAP_PROPERTIES heap_props, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES initial_state)
{ {
__prof; __prof;
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
@ -1502,9 +1502,9 @@ void GPU_D12_InsertBarrier(ID3D12GraphicsCommandList *cl, i32 num_descs, GPU_D12
* Command queue * Command queue
* ========================== */ * ========================== */
GPU_D12_CommandListPool *GPU_D12_AllocCommandListPool(GPU_D12_CommandQueue *cq); GPU_D12_CommandListPool *GPU_D12_AcquireCommandListPool(GPU_D12_CommandQueue *cq);
JobDef(GPU_D12_AllocCommandQueueJob, sig, id) JobDef(GPU_D12_AcquireCommandQueueJob, sig, id)
{ {
__prof; __prof;
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
@ -1512,7 +1512,7 @@ JobDef(GPU_D12_AllocCommandQueueJob, sig, id)
{ {
GPU_D12_CommandQueue *cq = 0; GPU_D12_CommandQueue *cq = 0;
{ {
Arena *arena = AllocArena(Gibi(64)); Arena *arena = AcquireArena(Gibi(64));
cq = PushStruct(arena, GPU_D12_CommandQueue); cq = PushStruct(arena, GPU_D12_CommandQueue);
cq->arena = arena; cq->arena = arena;
} }
@ -1534,7 +1534,7 @@ JobDef(GPU_D12_AllocCommandQueueJob, sig, id)
Panic(Lit("Failed to create command queue fence")); Panic(Lit("Failed to create command queue fence"));
} }
cq->cl_pool = GPU_D12_AllocCommandListPool(cq); cq->cl_pool = GPU_D12_AcquireCommandListPool(cq);
sig->cqs_out[id] = cq; sig->cqs_out[id] = cq;
} }
@ -1552,11 +1552,11 @@ void GPU_D12_ReleaseCommandQueue(GPU_D12_CommandQueue *cq)
* Command list * Command list
* ========================== */ * ========================== */
GPU_D12_CommandListPool *GPU_D12_AllocCommandListPool(GPU_D12_CommandQueue *cq) GPU_D12_CommandListPool *GPU_D12_AcquireCommandListPool(GPU_D12_CommandQueue *cq)
{ {
GPU_D12_CommandListPool *pool = 0; GPU_D12_CommandListPool *pool = 0;
{ {
Arena *arena = AllocArena(Gibi(64)); Arena *arena = AcquireArena(Gibi(64));
pool = PushStruct(arena, GPU_D12_CommandListPool); pool = PushStruct(arena, GPU_D12_CommandListPool);
pool->arena = arena; pool->arena = arena;
} }
@ -1768,7 +1768,7 @@ GPU_D12_CommandDescriptorHeap *GPU_D12_PushDescriptorHeap(GPU_D12_CommandList *c
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
Assert(dh_cpu->type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); /* Src heap must have expected type */ Assert(dh_cpu->type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); /* Src heap must have expected type */
/* Allocate GPU heap */ /* Acquire GPU heap */
GPU_D12_CommandDescriptorHeap *cdh = 0; GPU_D12_CommandDescriptorHeap *cdh = 0;
ID3D12DescriptorHeap *old_heap = 0; ID3D12DescriptorHeap *old_heap = 0;
D3D12_CPU_DESCRIPTOR_HANDLE old_start_cpu_handle = ZI; D3D12_CPU_DESCRIPTOR_HANDLE old_start_cpu_handle = ZI;
@ -1877,7 +1877,7 @@ GPU_D12_CommandBuffer *GPU_D12__PushCommandBuffer(GPU_D12_CommandList *cl, u64 d
/* Determine size */ /* Determine size */
u64 size = MaxU64(DX12_COMMAND_BUFFER_MIN_SIZE, AlignU64Pow2(data_len)); u64 size = MaxU64(DX12_COMMAND_BUFFER_MIN_SIZE, AlignU64Pow2(data_len));
/* Allocate buffer */ /* Acquire buffer */
GPU_D12_CommandBufferGroup *cb_group = 0; GPU_D12_CommandBufferGroup *cb_group = 0;
GPU_D12_CommandBuffer *cb = 0; GPU_D12_CommandBuffer *cb = 0;
GPU_D12_Resource *r = 0; GPU_D12_Resource *r = 0;
@ -1931,7 +1931,7 @@ GPU_D12_CommandBuffer *GPU_D12__PushCommandBuffer(GPU_D12_CommandList *cl, u64 d
} }
else else
{ {
/* Allocate new */ /* Acquire new */
cb = PushStructNoZero(g->command_buffers_arena, GPU_D12_CommandBuffer); cb = PushStructNoZero(g->command_buffers_arena, GPU_D12_CommandBuffer);
} }
Unlock(&lock); Unlock(&lock);
@ -1963,8 +1963,8 @@ GPU_D12_CommandBuffer *GPU_D12__PushCommandBuffer(GPU_D12_CommandList *cl, u64 d
desc.SampleDesc.Quality = 0; desc.SampleDesc.Quality = 0;
D3D12_RESOURCE_STATES initial_state = D3D12_RESOURCE_STATE_GENERIC_READ; D3D12_RESOURCE_STATES initial_state = D3D12_RESOURCE_STATE_GENERIC_READ;
r = GPU_D12_AllocResource(heap_props, heap_flags, desc, initial_state); r = GPU_D12_AcquireResource(heap_props, heap_flags, desc, initial_state);
r->srv_descriptor = GPU_D12_AllocDescriptor(g->cbv_srv_uav_heap); r->srv_descriptor = GPU_D12_AcquireDescriptor(g->cbv_srv_uav_heap);
} }
cb->resource = r; cb->resource = r;
@ -2024,7 +2024,7 @@ JobDef(GPU_D12_WaitOnFenceJob, sig, UNUSED id)
* Texture * Texture
* ========================== */ * ========================== */
GPU_Resource *GPU_AllocTexture(GPU_TextureFormat format, u32 flags, Vec2I32 size, void *initial_data) GPU_Resource *GPU_AcquireTexture(GPU_TextureFormat format, u32 flags, Vec2I32 size, void *initial_data)
{ {
__prof; __prof;
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
@ -2069,15 +2069,15 @@ GPU_Resource *GPU_AllocTexture(GPU_TextureFormat format, u32 flags, Vec2I32 size
D3D12_RESOURCE_STATES initial_state = D3D12_RESOURCE_STATE_COPY_DEST; D3D12_RESOURCE_STATES initial_state = D3D12_RESOURCE_STATE_COPY_DEST;
GPU_D12_Resource *r = GPU_D12_AllocResource(heap_props, heap_flags, desc, initial_state); GPU_D12_Resource *r = GPU_D12_AcquireResource(heap_props, heap_flags, desc, initial_state);
r->texture_size = size; r->texture_size = size;
r->srv_descriptor = GPU_D12_AllocDescriptor(g->cbv_srv_uav_heap); r->srv_descriptor = GPU_D12_AcquireDescriptor(g->cbv_srv_uav_heap);
ID3D12Device_CreateShaderResourceView(g->device, r->resource, 0, r->srv_descriptor->handle); ID3D12Device_CreateShaderResourceView(g->device, r->resource, 0, r->srv_descriptor->handle);
if (flags & GP_TEXTURE_FLAG_TARGETABLE) if (flags & GP_TEXTURE_FLAG_TARGETABLE)
{ {
desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
r->uav_descriptor = GPU_D12_AllocDescriptor(g->cbv_srv_uav_heap); r->uav_descriptor = GPU_D12_AcquireDescriptor(g->cbv_srv_uav_heap);
r->rtv_descriptor = GPU_D12_AllocDescriptor(g->rtv_heap); r->rtv_descriptor = GPU_D12_AcquireDescriptor(g->rtv_heap);
ID3D12Device_CreateUnorderedAccessView(g->device, r->resource, 0, 0, r->uav_descriptor->handle); ID3D12Device_CreateUnorderedAccessView(g->device, r->resource, 0, 0, r->uav_descriptor->handle);
ID3D12Device_CreateRenderTargetView(g->device, r->resource, 0, r->rtv_descriptor->handle); ID3D12Device_CreateRenderTargetView(g->device, r->resource, 0, r->rtv_descriptor->handle);
} }
@ -2145,7 +2145,7 @@ JobDef(GPU_D12_UploadJob, sig, UNUSED id)
upload_desc.SampleDesc.Quality = 0; upload_desc.SampleDesc.Quality = 0;
D3D12_RESOURCE_STATES upload_initial_state = D3D12_RESOURCE_STATE_GENERIC_READ; D3D12_RESOURCE_STATES upload_initial_state = D3D12_RESOURCE_STATE_GENERIC_READ;
upload = GPU_D12_AllocResource(upload_heap_props, upload_heap_flags, upload_desc, upload_initial_state); upload = GPU_D12_AcquireResource(upload_heap_props, upload_heap_flags, upload_desc, upload_initial_state);
} }
GPU_D12_CommandQueue *cq = g->command_queues[DX12_QUEUE_COPY_BACKGROUND]; GPU_D12_CommandQueue *cq = g->command_queues[DX12_QUEUE_COPY_BACKGROUND];
@ -2302,7 +2302,7 @@ D3D12_INDEX_BUFFER_VIEW GPU_D12_IbvFromCommandBuffer(GPU_D12_CommandBuffer *cb,
return ibv; return ibv;
} }
GPU_D12_Resource *GPU_D12_AllocGbuff(DXGI_FORMAT format, Vec2I32 size, D3D12_RESOURCE_STATES initial_state) GPU_D12_Resource *GPU_D12_AcquireGbuff(DXGI_FORMAT format, Vec2I32 size, D3D12_RESOURCE_STATES initial_state)
{ {
__prof; __prof;
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
@ -2325,10 +2325,10 @@ GPU_D12_Resource *GPU_D12_AllocGbuff(DXGI_FORMAT format, Vec2I32 size, D3D12_RES
desc.SampleDesc.Quality = 0; desc.SampleDesc.Quality = 0;
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
GPU_D12_Resource *r = GPU_D12_AllocResource(heap_props, heap_flags, desc, initial_state); GPU_D12_Resource *r = GPU_D12_AcquireResource(heap_props, heap_flags, desc, initial_state);
r->srv_descriptor = GPU_D12_AllocDescriptor(g->cbv_srv_uav_heap); r->srv_descriptor = GPU_D12_AcquireDescriptor(g->cbv_srv_uav_heap);
r->uav_descriptor = GPU_D12_AllocDescriptor(g->cbv_srv_uav_heap); r->uav_descriptor = GPU_D12_AcquireDescriptor(g->cbv_srv_uav_heap);
r->rtv_descriptor = GPU_D12_AllocDescriptor(g->rtv_heap); r->rtv_descriptor = GPU_D12_AcquireDescriptor(g->rtv_heap);
ID3D12Device_CreateShaderResourceView(g->device, r->resource, 0, r->srv_descriptor->handle); ID3D12Device_CreateShaderResourceView(g->device, r->resource, 0, r->srv_descriptor->handle);
ID3D12Device_CreateUnorderedAccessView(g->device, r->resource, 0, 0, r->uav_descriptor->handle); ID3D12Device_CreateUnorderedAccessView(g->device, r->resource, 0, 0, r->uav_descriptor->handle);
ID3D12Device_CreateRenderTargetView(g->device, r->resource, 0, r->rtv_descriptor->handle); ID3D12Device_CreateRenderTargetView(g->device, r->resource, 0, r->rtv_descriptor->handle);
@ -2349,21 +2349,21 @@ D3D12_GPU_DESCRIPTOR_HANDLE GPU_D12_GpuHandleFromDescriptor(GPU_D12_Descriptor *
* Render sig * Render sig
* ========================== */ * ========================== */
GPU_D12_RenderSig *GPU_D12_AllocRenderSig(void) GPU_D12_RenderSig *GPU_D12_AcquireRenderSig(void)
{ {
__prof; __prof;
GPU_D12_RenderSig *sig = 0; GPU_D12_RenderSig *sig = 0;
{ {
Arena *arena = AllocArena(Mebi(64)); Arena *arena = AcquireArena(Mebi(64));
sig = PushStruct(arena, GPU_D12_RenderSig); sig = PushStruct(arena, GPU_D12_RenderSig);
sig->arena = arena; sig->arena = arena;
} }
sig->material_instance_descs_arena = AllocArena(Gibi(1)); sig->material_instance_descs_arena = AcquireArena(Gibi(1));
sig->material_grid_descs_arena = AllocArena(Gibi(1)); sig->material_grid_descs_arena = AcquireArena(Gibi(1));
sig->ui_rect_instance_descs_arena = AllocArena(Gibi(1)); sig->ui_rect_instance_descs_arena = AcquireArena(Gibi(1));
sig->ui_shape_verts_arena = AllocArena(Gibi(1)); sig->ui_shape_verts_arena = AcquireArena(Gibi(1));
sig->ui_shape_indices_arena = AllocArena(Gibi(1)); sig->ui_shape_indices_arena = AcquireArena(Gibi(1));
return sig; return sig;
} }
@ -2389,10 +2389,10 @@ void GPU_D12_ResetRenderSig(GPU_D12_RenderSig *sig)
ResetArena(sig->material_grid_descs_arena); ResetArena(sig->material_grid_descs_arena);
} }
GPU_RenderSig *GPU_AllocRenderSig(void) GPU_RenderSig *GPU_AcquireRenderSig(void)
{ {
__prof; __prof;
GPU_D12_RenderSig *sig = GPU_D12_AllocRenderSig(); GPU_D12_RenderSig *sig = GPU_D12_AcquireRenderSig();
return (GPU_RenderSig *)sig; return (GPU_RenderSig *)sig;
} }
@ -2488,7 +2488,7 @@ GPU_Resource *GPU_RunRender(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
Rect render_viewport = RectFromVec2(VEC2(0, 0), VEC2(render_size.x, render_size.y)); Rect render_viewport = RectFromVec2(VEC2(0, 0), VEC2(render_size.x, render_size.y));
/* Allocate render buffers */ /* Acquire render buffers */
if (rsig->shade_target && !EqVec2I32(render_size, rsig->shade_target->texture_size)) if (rsig->shade_target && !EqVec2I32(render_size, rsig->shade_target->texture_size))
{ {
__profn("Release sig resources"); __profn("Release sig resources");
@ -2502,16 +2502,16 @@ GPU_Resource *GPU_RunRender(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
} }
if (!rsig->shade_target) if (!rsig->shade_target)
{ {
__profn("Allocate sig resources"); __profn("Acquire sig resources");
rsig->albedo = GPU_D12_AllocGbuff(DXGI_FORMAT_R8G8B8A8_UNORM, render_size, D3D12_RESOURCE_STATE_RENDER_TARGET); rsig->albedo = GPU_D12_AcquireGbuff(DXGI_FORMAT_R8G8B8A8_UNORM, render_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
rsig->emittance = GPU_D12_AllocGbuff(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_RENDER_TARGET); rsig->emittance = GPU_D12_AcquireGbuff(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
rsig->emittance_flood_read = GPU_D12_AllocGbuff(DXGI_FORMAT_R16G16_UINT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); rsig->emittance_flood_read = GPU_D12_AcquireGbuff(DXGI_FORMAT_R16G16_UINT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
rsig->emittance_flood_target = GPU_D12_AllocGbuff(DXGI_FORMAT_R16G16_UINT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); rsig->emittance_flood_target = GPU_D12_AcquireGbuff(DXGI_FORMAT_R16G16_UINT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
rsig->shade_read = GPU_D12_AllocGbuff(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); rsig->shade_read = GPU_D12_AcquireGbuff(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
rsig->shade_target = GPU_D12_AllocGbuff(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); rsig->shade_target = GPU_D12_AcquireGbuff(DXGI_FORMAT_R16G16B16A16_FLOAT, render_size, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
} }
/* Allocate ui buffers */ /* Acquire ui buffers */
if (rsig->ui_target && !EqVec2I32(ui_size, rsig->ui_target->texture_size)) if (rsig->ui_target && !EqVec2I32(ui_size, rsig->ui_target->texture_size))
{ {
GPU_D12_ReleaseDataFenced(rsig->ui_target, GPU_D12_FencedReleaseKind_Resource); GPU_D12_ReleaseDataFenced(rsig->ui_target, GPU_D12_FencedReleaseKind_Resource);
@ -2519,7 +2519,7 @@ GPU_Resource *GPU_RunRender(GPU_RenderSig *gp_render_sig, GPU_RenderParams param
} }
if (!rsig->ui_target) if (!rsig->ui_target)
{ {
rsig->ui_target = GPU_D12_AllocGbuff(DXGI_FORMAT_R8G8B8A8_UNORM, ui_size, D3D12_RESOURCE_STATE_RENDER_TARGET); rsig->ui_target = GPU_D12_AcquireGbuff(DXGI_FORMAT_R8G8B8A8_UNORM, ui_size, D3D12_RESOURCE_STATE_RENDER_TARGET);
} }
GPU_D12_PipelineScope *pipeline_scope = GPU_D12_BeginPipelineScope(); GPU_D12_PipelineScope *pipeline_scope = GPU_D12_BeginPipelineScope();
@ -3005,13 +3005,13 @@ void GPU_D12_InitSwapchainResources(GPU_D12_Swapchain *swapchain)
ZeroStruct(sb); ZeroStruct(sb);
sb->swapchain = swapchain; sb->swapchain = swapchain;
sb->resource = resource; sb->resource = resource;
sb->rtv_descriptor = GPU_D12_AllocDescriptor(g->rtv_heap); sb->rtv_descriptor = GPU_D12_AcquireDescriptor(g->rtv_heap);
sb->state = D3D12_RESOURCE_STATE_COMMON; sb->state = D3D12_RESOURCE_STATE_COMMON;
ID3D12Device_CreateRenderTargetView(g->device, sb->resource, 0, sb->rtv_descriptor->handle); ID3D12Device_CreateRenderTargetView(g->device, sb->resource, 0, sb->rtv_descriptor->handle);
} }
} }
GPU_Swapchain *GPU_AllocSwapchain(P_Window *window, Vec2I32 resolution) GPU_Swapchain *GPU_AcquireSwapchain(P_Window *window, Vec2I32 resolution)
{ {
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
HRESULT hr = 0; HRESULT hr = 0;

View File

@ -463,7 +463,7 @@ JobDecl(GPU_D12_CompileShaderJob, { Arena *arena; GPU_D12_ShaderDesc *descs; GPU
* Pipeline * Pipeline
* ========================== */ * ========================== */
JobDecl(GPU_D12_AllocPipelineJob, { GPU_D12_PipelineDesc *descs_in; GPU_D12_Pipeline **pipelines_out; }); JobDecl(GPU_D12_AcquirePipelineJob, { GPU_D12_PipelineDesc *descs_in; GPU_D12_Pipeline **pipelines_out; });
void GPU_D12_ReleasePipelineNow(GPU_D12_Pipeline *pipeline); void GPU_D12_ReleasePipelineNow(GPU_D12_Pipeline *pipeline);
@ -486,7 +486,7 @@ W_CallbackFuncDef(GPU_D12_WatchPipelineCallback, name);
* Descriptor * Descriptor
* ========================== */ * ========================== */
GPU_D12_Descriptor *GPU_D12_AllocDescriptor(GPU_D12_CpuDescriptorHeap *dh); GPU_D12_Descriptor *GPU_D12_AcquireDescriptor(GPU_D12_CpuDescriptorHeap *dh);
void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor); void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor);
@ -494,7 +494,7 @@ void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor);
* CPU descriptor heap * CPU descriptor heap
* ========================== */ * ========================== */
GPU_D12_CpuDescriptorHeap *GPU_D12_AllocCpuDescriptorHeap(enum D3D12_DESCRIPTOR_HEAP_TYPE type); GPU_D12_CpuDescriptorHeap *GPU_D12_AcquireCpuDescriptorHeap(enum D3D12_DESCRIPTOR_HEAP_TYPE type);
/* ========================== * /* ========================== *
* Fenced release * Fenced release
@ -506,7 +506,7 @@ void GPU_D12_ReleaseDataFenced(void *data, GPU_D12_FencedReleaseKind kind);
* Resource * Resource
* ========================== */ * ========================== */
GPU_D12_Resource *GPU_D12_AllocResource(D3D12_HEAP_PROPERTIES heap_props, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES initial_state); GPU_D12_Resource *GPU_D12_AcquireResource(D3D12_HEAP_PROPERTIES heap_props, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES initial_state);
void GPU_D12_ReleaseResourceNow(GPU_D12_Resource *t); void GPU_D12_ReleaseResourceNow(GPU_D12_Resource *t);
@ -522,7 +522,7 @@ void GPU_D12_InsertBarrier(ID3D12GraphicsCommandList *cl, i32 num_descs, GPU_D12
* Command queue * Command queue
* ========================== */ * ========================== */
JobDecl(GPU_D12_AllocCommandQueueJob, { GPU_D12_CommandQueueDesc *descs_in; GPU_D12_CommandQueue **cqs_out; }); JobDecl(GPU_D12_AcquireCommandQueueJob, { GPU_D12_CommandQueueDesc *descs_in; GPU_D12_CommandQueue **cqs_out; });
void GPU_D12_ReleaseCommandQueue(GPU_D12_CommandQueue *cq); void GPU_D12_ReleaseCommandQueue(GPU_D12_CommandQueue *cq);
@ -530,7 +530,7 @@ void GPU_D12_ReleaseCommandQueue(GPU_D12_CommandQueue *cq);
* Command list * Command list
* ========================== */ * ========================== */
GPU_D12_CommandListPool *GPU_D12_AllocCommandListPool(GPU_D12_CommandQueue *cq); GPU_D12_CommandListPool *GPU_D12_AcquireCommandListPool(GPU_D12_CommandQueue *cq);
GPU_D12_CommandList *GPU_D12_BeginCommandList(GPU_D12_CommandListPool *pool); GPU_D12_CommandList *GPU_D12_BeginCommandList(GPU_D12_CommandListPool *pool);
@ -581,7 +581,7 @@ D3D12_VERTEX_BUFFER_VIEW GPU_D12_VbvFromCommandBuffer(GPU_D12_CommandBuffer *cb,
D3D12_INDEX_BUFFER_VIEW GPU_D12_IbvFromCommandBuffer(GPU_D12_CommandBuffer *cb, DXGI_FORMAT format); D3D12_INDEX_BUFFER_VIEW GPU_D12_IbvFromCommandBuffer(GPU_D12_CommandBuffer *cb, DXGI_FORMAT format);
GPU_D12_Resource *GPU_D12_AllocGbuff(DXGI_FORMAT format, Vec2I32 size, D3D12_RESOURCE_STATES initial_state); GPU_D12_Resource *GPU_D12_AcquireGbuff(DXGI_FORMAT format, Vec2I32 size, D3D12_RESOURCE_STATES initial_state);
D3D12_GPU_DESCRIPTOR_HANDLE GPU_D12_GpuHandleFromDescriptor(GPU_D12_Descriptor *descriptor, GPU_D12_CommandDescriptorHeap *cdh); D3D12_GPU_DESCRIPTOR_HANDLE GPU_D12_GpuHandleFromDescriptor(GPU_D12_Descriptor *descriptor, GPU_D12_CommandDescriptorHeap *cdh);
@ -589,11 +589,11 @@ D3D12_GPU_DESCRIPTOR_HANDLE GPU_D12_GpuHandleFromDescriptor(GPU_D12_Descriptor *
* Render sig * Render sig
* ========================== */ * ========================== */
GPU_D12_RenderSig *GPU_D12_AllocRenderSig(void); GPU_D12_RenderSig *GPU_D12_AcquireRenderSig(void);
void GPU_D12_ResetRenderSig(GPU_D12_RenderSig *sig); void GPU_D12_ResetRenderSig(GPU_D12_RenderSig *sig);
GPU_RenderSig *GPU_AllocRenderSig(void); GPU_RenderSig *GPU_AcquireRenderSig(void);
/* ========================== * /* ========================== *
* Swapchain * Swapchain

View File

@ -23,7 +23,7 @@ void MIX_StartupCore(void)
{ {
__prof; __prof;
MIX_SharedState *g = &M_shared_state; MIX_SharedState *g = &M_shared_state;
g->track_arena = AllocArena(Gibi(64)); g->track_arena = AcquireArena(Gibi(64));
g->listener_pos = VEC2(0, 0); g->listener_pos = VEC2(0, 0);
g->listener_dir = VEC2(0, -1); g->listener_dir = VEC2(0, -1);
} }
@ -52,7 +52,7 @@ MIX_Track *MIX_TrackFromHandle(MIX_Handle handle)
} }
} }
MIX_Track *MIX_AllocTrackLocked(Lock *lock, SND_Sound *sound) MIX_Track *MIX_AcquireTrackLocked(Lock *lock, SND_Sound *sound)
{ {
MIX_SharedState *g = &M_shared_state; MIX_SharedState *g = &M_shared_state;
AssertLockedE(lock, &g->mutex); AssertLockedE(lock, &g->mutex);
@ -73,7 +73,7 @@ MIX_Track *MIX_AllocTrackLocked(Lock *lock, SND_Sound *sound)
} }
else else
{ {
/* Allocate new */ /* Acquire new */
track = PushStruct(g->track_arena, MIX_Track); track = PushStruct(g->track_arena, MIX_Track);
track->gen = 1; track->gen = 1;
} }
@ -156,7 +156,7 @@ MIX_Handle MIX_PlaySoundEx(SND_Sound *sound, MIX_TrackDesc desc)
{ {
Lock lock = LockE(&g->mutex); Lock lock = LockE(&g->mutex);
{ {
track = MIX_AllocTrackLocked(&lock, sound); track = MIX_AcquireTrackLocked(&lock, sound);
track->desc = desc; track->desc = desc;
} }
Unlock(&lock); Unlock(&lock);

View File

@ -105,7 +105,7 @@ void MIX_StartupCore(void);
MIX_Handle MIX_HandleFromTrack(MIX_Track *track); MIX_Handle MIX_HandleFromTrack(MIX_Track *track);
MIX_Track *MIX_TrackFromHandle(MIX_Handle handle); MIX_Track *MIX_TrackFromHandle(MIX_Handle handle);
MIX_Track *MIX_AllocTrackLocked(Lock *lock, SND_Sound *sound); MIX_Track *MIX_AcquireTrackLocked(Lock *lock, SND_Sound *sound);
void MIX_ReleaseTrackLocked(Lock *lock, MIX_Track *track); void MIX_ReleaseTrackLocked(Lock *lock, MIX_Track *track);
//////////////////////////////// ////////////////////////////////

View File

@ -15,19 +15,19 @@
//////////////////////////////// ////////////////////////////////
//~ Host //~ Host
N_Host *N_AllocHost(u16 listen_port) N_Host *N_AcquireHost(u16 listen_port)
{ {
Arena *arena = AllocArena(Gibi(64)); Arena *arena = AcquireArena(Gibi(64));
N_Host *host = PushStruct(arena, N_Host); N_Host *host = PushStruct(arena, N_Host);
host->arena = arena; host->arena = arena;
host->cmd_arena = AllocArena(Gibi(64)); host->cmd_arena = AcquireArena(Gibi(64));
host->channel_arena = AllocArena(Gibi(64)); host->channel_arena = AcquireArena(Gibi(64));
host->rcv_buffer_read = PushStruct(host->arena, N_RcvBuffer); host->rcv_buffer_read = PushStruct(host->arena, N_RcvBuffer);
host->rcv_buffer_write = PushStruct(host->arena, N_RcvBuffer); host->rcv_buffer_write = PushStruct(host->arena, N_RcvBuffer);
host->rcv_buffer_read->arena = AllocArena(Gibi(64)); host->rcv_buffer_read->arena = AcquireArena(Gibi(64));
host->rcv_buffer_write->arena = AllocArena(Gibi(64)); host->rcv_buffer_write->arena = AcquireArena(Gibi(64));
host->buddy = AllocBuddyCtx(Gibi(64)); host->buddy = AcquireBuddyCtx(Gibi(64));
host->channels = PushDry(host->channel_arena, N_Channel); host->channels = PushDry(host->channel_arena, N_Channel);
@ -37,7 +37,7 @@ N_Host *N_AllocHost(u16 listen_port)
host->num_msg_assembler_lookup_bins = N_NumMsgAssemblerLookupBins; host->num_msg_assembler_lookup_bins = N_NumMsgAssemblerLookupBins;
host->msg_assembler_lookup_bins = PushStructs(host->arena, N_MsgAssemblerLookupBin, host->num_msg_assembler_lookup_bins); host->msg_assembler_lookup_bins = PushStructs(host->arena, N_MsgAssemblerLookupBin, host->num_msg_assembler_lookup_bins);
host->sock = P_AllocSock(listen_port, Mebi(2), Mebi(2)); host->sock = P_AcquireSock(listen_port, Mebi(2), Mebi(2));
return host; return host;
} }
@ -128,7 +128,7 @@ N_ChannelList N_ChannelsFromId(Arena *arena, N_Host *host, N_ChannelId channel_i
return result; return result;
} }
N_Channel *N_AllocChannel(N_Host *host, P_Address address) N_Channel *N_AcquireChannel(N_Host *host, P_Address address)
{ {
N_ChannelId id = ZI; N_ChannelId id = ZI;
N_Channel *channel; N_Channel *channel;
@ -248,7 +248,7 @@ N_MsgAssembler *N_MsgAssemblerFromMsg(N_Host *host, N_ChannelId channel_id, u64
return 0; return 0;
} }
N_MsgAssembler *N_AllocMsgAssembler(N_Channel *channel, u64 msg_id, u64 chunk_count, u64 now_ns, b32 is_reliable) N_MsgAssembler *N_AcquireMsgAssembler(N_Channel *channel, u64 msg_id, u64 chunk_count, u64 now_ns, b32 is_reliable)
{ {
N_Host *host = channel->host; N_Host *host = channel->host;
N_MsgAssembler *ma; N_MsgAssembler *ma;
@ -275,10 +275,10 @@ N_MsgAssembler *N_AllocMsgAssembler(N_Channel *channel, u64 msg_id, u64 chunk_co
} }
u64 chunk_data_size = chunk_count * N_MaxPacketChunkLen; u64 chunk_data_size = chunk_count * N_MaxPacketChunkLen;
/* Allocate msg data using buddy allocator since the assembler has /* Acquire msg data using buddy allocator since the assembler has
* arbitrary lifetime and data needs to stay contiguous for random * arbitrary lifetime and data needs to stay contiguous for random
* access as packets are received */ * access as packets are received */
ma->buddy_block = AllocBuddyBlock(host->buddy, chunk_bitmap_size + chunk_data_size); ma->buddy_block = AcquireBuddyBlock(host->buddy, chunk_bitmap_size + chunk_data_size);
ma->chunk_bitmap = ma->buddy_block->memory; ma->chunk_bitmap = ma->buddy_block->memory;
ZeroBytes(ma->chunk_bitmap, chunk_bitmap_size); ZeroBytes(ma->chunk_bitmap, chunk_bitmap_size);
ma->chunk_data = ma->chunk_bitmap + chunk_bitmap_size; ma->chunk_data = ma->chunk_bitmap + chunk_bitmap_size;
@ -504,7 +504,7 @@ void N_Connect(N_Host *host, P_Address connect_address)
N_Channel *channel = N_ChannelFromAddress(host, connect_address); N_Channel *channel = N_ChannelFromAddress(host, connect_address);
if (!channel->valid) if (!channel->valid)
{ {
channel = N_AllocChannel(host, connect_address); channel = N_AcquireChannel(host, connect_address);
} }
} }
@ -632,7 +632,7 @@ N_EventList N_BeginUpdate(Arena *arena, N_Host *host)
{ {
P_LogInfoF("Host received conection attempt from %F", FmtString(P_StringFromAddress(scratch.arena, address))); P_LogInfoF("Host received conection attempt from %F", FmtString(P_StringFromAddress(scratch.arena, address)));
/* TODO: Verify that some per-host uuid isn't present in a rolling window to prevent reconnects right after a disconnect? */ /* TODO: Verify that some per-host uuid isn't present in a rolling window to prevent reconnects right after a disconnect? */
channel = N_AllocChannel(host, address); channel = N_AcquireChannel(host, address);
} }
N_Cmd *cmd = N_PushCmd(host); N_Cmd *cmd = N_PushCmd(host);
cmd->kind = N_CmdKind_ConnectSuccess; cmd->kind = N_CmdKind_ConnectSuccess;
@ -702,7 +702,7 @@ N_EventList N_BeginUpdate(Arena *arena, N_Host *host)
N_MsgAssembler *ma = N_MsgAssemblerFromMsg(host, channel->id, msg_id); N_MsgAssembler *ma = N_MsgAssemblerFromMsg(host, channel->id, msg_id);
if (!ma) if (!ma)
{ {
ma = N_AllocMsgAssembler(channel, msg_id, chunk_count, now_ns, is_reliable); ma = N_AcquireMsgAssembler(channel, msg_id, chunk_count, now_ns, is_reliable);
} }
if (chunk_count == ma->num_chunks_total && chunk_id < chunk_count) if (chunk_count == ma->num_chunks_total && chunk_id < chunk_count)

View File

@ -236,13 +236,13 @@ Struct(N_Host)
N_Channel *first_free_channel; N_Channel *first_free_channel;
u64 num_channels_reserved; u64 num_channels_reserved;
N_SndPacket *first_free_packet; /* Allocated in `arena` */ N_SndPacket *first_free_packet; /* Acquired in `arena` */
N_MsgAssembler *first_free_msg_assembler; /* Allocated in `arena` */ N_MsgAssembler *first_free_msg_assembler; /* Acquired in `arena` */
N_ChannelLookupBin *channel_lookup_bins; /* Allocated in `arena` */ N_ChannelLookupBin *channel_lookup_bins; /* Acquired in `arena` */
u64 num_channel_lookup_bins; u64 num_channel_lookup_bins;
N_MsgAssemblerLookupBin *msg_assembler_lookup_bins; /* Allocated in `arena` */ N_MsgAssemblerLookupBin *msg_assembler_lookup_bins; /* Acquired in `arena` */
u64 num_msg_assembler_lookup_bins; u64 num_msg_assembler_lookup_bins;
/* Double buffer for incoming data */ /* Double buffer for incoming data */
@ -262,7 +262,7 @@ Readonly Global N_Channel N_nil_channel = { .valid = 0 };
//////////////////////////////// ////////////////////////////////
//~ Host initialization //~ Host initialization
N_Host *N_AllocHost(u16 listen_port); N_Host *N_AcquireHost(u16 listen_port);
void N_ReleaseHost(N_Host *host); void N_ReleaseHost(N_Host *host);
//////////////////////////////// ////////////////////////////////
@ -278,7 +278,7 @@ u64 N_HashFromAddress(P_Address address);
N_Channel *N_ChannelFromAddress(N_Host *host, P_Address address); N_Channel *N_ChannelFromAddress(N_Host *host, P_Address address);
N_Channel *N_ChannelFromId(N_Host *host, N_ChannelId channel_id); N_Channel *N_ChannelFromId(N_Host *host, N_ChannelId channel_id);
N_ChannelList N_ChannelsFromId(Arena *arena, N_Host *host, N_ChannelId channel_id); N_ChannelList N_ChannelsFromId(Arena *arena, N_Host *host, N_ChannelId channel_id);
N_Channel *N_AllocChannel(N_Host *host, P_Address address); N_Channel *N_AcquireChannel(N_Host *host, P_Address address);
void N_ReleaseChannel(N_Channel *channel); void N_ReleaseChannel(N_Channel *channel);
//////////////////////////////// ////////////////////////////////
@ -286,7 +286,7 @@ void N_ReleaseChannel(N_Channel *channel);
u64 N_HashFromMsg(N_ChannelId channel_id, u64 msg_id); u64 N_HashFromMsg(N_ChannelId channel_id, u64 msg_id);
N_MsgAssembler *N_MsgAssemblerFromMsg(N_Host *host, N_ChannelId channel_id, u64 msg_id); N_MsgAssembler *N_MsgAssemblerFromMsg(N_Host *host, N_ChannelId channel_id, u64 msg_id);
N_MsgAssembler *N_AllocMsgAssembler(N_Channel *channel, u64 msg_id, u64 chunk_count, u64 now_ns, b32 is_reliable); N_MsgAssembler *N_AcquireMsgAssembler(N_Channel *channel, u64 msg_id, u64 chunk_count, u64 now_ns, b32 is_reliable);
void N_ReleaseMessageAssembler(N_MsgAssembler *ma); void N_ReleaseMessageAssembler(N_MsgAssembler *ma);
void N_TouchMessageAssembler(N_MsgAssembler *ma, i64 now_ns); void N_TouchMessageAssembler(N_MsgAssembler *ma, i64 now_ns);
b32 N_IsChunkFilled(N_MsgAssembler *ma, u64 chunk_id); b32 N_IsChunkFilled(N_MsgAssembler *ma, u64 chunk_id);

View File

@ -348,7 +348,7 @@ String P_GetFileMapData(P_FileMap map);
//~ @hookdecl Watch operations //~ @hookdecl Watch operations
// A watch object allows the caller to watch for changes in a directory // A watch object allows the caller to watch for changes in a directory
P_Watch *P_AllocWatch(String path); P_Watch *P_AcquireWatch(String path);
void P_ReleaseWatch(P_Watch *dw); void P_ReleaseWatch(P_Watch *dw);
P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw); P_WatchInfoList P_ReadWatchWait(Arena *arena, P_Watch *dw);
void P_WakeWatch(P_Watch *dw); void P_WakeWatch(P_Watch *dw);
@ -356,7 +356,7 @@ void P_WakeWatch(P_Watch *dw);
//////////////////////////////// ////////////////////////////////
//~ @hookdecl Window operations //~ @hookdecl Window operations
P_Window *P_AllocWindow(void); P_Window *P_AcquireWindow(void);
void P_ReleaseWindow(P_Window *window); void P_ReleaseWindow(P_Window *window);
//- Events //- Events
@ -390,7 +390,7 @@ b32 P_AddressIsEqual(P_Address a, P_Address b);
//////////////////////////////// ////////////////////////////////
//~ @hookdecl Sock operations //~ @hookdecl Sock operations
P_Sock *P_AllocSock(u16 listen_port, u64 sndbuf_size, u64 rcvbuf_size); P_Sock *P_AcquireSock(u16 listen_port, u64 sndbuf_size, u64 rcvbuf_size);
void P_ReleaseSock(P_Sock *sock); void P_ReleaseSock(P_Sock *sock);
P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock); P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock);
void P_WriteSock(P_Sock *sock, P_Address address, String data); void P_WriteSock(P_Sock *sock, P_Address address, String data);

View File

@ -10,7 +10,7 @@ void P_StartupLog(String logfile_path)
{ {
__prof; __prof;
P_SharedLogState *ctx = &P_shared_log_state; P_SharedLogState *ctx = &P_shared_log_state;
ctx->callbacks_arena = AllocArena(Mebi(8)); ctx->callbacks_arena = AcquireArena(Mebi(8));
if (logfile_path.len > 0) if (logfile_path.len > 0)
{ {
/* Create / wipe log file */ /* Create / wipe log file */

View File

@ -105,14 +105,14 @@ void P_StartupCore(void)
} }
//- Init watches pool //- Init watches pool
g->watches_arena = AllocArena(Gibi(64)); g->watches_arena = AcquireArena(Gibi(64));
//- Init windows pool //- Init windows pool
g->windows_arena = AllocArena(Gibi(64)); g->windows_arena = AcquireArena(Gibi(64));
//- Init winsock //- Init winsock
WSAStartup(MAKEWORD(2, 2), &g->wsa_data); WSAStartup(MAKEWORD(2, 2), &g->wsa_data);
g->socks_arena = AllocArena(Gibi(64)); g->socks_arena = AcquireArena(Gibi(64));
} }
//////////////////////////////// ////////////////////////////////
@ -168,7 +168,7 @@ String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src)
//////////////////////////////// ////////////////////////////////
//~ Win32 window //~ Win32 window
P_W32_Window *P_W32_AllocWindow(void) P_W32_Window *P_W32_AcquireWindow(void)
{ {
P_W32_SharedCtx *g = &P_W32_shared_ctx; P_W32_SharedCtx *g = &P_W32_shared_ctx;
P_W32_Window *window = 0; P_W32_Window *window = 0;
@ -187,15 +187,15 @@ P_W32_Window *P_W32_AllocWindow(void)
} }
ZeroStruct(window); ZeroStruct(window);
window->event_arenas[0] = AllocArena(Gibi(64)); window->event_arenas[0] = AcquireArena(Gibi(64));
window->event_arenas[1] = AllocArena(Gibi(64)); window->event_arenas[1] = AcquireArena(Gibi(64));
/* Start window event thread */ /* Start window event thread */
/* NOTE: This thread must finish building for the window to actually be /* NOTE: This thread must finish building for the window to actually be
* created and receive a HWND, because on Windows a the event proc must run on * created and receive a HWND, because on Windows a the event proc must run on
* the same thread that created the window. */ * the same thread that created the window. */
AddCounter(&window->ready_fence, 1); AddCounter(&window->ready_fence, 1);
window->window_thread = W32_AllocThread(&P_W32_WindowThreadEntryFunc, window, Lit("Window thread"), PROF_THREAD_GROUP_WINDOW); window->window_thread = W32_AcquireThread(&P_W32_WindowThreadEntryFunc, window, Lit("Window thread"), PROF_THREAD_GROUP_WINDOW);
WaitOnCounter(&window->ready_fence); WaitOnCounter(&window->ready_fence);
return window; return window;
@ -1251,7 +1251,7 @@ String P_GetFileMapData(P_FileMap map)
//////////////////////////////// ////////////////////////////////
//~ @hookdef Watch hooks //~ @hookdef Watch hooks
P_Watch *P_AllocWatch(String dir_path) P_Watch *P_AcquireWatch(String dir_path)
{ {
TempArena scratch = BeginScratchNoConflict(); TempArena scratch = BeginScratchNoConflict();
struct P_W32_SharedCtx *g = &P_W32_shared_ctx; struct P_W32_SharedCtx *g = &P_W32_shared_ctx;
@ -1440,10 +1440,10 @@ void P_WakeWatch(P_Watch *dw)
//////////////////////////////// ////////////////////////////////
//~ @hookdef Window hooks //~ @hookdef Window hooks
P_Window *P_AllocWindow(void) P_Window *P_AcquireWindow(void)
{ {
__prof; __prof;
return (P_Window *)P_W32_AllocWindow(); return (P_Window *)P_W32_AcquireWindow();
} }
void P_ReleaseWindow(P_Window *p_window) void P_ReleaseWindow(P_Window *p_window)
@ -1786,7 +1786,7 @@ b32 P_AddressIsEqual(P_Address a, P_Address b)
//////////////////////////////// ////////////////////////////////
//~ @hookdef Sock hooks //~ @hookdef Sock hooks
P_Sock *P_AllocSock(u16 listen_port, u64 sndbuf_size, u64 rcvbuf_size) P_Sock *P_AcquireSock(u16 listen_port, u64 sndbuf_size, u64 rcvbuf_size)
{ {
P_W32_SharedCtx *g = &P_W32_shared_ctx; P_W32_SharedCtx *g = &P_W32_shared_ctx;
P_W32_Sock *ws = 0; P_W32_Sock *ws = 0;

View File

@ -146,7 +146,7 @@ String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src);
//////////////////////////////// ////////////////////////////////
//~ Window operations //~ Window operations
P_W32_Window *P_W32_AllocWindow(void); P_W32_Window *P_W32_AcquireWindow(void);
void P_W32_ReleaseWindow(P_W32_Window *window); void P_W32_ReleaseWindow(P_W32_Window *window);
HWND P_W32_InitWindow(P_W32_Window *window); HWND P_W32_InitWindow(P_W32_Window *window);

View File

@ -10,7 +10,7 @@ void StartupUser(void)
SetGstat(GSTAT_DEBUG_STEPS, U64Max); SetGstat(GSTAT_DEBUG_STEPS, U64Max);
g->arena = AllocArena(Gibi(64)); g->arena = AcquireArena(Gibi(64));
g->real_time_ns = TimeNs(); g->real_time_ns = TimeNs();
/* TODO: Remove this */ /* TODO: Remove this */
@ -21,26 +21,26 @@ void StartupUser(void)
g->average_local_to_user_snapshot_publish_dt_ns = NsFromSeconds(1) / SIM_TICKS_PER_SECOND; g->average_local_to_user_snapshot_publish_dt_ns = NsFromSeconds(1) / SIM_TICKS_PER_SECOND;
/* User blend clients */ /* User blend clients */
g->user_client_store = sim_client_store_alloc(); g->user_client_store = sim_client_store_acquire();
g->user_unblended_client = sim_client_alloc(g->user_client_store); g->user_unblended_client = sim_client_acquire(g->user_client_store);
g->user_blended_client = sim_client_alloc(g->user_client_store); g->user_blended_client = sim_client_acquire(g->user_client_store);
g->ss_blended = sim_snapshot_nil(); g->ss_blended = sim_snapshot_nil();
/* Local to user client */ /* Local to user client */
g->local_to_user_client_store = sim_client_store_alloc(); g->local_to_user_client_store = sim_client_store_acquire();
g->local_to_user_client = sim_client_alloc(g->local_to_user_client_store); g->local_to_user_client = sim_client_acquire(g->local_to_user_client_store);
/* GPU handles */ /* GPU handles */
g->world_to_ui_xf = XformIdentity; g->world_to_ui_xf = XformIdentity;
g->world_to_render_xf = XformIdentity; g->world_to_render_xf = XformIdentity;
g->render_sig = GPU_AllocRenderSig(); g->render_sig = GPU_AcquireRenderSig();
g->console_logs_arena = AllocArena(Gibi(64)); g->console_logs_arena = AcquireArena(Gibi(64));
//P_RegisterLogCallback(ConsoleLogCallback, P_LogLevel_Success); //P_RegisterLogCallback(ConsoleLogCallback, P_LogLevel_Success);
P_RegisterLogCallback(ConsoleLogCallback, P_LogLevel_Debug); P_RegisterLogCallback(ConsoleLogCallback, P_LogLevel_Debug);
g->window = P_AllocWindow(); g->window = P_AcquireWindow();
g->swapchain = GPU_AllocSwapchain(g->window, VEC2I32(100, 100)); g->swapchain = GPU_AcquireSwapchain(g->window, VEC2I32(100, 100));
P_ShowWindow(g->window); P_ShowWindow(g->window);
/* Start jobs */ /* Start jobs */
@ -419,7 +419,7 @@ void UpdateUser(P_Window *window)
if (last_tick > old_last_tick) if (last_tick > old_last_tick)
{ {
Snapshot *src = sim_snapshot_from_tick(g->local_to_user_client, last_tick); Snapshot *src = sim_snapshot_from_tick(g->local_to_user_client, last_tick);
sim_snapshot_alloc(g->user_unblended_client, src, src->tick); sim_snapshot_acquire(g->user_unblended_client, src, src->tick);
g->last_local_to_user_snapshot_published_at_ns = g->local_to_user_client_publish_time_ns; g->last_local_to_user_snapshot_published_at_ns = g->local_to_user_client_publish_time_ns;
g->average_local_to_user_snapshot_publish_dt_ns -= g->average_local_to_user_snapshot_publish_dt_ns / 50; g->average_local_to_user_snapshot_publish_dt_ns -= g->average_local_to_user_snapshot_publish_dt_ns / 50;
g->average_local_to_user_snapshot_publish_dt_ns += g->local_to_user_client_publish_dt_ns / 50; g->average_local_to_user_snapshot_publish_dt_ns += g->local_to_user_client_publish_dt_ns / 50;
@ -494,15 +494,15 @@ void UpdateUser(P_Window *window)
if (left_snapshot->valid && right_snapshot->valid) if (left_snapshot->valid && right_snapshot->valid)
{ {
f64 blend = (f64)(g->render_time_ns - left_snapshot->sim_time_ns) / (f64)(right_snapshot->sim_time_ns - left_snapshot->sim_time_ns); f64 blend = (f64)(g->render_time_ns - left_snapshot->sim_time_ns) / (f64)(right_snapshot->sim_time_ns - left_snapshot->sim_time_ns);
g->ss_blended = sim_snapshot_alloc_from_lerp(g->user_blended_client, left_snapshot, right_snapshot, blend); g->ss_blended = sim_snapshot_acquire_from_lerp(g->user_blended_client, left_snapshot, right_snapshot, blend);
} }
else if (left_snapshot->valid) else if (left_snapshot->valid)
{ {
g->ss_blended = sim_snapshot_alloc(g->user_blended_client, left_snapshot, left_snapshot->tick); g->ss_blended = sim_snapshot_acquire(g->user_blended_client, left_snapshot, left_snapshot->tick);
} }
else if (right_snapshot->valid) else if (right_snapshot->valid)
{ {
g->ss_blended = sim_snapshot_alloc(g->user_blended_client, right_snapshot, right_snapshot->tick); g->ss_blended = sim_snapshot_acquire(g->user_blended_client, right_snapshot, right_snapshot->tick);
} }
/* Release unneeded unblended snapshots */ /* Release unneeded unblended snapshots */
@ -516,7 +516,7 @@ void UpdateUser(P_Window *window)
/* Interp disabled, just copy latest snapshot */ /* Interp disabled, just copy latest snapshot */
g->render_time_target_ns = newest_snapshot->sim_time_ns; g->render_time_target_ns = newest_snapshot->sim_time_ns;
g->render_time_ns = newest_snapshot->sim_time_ns; g->render_time_ns = newest_snapshot->sim_time_ns;
g->ss_blended = sim_snapshot_alloc(g->user_blended_client, newest_snapshot, newest_snapshot->tick); g->ss_blended = sim_snapshot_acquire(g->user_blended_client, newest_snapshot, newest_snapshot->tick);
/* Release unneeded unblended snapshots */ /* Release unneeded unblended snapshots */
if (newest_snapshot->tick > 0) if (newest_snapshot->tick > 0)
@ -930,9 +930,9 @@ void UpdateUser(P_Window *window)
} }
#if 0 #if 0
//- Alloc / release tile cache entries //- Acquire / release tile cache entries
/* Alloc entries from new sim chunks */ /* Acquire entries from new sim chunks */
for (u64 ent_index = 0; ent_index < g->ss_blended->num_ents_reserved; ++ent_index) for (u64 ent_index = 0; ent_index < g->ss_blended->num_ents_reserved; ++ent_index)
{ {
@ -942,7 +942,7 @@ void UpdateUser(P_Window *window)
struct user_tile_cache_entry *entry = user_tile_cache_entry_from_chunk_pos(chunk_ent->tile_chunk_pos); struct user_tile_cache_entry *entry = user_tile_cache_entry_from_chunk_pos(chunk_ent->tile_chunk_pos);
if (!entry->valid) if (!entry->valid)
{ {
entry = user_tile_cache_entry_alloc(chunk_ent->tile_chunk_pos); entry = user_tile_cache_entry_acquire(chunk_ent->tile_chunk_pos);
} }
} }
} }
@ -2083,13 +2083,13 @@ void GenerateuserInputCmds(Client *user_input_client, u64 tick)
{ {
SharedUserState *g = &shared_user_state; SharedUserState *g = &shared_user_state;
Snapshot *prev_user_input_ss = sim_snapshot_from_tick(user_input_client, user_input_client->last_tick); Snapshot *prev_user_input_ss = sim_snapshot_from_tick(user_input_client, user_input_client->last_tick);
Snapshot *user_input_ss = sim_snapshot_alloc(user_input_client, prev_user_input_ss, tick); Snapshot *user_input_ss = sim_snapshot_acquire(user_input_client, prev_user_input_ss, tick);
Entity *user_input_root = sim_ent_from_id(user_input_ss, SIM_ENT_ROOT_ID); Entity *user_input_root = sim_ent_from_id(user_input_ss, SIM_ENT_ROOT_ID);
/* Find / create local control cmd ent */ /* Find / create local control cmd ent */
Entity *control_cmd = sim_ent_find_first_match_one(user_input_ss, SEPROP_CMD); Entity *control_cmd = sim_ent_find_first_match_one(user_input_ss, SEPROP_CMD);
if (!control_cmd->valid) if (!control_cmd->valid)
{ {
control_cmd = sim_ent_alloc_sync_src(user_input_root); control_cmd = sim_ent_acquire_sync_src(user_input_root);
control_cmd->cmd_kind = SIM_CMD_KIND_CONTROL; control_cmd->cmd_kind = SIM_CMD_KIND_CONTROL;
control_cmd->predictor = user_input_client->player_id; control_cmd->predictor = user_input_client->player_id;
sim_ent_enable_prop(control_cmd, SEPROP_CMD); sim_ent_enable_prop(control_cmd, SEPROP_CMD);
@ -2106,7 +2106,7 @@ void GenerateuserInputCmds(Client *user_input_client, u64 tick)
/* Create chat cmd */ /* Create chat cmd */
if (g->user_sim_cmd_chat.len > 0) if (g->user_sim_cmd_chat.len > 0)
{ {
Entity *chat_cmd = sim_ent_alloc_sync_src(user_input_root); Entity *chat_cmd = sim_ent_acquire_sync_src(user_input_root);
chat_cmd->cmd_kind = SIM_CMD_KIND_CHAT; chat_cmd->cmd_kind = SIM_CMD_KIND_CHAT;
//chat_cmd->chat_msg = ZI //chat_cmd->chat_msg = ZI
} }
@ -2125,7 +2125,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
#if 0 #if 0
struct host_listen_address local_listen_addr = host_listen_address_from_local_name(Lit("LOCAL_SIM")); struct host_listen_address local_listen_addr = host_listen_address_from_local_name(Lit("LOCAL_SIM"));
struct host_listen_address net_listen_addr = host_listen_address_from_net_port(12345); struct host_listen_address net_listen_addr = host_listen_address_from_net_port(12345);
//N_Host *host = N_AllocHost(); //N_Host *host = N_AcquireHost();
/* TODO: Host system should allocate & copy string stored in local_listen_addr */ /* TODO: Host system should allocate & copy string stored in local_listen_addr */
//host_listen(host, local_listen_addr); //host_listen(host, local_listen_addr);
//host_listen(host, net_listen_addr); //host_listen(host, net_listen_addr);
@ -2135,24 +2135,24 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
N_Host *host; N_Host *host;
if (g->connect_address_str.len > 0) if (g->connect_address_str.len > 0)
{ {
host = N_AllocHost(0); host = N_AcquireHost(0);
P_Address addr = P_AddressFromString(g->connect_address_str); P_Address addr = P_AddressFromString(g->connect_address_str);
N_Connect(host, addr); N_Connect(host, addr);
} }
else else
{ {
host = N_AllocHost(12345); host = N_AcquireHost(12345);
is_master = 1; is_master = 1;
} }
BB_Buff msg_writer_bb = AllocBitbuff(Gibi(64)); BB_Buff msg_writer_bb = AcquireBitbuff(Gibi(64));
BB_Buff snapshot_writer_bb = AllocBitbuff(Gibi(64)); BB_Buff snapshot_writer_bb = AcquireBitbuff(Gibi(64));
SimAccel accel = sim_accel_alloc(); SimAccel accel = sim_accel_acquire();
ClientStore *store = sim_client_store_alloc(); ClientStore *store = sim_client_store_acquire();
Client *user_input_client = sim_client_alloc(store); /* Stores snapshots containing commands to be published to local client */ Client *user_input_client = sim_client_acquire(store); /* Stores snapshots containing commands to be published to local client */
Client *local_client = sim_client_alloc(store); /* Stores snapshots produced locally */ Client *local_client = sim_client_acquire(store); /* Stores snapshots produced locally */
Client *publish_client = sim_client_alloc(store); /* Stores versions of local snapshots that will be published to remote sims */ Client *publish_client = sim_client_acquire(store); /* Stores versions of local snapshots that will be published to remote sims */
Client *master_client = sim_client_nil(); /* Stores snapshots received from master */ Client *master_client = sim_client_nil(); /* Stores snapshots received from master */
Client *master_blended_client = sim_client_nil(); /* Stores interpolated master snapshots */ Client *master_blended_client = sim_client_nil(); /* Stores interpolated master snapshots */
@ -2229,7 +2229,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
if (is_master) if (is_master)
{ {
/* Create remote client */ /* Create remote client */
client = sim_client_alloc(store); client = sim_client_acquire(store);
sim_client_set_channel_id(client, channel_id); sim_client_set_channel_id(client, channel_id);
} }
else else
@ -2237,10 +2237,10 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
/* Create master client */ /* Create master client */
if (!master_client->valid) if (!master_client->valid)
{ {
client = sim_client_alloc(store); client = sim_client_acquire(store);
sim_client_set_channel_id(client, channel_id); sim_client_set_channel_id(client, channel_id);
master_client = client; master_client = client;
master_blended_client = sim_client_alloc(store); master_blended_client = sim_client_acquire(store);
} }
else else
{ {
@ -2374,8 +2374,8 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
BB_Buff bb = BitbuffFromString(n->tmp_encoded); BB_Buff bb = BitbuffFromString(n->tmp_encoded);
BB_Reader br = BB_ReaderFromBuff(&bb); BB_Reader br = BB_ReaderFromBuff(&bb);
/* Alloc & decode snapshot */ /* Acquire & decode snapshot */
Snapshot *ss = sim_snapshot_alloc(client, base_ss, tick); Snapshot *ss = sim_snapshot_acquire(client, base_ss, tick);
sim_snapshot_decode(&br, ss); sim_snapshot_decode(&br, ss);
/* Assume all incoming ents want to be sync srcs */ /* Assume all incoming ents want to be sync srcs */
@ -2494,7 +2494,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
ctx.master_client = master_client; ctx.master_client = master_client;
ctx.publish_client = publish_client; ctx.publish_client = publish_client;
Snapshot *prev_world = sim_snapshot_from_tick(local_client, prev_tick); Snapshot *prev_world = sim_snapshot_from_tick(local_client, prev_tick);
ctx.world = sim_snapshot_alloc(local_client, prev_world, next_tick); ctx.world = sim_snapshot_acquire(local_client, prev_world, next_tick);
GenerateuserInputCmds(user_input_client, next_tick); GenerateuserInputCmds(user_input_client, next_tick);
sim_step(&ctx); sim_step(&ctx);
} }
@ -2576,7 +2576,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
else else
{ {
master_ss_is_blended = 1; master_ss_is_blended = 1;
master_ss = sim_snapshot_alloc_from_lerp(master_blended_client, left_snapshot, right_snapshot, blend); master_ss = sim_snapshot_acquire_from_lerp(master_blended_client, left_snapshot, right_snapshot, blend);
/* Release unneeded blended master snapshots */ /* Release unneeded blended master snapshots */
if (master_ss->tick > 0) if (master_ss->tick > 0)
@ -2696,7 +2696,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
} }
else else
{ {
base_ss = sim_snapshot_alloc(local_client, master_ss, step_base_tick); base_ss = sim_snapshot_acquire(local_client, master_ss, step_base_tick);
} }
} }
@ -2718,7 +2718,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
Snapshot *prev_ss = base_ss; Snapshot *prev_ss = base_ss;
while (step_tick <= step_end_tick) while (step_tick <= step_end_tick)
{ {
ctx.world = sim_snapshot_alloc(local_client, prev_ss, step_tick); ctx.world = sim_snapshot_acquire(local_client, prev_ss, step_tick);
if (!mispredicted_tick && step_tick == step_end_tick) if (!mispredicted_tick && step_tick == step_end_tick)
{ {
sim_snapshot_sync_ents(ctx.world, master_ss, master_player->id, SIM_SYNC_FLAG_NOSYNC_PREDICTABLES); sim_snapshot_sync_ents(ctx.world, master_ss, master_player->id, SIM_SYNC_FLAG_NOSYNC_PREDICTABLES);
@ -2786,7 +2786,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id)
{ {
/* TODO: Double buffer */ /* TODO: Double buffer */
Lock lock = LockE(&g->local_to_user_client_mutex); Lock lock = LockE(&g->local_to_user_client_mutex);
sim_snapshot_alloc(g->local_to_user_client, local_ss, local_ss->tick); sim_snapshot_acquire(g->local_to_user_client, local_ss, local_ss->tick);
i64 publish_ns = TimeNs(); i64 publish_ns = TimeNs();
if (last_publish_to_user_ns == 0) if (last_publish_to_user_ns == 0)
{ {

View File

@ -21,7 +21,7 @@ internal Entity *ent_from_index(Snapshot *ss, u32 index)
* Entity allocation * Entity allocation
* ========================== */ * ========================== */
Entity *sim_ent_alloc_raw(Snapshot *ss, Entity *parent, EntityId id) Entity *sim_ent_acquire_raw(Snapshot *ss, Entity *parent, EntityId id)
{ {
Assert(parent->valid); Assert(parent->valid);
Assert(ss->valid); Assert(ss->valid);
@ -49,47 +49,47 @@ Entity *sim_ent_alloc_raw(Snapshot *ss, Entity *parent, EntityId id)
return ent; return ent;
} }
/* Allocates a new entity that will not sync */ /* Acquires a new entity that will not sync */
Entity *sim_ent_alloc_local(Entity *parent) Entity *sim_ent_acquire_local(Entity *parent)
{ {
Snapshot *ss = parent->ss; Snapshot *ss = parent->ss;
Entity *e = sim_ent_alloc_raw(ss, parent, sim_ent_random_id()); Entity *e = sim_ent_acquire_raw(ss, parent, sim_ent_random_id());
e->owner = ss->local_player; e->owner = ss->local_player;
return e; return e;
} }
Entity *sim_ent_alloc_local_with_id(Entity *parent, EntityId id) Entity *sim_ent_acquire_local_with_id(Entity *parent, EntityId id)
{ {
Snapshot *ss = parent->ss; Snapshot *ss = parent->ss;
Entity *e = sim_ent_alloc_raw(ss, parent, id); Entity *e = sim_ent_acquire_raw(ss, parent, id);
e->owner = ss->local_player; e->owner = ss->local_player;
return e; return e;
} }
/* Allocates a new entity to be synced to clients */ /* Acquires a new entity to be synced to clients */
Entity *sim_ent_alloc_sync_src(Entity *parent) Entity *sim_ent_acquire_sync_src(Entity *parent)
{ {
Snapshot *ss = parent->ss; Snapshot *ss = parent->ss;
Entity *e = sim_ent_alloc_raw(ss, parent, sim_ent_random_id()); Entity *e = sim_ent_acquire_raw(ss, parent, sim_ent_random_id());
sim_ent_enable_prop(e, SEPROP_SYNC_SRC); sim_ent_enable_prop(e, SEPROP_SYNC_SRC);
e->owner = ss->local_player; e->owner = ss->local_player;
return e; return e;
} }
Entity *sim_ent_alloc_sync_src_with_id(Entity *parent, EntityId id) Entity *sim_ent_acquire_sync_src_with_id(Entity *parent, EntityId id)
{ {
Snapshot *ss = parent->ss; Snapshot *ss = parent->ss;
Entity *e = sim_ent_alloc_raw(ss, parent, id); Entity *e = sim_ent_acquire_raw(ss, parent, id);
sim_ent_enable_prop(e, SEPROP_SYNC_SRC); sim_ent_enable_prop(e, SEPROP_SYNC_SRC);
e->owner = ss->local_player; e->owner = ss->local_player;
return e; return e;
} }
/* Allocates a new entity that will sync with incoming net src ents containing id, and coming from the specified owner */ /* Acquires a new entity that will sync with incoming net src ents containing id, and coming from the specified owner */
Entity *sim_ent_alloc_sync_dst(Entity *parent, EntityId ent_id, EntityId owner_id) Entity *sim_ent_acquire_sync_dst(Entity *parent, EntityId ent_id, EntityId owner_id)
{ {
Snapshot *ss = parent->ss; Snapshot *ss = parent->ss;
Entity *e = sim_ent_alloc_raw(ss, parent, ent_id); Entity *e = sim_ent_acquire_raw(ss, parent, ent_id);
sim_ent_enable_prop(e, SEPROP_SYNC_DST); sim_ent_enable_prop(e, SEPROP_SYNC_DST);
e->owner = owner_id; e->owner = owner_id;
return e; return e;
@ -624,7 +624,7 @@ void sim_ent_lerp(Entity *e, Entity *e0, Entity *e1, f64 blend)
* ========================== */ * ========================== */
/* Walks a local & remote ent tree and allocates any missing net dst ents from remote src ents */ /* Walks a local & remote ent tree and allocates any missing net dst ents from remote src ents */
void sim_ent_sync_alloc_tree(Entity *local_parent, Entity *remote, EntityId remote_player) void sim_ent_sync_acquire_tree(Entity *local_parent, Entity *remote, EntityId remote_player)
{ {
__prof; __prof;
if (sim_ent_has_prop(remote, SEPROP_SYNC_SRC)) { if (sim_ent_has_prop(remote, SEPROP_SYNC_SRC)) {
@ -634,10 +634,10 @@ void sim_ent_sync_alloc_tree(Entity *local_parent, Entity *remote, EntityId remo
EntityId id = remote->id; EntityId id = remote->id;
Entity *local_ent = sim_ent_from_id(local_ss, id); Entity *local_ent = sim_ent_from_id(local_ss, id);
if (!local_ent->valid) { if (!local_ent->valid) {
local_ent = sim_ent_alloc_sync_dst(local_parent, id, remote_player); local_ent = sim_ent_acquire_sync_dst(local_parent, id, remote_player);
} }
for (Entity *remote_child = sim_ent_from_id(remote_ss, remote->first); remote_child->valid; remote_child = sim_ent_from_id(remote_ss, remote_child->next)) { for (Entity *remote_child = sim_ent_from_id(remote_ss, remote->first); remote_child->valid; remote_child = sim_ent_from_id(remote_ss, remote_child->next)) {
sim_ent_sync_alloc_tree(local_ent, remote_child, remote_player); sim_ent_sync_acquire_tree(local_ent, remote_child, remote_player);
} }
} }
} }

View File

@ -487,13 +487,13 @@ Inline b32 sim_ent_should_simulate(Entity *ent)
* Entity functions * Entity functions
* ========================== */ * ========================== */
/* Alloc */ /* Acquire */
Entity *sim_ent_alloc_raw(Snapshot *ss, Entity *parent, EntityId id); Entity *sim_ent_acquire_raw(Snapshot *ss, Entity *parent, EntityId id);
Entity *sim_ent_alloc_local(Entity *parent); Entity *sim_ent_acquire_local(Entity *parent);
Entity *sim_ent_alloc_local_with_id(Entity *parent, EntityId id); Entity *sim_ent_acquire_local_with_id(Entity *parent, EntityId id);
Entity *sim_ent_alloc_sync_src(Entity *parent); Entity *sim_ent_acquire_sync_src(Entity *parent);
Entity *sim_ent_alloc_sync_src_with_id(Entity *parent, EntityId id); Entity *sim_ent_acquire_sync_src_with_id(Entity *parent, EntityId id);
Entity *sim_ent_alloc_sync_dst(Entity *parent, EntityId ent_id, EntityId owner_id); Entity *sim_ent_acquire_sync_dst(Entity *parent, EntityId ent_id, EntityId owner_id);
void sim_ent_release_raw(Entity *ent); void sim_ent_release_raw(Entity *ent);
void sim_ent_release(Entity *ent); void sim_ent_release(Entity *ent);
@ -542,7 +542,7 @@ TileKind sim_get_chunk_tile(Entity *chunk_ent, Vec2I32 local_tile_index);
void sim_ent_lerp(Entity *e, Entity *e0, Entity *e1, f64 blend); void sim_ent_lerp(Entity *e, Entity *e0, Entity *e1, f64 blend);
/* Sync */ /* Sync */
void sim_ent_sync_alloc_tree(Entity *local_parent, Entity *remote, EntityId remote_player); void sim_ent_sync_acquire_tree(Entity *local_parent, Entity *remote, EntityId remote_player);
void sim_ent_sync(Entity *local, Entity *remote); void sim_ent_sync(Entity *local, Entity *remote);
/* Encode / decode */ /* Encode / decode */

View File

@ -93,7 +93,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
if (!constraint_ent->valid) { if (!constraint_ent->valid) {
is_start = 1; is_start = 1;
/* Create constraint */ /* Create constraint */
constraint_ent = sim_ent_alloc_local_with_id(root, constraint_id); constraint_ent = sim_ent_acquire_local_with_id(root, constraint_id);
constraint_ent->contact_constraint_data.e0 = e0->id; constraint_ent->contact_constraint_data.e0 = e0->id;
constraint_ent->contact_constraint_data.e1 = e1->id; constraint_ent->contact_constraint_data.e1 = e1->id;
/* Both entities must be solid and one must be dynamic for a solve to be necessary. */ /* Both entities must be solid and one must be dynamic for a solve to be necessary. */
@ -232,7 +232,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_
Entity *dbg_ent = sim_ent_from_id(ss, dbg_ent_id); Entity *dbg_ent = sim_ent_from_id(ss, dbg_ent_id);
if (!dbg_ent->valid) { if (!dbg_ent->valid) {
/* FIXME: Entity never released */ /* FIXME: Entity never released */
dbg_ent = sim_ent_alloc_local_with_id(root, dbg_ent_id); dbg_ent = sim_ent_acquire_local_with_id(root, dbg_ent_id);
sim_ent_enable_prop(dbg_ent, SEPROP_COLLISION_DEBUG); sim_ent_enable_prop(dbg_ent, SEPROP_COLLISION_DEBUG);
} }
@ -1221,7 +1221,7 @@ void phys_update_aabbs(PhysStepCtx *ctx)
Xform xf = sim_ent_get_xform(ent); Xform xf = sim_ent_get_xform(ent);
SpaceEntry *space_entry = space_entry_from_handle(space, ent->space_handle); SpaceEntry *space_entry = space_entry_from_handle(space, ent->space_handle);
if (!space_entry->valid) { if (!space_entry->valid) {
space_entry = space_entry_alloc(space, ent->id); space_entry = space_entry_acquire(space, ent->id);
ent->space_handle = space_entry->handle; ent->space_handle = space_entry->handle;
} }
Aabb aabb = CLD_AabbFromShape(&ent->local_collider, xf); Aabb aabb = CLD_AabbFromShape(&ent->local_collider, xf);

View File

@ -55,7 +55,7 @@ Readonly Entity **_g_sim_ent_nil = &G.nil_ent;
void StartupSim(void) void StartupSim(void)
{ {
__prof; __prof;
G.nil_arena = AllocArena(Gibi(1)); G.nil_arena = AcquireArena(Gibi(1));
/* Nil client store */ /* Nil client store */
G.nil_client_store = PushStruct(G.nil_arena, ClientStore); G.nil_client_store = PushStruct(G.nil_arena, ClientStore);
@ -93,19 +93,19 @@ void StartupSim(void)
* Client store alloc * Client store alloc
* ========================== */ * ========================== */
ClientStore *sim_client_store_alloc(void) ClientStore *sim_client_store_acquire(void)
{ {
__prof; __prof;
ClientStore *store; ClientStore *store;
{ {
Arena *arena = AllocArena(Gibi(64)); Arena *arena = AcquireArena(Gibi(64));
store = PushStruct(arena, ClientStore); store = PushStruct(arena, ClientStore);
store->arena = arena; store->arena = arena;
} }
store->valid = 1; store->valid = 1;
store->num_client_lookup_bins = CLIENT_LOOKUP_BINS; store->num_client_lookup_bins = CLIENT_LOOKUP_BINS;
store->client_lookup_bins = PushStructs(store->arena, ClientLookupBin, store->num_client_lookup_bins); store->client_lookup_bins = PushStructs(store->arena, ClientLookupBin, store->num_client_lookup_bins);
store->clients_arena = AllocArena(Gibi(64)); store->clients_arena = AcquireArena(Gibi(64));
store->clients = PushDry(store->clients_arena, Client); store->clients = PushDry(store->clients_arena, Client);
return store; return store;
} }
@ -127,7 +127,7 @@ void sim_client_store_release(ClientStore *store)
* Client alloc * Client alloc
* ========================== */ * ========================== */
Client *sim_client_alloc(ClientStore *store) Client *sim_client_acquire(ClientStore *store)
{ {
ClientHandle handle = ZI; ClientHandle handle = ZI;
Client *client = sim_client_from_handle(store, store->first_free_client); Client *client = sim_client_from_handle(store, store->first_free_client);
@ -148,7 +148,7 @@ Client *sim_client_alloc(ClientStore *store)
client->valid = 1; client->valid = 1;
client->handle = handle; client->handle = handle;
client->snapshots_arena = AllocArena(Gibi(8)); client->snapshots_arena = AcquireArena(Gibi(8));
client->num_snapshot_lookup_bins = TICK_LOOKUP_BINS; client->num_snapshot_lookup_bins = TICK_LOOKUP_BINS;
client->snapshot_lookup_bins = PushStructs(client->snapshots_arena, SnapshotLookupBin, client->num_snapshot_lookup_bins); client->snapshot_lookup_bins = PushStructs(client->snapshots_arena, SnapshotLookupBin, client->num_snapshot_lookup_bins);
@ -266,7 +266,7 @@ Client *sim_client_from_handle(ClientStore *store, ClientHandle handle)
* ========================== */ * ========================== */
/* Produces a new snapshot at `tick` with data copied from `src` snapshot. */ /* Produces a new snapshot at `tick` with data copied from `src` snapshot. */
Snapshot *sim_snapshot_alloc(Client *client, Snapshot *src, u64 tick) Snapshot *sim_snapshot_acquire(Client *client, Snapshot *src, u64 tick)
{ {
if (tick == 0) { if (tick == 0) {
return sim_snapshot_nil(); return sim_snapshot_nil();
@ -285,8 +285,8 @@ Snapshot *sim_snapshot_alloc(Client *client, Snapshot *src, u64 tick)
arena = ss->arena; arena = ss->arena;
} else { } else {
/* Arenas allocated here will be released with client */ /* Arenas allocated here will be released with client */
arena = AllocArena(Gibi(1)); arena = AcquireArena(Gibi(1));
ents_arena = AllocArena(Gibi(1)); ents_arena = AcquireArena(Gibi(1));
} }
} }
ResetArena(arena); ResetArena(arena);
@ -596,7 +596,7 @@ void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile
Entity *chunk_ent = sim_ent_from_id(ss, chunk_id); Entity *chunk_ent = sim_ent_from_id(ss, chunk_id);
if (!chunk_ent->valid) { if (!chunk_ent->valid) {
Entity *root = sim_ent_from_id(ss, SIM_ENT_ROOT_ID); Entity *root = sim_ent_from_id(ss, SIM_ENT_ROOT_ID);
chunk_ent = sim_ent_alloc_sync_src_with_id(root, chunk_id); chunk_ent = sim_ent_acquire_sync_src_with_id(root, chunk_id);
sim_ent_enable_prop(chunk_ent, SEPROP_TILE_CHUNK); sim_ent_enable_prop(chunk_ent, SEPROP_TILE_CHUNK);
chunk_ent->tile_chunk_index = chunk_index; chunk_ent->tile_chunk_index = chunk_index;
} }
@ -609,7 +609,7 @@ void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile
* Snapshot lerp * Snapshot lerp
* ========================== */ * ========================== */
Snapshot *sim_snapshot_alloc_from_lerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend) Snapshot *sim_snapshot_acquire_from_lerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend)
{ {
__prof; __prof;
@ -619,12 +619,12 @@ Snapshot *sim_snapshot_alloc_from_lerp(Client *client, Snapshot *ss0, Snapshot *
Snapshot *ss; Snapshot *ss;
b32 should_blend = 1; b32 should_blend = 1;
if (ss0->continuity_gen == ss1->continuity_gen && 0 < blend && blend < 1) { if (ss0->continuity_gen == ss1->continuity_gen && 0 < blend && blend < 1) {
ss = sim_snapshot_alloc(client, ss0, ss0->tick); ss = sim_snapshot_acquire(client, ss0, ss0->tick);
} else if (RoundF64ToI64(blend) <= 0) { } else if (RoundF64ToI64(blend) <= 0) {
ss = sim_snapshot_alloc(client, ss0, ss0->tick); ss = sim_snapshot_acquire(client, ss0, ss0->tick);
should_blend = 0; should_blend = 0;
} else { } else {
ss = sim_snapshot_alloc(client, ss1, ss1->tick); ss = sim_snapshot_acquire(client, ss1, ss1->tick);
should_blend = 0; should_blend = 0;
} }
@ -674,7 +674,7 @@ void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId re
/* Create new ents from remote */ /* Create new ents from remote */
for (Entity *remote_top = sim_ent_from_id(remote_ss, remote_root->first); remote_top->valid; remote_top = sim_ent_from_id(remote_ss, remote_top->next)) { for (Entity *remote_top = sim_ent_from_id(remote_ss, remote_root->first); remote_top->valid; remote_top = sim_ent_from_id(remote_ss, remote_top->next)) {
sim_ent_sync_alloc_tree(local_root, remote_top, remote_player); sim_ent_sync_acquire_tree(local_root, remote_top, remote_player);
} }
/* Sync ents with remote, skipping index 0 (nil) & index 1 (root) */ /* Sync ents with remote, skipping index 0 (nil) & index 1 (root) */
@ -1014,7 +1014,7 @@ void sim_snapshot_decode(BB_Reader *br, Snapshot *ss)
should_read_ent = BB_ReadBit(br); should_read_ent = BB_ReadBit(br);
} }
/* Allocate new ents from decode queue */ /* Acquire new ents from decode queue */
for (struct sim_ent_decode_node *n = queue.first; n; n = n->next) { for (struct sim_ent_decode_node *n = queue.first; n; n = n->next) {
if (n->is_new) { if (n->is_new) {
u32 index = n->index; u32 index = n->index;

View File

@ -57,7 +57,7 @@ Inline ClientStore *sim_client_store_nil(void)
return *_g_sim_client_store_nil; return *_g_sim_client_store_nil;
} }
ClientStore *sim_client_store_alloc(void); ClientStore *sim_client_store_acquire(void);
void sim_client_store_release(ClientStore *store); void sim_client_store_release(ClientStore *store);
/* ========================== * /* ========================== *
@ -122,7 +122,7 @@ Inline b32 sim_client_handle_eq(ClientHandle a, ClientHandle b)
return a.gen == b.gen && a.idx == b.idx; return a.gen == b.gen && a.idx == b.idx;
} }
Client *sim_client_alloc(ClientStore *store); Client *sim_client_acquire(ClientStore *store);
void sim_client_release(Client *client); void sim_client_release(Client *client);
Client *sim_client_from_channel_id(ClientStore *store, N_ChannelId channel_id); Client *sim_client_from_channel_id(ClientStore *store, N_ChannelId channel_id);
@ -221,8 +221,8 @@ Inline Snapshot *sim_snapshot_nil(void)
return *_g_sim_snapshot_nil; return *_g_sim_snapshot_nil;
} }
/* Alloc */ /* Acquire */
Snapshot *sim_snapshot_alloc(Client *client, Snapshot *src, u64 tick); Snapshot *sim_snapshot_acquire(Client *client, Snapshot *src, u64 tick);
void sim_snapshot_release(Snapshot *sim_snapshot); void sim_snapshot_release(Snapshot *sim_snapshot);
void sim_snapshot_release_ticks_in_range(Client *client, u64 start, u64 end); void sim_snapshot_release_ticks_in_range(Client *client, u64 start, u64 end);
@ -240,7 +240,7 @@ Vec2I32 sim_tile_chunk_index_from_world_tile_index(Vec2I32 world_tile_index);
void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind); void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind);
/* Lerp */ /* Lerp */
Snapshot *sim_snapshot_alloc_from_lerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend); Snapshot *sim_snapshot_acquire_from_lerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend);
/* Sync */ /* Sync */
void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId remote_player, u32 sync_flags); void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId remote_player, u32 sync_flags);

View File

@ -15,11 +15,11 @@ Readonly Space _g_space_nil = { .valid = 0 };
/* NOTE: /* NOTE:
* The number of bins determines how often tiles will collide in the spatial hash. * The number of bins determines how often tiles will collide in the spatial hash.
* For example, at `num_bins_sqrt` = 256 (65536 bins), tiles <1, 1>, <1, 257>, and <257, 257> will collide. */ * For example, at `num_bins_sqrt` = 256 (65536 bins), tiles <1, 1>, <1, 257>, and <257, 257> will collide. */
Space *space_alloc(f32 cell_size, u32 num_bins_sqrt) Space *space_acquire(f32 cell_size, u32 num_bins_sqrt)
{ {
Space *space; Space *space;
{ {
Arena *arena = AllocArena(Gibi(64)); Arena *arena = AcquireArena(Gibi(64));
space = PushStruct(arena, Space); space = PushStruct(arena, Space);
space->entry_arena = arena; space->entry_arena = arena;
} }
@ -27,7 +27,7 @@ Space *space_alloc(f32 cell_size, u32 num_bins_sqrt)
space->valid = 1; space->valid = 1;
space->entries = PushDry(space->entry_arena, SpaceEntry); space->entries = PushDry(space->entry_arena, SpaceEntry);
space->cell_arena = AllocArena(Gibi(64)); space->cell_arena = AcquireArena(Gibi(64));
space->cell_size = cell_size; space->cell_size = cell_size;
space->num_bins = num_bins_sqrt * num_bins_sqrt; space->num_bins = num_bins_sqrt * num_bins_sqrt;
space->num_bins_sqrt = num_bins_sqrt; space->num_bins_sqrt = num_bins_sqrt;
@ -129,7 +129,7 @@ internal void space_cell_node_alloc(Vec2I32 cell_pos, SpaceEntry *entry)
} }
} }
/* Allocate new cell if necessary */ /* Acquire new cell if necessary */
if (!cell) { if (!cell) {
if (space->first_free_cell) { if (space->first_free_cell) {
cell = space->first_free_cell; cell = space->first_free_cell;
@ -150,7 +150,7 @@ internal void space_cell_node_alloc(Vec2I32 cell_pos, SpaceEntry *entry)
cell->valid = 1; cell->valid = 1;
} }
/* Allocate node */ /* Acquire node */
SpaceCellNode *node; SpaceCellNode *node;
{ {
if (space->first_free_cell_node) { if (space->first_free_cell_node) {
@ -267,7 +267,7 @@ SpaceEntry *space_entry_from_handle(Space *space, SpaceEntryHandle handle)
return entry; return entry;
} }
SpaceEntry *space_entry_alloc(Space *space, EntityId ent) SpaceEntry *space_entry_acquire(Space *space, EntityId ent)
{ {
SpaceEntry *entry = 0; SpaceEntry *entry = 0;
SpaceEntryHandle handle = ZI; SpaceEntryHandle handle = ZI;

View File

@ -114,7 +114,7 @@ Inline Space *space_nil(void)
* Space * Space
* ========================== */ * ========================== */
Space *space_alloc(f32 cell_size, u32 num_bins_sqrt); Space *space_acquire(f32 cell_size, u32 num_bins_sqrt);
void space_release(Space *space); void space_release(Space *space);
void space_reset(Space *space); void space_reset(Space *space);
@ -131,7 +131,7 @@ SpaceCell *space_get_cell(Space *space, Vec2I32 cell_pos);
* ========================== */ * ========================== */
SpaceEntry *space_entry_from_handle(Space *space, SpaceEntryHandle handle); SpaceEntry *space_entry_from_handle(Space *space, SpaceEntryHandle handle);
SpaceEntry *space_entry_alloc(Space *space, EntityId entity); SpaceEntry *space_entry_acquire(Space *space, EntityId entity);
void space_entry_release(SpaceEntry *entry); void space_entry_release(SpaceEntry *entry);
void space_entry_update_aabb(SpaceEntry *entry, Aabb new_aabb); void space_entry_update_aabb(SpaceEntry *entry, Aabb new_aabb);

View File

@ -2,10 +2,10 @@
* Sim accel * Sim accel
* ========================== */ * ========================== */
SimAccel sim_accel_alloc(void) SimAccel sim_accel_acquire(void)
{ {
SimAccel accel = ZI; SimAccel accel = ZI;
accel.space = space_alloc(SPACE_CELL_SIZE, SPACE_CELL_BINS_SQRT); accel.space = space_acquire(SPACE_CELL_SIZE, SPACE_CELL_BINS_SQRT);
return accel; return accel;
} }
@ -35,7 +35,7 @@ void sim_accel_reset(Snapshot *ss, SimAccel *accel)
internal Entity *test_spawn_smg(Entity *parent) internal Entity *test_spawn_smg(Entity *parent)
{ {
Entity *e = sim_ent_alloc_sync_src(parent); Entity *e = sim_ent_acquire_sync_src(parent);
e->sprite = S_TagFromPath(Lit("sprite/gun.ase")); e->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
sim_ent_enable_prop(e, SEPROP_ATTACHED); sim_ent_enable_prop(e, SEPROP_ATTACHED);
@ -51,7 +51,7 @@ internal Entity *test_spawn_smg(Entity *parent)
internal Entity *test_spawn_launcher(Entity *parent) internal Entity *test_spawn_launcher(Entity *parent)
{ {
Entity *e = sim_ent_alloc_sync_src(parent); Entity *e = sim_ent_acquire_sync_src(parent);
e->sprite = S_TagFromPath(Lit("sprite/gun.ase")); e->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
sim_ent_enable_prop(e, SEPROP_ATTACHED); sim_ent_enable_prop(e, SEPROP_ATTACHED);
@ -67,7 +67,7 @@ internal Entity *test_spawn_launcher(Entity *parent)
internal Entity *test_spawn_chucker(Entity *parent) internal Entity *test_spawn_chucker(Entity *parent)
{ {
Entity *chucker = sim_ent_alloc_sync_src(parent); Entity *chucker = sim_ent_acquire_sync_src(parent);
chucker->sprite = S_TagFromPath(Lit("sprite/gun.ase")); chucker->sprite = S_TagFromPath(Lit("sprite/gun.ase"));
sim_ent_enable_prop(chucker, SEPROP_ATTACHED); sim_ent_enable_prop(chucker, SEPROP_ATTACHED);
@ -80,7 +80,7 @@ internal Entity *test_spawn_chucker(Entity *parent)
/* Chucker zone */ /* Chucker zone */
{ {
Entity *zone = sim_ent_alloc_sync_src(chucker); Entity *zone = sim_ent_acquire_sync_src(chucker);
sim_ent_enable_prop(zone, SEPROP_CHUCKER_ZONE); sim_ent_enable_prop(zone, SEPROP_CHUCKER_ZONE);
@ -106,7 +106,7 @@ internal Entity *test_spawn_employee(Entity *parent)
Entity *employee = sim_ent_nil(); Entity *employee = sim_ent_nil();
{ {
Entity *e = sim_ent_alloc_sync_src(parent); Entity *e = sim_ent_acquire_sync_src(parent);
Vec2 pos = VEC2(1, -1); Vec2 pos = VEC2(1, -1);
@ -188,7 +188,7 @@ internal Entity *test_spawn_camera(Entity *parent, Entity *follow)
{ {
Entity *camera_ent = sim_ent_nil(); Entity *camera_ent = sim_ent_nil();
if (follow->valid) { if (follow->valid) {
camera_ent = sim_ent_alloc_sync_src(parent); camera_ent = sim_ent_acquire_sync_src(parent);
sim_ent_set_xform(camera_ent, XformIdentity); sim_ent_set_xform(camera_ent, XformIdentity);
sim_ent_enable_prop(camera_ent, SEPROP_CAMERA); sim_ent_enable_prop(camera_ent, SEPROP_CAMERA);
@ -205,7 +205,7 @@ internal Entity *test_spawn_camera(Entity *parent, Entity *follow)
internal Entity *test_spawn_explosion(Entity *parent, Vec2 pos, f32 strength, f32 radius) internal Entity *test_spawn_explosion(Entity *parent, Vec2 pos, f32 strength, f32 radius)
{ {
Entity *ent = sim_ent_alloc_sync_src(parent); Entity *ent = sim_ent_acquire_sync_src(parent);
sim_ent_set_xform(ent, XformFromPos(pos)); sim_ent_set_xform(ent, XformFromPos(pos));
sim_ent_enable_prop(ent, SEPROP_EXPLOSION); sim_ent_enable_prop(ent, SEPROP_EXPLOSION);
@ -247,8 +247,8 @@ internal void test_spawn_entities2(Entity *parent, Vec2 pos)
/* Small Box */ /* Small Box */
#if 1 #if 1
{ {
//Entity *e = sim_ent_alloc_local(parent); //Entity *e = sim_ent_acquire_local(parent);
Entity *e = sim_ent_alloc_sync_src(parent); Entity *e = sim_ent_acquire_sync_src(parent);
f32 rot = 0; f32 rot = 0;
Vec2 size = VEC2(0.125, 0.125); Vec2 size = VEC2(0.125, 0.125);
@ -290,7 +290,7 @@ internal void test_spawn_entities2(Entity *parent, Vec2 pos)
/* Tiny box */ /* Tiny box */
#if 0 #if 0
{ {
Entity *e = sim_ent_alloc_sync_src(parent); Entity *e = sim_ent_acquire_sync_src(parent);
f32 r = Pi / 4; f32 r = Pi / 4;
Vec2 size = VEC2(0.5, 0.25); Vec2 size = VEC2(0.5, 0.25);
@ -317,8 +317,8 @@ internal void test_spawn_entities3(Entity *parent, Vec2 pos)
/* Heavy box */ /* Heavy box */
{ {
//Entity *e = sim_ent_alloc_local(parent); //Entity *e = sim_ent_acquire_local(parent);
Entity *e = sim_ent_alloc_sync_src(parent); Entity *e = sim_ent_acquire_sync_src(parent);
f32 r = 0; f32 r = 0;
Vec2 size = VEC2(1, 1); Vec2 size = VEC2(1, 1);
@ -341,7 +341,7 @@ internal void test_spawn_entities4(Entity *parent, Vec2 pos)
LAX pos; LAX pos;
/* Light box */ /* Light box */
Entity *e = sim_ent_alloc_sync_src(parent); Entity *e = sim_ent_acquire_sync_src(parent);
f32 r = 0; f32 r = 0;
Vec2 size = VEC2(2, 1); Vec2 size = VEC2(2, 1);
@ -361,7 +361,7 @@ internal void test_spawn_entities4(Entity *parent, Vec2 pos)
internal void test_spawn_tile(Snapshot *world, Vec2 world_pos) internal void test_spawn_tile(Snapshot *world, Vec2 world_pos)
{ {
#if 0 #if 0
Entity *e = sim_ent_alloc_sync_src(parent); Entity *e = sim_ent_acquire_sync_src(parent);
i32 sign_x = (world_pos.x >= 0) - (world_pos.x < 0); i32 sign_x = (world_pos.x >= 0) - (world_pos.x < 0);
i32 sign_y = (world_pos.y >= 0) - (world_pos.y < 0); i32 sign_y = (world_pos.y >= 0) - (world_pos.y < 0);
@ -659,7 +659,7 @@ internal void test_generate_walls(Snapshot *world)
/* Create wall entities */ /* Create wall entities */
for (struct wall_node *node = first_wall; node; node = node->next) { for (struct wall_node *node = first_wall; node; node = node->next) {
Entity *wall_ent = sim_ent_alloc_sync_src(root); Entity *wall_ent = sim_ent_acquire_sync_src(root);
sim_ent_enable_prop(wall_ent, SEPROP_WALL); sim_ent_enable_prop(wall_ent, SEPROP_WALL);
Vec2 start = sim_pos_from_world_tile_index(node->start); Vec2 start = sim_pos_from_world_tile_index(node->start);
@ -747,7 +747,7 @@ internal PHYS_COLLISION_CALLBACK_FUNC_DEF(on_collision, data, step_ctx)
/* TODO: Remove this */ /* TODO: Remove this */
{ {
Xform xf = XformFromTrs(TRS(.t = point, .r = RandF64FromState(&step_ctx->rand, 0, Tau))); Xform xf = XformFromTrs(TRS(.t = point, .r = RandF64FromState(&step_ctx->rand, 0, Tau)));
Entity *decal = sim_ent_alloc_sync_src(root); Entity *decal = sim_ent_acquire_sync_src(root);
decal->sprite = S_TagFromPath(Lit("sprite/blood.ase")); decal->sprite = S_TagFromPath(Lit("sprite/blood.ase"));
decal->sprite_tint = Rgba32F(1, 1, 1, 0.25f); decal->sprite_tint = Rgba32F(1, 1, 1, 0.25f);
decal->layer = SIM_LAYER_FLOOR_DECALS; decal->layer = SIM_LAYER_FLOOR_DECALS;
@ -877,7 +877,7 @@ void sim_step(SimStepCtx *ctx)
/* Create player if necessary */ /* Create player if necessary */
if (is_master && !player->valid) { if (is_master && !player->valid) {
/* FIXME: Player never released upon disconnect */ /* FIXME: Player never released upon disconnect */
player = sim_ent_alloc_sync_src(root); player = sim_ent_acquire_sync_src(root);
player->player_client_handle = client->handle; player->player_client_handle = client->handle;
sim_ent_enable_prop(player, SEPROP_PLAYER); sim_ent_enable_prop(player, SEPROP_PLAYER);
player->predictor = player->id; player->predictor = player->id;
@ -1088,7 +1088,7 @@ void sim_step(SimStepCtx *ctx)
struct sim_data_key msg_key = cmd_ent->cmd_chat_msg; struct sim_data_key msg_key = cmd_ent->cmd_chat_msg;
String msg = sim_data_from_key(sim_data_store, msg_key); String msg = sim_data_from_key(sim_data_store, msg_key);
if (msg.len > 0) { if (msg.len > 0) {
Entity *chat_ent = sim_ent_alloc_sync_src(root); Entity *chat_ent = sim_ent_acquire_sync_src(root);
sim_ent_enable_prop(chat_ent, SEPROP_CHAT); sim_ent_enable_prop(chat_ent, SEPROP_CHAT);
chat_ent->chat_player = player->id; chat_ent->chat_player = player->id;
chat_ent->chat_msg = msg_key; chat_ent->chat_msg = msg_key;
@ -1359,7 +1359,7 @@ void sim_step(SimStepCtx *ctx)
/* Spawn bullet */ /* Spawn bullet */
Entity *bullet; Entity *bullet;
{ {
bullet = sim_ent_alloc_sync_src(root); bullet = sim_ent_acquire_sync_src(root);
sim_ent_enable_prop(bullet, SEPROP_BULLET); sim_ent_enable_prop(bullet, SEPROP_BULLET);
bullet->bullet_src = ent->id; bullet->bullet_src = ent->id;
@ -1382,7 +1382,7 @@ void sim_step(SimStepCtx *ctx)
/* Spawn tracer */ /* Spawn tracer */
{ {
Entity *tracer = sim_ent_alloc_sync_src(root); Entity *tracer = sim_ent_acquire_sync_src(root);
tracer->tracer_fade_duration = 0.025f; tracer->tracer_fade_duration = 0.025f;
tracer->layer = SIM_LAYER_TRACERS; tracer->layer = SIM_LAYER_TRACERS;
sim_ent_enable_prop(tracer, SEPROP_TRACER); sim_ent_enable_prop(tracer, SEPROP_TRACER);
@ -1406,7 +1406,7 @@ void sim_step(SimStepCtx *ctx)
/* Spawn bullet */ /* Spawn bullet */
Entity *bullet; Entity *bullet;
{ {
bullet = sim_ent_alloc_sync_src(root); bullet = sim_ent_acquire_sync_src(root);
sim_ent_enable_prop(bullet, SEPROP_BULLET); sim_ent_enable_prop(bullet, SEPROP_BULLET);
bullet->bullet_src = ent->id; bullet->bullet_src = ent->id;
@ -1428,7 +1428,7 @@ void sim_step(SimStepCtx *ctx)
/* Spawn tracer */ /* Spawn tracer */
{ {
Entity *tracer = sim_ent_alloc_sync_src(root); Entity *tracer = sim_ent_acquire_sync_src(root);
tracer->tracer_fade_duration = 0.025f; tracer->tracer_fade_duration = 0.025f;
tracer->layer = SIM_LAYER_TRACERS; tracer->layer = SIM_LAYER_TRACERS;
sim_ent_enable_prop(tracer, SEPROP_TRACER); sim_ent_enable_prop(tracer, SEPROP_TRACER);
@ -1448,7 +1448,7 @@ void sim_step(SimStepCtx *ctx)
Entity *old_joint_ent = sim_ent_from_id(world, ent->chucker_joint); Entity *old_joint_ent = sim_ent_from_id(world, ent->chucker_joint);
if (sim_ent_is_valid_and_active(target) && zone->chucker_zone_ent_tick == world->tick - 1) { if (sim_ent_is_valid_and_active(target) && zone->chucker_zone_ent_tick == world->tick - 1) {
if (!sim_ent_id_eq(old_joint_ent->weld_joint_data.e1, target->id)) { if (!sim_ent_id_eq(old_joint_ent->weld_joint_data.e1, target->id)) {
Entity *joint_ent = sim_ent_alloc_sync_src(root); Entity *joint_ent = sim_ent_acquire_sync_src(root);
sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE); sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE);
Xform xf0 = sim_ent_get_xform(ent); Xform xf0 = sim_ent_get_xform(ent);
@ -1487,7 +1487,7 @@ void sim_step(SimStepCtx *ctx)
if (sim_ent_has_prop(ent, SEPROP_CONTROLLED)) { if (sim_ent_has_prop(ent, SEPROP_CONTROLLED)) {
Entity *joint_ent = sim_ent_from_id(world, ent->move_joint); Entity *joint_ent = sim_ent_from_id(world, ent->move_joint);
if (is_master && !sim_ent_is_valid_and_active(joint_ent)) { if (is_master && !sim_ent_is_valid_and_active(joint_ent)) {
joint_ent = sim_ent_alloc_sync_src(root); joint_ent = sim_ent_acquire_sync_src(root);
joint_ent->predictor = ent->predictor; joint_ent->predictor = ent->predictor;
joint_ent->mass_unscaled = F32Infinity; joint_ent->mass_unscaled = F32Infinity;
joint_ent->inertia_unscaled = F32Infinity; joint_ent->inertia_unscaled = F32Infinity;
@ -1528,7 +1528,7 @@ void sim_step(SimStepCtx *ctx)
/* Retrieve / create aim joint */ /* Retrieve / create aim joint */
Entity *joint_ent = sim_ent_from_id(world, ent->aim_joint); Entity *joint_ent = sim_ent_from_id(world, ent->aim_joint);
if (is_master && !sim_ent_is_valid_and_active(joint_ent)) { if (is_master && !sim_ent_is_valid_and_active(joint_ent)) {
joint_ent = sim_ent_alloc_sync_src(root); joint_ent = sim_ent_acquire_sync_src(root);
joint_ent->predictor = ent->predictor; joint_ent->predictor = ent->predictor;
joint_ent->mass_unscaled = F32Infinity; joint_ent->mass_unscaled = F32Infinity;
joint_ent->inertia_unscaled = F32Infinity; joint_ent->inertia_unscaled = F32Infinity;
@ -1630,7 +1630,7 @@ void sim_step(SimStepCtx *ctx)
def.max_torque = ent->angular_ground_friction; def.max_torque = ent->angular_ground_friction;
if (joint_ent->motor_joint_data.max_force != def.max_force || joint_ent->motor_joint_data.max_torque != def.max_torque) { if (joint_ent->motor_joint_data.max_force != def.max_force || joint_ent->motor_joint_data.max_torque != def.max_torque) {
if (is_master && !sim_ent_is_valid_and_active(joint_ent)) { if (is_master && !sim_ent_is_valid_and_active(joint_ent)) {
joint_ent = sim_ent_alloc_sync_src(root); joint_ent = sim_ent_acquire_sync_src(root);
joint_ent->predictor = ent->predictor; joint_ent->predictor = ent->predictor;
sim_ent_enable_prop(joint_ent, SEPROP_MOTOR_JOINT); sim_ent_enable_prop(joint_ent, SEPROP_MOTOR_JOINT);
sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE); sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE);
@ -1667,7 +1667,7 @@ void sim_step(SimStepCtx *ctx)
if (sim_ent_should_simulate(target_ent)) { if (sim_ent_should_simulate(target_ent)) {
if (!sim_ent_is_valid_and_active(joint_ent)) { if (!sim_ent_is_valid_and_active(joint_ent)) {
/* FIXME: Joint ent may never release */ /* FIXME: Joint ent may never release */
joint_ent = sim_ent_alloc_local(root); joint_ent = sim_ent_acquire_local(root);
joint_ent->mass_unscaled = F32Infinity; joint_ent->mass_unscaled = F32Infinity;
joint_ent->inertia_unscaled = F32Infinity; joint_ent->inertia_unscaled = F32Infinity;
player->player_dbg_drag_joint_ent = joint_ent->id; player->player_dbg_drag_joint_ent = joint_ent->id;
@ -1794,7 +1794,7 @@ void sim_step(SimStepCtx *ctx)
/* Spawn quake */ /* Spawn quake */
{ {
Entity *quake = sim_ent_alloc_sync_src(root); Entity *quake = sim_ent_acquire_sync_src(root);
sim_ent_set_xform(quake, XformFromPos(pos)); sim_ent_set_xform(quake, XformFromPos(pos));
quake->quake_intensity = 0.2f; quake->quake_intensity = 0.2f;
quake->quake_fade = quake->quake_intensity / 0.1f; quake->quake_fade = quake->quake_intensity / 0.1f;
@ -1915,7 +1915,7 @@ void sim_step(SimStepCtx *ctx)
if (publish_client->valid && world->tick > publish_client->last_tick) { if (publish_client->valid && world->tick > publish_client->last_tick) {
Snapshot *prev_pub_world = sim_snapshot_from_tick(publish_client, publish_client->last_tick); Snapshot *prev_pub_world = sim_snapshot_from_tick(publish_client, publish_client->last_tick);
Snapshot *pub_world = sim_snapshot_alloc(publish_client, prev_pub_world, world->tick); Snapshot *pub_world = sim_snapshot_acquire(publish_client, prev_pub_world, world->tick);
/* Sync */ /* Sync */
sim_snapshot_sync_ents(pub_world, world, world_client->player_id, 0); sim_snapshot_sync_ents(pub_world, world, world_client->player_id, 0);

View File

@ -10,7 +10,7 @@ struct SimAccel {
Space *space; Space *space;
}; };
SimAccel sim_accel_alloc(void); SimAccel sim_accel_acquire(void);
void sim_accel_release(SimAccel *accel); void sim_accel_release(SimAccel *accel);
void sim_accel_reset(Snapshot *ss, SimAccel *accel); void sim_accel_reset(Snapshot *ss, SimAccel *accel);

View File

@ -41,7 +41,7 @@ inline void __prof_zone_cleanup_func(TracyCZoneCtx *ctx) { TracyCZoneEnd(*ctx) }
#define __prof __profnc(0, 0) #define __prof __profnc(0, 0)
#define __profvalue(v) TracyCZoneValue(__tracy_zone_ctx, (v)) #define __profvalue(v) TracyCZoneValue(__tracy_zone_ctx, (v))
#define __profalloc(ptr, size) TracyCAlloc((ptr), (size)) #define __profalloc(ptr, size) TracyCAcquire((ptr), (size))
#define __proffree(ptr) TracyCFree((ptr)) #define __proffree(ptr) TracyCFree((ptr))
#define __profmsg(txt, len, col) TracyCMessageC((txt), (len), Bgr32(col)) #define __profmsg(txt, len, col) TracyCMessageC((txt), (len), Bgr32(col))
#define __profframe(name) TracyCFrameMarkNamed((name)) #define __profframe(name) TracyCFrameMarkNamed((name))
@ -86,7 +86,7 @@ enum __prof_plot_type {
#if ProfilingLocks #if ProfilingLocks
# define __proflock_ctx(name) struct TracyCSharedLockCtx *name # define __proflock_ctx(name) struct TracyCSharedLockCtx *name
# define __proflock_alloc(ctx) TracyCSharedLockAnnounce((ctx)) # define __proflock_acquire(ctx) TracyCSharedLockAnnounce((ctx))
# define __proflock_release(ctx) TracyCSharedLockTerminate((ctx)) # define __proflock_release(ctx) TracyCSharedLockTerminate((ctx))
# define __proflock_before_exclusive_lock(ctx) TracyCSharedLockBeforeExclusiveLock((ctx)) # define __proflock_before_exclusive_lock(ctx) TracyCSharedLockBeforeExclusiveLock((ctx))
# define __proflock_after_exclusive_lock(ctx) TracyCSharedLockAfterExclusiveLock((ctx)) # define __proflock_after_exclusive_lock(ctx) TracyCSharedLockAfterExclusiveLock((ctx))
@ -99,7 +99,7 @@ enum __prof_plot_type {
# define __proflock_mark(ctx) TracyCSharedLockMark((ctx)) # define __proflock_mark(ctx) TracyCSharedLockMark((ctx))
# define __proflock_custom_name(ctx, name, len) TracyCSharedLockCustomName((ctx), (name), (len)) # define __proflock_custom_name(ctx, name, len) TracyCSharedLockCustomName((ctx), (name), (len))
#else #else
# define __proflock_alloc(ctx) # define __proflock_acquire(ctx)
# define __proflock_release(ctx) # define __proflock_release(ctx)
# define __proflock_before_exclusive_lock(ctx) # define __proflock_before_exclusive_lock(ctx)
# define __proflock_after_exclusive_lock(ctx) # define __proflock_after_exclusive_lock(ctx)
@ -118,24 +118,24 @@ enum __prof_plot_type {
inline void __prof_dx11_zone_cleanup_func(TracyCD3D11ZoneCtx *ctx) { ___tracy_d3d11_emit_zone_end(*ctx); } inline void __prof_dx11_zone_cleanup_func(TracyCD3D11ZoneCtx *ctx) { ___tracy_d3d11_emit_zone_end(*ctx); }
# define __profnc_dx11(dx11_ctx, name, color) static const struct ___tracy_source_location_data Cat(__tracy_gpu_d3d11_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, Bgr32(color) }; __attribute((cleanup(__prof_dx11_zone_cleanup_func))) TracyCD3D11ZoneCtx __tracy_d3d11_zone_ctx; ___tracy_d3d11_emit_zone_begin( dx11_ctx, &__tracy_d3d11_zone_ctx, &Cat(__tracy_gpu_d3d11_source_location,__LINE__), 1) # define __profnc_dx11(dx11_ctx, name, color) static const struct ___tracy_source_location_data Cat(__tracy_gpu_d3d11_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, Bgr32(color) }; __attribute((cleanup(__prof_dx11_zone_cleanup_func))) TracyCD3D11ZoneCtx __tracy_d3d11_zone_ctx; ___tracy_d3d11_emit_zone_begin( dx11_ctx, &__tracy_d3d11_zone_ctx, &Cat(__tracy_gpu_d3d11_source_location,__LINE__), 1)
# define __prof_dx11_ctx(name) struct TracyCD3D11Ctx *name # define __prof_dx11_ctx(name) struct TracyCD3D11Ctx *name
# define __prof_dx11_ctx_alloc(ctx, device, device_ctx, name, name_len) ctx = ___tracy_d3d11_context_announce(device, device_ctx, name, name_len) # define __prof_dx11_ctx_acquire(ctx, device, device_ctx, name, name_len) ctx = ___tracy_d3d11_context_announce(device, device_ctx, name, name_len)
# define __prof_dx11_ctx_release(ctx) ___tracy_d3d11_context_terminate(ctx) # define __prof_dx11_ctx_release(ctx) ___tracy_d3d11_context_terminate(ctx)
# define __prof_dx11_collect(ctx) ___tracy_d3d11_context_collect(ctx) # define __prof_dx11_collect(ctx) ___tracy_d3d11_context_collect(ctx)
/* Dx12 */ /* Dx12 */
inline void __prof_dx12_zone_cleanup_func(TracyCD3D12ZoneCtx *ctx) { ___tracy_d3d12_emit_zone_end(*ctx); } inline void __prof_dx12_zone_cleanup_func(TracyCD3D12ZoneCtx *ctx) { ___tracy_d3d12_emit_zone_end(*ctx); }
# define __profnc_dx12(dx12_ctx, cmd_list, name, color) static const struct ___tracy_source_location_data Cat(__tracy_gpu_d3d12_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, Bgr32(color) }; __attribute((cleanup(__prof_dx12_zone_cleanup_func))) TracyCD3D12ZoneCtx __tracy_d3d12_zone_ctx; ___tracy_d3d12_emit_zone_begin( dx12_ctx, cmd_list, &__tracy_d3d12_zone_ctx, &Cat(__tracy_gpu_d3d12_source_location,__LINE__), 1) # define __profnc_dx12(dx12_ctx, cmd_list, name, color) static const struct ___tracy_source_location_data Cat(__tracy_gpu_d3d12_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, Bgr32(color) }; __attribute((cleanup(__prof_dx12_zone_cleanup_func))) TracyCD3D12ZoneCtx __tracy_d3d12_zone_ctx; ___tracy_d3d12_emit_zone_begin( dx12_ctx, cmd_list, &__tracy_d3d12_zone_ctx, &Cat(__tracy_gpu_d3d12_source_location,__LINE__), 1)
# define __prof_dx12_ctx(name) struct TracyCD3D12Ctx *name # define __prof_dx12_ctx(name) struct TracyCD3D12Ctx *name
# define __prof_dx12_ctx_alloc(ctx, device, queue, name, name_len) ctx = ___tracy_d3d12_context_announce(device, queue, name, name_len) # define __prof_dx12_ctx_acquire(ctx, device, queue, name, name_len) ctx = ___tracy_d3d12_context_announce(device, queue, name, name_len)
# define __prof_dx12_ctx_release(ctx) ___tracy_d3d12_context_terminate(ctx) # define __prof_dx12_ctx_release(ctx) ___tracy_d3d12_context_terminate(ctx)
# define __prof_dx12_new_frame(ctx) ___tracy_d3d12_context_new_frame(ctx) # define __prof_dx12_new_frame(ctx) ___tracy_d3d12_context_new_frame(ctx)
# define __prof_dx12_collect(ctx) ___tracy_d3d12_context_collect(ctx) # define __prof_dx12_collect(ctx) ___tracy_d3d12_context_collect(ctx)
#else #else
# define __profnc_dx11(dx11_ctx, name, color) # define __profnc_dx11(dx11_ctx, name, color)
# define __prof_dx11_ctx_alloc(ctx, device, device_ctx, name, name_len) # define __prof_dx11_ctx_acquire(ctx, device, device_ctx, name, name_len)
# define __prof_dx11_ctx_release(ctx) # define __prof_dx11_ctx_release(ctx)
# define __prof_dx11_collect(ctx) # define __prof_dx11_collect(ctx)
# define __profnc_dx12(dx11_ctx, queue, name, color) # define __profnc_dx12(dx11_ctx, queue, name, color)
# define __prof_dx12_ctx_alloc(ctx, device, queue, name, name_len) # define __prof_dx12_ctx_acquire(ctx, device, queue, name, name_len)
# define __prof_dx12_ctx_release(ctx) # define __prof_dx12_ctx_release(ctx)
# define __prof_dx12_new_frame(ctx) # define __prof_dx12_new_frame(ctx)
# define __prof_dx12_collect(ctx) # define __prof_dx12_collect(ctx)

View File

@ -7,7 +7,7 @@ void S_StartupCore(void)
{ {
__prof; __prof;
S_SharedState *g = &S_shared_state; S_SharedState *g = &S_shared_state;
g->perm_arena = AllocArena(Mebi(1)); g->perm_arena = AcquireArena(Mebi(1));
{ {
/* Init loading texture */ /* Init loading texture */
g->loading_texture = PushStruct(g->perm_arena, S_Texture); g->loading_texture = PushStruct(g->perm_arena, S_Texture);
@ -20,7 +20,7 @@ void S_StartupCore(void)
u32 width = 64; u32 width = 64;
u32 height = 64; u32 height = 64;
u32 *pixels = S_GeneratePurpleBlackImage(scratch.arena, width, height); u32 *pixels = S_GeneratePurpleBlackImage(scratch.arena, width, height);
g->nil_texture->gp_texture = GPU_AllocTexture(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(width, height), pixels); g->nil_texture->gp_texture = GPU_AcquireTexture(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM, 0, VEC2I32(width, height), pixels);
EndScratch(scratch); EndScratch(scratch);
} }
@ -37,10 +37,10 @@ void S_StartupCore(void)
} }
SetArenaReadonly(g->perm_arena); SetArenaReadonly(g->perm_arena);
g->cache.arena = AllocArena(Gibi(64)); g->cache.arena = AcquireArena(Gibi(64));
g->cache.bins = PushStructs(g->cache.arena, S_CacheEntryBin, S_CacheBinsCount); g->cache.bins = PushStructs(g->cache.arena, S_CacheEntryBin, S_CacheBinsCount);
g->scopes_arena = AllocArena(Gibi(64)); g->scopes_arena = AcquireArena(Gibi(64));
RunJob(1, S_EvictorJob, JobPool_Background, JobPriority_Low, &g->shutdown_counter, 0); RunJob(1, S_EvictorJob, JobPool_Background, JobPriority_Low, &g->shutdown_counter, 0);
@ -252,7 +252,7 @@ S_Sheet S_SheetFromAseResult(Arena *arena, ASE_DecodedSheet ase)
} }
} }
/* Allocate slice groups & fill originals in 2d array */ /* Acquire slice groups & fill originals in 2d array */
sheet.slice_groups_count = num_temp_slice_group_nodes; sheet.slice_groups_count = num_temp_slice_group_nodes;
sheet.slice_groups = PushStructs(arena, S_SheetSliceGroup, sheet.slice_groups_count); sheet.slice_groups = PushStructs(arena, S_SheetSliceGroup, sheet.slice_groups_count);
sheet.slice_groups_dict = InitDict(arena, (u64)(num_temp_slice_group_nodes * S_SliceLookupTableBinRatio)); sheet.slice_groups_dict = InitDict(arena, (u64)(num_temp_slice_group_nodes * S_SliceLookupTableBinRatio));
@ -470,7 +470,7 @@ void S_LoadCacheEntryTexture(S_CacheEntryRef ref, S_Tag tag)
/* TODO: Replace arena allocs w/ buddy allocator */ /* TODO: Replace arena allocs w/ buddy allocator */
/* TODO: Arena probably overkill. Just using it to store texture struct. */ /* TODO: Arena probably overkill. Just using it to store texture struct. */
e->arena = AllocArena(S_TextureArenaReserve); e->arena = AcquireArena(S_TextureArenaReserve);
u64 memory_size = 0; u64 memory_size = 0;
{ {
/* Decode */ /* Decode */
@ -496,7 +496,7 @@ void S_LoadCacheEntryTexture(S_CacheEntryRef ref, S_Tag tag)
e->texture->height = decoded.height; e->texture->height = decoded.height;
e->texture->valid = 1; e->texture->valid = 1;
e->texture->loaded = 1; e->texture->loaded = 1;
e->texture->gp_texture = GPU_AllocTexture(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB, 0, VEC2I32(decoded.width, decoded.height), decoded.pixels); e->texture->gp_texture = GPU_AcquireTexture(GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB, 0, VEC2I32(decoded.width, decoded.height), decoded.pixels);
/* TODO: Query gpu for more accurate texture size in VRAM */ /* TODO: Query gpu for more accurate texture size in VRAM */
memory_size += (decoded.width * decoded.height) * sizeof(*decoded.pixels); memory_size += (decoded.width * decoded.height) * sizeof(*decoded.pixels);
success = 1; success = 1;
@ -553,7 +553,7 @@ void S_LoadCacheEntrySheet(S_CacheEntryRef ref, S_Tag tag)
Assert(e->kind == S_CacheEntryKind_Sheet); Assert(e->kind == S_CacheEntryKind_Sheet);
/* TODO: Replace arena allocs w/ buddy allocator */ /* TODO: Replace arena allocs w/ buddy allocator */
e->arena = AllocArena(S_SheetArenaReserve); e->arena = AcquireArena(S_SheetArenaReserve);
{ {
/* Decode */ /* Decode */
ASE_DecodedSheet decoded = ZI; ASE_DecodedSheet decoded = ZI;
@ -702,7 +702,7 @@ S_ScopeCacheEntryRef *S_EnsureRefFromRef(S_Scope *scope, S_CacheEntryRef ref)
S_Scope *S_BeginScope(void) S_Scope *S_BeginScope(void)
{ {
S_SharedState *g = &S_shared_state; S_SharedState *g = &S_shared_state;
/* Alloc scope */ /* Acquire scope */
S_Scope *result = 0; S_Scope *result = 0;
S_ScopeCacheEntryRef **bins = 0; S_ScopeCacheEntryRef **bins = 0;
S_ScopeCacheEntryRef *pool = 0; S_ScopeCacheEntryRef *pool = 0;
@ -949,7 +949,7 @@ void *S_DataFromTag(S_Scope *scope, S_Tag tag, S_CacheEntryKind kind, b32 await)
} }
else else
{ {
/* Allocate cmd */ /* Acquire cmd */
S_PushLoadJob(ref, tag); S_PushLoadJob(ref, tag);
} }
} }

View File

@ -128,7 +128,7 @@ Struct(S_CacheEntry)
Atomic32 state; Atomic32 state;
Atomic64Padded refcount_struct; /* Cast fetched result to `cache_refcount` */ Atomic64Padded refcount_struct; /* Cast fetched result to `cache_refcount` */
/* Allocated data */ /* Acquired data */
/* NOTE: This data is finalized once entry state = loaded */ /* NOTE: This data is finalized once entry state = loaded */
i64 load_time_ns; i64 load_time_ns;
u64 memory_usage; u64 memory_usage;

View File

@ -139,10 +139,10 @@ TTF_Result TTF_Decode(Arena *arena, String encoded, f32 point_size, u32 *cache_c
} }
//- Setup atlas //- Setup atlas
/* Allocate font memory */ /* Acquire font memory */
TTF_Glyph *glyphs = (TTF_Glyph *)PushStructs(arena, TTF_Glyph, glyph_count); TTF_Glyph *glyphs = (TTF_Glyph *)PushStructs(arena, TTF_Glyph, glyph_count);
/* Allocate (starting) atlas memory /* Acquire (starting) atlas memory
* NOTE: This is unecessary since atlas memory will grow anyway. Could * NOTE: This is unecessary since atlas memory will grow anyway. Could
* just start w/ atlas height 0. * just start w/ atlas height 0.
*/ */

View File

@ -6,9 +6,9 @@ W_SharedState W_shared_state = ZI;
void W_StartupCore(void) void W_StartupCore(void)
{ {
W_SharedState *g = &W_shared_state; W_SharedState *g = &W_shared_state;
g->watch = P_AllocWatch(Lit("./")); g->watch = P_AcquireWatch(Lit("./"));
g->watch_events_arena = AllocArena(Gibi(64)); g->watch_events_arena = AcquireArena(Gibi(64));
RunJob(1, W_MonitorJob, JobPool_Floating, JobPriority_Low, &g->watch_jobs_counter, 0); RunJob(1, W_MonitorJob, JobPool_Floating, JobPriority_Low, &g->watch_jobs_counter, 0);
RunJob(1, W_DispatcherJob, JobPool_Floating, JobPriority_Low, &g->watch_jobs_counter, 0); RunJob(1, W_DispatcherJob, JobPool_Floating, JobPriority_Low, &g->watch_jobs_counter, 0);