void setupDebugCallback() {
        if (!enableValidationLayers) return;

        VkDebugReportCallbackCreateInfoEXT createInfo = {};
        createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
        createInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
        createInfo.pfnCallback = (PFN_vkDebugReportCallbackEXT) debugCallback;

        if (CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &callback) != VK_SUCCESS) {
            throw std::runtime_error("failed to set up debug callback!");
        }
    }
Exemple #2
0
				instance::instance() {

					if (Aeon::framework::enableValidationLayers && !checkValidationLayerSupport()) {
						throw Aeon::framework::exception("validation layers requested, but not available!");
					}

					// Setup appinfo
					appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
					appInfo.pApplicationName = "Hello Triangle";
					appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
					appInfo.pEngineName = ENGINE_NAME;
					appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
					appInfo.apiVersion = VK_API_VERSION_1_0;

					//Setup create info
					createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
					createInfo.pApplicationInfo = &appInfo;

					auto extensions = getRequiredExtensions();
					createInfo.enabledExtensionCount = extensions.size();
					createInfo.ppEnabledExtensionNames = extensions.data();

					if (Aeon::framework::enableValidationLayers) {
						createInfo.enabledLayerCount = Aeon::framework::validationLayers.size();
						createInfo.ppEnabledLayerNames = Aeon::framework::validationLayers.data();
					}
					else {
						createInfo.enabledLayerCount = 0;
					}

					// Create VKInstance;
					if (vkCreateInstance(&createInfo, nullptr, &pdata) != VK_SUCCESS) {
						throw Aeon::framework::exception("failed to create instance!");
					}

					// Setup debug callback

					if (Aeon::framework::enableValidationLayers) {
						VkDebugReportCallbackCreateInfoEXT dbgcreateInfo = {};
						dbgcreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
						dbgcreateInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
						dbgcreateInfo.pfnCallback = debugCallback;

						if (CreateDebugReportCallbackEXT(pdata, &dbgcreateInfo, nullptr, &callback) != VK_SUCCESS) {
							throw Aeon::framework::exception("failed to set up debug callback!");
						}
					}
				}