Skip to content

Commit 66aaf8e

Browse files
committed
render_gpu: Add hints for debug and low-power preference
1 parent 1df95f3 commit 66aaf8e

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

include/SDL3/SDL_hints.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,34 @@ extern "C" {
27722772
*/
27732773
#define SDL_HINT_RENDER_VULKAN_DEBUG "SDL_RENDER_VULKAN_DEBUG"
27742774

2775+
/**
2776+
* A variable controlling whether to create the GPU device in debug mode.
2777+
*
2778+
* This variable can be set to the following values:
2779+
*
2780+
* - "0": Disable debug mode use (default)
2781+
* - "1": Enable debug mode use
2782+
*
2783+
* This hint should be set before creating a renderer.
2784+
*
2785+
* \since This hint is available since SDL 3.0.0.
2786+
*/
2787+
#define SDL_HINT_RENDER_GPU_DEBUG "SDL_RENDER_GPU_DEBUG"
2788+
2789+
/**
2790+
* A variable controlling whether to prefer a low-power GPU on multi-GPU systems.
2791+
*
2792+
* This variable can be set to the following values:
2793+
*
2794+
* - "0": Prefer high-performance GPU (default)
2795+
* - "1": Prefer low-power GPU
2796+
*
2797+
* This hint should be set before creating a renderer.
2798+
*
2799+
* \since This hint is available since SDL 3.0.0.
2800+
*/
2801+
#define SDL_HINT_RENDER_GPU_LOW_POWER "SDL_RENDER_GPU_LOW_POWER"
2802+
27752803
/**
27762804
* A variable specifying which render driver to use.
27772805
*

src/render/sdlgpu/SDL_render_gpu.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,16 @@ static int GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr
11651165
goto error;
11661166
}
11671167

1168-
SDL_SetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_DEBUGMODE_BOOL, SDL_TRUE);
1168+
SDL_bool debug = SDL_GetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_DEBUGMODE_BOOL, SDL_FALSE);
1169+
SDL_bool lowpower = SDL_GetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_PREFERLOWPOWER_BOOL, SDL_FALSE);
1170+
1171+
// Prefer environment variables/hints if they exist, otherwise defer to properties
1172+
debug = SDL_GetHintBoolean(SDL_HINT_RENDER_GPU_DEBUG, debug);
1173+
lowpower = SDL_GetHintBoolean(SDL_HINT_RENDER_GPU_LOW_POWER, lowpower);
1174+
1175+
SDL_SetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_DEBUGMODE_BOOL, debug);
1176+
SDL_SetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_PREFERLOWPOWER_BOOL, lowpower);
1177+
11691178
GPU_FillSupportedShaderFormats(create_props);
11701179
data->device = SDL_GpuCreateDeviceWithProperties(create_props);
11711180

0 commit comments

Comments
 (0)