From 4294c0683611bc6cca4e0c5c7fe44e69a841dc0b Mon Sep 17 00:00:00 2001
From: cosmonaut <[EMAIL REDACTED]>
Date: Tue, 14 Jan 2025 10:16:20 -0800
Subject: [PATCH] GPU: Check texture format support in pipeline creation
---
src/gpu/SDL_gpu.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/gpu/SDL_gpu.c b/src/gpu/SDL_gpu.c
index 34905cea2ce36..b3148c27d771e 100644
--- a/src/gpu/SDL_gpu.c
+++ b/src/gpu/SDL_gpu.c
@@ -801,6 +801,10 @@ SDL_GPUGraphicsPipeline *SDL_CreateGPUGraphicsPipeline(
SDL_assert_release(!"Color target formats cannot be a depth format!");
return NULL;
}
+ if (!SDL_GPUTextureSupportsFormat(device, graphicsPipelineCreateInfo->target_info.color_target_descriptions[i].format, SDL_GPU_TEXTURETYPE_2D, SDL_GPU_TEXTUREUSAGE_COLOR_TARGET)) {
+ SDL_assert_release(!"Format is not supported for color targets on this device!");
+ return NULL;
+ }
if (graphicsPipelineCreateInfo->target_info.color_target_descriptions[i].blend_state.enable_blend) {
const SDL_GPUColorTargetBlendState *blend_state = &graphicsPipelineCreateInfo->target_info.color_target_descriptions[i].blend_state;
CHECK_BLENDFACTOR_ENUM_INVALID(blend_state->src_color_blendfactor, NULL)
@@ -817,6 +821,10 @@ SDL_GPUGraphicsPipeline *SDL_CreateGPUGraphicsPipeline(
SDL_assert_release(!"Depth-stencil target format must be a depth format!");
return NULL;
}
+ if (!SDL_GPUTextureSupportsFormat(device, graphicsPipelineCreateInfo->target_info.depth_stencil_format, SDL_GPU_TEXTURETYPE_2D, SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET)) {
+ SDL_assert_release(!"Format is not supported for depth targets on this device!");
+ return NULL;
+ }
}
if (graphicsPipelineCreateInfo->vertex_input_state.num_vertex_buffers > 0 && graphicsPipelineCreateInfo->vertex_input_state.vertex_buffer_descriptions == NULL) {
SDL_assert_release(!"Vertex buffer descriptions array pointer cannot be NULL!");