You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
5.2 KiB
172 lines
5.2 KiB
#include <stdint.h>
|
|
|
|
#include "UnityPluginAPI/IUnityInterface.h"
|
|
#include "UnityPluginAPI/IUnityLog.h"
|
|
#include "UnityPluginAPI/IUnityGraphics.h"
|
|
#include "UnityPluginAPI/IUnityRenderingExtensions.h"
|
|
//#include "UnityPluginAPI/IUnityGraphicsD3D12.h"
|
|
|
|
#include "FSR3UnityTypes.h"
|
|
|
|
static const int32_t BaseEventId = 0;
|
|
|
|
static IUnityInterfaces* s_UnityInterfaces = nullptr;
|
|
static IUnityLog* s_Log = nullptr;
|
|
static IUnityGraphics* s_Graphics = nullptr;
|
|
static UnityGfxRenderer s_RendererType = kUnityGfxRendererNull;
|
|
|
|
static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType);
|
|
static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data);
|
|
static void UNITY_INTERFACE_API OnSetTextureEvent(int eventID, void* data);
|
|
|
|
// Unity plugin load event
|
|
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
|
|
{
|
|
s_UnityInterfaces = unityInterfaces;
|
|
s_Log = unityInterfaces->Get<IUnityLog>();
|
|
s_Graphics = unityInterfaces->Get<IUnityGraphics>();
|
|
|
|
s_Graphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
|
|
|
// Run OnGraphicsDeviceEvent(initialize) manually on plugin load
|
|
// to not miss the event in case the graphics device is already initialized
|
|
OnGraphicsDeviceEvent(kUnityGfxDeviceEventInitialize);
|
|
}
|
|
|
|
// Unity plugin unload event
|
|
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload()
|
|
{
|
|
s_Graphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
|
}
|
|
|
|
static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType)
|
|
{
|
|
switch (eventType)
|
|
{
|
|
case kUnityGfxDeviceEventInitialize:
|
|
{
|
|
s_RendererType = s_Graphics->GetRenderer();
|
|
//TODO: user initialization code on graphics device initialization. For example, D3D11 resource creation.
|
|
break;
|
|
}
|
|
case kUnityGfxDeviceEventShutdown:
|
|
{
|
|
s_RendererType = kUnityGfxRendererNull;
|
|
//TODO: user graphics API code to call on graphics device shutdown.
|
|
break;
|
|
}
|
|
case kUnityGfxDeviceEventBeforeReset:
|
|
{
|
|
//TODO: user graphics API code to call before graphics device reset.
|
|
break;
|
|
}
|
|
case kUnityGfxDeviceEventAfterReset:
|
|
{
|
|
//TODO: user graphics API code to call after graphics device reset.
|
|
break;
|
|
}
|
|
};
|
|
}
|
|
|
|
extern "C" bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_InitApi()
|
|
{
|
|
// TODO: implement
|
|
return false;
|
|
}
|
|
|
|
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_ShutdownApi()
|
|
{
|
|
// TODO: implement
|
|
}
|
|
|
|
extern "C" uint32_t UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetDeviceVersion()
|
|
{
|
|
return 0x0u;
|
|
}
|
|
|
|
extern "C" UnityRenderingEventAndData UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetRenderEventCallback()
|
|
{
|
|
return OnRenderEventAndData;
|
|
}
|
|
|
|
extern "C" UnityRenderingEventAndData UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetSetTextureEventCallback()
|
|
{
|
|
return OnSetTextureEvent;
|
|
}
|
|
|
|
extern "C" uint32_t UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_CreateFeatureSlot()
|
|
{
|
|
// TODO: thread-safe allocation of slot
|
|
return 0u;
|
|
}
|
|
|
|
// TODO: use FSR2Quality enum for qualityMode
|
|
extern "C" bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetRenderResolutionFromQualityMode(FSR3Quality qualityMode, uint32_t displayWidth, uint32_t displayHeight, uint32_t* renderWidth, uint32_t* renderHeight)
|
|
{
|
|
// TODO: implement
|
|
return false;
|
|
}
|
|
|
|
// TODO: use FSR2Quality enum for qualityMode
|
|
extern "C" float UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetUpscaleRatioFromQualityMode(FSR3Quality qualityMode)
|
|
{
|
|
// TODO: implement
|
|
return 1.0f;
|
|
}
|
|
|
|
extern "C" int32_t UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetBaseEventId()
|
|
{
|
|
return BaseEventId;
|
|
}
|
|
|
|
// Plugin function to handle a specific rendering event
|
|
static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data)
|
|
{
|
|
// User rendering code
|
|
switch (eventID)
|
|
{
|
|
case BaseEventId + FSR3PluginEvent::eDestroyFeature:
|
|
{
|
|
// TODO: thread-safe freeing of slot (data = feature slot int64_t, cast as pointer)
|
|
uint32_t featureSlot = (uint32_t)(int64_t)data;
|
|
break;
|
|
}
|
|
case BaseEventId + FSR3PluginEvent::eExecute:
|
|
{
|
|
auto* params = (FSR3CommandExecutionData*)data;
|
|
break;
|
|
}
|
|
case BaseEventId + FSR3PluginEvent::ePostExecute:
|
|
{
|
|
auto* params = (FSR3CommandExecutionData*)data;
|
|
break;
|
|
}
|
|
case BaseEventId + FSR3PluginEvent::eInit:
|
|
{
|
|
auto* params = (FSR3CommandInitializationData*)data;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void UNITY_INTERFACE_API OnSetTextureEvent(int eventID, void* data)
|
|
{
|
|
// TODO userData field in UnityRenderingExtTextureUpdateParamsV2 is an encoded value: (featureId & (int) ushort.MaxValue) << 16 | (textureSlot & (int) short.MaxValue) << 1 | (clearTextureTable ? 1 : 0);
|
|
auto* params = (UnityRenderingExtTextureUpdateParamsV2*)data;
|
|
|
|
// TODO: featureId => featureSlot
|
|
// TODO: textureSlot => FSR3Textures enum (could just use as numeric index to calculate a pointer offset)
|
|
|
|
// User rendering code
|
|
switch (eventID)
|
|
{
|
|
case kUnityRenderingExtEventUpdateTextureBeginV2:
|
|
{
|
|
break;
|
|
}
|
|
case kUnityRenderingExtEventUpdateTextureEndV2:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|