• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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_ANDROID_H
12 #define VN_ANDROID_H
13 
14 #include "vn_common.h"
15 
16 #include <vulkan/vk_android_native_buffer.h>
17 #include <vulkan/vulkan.h>
18 #include <vulkan/vulkan_android.h>
19 
20 /* venus implements VK_ANDROID_native_buffer up to spec version 7 */
21 #define VN_ANDROID_NATIVE_BUFFER_SPEC_VERSION 7
22 
23 #if DETECT_OS_ANDROID
24 
25 VkResult
26 vn_android_image_from_anb(struct vn_device *dev,
27                           const VkImageCreateInfo *image_info,
28                           const VkNativeBufferANDROID *anb_info,
29                           const VkAllocationCallbacks *alloc,
30                           struct vn_image **out_img);
31 
32 bool
33 vn_android_get_drm_format_modifier_info(
34    const VkPhysicalDeviceImageFormatInfo2 *format_info,
35    VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info);
36 
37 const VkFormat *
38 vn_android_format_to_view_formats(VkFormat format, uint32_t *out_count);
39 
40 uint64_t
41 vn_android_get_ahb_usage(const VkImageUsageFlags usage,
42                          const VkImageCreateFlags flags);
43 
44 VkResult
45 vn_android_device_import_ahb(
46    struct vn_device *dev,
47    struct vn_device_memory *mem,
48    const struct VkMemoryDedicatedAllocateInfo *dedicated_info);
49 
50 VkFormat
51 vn_android_drm_format_to_vk_format(uint32_t format);
52 
53 uint32_t
54 vn_android_get_ahb_buffer_memory_type_bits(struct vn_device *dev);
55 
56 uint64_t
57 vn_android_gralloc_get_shared_present_usage(void);
58 
59 #else
60 
61 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)62 vn_android_image_from_anb(UNUSED struct vn_device *dev,
63                           UNUSED const VkImageCreateInfo *image_info,
64                           UNUSED const VkNativeBufferANDROID *anb_info,
65                           UNUSED const VkAllocationCallbacks *alloc,
66                           UNUSED struct vn_image **out_img)
67 {
68    return VK_ERROR_OUT_OF_HOST_MEMORY;
69 }
70 
71 static inline bool
vn_android_get_drm_format_modifier_info(UNUSED const VkPhysicalDeviceImageFormatInfo2 * format_info,UNUSED VkPhysicalDeviceImageDrmFormatModifierInfoEXT * out_info)72 vn_android_get_drm_format_modifier_info(
73    UNUSED const VkPhysicalDeviceImageFormatInfo2 *format_info,
74    UNUSED VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info)
75 {
76    return false;
77 }
78 
79 static inline const VkFormat *
vn_android_format_to_view_formats(UNUSED VkFormat format,UNUSED uint32_t * out_count)80 vn_android_format_to_view_formats(UNUSED VkFormat format,
81                                   UNUSED uint32_t *out_count)
82 {
83    return NULL;
84 }
85 
86 static inline uint64_t
vn_android_get_ahb_usage(UNUSED const VkImageUsageFlags usage,UNUSED const VkImageCreateFlags flags)87 vn_android_get_ahb_usage(UNUSED const VkImageUsageFlags usage,
88                          UNUSED const VkImageCreateFlags flags)
89 {
90    return 0;
91 }
92 
93 static inline VkResult
vn_android_device_import_ahb(UNUSED struct vn_device * dev,UNUSED struct vn_device_memory * mem,UNUSED const struct VkMemoryDedicatedAllocateInfo * dedicated_info)94 vn_android_device_import_ahb(
95    UNUSED struct vn_device *dev,
96    UNUSED struct vn_device_memory *mem,
97    UNUSED const struct VkMemoryDedicatedAllocateInfo *dedicated_info)
98 {
99    return VK_ERROR_OUT_OF_HOST_MEMORY;
100 }
101 
102 static inline VkFormat
vn_android_drm_format_to_vk_format(UNUSED uint32_t format)103 vn_android_drm_format_to_vk_format(UNUSED uint32_t format)
104 {
105    return VK_FORMAT_UNDEFINED;
106 }
107 
108 static inline uint32_t
vn_android_get_ahb_buffer_memory_type_bits(UNUSED struct vn_device * dev)109 vn_android_get_ahb_buffer_memory_type_bits(UNUSED struct vn_device *dev)
110 {
111    return 0;
112 }
113 
114 static inline uint64_t
vn_android_gralloc_get_shared_present_usage(void)115 vn_android_gralloc_get_shared_present_usage(void)
116 {
117    return 0;
118 }
119 
120 #endif /* DETECT_OS_ANDROID */
121 
122 #endif /* VN_ANDROID_H */
123