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_object_base base; 24 25 VkDeviceSize size; 26 27 /* non-NULL when suballocated */ 28 struct vn_device_memory *base_memory; 29 /* non-NULL when mappable or external */ 30 struct vn_renderer_bo *base_bo; 31 VkDeviceSize base_offset; 32 33 VkDeviceSize map_end; 34 35 /* non-NULL when backed by AHB */ 36 struct AHardwareBuffer *ahb; 37 }; 38 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_device_memory, 39 base.base, 40 VkDeviceMemory, 41 VK_OBJECT_TYPE_DEVICE_MEMORY) 42 43 void 44 vn_device_memory_pool_fini(struct vn_device *dev, uint32_t mem_type_index); 45 46 VkResult 47 vn_device_memory_import_dma_buf(struct vn_device *dev, 48 struct vn_device_memory *mem, 49 const VkMemoryAllocateInfo *alloc_info, 50 bool force_unmappable, 51 int fd); 52 53 VkResult 54 vn_get_memory_dma_buf_properties(struct vn_device *dev, 55 int fd, 56 uint64_t *out_alloc_size, 57 uint32_t *out_mem_type_bits); 58 59 #endif /* VN_DEVICE_MEMORY_H */ 60