From 3601b23a521f38f3311fde52e94a3a70a150df9d Mon Sep 17 00:00:00 2001 From: hgn Date: Wed, 4 Sep 2024 20:53:51 +0100 Subject: [PATCH] memory info --- vg_engine.c | 7 +++++++ vg_m.h | 13 +++++++++++-- vg_mem.c | 27 ++++++++++++++++++++++++--- vg_mem.h | 2 +- vg_render.c | 4 +--- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/vg_engine.c b/vg_engine.c index ed016be..ddcda8f 100644 --- a/vg_engine.c +++ b/vg_engine.c @@ -739,6 +739,12 @@ static void _vg_terminate(void) exit(0); } +static int cmd_log_memory( int argc, const char *argv[] ) +{ + vg_mem_log( vg_mem.rtmemory, 0, "rtmemory" ); + return 0; +} + static int cmd_vg_settings_toggle( int argc, const char *argv[] ); void vg_enter( int argc, char *argv[], const char *window_name ) { @@ -762,6 +768,7 @@ void vg_enter( int argc, char *argv[], const char *window_name ) vg_console_load_autos(); vg_console_reg_cmd( "vg_settings", cmd_vg_settings_toggle, NULL ); + vg_console_reg_cmd( "vg_rtmemory", cmd_log_memory, NULL ); _vg_init_window( window_name ); vg_async_init(); diff --git a/vg_m.h b/vg_m.h index 4af60c8..dae258c 100644 --- a/vg_m.h +++ b/vg_m.h @@ -1567,6 +1567,16 @@ static inline int box_overlap( boxf a, boxf b ) ; } +static int box_within_pt( boxf box, v3f pt ) +{ + if( (pt[0] >= box[0][0]) && (pt[1] >= box[0][1]) && (pt[2] >= box[0][2]) && + (pt[0] <= box[1][0]) && (pt[1] <= box[1][1]) && (pt[2] <= box[1][2]) ) + { + return 1; + } + else return 0; +} + static int box_within( boxf greater, boxf lesser ) { v3f a, b; @@ -1578,8 +1588,7 @@ static int box_within( boxf greater, boxf lesser ) { return 1; } - - return 0; + else return 0; } static inline void box_init_inf( boxf box ){ diff --git a/vg_mem.c b/vg_mem.c index 8fa1057..863b2a5 100644 --- a/vg_mem.c +++ b/vg_mem.c @@ -49,8 +49,14 @@ void *_vg_linear_alloc( void *buffer, u32 size, const char *constr_name ) } if( alloc->flags & VG_MEMORY_SYSTEM ) + { if( (alloc->allocation_count + 1) > VG_MAX_ALLOCATIONS ) + { + vg_error( "Alloc (%p) allocation count is at the limit of" + " %u allocations.\n", alloc, VG_MAX_ALLOCATIONS ); vg_fatal_error( "Max linear allocations reached" ); + } + } void *data; @@ -109,6 +115,7 @@ void *vg_linear_resize( void *buffer, void *data, u32 newsize ) vg_fatal_error( "realloc failed" ); alloc->alloc_table[ alloc->allocation_count-1 ].data = data; + alloc->alloc_table[ alloc->allocation_count-1 ].size = newsize; alloc->last_alloc = data; return data; } @@ -308,16 +315,29 @@ void vg_alloc_quota(void) "Scratch buffer" ); } +static void vg_mem_print_size( u32 bytes, char buf[32] ) +{ + if( bytes > 1024*1024 ) + snprintf( buf, 32, "%umb", bytes/(1024*1024) ); + else if( bytes > 1024 ) + snprintf( buf, 32, "%ukb", bytes/1024 ); + else + snprintf( buf, 32, "%ub", bytes ); +} + void vg_mem_log( void *lin_alloc, int depth, const char *name ) { if( vg_mem.use_libc_malloc ){ vg_linear_allocator *alloc = vg_linear_header( lin_alloc ); u32 s = alloc->size; - f32 p = ((float)alloc->cur / (float)alloc->size) * 100.0f; + f32 p = ((float)alloc->cur / (float)s) * 100.0f; for( int i=0; iflags & VG_MEMORY_SYSTEM ){ for( u32 i=0; iallocation_count; i++ ){ @@ -325,7 +345,8 @@ void vg_mem_log( void *lin_alloc, int depth, const char *name ) if( meta->type == k_allocation_type_block ){ for( int i=0; iname, meta->size ); + vg_mem_print_size( meta->size, asize ); + printf( "B(%s): %s\n", meta->name, asize ); } else{ vg_mem_log( meta->data, depth +1, meta->name ); diff --git a/vg_mem.h b/vg_mem.h index 6fde883..94042a9 100644 --- a/vg_mem.h +++ b/vg_mem.h @@ -1,6 +1,6 @@ #pragma once -#define VG_MAX_ALLOCATIONS 128 +#define VG_MAX_ALLOCATIONS 256 typedef struct vg_linear_allocator vg_linear_allocator; typedef struct vg_allocation_meta vg_allocation_meta; diff --git a/vg_render.c b/vg_render.c index 3274721..a1fc499 100644 --- a/vg_render.c +++ b/vg_render.c @@ -143,10 +143,8 @@ void vg_postprocess_to_screen( vg_framebuffer *fb ) glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glViewport( 0,0, vg.window_x, vg.window_y ); - glEnable(GL_BLEND); + glDisable(GL_BLEND); glDisable(GL_DEPTH_TEST); - glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA); - glBlendEquation(GL_FUNC_ADD); v2f inverse; vg_framebuffer_inverse_ratio( fb, inverse ); -- 2.25.1