diff --git a/src/base/base_async.c b/src/base/base_async.c new file mode 100644 index 00000000..46cbe09a --- /dev/null +++ b/src/base/base_async.c @@ -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) +{ +} diff --git a/src/base/base_async.h b/src/base/base_async.h new file mode 100644 index 00000000..f6d60553 --- /dev/null +++ b/src/base/base_async.h @@ -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); diff --git a/src/base/base_inc.h b/src/base/base_inc.h index f8cc1737..21e78bdd 100644 --- a/src/base/base_inc.h +++ b/src/base/base_inc.h @@ -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 diff --git a/src/base/base_win32/base_win32.c b/src/base/base_win32/base_win32.c index cd8d5c20..514b3309 100644 --- a/src/base/base_win32/base_win32.c +++ b/src/base/base_win32/base_win32.c @@ -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)) { diff --git a/src/glyph_cache/glyph_cache.c b/src/glyph_cache/glyph_cache.c index 1f0294ad..8ba0d2a5 100644 --- a/src/glyph_cache/glyph_cache.c +++ b/src/glyph_cache/glyph_cache.c @@ -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); } diff --git a/src/glyph_cache/glyph_cache.h b/src/glyph_cache/glyph_cache.h index 37744432..af15e15d 100644 --- a/src/glyph_cache/glyph_cache.h +++ b/src/glyph_cache/glyph_cache.h @@ -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; //////////////////////////////////////////////////////////// diff --git a/src/gpu/gpu_dx12/gpu_dx12_core.c b/src/gpu/gpu_dx12/gpu_dx12_core.c index 015c232d..1c1ae1d6 100644 --- a/src/gpu/gpu_dx12/gpu_dx12_core.c +++ b/src/gpu/gpu_dx12/gpu_dx12_core.c @@ -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); } @@ -1067,9 +1067,11 @@ G_ResourceHandle G_PushTextureEx(G_ArenaHandle arena_handle, G_TextureResourceDe d3d_desc.MipLevels = MaxI32(desc.mip_levels, 1); d3d_desc.SampleDesc.Count = 1; d3d_desc.SampleDesc.Quality = 0; - 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_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 (;;) { diff --git a/src/gpu/gpu_dx12/gpu_dx12_core.h b/src/gpu/gpu_dx12/gpu_dx12_core.h index c96b55cb..ea5198f3 100644 --- a/src/gpu/gpu_dx12/gpu_dx12_core.h +++ b/src/gpu/gpu_dx12/gpu_dx12_core.h @@ -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);