Skip to content

anv/android: Rework our handling of AHardwareBuffer imports

Faith Ekstrand requested to merge gfxstrand/mesa:review/rework-ahb-import into main

The current code we have for this is a bit of a mess, likely due to trying too hard to put it in anv_android.c. The external_format bit in anv_image, for instance, really means "quit creation early" which is something we want to do for AHardwareBuffer imports regardless of whether or not they use a native format. It gets set both by declaring an AHardwareBuffer external handle type and by VkExternalFormatANDROID. However, VkExternalFormatANDROID is only allowed for AHardwareBuffer imports. If we ever did get an external format outside the context of an AHardwareBuffer import, we would end up with a useless partially created image.

When we detect an AHardwareBuffer import, we punt off to a function in anv_android.c that does nothing interesting but call anv_create_image with AUX disabled and external_format = true. The aux disable here is useless because the actual isl_surf layout is done by resolve_ahw_image which also sets ISL_SURF_USAGE_DISABLE_AUX_BIT. As far as external formats go, anv_image_from_external() sets it regardless of whether or not there is actually an external format.

This commit replaces anv_image::external_format with anv_image::from_ahb which is the thing we actually want to track for this. We delete anv_image_from_external and a bunch of the external_format handling because it's all useless. The end result is massively simpler and, while it appears to blur the boundary between Android code and the rest of the driver, it makes the whole flow more obvious.

Merge request reports