vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: a8b1076b26fee0d81383908dabbffedab42fe068
Parent: e6e87c06a0103378165dc3fd65c7a9e16d9412ad
Author: Randy Palamar
Date:   Sun, 17 Nov 2024 20:17:19 -0700

tidy up some debug code paths

there is no need to call debug stuff from the platform layer nor
is there a need for so many debug_begin/debug_end etc. This
restores the ability for all debug code to be removed from the
release build including the stubs.

Diffstat:
Mdebug.c | 29++++++++++++++++++++++++++---
Mdebug.h | 23++++++++---------------
Mplatform_linux_x11.c | 11-----------
Mtest.c | 28++--------------------------
Mvtgl.c | 33+++++----------------------------
5 files changed, 41 insertions(+), 83 deletions(-)

diff --git a/debug.c b/debug.c @@ -142,7 +142,7 @@ coalesce_debug_events(DebugState *ds, u32 invalid_snapshot_index) DebugEvent *oe = odb->opening_event; if (oe->metadata_index != de->metadata_index) { /* TODO: the first block was never closed */ - INVALID_CODE_PATH; + //INVALID_CODE_PATH; break; } @@ -369,6 +369,8 @@ draw_debug_overlay(TerminalMemory *term_memory, TerminalInput *input, RenderCtx r.pos.y = txt_pos.y - 2 * line_pad; r.size.h = ws.h - r.pos.y; + flush_render_push_buffer(rc); + END_TIMED_BLOCK(); } @@ -385,10 +387,31 @@ debug_init(TerminalMemory *memory) restart_collation(ds, g_debug_table.snapshot_index); } -DEBUG_EXPORT DEBUG_BEGIN_FRAME_FN(debug_begin_frame) +static void +debug_frame_end(TerminalMemory *memory, TerminalInput *input, RenderCtx *rc) { DebugState *debug_state = memory->debug_memory; if (!debug_state->initialized) debug_init(memory); - FRAME_MARK(wall_clock_elapsed); + + draw_debug_overlay(memory, input, rc); + + g_debug_table.snapshot_index++; + if (g_debug_table.snapshot_index == MAX_DEBUG_RECORD_COUNT) + g_debug_table.snapshot_index = 0; + u64 event_array_event_index = __atomic_exchange_n(&g_debug_table.event_array_event_index, + (u64)g_debug_table.snapshot_index << 32, + __ATOMIC_ACQUIRE); + + u32 array_index = event_array_event_index >> 32; + u32 event_count = event_array_event_index & 0xFFFFFFFF; + + g_debug_table.events_count[array_index] = event_count; + g_debug_table.metadata_count = __COUNTER__; + + if (!debug_state->paused) { + if (debug_state->record_count >= 2*MAX_DEBUG_RECORD_COUNT) + restart_collation(debug_state, g_debug_table.snapshot_index); + coalesce_debug_events(debug_state, g_debug_table.snapshot_index); + } } diff --git a/debug.h b/debug.h @@ -70,31 +70,21 @@ typedef struct { OpenDebugBlock *first_free_block; } DebugState; -/* TODO: this can probably be removed */ -typedef struct TerminalMemory TerminalMemory; - -#define DEBUG_BEGIN_FRAME_FN(name) void name(TerminalMemory *memory, f32 wall_clock_elapsed) -typedef DEBUG_BEGIN_FRAME_FN(debug_begin_frame_fn); - -#define DEBUG_END_FRAME_FN(name) void name(TerminalMemory *memory) -typedef DEBUG_END_FRAME_FN(debug_end_frame_fn); - #define INVALID_CODE_PATH ASSERT(0) #ifndef _DEBUG #define ASSERT(c) do { (void)(c); } while(0) #define DEBUG_EXPORT static +#define FRAME_MARK(...) + #define BEGIN_TIMED_BLOCK(...) #define END_TIMED_BLOCK(...) #define BEGIN_NAMED_BLOCK(...) #define END_NAMED_BLOCK(...) -#define draw_debug_overlay(...) - -DEBUG_BEGIN_FRAME_FN(debug_begin_frame) {} -DEBUG_END_FRAME_FN(debug_end_frame) {} +#define debug_frame_end(...) #else @@ -156,9 +146,12 @@ static DebugTable g_debug_table; RECORD_DEBUG_META_COMMON(__counter_##name, #name) #define END_NAMED_BLOCK(name) RECORD_DEBUG_EVENT(__counter_##name, DE_END) +typedef struct RenderCtx RenderCtx; +typedef struct TerminalMemory TerminalMemory; typedef struct TerminalInput TerminalInput; typedef struct Term Term; -typedef struct RenderCtx RenderCtx; + static void dump_lines_to_file(Term *t); -static void draw_debug_overlay(TerminalMemory *memory, TerminalInput *input, RenderCtx *rc); +static void debug_frame_end(TerminalMemory *memory, TerminalInput *input, RenderCtx *rc); + #endif diff --git a/platform_linux_x11.c b/platform_linux_x11.c @@ -61,8 +61,6 @@ static PlatformCtx linux_ctx; #define DEBUG_LIB_NAME "./vtgl.so" #define LIB_FNS \ - X(debug_begin_frame) \ - X(debug_end_frame) \ X(vtgl_active_selection) \ X(vtgl_initialize) \ X(vtgl_handle_keys) \ @@ -560,8 +558,6 @@ main(i32 argc, char *argv[], char *envp[]) linux_ctx.input.dt = current_time - last_time; last_time = current_time; - debug_begin_frame(&linux_ctx.memory, linux_ctx.input.dt); - vtgl_frame_step(&linux_ctx.memory, &linux_ctx.input); Range current_sel = vtgl_active_selection(&linux_ctx.memory, 0); @@ -574,15 +570,8 @@ main(i32 argc, char *argv[], char *envp[]) last_sel = current_sel; } - debug_end_frame(&linux_ctx.memory); - glfwSwapBuffers(linux_ctx.window); } return 0; } - -#ifdef _DEBUG -/* NOTE: shut up compiler warning that can't be disabled */ -DebugMetadata debug_metadata[__COUNTER__]; -#endif diff --git a/test.c b/test.c @@ -1,27 +1,9 @@ -#define GLFW_PRESS 1 -#define GLFW_REPEAT 2 - -#define GLFW_MOD_SHIFT 0x0001 -#define GLFW_MOD_CONTROL 0x0002 -#define GLFW_MOD_ALT 0x0004 - -#define GLFW_KEY_C 67 -#define GLFW_KEY_J 74 -#define GLFW_KEY_K 75 -#define GLFW_KEY_V 86 -#define GLFW_KEY_PAGE_UP 266 -#define GLFW_KEY_PAGE_DOWN 267 - -#define GLFWwindow void - +/* See LICENSE for copyright details */ #include "util.h" #include "config.h" /* NOTE: stubs for stuff we aren't testing */ static void get_gpu_glyph_index(Arena, void *, void *, u32, u32, u32, CachedGlyph **); -static GlyphCacheStats get_and_clear_glyph_cache_stats(void *p) { return (GlyphCacheStats){0}; } -static void init_font(void *a, void *b) {} -static void push_char(RenderPushBuffer *r, GLCtx *g, v2 vs, v2 vo, v2 ts, uv2 co, i32 ci) {} KEYBIND_FN(copy) { return 0; } KEYBIND_FN(paste) { return 0; } @@ -345,18 +327,12 @@ static TEST_FN(working_ringbuffer) return result; } -static u32 failure_count; - -#ifdef _DEBUG -/* NOTE: shut up compiler warning that can't be disabled */ -DebugMetadata debug_metadata[__COUNTER__]; -#endif - int main(void) { Arena memory = arena_from_memory_block(posix_alloc(32 * MEGABYTE)); Term term = {0}; + u32 failure_count = 0; Stream log = stream_alloc(&memory, 4 * MEGABYTE); for (u32 i = 0; i < ARRAY_COUNT(term.saved_cursors); i++) { diff --git a/vtgl.c b/vtgl.c @@ -1241,6 +1241,8 @@ DEBUG_EXPORT VTGL_ACTIVE_SELECTION_FN(vtgl_active_selection) DEBUG_EXPORT VTGL_FRAME_STEP_FN(vtgl_frame_step) { + FRAME_MARK(input->dt); + BEGIN_TIMED_BLOCK(); Term *t = memory->memory; @@ -1363,10 +1365,10 @@ DEBUG_EXPORT VTGL_FRAME_STEP_FN(vtgl_frame_step) /* NOTE: this happens at the end so that ui stuff doesn't go through the post * processing/effects shader */ - BEGIN_NAMED_BLOCK(debug_overlay); glUseProgram(t->gl.programs[SHADER_RECTS]); - draw_debug_overlay(memory, input, &rc); - flush_render_push_buffer(&rc); + + BEGIN_NAMED_BLOCK(debug_overlay); + debug_frame_end(memory, input, &rc); END_NAMED_BLOCK(debug_overlay); end_temp_arena(t->temp_arena); @@ -1376,29 +1378,4 @@ DEBUG_EXPORT VTGL_FRAME_STEP_FN(vtgl_frame_step) #ifdef _DEBUG #include "debug.c" - -DEBUG_EXPORT DEBUG_END_FRAME_FN(debug_end_frame) -{ - DebugState *debug_state = memory->debug_memory; - - g_debug_table.snapshot_index++; - if (g_debug_table.snapshot_index == MAX_DEBUG_RECORD_COUNT) - g_debug_table.snapshot_index = 0; - u64 event_array_event_index = __atomic_exchange_n(&g_debug_table.event_array_event_index, - (u64)g_debug_table.snapshot_index << 32, - __ATOMIC_ACQUIRE); - - u32 array_index = event_array_event_index >> 32; - u32 event_count = event_array_event_index & 0xFFFFFFFF; - - g_debug_table.events_count[array_index] = event_count; - g_debug_table.metadata_count = __COUNTER__; - - if (!debug_state->paused) { - if (debug_state->record_count >= 2*MAX_DEBUG_RECORD_COUNT) - restart_collation(debug_state, g_debug_table.snapshot_index); - coalesce_debug_events(debug_state, g_debug_table.snapshot_index); - } -} - #endif