mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-09-28 16:26:46 +00:00
prevent crash with non standard fsr2/3 implementations
This commit is contained in:
+2
-2
@@ -285,8 +285,8 @@ public:
|
||||
|
||||
IFeature* CurrentFeature = nullptr;
|
||||
|
||||
ID3D12Device* lastCreatedD3D12Device = nullptr;
|
||||
ID3D11Device* lastCreatedD3D11Device = nullptr;
|
||||
std::vector<ID3D12Device*> d3d12Devices;
|
||||
std::vector<ID3D11Device*> d3d11Devices;
|
||||
|
||||
bool Reload(std::filesystem::path iniPath);
|
||||
bool LoadFromPath(const wchar_t* InPath);
|
||||
|
||||
+38
-38
@@ -362,29 +362,6 @@ static Fsr212::FfxErrorCode ffxFsr2ContextCreate_Dx12(Fsr212::FfxFsr2Context* co
|
||||
if (contextDescription == nullptr || contextDescription->device == nullptr)
|
||||
return Fsr212::FFX_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
// Added for FMF2, but not helped
|
||||
if (((IUnknown*)contextDescription->device)->QueryInterface(IID_PPV_ARGS(&_d3d12Device)) != S_OK)
|
||||
{
|
||||
LOG_WARN("Not D3D12Device: {:X}", (size_t)contextDescription->device);
|
||||
|
||||
if (Config::Instance()->lastCreatedD3D12Device != nullptr)
|
||||
{
|
||||
LOG_WARN("using last created D3D12 device!");
|
||||
contextDescription->device = Config::Instance()->lastCreatedD3D12Device;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Fsr212::FFX_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_d3d12Device->Release();
|
||||
}
|
||||
|
||||
if (_d3d12Device == nullptr)
|
||||
_d3d12Device = (ID3D12Device*)contextDescription->device;
|
||||
|
||||
auto ccResult = o_ffxFsr2ContextCreate_Dx12(context, contextDescription);
|
||||
|
||||
if (ccResult != Fsr212::FFX_OK)
|
||||
@@ -393,6 +370,26 @@ static Fsr212::FfxErrorCode ffxFsr2ContextCreate_Dx12(Fsr212::FfxFsr2Context* co
|
||||
return ccResult;
|
||||
}
|
||||
|
||||
// check for d3d12 device
|
||||
// to prevent crashes when game is using custom interface and
|
||||
// contextDescription->device is not a d3d12 device
|
||||
if (_d3d12Device == nullptr)
|
||||
{
|
||||
auto bDevice = (ID3D12Device*)contextDescription->device;
|
||||
|
||||
for (size_t i = 0; i < Config::Instance()->d3d12Devices.size(); i++)
|
||||
{
|
||||
if (Config::Instance()->d3d12Devices[i] == bDevice)
|
||||
{
|
||||
_d3d12Device = bDevice;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_d3d12Device == nullptr)
|
||||
return ccResult; // _d3d12Device = Config::Instance()->d3d12Devices[Config::Instance()->d3d12Devices.size() - 1];
|
||||
|
||||
NVSDK_NGX_FeatureCommonInfo fcInfo{};
|
||||
wchar_t const** paths = new const wchar_t* [1];
|
||||
auto dllPath = Util::DllPath().remove_filename().wstring();
|
||||
@@ -584,6 +581,9 @@ static Fsr212::FfxErrorCode ffxFsr2TinyContextDispatch_Dx12(Fsr212::FfxFsr2Conte
|
||||
// Tramboline method
|
||||
static Fsr212::FfxErrorCode ffxFsr2ContextDispatchBase_Dx12(Fsr212::FfxFsr2Context* context, FfxFsr2DispatchDescriptionBase* dispatchDescription)
|
||||
{
|
||||
if (_d3d12Device == nullptr)
|
||||
return o_ffxFsr2ContextDispatch_Dx12(context, dispatchDescription);
|
||||
|
||||
// Tiny Tina's Wonderland
|
||||
if (o_ffxGetResourceFromDX12Resource_Dx12 != nullptr)
|
||||
return ffxFsr2TinyContextDispatch_Dx12(context, (FfxFsr2TinyDispatchDescription*)dispatchDescription);
|
||||
@@ -627,12 +627,12 @@ static Fsr212::FfxErrorCode ffxFsr2ContextDestroy_Dx12(Fsr212::FfxFsr2Context* c
|
||||
if (context == nullptr)
|
||||
return Fsr212::FFX_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
if (!_initParams.contains(context))
|
||||
return Fsr212::FFX_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
auto cdResult = o_ffxFsr2ContextDestroy_Dx12(context);
|
||||
LOG_INFO("result: {:X}", (UINT)cdResult);
|
||||
|
||||
if (!_initParams.contains(context) || _d3d12Device == nullptr)
|
||||
return cdResult;
|
||||
|
||||
if (_contexts.contains(context))
|
||||
NVSDK_NGX_D3D12_ReleaseFeature(_contexts[context]);
|
||||
|
||||
@@ -811,11 +811,11 @@ void HookFSR2ExeInputs()
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
|
||||
//if (o_ffxFsr2GetScratchMemorySizeDX12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr2GetScratchMemorySizeDX12, hk_ffxFsr2GetScratchMemorySizeDX12);
|
||||
if (o_ffxFsr2GetScratchMemorySizeDX12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2GetScratchMemorySizeDX12, hk_ffxFsr2GetScratchMemorySizeDX12);
|
||||
|
||||
//if (o_ffxFsr2GetInterfaceDX12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr2GetInterfaceDX12, hk_ffxFsr2GetInterfaceDX12);
|
||||
if (o_ffxFsr2GetInterfaceDX12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2GetInterfaceDX12, hk_ffxFsr2GetInterfaceDX12);
|
||||
|
||||
if (o_ffxGetResourceDX12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxGetResourceDX12, hk_ffxGetResourceBaseDX12);
|
||||
@@ -829,8 +829,8 @@ void HookFSR2ExeInputs()
|
||||
if (o_ffxFsr2ContextDispatch_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2ContextDispatch_Dx12, ffxFsr2ContextDispatchBase_Dx12);
|
||||
|
||||
//if (o_ffxFsr2ContextGenerateReactiveMask_Dx12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr2ContextGenerateReactiveMask_Dx12, ffxFsr2ContextGenerateReactiveMask_Dx12);
|
||||
if (o_ffxFsr2ContextGenerateReactiveMask_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2ContextGenerateReactiveMask_Dx12, ffxFsr2ContextGenerateReactiveMask_Dx12);
|
||||
|
||||
if (o_ffxFsr2ContextDestroy_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2ContextDestroy_Dx12, ffxFsr2ContextDestroy_Dx12);
|
||||
@@ -893,11 +893,11 @@ void HookFSR2Dx12Inputs(HMODULE module)
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
|
||||
//if (o_ffxFsr2GetScratchMemorySizeDX12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr2GetScratchMemorySizeDX12, hk_ffxFsr2GetScratchMemorySizeDX12);
|
||||
if (o_ffxFsr2GetScratchMemorySizeDX12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2GetScratchMemorySizeDX12, hk_ffxFsr2GetScratchMemorySizeDX12);
|
||||
|
||||
//if (o_ffxFsr2GetInterfaceDX12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr2GetInterfaceDX12, hk_ffxFsr2GetInterfaceDX12);
|
||||
if (o_ffxFsr2GetInterfaceDX12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2GetInterfaceDX12, hk_ffxFsr2GetInterfaceDX12);
|
||||
|
||||
if (o_ffxGetResourceDX12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxGetResourceDX12, hk_ffxGetResourceBaseDX12);
|
||||
@@ -954,8 +954,8 @@ void HookFSR2Inputs(HMODULE module)
|
||||
if (o_ffxFsr2ContextDispatch_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2ContextDispatch_Dx12, ffxFsr2ContextDispatchBase_Dx12);
|
||||
|
||||
//if (o_ffxFsr2ContextGenerateReactiveMask_Dx12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr2ContextGenerateReactiveMask_Dx12, ffxFsr2ContextGenerateReactiveMask_Dx12);
|
||||
if (o_ffxFsr2ContextGenerateReactiveMask_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2ContextGenerateReactiveMask_Dx12, ffxFsr2ContextGenerateReactiveMask_Dx12);
|
||||
|
||||
if (o_ffxFsr2ContextDestroy_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr2ContextDestroy_Dx12, ffxFsr2ContextDestroy_Dx12);
|
||||
|
||||
+58
-50
@@ -161,35 +161,17 @@ static std::optional<float> GetQualityOverrideRatioFfx(const Fsr3::FfxFsr3Upscal
|
||||
return output;
|
||||
}
|
||||
|
||||
typedef struct dummyDevice
|
||||
{
|
||||
char dummy[256];
|
||||
};
|
||||
|
||||
// FSR3 Upscaler
|
||||
static Fsr3::FfxErrorCode ffxFsr3ContextCreate_Dx12(Fsr3::FfxFsr3UpscalerContext* pContext, Fsr3::FfxFsr3UpscalerContextDescription* pContextDescription)
|
||||
{
|
||||
if (pContext == nullptr || pContextDescription->backendInterface.device == nullptr)
|
||||
return Fsr3::FFX_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
// Added for FMF2, but not helped
|
||||
if (((IUnknown*)pContextDescription->backendInterface.device)->QueryInterface(IID_PPV_ARGS(&_d3d12Device)) != S_OK)
|
||||
{
|
||||
LOG_WARN("Not D3D12Device: {:X}", (size_t)pContextDescription->backendInterface.device);
|
||||
|
||||
if (Config::Instance()->lastCreatedD3D12Device != nullptr)
|
||||
{
|
||||
LOG_WARN("using last created D3D12 device!");
|
||||
pContextDescription->backendInterface.device = Config::Instance()->lastCreatedD3D12Device;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Fsr3::FFX_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_d3d12Device->Release();
|
||||
}
|
||||
|
||||
if (_d3d12Device == nullptr)
|
||||
_d3d12Device = (ID3D12Device*)pContextDescription->backendInterface.device;
|
||||
|
||||
auto ccResult = o_ffxFsr3UpscalerContextCreate_Dx12(pContext, pContextDescription);
|
||||
|
||||
if (ccResult != Fsr3::FFX_OK)
|
||||
@@ -198,6 +180,26 @@ static Fsr3::FfxErrorCode ffxFsr3ContextCreate_Dx12(Fsr3::FfxFsr3UpscalerContext
|
||||
return ccResult;
|
||||
}
|
||||
|
||||
// check for d3d12 device
|
||||
// to prevent crashes when game is using custom interface and
|
||||
// contextDescription->device is not a d3d12 device
|
||||
if (_d3d12Device == nullptr)
|
||||
{
|
||||
auto bDevice = (ID3D12Device*)pContextDescription->backendInterface.device;
|
||||
|
||||
for (size_t i = 0; i < Config::Instance()->d3d12Devices.size(); i++)
|
||||
{
|
||||
if (Config::Instance()->d3d12Devices[i] == bDevice)
|
||||
{
|
||||
_d3d12Device = bDevice;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_d3d12Device == nullptr)
|
||||
return ccResult; // _d3d12Device = Config::Instance()->d3d12Devices[Config::Instance()->d3d12Devices.size() - 1];
|
||||
|
||||
NVSDK_NGX_FeatureCommonInfo fcInfo{};
|
||||
wchar_t const** paths = new const wchar_t* [1];
|
||||
auto dllPath = Util::DllPath().remove_filename().wstring();
|
||||
@@ -238,8 +240,11 @@ static Fsr3::FfxErrorCode ffxFsr3ContextCreate_Dx12(Fsr3::FfxFsr3UpscalerContext
|
||||
|
||||
static Fsr3::FfxErrorCode ffxFsr3ContextDispatch_Dx12(Fsr3::FfxFsr3UpscalerContext* pContext, Fsr3::FfxFsr3UpscalerDispatchDescription* pDispatchDescription)
|
||||
{
|
||||
if (pDispatchDescription == nullptr || pContext == nullptr || pDispatchDescription->commandList == nullptr || _d3d12Device == nullptr)
|
||||
return Fsr3::FFX_ERROR_INVALID_ARGUMENT;
|
||||
if(_d3d12Device == nullptr)
|
||||
return o_ffxFsr3UpscalerContextDispatch_Dx12(pContext, pDispatchDescription);
|
||||
|
||||
if (pDispatchDescription == nullptr || pContext == nullptr || pDispatchDescription->commandList == nullptr)
|
||||
return Fsr3::FFX_ERROR_BACKEND_API_ERROR;
|
||||
|
||||
// If not in contexts list create and add context
|
||||
if (!_contexts.contains(pContext) && _initParams.contains(pContext) && !CreateDLSSContext(pContext, pDispatchDescription))
|
||||
@@ -289,24 +294,24 @@ static Fsr3::FfxErrorCode ffxFsr3ContextDispatch_Dx12(Fsr3::FfxFsr3UpscalerConte
|
||||
|
||||
static Fsr3::FfxErrorCode ffxFsr3ContextGenerateReactiveMask_Dx12(Fsr3::FfxFsr3UpscalerContext* pContext, const Fsr3::FfxFsr3UpscalerGenerateReactiveDescription* pParams)
|
||||
{
|
||||
LOG_DEBUG("");
|
||||
return o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12(pContext, pParams);
|
||||
//return Fsr3::FFX_OK;
|
||||
auto result = o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12(pContext, pParams);
|
||||
LOG_DEBUG("result: {:X}", (UINT)result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static Fsr3::FfxErrorCode ffxFsr3ContextDestroy_Dx12(Fsr3::FfxFsr3UpscalerContext* pContext)
|
||||
{
|
||||
if (pContext == nullptr)
|
||||
return Fsr3::FFX_ERROR_INVALID_ARGUMENT;
|
||||
return Fsr3::FFX_ERROR_BACKEND_API_ERROR;
|
||||
|
||||
LOG_DEBUG("context: {:X}", (size_t)pContext);
|
||||
|
||||
if (!_initParams.contains(pContext))
|
||||
return Fsr3::FFX_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
auto cdResult = o_ffxFsr3UpscalerContextDestroy_Dx12(pContext);
|
||||
LOG_INFO("result: {:X}", (UINT)cdResult);
|
||||
|
||||
if (!_initParams.contains(pContext))
|
||||
return cdResult;
|
||||
|
||||
if (_contexts.contains(pContext))
|
||||
NVSDK_NGX_D3D12_ReleaseFeature(_contexts[pContext]);
|
||||
|
||||
@@ -348,6 +353,9 @@ static Fsr3::FfxErrorCode ffxFsr3UpscalerGetSharedResourceDescriptions(Fsr3::Ffx
|
||||
{
|
||||
LOG_DEBUG("");
|
||||
|
||||
if (_d3d12Device == nullptr)
|
||||
return o_ffxFsr3UpscalerGetSharedResourceDescriptions(pContext, SharedResources);
|
||||
|
||||
if (pContext == nullptr || SharedResources == nullptr)
|
||||
return Fsr3::FFX_ERROR_INVALID_POINTER;
|
||||
|
||||
@@ -434,14 +442,14 @@ void HookFSR3ExeInputs()
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
|
||||
//if (o_ffxFSR3GetScratchMemorySizeDX12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFSR3GetScratchMemorySizeDX12, hk_ffxFsr3GetScratchMemorySizeDX12);
|
||||
if (o_ffxFSR3GetScratchMemorySizeDX12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFSR3GetScratchMemorySizeDX12, hk_ffxFsr3GetScratchMemorySizeDX12);
|
||||
|
||||
//if (o_ffxFSR3GetInterfaceDX12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFSR3GetInterfaceDX12, hk_ffxFsr3GetInterfaceDX12);
|
||||
if (o_ffxFSR3GetInterfaceDX12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFSR3GetInterfaceDX12, hk_ffxFsr3GetInterfaceDX12);
|
||||
|
||||
//if (o_ffxGetFSR3ResourceDX12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxGetFSR3ResourceDX12, hk_ffxFsr3GetResourceDX12);
|
||||
if (o_ffxGetFSR3ResourceDX12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxGetFSR3ResourceDX12, hk_ffxFsr3GetResourceDX12);
|
||||
|
||||
if (o_ffxFsr3UpscalerContextCreate_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerContextCreate_Dx12, ffxFsr3ContextCreate_Dx12);
|
||||
@@ -449,8 +457,8 @@ void HookFSR3ExeInputs()
|
||||
if (o_ffxFsr3UpscalerContextDispatch_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerContextDispatch_Dx12, ffxFsr3ContextDispatch_Dx12);
|
||||
|
||||
//if (o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12, ffxFsr3ContextGenerateReactiveMask_Dx12);
|
||||
if (o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12, ffxFsr3ContextGenerateReactiveMask_Dx12);
|
||||
|
||||
if (o_ffxFsr3UpscalerContextDestroy_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerContextDestroy_Dx12, ffxFsr3ContextDestroy_Dx12);
|
||||
@@ -461,11 +469,11 @@ void HookFSR3ExeInputs()
|
||||
if (o_ffxFsr3UpscalerGetRenderResolutionFromQualityMode_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerGetRenderResolutionFromQualityMode_Dx12, ffxFsr3GetRenderResolutionFromQualityMode_Dx12);
|
||||
|
||||
//if (o_ffxFsr3UpscalerGetSharedResourceDescriptions != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr3UpscalerGetSharedResourceDescriptions, ffxFsr3UpscalerGetSharedResourceDescriptions);
|
||||
if (o_ffxFsr3UpscalerGetSharedResourceDescriptions != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerGetSharedResourceDescriptions, ffxFsr3UpscalerGetSharedResourceDescriptions);
|
||||
|
||||
//if (o_ffxFsr3UpscalerResourceIsNull != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr3UpscalerResourceIsNull, ffxFsr3UpscalerResourceIsNull);
|
||||
if (o_ffxFsr3UpscalerResourceIsNull != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerResourceIsNull, ffxFsr3UpscalerResourceIsNull);
|
||||
|
||||
Config::Instance()->fsrHooks = true;
|
||||
|
||||
@@ -559,8 +567,8 @@ void HookFSR3Inputs(HMODULE module)
|
||||
if (o_ffxFsr3UpscalerContextDispatch_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerContextDispatch_Dx12, ffxFsr3ContextDispatch_Dx12);
|
||||
|
||||
//if (o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12 != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12, ffxFsr3ContextGenerateReactiveMask_Dx12);
|
||||
if (o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerContextGenerateReactiveMask_Dx12, ffxFsr3ContextGenerateReactiveMask_Dx12);
|
||||
|
||||
if (o_ffxFsr3UpscalerContextDestroy_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerContextDestroy_Dx12, ffxFsr3ContextDestroy_Dx12);
|
||||
@@ -571,11 +579,11 @@ void HookFSR3Inputs(HMODULE module)
|
||||
if (o_ffxFsr3UpscalerGetRenderResolutionFromQualityMode_Dx12 != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerGetRenderResolutionFromQualityMode_Dx12, ffxFsr3GetRenderResolutionFromQualityMode_Dx12);
|
||||
|
||||
//if (o_ffxFsr3UpscalerGetSharedResourceDescriptions != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr3UpscalerGetSharedResourceDescriptions, ffxFsr3UpscalerGetSharedResourceDescriptions);
|
||||
if (o_ffxFsr3UpscalerGetSharedResourceDescriptions != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerGetSharedResourceDescriptions, ffxFsr3UpscalerGetSharedResourceDescriptions);
|
||||
|
||||
//if (o_ffxFsr3UpscalerResourceIsNull != nullptr)
|
||||
// DetourAttach(&(PVOID&)o_ffxFsr3UpscalerResourceIsNull, ffxFsr3UpscalerResourceIsNull);
|
||||
if (o_ffxFsr3UpscalerResourceIsNull != nullptr)
|
||||
DetourAttach(&(PVOID&)o_ffxFsr3UpscalerResourceIsNull, ffxFsr3UpscalerResourceIsNull);
|
||||
|
||||
Config::Instance()->fsrHooks = true;
|
||||
|
||||
|
||||
@@ -1614,7 +1614,7 @@ HRESULT WINAPI detEnumAdapters1(IDXGIFactory1* This, UINT Adapter, IDXGIAdapter1
|
||||
{
|
||||
DXGI_ADAPTER_DESC desc;
|
||||
Config::Instance()->skipSpoofing = true;
|
||||
if ((*ppAdapter)->GetDesc(&desc) == S_OK)
|
||||
if (ptrGetDesc(*ppAdapter, &desc) == S_OK)
|
||||
{
|
||||
std::wstring name(desc.Description);
|
||||
LOG_DEBUG("High performance adapter ({}) will be used", wstring_to_string(name));
|
||||
@@ -1673,7 +1673,7 @@ HRESULT WINAPI detEnumAdapters(IDXGIFactory* This, UINT Adapter, IDXGIAdapter**
|
||||
{
|
||||
DXGI_ADAPTER_DESC desc;
|
||||
Config::Instance()->skipSpoofing = true;
|
||||
if ((*ppAdapter)->GetDesc(&desc) == S_OK)
|
||||
if (ptrGetDesc(*ppAdapter, &desc) == S_OK)
|
||||
{
|
||||
std::wstring name(desc.Description);
|
||||
LOG_DEBUG("Adapter ({}) will be used", wstring_to_string(name));
|
||||
|
||||
@@ -437,6 +437,7 @@ namespace Fsr3
|
||||
/// bump to ensure full functionality across effects and backends.
|
||||
///
|
||||
/// @ingroup FfxInterface
|
||||
|
||||
typedef struct FfxInterface {
|
||||
|
||||
FfxGetSDKVersionFunc fpGetSDKVersion; ///< A callback function to query the SDK version.
|
||||
@@ -461,6 +462,7 @@ namespace Fsr3
|
||||
FfxDevice device; ///< A backend specific device
|
||||
|
||||
} FfxInterface;
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@@ -340,6 +340,8 @@ inline static PFN_EnumAdapterByGpuPreference2 ptrEnumAdapterByGpuPreference = nu
|
||||
static PFN_CreateSwapChain oCreateSwapChain = nullptr;
|
||||
static PFN_CreateSwapChainForHwnd oCreateSwapChainForHwnd = nullptr;
|
||||
|
||||
inline bool skipHighPerfCheck = false;
|
||||
|
||||
// DirectX
|
||||
typedef void(*PFN_CreateSampler)(ID3D12Device* device, const D3D12_SAMPLER_DESC* pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor);
|
||||
typedef HRESULT(*PFN_CreateSamplerState)(ID3D11Device* This, const D3D11_SAMPLER_DESC* pSamplerDesc, ID3D11SamplerState** ppSamplerState);
|
||||
@@ -3050,7 +3052,54 @@ static HRESULT hkEnumAdapterByLuid(IDXGIFactory4* This, LUID AdapterLuid, REFIID
|
||||
|
||||
static HRESULT hkEnumAdapters1(IDXGIFactory1* This, UINT Adapter, IUnknown** ppAdapter)
|
||||
{
|
||||
auto result = ptrEnumAdapters1(This, Adapter, ppAdapter);
|
||||
HRESULT result = S_OK;
|
||||
|
||||
if (!skipHighPerfCheck && Config::Instance()->PreferDedicatedGpu.value_or(false))
|
||||
{
|
||||
if (Config::Instance()->PreferFirstDedicatedGpu.value_or(false) && Adapter > 0)
|
||||
{
|
||||
LOG_DEBUG("{}, returning not found", Adapter);
|
||||
return DXGI_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
IDXGIFactory6* factory6 = nullptr;
|
||||
if (This->QueryInterface(IID_PPV_ARGS(&factory6)) == S_OK && factory6 != nullptr)
|
||||
{
|
||||
LOG_DEBUG("Trying to select high performance adapter ({})", Adapter);
|
||||
|
||||
skipHighPerfCheck = true;
|
||||
result = ptrEnumAdapterByGpuPreference(factory6, Adapter, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, __uuidof(IDXGIAdapter), ppAdapter);
|
||||
skipHighPerfCheck = false;
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
LOG_ERROR("Can't get high performance adapter: {:X}, fallback to standard method", Adapter);
|
||||
result = ptrEnumAdapters1(This, Adapter, ppAdapter);
|
||||
}
|
||||
|
||||
if (result == S_OK)
|
||||
{
|
||||
DXGI_ADAPTER_DESC desc;
|
||||
Config::Instance()->skipSpoofing = true;
|
||||
if ((*(IDXGIAdapter**)ppAdapter)->GetDesc(&desc) == S_OK)
|
||||
{
|
||||
std::wstring name(desc.Description);
|
||||
LOG_DEBUG("Adapter ({}) will be used", wstring_to_string(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Can't get adapter description!");
|
||||
}
|
||||
Config::Instance()->skipSpoofing = false;
|
||||
}
|
||||
|
||||
factory6->Release();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ptrEnumAdapters(This, Adapter, ppAdapter);
|
||||
}
|
||||
|
||||
if (result == S_OK)
|
||||
CheckAdapter(*ppAdapter);
|
||||
@@ -3060,7 +3109,54 @@ static HRESULT hkEnumAdapters1(IDXGIFactory1* This, UINT Adapter, IUnknown** ppA
|
||||
|
||||
static HRESULT hkEnumAdapters(IDXGIFactory* This, UINT Adapter, IUnknown** ppAdapter)
|
||||
{
|
||||
auto result = ptrEnumAdapters(This, Adapter, ppAdapter);
|
||||
HRESULT result = S_OK;
|
||||
|
||||
if (!skipHighPerfCheck && Config::Instance()->PreferDedicatedGpu.value_or(false))
|
||||
{
|
||||
if (Config::Instance()->PreferFirstDedicatedGpu.value_or(false) && Adapter > 0)
|
||||
{
|
||||
LOG_DEBUG("{}, returning not found", Adapter);
|
||||
return DXGI_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
IDXGIFactory6* factory6 = nullptr;
|
||||
if (This->QueryInterface(IID_PPV_ARGS(&factory6)) == S_OK && factory6 != nullptr)
|
||||
{
|
||||
LOG_DEBUG("Trying to select high performance adapter ({})", Adapter);
|
||||
|
||||
skipHighPerfCheck = true;
|
||||
result = ptrEnumAdapterByGpuPreference(factory6, Adapter, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, __uuidof(IDXGIAdapter), ppAdapter);
|
||||
skipHighPerfCheck = false;
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
LOG_ERROR("Can't get high performance adapter: {:X}, fallback to standard method", Adapter);
|
||||
result = ptrEnumAdapters(This, Adapter, ppAdapter);
|
||||
}
|
||||
|
||||
if (result == S_OK)
|
||||
{
|
||||
DXGI_ADAPTER_DESC desc;
|
||||
Config::Instance()->skipSpoofing = true;
|
||||
if ((*(IDXGIAdapter**)ppAdapter)->GetDesc(&desc) == S_OK)
|
||||
{
|
||||
std::wstring name(desc.Description);
|
||||
LOG_DEBUG("Adapter ({}) will be used", wstring_to_string(name));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Can't get adapter description!");
|
||||
}
|
||||
Config::Instance()->skipSpoofing = false;
|
||||
}
|
||||
|
||||
factory6->Release();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ptrEnumAdapters(This, Adapter, ppAdapter);
|
||||
}
|
||||
|
||||
if (result == S_OK)
|
||||
CheckAdapter(*ppAdapter);
|
||||
@@ -3274,6 +3370,7 @@ static HRESULT hkD3D11On12CreateDevice(IUnknown* pDevice, UINT Flags, D3D_FEATUR
|
||||
{
|
||||
LOG_INFO("Device captured, D3D11Device: {0:X}", (UINT64)*ppDevice);
|
||||
d3d11on12Device = *ppDevice;
|
||||
Config::Instance()->d3d11Devices.push_back(*ppDevice);
|
||||
HookToDevice(d3d11on12Device);
|
||||
}
|
||||
|
||||
@@ -3323,7 +3420,7 @@ static HRESULT hkD3D11CreateDevice(IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE Drive
|
||||
|
||||
LOG_FUNC_RESULT(result);
|
||||
|
||||
Config::Instance()->lastCreatedD3D11Device = *ppDevice;
|
||||
Config::Instance()->d3d11Devices.push_back(*ppDevice);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -3405,7 +3502,7 @@ static HRESULT hkD3D11CreateDeviceAndSwapChain(IDXGIAdapter* pAdapter, D3D_DRIVE
|
||||
|
||||
LOG_FUNC_RESULT(result);
|
||||
|
||||
Config::Instance()->lastCreatedD3D11Device = *ppDevice;
|
||||
Config::Instance()->d3d11Devices.push_back(*ppDevice);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -3477,7 +3574,7 @@ static HRESULT hkD3D12CreateDevice(IDXGIAdapter* pAdapter, D3D_FEATURE_LEVEL Min
|
||||
#endif
|
||||
}
|
||||
|
||||
Config::Instance()->lastCreatedD3D12Device = (ID3D12Device*)*ppDevice;
|
||||
Config::Instance()->d3d12Devices.push_back((ID3D12Device*)*ppDevice);
|
||||
|
||||
LOG_FUNC_RESULT(result);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#define VER_MAJOR_VERSION 0
|
||||
#define VER_MINOR_VERSION 7
|
||||
#define VER_HOTFIX_VERSION 0
|
||||
#define VER_BUILD_NUMBER 86
|
||||
#define VER_BUILD_NUMBER 87
|
||||
|
||||
#define VER_PRE_RELEASE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user