adding nesting to debug logs

This commit is contained in:
2024-11-05 12:49:21 +01:00
parent 4ae7bd0420
commit eaf5be3061
16 changed files with 42 additions and 9 deletions

View File

@@ -30,11 +30,16 @@ namespace mlx
static void Report(LogType type, std::string message); static void Report(LogType type, std::string message);
static void Report(LogType type, unsigned int line, std::string_view file, std::string_view function, std::string message); static void Report(LogType type, unsigned int line, std::string_view file, std::string_view function, std::string message);
static void BeginSection();
static void EndSection();
~Logs() = delete; ~Logs() = delete;
private:
static std::uint32_t s_nesting;
}; };
#if defined(DEBUG) #ifdef DEBUG
template<typename... Args> template<typename... Args>
void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args); void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
#else #else

View File

@@ -102,7 +102,7 @@ namespace mlx
} }
} }
#if defined(DEBUG) #ifdef DEBUG
template<typename... Args> template<typename... Args>
void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args) void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args)
{ {

View File

@@ -33,13 +33,11 @@ namespace mlx
inline const Vec4f& GetClearColor() const noexcept { return m_clear_color; } inline const Vec4f& GetClearColor() const noexcept { return m_clear_color; }
[[nodiscard]] MLX_FORCEINLINE const std::vector<std::shared_ptr<Drawable>>& GetDrawables() const noexcept { return m_drawables; } [[nodiscard]] MLX_FORCEINLINE const std::vector<std::shared_ptr<Drawable>>& GetDrawables() const noexcept { return m_drawables; }
[[nodiscard]] MLX_FORCEINLINE ViewerData& GetViewerData() noexcept { return m_viewer_data; }
~Scene() = default; ~Scene() = default;
private: private:
std::vector<std::shared_ptr<Drawable>> m_drawables; std::vector<std::shared_ptr<Drawable>> m_drawables;
ViewerData m_viewer_data;
std::shared_ptr<Font> p_bound_font; std::shared_ptr<Font> p_bound_font;
Vec4f m_clear_color = { 0.0f, 0.0f, 0.0f, 1.0f }; Vec4f m_clear_color = { 0.0f, 0.0f, 0.0f, 1.0f };
}; };

View File

@@ -12,6 +12,10 @@ namespace mlx
}; };
} }
std::uint32_t Logs::s_nesting = 0;
constexpr int LOGS_TABS_WIDTH = 4;
void Logs::Report(LogType type, std::string message) void Logs::Report(LogType type, std::string message)
{ {
Report(type, 0, {}, {}, std::move(message)); Report(type, 0, {}, {}, std::move(message));
@@ -38,7 +42,14 @@ namespace mlx
switch(type) switch(type)
{ {
case LogType::Debug: std::cout << Ansi::blue << "[MLX Debug] " << Ansi::def << code_infos << message << '\n'; break; case LogType::Debug:
{
std::cout << Ansi::blue << "[MLX Debug] " << Ansi::def << std::flush;
std::printf("%*s", s_nesting * LOGS_TABS_WIDTH, "");
std::fflush(stdout);
std::cout << code_infos << message << std::endl;
break;
}
case LogType::Message: std::cout << Ansi::blue << "[MLX Message] " << Ansi::def << code_infos << message << '\n'; break; case LogType::Message: std::cout << Ansi::blue << "[MLX Message] " << Ansi::def << code_infos << message << '\n'; break;
case LogType::Warning: std::cout << Ansi::magenta << "[MLX Warning] " << Ansi::def << code_infos << message << '\n'; break; case LogType::Warning: std::cout << Ansi::magenta << "[MLX Warning] " << Ansi::def << code_infos << message << '\n'; break;
case LogType::Error: std::cerr << Ansi::red << "[MLX Error] " << Ansi::def << code_infos << message << '\n'; break; case LogType::Error: std::cerr << Ansi::red << "[MLX Error] " << Ansi::def << code_infos << message << '\n'; break;
@@ -52,4 +63,15 @@ namespace mlx
EventBus::Send("__MlxApplication", Internal::FatalErrorEvent{}); EventBus::Send("__MlxApplication", Internal::FatalErrorEvent{});
} }
} }
void Logs::BeginSection()
{
s_nesting++;
}
void Logs::EndSection()
{
if(s_nesting > 0)
s_nesting--;
}
} }

View File

@@ -133,15 +133,19 @@ namespace mlx
DebugLog("Vulkan: framebuffer destroyed"); DebugLog("Vulkan: framebuffer destroyed");
} }
m_framebuffers.clear(); m_framebuffers.clear();
kvfDestroyPipelineLayout(RenderCore::Get().GetDevice(), m_pipeline_layout); kvfDestroyPipelineLayout(RenderCore::Get().GetDevice(), m_pipeline_layout);
m_pipeline_layout = VK_NULL_HANDLE; m_pipeline_layout = VK_NULL_HANDLE;
DebugLog("Vulkan: graphics pipeline layout destroyed"); DebugLog("Vulkan: graphics pipeline layout destroyed");
kvfDestroyRenderPass(RenderCore::Get().GetDevice(), m_renderpass); kvfDestroyRenderPass(RenderCore::Get().GetDevice(), m_renderpass);
m_renderpass = VK_NULL_HANDLE; m_renderpass = VK_NULL_HANDLE;
DebugLog("Vulkan: renderpass destroyed"); DebugLog("Vulkan: renderpass destroyed");
kvfDestroyPipeline(RenderCore::Get().GetDevice(), m_pipeline); kvfDestroyPipeline(RenderCore::Get().GetDevice(), m_pipeline);
m_pipeline = VK_NULL_HANDLE; m_pipeline = VK_NULL_HANDLE;
DebugLog("Vulkan: graphics pipeline destroyed"); DebugLog("Vulkan: graphics pipeline destroyed");
p_renderer = nullptr; p_renderer = nullptr;
m_clears.clear(); m_clears.clear();
m_attachments.clear(); m_attachments.clear();

View File

@@ -56,6 +56,7 @@ namespace mlx
return; return;
s_instance = this; s_instance = this;
Logs::BeginSection();
loader = std::make_unique<VulkanLoader>(); loader = std::make_unique<VulkanLoader>();
LoadKVFGlobalVulkanFunctionPointers(); LoadKVFGlobalVulkanFunctionPointers();
@@ -79,6 +80,7 @@ namespace mlx
VkSurfaceKHR surface = window.CreateVulkanSurface(m_instance); VkSurfaceKHR surface = window.CreateVulkanSurface(m_instance);
Logs::BeginSection();
m_physical_device = kvfPickGoodDefaultPhysicalDevice(m_instance, surface); m_physical_device = kvfPickGoodDefaultPhysicalDevice(m_instance, surface);
// just for style // just for style
@@ -94,10 +96,12 @@ namespace mlx
loader->LoadDevice(m_device); loader->LoadDevice(m_device);
LoadKVFDeviceVulkanFunctionPointers(); LoadKVFDeviceVulkanFunctionPointers();
Logs::EndSection();
vkDestroySurfaceKHR(m_instance, surface, nullptr); vkDestroySurfaceKHR(m_instance, surface, nullptr);
m_allocator.Init(); m_allocator.Init();
Logs::EndSection();
} }
#undef MLX_LOAD_FUNCTION #undef MLX_LOAD_FUNCTION

View File

@@ -28,7 +28,7 @@ namespace mlx
}, { ShaderPushConstantLayout({ 0, sizeof(SpriteData) }) } }, { ShaderPushConstantLayout({ 0, sizeof(SpriteData) }) }
); );
std::vector<std::uint8_t> vertex_shader_code = { std::vector<std::uint8_t> vertex_shader_code = {
#include <Embedded/2DVertex.spv.h> #include <Embedded/Shader2DVertex.spv.h>
}; };
p_vertex_shader = std::make_shared<Shader>(vertex_shader_code, ShaderType::Vertex, std::move(vertex_shader_layout)); p_vertex_shader = std::make_shared<Shader>(vertex_shader_code, ShaderType::Vertex, std::move(vertex_shader_layout));
ShaderLayout fragment_shader_layout( ShaderLayout fragment_shader_layout(
@@ -41,7 +41,7 @@ namespace mlx
}, {} }, {}
); );
std::vector<std::uint8_t> fragment_shader_code = { std::vector<std::uint8_t> fragment_shader_code = {
#include <Embedded/2DFragment.spv.h> #include <Embedded/Shader2DFragment.spv.h>
}; };
p_fragment_shader = std::make_shared<Shader>(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout)); p_fragment_shader = std::make_shared<Shader>(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout));

View File

@@ -14,7 +14,7 @@ namespace mlx
{}, {} {}, {}
); );
std::vector<std::uint8_t> vertex_shader_code = { std::vector<std::uint8_t> vertex_shader_code = {
#include <Embedded/ScreenVertex.spv.h> #include <Embedded/ShaderScreenVertex.spv.h>
}; };
p_vertex_shader = std::make_shared<Shader>(vertex_shader_code, ShaderType::Vertex, std::move(vertex_shader_layout)); p_vertex_shader = std::make_shared<Shader>(vertex_shader_code, ShaderType::Vertex, std::move(vertex_shader_layout));
ShaderLayout fragment_shader_layout( ShaderLayout fragment_shader_layout(
@@ -27,7 +27,7 @@ namespace mlx
}, {} }, {}
); );
std::vector<std::uint8_t> fragment_shader_code = { std::vector<std::uint8_t> fragment_shader_code = {
#include <Embedded/ScreenFragment.spv.h> #include <Embedded/ShaderScreenFragment.spv.h>
}; };
p_fragment_shader = std::make_shared<Shader>(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout)); p_fragment_shader = std::make_shared<Shader>(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout));