Browse Source
Moved handling of FidelityFX library and dynamic function loading into a separate base class, and reworked some things so that only UpscalerGraphicsDevice needs to access the mutex
master
Moved handling of FidelityFX library and dynamic function loading into a separate base class, and reworked some things so that only UpscalerGraphicsDevice needs to access the mutex
master
6 changed files with 135 additions and 104 deletions
-
1FSR3UnityPlugin.vcxproj
-
3FSR3UnityPlugin.vcxproj.filters
-
101FSR3Upscaler_DX12.cpp
-
31FSR3Upscaler_DX12.h
-
94FSR3Upscaler_FFXBase.h
-
9UpscalerGraphicsDevice.h
@ -0,0 +1,94 @@ |
|||
#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; |
|||
} |
|||
|
|||
void DoShutdown() override |
|||
{ |
|||
if (m_ffxModule != nullptr) |
|||
{ |
|||
FreeLibrary(m_ffxModule); |
|||
m_ffxModule = nullptr; |
|||
} |
|||
} |
|||
|
|||
ffxFunctions m_ffxFunctions{}; |
|||
|
|||
private: |
|||
IUnityLog* m_Log; |
|||
HMODULE m_ffxModule; |
|||
}; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue