diff --git a/extensions/pl_example_ext.h b/extensions/pl_example_ext.h index 44dc520..5257a23 100644 --- a/extensions/pl_example_ext.h +++ b/extensions/pl_example_ext.h @@ -21,7 +21,7 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define plExampleI_version (plVersion){1, 0, 0} +#define plExampleI_version {1, 0, 0} //----------------------------------------------------------------------------- // [SECTION] public api diff --git a/src/app.c b/src/app.c index c978b39..9a5d775 100644 --- a/src/app.c +++ b/src/app.c @@ -40,16 +40,14 @@ Index of this file: #include "pl_stats_ext.h" #include "pl_job_ext.h" #include "pl_string_intern_ext.h" -#include "pl_network_ext.h" -#include "pl_threads_ext.h" -#include "pl_atomics_ext.h" #include "pl_library_ext.h" -#include "pl_file_ext.h" #include "pl_rect_pack_ext.h" #include "pl_gpu_allocators_ext.h" #include "pl_image_ext.h" -#include "pl_virtual_memory_ext.h" -#include "pl_debug_ext.h" // not technically stable +#include "pl_console_ext.h" +#include "pl_screen_log_ext.h" +#include "pl_tools_ext.h" +#include "pl_platform_ext.h" // example extensions #include "pl_example_ext.h" @@ -70,9 +68,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 +92,7 @@ typedef struct _plAppData // [SECTION] apis //----------------------------------------------------------------------------- +const plDataRegistryI* gptDataRegistry = NULL; const plMemoryI* gptMemory = NULL; const plIOI* gptIO = NULL; const plWindowI* gptWindows = NULL; @@ -101,7 +104,7 @@ const plDrawBackendI* gptDrawBackend = NULL; const plProfileI* gptProfile = NULL; const plExampleI* gptExample = NULL; const plStatsI* gptStats = NULL; -const plDebugApiI* gptDebug = NULL; +const plToolsI* gptTools = NULL; const plImageI* gptImage = NULL; const plGPUAllocatorsI* gptGpuAllocators = NULL; const plJobI* gptJob = NULL; @@ -114,6 +117,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 +150,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. @@ -165,7 +170,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI); gptStats = pl_get_api_latest(ptApiRegistry, plStatsI); gptExample = pl_get_api_latest(ptApiRegistry, plExampleI); - gptDebug = pl_get_api_latest(ptApiRegistry, plDebugApiI); + gptTools = pl_get_api_latest(ptApiRegistry, plToolsI); gptImage = pl_get_api_latest(ptApiRegistry, plImageI); gptGpuAllocators = pl_get_api_latest(ptApiRegistry, plGPUAllocatorsI); gptJob = pl_get_api_latest(ptApiRegistry, plJobI); @@ -178,6 +183,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; } @@ -189,6 +196,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // load extensions ptExtensionRegistry->load("pl_unity_ext", NULL, NULL, false); + ptExtensionRegistry->load("pl_platform_ext", NULL, NULL, false); ptExtensionRegistry->load("pl_example_ext", NULL, NULL, true); // load apis @@ -203,7 +211,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) gptProfile = pl_get_api_latest(ptApiRegistry, plProfileI); gptStats = pl_get_api_latest(ptApiRegistry, plStatsI); gptExample = pl_get_api_latest(ptApiRegistry, plExampleI); - gptDebug = pl_get_api_latest(ptApiRegistry, plDebugApiI); + gptTools = pl_get_api_latest(ptApiRegistry, plToolsI); gptImage = pl_get_api_latest(ptApiRegistry, plImageI); gptGpuAllocators = pl_get_api_latest(ptApiRegistry, plGPUAllocatorsI); gptJob = pl_get_api_latest(ptApiRegistry, plJobI); @@ -216,12 +224,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", @@ -235,6 +248,16 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData) // setup graphics extension pl__setup_graphics_extensions(ptAppData); + // initialize APIs that require it + gptTools->initialize((plToolsInit){.ptDevice = ptAppData->ptDevice}); + + // retrieve some console variables + ptAppData->pbShowLogging = (bool*)gptConsole->get_variable("t.LogTool", NULL, NULL); + ptAppData->pbShowStats = (bool*)gptConsole->get_variable("t.StatTool", NULL, NULL); + ptAppData->pbShowProfiling = (bool*)gptConsole->get_variable("t.ProfileTool", NULL, NULL); + ptAppData->pbShowMemoryAllocations = (bool*)gptConsole->get_variable("t.MemoryAllocationTool", NULL, NULL); + ptAppData->pbShowDeviceMemoryAnalyzer = (bool*)gptConsole->get_variable("t.DeviceMemoryAnalyzerTool", NULL, NULL); + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~setup draw extensions~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // initialize @@ -252,6 +275,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 +315,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 +375,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 +393,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 +415,7 @@ pl_app_update(plAppData* ptAppData) if(ptAppData->bShowUiDebug) gptUi->show_debug_window(&ptAppData->bShowUiDebug); - gptDebug->show_debug_windows(&ptAppData->tDebugInfo); + gptTools->update(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~graphics work~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -411,6 +445,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); @@ -513,6 +551,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);