@ -9,8 +9,6 @@
# include "FSR3Upscaler_DX12.h"
# include "FSR3Upscaler_DX12.h"
# include "FSR3Upscaler_Vulkan.h"
# include "FSR3Upscaler_Vulkan.h"
static const int32_t BaseEventId = 313 ;
static IUnityInterfaces * s_UnityInterfaces = nullptr ;
static IUnityInterfaces * s_UnityInterfaces = nullptr ;
static IUnityLog * s_Log = nullptr ;
static IUnityLog * s_Log = nullptr ;
static IUnityGraphics * s_Graphics = nullptr ;
static IUnityGraphics * s_Graphics = nullptr ;
@ -20,6 +18,7 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev
static void UNITY_INTERFACE_API OnRenderEventAndData ( int eventID , void * data ) ;
static void UNITY_INTERFACE_API OnRenderEventAndData ( int eventID , void * data ) ;
static void UNITY_INTERFACE_API OnSetTextureEvent ( int eventID , void * data ) ;
static void UNITY_INTERFACE_API OnSetTextureEvent ( int eventID , void * data ) ;
static int32_t s_BaseEventId = 0 ;
static IUpscaler * s_Upscaler = nullptr ;
static IUpscaler * s_Upscaler = nullptr ;
// Unity plugin load event
// Unity plugin load event
@ -29,6 +28,8 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnit
s_Log = unityInterfaces - > Get < IUnityLog > ( ) ;
s_Log = unityInterfaces - > Get < IUnityLog > ( ) ;
s_Graphics = unityInterfaces - > Get < IUnityGraphics > ( ) ;
s_Graphics = unityInterfaces - > Get < IUnityGraphics > ( ) ;
s_BaseEventId = s_Graphics - > ReserveEventIDRange ( ( int ) ePluginEventCount ) ;
s_Graphics - > RegisterDeviceEventCallback ( OnGraphicsDeviceEvent ) ;
s_Graphics - > RegisterDeviceEventCallback ( OnGraphicsDeviceEvent ) ;
// Run OnGraphicsDeviceEvent(initialize) manually on plugin load
// Run OnGraphicsDeviceEvent(initialize) manually on plugin load
@ -84,7 +85,7 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev
eventConfig . graphicsQueueAccess = kUnityD3D12GraphicsQueueAccess_DontCare ;
eventConfig . graphicsQueueAccess = kUnityD3D12GraphicsQueueAccess_DontCare ;
eventConfig . flags = kUnityD3D12EventConfigFlag_EnsurePreviousFrameSubmission | kUnityD3D12EventConfigFlag_FlushCommandBuffers | kUnityD3D12EventConfigFlag_SyncWorkerThreads | kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState ;
eventConfig . flags = kUnityD3D12EventConfigFlag_EnsurePreviousFrameSubmission | kUnityD3D12EventConfigFlag_FlushCommandBuffers | kUnityD3D12EventConfigFlag_SyncWorkerThreads | kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState ;
eventConfig . ensureActiveRenderTextureIsBound = false ;
eventConfig . ensureActiveRenderTextureIsBound = false ;
graphicsD3D12 - > ConfigureEvent ( BaseEventId + FSR3PluginEvent : : eExecute , & eventConfig ) ;
graphicsD3D12 - > ConfigureEvent ( s_ BaseEventId + FSR3PluginEvent : : eExecute , & eventConfig ) ;
break ;
break ;
}
}
case kUnityGfxRendererVulkan :
case kUnityGfxRendererVulkan :
@ -102,7 +103,7 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev
eventConfig . graphicsQueueAccess = kUnityVulkanGraphicsQueueAccess_DontCare ;
eventConfig . graphicsQueueAccess = kUnityVulkanGraphicsQueueAccess_DontCare ;
eventConfig . flags = kUnityVulkanEventConfigFlag_EnsurePreviousFrameSubmission | kUnityVulkanEventConfigFlag_FlushCommandBuffers | kUnityVulkanEventConfigFlag_SyncWorkerThreads | kUnityVulkanEventConfigFlag_ModifiesCommandBuffersState ;
eventConfig . flags = kUnityVulkanEventConfigFlag_EnsurePreviousFrameSubmission | kUnityVulkanEventConfigFlag_FlushCommandBuffers | kUnityVulkanEventConfigFlag_SyncWorkerThreads | kUnityVulkanEventConfigFlag_ModifiesCommandBuffersState ;
eventConfig . renderPassPrecondition = kUnityVulkanRenderPass_EnsureInside ;
eventConfig . renderPassPrecondition = kUnityVulkanRenderPass_EnsureInside ;
graphicsVulkan - > ConfigureEvent ( BaseEventId + FSR3PluginEvent : : eExecute , & eventConfig ) ;
graphicsVulkan - > ConfigureEvent ( s_ BaseEventId + FSR3PluginEvent : : eExecute , & eventConfig ) ;
break ;
break ;
}
}
}
}
@ -204,7 +205,7 @@ extern "C" bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetRenderResolu
extern " C " int32_t UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetBaseEventId ( )
extern " C " int32_t UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetBaseEventId ( )
{
{
return BaseEventId ;
return s_ BaseEventId;
}
}
// Plugin function to handle a specific rendering event
// Plugin function to handle a specific rendering event
@ -214,27 +215,27 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data)
return ;
return ;
// User rendering code
// User rendering code
switch ( eventID )
switch ( eventID - s_BaseEventId )
{
{
case BaseEventId + FSR3PluginEvent : : eDestroyFeature :
case FSR3PluginEvent : : eDestroyFeature :
{
{
uint32_t featureSlot = ( uint32_t ) ( intptr_t ) data ;
uint32_t featureSlot = ( uint32_t ) ( intptr_t ) data ;
s_Upscaler - > DestroyFeature ( featureSlot ) ;
s_Upscaler - > DestroyFeature ( featureSlot ) ;
break ;
break ;
}
}
case BaseEventId + FSR3PluginEvent : : eExecute :
case FSR3PluginEvent : : eExecute :
{
{
auto * execData = ( FSR3CommandExecutionData * ) data ;
auto * execData = ( FSR3CommandExecutionData * ) data ;
s_Upscaler - > Execute ( execData ) ;
s_Upscaler - > Execute ( execData ) ;
break ;
break ;
}
}
case BaseEventId + FSR3PluginEvent : : ePostExecute :
case FSR3PluginEvent : : ePostExecute :
{
{
auto * execData = ( FSR3CommandExecutionData * ) data ;
auto * execData = ( FSR3CommandExecutionData * ) data ;
s_Upscaler - > PostExecute ( execData ) ;
s_Upscaler - > PostExecute ( execData ) ;
break ;
break ;
}
}
case BaseEventId + FSR3PluginEvent : : eInit :
case FSR3PluginEvent : : eInit :
{
{
auto * initData = ( FSR3CommandInitializationData * ) data ;
auto * initData = ( FSR3CommandInitializationData * ) data ;
s_Upscaler - > InitFeature ( initData ) ;
s_Upscaler - > InitFeature ( initData ) ;