Blender V4.3
vk_memory.cc
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#include "vk_memory.hh"
10
11#include "MEM_guardedalloc.h"
12
13namespace blender::gpu {
14
15#ifdef WITH_VULKAN_GUARDEDALLOC
16
17void *vk_memory_allocation(void *user_data,
18 size_t size,
19 size_t alignment,
20 VkSystemAllocationScope /*scope*/)
21{
22 const char *name = static_cast<const char *>(const_cast<const void *>(user_data));
23 if (alignment) {
24 return MEM_mallocN_aligned(size, alignment, name);
25 }
26 return MEM_mallocN(size, name);
27}
28
29void *vk_memory_reallocation(void *user_data,
30 void *original,
31 size_t size,
32 size_t /*alignment*/,
33 VkSystemAllocationScope /*scope*/)
34{
35 const char *name = static_cast<const char *>(const_cast<const void *>(user_data));
36 return MEM_reallocN_id(original, size, name);
37}
38
39void vk_memory_free(void * /*user_data*/, void *memory)
40{
41 if (memory != nullptr) {
42 MEM_freeN(memory);
43 }
44}
45
46#endif
47
48} // namespace blender::gpu
Read Guarded memory(de)allocation.
void * MEM_mallocN_aligned(size_t len, size_t alignment, const char *str)
Definition mallocn.cc:110
void *(* MEM_reallocN_id)(void *vmemh, size_t len, const char *str)
Definition mallocn.cc:40
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105