gpu: Check shader format support in PrepareDriver

This commit is contained in:
Ethan Lee
2025-05-19 08:56:29 -04:00
committed by Sam Lantinga
parent 8289656a4e
commit 510126ee63
5 changed files with 37 additions and 32 deletions

View File

@@ -517,7 +517,6 @@ void SDL_GPU_BlitCommon(
static const SDL_GPUBootstrap * SDL_GPUSelectBackend(SDL_PropertiesID props)
{
Uint32 i;
SDL_GPUShaderFormat format_flags = 0;
const char *gpudriver;
SDL_VideoDevice *_this = SDL_GetVideoDevice();
@@ -526,25 +525,6 @@ static const SDL_GPUBootstrap * SDL_GPUSelectBackend(SDL_PropertiesID props)
return NULL;
}
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_PRIVATE_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_PRIVATE;
}
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_SPIRV;
}
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_DXBC;
}
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_DXIL;
}
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_MSL;
}
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOLEAN, false)) {
format_flags |= SDL_GPU_SHADERFORMAT_METALLIB;
}
gpudriver = SDL_GetHint(SDL_HINT_GPU_DRIVER);
if (gpudriver == NULL) {
gpudriver = SDL_GetStringProperty(props, SDL_PROP_GPU_DEVICE_CREATE_NAME_STRING, NULL);
@@ -554,10 +534,6 @@ static const SDL_GPUBootstrap * SDL_GPUSelectBackend(SDL_PropertiesID props)
if (gpudriver != NULL) {
for (i = 0; backends[i]; i += 1) {
if (SDL_strcasecmp(gpudriver, backends[i]->name) == 0) {
if (!(backends[i]->shader_formats & format_flags)) {
SDL_SetError("Required shader format for backend %s not provided!", gpudriver);
return NULL;
}
if (backends[i]->PrepareDriver(_this, props)) {
return backends[i];
}
@@ -569,10 +545,6 @@ static const SDL_GPUBootstrap * SDL_GPUSelectBackend(SDL_PropertiesID props)
}
for (i = 0; backends[i]; i += 1) {
if ((backends[i]->shader_formats & format_flags) == 0) {
// Don't select a backend which doesn't support the app's shaders.
continue;
}
if (backends[i]->PrepareDriver(_this, props)) {
return backends[i];
}