vulkan_test2

changeset 3:68e1c437343f

more vulkan
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 22 Sep 2017 01:01:10 +0300
parents 5b2ae06283aa
children c31c4115d44a
files Makefile main.c src/main.c src/vku.c src/vku.h
diffstat 5 files changed, 320 insertions(+), 226 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Sun Dec 18 09:15:16 2016 +0200
     1.2 +++ b/Makefile	Fri Sep 22 01:01:10 2017 +0300
     1.3 @@ -1,4 +1,5 @@
     1.4 -obj = main.o
     1.5 +src = $(wildcard src/*.c)
     1.6 +obj = $(src:.c=.o)
     1.7  bin = test
     1.8  
     1.9  CFLAGS = -pedantic -Wall -g
     2.1 --- a/main.c	Sun Dec 18 09:15:16 2016 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,225 +0,0 @@
     2.4 -#include <stdio.h>
     2.5 -#include <stdlib.h>
     2.6 -#include <string.h>
     2.7 -#include <alloca.h>
     2.8 -#include <vulkan/vulkan.h>
     2.9 -
    2.10 -const char *get_device_name(VkPhysicalDeviceType type);
    2.11 -const char *get_mem_prop_flag_string(VkMemoryPropertyFlags flags);
    2.12 -const char *get_queue_flag_string(VkQueueFlagBits flags);
    2.13 -int ver_major(uint32_t ver);
    2.14 -int ver_minor(uint32_t ver);
    2.15 -int ver_patch(uint32_t ver);
    2.16 -const char *mem_size_str(long sz);
    2.17 -
    2.18 -int main(void)
    2.19 -{
    2.20 -	int i, j;
    2.21 -	VkInstance vk;
    2.22 -	VkInstanceCreateInfo inst_info;
    2.23 -	VkPhysicalDevice *devices;
    2.24 -	VkDevice vkdev;
    2.25 -	VkDeviceCreateInfo dev_info;
    2.26 -	VkDeviceQueueCreateInfo queue_info;
    2.27 -	uint32_t num_devices;
    2.28 -	int sel_dev = -1;
    2.29 -	int sel_qfamily = -1;
    2.30 -	float qprio = 0.0f;
    2.31 -
    2.32 -	memset(&inst_info, 0, sizeof inst_info);
    2.33 -	inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    2.34 -
    2.35 -	if(vkCreateInstance(&inst_info, 0, &vk) != 0) {
    2.36 -		fprintf(stderr, "failed to create vulkan instance\n");
    2.37 -		return 1;
    2.38 -	}
    2.39 -	printf("created vulkan instance\n");
    2.40 -
    2.41 -	if(vkEnumeratePhysicalDevices(vk, &num_devices, 0) != 0) {
    2.42 -		fprintf(stderr, "failed to enumerate vulkan physical devices\n");
    2.43 -		return 1;
    2.44 -	}
    2.45 -	devices = alloca(num_devices * sizeof *devices);
    2.46 -	if(vkEnumeratePhysicalDevices(vk, &num_devices, devices) != 0) {
    2.47 -		fprintf(stderr, "failed to enumerate vulkan physical devices\n");
    2.48 -		return 1;
    2.49 -	}
    2.50 -	printf("found %u physical device(s)\n", (unsigned int)num_devices);
    2.51 -
    2.52 -	for(i=0; i<(int)num_devices; i++) {
    2.53 -		VkPhysicalDeviceProperties dev_prop;
    2.54 -		VkPhysicalDeviceMemoryProperties mem_prop;
    2.55 -		VkQueueFamilyProperties *qprop;
    2.56 -		uint32_t qprop_count;
    2.57 -
    2.58 -		vkGetPhysicalDeviceProperties(devices[i], &dev_prop);
    2.59 -
    2.60 -		printf("Device %d: %s\n", i, dev_prop.deviceName);
    2.61 -		printf("  type: %s\n", get_device_name(dev_prop.deviceType));
    2.62 -		printf("  API version: %d.%d.%d\n", ver_major(dev_prop.apiVersion), ver_minor(dev_prop.apiVersion),
    2.63 -				ver_patch(dev_prop.apiVersion));
    2.64 -		printf("  driver version: %d.%d.%d\n", ver_major(dev_prop.driverVersion), ver_minor(dev_prop.driverVersion),
    2.65 -				ver_patch(dev_prop.driverVersion));
    2.66 -		printf("  vendor id: %x  device id: %x\n", dev_prop.vendorID, dev_prop.deviceID);
    2.67 -
    2.68 -
    2.69 -		vkGetPhysicalDeviceMemoryProperties(devices[i], &mem_prop);
    2.70 -		printf("  %d memory heaps:\n", mem_prop.memoryHeapCount);
    2.71 -		for(j=0; j<mem_prop.memoryHeapCount; j++) {
    2.72 -			VkMemoryHeap heap = mem_prop.memoryHeaps[j];
    2.73 -			printf("    Heap %d - size: %s, flags: %s\n", j, mem_size_str(heap.size),
    2.74 -					heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT ? "device-local" : "-");
    2.75 -		}
    2.76 -		printf("  %d memory types:\n", mem_prop.memoryTypeCount);
    2.77 -		for(j=0; j<mem_prop.memoryTypeCount; j++) {
    2.78 -			VkMemoryType type = mem_prop.memoryTypes[j];
    2.79 -			printf("    Type %d - heap: %d, flags: %s\n", j, type.heapIndex,
    2.80 -					get_mem_prop_flag_string(type.propertyFlags));
    2.81 -		}
    2.82 -
    2.83 -		vkGetPhysicalDeviceQueueFamilyProperties(devices[i], &qprop_count, 0);
    2.84 -		if(qprop_count <= 0) {
    2.85 -			continue;
    2.86 -		}
    2.87 -		qprop = malloc(qprop_count * sizeof *qprop);
    2.88 -		vkGetPhysicalDeviceQueueFamilyProperties(devices[i], &qprop_count, qprop);
    2.89 -
    2.90 -		for(j=0; j<qprop_count; j++) {
    2.91 -			printf("  Queue family %d:\n", j);
    2.92 -			printf("    flags: %s\n", get_queue_flag_string(qprop[j].queueFlags));
    2.93 -			printf("    num queues: %u\n", qprop[j].queueCount);
    2.94 -
    2.95 -			if(qprop[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
    2.96 -				sel_dev = i;
    2.97 -				sel_qfamily = j;
    2.98 -			}
    2.99 -		}
   2.100 -		free(qprop);
   2.101 -	}
   2.102 -
   2.103 -	if(sel_dev < 0 || sel_qfamily < 0) {
   2.104 -		fprintf(stderr, "failed to find any device with a graphics-capable command queue\n");
   2.105 -		vkDestroyDevice(vkdev, 0);
   2.106 -		return 1;
   2.107 -	}
   2.108 -
   2.109 -	// create device & command queue
   2.110 -	memset(&queue_info, 0, sizeof queue_info);
   2.111 -	queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
   2.112 -	queue_info.queueFamilyIndex = sel_qfamily;
   2.113 -	queue_info.queueCount = 1;
   2.114 -	queue_info.pQueuePriorities = &qprio;
   2.115 -
   2.116 -	memset(&dev_info, 0, sizeof dev_info);
   2.117 -	dev_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
   2.118 -	dev_info.queueCreateInfoCount = 1;
   2.119 -	dev_info.pQueueCreateInfos = &queue_info;
   2.120 -
   2.121 -	if(vkCreateDevice(devices[sel_dev], &dev_info, 0, &vkdev) != 0) {
   2.122 -		fprintf(stderr, "failed to create device %d\n", sel_dev);
   2.123 -		return 1;
   2.124 -	}
   2.125 -	printf("created device %d\n", sel_dev);
   2.126 -
   2.127 -	vkDestroyDevice(vkdev, 0);
   2.128 -	vkDestroyInstance(vk, 0);
   2.129 -	return 0;
   2.130 -}
   2.131 -
   2.132 -
   2.133 -const char *get_device_name(VkPhysicalDeviceType type)
   2.134 -{
   2.135 -	switch(type) {
   2.136 -	case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
   2.137 -		return "integrated GPU";
   2.138 -	case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
   2.139 -		return "discrete GPU";
   2.140 -	case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
   2.141 -		return "virtual GPU";
   2.142 -	case VK_PHYSICAL_DEVICE_TYPE_CPU:
   2.143 -		return "CPU";
   2.144 -	default:
   2.145 -		break;
   2.146 -	}
   2.147 -	return "unknown";
   2.148 -}
   2.149 -
   2.150 -const char *get_mem_prop_flag_string(VkMemoryPropertyFlags flags)
   2.151 -{
   2.152 -	static char str[128];
   2.153 -
   2.154 -	str[0] = 0;
   2.155 -	if(flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
   2.156 -		strcat(str, "device-local ");
   2.157 -	}
   2.158 -	if(flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
   2.159 -		strcat(str, "host-visible ");
   2.160 -	}
   2.161 -	if(flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {
   2.162 -		strcat(str, "host-coherent ");
   2.163 -	}
   2.164 -	if(flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) {
   2.165 -		strcat(str, "host-cached ");
   2.166 -	}
   2.167 -	if(flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) {
   2.168 -		strcat(str, "lazily-allocated ");
   2.169 -	}
   2.170 -
   2.171 -	if(!*str) {
   2.172 -		strcat(str, "-");
   2.173 -	}
   2.174 -	return str;
   2.175 -}
   2.176 -
   2.177 -const char *get_queue_flag_string(VkQueueFlagBits flags)
   2.178 -{
   2.179 -	static char str[128];
   2.180 -
   2.181 -	str[0] = 0;
   2.182 -	if(flags & VK_QUEUE_GRAPHICS_BIT) {
   2.183 -		strcat(str, "graphics ");
   2.184 -	}
   2.185 -	if(flags & VK_QUEUE_COMPUTE_BIT) {
   2.186 -		strcat(str, "compute ");
   2.187 -	}
   2.188 -	if(flags & VK_QUEUE_TRANSFER_BIT) {
   2.189 -		strcat(str, "transfer ");
   2.190 -	}
   2.191 -	if(flags & VK_QUEUE_SPARSE_BINDING_BIT) {
   2.192 -		strcat(str, "sparse-binding ");
   2.193 -	}
   2.194 -	if(!*str) {
   2.195 -		strcat(str, "-");
   2.196 -	}
   2.197 -	return str;
   2.198 -}
   2.199 -
   2.200 -int ver_major(uint32_t ver)
   2.201 -{
   2.202 -	return (ver >> 22) & 0x3ff;
   2.203 -}
   2.204 -
   2.205 -int ver_minor(uint32_t ver)
   2.206 -{
   2.207 -	return (ver >> 12) & 0x3ff;
   2.208 -}
   2.209 -
   2.210 -int ver_patch(uint32_t ver)
   2.211 -{
   2.212 -	return ver & 0xfff;
   2.213 -}
   2.214 -
   2.215 -const char *mem_size_str(long sz)
   2.216 -{
   2.217 -	static char str[64];
   2.218 -	static const char *unitstr[] = { "bytes", "KB", "MB", "GB", "TB", "PB", 0 };
   2.219 -	int uidx = 0;
   2.220 -	sz *= 10;
   2.221 -
   2.222 -	while(sz >= 10240 && unitstr[uidx + 1]) {
   2.223 -		sz /= 1024;
   2.224 -		++uidx;
   2.225 -	}
   2.226 -	sprintf(str, "%ld.%ld %s", sz / 10, sz % 10, unitstr[uidx]);
   2.227 -	return str;
   2.228 -}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/main.c	Fri Sep 22 01:01:10 2017 +0300
     3.3 @@ -0,0 +1,13 @@
     3.4 +#include <stdio.h>
     3.5 +#include <vulkan/vulkan.h>
     3.6 +#include "vku.h"
     3.7 +
     3.8 +int main(void)
     3.9 +{
    3.10 +	if(vku_create_dev() == -1) {
    3.11 +		return -1;
    3.12 +	}
    3.13 +
    3.14 +	vku_cleanup();
    3.15 +	return 0;
    3.16 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/vku.c	Fri Sep 22 01:01:10 2017 +0300
     4.3 @@ -0,0 +1,281 @@
     4.4 +#include <stdio.h>
     4.5 +#include <stdlib.h>
     4.6 +#include <string.h>
     4.7 +#include <alloca.h>
     4.8 +#include "vku.h"
     4.9 +
    4.10 +static const char *get_device_name(VkPhysicalDeviceType type);
    4.11 +static const char *get_mem_prop_flag_string(VkMemoryPropertyFlags flags);
    4.12 +static const char *get_queue_flag_string(VkQueueFlagBits flags);
    4.13 +static int ver_major(uint32_t ver);
    4.14 +static int ver_minor(uint32_t ver);
    4.15 +static int ver_patch(uint32_t ver);
    4.16 +static const char *mem_size_str(long sz);
    4.17 +
    4.18 +
    4.19 +VkInstance vk;
    4.20 +VkDevice vkdev;
    4.21 +VkQueue vkq;
    4.22 +
    4.23 +int vku_create_dev(void)
    4.24 +{
    4.25 +	int i, j;
    4.26 +	VkInstanceCreateInfo inst_info;
    4.27 +	VkPhysicalDevice *devices;
    4.28 +	VkDeviceCreateInfo dev_info;
    4.29 +	VkDeviceQueueCreateInfo queue_info;
    4.30 +	VkCommandPoolCreateInfo cmdpool_info;
    4.31 +	uint32_t num_devices;
    4.32 +	int sel_dev = -1;
    4.33 +	int sel_qfamily = -1;
    4.34 +	float qprio = 0.0f;
    4.35 +
    4.36 +	memset(&inst_info, 0, sizeof inst_info);
    4.37 +	inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    4.38 +
    4.39 +	if(vkCreateInstance(&inst_info, 0, &vk) != 0) {
    4.40 +		fprintf(stderr, "failed to create vulkan instance\n");
    4.41 +		return -1;
    4.42 +	}
    4.43 +	printf("created vulkan instance\n");
    4.44 +
    4.45 +	if(vkEnumeratePhysicalDevices(vk, &num_devices, 0) != 0) {
    4.46 +		fprintf(stderr, "failed to enumerate vulkan physical devices\n");
    4.47 +		return -1;
    4.48 +	}
    4.49 +	devices = alloca(num_devices * sizeof *devices);
    4.50 +	if(vkEnumeratePhysicalDevices(vk, &num_devices, devices) != 0) {
    4.51 +		fprintf(stderr, "failed to enumerate vulkan physical devices\n");
    4.52 +		return -1;
    4.53 +	}
    4.54 +	printf("found %u physical device(s)\n", (unsigned int)num_devices);
    4.55 +
    4.56 +	for(i=0; i<(int)num_devices; i++) {
    4.57 +		VkPhysicalDeviceProperties dev_prop;
    4.58 +		VkPhysicalDeviceMemoryProperties mem_prop;
    4.59 +		VkQueueFamilyProperties *qprop;
    4.60 +		uint32_t qprop_count;
    4.61 +
    4.62 +		vkGetPhysicalDeviceProperties(devices[i], &dev_prop);
    4.63 +
    4.64 +		printf("Device %d: %s\n", i, dev_prop.deviceName);
    4.65 +		printf("  type: %s\n", get_device_name(dev_prop.deviceType));
    4.66 +		printf("  API version: %d.%d.%d\n", ver_major(dev_prop.apiVersion), ver_minor(dev_prop.apiVersion),
    4.67 +				ver_patch(dev_prop.apiVersion));
    4.68 +		printf("  driver version: %d.%d.%d\n", ver_major(dev_prop.driverVersion), ver_minor(dev_prop.driverVersion),
    4.69 +				ver_patch(dev_prop.driverVersion));
    4.70 +		printf("  vendor id: %x  device id: %x\n", dev_prop.vendorID, dev_prop.deviceID);
    4.71 +
    4.72 +
    4.73 +		vkGetPhysicalDeviceMemoryProperties(devices[i], &mem_prop);
    4.74 +		printf("  %d memory heaps:\n", mem_prop.memoryHeapCount);
    4.75 +		for(j=0; j<mem_prop.memoryHeapCount; j++) {
    4.76 +			VkMemoryHeap heap = mem_prop.memoryHeaps[j];
    4.77 +			printf("    Heap %d - size: %s, flags: %s\n", j, mem_size_str(heap.size),
    4.78 +					heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT ? "device-local" : "-");
    4.79 +		}
    4.80 +		printf("  %d memory types:\n", mem_prop.memoryTypeCount);
    4.81 +		for(j=0; j<mem_prop.memoryTypeCount; j++) {
    4.82 +			VkMemoryType type = mem_prop.memoryTypes[j];
    4.83 +			printf("    Type %d - heap: %d, flags: %s\n", j, type.heapIndex,
    4.84 +					get_mem_prop_flag_string(type.propertyFlags));
    4.85 +		}
    4.86 +
    4.87 +		vkGetPhysicalDeviceQueueFamilyProperties(devices[i], &qprop_count, 0);
    4.88 +		if(qprop_count <= 0) {
    4.89 +			continue;
    4.90 +		}
    4.91 +		qprop = malloc(qprop_count * sizeof *qprop);
    4.92 +		vkGetPhysicalDeviceQueueFamilyProperties(devices[i], &qprop_count, qprop);
    4.93 +
    4.94 +		for(j=0; j<qprop_count; j++) {
    4.95 +			printf("  Queue family %d:\n", j);
    4.96 +			printf("    flags: %s\n", get_queue_flag_string(qprop[j].queueFlags));
    4.97 +			printf("    num queues: %u\n", qprop[j].queueCount);
    4.98 +
    4.99 +			if(qprop[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
   4.100 +				sel_dev = i;
   4.101 +				sel_qfamily = j;
   4.102 +			}
   4.103 +		}
   4.104 +		free(qprop);
   4.105 +	}
   4.106 +
   4.107 +	if(sel_dev < 0 || sel_qfamily < 0) {
   4.108 +		fprintf(stderr, "failed to find any device with a graphics-capable command queue\n");
   4.109 +		vkDestroyDevice(vkdev, 0);
   4.110 +		return -1;
   4.111 +	}
   4.112 +
   4.113 +	/* create device & command queue */
   4.114 +	memset(&queue_info, 0, sizeof queue_info);
   4.115 +	queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
   4.116 +	queue_info.queueFamilyIndex = sel_qfamily;
   4.117 +	queue_info.queueCount = 1;
   4.118 +	queue_info.pQueuePriorities = &qprio;
   4.119 +
   4.120 +	memset(&dev_info, 0, sizeof dev_info);
   4.121 +	dev_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
   4.122 +	dev_info.queueCreateInfoCount = 1;
   4.123 +	dev_info.pQueueCreateInfos = &queue_info;
   4.124 +
   4.125 +	if(vkCreateDevice(devices[sel_dev], &dev_info, 0, &vkdev) != 0) {
   4.126 +		fprintf(stderr, "failed to create device %d\n", sel_dev);
   4.127 +		return -1;
   4.128 +	}
   4.129 +	printf("created device %d\n", sel_dev);
   4.130 +
   4.131 +	vkGetDeviceQueue(vkdev, sel_qfamily, 0, &vkq);
   4.132 +
   4.133 +	/* create command buffer pool */
   4.134 +	memset(&cmdpool_info, 0, sizeof cmdpool_info);
   4.135 +	cmdpool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
   4.136 +	cmdpool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
   4.137 +	cmdpool_info.queueFamilyIndex = sel_qfamily;
   4.138 +
   4.139 +	if(vkCreateCommandPool(vkdev, &cmdpool_info, 0, &vkcmdpool) != 0) {
   4.140 +		fprintf(stderr, "failed to get command quque!\n");
   4.141 +		return -1;
   4.142 +	}
   4.143 +
   4.144 +	return 0;
   4.145 +}
   4.146 +
   4.147 +void vku_cleanup(void)
   4.148 +{
   4.149 +	if(vk) {
   4.150 +		vkDeviceWaitIdle(vkdev);
   4.151 +		vkDestroyDevice(vkdev, 0);
   4.152 +		vkDestroyInstance(vk, 0);
   4.153 +		vk = 0;
   4.154 +	}
   4.155 +}
   4.156 +
   4.157 +struct vk_buffer *vku_create_buffer(int sz, unsigned int usage)
   4.158 +{
   4.159 +	struct vk_buffer *buf;
   4.160 +	VkBufferCreateInfo binfo;
   4.161 +
   4.162 +	if(!(buf = malloc(sizeof *buf))) {
   4.163 +		perror("failed to allocate vk_buffer structure");
   4.164 +		return 0;
   4.165 +	}
   4.166 +
   4.167 +	memset(&binfo, 0, sizeof binfo);
   4.168 +	binfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
   4.169 +	binfo.size = sz;
   4.170 +	binfo.usage = usage;
   4.171 +	binfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
   4.172 +
   4.173 +	if(vkCreateBuffer(vkdev, &binfo, 0, &buf->buf) != 0) {
   4.174 +		fprintf(stderr, "failed to create %d byte buffer (usage: %x)\n", sz, usage);
   4.175 +		return 0;
   4.176 +	}
   4.177 +	// TODO back with memory
   4.178 +	return buf;
   4.179 +}
   4.180 +
   4.181 +void vku_destroy_buffer(struct vk_buffer *buf)
   4.182 +{
   4.183 +	if(buf) {
   4.184 +		vkDestroyBuffer(vkdev, buf->buf, 0);
   4.185 +		free(buf);
   4.186 +	}
   4.187 +}
   4.188 +
   4.189 +static const char *get_device_name(VkPhysicalDeviceType type)
   4.190 +{
   4.191 +	switch(type) {
   4.192 +	case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
   4.193 +		return "integrated GPU";
   4.194 +	case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
   4.195 +		return "discrete GPU";
   4.196 +	case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
   4.197 +		return "virtual GPU";
   4.198 +	case VK_PHYSICAL_DEVICE_TYPE_CPU:
   4.199 +		return "CPU";
   4.200 +	default:
   4.201 +		break;
   4.202 +	}
   4.203 +	return "unknown";
   4.204 +}
   4.205 +
   4.206 +static const char *get_mem_prop_flag_string(VkMemoryPropertyFlags flags)
   4.207 +{
   4.208 +	static char str[128];
   4.209 +
   4.210 +	str[0] = 0;
   4.211 +	if(flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
   4.212 +		strcat(str, "device-local ");
   4.213 +	}
   4.214 +	if(flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
   4.215 +		strcat(str, "host-visible ");
   4.216 +	}
   4.217 +	if(flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {
   4.218 +		strcat(str, "host-coherent ");
   4.219 +	}
   4.220 +	if(flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) {
   4.221 +		strcat(str, "host-cached ");
   4.222 +	}
   4.223 +	if(flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) {
   4.224 +		strcat(str, "lazily-allocated ");
   4.225 +	}
   4.226 +
   4.227 +	if(!*str) {
   4.228 +		strcat(str, "-");
   4.229 +	}
   4.230 +	return str;
   4.231 +}
   4.232 +
   4.233 +static const char *get_queue_flag_string(VkQueueFlagBits flags)
   4.234 +{
   4.235 +	static char str[128];
   4.236 +
   4.237 +	str[0] = 0;
   4.238 +	if(flags & VK_QUEUE_GRAPHICS_BIT) {
   4.239 +		strcat(str, "graphics ");
   4.240 +	}
   4.241 +	if(flags & VK_QUEUE_COMPUTE_BIT) {
   4.242 +		strcat(str, "compute ");
   4.243 +	}
   4.244 +	if(flags & VK_QUEUE_TRANSFER_BIT) {
   4.245 +		strcat(str, "transfer ");
   4.246 +	}
   4.247 +	if(flags & VK_QUEUE_SPARSE_BINDING_BIT) {
   4.248 +		strcat(str, "sparse-binding ");
   4.249 +	}
   4.250 +	if(!*str) {
   4.251 +		strcat(str, "-");
   4.252 +	}
   4.253 +	return str;
   4.254 +}
   4.255 +
   4.256 +static int ver_major(uint32_t ver)
   4.257 +{
   4.258 +	return (ver >> 22) & 0x3ff;
   4.259 +}
   4.260 +
   4.261 +static int ver_minor(uint32_t ver)
   4.262 +{
   4.263 +	return (ver >> 12) & 0x3ff;
   4.264 +}
   4.265 +
   4.266 +static int ver_patch(uint32_t ver)
   4.267 +{
   4.268 +	return ver & 0xfff;
   4.269 +}
   4.270 +
   4.271 +static const char *mem_size_str(long sz)
   4.272 +{
   4.273 +	static char str[64];
   4.274 +	static const char *unitstr[] = { "bytes", "KB", "MB", "GB", "TB", "PB", 0 };
   4.275 +	int uidx = 0;
   4.276 +	sz *= 10;
   4.277 +
   4.278 +	while(sz >= 10240 && unitstr[uidx + 1]) {
   4.279 +		sz /= 1024;
   4.280 +		++uidx;
   4.281 +	}
   4.282 +	sprintf(str, "%ld.%ld %s", sz / 10, sz % 10, unitstr[uidx]);
   4.283 +	return str;
   4.284 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/vku.h	Fri Sep 22 01:01:10 2017 +0300
     5.3 @@ -0,0 +1,24 @@
     5.4 +#ifndef VKU_H_
     5.5 +#define VKU_H_
     5.6 +
     5.7 +#include <vulkan/vulkan.h>
     5.8 +
     5.9 +VkInstance vk;
    5.10 +VkDevice vkdev;
    5.11 +VkQueue vkq;
    5.12 +VkCommandPool vkcmdpool;
    5.13 +
    5.14 +struct vk_buffer {
    5.15 +	VkBuffer buf;
    5.16 +	VkDeviceMemory mem_pool;
    5.17 +	int mem_start, mem_size;
    5.18 +};
    5.19 +
    5.20 +int vku_create_dev(void);
    5.21 +void vku_cleanup(void);
    5.22 +
    5.23 +
    5.24 +struct vk_buffer *vku_create_buffer(int sz, unsigned int usage);
    5.25 +void vku_destroy_buffer(struct vk_buffer *buf);
    5.26 +
    5.27 +#endif	/* VKU_H_ */