mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-12-01 00:21:35 +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.addImage(&buffers->PipelineImage[mCurrentPipelineImage], VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, false);
|
||||||
imageTransition.execute(fb->GetDrawCommands());
|
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)
|
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.Image) fb->FrameDeleteList.Images.push_back(std::move(TexImage.Image));
|
||||||
if (TexImage.View) fb->FrameDeleteList.ImageViews.push_back(std::move(TexImage.View));
|
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.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));
|
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);
|
VkTextureImage *tex = GetTexture(output.Type, output.Texture);
|
||||||
|
|
||||||
VkImageView view;
|
VkImageView view;
|
||||||
|
std::unique_ptr<VulkanFramebuffer> *framebufferptr = nullptr;
|
||||||
int w, h;
|
int w, h;
|
||||||
if (tex)
|
if (tex)
|
||||||
{
|
{
|
||||||
|
@ -608,15 +610,17 @@ VulkanFramebuffer *VkPPRenderState::GetOutput(VkPPRenderPassSetup *passSetup, co
|
||||||
view = tex->View->view;
|
view = tex->View->view;
|
||||||
w = tex->Image->width;
|
w = tex->Image->width;
|
||||||
h = tex->Image->height;
|
h = tex->Image->height;
|
||||||
|
framebufferptr = &tex->PPFramebuffer;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
view = fb->swapChain->swapChainImageViews[fb->presentImageIndex];
|
view = fb->swapChain->swapChainImageViews[fb->presentImageIndex];
|
||||||
|
framebufferptr = &fb->swapChain->framebuffers[fb->presentImageIndex];
|
||||||
w = fb->swapChain->actualExtent.width;
|
w = fb->swapChain->actualExtent.width;
|
||||||
h = fb->swapChain->actualExtent.height;
|
h = fb->swapChain->actualExtent.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &framebuffer = passSetup->Framebuffers[view];
|
auto &framebuffer = *framebufferptr;
|
||||||
if (!framebuffer)
|
if (!framebuffer)
|
||||||
{
|
{
|
||||||
FramebufferBuilder builder;
|
FramebufferBuilder builder;
|
||||||
|
|
|
@ -104,7 +104,6 @@ public:
|
||||||
std::unique_ptr<VulkanPipelineLayout> PipelineLayout;
|
std::unique_ptr<VulkanPipelineLayout> PipelineLayout;
|
||||||
std::unique_ptr<VulkanRenderPass> RenderPass;
|
std::unique_ptr<VulkanRenderPass> RenderPass;
|
||||||
std::unique_ptr<VulkanPipeline> Pipeline;
|
std::unique_ptr<VulkanPipeline> Pipeline;
|
||||||
std::map<VkImageView, std::unique_ptr<VulkanFramebuffer>> Framebuffers;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CreateDescriptorLayout(const VkPPRenderPassKey &key);
|
void CreateDescriptorLayout(const VkPPRenderPassKey &key);
|
||||||
|
|
|
@ -59,7 +59,6 @@ public:
|
||||||
VkRenderPassKey PassKey;
|
VkRenderPassKey PassKey;
|
||||||
std::unique_ptr<VulkanRenderPass> RenderPasses[8];
|
std::unique_ptr<VulkanRenderPass> RenderPasses[8];
|
||||||
std::map<VkPipelineKey, std::unique_ptr<VulkanPipeline>> Pipelines;
|
std::map<VkPipelineKey, std::unique_ptr<VulkanPipeline>> Pipelines;
|
||||||
std::map<VkImageView, std::unique_ptr<VulkanFramebuffer>> Framebuffer;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<VulkanRenderPass> CreateRenderPass(int clearTargets);
|
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();
|
EndRenderPass();
|
||||||
|
|
||||||
mRenderTarget.View = view;
|
mRenderTarget.Image = image;
|
||||||
mRenderTarget.DepthStencil = depthStencilView;
|
mRenderTarget.DepthStencil = depthStencilView;
|
||||||
mRenderTarget.Width = width;
|
mRenderTarget.Width = width;
|
||||||
mRenderTarget.Height = height;
|
mRenderTarget.Height = height;
|
||||||
|
@ -552,14 +552,14 @@ void VkRenderState::BeginRenderPass(VulkanCommandBuffer *cmdbuffer)
|
||||||
|
|
||||||
mPassSetup = fb->GetRenderPassManager()->GetRenderPass(key);
|
mPassSetup = fb->GetRenderPassManager()->GetRenderPass(key);
|
||||||
|
|
||||||
auto &framebuffer = mPassSetup->Framebuffer[mRenderTarget.View->view];
|
auto &framebuffer = mRenderTarget.Image->RSFramebuffers[key];
|
||||||
if (!framebuffer)
|
if (!framebuffer)
|
||||||
{
|
{
|
||||||
auto buffers = fb->GetBuffers();
|
auto buffers = fb->GetBuffers();
|
||||||
FramebufferBuilder builder;
|
FramebufferBuilder builder;
|
||||||
builder.setRenderPass(mPassSetup->GetRenderPass(0));
|
builder.setRenderPass(mPassSetup->GetRenderPass(0));
|
||||||
builder.setSize(mRenderTarget.Width, mRenderTarget.Height);
|
builder.setSize(mRenderTarget.Width, mRenderTarget.Height);
|
||||||
builder.addAttachment(mRenderTarget.View);
|
builder.addAttachment(mRenderTarget.Image->View.get());
|
||||||
if (key.DrawBuffers > 1)
|
if (key.DrawBuffers > 1)
|
||||||
builder.addAttachment(buffers->SceneFog.View.get());
|
builder.addAttachment(buffers->SceneFog.View.get());
|
||||||
if (key.DrawBuffers > 2)
|
if (key.DrawBuffers > 2)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "hwrenderer/textures/hw_material.h"
|
#include "hwrenderer/textures/hw_material.h"
|
||||||
|
|
||||||
class VkRenderPassSetup;
|
class VkRenderPassSetup;
|
||||||
|
class VkTextureImage;
|
||||||
|
|
||||||
class VkRenderState : public FRenderState
|
class VkRenderState : public FRenderState
|
||||||
{
|
{
|
||||||
|
@ -43,7 +44,7 @@ public:
|
||||||
void EnableDrawBuffers(int count) override;
|
void EnableDrawBuffers(int count) override;
|
||||||
|
|
||||||
void BeginFrame();
|
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 Bind(int bindingpoint, uint32_t offset);
|
||||||
void EndRenderPass();
|
void EndRenderPass();
|
||||||
void EndFrame();
|
void EndFrame();
|
||||||
|
@ -112,7 +113,7 @@ protected:
|
||||||
|
|
||||||
struct RenderTarget
|
struct RenderTarget
|
||||||
{
|
{
|
||||||
VulkanImageView *View = nullptr;
|
VkTextureImage *Image = nullptr;
|
||||||
VulkanImageView *DepthStencil = nullptr;
|
VulkanImageView *DepthStencil = nullptr;
|
||||||
int Width = 0;
|
int Width = 0;
|
||||||
int Height = 0;
|
int Height = 0;
|
||||||
|
|
|
@ -206,6 +206,7 @@ void VulkanFrameBuffer::DeleteFrameObjects()
|
||||||
{
|
{
|
||||||
FrameDeleteList.Images.clear();
|
FrameDeleteList.Images.clear();
|
||||||
FrameDeleteList.ImageViews.clear();
|
FrameDeleteList.ImageViews.clear();
|
||||||
|
FrameDeleteList.Framebuffers.clear();
|
||||||
FrameDeleteList.Buffers.clear();
|
FrameDeleteList.Buffers.clear();
|
||||||
FrameDeleteList.Descriptors.clear();
|
FrameDeleteList.Descriptors.clear();
|
||||||
FrameDeleteList.DescriptorPools.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
|
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);
|
bool useSSAO = (gl_ssao != 0);
|
||||||
GetRenderState()->SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS);
|
GetRenderState()->SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS);
|
||||||
GetRenderState()->EnableDrawBuffers(GetRenderState()->GetPassDrawBufferCount());
|
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.addImage(image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, true);
|
||||||
barrier0.execute(GetDrawCommands());
|
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;
|
IntRect bounds;
|
||||||
bounds.left = bounds.top = 0;
|
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.addImage(image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, false);
|
||||||
barrier1.execute(GetDrawCommands());
|
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);
|
tex->SetUpdated(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ public:
|
||||||
public:
|
public:
|
||||||
std::vector<std::unique_ptr<VulkanImage>> Images;
|
std::vector<std::unique_ptr<VulkanImage>> Images;
|
||||||
std::vector<std::unique_ptr<VulkanImageView>> ImageViews;
|
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<VulkanBuffer>> Buffers;
|
||||||
std::vector<std::unique_ptr<VulkanDescriptorSet>> Descriptors;
|
std::vector<std::unique_ptr<VulkanDescriptorSet>> Descriptors;
|
||||||
std::vector<std::unique_ptr<VulkanDescriptorPool>> DescriptorPools;
|
std::vector<std::unique_ptr<VulkanDescriptorPool>> DescriptorPools;
|
||||||
|
|
|
@ -207,6 +207,7 @@ bool VulkanSwapChain::CreateSwapChain(VkSwapchainKHR oldSwapChain)
|
||||||
|
|
||||||
void VulkanSwapChain::CreateViews()
|
void VulkanSwapChain::CreateViews()
|
||||||
{
|
{
|
||||||
|
framebuffers.resize(swapChainImages.size());
|
||||||
swapChainImageViews.reserve(swapChainImages.size());
|
swapChainImageViews.reserve(swapChainImages.size());
|
||||||
for (size_t i = 0; i < swapChainImages.size(); i++)
|
for (size_t i = 0; i < swapChainImages.size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -335,6 +336,7 @@ void VulkanSwapChain::GetImages()
|
||||||
|
|
||||||
void VulkanSwapChain::ReleaseViews()
|
void VulkanSwapChain::ReleaseViews()
|
||||||
{
|
{
|
||||||
|
framebuffers.clear();
|
||||||
for (auto &view : swapChainImageViews)
|
for (auto &view : swapChainImageViews)
|
||||||
{
|
{
|
||||||
vkDestroyImageView(device->device, view, nullptr);
|
vkDestroyImageView(device->device, view, nullptr);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
class VulkanSemaphore;
|
class VulkanSemaphore;
|
||||||
class VulkanFence;
|
class VulkanFence;
|
||||||
|
class VulkanFramebuffer;
|
||||||
|
|
||||||
class VulkanSwapChain
|
class VulkanSwapChain
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,7 @@ public:
|
||||||
|
|
||||||
std::vector<VkImage> swapChainImages;
|
std::vector<VkImage> swapChainImages;
|
||||||
std::vector<VkImageView> swapChainImageViews;
|
std::vector<VkImageView> swapChainImageViews;
|
||||||
|
std::vector<std::unique_ptr<VulkanFramebuffer>> framebuffers;
|
||||||
|
|
||||||
VkExtent2D actualExtent;
|
VkExtent2D actualExtent;
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,10 @@ void VkHardwareTexture::Reset()
|
||||||
auto &deleteList = fb->FrameDeleteList;
|
auto &deleteList = fb->FrameDeleteList;
|
||||||
if (mImage.Image) deleteList.Images.push_back(std::move(mImage.Image));
|
if (mImage.Image) deleteList.Images.push_back(std::move(mImage.Image));
|
||||||
if (mImage.View) deleteList.ImageViews.push_back(std::move(mImage.View));
|
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.Image) deleteList.Images.push_back(std::move(mDepthStencil.Image));
|
||||||
if (mDepthStencil.View) deleteList.ImageViews.push_back(std::move(mDepthStencil.View));
|
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();
|
mImage.reset();
|
||||||
mDepthStencil.reset();
|
mDepthStencil.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "vulkan/system/vk_objects.h"
|
#include "vulkan/system/vk_objects.h"
|
||||||
#include "vulkan/system/vk_builders.h"
|
#include "vulkan/system/vk_builders.h"
|
||||||
|
#include "vulkan/renderer/vk_renderpass.h"
|
||||||
|
|
||||||
class VkTextureImage
|
class VkTextureImage
|
||||||
{
|
{
|
||||||
|
@ -23,6 +24,8 @@ public:
|
||||||
std::unique_ptr<VulkanImageView> DepthOnlyView;
|
std::unique_ptr<VulkanImageView> DepthOnlyView;
|
||||||
VkImageLayout Layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
VkImageLayout Layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
VkImageAspectFlags AspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
VkImageAspectFlags AspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
std::unique_ptr<VulkanFramebuffer> PPFramebuffer;
|
||||||
|
std::map<VkRenderPassKey, std::unique_ptr<VulkanFramebuffer>> RSFramebuffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
class VkImageTransition
|
class VkImageTransition
|
||||||
|
|
Loading…
Reference in a new issue