From 1268da7b975979f1cfdd15a8f953e7c6ed8934ba Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 25 Jun 2020 13:03:26 -0400 Subject: [PATCH] Make vulkan_memory_allocator build with the MacOSX11.0 SDK. The 11.0 SDK adds a declaration of aligned_malloc() that's available on macOS 10.15 and later. vulkan_memory_allocator also defines a symbol with the same name, which causes problems. As fix, rename the vulkan_memory_allocator version to vma_aligned_malloc(). Use this opportunity to use the same mechanism on Windows (a no-op), and, while here, call the system aligned_malloc() on macOS 10.15 from there too. Bug: chromium:1098741 Change-Id: If738a1451a08c0813532fc4b778d9118a23210b7 --- src/vk_mem_alloc.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index a880c10..4d577b4 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -3943,7 +3943,7 @@ remove them if not needed. #if defined(__ANDROID_API__) && (__ANDROID_API__ < 16) #include -void *aligned_alloc(size_t alignment, size_t size) +void *vma_aligned_alloc(size_t alignment, size_t size) { // alignment must be >= sizeof(void*) if(alignment < sizeof(void*)) @@ -3955,8 +3955,12 @@ void *aligned_alloc(size_t alignment, size_t size) } #elif defined(__APPLE__) || defined(__ANDROID__) || (defined(__linux__) && defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC)) #include -void *aligned_alloc(size_t alignment, size_t size) +void *vma_aligned_alloc(size_t alignment, size_t size) { +#if defined(__APPLE__) + if (__builtin_available(macOS 10.15, iOS 13, *)) + return aligned_alloc(size, alignment); +#endif // alignment must be >= sizeof(void*) if(alignment < sizeof(void*)) { @@ -3968,6 +3972,16 @@ void *aligned_alloc(size_t alignment, size_t size) return pointer; return VMA_NULL; } +#elif defined(_WIN32) +void *vma_aligned_alloc(size_t alignment, size_t size) +{ + return _aligned_malloc(size, alignment); +} +#else +void *vma_aligned_alloc(size_t alignment, size_t size) +{ + return aligned_alloc(alignment, size); +} #endif // If your compiler is not compatible with C++11 and definition of @@ -3999,11 +4013,7 @@ void *aligned_alloc(size_t alignment, size_t size) #endif #ifndef VMA_SYSTEM_ALIGNED_MALLOC - #if defined(_WIN32) - #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (_aligned_malloc((size), (alignment))) - #else - #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (aligned_alloc((alignment), (size) )) - #endif + #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) vma_aligned_alloc((alignment), (size)) #endif #ifndef VMA_SYSTEM_FREE