Advertisement
GreatyBat

Untitled

Aug 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.98 KB | None | 0 0
  1.  
  2.  
  3. #include "stdafx.h"
  4. #include"vulkan\vulkan.h"
  5. #include<iostream>
  6. #include<vector>
  7. #include <chrono>
  8. #include <thread>
  9.  
  10. #define ASSERT_VUKLAN(val) if(val != VK_SUCCESS){ __debugbreak();}
  11.  
  12. VkInstance instance;
  13. VkDevice device;
  14.  
  15. void printStats(VkPhysicalDevice &device) {
  16.     VkPhysicalDeviceProperties properties;
  17.     vkGetPhysicalDeviceProperties(device, &properties);
  18.     std::cout << "Name: " << properties.deviceName << std::endl;
  19.     uint32_t apiVer = properties.apiVersion;
  20.     std::cout << "API Version: " << VK_VERSION_MAJOR(apiVer) << "." << VK_VERSION_MINOR(apiVer) << "." << VK_VERSION_PATCH(apiVer) << std::endl;
  21.     std::cout << "Driver Version: " << properties.driverVersion << std::endl;
  22.     std::cout << "Vendor ID:   " << properties.vendorID << std::endl;
  23.     std::cout << "Device ID:   " << properties.deviceID << std::endl;
  24.     std::cout << "Device Type: " << properties.deviceType << std::endl;
  25.     std::cout << "Discrete Queue Priorities: " << properties.limits.discreteQueuePriorities << std::endl;
  26.     VkPhysicalDeviceFeatures features;
  27.     vkGetPhysicalDeviceFeatures(device, &features);
  28.     std::cout << "Geometry Shader: " << features.geometryShader << std::endl;
  29.  
  30.     VkPhysicalDeviceMemoryProperties memProp;
  31.     vkGetPhysicalDeviceMemoryProperties(device, &memProp);
  32.  
  33.     uint32_t amountOfQueueFamilies = 0;
  34.     vkGetPhysicalDeviceQueueFamilyProperties(device, &amountOfQueueFamilies, NULL);
  35.     VkQueueFamilyProperties *familyProperties = new VkQueueFamilyProperties[amountOfQueueFamilies];
  36.     vkGetPhysicalDeviceQueueFamilyProperties(device, &amountOfQueueFamilies, familyProperties);
  37.     std::cout << std::endl;
  38.     std::cout << "Amount of Queue Families: " << amountOfQueueFamilies;
  39.  
  40.     for (int i = 0; i < amountOfQueueFamilies; i++) {
  41.         std::cout << std::endl;
  42.         std::cout << "Queue Family #" << i << std::endl;
  43.         std::cout << "VK_QUEUE_GRAPHICS_BIT       " << ((familyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) << std::endl;
  44.         std::cout << "VK_QUEUE_COMPUTE_BIT        " << ((familyProperties[i].queueFlags & VK_QUEUE_COMPUTE_BIT) != 0) << std::endl;
  45.         std::cout << "VK_QUEUE_TRANSFER_BIT       " << ((familyProperties[i].queueFlags & VK_QUEUE_TRANSFER_BIT) != 0) << std::endl;
  46.         std::cout << "VK_QUEUE_SPARSE_BINDING_BIT " << ((familyProperties[i].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) != 0) << std::endl;
  47.         std::cout << "Queue Count: " << familyProperties[i].queueCount << std::endl;
  48.         std::cout << "Timestamp Valid Bits: " << familyProperties[i].timestampValidBits << std::endl;
  49.         uint32_t width = familyProperties[i].minImageTransferGranularity.width;
  50.         uint32_t height = familyProperties[i].minImageTransferGranularity.height;
  51.         uint32_t depth = familyProperties[i].minImageTransferGranularity.depth;
  52.         std::cout << "Min Image Timestamp Granularity " << width << ", " << height << ", " << depth << std::endl;
  53.     }
  54.     std::this_thread::sleep_for(std::chrono::milliseconds(3000));
  55.     delete[] familyProperties;
  56. }
  57.  
  58. int main()
  59. {
  60.     VkApplicationInfo appInfo;
  61.     appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
  62.     appInfo.pNext = NULL;
  63.     appInfo.pApplicationName = "Vulkan App";
  64.     appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
  65.     appInfo.pEngineName = "Vulkan Engine";
  66.     appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
  67.     appInfo.apiVersion = VK_API_VERSION_1_0;
  68.  
  69.     uint32_t amountOfLayers = 0;
  70.     vkEnumerateInstanceLayerProperties(&amountOfLayers, NULL);
  71.     VkLayerProperties *layers = new VkLayerProperties[amountOfLayers];
  72.     vkEnumerateInstanceLayerProperties(&amountOfLayers, layers);
  73.     std::cout << "Amount of Instance Layers: " << amountOfLayers << std::endl;
  74.     for (int i = 0; i < amountOfLayers; i++) {
  75.         std::cout << std::endl;
  76.         std::cout << "Name:                   " << layers[i].layerName << std::endl;
  77.         std::cout << "Spec Version:           " << layers[i].specVersion << std::endl;
  78.         std::cout << "Implemetnation Version: " << layers[i].implementationVersion << std::endl;
  79.         std::cout << "Decsription:            " << layers[i].description << std::endl;
  80.     }
  81.  
  82.     uint32_t amountOfExtentions = 0;
  83.     vkEnumerateInstanceExtensionProperties(NULL,&amountOfExtentions,NULL);
  84.     VkExtensionProperties *extensions = new VkExtensionProperties[amountOfExtentions];
  85.     vkEnumerateInstanceExtensionProperties(NULL, &amountOfExtentions, extensions);
  86.     std::cout << std::endl;
  87.     std::cout << "Amount of Extensions: " << amountOfExtentions << std::endl;
  88.     for (int i = 0; i < amountOfExtentions; i++) {
  89.         std::cout << std::endl;
  90.         std::cout << "Name: " << extensions[i].extensionName << std::endl;
  91.         std::cout << "Spec Version: " << extensions[i].specVersion << std::endl;
  92.     }
  93.  
  94.     const std::vector<const char*> validationLayers = {
  95.         "VK_LAYER_LUNARG_standard_validation"
  96.     };
  97.     VkInstanceCreateInfo instanceInfo;
  98.     instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
  99.     instanceInfo.pNext = NULL;
  100.     instanceInfo.flags = 0;
  101.     instanceInfo.pApplicationInfo = &appInfo;
  102.     instanceInfo.enabledLayerCount = validationLayers.size();
  103.     instanceInfo.ppEnabledLayerNames = validationLayers.data();
  104.     instanceInfo.enabledExtensionCount = 0;
  105.     instanceInfo.ppEnabledExtensionNames = NULL;
  106.  
  107.     VkResult result = vkCreateInstance(&instanceInfo,NULL,&instance);
  108.     vkGetInstanceProcAddr(instance, "");
  109.     ASSERT_VUKLAN(result);
  110.  
  111.     uint32_t amountOfPhysicalDevices = 0;
  112.     result = vkEnumeratePhysicalDevices(instance, &amountOfPhysicalDevices, NULL);
  113.     ASSERT_VUKLAN(result);
  114.  
  115.     std::vector<VkPhysicalDevice> physicalDevices; // Andere Variante, wird automatisch deleted, bedarf am Ende der main() keinerlei behandlung mehr.
  116.     physicalDevices.resize(amountOfPhysicalDevices);
  117.     result = vkEnumeratePhysicalDevices(instance, &amountOfPhysicalDevices, physicalDevices.data());
  118.     ASSERT_VUKLAN(result);
  119.    
  120.     for (int i = 0; i < amountOfPhysicalDevices; i++) {
  121.         printStats(physicalDevices[i]);
  122.     }
  123.  
  124.     float queuePrios[] = { 1.0f,1.0f,1.0f,1.0f};
  125.     VkDeviceQueueCreateInfo deviceQueueCreateInfo;
  126.     deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
  127.     deviceQueueCreateInfo.pNext = NULL;
  128.     deviceQueueCreateInfo.flags = 0;
  129.     deviceQueueCreateInfo.queueFamilyIndex = 0;
  130.     deviceQueueCreateInfo.queueCount = 1;
  131.     deviceQueueCreateInfo.pQueuePriorities = queuePrios;
  132.  
  133.     VkPhysicalDeviceFeatures usedFeatures = {};
  134.  
  135.     VkDeviceCreateInfo deviceCreateInfo;
  136.     deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
  137.     deviceCreateInfo.pNext = NULL;
  138.     deviceCreateInfo.flags = 0;
  139.     deviceCreateInfo.queueCreateInfoCount = 1;
  140.     deviceCreateInfo.pQueueCreateInfos = &deviceQueueCreateInfo;
  141.     deviceCreateInfo.enabledLayerCount = 0;
  142.     deviceCreateInfo.ppEnabledLayerNames = NULL;
  143.     deviceCreateInfo.enabledExtensionCount = 0;
  144.     deviceCreateInfo.ppEnabledExtensionNames = NULL;
  145.     deviceCreateInfo.pEnabledFeatures = &usedFeatures;
  146.  
  147.    
  148.     result = vkCreateDevice(physicalDevices[0], &deviceCreateInfo, NULL, &device);
  149.     ASSERT_VUKLAN(result);
  150.  
  151.     std::this_thread::sleep_for(std::chrono::milliseconds(6000));
  152.  
  153.     vkDeviceWaitIdle(device);
  154.  
  155.     vkDestroyDevice(device, NULL);
  156.     vkDestroyInstance(instance, NULL);
  157.  
  158.     delete[] layers;
  159.     delete[] extensions;
  160.     return 0;
  161.    
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement