SDL: Vulkan: added handling for SDL_MATRIX_COEFFICIENTS_UNSPECIFIED

From 0c6a1b636e42b7193027383d75f509a9e5d00214 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 28 Feb 2024 19:16:55 -0800
Subject: [PATCH] Vulkan: added handling for
 SDL_MATRIX_COEFFICIENTS_UNSPECIFIED

---
 src/render/vulkan/SDL_render_vulkan.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/render/vulkan/SDL_render_vulkan.c b/src/render/vulkan/SDL_render_vulkan.c
index 927f327c6f10..d92dce4426c6 100644
--- a/src/render/vulkan/SDL_render_vulkan.c
+++ b/src/render/vulkan/SDL_render_vulkan.c
@@ -2438,6 +2438,7 @@ static int VULKAN_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
         texture->format == SDL_PIXELFORMAT_NV12 ||
         texture->format == SDL_PIXELFORMAT_NV21 ||
         texture->format == SDL_PIXELFORMAT_P010) {
+        const uint32_t YUV_SD_THRESHOLD = 576;
 
         /* Check that we have VK_KHR_sampler_ycbcr_conversion support */
         if (!rendererData->supportsKHRSamplerYCbCrConversion) {
@@ -2465,6 +2466,15 @@ static int VULKAN_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
         case SDL_MATRIX_COEFFICIENTS_BT2020_CL:
             samplerYcbcrConversionCreateInfo.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020_KHR;
             break;
+        case SDL_MATRIX_COEFFICIENTS_UNSPECIFIED:
+            if (texture->format == SDL_PIXELFORMAT_P010) {
+                samplerYcbcrConversionCreateInfo.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020_KHR;
+            } else if (height > YUV_SD_THRESHOLD) {
+                samplerYcbcrConversionCreateInfo.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709_KHR;
+            } else {
+                samplerYcbcrConversionCreateInfo.ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601_KHR;
+            }
+            break;
         default:
             return SDL_SetError("[Vulkan] Unsupported Ycbcr colorspace: %d", SDL_COLORSPACEMATRIX(texture->colorspace));
         }