- memset(&pdevprop2, 0, sizeof pdevprop2);
- pdevprop2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
- pdevprop2.pNext = have_raytrace ? &raypipe_prop : 0;
-
- vkGetPhysicalDeviceProperties2(pdev_list[i], &pdevprop2);
- printf(" %d: %s\n", i, pdevprop2.properties.deviceName);
- if(have_raytrace) {
- printf(" Raytracing properties:\n");
- printf(" max ray recursion: %u\n", raypipe_prop.maxRayRecursionDepth);
- printf(" max ray dispatch: %u\n", raypipe_prop.maxRayDispatchInvocationCount);
- printf(" max leaf geometry: %llu\n", (unsigned long long)rayacc_prop.maxGeometryCount);
- printf(" max leaf primitves: %llu\n", (unsigned long long)rayacc_prop.maxPrimitiveCount);
- printf(" max instances: %llu\n", (unsigned long long)rayacc_prop.maxInstanceCount);
+ vkGetPhysicalDeviceProperties(pdev[i], &pdevprop);
+ printf(" %d: %s (score: %d)\n", i, pdevprop.deviceName, score);
+ }
+ if(best_dev == -1) {
+ fprintf(stderr, "no suitable vulkan device found\n");
+ free(pdev);
+ return -1;
+ }
+
+ vkpdev = pdev[i];
+
+ free(pdev);
+ choose_pixfmt();
+ return 0;
+}
+
+static int create_device(void)
+{
+ return 0;
+}
+
+static int eval_pdev_score(VkPhysicalDevice dev)
+{
+ uint32_t i, num_fmt, num_qfam, num_ext;
+ VkQueueFamilyProperties *qfam;
+ VkExtensionProperties *ext;
+ VkPhysicalDeviceProperties prop;
+ VkPhysicalDeviceFeatures feat;
+ VkSurfaceFormatKHR *sfmt;
+ VkBool32 can_pres;
+
+ vkGetPhysicalDeviceProperties(dev, &prop);
+ vkGetPhysicalDeviceFeatures(dev, &feat);
+
+ /* check if we have the swapchain extension */
+ vkEnumerateDeviceExtensionProperties(dev, 0, &num_ext, 0);
+ ext = malloc_nf(num_ext * sizeof *ext);
+ vkEnumerateDeviceExtensionProperties(dev, 0, &num_ext, ext);
+
+ if(!have_ext(ext, num_ext, "VK_KHR_swapchain")) {
+ free(ext);
+ return 0;
+ }
+
+ /* populate format and present modes arrays, and make sure we have some of each */
+ vkGetPhysicalDeviceSurfaceFormatsKHR(dev, vksurf, &num_fmt, 0);
+ if(!num_fmt) {
+ free(ext);
+ return 0;
+ }
+ sfmt = malloc_nf(num_fmt * sizeof *sfmt);
+ vkGetPhysicalDeviceSurfaceFormatsKHR(dev, vksurf, &num_fmt, sfmt);
+
+ vkGetPhysicalDeviceSurfaceCapabilitiesKHR(dev, vksurf, &vksurf_caps);
+
+ /* find a queue family which can do graphics and can present */
+ vkGetPhysicalDeviceQueueFamilyProperties(dev, &num_qfam, 0);
+ qfam = malloc_nf(num_qfam * sizeof *qfam);
+ vkGetPhysicalDeviceQueueFamilyProperties(dev, &num_qfam, qfam);
+
+ vkqfam_idx = -1;
+ 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) {
+ vkqfam_idx = i;
+ free(ext);
+ free(sfmt);
+ free(qfam);
+ return 1;