radv: Derive android usage from create flags.
[mesa.git] / src / amd / vulkan / radv_android.c
1 /*
2 * Copyright © 2017, Google Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <hardware/gralloc.h>
25 #include <hardware/hardware.h>
26 #include <hardware/hwvulkan.h>
27 #include <vndk/hardware_buffer.h>
28 #include <vulkan/vk_android_native_buffer.h>
29 #include <vulkan/vk_icd.h>
30 #include <libsync.h>
31
32 #include "radv_private.h"
33 #include "vk_util.h"
34
35 static int radv_hal_open(const struct hw_module_t* mod, const char* id, struct hw_device_t** dev);
36 static int radv_hal_close(struct hw_device_t *dev);
37
38 static void UNUSED
39 static_asserts(void)
40 {
41 STATIC_ASSERT(HWVULKAN_DISPATCH_MAGIC == ICD_LOADER_MAGIC);
42 }
43
44 PUBLIC struct hwvulkan_module_t HAL_MODULE_INFO_SYM = {
45 .common = {
46 .tag = HARDWARE_MODULE_TAG,
47 .module_api_version = HWVULKAN_MODULE_API_VERSION_0_1,
48 .hal_api_version = HARDWARE_MAKE_API_VERSION(1, 0),
49 .id = HWVULKAN_HARDWARE_MODULE_ID,
50 .name = "AMD Vulkan HAL",
51 .author = "Google",
52 .methods = &(hw_module_methods_t) {
53 .open = radv_hal_open,
54 },
55 },
56 };
57
58 /* If any bits in test_mask are set, then unset them and return true. */
59 static inline bool
60 unmask32(uint32_t *inout_mask, uint32_t test_mask)
61 {
62 uint32_t orig_mask = *inout_mask;
63 *inout_mask &= ~test_mask;
64 return *inout_mask != orig_mask;
65 }
66
67 static int
68 radv_hal_open(const struct hw_module_t* mod, const char* id,
69 struct hw_device_t** dev)
70 {
71 assert(mod == &HAL_MODULE_INFO_SYM.common);
72 assert(strcmp(id, HWVULKAN_DEVICE_0) == 0);
73
74 hwvulkan_device_t *hal_dev = malloc(sizeof(*hal_dev));
75 if (!hal_dev)
76 return -1;
77
78 *hal_dev = (hwvulkan_device_t) {
79 .common = {
80 .tag = HARDWARE_DEVICE_TAG,
81 .version = HWVULKAN_DEVICE_API_VERSION_0_1,
82 .module = &HAL_MODULE_INFO_SYM.common,
83 .close = radv_hal_close,
84 },
85 .EnumerateInstanceExtensionProperties = radv_EnumerateInstanceExtensionProperties,
86 .CreateInstance = radv_CreateInstance,
87 .GetInstanceProcAddr = radv_GetInstanceProcAddr,
88 };
89
90 *dev = &hal_dev->common;
91 return 0;
92 }
93
94 static int
95 radv_hal_close(struct hw_device_t *dev)
96 {
97 /* hwvulkan.h claims that hw_device_t::close() is never called. */
98 return -1;
99 }
100
101 VkResult
102 radv_image_from_gralloc(VkDevice device_h,
103 const VkImageCreateInfo *base_info,
104 const VkNativeBufferANDROID *gralloc_info,
105 const VkAllocationCallbacks *alloc,
106 VkImage *out_image_h)
107
108 {
109 RADV_FROM_HANDLE(radv_device, device, device_h);
110 VkImage image_h = VK_NULL_HANDLE;
111 struct radv_image *image = NULL;
112 struct radv_bo *bo = NULL;
113 VkResult result;
114
115 if (gralloc_info->handle->numFds != 1) {
116 return vk_errorf(device->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE,
117 "VkNativeBufferANDROID::handle::numFds is %d, "
118 "expected 1", gralloc_info->handle->numFds);
119 }
120
121 /* Do not close the gralloc handle's dma_buf. The lifetime of the dma_buf
122 * must exceed that of the gralloc handle, and we do not own the gralloc
123 * handle.
124 */
125 int dma_buf = gralloc_info->handle->data[0];
126
127 VkDeviceMemory memory_h;
128
129 const VkImportMemoryFdInfoKHR import_info = {
130 .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
131 .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
132 .fd = dup(dma_buf),
133 };
134
135 /* Find the first VRAM memory type, or GART for PRIME images. */
136 int memory_type_index = -1;
137 for (int i = 0; i < device->physical_device->memory_properties.memoryTypeCount; ++i) {
138 bool is_local = !!(device->physical_device->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
139 if (is_local) {
140 memory_type_index = i;
141 break;
142 }
143 }
144
145 /* fallback */
146 if (memory_type_index == -1)
147 memory_type_index = 0;
148
149 result = radv_AllocateMemory(device_h,
150 &(VkMemoryAllocateInfo) {
151 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
152 .pNext = &import_info,
153 /* Max buffer size, unused for imports */
154 .allocationSize = 0x7FFFFFFF,
155 .memoryTypeIndex = memory_type_index,
156 },
157 alloc,
158 &memory_h);
159 if (result != VK_SUCCESS)
160 return result;
161
162 struct radeon_bo_metadata md;
163 device->ws->buffer_get_metadata(radv_device_memory_from_handle(memory_h)->bo, &md);
164
165 VkImageCreateInfo updated_base_info = *base_info;
166
167 VkExternalMemoryImageCreateInfo external_memory_info = {
168 .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
169 .pNext = updated_base_info.pNext,
170 .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
171 };
172
173 updated_base_info.pNext = &external_memory_info;
174
175 result = radv_image_create(device_h,
176 &(struct radv_image_create_info) {
177 .vk_info = &updated_base_info,
178 .no_metadata_planes = true,
179 .bo_metadata = &md,
180 },
181 alloc,
182 &image_h);
183
184 if (result != VK_SUCCESS)
185 goto fail_create_image;
186
187 image = radv_image_from_handle(image_h);
188
189 radv_image_override_offset_stride(device, image, 0, gralloc_info->stride);
190
191 radv_BindImageMemory(device_h, image_h, memory_h, 0);
192
193 image->owned_memory = memory_h;
194 /* Don't clobber the out-parameter until success is certain. */
195 *out_image_h = image_h;
196
197 return VK_SUCCESS;
198
199 fail_create_image:
200 radv_FreeMemory(device_h, memory_h, alloc);
201 return result;
202 }
203
204 VkResult radv_GetSwapchainGrallocUsageANDROID(
205 VkDevice device_h,
206 VkFormat format,
207 VkImageUsageFlags imageUsage,
208 int* grallocUsage)
209 {
210 RADV_FROM_HANDLE(radv_device, device, device_h);
211 struct radv_physical_device *phys_dev = device->physical_device;
212 VkPhysicalDevice phys_dev_h = radv_physical_device_to_handle(phys_dev);
213 VkResult result;
214
215 *grallocUsage = 0;
216
217 /* WARNING: Android Nougat's libvulkan.so hardcodes the VkImageUsageFlags
218 * returned to applications via VkSurfaceCapabilitiesKHR::supportedUsageFlags.
219 * The relevant code in libvulkan/swapchain.cpp contains this fun comment:
220 *
221 * TODO(jessehall): I think these are right, but haven't thought hard
222 * about it. Do we need to query the driver for support of any of
223 * these?
224 *
225 * Any disagreement between this function and the hardcoded
226 * VkSurfaceCapabilitiesKHR:supportedUsageFlags causes tests
227 * dEQP-VK.wsi.android.swapchain.*.image_usage to fail.
228 */
229
230 const VkPhysicalDeviceImageFormatInfo2 image_format_info = {
231 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
232 .format = format,
233 .type = VK_IMAGE_TYPE_2D,
234 .tiling = VK_IMAGE_TILING_OPTIMAL,
235 .usage = imageUsage,
236 };
237
238 VkImageFormatProperties2 image_format_props = {
239 .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2,
240 };
241
242 /* Check that requested format and usage are supported. */
243 result = radv_GetPhysicalDeviceImageFormatProperties2(phys_dev_h,
244 &image_format_info, &image_format_props);
245 if (result != VK_SUCCESS) {
246 return vk_errorf(device->instance, result,
247 "radv_GetPhysicalDeviceImageFormatProperties2 failed "
248 "inside %s", __func__);
249 }
250
251 if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_DST_BIT |
252 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT))
253 *grallocUsage |= GRALLOC_USAGE_HW_RENDER;
254
255 if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
256 VK_IMAGE_USAGE_SAMPLED_BIT |
257 VK_IMAGE_USAGE_STORAGE_BIT |
258 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT))
259 *grallocUsage |= GRALLOC_USAGE_HW_TEXTURE;
260
261 /* All VkImageUsageFlags not explicitly checked here are unsupported for
262 * gralloc swapchains.
263 */
264 if (imageUsage != 0) {
265 return vk_errorf(device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
266 "unsupported VkImageUsageFlags(0x%x) for gralloc "
267 "swapchain", imageUsage);
268 }
269
270 /*
271 * FINISHME: Advertise all display-supported formats. Mostly
272 * DRM_FORMAT_ARGB2101010 and DRM_FORMAT_ABGR2101010, but need to check
273 * what we need for 30-bit colors.
274 */
275 if (format == VK_FORMAT_B8G8R8A8_UNORM ||
276 format == VK_FORMAT_B5G6R5_UNORM_PACK16) {
277 *grallocUsage |= GRALLOC_USAGE_HW_FB |
278 GRALLOC_USAGE_HW_COMPOSER |
279 GRALLOC_USAGE_EXTERNAL_DISP;
280 }
281
282 if (*grallocUsage == 0)
283 return VK_ERROR_FORMAT_NOT_SUPPORTED;
284
285 return VK_SUCCESS;
286 }
287
288 VkResult
289 radv_AcquireImageANDROID(
290 VkDevice device,
291 VkImage image_h,
292 int nativeFenceFd,
293 VkSemaphore semaphore,
294 VkFence fence)
295 {
296 VkResult semaphore_result = VK_SUCCESS, fence_result = VK_SUCCESS;
297
298 if (semaphore != VK_NULL_HANDLE) {
299 int semaphore_fd = nativeFenceFd >= 0 ? dup(nativeFenceFd) : nativeFenceFd;
300 semaphore_result = radv_ImportSemaphoreFdKHR(device,
301 &(VkImportSemaphoreFdInfoKHR) {
302 .sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR,
303 .flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT,
304 .fd = semaphore_fd,
305 .semaphore = semaphore,
306 });
307 }
308
309 if (fence != VK_NULL_HANDLE) {
310 int fence_fd = nativeFenceFd >= 0 ? dup(nativeFenceFd) : nativeFenceFd;
311 fence_result = radv_ImportFenceFdKHR(device,
312 &(VkImportFenceFdInfoKHR) {
313 .sType = VK_STRUCTURE_TYPE_IMPORT_FENCE_FD_INFO_KHR,
314 .flags = VK_FENCE_IMPORT_TEMPORARY_BIT,
315 .fd = fence_fd,
316 .fence = fence,
317 });
318 }
319
320 close(nativeFenceFd);
321
322 if (semaphore_result != VK_SUCCESS)
323 return semaphore_result;
324 return fence_result;
325 }
326
327 VkResult
328 radv_QueueSignalReleaseImageANDROID(
329 VkQueue _queue,
330 uint32_t waitSemaphoreCount,
331 const VkSemaphore* pWaitSemaphores,
332 VkImage image,
333 int* pNativeFenceFd)
334 {
335 RADV_FROM_HANDLE(radv_queue, queue, _queue);
336 VkResult result = VK_SUCCESS;
337
338 if (waitSemaphoreCount == 0) {
339 if (pNativeFenceFd)
340 *pNativeFenceFd = -1;
341 return VK_SUCCESS;
342 }
343
344 int fd = -1;
345
346 for (uint32_t i = 0; i < waitSemaphoreCount; ++i) {
347 int tmp_fd;
348 result = radv_GetSemaphoreFdKHR(radv_device_to_handle(queue->device),
349 &(VkSemaphoreGetFdInfoKHR) {
350 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR,
351 .handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT,
352 .semaphore = pWaitSemaphores[i],
353 }, &tmp_fd);
354 if (result != VK_SUCCESS) {
355 if (fd >= 0)
356 close (fd);
357 return result;
358 }
359
360 if (fd < 0)
361 fd = tmp_fd;
362 else if (tmp_fd >= 0) {
363 sync_accumulate("radv", &fd, tmp_fd);
364 close(tmp_fd);
365 }
366 }
367
368 if (pNativeFenceFd) {
369 *pNativeFenceFd = fd;
370 } else if (fd >= 0) {
371 close(fd);
372 /* We still need to do the exports, to reset the semaphores, but
373 * otherwise we don't wait on them. */
374 }
375 return VK_SUCCESS;
376 }
377
378 #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
379
380 enum {
381 /* Usage bit equal to GRALLOC_USAGE_HW_CAMERA_MASK */
382 AHARDWAREBUFFER_USAGE_CAMERA_MASK = 0x00060000U,
383 };
384
385 static inline VkFormat
386 vk_format_from_android(unsigned android_format, unsigned android_usage)
387 {
388 switch (android_format) {
389 case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
390 return VK_FORMAT_R8G8B8A8_UNORM;
391 case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
392 case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
393 return VK_FORMAT_R8G8B8_UNORM;
394 case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
395 return VK_FORMAT_R5G6B5_UNORM_PACK16;
396 case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
397 return VK_FORMAT_R16G16B16A16_SFLOAT;
398 case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
399 return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
400 case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:
401 return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
402 case AHARDWAREBUFFER_FORMAT_IMPLEMENTATION_DEFINED:
403 if (android_usage & AHARDWAREBUFFER_USAGE_CAMERA_MASK)
404 return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
405 else
406 return VK_FORMAT_R8G8B8_UNORM;
407 case AHARDWAREBUFFER_FORMAT_BLOB:
408 default:
409 return VK_FORMAT_UNDEFINED;
410 }
411 }
412
413 uint64_t
414 radv_ahb_usage_from_vk_usage(const VkImageCreateFlags vk_create,
415 const VkImageUsageFlags vk_usage)
416 {
417 uint64_t ahb_usage = 0;
418 if (vk_usage & VK_IMAGE_USAGE_SAMPLED_BIT)
419 ahb_usage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
420
421 if (vk_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)
422 ahb_usage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
423
424 if (vk_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
425 ahb_usage |= AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT;
426
427 if (vk_create & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
428 ahb_usage |= AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP;
429
430 if (vk_create & VK_IMAGE_CREATE_PROTECTED_BIT)
431 ahb_usage |= AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT;
432
433 /* No usage bits set - set at least one GPU usage. */
434 if (ahb_usage == 0)
435 ahb_usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
436 return ahb_usage;
437 }
438
439 static VkResult
440 get_ahb_buffer_format_properties(
441 VkDevice device_h,
442 const struct AHardwareBuffer *buffer,
443 VkAndroidHardwareBufferFormatPropertiesANDROID *pProperties)
444 {
445 RADV_FROM_HANDLE(radv_device, device, device_h);
446
447 /* Get a description of buffer contents . */
448 AHardwareBuffer_Desc desc;
449 AHardwareBuffer_describe(buffer, &desc);
450
451 /* Verify description. */
452 const uint64_t gpu_usage =
453 AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
454 AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT |
455 AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER;
456
457 /* "Buffer must be a valid Android hardware buffer object with at least
458 * one of the AHARDWAREBUFFER_USAGE_GPU_* usage flags."
459 */
460 if (!(desc.usage & (gpu_usage)))
461 return VK_ERROR_INVALID_EXTERNAL_HANDLE;
462
463 /* Fill properties fields based on description. */
464 VkAndroidHardwareBufferFormatPropertiesANDROID *p = pProperties;
465
466 p->format = vk_format_from_android(desc.format, desc.usage);
467 p->externalFormat = (uint64_t) (uintptr_t) p->format;
468
469 VkFormatProperties format_properties;
470 radv_GetPhysicalDeviceFormatProperties(
471 radv_physical_device_to_handle(device->physical_device),
472 p->format, &format_properties);
473
474 if (desc.usage & AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER)
475 p->formatFeatures = format_properties.linearTilingFeatures;
476 else
477 p->formatFeatures = format_properties.optimalTilingFeatures;
478
479 /* "Images can be created with an external format even if the Android hardware
480 * buffer has a format which has an equivalent Vulkan format to enable
481 * consistent handling of images from sources that might use either category
482 * of format. However, all images created with an external format are subject
483 * to the valid usage requirements associated with external formats, even if
484 * the Android hardware buffer’s format has a Vulkan equivalent."
485 *
486 * "The formatFeatures member *must* include
487 * VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT and at least one of
488 * VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT or
489 * VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT"
490 */
491 assert(p->formatFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
492
493 p->formatFeatures |= VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT;
494
495 /* "Implementations may not always be able to determine the color model,
496 * numerical range, or chroma offsets of the image contents, so the values
497 * in VkAndroidHardwareBufferFormatPropertiesANDROID are only suggestions.
498 * Applications should treat these values as sensible defaults to use in
499 * the absence of more reliable information obtained through some other
500 * means."
501 */
502 p->samplerYcbcrConversionComponents.r = VK_COMPONENT_SWIZZLE_IDENTITY;
503 p->samplerYcbcrConversionComponents.g = VK_COMPONENT_SWIZZLE_IDENTITY;
504 p->samplerYcbcrConversionComponents.b = VK_COMPONENT_SWIZZLE_IDENTITY;
505 p->samplerYcbcrConversionComponents.a = VK_COMPONENT_SWIZZLE_IDENTITY;
506
507 p->suggestedYcbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601;
508 p->suggestedYcbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL;
509
510 p->suggestedXChromaOffset = VK_CHROMA_LOCATION_MIDPOINT;
511 p->suggestedYChromaOffset = VK_CHROMA_LOCATION_MIDPOINT;
512
513 return VK_SUCCESS;
514 }
515
516 VkResult
517 radv_GetAndroidHardwareBufferPropertiesANDROID(
518 VkDevice device_h,
519 const struct AHardwareBuffer *buffer,
520 VkAndroidHardwareBufferPropertiesANDROID *pProperties)
521 {
522 RADV_FROM_HANDLE(radv_device, dev, device_h);
523 struct radv_physical_device *pdevice = dev->physical_device;
524
525 VkAndroidHardwareBufferFormatPropertiesANDROID *format_prop =
526 vk_find_struct(pProperties->pNext,
527 ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID);
528
529 /* Fill format properties of an Android hardware buffer. */
530 if (format_prop)
531 get_ahb_buffer_format_properties(device_h, buffer, format_prop);
532
533 /* NOTE - We support buffers with only one handle but do not error on
534 * multiple handle case. Reason is that we want to support YUV formats
535 * where we have many logical planes but they all point to the same
536 * buffer, like is the case with VK_FORMAT_G8_B8R8_2PLANE_420_UNORM.
537 */
538 const native_handle_t *handle =
539 AHardwareBuffer_getNativeHandle(buffer);
540 int dma_buf = (handle && handle->numFds) ? handle->data[0] : -1;
541 if (dma_buf < 0)
542 return VK_ERROR_INVALID_EXTERNAL_HANDLE;
543
544 /* All memory types. */
545 uint32_t memory_types = (1u << pdevice->memory_properties.memoryTypeCount) - 1;
546
547 pProperties->allocationSize = lseek(dma_buf, 0, SEEK_END);
548 pProperties->memoryTypeBits = memory_types;
549
550 return VK_SUCCESS;
551 }
552
553 VkResult
554 radv_GetMemoryAndroidHardwareBufferANDROID(
555 VkDevice device_h,
556 const VkMemoryGetAndroidHardwareBufferInfoANDROID *pInfo,
557 struct AHardwareBuffer **pBuffer)
558 {
559 RADV_FROM_HANDLE(radv_device_memory, mem, pInfo->memory);
560
561 /* This should always be set due to the export handle types being set on
562 * allocation. */
563 assert(mem->android_hardware_buffer);
564
565 /* Some quotes from Vulkan spec:
566 *
567 * "If the device memory was created by importing an Android hardware
568 * buffer, vkGetMemoryAndroidHardwareBufferANDROID must return that same
569 * Android hardware buffer object."
570 *
571 * "VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID must
572 * have been included in VkExportMemoryAllocateInfo::handleTypes when
573 * memory was created."
574 */
575 *pBuffer = mem->android_hardware_buffer;
576 /* Increase refcount. */
577 AHardwareBuffer_acquire(mem->android_hardware_buffer);
578 return VK_SUCCESS;
579 }
580
581 #endif