Vulkan: Support recreating swapchain with SwapChain.Configure()

This patch adds the support of recreating a swapchain with SwapChain.
Configure() on Vulkan backends.
1. Query the Vulkan surface information again.
2. Clean up old swapchain.

BUG=dawn:177

Change-Id: Id7e9e07e9dbbba4a71322367cae10fb179106220
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9340
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2019-07-25 01:08:14 +00:00 committed by Commit Bot service account
parent 2718177841
commit 9d2ccaf65c
2 changed files with 15 additions and 2 deletions

View File

@ -57,7 +57,7 @@ namespace dawn_native { namespace vulkan {
}
}
void NativeSwapChainImpl::Init(DawnWSIContextVulkan* /*context*/) {
void NativeSwapChainImpl::UpdateSurfaceConfig() {
if (mDevice->ConsumedError(
GatherSurfaceInfo(*ToBackend(mDevice->GetAdapter()), mSurface, &mInfo))) {
ASSERT(false);
@ -68,10 +68,16 @@ namespace dawn_native { namespace vulkan {
}
}
void NativeSwapChainImpl::Init(DawnWSIContextVulkan* /*context*/) {
UpdateSurfaceConfig();
}
DawnSwapChainError NativeSwapChainImpl::Configure(DawnTextureFormat format,
DawnTextureUsageBit usage,
uint32_t width,
uint32_t height) {
UpdateSurfaceConfig();
ASSERT(mInfo.capabilities.minImageExtent.width <= width);
ASSERT(mInfo.capabilities.maxImageExtent.width >= width);
ASSERT(mInfo.capabilities.minImageExtent.height <= height);
@ -81,6 +87,7 @@ namespace dawn_native { namespace vulkan {
// TODO(cwallez@chromium.org): need to check usage works too
// Create the swapchain with the configuration we chose
VkSwapchainKHR oldSwapchain = mSwapChain;
VkSwapchainCreateInfoKHR createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
createInfo.pNext = nullptr;
@ -101,7 +108,7 @@ namespace dawn_native { namespace vulkan {
createInfo.compositeAlpha = mConfig.compositeAlpha;
createInfo.presentMode = mConfig.presentMode;
createInfo.clipped = false;
createInfo.oldSwapchain = VK_NULL_HANDLE;
createInfo.oldSwapchain = oldSwapchain;
if (mDevice->fn.CreateSwapchainKHR(mDevice->GetVkDevice(), &createInfo, nullptr,
&mSwapChain) != VK_SUCCESS) {
@ -148,6 +155,10 @@ namespace dawn_native { namespace vulkan {
nullptr, 1, &barrier);
}
if (oldSwapchain != VK_NULL_HANDLE) {
mDevice->GetFencedDeleter()->DeleteWhenUnused(oldSwapchain);
}
return DAWN_SWAP_CHAIN_NO_ERROR;
}

View File

@ -52,6 +52,8 @@ namespace dawn_native { namespace vulkan {
};
private:
void UpdateSurfaceConfig();
VkSurfaceKHR mSurface = VK_NULL_HANDLE;
VkSwapchainKHR mSwapChain = VK_NULL_HANDLE;
std::vector<VkImage> mSwapChainImages;