@@ -4184,37 +4184,42 @@ static void demo_select_physical_device(struct demo* demo) {
4184
4184
} else {
4185
4185
/* Try to auto select most suitable device */
4186
4186
if (demo -> gpu_number == -1 ) {
4187
- uint32_t count_device_type [VK_PHYSICAL_DEVICE_TYPE_CPU + 1 ];
4188
- memset (count_device_type , 0 , sizeof (count_device_type ));
4189
-
4190
4187
VkPhysicalDeviceProperties physicalDeviceProperties ;
4188
+ int prev_priority = 0 ;
4191
4189
for (uint32_t i = 0 ; i < gpu_count ; i ++ ) {
4192
4190
vkGetPhysicalDeviceProperties (physical_devices [i ], & physicalDeviceProperties );
4193
4191
assert (physicalDeviceProperties .deviceType <= VK_PHYSICAL_DEVICE_TYPE_CPU );
4192
+
4193
+ // Continue next gpu if this gpu does not support the surface.
4194
4194
VkBool32 supported = 0 ;
4195
4195
vkGetPhysicalDeviceSurfaceSupportKHR (physical_devices [i ], 0 , demo -> surface , & supported );
4196
- if (supported )
4197
- count_device_type [physicalDeviceProperties .deviceType ]++ ;
4198
- }
4196
+ if (!supported ) continue ;
4199
4197
4200
- VkPhysicalDeviceType search_for_device_type = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU ;
4201
- if (count_device_type [VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU ]) {
4202
- search_for_device_type = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU ;
4203
- } else if (count_device_type [VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU ]) {
4204
- search_for_device_type = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU ;
4205
- } else if (count_device_type [VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU ]) {
4206
- search_for_device_type = VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU ;
4207
- } else if (count_device_type [VK_PHYSICAL_DEVICE_TYPE_CPU ]) {
4208
- search_for_device_type = VK_PHYSICAL_DEVICE_TYPE_CPU ;
4209
- } else if (count_device_type [VK_PHYSICAL_DEVICE_TYPE_OTHER ]) {
4210
- search_for_device_type = VK_PHYSICAL_DEVICE_TYPE_OTHER ;
4211
- }
4198
+ int priority = 0 ;
4199
+ switch (physicalDeviceProperties .deviceType ) {
4200
+ case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU :
4201
+ priority = 5 ;
4202
+ break ;
4203
+ case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU :
4204
+ priority = 4 ;
4205
+ break ;
4206
+ case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU :
4207
+ priority = 3 ;
4208
+ break ;
4209
+ case VK_PHYSICAL_DEVICE_TYPE_CPU :
4210
+ priority = 2 ;
4211
+ break ;
4212
+ case VK_PHYSICAL_DEVICE_TYPE_OTHER :
4213
+ priority = 1 ;
4214
+ break ;
4215
+ default :
4216
+ priority = -1 ;
4217
+ break ;
4218
+ }
4212
4219
4213
- for (uint32_t i = 0 ; i < gpu_count ; i ++ ) {
4214
- vkGetPhysicalDeviceProperties (physical_devices [i ], & physicalDeviceProperties );
4215
- if (physicalDeviceProperties .deviceType == search_for_device_type ) {
4220
+ if (priority > prev_priority ) {
4216
4221
demo -> gpu_number = i ;
4217
- break ;
4222
+ prev_priority = priority ;
4218
4223
}
4219
4224
}
4220
4225
}
0 commit comments