From d9a584a55a63af80469e1c413a958ef745033862 Mon Sep 17 00:00:00 2001 From: Jonathan Hoffstadt Date: Mon, 17 Feb 2025 14:04:05 -0600 Subject: [PATCH] build: update for PL changes --- src/app.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 10 deletions(-) diff --git a/src/app.c b/src/app.c index c978b39..3478b62 100644 --- a/src/app.c +++ b/src/app.c @@ -49,6 +49,8 @@ Index of this file: #include "pl_gpu_allocators_ext.h" #include "pl_image_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 // example extensions @@ -70,9 +72,13 @@ typedef struct _plAppData plFont* ptDefaultFont; // ui options - plDebugApiInfo tDebugInfo; - bool bShowUiDebug; - bool bShowUiStyle; + bool bShowUiDebug; + bool bShowUiStyle; + bool* pbShowDeviceMemoryAnalyzer; + bool* pbShowMemoryAllocations; + bool* pbShowProfiling; + bool* pbShowStats; + bool* pbShowLogging; // graphics & sync objects plDevice* ptDevice; @@ -90,6 +96,7 @@ typedef struct _plAppData // [SECTION] apis //----------------------------------------------------------------------------- +const plDataRegistryI* gptDataRegistry = NULL; const plMemoryI* gptMemory = NULL; const plIOI* gptIO = NULL; const plWindowI* gptWindows = NULL; @@ -114,6 +121,8 @@ const plStringInternI* gptString = NULL; const plLibraryI* gptLibrary = NULL; const plLogI* gptLog = NULL; const plVirtualMemoryI* gptVirtualMemory = NULL; +const plConsoleI* gptConsole = NULL; +const plScreenLogI* gptScreenLog = NULL; // helpers #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 // 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 // during a hot reload. @@ -178,6 +187,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) gptLibrary = pl_get_api_latest(ptApiRegistry, plLibraryI); gptLog = pl_get_api_latest(ptApiRegistry, plLogI); gptVirtualMemory = pl_get_api_latest(ptApiRegistry, plVirtualMemoryI); + gptConsole = pl_get_api_latest(ptApiRegistry, plConsoleI); + gptScreenLog = pl_get_api_latest(ptApiRegistry, plScreenLogI); return ptAppData; } @@ -216,12 +227,17 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) gptLibrary = pl_get_api_latest(ptApiRegistry, plLibraryI); gptLog = pl_get_api_latest(ptApiRegistry, plLogI); 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 // allocate app memory here ptAppData = PL_ALLOC(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 plWindowDesc tWindowDesc = { .pcTitle = "App Template", @@ -232,6 +248,16 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) }; 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 pl__setup_graphics_extensions(ptAppData); @@ -252,6 +278,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) gptDrawBackend->build_font_atlas(ptCmdBuffer, ptAtlas); gptGfx->return_command_buffer(ptCmdBuffer); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~message extension~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + gptScreenLog->initialize((plScreenLogSettings){.ptFont = ptAppData->ptDefaultFont}); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ui extension~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gptUi->initialize(); @@ -288,6 +318,8 @@ pl_app_shutdown(plAppData* ptAppData) gptDrawBackend->cleanup_font_atlas(NULL); gptUi->cleanup(); gptDrawBackend->cleanup(); + gptScreenLog->cleanup(); + gptConsole->cleanup(); gptGfx->cleanup_swapchain(ptAppData->ptSwapchain); gptGfx->cleanup_surface(ptAppData->ptSurface); gptGfx->cleanup_device(ptAppData->ptDevice); @@ -346,6 +378,11 @@ pl_app_update(plAppData* ptAppData) // 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)}); + if(gptIO->is_key_pressed(PL_KEY_F1, false)) + gptConsole->open(); + + gptConsole->update(); + if(gptUi->begin_window("Pilot Light", NULL, false)) { @@ -359,11 +396,11 @@ pl_app_update(plAppData* ptAppData) } if(gptUi->begin_collapsing_header("Tools", 0)) { - gptUi->checkbox("Device Memory Analyzer", &ptAppData->tDebugInfo.bShowDeviceMemoryAnalyzer); - gptUi->checkbox("Memory Allocations", &ptAppData->tDebugInfo.bShowMemoryAllocations); - gptUi->checkbox("Profiling", &ptAppData->tDebugInfo.bShowProfiling); - gptUi->checkbox("Statistics", &ptAppData->tDebugInfo.bShowStats); - gptUi->checkbox("Logging", &ptAppData->tDebugInfo.bShowLogging); + gptUi->checkbox("Device Memory Analyzer", ptAppData->pbShowDeviceMemoryAnalyzer); + gptUi->checkbox("Memory Allocations", ptAppData->pbShowMemoryAllocations); + gptUi->checkbox("Profiling", ptAppData->pbShowProfiling); + gptUi->checkbox("Statistics", ptAppData->pbShowStats); + gptUi->checkbox("Logging", ptAppData->pbShowLogging); gptUi->end_collapsing_header(); } if(gptUi->begin_collapsing_header("User Interface", 0)) @@ -381,7 +418,7 @@ pl_app_update(plAppData* ptAppData) if(ptAppData->bShowUiDebug) gptUi->show_debug_window(&ptAppData->bShowUiDebug); - gptDebug->show_debug_windows(&ptAppData->tDebugInfo); + gptDebug->update(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~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_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 gptGfx->end_render_pass(ptEncoder); @@ -490,6 +531,8 @@ pl__setup_graphics_extensions(plAppData* ptAppData) }; ptAppData->ptDevice = gptGfx->create_device(&tDeviceInit); + gptDataRegistry->set_data("device", ptAppData->ptDevice); // used by debug extension + // create command pools for(uint32_t i = 0; i < gptGfx->get_frames_in_flight(); i++) ptAppData->atCmdPools[i] = gptGfx->create_command_pool(ptAppData->ptDevice, NULL); @@ -513,6 +556,24 @@ pl__setup_graphics_extensions(plAppData* ptAppData) .uRenderTargetCount = 1, .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);