mirror of
https://github.com/libsdl-org/SDL.git
synced 2024-11-23 10:53:27 +08:00
gpu: Rework driver name queries, add GetGPUShaderFormats
This commit is contained in:
parent
6d92de5d3a
commit
96e147b2b9
@ -932,23 +932,6 @@ typedef enum SDL_GPUSwapchainComposition
|
|||||||
SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048
|
SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048
|
||||||
} SDL_GPUSwapchainComposition;
|
} SDL_GPUSwapchainComposition;
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies a backend API supported by SDL_GPU.
|
|
||||||
*
|
|
||||||
* Only one of these will be in use at a time.
|
|
||||||
*
|
|
||||||
* \since This enum is available since SDL 3.0.0
|
|
||||||
*/
|
|
||||||
typedef enum SDL_GPUDriver
|
|
||||||
{
|
|
||||||
SDL_GPU_DRIVER_INVALID,
|
|
||||||
SDL_GPU_DRIVER_PRIVATE, /* NDA'd platforms */
|
|
||||||
SDL_GPU_DRIVER_VULKAN,
|
|
||||||
SDL_GPU_DRIVER_D3D11,
|
|
||||||
SDL_GPU_DRIVER_D3D12,
|
|
||||||
SDL_GPU_DRIVER_METAL
|
|
||||||
} SDL_GPUDriver;
|
|
||||||
|
|
||||||
/* Structures */
|
/* Structures */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1704,7 +1687,8 @@ typedef struct SDL_GPUStorageTextureWriteOnlyBinding
|
|||||||
*
|
*
|
||||||
* \since This function is available since SDL 3.0.0.
|
* \since This function is available since SDL 3.0.0.
|
||||||
*
|
*
|
||||||
* \sa SDL_GetGPUDriver
|
* \sa SDL_GetGPUShaderFormats
|
||||||
|
* \sa SDL_GetGPUDeviceDriver
|
||||||
* \sa SDL_DestroyGPUDevice
|
* \sa SDL_DestroyGPUDevice
|
||||||
*/
|
*/
|
||||||
extern SDL_DECLSPEC SDL_GPUDevice *SDLCALL SDL_CreateGPUDevice(
|
extern SDL_DECLSPEC SDL_GPUDevice *SDLCALL SDL_CreateGPUDevice(
|
||||||
@ -1749,7 +1733,8 @@ extern SDL_DECLSPEC SDL_GPUDevice *SDLCALL SDL_CreateGPUDevice(
|
|||||||
*
|
*
|
||||||
* \since This function is available since SDL 3.0.0.
|
* \since This function is available since SDL 3.0.0.
|
||||||
*
|
*
|
||||||
* \sa SDL_GetGPUDriver
|
* \sa SDL_GetGPUShaderFormats
|
||||||
|
* \sa SDL_GetGPUDeviceDriver
|
||||||
* \sa SDL_DestroyGPUDevice
|
* \sa SDL_DestroyGPUDevice
|
||||||
*/
|
*/
|
||||||
extern SDL_DECLSPEC SDL_GPUDevice *SDLCALL SDL_CreateGPUDeviceWithProperties(
|
extern SDL_DECLSPEC SDL_GPUDevice *SDLCALL SDL_CreateGPUDeviceWithProperties(
|
||||||
@ -1778,14 +1763,55 @@ extern SDL_DECLSPEC SDL_GPUDevice *SDLCALL SDL_CreateGPUDeviceWithProperties(
|
|||||||
extern SDL_DECLSPEC void SDLCALL SDL_DestroyGPUDevice(SDL_GPUDevice *device);
|
extern SDL_DECLSPEC void SDLCALL SDL_DestroyGPUDevice(SDL_GPUDevice *device);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the backend used to create this GPU context.
|
* Get the number of GPU drivers compiled into SDL.
|
||||||
|
*
|
||||||
|
* \returns the number of built in GPU drivers.
|
||||||
|
*
|
||||||
|
* \since This function is available since SDL 3.0.0.
|
||||||
|
*
|
||||||
|
* \sa SDL_GetGPUDriver
|
||||||
|
*/
|
||||||
|
extern SDL_DECLSPEC int SDLCALL SDL_GetNumGPUDrivers(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of a built in GPU driver.
|
||||||
|
*
|
||||||
|
* The GPU drivers are presented in the order in which they are normally
|
||||||
|
* checked during initialization.
|
||||||
|
*
|
||||||
|
* The names of drivers are all simple, low-ASCII identifiers, like "vulkan",
|
||||||
|
* "metal" or "direct3d12". These never have Unicode characters, and are not
|
||||||
|
* meant to be proper names.
|
||||||
|
*
|
||||||
|
* \param index the index of a GPU driver.
|
||||||
|
* \returns the name of the GPU driver with the given **index**.
|
||||||
|
*
|
||||||
|
* \since This function is available since SDL 3.0.0.
|
||||||
|
*
|
||||||
|
* \sa SDL_GetNumGPUDrivers
|
||||||
|
*/
|
||||||
|
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGPUDriver(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the backend used to create this GPU context.
|
||||||
*
|
*
|
||||||
* \param device a GPU context to query.
|
* \param device a GPU context to query.
|
||||||
* \returns an SDL_GPUDriver value, or SDL_GPU_DRIVER_INVALID on error.
|
* \returns the name of the device's driver, or NULL on error.
|
||||||
*
|
*
|
||||||
* \since This function is available since SDL 3.0.0.
|
* \since This function is available since SDL 3.0.0.
|
||||||
*/
|
*/
|
||||||
extern SDL_DECLSPEC SDL_GPUDriver SDLCALL SDL_GetGPUDriver(SDL_GPUDevice *device);
|
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGPUDeviceDriver(SDL_GPUDevice *device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the supported shader formats for this GPU context.
|
||||||
|
*
|
||||||
|
* \param device a GPU context to query.
|
||||||
|
* \returns a bitflag indicating which shader formats the driver is
|
||||||
|
* able to consume.
|
||||||
|
*
|
||||||
|
* \since This function is available since SDL 3.0.0.
|
||||||
|
*/
|
||||||
|
extern SDL_DECLSPEC SDL_GPUShaderFormat SDLCALL SDL_GetGPUShaderFormats(SDL_GPUDevice *device);
|
||||||
|
|
||||||
/* State Creation */
|
/* State Creation */
|
||||||
|
|
||||||
|
@ -276,7 +276,9 @@ SDL3_0.0.0 {
|
|||||||
SDL_GetFullscreenDisplayModes;
|
SDL_GetFullscreenDisplayModes;
|
||||||
SDL_GetGDKDefaultUser;
|
SDL_GetGDKDefaultUser;
|
||||||
SDL_GetGDKTaskQueue;
|
SDL_GetGDKTaskQueue;
|
||||||
|
SDL_GetGPUDeviceDriver;
|
||||||
SDL_GetGPUDriver;
|
SDL_GetGPUDriver;
|
||||||
|
SDL_GetGPUShaderFormats;
|
||||||
SDL_GetGPUSwapchainTextureFormat;
|
SDL_GetGPUSwapchainTextureFormat;
|
||||||
SDL_GetGamepadAppleSFSymbolsNameForAxis;
|
SDL_GetGamepadAppleSFSymbolsNameForAxis;
|
||||||
SDL_GetGamepadAppleSFSymbolsNameForButton;
|
SDL_GetGamepadAppleSFSymbolsNameForButton;
|
||||||
@ -392,6 +394,7 @@ SDL3_0.0.0 {
|
|||||||
SDL_GetNumAllocations;
|
SDL_GetNumAllocations;
|
||||||
SDL_GetNumAudioDrivers;
|
SDL_GetNumAudioDrivers;
|
||||||
SDL_GetNumCameraDrivers;
|
SDL_GetNumCameraDrivers;
|
||||||
|
SDL_GetNumGPUDrivers;
|
||||||
SDL_GetNumGamepadTouchpadFingers;
|
SDL_GetNumGamepadTouchpadFingers;
|
||||||
SDL_GetNumGamepadTouchpads;
|
SDL_GetNumGamepadTouchpads;
|
||||||
SDL_GetNumHapticAxes;
|
SDL_GetNumHapticAxes;
|
||||||
|
@ -301,7 +301,9 @@
|
|||||||
#define SDL_GetFullscreenDisplayModes SDL_GetFullscreenDisplayModes_REAL
|
#define SDL_GetFullscreenDisplayModes SDL_GetFullscreenDisplayModes_REAL
|
||||||
#define SDL_GetGDKDefaultUser SDL_GetGDKDefaultUser_REAL
|
#define SDL_GetGDKDefaultUser SDL_GetGDKDefaultUser_REAL
|
||||||
#define SDL_GetGDKTaskQueue SDL_GetGDKTaskQueue_REAL
|
#define SDL_GetGDKTaskQueue SDL_GetGDKTaskQueue_REAL
|
||||||
|
#define SDL_GetGPUDeviceDriver SDL_GetGPUDeviceDriver_REAL
|
||||||
#define SDL_GetGPUDriver SDL_GetGPUDriver_REAL
|
#define SDL_GetGPUDriver SDL_GetGPUDriver_REAL
|
||||||
|
#define SDL_GetGPUShaderFormats SDL_GetGPUShaderFormats_REAL
|
||||||
#define SDL_GetGPUSwapchainTextureFormat SDL_GetGPUSwapchainTextureFormat_REAL
|
#define SDL_GetGPUSwapchainTextureFormat SDL_GetGPUSwapchainTextureFormat_REAL
|
||||||
#define SDL_GetGamepadAppleSFSymbolsNameForAxis SDL_GetGamepadAppleSFSymbolsNameForAxis_REAL
|
#define SDL_GetGamepadAppleSFSymbolsNameForAxis SDL_GetGamepadAppleSFSymbolsNameForAxis_REAL
|
||||||
#define SDL_GetGamepadAppleSFSymbolsNameForButton SDL_GetGamepadAppleSFSymbolsNameForButton_REAL
|
#define SDL_GetGamepadAppleSFSymbolsNameForButton SDL_GetGamepadAppleSFSymbolsNameForButton_REAL
|
||||||
@ -417,6 +419,7 @@
|
|||||||
#define SDL_GetNumAllocations SDL_GetNumAllocations_REAL
|
#define SDL_GetNumAllocations SDL_GetNumAllocations_REAL
|
||||||
#define SDL_GetNumAudioDrivers SDL_GetNumAudioDrivers_REAL
|
#define SDL_GetNumAudioDrivers SDL_GetNumAudioDrivers_REAL
|
||||||
#define SDL_GetNumCameraDrivers SDL_GetNumCameraDrivers_REAL
|
#define SDL_GetNumCameraDrivers SDL_GetNumCameraDrivers_REAL
|
||||||
|
#define SDL_GetNumGPUDrivers SDL_GetNumGPUDrivers_REAL
|
||||||
#define SDL_GetNumGamepadTouchpadFingers SDL_GetNumGamepadTouchpadFingers_REAL
|
#define SDL_GetNumGamepadTouchpadFingers SDL_GetNumGamepadTouchpadFingers_REAL
|
||||||
#define SDL_GetNumGamepadTouchpads SDL_GetNumGamepadTouchpads_REAL
|
#define SDL_GetNumGamepadTouchpads SDL_GetNumGamepadTouchpads_REAL
|
||||||
#define SDL_GetNumHapticAxes SDL_GetNumHapticAxes_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_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_GetGDKDefaultUser,(XUserHandle *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(SDL_bool,SDL_GetGDKTaskQueue,(XTaskQueueHandle *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(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_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)
|
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_GetNumAllocations,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(int,SDL_GetNumAudioDrivers,(void),(),return)
|
SDL_DYNAPI_PROC(int,SDL_GetNumAudioDrivers,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(int,SDL_GetNumCameraDrivers,(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_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_GetNumGamepadTouchpads,(SDL_Gamepad *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(int,SDL_GetNumHapticAxes,(SDL_Haptic *a),(a),return)
|
SDL_DYNAPI_PROC(int,SDL_GetNumHapticAxes,(SDL_Haptic *a),(a),return)
|
||||||
|
@ -371,7 +371,7 @@ void SDL_GPU_BlitCommon(
|
|||||||
// Driver Functions
|
// Driver Functions
|
||||||
|
|
||||||
#ifndef SDL_GPU_DISABLED
|
#ifndef SDL_GPU_DISABLED
|
||||||
static SDL_GPUDriver SDL_GPUSelectBackend(
|
static const SDL_GPUBootstrap * SDL_GPUSelectBackend(
|
||||||
SDL_VideoDevice *_this,
|
SDL_VideoDevice *_this,
|
||||||
const char *gpudriver,
|
const char *gpudriver,
|
||||||
SDL_GPUShaderFormat format_flags)
|
SDL_GPUShaderFormat format_flags)
|
||||||
@ -384,16 +384,16 @@ static SDL_GPUDriver SDL_GPUSelectBackend(
|
|||||||
if (SDL_strcasecmp(gpudriver, backends[i]->name) == 0) {
|
if (SDL_strcasecmp(gpudriver, backends[i]->name) == 0) {
|
||||||
if (!(backends[i]->shader_formats & format_flags)) {
|
if (!(backends[i]->shader_formats & format_flags)) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_GPU, "Required shader format for backend %s not provided!", gpudriver);
|
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)) {
|
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);
|
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) {
|
for (i = 0; backends[i]; i += 1) {
|
||||||
@ -402,12 +402,12 @@ static SDL_GPUDriver SDL_GPUSelectBackend(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (backends[i]->PrepareDriver(_this)) {
|
if (backends[i]->PrepareDriver(_this)) {
|
||||||
return backends[i]->backendflag;
|
return backends[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_GPU, "No supported SDL_GPU backend found!");
|
SDL_LogError(SDL_LOG_CATEGORY_GPU, "No supported SDL_GPU backend found!");
|
||||||
return SDL_GPU_DRIVER_INVALID;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif // SDL_GPU_DISABLED
|
#endif // SDL_GPU_DISABLED
|
||||||
|
|
||||||
@ -455,10 +455,9 @@ SDL_GPUDevice *SDL_CreateGPUDeviceWithProperties(SDL_PropertiesID props)
|
|||||||
bool debug_mode;
|
bool debug_mode;
|
||||||
bool preferLowPower;
|
bool preferLowPower;
|
||||||
|
|
||||||
int i;
|
|
||||||
const char *gpudriver;
|
const char *gpudriver;
|
||||||
SDL_GPUDevice *result = NULL;
|
SDL_GPUDevice *result = NULL;
|
||||||
SDL_GPUDriver selectedBackend;
|
const SDL_GPUBootstrap *selectedBackend;
|
||||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||||
|
|
||||||
if (_this == NULL) {
|
if (_this == NULL) {
|
||||||
@ -494,17 +493,12 @@ SDL_GPUDevice *SDL_CreateGPUDeviceWithProperties(SDL_PropertiesID props)
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectedBackend = SDL_GPUSelectBackend(_this, gpudriver, format_flags);
|
selectedBackend = SDL_GPUSelectBackend(_this, gpudriver, format_flags);
|
||||||
if (selectedBackend != SDL_GPU_DRIVER_INVALID) {
|
if (selectedBackend != NULL) {
|
||||||
for (i = 0; backends[i]; i += 1) {
|
result = selectedBackend->CreateDevice(debug_mode, preferLowPower, props);
|
||||||
if (backends[i]->backendflag == selectedBackend) {
|
if (result != NULL) {
|
||||||
result = backends[i]->CreateDevice(debug_mode, preferLowPower, props);
|
result->backend = selectedBackend->name;
|
||||||
if (result != NULL) {
|
result->shader_formats = selectedBackend->shader_formats;
|
||||||
result->backend = backends[i]->backendflag;
|
result->debug_mode = debug_mode;
|
||||||
result->shader_formats = backends[i]->shader_formats;
|
|
||||||
result->debug_mode = debug_mode;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -521,13 +515,34 @@ void SDL_DestroyGPUDevice(SDL_GPUDevice *device)
|
|||||||
device->DestroyDevice(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;
|
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(
|
Uint32 SDL_GPUTextureFormatTexelBlockSize(
|
||||||
SDL_GPUTextureFormat format)
|
SDL_GPUTextureFormat format)
|
||||||
{
|
{
|
||||||
|
@ -693,12 +693,14 @@ struct SDL_GPUDevice
|
|||||||
// Opaque pointer for the Driver
|
// Opaque pointer for the Driver
|
||||||
SDL_GPURenderer *driverData;
|
SDL_GPURenderer *driverData;
|
||||||
|
|
||||||
// Store this for SDL_GetGPUDriver()
|
// Store this for SDL_GetGPUDeviceDriver()
|
||||||
SDL_GPUDriver backend;
|
const char *backend;
|
||||||
|
|
||||||
|
// Store this for SDL_GetGPUShaderFormats()
|
||||||
|
SDL_GPUShaderFormat shader_formats;
|
||||||
|
|
||||||
// Store this for SDL_gpu.c's debug layer
|
// Store this for SDL_gpu.c's debug layer
|
||||||
bool debug_mode;
|
bool debug_mode;
|
||||||
SDL_GPUShaderFormat shader_formats;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ASSIGN_DRIVER_FUNC(func, name) \
|
#define ASSIGN_DRIVER_FUNC(func, name) \
|
||||||
@ -786,7 +788,6 @@ struct SDL_GPUDevice
|
|||||||
typedef struct SDL_GPUBootstrap
|
typedef struct SDL_GPUBootstrap
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
const SDL_GPUDriver backendflag;
|
|
||||||
const SDL_GPUShaderFormat shader_formats;
|
const SDL_GPUShaderFormat shader_formats;
|
||||||
bool (*PrepareDriver)(SDL_VideoDevice *_this);
|
bool (*PrepareDriver)(SDL_VideoDevice *_this);
|
||||||
SDL_GPUDevice *(*CreateDevice)(bool debug_mode, bool prefer_low_power, SDL_PropertiesID props);
|
SDL_GPUDevice *(*CreateDevice)(bool debug_mode, bool prefer_low_power, SDL_PropertiesID props);
|
||||||
|
@ -6432,7 +6432,6 @@ tryCreateDevice:
|
|||||||
|
|
||||||
SDL_GPUBootstrap D3D11Driver = {
|
SDL_GPUBootstrap D3D11Driver = {
|
||||||
"direct3d11",
|
"direct3d11",
|
||||||
SDL_GPU_DRIVER_D3D11,
|
|
||||||
SDL_GPU_SHADERFORMAT_DXBC,
|
SDL_GPU_SHADERFORMAT_DXBC,
|
||||||
D3D11_PrepareDriver,
|
D3D11_PrepareDriver,
|
||||||
D3D11_CreateDevice
|
D3D11_CreateDevice
|
||||||
|
@ -8348,7 +8348,6 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
|
|||||||
|
|
||||||
SDL_GPUBootstrap D3D12Driver = {
|
SDL_GPUBootstrap D3D12Driver = {
|
||||||
"direct3d12",
|
"direct3d12",
|
||||||
SDL_GPU_DRIVER_D3D12,
|
|
||||||
SDL_GPU_SHADERFORMAT_DXIL,
|
SDL_GPU_SHADERFORMAT_DXIL,
|
||||||
D3D12_PrepareDriver,
|
D3D12_PrepareDriver,
|
||||||
D3D12_CreateDevice
|
D3D12_CreateDevice
|
||||||
|
@ -4120,7 +4120,6 @@ static SDL_GPUDevice *METAL_CreateDevice(bool debugMode, bool preferLowPower, SD
|
|||||||
|
|
||||||
SDL_GPUBootstrap MetalDriver = {
|
SDL_GPUBootstrap MetalDriver = {
|
||||||
"metal",
|
"metal",
|
||||||
SDL_GPU_DRIVER_METAL,
|
|
||||||
SDL_GPU_SHADERFORMAT_MSL | SDL_GPU_SHADERFORMAT_METALLIB,
|
SDL_GPU_SHADERFORMAT_MSL | SDL_GPU_SHADERFORMAT_METALLIB,
|
||||||
METAL_PrepareDriver,
|
METAL_PrepareDriver,
|
||||||
METAL_CreateDevice
|
METAL_CreateDevice
|
||||||
|
@ -11889,7 +11889,6 @@ static SDL_GPUDevice *VULKAN_CreateDevice(bool debugMode, bool preferLowPower, S
|
|||||||
|
|
||||||
SDL_GPUBootstrap VulkanDriver = {
|
SDL_GPUBootstrap VulkanDriver = {
|
||||||
"vulkan",
|
"vulkan",
|
||||||
SDL_GPU_DRIVER_VULKAN,
|
|
||||||
SDL_GPU_SHADERFORMAT_SPIRV,
|
SDL_GPU_SHADERFORMAT_SPIRV,
|
||||||
VULKAN_PrepareDriver,
|
VULKAN_PrepareDriver,
|
||||||
VULKAN_CreateDevice
|
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)
|
static SDL_GPUShader *CompileShader(const GPU_ShaderSources *sources, SDL_GPUDevice *device, SDL_GPUShaderStage stage)
|
||||||
{
|
{
|
||||||
const GPU_ShaderModuleSource *sms = NULL;
|
const GPU_ShaderModuleSource *sms = NULL;
|
||||||
SDL_GPUDriver driver = SDL_GetGPUDriver(device);
|
SDL_GPUShaderFormat formats = SDL_GetGPUShaderFormats(device);
|
||||||
|
|
||||||
switch (driver) {
|
if (formats == SDL_GPU_SHADERFORMAT_INVALID) {
|
||||||
// clang-format off
|
// SDL_GetGPUShaderFormats already set the error
|
||||||
IF_VULKAN( case SDL_GPU_DRIVER_VULKAN: sms = &sources->spirv; break;)
|
return NULL;
|
||||||
IF_D3D11( case SDL_GPU_DRIVER_D3D11: sms = &sources->dxbc50; break;)
|
#if HAVE_SPIRV_SHADERS
|
||||||
IF_D3D12( case SDL_GPU_DRIVER_D3D12: sms = &sources->dxil60; break;)
|
} else if (formats & SDL_GPU_SHADERFORMAT_SPIRV) {
|
||||||
IF_METAL( case SDL_GPU_DRIVER_METAL: sms = &sources->msl; break;)
|
sms = &sources->spirv;
|
||||||
// clang-format on
|
#endif // HAVE_SPIRV_SHADERS
|
||||||
|
#if HAVE_DXBC50_SHADERS
|
||||||
default:
|
} 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");
|
SDL_SetError("Unsupported GPU backend");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -170,7 +181,11 @@ static SDL_GPUShader *CompileShader(const GPU_ShaderSources *sources, SDL_GPUDev
|
|||||||
sci.code_size = sms->code_len;
|
sci.code_size = sms->code_len;
|
||||||
sci.format = sms->format;
|
sci.format = sms->format;
|
||||||
// FIXME not sure if this is correct
|
// 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_samplers = sources->num_samplers;
|
||||||
sci.num_uniform_buffers = sources->num_uniform_buffers;
|
sci.num_uniform_buffers = sources->num_uniform_buffers;
|
||||||
sci.stage = stage;
|
sci.stage = stage;
|
||||||
|
@ -423,18 +423,18 @@ load_shader(SDL_bool is_vertex)
|
|||||||
createinfo.num_uniform_buffers = is_vertex ? 1 : 0;
|
createinfo.num_uniform_buffers = is_vertex ? 1 : 0;
|
||||||
createinfo.props = 0;
|
createinfo.props = 0;
|
||||||
|
|
||||||
SDL_GPUDriver backend = SDL_GetGPUDriver(gpu_device);
|
SDL_GPUShaderFormat format = SDL_GetGPUShaderFormats(gpu_device);
|
||||||
if (backend == SDL_GPU_DRIVER_D3D11) {
|
if (format & SDL_GPU_SHADERFORMAT_DXBC) {
|
||||||
createinfo.format = SDL_GPU_SHADERFORMAT_DXBC;
|
createinfo.format = SDL_GPU_SHADERFORMAT_DXBC;
|
||||||
createinfo.code = is_vertex ? D3D11_CubeVert : D3D11_CubeFrag;
|
createinfo.code = is_vertex ? D3D11_CubeVert : D3D11_CubeFrag;
|
||||||
createinfo.code_size = is_vertex ? SDL_arraysize(D3D11_CubeVert) : SDL_arraysize(D3D11_CubeFrag);
|
createinfo.code_size = is_vertex ? SDL_arraysize(D3D11_CubeVert) : SDL_arraysize(D3D11_CubeFrag);
|
||||||
createinfo.entrypoint = is_vertex ? "VSMain" : "PSMain";
|
createinfo.entrypoint = is_vertex ? "VSMain" : "PSMain";
|
||||||
} else if (backend == SDL_GPU_DRIVER_D3D12) {
|
} else if (format & SDL_GPU_SHADERFORMAT_DXIL) {
|
||||||
createinfo.format = SDL_GPU_SHADERFORMAT_DXIL;
|
createinfo.format = SDL_GPU_SHADERFORMAT_DXIL;
|
||||||
createinfo.code = is_vertex ? D3D12_CubeVert : D3D12_CubeFrag;
|
createinfo.code = is_vertex ? D3D12_CubeVert : D3D12_CubeFrag;
|
||||||
createinfo.code_size = is_vertex ? SDL_arraysize(D3D12_CubeVert) : SDL_arraysize(D3D12_CubeFrag);
|
createinfo.code_size = is_vertex ? SDL_arraysize(D3D12_CubeVert) : SDL_arraysize(D3D12_CubeFrag);
|
||||||
createinfo.entrypoint = is_vertex ? "VSMain" : "PSMain";
|
createinfo.entrypoint = is_vertex ? "VSMain" : "PSMain";
|
||||||
} else if (backend == SDL_GPU_DRIVER_METAL) {
|
} else if (format & SDL_GPU_SHADERFORMAT_METALLIB) {
|
||||||
createinfo.format = SDL_GPU_SHADERFORMAT_METALLIB;
|
createinfo.format = SDL_GPU_SHADERFORMAT_METALLIB;
|
||||||
createinfo.code = is_vertex ? cube_vert_metallib : cube_frag_metallib;
|
createinfo.code = is_vertex ? cube_vert_metallib : cube_frag_metallib;
|
||||||
createinfo.code_size = is_vertex ? cube_vert_metallib_len : cube_frag_metallib_len;
|
createinfo.code_size = is_vertex ? cube_vert_metallib_len : cube_frag_metallib_len;
|
||||||
|
Loading…
Reference in New Issue
Block a user