diff options
| author | Courtney Goeltzenleuchter <courtney@LunarG.com> | 2015-07-06 09:08:37 -0600 |
|---|---|---|
| committer | Courtney Goeltzenleuchter <courtney@LunarG.com> | 2015-07-07 17:57:48 -0600 |
| commit | 0f42ac17372753bfb72bca5e0519cfcf9a41313b (patch) | |
| tree | f68005c6f5a86625e145356c79946f0468b41903 | |
| parent | ac439421f765069c1132ff3aefc6fba411995d34 (diff) | |
| download | usermoji-0f42ac17372753bfb72bca5e0519cfcf9a41313b.tar.xz | |
loader: Use app's alloc routines if available
Switch some of the allocations over to the app's
allocation callbacks. More to come.
| -rw-r--r-- | loader/trampoline.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/loader/trampoline.c b/loader/trampoline.c index e707082a..0afa9e1d 100644 --- a/loader/trampoline.c +++ b/loader/trampoline.c @@ -53,21 +53,24 @@ LOADER_EXPORT VkResult VKAPI vkCreateInstance( /* merge any duplicate extensions */ loader_platform_thread_once(&once_exts, loader_coalesce_extensions); - ptr_instance = (struct loader_instance*) malloc(sizeof(struct loader_instance)); + if (pCreateInfo->pAllocCb + && pCreateInfo->pAllocCb->pfnAlloc + && pCreateInfo->pAllocCb->pfnFree) { + ptr_instance = (struct loader_instance *) pCreateInfo->pAllocCb->pfnAlloc( + pCreateInfo->pAllocCb->pUserData, + sizeof(struct loader_instance), + sizeof(VkInstance), + VK_SYSTEM_ALLOC_TYPE_API_OBJECT); + } else { + ptr_instance = (struct loader_instance *) malloc(sizeof(struct loader_instance)); + } if (ptr_instance == NULL) { return VK_ERROR_OUT_OF_HOST_MEMORY; } - loader_platform_thread_lock_mutex(&loader_lock); + memset(ptr_instance, 0, sizeof(struct loader_instance)); - ptr_instance->disp = malloc(sizeof(VkLayerInstanceDispatchTable)); - if (ptr_instance->disp == NULL) { - loader_platform_thread_unlock_mutex(&loader_lock); - return VK_ERROR_OUT_OF_HOST_MEMORY; - } - memcpy(ptr_instance->disp, &instance_disp, sizeof(instance_disp)); - ptr_instance->next = loader.instances; - loader.instances = ptr_instance; + loader_platform_thread_lock_mutex(&loader_lock); if (pCreateInfo->pAllocCb && pCreateInfo->pAllocCb->pfnAlloc @@ -77,7 +80,24 @@ LOADER_EXPORT VkResult VKAPI vkCreateInstance( ptr_instance->alloc_callbacks.pfnFree = pCreateInfo->pAllocCb->pfnFree; } - loader_enable_instance_layers(ptr_instance, pCreateInfo); + ptr_instance->disp = loader_heap_alloc( + ptr_instance, + sizeof(VkLayerInstanceDispatchTable), + VK_SYSTEM_ALLOC_TYPE_INTERNAL); + if (ptr_instance->disp == NULL) { + loader_platform_thread_unlock_mutex(&loader_lock); + return VK_ERROR_OUT_OF_HOST_MEMORY; + } + memcpy(ptr_instance->disp, &instance_disp, sizeof(instance_disp)); + ptr_instance->next = loader.instances; + loader.instances = ptr_instance; + + res = loader_enable_instance_layers(ptr_instance, pCreateInfo); + if (res != VK_SUCCESS) { + loader_heap_free(ptr_instance, ptr_instance->disp); + loader_heap_free(ptr_instance, ptr_instance); + return res; + } debug_report_create_instance(ptr_instance, pCreateInfo); |
