diff --git a/src/rendering/vulkan/renderer/vk_postprocess.cpp b/src/rendering/vulkan/renderer/vk_postprocess.cpp index 3f0cc6ea3..fc8a0a6f2 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.cpp +++ b/src/rendering/vulkan/renderer/vk_postprocess.cpp @@ -35,7 +35,7 @@ void VkPostprocess::SetActiveRenderTarget() imageTransition.addImage(&buffers->PipelineImage[mCurrentPipelineImage], VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, false); imageTransition.execute(fb->GetDrawCommands()); - fb->GetRenderState()->SetRenderTarget(buffers->PipelineImage[mCurrentPipelineImage].View.get(), nullptr, buffers->GetWidth(), buffers->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, VK_SAMPLE_COUNT_1_BIT); + fb->GetRenderState()->SetRenderTarget(&buffers->PipelineImage[mCurrentPipelineImage], nullptr, buffers->GetWidth(), buffers->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, VK_SAMPLE_COUNT_1_BIT); } void VkPostprocess::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) @@ -409,6 +409,7 @@ VkPPTexture::~VkPPTexture() if (TexImage.Image) fb->FrameDeleteList.Images.push_back(std::move(TexImage.Image)); if (TexImage.View) fb->FrameDeleteList.ImageViews.push_back(std::move(TexImage.View)); if (TexImage.DepthOnlyView) fb->FrameDeleteList.ImageViews.push_back(std::move(TexImage.DepthOnlyView)); + if (TexImage.PPFramebuffer) fb->FrameDeleteList.Framebuffers.push_back(std::move(TexImage.PPFramebuffer)); if (Staging) fb->FrameDeleteList.Buffers.push_back(std::move(Staging)); } } @@ -596,6 +597,7 @@ VulkanFramebuffer *VkPPRenderState::GetOutput(VkPPRenderPassSetup *passSetup, co VkTextureImage *tex = GetTexture(output.Type, output.Texture); VkImageView view; + std::unique_ptr *framebufferptr = nullptr; int w, h; if (tex) { @@ -608,15 +610,17 @@ VulkanFramebuffer *VkPPRenderState::GetOutput(VkPPRenderPassSetup *passSetup, co view = tex->View->view; w = tex->Image->width; h = tex->Image->height; + framebufferptr = &tex->PPFramebuffer; } else { view = fb->swapChain->swapChainImageViews[fb->presentImageIndex]; + framebufferptr = &fb->swapChain->framebuffers[fb->presentImageIndex]; w = fb->swapChain->actualExtent.width; h = fb->swapChain->actualExtent.height; } - auto &framebuffer = passSetup->Framebuffers[view]; + auto &framebuffer = *framebufferptr; if (!framebuffer) { FramebufferBuilder builder; diff --git a/src/rendering/vulkan/renderer/vk_postprocess.h b/src/rendering/vulkan/renderer/vk_postprocess.h index 07f524f86..53390e00e 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.h +++ b/src/rendering/vulkan/renderer/vk_postprocess.h @@ -104,7 +104,6 @@ public: std::unique_ptr PipelineLayout; std::unique_ptr RenderPass; std::unique_ptr Pipeline; - std::map> Framebuffers; private: void CreateDescriptorLayout(const VkPPRenderPassKey &key); diff --git a/src/rendering/vulkan/renderer/vk_renderpass.h b/src/rendering/vulkan/renderer/vk_renderpass.h index fc746ed61..877a752d1 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.h +++ b/src/rendering/vulkan/renderer/vk_renderpass.h @@ -59,7 +59,6 @@ public: VkRenderPassKey PassKey; std::unique_ptr RenderPasses[8]; std::map> Pipelines; - std::map> Framebuffer; private: std::unique_ptr CreateRenderPass(int clearTargets); diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 1e02d0dfd..c2fc30875 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -528,11 +528,11 @@ void VkRenderState::EnableDrawBuffers(int count) } } -void VkRenderState::SetRenderTarget(VulkanImageView *view, VulkanImageView *depthStencilView, int width, int height, VkFormat format, VkSampleCountFlagBits samples) +void VkRenderState::SetRenderTarget(VkTextureImage *image, VulkanImageView *depthStencilView, int width, int height, VkFormat format, VkSampleCountFlagBits samples) { EndRenderPass(); - mRenderTarget.View = view; + mRenderTarget.Image = image; mRenderTarget.DepthStencil = depthStencilView; mRenderTarget.Width = width; mRenderTarget.Height = height; @@ -552,14 +552,14 @@ void VkRenderState::BeginRenderPass(VulkanCommandBuffer *cmdbuffer) mPassSetup = fb->GetRenderPassManager()->GetRenderPass(key); - auto &framebuffer = mPassSetup->Framebuffer[mRenderTarget.View->view]; + auto &framebuffer = mRenderTarget.Image->RSFramebuffers[key]; if (!framebuffer) { auto buffers = fb->GetBuffers(); FramebufferBuilder builder; builder.setRenderPass(mPassSetup->GetRenderPass(0)); builder.setSize(mRenderTarget.Width, mRenderTarget.Height); - builder.addAttachment(mRenderTarget.View); + builder.addAttachment(mRenderTarget.Image->View.get()); if (key.DrawBuffers > 1) builder.addAttachment(buffers->SceneFog.View.get()); if (key.DrawBuffers > 2) diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/rendering/vulkan/renderer/vk_renderstate.h index 522410a2e..ef58804b7 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/rendering/vulkan/renderer/vk_renderstate.h @@ -12,6 +12,7 @@ #include "hwrenderer/textures/hw_material.h" class VkRenderPassSetup; +class VkTextureImage; class VkRenderState : public FRenderState { @@ -43,7 +44,7 @@ public: void EnableDrawBuffers(int count) override; void BeginFrame(); - void SetRenderTarget(VulkanImageView *view, VulkanImageView *depthStencilView, int width, int height, VkFormat Format, VkSampleCountFlagBits samples); + void SetRenderTarget(VkTextureImage *image, VulkanImageView *depthStencilView, int width, int height, VkFormat Format, VkSampleCountFlagBits samples); void Bind(int bindingpoint, uint32_t offset); void EndRenderPass(); void EndFrame(); @@ -112,7 +113,7 @@ protected: struct RenderTarget { - VulkanImageView *View = nullptr; + VkTextureImage *Image = nullptr; VulkanImageView *DepthStencil = nullptr; int Width = 0; int Height = 0; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index b0b3b2fba..df283c60e 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -206,6 +206,7 @@ void VulkanFrameBuffer::DeleteFrameObjects() { FrameDeleteList.Images.clear(); FrameDeleteList.ImageViews.clear(); + FrameDeleteList.Framebuffers.clear(); FrameDeleteList.Buffers.clear(); FrameDeleteList.Descriptors.clear(); FrameDeleteList.DescriptorPools.clear(); @@ -451,7 +452,7 @@ sector_t *VulkanFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * if (mainview) // Bind the scene frame buffer and turn on draw buffers used by ssao { - mRenderState->SetRenderTarget(GetBuffers()->SceneColor.View.get(), GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); + mRenderState->SetRenderTarget(&GetBuffers()->SceneColor, GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); bool useSSAO = (gl_ssao != 0); GetRenderState()->SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); GetRenderState()->EnableDrawBuffers(GetRenderState()->GetPassDrawBufferCount()); @@ -521,7 +522,7 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint barrier0.addImage(image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, true); barrier0.execute(GetDrawCommands()); - mRenderState->SetRenderTarget(image->View.get(), depthStencil->View.get(), image->Image->width, image->Image->height, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT); + mRenderState->SetRenderTarget(image, depthStencil->View.get(), image->Image->width, image->Image->height, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT); IntRect bounds; bounds.left = bounds.top = 0; @@ -537,7 +538,7 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint barrier1.addImage(image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, false); barrier1.execute(GetDrawCommands()); - mRenderState->SetRenderTarget(GetBuffers()->SceneColor.View.get(), GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); + mRenderState->SetRenderTarget(&GetBuffers()->SceneColor, GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); tex->SetUpdated(true); } diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index af3c7047a..9010b8d6b 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -57,6 +57,7 @@ public: public: std::vector> Images; std::vector> ImageViews; + std::vector> Framebuffers; std::vector> Buffers; std::vector> Descriptors; std::vector> DescriptorPools; diff --git a/src/rendering/vulkan/system/vk_swapchain.cpp b/src/rendering/vulkan/system/vk_swapchain.cpp index 4842d9e22..f5ca6599b 100644 --- a/src/rendering/vulkan/system/vk_swapchain.cpp +++ b/src/rendering/vulkan/system/vk_swapchain.cpp @@ -207,6 +207,7 @@ bool VulkanSwapChain::CreateSwapChain(VkSwapchainKHR oldSwapChain) void VulkanSwapChain::CreateViews() { + framebuffers.resize(swapChainImages.size()); swapChainImageViews.reserve(swapChainImages.size()); for (size_t i = 0; i < swapChainImages.size(); i++) { @@ -335,6 +336,7 @@ void VulkanSwapChain::GetImages() void VulkanSwapChain::ReleaseViews() { + framebuffers.clear(); for (auto &view : swapChainImageViews) { vkDestroyImageView(device->device, view, nullptr); diff --git a/src/rendering/vulkan/system/vk_swapchain.h b/src/rendering/vulkan/system/vk_swapchain.h index a07bc0d90..5d4fc4807 100644 --- a/src/rendering/vulkan/system/vk_swapchain.h +++ b/src/rendering/vulkan/system/vk_swapchain.h @@ -4,6 +4,7 @@ class VulkanSemaphore; class VulkanFence; +class VulkanFramebuffer; class VulkanSwapChain { @@ -22,6 +23,7 @@ public: std::vector swapChainImages; std::vector swapChainImageViews; + std::vector> framebuffers; VkExtent2D actualExtent; diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index b8d498677..93a1cc92d 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -72,8 +72,10 @@ void VkHardwareTexture::Reset() auto &deleteList = fb->FrameDeleteList; if (mImage.Image) deleteList.Images.push_back(std::move(mImage.Image)); if (mImage.View) deleteList.ImageViews.push_back(std::move(mImage.View)); + for (auto &it : mImage.RSFramebuffers) deleteList.Framebuffers.push_back(std::move(it.second)); if (mDepthStencil.Image) deleteList.Images.push_back(std::move(mDepthStencil.Image)); if (mDepthStencil.View) deleteList.ImageViews.push_back(std::move(mDepthStencil.View)); + for (auto &it : mDepthStencil.RSFramebuffers) deleteList.Framebuffers.push_back(std::move(it.second)); mImage.reset(); mDepthStencil.reset(); } diff --git a/src/rendering/vulkan/textures/vk_imagetransition.h b/src/rendering/vulkan/textures/vk_imagetransition.h index c5b32dd50..c12918d04 100644 --- a/src/rendering/vulkan/textures/vk_imagetransition.h +++ b/src/rendering/vulkan/textures/vk_imagetransition.h @@ -3,6 +3,7 @@ #include "vulkan/system/vk_objects.h" #include "vulkan/system/vk_builders.h" +#include "vulkan/renderer/vk_renderpass.h" class VkTextureImage { @@ -23,6 +24,8 @@ public: std::unique_ptr DepthOnlyView; VkImageLayout Layout = VK_IMAGE_LAYOUT_UNDEFINED; VkImageAspectFlags AspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + std::unique_ptr PPFramebuffer; + std::map> RSFramebuffers; }; class VkImageTransition