From 2ab4562a25ea301d792641fc5eee2276034d2bfd Mon Sep 17 00:00:00 2001 From: Alexander Gauggel <agauggel@uni-koblenz.de> Date: Sat, 26 Jun 2021 12:55:17 +0200 Subject: [PATCH] [#82] Keep bloom textures at half res, improves performance without quality loss --- .../shaders/bloomFlaresComposite.comp | 2 +- projects/voxelization/src/BloomAndFlares.cpp | 26 +++++++++---------- projects/voxelization/src/BloomAndFlares.hpp | 8 +++--- projects/voxelization/src/main.cpp | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/projects/voxelization/resources/shaders/bloomFlaresComposite.comp b/projects/voxelization/resources/shaders/bloomFlaresComposite.comp index 190bed06..eb17ea90 100644 --- a/projects/voxelization/resources/shaders/bloomFlaresComposite.comp +++ b/projects/voxelization/resources/shaders/bloomFlaresComposite.comp @@ -16,7 +16,7 @@ void main() } ivec2 pixel_coord = ivec2(gl_GlobalInvocationID.xy); - vec2 pixel_size = vec2(1.0f) / textureSize(sampler2D(blurImage, linearSampler), 0); + vec2 pixel_size = vec2(1.0f) / imageSize(colorBuffer); vec2 UV = pixel_coord.xy * pixel_size; vec4 composite_color = vec4(0.0f); diff --git a/projects/voxelization/src/BloomAndFlares.cpp b/projects/voxelization/src/BloomAndFlares.cpp index 4e69e559..aa077ef5 100644 --- a/projects/voxelization/src/BloomAndFlares.cpp +++ b/projects/voxelization/src/BloomAndFlares.cpp @@ -9,14 +9,14 @@ BloomAndFlares::BloomAndFlares( p_Core(p_Core), m_ColorBufferFormat(colorBufferFormat), - m_Width(width), - m_Height(height), + m_Width(width / 2), + m_Height(height / 2), m_LinearSampler(p_Core->createSampler(vkcv::SamplerFilterType::LINEAR, vkcv::SamplerFilterType::LINEAR, vkcv::SamplerMipmapMode::LINEAR, vkcv::SamplerAddressMode::CLAMP_TO_EDGE)), - m_Blur(p_Core->createImage(colorBufferFormat, width, height, 1, true, true, false)), - m_LensFeatures(p_Core->createImage(colorBufferFormat, width, height, 1, true, true, false)) + m_Blur(p_Core->createImage(colorBufferFormat, m_Width, m_Height, 1, true, true, false)), + m_LensFeatures(p_Core->createImage(colorBufferFormat, m_Width, m_Height, 1, true, true, false)) { vkcv::shader::GLSLCompiler compiler; @@ -264,8 +264,8 @@ void BloomAndFlares::execLensFeaturePipe(const vkcv::CommandStreamHandle &cmdStr } } -void BloomAndFlares::execCompositePipe(const vkcv::CommandStreamHandle &cmdStream, - const vkcv::ImageHandle &colorAttachment) +void BloomAndFlares::execCompositePipe(const vkcv::CommandStreamHandle &cmdStream, const vkcv::ImageHandle& colorAttachment, + const uint32_t attachmentWidth, const uint32_t attachmentHeight) { p_Core->prepareImageForSampling(cmdStream, m_Blur.getHandle()); p_Core->prepareImageForSampling(cmdStream, m_LensFeatures.getHandle()); @@ -279,8 +279,8 @@ void BloomAndFlares::execCompositePipe(const vkcv::CommandStreamHandle &cmdStrea compositeWrites.storageImageWrites = {vkcv::StorageImageDescriptorWrite(3, colorAttachment)}; p_Core->writeDescriptorSet(m_CompositeDescSet, compositeWrites); - float dispatchCountX = static_cast<float>(m_Width) / 8.0f; - float dispatchCountY = static_cast<float>(m_Height) / 8.0f; + float dispatchCountX = static_cast<float>(attachmentWidth) / 8.0f; + float dispatchCountY = static_cast<float>(attachmentHeight) / 8.0f; uint32_t compositeDispatchCount[3] = { static_cast<uint32_t>(glm::ceil(dispatchCountX)), @@ -297,19 +297,19 @@ void BloomAndFlares::execCompositePipe(const vkcv::CommandStreamHandle &cmdStrea vkcv::PushConstantData(nullptr, 0)); } -void BloomAndFlares::execWholePipeline(const vkcv::CommandStreamHandle &cmdStream, - const vkcv::ImageHandle &colorAttachment) +void BloomAndFlares::execWholePipeline(const vkcv::CommandStreamHandle &cmdStream, const vkcv::ImageHandle &colorAttachment, + const uint32_t attachmentWidth, const uint32_t attachmentHeight) { execDownsamplePipe(cmdStream, colorAttachment); execUpsamplePipe(cmdStream); execLensFeaturePipe(cmdStream); - execCompositePipe(cmdStream, colorAttachment); + execCompositePipe(cmdStream, colorAttachment, attachmentWidth, attachmentHeight); } void BloomAndFlares::updateImageDimensions(uint32_t width, uint32_t height) { - m_Width = width; - m_Height = height; + m_Width = width / 2; + m_Height = height / 2; p_Core->getContext().getDevice().waitIdle(); m_Blur = p_Core->createImage(m_ColorBufferFormat, m_Width, m_Height, 1, true, true, false); diff --git a/projects/voxelization/src/BloomAndFlares.hpp b/projects/voxelization/src/BloomAndFlares.hpp index 71ec21eb..7f0c5236 100644 --- a/projects/voxelization/src/BloomAndFlares.hpp +++ b/projects/voxelization/src/BloomAndFlares.hpp @@ -9,7 +9,8 @@ public: uint32_t width, uint32_t height); - void execWholePipeline(const vkcv::CommandStreamHandle &cmdStream, const vkcv::ImageHandle &colorAttachment); + void execWholePipeline(const vkcv::CommandStreamHandle &cmdStream, const vkcv::ImageHandle &colorAttachment, + const uint32_t attachmentWidth, const uint32_t attachmentHeight); void updateImageDimensions(uint32_t width, uint32_t height); @@ -27,10 +28,10 @@ private: vkcv::PipelineHandle m_DownsamplePipe; std::vector<vkcv::DescriptorSetHandle> m_DownsampleDescSets; // per mip desc set + std::vector<vkcv::DescriptorSetHandle> m_UpsampleLensFlareDescSets; // per mip desc set vkcv::PipelineHandle m_UpsamplePipe; std::vector<vkcv::DescriptorSetHandle> m_UpsampleDescSets; // per mip desc set - std::vector<vkcv::DescriptorSetHandle> m_UpsampleLensFlareDescSets; // per mip desc set vkcv::PipelineHandle m_LensFlarePipe; vkcv::DescriptorSetHandle m_LensFlareDescSet; @@ -41,7 +42,8 @@ private: void execDownsamplePipe(const vkcv::CommandStreamHandle &cmdStream, const vkcv::ImageHandle &colorAttachment); void execUpsamplePipe(const vkcv::CommandStreamHandle &cmdStream); void execLensFeaturePipe(const vkcv::CommandStreamHandle &cmdStream); - void execCompositePipe(const vkcv::CommandStreamHandle &cmdStream, const vkcv::ImageHandle &colorAttachment); + void execCompositePipe(const vkcv::CommandStreamHandle &cmdStream, const vkcv::ImageHandle &colorAttachment, + const uint32_t attachmentWidth, const uint32_t attachmentHeight); }; diff --git a/projects/voxelization/src/main.cpp b/projects/voxelization/src/main.cpp index 9ba4b8b7..bafcc45c 100644 --- a/projects/voxelization/src/main.cpp +++ b/projects/voxelization/src/main.cpp @@ -654,7 +654,7 @@ int main(int argc, const char** argv) { } } - bloomFlares.execWholePipeline(cmdStream, resolvedColorBuffer); + bloomFlares.execWholePipeline(cmdStream, resolvedColorBuffer, windowWidth, windowHeight); core.prepareImageForStorage(cmdStream, swapchainInput); core.prepareImageForSampling(cmdStream, resolvedColorBuffer); -- GitLab