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@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@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@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@0: vkGetPhysicalDeviceQueueFamilyProperties(devices[i], &qprop_count, 0); nuclear@0: if(qprop_count <= 0) { nuclear@0: continue; nuclear@0: } nuclear@0: qprop = malloc(qprop_count * sizeof *qprop); nuclear@0: vkGetPhysicalDeviceQueueFamilyProperties(devices[i], &qprop_count, qprop); nuclear@0: nuclear@0: 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: }