wsi/metal: Expose additional color spaces if instance extension enabled

Caught through VVL test NegativeWsi.SwapchainImageFormatList. The test
would try to create a swapchain with a color space from
VK_EXT_swapchain_colorspace without enabling the extension. This is
because wsi would expose those color spaces even when the extension was
not enabled.

Fixes: fd045ac99c ("wsi/metal: add support for color spaces")

Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Signed-off-by: Aitor Camacho <aitor@lunarg.com>
(cherry picked from commit e6f118f12b)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40092>
This commit is contained in:
Aitor Camacho 2026-02-09 21:51:48 +09:00 committed by Eric Engestrom
parent 1994d93542
commit 4229b57783
2 changed files with 13 additions and 3 deletions

View file

@ -5404,7 +5404,7 @@
"description": "wsi/metal: Expose additional color spaces if instance extension enabled",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "fd045ac99cea5bea1e9e55c4381c37ad0e824352",
"notes": null

View file

@ -192,13 +192,18 @@ wsi_metal_surface_get_formats(VkIcdSurfaceBase *icd_surface,
uint32_t* pSurfaceFormatCount,
VkSurfaceFormatKHR* pSurfaceFormats)
{
VK_FROM_HANDLE(vk_physical_device, pdev, wsi_device->pdevice);
VK_OUTARRAY_MAKE_TYPED(VkSurfaceFormatKHR, out, pSurfaceFormats, pSurfaceFormatCount);
VkFormat sorted_formats[ARRAY_SIZE(available_surface_formats)];
get_sorted_vk_formats(wsi_device->force_bgra8_unorm_first, sorted_formats);
unsigned color_space_count =
pdev->instance->enabled_extensions.EXT_swapchain_colorspace
? ARRAY_SIZE(available_surface_color_spaces)
: 1u;
for (unsigned i = 0; i < ARRAY_SIZE(sorted_formats); i++) {
for (unsigned j = 0; j < ARRAY_SIZE(available_surface_color_spaces); j++) {
for (unsigned j = 0; j < color_space_count; j++) {
vk_outarray_append_typed(VkSurfaceFormatKHR, &out, f) {
f->format = sorted_formats[i];
f->colorSpace = available_surface_color_spaces[j];
@ -216,13 +221,18 @@ wsi_metal_surface_get_formats2(VkIcdSurfaceBase *icd_surface,
uint32_t* pSurfaceFormatCount,
VkSurfaceFormat2KHR* pSurfaceFormats)
{
VK_FROM_HANDLE(vk_physical_device, pdev, wsi_device->pdevice);
VK_OUTARRAY_MAKE_TYPED(VkSurfaceFormat2KHR, out, pSurfaceFormats, pSurfaceFormatCount);
VkFormat sorted_formats[ARRAY_SIZE(available_surface_formats)];
get_sorted_vk_formats(wsi_device->force_bgra8_unorm_first, sorted_formats);
unsigned color_space_count =
pdev->instance->enabled_extensions.EXT_swapchain_colorspace
? ARRAY_SIZE(available_surface_color_spaces)
: 1u;
for (unsigned i = 0; i < ARRAY_SIZE(sorted_formats); i++) {
for (unsigned j = 0; j < ARRAY_SIZE(available_surface_color_spaces); j++) {
for (unsigned j = 0; j < color_space_count; j++) {
vk_outarray_append_typed(VkSurfaceFormat2KHR, &out, f) {
assert(f->sType == VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR);
f->surfaceFormat.format = sorted_formats[i];