From 3f9f66740aa6cd8a329cc738c21aaff9020fed46 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Mon, 28 Mar 2022 13:21:46 +0200 Subject: [PATCH] Fix for compilation on AppleClang 13.1 Fixes #253 --- include/vk_mem_alloc.h | 33 +++++++++++++++++++++++++++++---- src/VulkanSample.cpp | 4 ++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 7525264..5589f04 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -2569,6 +2569,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString( #include #include #include +#include #ifdef _MSC_VER #include // For functions like __popcnt, _BitScanForward etc. @@ -5491,6 +5492,7 @@ public: // Posts next part of an open string. The number is converted to decimal characters. void ContinueString(uint32_t n); void ContinueString(uint64_t n); + void ContinueString_Size(size_t n); // Posts next part of an open string. Pointer value is converted to characters // using "%p" formatting - shown as hexadecimal number, e.g.: 000000081276Ad00 void ContinueString_Pointer(const void* ptr); @@ -5500,6 +5502,7 @@ public: // Writes a number value. void WriteNumber(uint32_t n); void WriteNumber(uint64_t n); + void WriteSize(size_t n); // Writes a boolean value - false or true. void WriteBool(bool b); // Writes a null value. @@ -5524,6 +5527,11 @@ private: VmaVector< StackItem, VmaStlAllocator > m_Stack; bool m_InsideString; + // Write size_t for less than 64bits + void WriteSize(size_t n, std::integral_constant) { m_SB.AddNumber(static_cast(n)); } + // Write size_t for 64bits + void WriteSize(size_t n, std::integral_constant) { m_SB.AddNumber(static_cast(n)); } + void BeginValue(bool isString); void WriteIndent(bool oneLess = false); }; @@ -5666,6 +5674,14 @@ void VmaJsonWriter::ContinueString(uint64_t n) m_SB.AddNumber(n); } +void VmaJsonWriter::ContinueString_Size(size_t n) +{ + VMA_ASSERT(m_InsideString); + // Fix for AppleClang incorrect type casting + // TODO: Change to if constexpr when C++17 used as minimal standard + WriteSize(n, std::is_same{}); +} + void VmaJsonWriter::ContinueString_Pointer(const void* ptr) { VMA_ASSERT(m_InsideString); @@ -5697,6 +5713,15 @@ void VmaJsonWriter::WriteNumber(uint64_t n) m_SB.AddNumber(n); } +void VmaJsonWriter::WriteSize(size_t n) +{ + VMA_ASSERT(!m_InsideString); + BeginValue(false); + // Fix for AppleClang incorrect type casting + // TODO: Change to if constexpr when C++17 used as minimal standard + WriteSize(n, std::is_same{}); +} + void VmaJsonWriter::WriteBool(bool b) { VMA_ASSERT(!m_InsideString); @@ -6445,13 +6470,13 @@ void VmaBlockMetadata::PrintDetailedMap_Begin(class VmaJsonWriter& json, json.WriteNumber(GetSize()); json.WriteString("UnusedBytes"); - json.WriteNumber(unusedBytes); + json.WriteSize(unusedBytes); json.WriteString("Allocations"); - json.WriteNumber(allocationCount); + json.WriteSize(allocationCount); json.WriteString("UnusedRanges"); - json.WriteNumber(unusedRangeCount); + json.WriteSize(unusedRangeCount); json.WriteString("Suballocations"); json.BeginArray(); @@ -15978,7 +16003,7 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json) { json.WriteString("Name"); json.BeginString(); - json.ContinueString(index++); + json.ContinueString_Size(index++); if (pool->GetName()) { json.WriteString(" - "); diff --git a/src/VulkanSample.cpp b/src/VulkanSample.cpp index dfc01ad..d7b0db9 100644 --- a/src/VulkanSample.cpp +++ b/src/VulkanSample.cpp @@ -35,8 +35,8 @@ static const char* const SHADER_PATH1 = "./"; static const char* const SHADER_PATH2 = "../bin/"; static const wchar_t* const WINDOW_CLASS_NAME = L"VULKAN_MEMORY_ALLOCATOR_SAMPLE"; static const char* const VALIDATION_LAYER_NAME = "VK_LAYER_KHRONOS_validation"; -static const char* const APP_TITLE_A = "Vulkan Memory Allocator Sample 2.4.0"; -static const wchar_t* const APP_TITLE_W = L"Vulkan Memory Allocator Sample 2.4.0"; +static const char* const APP_TITLE_A = "Vulkan Memory Allocator Sample 3.0.0"; +static const wchar_t* const APP_TITLE_W = L"Vulkan Memory Allocator Sample 3.0.0"; static const bool VSYNC = true; static const uint32_t COMMAND_BUFFER_COUNT = 2;