Skip to content

Commit

Permalink
refac: moved profiler to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Nov 18, 2024
1 parent 7db12ef commit 3a6aa2b
Show file tree
Hide file tree
Showing 26 changed files with 432 additions and 251 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ jobs:
if not exist ../out/pl_image_ext.dll exit 1
if not exist ../out/pl_job_ext.dll exit 1
if not exist ../out/pl_model_loader_ext.dll exit 1
if not exist ../out/pl_profile_ext.dll exit 1
if not exist ../out/pl_rect_pack_ext.dll exit 1
if not exist ../out/pl_renderer_ext.dll exit 1
if not exist ../out/pl_resource_ext.dll exit 1
Expand Down Expand Up @@ -240,6 +241,7 @@ jobs:
test -f ./out/pl_image_ext.dylib || exit 1
test -f ./out/pl_job_ext.dylib || exit 1
test -f ./out/pl_model_loader_ext.dylib || exit 1
test -f ./out/pl_profile_ext.dylib || exit 1
test -f ./out/pl_rect_pack_ext.dylib || exit 1
test -f ./out/pl_renderer_ext.dylib || exit 1
test -f ./out/pl_resource_ext.dylib || exit 1
Expand Down Expand Up @@ -375,6 +377,7 @@ jobs:
test -f ./out/pl_image_ext.so || exit 1
test -f ./out/pl_job_ext.so || exit 1
test -f ./out/pl_model_loader_ext.so || exit 1
test -f ./out/pl_profile_ext.so || exit 1
test -f ./out/pl_rect_pack_ext.so || exit 1
test -f ./out/pl_renderer_ext.so || exit 1
test -f ./out/pl_resource_ext.so || exit 1
Expand Down
20 changes: 10 additions & 10 deletions examples/example_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Index of this file:
#include <stdio.h>
#include <string.h> // memset
#include "pl.h"
#include "pl_profile.h"
#include "pl_log.h"
#include "pl_ds.h"
#include "pl_memory.h"
Expand All @@ -40,6 +39,7 @@ Index of this file:
#include "pl_shader_ext.h"
#include "pl_graphics_ext.h"
#include "pl_draw_backend_ext.h"
#include "pl_profile_ext.h"

//-----------------------------------------------------------------------------
// [SECTION] structs
Expand Down Expand Up @@ -80,6 +80,7 @@ const plGraphicsI* gptGfx = NULL;
const plDrawI* gptDraw = NULL;
const plShaderI* gptShader = NULL;
const plDrawBackendI* gptDrawBackend = NULL;
const plProfileI* gptProfile = NULL;

//-----------------------------------------------------------------------------
// [SECTION] pl_app_load
Expand All @@ -97,7 +98,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// set log & profile contexts
pl_set_log_context(ptDataRegistry->get_data(PL_LOG_CONTEXT_NAME));
pl_set_profile_context(ptDataRegistry->get_data(PL_PROFILE_CONTEXT_NAME));

// if "ptAppData" is a valid pointer, then this function is being called
// during a hot reload.
Expand All @@ -112,6 +112,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptDraw = pl_get_api_latest(ptApiRegistry, plDrawI);
gptShader = pl_get_api_latest(ptApiRegistry, plShaderI);
gptDrawBackend = pl_get_api_latest(ptApiRegistry, plDrawBackendI);
gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI);

return ptAppData;
}
Expand All @@ -134,6 +135,9 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptDraw = pl_get_api_latest(ptApiRegistry, plDrawI);
gptShader = pl_get_api_latest(ptApiRegistry, plShaderI);
gptDrawBackend = pl_get_api_latest(ptApiRegistry, plDrawBackendI);
gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI);

gptProfile->initialize();

// initialize shader compiler
static const plShaderOptions tDefaultShaderOptions = {
Expand Down Expand Up @@ -353,7 +357,7 @@ pl_app_resize(plAppData* ptAppData)
PL_EXPORT void
pl_app_update(plAppData* ptAppData)
{
pl_begin_profile_frame();
gptProfile->begin_frame();

gptIO->new_frame();
gptDrawBackend->new_frame();
Expand All @@ -367,7 +371,7 @@ pl_app_update(plAppData* ptAppData)
if(!gptGfx->acquire_swapchain_image(ptAppData->ptSwapchain))
{
pl_app_resize(ptAppData);
pl_end_profile_frame();
gptProfile->end_frame();
return;
}

Expand Down Expand Up @@ -467,7 +471,7 @@ pl_app_update(plAppData* ptAppData)
pl_app_resize(ptAppData);

gptGfx->return_command_buffer(ptCommandBuffer);
pl_end_profile_frame();
gptProfile->end_frame();
}

//-----------------------------------------------------------------------------
Expand All @@ -476,8 +480,4 @@ pl_app_update(plAppData* ptAppData)

#define PL_LOG_IMPLEMENTATION
#include "pl_log.h"
#undef PL_LOG_IMPLEMENTATION

#define PL_PROFILE_IMPLEMENTATION
#include "pl_profile.h"
#undef PL_PROFILE_IMPLEMENTATION
#undef PL_LOG_IMPLEMENTATION
18 changes: 9 additions & 9 deletions examples/example_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Index of this file:
#include <stdio.h>
#include <string.h> // memset
#include "pl.h"
#include "pl_profile.h"
#include "pl_log.h"
#include "pl_ds.h"
#include "pl_memory.h"
Expand All @@ -42,6 +41,7 @@ Index of this file:
#include "pl_ui_ext.h"
#include "pl_graphics_ext.h"
#include "pl_draw_backend_ext.h"
#include "pl_profile_ext.h"

//-----------------------------------------------------------------------------
// [SECTION] structs
Expand Down Expand Up @@ -82,6 +82,7 @@ const plDrawI* gptDraw = NULL;
const plUiI* gptUi = NULL;
const plShaderI* gptShader = NULL;
const plDrawBackendI* gptDrawBackend = NULL;
const plProfileI* gptProfile = NULL;

//-----------------------------------------------------------------------------
// [SECTION] forward declarations
Expand All @@ -106,7 +107,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// set log & profile contexts
pl_set_log_context(ptDataRegistry->get_data(PL_LOG_CONTEXT_NAME));
pl_set_profile_context(ptDataRegistry->get_data(PL_PROFILE_CONTEXT_NAME));

// if "ptAppData" is a valid pointer, then this function is being called
// during a hot reload.
Expand All @@ -122,6 +122,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptShader = pl_get_api_latest(ptApiRegistry, plShaderI);
gptDrawBackend = pl_get_api_latest(ptApiRegistry, plDrawBackendI);
gptUi = pl_get_api_latest(ptApiRegistry, plUiI);
gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI);

return ptAppData;
}
Expand All @@ -145,6 +146,9 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptShader = pl_get_api_latest(ptApiRegistry, plShaderI);
gptDrawBackend = pl_get_api_latest(ptApiRegistry, plDrawBackendI);
gptUi = pl_get_api_latest(ptApiRegistry, plUiI);
gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI);

gptProfile->initialize();

// initialize shader compiler
static const plShaderOptions tDefaultShaderOptions = {
Expand Down Expand Up @@ -441,7 +445,7 @@ pl_app_resize(plAppData* ptAppData)
PL_EXPORT void
pl_app_update(plAppData* ptAppData)
{
pl_begin_profile_frame();
gptProfile->begin_frame();

gptIO->new_frame();
gptDrawBackend->new_frame();
Expand All @@ -457,7 +461,7 @@ pl_app_update(plAppData* ptAppData)
if(!gptGfx->acquire_swapchain_image(ptAppData->ptSwapchain))
{
pl_app_resize(ptAppData);
pl_end_profile_frame();
gptProfile->end_frame();
return;
}

Expand Down Expand Up @@ -546,7 +550,7 @@ pl_app_update(plAppData* ptAppData)
pl_app_resize(ptAppData);

gptGfx->return_command_buffer(ptCommandBuffer);
pl_end_profile_frame();
gptProfile->end_frame();
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1306,7 +1310,3 @@ pl_show_ui_demo_window(plAppData* ptAppData)
#define PL_LOG_IMPLEMENTATION
#include "pl_log.h"
#undef PL_LOG_IMPLEMENTATION

#define PL_PROFILE_IMPLEMENTATION
#include "pl_profile.h"
#undef PL_PROFILE_IMPLEMENTATION
18 changes: 9 additions & 9 deletions examples/example_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Index of this file:
#include <stdio.h>
#include <string.h> // memset
#include "pl.h"
#include "pl_profile.h"
#include "pl_log.h"
#include "pl_ds.h"
#include "pl_memory.h"
Expand All @@ -39,6 +38,7 @@ Index of this file:
#include "pl_window_ext.h"
#include "pl_graphics_ext.h"
#include "pl_shader_ext.h"
#include "pl_profile_ext.h"

//-----------------------------------------------------------------------------
// [SECTION] structs
Expand Down Expand Up @@ -75,6 +75,7 @@ const plIOI* gptIO = NULL;
const plWindowI* gptWindows = NULL;
const plGraphicsI* gptGfx = NULL;
const plShaderI* gptShader = NULL;
const plProfileI* gptProfile = NULL;

//-----------------------------------------------------------------------------
// [SECTION] pl_app_load
Expand All @@ -92,7 +93,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// set log & profile contexts
pl_set_log_context(ptDataRegistry->get_data(PL_LOG_CONTEXT_NAME));
pl_set_profile_context(ptDataRegistry->get_data(PL_PROFILE_CONTEXT_NAME));

// if "ptAppData" is a valid pointer, then this function is being called
// during a hot reload.
Expand All @@ -104,6 +104,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
gptShader = pl_get_api_latest(ptApiRegistry, plShaderI);
gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI);

return ptAppData;
}
Expand All @@ -124,6 +125,9 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
gptShader = pl_get_api_latest(ptApiRegistry, plShaderI);
gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI);

gptProfile->initialize();

// use window API to create a window
plWindowDesc tWindowDesc = {
Expand Down Expand Up @@ -366,7 +370,7 @@ pl_app_resize(plAppData* ptAppData)
PL_EXPORT void
pl_app_update(plAppData* ptAppData)
{
pl_begin_profile_frame();
gptProfile->begin_frame();

gptIO->new_frame();

Expand All @@ -379,7 +383,7 @@ pl_app_update(plAppData* ptAppData)
if(!gptGfx->acquire_swapchain_image(ptAppData->ptSwapchain))
{
pl_app_resize(ptAppData);
pl_end_profile_frame();
gptProfile->end_frame();
return;
}

Expand Down Expand Up @@ -432,7 +436,7 @@ pl_app_update(plAppData* ptAppData)
pl_app_resize(ptAppData);

gptGfx->return_command_buffer(ptCommandBuffer);
pl_end_profile_frame();
gptProfile->end_frame();
}

//-----------------------------------------------------------------------------
Expand All @@ -442,7 +446,3 @@ pl_app_update(plAppData* ptAppData)
#define PL_LOG_IMPLEMENTATION
#include "pl_log.h"
#undef PL_LOG_IMPLEMENTATION

#define PL_PROFILE_IMPLEMENTATION
#include "pl_profile.h"
#undef PL_PROFILE_IMPLEMENTATION
18 changes: 9 additions & 9 deletions examples/example_5.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Index of this file:

#include <stdio.h>
#include "pl.h"
#include "pl_profile.h"
#include "pl_log.h"
#include "pl_ds.h"
#include "pl_memory.h"
Expand All @@ -39,6 +38,7 @@ Index of this file:
#include "pl_window_ext.h"
#include "pl_graphics_ext.h"
#include "pl_shader_ext.h"
#include "pl_profile_ext.h"

//-----------------------------------------------------------------------------
// [SECTION] structs
Expand Down Expand Up @@ -77,6 +77,7 @@ const plIOI* gptIO = NULL;
const plWindowI* gptWindows = NULL;
const plGraphicsI* gptGfx = NULL;
const plShaderI* gptShader = NULL;
const plProfileI* gptProfile = NULL;

//-----------------------------------------------------------------------------
// [SECTION] pl_app_load
Expand All @@ -94,7 +95,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// set log & profile contexts
pl_set_log_context(ptDataRegistry->get_data(PL_LOG_CONTEXT_NAME));
pl_set_profile_context(ptDataRegistry->get_data(PL_PROFILE_CONTEXT_NAME));

// if "ptAppData" is a valid pointer, then this function is being called
// during a hot reload.
Expand All @@ -106,6 +106,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
gptShader = pl_get_api_latest(ptApiRegistry, plShaderI);
gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI);

return ptAppData;
}
Expand All @@ -126,6 +127,9 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptWindows = pl_get_api_latest(ptApiRegistry, plWindowI);
gptGfx = pl_get_api_latest(ptApiRegistry, plGraphicsI);
gptShader = pl_get_api_latest(ptApiRegistry, plShaderI);
gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI);

gptProfile->initialize();

// use window API to create a window
plWindowDesc tWindowDesc = {
Expand Down Expand Up @@ -441,7 +445,7 @@ pl_app_resize(plAppData* ptAppData)
PL_EXPORT void
pl_app_update(plAppData* ptAppData)
{
pl_begin_profile_frame();
gptProfile->begin_frame();

gptIO->new_frame();

Expand All @@ -454,7 +458,7 @@ pl_app_update(plAppData* ptAppData)
if(!gptGfx->acquire_swapchain_image(ptAppData->ptSwapchain))
{
pl_app_resize(ptAppData);
pl_end_profile_frame();
gptProfile->end_frame();
return;
}

Expand Down Expand Up @@ -508,7 +512,7 @@ pl_app_update(plAppData* ptAppData)
pl_app_resize(ptAppData);

gptGfx->return_command_buffer(ptCommandBuffer);
pl_end_profile_frame();
gptProfile->end_frame();
}

//-----------------------------------------------------------------------------
Expand All @@ -518,7 +522,3 @@ pl_app_update(plAppData* ptAppData)
#define PL_LOG_IMPLEMENTATION
#include "pl_log.h"
#undef PL_LOG_IMPLEMENTATION

#define PL_PROFILE_IMPLEMENTATION
#include "pl_profile.h"
#undef PL_PROFILE_IMPLEMENTATION
Loading

0 comments on commit 3a6aa2b

Please sign in to comment.