mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-05-12 20:51:00 +00:00
Added check to prevent crashes at UpdateFFxApiProvider when using amd_fidelityfx_dx12.dll & amd_fidelityfx_framegeneration_dx12.dll combo
This commit is contained in:
@@ -171,6 +171,25 @@ void CheckForGPU()
|
||||
LOG_INFO("Fsr4Update: {}", Config::Instance()->Fsr4Update.value_or_default());
|
||||
}
|
||||
|
||||
struct ffxProviderInterface
|
||||
{
|
||||
uint64_t versionId;
|
||||
const char* versionName;
|
||||
PVOID canProvide;
|
||||
PVOID createContext;
|
||||
PVOID destroyContext;
|
||||
PVOID configure;
|
||||
PVOID query;
|
||||
PVOID dispatch;
|
||||
};
|
||||
|
||||
struct ExternalProviderData
|
||||
{
|
||||
uint32_t structVersion = 2;
|
||||
uint64_t descType;
|
||||
ffxProviderInterface provider;
|
||||
};
|
||||
|
||||
struct AmdExtFfxApi : public IAmdExtFfxApi
|
||||
{
|
||||
PFN_UpdateFfxApiProvider o_UpdateFfxApiProvider = nullptr;
|
||||
@@ -179,6 +198,15 @@ struct AmdExtFfxApi : public IAmdExtFfxApi
|
||||
{
|
||||
LOG_INFO("UpdateFfxApiProvider called");
|
||||
|
||||
// To prevent crashes with amd_fidelityfx_dx12.dll & amd_fidelityfx_framegeneration_dx12.dll combo added this
|
||||
// check after ML FG update this should be disabled!
|
||||
auto providerData = reinterpret_cast<ExternalProviderData*>(pData);
|
||||
if (providerData->descType >= 0x00020001u && providerData->descType <= 0x00030009u)
|
||||
{
|
||||
LOG_ERROR("Skip update for FG");
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (o_UpdateFfxApiProvider == nullptr)
|
||||
{
|
||||
fsr4Module = NtdllProxy::LoadLibraryExW_Ldr(L"amdxcffx64.dll", NULL, 0);
|
||||
@@ -235,7 +263,9 @@ struct AmdExtFfxApi : public IAmdExtFfxApi
|
||||
if (o_UpdateFfxApiProvider != nullptr)
|
||||
{
|
||||
State::DisableChecks(1);
|
||||
|
||||
auto result = o_UpdateFfxApiProvider(pData, dataSizeInBytes);
|
||||
|
||||
LOG_INFO("UpdateFfxApiProvider called, result: {} ({:X})", result == S_OK ? "Ok" : "Error", (UINT) result);
|
||||
State::EnableChecks(1);
|
||||
return result;
|
||||
@@ -452,4 +482,4 @@ HRESULT STDMETHODCALLTYPE hkAmdExtD3DCreateInterface(IUnknown* pOuter, REFIID ri
|
||||
return o_AmdExtD3DCreateInterface(pOuter, riid, ppvObject);
|
||||
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,11 +176,8 @@ class FfxApiProxy
|
||||
}
|
||||
}
|
||||
|
||||
if (_D3D12_CreateContext == nullptr)
|
||||
{
|
||||
InitFfxDx12_SR();
|
||||
InitFfxDx12_FG();
|
||||
}
|
||||
InitFfxDx12_SR();
|
||||
InitFfxDx12_FG();
|
||||
|
||||
bool loadResult = _D3D12_CreateContext != nullptr;
|
||||
|
||||
@@ -545,6 +542,11 @@ class FfxApiProxy
|
||||
{
|
||||
auto isFg = IsFGType(desc->type);
|
||||
|
||||
if (isFg && _dllDx12_FG != nullptr)
|
||||
return _D3D12_CreateContext_FG(context, desc, memCb);
|
||||
else if (!isFg && _dllDx12_SR != nullptr)
|
||||
return _D3D12_CreateContext_SR(context, desc, memCb);
|
||||
|
||||
if (_dllDx12 != nullptr && !(isFg && _skipFGCreateCalls) && !(!isFg && _skipSRCreateCalls))
|
||||
{
|
||||
if (isFg)
|
||||
@@ -562,11 +564,6 @@ class FfxApiProxy
|
||||
return result;
|
||||
}
|
||||
|
||||
if (isFg && _dllDx12_FG != nullptr)
|
||||
return _D3D12_CreateContext_FG(context, desc, memCb);
|
||||
else if (!isFg && _dllDx12_SR != nullptr)
|
||||
return _D3D12_CreateContext_SR(context, desc, memCb);
|
||||
|
||||
return FFX_API_RETURN_NO_PROVIDER;
|
||||
}
|
||||
|
||||
@@ -603,6 +600,11 @@ class FfxApiProxy
|
||||
{
|
||||
auto isFg = IsFGType(desc->type);
|
||||
|
||||
if (isFg && _dllDx12_FG != nullptr)
|
||||
return _D3D12_Configure_FG(context, desc);
|
||||
else if (!isFg && _dllDx12_SR != nullptr)
|
||||
return _D3D12_Configure_SR(context, desc);
|
||||
|
||||
if (_dllDx12 != nullptr && !(isFg && _skipFGConfigureCalls) && !(!isFg && _skipSRConfigureCalls))
|
||||
{
|
||||
if (isFg)
|
||||
@@ -620,11 +622,6 @@ class FfxApiProxy
|
||||
return result;
|
||||
}
|
||||
|
||||
if (isFg && _dllDx12_FG != nullptr)
|
||||
return _D3D12_Configure_FG(context, desc);
|
||||
else if (!isFg && _dllDx12_SR != nullptr)
|
||||
return _D3D12_Configure_SR(context, desc);
|
||||
|
||||
return FFX_API_RETURN_NO_PROVIDER;
|
||||
}
|
||||
|
||||
@@ -632,6 +629,11 @@ class FfxApiProxy
|
||||
{
|
||||
auto isFg = IsFGType(desc->type);
|
||||
|
||||
if (isFg && _dllDx12_FG != nullptr)
|
||||
return _D3D12_Query_FG(context, desc);
|
||||
else if (!isFg && _dllDx12_SR != nullptr)
|
||||
return _D3D12_Query_SR(context, desc);
|
||||
|
||||
if (_dllDx12 != nullptr && !(isFg && _skipFGQueryCalls) && !(!isFg && _skipSRQueryCalls))
|
||||
{
|
||||
if (isFg)
|
||||
@@ -649,11 +651,6 @@ class FfxApiProxy
|
||||
return result;
|
||||
}
|
||||
|
||||
if (isFg && _dllDx12_FG != nullptr)
|
||||
return _D3D12_Query_FG(context, desc);
|
||||
else if (!isFg && _dllDx12_SR != nullptr)
|
||||
return _D3D12_Query_SR(context, desc);
|
||||
|
||||
return FFX_API_RETURN_NO_PROVIDER;
|
||||
}
|
||||
|
||||
@@ -661,6 +658,11 @@ class FfxApiProxy
|
||||
{
|
||||
auto isFg = IsFGType(desc->type);
|
||||
|
||||
if (isFg && _dllDx12_FG != nullptr)
|
||||
return _D3D12_Dispatch_FG(context, desc);
|
||||
else if (!isFg && _dllDx12_SR != nullptr)
|
||||
return _D3D12_Dispatch_SR(context, desc);
|
||||
|
||||
if (_dllDx12 != nullptr && !(isFg && _skipFGDispatchCalls) && !(!isFg && _skipSRDispatchCalls))
|
||||
{
|
||||
if (isFg)
|
||||
@@ -678,11 +680,6 @@ class FfxApiProxy
|
||||
return result;
|
||||
}
|
||||
|
||||
if (isFg && _dllDx12_FG != nullptr)
|
||||
return _D3D12_Dispatch_FG(context, desc);
|
||||
else if (!isFg && _dllDx12_SR != nullptr)
|
||||
return _D3D12_Dispatch_SR(context, desc);
|
||||
|
||||
return FFX_API_RETURN_NO_PROVIDER;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user