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.
104 lines
2.8 KiB
104 lines
2.8 KiB
#pragma once
|
|
#include "UpscalerGraphicsDevice.h"
|
|
|
|
#include <sstream>
|
|
|
|
#include "UnityPluginAPI/IUnityLog.h"
|
|
|
|
#include "ffx_api/ffx_upscale.hpp"
|
|
#include "ffx_api/ffx_api_loader.h"
|
|
|
|
struct FSR3Feature_FFX
|
|
{
|
|
ffx::Context upscalingContext;
|
|
|
|
uint32_t upscaleSizeWidth;
|
|
uint32_t upscaleSizeHeight;
|
|
uint32_t flags;
|
|
|
|
uint64_t dispatchFrameValue;
|
|
|
|
FSR3TextureTable textureTable;
|
|
};
|
|
|
|
class FSR3Upscaler_FFXBase : UpscalerGraphicsDevice<FSR3Feature_FFX>
|
|
{
|
|
public:
|
|
FSR3Upscaler_FFXBase(IUnityInterfaces* unityInterfaces)
|
|
: m_ffxModule(NULL)
|
|
{
|
|
m_Log = unityInterfaces->Get<IUnityLog>();
|
|
}
|
|
|
|
protected:
|
|
bool LoadFidelityFXLibrary(_In_ LPCWSTR lpLibFileName, void* device)
|
|
{
|
|
m_ffxModule = LoadLibrary(lpLibFileName);
|
|
if (m_ffxModule == NULL)
|
|
{
|
|
UNITY_LOG_ERROR(m_Log, "Failed to load FidelityFX library!");
|
|
return false;
|
|
}
|
|
|
|
ffxLoadFunctions(&m_ffxFunctions, m_ffxModule);
|
|
if (m_ffxFunctions.CreateContext == nullptr)
|
|
{
|
|
UNITY_LOG_ERROR(m_Log, "Failed to load FidelityFX library functions!");
|
|
return false;
|
|
}
|
|
|
|
// Check that we can actually create an upscaler with this library
|
|
ffx::QueryDescGetVersions versionQuery{};
|
|
versionQuery.createDescType = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE;
|
|
versionQuery.device = device;
|
|
uint64_t versionCount = 0;
|
|
versionQuery.outputCount = &versionCount;
|
|
m_ffxFunctions.Query(nullptr, &versionQuery.header);
|
|
|
|
if (versionCount == 0)
|
|
{
|
|
UNITY_LOG_ERROR(m_Log, "Failed to load FidelityFX upscaler versions!");
|
|
return false;
|
|
}
|
|
|
|
// Obtain the default upscaler version and log its name
|
|
std::vector<const char*> versionNames;
|
|
std::vector<uint64_t> versionIds;
|
|
versionIds.resize(versionCount);
|
|
versionNames.resize(versionCount);
|
|
versionQuery.versionIds = versionIds.data();
|
|
versionQuery.versionNames = versionNames.data();
|
|
m_ffxFunctions.Query(nullptr, &versionQuery.header);
|
|
|
|
std::stringstream ss;
|
|
ss << "Loaded FidelityFX upscaler: FSR " << versionNames[0];
|
|
UNITY_LOG(m_Log, ss.str().c_str());
|
|
|
|
return true;
|
|
}
|
|
|
|
bool IsValidFeature(FSR3Feature_FFX& feature) override
|
|
{
|
|
return feature.upscalingContext != nullptr;
|
|
}
|
|
|
|
void DestroyContext(FSR3Feature_FFX& feature) override
|
|
{
|
|
m_ffxFunctions.DestroyContext(&feature.upscalingContext, nullptr);
|
|
}
|
|
|
|
void DoShutdown() override
|
|
{
|
|
if (m_ffxModule != nullptr)
|
|
{
|
|
FreeLibrary(m_ffxModule);
|
|
m_ffxModule = nullptr;
|
|
}
|
|
}
|
|
|
|
ffxFunctions m_ffxFunctions{};
|
|
|
|
private:
|
|
IUnityLog* m_Log;
|
|
HMODULE m_ffxModule;
|
|
};
|