Skip to content

Commit c5fafed

Browse files
committed
render_gpu: Add hints for debug and low-power preference
1 parent 8c03741 commit c5fafed

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

include/SDL3/SDL_hints.h

+28
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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,16 @@ static int GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr
11631163
goto error;
11641164
}
11651165

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

0 commit comments

Comments
 (0)