anv/android: Rework our handling of AHardwareBuffer imports
authorJason Ekstrand <jason@jlekstrand.net>
Thu, 22 Jul 2021 16:17:28 +0000 (11:17 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 27 Jul 2021 14:45:28 +0000 (14:45 +0000)
commit49908c602ffd2d84063effa7ddd0ee842be41a89
treeaf456becfe24918b2c2ad61c3bea0d86ccb20018
parentd903f51631cb003747b69f74454fa1823310786e
anv/android: Rework our handling of AHardwareBuffer imports

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.

Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12040>
src/intel/vulkan/anv_android.c
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_private.h