From 1294cd0d7f2f6e7b3992a234d94906206cd2d423 Mon Sep 17 00:00:00 2001 From: moudgils <47460854+moudgils@users.noreply.github.com> Date: Mon, 29 Nov 2021 13:33:48 -0800 Subject: [PATCH] Various Vulkan fixes (#5880) * Various Vulkan fixes - Swapchain related fix for UI editor - Object of type VkQueue is simultaneously used in the main thread and the queue thread. Pushed the swapchain invalidation to the presentation queue thread - Added padding for DepthOfFieldData to ensure it is 16 byte aligned - Added aspect flag for SMAAEdgeDetectionTemplate pass - Reduced MaxUnboundedArrayDescriptors so that it is under the maxDescriptorSetSampledImages limit - Added CopyRead flag for ReflectionScreenSpaceBlurPass related transient resources. Signed-off-by: moudgils <47460854+moudgils@users.noreply.github.com> * Missed file Signed-off-by: moudgils <47460854+moudgils@users.noreply.github.com> --- .../Assets/Passes/SMAAEdgeDetection.pass | 7 ++++++- .../PostProcessing/ViewSrg.azsli | 3 ++- .../ReflectionScreenSpaceBlurPass.cpp | 2 +- .../Code/Source/RHI/DescriptorSetLayout.h | 2 +- .../RHI/Vulkan/Code/Source/RHI/SwapChain.cpp | 18 ++++++++++++------ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Passes/SMAAEdgeDetection.pass b/Gems/Atom/Feature/Common/Assets/Passes/SMAAEdgeDetection.pass index ab03ea01ef..674acdd3a0 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/SMAAEdgeDetection.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/SMAAEdgeDetection.pass @@ -15,7 +15,12 @@ { "Name": "InputDepth", "SlotType": "Input", - "ScopeAttachmentUsage": "Shader" + "ScopeAttachmentUsage": "Shader", + "ImageViewDesc": { + "AspectFlags": [ + "Depth" + ] + } }, { "Name": "OutputEdgeDetectionResult", diff --git a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/PostProcessing/ViewSrg.azsli b/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/PostProcessing/ViewSrg.azsli index 10906ac09b..e8501a4a2d 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/PostProcessing/ViewSrg.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderResourceGroups/PostProcessing/ViewSrg.azsli @@ -26,8 +26,9 @@ partial ShaderResourceGroup ViewSrg // circle of confusion to screen ratio; float m_cocToScreenRatio; + [[pad_to(16)]] }; - + DepthOfFieldData m_dof; struct ExposureControlParameters diff --git a/Gems/Atom/Feature/Common/Code/Source/ReflectionScreenSpace/ReflectionScreenSpaceBlurPass.cpp b/Gems/Atom/Feature/Common/Code/Source/ReflectionScreenSpace/ReflectionScreenSpaceBlurPass.cpp index c0b25697a3..298aefe8df 100644 --- a/Gems/Atom/Feature/Common/Code/Source/ReflectionScreenSpace/ReflectionScreenSpaceBlurPass.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/ReflectionScreenSpace/ReflectionScreenSpaceBlurPass.cpp @@ -127,7 +127,7 @@ namespace AZ { RHI::Size mipSize = imageSize.GetReducedMip(mip); - RHI::ImageBindFlags imageBindFlags = RHI::ImageBindFlags::Color | RHI::ImageBindFlags::ShaderReadWrite; + RHI::ImageBindFlags imageBindFlags = RHI::ImageBindFlags::Color | RHI::ImageBindFlags::ShaderReadWrite | RHI::ImageBindFlags::CopyRead; auto transientImageDesc = RHI::ImageDescriptor::Create2D(imageBindFlags, mipSize.m_width, mipSize.m_height, RHI::Format::R16G16B16A16_FLOAT); RPI::PassAttachment* transientPassAttachment = aznew RPI::PassAttachment(); diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/DescriptorSetLayout.h b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/DescriptorSetLayout.h index 50132d62ec..2d40d21ed5 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/DescriptorSetLayout.h +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/DescriptorSetLayout.h @@ -76,7 +76,7 @@ namespace AZ const AZStd::vector& GetNativeBindingFlags() const; const RHI::ShaderResourceGroupLayout* GetShaderResourceGroupLayout() const; - static const uint32_t MaxUnboundedArrayDescriptors = (1024 * 1024 * 2); // 2M + static const uint32_t MaxUnboundedArrayDescriptors = 900000; //Using this number as it needs to be less than maxDescriptorSetSampledImages limit of 1048576 bool GetHasUnboundedArray() const { return m_hasUnboundedArray; } private: diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp index 47c92d97fb..67f4834524 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp @@ -483,12 +483,18 @@ namespace AZ void SwapChain::InvalidateNativeSwapChain() { auto& device = static_cast(GetDevice()); - vkDeviceWaitIdle(device.GetNativeDevice()); - if (m_nativeSwapChain != VK_NULL_HANDLE) + auto presentCommand = [this, &device]([[maybe_unused]] void* queue) { - vkDestroySwapchainKHR(device.GetNativeDevice(), m_nativeSwapChain, nullptr); - m_nativeSwapChain = VK_NULL_HANDLE; - } + vkDeviceWaitIdle(device.GetNativeDevice()); + if (m_nativeSwapChain != VK_NULL_HANDLE) + { + vkDestroySwapchainKHR(device.GetNativeDevice(), m_nativeSwapChain, nullptr); + m_nativeSwapChain = VK_NULL_HANDLE; + } + }; + + m_presentationQueue->QueueCommand(AZStd::move(presentCommand)); + m_presentationQueue->FlushCommands(); } RHI::ResultCode SwapChain::CreateSwapchain() @@ -496,7 +502,7 @@ namespace AZ auto& device = static_cast(GetDevice()); m_surfaceCapabilities = GetSurfaceCapabilities(); - m_surfaceFormat = GetSupportedSurfaceFormat(GetDescriptor().m_dimensions.m_imageFormat); + m_surfaceFormat = GetSupportedSurfaceFormat(m_dimensions.m_imageFormat); m_presentMode = GetSupportedPresentMode(GetDescriptor().m_verticalSyncInterval); m_compositeAlphaFlagBits = GetSupportedCompositeAlpha();