简体   繁体   中英

VK_FORMAT_UNDEFINED for Android hardware buffer with depth format on Vulkan

If I allocate an Android hardware buffer with a depth format (AHARDWAREBUFFER_FORMAT_D16_UNORM), the resulting Vulkan format retrieved by vkGetAndroidHardwareBufferPropertiesANDROID is VK_FORMAT_UNDEFINED, even though the hardware buffer depth format has a direct Vulkan format equivalent (VK_FORMAT_D16_UNORM). The same does not happen with a color format: with AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM vkGetAndroidHardwareBufferPropertiesANDROID yields VK_FORMAT_R8G8B8A8_UNORM as expected.

Do I need to use a special parameter or extension in order to get the depth format to be correctly mapped?

Here is a snippet of the code:

uint32_t width = 1024;
uint32_t height = 1024;
// uint32_t hardwareBufferFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
uint32_t hardwareBufferFormat = AHARDWAREBUFFER_FORMAT_D16_UNORM;
uint32_t hardwareBufferUsage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER;
VkAndroidHardwareBufferFormatPropertiesANDROID bufferFormatProperties{VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID};
VkAndroidHardwareBufferPropertiesANDROID bufferProperties{VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID};
bufferProperties.pNext = &bufferFormatProperties;
AHardwareBuffer *hardwareBuffer;
AHardwareBuffer_Desc desc{width, height, 1, hardwareBufferFormat, hardwareBufferUsage, 0, 0, 0};
int error = AHardwareBuffer_allocate(&desc, &hardwareBuffer);
if (error < 0) {
  LOGE("AHardwareBuffer_allocate error: %d", error);
  return;
}

vkGetAndroidHardwareBufferPropertiesANDROID(tutorialDevice, hardwareBuffer, &bufferProperties);

Full code, branch on fork of android-vulkan-tutorials ( https://github.com/googlesamples/android-vulkan-tutorials ), available here: https://github.com/pm328/android-vulkan-tutorials/pull/1/files

Devices tested: Samsung Galaxy S20, Galaxy Note 10+ 5G

GPU: Adreno (Qualcomm Snapdragon)

Android Version: 10

I also tested AHARDWAREBUFFER_FORMAT_D24_UNORM, AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT and AHARDWAREBUFFER_FORMAT_D32_FLOAT with the exact same result.

It's not guaranteed that all AHARDWAREBUFFER_FORMAT types can be allocated via his method; what is available is platform-specific. Call AHardwareBuffer_isSupported() to see if they are, but it wouldn't surprise me if depth buffers are not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM