@@ -118,14 +118,22 @@ typedef struct VulkanExtensions
118
118
119
119
/* Conversions */
120
120
121
- static const Uint8 DEVICE_PRIORITY [] = {
121
+ static const Uint8 DEVICE_PRIORITY_HIGHPERFORMANCE [] = {
122
122
0 , /* VK_PHYSICAL_DEVICE_TYPE_OTHER */
123
123
3 , /* VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU */
124
124
4 , /* VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU */
125
125
2 , /* VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU */
126
126
1 /* VK_PHYSICAL_DEVICE_TYPE_CPU */
127
127
};
128
128
129
+ static const Uint8 DEVICE_PRIORITY_LOWPOWER [] = {
130
+ 0 , /* VK_PHYSICAL_DEVICE_TYPE_OTHER */
131
+ 4 , /* VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU */
132
+ 3 , /* VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU */
133
+ 2 , /* VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU */
134
+ 1 /* VK_PHYSICAL_DEVICE_TYPE_CPU */
135
+ };
136
+
129
137
static VkPresentModeKHR SDLToVK_PresentMode [] = {
130
138
VK_PRESENT_MODE_FIFO_KHR ,
131
139
VK_PRESENT_MODE_IMMEDIATE_KHR ,
@@ -1277,6 +1285,7 @@ struct VulkanRenderer
1277
1285
Uint8 outofBARMemoryWarning ;
1278
1286
1279
1287
SDL_bool debugMode ;
1288
+ SDL_bool preferLowPower ;
1280
1289
VulkanExtensions supports ;
1281
1290
SDL_bool supportsDebugUtils ;
1282
1291
SDL_bool supportsColorspace ;
@@ -10978,21 +10987,25 @@ static Uint8 VULKAN_INTERNAL_IsDeviceSuitable(
10978
10987
VkPhysicalDeviceProperties deviceProperties ;
10979
10988
Uint32 i ;
10980
10989
10990
+ const Uint8 * devicePriority = renderer -> preferLowPower ?
10991
+ DEVICE_PRIORITY_LOWPOWER :
10992
+ DEVICE_PRIORITY_HIGHPERFORMANCE ;
10993
+
10981
10994
/* Get the device rank before doing any checks, in case one fails.
10982
10995
* Note: If no dedicated device exists, one that supports our features
10983
10996
* would be fine
10984
10997
*/
10985
10998
renderer -> vkGetPhysicalDeviceProperties (
10986
10999
physicalDevice ,
10987
11000
& deviceProperties );
10988
- if (* deviceRank < DEVICE_PRIORITY [deviceProperties .deviceType ]) {
11001
+ if (* deviceRank < devicePriority [deviceProperties .deviceType ]) {
10989
11002
/* This device outranks the best device we've found so far!
10990
11003
* This includes a dedicated GPU that has less features than an
10991
11004
* integrated GPU, because this is a freak case that is almost
10992
11005
* never intentionally desired by the end user
10993
11006
*/
10994
- * deviceRank = DEVICE_PRIORITY [deviceProperties .deviceType ];
10995
- } else if (* deviceRank > DEVICE_PRIORITY [deviceProperties .deviceType ]) {
11007
+ * deviceRank = devicePriority [deviceProperties .deviceType ];
11008
+ } else if (* deviceRank > devicePriority [deviceProperties .deviceType ]) {
10996
11009
/* Device is outranked by a previous device, don't even try to
10997
11010
* run a query and reset the rank to avoid overwrites
10998
11011
*/
@@ -11457,7 +11470,7 @@ static SDL_bool VULKAN_PrepareDriver(SDL_VideoDevice *_this)
11457
11470
return result ;
11458
11471
}
11459
11472
11460
- static SDL_GpuDevice * VULKAN_CreateDevice (SDL_bool debugMode )
11473
+ static SDL_GpuDevice * VULKAN_CreateDevice (SDL_bool debugMode , SDL_bool preferLowPower )
11461
11474
{
11462
11475
VulkanRenderer * renderer ;
11463
11476
@@ -11479,6 +11492,7 @@ static SDL_GpuDevice *VULKAN_CreateDevice(SDL_bool debugMode)
11479
11492
renderer = (VulkanRenderer * )SDL_malloc (sizeof (VulkanRenderer ));
11480
11493
SDL_memset (renderer , '\0' , sizeof (VulkanRenderer ));
11481
11494
renderer -> debugMode = debugMode ;
11495
+ renderer -> preferLowPower = preferLowPower ;
11482
11496
11483
11497
if (!VULKAN_INTERNAL_PrepareVulkan (renderer )) {
11484
11498
SDL_LogError (SDL_LOG_CATEGORY_APPLICATION , "Failed to initialize Vulkan!" );
0 commit comments