From 2798a43674ea25cf616de98a32d124bcdf258e21 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 12 Mar 2025 21:37:59 +0100 Subject: [PATCH] yes --- runtime/Sources/Core/Logs.cpp | 6 ++---- runtime/Sources/Core/SDLManager.cpp | 3 +++ runtime/Sources/Platform/Inputs.cpp | 12 +++++++++++- runtime/Sources/Renderer/Descriptor.cpp | 7 +++++-- runtime/Sources/Renderer/Swapchain.cpp | 12 ++++++++++-- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/runtime/Sources/Core/Logs.cpp b/runtime/Sources/Core/Logs.cpp index 780cb15..ae8721f 100644 --- a/runtime/Sources/Core/Logs.cpp +++ b/runtime/Sources/Core/Logs.cpp @@ -21,10 +21,8 @@ namespace mlx { using namespace std::literals; - #ifndef DEBUG - if(type == LogType::Debug) - return; - #endif + if(type == LogType::Debug && std::getenv("MLX_DEBUG_LOGS") == nullptr) + return; std::string code_infos; if((type == LogType::Error || type == LogType::FatalError) && !file.empty() && !function.empty()) diff --git a/runtime/Sources/Core/SDLManager.cpp b/runtime/Sources/Core/SDLManager.cpp index c6a794a..3736dbc 100644 --- a/runtime/Sources/Core/SDLManager.cpp +++ b/runtime/Sources/Core/SDLManager.cpp @@ -31,6 +31,8 @@ namespace mlx SDL_SetHint(SDL_HINT_VIDEODRIVER, "wayland,x11"); #endif + //SDL_SetHintWithPriority(SDL_HINT_SHUTDOWN_DBUS_ON_QUIT, "1", SDL_HINT_OVERRIDE); + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0) FatalError("SDL: unable to init all subsystems; %", SDL_GetError()); DebugLog("SDL Manager initialized"); @@ -252,6 +254,7 @@ namespace mlx case SDL_WINDOWEVENT_FOCUS_GAINED: functor(MLX_WINDOW_EVENT, id, 5); break; case SDL_WINDOWEVENT_LEAVE: functor(MLX_WINDOW_EVENT, id, 6); break; case SDL_WINDOWEVENT_FOCUS_LOST: functor(MLX_WINDOW_EVENT, id, 7); break; + case SDL_WINDOWEVENT_SIZE_CHANGED: functor(MLX_WINDOW_EVENT, id, 8); break; default : break; } diff --git a/runtime/Sources/Platform/Inputs.cpp b/runtime/Sources/Platform/Inputs.cpp index dd4c905..bf86a1c 100644 --- a/runtime/Sources/Platform/Inputs.cpp +++ b/runtime/Sources/Platform/Inputs.cpp @@ -1,11 +1,19 @@ #include -#include #include #include +#include namespace mlx { + namespace Internal + { + struct ResizeEventBroadcast : public EventBase + { + Event What() const override { return Event::ResizeEventCode; } + }; + } + void Inputs::FetchInputs() { SDLManager::Get().InputsFetcher([this](mlx_event_type event, int window_id, int code) @@ -14,6 +22,8 @@ namespace mlx return; if(!m_events_hooks.contains(window_id) || m_events_hooks[window_id][event].empty()) return; + if(event == MLX_WINDOW_EVENT && code == 8) + EventBus::SendBroadcast(Internal::ResizeEventBroadcast{}); for(const auto& hook : m_events_hooks[window_id][event]) { if(hook.fn) diff --git a/runtime/Sources/Renderer/Descriptor.cpp b/runtime/Sources/Renderer/Descriptor.cpp index ba29b37..aea8595 100644 --- a/runtime/Sources/Renderer/Descriptor.cpp +++ b/runtime/Sources/Renderer/Descriptor.cpp @@ -112,10 +112,13 @@ namespace mlx return set; } - void DescriptorPool::ReturnDescriptorSet(std::shared_ptr set) + void DescriptorPool::ReturnDescriptorSet(std::shared_ptr set) { - auto it = std::find_if(m_used_sets.begin(), m_used_sets.end(), [&](std::shared_ptr rhs_set) + std::size_t i = 0; + auto it = std::find_if(m_used_sets.begin(), m_used_sets.end(), [&](const std::shared_ptr& rhs_set) { + i++; + std::cout << m_used_sets.size() << " " << i << std::endl; return set == rhs_set; }); if(it == m_used_sets.end()) diff --git a/runtime/Sources/Renderer/Swapchain.cpp b/runtime/Sources/Renderer/Swapchain.cpp index a3b0eac..9c08607 100644 --- a/runtime/Sources/Renderer/Swapchain.cpp +++ b/runtime/Sources/Renderer/Swapchain.cpp @@ -15,7 +15,6 @@ namespace mlx Event What() const override { return Event::ResizeEventCode; } }; } - std::string VulkanFormatName(VkFormat format) { @@ -159,7 +158,16 @@ namespace mlx void Swapchain::Init(NonOwningPtr window) { p_window = window; + + std::function functor = [this](const EventBase& event) + { + if(event.What() == Event::ResizeEventCode && !m_resize) + m_resize = true; + }; + EventBus::RegisterListener({ functor, "mlx_swapchain_" + std::to_string(reinterpret_cast(this)) }); + CreateSwapchain(); + m_resize = false; } void Swapchain::AquireFrame(VkSemaphore signal) @@ -170,6 +178,7 @@ namespace mlx Destroy(); CreateSwapchain(); EventBus::SendBroadcast(Internal::ResizeEventBroadcast{}); + m_resize = false; } VkResult result = RenderCore::Get().vkAcquireNextImageKHR(RenderCore::Get().GetDevice(), m_swapchain, UINT64_MAX, signal, VK_NULL_HANDLE, &m_current_image_index); @@ -245,7 +254,6 @@ namespace mlx kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence); kvfDestroyFence(RenderCore::Get().GetDevice(), fence); kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd); - m_resize = false; DebugLog("Vulkan: swapchain created with format %", VulkanFormatName(format)); } }