summaryrefslogtreecommitdiffstats
path: root/video/out/vulkan/malloc.h
blob: 9b311ce311d24989923c42fc23de7ff4cc6228d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include "common.h"

void vk_malloc_init(struct mpvk_ctx *vk);
void vk_malloc_uninit(struct mpvk_ctx *vk);

// Represents a single "slice" of generic (non-buffer) memory, plus some
// metadata for accounting. This struct is essentially read-only.
struct vk_memslice {
    VkDeviceMemory vkmem;
    size_t offset;
    size_t size;
    size_t slab_size;
    void *priv;
};

void vk_free_memslice(struct mpvk_ctx *vk, struct vk_memslice slice);
bool vk_malloc_generic(struct mpvk_ctx *vk, VkMemoryRequirements reqs,
                       VkMemoryPropertyFlags flags, struct vk_memslice *out);

// Represents a single "slice" of a larger buffer
struct vk_bufslice {
    struct vk_memslice mem; // must be freed by the user when done
    VkBuffer buf;           // the buffer this memory was sliced from
    // For persistently mapped buffers, this points to the first usable byte of
    // this slice.
    void *data;
};

// Allocate a buffer slice. This is more efficient than vk_malloc_generic for
// when the user needs lots of buffers, since it doesn't require
// creating/destroying lots of (little) VkBuffers.
bool vk_malloc_buffer(struct mpvk_ctx *vk, VkBufferUsageFlags bufFlags,
                      VkMemoryPropertyFlags memFlags, VkDeviceSize size,
                      VkDeviceSize alignment, bool exportable,
                      struct vk_bufslice *out);