Blender V4.3
vk_memory.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include "vk_common.hh"
12
13namespace blender::gpu {
14
31#ifdef WITH_VULKAN_GUARDEDALLOC
32void *vk_memory_allocation(void *user_data,
33 size_t size,
34 size_t alignment,
35 VkSystemAllocationScope scope);
36void *vk_memory_reallocation(
37 void *user_data, void *original, size_t size, size_t alignment, VkSystemAllocationScope scope);
38void vk_memory_free(void *user_data, void *memory);
39
40constexpr VkAllocationCallbacks vk_allocation_callbacks_init(const char *name)
41{
42 VkAllocationCallbacks callbacks = {};
43 callbacks.pUserData = const_cast<char *>(name);
44 callbacks.pfnAllocation = vk_memory_allocation;
45 callbacks.pfnReallocation = vk_memory_reallocation;
46 callbacks.pfnFree = vk_memory_free;
47 callbacks.pfnInternalAllocation = nullptr;
48 callbacks.pfnInternalFree = nullptr;
49 return callbacks;
50}
51
52# define VK_ALLOCATION_CALLBACKS \
53 static constexpr const VkAllocationCallbacks vk_allocation_callbacks_ = \
54 vk_allocation_callbacks_init(__func__); \
55 static constexpr const VkAllocationCallbacks *vk_allocation_callbacks = \
56 &vk_allocation_callbacks_;
57#else
58# define VK_ALLOCATION_CALLBACKS \
59 static constexpr const VkAllocationCallbacks *vk_allocation_callbacks = nullptr;
60#endif
61
62} // namespace blender::gpu