Fix for compilation on AppleClang 13.1

Fixes #253
This commit is contained in:
Adam Sawicki 2022-03-28 13:21:46 +02:00
parent 35e1539161
commit 3f9f66740a
2 changed files with 31 additions and 6 deletions

View File

@ -2569,6 +2569,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString(
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <utility> #include <utility>
#include <type_traits>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <intrin.h> // For functions like __popcnt, _BitScanForward etc. #include <intrin.h> // 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. // Posts next part of an open string. The number is converted to decimal characters.
void ContinueString(uint32_t n); void ContinueString(uint32_t n);
void ContinueString(uint64_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 // Posts next part of an open string. Pointer value is converted to characters
// using "%p" formatting - shown as hexadecimal number, e.g.: 000000081276Ad00 // using "%p" formatting - shown as hexadecimal number, e.g.: 000000081276Ad00
void ContinueString_Pointer(const void* ptr); void ContinueString_Pointer(const void* ptr);
@ -5500,6 +5502,7 @@ public:
// Writes a number value. // Writes a number value.
void WriteNumber(uint32_t n); void WriteNumber(uint32_t n);
void WriteNumber(uint64_t n); void WriteNumber(uint64_t n);
void WriteSize(size_t n);
// Writes a boolean value - false or true. // Writes a boolean value - false or true.
void WriteBool(bool b); void WriteBool(bool b);
// Writes a null value. // Writes a null value.
@ -5524,6 +5527,11 @@ private:
VmaVector< StackItem, VmaStlAllocator<StackItem> > m_Stack; VmaVector< StackItem, VmaStlAllocator<StackItem> > m_Stack;
bool m_InsideString; bool m_InsideString;
// Write size_t for less than 64bits
void WriteSize(size_t n, std::integral_constant<bool, false>) { m_SB.AddNumber(static_cast<uint32_t>(n)); }
// Write size_t for 64bits
void WriteSize(size_t n, std::integral_constant<bool, true>) { m_SB.AddNumber(static_cast<uint64_t>(n)); }
void BeginValue(bool isString); void BeginValue(bool isString);
void WriteIndent(bool oneLess = false); void WriteIndent(bool oneLess = false);
}; };
@ -5666,6 +5674,14 @@ void VmaJsonWriter::ContinueString(uint64_t n)
m_SB.AddNumber(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<size_t, uint64_t>{});
}
void VmaJsonWriter::ContinueString_Pointer(const void* ptr) void VmaJsonWriter::ContinueString_Pointer(const void* ptr)
{ {
VMA_ASSERT(m_InsideString); VMA_ASSERT(m_InsideString);
@ -5697,6 +5713,15 @@ void VmaJsonWriter::WriteNumber(uint64_t n)
m_SB.AddNumber(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<size_t, uint64_t>{});
}
void VmaJsonWriter::WriteBool(bool b) void VmaJsonWriter::WriteBool(bool b)
{ {
VMA_ASSERT(!m_InsideString); VMA_ASSERT(!m_InsideString);
@ -6445,13 +6470,13 @@ void VmaBlockMetadata::PrintDetailedMap_Begin(class VmaJsonWriter& json,
json.WriteNumber(GetSize()); json.WriteNumber(GetSize());
json.WriteString("UnusedBytes"); json.WriteString("UnusedBytes");
json.WriteNumber(unusedBytes); json.WriteSize(unusedBytes);
json.WriteString("Allocations"); json.WriteString("Allocations");
json.WriteNumber(allocationCount); json.WriteSize(allocationCount);
json.WriteString("UnusedRanges"); json.WriteString("UnusedRanges");
json.WriteNumber(unusedRangeCount); json.WriteSize(unusedRangeCount);
json.WriteString("Suballocations"); json.WriteString("Suballocations");
json.BeginArray(); json.BeginArray();
@ -15978,7 +16003,7 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
{ {
json.WriteString("Name"); json.WriteString("Name");
json.BeginString(); json.BeginString();
json.ContinueString(index++); json.ContinueString_Size(index++);
if (pool->GetName()) if (pool->GetName())
{ {
json.WriteString(" - "); json.WriteString(" - ");

View File

@ -35,8 +35,8 @@ static const char* const SHADER_PATH1 = "./";
static const char* const SHADER_PATH2 = "../bin/"; static const char* const SHADER_PATH2 = "../bin/";
static const wchar_t* const WINDOW_CLASS_NAME = L"VULKAN_MEMORY_ALLOCATOR_SAMPLE"; 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 VALIDATION_LAYER_NAME = "VK_LAYER_KHRONOS_validation";
static const char* const APP_TITLE_A = "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 2.4.0"; static const wchar_t* const APP_TITLE_W = L"Vulkan Memory Allocator Sample 3.0.0";
static const bool VSYNC = true; static const bool VSYNC = true;
static const uint32_t COMMAND_BUFFER_COUNT = 2; static const uint32_t COMMAND_BUFFER_COUNT = 2;