From d65de299e86b27e8ecce5cb9e61585a7a4562ec8 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 5 Mar 2019 04:59:17 +0100 Subject: [PATCH] - add some classes for managing postprocess and render buffers --- src/CMakeLists.txt | 2 + .../vulkan/renderer/vk_postprocess.cpp | 119 ++++++++++++++++++ .../vulkan/renderer/vk_postprocess.h | 28 +++++ .../vulkan/renderer/vk_renderbuffers.cpp | 89 +++++++++++++ .../vulkan/renderer/vk_renderbuffers.h | 37 ++++++ .../vulkan/renderer/vk_renderpass.cpp | 66 +++------- src/rendering/vulkan/renderer/vk_renderpass.h | 15 +-- .../vulkan/renderer/vk_renderstate.cpp | 26 ++-- .../vulkan/system/vk_framebuffer.cpp | 13 +- src/rendering/vulkan/system/vk_framebuffer.h | 9 ++ 10 files changed, 328 insertions(+), 76 deletions(-) create mode 100644 src/rendering/vulkan/renderer/vk_postprocess.cpp create mode 100644 src/rendering/vulkan/renderer/vk_postprocess.h create mode 100644 src/rendering/vulkan/renderer/vk_renderbuffers.cpp create mode 100644 src/rendering/vulkan/renderer/vk_renderbuffers.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 38884afb98..16b4d1e514 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -901,6 +901,8 @@ set( FASTMATH_SOURCES rendering/vulkan/system/vk_buffers.cpp rendering/vulkan/renderer/vk_renderstate.cpp rendering/vulkan/renderer/vk_renderpass.cpp + rendering/vulkan/renderer/vk_postprocess.cpp + rendering/vulkan/renderer/vk_renderbuffers.cpp rendering/vulkan/shaders/vk_shader.cpp rendering/vulkan/textures/vk_samplers.cpp rendering/vulkan/textures/vk_hwtexture.cpp diff --git a/src/rendering/vulkan/renderer/vk_postprocess.cpp b/src/rendering/vulkan/renderer/vk_postprocess.cpp new file mode 100644 index 0000000000..be86a1fd41 --- /dev/null +++ b/src/rendering/vulkan/renderer/vk_postprocess.cpp @@ -0,0 +1,119 @@ + +#include "vk_postprocess.h" +#include "vk_renderbuffers.h" +#include "vulkan/shaders/vk_shader.h" +#include "vulkan/system/vk_builders.h" +#include "vulkan/system/vk_framebuffer.h" +#include "vulkan/system/vk_buffers.h" +#include "hwrenderer/utility/hw_cvars.h" +#include "hwrenderer/postprocessing/hw_presentshader.h" +#include "hwrenderer/postprocessing/hw_postprocess.h" +#include "hwrenderer/postprocessing/hw_postprocess_cvars.h" +#include "hwrenderer/utility/hw_vrmodes.h" +#include "hwrenderer/data/flatvertices.h" +#include "r_videoscale.h" + +VkPostprocess::VkPostprocess() +{ +} + +VkPostprocess::~VkPostprocess() +{ +} + +void VkPostprocess::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) +{ + auto fb = GetVulkanFrameBuffer(); + + hw_postprocess.fixedcm = fixedcm; + hw_postprocess.SceneWidth = fb->GetBuffers()->GetSceneWidth(); + hw_postprocess.SceneHeight = fb->GetBuffers()->GetSceneHeight(); + + hw_postprocess.DeclareShaders(); + hw_postprocess.UpdateTextures(); + hw_postprocess.UpdateSteps(); + + CompileEffectShaders(); + UpdateEffectTextures(); + + RenderEffect("UpdateCameraExposure"); + //mCustomPostProcessShaders->Run("beforebloom"); + RenderEffect("BloomScene"); + //BindCurrentFB(); + afterBloomDrawEndScene2D(); + RenderEffect("TonemapScene"); + RenderEffect("ColormapScene"); + RenderEffect("LensDistortScene"); + RenderEffect("ApplyFXAA"); + //mCustomPostProcessShaders->Run("scene"); +} + +void VkPostprocess::AmbientOccludeScene(float m5) +{ + auto fb = GetVulkanFrameBuffer(); + + hw_postprocess.SceneWidth = fb->GetBuffers()->GetSceneWidth(); + hw_postprocess.SceneHeight = fb->GetBuffers()->GetSceneHeight(); + hw_postprocess.m5 = m5; + + hw_postprocess.DeclareShaders(); + hw_postprocess.UpdateTextures(); + hw_postprocess.UpdateSteps(); + + CompileEffectShaders(); + UpdateEffectTextures(); + + RenderEffect("AmbientOccludeScene"); +} + +void VkPostprocess::BlurScene(float gameinfobluramount) +{ + hw_postprocess.gameinfobluramount = gameinfobluramount; + + hw_postprocess.DeclareShaders(); + hw_postprocess.UpdateTextures(); + hw_postprocess.UpdateSteps(); + + CompileEffectShaders(); + UpdateEffectTextures(); + + auto vrmode = VRMode::GetVRMode(true); + int eyeCount = vrmode->mEyeCount; + for (int i = 0; i < eyeCount; ++i) + { + RenderEffect("BlurScene"); + if (eyeCount - i > 1) NextEye(eyeCount); + } +} + +void VkPostprocess::ClearTonemapPalette() +{ + hw_postprocess.Textures.Remove("Tonemap.Palette"); +} + +void VkPostprocess::RenderBuffersReset() +{ +} + +void VkPostprocess::UpdateEffectTextures() +{ +} + +void VkPostprocess::CompileEffectShaders() +{ +} + +void VkPostprocess::RenderEffect(const FString &name) +{ +} + +void VkPostprocess::RenderScreenQuad() +{ + //auto buffer = static_cast(screen->mVertexData->GetBufferObjects().first); + //buffer->Bind(nullptr); + //glDrawArrays(GL_TRIANGLE_STRIP, FFlatVertexBuffer::PRESENT_INDEX, 4); +} + +void VkPostprocess::NextEye(int eyeCount) +{ +} diff --git a/src/rendering/vulkan/renderer/vk_postprocess.h b/src/rendering/vulkan/renderer/vk_postprocess.h new file mode 100644 index 0000000000..2a4dec4df1 --- /dev/null +++ b/src/rendering/vulkan/renderer/vk_postprocess.h @@ -0,0 +1,28 @@ + +#pragma once + +#include "vulkan/system/vk_objects.h" + +class FString; + +class VkPostprocess +{ +public: + VkPostprocess(); + ~VkPostprocess(); + + void RenderBuffersReset(); + + void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D); + + void AmbientOccludeScene(float m5); + void BlurScene(float gameinfobluramount); + void ClearTonemapPalette(); + +private: + void UpdateEffectTextures(); + void CompileEffectShaders(); + void RenderEffect(const FString &name); + void NextEye(int eyeCount); + void RenderScreenQuad(); +}; diff --git a/src/rendering/vulkan/renderer/vk_renderbuffers.cpp b/src/rendering/vulkan/renderer/vk_renderbuffers.cpp new file mode 100644 index 0000000000..934b0b64ce --- /dev/null +++ b/src/rendering/vulkan/renderer/vk_renderbuffers.cpp @@ -0,0 +1,89 @@ + +#include "vk_renderbuffers.h" +#include "vk_renderpass.h" +#include "vk_postprocess.h" +#include "vulkan/shaders/vk_shader.h" +#include "vulkan/system/vk_builders.h" +#include "vulkan/system/vk_framebuffer.h" +#include "hwrenderer/utility/hw_cvars.h" + +VkRenderBuffers::VkRenderBuffers() +{ +} + +VkRenderBuffers::~VkRenderBuffers() +{ +} + +void VkRenderBuffers::BeginFrame(int width, int height, int sceneWidth, int sceneHeight) +{ + int samples = clamp((int)gl_multisample, 0, mMaxSamples); + + if (width != mWidth || height != mHeight || mSamples != samples) + { + auto fb = GetVulkanFrameBuffer(); + fb->GetRenderPassManager()->RenderBuffersReset(); + fb->GetPostprocess()->RenderBuffersReset(); + } + + if (width != mWidth || height != mHeight) + CreatePipeline(width, height); + + if (width != mWidth || height != mHeight || mSamples != samples) + CreateScene(width, height, samples); + + mWidth = width; + mHeight = height; + mSamples = samples; + mSceneWidth = sceneWidth; + mSceneHeight = sceneHeight; +} + +void VkRenderBuffers::CreatePipeline(int width, int height) +{ +} + +void VkRenderBuffers::CreateScene(int width, int height, int samples) +{ + auto fb = GetVulkanFrameBuffer(); + + SceneColorView.reset(); + SceneDepthStencilView.reset(); + SceneDepthView.reset(); + SceneColor.reset(); + SceneDepthStencil.reset(); + + ImageBuilder builder; + builder.setSize(SCREENWIDTH, SCREENHEIGHT); + builder.setFormat(VK_FORMAT_R16G16B16A16_SFLOAT); + builder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); + SceneColor = builder.create(fb->device); + + builder.setFormat(SceneDepthStencilFormat); + builder.setUsage(VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); + if (!builder.isFormatSupported(fb->device)) + { + SceneDepthStencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; + builder.setFormat(SceneDepthStencilFormat); + if (!builder.isFormatSupported(fb->device)) + { + I_FatalError("This device does not support any of the required depth stencil image formats."); + } + } + SceneDepthStencil = builder.create(fb->device); + + ImageViewBuilder viewbuilder; + viewbuilder.setImage(SceneColor.get(), VK_FORMAT_R16G16B16A16_SFLOAT); + SceneColorView = viewbuilder.create(fb->device); + + viewbuilder.setImage(SceneDepthStencil.get(), SceneDepthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); + SceneDepthStencilView = viewbuilder.create(fb->device); + + viewbuilder.setImage(SceneDepthStencil.get(), SceneDepthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT); + SceneDepthView = viewbuilder.create(fb->device); + + PipelineBarrier barrier; + barrier.addImage(SceneColor.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); + barrier.addImage(SceneDepthStencil.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_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT); +} diff --git a/src/rendering/vulkan/renderer/vk_renderbuffers.h b/src/rendering/vulkan/renderer/vk_renderbuffers.h new file mode 100644 index 0000000000..f657774505 --- /dev/null +++ b/src/rendering/vulkan/renderer/vk_renderbuffers.h @@ -0,0 +1,37 @@ + +#pragma once + +#include "vulkan/system/vk_objects.h" + +class VkRenderBuffers +{ +public: + VkRenderBuffers(); + ~VkRenderBuffers(); + + void BeginFrame(int width, int height, int sceneWidth, int sceneHeight); + + int GetWidth() const { return mWidth; } + int GetHeight() const { return mHeight; } + int GetSceneWidth() const { return mSceneWidth; } + int GetSceneHeight() const { return mSceneHeight; } + + std::unique_ptr SceneColor; + std::unique_ptr SceneDepthStencil; + std::unique_ptr SceneColorView; + std::unique_ptr SceneDepthStencilView; + std::unique_ptr SceneDepthView; + + VkFormat SceneDepthStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT; + +private: + void CreatePipeline(int width, int height); + void CreateScene(int width, int height, int samples); + + int mWidth = 0; + int mHeight = 0; + int mSceneWidth = 0; + int mSceneHeight = 0; + int mSamples = 0; + int mMaxSamples = 16; +}; diff --git a/src/rendering/vulkan/renderer/vk_renderpass.cpp b/src/rendering/vulkan/renderer/vk_renderpass.cpp index ca1120b2f5..086d63e4da 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/src/rendering/vulkan/renderer/vk_renderpass.cpp @@ -1,5 +1,6 @@ #include "vk_renderpass.h" +#include "vk_renderbuffers.h" #include "vulkan/shaders/vk_shader.h" #include "vulkan/system/vk_builders.h" #include "vulkan/system/vk_framebuffer.h" @@ -21,53 +22,23 @@ void VkRenderPassManager::Init() CreateDynamicSet(); } -void VkRenderPassManager::BeginFrame() +void VkRenderPassManager::RenderBuffersReset() { - if (!SceneColor || SceneColor->width != SCREENWIDTH || SceneColor->height != SCREENHEIGHT) - { - auto fb = GetVulkanFrameBuffer(); + RenderPassSetup.clear(); +} - RenderPassSetup.clear(); - SceneColorView.reset(); - SceneDepthStencilView.reset(); - SceneDepthView.reset(); - SceneColor.reset(); - SceneDepthStencil.reset(); +void VkRenderPassManager::BeginRenderPass(const VkRenderPassKey &key, VulkanCommandBuffer *cmdbuffer) +{ + auto buffers = GetVulkanFrameBuffer()->GetBuffers(); - ImageBuilder builder; - builder.setSize(SCREENWIDTH, SCREENHEIGHT); - builder.setFormat(VK_FORMAT_R16G16B16A16_SFLOAT); - builder.setUsage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); - SceneColor = builder.create(fb->device); + VkRenderPassSetup *passSetup = GetRenderPass(key); - builder.setFormat(SceneDepthStencilFormat); - builder.setUsage(VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); - if (!builder.isFormatSupported(fb->device)) - { - SceneDepthStencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; - builder.setFormat(SceneDepthStencilFormat); - if (!builder.isFormatSupported(fb->device)) - { - I_FatalError("This device does not support any of the required depth stencil image formats."); - } - } - SceneDepthStencil = builder.create(fb->device); - - ImageViewBuilder viewbuilder; - viewbuilder.setImage(SceneColor.get(), VK_FORMAT_R16G16B16A16_SFLOAT); - SceneColorView = viewbuilder.create(fb->device); - - viewbuilder.setImage(SceneDepthStencil.get(), SceneDepthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); - SceneDepthStencilView = viewbuilder.create(fb->device); - - viewbuilder.setImage(SceneDepthStencil.get(), SceneDepthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT); - SceneDepthView = viewbuilder.create(fb->device); - - PipelineBarrier barrier; - barrier.addImage(SceneColor.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); - barrier.addImage(SceneDepthStencil.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_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT); - } + RenderPassBegin beginInfo; + beginInfo.setRenderPass(passSetup->RenderPass.get()); + beginInfo.setRenderArea(0, 0, buffers->GetWidth(), buffers->GetHeight()); + beginInfo.setFramebuffer(passSetup->Framebuffer.get()); + cmdbuffer->beginRenderPass(beginInfo); + cmdbuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, passSetup->Pipeline.get()); } VkRenderPassSetup *VkRenderPassManager::GetRenderPass(const VkRenderPassKey &key) @@ -181,7 +152,7 @@ void VkRenderPassSetup::CreateRenderPass(const VkRenderPassKey &key) RenderPassBuilder builder; builder.addRgba16fAttachment(false, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); if (key.DepthTest || key.DepthWrite || key.StencilTest) - builder.addDepthStencilAttachment(false, GetVulkanFrameBuffer()->GetRenderPassManager()->SceneDepthStencilFormat, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + builder.addDepthStencilAttachment(false, GetVulkanFrameBuffer()->GetBuffers()->SceneDepthStencilFormat, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); builder.addSubpass(); builder.addSubpassColorAttachmentRef(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); if (key.DepthTest || key.DepthWrite || key.StencilTest) @@ -319,11 +290,12 @@ void VkRenderPassSetup::CreatePipeline(const VkRenderPassKey &key) void VkRenderPassSetup::CreateFramebuffer(const VkRenderPassKey &key) { auto fb = GetVulkanFrameBuffer(); + auto buffers = fb->GetBuffers(); FramebufferBuilder builder; builder.setRenderPass(RenderPass.get()); - builder.setSize(SCREENWIDTH, SCREENHEIGHT); - builder.addAttachment(fb->GetRenderPassManager()->SceneColorView.get()); + builder.setSize(buffers->GetWidth(), buffers->GetHeight()); + builder.addAttachment(buffers->SceneColorView.get()); if (key.DepthTest || key.DepthWrite || key.StencilTest) - builder.addAttachment(fb->GetRenderPassManager()->SceneDepthStencilView.get()); + builder.addAttachment(buffers->SceneDepthStencilView.get()); Framebuffer = builder.create(GetVulkanFrameBuffer()->device); } diff --git a/src/rendering/vulkan/renderer/vk_renderpass.h b/src/rendering/vulkan/renderer/vk_renderpass.h index 66cdd57beb..2e3054e19b 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.h +++ b/src/rendering/vulkan/renderer/vk_renderpass.h @@ -63,8 +63,9 @@ public: VkRenderPassManager(); void Init(); - void BeginFrame(); - VkRenderPassSetup *GetRenderPass(const VkRenderPassKey &key); + void RenderBuffersReset(); + + void BeginRenderPass(const VkRenderPassKey &key, VulkanCommandBuffer *cmdbuffer); int GetVertexFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs); @@ -74,14 +75,6 @@ public: std::unique_ptr DescriptorPool; std::map> RenderPassSetup; - std::unique_ptr SceneColor; - std::unique_ptr SceneDepthStencil; - std::unique_ptr SceneColorView; - std::unique_ptr SceneDepthStencilView; - std::unique_ptr SceneDepthView; - - VkFormat SceneDepthStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT; - std::unique_ptr DynamicSet; std::vector VertexFormats; @@ -92,4 +85,6 @@ private: void CreatePipelineLayout(); void CreateDescriptorPool(); void CreateDynamicSet(); + + VkRenderPassSetup *GetRenderPass(const VkRenderPassKey &key); }; diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 5eb1d9528b..8210a6b717 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -3,6 +3,7 @@ #include "vulkan/system/vk_framebuffer.h" #include "vulkan/system/vk_builders.h" #include "vulkan/renderer/vk_renderpass.h" +#include "vulkan/renderer/vk_renderbuffers.h" #include "vulkan/textures/vk_hwtexture.h" #include "templates.h" #include "doomstat.h" @@ -243,9 +244,6 @@ void VkRenderState::ApplyDepthBias() void VkRenderState::ApplyRenderPass(int dt) { - auto fb = GetVulkanFrameBuffer(); - auto passManager = fb->GetRenderPassManager(); - // Find a render pass that matches our state VkRenderPassKey passKey; passKey.DrawType = dt; @@ -279,7 +277,7 @@ void VkRenderState::ApplyRenderPass(int dt) if (!mCommandBuffer) { - mCommandBuffer = fb->GetDrawCommands(); + mCommandBuffer = GetVulkanFrameBuffer()->GetDrawCommands(); changingRenderPass = true; mScissorChanged = true; mViewportChanged = true; @@ -293,15 +291,7 @@ void VkRenderState::ApplyRenderPass(int dt) if (changingRenderPass) { - VkRenderPassSetup *passSetup = passManager->GetRenderPass(passKey); - - RenderPassBegin beginInfo; - beginInfo.setRenderPass(passSetup->RenderPass.get()); - beginInfo.setRenderArea(0, 0, SCREENWIDTH, SCREENHEIGHT); - beginInfo.setFramebuffer(passSetup->Framebuffer.get()); - mCommandBuffer->beginRenderPass(beginInfo); - mCommandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, passSetup->Pipeline.get()); - + GetVulkanFrameBuffer()->GetRenderPassManager()->BeginRenderPass(passKey, mCommandBuffer); mRenderPassKey = passKey; } } @@ -329,10 +319,11 @@ void VkRenderState::ApplyScissor() } else { + auto buffers = GetVulkanFrameBuffer()->GetBuffers(); scissor.offset.x = 0; scissor.offset.y = 0; - scissor.extent.width = SCREENWIDTH; - scissor.extent.height = SCREENHEIGHT; + scissor.extent.width = buffers->GetWidth(); + scissor.extent.height = buffers->GetHeight(); } mCommandBuffer->setScissor(0, 1, &scissor); mScissorChanged = false; @@ -353,10 +344,11 @@ void VkRenderState::ApplyViewport() } else { + auto buffers = GetVulkanFrameBuffer()->GetBuffers(); viewport.x = 0.0f; viewport.y = 0.0f; - viewport.width = (float)SCREENWIDTH; - viewport.height = (float)SCREENHEIGHT; + viewport.width = (float)buffers->GetWidth(); + viewport.height = (float)buffers->GetHeight(); } viewport.minDepth = mViewportDepthMin; viewport.maxDepth = mViewportDepthMax; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index b12c845b2c..e429ac7d52 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -28,6 +28,7 @@ #include "r_videoscale.h" #include "actor.h" #include "i_time.h" +#include "g_game.h" #include "gamedata/fonts/v_text.h" #include "hwrenderer/utility/hw_clock.h" @@ -48,6 +49,8 @@ #include "vk_buffers.h" #include "vulkan/renderer/vk_renderstate.h" #include "vulkan/renderer/vk_renderpass.h" +#include "vulkan/renderer/vk_postprocess.h" +#include "vulkan/renderer/vk_renderbuffers.h" #include "vulkan/shaders/vk_shader.h" #include "vulkan/textures/vk_samplers.h" #include "vulkan/textures/vk_hwtexture.h" @@ -105,6 +108,11 @@ void VulkanFrameBuffer::InitializeState() mUploadSemaphore.reset(new VulkanSemaphore(device)); mGraphicsCommandPool.reset(new VulkanCommandPool(device, device->graphicsFamily)); + mScreenBuffers.reset(new VkRenderBuffers()); + mSaveBuffers.reset(new VkRenderBuffers()); + mActiveRenderBuffers = mScreenBuffers.get(); + + mPostprocess.reset(new VkPostprocess()); mRenderPassManager.reset(new VkRenderPassManager()); mVertexData = new FFlatVertexBuffer(GetWidth(), GetHeight()); @@ -149,7 +157,7 @@ void VulkanFrameBuffer::Update() //DrawPresentTexture(mOutputLetterbox, true); { - auto sceneColor = mRenderPassManager->SceneColor.get(); + auto sceneColor = mScreenBuffers->SceneColor.get(); PipelineBarrier barrier0; barrier0.addImage(sceneColor, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT); @@ -557,7 +565,8 @@ void VulkanFrameBuffer::UpdatePalette() void VulkanFrameBuffer::BeginFrame() { - mRenderPassManager->BeginFrame(); + mScreenBuffers->BeginFrame(screen->mScreenViewport.width, screen->mScreenViewport.height, screen->mSceneViewport.width, screen->mSceneViewport.height); + mSaveBuffers->BeginFrame(SAVEPICWIDTH, SAVEPICHEIGHT, SAVEPICWIDTH, SAVEPICHEIGHT); } void VulkanFrameBuffer::Draw2D() diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 88ad3fc175..062c43f3c0 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -11,6 +11,8 @@ class VkRenderPassManager; class VkRenderState; class VKDataBuffer; class VkHardwareTexture; +class VkRenderBuffers; +class VkPostprocess; class SWSceneDrawer; class VulkanFrameBuffer : public SystemBaseFrameBuffer @@ -27,6 +29,8 @@ public: VkSamplerManager *GetSamplerManager() { return mSamplerManager.get(); } VkRenderPassManager *GetRenderPassManager() { return mRenderPassManager.get(); } VkRenderState *GetRenderState() { return mRenderState.get(); } + VkPostprocess *GetPostprocess() { return mPostprocess.get(); } + VkRenderBuffers *GetBuffers() { return mActiveRenderBuffers; } unsigned int GetLightBufferBlockSize() const; @@ -84,6 +88,9 @@ private: std::unique_ptr mShaderManager; std::unique_ptr mSamplerManager; + std::unique_ptr mScreenBuffers; + std::unique_ptr mSaveBuffers; + std::unique_ptr mPostprocess; std::unique_ptr mRenderPassManager; std::unique_ptr mGraphicsCommandPool; std::unique_ptr mUploadCommands; @@ -91,6 +98,8 @@ private: std::unique_ptr mUploadSemaphore; std::unique_ptr mRenderState; + VkRenderBuffers *mActiveRenderBuffers = nullptr; + int camtexcount = 0; int lastSwapWidth = 0;