#pragma once #include "UpscalerGraphicsDevice.h" #include #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 { public: FSR3Upscaler_FFXBase(IUnityInterfaces* unityInterfaces) : m_ffxModule(NULL) { m_Log = unityInterfaces->Get(); } 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 versionNames; std::vector 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; } void DoShutdown() override { if (m_ffxModule != nullptr) { FreeLibrary(m_ffxModule); m_ffxModule = nullptr; } } ffxFunctions m_ffxFunctions{}; private: IUnityLog* m_Log; HMODULE m_ffxModule; };