VkInstanceCreateInfo instance_create_info {}; instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instance_create_info.pApplicationInfo = &appInfo; // the appInfo is stored here
auto extensions = getRequiredExtensions(); instance_create_info.enabledExtensionCount = static_cast<uint32_t>(extensions.size()); instance_create_info.ppEnabledExtensionNames = extensions.data();
void Pilot::PVulkanContext::initializePhysicalDevice() { uint32_t physical_device_count; vkEnumeratePhysicalDevices(_instance, &physical_device_count, nullptr); if (physical_device_count == 0) { throw std::runtime_error("enumerate physical devices"); } else { // find one device that matches our requirement // or find which is the best std::vector<VkPhysicalDevice> physical_devices(physical_device_count); vkEnumeratePhysicalDevices(_instance, &physical_device_count, physical_devices.data());
std::vector<std::pair<int, VkPhysicalDevice>> ranked_physical_devices; for (constauto& device : physical_devices) { VkPhysicalDeviceProperties physical_device_properties; vkGetPhysicalDeviceProperties(device, &physical_device_properties); int score = 0;
int i = 0; for (constauto& queue_family : queue_families) { if (queue_family.queueFlags & VK_QUEUE_GRAPHICS_BIT) // if support graphics command queue { indices.graphicsFamily = i; }
VkBool32 is_present_support = false; vkGetPhysicalDeviceSurfaceSupportKHR(physical_device, i, _surface, &is_present_support); // if support surface presentation if (is_present_support) { indices.presentFamily = i; }
if (indices.isComplete()) { break; } i++; } return indices; }
void Pilot::PVulkanContext::createSwapchain() { // query all supports of this physical device SwapChainSupportDetails swapchain_support_details = querySwapChainSupport(_physical_device);
// choose the best or fitting format VkSurfaceFormatKHR chosen_surface_format = chooseSwapchainSurfaceFormatFromDetails(swapchain_support_details.formats); // choose the best or fitting present mode VkPresentModeKHR chosen_presentMode = chooseSwapchainPresentModeFromDetails(swapchain_support_details.presentModes); // choose the best or fitting extent VkExtent2D chosen_extent = chooseSwapchainExtentFromDetails(swapchain_support_details.capabilities);
// create imageview (one for each this time) for all swapchain images for (size_t i = 0; i < _swapchain_images.size(); i++) { _swapchain_imageviews[i] = PVulkanUtil::createImageView(_device, _swapchain_images[i], _swapchain_image_format, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_VIEW_TYPE_2D, 1, 1); } }