# HG changeset patch # User John Tsiombikas # Date 1459484027 -10800 # Node ID a13895a5f67316cc494fe02fa04678ebc2aec1f5 initial commit diff -r 000000000000 -r a13895a5f673 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Fri Apr 01 07:13:47 2016 +0300 @@ -0,0 +1,12 @@ +obj = main.o +bin = test + +CFLAGS = -pedantic -Wall -g +LDFLAGS = -lvulkan + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(bin) diff -r 000000000000 -r a13895a5f673 main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.c Fri Apr 01 07:13:47 2016 +0300 @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include + +const char *get_device_name(VkPhysicalDeviceType type); +const char *get_queue_flag_string(VkQueueFlagBits flags); +int ver_major(uint32_t ver); +int ver_minor(uint32_t ver); +int ver_patch(uint32_t ver); + +int main(void) +{ + int i, j; + VkInstance vk; + VkInstanceCreateInfo inst_info; + VkPhysicalDevice *devices; + VkDevice vkdev; + VkDeviceCreateInfo dev_info; + VkDeviceQueueCreateInfo queue_info; + uint32_t num_devices; + int sel_dev = -1; + int sel_qfamily = -1; + float qprio = 0.0f; + + memset(&inst_info, 0, sizeof inst_info); + inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + + if(vkCreateInstance(&inst_info, 0, &vk) != 0) { + fprintf(stderr, "failed to create vulkan instance\n"); + return 1; + } + printf("created vulkan instance\n"); + + if(vkEnumeratePhysicalDevices(vk, &num_devices, 0) != 0) { + fprintf(stderr, "failed to enumerate vulkan physical devices\n"); + return 1; + } + devices = alloca(num_devices * sizeof *devices); + if(vkEnumeratePhysicalDevices(vk, &num_devices, devices) != 0) { + fprintf(stderr, "failed to enumerate vulkan physical devices\n"); + return 1; + } + printf("found %u physical device(s)\n", (unsigned int)num_devices); + + for(i=0; i<(int)num_devices; i++) { + VkPhysicalDeviceProperties dev_prop; + VkQueueFamilyProperties *qprop; + uint32_t qprop_count; + + vkGetPhysicalDeviceProperties(devices[i], &dev_prop); + + printf("Device %d: %s\n", i, dev_prop.deviceName); + printf(" type: %s\n", get_device_name(dev_prop.deviceType)); + printf(" API version: %d.%d.%d\n", ver_major(dev_prop.apiVersion), ver_minor(dev_prop.apiVersion), + ver_patch(dev_prop.apiVersion)); + printf(" driver version: %d.%d.%d\n", ver_major(dev_prop.driverVersion), ver_minor(dev_prop.driverVersion), + ver_patch(dev_prop.driverVersion)); + printf(" vendor id: %x device id: %x\n", dev_prop.vendorID, dev_prop.deviceID); + + vkGetPhysicalDeviceQueueFamilyProperties(devices[i], &qprop_count, 0); + if(qprop_count <= 0) { + continue; + } + qprop = malloc(qprop_count * sizeof *qprop); + vkGetPhysicalDeviceQueueFamilyProperties(devices[i], &qprop_count, qprop); + + for(j=0; j> 22) & 0x3ff; +} + +int ver_minor(uint32_t ver) +{ + return (ver >> 12) & 0x3ff; +} + +int ver_patch(uint32_t ver) +{ + return ver & 0xfff; +}