summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Clark <robdclark@chromium.org>2024-05-06 10:47:42 -0700
committerMarge Bot <emma+marge@anholt.net>2024-05-14 14:53:44 +0000
commitb9bbeb77c76314cf3c3206a7e1bbd54e00aae1c5 (patch)
tree2d28fd35cfa73e5562e7af5fb45ac378dcd324b2
parentbe0a893a2e0126e1ed1cae60820333e8686d3593 (diff)
vulkan/android: Add helper to probe AHB support
GetPhysicalDeviceImageFormatProperties() must that an image {format, flags, usage} combo is unsupported if gralloc will not be able to perform the allocation. The practical way to test this is to do a small test allocation. Signed-off-by: Rob Clark <robdclark@chromium.org> Reviewed-by: Roman Stratiienko <r.stratiienko@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29090>
-rw-r--r--src/android_stub/nativewindow_stub.cpp6
-rw-r--r--src/vulkan/runtime/vk_android.c33
-rw-r--r--src/vulkan/runtime/vk_android.h12
3 files changed, 51 insertions, 0 deletions
diff --git a/src/android_stub/nativewindow_stub.cpp b/src/android_stub/nativewindow_stub.cpp
index b0600778691..9276a9c3d2e 100644
--- a/src/android_stub/nativewindow_stub.cpp
+++ b/src/android_stub/nativewindow_stub.cpp
@@ -31,6 +31,12 @@ AHardwareBuffer_allocate(const AHardwareBuffer_Desc *desc,
return 0;
}
+int
+AHardwareBuffer_isSupported(const AHardwareBuffer_Desc* desc)
+{
+ return 0;
+}
+
const native_handle_t *
AHardwareBuffer_getNativeHandle(const AHardwareBuffer *buffer)
{
diff --git a/src/vulkan/runtime/vk_android.c b/src/vulkan/runtime/vk_android.c
index 59afd1b71e6..6073ee37ddf 100644
--- a/src/vulkan/runtime/vk_android.c
+++ b/src/vulkan/runtime/vk_android.c
@@ -477,6 +477,39 @@ vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
return ahb_usage;
}
+/* Probe gralloc implementation to test whether it can allocate a buffer
+ * for the given format and usage. Vk drivers must not advertise support
+ * for AHB backed VkImage's if the gralloc implementation is not able to
+ * perform the allocation.
+ */
+bool
+vk_ahb_probe_format(VkFormat vk_format,
+ VkImageCreateFlags vk_create,
+ VkImageUsageFlags vk_usage)
+{
+ AHardwareBuffer_Desc desc = {
+ .width = 16,
+ .height = 16,
+ .layers = 1,
+ .format = vk_image_format_to_ahb_format(vk_format),
+ .usage = vk_image_usage_to_ahb_usage(vk_create, vk_usage),
+ };
+#if ANDROID_API_LEVEL >= 29
+ return AHardwareBuffer_isSupported(&desc);
+#else
+ AHardwareBuffer *ahb = NULL;
+ int ret = 0;
+
+ ret = AHardwareBuffer_allocate(&desc, &ahb);
+ if (ret)
+ return false;
+
+ AHardwareBuffer_release(ahb);
+
+ return true;
+#endif
+}
+
struct AHardwareBuffer *
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo)
{
diff --git a/src/vulkan/runtime/vk_android.h b/src/vulkan/runtime/vk_android.h
index 448887d5797..5c7fb10f299 100644
--- a/src/vulkan/runtime/vk_android.h
+++ b/src/vulkan/runtime/vk_android.h
@@ -110,6 +110,10 @@ uint32_t vk_image_format_to_ahb_format(VkFormat vk_format);
uint64_t vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
const VkImageUsageFlags vk_usage);
+bool vk_ahb_probe_format(VkFormat vk_format,
+ VkImageCreateFlags vk_create,
+ VkImageUsageFlags vk_usage);
+
struct AHardwareBuffer *
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo);
@@ -134,6 +138,14 @@ vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
return 0;
}
+static inline bool
+vk_ahb_probe_format(VkFormat vk_format,
+ VkImageCreateFlags vk_create,
+ VkImageUsageFlags vk_usage)
+{
+ return false;
+}
+
static inline struct AHardwareBuffer *
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo)
{