mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-28 06:53:40 +00:00
- store the vulkan framebuffer with the image (this ensures the framebuffer object is destroyed along with the image)
This commit is contained in:
parent
ea8af08bcf
commit
a093f686a7
11 changed files with 27 additions and 13 deletions
|
@ -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<void()> &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<VulkanFramebuffer> *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;
|
||||
|
|
|
@ -104,7 +104,6 @@ public:
|
|||
std::unique_ptr<VulkanPipelineLayout> PipelineLayout;
|
||||
std::unique_ptr<VulkanRenderPass> RenderPass;
|
||||
std::unique_ptr<VulkanPipeline> Pipeline;
|
||||
std::map<VkImageView, std::unique_ptr<VulkanFramebuffer>> Framebuffers;
|
||||
|
||||
private:
|
||||
void CreateDescriptorLayout(const VkPPRenderPassKey &key);
|
||||
|
|
|
@ -59,7 +59,6 @@ public:
|
|||
VkRenderPassKey PassKey;
|
||||
std::unique_ptr<VulkanRenderPass> RenderPasses[8];
|
||||
std::map<VkPipelineKey, std::unique_ptr<VulkanPipeline>> Pipelines;
|
||||
std::map<VkImageView, std::unique_ptr<VulkanFramebuffer>> Framebuffer;
|
||||
|
||||
private:
|
||||
std::unique_ptr<VulkanRenderPass> CreateRenderPass(int clearTargets);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ public:
|
|||
public:
|
||||
std::vector<std::unique_ptr<VulkanImage>> Images;
|
||||
std::vector<std::unique_ptr<VulkanImageView>> ImageViews;
|
||||
std::vector<std::unique_ptr<VulkanFramebuffer>> Framebuffers;
|
||||
std::vector<std::unique_ptr<VulkanBuffer>> Buffers;
|
||||
std::vector<std::unique_ptr<VulkanDescriptorSet>> Descriptors;
|
||||
std::vector<std::unique_ptr<VulkanDescriptorPool>> DescriptorPools;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
class VulkanSemaphore;
|
||||
class VulkanFence;
|
||||
class VulkanFramebuffer;
|
||||
|
||||
class VulkanSwapChain
|
||||
{
|
||||
|
@ -22,6 +23,7 @@ public:
|
|||
|
||||
std::vector<VkImage> swapChainImages;
|
||||
std::vector<VkImageView> swapChainImageViews;
|
||||
std::vector<std::unique_ptr<VulkanFramebuffer>> framebuffers;
|
||||
|
||||
VkExtent2D actualExtent;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<VulkanImageView> DepthOnlyView;
|
||||
VkImageLayout Layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
VkImageAspectFlags AspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
std::unique_ptr<VulkanFramebuffer> PPFramebuffer;
|
||||
std::map<VkRenderPassKey, std::unique_ptr<VulkanFramebuffer>> RSFramebuffers;
|
||||
};
|
||||
|
||||
class VkImageTransition
|
||||
|
|
Loading…
Reference in a new issue