From e6f73232f1b16af430e850646215d2c9e07dde2e Mon Sep 17 00:00:00 2001 From: hgn Date: Mon, 24 Apr 2023 13:00:24 +0100 Subject: [PATCH] simplify --- vg.h | 7 ++----- vg_async.h | 15 +++++++++++++++ vg_audio_dsp.h | 3 +-- vg_input.h | 3 +-- vg_lines.h | 3 +-- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/vg.h b/vg.h index 9ad04b1..d98828e 100644 --- a/vg.h +++ b/vg.h @@ -282,9 +282,7 @@ VG_STATIC void async_vg_bake_shaders( void *payload, u32 size ) VG_STATIC void vg_bake_shaders(void) { vg_console_reg_cmd( "reload_shaders", vg_shaders_live_recompile, NULL ); - - vg_async_item *call = vg_async_alloc(0); - vg_async_dispatch( call, async_vg_bake_shaders ); + vg_async_call( async_vg_bake_shaders, NULL, 0 ); } void async_internal_complete( void *payload, u32 size ) @@ -313,8 +311,7 @@ VG_STATIC void _vg_load_full(void) vg_loader_step( vg_audio_init, vg_audio_free ); vg_loader_step( vg_profiler_init, NULL ); - vg_async_item *test_async = vg_async_alloc( 0 ); - vg_async_dispatch( test_async, async_internal_complete ); + vg_async_call( async_internal_complete, NULL, 0 ); /* client */ vg_load(); diff --git a/vg_async.h b/vg_async.h index 190b5a8..fd65c0d 100644 --- a/vg_async.h +++ b/vg_async.h @@ -98,6 +98,9 @@ VG_STATIC vg_async_item *vg_async_alloc( u32 size ) return entry; } +/* + * Wait until the current stack of async calls is completely flushed out + */ VG_STATIC void vg_async_stall(void) { vg_info( "async_stall: %d\n", SDL_SemValue( vg_async.sem_wait_for_flush ) ); @@ -118,6 +121,18 @@ VG_STATIC void vg_async_dispatch( vg_async_item *item, SDL_AtomicUnlock( &vg_async.sl_index ); } +/* + * Make a simple async call without allocating extra. + */ +VG_STATIC void vg_async_call( void (*runner)( void *payload, u32 size ), + void *payload, u32 size ) +{ + vg_async_item *call = vg_async_alloc(0); + call->payload = payload; + call->size = size; + vg_async_dispatch( call, runner ); +} + /* * Run as much of the async buffer as possible */ diff --git a/vg_audio_dsp.h b/vg_audio_dsp.h index e6a953e..c973cc9 100644 --- a/vg_audio_dsp.h +++ b/vg_audio_dsp.h @@ -154,8 +154,7 @@ static void vg_dsp_init( void ) vg_dsp.buffer = vg_linear_alloc( vg_mem.rtmemory, 1024*1024*1 ); vg_dsp.view_texture_buffer = vg_linear_alloc( vg_mem.rtmemory, 512*512 ); - vg_async_item *call = vg_async_alloc(0); - vg_async_dispatch( call, async_vg_dsp_alloc_texture ); + vg_async_call( async_vg_dsp_alloc_texture, NULL, 0 ); /* temporary global design */ dsp_init_lpf( &__lpf_mud_free, 125.0f ); diff --git a/vg_input.h b/vg_input.h index 778d6f0..02c271a 100644 --- a/vg_input.h +++ b/vg_input.h @@ -589,8 +589,7 @@ VG_STATIC void async_vg_input_init( void *payload, u32 size ) VG_STATIC void vg_input_init(void) { - vg_async_item *call = vg_async_alloc(0); - vg_async_dispatch( call, async_vg_input_init ); + vg_async_call( async_vg_input_init, NULL, 0 ); } VG_STATIC void vg_input_free(void) diff --git a/vg_lines.h b/vg_lines.h index 84e9632..58818f2 100644 --- a/vg_lines.h +++ b/vg_lines.h @@ -113,8 +113,7 @@ VG_STATIC void async_vg_lines_init( void *payload, u32 payload_size ) VG_STATIC void vg_lines_init(void) { - vg_async_item *call = vg_async_alloc(0); - vg_async_dispatch( call, async_vg_lines_init ); + vg_async_call( async_vg_lines_init, NULL, 0 ); vg_console_reg_var( "vg_lines", &vg_lines.draw, k_var_dtype_i32, VG_VAR_CHEAT ); -- 2.25.1