nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: const char *get_device_name(VkPhysicalDeviceType type); nuclear@2: const char *get_mem_prop_flag_string(VkMemoryPropertyFlags flags); nuclear@0: const char *get_queue_flag_string(VkQueueFlagBits flags); nuclear@0: int ver_major(uint32_t ver); nuclear@0: int ver_minor(uint32_t ver); nuclear@0: int ver_patch(uint32_t ver); nuclear@2: const char *mem_size_str(long sz); nuclear@0: nuclear@0: int main(void) nuclear@0: { nuclear@0: int i, j; nuclear@0: VkInstance vk; nuclear@0: VkInstanceCreateInfo inst_info; nuclear@0: VkPhysicalDevice *devices; nuclear@0: VkDevice vkdev; nuclear@0: VkDeviceCreateInfo dev_info; nuclear@0: VkDeviceQueueCreateInfo queue_info; nuclear@0: uint32_t num_devices; nuclear@0: int sel_dev = -1; nuclear@0: int sel_qfamily = -1; nuclear@0: float qprio = 0.0f; nuclear@0: nuclear@0: memset(&inst_info, 0, sizeof inst_info); nuclear@0: inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; nuclear@0: nuclear@0: if(vkCreateInstance(&inst_info, 0, &vk) != 0) { nuclear@0: fprintf(stderr, "failed to create vulkan instance\n"); nuclear@0: return 1; nuclear@0: } nuclear@0: printf("created vulkan instance\n"); nuclear@0: nuclear@0: if(vkEnumeratePhysicalDevices(vk, &num_devices, 0) != 0) { nuclear@0: fprintf(stderr, "failed to enumerate vulkan physical devices\n"); nuclear@0: return 1; nuclear@0: } nuclear@0: devices = alloca(num_devices * sizeof *devices); nuclear@0: if(vkEnumeratePhysicalDevices(vk, &num_devices, devices) != 0) { nuclear@0: fprintf(stderr, "failed to enumerate vulkan physical devices\n"); nuclear@0: return 1; nuclear@0: } nuclear@0: printf("found %u physical device(s)\n", (unsigned int)num_devices); nuclear@0: nuclear@0: for(i=0; i<(int)num_devices; i++) { nuclear@0: VkPhysicalDeviceProperties dev_prop; nuclear@2: VkPhysicalDeviceMemoryProperties mem_prop; nuclear@0: VkQueueFamilyProperties *qprop; nuclear@0: uint32_t qprop_count; nuclear@0: nuclear@0: vkGetPhysicalDeviceProperties(devices[i], &dev_prop); nuclear@0: nuclear@0: printf("Device %d: %s\n", i, dev_prop.deviceName); nuclear@0: printf(" type: %s\n", get_device_name(dev_prop.deviceType)); nuclear@0: printf(" API version: %d.%d.%d\n", ver_major(dev_prop.apiVersion), ver_minor(dev_prop.apiVersion), nuclear@0: ver_patch(dev_prop.apiVersion)); nuclear@0: printf(" driver version: %d.%d.%d\n", ver_major(dev_prop.driverVersion), ver_minor(dev_prop.driverVersion), nuclear@0: ver_patch(dev_prop.driverVersion)); nuclear@0: printf(" vendor id: %x device id: %x\n", dev_prop.vendorID, dev_prop.deviceID); nuclear@0: nuclear@2: nuclear@2: vkGetPhysicalDeviceMemoryProperties(devices[i], &mem_prop); nuclear@2: printf(" %d memory heaps:\n", mem_prop.memoryHeapCount); nuclear@2: for(j=0; j> 22) & 0x3ff; nuclear@0: } nuclear@0: nuclear@0: int ver_minor(uint32_t ver) nuclear@0: { nuclear@0: return (ver >> 12) & 0x3ff; nuclear@0: } nuclear@0: nuclear@0: int ver_patch(uint32_t ver) nuclear@0: { nuclear@0: return ver & 0xfff; nuclear@0: } nuclear@2: nuclear@2: const char *mem_size_str(long sz) nuclear@2: { nuclear@2: static char str[64]; nuclear@2: static const char *unitstr[] = { "bytes", "KB", "MB", "GB", "TB", "PB", 0 }; nuclear@2: int uidx = 0; nuclear@2: sz *= 10; nuclear@2: nuclear@2: while(sz >= 10240 && unitstr[uidx + 1]) { nuclear@2: sz /= 1024; nuclear@2: ++uidx; nuclear@2: } nuclear@2: sprintf(str, "%ld.%ld %s", sz / 10, sz % 10, unitstr[uidx]); nuclear@2: return str; nuclear@2: }