This commit is contained in:
2025-03-12 21:37:59 +01:00
parent f478bb4a9e
commit 2798a43674
5 changed files with 31 additions and 9 deletions

View File

@@ -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())

View File

@@ -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;
}

View File

@@ -1,11 +1,19 @@
#include <PreCompiled.h>
#include <mlx.h>
#include <Platform/Inputs.h>
#include <Core/SDLManager.h>
#include <Core/EventBus.h>
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)

View File

@@ -112,10 +112,13 @@ namespace mlx
return set;
}
void DescriptorPool::ReturnDescriptorSet(std::shared_ptr<class DescriptorSet> set)
void DescriptorPool::ReturnDescriptorSet(std::shared_ptr<DescriptorSet> set)
{
auto it = std::find_if(m_used_sets.begin(), m_used_sets.end(), [&](std::shared_ptr<DescriptorSet> rhs_set)
std::size_t i = 0;
auto it = std::find_if(m_used_sets.begin(), m_used_sets.end(), [&](const std::shared_ptr<DescriptorSet>& rhs_set)
{
i++;
std::cout << m_used_sets.size() << " " << i << std::endl;
return set == rhs_set;
});
if(it == m_used_sets.end())

View File

@@ -16,7 +16,6 @@ namespace mlx
};
}
std::string VulkanFormatName(VkFormat format)
{
#define STRINGIFY(x) case x: return #x
@@ -159,7 +158,16 @@ namespace mlx
void Swapchain::Init(NonOwningPtr<Window> window)
{
p_window = window;
std::function<void(const EventBase&)> 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<std::uintptr_t>(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));
}
}