#include <stdlib.h>
-void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope alloc_scope) {
+// A debug option to disable allocators at compile time to investigate future issues.
+#define DEBUG_DISABLE_APP_ALLOCATORS 0
+
+void *loader_alloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope) {
void *pMemory = NULL;
#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
{
#else
- if (instance && instance->alloc_callbacks.pfnAllocation) {
+ if (pAllocator && pAllocator->pfnAllocation) {
// These are internal structures, so it's best to align everything to
// the largest unit size which is the size of a uint64_t.
- pMemory = instance->alloc_callbacks.pfnAllocation(instance->alloc_callbacks.pUserData, size, sizeof(uint64_t), alloc_scope);
+ pMemory = pAllocator->pfnAllocation(pAllocator->pUserData, size, sizeof(uint64_t), allocation_scope);
} else {
#endif
pMemory = malloc(size);
return pMemory;
}
-void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory) {
- if (pMemory != NULL) {
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (instance && instance->alloc_callbacks.pfnFree) {
- instance->alloc_callbacks.pfnFree(instance->alloc_callbacks.pUserData, pMemory);
- } else {
-#endif
- free(pMemory);
- }
- }
-}
-
-void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size,
- VkSystemAllocationScope alloc_scope) {
- void *pNewMem = NULL;
- if (pMemory == NULL || orig_size == 0) {
- pNewMem = loader_instance_heap_alloc(instance, size, alloc_scope);
- } else if (size == 0) {
- loader_instance_heap_free(instance, pMemory);
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
-#else
- } else if (instance && instance->alloc_callbacks.pfnReallocation) {
- // These are internal structures, so it's best to align everything to
- // the largest unit size which is the size of a uint64_t.
- pNewMem = instance->alloc_callbacks.pfnReallocation(instance->alloc_callbacks.pUserData, pMemory, size, sizeof(uint64_t),
- alloc_scope);
-#endif
- } else {
- pNewMem = realloc(pMemory, size);
- }
- return pNewMem;
-}
-
-void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope alloc_scope) {
+void *loader_calloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope) {
void *pMemory = NULL;
#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
{
#else
- if (device && device->alloc_callbacks.pfnAllocation) {
+ if (pAllocator && pAllocator->pfnAllocation) {
// These are internal structures, so it's best to align everything to
// the largest unit size which is the size of a uint64_t.
- pMemory = device->alloc_callbacks.pfnAllocation(device->alloc_callbacks.pUserData, size, sizeof(uint64_t), alloc_scope);
+ pMemory = pAllocator->pfnAllocation(pAllocator->pUserData, size, sizeof(uint64_t), allocation_scope);
+ if (pMemory) {
+ memset(pMemory, 0, size);
+ }
} else {
#endif
- pMemory = malloc(size);
+ pMemory = calloc(1, size);
}
+
return pMemory;
}
-void loader_device_heap_free(const struct loader_device *device, void *pMemory) {
+void loader_free(const VkAllocationCallbacks *pAllocator, void *pMemory) {
if (pMemory != NULL) {
#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
{
#else
- if (device && device->alloc_callbacks.pfnFree) {
- device->alloc_callbacks.pfnFree(device->alloc_callbacks.pUserData, pMemory);
+ if (pAllocator && pAllocator->pfnFree) {
+ pAllocator->pfnFree(pAllocator->pUserData, pMemory);
} else {
#endif
free(pMemory);
}
}
-void *loader_device_heap_realloc(const struct loader_device *device, void *pMemory, size_t orig_size, size_t size,
- VkSystemAllocationScope alloc_scope) {
+void *loader_realloc(const VkAllocationCallbacks *pAllocator, void *pMemory, size_t orig_size, size_t size,
+ VkSystemAllocationScope allocation_scope) {
void *pNewMem = NULL;
if (pMemory == NULL || orig_size == 0) {
- pNewMem = loader_device_heap_alloc(device, size, alloc_scope);
+ pNewMem = loader_alloc(pAllocator, size, allocation_scope);
} else if (size == 0) {
- loader_device_heap_free(device, pMemory);
+ loader_free(pAllocator, pMemory);
#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
#else
- } else if (device && device->alloc_callbacks.pfnReallocation) {
+ } else if (pAllocator && pAllocator->pfnReallocation) {
// These are internal structures, so it's best to align everything to
// the largest unit size which is the size of a uint64_t.
- pNewMem = device->alloc_callbacks.pfnReallocation(device->alloc_callbacks.pUserData, pMemory, size, sizeof(uint64_t),
- alloc_scope);
+ pNewMem = pAllocator->pfnReallocation(pAllocator->pUserData, pMemory, size, sizeof(uint64_t), allocation_scope);
#endif
} else {
pNewMem = realloc(pMemory, size);
}
return pNewMem;
-}
\ No newline at end of file
+}
+
+void *loader_instance_heap_alloc(const struct loader_instance *inst, size_t size, VkSystemAllocationScope allocation_scope) {
+ return loader_alloc(inst ? &inst->alloc_callbacks : NULL, size, allocation_scope);
+}
+
+void *loader_instance_heap_calloc(const struct loader_instance *inst, size_t size, VkSystemAllocationScope allocation_scope) {
+ return loader_calloc(inst ? &inst->alloc_callbacks : NULL, size, allocation_scope);
+}
+
+void loader_instance_heap_free(const struct loader_instance *inst, void *pMemory) {
+ loader_free(inst ? &inst->alloc_callbacks : NULL, pMemory);
+}
+void *loader_instance_heap_realloc(const struct loader_instance *inst, void *pMemory, size_t orig_size, size_t size,
+ VkSystemAllocationScope allocation_scope) {
+ return loader_realloc(inst ? &inst->alloc_callbacks : NULL, pMemory, orig_size, size, allocation_scope);
+}
+
+void *loader_device_heap_alloc(const struct loader_device *dev, size_t size, VkSystemAllocationScope allocation_scope) {
+ return loader_alloc(dev ? &dev->alloc_callbacks : NULL, size, allocation_scope);
+}
+
+void *loader_device_heap_calloc(const struct loader_device *dev, size_t size, VkSystemAllocationScope allocation_scope) {
+ return loader_calloc(dev ? &dev->alloc_callbacks : NULL, size, allocation_scope);
+}
+
+void loader_device_heap_free(const struct loader_device *dev, void *pMemory) {
+ loader_free(dev ? &dev->alloc_callbacks : NULL, pMemory);
+}
+void *loader_device_heap_realloc(const struct loader_device *dev, void *pMemory, size_t orig_size, size_t size,
+ VkSystemAllocationScope allocation_scope) {
+ return loader_realloc(dev ? &dev->alloc_callbacks : NULL, pMemory, orig_size, size, allocation_scope);
+}
+
+void *loader_alloc_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *inst, size_t size,
+ VkSystemAllocationScope allocation_scope) {
+ return loader_alloc(NULL != pAllocator ? pAllocator : &inst->alloc_callbacks, size, allocation_scope);
+}
+
+void *loader_calloc_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
+ size_t size, VkSystemAllocationScope allocation_scope) {
+ return loader_calloc(NULL != pAllocator ? pAllocator : &instance->alloc_callbacks, size, allocation_scope);
+}
+
+void loader_free_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
+ void *pMemory) {
+ loader_free(NULL != pAllocator ? pAllocator : &instance->alloc_callbacks, pMemory);
+}
+
+void *loader_realloc_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
+ void *pMemory, size_t orig_size, size_t size,
+ VkSystemAllocationScope allocation_scope) {
+ return loader_realloc(NULL != pAllocator ? pAllocator : &instance->alloc_callbacks, pMemory, orig_size, size, allocation_scope);
+}
#include "loader_common.h"
-void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope allocationScope);
+void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope allocation_scope);
+void *loader_instance_heap_calloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope allocation_scope);
void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory);
void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size,
- VkSystemAllocationScope alloc_scope);
+ VkSystemAllocationScope allocation_scope);
+
void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope allocationScope);
+void *loader_device_heap_calloc(const struct loader_device *device, size_t size, VkSystemAllocationScope allocationScope);
void loader_device_heap_free(const struct loader_device *device, void *pMemory);
void *loader_device_heap_realloc(const struct loader_device *device, void *pMemory, size_t orig_size, size_t size,
VkSystemAllocationScope alloc_scope);
+// Wrappers around various memory functions. The loader will use the VkAllocationCallbacks functions if pAllocator is not NULL,
+// otherwise use the system functions
+void *loader_alloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope);
+void *loader_calloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope);
+void loader_free(const VkAllocationCallbacks *pAllocator, void *pMemory);
+void *loader_realloc(const VkAllocationCallbacks *pAllocator, void *pMemory, size_t orig_size, size_t size,
+ VkSystemAllocationScope allocation_scope);
+
+// helper allocation functions that will use pAllocator and if it is NULL, fallback to the allocator of instance
+void *loader_alloc_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
+ size_t size, VkSystemAllocationScope allocation_scope);
+void *loader_calloc_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
+ size_t size, VkSystemAllocationScope allocation_scope);
+void loader_free_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
+ void *pMemory);
+void *loader_realloc_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
+ void *pMemory, size_t orig_size, size_t size, VkSystemAllocationScope allocation_scope);
+
#if defined(__linux__) || defined(__APPLE__) || defined(__Fuchsia__) || defined(__QNXNTO__) || defined(__FreeBSD__)
#define loader_stack_alloc(size) alloca(size)
#elif defined(_WIN32)
#define loader_stack_alloc(size) _alloca(size)
-#endif // defined(_WIN32)
\ No newline at end of file
+#endif // defined(_WIN32)
const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT messenger) {
VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL;
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pNewDbgFuncNode = (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode),
- sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- } else {
-#endif
- pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_instance_heap_alloc(inst, sizeof(VkLayerDbgFunctionNode),
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- }
+ pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_calloc_with_instance_fallback(
+ pAllocator, inst, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+
if (!pNewDbgFuncNode) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
- memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode));
pNewDbgFuncNode->is_messenger = true;
pNewDbgFuncNode->messenger.messenger = messenger;
if (pTrav->is_messenger && pTrav->messenger.messenger == messenger) {
pPrev->pNext = pTrav->pNext;
if (inst->DbgFunctionHead == pTrav) inst->DbgFunctionHead = pTrav->pNext;
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pAllocator->pfnFree(pAllocator->pUserData, pTrav);
- } else {
-#endif
- loader_instance_heap_free(inst, pTrav);
- }
+ loader_free_with_instance_fallback(pAllocator, inst, pTrav);
break;
}
pPrev = pTrav;
return VK_SUCCESS;
}
-// 2nd, allocate memory for each VkDebugUtilsMessengerCreateInfoEXT:
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pInfos = *infos = ((VkDebugUtilsMessengerCreateInfoEXT *)pAllocator->pfnAllocation(
- pAllocator->pUserData, n * sizeof(VkDebugUtilsMessengerCreateInfoEXT), sizeof(void *),
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
- } else {
-#endif
- pInfos = *infos = ((VkDebugUtilsMessengerCreateInfoEXT *)malloc(n * sizeof(VkDebugUtilsMessengerCreateInfoEXT)));
- }
+ // 2nd, allocate memory for each VkDebugUtilsMessengerCreateInfoEXT:
+ pInfos = *infos = ((VkDebugUtilsMessengerCreateInfoEXT *)loader_alloc(
+ pAllocator, n * sizeof(VkDebugUtilsMessengerCreateInfoEXT), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
+
if (!pInfos) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
-// 3rd, allocate memory for a unique handle for each callback:
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pMessengers = *messengers = ((VkDebugUtilsMessengerEXT *)pAllocator->pfnAllocation(
- pAllocator->pUserData, n * sizeof(VkDebugUtilsMessengerEXT), sizeof(void *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
- if (NULL == pMessengers) {
- pAllocator->pfnFree(pAllocator->pUserData, pInfos);
- return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
- } else {
-#endif
- pMessengers = *messengers = ((VkDebugUtilsMessengerEXT *)malloc(n * sizeof(VkDebugUtilsMessengerEXT)));
- if (NULL == pMessengers) {
- free(pInfos);
- return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
+ // 3rd, allocate memory for a unique handle for each callback:
+ pMessengers = *messengers = ((VkDebugUtilsMessengerEXT *)loader_alloc(pAllocator, n * sizeof(VkDebugUtilsMessengerEXT),
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
+ if (NULL == pMessengers) {
+ loader_free(pAllocator, pInfos);
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
}
// 4th, copy each VkDebugUtilsMessengerCreateInfoEXT for use by
// vkDestroyInstance, and assign a unique handle to each messenger (just
void util_FreeDebugUtilsMessengerCreateInfos(const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerCreateInfoEXT *infos,
VkDebugUtilsMessengerEXT *messengers) {
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pAllocator->pfnFree(pAllocator->pUserData, infos);
- pAllocator->pfnFree(pAllocator->pUserData, messengers);
- } else {
-#endif
- free(infos);
- free(messengers);
- }
+ loader_free(pAllocator, infos);
+ loader_free(pAllocator, messengers);
}
VkResult util_CreateDebugUtilsMessengers(struct loader_instance *inst, const VkAllocationCallbacks *pAllocator,
uint32_t storage_idx;
VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL;
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- icd_info = ((VkDebugUtilsMessengerEXT *)pAllocator->pfnAllocation(pAllocator->pUserData,
- inst->total_icd_count * sizeof(VkDebugUtilsMessengerEXT),
- sizeof(void *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
- if (icd_info) {
- memset(icd_info, 0, inst->total_icd_count * sizeof(VkDebugUtilsMessengerEXT));
- }
- } else {
-#endif
- icd_info = calloc(sizeof(VkDebugUtilsMessengerEXT), inst->total_icd_count);
- }
+ icd_info = (VkDebugUtilsMessengerEXT *)loader_calloc_with_instance_fallback(
+ pAllocator, inst, inst->total_icd_count * sizeof(VkDebugUtilsMessengerEXT), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+
if (!icd_info) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
storage_idx++;
}
-// Setup the debug report callback in the terminator since a layer may want
-// to grab the information itself (RenderDoc) and then return back to the
-// user callback a sub-set of the messages.
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 0)
- if (pAllocator != NULL) {
- pNewDbgFuncNode = (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode),
- sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- } else {
-#else
- {
-#endif
- pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_instance_heap_alloc(inst, sizeof(VkLayerDbgFunctionNode),
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- }
+ // Setup the debug report callback in the terminator since a layer may want
+ // to grab the information itself (RenderDoc) and then return back to the
+ // user callback a sub-set of the messages.
+ pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_calloc_with_instance_fallback(
+ pAllocator, inst, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!pNewDbgFuncNode) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
- memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode));
pNewDbgFuncNode->is_messenger = true;
pNewDbgFuncNode->messenger.pfnUserCallback = pCreateInfo->pfnUserCallback;
}
storage_idx++;
}
-
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- if (NULL != pNewDbgFuncNode) {
- pAllocator->pfnFree(pAllocator->pUserData, pNewDbgFuncNode);
- }
- if (NULL != icd_info) {
- pAllocator->pfnFree(pAllocator->pUserData, icd_info);
- }
- } else {
-#endif
- if (NULL != pNewDbgFuncNode) {
- free(pNewDbgFuncNode);
- }
- if (NULL != icd_info) {
- free(icd_info);
- }
- }
+ loader_free(pAllocator, pNewDbgFuncNode);
+ loader_free(pAllocator, icd_info);
}
return res;
util_DestroyDebugUtilsMessenger(inst, messenger, pAllocator);
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pAllocator->pfnFree(pAllocator->pUserData, icd_info);
- } else {
-#endif
- free(icd_info);
- }
+ loader_free(pAllocator, icd_info);
}
// This is the instance chain terminator function for SubmitDebugUtilsMessageEXT
const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT callback) {
VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL;
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pNewDbgFuncNode = (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode),
- sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- } else {
-#endif
- pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_instance_heap_alloc(inst, sizeof(VkLayerDbgFunctionNode),
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- }
+ pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_calloc_with_instance_fallback(
+ pAllocator, inst, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!pNewDbgFuncNode) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
- memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode));
pNewDbgFuncNode->is_messenger = false;
pNewDbgFuncNode->report.msgCallback = callback;
if (!pTrav->is_messenger && pTrav->report.msgCallback == callback) {
pPrev->pNext = pTrav->pNext;
if (inst->DbgFunctionHead == pTrav) inst->DbgFunctionHead = pTrav->pNext;
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pAllocator->pfnFree(pAllocator->pUserData, pTrav);
- } else {
-#endif
- loader_instance_heap_free(inst, pTrav);
- }
+ loader_free_with_instance_fallback(pAllocator, inst, pTrav);
break;
}
pPrev = pTrav;
return VK_SUCCESS;
}
-// 2nd, allocate memory for each VkDebugReportCallbackCreateInfoEXT:
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pInfos = *infos = ((VkDebugReportCallbackCreateInfoEXT *)pAllocator->pfnAllocation(
- pAllocator->pUserData, n * sizeof(VkDebugReportCallbackCreateInfoEXT), sizeof(void *),
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
- } else {
-#endif
- pInfos = *infos = ((VkDebugReportCallbackCreateInfoEXT *)malloc(n * sizeof(VkDebugReportCallbackCreateInfoEXT)));
- }
+ // 2nd, allocate memory for each VkDebugReportCallbackCreateInfoEXT:
+ pInfos = *infos = ((VkDebugReportCallbackCreateInfoEXT *)loader_alloc(
+ pAllocator, n * sizeof(VkDebugReportCallbackCreateInfoEXT), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
if (!pInfos) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
-// 3rd, allocate memory for a unique handle for each callback:
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pCallbacks = *callbacks = ((VkDebugReportCallbackEXT *)pAllocator->pfnAllocation(
- pAllocator->pUserData, n * sizeof(VkDebugReportCallbackEXT), sizeof(void *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
- if (!pCallbacks) {
- pAllocator->pfnFree(pAllocator->pUserData, pInfos);
- return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
- } else {
-#endif
- pCallbacks = *callbacks = ((VkDebugReportCallbackEXT *)malloc(n * sizeof(VkDebugReportCallbackEXT)));
- if (!pCallbacks) {
- free(pInfos);
- return VK_ERROR_OUT_OF_HOST_MEMORY;
- }
+ // 3rd, allocate memory for a unique handle for each callback:
+
+ pCallbacks = *callbacks = ((VkDebugReportCallbackEXT *)loader_alloc(pAllocator, n * sizeof(VkDebugReportCallbackEXT),
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
+ if (!pCallbacks) {
+ loader_free(pAllocator, pInfos);
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
}
+
// 4th, copy each VkDebugReportCallbackCreateInfoEXT for use by
// vkDestroyInstance, and assign a unique handle to each callback (just
// use the address of the copied VkDebugReportCallbackCreateInfoEXT):
void util_FreeDebugReportCreateInfos(const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackCreateInfoEXT *infos,
VkDebugReportCallbackEXT *callbacks) {
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pAllocator->pfnFree(pAllocator->pUserData, infos);
- pAllocator->pfnFree(pAllocator->pUserData, callbacks);
- } else {
-#endif
- free(infos);
- free(callbacks);
- }
+ loader_free(pAllocator, infos);
+ loader_free(pAllocator, callbacks);
}
VkResult util_CreateDebugReportCallbacks(struct loader_instance *inst, const VkAllocationCallbacks *pAllocator,
const char *pMsg) {
struct loader_instance *inst = loader_get_instance(instance);
- inst->disp->layer_inst_disp.DebugReportMessageEXT(inst->instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
+ inst->disp->layer_inst_disp.DebugReportMessageEXT(inst->instance, flags, objType, object, location, msgCode, pLayerPrefix,
+ pMsg);
}
// This is the instance chain terminator function
uint32_t storage_idx;
VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL;
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- icd_info = ((VkDebugReportCallbackEXT *)pAllocator->pfnAllocation(pAllocator->pUserData,
- inst->total_icd_count * sizeof(VkDebugReportCallbackEXT),
- sizeof(void *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
- if (icd_info) {
- memset(icd_info, 0, inst->total_icd_count * sizeof(VkDebugReportCallbackEXT));
- }
- } else {
-#endif
- icd_info = calloc(sizeof(VkDebugReportCallbackEXT), inst->total_icd_count);
- }
+ icd_info = ((VkDebugReportCallbackEXT *)loader_calloc(pAllocator, inst->total_icd_count * sizeof(VkDebugReportCallbackEXT),
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT));
if (!icd_info) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
storage_idx++;
}
-// Setup the debug report callback in the terminator since a layer may want
-// to grab the information itself (RenderDoc) and then return back to the
-// user callback a sub-set of the messages.
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 0)
- if (pAllocator != NULL) {
- pNewDbgFuncNode = (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode),
- sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- } else {
-#else
- {
-#endif
- pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_instance_heap_alloc(inst, sizeof(VkLayerDbgFunctionNode),
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- }
+ // Setup the debug report callback in the terminator since a layer may want
+ // to grab the information itself (RenderDoc) and then return back to the
+ // user callback a sub-set of the messages.
+ pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_calloc_with_instance_fallback(
+ pAllocator, inst, sizeof(VkLayerDbgFunctionNode), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+
if (!pNewDbgFuncNode) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
- memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode));
pNewDbgFuncNode->is_messenger = false;
pNewDbgFuncNode->report.pfnMsgCallback = pCreateInfo->pfnCallback;
}
storage_idx++;
}
-
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- if (NULL != pNewDbgFuncNode) {
- pAllocator->pfnFree(pAllocator->pUserData, pNewDbgFuncNode);
- }
- if (NULL != icd_info) {
- pAllocator->pfnFree(pAllocator->pUserData, icd_info);
- }
- } else {
-#endif
- if (NULL != pNewDbgFuncNode) {
- free(pNewDbgFuncNode);
- }
- if (NULL != icd_info) {
- free(icd_info);
- }
- }
+ loader_free(pAllocator, pNewDbgFuncNode);
+ loader_free(pAllocator, icd_info);
}
return res;
util_DestroyDebugReportCallback(inst, callback, pAllocator);
-#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
- {
-#else
- if (pAllocator != NULL) {
- pAllocator->pfnFree(pAllocator->pUserData, icd_info);
- } else {
-#endif
- free(icd_info);
- }
+ loader_free(pAllocator, icd_info);
}
// This is the instance chain terminator function for DebugReportMessage