Stop leaking framebuffers on shutdown. Fix other shutdown issues.

This commit is contained in:
Henrik Rydgård 2017-11-01 21:42:19 +01:00
parent 0e5b398c9d
commit 8d0209c7e4
6 changed files with 35 additions and 0 deletions

View File

@ -118,6 +118,22 @@ FramebufferManagerCommon::FramebufferManagerCommon(Draw::DrawContext *draw)
}
FramebufferManagerCommon::~FramebufferManagerCommon() {
DecimateFBOs();
for (auto vfb : vfbs_) {
DestroyFramebuf(vfb);
}
vfbs_.clear();
for (auto &tempFB : tempFBOs_) {
tempFB.second.fbo->Release();
}
tempFBOs_.clear();
// Do the same for ReadFramebuffersToMemory's VFBs
for (auto vfb : bvfbs_) {
DestroyFramebuf(vfb);
}
bvfbs_.clear();
}
void FramebufferManagerCommon::Init() {

View File

@ -984,6 +984,8 @@ void EmuScreen::postRender() {
Draw::DrawContext *draw = screenManager()->getDrawContext();
if (!draw)
return;
if (invalid_)
draw->WipeQueue();
draw->EndFrame();
}

View File

@ -554,6 +554,14 @@ void VulkanRenderManager::Finish() {
vulkan_->EndFrame();
}
void VulkanRenderManager::Wipe() {
int curFrame = vulkan_->GetCurFrame();
for (auto iter : steps_) {
delete iter;
}
steps_.clear();
}
// Can be called multiple times with no bad side effects. This is so that we can either begin a frame the normal way,
// or stop it in the middle for a synchronous readback, then start over again mostly normally but without repeating
// the backbuffer image acquisition.

View File

@ -83,6 +83,9 @@ public:
void Finish();
void Run(int frame);
// Zaps queued up commands. Use if you know there's a risk you've queued up stuff that has already been deleted. Can happen during in-game shutdown.
void Wipe();
void BindFramebufferAsRenderTarget(VKRFramebuffer *fb, VKRRenderPassAction color, VKRRenderPassAction depth, uint32_t clearColor, float clearDepth, uint8_t clearStencil);
VkImageView BindFramebufferAsTexture(VKRFramebuffer *fb, int binding, int aspectBit, int attachment);
void CopyFramebufferToMemorySync(VKRFramebuffer *src, int aspectBits, int x, int y, int w, int h, Draw::DataFormat destFormat, uint8_t *pixels, int pixelStride);

View File

@ -609,6 +609,7 @@ public:
// Frame management (for the purposes of sync and resource management, necessary with modern APIs). Default implementations here.
virtual void BeginFrame() {}
virtual void EndFrame() {}
virtual void WipeQueue() {}
// This should be avoided as much as possible, in favor of clearing when binding a render target, which is native
// on Vulkan.

View File

@ -418,6 +418,7 @@ public:
void BeginFrame() override;
void EndFrame() override;
void WipeQueue() override;
void FlushState() override {
}
@ -766,6 +767,10 @@ void VKContext::EndFrame() {
push_ = nullptr;
}
void VKContext::WipeQueue() {
renderManager_.Wipe();
}
VkDescriptorSet VKContext::GetOrCreateDescriptorSet(VkBuffer buf) {
DescriptorSetKey key;