Skip to content

Commit

Permalink
render_gpu: Add hints for debug and low-power preference
Browse files Browse the repository at this point in the history
  • Loading branch information
Akaricchi committed Aug 19, 2024
1 parent 8c03741 commit c5fafed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
28 changes: 28 additions & 0 deletions include/SDL3/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,34 @@ extern "C" {
*/
#define SDL_HINT_RENDER_VULKAN_DEBUG "SDL_RENDER_VULKAN_DEBUG"

/**
* A variable controlling whether to create the GPU device in debug mode.
*
* This variable can be set to the following values:
*
* - "0": Disable debug mode use (default)
* - "1": Enable debug mode use
*
* This hint should be set before creating a renderer.
*
* \since This hint is available since SDL 3.0.0.
*/
#define SDL_HINT_RENDER_GPU_DEBUG "SDL_RENDER_GPU_DEBUG"

/**
* A variable controlling whether to prefer a low-power GPU on multi-GPU systems.
*
* This variable can be set to the following values:
*
* - "0": Prefer high-performance GPU (default)
* - "1": Prefer low-power GPU
*
* This hint should be set before creating a renderer.
*
* \since This hint is available since SDL 3.0.0.
*/
#define SDL_HINT_RENDER_GPU_LOW_POWER "SDL_RENDER_GPU_LOW_POWER"

/**
* A variable specifying which render driver to use.
*
Expand Down
11 changes: 10 additions & 1 deletion src/render/sdlgpu/SDL_render_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,16 @@ static int GPU_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr
goto error;
}

SDL_SetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_DEBUGMODE_BOOL, SDL_TRUE);
SDL_bool debug = SDL_GetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_DEBUGMODE_BOOL, SDL_FALSE);
SDL_bool lowpower = SDL_GetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_PREFERLOWPOWER_BOOL, SDL_FALSE);

// Prefer environment variables/hints if they exist, otherwise defer to properties
debug = SDL_GetHintBoolean(SDL_HINT_RENDER_GPU_DEBUG, debug);
lowpower = SDL_GetHintBoolean(SDL_HINT_RENDER_GPU_LOW_POWER, lowpower);

SDL_SetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_DEBUGMODE_BOOL, debug);
SDL_SetBooleanProperty(create_props, SDL_PROP_GPU_CREATEDEVICE_PREFERLOWPOWER_BOOL, lowpower);

GPU_FillSupportedShaderFormats(create_props);
data->device = SDL_GpuCreateDeviceWithProperties(create_props);

Expand Down

0 comments on commit c5fafed

Please sign in to comment.