SDL: SDL_test: add --gpu option

From 88fe52df7b79c7786b1c96ca200d45eec4618e18 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 30 Aug 2024 13:43:38 +0200
Subject: [PATCH] SDL_test: add --gpu option

---
 include/SDL3/SDL_test_common.h |  1 +
 src/test/SDL_test_common.c     | 10 ++++++++++
 test/testgpu_spinning_cube.c   |  4 ++--
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/include/SDL3/SDL_test_common.h b/include/SDL3/SDL_test_common.h
index dcc0c7bc77438..8bef92955dba8 100644
--- a/include/SDL3/SDL_test_common.h
+++ b/include/SDL3/SDL_test_common.h
@@ -91,6 +91,7 @@ typedef struct
     SDL_DisplayMode fullscreen_mode;
     int num_windows;
     SDL_Window **windows;
+    const char *gpudriver;
 
     /* Renderer info */
     const char *renderdriver;
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 4805fd9a916b5..71e3609579835 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -72,6 +72,7 @@ static const char *video_usage[] = {
     "[--usable-bounds]",
     "[--utility]",
     "[--video driver]",
+    "[--gpu driver]",
     "[--vsync]"
 };
 
@@ -615,6 +616,15 @@ int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
             state->hide_cursor = SDL_TRUE;
             return 1;
         }
+        if (SDL_strcasecmp(argv[index], "--gpu") == 0) {
+            ++index;
+            if (!argv[index]) {
+                return -1;
+            }
+            state->gpudriver = argv[index];
+            SDL_SetHint(SDL_HINT_GPU_DRIVER, state->gpudriver);
+            return 2;
+        }
     } else {
         if (SDL_strcasecmp(argv[index], "--info") == 0) {
             ++index;
diff --git a/test/testgpu_spinning_cube.c b/test/testgpu_spinning_cube.c
index eb4b5491e442e..4aed3aff2f9de 100644
--- a/test/testgpu_spinning_cube.c
+++ b/test/testgpu_spinning_cube.c
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
+  Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -470,7 +470,7 @@ init_render_state(int msaa)
     gpu_device = SDL_CreateGPUDevice(
         TESTGPU_SUPPORTED_FORMATS,
         SDL_TRUE,
-        NULL
+        state->gpudriver
     );
     CHECK_CREATE(gpu_device, "GPU device");