treewide: Use wsi_common_is_swapchain_image() helper
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

Replace the duplicated swapchain image detection pattern across all
Vulkan drivers with the new wsi_common_is_swapchain_image() helper.

Since the swapchain handle can be extracted from VkImageCreateInfo's
pNext chain inside wsi_common_create_swapchain_image(), remove the
now-redundant VkSwapchainKHR parameter from that function.

This removes the #ifdef guards for Android/WSI platforms from each
driver, as the helper now handles this uniformly.

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38541>
This commit is contained in:
Christian Gmeiner 2025-12-08 23:54:25 +01:00 committed by Marge Bot
parent 9a89280d62
commit b393518bdf
14 changed files with 24 additions and 100 deletions

View file

@ -1776,18 +1776,11 @@ radv_CreateImage(VkDevice _device, const VkImageCreateInfo *pCreateInfo, const V
return radv_image_from_gralloc(_device, pCreateInfo, gralloc_info, pAllocator, pImage);
#endif
#ifdef RADV_USE_WSI_PLATFORM
/* Ignore swapchain creation info on Android. Since we don't have an implementation in Mesa,
* we're guaranteed to access an Android object incorrectly.
*/
VK_FROM_HANDLE(radv_device, device, _device);
const struct radv_physical_device *pdev = radv_device_physical(device);
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
return wsi_common_create_swapchain_image(pdev->vk.wsi_device, pCreateInfo, swapchain_info->swapchain, pImage);
}
#endif
if (wsi_common_is_swapchain_image(pCreateInfo))
return wsi_common_create_swapchain_image(pdev->vk.wsi_device, pCreateInfo, pImage);
const struct wsi_image_create_info *wsi_info = vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA);
bool scanout = wsi_info && wsi_info->scanout;

View file

@ -984,18 +984,8 @@ hk_CreateImage(VkDevice _device, const VkImageCreateInfo *pCreateInfo,
struct hk_image *image;
VkResult result;
#ifdef HK_USE_WSI_PLATFORM
/* Ignore swapchain creation info on Android. Since we don't have an
* implementation in Mesa, we're guaranteed to access an Android object
* incorrectly.
*/
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
return wsi_common_create_swapchain_image(
&pdev->wsi_device, pCreateInfo, swapchain_info->swapchain, pImage);
}
#endif
if (wsi_common_is_swapchain_image(pCreateInfo))
return wsi_common_create_swapchain_image(&pdev->wsi_device, pCreateInfo, pImage);
image = vk_zalloc2(&dev->vk.alloc, pAllocator, sizeof(*image), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);

View file

@ -533,16 +533,11 @@ create_image(struct v3dv_device *device,
const VkAllocationCallbacks *pAllocator,
VkImage *pImage)
{
#if !DETECT_OS_ANDROID
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
if (wsi_common_is_swapchain_image(pCreateInfo)) {
return wsi_common_create_swapchain_image(&device->pdevice->wsi_device,
pCreateInfo,
swapchain_info->swapchain,
pImage);
}
#endif
VkResult result;
struct v3dv_image *image = NULL;

View file

@ -834,20 +834,11 @@ tu_CreateImage(VkDevice _device,
VK_FROM_HANDLE(tu_device, device, _device);
#ifdef TU_USE_WSI_PLATFORM
/* Ignore swapchain creation info on Android. Since we don't have an
* implementation in Mesa, we're guaranteed to access an Android object
* incorrectly.
*/
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
if (wsi_common_is_swapchain_image(pCreateInfo)) {
return wsi_common_create_swapchain_image(device->physical_device->vk.wsi_device,
pCreateInfo,
swapchain_info->swapchain,
pImage);
}
#endif
struct tu_image *image = (struct tu_image *)
vk_image_create(&device->vk, pCreateInfo, alloc, sizeof(*image));

View file

@ -223,17 +223,14 @@ lvp_CreateImage(VkDevice _device,
const VkAllocationCallbacks *pAllocator,
VkImage *pImage)
{
#if !DETECT_OS_ANDROID
VK_FROM_HANDLE(lvp_device, device, _device);
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
if (wsi_common_is_swapchain_image(pCreateInfo)) {
return wsi_common_create_swapchain_image(&lvp_device_physical(device)->wsi_device,
pCreateInfo,
swapchain_info->swapchain,
pImage);
}
#endif
return lvp_image_create(_device, pCreateInfo, pAllocator,
pImage);
}

View file

@ -162,16 +162,11 @@ VkResult pvr_CreateImage(VkDevice _device,
VK_FROM_HANDLE(pvr_device, device, _device);
struct pvr_image *image;
#if defined(PVR_USE_WSI_PLATFORM)
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
if (wsi_common_is_swapchain_image(pCreateInfo)) {
return wsi_common_create_swapchain_image(&device->pdevice->wsi_device,
pCreateInfo,
swapchain_info->swapchain,
pImage);
}
#endif
image =
vk_image_create(&device->vk, pCreateInfo, pAllocator, sizeof(*image));

View file

@ -2268,20 +2268,11 @@ VkResult anv_CreateImage(
mesa_logi("=== %s %s:%d flags:0x%08x\n", __func__, __FILE__,
__LINE__, pCreateInfo->flags);
#ifndef VK_USE_PLATFORM_ANDROID_KHR
/* Skip the WSI common swapchain creation here on Android. Similar to ahb,
* this case is handled by a partial image init and then resolved when the
* image is bound and gralloc info is passed.
*/
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
if (wsi_common_is_swapchain_image(pCreateInfo)) {
return wsi_common_create_swapchain_image(&device->physical->wsi_device,
pCreateInfo,
swapchain_info->swapchain,
pImage);
}
#endif
struct anv_image *image =
vk_object_zalloc(&device->vk, pAllocator, sizeof(*image),

View file

@ -1341,20 +1341,11 @@ VkResult anv_CreateImage(
{
ANV_FROM_HANDLE(anv_device, device, _device);
#ifndef VK_USE_PLATFORM_ANDROID_KHR
/* Ignore swapchain creation info on Android. Since we don't have an
* implementation in Mesa, we're guaranteed to access an Android object
* incorrectly.
*/
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
if (wsi_common_is_swapchain_image(pCreateInfo)) {
return wsi_common_create_swapchain_image(&device->physical->wsi_device,
pCreateInfo,
swapchain_info->swapchain,
pImage);
}
#endif
struct anv_image *image =
vk_object_zalloc(&device->vk, pAllocator, sizeof(*image),

View file

@ -604,18 +604,8 @@ kk_CreateImage(VkDevice _device, const VkImageCreateInfo *pCreateInfo,
struct kk_image *image;
VkResult result;
#ifdef KK_USE_WSI_PLATFORM
/* Ignore swapchain creation info on Android. Since we don't have an
* implementation in Mesa, we're guaranteed to access an Android object
* incorrectly.
*/
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
return wsi_common_create_swapchain_image(
&pdev->wsi_device, pCreateInfo, swapchain_info->swapchain, pImage);
}
#endif
if (wsi_common_is_swapchain_image(pCreateInfo))
return wsi_common_create_swapchain_image(&pdev->wsi_device, pCreateInfo, pImage);
image = vk_zalloc2(&dev->vk.alloc, pAllocator, sizeof(*image), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);

View file

@ -1086,20 +1086,11 @@ nvk_CreateImage(VkDevice _device,
struct nvk_image *image;
VkResult result;
#ifdef NVK_USE_WSI_PLATFORM
/* Ignore swapchain creation info on Android. Since we don't have an
* implementation in Mesa, we're guaranteed to access an Android object
* incorrectly.
*/
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
if (wsi_common_is_swapchain_image(pCreateInfo)) {
return wsi_common_create_swapchain_image(&pdev->wsi_device,
pCreateInfo,
swapchain_info->swapchain,
pImage);
}
#endif
image = vk_zalloc2(&dev->vk.alloc, pAllocator, sizeof(*image), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);

View file

@ -618,12 +618,9 @@ panvk_CreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
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) {
if (wsi_common_is_swapchain_image(pCreateInfo)) {
return wsi_common_create_swapchain_image(&phys_dev->wsi_device,
pCreateInfo,
swapchain_info->swapchain,
pImage);
}

View file

@ -689,7 +689,7 @@ vn_CreateImage(VkDevice device,
#else
result = wsi_common_create_swapchain_image(
&dev->physical_device->wsi_device, pCreateInfo,
swapchain_info->swapchain, (VkImage *)&img);
(VkImage *)&img);
#endif
} else {
struct vn_image_create_info local_info;

View file

@ -39,6 +39,7 @@
#include "vk_sync_dummy.h"
#include "vk_util.h"
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
@ -1838,10 +1839,13 @@ wsi_GetDeviceGroupSurfacePresentModesKHR(VkDevice device,
VkResult
wsi_common_create_swapchain_image(const struct wsi_device *wsi,
const VkImageCreateInfo *pCreateInfo,
VkSwapchainKHR _swapchain,
VkImage *pImage)
{
VK_FROM_HANDLE(wsi_swapchain, chain, _swapchain);
const VkImageSwapchainCreateInfoKHR *swapchain_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
assert(swapchain_info);
VK_FROM_HANDLE(wsi_swapchain, chain, swapchain_info->swapchain);
#ifndef NDEBUG
const VkImageCreateInfo *swcInfo = &chain->image_info.create;

View file

@ -309,7 +309,6 @@ wsi_common_is_swapchain_image(const VkImageCreateInfo *pCreateInfo)
VkResult
wsi_common_create_swapchain_image(const struct wsi_device *wsi,
const VkImageCreateInfo *pCreateInfo,
VkSwapchainKHR _swapchain,
VkImage *pImage);
VkImageUsageFlags