build: update for PL changes

This commit is contained in:
Jonathan Hoffstadt 2025-02-17 14:04:05 -06:00
parent b42fbafb2c
commit d9a584a55a

View File

@ -49,6 +49,8 @@ Index of this file:
#include "pl_gpu_allocators_ext.h" #include "pl_gpu_allocators_ext.h"
#include "pl_image_ext.h" #include "pl_image_ext.h"
#include "pl_virtual_memory_ext.h" #include "pl_virtual_memory_ext.h"
#include "pl_console_ext.h"
#include "pl_screen_log_ext.h"
#include "pl_debug_ext.h" // not technically stable #include "pl_debug_ext.h" // not technically stable
// example extensions // example extensions
@ -70,9 +72,13 @@ typedef struct _plAppData
plFont* ptDefaultFont; plFont* ptDefaultFont;
// ui options // ui options
plDebugApiInfo tDebugInfo; bool bShowUiDebug;
bool bShowUiDebug; bool bShowUiStyle;
bool bShowUiStyle; bool* pbShowDeviceMemoryAnalyzer;
bool* pbShowMemoryAllocations;
bool* pbShowProfiling;
bool* pbShowStats;
bool* pbShowLogging;
// graphics & sync objects // graphics & sync objects
plDevice* ptDevice; plDevice* ptDevice;
@ -90,6 +96,7 @@ typedef struct _plAppData
// [SECTION] apis // [SECTION] apis
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const plDataRegistryI* gptDataRegistry = NULL;
const plMemoryI* gptMemory = NULL; const plMemoryI* gptMemory = NULL;
const plIOI* gptIO = NULL; const plIOI* gptIO = NULL;
const plWindowI* gptWindows = NULL; const plWindowI* gptWindows = NULL;
@ -114,6 +121,8 @@ const plStringInternI* gptString = NULL;
const plLibraryI* gptLibrary = NULL; const plLibraryI* gptLibrary = NULL;
const plLogI* gptLog = NULL; const plLogI* gptLog = NULL;
const plVirtualMemoryI* gptVirtualMemory = NULL; const plVirtualMemoryI* gptVirtualMemory = NULL;
const plConsoleI* gptConsole = NULL;
const plScreenLogI* gptScreenLog = NULL;
// helpers // helpers
#define PL_ALLOC(x) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__) #define PL_ALLOC(x) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
@ -145,7 +154,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// retrieve the data registry API, this is the API used for sharing data // retrieve the data registry API, this is the API used for sharing data
// between extensions & the runtime // between extensions & the runtime
const plDataRegistryI* ptDataRegistry = pl_get_api_latest(ptApiRegistry, plDataRegistryI); gptDataRegistry = pl_get_api_latest(ptApiRegistry, plDataRegistryI);
// if "ptAppData" is a valid pointer, then this function is being called // if "ptAppData" is a valid pointer, then this function is being called
// during a hot reload. // during a hot reload.
@ -178,6 +187,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptLibrary = pl_get_api_latest(ptApiRegistry, plLibraryI); gptLibrary = pl_get_api_latest(ptApiRegistry, plLibraryI);
gptLog = pl_get_api_latest(ptApiRegistry, plLogI); gptLog = pl_get_api_latest(ptApiRegistry, plLogI);
gptVirtualMemory = pl_get_api_latest(ptApiRegistry, plVirtualMemoryI); gptVirtualMemory = pl_get_api_latest(ptApiRegistry, plVirtualMemoryI);
gptConsole = pl_get_api_latest(ptApiRegistry, plConsoleI);
gptScreenLog = pl_get_api_latest(ptApiRegistry, plScreenLogI);
return ptAppData; return ptAppData;
} }
@ -216,12 +227,17 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptLibrary = pl_get_api_latest(ptApiRegistry, plLibraryI); gptLibrary = pl_get_api_latest(ptApiRegistry, plLibraryI);
gptLog = pl_get_api_latest(ptApiRegistry, plLogI); gptLog = pl_get_api_latest(ptApiRegistry, plLogI);
gptVirtualMemory = pl_get_api_latest(ptApiRegistry, plVirtualMemoryI); gptVirtualMemory = pl_get_api_latest(ptApiRegistry, plVirtualMemoryI);
gptConsole = pl_get_api_latest(ptApiRegistry, plConsoleI);
gptScreenLog = pl_get_api_latest(ptApiRegistry, plScreenLogI);
// this path is taken only during first load, so we // this path is taken only during first load, so we
// allocate app memory here // allocate app memory here
ptAppData = PL_ALLOC(sizeof(plAppData)); ptAppData = PL_ALLOC(sizeof(plAppData));
memset(ptAppData, 0, sizeof(plAppData)); memset(ptAppData, 0, sizeof(plAppData));
// add console variables
gptConsole->initialize((plConsoleSettings){.tFlags = PL_CONSOLE_FLAGS_POPUP});
// use window API to create a window // use window API to create a window
plWindowDesc tWindowDesc = { plWindowDesc tWindowDesc = {
.pcTitle = "App Template", .pcTitle = "App Template",
@ -232,6 +248,16 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
}; };
gptWindows->create_window(tWindowDesc, &ptAppData->ptWindow); gptWindows->create_window(tWindowDesc, &ptAppData->ptWindow);
// initialize APIs that require it
gptDebug->initialize();
// retrieve some console variables
ptAppData->pbShowLogging = (bool*)gptConsole->get_variable("d.LogTool", NULL, NULL);
ptAppData->pbShowStats = (bool*)gptConsole->get_variable("d.StatTool", NULL, NULL);
ptAppData->pbShowProfiling = (bool*)gptConsole->get_variable("d.ProfileTool", NULL, NULL);
ptAppData->pbShowMemoryAllocations = (bool*)gptConsole->get_variable("d.MemoryAllocationTool", NULL, NULL);
ptAppData->pbShowDeviceMemoryAnalyzer = (bool*)gptConsole->get_variable("d.DeviceMemoryAnalyzerTool", NULL, NULL);
// setup graphics extension // setup graphics extension
pl__setup_graphics_extensions(ptAppData); pl__setup_graphics_extensions(ptAppData);
@ -252,6 +278,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptDrawBackend->build_font_atlas(ptCmdBuffer, ptAtlas); gptDrawBackend->build_font_atlas(ptCmdBuffer, ptAtlas);
gptGfx->return_command_buffer(ptCmdBuffer); gptGfx->return_command_buffer(ptCmdBuffer);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~message extension~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gptScreenLog->initialize((plScreenLogSettings){.ptFont = ptAppData->ptDefaultFont});
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ui extension~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ui extension~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gptUi->initialize(); gptUi->initialize();
@ -288,6 +318,8 @@ pl_app_shutdown(plAppData* ptAppData)
gptDrawBackend->cleanup_font_atlas(NULL); gptDrawBackend->cleanup_font_atlas(NULL);
gptUi->cleanup(); gptUi->cleanup();
gptDrawBackend->cleanup(); gptDrawBackend->cleanup();
gptScreenLog->cleanup();
gptConsole->cleanup();
gptGfx->cleanup_swapchain(ptAppData->ptSwapchain); gptGfx->cleanup_swapchain(ptAppData->ptSwapchain);
gptGfx->cleanup_surface(ptAppData->ptSurface); gptGfx->cleanup_surface(ptAppData->ptSurface);
gptGfx->cleanup_device(ptAppData->ptDevice); gptGfx->cleanup_device(ptAppData->ptDevice);
@ -346,6 +378,11 @@ pl_app_update(plAppData* ptAppData)
// just some drawing // just some drawing
gptDraw->add_circle(ptAppData->ptFGLayer, (plVec2){100.0f, 100.0f}, 50.0f, 12, (plDrawLineOptions){.fThickness = 2.0f, .uColor = PL_COLOR_32_RGBA(1.0f, 0.0f, 1.0f, 1.0f)}); gptDraw->add_circle(ptAppData->ptFGLayer, (plVec2){100.0f, 100.0f}, 50.0f, 12, (plDrawLineOptions){.fThickness = 2.0f, .uColor = PL_COLOR_32_RGBA(1.0f, 0.0f, 1.0f, 1.0f)});
if(gptIO->is_key_pressed(PL_KEY_F1, false))
gptConsole->open();
gptConsole->update();
if(gptUi->begin_window("Pilot Light", NULL, false)) if(gptUi->begin_window("Pilot Light", NULL, false))
{ {
@ -359,11 +396,11 @@ pl_app_update(plAppData* ptAppData)
} }
if(gptUi->begin_collapsing_header("Tools", 0)) if(gptUi->begin_collapsing_header("Tools", 0))
{ {
gptUi->checkbox("Device Memory Analyzer", &ptAppData->tDebugInfo.bShowDeviceMemoryAnalyzer); gptUi->checkbox("Device Memory Analyzer", ptAppData->pbShowDeviceMemoryAnalyzer);
gptUi->checkbox("Memory Allocations", &ptAppData->tDebugInfo.bShowMemoryAllocations); gptUi->checkbox("Memory Allocations", ptAppData->pbShowMemoryAllocations);
gptUi->checkbox("Profiling", &ptAppData->tDebugInfo.bShowProfiling); gptUi->checkbox("Profiling", ptAppData->pbShowProfiling);
gptUi->checkbox("Statistics", &ptAppData->tDebugInfo.bShowStats); gptUi->checkbox("Statistics", ptAppData->pbShowStats);
gptUi->checkbox("Logging", &ptAppData->tDebugInfo.bShowLogging); gptUi->checkbox("Logging", ptAppData->pbShowLogging);
gptUi->end_collapsing_header(); gptUi->end_collapsing_header();
} }
if(gptUi->begin_collapsing_header("User Interface", 0)) if(gptUi->begin_collapsing_header("User Interface", 0))
@ -381,7 +418,7 @@ pl_app_update(plAppData* ptAppData)
if(ptAppData->bShowUiDebug) if(ptAppData->bShowUiDebug)
gptUi->show_debug_window(&ptAppData->bShowUiDebug); gptUi->show_debug_window(&ptAppData->bShowUiDebug);
gptDebug->show_debug_windows(&ptAppData->tDebugInfo); gptDebug->update();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~graphics work~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~graphics work~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -411,6 +448,10 @@ pl_app_update(plAppData* ptAppData)
gptDrawBackend->submit_2d_drawlist(gptUi->get_draw_list(), ptEncoder, ptIO->tMainViewportSize.x, ptIO->tMainViewportSize.y, gptGfx->get_swapchain_info(ptAppData->ptSwapchain).tSampleCount); gptDrawBackend->submit_2d_drawlist(gptUi->get_draw_list(), ptEncoder, ptIO->tMainViewportSize.x, ptIO->tMainViewportSize.y, gptGfx->get_swapchain_info(ptAppData->ptSwapchain).tSampleCount);
gptDrawBackend->submit_2d_drawlist(gptUi->get_debug_draw_list(), ptEncoder, ptIO->tMainViewportSize.x, ptIO->tMainViewportSize.y, gptGfx->get_swapchain_info(ptAppData->ptSwapchain).tSampleCount); gptDrawBackend->submit_2d_drawlist(gptUi->get_debug_draw_list(), ptEncoder, ptIO->tMainViewportSize.x, ptIO->tMainViewportSize.y, gptGfx->get_swapchain_info(ptAppData->ptSwapchain).tSampleCount);
plDrawList2D* ptMessageDrawlist = gptScreenLog->get_drawlist(ptIO->tMainViewportSize.x, ptIO->tMainViewportSize.y);
gptDrawBackend->submit_2d_drawlist(ptMessageDrawlist, ptEncoder, ptIO->tMainViewportSize.x, ptIO->tMainViewportSize.y, gptGfx->get_swapchain_info(ptAppData->ptSwapchain).tSampleCount);
// end render pass // end render pass
gptGfx->end_render_pass(ptEncoder); gptGfx->end_render_pass(ptEncoder);
@ -490,6 +531,8 @@ pl__setup_graphics_extensions(plAppData* ptAppData)
}; };
ptAppData->ptDevice = gptGfx->create_device(&tDeviceInit); ptAppData->ptDevice = gptGfx->create_device(&tDeviceInit);
gptDataRegistry->set_data("device", ptAppData->ptDevice); // used by debug extension
// create command pools // create command pools
for(uint32_t i = 0; i < gptGfx->get_frames_in_flight(); i++) for(uint32_t i = 0; i < gptGfx->get_frames_in_flight(); i++)
ptAppData->atCmdPools[i] = gptGfx->create_command_pool(ptAppData->ptDevice, NULL); ptAppData->atCmdPools[i] = gptGfx->create_command_pool(ptAppData->ptDevice, NULL);
@ -513,6 +556,24 @@ pl__setup_graphics_extensions(plAppData* ptAppData)
.uRenderTargetCount = 1, .uRenderTargetCount = 1,
.auRenderTargets = {0} .auRenderTargets = {0}
} }
},
.atSubpassDependencies = {
{
.uSourceSubpass = UINT32_MAX,
.uDestinationSubpass = 0,
.tSourceStageMask = PL_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT | PL_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS | PL_PIPELINE_STAGE_LATE_FRAGMENT_TESTS | PL_PIPELINE_STAGE_COMPUTE_SHADER,
.tDestinationStageMask = PL_PIPELINE_STAGE_FRAGMENT_SHADER | PL_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT | PL_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS | PL_PIPELINE_STAGE_LATE_FRAGMENT_TESTS,
.tSourceAccessMask = PL_ACCESS_COLOR_ATTACHMENT_WRITE | PL_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE | PL_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ,
.tDestinationAccessMask = PL_ACCESS_SHADER_READ | PL_ACCESS_COLOR_ATTACHMENT_WRITE | PL_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE | PL_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ,
},
{
.uSourceSubpass = 0,
.uDestinationSubpass = UINT32_MAX,
.tSourceStageMask = PL_PIPELINE_STAGE_FRAGMENT_SHADER | PL_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT | PL_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS | PL_PIPELINE_STAGE_LATE_FRAGMENT_TESTS,
.tDestinationStageMask = PL_PIPELINE_STAGE_FRAGMENT_SHADER | PL_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT | PL_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS | PL_PIPELINE_STAGE_LATE_FRAGMENT_TESTS | PL_PIPELINE_STAGE_COMPUTE_SHADER,
.tSourceAccessMask = PL_ACCESS_SHADER_READ | PL_ACCESS_COLOR_ATTACHMENT_WRITE | PL_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE | PL_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ,
.tDestinationAccessMask = PL_ACCESS_SHADER_READ | PL_ACCESS_COLOR_ATTACHMENT_WRITE | PL_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE | PL_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ,
},
} }
}; };
ptAppData->tMainRenderPassLayout = gptGfx->create_render_pass_layout(ptAppData->ptDevice, &tMainRenderPassLayoutDesc); ptAppData->tMainRenderPassLayout = gptGfx->create_render_pass_layout(ptAppData->ptDevice, &tMainRenderPassLayoutDesc);