Skip to content

Commit 510126e

Browse files
flibitijibiboslouken
authored andcommitted
gpu: Check shader format support in PrepareDriver
1 parent 8289656 commit 510126e

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

src/gpu/SDL_gpu.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ void SDL_GPU_BlitCommon(
517517
static const SDL_GPUBootstrap * SDL_GPUSelectBackend(SDL_PropertiesID props)
518518
{
519519
Uint32 i;
520-
SDL_GPUShaderFormat format_flags = 0;
521520
const char *gpudriver;
522521
SDL_VideoDevice *_this = SDL_GetVideoDevice();
523522

@@ -526,25 +525,6 @@ static const SDL_GPUBootstrap * SDL_GPUSelectBackend(SDL_PropertiesID props)
526525
return NULL;
527526
}
528527

529-
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_PRIVATE_BOOLEAN, false)) {
530-
format_flags |= SDL_GPU_SHADERFORMAT_PRIVATE;
531-
}
532-
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN, false)) {
533-
format_flags |= SDL_GPU_SHADERFORMAT_SPIRV;
534-
}
535-
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN, false)) {
536-
format_flags |= SDL_GPU_SHADERFORMAT_DXBC;
537-
}
538-
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN, false)) {
539-
format_flags |= SDL_GPU_SHADERFORMAT_DXIL;
540-
}
541-
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN, false)) {
542-
format_flags |= SDL_GPU_SHADERFORMAT_MSL;
543-
}
544-
if (SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOLEAN, false)) {
545-
format_flags |= SDL_GPU_SHADERFORMAT_METALLIB;
546-
}
547-
548528
gpudriver = SDL_GetHint(SDL_HINT_GPU_DRIVER);
549529
if (gpudriver == NULL) {
550530
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)
554534
if (gpudriver != NULL) {
555535
for (i = 0; backends[i]; i += 1) {
556536
if (SDL_strcasecmp(gpudriver, backends[i]->name) == 0) {
557-
if (!(backends[i]->shader_formats & format_flags)) {
558-
SDL_SetError("Required shader format for backend %s not provided!", gpudriver);
559-
return NULL;
560-
}
561537
if (backends[i]->PrepareDriver(_this, props)) {
562538
return backends[i];
563539
}
@@ -569,10 +545,6 @@ static const SDL_GPUBootstrap * SDL_GPUSelectBackend(SDL_PropertiesID props)
569545
}
570546

571547
for (i = 0; backends[i]; i += 1) {
572-
if ((backends[i]->shader_formats & format_flags) == 0) {
573-
// Don't select a backend which doesn't support the app's shaders.
574-
continue;
575-
}
576548
if (backends[i]->PrepareDriver(_this, props)) {
577549
return backends[i];
578550
}

src/gpu/SDL_sysgpu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ struct SDL_GPUDevice
11411141
typedef struct SDL_GPUBootstrap
11421142
{
11431143
const char *name;
1144-
const SDL_GPUShaderFormat shader_formats;
11451144
bool (*PrepareDriver)(SDL_VideoDevice *_this, SDL_PropertiesID props);
11461145
SDL_GPUDevice *(*CreateDevice)(bool debug_mode, bool prefer_low_power, SDL_PropertiesID props);
11471146
} SDL_GPUBootstrap;

src/gpu/d3d12/SDL_gpu_d3d12.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8333,6 +8333,17 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this, SDL_PropertiesID props)
83338333
IDXGIFactory6 *factory6;
83348334
IDXGIAdapter1 *adapter;
83358335

8336+
// Early check to see if the app has _any_ D3D12 formats, if not we don't
8337+
// have to fuss with loading D3D in the first place.
8338+
bool has_dxbc = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN, false);
8339+
bool has_dxil = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN, false);
8340+
bool supports_dxil = false;
8341+
// TODO SM7: bool has_spirv = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN, false);
8342+
// TODO SM7: bool supports_spirv = false;
8343+
if (!has_dxbc && !has_dxil) {
8344+
return false;
8345+
}
8346+
83368347
// Can we load D3D12?
83378348

83388349
d3d12Dll = SDL_LoadObject(D3D12_DLL);
@@ -8427,6 +8438,18 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this, SDL_PropertiesID props)
84278438
(void **)&device);
84288439

84298440
if (SUCCEEDED(res)) {
8441+
D3D12_FEATURE_DATA_SHADER_MODEL shaderModel;
8442+
shaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_0;
8443+
8444+
res = ID3D12Device_CheckFeatureSupport(
8445+
device,
8446+
D3D12_FEATURE_SHADER_MODEL,
8447+
&shaderModel,
8448+
sizeof(shaderModel));
8449+
if (SUCCEEDED(res) && shaderModel.HighestShaderModel >= D3D_SHADER_MODEL_6_0) {
8450+
supports_dxil = true;
8451+
}
8452+
84308453
ID3D12Device_Release(device);
84318454
}
84328455
IDXGIAdapter1_Release(adapter);
@@ -8435,6 +8458,11 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this, SDL_PropertiesID props)
84358458
SDL_UnloadObject(d3d12Dll);
84368459
SDL_UnloadObject(dxgiDll);
84378460

8461+
if (!supports_dxil && !has_dxbc) {
8462+
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "D3D12: DXIL is not supported and DXBC is not being provided");
8463+
return false;
8464+
}
8465+
84388466
if (FAILED(res)) {
84398467
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "D3D12: Could not create D3D12Device with feature level " D3D_FEATURE_LEVEL_CHOICE_STR);
84408468
return false;
@@ -9207,7 +9235,6 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
92079235

92089236
SDL_GPUBootstrap D3D12Driver = {
92099237
"direct3d12",
9210-
SDL_GPU_SHADERFORMAT_DXIL | SDL_GPU_SHADERFORMAT_DXBC,
92119238
D3D12_PrepareDriver,
92129239
D3D12_CreateDevice
92139240
};

src/gpu/metal/SDL_gpu_metal.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4309,6 +4309,11 @@ static bool METAL_SupportsTextureFormat(
43094309

43104310
static bool METAL_PrepareDriver(SDL_VideoDevice *this, SDL_PropertiesID props)
43114311
{
4312+
if (!SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN, false) &&
4313+
!SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOLEAN, false)) {
4314+
return false;
4315+
}
4316+
43124317
if (@available(macOS 10.14, iOS 13.0, tvOS 13.0, *)) {
43134318
return (this->Metal_CreateView != NULL);
43144319
}
@@ -4619,7 +4624,6 @@ static void METAL_INTERNAL_DestroyBlitResources(
46194624

46204625
SDL_GPUBootstrap MetalDriver = {
46214626
"metal",
4622-
SDL_GPU_SHADERFORMAT_MSL | SDL_GPU_SHADERFORMAT_METALLIB,
46234627
METAL_PrepareDriver,
46244628
METAL_CreateDevice
46254629
};

src/gpu/vulkan/SDL_gpu_vulkan.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11605,6 +11605,10 @@ static bool VULKAN_PrepareDriver(SDL_VideoDevice *_this, SDL_PropertiesID props)
1160511605
VulkanRenderer *renderer;
1160611606
bool result = false;
1160711607

11608+
if (!SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN, false)) {
11609+
return false;
11610+
}
11611+
1160811612
if (_this->Vulkan_CreateSurface == NULL) {
1160911613
return false;
1161011614
}
@@ -11987,7 +11991,6 @@ static SDL_GPUDevice *VULKAN_CreateDevice(bool debugMode, bool preferLowPower, S
1198711991

1198811992
SDL_GPUBootstrap VulkanDriver = {
1198911993
"vulkan",
11990-
SDL_GPU_SHADERFORMAT_SPIRV,
1199111994
VULKAN_PrepareDriver,
1199211995
VULKAN_CreateDevice
1199311996
};

0 commit comments

Comments
 (0)