summaryrefslogtreecommitdiff
path: root/vulkan/include/vulkan/vk_android_native_buffer.h
blob: ba98696aef3cbf630d99aa50c648153c74999599 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 * Copyright 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __VK_ANDROID_NATIVE_BUFFER_H__
#define __VK_ANDROID_NATIVE_BUFFER_H__

#include <cutils/native_handle.h>
#include <vulkan/vulkan.h>

#ifdef __cplusplus
extern "C" {
#endif

#define VK_ANDROID_native_buffer 1

#define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER 11
/*
 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 6
 *
 * This version of the extension transitions from gralloc0 to gralloc1 usage
 * flags (int -> 2x uint64_t). The WSI implementation will temporarily continue
 * to fill out deprecated fields in VkNativeBufferANDROID, and will call the
 * deprecated vkGetSwapchainGrallocUsageANDROID if the new
 * vkGetSwapchainGrallocUsage2ANDROID is not supported. This transitionary
 * backwards-compatibility support is temporary, and will likely be removed
 * (along with all gralloc0 support) in a future release.
 */
/*
 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8
 *
 * This version of the extension doesn't introduce new types or structs, but is
 * to accommodate the new struct VkBindImageMemorySwapchainInfoKHR added in
 * VK_KHR_swapchain spec version 69. When VkBindImageMemorySwapchainInfoKHR is
 * chained in the pNext chain of VkBindImageMemoryInfo, a VkNativeBufferANDROID
 * that holds the correct gralloc handle according to the imageIndex specified
 * in VkBindImageMemorySwapchainInfoKHR will be additionally chained to the
 * pNext chain of VkBindImageMemoryInfo and passed down to the driver.
 */
#define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8
#define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer"

#define VK_ANDROID_NATIVE_BUFFER_ENUM(type, id) \
    ((type)(1000000000 +                        \
            (1000 * (VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER - 1)) + (id)))
#define VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID \
    VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 0)
#define VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID \
    VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 1)
#define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID \
    VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 2)

/* clang-format off */
typedef enum VkSwapchainImageUsageFlagBitsANDROID {
    VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID = 0x00000001,
    VK_SWAPCHAIN_IMAGE_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} VkSwapchainImageUsageFlagBitsANDROID;
typedef VkFlags VkSwapchainImageUsageFlagsANDROID;

/*
 * struct VkNativeBufferUsage2ANDROID
 *
 * consumer: gralloc1 consumer usage flag
 * producer: gralloc1 producer usage flag
 */
typedef struct {
    uint64_t                          consumer;
    uint64_t                          producer;
} VkNativeBufferUsage2ANDROID;

/*
 * struct VkNativeBufferANDROID
 *
 * sType: VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID
 * pNext: NULL or a pointer to a structure extending this structure
 * handle: buffer handle returned from gralloc alloc()
 * stride: stride returned from gralloc alloc()
 * format: gralloc format requested when the buffer was allocated
 * usage: gralloc usage requested when the buffer was allocated
 * usage2: gralloc usage requested when the buffer was allocated
 */
typedef struct {
    VkStructureType                   sType;
    const void*                       pNext;
    buffer_handle_t                   handle;
    int                               stride;
    int                               format;
    int                               usage; /* DEPRECATED in SPEC_VERSION 6 */
    VkNativeBufferUsage2ANDROID       usage2; /* ADDED in SPEC_VERSION 6 */
} VkNativeBufferANDROID;

/*
 * struct VkSwapchainImageCreateInfoANDROID
 *
 * sType: VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID
 * pNext: NULL or a pointer to a structure extending this structure
 * usage: is a bitmask of VkSwapchainImageUsageFlagsANDROID
 */
typedef struct {
    VkStructureType                   sType;
    const void*                       pNext;
    VkSwapchainImageUsageFlagsANDROID usage;
} VkSwapchainImageCreateInfoANDROID;

/*
 * struct VkPhysicalDevicePresentationPropertiesANDROID
 *
 * sType: VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID
 * pNext: NULL or a pointer to a structure extending this structure
 * sharedImage: specifies if the image can be shared with the display system
 */
typedef struct {
    VkStructureType                   sType;
    const void*                       pNext;
    VkBool32                          sharedImage;
} VkPhysicalDevicePresentationPropertiesANDROID;

/* DEPRECATED in SPEC_VERSION 6 */
typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsageANDROID)(
    VkDevice                          device,
    VkFormat                          format,
    VkImageUsageFlags                 imageUsage,
    int*                              grallocUsage);

/* ADDED in SPEC_VERSION 6 */
typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage2ANDROID)(
    VkDevice                          device,
    VkFormat                          format,
    VkImageUsageFlags                 imageUsage,
    VkSwapchainImageUsageFlagsANDROID swapchainImageUsage,
    uint64_t*                         grallocConsumerUsage,
    uint64_t*                         grallocProducerUsage);

typedef VkResult (VKAPI_PTR *PFN_vkAcquireImageANDROID)(
    VkDevice                          device,
    VkImage                           image,
    int                               nativeFenceFd,
    VkSemaphore                       semaphore,
    VkFence                           fence);

typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalReleaseImageANDROID)(
    VkQueue                           queue,
    uint32_t                          waitSemaphoreCount,
    const VkSemaphore*                pWaitSemaphores,
    VkImage                           image,
    int*                              pNativeFenceFd);

#ifndef VK_NO_PROTOTYPES

/* DEPRECATED in SPEC_VERSION 6 */
VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID(
    VkDevice                          device,
    VkFormat                          format,
    VkImageUsageFlags                 imageUsage,
    int*                              grallocUsage
);

/* ADDED in SPEC_VERSION 6 */
VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID(
    VkDevice                          device,
    VkFormat                          format,
    VkImageUsageFlags                 imageUsage,
    VkSwapchainImageUsageFlagsANDROID swapchainImageUsage,
    uint64_t*                         grallocConsumerUsage,
    uint64_t*                         grallocProducerUsage
);

VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID(
    VkDevice                          device,
    VkImage                           image,
    int                               nativeFenceFd,
    VkSemaphore                       semaphore,
    VkFence                           fence
);

VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID(
    VkQueue                           queue,
    uint32_t                          waitSemaphoreCount,
    const VkSemaphore*                pWaitSemaphores,
    VkImage                           image,
    int*                              pNativeFenceFd
);

#endif
/* clang-format on */

#ifdef __cplusplus
}
#endif

#endif /* __VK_ANDROID_NATIVE_BUFFER_H__ */