From 2db0aed93238fce2d2a256cf2451251efcac7e5e Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 18 Mar 2025 19:47:32 +0100 Subject: [PATCH] Configure render event for DX12 and Vulkan, to ensure the upscaler gets called without any synchronization errors. Fixes graphical glitching on Nvidia cards, as well as subtle bugs in the FSR3 pipeline on AMD. --- FSR3UnityPlugin.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/FSR3UnityPlugin.cpp b/FSR3UnityPlugin.cpp index 1c01061..77c5c83 100644 --- a/FSR3UnityPlugin.cpp +++ b/FSR3UnityPlugin.cpp @@ -27,7 +27,7 @@ #include "FSR3UnityTypes.h" -static const int32_t BaseEventId = 0; +static const int32_t BaseEventId = 313; static IUnityInterfaces* s_UnityInterfaces = nullptr; static IUnityLog* s_Log = nullptr; @@ -119,6 +119,12 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev UNITY_LOG_ERROR(s_Log, "Could not obtain D3D12 Graphics interface!"); return; } + + UnityD3D12PluginEventConfig eventConfig; + eventConfig.graphicsQueueAccess = kUnityD3D12GraphicsQueueAccess_DontCare; + eventConfig.flags = kUnityD3D12EventConfigFlag_EnsurePreviousFrameSubmission | kUnityD3D12EventConfigFlag_FlushCommandBuffers | kUnityD3D12EventConfigFlag_SyncWorkerThreads | kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState; + eventConfig.ensureActiveRenderTextureIsBound = false; + s_GraphicsD3D12->ConfigureEvent(BaseEventId + FSR3PluginEvent::eExecute, &eventConfig); break; } case kUnityGfxRendererVulkan: @@ -129,6 +135,12 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev UNITY_LOG_ERROR(s_Log, "Could not obtain Vulkan Graphics interface!"); return; } + + UnityVulkanPluginEventConfig eventConfig; + eventConfig.graphicsQueueAccess = kUnityVulkanGraphicsQueueAccess_DontCare; + eventConfig.flags = kUnityVulkanEventConfigFlag_EnsurePreviousFrameSubmission | kUnityVulkanEventConfigFlag_FlushCommandBuffers | kUnityVulkanEventConfigFlag_SyncWorkerThreads | kUnityVulkanEventConfigFlag_ModifiesCommandBuffersState; + eventConfig.renderPassPrecondition = kUnityVulkanRenderPass_EnsureInside; + s_GraphicsVulkan->ConfigureEvent(BaseEventId + FSR3PluginEvent::eExecute, &eventConfig); break; } }