From 40c14bcd674ccdc0e7f58e9dd9723d842bba8802 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 6 Mar 2019 17:59:11 +0100 Subject: [PATCH] - create pipeline images - fix some minor typos --- .../vulkan/renderer/vk_postprocess.cpp | 2 +- .../vulkan/renderer/vk_postprocess.h | 1 + .../vulkan/renderer/vk_renderbuffers.cpp | 27 ++++++++++++++++++- .../vulkan/renderer/vk_renderbuffers.h | 6 ++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/rendering/vulkan/renderer/vk_postprocess.cpp b/src/rendering/vulkan/renderer/vk_postprocess.cpp index 38cd442c7..bce78e08d 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.cpp +++ b/src/rendering/vulkan/renderer/vk_postprocess.cpp @@ -237,7 +237,7 @@ void VkPostprocess::RenderEffect(const FString &name) VkPPRenderPassKey key; key.BlendMode = step.BlendMode; key.InputTextures = step.Textures.Size(); - key.Uniforms = step.Uniforms.Data.Size() != 0; + key.Uniforms = step.Uniforms.Data.Size(); key.Shader = mShaders[step.ShaderName].get(); key.OutputFormat = (step.Output.Type == PPTextureType::PPTexture) ? mTextures[step.Output.Texture]->Format : VK_FORMAT_R16G16B16A16_SFLOAT; diff --git a/src/rendering/vulkan/renderer/vk_postprocess.h b/src/rendering/vulkan/renderer/vk_postprocess.h index 116e40351..d2486c9c5 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.h +++ b/src/rendering/vulkan/renderer/vk_postprocess.h @@ -59,6 +59,7 @@ private: std::map> mShaders; std::array, 16> mSamplers; std::map> mRenderPassSetup; + int mCurrentPipelineImage = 0; }; class VkPPShader diff --git a/src/rendering/vulkan/renderer/vk_renderbuffers.cpp b/src/rendering/vulkan/renderer/vk_renderbuffers.cpp index 934b0b64c..9c2e68b8f 100644 --- a/src/rendering/vulkan/renderer/vk_renderbuffers.cpp +++ b/src/rendering/vulkan/renderer/vk_renderbuffers.cpp @@ -41,6 +41,31 @@ void VkRenderBuffers::BeginFrame(int width, int height, int sceneWidth, int scen void VkRenderBuffers::CreatePipeline(int width, int height) { + auto fb = GetVulkanFrameBuffer(); + + for (int i = 0; i < NumPipelineImages; i++) + { + PipelineImage[i].reset(); + PipelineView[i].reset(); + } + + PipelineBarrier barrier; + for (int i = 0; i < NumPipelineImages; i++) + { + ImageBuilder builder; + builder.setSize(width, height); + 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); + PipelineImage[i] = builder.create(fb->device); + + ImageViewBuilder viewbuilder; + viewbuilder.setImage(PipelineImage[i].get(), VK_FORMAT_R16G16B16A16_SFLOAT); + PipelineView[i] = viewbuilder.create(fb->device); + + barrier.addImage(PipelineImage[i].get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 0, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); + PipelineLayout[i] = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + } + 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); } void VkRenderBuffers::CreateScene(int width, int height, int samples) @@ -54,7 +79,7 @@ void VkRenderBuffers::CreateScene(int width, int height, int samples) SceneDepthStencil.reset(); ImageBuilder builder; - builder.setSize(SCREENWIDTH, SCREENHEIGHT); + builder.setSize(width, height); 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); diff --git a/src/rendering/vulkan/renderer/vk_renderbuffers.h b/src/rendering/vulkan/renderer/vk_renderbuffers.h index f65777450..390111fdc 100644 --- a/src/rendering/vulkan/renderer/vk_renderbuffers.h +++ b/src/rendering/vulkan/renderer/vk_renderbuffers.h @@ -21,9 +21,13 @@ public: std::unique_ptr SceneColorView; std::unique_ptr SceneDepthStencilView; std::unique_ptr SceneDepthView; - VkFormat SceneDepthStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT; + static const int NumPipelineImages = 2; + std::unique_ptr PipelineImage[NumPipelineImages]; + std::unique_ptr PipelineView[NumPipelineImages]; + VkImageLayout PipelineLayout[NumPipelineImages]; + private: void CreatePipeline(int width, int height); void CreateScene(int width, int height, int samples);