Skip to content

Commit 10004ab

Browse files
committed
hints: Added SDL_HINT_LOG_BACKENDS.
Fixes #13354.
1 parent 277f91c commit 10004ab

File tree

12 files changed

+57
-7
lines changed

12 files changed

+57
-7
lines changed

include/SDL3/SDL_hints.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4381,6 +4381,27 @@ extern "C" {
43814381
*/
43824382
#define SDL_HINT_PEN_TOUCH_EVENTS "SDL_PEN_TOUCH_EVENTS"
43834383

4384+
/**
4385+
* A variable controlling whether SDL backend information is logged.
4386+
*
4387+
* The variable can be set to the following values:
4388+
*
4389+
* - "0": Subsystem information will not be logged. (default)
4390+
* - "1": Subsystem information will be logged.
4391+
*
4392+
* This is generally meant to be used as an environment variable to let
4393+
* end-users report what subsystems were chosen on their system, to aid
4394+
* in debugging. Logged information is sent through SDL_Log(), which
4395+
* means by default they appear on stdout on most platforms or maybe
4396+
* OutputDebugString() on Windows, and can be funneled by the app with
4397+
* SDL_SetLogOutputFunction(), etc.
4398+
*
4399+
* This hint can be set anytime, but the specific logs are generated
4400+
* during subsystem init.
4401+
*
4402+
* \since This hint is available since SDL 3.4.0.
4403+
*/
4404+
#define SDL_HINT_LOG_BACKENDS "SDL_LOG_BACKENDS"
43844405

43854406
/**
43864407
* An enumeration of hint priorities.

src/SDL_utils.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,12 @@ char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_nam
552552

553553
return name;
554554
}
555+
556+
void SDL_LogBackend(const char *subsystem, const char *backend)
557+
{
558+
if (SDL_GetHintBoolean(SDL_HINT_LOG_BACKENDS, false)) {
559+
SDL_Log("SDL_BACKEND: %s -> '%s'", subsystem, backend);
560+
}
561+
}
562+
563+

src/SDL_utils_c.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,7 @@ extern const char *SDL_GetPersistentString(const char *string);
7575

7676
extern char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name, const char *default_name);
7777

78+
// Log what backend a subsystem chose, if a hint was set to do so. Useful for debugging.
79+
extern void SDL_LogBackend(const char *subsystem, const char *backend);
80+
7881
#endif // SDL_utils_h_

src/audio/SDL_audio.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,9 @@ bool SDL_InitAudio(const char *driver_name)
10061006
}
10071007
}
10081008

1009-
if (!initialized) {
1009+
if (initialized) {
1010+
SDL_LogBackend("audio", current_audio.name);
1011+
} else {
10101012
// specific drivers will set the error message if they fail, but otherwise we do it here.
10111013
if (!tried_to_init) {
10121014
if (driver_name) {

src/camera/SDL_camera.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,9 @@ bool SDL_CameraInit(const char *driver_name)
15241524
}
15251525
}
15261526

1527-
if (!initialized) {
1527+
if (initialized) {
1528+
SDL_LogBackend("camera", camera_driver.name);
1529+
} else {
15281530
// specific drivers will set the error message if they fail, but otherwise we do it here.
15291531
if (!tried_to_init) {
15301532
if (driver_name) {

src/gpu/SDL_gpu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ SDL_GPUDevice *SDL_CreateGPUDeviceWithProperties(SDL_PropertiesID props)
711711

712712
selectedBackend = SDL_GPUSelectBackend(props);
713713
if (selectedBackend != NULL) {
714+
SDL_LogBackend("gpu", selectedBackend->name);
714715
debug_mode = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN, true);
715716
preferLowPower = SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOLEAN, false);
716717

src/io/io_uring/SDL_asyncio_liburing.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,12 @@ static void MaybeInitializeLibUring(void)
512512
{
513513
if (SDL_ShouldInit(&liburing_init)) {
514514
if (LoadLibUring()) {
515+
SDL_LogBackend("asyncio", "liburing");
515516
CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_liburing;
516517
QuitAsyncIO = SDL_SYS_QuitAsyncIO_liburing;
517518
AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_liburing;
518519
} else { // can't use liburing? Use the "generic" threadpool implementation instead.
520+
SDL_LogBackend("asyncio", "generic");
519521
CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_Generic;
520522
QuitAsyncIO = SDL_SYS_QuitAsyncIO_Generic;
521523
AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_Generic;

src/io/windows/SDL_asyncio_windows_ioring.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,12 @@ static void MaybeInitializeWinIoRing(void)
511511
{
512512
if (SDL_ShouldInit(&ioring_init)) {
513513
if (LoadWinIoRing()) {
514+
SDL_LogBackend("asyncio", "ioring");
514515
CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_ioring;
515516
QuitAsyncIO = SDL_SYS_QuitAsyncIO_ioring;
516517
AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_ioring;
517518
} else { // can't use ioring? Use the "generic" threadpool implementation instead.
519+
SDL_LogBackend("asyncio", "generic");
518520
CreateAsyncIOQueue = SDL_SYS_CreateAsyncIOQueue_Generic;
519521
QuitAsyncIO = SDL_SYS_QuitAsyncIO_Generic;
520522
AsyncIOFromFile = SDL_SYS_AsyncIOFromFile_Generic;

src/power/SDL_power.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static SDL_GetPowerInfo_Impl implementations[] = {
8484
SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent)
8585
{
8686
#ifndef SDL_POWER_DISABLED
87-
const int total = sizeof(implementations) / sizeof(implementations[0]);
87+
const int total = SDL_arraysize(implementations);
8888
SDL_PowerState result = SDL_POWERSTATE_UNKNOWN;
8989
int i;
9090
#endif

src/render/SDL_render.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,9 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
10631063
}
10641064
}
10651065

1066-
if (!rc) {
1066+
if (rc) {
1067+
SDL_LogBackend("render", renderer->name);
1068+
} else {
10671069
if (driver_name) {
10681070
SDL_SetError("%s not available", driver_name);
10691071
} else {

0 commit comments

Comments
 (0)