SDL: GPU Vulkan: handle VK_ERROR_SURFACE_LOST_KHR in acquire path

From c98b36ff03023affddd12c9c8951d370f7ccb742 Mon Sep 17 00:00:00 2001
From: Sascha Reuter <[EMAIL REDACTED]>
Date: Mon, 6 Apr 2026 19:57:00 +1000
Subject: [PATCH] GPU Vulkan: handle VK_ERROR_SURFACE_LOST_KHR in acquire path

On Android, backgrounding and foregrounding an app causes the Vulkan
surface to be destroyed. vkAcquireNextImageKHR returns
VK_ERROR_SURFACE_LOST_KHR, but the acquire while(true) loop only calls
RecreateSwapchain which doesn't recreate the surface, resulting in an
infinite retry loop and a black screen.

Handle VK_ERROR_SURFACE_LOST_KHR by setting both needsSurfaceRecreate
and needsSwapchainRecreate, then returning to let the existing
recreation path handle it on the next call.

Fixes #15322
---
 src/gpu/vulkan/SDL_gpu_vulkan.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/gpu/vulkan/SDL_gpu_vulkan.c b/src/gpu/vulkan/SDL_gpu_vulkan.c
index cbb7fc72bd85f..af4f265643b0d 100644
--- a/src/gpu/vulkan/SDL_gpu_vulkan.c
+++ b/src/gpu/vulkan/SDL_gpu_vulkan.c
@@ -10214,6 +10214,13 @@ static bool VULKAN_INTERNAL_AcquireSwapchainTexture(
             break;  // we got the next image!
         }
 
+        // Surface lost — flag for surface + swapchain recreation on next call
+        if (acquireResult == VK_ERROR_SURFACE_LOST_KHR) {
+            windowData->needsSurfaceRecreate = true;
+            windowData->needsSwapchainRecreate = true;
+            return true;
+        }
+
         // If acquisition is invalid, let's try to recreate
         Uint32 recreateSwapchainResult = VULKAN_INTERNAL_RecreateSwapchain(renderer, windowData);
         if (!recreateSwapchainResult) {