fixing valgrind issues, injecting garbage collector inside vulkan's funtions

This commit is contained in:
Kbz-8
2024-12-13 02:51:52 +01:00
parent 5a04ad7781
commit 5d4d97e05d
8 changed files with 165 additions and 160 deletions

View File

@@ -31,6 +31,7 @@
#include <Platform/Window.h>
#include <Maths/Mat4.h>
namespace mlx
{
static std::unique_ptr<VulkanLoader> loader;
@@ -53,6 +54,21 @@ namespace mlx
std::cout << std::endl;
}
void* VulkanAllocationFunction(void*, std::size_t size, std::size_t alignment, VkSystemAllocationScope)
{
return MemManager::AlignedMalloc(alignment, size);
}
void* VulkanReallocationFunction(void*, void* ptr, std::size_t size, std::size_t, VkSystemAllocationScope)
{
return MemManager::Realloc(ptr, size);
}
void VulkanFreeFunction(void*, void* ptr)
{
MemManager::Free(ptr);
}
RenderCore* RenderCore::s_instance = nullptr;
RenderCore::RenderCore()
@@ -102,7 +118,17 @@ namespace mlx
vkDestroySurfaceKHR(m_instance, surface, nullptr);
m_allocator.Init();
VkAllocationCallbacks callbacks;
callbacks.pUserData = nullptr;
callbacks.pfnAllocation = VulkanAllocationFunction;
callbacks.pfnReallocation = VulkanReallocationFunction;
callbacks.pfnFree = VulkanFreeFunction;
callbacks.pfnInternalAllocation = nullptr;
callbacks.pfnInternalFree = nullptr;
kvfSetAllocationCallbacks(m_device, &callbacks);
m_allocator.Init(&callbacks);
}
#undef MLX_LOAD_FUNCTION