mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-15 22:35:59 +00:00
gpu: Rework driver name queries, add GetGPUShaderFormats
This commit is contained in:
@@ -276,7 +276,9 @@ SDL3_0.0.0 {
|
||||
SDL_GetFullscreenDisplayModes;
|
||||
SDL_GetGDKDefaultUser;
|
||||
SDL_GetGDKTaskQueue;
|
||||
SDL_GetGPUDeviceDriver;
|
||||
SDL_GetGPUDriver;
|
||||
SDL_GetGPUShaderFormats;
|
||||
SDL_GetGPUSwapchainTextureFormat;
|
||||
SDL_GetGamepadAppleSFSymbolsNameForAxis;
|
||||
SDL_GetGamepadAppleSFSymbolsNameForButton;
|
||||
@@ -392,6 +394,7 @@ SDL3_0.0.0 {
|
||||
SDL_GetNumAllocations;
|
||||
SDL_GetNumAudioDrivers;
|
||||
SDL_GetNumCameraDrivers;
|
||||
SDL_GetNumGPUDrivers;
|
||||
SDL_GetNumGamepadTouchpadFingers;
|
||||
SDL_GetNumGamepadTouchpads;
|
||||
SDL_GetNumHapticAxes;
|
||||
|
@@ -301,7 +301,9 @@
|
||||
#define SDL_GetFullscreenDisplayModes SDL_GetFullscreenDisplayModes_REAL
|
||||
#define SDL_GetGDKDefaultUser SDL_GetGDKDefaultUser_REAL
|
||||
#define SDL_GetGDKTaskQueue SDL_GetGDKTaskQueue_REAL
|
||||
#define SDL_GetGPUDeviceDriver SDL_GetGPUDeviceDriver_REAL
|
||||
#define SDL_GetGPUDriver SDL_GetGPUDriver_REAL
|
||||
#define SDL_GetGPUShaderFormats SDL_GetGPUShaderFormats_REAL
|
||||
#define SDL_GetGPUSwapchainTextureFormat SDL_GetGPUSwapchainTextureFormat_REAL
|
||||
#define SDL_GetGamepadAppleSFSymbolsNameForAxis SDL_GetGamepadAppleSFSymbolsNameForAxis_REAL
|
||||
#define SDL_GetGamepadAppleSFSymbolsNameForButton SDL_GetGamepadAppleSFSymbolsNameForButton_REAL
|
||||
@@ -417,6 +419,7 @@
|
||||
#define SDL_GetNumAllocations SDL_GetNumAllocations_REAL
|
||||
#define SDL_GetNumAudioDrivers SDL_GetNumAudioDrivers_REAL
|
||||
#define SDL_GetNumCameraDrivers SDL_GetNumCameraDrivers_REAL
|
||||
#define SDL_GetNumGPUDrivers SDL_GetNumGPUDrivers_REAL
|
||||
#define SDL_GetNumGamepadTouchpadFingers SDL_GetNumGamepadTouchpadFingers_REAL
|
||||
#define SDL_GetNumGamepadTouchpads SDL_GetNumGamepadTouchpads_REAL
|
||||
#define SDL_GetNumHapticAxes SDL_GetNumHapticAxes_REAL
|
||||
|
@@ -321,7 +321,9 @@ SDL_DYNAPI_PROC(float,SDL_GetFloatProperty,(SDL_PropertiesID a, const char *b, f
|
||||
SDL_DYNAPI_PROC(SDL_DisplayMode**,SDL_GetFullscreenDisplayModes,(SDL_DisplayID a, int *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_GetGDKDefaultUser,(XUserHandle *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_GetGDKTaskQueue,(XTaskQueueHandle *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_GPUDriver,SDL_GetGPUDriver,(SDL_GPUDevice *a),(a),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GetGPUDeviceDriver,(SDL_GPUDevice *a),(a),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GetGPUDriver,(int a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_GPUShaderFormat,SDL_GetGPUShaderFormats,(SDL_GPUDevice *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_GPUTextureFormat,SDL_GetGPUSwapchainTextureFormat,(SDL_GPUDevice *a, SDL_Window *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return)
|
||||
@@ -437,6 +439,7 @@ SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetNaturalDisplayOrientation,(SDL_Dis
|
||||
SDL_DYNAPI_PROC(int,SDL_GetNumAllocations,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetNumAudioDrivers,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetNumCameraDrivers,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetNumGPUDrivers,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetNumGamepadTouchpadFingers,(SDL_Gamepad *a, int b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetNumGamepadTouchpads,(SDL_Gamepad *a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetNumHapticAxes,(SDL_Haptic *a),(a),return)
|
||||
|
@@ -371,7 +371,7 @@ void SDL_GPU_BlitCommon(
|
||||
// Driver Functions
|
||||
|
||||
#ifndef SDL_GPU_DISABLED
|
||||
static SDL_GPUDriver SDL_GPUSelectBackend(
|
||||
static const SDL_GPUBootstrap * SDL_GPUSelectBackend(
|
||||
SDL_VideoDevice *_this,
|
||||
const char *gpudriver,
|
||||
SDL_GPUShaderFormat format_flags)
|
||||
@@ -384,16 +384,16 @@ static SDL_GPUDriver SDL_GPUSelectBackend(
|
||||
if (SDL_strcasecmp(gpudriver, backends[i]->name) == 0) {
|
||||
if (!(backends[i]->shader_formats & format_flags)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_GPU, "Required shader format for backend %s not provided!", gpudriver);
|
||||
return SDL_GPU_DRIVER_INVALID;
|
||||
return NULL;
|
||||
}
|
||||
if (backends[i]->PrepareDriver(_this)) {
|
||||
return backends[i]->backendflag;
|
||||
return backends[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_LogError(SDL_LOG_CATEGORY_GPU, "SDL_HINT_GPU_DRIVER %s unsupported!", gpudriver);
|
||||
return SDL_GPU_DRIVER_INVALID;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; backends[i]; i += 1) {
|
||||
@@ -402,12 +402,12 @@ static SDL_GPUDriver SDL_GPUSelectBackend(
|
||||
continue;
|
||||
}
|
||||
if (backends[i]->PrepareDriver(_this)) {
|
||||
return backends[i]->backendflag;
|
||||
return backends[i];
|
||||
}
|
||||
}
|
||||
|
||||
SDL_LogError(SDL_LOG_CATEGORY_GPU, "No supported SDL_GPU backend found!");
|
||||
return SDL_GPU_DRIVER_INVALID;
|
||||
return NULL;
|
||||
}
|
||||
#endif // SDL_GPU_DISABLED
|
||||
|
||||
@@ -455,10 +455,9 @@ SDL_GPUDevice *SDL_CreateGPUDeviceWithProperties(SDL_PropertiesID props)
|
||||
bool debug_mode;
|
||||
bool preferLowPower;
|
||||
|
||||
int i;
|
||||
const char *gpudriver;
|
||||
SDL_GPUDevice *result = NULL;
|
||||
SDL_GPUDriver selectedBackend;
|
||||
const SDL_GPUBootstrap *selectedBackend;
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
|
||||
if (_this == NULL) {
|
||||
@@ -494,17 +493,12 @@ SDL_GPUDevice *SDL_CreateGPUDeviceWithProperties(SDL_PropertiesID props)
|
||||
}
|
||||
|
||||
selectedBackend = SDL_GPUSelectBackend(_this, gpudriver, format_flags);
|
||||
if (selectedBackend != SDL_GPU_DRIVER_INVALID) {
|
||||
for (i = 0; backends[i]; i += 1) {
|
||||
if (backends[i]->backendflag == selectedBackend) {
|
||||
result = backends[i]->CreateDevice(debug_mode, preferLowPower, props);
|
||||
if (result != NULL) {
|
||||
result->backend = backends[i]->backendflag;
|
||||
result->shader_formats = backends[i]->shader_formats;
|
||||
result->debug_mode = debug_mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (selectedBackend != NULL) {
|
||||
result = selectedBackend->CreateDevice(debug_mode, preferLowPower, props);
|
||||
if (result != NULL) {
|
||||
result->backend = selectedBackend->name;
|
||||
result->shader_formats = selectedBackend->shader_formats;
|
||||
result->debug_mode = debug_mode;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -521,13 +515,34 @@ void SDL_DestroyGPUDevice(SDL_GPUDevice *device)
|
||||
device->DestroyDevice(device);
|
||||
}
|
||||
|
||||
SDL_GPUDriver SDL_GetGPUDriver(SDL_GPUDevice *device)
|
||||
int SDL_GetNumGPUDrivers(void)
|
||||
{
|
||||
CHECK_DEVICE_MAGIC(device, SDL_GPU_DRIVER_INVALID);
|
||||
return SDL_arraysize(backends) - 1;
|
||||
}
|
||||
|
||||
const char * SDL_GetGPUDriver(int index)
|
||||
{
|
||||
if (index < 0 || index >= SDL_GetNumGPUDrivers()) {
|
||||
SDL_InvalidParamError("index");
|
||||
return NULL;
|
||||
}
|
||||
return backends[index]->name;
|
||||
}
|
||||
|
||||
const char * SDL_GetGPUDeviceDriver(SDL_GPUDevice *device)
|
||||
{
|
||||
CHECK_DEVICE_MAGIC(device, NULL);
|
||||
|
||||
return device->backend;
|
||||
}
|
||||
|
||||
SDL_GPUShaderFormat SDL_GetGPUShaderFormats(SDL_GPUDevice *device)
|
||||
{
|
||||
CHECK_DEVICE_MAGIC(device, SDL_GPU_SHADERFORMAT_INVALID);
|
||||
|
||||
return device->shader_formats;
|
||||
}
|
||||
|
||||
Uint32 SDL_GPUTextureFormatTexelBlockSize(
|
||||
SDL_GPUTextureFormat format)
|
||||
{
|
||||
|
@@ -693,12 +693,14 @@ struct SDL_GPUDevice
|
||||
// Opaque pointer for the Driver
|
||||
SDL_GPURenderer *driverData;
|
||||
|
||||
// Store this for SDL_GetGPUDriver()
|
||||
SDL_GPUDriver backend;
|
||||
// Store this for SDL_GetGPUDeviceDriver()
|
||||
const char *backend;
|
||||
|
||||
// Store this for SDL_GetGPUShaderFormats()
|
||||
SDL_GPUShaderFormat shader_formats;
|
||||
|
||||
// Store this for SDL_gpu.c's debug layer
|
||||
bool debug_mode;
|
||||
SDL_GPUShaderFormat shader_formats;
|
||||
};
|
||||
|
||||
#define ASSIGN_DRIVER_FUNC(func, name) \
|
||||
@@ -786,7 +788,6 @@ struct SDL_GPUDevice
|
||||
typedef struct SDL_GPUBootstrap
|
||||
{
|
||||
const char *name;
|
||||
const SDL_GPUDriver backendflag;
|
||||
const SDL_GPUShaderFormat shader_formats;
|
||||
bool (*PrepareDriver)(SDL_VideoDevice *_this);
|
||||
SDL_GPUDevice *(*CreateDevice)(bool debug_mode, bool prefer_low_power, SDL_PropertiesID props);
|
||||
|
@@ -6432,7 +6432,6 @@ tryCreateDevice:
|
||||
|
||||
SDL_GPUBootstrap D3D11Driver = {
|
||||
"direct3d11",
|
||||
SDL_GPU_DRIVER_D3D11,
|
||||
SDL_GPU_SHADERFORMAT_DXBC,
|
||||
D3D11_PrepareDriver,
|
||||
D3D11_CreateDevice
|
||||
|
@@ -8348,7 +8348,6 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
|
||||
|
||||
SDL_GPUBootstrap D3D12Driver = {
|
||||
"direct3d12",
|
||||
SDL_GPU_DRIVER_D3D12,
|
||||
SDL_GPU_SHADERFORMAT_DXIL,
|
||||
D3D12_PrepareDriver,
|
||||
D3D12_CreateDevice
|
||||
|
@@ -4120,7 +4120,6 @@ static SDL_GPUDevice *METAL_CreateDevice(bool debugMode, bool preferLowPower, SD
|
||||
|
||||
SDL_GPUBootstrap MetalDriver = {
|
||||
"metal",
|
||||
SDL_GPU_DRIVER_METAL,
|
||||
SDL_GPU_SHADERFORMAT_MSL | SDL_GPU_SHADERFORMAT_METALLIB,
|
||||
METAL_PrepareDriver,
|
||||
METAL_CreateDevice
|
||||
|
@@ -11889,7 +11889,6 @@ static SDL_GPUDevice *VULKAN_CreateDevice(bool debugMode, bool preferLowPower, S
|
||||
|
||||
SDL_GPUBootstrap VulkanDriver = {
|
||||
"vulkan",
|
||||
SDL_GPU_DRIVER_VULKAN,
|
||||
SDL_GPU_SHADERFORMAT_SPIRV,
|
||||
VULKAN_PrepareDriver,
|
||||
VULKAN_CreateDevice
|
||||
|
@@ -150,17 +150,28 @@ static const GPU_ShaderSources frag_shader_sources[NUM_FRAG_SHADERS] = {
|
||||
static SDL_GPUShader *CompileShader(const GPU_ShaderSources *sources, SDL_GPUDevice *device, SDL_GPUShaderStage stage)
|
||||
{
|
||||
const GPU_ShaderModuleSource *sms = NULL;
|
||||
SDL_GPUDriver driver = SDL_GetGPUDriver(device);
|
||||
SDL_GPUShaderFormat formats = SDL_GetGPUShaderFormats(device);
|
||||
|
||||
switch (driver) {
|
||||
// clang-format off
|
||||
IF_VULKAN( case SDL_GPU_DRIVER_VULKAN: sms = &sources->spirv; break;)
|
||||
IF_D3D11( case SDL_GPU_DRIVER_D3D11: sms = &sources->dxbc50; break;)
|
||||
IF_D3D12( case SDL_GPU_DRIVER_D3D12: sms = &sources->dxil60; break;)
|
||||
IF_METAL( case SDL_GPU_DRIVER_METAL: sms = &sources->msl; break;)
|
||||
// clang-format on
|
||||
|
||||
default:
|
||||
if (formats == SDL_GPU_SHADERFORMAT_INVALID) {
|
||||
// SDL_GetGPUShaderFormats already set the error
|
||||
return NULL;
|
||||
#if HAVE_SPIRV_SHADERS
|
||||
} else if (formats & SDL_GPU_SHADERFORMAT_SPIRV) {
|
||||
sms = &sources->spirv;
|
||||
#endif // HAVE_SPIRV_SHADERS
|
||||
#if HAVE_DXBC50_SHADERS
|
||||
} else if (formats & SDL_GPU_SHADERFORMAT_DXBC) {
|
||||
sms = &sources->dxbc50;
|
||||
#endif // HAVE_DXBC50_SHADERS
|
||||
#if HAVE_DXIL60_SHADERS
|
||||
} else if (formats & SDL_GPU_SHADERFORMAT_DXIL) {
|
||||
sms = &sources->dxil60;
|
||||
#endif // HAVE_DXIL60_SHADERS
|
||||
#if HAVE_METAL_SHADERS
|
||||
} else if (formats & SDL_GPU_SHADERFORMAT_MSL) {
|
||||
sms = &sources->msl;
|
||||
#endif // HAVE_METAL_SHADERS
|
||||
} else {
|
||||
SDL_SetError("Unsupported GPU backend");
|
||||
return NULL;
|
||||
}
|
||||
@@ -170,7 +181,11 @@ static SDL_GPUShader *CompileShader(const GPU_ShaderSources *sources, SDL_GPUDev
|
||||
sci.code_size = sms->code_len;
|
||||
sci.format = sms->format;
|
||||
// FIXME not sure if this is correct
|
||||
sci.entrypoint = driver == SDL_GPU_DRIVER_METAL ? "main0" : "main";
|
||||
sci.entrypoint =
|
||||
#if HAVE_METAL_SHADERS
|
||||
(sms == &sources->msl) ? "main0" :
|
||||
#endif // HAVE_METAL_SHADERS
|
||||
"main";
|
||||
sci.num_samplers = sources->num_samplers;
|
||||
sci.num_uniform_buffers = sources->num_uniform_buffers;
|
||||
sci.stage = stage;
|
||||
|
Reference in New Issue
Block a user