1/* 2 * Copyright 2021 Google LLC 3 * SPDX-License-Identifier: MIT 4 */ 5 6#include "vk_alloc.h" 7 8#include <stdlib.h> 9 10#ifndef _MSC_VER 11#include <stddef.h> 12#define MAX_ALIGN alignof(max_align_t) 13#else 14/* long double might be 128-bit, but our callers do not need that anyway(?) */ 15#include <stdint.h> 16#define MAX_ALIGN alignof(uint64_t) 17#endif 18 19static VKAPI_ATTR void * VKAPI_CALL 20vk_default_alloc(void *pUserData, 21 size_t size, 22 size_t alignment, 23 VkSystemAllocationScope allocationScope) 24{ 25 assert(MAX_ALIGN % alignment == 0); 26 return malloc(size); 27} 28 29static VKAPI_ATTR void * VKAPI_CALL 30vk_default_realloc(void *pUserData, 31 void *pOriginal, 32 size_t size, 33 size_t alignment, 34 VkSystemAllocationScope allocationScope) 35{ 36 assert(MAX_ALIGN % alignment == 0); 37 return realloc(pOriginal, size); 38} 39 40static VKAPI_ATTR void VKAPI_CALL 41vk_default_free(void *pUserData, void *pMemory) 42{ 43 free(pMemory); 44} 45 46const VkAllocationCallbacks * 47vk_default_allocator(void) 48{ 49 static const VkAllocationCallbacks allocator = { 50 .pfnAllocation = vk_default_alloc, 51 .pfnReallocation = vk_default_realloc, 52 .pfnFree = vk_default_free, 53 }; 54 return &allocator; 55} 56