From a8acdc4b010bd95a1d01738b471bef66645a44fd Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 17 Jan 2025 15:12:46 +0000 Subject: [PATCH] Enumerate physical devices to check for any supporting shaderFloat64 --- main.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index 5a9dcf5..b962ce8 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,7 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define CLAMP(x, min, max) MAX((min), MIN(x, (max))) +#define PHYSICAL_DEV_BUFFER_SIZE 8 #define QUEUE_FAMILY_PROP_BUFFER_SIZE 16 #define EXT_PROP_BUFFER_SIZE 256 #define SURFACE_FMT_BUFFER_SIZE 64 @@ -96,15 +97,22 @@ int main(void) assert(result == VK_SUCCESS); // Select a physical device + VkPhysicalDevice physical_devs[PHYSICAL_DEV_BUFFER_SIZE]; + uint32_t dev_count = PHYSICAL_DEV_BUFFER_SIZE; + result = vkEnumeratePhysicalDevices(inst, &dev_count, physical_devs); + assert(result == VK_SUCCESS); + bool found_physical_dev = false; VkPhysicalDevice physical_dev; - uint32_t dev_count = 1; - result = vkEnumeratePhysicalDevices(inst, &dev_count, &physical_dev); - assert(result == VK_SUCCESS || result == VK_INCOMPLETE); - - // Check that the device supports double precision - VkPhysicalDeviceFeatures features; - vkGetPhysicalDeviceFeatures(physical_dev, &features); - assert(features.shaderFloat64); + for (unsigned i = 0; i < dev_count; ++i) { + // Check that the device supports double precision + VkPhysicalDeviceFeatures features; + vkGetPhysicalDeviceFeatures(physical_devs[i], &features); + if (features.shaderFloat64) { + physical_dev = physical_devs[i]; + found_physical_dev = true; + } + } + assert(found_physical_dev); // Select queue family uint32_t queue_family_count = QUEUE_FAMILY_PROP_BUFFER_SIZE;