|
|
|
@ -16,7 +16,7 @@ |
|
|
|
#include "ffx-fsr2-api/ffx_fsr2.h"
|
|
|
|
#include "ffx-fsr2-api/dx12/ffx_fsr2_dx12.h"
|
|
|
|
|
|
|
|
#include "FSR3UnityTypes.h"
|
|
|
|
#include "FSR2UnityTypes.h"
|
|
|
|
|
|
|
|
static const int32_t BaseEventId = 0; |
|
|
|
|
|
|
|
@ -33,16 +33,16 @@ 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); |
|
|
|
|
|
|
|
struct FSR3Feature |
|
|
|
struct FSR2Feature |
|
|
|
{ |
|
|
|
FfxFsr2Context upscalingContext; |
|
|
|
uint32_t flags; |
|
|
|
bool isValid; |
|
|
|
|
|
|
|
FSR3TextureTable textureTable; |
|
|
|
FSR2TextureTable textureTable; |
|
|
|
}; |
|
|
|
|
|
|
|
static std::vector<FSR3Feature> s_Features; |
|
|
|
static std::vector<FSR2Feature> s_Features; |
|
|
|
static std::queue<uint32_t> s_FeatureSlots; |
|
|
|
static std::mutex s_FeatureMutex; |
|
|
|
|
|
|
|
@ -111,7 +111,7 @@ static uint32_t AllocateFeatureSlot() |
|
|
|
{ |
|
|
|
// Create a new feature if there are no free slots
|
|
|
|
uint32_t featureSlot = (uint32_t)s_Features.size(); |
|
|
|
s_Features.push_back(std::move(FSR3Feature())); |
|
|
|
s_Features.push_back(std::move(FSR2Feature())); |
|
|
|
return featureSlot; |
|
|
|
} |
|
|
|
|
|
|
|
@ -127,7 +127,7 @@ static void FreeFeatureSlot(uint32_t featureSlot) |
|
|
|
std::lock_guard<std::mutex> lock(s_FeatureMutex); |
|
|
|
|
|
|
|
s_FeatureSlots.push(featureSlot); |
|
|
|
memset(&s_Features[featureSlot], 0, sizeof(FSR3Feature)); |
|
|
|
memset(&s_Features[featureSlot], 0, sizeof(FSR2Feature)); |
|
|
|
} |
|
|
|
|
|
|
|
extern "C" bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_InitApi() |
|
|
|
@ -189,24 +189,24 @@ extern "C" uint32_t UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_CreateFeatu |
|
|
|
return AllocateFeatureSlot(); |
|
|
|
} |
|
|
|
|
|
|
|
extern "C" float UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetUpscaleRatioFromQualityMode(FSR3Quality qualityMode) |
|
|
|
extern "C" float UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetUpscaleRatioFromQualityMode(FSR2Quality qualityMode) |
|
|
|
{ |
|
|
|
switch (qualityMode) |
|
|
|
{ |
|
|
|
case FSR3Quality::qQuality: |
|
|
|
case FSR2Quality::qQuality: |
|
|
|
return 1.5f; |
|
|
|
case FSR3Quality::qBalanced: |
|
|
|
case FSR2Quality::qBalanced: |
|
|
|
return 1.7f; |
|
|
|
case FSR3Quality::qPerformance: |
|
|
|
case FSR2Quality::qPerformance: |
|
|
|
return 2.0f; |
|
|
|
case FSR3Quality::qUltraPerformance: |
|
|
|
case FSR2Quality::qUltraPerformance: |
|
|
|
return 3.0f; |
|
|
|
default: |
|
|
|
return 1.0f; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|
extern "C" bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_GetRenderResolutionFromQualityMode(FSR2Quality qualityMode, uint32_t displayWidth, uint32_t displayHeight, uint32_t* renderWidth, uint32_t* renderHeight) |
|
|
|
{ |
|
|
|
if (renderWidth == nullptr || renderHeight == nullptr) |
|
|
|
return false; |
|
|
|
@ -231,7 +231,7 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data) |
|
|
|
// User rendering code
|
|
|
|
switch (eventID) |
|
|
|
{ |
|
|
|
case BaseEventId + FSR3PluginEvent::eDestroyFeature: |
|
|
|
case BaseEventId + FSR2PluginEvent::eDestroyFeature: |
|
|
|
{ |
|
|
|
uint32_t featureSlot = (uint32_t)(int64_t)data; |
|
|
|
if (featureSlot < 0 || featureSlot >= s_Features.size()) |
|
|
|
@ -245,9 +245,9 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data) |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
case BaseEventId + FSR3PluginEvent::eExecute: |
|
|
|
case BaseEventId + FSR2PluginEvent::eExecute: |
|
|
|
{ |
|
|
|
auto* params = (FSR3CommandExecutionData*)data; |
|
|
|
auto* params = (FSR2CommandExecutionData*)data; |
|
|
|
if (params->featureSlot < 0 || params->featureSlot >= s_Features.size()) |
|
|
|
return; |
|
|
|
|
|
|
|
@ -294,14 +294,14 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data) |
|
|
|
ffxFsr2ContextDispatch(&feature.upscalingContext, &dispatchDescription); |
|
|
|
break; |
|
|
|
} |
|
|
|
case BaseEventId + FSR3PluginEvent::ePostExecute: |
|
|
|
case BaseEventId + FSR2PluginEvent::ePostExecute: |
|
|
|
{ |
|
|
|
auto* params = (FSR3CommandExecutionData*)data; |
|
|
|
auto* params = (FSR2CommandExecutionData*)data; |
|
|
|
break; |
|
|
|
} |
|
|
|
case BaseEventId + FSR3PluginEvent::eInit: |
|
|
|
case BaseEventId + FSR2PluginEvent::eInit: |
|
|
|
{ |
|
|
|
auto* params = (FSR3CommandInitializationData*)data; |
|
|
|
auto* params = (FSR2CommandInitializationData*)data; |
|
|
|
if (params->featureSlot < 0 || params->featureSlot >= s_Features.size()) |
|
|
|
return; |
|
|
|
|
|
|
|
@ -345,7 +345,7 @@ static void UNITY_INTERFACE_API OnSetTextureEvent(int eventID, void* data) |
|
|
|
{ |
|
|
|
if (clearTextureTable) |
|
|
|
{ |
|
|
|
memset(&feature.textureTable, 0, sizeof(FSR3TextureTable)); |
|
|
|
memset(&feature.textureTable, 0, sizeof(FSR2TextureTable)); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |