summaryrefslogtreecommitdiff
path: root/src/virtio/vulkan/vn_device_memory.h
blob: a2c48485160af364aa7d4273c27082f24de27101 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright 2019 Google LLC
 * SPDX-License-Identifier: MIT
 *
 * based in part on anv and radv which are:
 * Copyright © 2015 Intel Corporation
 * Copyright © 2016 Red Hat.
 * Copyright © 2016 Bas Nieuwenhuizen
 */

#ifndef VN_DEVICE_MEMORY_H
#define VN_DEVICE_MEMORY_H

#include "vn_common.h"

struct vn_device_memory_pool {
   mtx_t mutex;
   struct vn_device_memory *memory;
   VkDeviceSize used;
};

struct vn_device_memory {
   struct vn_object_base base;

   VkDeviceSize size;
   VkMemoryPropertyFlags flags;

   /* non-NULL when suballocated */
   struct vn_device_memory *base_memory;
   /* non-NULL when mappable or external */
   struct vn_renderer_bo *base_bo;
   /* enforce kernel and ring ordering between memory export and free */
   bool bo_roundtrip_seqno_valid;
   uint64_t bo_roundtrip_seqno;
   VkDeviceSize base_offset;

   VkDeviceSize map_end;

   /* non-NULL when backed by AHB */
   struct AHardwareBuffer *ahb;
};
VK_DEFINE_NONDISP_HANDLE_CASTS(vn_device_memory,
                               base.base,
                               VkDeviceMemory,
                               VK_OBJECT_TYPE_DEVICE_MEMORY)

void
vn_device_memory_pool_fini(struct vn_device *dev, uint32_t mem_type_index);

VkResult
vn_device_memory_import_dma_buf(struct vn_device *dev,
                                struct vn_device_memory *mem,
                                const VkMemoryAllocateInfo *alloc_info,
                                bool force_unmappable,
                                int fd);

VkResult
vn_get_memory_dma_buf_properties(struct vn_device *dev,
                                 int fd,
                                 uint64_t *out_alloc_size,
                                 uint32_t *out_mem_type_bits);

#endif /* VN_DEVICE_MEMORY_H */