adding secret bindings

This commit is contained in:
2025-03-12 22:57:29 +01:00
parent 4bd35e72fd
commit 2345cf4417
15 changed files with 137 additions and 11 deletions

View File

@@ -14,6 +14,8 @@ namespace mlx
Handle CreateWindow(const mlx_window_create_info* info, std::int32_t& id, bool hidden);
void DestroyWindow(Handle window) noexcept;
SDL_Window* GetRawWindow(Handle window) noexcept;
void InputsFetcher(std::function<void(mlx_event_type, int, int)> functor);
VkSurfaceKHR CreateVulkanSurface(Handle window, VkInstance instance) const noexcept;

View File

@@ -38,6 +38,8 @@ namespace mlx
MLX_FORCEINLINE std::vector<const char*> GetRequiredVulkanInstanceExtentions() const noexcept { return SDLManager::Get().GetRequiredVulkanInstanceExtentions(p_window); }
MLX_FORCEINLINE Vec2ui GetVulkanDrawableSize() const noexcept { return SDLManager::Get().GetVulkanDrawableSize(p_window); }
[[nodiscard]] inline Handle GetRawHandle() const noexcept { return p_window; }
void Destroy() noexcept;
~Window() { Destroy(); }

View File

@@ -2,11 +2,11 @@
#include <Core/Application.h>
#include <Core/SDLManager.h>
#include <Renderer/RenderCore.h>
#include <mlx.h>
#include <mlx_extended.h>
#include <Core/Memory.h>
#include <Core/Handles.h>
#include <Renderer/RenderCore.h>
static mlx::Application* __internal_application_ptr = nullptr;
@@ -427,4 +427,63 @@ extern "C"
return;
gs->TexturePut(texture, x, y, scale_x, scale_y, angle);
}
// Hidden bindings
VkInstance mlx_get_vk_instance(mlx_context mlx)
{
MLX_CHECK_APPLICATION_POINTER(mlx);
return mlx::RenderCore::Get().GetInstance();
}
VkPhysicalDevice mlx_get_vk_physical_device(mlx_context mlx)
{
MLX_CHECK_APPLICATION_POINTER(mlx);
return mlx::RenderCore::Get().GetPhysicalDevice();
}
VkDevice mlx_get_vk_device(mlx_context mlx)
{
MLX_CHECK_APPLICATION_POINTER(mlx);
return mlx::RenderCore::Get().GetDevice();
}
mlx_function mlx_get_vk_fn(const char* name)
{
#define MLX_VULKAN_GLOBAL_FUNCTION(fn) if(std::strcmp(name, #fn) == 0) return reinterpret_cast<mlx_function>(mlx::RenderCore::Get().fn);
#define MLX_VULKAN_INSTANCE_FUNCTION(fn) if(std::strcmp(name, #fn) == 0) return reinterpret_cast<mlx_function>(mlx::RenderCore::Get().fn);
#define MLX_VULKAN_DEVICE_FUNCTION(fn) if(std::strcmp(name, #fn) == 0) return reinterpret_cast<mlx_function>(mlx::RenderCore::Get().fn);
#include <Renderer/Vulkan/VulkanDefs.h>
#undef MLX_VULKAN_GLOBAL_FUNCTION
#undef MLX_VULKAN_INSTANCE_FUNCTION
#undef MLX_VULKAN_DEVICE_FUNCTION
return nullptr;
}
void* mlx_get_window_handle(mlx_context mlx, mlx_window win)
{
MLX_CHECK_APPLICATION_POINTER(mlx);
mlx::NonOwningPtr<mlx::GraphicsSupport> gs = mlx->app->GetGraphicsSupport(win);
if(!gs || !gs->HasWindow())
return nullptr;
return mlx::SDLManager::Get().GetRawWindow(gs->GetWindow()->GetRawHandle());
}
mlx_function mlx_get_proc_addr(mlx_context mlx, const char* name)
{
MLX_CHECK_APPLICATION_POINTER(mlx);
#define MLX_MAKE_ENTRY(fn) { #fn, reinterpret_cast<mlx_function>(fn) }
std::unordered_map<std::string, mlx_function> entries = {
MLX_MAKE_ENTRY(mlx_get_vk_instance),
MLX_MAKE_ENTRY(mlx_get_vk_physical_device),
MLX_MAKE_ENTRY(mlx_get_vk_device),
MLX_MAKE_ENTRY(mlx_get_vk_fn),
MLX_MAKE_ENTRY(mlx_get_window_handle),
};
auto it = entries.find(std::string{ name });
if(it != entries.end())
return it->second;
return nullptr;
}
}

View File

@@ -21,8 +21,10 @@ namespace mlx
{
using namespace std::literals;
#ifndef DEBUG
if(type == LogType::Debug && std::getenv("MLX_DEBUG_LOGS") == nullptr)
return;
#endif
std::string code_infos;
if((type == LogType::Error || type == LogType::FatalError) && !file.empty() && !function.empty())

View File

@@ -80,6 +80,12 @@ namespace mlx
delete infos;
}
SDL_Window* SDLManager::GetRawWindow(Handle window) noexcept
{
Internal::WindowInfos* infos = static_cast<Internal::WindowInfos*>(window);
return infos->window;
}
VkSurfaceKHR SDLManager::CreateVulkanSurface(Handle window, VkInstance instance) const noexcept
{
VkSurfaceKHR surface;

View File

@@ -114,11 +114,11 @@ namespace mlx
void DescriptorPool::ReturnDescriptorSet(std::shared_ptr<DescriptorSet> set)
{
std::size_t i = 0;
//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;
//i++;
//std::cout << m_used_sets.size() << " " << i << std::endl;
return set == rhs_set;
});
if(it == m_used_sets.end())