some device scoring heuristics master
authorJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 23 Dec 2021 09:17:21 +0000 (11:17 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 23 Dec 2021 09:17:21 +0000 (11:17 +0200)
src/vk.c

index 917a801..2a1db64 100644 (file)
--- a/src/vk.c
+++ b/src/vk.c
@@ -446,6 +446,7 @@ static int create_swapchain(void)
 
 static int eval_pdev_score(VkPhysicalDevice dev)
 {
+       int score = 0;
        uint32_t i, num_fmt, num_qfam, num_ext;
        VkQueueFamilyProperties *qfam;
        VkExtensionProperties *ext;
@@ -486,17 +487,35 @@ static int eval_pdev_score(VkPhysicalDevice dev)
        for(i=0; i<num_qfam; i++) {
                vkGetPhysicalDeviceSurfaceSupportKHR(dev, i, vksurf, &can_pres);
                if(qfam[i].queueCount && (qfam[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) && can_pres) {
-                       free(ext);
-                       free(sfmt);
-                       free(qfam);
-                       return 1;
+                       score = 1;
+               }
+       }
+
+       switch(prop.deviceType) {
+       case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
+               score++;
+               break;
+       case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
+               score += 2;
+               break;
+       case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
+               score += 4;
+               break;
+       default:
+               break;
+       }
+
+       if(initflags & VKINIT_RAY) {
+               if(have_ext(ext, num_ext, "VK_KHR_acceleration_structure") &&
+                               have_ext(ext, num_ext, "VK_KHR_ray_tracing_pipeline")) {
+                       score += 100;
                }
        }
 
        free(ext);
        free(sfmt);
        free(qfam);
-       return 0;
+       return score;
 }
 
 static int choose_pixfmt(void)