vulkan_test2

changeset 2:5b2ae06283aa

more queries
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 18 Dec 2016 09:15:16 +0200
parents 8cb584143df3
children 68e1c437343f
files main.c
diffstat 1 files changed, 63 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/main.c	Fri Apr 01 07:14:47 2016 +0300
     1.2 +++ b/main.c	Sun Dec 18 09:15:16 2016 +0200
     1.3 @@ -5,10 +5,12 @@
     1.4  #include <vulkan/vulkan.h>
     1.5  
     1.6  const char *get_device_name(VkPhysicalDeviceType type);
     1.7 +const char *get_mem_prop_flag_string(VkMemoryPropertyFlags flags);
     1.8  const char *get_queue_flag_string(VkQueueFlagBits flags);
     1.9  int ver_major(uint32_t ver);
    1.10  int ver_minor(uint32_t ver);
    1.11  int ver_patch(uint32_t ver);
    1.12 +const char *mem_size_str(long sz);
    1.13  
    1.14  int main(void)
    1.15  {
    1.16 @@ -46,6 +48,7 @@
    1.17  
    1.18  	for(i=0; i<(int)num_devices; i++) {
    1.19  		VkPhysicalDeviceProperties dev_prop;
    1.20 +		VkPhysicalDeviceMemoryProperties mem_prop;
    1.21  		VkQueueFamilyProperties *qprop;
    1.22  		uint32_t qprop_count;
    1.23  
    1.24 @@ -59,6 +62,21 @@
    1.25  				ver_patch(dev_prop.driverVersion));
    1.26  		printf("  vendor id: %x  device id: %x\n", dev_prop.vendorID, dev_prop.deviceID);
    1.27  
    1.28 +
    1.29 +		vkGetPhysicalDeviceMemoryProperties(devices[i], &mem_prop);
    1.30 +		printf("  %d memory heaps:\n", mem_prop.memoryHeapCount);
    1.31 +		for(j=0; j<mem_prop.memoryHeapCount; j++) {
    1.32 +			VkMemoryHeap heap = mem_prop.memoryHeaps[j];
    1.33 +			printf("    Heap %d - size: %s, flags: %s\n", j, mem_size_str(heap.size),
    1.34 +					heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT ? "device-local" : "-");
    1.35 +		}
    1.36 +		printf("  %d memory types:\n", mem_prop.memoryTypeCount);
    1.37 +		for(j=0; j<mem_prop.memoryTypeCount; j++) {
    1.38 +			VkMemoryType type = mem_prop.memoryTypes[j];
    1.39 +			printf("    Type %d - heap: %d, flags: %s\n", j, type.heapIndex,
    1.40 +					get_mem_prop_flag_string(type.propertyFlags));
    1.41 +		}
    1.42 +
    1.43  		vkGetPhysicalDeviceQueueFamilyProperties(devices[i], &qprop_count, 0);
    1.44  		if(qprop_count <= 0) {
    1.45  			continue;
    1.46 @@ -126,6 +144,33 @@
    1.47  	return "unknown";
    1.48  }
    1.49  
    1.50 +const char *get_mem_prop_flag_string(VkMemoryPropertyFlags flags)
    1.51 +{
    1.52 +	static char str[128];
    1.53 +
    1.54 +	str[0] = 0;
    1.55 +	if(flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
    1.56 +		strcat(str, "device-local ");
    1.57 +	}
    1.58 +	if(flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
    1.59 +		strcat(str, "host-visible ");
    1.60 +	}
    1.61 +	if(flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {
    1.62 +		strcat(str, "host-coherent ");
    1.63 +	}
    1.64 +	if(flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) {
    1.65 +		strcat(str, "host-cached ");
    1.66 +	}
    1.67 +	if(flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) {
    1.68 +		strcat(str, "lazily-allocated ");
    1.69 +	}
    1.70 +
    1.71 +	if(!*str) {
    1.72 +		strcat(str, "-");
    1.73 +	}
    1.74 +	return str;
    1.75 +}
    1.76 +
    1.77  const char *get_queue_flag_string(VkQueueFlagBits flags)
    1.78  {
    1.79  	static char str[128];
    1.80 @@ -143,6 +188,9 @@
    1.81  	if(flags & VK_QUEUE_SPARSE_BINDING_BIT) {
    1.82  		strcat(str, "sparse-binding ");
    1.83  	}
    1.84 +	if(!*str) {
    1.85 +		strcat(str, "-");
    1.86 +	}
    1.87  	return str;
    1.88  }
    1.89  
    1.90 @@ -160,3 +208,18 @@
    1.91  {
    1.92  	return ver & 0xfff;
    1.93  }
    1.94 +
    1.95 +const char *mem_size_str(long sz)
    1.96 +{
    1.97 +	static char str[64];
    1.98 +	static const char *unitstr[] = { "bytes", "KB", "MB", "GB", "TB", "PB", 0 };
    1.99 +	int uidx = 0;
   1.100 +	sz *= 10;
   1.101 +
   1.102 +	while(sz >= 10240 && unitstr[uidx + 1]) {
   1.103 +		sz /= 1024;
   1.104 +		++uidx;
   1.105 +	}
   1.106 +	sprintf(str, "%ld.%ld %s", sz / 10, sz % 10, unitstr[uidx]);
   1.107 +	return str;
   1.108 +}