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>
This commit is contained in:
@@ -31,6 +31,12 @@ AHardwareBuffer_allocate(const AHardwareBuffer_Desc *desc,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
AHardwareBuffer_isSupported(const AHardwareBuffer_Desc* desc)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const native_handle_t *
|
const native_handle_t *
|
||||||
AHardwareBuffer_getNativeHandle(const AHardwareBuffer *buffer)
|
AHardwareBuffer_getNativeHandle(const AHardwareBuffer *buffer)
|
||||||
{
|
{
|
||||||
|
@@ -477,6 +477,39 @@ vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
|
|||||||
return ahb_usage;
|
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 *
|
struct AHardwareBuffer *
|
||||||
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo)
|
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo)
|
||||||
{
|
{
|
||||||
|
@@ -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,
|
uint64_t vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
|
||||||
const VkImageUsageFlags vk_usage);
|
const VkImageUsageFlags vk_usage);
|
||||||
|
|
||||||
|
bool vk_ahb_probe_format(VkFormat vk_format,
|
||||||
|
VkImageCreateFlags vk_create,
|
||||||
|
VkImageUsageFlags vk_usage);
|
||||||
|
|
||||||
struct AHardwareBuffer *
|
struct AHardwareBuffer *
|
||||||
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo);
|
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo);
|
||||||
|
|
||||||
@@ -134,6 +138,14 @@ vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
vk_ahb_probe_format(VkFormat vk_format,
|
||||||
|
VkImageCreateFlags vk_create,
|
||||||
|
VkImageUsageFlags vk_usage)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static inline struct AHardwareBuffer *
|
static inline struct AHardwareBuffer *
|
||||||
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo)
|
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user