VulkanTutorial/VulkanTutorial/VulkanApp.cpp
/* Instance is how vulkan interacts with this application*/
Instance is how vulkan interacts with this application
Instance is how vulkan interacts with this application
void VulkanApp::createInstance() {
  if (enable_valid_layers_ && !checkValidationLayerSupport())
    throw std::runtime_error("Validation layers requested, not available.");
  VkApplicationInfo appInfo{};
  appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
  appInfo.pApplicationName = "Hello Triangle";
  appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
  appInfo.pEngineName = "No Engine Name";
  appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
  appInfo.apiVersion = VK_API_VERSION_1_2;
  VkInstanceCreateInfo createInfo{};
  createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
  createInfo.pApplicationInfo = &appInfo;
  VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo;
  auto required_extensions = getRequiredExtensions();
  createInfo.enabledExtensionCount =
      static_cast<uint32_t>(required_extensions.size());
  createInfo.ppEnabledExtensionNames = required_extensions.data();
  if (enable_valid_layers_) {
    createInfo.enabledLayerCount =
        static_cast<uint32_t>(validation_layers_.size());
    createInfo.ppEnabledLayerNames = validation_layers_.data();
    populateDebugMessengerCreateInfo(debugCreateInfo);
    createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
  } else {
    createInfo.enabledLayerCount = 0;
    createInfo.pNext = nullptr;
  }
  if (vkCreateInstance(&createInfo, nullptr, &instance_) != VK_SUCCESS) {
    throw std::runtime_error("Failed to create vulkan instance");
  }
  uint32_t extension_count = 0;
  vkEnumerateInstanceExtensionProperties(nullptr, &extension_count, nullptr);
  std::vector<VkExtensionProperties> extensions(extension_count);
  vkEnumerateInstanceExtensionProperties(nullptr, &extension_count,
                                         extensions.data());
  std::cout << "Available extensions" << std::endl;
  for (auto& ext : extensions) {
    std::cout << "\t" << ext.extensionName << '\n';
  }
}
void VulkanApp :: createInstance ( ) { if ( enable_valid_layers_ && ! checkValidationLayerSupport ( ) ) throw std :: runtime_error ( " " ) ; VkApplicationInfo appInfo { } ; appInfo . sType = VK_STRUCTURE_TYPE_APPLICATION_INFO ; appInfo . pApplicationName = " " ; appInfo . applicationVersion = VK_MAKE_VERSION ( 1 , 0 , 0 ) ; appInfo . pEngineName = " " ; appInfo . engineVersion = VK_MAKE_VERSION ( 1 , 0 , 0 ) ; appInfo . apiVersion = VK_API_VERSION_1_2 ; VkInstanceCreateInfo createInfo { } ; createInfo . sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO ; createInfo . pApplicationInfo = & appInfo ; VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo ; auto required_extensions = getRequiredExtensions ( ) ; createInfo . enabledExtensionCount = static_cast < uint32_t > ( required_extensions . size ( ) ) ; createInfo . ppEnabledExtensionNames = required_extensions . data ( ) ; if ( enable_valid_layers_ ) { createInfo . enabledLayerCount = static_cast < uint32_t > ( validation_layers_ . size ( ) ) ; createInfo . ppEnabledLayerNames = validation_layers_ . data ( ) ; populateDebugMessengerCreateInfo ( debugCreateInfo ) ; createInfo . pNext = ( VkDebugUtilsMessengerCreateInfoEXT * ) & debugCreateInfo ; } else { createInfo . enabledLayerCount = 0 ; createInfo . pNext = nullptr ; } if ( vkCreateInstance ( & createInfo , nullptr , & instance_ ) != VK_SUCCESS ) { throw std :: runtime_error ( " " ) ; } uint32_t extension_count = 0 ; vkEnumerateInstanceExtensionProperties ( nullptr , & extension_count , nullptr ) ; std :: vector < VkExtensionProperties > extensions ( extension_count ) ; vkEnumerateInstanceExtensionProperties ( nullptr , & extension_count , extensions . data ( ) ) ; std :: cout << " " << std :: endl ; for ( auto & ext : extensions ) { std :: cout << " \t " << ext . extensionName << ' \n ' ; } }
Instance is how vulkan interacts with this application
Instance is how vulkan interacts with this application
// Optional app info // Not optional // Create debug messenger so debugging can be done in vkCreateInstance and  // vkDestroyInstance // Check driver for supported extensions // Get the extension details