Skip to content

Commit 3f9f667

Browse files
Fix for compilation on AppleClang 13.1
Fixes #253
1 parent 35e1539 commit 3f9f667

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

include/vk_mem_alloc.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,7 @@ VMA_CALL_PRE void VMA_CALL_POST vmaFreeStatsString(
25692569
#include <cstdlib>
25702570
#include <cstring>
25712571
#include <utility>
2572+
#include <type_traits>
25722573

25732574
#ifdef _MSC_VER
25742575
#include <intrin.h> // For functions like __popcnt, _BitScanForward etc.
@@ -5491,6 +5492,7 @@ class VmaJsonWriter
54915492
// Posts next part of an open string. The number is converted to decimal characters.
54925493
void ContinueString(uint32_t n);
54935494
void ContinueString(uint64_t n);
5495+
void ContinueString_Size(size_t n);
54945496
// Posts next part of an open string. Pointer value is converted to characters
54955497
// using "%p" formatting - shown as hexadecimal number, e.g.: 000000081276Ad00
54965498
void ContinueString_Pointer(const void* ptr);
@@ -5500,6 +5502,7 @@ class VmaJsonWriter
55005502
// Writes a number value.
55015503
void WriteNumber(uint32_t n);
55025504
void WriteNumber(uint64_t n);
5505+
void WriteSize(size_t n);
55035506
// Writes a boolean value - false or true.
55045507
void WriteBool(bool b);
55055508
// Writes a null value.
@@ -5524,6 +5527,11 @@ class VmaJsonWriter
55245527
VmaVector< StackItem, VmaStlAllocator<StackItem> > m_Stack;
55255528
bool m_InsideString;
55265529

5530+
// Write size_t for less than 64bits
5531+
void WriteSize(size_t n, std::integral_constant<bool, false>) { m_SB.AddNumber(static_cast<uint32_t>(n)); }
5532+
// Write size_t for 64bits
5533+
void WriteSize(size_t n, std::integral_constant<bool, true>) { m_SB.AddNumber(static_cast<uint64_t>(n)); }
5534+
55275535
void BeginValue(bool isString);
55285536
void WriteIndent(bool oneLess = false);
55295537
};
@@ -5666,6 +5674,14 @@ void VmaJsonWriter::ContinueString(uint64_t n)
56665674
m_SB.AddNumber(n);
56675675
}
56685676

5677+
void VmaJsonWriter::ContinueString_Size(size_t n)
5678+
{
5679+
VMA_ASSERT(m_InsideString);
5680+
// Fix for AppleClang incorrect type casting
5681+
// TODO: Change to if constexpr when C++17 used as minimal standard
5682+
WriteSize(n, std::is_same<size_t, uint64_t>{});
5683+
}
5684+
56695685
void VmaJsonWriter::ContinueString_Pointer(const void* ptr)
56705686
{
56715687
VMA_ASSERT(m_InsideString);
@@ -5697,6 +5713,15 @@ void VmaJsonWriter::WriteNumber(uint64_t n)
56975713
m_SB.AddNumber(n);
56985714
}
56995715

5716+
void VmaJsonWriter::WriteSize(size_t n)
5717+
{
5718+
VMA_ASSERT(!m_InsideString);
5719+
BeginValue(false);
5720+
// Fix for AppleClang incorrect type casting
5721+
// TODO: Change to if constexpr when C++17 used as minimal standard
5722+
WriteSize(n, std::is_same<size_t, uint64_t>{});
5723+
}
5724+
57005725
void VmaJsonWriter::WriteBool(bool b)
57015726
{
57025727
VMA_ASSERT(!m_InsideString);
@@ -6445,13 +6470,13 @@ void VmaBlockMetadata::PrintDetailedMap_Begin(class VmaJsonWriter& json,
64456470
json.WriteNumber(GetSize());
64466471

64476472
json.WriteString("UnusedBytes");
6448-
json.WriteNumber(unusedBytes);
6473+
json.WriteSize(unusedBytes);
64496474

64506475
json.WriteString("Allocations");
6451-
json.WriteNumber(allocationCount);
6476+
json.WriteSize(allocationCount);
64526477

64536478
json.WriteString("UnusedRanges");
6454-
json.WriteNumber(unusedRangeCount);
6479+
json.WriteSize(unusedRangeCount);
64556480

64566481
json.WriteString("Suballocations");
64576482
json.BeginArray();
@@ -15978,7 +16003,7 @@ void VmaAllocator_T::PrintDetailedMap(VmaJsonWriter& json)
1597816003
{
1597916004
json.WriteString("Name");
1598016005
json.BeginString();
15981-
json.ContinueString(index++);
16006+
json.ContinueString_Size(index++);
1598216007
if (pool->GetName())
1598316008
{
1598416009
json.WriteString(" - ");

src/VulkanSample.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static const char* const SHADER_PATH1 = "./";
3535
static const char* const SHADER_PATH2 = "../bin/";
3636
static const wchar_t* const WINDOW_CLASS_NAME = L"VULKAN_MEMORY_ALLOCATOR_SAMPLE";
3737
static const char* const VALIDATION_LAYER_NAME = "VK_LAYER_KHRONOS_validation";
38-
static const char* const APP_TITLE_A = "Vulkan Memory Allocator Sample 2.4.0";
39-
static const wchar_t* const APP_TITLE_W = L"Vulkan Memory Allocator Sample 2.4.0";
38+
static const char* const APP_TITLE_A = "Vulkan Memory Allocator Sample 3.0.0";
39+
static const wchar_t* const APP_TITLE_W = L"Vulkan Memory Allocator Sample 3.0.0";
4040

4141
static const bool VSYNC = true;
4242
static const uint32_t COMMAND_BUFFER_COUNT = 2;

0 commit comments

Comments
 (0)