|
|
|
@ -11,8 +11,6 @@ |
|
|
|
|
|
|
|
#include "SwapChainTrampoline.h"
|
|
|
|
|
|
|
|
static const int32_t BaseEventId = 313; |
|
|
|
|
|
|
|
static IUnityInterfaces* s_UnityInterfaces = nullptr; |
|
|
|
static IUnityLog* s_Log = nullptr; |
|
|
|
static IUnityGraphics* s_Graphics = nullptr; |
|
|
|
@ -22,6 +20,7 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev |
|
|
|
static void UNITY_INTERFACE_API OnRenderEventAndData(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 IUnityGraphicsD3D12v7* s_GraphicsD3D12 = nullptr; |
|
|
|
@ -33,6 +32,8 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnit |
|
|
|
s_Log = unityInterfaces->Get<IUnityLog>(); |
|
|
|
s_Graphics = unityInterfaces->Get<IUnityGraphics>(); |
|
|
|
|
|
|
|
s_BaseEventId = s_Graphics->ReserveEventIDRange((int)ePluginEventCount); |
|
|
|
|
|
|
|
s_Graphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent); |
|
|
|
|
|
|
|
// Run OnGraphicsDeviceEvent(initialize) manually on plugin load
|
|
|
|
@ -90,13 +91,13 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev |
|
|
|
eventConfig.graphicsQueueAccess = kUnityD3D12GraphicsQueueAccess_DontCare; |
|
|
|
eventConfig.flags = kUnityD3D12EventConfigFlag_EnsurePreviousFrameSubmission | kUnityD3D12EventConfigFlag_FlushCommandBuffers | kUnityD3D12EventConfigFlag_SyncWorkerThreads | kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState; |
|
|
|
eventConfig.ensureActiveRenderTextureIsBound = false; |
|
|
|
graphicsD3D12->ConfigureEvent(BaseEventId + FSR3PluginEvent::eExecute, &eventConfig); |
|
|
|
graphicsD3D12->ConfigureEvent(s_BaseEventId + FSR3PluginEvent::eExecute, &eventConfig); |
|
|
|
|
|
|
|
UnityD3D12PluginEventConfig eventConfigSC{}; |
|
|
|
eventConfigSC.graphicsQueueAccess = kUnityD3D12GraphicsQueueAccess_Allow; |
|
|
|
eventConfigSC.flags = kUnityD3D12EventConfigFlag_EnsurePreviousFrameSubmission | kUnityD3D12EventConfigFlag_FlushCommandBuffers | kUnityD3D12EventConfigFlag_SyncWorkerThreads; |
|
|
|
eventConfigSC.ensureActiveRenderTextureIsBound = false; |
|
|
|
graphicsD3D12->ConfigureEvent(BaseEventId + FSR3PluginEvent::eSwapChain, &eventConfigSC); |
|
|
|
graphicsD3D12->ConfigureEvent(s_BaseEventId + FSR3PluginEvent::eSwapChain, &eventConfigSC); |
|
|
|
break; |
|
|
|
} |
|
|
|
case kUnityGfxRendererVulkan: |
|
|
|
@ -114,7 +115,7 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev |
|
|
|
eventConfig.graphicsQueueAccess = kUnityVulkanGraphicsQueueAccess_DontCare; |
|
|
|
eventConfig.flags = kUnityVulkanEventConfigFlag_EnsurePreviousFrameSubmission | kUnityVulkanEventConfigFlag_FlushCommandBuffers | kUnityVulkanEventConfigFlag_SyncWorkerThreads | kUnityVulkanEventConfigFlag_ModifiesCommandBuffersState; |
|
|
|
eventConfig.renderPassPrecondition = kUnityVulkanRenderPass_EnsureInside; |
|
|
|
graphicsVulkan->ConfigureEvent(BaseEventId + FSR3PluginEvent::eExecute, &eventConfig); |
|
|
|
graphicsVulkan->ConfigureEvent(s_BaseEventId + FSR3PluginEvent::eExecute, &eventConfig); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -292,7 +293,7 @@ extern "C" bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetRenderResolu |
|
|
|
|
|
|
|
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
|
|
|
|
@ -302,27 +303,27 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data) |
|
|
|
return; |
|
|
|
|
|
|
|
// User rendering code
|
|
|
|
switch (eventID) |
|
|
|
switch (eventID - s_BaseEventId) |
|
|
|
{ |
|
|
|
case BaseEventId + FSR3PluginEvent::eDestroyFeature: |
|
|
|
case FSR3PluginEvent::eDestroyFeature: |
|
|
|
{ |
|
|
|
uint32_t featureSlot = (uint32_t)(intptr_t)data; |
|
|
|
s_Upscaler->DestroyFeature(featureSlot); |
|
|
|
break; |
|
|
|
} |
|
|
|
case BaseEventId + FSR3PluginEvent::eExecute: |
|
|
|
case FSR3PluginEvent::eExecute: |
|
|
|
{ |
|
|
|
auto* execData = (FSR3CommandExecutionData*)data; |
|
|
|
s_Upscaler->Execute(execData); |
|
|
|
break; |
|
|
|
} |
|
|
|
case BaseEventId + FSR3PluginEvent::ePostExecute: |
|
|
|
case FSR3PluginEvent::ePostExecute: |
|
|
|
{ |
|
|
|
auto* execData = (FSR3CommandExecutionData*)data; |
|
|
|
s_Upscaler->PostExecute(execData); |
|
|
|
break; |
|
|
|
} |
|
|
|
case BaseEventId + FSR3PluginEvent::eInit: |
|
|
|
case FSR3PluginEvent::eInit: |
|
|
|
{ |
|
|
|
auto* initData = (FSR3CommandInitializationData*)data; |
|
|
|
s_Upscaler->InitFeature(initData); |
|
|
|
|