// ============================================= // Aster: global.cpp // Copyright (c) 2020-2024 Anish Bhobe // ============================================= #include "global.h" #include #include #define VMA_IMPLEMENTATION #include // NOTE: Vulkan Dispatch Loader Storage - Should only appear once. VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE struct MemorySize { u16 m_Gigabytes; u16 m_Megabytes; u16 m_Kilobytes; u16 m_Bytes; MemorySize & operator+=(usize bytes) { usize totalBytes = bytes + m_Bytes; m_Bytes = totalBytes % 1024; const usize totalKb = m_Kilobytes + totalBytes / 1024; m_Kilobytes = totalKb % 1024; const usize totalMb = m_Megabytes + totalKb / 1024; m_Megabytes = totalMb % 1024; m_Gigabytes += totalMb / 1024; return *this; } }; MemorySize g_TotalAlloc = {}; template <> struct fmt::formatter { // ReSharper disable once CppInconsistentNaming constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); } template // ReSharper disable once CppInconsistentNaming constexpr auto format(MemorySize const &mem, Context &ctx) const { // return format_to(ctx.out(), "({}, {})", foo.a, foo.b); // --== KEY LINE ==-- if (mem.m_Gigabytes > 0) { return v11::format_to(ctx.out(), "{}.{} GB", mem.m_Gigabytes, Cast(mem.m_Megabytes / 1024.0)); } if (mem.m_Megabytes > 0) { return v11::format_to(ctx.out(), "{}.{} MB", mem.m_Megabytes, Cast(mem.m_Kilobytes / 1024.0)); } if (mem.m_Kilobytes > 0) { return v11::format_to(ctx.out(), "{}.{} KB", mem.m_Kilobytes, Cast(mem.m_Bytes / 1024.0)); } return v11::format_to(ctx.out(), "{} Bytes", mem.m_Bytes); } }; void * operator new[](size_t size, const char * /*pName*/, int flags, unsigned /*debugFlags*/, const char * /*file*/, int /*line*/) { g_TotalAlloc += size; VERBOSE("Total: {} - Allocated {} bytes. ({})", g_TotalAlloc, size, (flags & eastl::MEM_TEMP) ? "temp" : "perm"); return new u8[size]; } void * operator new[](size_t size, size_t /*alignment*/, size_t /*alignmentOffset*/, const char * /*pName*/, int flags, unsigned /*debugFlags*/, const char * /*file*/, int /*line*/) { g_TotalAlloc += size; VERBOSE("Total: {} - Allocated {} bytes. ({})", g_TotalAlloc, size, (flags & eastl::MEM_TEMP) ? "temp" : "perm"); return new u8[size]; }