示例#1
0
文件: main.cpp 项目: Asmodean-/Vulkan
static void terminateApp()
{
	if (device.get())
	{
		queue.reset();

		//

		device->destroy();
	}

	//

	if (surface.get())
	{
		surface->destroy();
	}

	//

	if (window.get())
	{
		window->destroy();
	}

	if (display.get())
	{
		display->destroy();
	}

	vkts::visualTerminate();

	//

	physicalDevice.reset();

	if (instance.get())
	{
		instance->destroy();
	}

	//

	vkts::engineTerminate();
}
示例#2
0
文件: main.cpp 项目: YoutaVen/Vulkan
static void terminateApp()
{
	if (device.get())
	{
		queue.reset();

		//

		device->destroy();
	}

	//

	physicalDevice.reset();

	if (instance.get())
	{
		instance->destroy();
	}

	//

	vkts::engineTerminate();
}
示例#3
0
文件: main.cpp 项目: YoutaVen/Vulkan
int main()
{
	//
	// Engine initialization.
	//

	if (!vkts::engineInit())
	{
		return -1;
	}

	vkts::logSetLevel(VKTS_LOG_INFO);

	//

	instance = vkts::instanceCreate(VKTS_EXAMPLE_NAME, VK_MAKE_VERSION(1, 0, 0), VK_MAKE_VERSION(1, 0, 0), 0, 0, nullptr, 0, nullptr);

	if (!instance.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create instance.");

		terminateApp();

		return -1;
	}

	physicalDevice = vkts::physicalDeviceCreate(instance->getInstance(), 0);

	if (!physicalDevice.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not get physical device.");

		terminateApp();

		return -1;
	}

	//

	uint32_t queueFamilyIndex;

	if (!vkts::queueGetFamilyIndex(physicalDevice->getAllQueueFamilyProperties(), VK_QUEUE_COMPUTE_BIT, 0, nullptr, queueFamilyIndex))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not find queue family index.");

		terminateApp();

		return -1;
	}

	//

	float queuePriorities[1] = {0.0f};

	VkDeviceQueueCreateInfo deviceQueueCreateInfo;

	memset(&deviceQueueCreateInfo, 0, sizeof(VkDeviceQueueCreateInfo));

	deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;

	deviceQueueCreateInfo.flags = 0;
	deviceQueueCreateInfo.queueFamilyIndex = 0;
	deviceQueueCreateInfo.queueCount = 1;
	deviceQueueCreateInfo.pQueuePriorities = queuePriorities;

	device = vkts::deviceCreate(physicalDevice->getPhysicalDevice(), 0, 1, &deviceQueueCreateInfo, 0, nullptr, 0, nullptr, nullptr);

	if (!device.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create device.");

		terminateApp();

		return -1;
	}

	//

	queue = vkts::queueGet(device->getDevice(), queueFamilyIndex, 0);

	if (!queue.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not get device queue.");

		terminateApp();

		return -1;
	}

	//
	// Example setup.
	//

	vkts::IUpdateThreadSP example = vkts::IUpdateThreadSP(new Example(instance, physicalDevice, device, queue));

	if (!example.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create application.");

		terminateApp();

		return -1;
	}

	// This update thread is executed in the main loop. No additional thread is launched.
	vkts::engineAddUpdateThread(example);

	//
	// Execution.
	//

	vkts::engineRun();

	//
	// Termination.
	//

	terminateApp();

	return 0;
}
示例#4
0
文件: main.cpp 项目: Asmodean-/Vulkan
int main()
{
	//
	// Engine initialization.
	//

	if (!vkts::engineInit())
	{
		return -1;
	}

	vkts::logSetLevel(VKTS_LOG_INFO);

	//

	VkResult result;

	//

	if (!vkts::wsiGatherNeededInstanceExtensions())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Example: Could not gather instance extensions.");

		terminateApp();

		return -1;
	}

	instance = vkts::instanceCreate(VKTS_EXAMPLE_NAME, VK_MAKE_VERSION(1, 0, 0), VK_MAKE_VERSION(1, 0, 0), 0, 0, nullptr, vkts::extensionGetNeededInstanceExtensionCount(), vkts::extensionGetNeededInstanceExtensionNames());

	if (!instance.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create instance.");

		terminateApp();

		return -1;
	}

	if (!vkts::wsiInitInstanceExtensions(instance->getInstance()))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not initialize instance extension.");

		terminateApp();

		return -1;
	}

	physicalDevice = vkts::physicalDeviceCreate(instance->getInstance(), 0);

	if (!physicalDevice.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not get physical device.");

		terminateApp();

		return -1;
	}

	if (!vkts::wsiGatherNeededDeviceExtensions(physicalDevice->getPhysicalDevice()))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not gather device extension.");

		terminateApp();

		return -1;
	}

	//
	// Visual initialization.
	//

	if (!vkts::visualInit(instance->getInstance(), physicalDevice->getPhysicalDevice()))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not initialize visual.");

		terminateApp();

		return -1;
	}

	display = vkts::visualCreateDefaultDisplay().lock();

	if (!display.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create display.");

		terminateApp();

		return -1;
	}

	window = vkts::visualCreateWindow(display, VKTS_EXAMPLE_NAME, 1024, 768, VK_FALSE, VK_TRUE, VK_FALSE).lock();

	if (!window.get())
	{
		window = vkts::visualGetWindow(VKTS_DEFAULT_WINDOW_INDEX).lock();

		if (!window.get())
		{
			vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create window.");

			terminateApp();

			return -1;
		}
	}

	//

	surface = vkts::wsiSurfaceCreate(instance->getInstance(), display->getNativeDisplay(), window->getNativeWindow());

	if (!surface.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create surface.");

		terminateApp();

		return -1;
	}

	//

	std::vector<VkBool32> supportFilter;

	result = vkts::wsiGetPhysicalDeviceSurfaceSupport(physicalDevice->getPhysicalDevice(), surface->getSurface(), (uint32_t) physicalDevice->getAllQueueFamilyProperties().size(), supportFilter);

	if (result != VK_SUCCESS || supportFilter.size() == 0)
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not get physical device surface support.");

		terminateApp();

		return -1;
	}

	//

	uint32_t queueFamilyIndex;

	if (!vkts::queueGetFamilyIndex(physicalDevice->getAllQueueFamilyProperties(), VK_QUEUE_GRAPHICS_BIT, 0, &supportFilter, queueFamilyIndex))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not find queue family index.");

		terminateApp();

		return -1;
	}

	//

	float queuePriorities[1] = {0.0f};

	VkDeviceQueueCreateInfo deviceQueueCreateInfo;

	memset(&deviceQueueCreateInfo, 0, sizeof(VkDeviceQueueCreateInfo));

	deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;

	deviceQueueCreateInfo.flags = 0;
	deviceQueueCreateInfo.queueFamilyIndex = 0;
	deviceQueueCreateInfo.queueCount = 1;
	deviceQueueCreateInfo.pQueuePriorities = queuePriorities;

	device = vkts::deviceCreate(physicalDevice->getPhysicalDevice(), 0, 1, &deviceQueueCreateInfo, 0, nullptr, vkts::extensionGetNeededDeviceExtensionCount(), vkts::extensionGetNeededDeviceExtensionNames(), nullptr);

	if (!device.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create device.");

		terminateApp();

		return -1;
	}

	if (!vkts::wsiInitDeviceExtensions(device->getDevice()))
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not initialize device extension.");

		terminateApp();

		return -1;
	}

	//

	queue = vkts::queueGet(device->getDevice(), queueFamilyIndex, 0);

	if (!queue.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not get device queue.");

		terminateApp();

		return -1;
	}

	//
	// Example setup.
	//

	// Single threaded application, so it is safe to pass display and window.
	vkts::IUpdateThreadSP example = vkts::IUpdateThreadSP(new Example(instance, physicalDevice, window->getIndex(), surface, device, queue));

	if (!example.get())
	{
		vkts::logPrint(VKTS_LOG_ERROR, "Main: Could not create application.");

		terminateApp();

		return -1;
	}

	// This update thread is executed in the main loop. No additional thread is launched.
	vkts::engineAddUpdateThread(example);

	//
	// Execution.
	//

	vkts::engineRun();

	//
	// Termination.
	//

	terminateApp();

	return 0;
}