Skip to content
Permalink
Browse files

- move camtex depthstencil to VkHardwareTexture

  • Loading branch information...
dpjudas authored and madame-rachelle committed May 5, 2019
1 parent 9ca0c6a commit e150483ead8e04f5750d0befadc6f5bd8194b302
@@ -34,7 +34,7 @@ void VkPostprocess::SetActiveRenderTarget()
imageTransition.addImage(buffers->PipelineImage[mCurrentPipelineImage].get(), &buffers->PipelineLayout[mCurrentPipelineImage], VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, false);
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)
@@ -55,7 +55,6 @@ void VkRenderBuffers::BeginFrame(int width, int height, int sceneWidth, int scen
if (width != mWidth || height != mHeight || mSamples != samples)
CreateScene(width, height, samples);

CreateCamTexDepthStencil();
CreateShadowmap();

mWidth = width;
@@ -143,31 +142,6 @@ void VkRenderBuffers::CreateSceneColor(int width, int height, VkSampleCountFlagB
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)
{
auto fb = GetVulkanFrameBuffer();
@@ -32,9 +32,6 @@ class VkRenderBuffers
VkImageLayout SceneNormalLayout = 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;
std::unique_ptr<VulkanImage> PipelineImage[NumPipelineImages];
std::unique_ptr<VulkanImageView> PipelineView[NumPipelineImages];
@@ -53,7 +50,6 @@ class VkRenderBuffers
void CreateSceneFog(int width, int height, VkSampleCountFlagBits samples);
void CreateSceneNormal(int width, int height, VkSampleCountFlagBits samples);
void CreateShadowmap();
void CreateCamTexDepthStencil();
VkSampleCountFlagBits GetBestSampleCount();

int mWidth = 0;
@@ -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();

mRenderTarget.View = view;
mRenderTarget.DepthStencil = depthStencilView;
mRenderTarget.Width = width;
mRenderTarget.Height = height;
mRenderTarget.Format = format;
@@ -566,7 +567,7 @@ void VkRenderState::BeginRenderPass(const VkRenderPassKey &key, VulkanCommandBuf
if (key.DrawBuffers > 2)
builder.addAttachment(buffers->SceneNormalView.get());
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->SetDebugName("VkRenderPassSetup.Framebuffer");
}
@@ -43,7 +43,7 @@ class VkRenderState : public FRenderState
void EnableDrawBuffers(int count) override;

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 EndRenderPass();
void EndFrame();
@@ -112,6 +112,7 @@ class VkRenderState : public FRenderState
struct RenderTarget
{
VulkanImageView *View = nullptr;
VulkanImageView *DepthStencil = nullptr;
int Width = 0;
int Height = 0;
VkFormat Format = VK_FORMAT_R16G16B16A16_SFLOAT;
@@ -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
{
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);
GetRenderState()->SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS);
GetRenderState()->EnableDrawBuffers(GetRenderState()->GetPassDrawBufferCount());
@@ -505,15 +505,15 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint
int height = mat->TextureHeight();
VulkanImage *image = BaseLayer->GetImage(tex, 0, 0);
VulkanImageView *view = BaseLayer->GetImageView(tex, 0, 0);
VulkanImageView *depthStencilView = BaseLayer->GetDepthStencilView(tex);

mRenderState->EndRenderPass();
auto cmdbuffer = GetDrawCommands();

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.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;
bounds.left = bounds.top = 0;
@@ -527,9 +527,9 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint

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.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);
}
@@ -36,6 +36,7 @@
#include "vulkan/textures/vk_samplers.h"
#include "vulkan/renderer/vk_renderpass.h"
#include "vulkan/renderer/vk_postprocess.h"
#include "vulkan/renderer/vk_renderbuffers.h"
#include "vk_hwtexture.h"

VkHardwareTexture *VkHardwareTexture::First = nullptr;
@@ -71,6 +72,8 @@ void VkHardwareTexture::Reset()
auto &deleteList = fb->FrameDeleteList;
if (mImage) deleteList.Images.push_back(std::move(mImage));
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();
}

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)
{
if (!tex->isHardwareCanvas())
@@ -40,6 +40,7 @@ class VkHardwareTexture : public IHardwareTexture

VulkanImage *GetImage(FTexture *tex, int translation, int flags);
VulkanImageView *GetImageView(FTexture *tex, int translation, int flags);
VulkanImageView *GetDepthStencilView(FTexture *tex);

static void ResetAllDescriptors();

@@ -75,4 +76,7 @@ class VkHardwareTexture : public IHardwareTexture
std::unique_ptr<VulkanImageView> mImageView;
VkImageLayout mImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
int mTexelsize = 4;

std::unique_ptr<VulkanImage> mDepthStencil;
std::unique_ptr<VulkanImageView> mDepthStencilView;
};

0 comments on commit e150483

Please sign in to comment.
You can’t perform that action at this time.