- move camtex depthstencil to VkHardwareTexture

This commit is contained in:
Magnus Norddahl 2019-05-05 13:36:03 +02:00
parent 3d63f63fb2
commit e21ffc131e
8 changed files with 49 additions and 40 deletions

View file

@ -34,7 +34,7 @@ void VkPostprocess::SetActiveRenderTarget()
imageTransition.addImage(buffers->PipelineImage[mCurrentPipelineImage].get(), &buffers->PipelineLayout[mCurrentPipelineImage], VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, false); imageTransition.addImage(buffers->PipelineImage[mCurrentPipelineImage].get(), &buffers->PipelineLayout[mCurrentPipelineImage], VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, false);
imageTransition.execute(fb->GetDrawCommands()); imageTransition.execute(fb->GetDrawCommands());
fb->GetRenderState()->SetRenderTarget(buffers->PipelineView[mCurrentPipelineImage].get(), buffers->GetWidth(), buffers->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, VK_SAMPLE_COUNT_1_BIT); fb->GetRenderState()->SetRenderTarget(buffers->PipelineView[mCurrentPipelineImage].get(), 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)

View file

@ -55,7 +55,6 @@ void VkRenderBuffers::BeginFrame(int width, int height, int sceneWidth, int scen
if (width != mWidth || height != mHeight || mSamples != samples) if (width != mWidth || height != mHeight || mSamples != samples)
CreateScene(width, height, samples); CreateScene(width, height, samples);
CreateCamTexDepthStencil();
CreateShadowmap(); CreateShadowmap();
mWidth = width; mWidth = width;
@ -143,31 +142,6 @@ void VkRenderBuffers::CreateSceneColor(int width, int height, VkSampleCountFlagB
SceneColorView->SetDebugName("VkRenderBuffers.SceneColorView"); SceneColorView->SetDebugName("VkRenderBuffers.SceneColorView");
} }
void VkRenderBuffers::CreateCamTexDepthStencil()
{
if (CamtexDepthStencil)
return;
auto fb = GetVulkanFrameBuffer();
ImageBuilder builder;
builder.setSize(1024, 1024);
builder.setSamples(VK_SAMPLE_COUNT_1_BIT);
builder.setFormat(SceneDepthStencilFormat);
builder.setUsage(VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
CamtexDepthStencil = builder.create(fb->device);
CamtexDepthStencil->SetDebugName("VkRenderBuffers.CamtexDepthStencil");
ImageViewBuilder viewbuilder;
viewbuilder.setImage(CamtexDepthStencil.get(), SceneDepthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
CamtexDepthStencilView = viewbuilder.create(fb->device);
CamtexDepthStencilView->SetDebugName("VkRenderBuffers.CamtexDepthStencilView");
PipelineBarrier barrier;
barrier.addImage(CamtexDepthStencil.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
barrier.execute(fb->GetDrawCommands(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
}
void VkRenderBuffers::CreateSceneDepthStencil(int width, int height, VkSampleCountFlagBits samples) void VkRenderBuffers::CreateSceneDepthStencil(int width, int height, VkSampleCountFlagBits samples)
{ {
auto fb = GetVulkanFrameBuffer(); auto fb = GetVulkanFrameBuffer();

View file

@ -32,9 +32,6 @@ public:
VkImageLayout SceneNormalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; VkImageLayout SceneNormalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkImageLayout SceneFogLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; VkImageLayout SceneFogLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
std::unique_ptr<VulkanImage> CamtexDepthStencil;
std::unique_ptr<VulkanImageView> CamtexDepthStencilView;
static const int NumPipelineImages = 2; static const int NumPipelineImages = 2;
std::unique_ptr<VulkanImage> PipelineImage[NumPipelineImages]; std::unique_ptr<VulkanImage> PipelineImage[NumPipelineImages];
std::unique_ptr<VulkanImageView> PipelineView[NumPipelineImages]; std::unique_ptr<VulkanImageView> PipelineView[NumPipelineImages];
@ -53,7 +50,6 @@ private:
void CreateSceneFog(int width, int height, VkSampleCountFlagBits samples); void CreateSceneFog(int width, int height, VkSampleCountFlagBits samples);
void CreateSceneNormal(int width, int height, VkSampleCountFlagBits samples); void CreateSceneNormal(int width, int height, VkSampleCountFlagBits samples);
void CreateShadowmap(); void CreateShadowmap();
void CreateCamTexDepthStencil();
VkSampleCountFlagBits GetBestSampleCount(); VkSampleCountFlagBits GetBestSampleCount();
int mWidth = 0; int mWidth = 0;

View file

@ -536,11 +536,12 @@ void VkRenderState::EnableDrawBuffers(int count)
} }
} }
void VkRenderState::SetRenderTarget(VulkanImageView *view, int width, int height, VkFormat format, VkSampleCountFlagBits samples) void VkRenderState::SetRenderTarget(VulkanImageView *view, VulkanImageView *depthStencilView, int width, int height, VkFormat format, VkSampleCountFlagBits samples)
{ {
EndRenderPass(); EndRenderPass();
mRenderTarget.View = view; mRenderTarget.View = view;
mRenderTarget.DepthStencil = depthStencilView;
mRenderTarget.Width = width; mRenderTarget.Width = width;
mRenderTarget.Height = height; mRenderTarget.Height = height;
mRenderTarget.Format = format; mRenderTarget.Format = format;
@ -566,7 +567,7 @@ void VkRenderState::BeginRenderPass(const VkRenderPassKey &key, VulkanCommandBuf
if (key.DrawBuffers > 2) if (key.DrawBuffers > 2)
builder.addAttachment(buffers->SceneNormalView.get()); builder.addAttachment(buffers->SceneNormalView.get());
if (key.UsesDepthStencil()) if (key.UsesDepthStencil())
builder.addAttachment(mRenderTarget.Format == VK_FORMAT_R8G8B8A8_UNORM ? buffers->CamtexDepthStencilView.get() : buffers->SceneDepthStencilView.get()); builder.addAttachment(mRenderTarget.DepthStencil);
framebuffer = builder.create(GetVulkanFrameBuffer()->device); framebuffer = builder.create(GetVulkanFrameBuffer()->device);
framebuffer->SetDebugName("VkRenderPassSetup.Framebuffer"); framebuffer->SetDebugName("VkRenderPassSetup.Framebuffer");
} }

View file

@ -43,7 +43,7 @@ public:
void EnableDrawBuffers(int count) override; void EnableDrawBuffers(int count) override;
void BeginFrame(); void BeginFrame();
void SetRenderTarget(VulkanImageView *view, int width, int height, VkFormat Format, VkSampleCountFlagBits samples); void SetRenderTarget(VulkanImageView *view, 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,6 +112,7 @@ protected:
struct RenderTarget struct RenderTarget
{ {
VulkanImageView *View = nullptr; VulkanImageView *View = nullptr;
VulkanImageView *DepthStencil = nullptr;
int Width = 0; int Width = 0;
int Height = 0; int Height = 0;
VkFormat Format = VK_FORMAT_R16G16B16A16_SFLOAT; VkFormat Format = VK_FORMAT_R16G16B16A16_SFLOAT;

View file

@ -442,7 +442,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()->SceneColorView.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); mRenderState->SetRenderTarget(GetBuffers()->SceneColorView.get(), GetBuffers()->SceneDepthStencilView.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());
@ -505,15 +505,15 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint
int height = mat->TextureHeight(); int height = mat->TextureHeight();
VulkanImage *image = BaseLayer->GetImage(tex, 0, 0); VulkanImage *image = BaseLayer->GetImage(tex, 0, 0);
VulkanImageView *view = BaseLayer->GetImageView(tex, 0, 0); VulkanImageView *view = BaseLayer->GetImageView(tex, 0, 0);
VulkanImageView *depthStencilView = BaseLayer->GetDepthStencilView(tex);
mRenderState->EndRenderPass(); mRenderState->EndRenderPass();
auto cmdbuffer = GetDrawCommands();
PipelineBarrier barrier0; PipelineBarrier barrier0;
barrier0.addImage(image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); barrier0.addImage(image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
barrier0.execute(cmdbuffer, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); barrier0.execute(GetDrawCommands(), VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
mRenderState->SetRenderTarget(view, image->width, image->height, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT); mRenderState->SetRenderTarget(view, depthStencilView, image->width, 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;
@ -527,9 +527,9 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint
PipelineBarrier barrier1; PipelineBarrier barrier1;
barrier1.addImage(image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT); barrier1.addImage(image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT);
barrier1.execute(cmdbuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); barrier1.execute(GetDrawCommands(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
mRenderState->SetRenderTarget(GetBuffers()->SceneColorView.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); mRenderState->SetRenderTarget(GetBuffers()->SceneColorView.get(), GetBuffers()->SceneDepthStencilView.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples());
tex->SetUpdated(true); tex->SetUpdated(true);
} }

View file

@ -36,6 +36,7 @@
#include "vulkan/textures/vk_samplers.h" #include "vulkan/textures/vk_samplers.h"
#include "vulkan/renderer/vk_renderpass.h" #include "vulkan/renderer/vk_renderpass.h"
#include "vulkan/renderer/vk_postprocess.h" #include "vulkan/renderer/vk_postprocess.h"
#include "vulkan/renderer/vk_renderbuffers.h"
#include "vk_hwtexture.h" #include "vk_hwtexture.h"
VkHardwareTexture *VkHardwareTexture::First = nullptr; VkHardwareTexture *VkHardwareTexture::First = nullptr;
@ -71,6 +72,8 @@ void VkHardwareTexture::Reset()
auto &deleteList = fb->FrameDeleteList; auto &deleteList = fb->FrameDeleteList;
if (mImage) deleteList.Images.push_back(std::move(mImage)); if (mImage) deleteList.Images.push_back(std::move(mImage));
if (mImageView) deleteList.ImageViews.push_back(std::move(mImageView)); if (mImageView) deleteList.ImageViews.push_back(std::move(mImageView));
if (mDepthStencil) deleteList.Images.push_back(std::move(mDepthStencil));
if (mDepthStencilView) deleteList.ImageViews.push_back(std::move(mDepthStencilView));
} }
} }
@ -174,6 +177,36 @@ VulkanImageView *VkHardwareTexture::GetImageView(FTexture *tex, int translation,
return mImageView.get(); return mImageView.get();
} }
VulkanImageView *VkHardwareTexture::GetDepthStencilView(FTexture *tex)
{
if (!mDepthStencilView)
{
auto fb = GetVulkanFrameBuffer();
VkFormat format = fb->GetBuffers()->SceneDepthStencilFormat;
int w = tex->GetWidth();
int h = tex->GetHeight();
ImageBuilder builder;
builder.setSize(w, h);
builder.setSamples(VK_SAMPLE_COUNT_1_BIT);
builder.setFormat(format);
builder.setUsage(VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
mDepthStencil = builder.create(fb->device);
mDepthStencil->SetDebugName("VkHardwareTexture.DepthStencil");
ImageViewBuilder viewbuilder;
viewbuilder.setImage(mDepthStencil.get(), format, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
mDepthStencilView = viewbuilder.create(fb->device);
mDepthStencilView->SetDebugName("VkHardwareTexture.DepthStencilView");
PipelineBarrier barrier;
barrier.addImage(mDepthStencil.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
barrier.execute(fb->GetTransferCommands(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
}
return mDepthStencilView.get();
}
void VkHardwareTexture::CreateImage(FTexture *tex, int translation, int flags) void VkHardwareTexture::CreateImage(FTexture *tex, int translation, int flags)
{ {
if (!tex->isHardwareCanvas()) if (!tex->isHardwareCanvas())

View file

@ -40,6 +40,7 @@ public:
VulkanImage *GetImage(FTexture *tex, int translation, int flags); VulkanImage *GetImage(FTexture *tex, int translation, int flags);
VulkanImageView *GetImageView(FTexture *tex, int translation, int flags); VulkanImageView *GetImageView(FTexture *tex, int translation, int flags);
VulkanImageView *GetDepthStencilView(FTexture *tex);
static void ResetAllDescriptors(); static void ResetAllDescriptors();
@ -75,4 +76,7 @@ private:
std::unique_ptr<VulkanImageView> mImageView; std::unique_ptr<VulkanImageView> mImageView;
VkImageLayout mImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; VkImageLayout mImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
int mTexelsize = 4; int mTexelsize = 4;
std::unique_ptr<VulkanImage> mDepthStencil;
std::unique_ptr<VulkanImageView> mDepthStencilView;
}; };