From ad90e4b5118f60e6802cc8b88bef8342f9180e26 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 3 May 2022 19:36:30 -0400 Subject: [PATCH] aurora: Add pipeline progress window --- Runtime/ImGuiConsole.cpp | 26 ++++++++++++++++++++++++++ Runtime/ImGuiConsole.hpp | 1 + aurora/lib/gfx/common.cpp | 26 +++++++++++++++++++------- imgui/ImGuiEngine.cpp | 4 ++-- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index 8aadce193..d6b2ae7d7 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -1291,6 +1291,7 @@ void ImGuiConsole::PreUpdate() { ShowDebugOverlay(); ShowInputViewer(); ShowPlayerTransformEditor(); + ShowPipelineProgress(); } void ImGuiConsole::PostUpdate() { @@ -1707,4 +1708,29 @@ void ImGuiConsole::ShowPlayerTransformEditor() { } ImGui::End(); } + +void ImGuiConsole::ShowPipelineProgress() { + if (aurora::gfx::queuedPipelines == 0) { + return; + } + const auto* viewport = ImGui::GetMainViewport(); + const auto padding = viewport->WorkPos.y + 10.f; + const auto halfWidth = viewport->GetWorkCenter().x; + ImGui::SetNextWindowPos(ImVec2{halfWidth, padding}, ImGuiCond_Always, ImVec2{0.5f, 0.f}); + ImGui::SetNextWindowSize(ImVec2{halfWidth, 0.f}, ImGuiCond_Always); + ImGui::SetNextWindowBgAlpha(0.65f); + ImGui::Begin("Pipelines", nullptr, + ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoSavedSettings); + const u32 totalPipelines = aurora::gfx::queuedPipelines + aurora::gfx::createdPipelines; + const auto percent = static_cast(aurora::gfx::createdPipelines) / static_cast(totalPipelines); + const auto progressStr = + fmt::format(FMT_STRING("Processing pipelines: {} / {}"), aurora::gfx::createdPipelines, totalPipelines); + const auto textSize = ImGui::CalcTextSize(progressStr.data(), progressStr.data() + progressStr.size()); + ImGui::NewLine(); + ImGui::SameLine(ImGui::GetWindowWidth() / 2.f - textSize.x + textSize.x / 2.f); + ImGuiStringViewText(progressStr); + ImGui::ProgressBar(percent); + ImGui::End(); +} } // namespace metaforce diff --git a/Runtime/ImGuiConsole.hpp b/Runtime/ImGuiConsole.hpp index 3d6e9f79e..b1e73ff5b 100644 --- a/Runtime/ImGuiConsole.hpp +++ b/Runtime/ImGuiConsole.hpp @@ -115,5 +115,6 @@ private: void SetOverlayWindowLocation(int corner) const; void ShowCornerContextMenu(int& corner, int avoidCorner) const; void ShowPlayerTransformEditor(); + void ShowPipelineProgress(); }; } // namespace metaforce diff --git a/aurora/lib/gfx/common.cpp b/aurora/lib/gfx/common.cpp index 8001dfc6c..a3ca6d4e2 100644 --- a/aurora/lib/gfx/common.cpp +++ b/aurora/lib/gfx/common.cpp @@ -125,7 +125,7 @@ static PipelineRef g_currentPipeline; static std::vector g_commands; -static ByteBuffer g_serializedPipelines; +static ByteBuffer g_serializedPipelines{}; static u32 g_serializedPipelineCount = 0; template @@ -320,7 +320,6 @@ void initialize() { g_state.stream = stream::construct_state(); g_state.model = model::construct_state(); - g_serializedPipelines = {}; { // Load serialized pipeline cache std::ifstream file("pipeline_cache.bin", std::ios::in | std::ios::binary | std::ios::ate); @@ -342,20 +341,33 @@ void initialize() { offset += sizeof(u32); switch (type) { case ShaderType::MoviePlayer: { - const movie_player::PipelineConfig config = + if (size != sizeof(movie_player::PipelineConfig)) { + break; + } + const auto config = *reinterpret_cast(g_serializedPipelines.data() + offset); find_pipeline( type, config, [=]() { return movie_player::create_pipeline(g_state.moviePlayer, config); }, false); } break; case ShaderType::Stream: { - const stream::PipelineConfig config = - *reinterpret_cast(g_serializedPipelines.data() + offset); + if (size != sizeof(stream::PipelineConfig)) { + break; + } + const auto config = *reinterpret_cast(g_serializedPipelines.data() + offset); + if (config.version != gx::GXPipelineConfigVersion) { + break; + } find_pipeline( type, config, [=]() { return stream::create_pipeline(g_state.stream, config); }, false); } break; case ShaderType::Model: { - const model::PipelineConfig config = - *reinterpret_cast(g_serializedPipelines.data() + offset); + if (size != sizeof(model::PipelineConfig)) { + break; + } + const auto config = *reinterpret_cast(g_serializedPipelines.data() + offset); + if (config.version != gx::GXPipelineConfigVersion) { + break; + } find_pipeline( type, config, [=]() { return model::create_pipeline(g_state.model, config); }, false); } break; diff --git a/imgui/ImGuiEngine.cpp b/imgui/ImGuiEngine.cpp index 0c1085e09..0e6701ef3 100644 --- a/imgui/ImGuiEngine.cpp +++ b/imgui/ImGuiEngine.cpp @@ -119,8 +119,8 @@ void ImGuiEngine_Initialize(float scale) { colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f); colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); - colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); - colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + colors[ImGuiCol_PlotHistogram] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); + colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.28f, 0.56f, 1.00f, 1.00f); colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);