1/*
2 *
3 * Copyright (c) 2014-2021 The Khronos Group Inc.
4 * Copyright (c) 2014-2021 Valve Corporation
5 * Copyright (c) 2014-2021 LunarG, Inc.
6 * Copyright (C) 2015 Google Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *     http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 * Author: Jon Ashburn <jon@lunarg.com>
21 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
22 * Author: Chia-I Wu <olvaffe@gmail.com>
23 * Author: Chia-I Wu <olv@lunarg.com>
24 * Author: Mark Lobodzinski <mark@LunarG.com>
25 * Author: Lenny Komow <lenny@lunarg.com>
26 * Author: Charles Giessen <charles@lunarg.com>
27 */
28
29#pragma once
30
31#include "loader_common.h"
32#include "stack_allocation.h"
33
34void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope allocation_scope);
35void *loader_instance_heap_calloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope allocation_scope);
36void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory);
37void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size,
38                                   VkSystemAllocationScope allocation_scope);
39
40void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope allocationScope);
41void *loader_device_heap_calloc(const struct loader_device *device, size_t size, VkSystemAllocationScope allocationScope);
42void loader_device_heap_free(const struct loader_device *device, void *pMemory);
43void *loader_device_heap_realloc(const struct loader_device *device, void *pMemory, size_t orig_size, size_t size,
44                                 VkSystemAllocationScope alloc_scope);
45
46// Wrappers around various memory functions. The loader will use the VkAllocationCallbacks functions if pAllocator is not NULL,
47// otherwise use the system functions
48void *loader_alloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope);
49void *loader_calloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope);
50void loader_free(const VkAllocationCallbacks *pAllocator, void *pMemory);
51void *loader_realloc(const VkAllocationCallbacks *pAllocator, void *pMemory, size_t orig_size, size_t size,
52                     VkSystemAllocationScope allocation_scope);
53
54// helper allocation functions that will use pAllocator and if it is NULL, fallback to the allocator of instance
55void *loader_alloc_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
56                                          size_t size, VkSystemAllocationScope allocation_scope);
57void *loader_calloc_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
58                                           size_t size, VkSystemAllocationScope allocation_scope);
59void loader_free_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
60                                        void *pMemory);
61void *loader_realloc_with_instance_fallback(const VkAllocationCallbacks *pAllocator, const struct loader_instance *instance,
62                                            void *pMemory, size_t orig_size, size_t size, VkSystemAllocationScope allocation_scope);
63