Commit 43be7163 by Hernan Liatis

Handle oldSwapchains

When we create a new swapchain, we can pass in a parent swapchain from the same surface. The old swapchain is no longer associated with the surface and "retires" by deleting all non-acquired images. Bug: b/124265819 Change-Id: I31315045c926b929483d1b6cb1fc3d9f7aa87b94 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26668Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarHernan Liatis <hliatis@google.com>
parent b4de34ef
...@@ -2172,6 +2172,16 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwa ...@@ -2172,6 +2172,16 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwa
TRACE("(VkDevice device = 0x%X, const VkSwapchainCreateInfoKHR* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkSwapchainKHR* pSwapchain = 0x%X)", TRACE("(VkDevice device = 0x%X, const VkSwapchainCreateInfoKHR* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkSwapchainKHR* pSwapchain = 0x%X)",
device, pCreateInfo, pAllocator, pSwapchain); device, pCreateInfo, pAllocator, pSwapchain);
if(pCreateInfo->oldSwapchain)
{
vk::Cast(pCreateInfo->oldSwapchain)->retire();
}
if(vk::Cast(pCreateInfo->surface)->getAssociatedSwapchain() != VK_NULL_HANDLE)
{
return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR;
}
VkResult status = vk::SwapchainKHR::Create(pAllocator, pCreateInfo, pSwapchain); VkResult status = vk::SwapchainKHR::Create(pAllocator, pCreateInfo, pSwapchain);
if(status != VK_SUCCESS) if(status != VK_SUCCESS)
...@@ -2187,6 +2197,8 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwa ...@@ -2187,6 +2197,8 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwa
return status; return status;
} }
vk::Cast(pCreateInfo->surface)->associateSwapchain(*pSwapchain);
return VK_SUCCESS; return VK_SUCCESS;
} }
......
...@@ -83,4 +83,19 @@ VkResult SurfaceKHR::getPresentModes(uint32_t *pPresentModeCount, VkPresentModeK ...@@ -83,4 +83,19 @@ VkResult SurfaceKHR::getPresentModes(uint32_t *pPresentModeCount, VkPresentModeK
return VK_SUCCESS; return VK_SUCCESS;
} }
void SurfaceKHR::associateSwapchain(VkSwapchainKHR swapchain)
{
associatedSwapchain = swapchain;
}
void SurfaceKHR::disassociateSwapchain()
{
associatedSwapchain = VK_NULL_HANDLE;
}
VkSwapchainKHR SurfaceKHR::getAssociatedSwapchain()
{
return associatedSwapchain;
}
} }
\ No newline at end of file
...@@ -64,7 +64,14 @@ public: ...@@ -64,7 +64,14 @@ public:
virtual void detachImage(PresentImage* image) = 0; virtual void detachImage(PresentImage* image) = 0;
virtual void present(PresentImage* image) = 0; virtual void present(PresentImage* image) = 0;
void associateSwapchain(VkSwapchainKHR swapchain);
void disassociateSwapchain();
VkSwapchainKHR getAssociatedSwapchain();
private: private:
VkSwapchainKHR associatedSwapchain;
const std::vector<VkSurfaceFormatKHR> surfaceFormats = const std::vector<VkSurfaceFormatKHR> surfaceFormats =
{ {
{VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}, {VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR},
......
...@@ -24,7 +24,8 @@ namespace vk ...@@ -24,7 +24,8 @@ namespace vk
{ {
SwapchainKHR::SwapchainKHR(const VkSwapchainCreateInfoKHR *pCreateInfo, void *mem) : SwapchainKHR::SwapchainKHR(const VkSwapchainCreateInfoKHR *pCreateInfo, void *mem) :
createInfo(*pCreateInfo) createInfo(*pCreateInfo),
retired(false)
{ {
images.resize(pCreateInfo->minImageCount); images.resize(pCreateInfo->minImageCount);
resetImages(); resetImages();
...@@ -43,6 +44,11 @@ void SwapchainKHR::destroy(const VkAllocationCallbacks *pAllocator) ...@@ -43,6 +44,11 @@ void SwapchainKHR::destroy(const VkAllocationCallbacks *pAllocator)
currentImage.imageStatus = NONEXISTENT; currentImage.imageStatus = NONEXISTENT;
} }
} }
if(!retired)
{
vk::Cast(createInfo.surface)->disassociateSwapchain();
}
} }
size_t SwapchainKHR::ComputeRequiredAllocationSize(const VkSwapchainCreateInfoKHR *pCreateInfo) size_t SwapchainKHR::ComputeRequiredAllocationSize(const VkSwapchainCreateInfoKHR *pCreateInfo)
...@@ -50,6 +56,27 @@ size_t SwapchainKHR::ComputeRequiredAllocationSize(const VkSwapchainCreateInfoKH ...@@ -50,6 +56,27 @@ size_t SwapchainKHR::ComputeRequiredAllocationSize(const VkSwapchainCreateInfoKH
return 0; return 0;
} }
void SwapchainKHR::retire()
{
if(!retired)
{
retired = true;
vk::Cast(createInfo.surface)->disassociateSwapchain();
for(auto& currentImage : images)
{
if(currentImage.imageStatus == AVAILABLE)
{
vk::Cast(createInfo.surface)->detachImage(&currentImage);
vk::destroy(currentImage.imageMemory, nullptr);
vk::destroy(currentImage.image, nullptr);
currentImage.imageStatus = NONEXISTENT;
}
}
}
}
void SwapchainKHR::resetImages() void SwapchainKHR::resetImages()
{ {
for(auto& currentImage : images) for(auto& currentImage : images)
...@@ -182,6 +209,15 @@ void SwapchainKHR::present(uint32_t index) ...@@ -182,6 +209,15 @@ void SwapchainKHR::present(uint32_t index)
image.imageStatus = PRESENTING; image.imageStatus = PRESENTING;
vk::Cast(createInfo.surface)->present(&image); vk::Cast(createInfo.surface)->present(&image);
image.imageStatus = AVAILABLE; image.imageStatus = AVAILABLE;
if(retired)
{
vk::Cast(createInfo.surface)->detachImage(&image);
vk::destroy(image.imageMemory, nullptr);
vk::destroy(image.image, nullptr);
image.imageStatus = NONEXISTENT;
}
} }
} }
\ No newline at end of file
...@@ -35,6 +35,8 @@ public: ...@@ -35,6 +35,8 @@ public:
static size_t ComputeRequiredAllocationSize(const VkSwapchainCreateInfoKHR* pCreateInfo); static size_t ComputeRequiredAllocationSize(const VkSwapchainCreateInfoKHR* pCreateInfo);
void retire();
VkResult createImages(VkDevice device); VkResult createImages(VkDevice device);
uint32_t getImageCount() const; uint32_t getImageCount() const;
...@@ -47,6 +49,7 @@ public: ...@@ -47,6 +49,7 @@ public:
private: private:
VkSwapchainCreateInfoKHR createInfo; VkSwapchainCreateInfoKHR createInfo;
std::vector<PresentImage> images; std::vector<PresentImage> images;
bool retired;
void resetImages(); void resetImages();
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment