Properly clean up post processing resources
This commit is contained in:
parent
a084d8fe45
commit
34795d2376
4 changed files with 23 additions and 0 deletions
|
@ -8,6 +8,7 @@ struct RenderTarget;
|
||||||
class PostPass {
|
class PostPass {
|
||||||
public:
|
public:
|
||||||
PostPass(Renderer& renderer);
|
PostPass(Renderer& renderer);
|
||||||
|
~PostPass();
|
||||||
|
|
||||||
void render(VkCommandBuffer commandBuffer, RenderTarget* target);
|
void render(VkCommandBuffer commandBuffer, RenderTarget* target);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,15 @@ PostPass::PostPass(Renderer& renderer) : renderer_(renderer) {
|
||||||
createSampler();
|
createSampler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PostPass::~PostPass() {
|
||||||
|
vkDestroySampler(renderer_.getDevice(), offscreenSampler_, nullptr);
|
||||||
|
|
||||||
|
vkDestroyPipelineLayout(renderer_.getDevice(), pipelineLayout_, nullptr);
|
||||||
|
vkDestroyPipeline(renderer_.getDevice(), pipeline_, nullptr);
|
||||||
|
|
||||||
|
vkDestroyDescriptorSetLayout(renderer_.getDevice(), setLayout_, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
void PostPass::render(VkCommandBuffer commandBuffer, RenderTarget* target) {
|
void PostPass::render(VkCommandBuffer commandBuffer, RenderTarget* target) {
|
||||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
||||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout_, 0, 1, &target->postSets[target->currentImage], 0, nullptr);
|
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout_, 0, 1, &target->postSets[target->currentImage], 0, nullptr);
|
||||||
|
|
|
@ -28,8 +28,11 @@ Renderer::Renderer() {
|
||||||
Renderer::~Renderer() {
|
Renderer::~Renderer() {
|
||||||
vkDeviceWaitIdle(device_);
|
vkDeviceWaitIdle(device_);
|
||||||
|
|
||||||
|
delete postPass_;
|
||||||
delete worldPass_;
|
delete worldPass_;
|
||||||
|
|
||||||
|
vkDestroyDescriptorPool(device_, descriptorPool_, nullptr);
|
||||||
|
|
||||||
vkDestroyRenderPass(device_, presentationRenderPass_, nullptr);
|
vkDestroyRenderPass(device_, presentationRenderPass_, nullptr);
|
||||||
|
|
||||||
vkDestroyCommandPool(device_, commandPool_, nullptr);
|
vkDestroyCommandPool(device_, commandPool_, nullptr);
|
||||||
|
@ -312,7 +315,14 @@ void Renderer::destroyRenderTarget(RenderTarget* target) {
|
||||||
|
|
||||||
delete[] target->commandBuffers;
|
delete[] target->commandBuffers;
|
||||||
|
|
||||||
|
vkFreeDescriptorSets(device_, descriptorPool_, target->numImages, target->postSets);
|
||||||
|
|
||||||
for(uint32_t i = 0; i < target->numImages; i++) {
|
for(uint32_t i = 0; i < target->numImages; i++) {
|
||||||
|
vkDestroyFramebuffer(device_, target->offscreenFramebuffers[i], nullptr);
|
||||||
|
vkDestroyImageView(device_, target->offscreenImageViews[i], nullptr);
|
||||||
|
vkFreeMemory(device_, target->offscreenMemory[i], nullptr);
|
||||||
|
vkDestroyImage(device_, target->offscreenImages[i], nullptr);
|
||||||
|
|
||||||
vkDestroyFramebuffer(device_, target->swapchainFramebuffers[i], nullptr);
|
vkDestroyFramebuffer(device_, target->swapchainFramebuffers[i], nullptr);
|
||||||
vkDestroyImageView(device_, target->swapchainImageViews[i], nullptr);
|
vkDestroyImageView(device_, target->swapchainImageViews[i], nullptr);
|
||||||
}
|
}
|
||||||
|
@ -595,6 +605,7 @@ void Renderer::createDescriptorPool() {
|
||||||
|
|
||||||
VkDescriptorPoolCreateInfo poolInfo = {};
|
VkDescriptorPoolCreateInfo poolInfo = {};
|
||||||
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
|
poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||||
poolInfo.poolSizeCount = 1;
|
poolInfo.poolSizeCount = 1;
|
||||||
poolInfo.pPoolSizes = &poolSize;
|
poolInfo.pPoolSizes = &poolSize;
|
||||||
poolInfo.maxSets = 15;
|
poolInfo.maxSets = 15;
|
||||||
|
|
|
@ -13,6 +13,8 @@ WorldPass::WorldPass(Renderer& renderer) : renderer_(renderer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldPass::~WorldPass() {
|
WorldPass::~WorldPass() {
|
||||||
|
vkDestroyRenderPass(renderer_.getDevice(), renderPass_, nullptr);
|
||||||
|
|
||||||
vkDestroyPipeline(renderer_.getDevice(), pipeline_, nullptr);
|
vkDestroyPipeline(renderer_.getDevice(), pipeline_, nullptr);
|
||||||
vkDestroyPipelineLayout(renderer_.getDevice(), pipelineLayout_, nullptr);
|
vkDestroyPipelineLayout(renderer_.getDevice(), pipelineLayout_, nullptr);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue