- move swapchain and the presentation related synchronization objects out of VulkanDevice

This commit is contained in:
Magnus Norddahl 2019-03-14 23:33:19 +01:00
commit 836938440c
7 changed files with 57 additions and 93 deletions

View file

@ -43,7 +43,6 @@
#include "doomerrors.h"
#include "gamedata/fonts/v_text.h"
void I_GetVulkanDrawableSize(int *width, int *height);
bool I_GetVulkanPlatformExtensions(unsigned int *count, const char **names);
bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface);
@ -51,8 +50,6 @@ bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface);
static std::vector<VulkanPhysicalDevice> AvailableDevices;
static std::vector<VulkanCompatibleDevice> SupportedDevices;
EXTERN_CVAR(Bool, vid_vsync);
CUSTOM_CVAR(Bool, vk_debug, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
Printf("This won't take effect until " GAMENAME " is restarted.\n");
@ -88,12 +85,6 @@ VulkanDevice::VulkanDevice()
SelectPhysicalDevice();
CreateDevice();
CreateAllocator();
int width, height;
I_GetVulkanDrawableSize(&width, &height);
swapChain = std::make_unique<VulkanSwapChain>(this, width, height, vid_vsync);
CreateSemaphores();
}
catch (...)
{
@ -202,44 +193,6 @@ void VulkanDevice::SelectPhysicalDevice()
transferFamily = SupportedDevices[selected].transferFamily;
}
void VulkanDevice::WindowResized()
{
int width, height;
I_GetVulkanDrawableSize(&width, &height);
swapChain.reset();
swapChain = std::make_unique<VulkanSwapChain>(this, width, height, vid_vsync);
}
void VulkanDevice::WaitPresent()
{
vkWaitForFences(device, 1, &renderFinishedFence->fence, VK_TRUE, std::numeric_limits<uint64_t>::max());
vkResetFences(device, 1, &renderFinishedFence->fence);
}
void VulkanDevice::BeginFrame()
{
VkResult result = vkAcquireNextImageKHR(device, swapChain->swapChain, std::numeric_limits<uint64_t>::max(), imageAvailableSemaphore->semaphore, VK_NULL_HANDLE, &presentImageIndex);
if (result != VK_SUCCESS)
throw std::runtime_error("Failed to acquire next image!");
}
void VulkanDevice::PresentFrame()
{
VkSemaphore waitSemaphores[] = { renderFinishedSemaphore->semaphore };
VkSwapchainKHR swapChains[] = { swapChain->swapChain };
VkPresentInfoKHR presentInfo = {};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = waitSemaphores;
presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = swapChains;
presentInfo.pImageIndices = &presentImageIndex;
presentInfo.pResults = nullptr;
vkQueuePresentKHR(presentQueue, &presentInfo);
}
void VulkanDevice::CreateAllocator()
{
VmaAllocatorCreateInfo allocinfo = {};
@ -251,13 +204,6 @@ void VulkanDevice::CreateAllocator()
throw std::runtime_error("Unable to create allocator");
}
void VulkanDevice::CreateSemaphores()
{
imageAvailableSemaphore.reset(new VulkanSemaphore(this));
renderFinishedSemaphore.reset(new VulkanSemaphore(this));
renderFinishedFence.reset(new VulkanFence(this));
}
void VulkanDevice::CreateDevice()
{
float queuePriority = 1.0f;
@ -531,11 +477,6 @@ void VulkanDevice::ReleaseResources()
if (device)
vkDeviceWaitIdle(device);
imageAvailableSemaphore.reset();
renderFinishedSemaphore.reset();
renderFinishedFence.reset();
swapChain.reset();
if (allocator)
vmaDestroyAllocator(allocator);