From e46d8756e589401b5074027b8ec8ecfbb41ed07d Mon Sep 17 00:00:00 2001
From: cosmonaut <[EMAIL REDACTED]>
Date: Thu, 19 Dec 2024 15:55:04 -0800
Subject: [PATCH] tests: Update GPU tests to use new swapchain best practice
---
test/testgpu_simple_clear.c | 33 ++++++++++++++++-----------------
test/testgpu_spinning_cube.c | 10 ++--------
2 files changed, 18 insertions(+), 25 deletions(-)
diff --git a/test/testgpu_simple_clear.c b/test/testgpu_simple_clear.c
index 940dd37d668e5..ded85e4eaea97 100644
--- a/test/testgpu_simple_clear.c
+++ b/test/testgpu_simple_clear.c
@@ -82,26 +82,25 @@ SDL_AppResult SDL_AppIterate(void *appstate)
}
SDL_GPUTexture *swapchainTexture;
- if (!SDL_AcquireGPUSwapchainTexture(cmdbuf, state->windows[0], &swapchainTexture, NULL, NULL)) {
+ if (!SDL_WaitAndAcquireGPUSwapchainTexture(cmdbuf, state->windows[0], &swapchainTexture, NULL, NULL)) {
SDL_Log("SDL_AcquireGPUSwapchainTexture failed: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
- if (swapchainTexture != NULL) {
- const double currentTime = (double)SDL_GetPerformanceCounter() / SDL_GetPerformanceFrequency();
- SDL_GPURenderPass *renderPass;
- SDL_GPUColorTargetInfo color_target_info;
- SDL_zero(color_target_info);
- color_target_info.texture = swapchainTexture;
- color_target_info.clear_color.r = (float)(0.5 + 0.5 * SDL_sin(currentTime));
- color_target_info.clear_color.g = (float)(0.5 + 0.5 * SDL_sin(currentTime + SDL_PI_D * 2 / 3));
- color_target_info.clear_color.b = (float)(0.5 + 0.5 * SDL_sin(currentTime + SDL_PI_D * 4 / 3));
- color_target_info.clear_color.a = 1.0f;
- color_target_info.load_op = SDL_GPU_LOADOP_CLEAR;
- color_target_info.store_op = SDL_GPU_STOREOP_STORE;
-
- renderPass = SDL_BeginGPURenderPass(cmdbuf, &color_target_info, 1, NULL);
- SDL_EndGPURenderPass(renderPass);
- }
+
+ const double currentTime = (double)SDL_GetPerformanceCounter() / SDL_GetPerformanceFrequency();
+ SDL_GPURenderPass *renderPass;
+ SDL_GPUColorTargetInfo color_target_info;
+ SDL_zero(color_target_info);
+ color_target_info.texture = swapchainTexture;
+ color_target_info.clear_color.r = (float)(0.5 + 0.5 * SDL_sin(currentTime));
+ color_target_info.clear_color.g = (float)(0.5 + 0.5 * SDL_sin(currentTime + SDL_PI_D * 2 / 3));
+ color_target_info.clear_color.b = (float)(0.5 + 0.5 * SDL_sin(currentTime + SDL_PI_D * 4 / 3));
+ color_target_info.clear_color.a = 1.0f;
+ color_target_info.load_op = SDL_GPU_LOADOP_CLEAR;
+ color_target_info.store_op = SDL_GPU_STOREOP_STORE;
+
+ renderPass = SDL_BeginGPURenderPass(cmdbuf, &color_target_info, 1, NULL);
+ SDL_EndGPURenderPass(renderPass);
SDL_SubmitGPUCommandBuffer(cmdbuf);
diff --git a/test/testgpu_spinning_cube.c b/test/testgpu_spinning_cube.c
index df07e5c5f0c4a..8ea37ace78db7 100644
--- a/test/testgpu_spinning_cube.c
+++ b/test/testgpu_spinning_cube.c
@@ -341,20 +341,14 @@ Render(SDL_Window *window, const int windownum)
SDL_Log("Failed to acquire command buffer :%s", SDL_GetError());
quit(2);
}
- if (!SDL_AcquireGPUSwapchainTexture(cmd, state->windows[windownum], &swapchainTexture, &drawablew, &drawableh)) {
+ if (!SDL_WaitAndAcquireGPUSwapchainTexture(cmd, state->windows[windownum], &swapchainTexture, &drawablew, &drawableh)) {
SDL_Log("Failed to acquire swapchain texture: %s", SDL_GetError());
quit(2);
}
- if (swapchainTexture == NULL) {
- /* No swapchain was acquired, probably too many frames in flight */
- SDL_SubmitGPUCommandBuffer(cmd);
- return;
- }
-
/*
* Do some rotation with Euler angles. It is not a fixed axis as
- * quaterions would be, but the effect is cool.
+ * quaternions would be, but the effect is cool.
*/
rotate_matrix((float)winstate->angle_x, 1.0f, 0.0f, 0.0f, matrix_modelview);
rotate_matrix((float)winstate->angle_y, 0.0f, 1.0f, 0.0f, matrix_rotate);