summaryrefslogtreecommitdiff
path: root/src/virtio/vulkan/vn_android.h
blob: 327ff7a674a1a9aba4ca72ad5c2baea114ad7a30 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * Copyright 2021 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_ANDROID_H
#define VN_ANDROID_H

#include "vn_common.h"

#include <vulkan/vk_android_native_buffer.h>
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_android.h>

/* venus implements VK_ANDROID_native_buffer up to spec version 7 */
#define VN_ANDROID_NATIVE_BUFFER_SPEC_VERSION 7

#ifdef ANDROID

static inline const VkNativeBufferANDROID *
vn_android_find_native_buffer(const VkImageCreateInfo *create_info)
{
   return vk_find_struct_const(create_info->pNext, NATIVE_BUFFER_ANDROID);
}

VkResult
vn_android_image_from_anb(struct vn_device *dev,
                          const VkImageCreateInfo *image_info,
                          const VkNativeBufferANDROID *anb_info,
                          const VkAllocationCallbacks *alloc,
                          struct vn_image **out_img);

bool
vn_android_get_drm_format_modifier_info(
   const VkPhysicalDeviceImageFormatInfo2 *format_info,
   VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info);

uint64_t
vn_android_get_ahb_usage(const VkImageUsageFlags usage,
                         const VkImageCreateFlags flags);

VkResult
vn_android_image_from_ahb(struct vn_device *dev,
                          const VkImageCreateInfo *create_info,
                          const VkAllocationCallbacks *alloc,
                          struct vn_image **out_img);

VkResult
vn_android_device_import_ahb(struct vn_device *dev,
                             struct vn_device_memory *mem,
                             const VkMemoryAllocateInfo *alloc_info,
                             const VkAllocationCallbacks *alloc,
                             struct AHardwareBuffer *ahb,
                             bool internal_ahb);

VkResult
vn_android_device_allocate_ahb(struct vn_device *dev,
                               struct vn_device_memory *mem,
                               const VkMemoryAllocateInfo *alloc_info,
                               const VkAllocationCallbacks *alloc);

void
vn_android_release_ahb(struct AHardwareBuffer *ahb);

VkFormat
vn_android_drm_format_to_vk_format(uint32_t format);

VkResult
vn_android_buffer_from_ahb(struct vn_device *dev,
                           const VkBufferCreateInfo *create_info,
                           const VkAllocationCallbacks *alloc,
                           struct vn_buffer **out_buf);

VkResult
vn_android_init_ahb_buffer_memory_type_bits(struct vn_device *dev);

#else

static inline const VkNativeBufferANDROID *
vn_android_find_native_buffer(UNUSED const VkImageCreateInfo *create_info)
{
   return NULL;
}

static inline VkResult
vn_android_image_from_anb(UNUSED struct vn_device *dev,
                          UNUSED const VkImageCreateInfo *image_info,
                          UNUSED const VkNativeBufferANDROID *anb_info,
                          UNUSED const VkAllocationCallbacks *alloc,
                          UNUSED struct vn_image **out_img)
{
   return VK_ERROR_OUT_OF_HOST_MEMORY;
}

static inline bool
vn_android_get_drm_format_modifier_info(
   UNUSED const VkPhysicalDeviceImageFormatInfo2 *format_info,
   UNUSED VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info)
{
   return false;
}

static inline uint64_t
vn_android_get_ahb_usage(UNUSED const VkImageUsageFlags usage,
                         UNUSED const VkImageCreateFlags flags)
{
   return 0;
}

static inline VkResult
vn_android_image_from_ahb(UNUSED struct vn_device *dev,
                          UNUSED const VkImageCreateInfo *create_info,
                          UNUSED const VkAllocationCallbacks *alloc,
                          UNUSED struct vn_image **out_img)
{
   return VK_ERROR_OUT_OF_HOST_MEMORY;
}

static inline VkResult
vn_android_device_import_ahb(UNUSED struct vn_device *dev,
                             UNUSED struct vn_device_memory *mem,
                             UNUSED const VkMemoryAllocateInfo *alloc_info,
                             UNUSED const VkAllocationCallbacks *alloc,
                             UNUSED struct AHardwareBuffer *ahb,
                             UNUSED bool internal_ahb)
{
   return VK_ERROR_OUT_OF_HOST_MEMORY;
}

static inline VkResult
vn_android_device_allocate_ahb(UNUSED struct vn_device *dev,
                               UNUSED struct vn_device_memory *mem,
                               UNUSED const VkMemoryAllocateInfo *alloc_info,
                               UNUSED const VkAllocationCallbacks *alloc)
{
   return VK_ERROR_OUT_OF_HOST_MEMORY;
}

static inline void
vn_android_release_ahb(UNUSED struct AHardwareBuffer *ahb)
{
   return;
}

static inline VkFormat
vn_android_drm_format_to_vk_format(UNUSED uint32_t format)
{
   return VK_FORMAT_UNDEFINED;
}

static inline VkResult
vn_android_buffer_from_ahb(UNUSED struct vn_device *dev,
                           UNUSED const VkBufferCreateInfo *create_info,
                           UNUSED const VkAllocationCallbacks *alloc,
                           UNUSED struct vn_buffer **out_buf)
{
   return VK_ERROR_OUT_OF_HOST_MEMORY;
}

static inline VkResult
vn_android_init_ahb_buffer_memory_type_bits(UNUSED struct vn_device *dev)
{
   return VK_ERROR_FEATURE_NOT_PRESENT;
}

#endif /* ANDROID */

#endif /* VN_ANDROID_H */