From b46a80be2cd3313dae12c387918ec955406be533 Mon Sep 17 00:00:00 2001 From: Steve Pham <82231385+spham-amzn@users.noreply.github.com> Date: Sat, 31 Jul 2021 08:42:02 -0700 Subject: [PATCH] Fix for Linux/Vulkan/Editor crash on startup * Temporary fix for Linux/Vulkan/XCB where the swap chain is not ready to present until the resize is complete * Fix invalid GUID from LinuxXcbConnectionManager Signed-off-by: spham-amzn --- .../Linux/AzFramework/API/ApplicationAPI_Linux.h | 2 +- Gems/Atom/RHI/Code/Include/Atom/RHI/SwapChain.h | 9 +++++++++ Gems/Atom/RHI/Code/Source/RHI/SwapChain.cpp | 4 ++++ Gems/Atom/RHI/Vulkan/Code/Source/RHI/CommandQueue.cpp | 9 +++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Code/Framework/AzFramework/Platform/Linux/AzFramework/API/ApplicationAPI_Linux.h b/Code/Framework/AzFramework/Platform/Linux/AzFramework/API/ApplicationAPI_Linux.h index 03c65ce0c3..9b57d1d49e 100644 --- a/Code/Framework/AzFramework/Platform/Linux/AzFramework/API/ApplicationAPI_Linux.h +++ b/Code/Framework/AzFramework/Platform/Linux/AzFramework/API/ApplicationAPI_Linux.h @@ -35,7 +35,7 @@ namespace AzFramework class LinuxXcbConnectionManager { public: - AZ_RTTI(LinuxXcbConnectionManager, "{649951316-3626-4C9D-9DCA-2E7ABF84C0A9}"); + AZ_RTTI(LinuxXcbConnectionManager, "{1F756E14-8D74-42FD-843C-4863307710DB}"); virtual ~LinuxXcbConnectionManager() = default; diff --git a/Gems/Atom/RHI/Code/Include/Atom/RHI/SwapChain.h b/Gems/Atom/RHI/Code/Include/Atom/RHI/SwapChain.h index 14e9968e42..c1fd4453d4 100644 --- a/Gems/Atom/RHI/Code/Include/Atom/RHI/SwapChain.h +++ b/Gems/Atom/RHI/Code/Include/Atom/RHI/SwapChain.h @@ -81,6 +81,15 @@ namespace AZ AZ_RTTI(SwapChain, "{888B64A5-D956-406F-9C33-CF6A54FC41B0}", Object); +#if defined(PAL_TRAIT_LINUX_WINDOW_MANAGER_XCB) + // On Linux platforms that uses XCB, a resize may occur in the swap chain but the command queue may still + // reference the original surface. This flag is a temporary fix to make sure that all the swap chains + // have finished their resize events before presenting the command queue. + + // [GFX TODO][GHI - 2678] + AZStd::atomic_bool m_resized{ false }; +#endif // PAL_TRAIT_LINUX_WINDOW_MANAGER_XCB + protected: SwapChain(); diff --git a/Gems/Atom/RHI/Code/Source/RHI/SwapChain.cpp b/Gems/Atom/RHI/Code/Source/RHI/SwapChain.cpp index b0501d937d..5fbb83fccf 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/SwapChain.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/SwapChain.cpp @@ -164,6 +164,10 @@ namespace AZ m_currentImageIndex = 0; } +#if defined(PAL_TRAIT_LINUX_WINDOW_MANAGER_XCB) + m_resized.store(true); +#endif // PAL_TRAIT_LINUX_WINDOW_MANAGER_XCB + return resultCode; } diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/CommandQueue.cpp b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/CommandQueue.cpp index ca6c829cca..84b4964235 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/CommandQueue.cpp +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/CommandQueue.cpp @@ -42,6 +42,15 @@ namespace AZ void CommandQueue::ExecuteWork(const RHI::ExecuteWorkRequest& rhiRequest) { +#if defined(PAL_TRAIT_LINUX_WINDOW_MANAGER_XCB) + for (RHI::SwapChain* swapChain : rhiRequest.m_swapChainsToPresent) + { + if (!swapChain->m_resized) + { + return; + } + } +#endif // PAL_TRAIT_LINUX_WINDOW_MANAGER_XCB const ExecuteWorkRequest& request = static_cast(rhiRequest); QueueCommand([=](void* queue) {