start implementing async system

This commit is contained in:
jacob 2025-12-12 12:37:47 -06:00
parent e9e8dcc04d
commit ac8a4cf6c2
8 changed files with 124 additions and 14 deletions

22
src/base/base_async.c Normal file
View File

@ -0,0 +1,22 @@
////////////////////////////////////////////////////////////
//~ Bootstrap
void BootstrapAsync(void)
{
/* TODO: Dynamic lane counts */
DispatchWave(Lit("Async"), 4, AsyncEntryPoint, 0);
}
////////////////////////////////////////////////////////////
//~ Async ops
void OnAsyncTick(AsyncFunc *func)
{
}
////////////////////////////////////////////////////////////
//~ Async worker
void AsyncEntryPoint(WaveLaneCtx *lane)
{
}

19
src/base/base_async.h Normal file
View File

@ -0,0 +1,19 @@
////////////////////////////////////////////////////////////
//~ Async types
typedef void AsyncFunc(WaveLaneCtx *lane);
////////////////////////////////////////////////////////////
//~ Bootstrap
void BootstrapAsync(void);
////////////////////////////////////////////////////////////
//~ Async ops
void OnAsyncTick(AsyncFunc *func);
////////////////////////////////////////////////////////////
//~ Async worker
void AsyncEntryPoint(WaveLaneCtx *lane);

View File

@ -25,6 +25,7 @@
# include "base_bitbuff.h"
# include "base_resource.h"
# include "base_controller.h"
# include "base_async.h"
#elif IsLanguageG
# include "base_shader.gh"
#endif
@ -46,6 +47,7 @@
# include "base_bitbuff.c"
# include "base_resource.c"
# include "base_controller.c"
# include "base_async.c"
#endif
//- Include base_win32

View File

@ -320,6 +320,9 @@ i32 W32_Main(void)
BootstrapResources(ctx.embedded_strings_count, ctx.embedded_strings);
}
/* Bootstrap async */
BootstrapAsync();
/* Bootstrap layers */
if (!Atomic32Fetch(&g->panicking))
{

View File

@ -5,7 +5,7 @@ GC_State GC = ZI;
void GC_BootStrap(void)
{
// OnAsync(GC_AsyncTick);
OnAsyncTick(GC_AsyncTick);
}
////////////////////////////////////////////////////////////
@ -79,6 +79,10 @@ GC_Run GC_RunFromString(Arena *arena, String str, GC_FontKey font, f32 font_size
}
}
if (uncached_codepoints.len > 0)
{
}
f32 baseline_pos = 0;
result.rects = PushStructs(arena, GC_RunRect, ready_glyphs_count);
result.rects_count = ready_glyphs_count;
@ -130,6 +134,22 @@ GC_Run GC_RunFromString(Arena *arena, String str, GC_FontKey font, f32 font_size
void GC_AsyncTick(WaveLaneCtx *lane)
{
TempArena scratch = BeginScratchNoConflict();
GC_WorkerState *w = &GC.worker_state;
/* Flatten cmds */
// if (lane->idx == 0)
// {
// Lock lock = LockE();
// {
// }
// Unlock(&lock);
// }
WaveSync(lane);
EndScratch(scratch);
}

View File

@ -9,13 +9,6 @@ Struct(GC_FontKey)
////////////////////////////////////////////////////////////
//~ Glyph types
Struct(GC_GlyphDesc)
{
GC_FontKey font;
f32 font_size;
u32 codepoint;
};
Struct(GC_Glyph)
{
GC_Glyph *next;
@ -42,6 +35,20 @@ Struct(GC_GlyphBin)
GC_Glyph *first;
};
Struct(GC_GlyphDesc)
{
GC_FontKey font;
f32 font_size;
u32 codepoint;
};
// Struct(GC_GlyphDescChunk)
// {
// GC_GlyphDescChunk *next;
// u64 descs_count;
// GC_GlyphDesc *descs;
// };
////////////////////////////////////////////////////////////
//~ Run types
@ -73,13 +80,48 @@ Struct(GC_Run)
b32 ready;
};
////////////////////////////////////////////////////////////
//~ Cmd types
// Enum(GC_CmdKind)
// {
// GC_CmdKind_None,
// GC_CmdKind_LoadGlyphs
// };
Struct(GC_Cmd)
{
GC_Glyph *glyph;
};
Struct(GC_CmdChunk)
{
GC_CmdChunk *next;
u64 cmds_count;
GC_Cmd *cmds;
};
////////////////////////////////////////////////////////////
//~ State
Struct(GC_WorkerState)
{
u64 cmds_count;
GC_Cmd *cmds;
};
Struct(GC_State)
{
Mutex glyphs_mutex;
GC_GlyphBin glyph_bins[16384];
Mutex submitted_cmds_mutex;
u64 submitted_cmds_count;
GC_CmdChunk *first_submitted_cmd_chunk;
GC_CmdChunk *last_submitted_cmd_chunk;
GC_WorkerState worker_state;
} extern GC;
////////////////////////////////////////////////////////////

View File

@ -332,7 +332,7 @@ void G_Bootstrap(void)
// DispatchWave(name, 1, G_D12_WorkerEntry, (void *)(u64)kind);
// }
DispatchWave(Lit("Gpu collection worker"), 1, G_D12_CollectionWorkerEntry, 0);
DispatchWave(Lit("Gpu collection worker"), 1, G_D12_CollectionWorkerEntryPoint, 0);
EndScratch(scratch);
}
@ -1070,6 +1070,8 @@ G_ResourceHandle G_PushTextureEx(G_ArenaHandle arena_handle, G_TextureResourceDe
d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS * AnyBit(desc.flags, G_ResourceFlag_AllowShaderReadWrite);
d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET * AnyBit(desc.flags, G_ResourceFlag_AllowRenderTarget);
d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL * AnyBit(desc.flags, G_ResourceFlag_AllowDepthStencil);
d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS * (desc.initial_layout == G_Layout_Simultaneous);
u64 alloc_size = 0;
u64 alloc_align = 0;
@ -2842,7 +2844,7 @@ void G_CommitBackbuffer(G_ResourceHandle backbuffer_handle, i32 vsync)
/* TODO: Move this to common */
void G_D12_CollectionWorkerEntry(WaveLaneCtx *lane)
void G_D12_CollectionWorkerEntryPoint(WaveLaneCtx *lane)
{
for (;;)
{

View File

@ -472,4 +472,4 @@ G_D12_StagingRegionNode *G_D12_PushStagingRegion(G_D12_CmdList *cl, u64 size);
////////////////////////////////////////////////////////////
//~ Collection worker
void G_D12_CollectionWorkerEntry(WaveLaneCtx *lane);
void G_D12_CollectionWorkerEntryPoint(WaveLaneCtx *lane);