panvk: stub out Android ANB and AHB image handling

ANB and AHB image handling will be implemented on top of
VK_EXT_image_drm_format_modifier impl. To be specific, they will be
resolved to VkImageDrmFormatModifierExplicitCreateInfoEXT when the
backing gralloc image is available:
- ANB: upon ANB image creation
- ANB alias: upon binding image to memory
- AHB: upon dedicated memory import

So for ANB alias and AHB, the initial VkImage creation only needs to
allocate the image object while the create info has to be deferred till
later to help with actual image layouting.

Acked-by: Lars-Ivar Hesselberg Simonsen <lars-ivar.simonsen@arm.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36603>
This commit is contained in:
Yiwei Zhang 2025-08-05 03:18:38 +00:00 committed by Marge Bot
parent b5973bed78
commit 63db388543
4 changed files with 113 additions and 0 deletions

View file

@ -176,6 +176,10 @@ if with_platform_wayland
panvk_deps += dep_wayland_client
endif
if with_platform_android
libpanvk_files += files('panvk_android.c')
endif
libvulkan_panfrost = shared_library(
'vulkan_panfrost',
[libpanvk_files, panvk_entrypoints, panvk_tracepoints],

View file

@ -0,0 +1,62 @@
/*
* Copyright 2025 Google LLC
* SPDX-License-Identifier: MIT
*/
#include "panvk_android.h"
#include "vulkan/vk_android_native_buffer.h"
#include "vk_util.h"
bool
panvk_android_is_gralloc_image(const VkImageCreateInfo *pCreateInfo)
{
vk_foreach_struct_const(ext, pCreateInfo->pNext) {
switch ((uint32_t)ext->sType) {
case VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID:
return true;
case VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHR: {
const VkImageSwapchainCreateInfoKHR *swapchain_info = (void *)ext;
if (swapchain_info->swapchain != VK_NULL_HANDLE)
return true;
break;
}
case VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO: {
const VkExternalMemoryImageCreateInfo *external_info = (void *)ext;
if (external_info->handleTypes &
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
return true;
break;
}
default:
break;
}
}
return false;
}
static VkResult
panvk_android_create_deferred_image(VkDevice device,
const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkImage *pImage)
{
return VK_ERROR_FEATURE_NOT_PRESENT;
}
VkResult
panvk_android_create_gralloc_image(VkDevice device,
const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkImage *pImage)
{
const VkNativeBufferANDROID *anb =
vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID);
if (!anb) {
return panvk_android_create_deferred_image(device, pCreateInfo,
pAllocator, pImage);
}
return VK_ERROR_FEATURE_NOT_PRESENT;
}

View file

@ -0,0 +1,41 @@
/*
* Copyright 2025 Google LLC
* SPDX-License-Identifier: MIT
*/
#ifndef PANVK_ANDROID_H
#define PANVK_ANDROID_H
#include <stdbool.h>
#include "util/detect_os.h"
#include "vulkan/vulkan.h"
#ifdef VK_USE_PLATFORM_ANDROID_KHR
bool panvk_android_is_gralloc_image(const VkImageCreateInfo *pCreateInfo);
VkResult panvk_android_create_gralloc_image(
VkDevice device, const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkImage *pImage);
#else /* VK_USE_PLATFORM_ANDROID_KHR */
static inline bool
panvk_android_is_gralloc_image(const VkImageCreateInfo *pCreateInfo)
{
return false;
}
static inline VkResult
panvk_android_create_gralloc_image(VkDevice device,
const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkImage *pImage)
{
return VK_ERROR_FEATURE_NOT_PRESENT;
}
#endif /* VK_USE_PLATFORM_ANDROID_KHR */
#endif /* PANVK_ANDROID_H */

View file

@ -29,6 +29,7 @@
#include "pan_afbc.h"
#include "pan_props.h"
#include "panvk_android.h"
#include "panvk_device.h"
#include "panvk_device_memory.h"
#include "panvk_entrypoints.h"
@ -431,6 +432,11 @@ panvk_CreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
struct panvk_physical_device *phys_dev =
to_panvk_physical_device(dev->vk.physical);
if (panvk_android_is_gralloc_image(pCreateInfo)) {
return panvk_android_create_gralloc_image(device, pCreateInfo, pAllocator,
pImage);
}
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {