From c11ab1099bbdceb00596adcea69d4c102e93e399 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 15 Mar 2025 17:10:02 +0100 Subject: [PATCH] Wait for graphics queue to become idle before destroying an upscale context, in case a dispatch is still busy. Fixes remaining crashes in Vulkan when enabling/disabling the plugin too rapidly. --- FSR3UnityPlugin.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/FSR3UnityPlugin.cpp b/FSR3UnityPlugin.cpp index 12ad251..64922f4 100644 --- a/FSR3UnityPlugin.cpp +++ b/FSR3UnityPlugin.cpp @@ -260,6 +260,16 @@ static void DestroyFeature(uint32_t featureSlot) WaitForSingleObjectEx(s_FrameFenceEventHandle, INFINITE, false); } } + else if (s_GraphicsVulkan != nullptr) + { + UnityVulkanRecordingState state; + s_GraphicsVulkan->CommandRecordingState(&state, kUnityVulkanGraphicsQueueAccess_DontCare); + if (feature.dispatchFrameValue > state.safeFrameNumber) + { + UnityVulkanInstance instance = s_GraphicsVulkan->Instance(); + vkQueueWaitIdle(instance.graphicsQueue); + } + } if (feature.upscalingContext != nullptr) { @@ -483,7 +493,7 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data) s_GraphicsVulkan->CommandRecordingState(&state, kUnityVulkanGraphicsQueueAccess_DontCare); dispatchUpscale.commandList = state.commandBuffer; - // TODO: probably need to make use of state.currentFrameNumber and state.safeFrameNumber to keep track of when it's safe to destroy the upscaling context + // Keep track of which frame this dispatch is happening on, so we can verify when it's finished feature.dispatchFrameValue = state.currentFrameNumber; UnityVulkanInstance instance = s_GraphicsVulkan->Instance();