@@ -35,14 +35,15 @@ static const wchar_t* const APP_TITLE_W = L"Vulkan Memory Allocator Sample 2.0";
35
35
36
36
static const bool VSYNC = true ;
37
37
static const uint32_t COMMAND_BUFFER_COUNT = 2 ;
38
-
39
- static bool g_EnableValidationLayer = true ;
38
+ static void * const CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA = ( void *)( intptr_t ) 43564544 ;
39
+ static const bool USE_CUSTOM_CPU_ALLOCATION_CALLBACKS = false ;
40
40
41
41
VkPhysicalDevice g_hPhysicalDevice;
42
42
VkDevice g_hDevice;
43
43
VmaAllocator g_hAllocator;
44
44
bool g_MemoryAliasingWarningEnabled = true ;
45
45
46
+ static bool g_EnableValidationLayer = true ;
46
47
static bool VK_KHR_get_memory_requirements2_enabled = false ;
47
48
static bool VK_KHR_dedicated_allocation_enabled = false ;
48
49
@@ -102,6 +103,28 @@ static VkImage g_hTextureImage;
102
103
static VmaAllocation g_hTextureImageAlloc;
103
104
static VkImageView g_hTextureImageView;
104
105
106
+ static void * CustomCpuAllocation (
107
+ void * pUserData, size_t size, size_t alignment,
108
+ VkSystemAllocationScope allocationScope)
109
+ {
110
+ assert (pUserData == CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA);
111
+ return _aligned_malloc (size, alignment);
112
+ }
113
+
114
+ static void * CustomCpuReallocation (
115
+ void * pUserData, void * pOriginal, size_t size, size_t alignment,
116
+ VkSystemAllocationScope allocationScope)
117
+ {
118
+ assert (pUserData == CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA);
119
+ return _aligned_realloc (pOriginal, size, alignment);
120
+ }
121
+
122
+ static void CustomCpuFree (void * pUserData, void * pMemory)
123
+ {
124
+ assert (pUserData == CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA);
125
+ _aligned_free (pMemory);
126
+ }
127
+
105
128
static void BeginSingleTimeCommands ()
106
129
{
107
130
VkCommandBufferBeginInfo cmdBufBeginInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
@@ -1255,10 +1278,22 @@ static void InitializeApplication()
1255
1278
VmaAllocatorCreateInfo allocatorInfo = {};
1256
1279
allocatorInfo.physicalDevice = g_hPhysicalDevice;
1257
1280
allocatorInfo.device = g_hDevice;
1281
+
1258
1282
if (VK_KHR_dedicated_allocation_enabled)
1259
1283
{
1260
1284
allocatorInfo.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT;
1261
1285
}
1286
+
1287
+ VkAllocationCallbacks cpuAllocationCallbacks = {};
1288
+ if (USE_CUSTOM_CPU_ALLOCATION_CALLBACKS)
1289
+ {
1290
+ cpuAllocationCallbacks.pUserData = CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA;
1291
+ cpuAllocationCallbacks.pfnAllocation = &CustomCpuAllocation;
1292
+ cpuAllocationCallbacks.pfnReallocation = &CustomCpuReallocation;
1293
+ cpuAllocationCallbacks.pfnFree = &CustomCpuFree;
1294
+ allocatorInfo.pAllocationCallbacks = &cpuAllocationCallbacks;
1295
+ }
1296
+
1262
1297
ERR_GUARD_VULKAN ( vmaCreateAllocator (&allocatorInfo, &g_hAllocator) );
1263
1298
1264
1299
// Retrieve queue (doesn't need to be destroyed)
0 commit comments