venus: support VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8

The aliased WSI image creation path is very much like the AHB case. It's
also the same with the deferred ANB binding path to support
VK_EXT_swapchain_maintenance1. Drop the cap as mesa currently only
supports up to spec version 8 because the later versions haven't been
upstreamed to the Vulkan registry yet.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29864>
This commit is contained in:
Yiwei Zhang
2024-06-22 18:35:05 +00:00
committed by Marge Bot
parent 9420e90dfb
commit c4b30b604f
4 changed files with 55 additions and 20 deletions

View File

@@ -523,10 +523,20 @@ vn_android_image_from_anb_internal(struct vn_device *dev,
return result;
/* encoder will strip the Android specific pNext structs */
result = vn_image_create(dev, &builder.create, alloc, &img);
if (result != VK_SUCCESS) {
vn_log(dev->instance, "anb: vn_image_create failed");
return result;
if (*out_img) {
/* driver side img obj has been created for deferred init like ahb */
img = *out_img;
result = vn_image_init_deferred(dev, &builder.create, img);
if (result != VK_SUCCESS) {
vn_log(dev->instance, "anb: vn_image_init_deferred failed");
return result;
}
} else {
result = vn_image_create(dev, &builder.create, alloc, &img);
if (result != VK_SUCCESS) {
vn_log(dev->instance, "anb: vn_image_create failed");
return result;
}
}
img->wsi.is_wsi = true;
@@ -634,6 +644,25 @@ vn_android_image_from_anb(struct vn_device *dev,
return VK_SUCCESS;
}
struct vn_device_memory *
vn_android_get_wsi_memory_from_bind_info(
struct vn_device *dev, const VkBindImageMemoryInfo *bind_info)
{
const VkNativeBufferANDROID *anb_info =
vk_find_struct_const(bind_info->pNext, NATIVE_BUFFER_ANDROID);
assert(anb_info && anb_info->handle);
struct vn_image *img = vn_image_from_handle(bind_info->image);
VkResult result = vn_android_image_from_anb_internal(
dev, &img->deferred_info->create, anb_info, &dev->base.base.alloc,
&img);
if (result != VK_SUCCESS)
return NULL;
assert(img->wsi.memory_owned);
return img->wsi.memory;
}
static VkResult
vn_android_get_ahb_format_properties(
struct vn_device *dev,

View File

@@ -17,9 +17,6 @@
#include <vulkan/vulkan.h>
#include <vulkan/vulkan_android.h>
/* venus implements VK_ANDROID_native_buffer up to spec version 7 */
#define VN_ANDROID_NATIVE_BUFFER_SPEC_VERSION 7
#if DETECT_OS_ANDROID
VkResult
@@ -29,6 +26,10 @@ vn_android_image_from_anb(struct vn_device *dev,
const VkAllocationCallbacks *alloc,
struct vn_image **out_img);
struct vn_device_memory *
vn_android_get_wsi_memory_from_bind_info(
struct vn_device *dev, const VkBindImageMemoryInfo *bind_info);
bool
vn_android_get_drm_format_modifier_info(
const VkPhysicalDeviceImageFormatInfo2 *format_info,
@@ -68,6 +69,14 @@ vn_android_image_from_anb(UNUSED struct vn_device *dev,
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
static inline struct vn_device_memory *
vn_android_get_wsi_memory_from_bind_info(
UNUSED struct vn_device *dev,
UNUSED const VkBindImageMemoryInfo *bind_info)
{
return NULL;
}
static inline bool
vn_android_get_drm_format_modifier_info(
UNUSED const VkPhysicalDeviceImageFormatInfo2 *format_info,

View File

@@ -680,8 +680,12 @@ vn_CreateImage(VkDevice device,
} else if (ahb_info) {
result = vn_image_create_deferred(dev, pCreateInfo, alloc, &img);
} else if (swapchain_info) {
#if DETECT_OS_ANDROID
result = vn_image_create_deferred(dev, pCreateInfo, alloc, &img);
#else
result = vn_wsi_create_image_from_swapchain(
dev, pCreateInfo, swapchain_info, alloc, &img);
#endif
} else {
struct vn_image_create_info local_info;
if (external_info &&
@@ -781,10 +785,11 @@ vn_image_bind_wsi_memory(struct vn_device *dev,
if (!mem) {
#if DETECT_OS_ANDROID
/* TODO handle VkNativeBufferANDROID when we bump up
* VN_ANDROID_NATIVE_BUFFER_SPEC_VERSION
*/
unreachable("VkBindImageMemoryInfo with no memory");
mem = vn_android_get_wsi_memory_from_bind_info(dev, info);
if (!mem) {
STACK_ARRAY_FINISH(local_infos);
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
#else
const VkBindImageMemorySwapchainInfoKHR *swapchain_info =
vk_find_struct_const(info->pNext,
@@ -795,8 +800,8 @@ vn_image_bind_wsi_memory(struct vn_device *dev,
vn_image_from_handle(wsi_common_get_image(
swapchain_info->swapchain, swapchain_info->imageIndex));
mem = swapchain_img->wsi.memory;
info->memory = vn_device_memory_to_handle(mem);
#endif
info->memory = vn_device_memory_to_handle(mem);
}
assert(mem && info->memory != VK_NULL_HANDLE);

View File

@@ -1169,14 +1169,6 @@ vn_physical_device_init_supported_extensions(
physical_dev->extension_spec_versions[i], props->specVersion);
}
}
/* override VK_ANDROID_native_buffer spec version */
if (native.ANDROID_native_buffer) {
const uint32_t index =
VN_EXTENSION_TABLE_INDEX(native, ANDROID_native_buffer);
physical_dev->extension_spec_versions[index] =
VN_ANDROID_NATIVE_BUFFER_SPEC_VERSION;
}
}
static VkResult