2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-12-04 21:17:37 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/vulkan/FencedDeleter.h"
|
2017-12-04 21:17:37 +00:00
|
|
|
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/vulkan/DeviceVk.h"
|
2017-12-04 21:17:37 +00:00
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native { namespace vulkan {
|
2017-12-04 21:17:37 +00:00
|
|
|
|
|
|
|
FencedDeleter::FencedDeleter(Device* device) : mDevice(device) {
|
|
|
|
}
|
|
|
|
|
|
|
|
FencedDeleter::~FencedDeleter() {
|
|
|
|
ASSERT(mBuffersToDelete.Empty());
|
2018-02-02 21:49:51 +00:00
|
|
|
ASSERT(mDescriptorPoolsToDelete.Empty());
|
2018-01-09 16:37:24 +00:00
|
|
|
ASSERT(mFramebuffersToDelete.Empty());
|
2018-01-09 14:55:27 +00:00
|
|
|
ASSERT(mImagesToDelete.Empty());
|
2018-01-09 16:37:24 +00:00
|
|
|
ASSERT(mImageViewsToDelete.Empty());
|
2017-12-04 21:17:37 +00:00
|
|
|
ASSERT(mMemoriesToDelete.Empty());
|
2018-01-09 18:50:07 +00:00
|
|
|
ASSERT(mPipelinesToDelete.Empty());
|
2018-01-09 14:55:27 +00:00
|
|
|
ASSERT(mPipelineLayoutsToDelete.Empty());
|
2020-08-20 00:40:07 +00:00
|
|
|
ASSERT(mQueryPoolsToDelete.Empty());
|
2018-01-09 14:55:27 +00:00
|
|
|
ASSERT(mRenderPassesToDelete.Empty());
|
2018-04-18 02:18:03 +00:00
|
|
|
ASSERT(mSamplersToDelete.Empty());
|
2018-01-26 21:47:12 +00:00
|
|
|
ASSERT(mSemaphoresToDelete.Empty());
|
2018-01-09 18:50:07 +00:00
|
|
|
ASSERT(mShaderModulesToDelete.Empty());
|
2018-01-26 21:47:12 +00:00
|
|
|
ASSERT(mSurfacesToDelete.Empty());
|
|
|
|
ASSERT(mSwapChainsToDelete.Empty());
|
2017-12-04 21:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FencedDeleter::DeleteWhenUnused(VkBuffer buffer) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mBuffersToDelete.Enqueue(buffer, mDevice->GetPendingCommandSerial());
|
2017-12-04 21:17:37 +00:00
|
|
|
}
|
|
|
|
|
2018-02-02 21:49:51 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkDescriptorPool pool) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mDescriptorPoolsToDelete.Enqueue(pool, mDevice->GetPendingCommandSerial());
|
2018-02-02 21:49:51 +00:00
|
|
|
}
|
|
|
|
|
2017-12-04 21:17:37 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkDeviceMemory memory) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mMemoriesToDelete.Enqueue(memory, mDevice->GetPendingCommandSerial());
|
2017-12-04 21:17:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 16:37:24 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkFramebuffer framebuffer) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mFramebuffersToDelete.Enqueue(framebuffer, mDevice->GetPendingCommandSerial());
|
2018-01-09 16:37:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-03 15:58:14 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkImage image) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mImagesToDelete.Enqueue(image, mDevice->GetPendingCommandSerial());
|
2018-01-03 15:58:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 16:37:24 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkImageView view) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mImageViewsToDelete.Enqueue(view, mDevice->GetPendingCommandSerial());
|
2018-01-09 16:37:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 18:50:07 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkPipeline pipeline) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mPipelinesToDelete.Enqueue(pipeline, mDevice->GetPendingCommandSerial());
|
2018-01-09 18:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 12:37:02 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkPipelineLayout layout) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mPipelineLayoutsToDelete.Enqueue(layout, mDevice->GetPendingCommandSerial());
|
2018-01-09 12:37:02 +00:00
|
|
|
}
|
|
|
|
|
2020-08-20 00:40:07 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkQueryPool querypool) {
|
|
|
|
mQueryPoolsToDelete.Enqueue(querypool, mDevice->GetPendingCommandSerial());
|
|
|
|
}
|
|
|
|
|
2018-01-09 14:55:27 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkRenderPass renderPass) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mRenderPassesToDelete.Enqueue(renderPass, mDevice->GetPendingCommandSerial());
|
2018-01-09 14:55:27 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 02:18:03 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkSampler sampler) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mSamplersToDelete.Enqueue(sampler, mDevice->GetPendingCommandSerial());
|
2018-04-18 02:18:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 21:47:12 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkSemaphore semaphore) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mSemaphoresToDelete.Enqueue(semaphore, mDevice->GetPendingCommandSerial());
|
2018-01-26 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 18:50:07 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkShaderModule module) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mShaderModulesToDelete.Enqueue(module, mDevice->GetPendingCommandSerial());
|
2018-01-09 18:50:07 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 21:47:12 +00:00
|
|
|
void FencedDeleter::DeleteWhenUnused(VkSurfaceKHR surface) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mSurfacesToDelete.Enqueue(surface, mDevice->GetPendingCommandSerial());
|
2018-01-26 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FencedDeleter::DeleteWhenUnused(VkSwapchainKHR swapChain) {
|
2018-12-01 03:20:19 +00:00
|
|
|
mSwapChainsToDelete.Enqueue(swapChain, mDevice->GetPendingCommandSerial());
|
2018-01-26 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 19:35:14 +00:00
|
|
|
void FencedDeleter::Tick(ExecutionSerial completedSerial) {
|
2018-01-09 12:37:02 +00:00
|
|
|
VkDevice vkDevice = mDevice->GetVkDevice();
|
2019-02-04 09:31:09 +00:00
|
|
|
VkInstance instance = mDevice->GetVkInstance();
|
2018-01-09 12:37:02 +00:00
|
|
|
|
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);
|
2018-01-09 16:37:24 +00:00
|
|
|
|
|
|
|
for (VkFramebuffer framebuffer : mFramebuffersToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroyFramebuffer(vkDevice, framebuffer, nullptr);
|
|
|
|
}
|
|
|
|
mFramebuffersToDelete.ClearUpTo(completedSerial);
|
|
|
|
|
|
|
|
for (VkImageView view : mImageViewsToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroyImageView(vkDevice, view, nullptr);
|
|
|
|
}
|
|
|
|
mImageViewsToDelete.ClearUpTo(completedSerial);
|
|
|
|
|
2018-01-09 18:50:07 +00:00
|
|
|
for (VkShaderModule module : mShaderModulesToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroyShaderModule(vkDevice, module, nullptr);
|
|
|
|
}
|
|
|
|
mShaderModulesToDelete.ClearUpTo(completedSerial);
|
|
|
|
|
|
|
|
for (VkPipeline pipeline : mPipelinesToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroyPipeline(vkDevice, pipeline, nullptr);
|
|
|
|
}
|
|
|
|
mPipelinesToDelete.ClearUpTo(completedSerial);
|
2018-01-26 21:47:12 +00:00
|
|
|
|
|
|
|
// Vulkan swapchains must be destroyed before their corresponding VkSurface
|
|
|
|
for (VkSwapchainKHR swapChain : mSwapChainsToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroySwapchainKHR(vkDevice, swapChain, nullptr);
|
|
|
|
}
|
|
|
|
mSwapChainsToDelete.ClearUpTo(completedSerial);
|
|
|
|
for (VkSurfaceKHR surface : mSurfacesToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroySurfaceKHR(instance, surface, nullptr);
|
|
|
|
}
|
|
|
|
mSurfacesToDelete.ClearUpTo(completedSerial);
|
|
|
|
|
|
|
|
for (VkSemaphore semaphore : mSemaphoresToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroySemaphore(vkDevice, semaphore, nullptr);
|
|
|
|
}
|
|
|
|
mSemaphoresToDelete.ClearUpTo(completedSerial);
|
2018-02-02 21:49:51 +00:00
|
|
|
|
|
|
|
for (VkDescriptorPool pool : mDescriptorPoolsToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroyDescriptorPool(vkDevice, pool, nullptr);
|
|
|
|
}
|
|
|
|
mDescriptorPoolsToDelete.ClearUpTo(completedSerial);
|
2018-04-18 02:18:03 +00:00
|
|
|
|
2020-08-20 00:40:07 +00:00
|
|
|
for (VkQueryPool pool : mQueryPoolsToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroyQueryPool(vkDevice, pool, nullptr);
|
|
|
|
}
|
|
|
|
mQueryPoolsToDelete.ClearUpTo(completedSerial);
|
|
|
|
|
2018-04-18 02:18:03 +00:00
|
|
|
for (VkSampler sampler : mSamplersToDelete.IterateUpTo(completedSerial)) {
|
|
|
|
mDevice->fn.DestroySampler(vkDevice, sampler, nullptr);
|
|
|
|
}
|
|
|
|
mSamplersToDelete.ClearUpTo(completedSerial);
|
2017-12-04 21:17:37 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
}} // namespace dawn_native::vulkan
|