From 65ada18d1d195c19b0a427c45873ac8995e752cb Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 8 Nov 2024 14:25:11 -0800 Subject: [PATCH] fix render layer guid linking w/out font provider layer; eliminate generation number on render handles; sketch out tester scratch program for text drawing performance --- build.bat | 1 + project.4coder | 10 ++-- src/base/base_core.h | 6 +++ src/draw/draw.c | 2 + src/draw/draw.h | 2 +- src/raddbg/raddbg_core.c | 2 +- src/raddbg/raddbg_views.c | 4 +- src/raddbg/raddbg_widgets.c | 2 +- src/render/d3d11/render_d3d11.c | 9 ++-- src/render/d3d11/render_d3d11.h | 3 ++ src/render/render_core.h | 6 +-- src/scratch/textperf.c | 84 +++++++++++++++++++++++++++++++++ src/ui/ui_core.c | 2 +- 13 files changed, 113 insertions(+), 20 deletions(-) create mode 100644 src/scratch/textperf.c diff --git a/build.bat b/build.bat index 446e23a2..8a8ea71f 100644 --- a/build.bat +++ b/build.bat @@ -109,6 +109,7 @@ if "%rdi_dump%"=="1" set didbuild=1 && %compile% ..\src\rdi_du if "%rdi_breakpad_from_pdb%"=="1" set didbuild=1 && %compile% ..\src\rdi_breakpad_from_pdb\rdi_breakpad_from_pdb_main.c %compile_link% %out%rdi_breakpad_from_pdb.exe || exit /b 1 if "%tester%"=="1" set didbuild=1 && %compile% ..\src\tester\tester_main.c %compile_link% %out%tester.exe || exit /b 1 if "%ryan_scratch%"=="1" set didbuild=1 && %compile% ..\src\scratch\ryan_scratch.c %compile_link% %out%ryan_scratch.exe || exit /b 1 +if "%textperf%"=="1" set didbuild=1 && %compile% ..\src\scratch\textperf.c %compile_link% %out%textperf.exe || exit /b 1 if "%parse_inline_sites%"=="1" set didbuild=1 && %compile% ..\src\scratch\parse_inline_sites.c %compile_link% %out%parse_inline_sites.exe || exit /b 1 if "%mule_main%"=="1" set didbuild=1 && del vc*.pdb mule*.pdb && %compile_release% %only_compile% ..\src\mule\mule_inline.cpp && %compile_release% %only_compile% ..\src\mule\mule_o2.cpp && %compile_debug% %EHsc% ..\src\mule\mule_main.cpp ..\src\mule\mule_c.c mule_inline.obj mule_o2.obj %compile_link% %no_aslr% %out%mule_main.exe || exit /b 1 if "%mule_module%"=="1" set didbuild=1 && %compile% ..\src\mule\mule_module.cpp %compile_link% %link_dll% %out%mule_module.dll || exit /b 1 diff --git a/project.4coder b/project.4coder index 6b9ca8f1..0be9237b 100644 --- a/project.4coder +++ b/project.4coder @@ -46,11 +46,11 @@ load_paths = commands = { //- rjf: fkey command slots (change locally but do not commit) - // .f1 = { .win = "build raddbg telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, - // .f2 = { .win = "build rdi_from_pdb", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, - // .f3 = { .win = "pushd build && raddbg.exe --user:local_dev.raddbg_user --project:local_dev.raddbg_project --xuto_run && popd",.linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, - .f1 = { .win = "build ryan_scratch release telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, - .f3 = { .win = "pushd build && ryan_scratch.exe --capture && popd",.linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, + .f1 = { .win = "build raddbg telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, + .f2 = { .win = "build rdi_from_pdb", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, + .f3 = { .win = "pushd build && raddbg.exe --user:local_dev.raddbg_user --project:local_dev.raddbg_project --xuto_run && popd",.linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, + // .f1 = { .win = "build textperf release telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, + // .f3 = { .win = "pushd build && textperf.exe --capture && popd",.linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, //- rjf: local target builds .build_raddbg = { .win = "build raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, diff --git a/src/base/base_core.h b/src/base/base_core.h index 54c7de26..b871be76 100644 --- a/src/base/base_core.h +++ b/src/base/base_core.h @@ -40,6 +40,12 @@ # define thread_static __thread #endif +#if COMPILER_MSVC +# define force_inline __forceinline +#elif COMPILER_CLANG || COMPILER_GCC +# define force_inline __attribute__((always_inline)) +#endif + //////////////////////////////// //~ rjf: Linkage Keyword Macros diff --git a/src/draw/draw.c b/src/draw/draw.c index c09e375f..272571b3 100644 --- a/src/draw/draw.c +++ b/src/draw/draw.c @@ -609,6 +609,7 @@ dr_truncated_fancy_run_fuzzy_matches(Vec2F32 p, DR_FancyRunList *list, F32 max_x internal void dr_text_run(Vec2F32 p, Vec4F32 color, FNT_Run run) { + ProfBeginFunction(); F32 advance = 0; FNT_Piece *piece_first = run.pieces.v; FNT_Piece *piece_opl = piece_first + run.pieces.count; @@ -629,6 +630,7 @@ dr_text_run(Vec2F32 p, Vec4F32 color, FNT_Run run) } advance += piece->advance; } + ProfEnd(); } internal void diff --git a/src/draw/draw.h b/src/draw/draw.h index ac54de5f..1efb2bed 100644 --- a/src/draw/draw.h +++ b/src/draw/draw.h @@ -132,7 +132,7 @@ internal DR_Bucket *dr_bucket_make(void); internal void dr_push_bucket(DR_Bucket *bucket); internal void dr_pop_bucket(void); internal DR_Bucket *dr_top_bucket(void); -#define D_BucketScope(b) DeferLoop(dr_push_bucket(b), dr_pop_bucket()) +#define DR_BucketScope(b) DeferLoop(dr_push_bucket(b), dr_pop_bucket()) //////////////////////////////// //~ rjf: Bucket Stacks diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 53a78a08..4991ea6e 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -8214,7 +8214,7 @@ rd_window_frame(RD_Window *ws) //- rjf: draw UI // ws->draw_bucket = dr_bucket_make(); - D_BucketScope(ws->draw_bucket) + DR_BucketScope(ws->draw_bucket) ProfScope("draw UI") { Temp scratch = scratch_begin(0, 0); diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index b69e255b..f2b38a76 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -7074,7 +7074,7 @@ RD_VIEW_RULE_UI_FUNCTION_DEF(memory) { Rng1U64 selection_in_row = intersect_1u64(row_range_bytes, selection); DR_Bucket *bucket = dr_bucket_make(); - D_BucketScope(bucket) + DR_BucketScope(bucket) { Vec2F32 text_pos = ui_box_text_position(ascii_box); dr_rect(r2f32p(text_pos.x + fnt_dim_from_tag_size_string(font, font_size, 0, 0, str8_prefix(ascii_text, selection_in_row.min+0-row_range_bytes.min)).x - font_size/8.f, @@ -7089,7 +7089,7 @@ RD_VIEW_RULE_UI_FUNCTION_DEF(memory) if(mouse_hover_byte_num != 0 && contains_1u64(row_range_bytes, mouse_hover_byte_num-1)) { DR_Bucket *bucket = dr_bucket_make(); - D_BucketScope(bucket) + DR_BucketScope(bucket) { Vec2F32 text_pos = ui_box_text_position(ascii_box); Vec4F32 color = rd_rgba_from_theme_color(RD_ThemeColor_HighlightOverlay); diff --git a/src/raddbg/raddbg_widgets.c b/src/raddbg/raddbg_widgets.c index 1bda7c4a..cc2af029 100644 --- a/src/raddbg/raddbg_widgets.c +++ b/src/raddbg/raddbg_widgets.c @@ -2006,7 +2006,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe if(line_drag_drop && contains_2f32(clipped_top_container_rect, ui_mouse())) { DR_Bucket *bucket = dr_bucket_make(); - D_BucketScope(bucket) + DR_BucketScope(bucket) { Vec4F32 color = line_drag_drop_color; Rng2F32 drop_line_rect = r2f32p(top_container_box->rect.x0, diff --git a/src/render/d3d11/render_d3d11.c b/src/render/d3d11/render_d3d11.c index d3aa0333..84ac64a7 100644 --- a/src/render/d3d11/render_d3d11.c +++ b/src/render/d3d11/render_d3d11.c @@ -39,7 +39,7 @@ internal R_D3D11_Window * r_d3d11_window_from_handle(R_Handle handle) { R_D3D11_Window *window = (R_D3D11_Window *)handle.u64[0]; - if(window->generation != handle.u64[1]) + if(window == 0) { window = &r_d3d11_window_nil; } @@ -51,7 +51,6 @@ r_d3d11_handle_from_window(R_D3D11_Window *window) { R_Handle handle = {0}; handle.u64[0] = (U64)window; - handle.u64[1] = window->generation; return handle; } @@ -59,7 +58,7 @@ internal R_D3D11_Tex2D * r_d3d11_tex2d_from_handle(R_Handle handle) { R_D3D11_Tex2D *texture = (R_D3D11_Tex2D *)handle.u64[0]; - if(texture == 0 || texture->generation != handle.u64[1]) + if(texture == 0) { texture = &r_d3d11_tex2d_nil; } @@ -71,7 +70,6 @@ r_d3d11_handle_from_tex2d(R_D3D11_Tex2D *texture) { R_Handle handle = {0}; handle.u64[0] = (U64)texture; - handle.u64[1] = texture->generation; return handle; } @@ -79,7 +77,7 @@ internal R_D3D11_Buffer * r_d3d11_buffer_from_handle(R_Handle handle) { R_D3D11_Buffer *buffer = (R_D3D11_Buffer *)handle.u64[0]; - if(buffer == 0 || buffer->generation != handle.u64[1]) + if(buffer == 0) { buffer = &r_d3d11_buffer_nil; } @@ -91,7 +89,6 @@ r_d3d11_handle_from_buffer(R_D3D11_Buffer *buffer) { R_Handle handle = {0}; handle.u64[0] = (U64)buffer; - handle.u64[1] = buffer->generation; return handle; } diff --git a/src/render/d3d11/render_d3d11.h b/src/render/d3d11/render_d3d11.h index 47b3d4b7..5bdec2ab 100644 --- a/src/render/d3d11/render_d3d11.h +++ b/src/render/d3d11/render_d3d11.h @@ -4,6 +4,9 @@ #ifndef RENDER_D3D11_H #define RENDER_D3D11_H +#include +#include +#include #include #include #include diff --git a/src/render/render_core.h b/src/render/render_core.h index b17b4ab1..a7ef99c9 100644 --- a/src/render/render_core.h +++ b/src/render/render_core.h @@ -29,9 +29,9 @@ enum typedef union R_Handle R_Handle; union R_Handle { - U64 u64[2]; - U32 u32[4]; - U16 u16[8]; + U64 u64[1]; + U32 u32[2]; + U16 u16[4]; }; //////////////////////////////// diff --git a/src/scratch/textperf.c b/src/scratch/textperf.c new file mode 100644 index 00000000..c9e3792e --- /dev/null +++ b/src/scratch/textperf.c @@ -0,0 +1,84 @@ +// Copyright (c) 2024 Epic Games Tools +// Licensed under the MIT license (https://opensource.org/license/mit/) + +//////////////////////////////// +//~ rjf: Build Options + +#define BUILD_TITLE "textperf" +#define OS_FEATURE_GRAPHICAL 1 + +//////////////////////////////// +//~ rjf: Includes + +//- rjf: [h] +#include "base/base_inc.h" +#include "os/os_inc.h" +#include "render/render_inc.h" +#include "font_provider/font_provider_inc.h" +#include "font_cache/font_cache.h" +#include "draw/draw.h" + +//- rjf: [c] +#include "base/base_inc.c" +#include "os/os_inc.c" +#include "render/render_inc.c" +#include "font_provider/font_provider_inc.c" +#include "font_cache/font_cache.c" +#include "draw/draw.c" + +//////////////////////////////// +//~ rjf: Globals + +global OS_Handle os_window = {0}; +global R_Handle r_window = {0}; + +//////////////////////////////// +//~ rjf: Entry Points + +internal B32 +frame(void) +{ + ProfBeginFunction(); + B32 quit = 0; + Temp scratch = scratch_begin(0, 0); + OS_EventList events = os_get_events(scratch.arena, 0); + for(OS_Event *evt = events.first; evt != 0; evt = evt->next) + { + if(evt->kind == OS_EventKind_WindowClose) + { + quit = 1; + break; + } + } + r_begin_frame(); + dr_begin_frame(); + r_window_begin_frame(os_window, r_window); + DR_Bucket *bucket = dr_bucket_make(); + DR_BucketScope(bucket) ProfScope("draw") + { + Vec2F32 mouse = os_mouse_from_window(os_window); + FNT_Tag font = fnt_tag_from_path(str8_lit("C:/devel/raddebugger/data/Inconsolata-Regular.ttf")); + for(F32 x = 0; x < 500; x += 5.f) + { + for(F32 y = 0; y < 500; y += 5.f) + { + dr_text(font, 16.f, 0, 0, FNT_RasterFlag_Smooth|FNT_RasterFlag_Hinted, v2f32(30 + x + mouse.x, 30 + y + mouse.y), v4f32(1, 1, 1, 1), str8_lit("This is a test.")); + } + } + } + r_window_submit(os_window, r_window, &bucket->passes); + r_window_end_frame(os_window, r_window); + r_end_frame(); + scratch_end(scratch); + ProfEnd(); + return quit; +} + +internal void +entry_point(CmdLine *cmdline) +{ + os_window = os_window_open(v2f32(1600, 900), 0, str8_lit("textperf")); + r_window = r_window_equip(os_window); + os_window_first_paint(os_window); + for(;!update();); +} diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index c1668547..904b22a5 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -2479,7 +2479,7 @@ ui_box_equip_draw_bucket(UI_Box *box, DR_Bucket *bucket) box->flags |= UI_BoxFlag_DrawBucket; if(box->draw_bucket != 0) { - D_BucketScope(box->draw_bucket) dr_sub_bucket(bucket); + DR_BucketScope(box->draw_bucket) dr_sub_bucket(bucket); } else {