From 4e1daad92a13d2a0423120fe6dddbd520ffb9be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Thu, 2 Jun 2022 12:43:06 +0200 Subject: [PATCH] profiler, infodisplay, logging updates --- WickedEngine/wiApplication.cpp | 21 ++++++++++++++++++--- WickedEngine/wiBacklog.cpp | 4 ++-- WickedEngine/wiColor.h | 3 +++ WickedEngine/wiHelper.cpp | 2 +- WickedEngine/wiProfiler.cpp | 18 +++++++++++------- WickedEngine/wiRenderer.cpp | 21 ++++++++++++++++++++- WickedEngine/wiRenderer.h | 2 ++ WickedEngine/wiVersion.cpp | 2 +- 8 files changed, 58 insertions(+), 15 deletions(-) diff --git a/WickedEngine/wiApplication.cpp b/WickedEngine/wiApplication.cpp index c6786cff9..7789e5855 100644 --- a/WickedEngine/wiApplication.cpp +++ b/WickedEngine/wiApplication.cpp @@ -368,15 +368,30 @@ namespace wi infodisplay_str += "Graphics pipelines active: " + std::to_string(graphicsDevice->GetActivePipelineCount()) + "\n"; } + wi::font::Params params = wi::font::Params(4, 4, infoDisplay.size, wi::font::WIFALIGN_LEFT, wi::font::WIFALIGN_TOP, wi::Color(255, 255, 255, 255), wi::Color(0, 0, 0, 255)); + params.cursor = wi::font::Draw(infodisplay_str, params, cmd); + + // Write warnings below: + params.color = wi::Color::Warning(); #ifdef _DEBUG - infodisplay_str += "Warning: This is a [DEBUG] build, performance will be slow!\n"; + params.cursor = wi::font::Draw("Warning: This is a [DEBUG] build, performance will be slow!\n", params, cmd); #endif if (graphicsDevice->IsDebugDevice()) { - infodisplay_str += "Warning: Graphics is in [debugdevice] mode, performance will be slow!\n"; + params.cursor = wi::font::Draw("Warning: Graphics is in [debugdevice] mode, performance will be slow!\n", params, cmd); + } + + // Write errors below: + params.color = wi::Color::Error(); + if (wi::renderer::GetShaderMissingCount() > 0) + { + params.cursor = wi::font::Draw(std::to_string(wi::renderer::GetShaderMissingCount()) + " shaders missing! Check the backlog for more information!\n", params, cmd); + } + if (wi::renderer::GetShaderErrorCount() > 0) + { + params.cursor = wi::font::Draw(std::to_string(wi::renderer::GetShaderErrorCount()) + " shader compilation errors! Check the backlog for more information!\n", params, cmd); } - wi::font::Draw(infodisplay_str, wi::font::Params(4, 4, infoDisplay.size, wi::font::WIFALIGN_LEFT, wi::font::WIFALIGN_TOP, wi::Color(255, 255, 255, 255), wi::Color(0, 0, 0, 255)), cmd); if (infoDisplay.colorgrading_helper) { diff --git a/WickedEngine/wiBacklog.cpp b/WickedEngine/wiBacklog.cpp index 780f36111..e0c066230 100644 --- a/WickedEngine/wiBacklog.cpp +++ b/WickedEngine/wiBacklog.cpp @@ -191,10 +191,10 @@ namespace wi::backlog switch (x.level) { case LogLevel::Warning: - font_params.color = 0xFF66FFFF; // light yellow + font_params.color = wi::Color::Warning(); break; case LogLevel::Error: - font_params.color = 0xFF6666FF; // light red + font_params.color = wi::Color::Error(); break; default: font_params.color = wi::Color::White(); diff --git a/WickedEngine/wiColor.h b/WickedEngine/wiColor.h index 614155048..62453a7ad 100644 --- a/WickedEngine/wiColor.h +++ b/WickedEngine/wiColor.h @@ -68,6 +68,9 @@ namespace wi static constexpr Color Gray() { return Color(127, 127, 127, 255); } static constexpr Color Ghost() { return Color(127, 127, 127, 127); } static constexpr Color Booger() { return Color(127, 127, 127, 200); } + + static constexpr Color Warning() { return 0xFF66FFFF; } // light yellow + static constexpr Color Error() { return 0xFF6666FF; } // light red }; } diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index 493e48d68..af7f826ff 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -660,7 +660,7 @@ namespace wi::helper #endif // PLATFORM_UWP - wi::backlog::post("File not found: " + fileName); + wi::backlog::post("File not found: " + fileName, wi::backlog::LogLevel::Warning); return false; } bool FileRead(const std::string& fileName, wi::vector& data) diff --git a/WickedEngine/wiProfiler.cpp b/WickedEngine/wiProfiler.cpp index 213b7b87f..4f467c720 100644 --- a/WickedEngine/wiProfiler.cpp +++ b/WickedEngine/wiProfiler.cpp @@ -24,6 +24,7 @@ using namespace wi::graphics; namespace wi::profiler { bool ENABLED = false; + bool ENABLED_REQUEST = false; bool initialized = false; std::mutex lock; range_id cpu_frame; @@ -58,6 +59,12 @@ namespace wi::profiler void BeginFrame() { + if (ENABLED_REQUEST != ENABLED) + { + ranges.clear(); + ENABLED = ENABLED_REQUEST; + } + if (!ENABLED) return; @@ -278,8 +285,7 @@ namespace wi::profiler std::stringstream ss(""); ss.precision(2); - ss << "Frame Profiler Ranges:" << std::endl << "----------------------------" << std::endl; - + ss << "Frame Profiler Ranges:\n----------------------------\n"; for (auto& x : ranges) { @@ -347,11 +353,9 @@ namespace wi::profiler void SetEnabled(bool value) { - if (value != ENABLED) - { - ranges.clear(); - ENABLED = value; - } + // Don't enable/disable the profiler immediately, only on the next frame + // to avoid enabling inside a Begin/End by mistake + ENABLED_REQUEST = value; } bool IsEnabled() diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 84c7bbd75..3cedf0c9f 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -28,6 +28,7 @@ #include #include +#include using namespace wi::primitive; using namespace wi::graphics; @@ -102,6 +103,8 @@ bool DDGI_ENABLED = false; bool DDGI_DEBUG_ENABLED = false; uint32_t DDGI_RAYCOUNT = 128u; float GI_BOOST = 1.0f; +std::atomic SHADER_ERRORS{ 0 }; +std::atomic SHADER_MISSING{ 0 }; struct VoxelizedSceneData @@ -626,6 +629,15 @@ size_t GetShaderDumpCount() } #endif // SHADERDUMP +size_t GetShaderErrorCount() +{ + return SHADER_ERRORS.load(); +} +size_t GetShaderMissingCount() +{ + return SHADER_MISSING.load(); +} + bool LoadShader( ShaderStage stage, Shader& shader, @@ -658,7 +670,7 @@ bool LoadShader( } else { - wi::backlog::post("shader dump doesn't contain shader: " + shaderbinaryfilename); + wi::backlog::post("shader dump doesn't contain shader: " + shaderbinaryfilename, wi::backlog::LogLevel::Error); } #endif // SHADERDUMP_ENABLED } @@ -695,6 +707,7 @@ bool LoadShader( else { wi::backlog::post("shader compile FAILED: " + shaderbinaryfilename + "\n" + output.error_message, wi::backlog::LogLevel::Error); + SHADER_ERRORS.fetch_add(1); } } @@ -705,6 +718,10 @@ bool LoadShader( { return device->CreateShader(stage, buffer.data(), buffer.size(), &shader); } + else + { + SHADER_MISSING.fetch_add(1); + } } return false; @@ -2162,6 +2179,8 @@ void SetShaderSourcePath(const std::string& path) void ReloadShaders() { device->ClearPipelineStateCache(); + SHADER_ERRORS.store(0); + SHADER_MISSING.store(0); wi::eventhandler::FireEvent(wi::eventhandler::EVENT_RELOAD_SHADERS, 0); } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 8da9028c8..3d6fc5542 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -66,6 +66,8 @@ namespace wi::renderer // Returns how many shaders are embedded (if wiShaderDump.h is used) // wiShaderDump.h can be generated by OfflineShaderCompiler.exe using shaderdump argument size_t GetShaderDumpCount(); + size_t GetShaderErrorCount(); + size_t GetShaderMissingCount(); bool LoadShader( wi::graphics::ShaderStage stage, diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 71654fa23..4aa61a67a 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 60; // minor bug fixes, alterations, refactors, updates - const int revision = 79; + const int revision = 80; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);