2017-12-04 21:17:37 +00:00
|
|
|
// Copyright 2017 The NXT Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "backend/vulkan/FencedDeleter.h"
|
|
|
|
|
|
|
|
#include "backend/vulkan/VulkanBackend.h"
|
|
|
|
|
|
|
|
namespace backend { namespace vulkan {
|
|
|
|
|
|
|
|
FencedDeleter::FencedDeleter(Device* device) : mDevice(device) {
|
|
|
|
}
|
|
|
|
|
|
|
|
FencedDeleter::~FencedDeleter() {
|
|
|
|
ASSERT(mBuffersToDelete.Empty());
|
2018-01-09 14:55:27 +00:00
|
|
|
ASSERT(mImagesToDelete.Empty());
|
2017-12-04 21:17:37 +00:00
|
|
|
ASSERT(mMemoriesToDelete.Empty());
|
2018-01-09 14:55:27 +00:00
|
|
|
ASSERT(mPipelineLayoutsToDelete.Empty());
|
|
|
|
ASSERT(mRenderPassesToDelete.Empty());
|
2017-12-04 21:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FencedDeleter::DeleteWhenUnused(VkBuffer buffer) {
|
|
|
|
mBuffersToDelete.Enqueue(buffer, mDevice->GetSerial());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FencedDeleter::DeleteWhenUnused(VkDeviceMemory memory) {
|
|
|
|
mMemoriesToDelete.Enqueue(memory, mDevice->GetSerial());
|
|
|
|
}
|
|
|
|
|
2018-01-03 15:58:14 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkImage image) {
|
|
|
|
mImagesToDelete.Enqueue(image, mDevice->GetSerial());
|
|
|
|
}
|
|
|
|
|
2018-01-09 12:37:02 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkPipelineLayout layout) {
|
|
|
|
mPipelineLayoutsToDelete.Enqueue(layout, mDevice->GetSerial());
|
|
|
|
}
|
|
|
|
|
2018-01-09 14:55:27 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkRenderPass renderPass) {
|
|
|
|
mRenderPassesToDelete.Enqueue(renderPass, mDevice->GetSerial());
|
|
|
|
}
|
|
|
|
|
2017-12-04 21:17:37 +00:00
|
|
|
void FencedDeleter::Tick(Serial completedSerial) {
|
2018-01-09 12:37:02 +00:00
|
|
|
VkDevice vkDevice = mDevice->GetVkDevice();
|
|
|
|
|
2018-01-03 15:58:14 +00:00
|
|
|
// Buffers and images must be deleted before memories because it is invalid to free memory
|
2017-12-04 21:17:37 +00:00
|
|
|
// that still have resources bound to it.
|
|
|
|
for (VkBuffer buffer : mBuffersToDelete.IterateUpTo(completedSerial)) {
|
2018-01-09 12:37:02 +00:00
|
|
|
mDevice->fn.DestroyBuffer(vkDevice, buffer, nullptr);
|
2017-12-04 21:17:37 +00:00
|
|
|
}
|
|
|
|
mBuffersToDelete.ClearUpTo(completedSerial);
|
2018-01-03 15:58:14 +00:00
|
|
|
for (VkImage image : mImagesToDelete.IterateUpTo(completedSerial)) {
|
2018-01-09 12:37:02 +00:00
|
|
|
mDevice->fn.DestroyImage(vkDevice, image, nullptr);
|
2018-01-03 15:58:14 +00:00
|
|
|
}
|
|
|
|
mImagesToDelete.ClearUpTo(completedSerial);
|
2017-12-04 21:17:37 +00:00
|
|
|
|
|
|
|
for (VkDeviceMemory memory : mMemoriesToDelete.IterateUpTo(completedSerial)) {
|
2018-01-09 12:37:02 +00:00
|
|
|
mDevice->fn.FreeMemory(vkDevice, memory, nullptr);
|
2017-12-04 21:17:37 +00:00
|
|
|
}
|
|
|
|
mMemoriesToDelete.ClearUpTo(completedSerial);
|
2018-01-09 12:37:02 +00:00
|
|
|
|
|
|
|
for (VkPipelineLayout layout : mPipelineLayoutsToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroyPipelineLayout(vkDevice, layout, nullptr);
|
|
|
|
}
|
|
|
|
mPipelineLayoutsToDelete.ClearUpTo(completedSerial);
|
2018-01-09 14:55:27 +00:00
|
|
|
|
|
|
|
for (VkRenderPass renderPass : mRenderPassesToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroyRenderPass(vkDevice, renderPass, nullptr);
|
|
|
|
}
|
|
|
|
mRenderPassesToDelete.ClearUpTo(completedSerial);
|
2017-12-04 21:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}} // namespace backend::vulkan
|