Browse Source

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.

master
Nico de Poel 11 months ago
parent
commit
c11ab1099b
  1. 12
      FSR3UnityPlugin.cpp

12
FSR3UnityPlugin.cpp

@ -260,6 +260,16 @@ static void DestroyFeature(uint32_t featureSlot)
WaitForSingleObjectEx(s_FrameFenceEventHandle, INFINITE, false); 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) if (feature.upscalingContext != nullptr)
{ {
@ -483,7 +493,7 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data)
s_GraphicsVulkan->CommandRecordingState(&state, kUnityVulkanGraphicsQueueAccess_DontCare); s_GraphicsVulkan->CommandRecordingState(&state, kUnityVulkanGraphicsQueueAccess_DontCare);
dispatchUpscale.commandList = state.commandBuffer; 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; feature.dispatchFrameValue = state.currentFrameNumber;
UnityVulkanInstance instance = s_GraphicsVulkan->Instance(); UnityVulkanInstance instance = s_GraphicsVulkan->Instance();

Loading…
Cancel
Save