• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google LLC
3  * SPDX-License-Identifier: MIT
4  *
5  * based in part on anv and radv which are:
6  * Copyright © 2015 Intel Corporation
7  * Copyright © 2016 Red Hat.
8  * Copyright © 2016 Bas Nieuwenhuizen
9  */
10 
11 #ifndef VN_DEVICE_MEMORY_H
12 #define VN_DEVICE_MEMORY_H
13 
14 #include "vn_common.h"
15 
16 struct vn_device_memory_pool {
17    mtx_t mutex;
18    struct vn_device_memory *memory;
19    VkDeviceSize used;
20 };
21 
22 struct vn_device_memory {
23    struct vn_device_memory_base base;
24 
25    /* non-NULL when suballocated */
26    struct vn_device_memory *base_memory;
27    /* non-NULL when mappable or external */
28    struct vn_renderer_bo *base_bo;
29 
30    /* ensure renderer side resource create is called after vkAllocateMemory
31     *
32     * 1. driver submits vkAllocateMemory (alloc) via ring for a ring seqno
33     * 2. driver submits via vq to wait for above ring to reach the seqno
34     * 3. driver creates virtgpu bo from renderer VkDeviceMemory
35     *
36     * ensure renderer side resource destroy is called after vkAllocateMemory
37     *
38     * 1. driver submits vkAllocateMemory (import) via ring for a ring seqno
39     * 2. driver submits via vq to wait for above ring to reach the seqno
40     * 3. driver destroys virtgpu bo
41     */
42    bool bo_ring_seqno_valid;
43    uint32_t bo_ring_seqno;
44 
45    /* ensure renderer side vkFreeMemory is called after vkGetMemoryFdKHR
46     *
47     * 1. driver creates virtgpu bo from renderer VkDeviceMemory
48     * 2. driver submits via vq to update the vq seqno
49     * 3, driver submits via ring to wait for vq reaching above seqno
50     * 4. driver submits vkFreeMemory via ring
51     *
52     * To be noted: a successful virtgpu mmap implies a roundtrip, so
53     * vn_FreeMemory after that no longer has to wait.
54     */
55    bool bo_roundtrip_seqno_valid;
56    uint64_t bo_roundtrip_seqno;
57 
58    VkDeviceSize base_offset;
59 
60    VkDeviceSize map_end;
61 };
62 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_device_memory,
63                                base.base.base,
64                                VkDeviceMemory,
65                                VK_OBJECT_TYPE_DEVICE_MEMORY)
66 
67 void
68 vn_device_memory_pool_fini(struct vn_device *dev, uint32_t mem_type_index);
69 
70 VkResult
71 vn_device_memory_import_dma_buf(struct vn_device *dev,
72                                 struct vn_device_memory *mem,
73                                 const VkMemoryAllocateInfo *alloc_info,
74                                 bool force_unmappable,
75                                 int fd);
76 
77 VkResult
78 vn_get_memory_dma_buf_properties(struct vn_device *dev,
79                                  int fd,
80                                  uint64_t *out_alloc_size,
81                                  uint32_t *out_mem_type_bits);
82 
83 #endif /* VN_DEVICE_MEMORY_H */
84