Skip to content

Commit

Permalink
Add explicit path to NGX DLLs when establishing DLSS/DLSSG version
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Feb 28, 2025
1 parent 10046eb commit 35b8758
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 81 deletions.
6 changes: 3 additions & 3 deletions include/SpecialK/render/ngx/ngx.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct NGX_ThreadSafety {

extern SK_LazyGlobal <NGX_ThreadSafety> SK_NGX_Threading;

void SK_NGX_EstablishDLSSVersion (void) noexcept;
void SK_NGX_EstablishDLSSGVersion (void) noexcept;
void SK_NGX_EstablishDLSSVersion (const wchar_t*) noexcept;
void SK_NGX_EstablishDLSSGVersion (const wchar_t*) noexcept;

struct SK_DLSS_Context
{
Expand Down Expand Up @@ -80,7 +80,7 @@ struct SK_DLSS_Context
static bool isIndicatorShown (void);
} frame_gen;

inline void log_call (void) noexcept { apis_called = true; SK_NGX_EstablishDLSSVersion (); };
inline void log_call (void) noexcept { apis_called = true; SK_NGX_EstablishDLSSVersion (L"nvngx_dlss.dll"); };
};

extern SK_DLSS_Context SK_NGX_DLSS12;
Expand Down
150 changes: 84 additions & 66 deletions src/diagnostics/load_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,14 @@ SK_TraceLoadLibrary ( HMODULE hCallingMod,
else if ( StrStrI ( lpFileName, SK_TEXT("nvngx_dlss.dll")) ||
StrStrIW (wszModName, L"nvngx_dlss.dll") )
{
extern void SK_NGX_EstablishDLSSVersion (void) noexcept;
SK_NGX_EstablishDLSSVersion ();
extern void SK_NGX_EstablishDLSSVersion (const wchar_t*) noexcept;
SK_NGX_EstablishDLSSVersion (wszModName);
}
else if ( StrStrI ( lpFileName, SK_TEXT("nvngx_dlssg.dll")) ||
StrStrIW (wszModName, L"nvngx_dlssg.dll") )
{
extern void SK_NGX_EstablishDLSSGVersion (void) noexcept;
SK_NGX_EstablishDLSSGVersion ();
extern void SK_NGX_EstablishDLSSGVersion (const wchar_t*) noexcept;
SK_NGX_EstablishDLSSGVersion (wszModName);
}

#if 0
Expand Down Expand Up @@ -974,48 +974,57 @@ LoadLibrary_Marshal ( LPVOID lpRet,
hMod = nullptr;
}

else if (config.nvidia.dlss.auto_redirect_dlss && StrStrIW (compliant_path, L"nvngx_dlss.dll"))
else if (StrStrIW (compliant_path, L"nvngx_dlss.dll"))
{
static auto path_to_plugin_dlss =
std::filesystem::path (
SK_GetPlugInDirectory (SK_PlugIn_Type::ThirdParty)
) / L"NVIDIA" / L"nvngx_dlss.dll";

std::error_code ec;
if (std::filesystem::exists (path_to_plugin_dlss, ec))
if (config.nvidia.dlss.auto_redirect_dlss)
{
if (*SK_GetDLLVersionShort (compliant_path).c_str () > L'1')
static auto path_to_plugin_dlss =
std::filesystem::path (
SK_GetPlugInDirectory (SK_PlugIn_Type::ThirdParty)
) / L"NVIDIA" / L"nvngx_dlss.dll";

std::error_code ec;
if (std::filesystem::exists (path_to_plugin_dlss, ec))
{
dll_log->Log (
L"[DLL Loader] ** Redirecting NVIDIA DLSS DLL (%ws) to (%ws)",
compliant_path,
path_to_plugin_dlss.c_str ()
);
if (*SK_GetDLLVersionShort (compliant_path).c_str () > L'1')
{
dll_log->Log (
L"[DLL Loader] ** Redirecting NVIDIA DLSS DLL (%ws) to (%ws)",
compliant_path,
path_to_plugin_dlss.c_str ()
);

hMod =
SK_LoadLibraryW (path_to_plugin_dlss.c_str ());
}
hMod =
SK_LoadLibraryW (path_to_plugin_dlss.c_str ());
}

else
{
dll_log->Log (
L"[DLL Loader] ** Game's DLSS version (%ws) is too old to replace.",
SK_GetDLLVersionShort (compliant_path).c_str ()
);
else
{
dll_log->Log (
L"[DLL Loader] ** Game's DLSS version (%ws) is too old to replace.",
SK_GetDLLVersionShort (compliant_path).c_str ()
);

hMod = nullptr;
hMod = nullptr;
}

if (! hMod)
{
dll_log->Log (L"[DLL Loader] # Plug-In Load Failed, using original DLL!");

hMod =
SK_LoadLibraryW (compliant_path);
}
}

if (! hMod)
else
{
dll_log->Log (L"[DLL Loader] # Plug-In Load Failed, using original DLL!");

hMod =
SK_LoadLibraryW (compliant_path);
}

extern void SK_NGX_EstablishDLSSVersion (void);
SK_NGX_EstablishDLSSVersion ();
extern void SK_NGX_EstablishDLSSVersion (const wchar_t* wszDLSS) noexcept;
SK_NGX_EstablishDLSSVersion (compliant_path);
}
}

Expand Down Expand Up @@ -1354,49 +1363,58 @@ LoadLibraryEx_Marshal ( LPVOID lpRet, LPCWSTR lpFileName,
try
{
#endif
if (config.nvidia.dlss.auto_redirect_dlss && StrStrIW (compliant_path, L"nvngx_dlss.dll"))
if (StrStrIW (compliant_path, L"nvngx_dlss.dll"))
{
static auto path_to_plugin_dlss =
std::filesystem::path (
SK_GetPlugInDirectory (SK_PlugIn_Type::ThirdParty)
) / L"NVIDIA" / L"nvngx_dlss.dll";

std::error_code ec;
if (std::filesystem::exists (path_to_plugin_dlss, ec))
if (config.nvidia.dlss.auto_redirect_dlss)
{
if (*SK_GetDLLVersionShort (compliant_path).c_str () > L'1')
static auto path_to_plugin_dlss =
std::filesystem::path (
SK_GetPlugInDirectory (SK_PlugIn_Type::ThirdParty)
) / L"NVIDIA" / L"nvngx_dlss.dll";

std::error_code ec;
if (std::filesystem::exists (path_to_plugin_dlss, ec))
{
dll_log->Log (
L"[DLL Loader] ** Redirecting NVIDIA DLSS DLL (%ws) to (%ws)",
compliant_path,
path_to_plugin_dlss.c_str ()
);
if (*SK_GetDLLVersionShort (compliant_path).c_str () > L'1')
{
dll_log->Log (
L"[DLL Loader] ** Redirecting NVIDIA DLSS DLL (%ws) to (%ws)",
compliant_path,
path_to_plugin_dlss.c_str ()
);

hMod =
SK_LoadLibraryW (path_to_plugin_dlss.c_str ());
}
hMod =
SK_LoadLibraryW (path_to_plugin_dlss.c_str ());
}

else
{
dll_log->Log (
L"[DLL Loader] ** Game's DLSS version (%ws) is too old to replace.",
SK_GetDLLVersionShort (compliant_path).c_str ()
);
else
{
dll_log->Log (
L"[DLL Loader] ** Game's DLSS version (%ws) is too old to replace.",
SK_GetDLLVersionShort (compliant_path).c_str ()
);

hMod = nullptr;
}
hMod = nullptr;
}

if (! hMod)
{
dll_log->Log (L"[DLL Loader] # Plug-In Load Failed, using original DLL!");
if (! hMod)
{
dll_log->Log (L"[DLL Loader] # Plug-In Load Failed, using original DLL!");

hMod =
SK_LoadLibraryExW (compliant_path, hFile, dwFlags);
hMod =
SK_LoadLibraryExW (compliant_path, hFile, dwFlags);
}
}
}

extern void SK_NGX_EstablishDLSSVersion (void);
SK_NGX_EstablishDLSSVersion ();

else
{
hMod =
SK_LoadLibraryExW (compliant_path, hFile, dwFlags);
}

extern void SK_NGX_EstablishDLSSVersion (const wchar_t* wszDLSS) noexcept;
SK_NGX_EstablishDLSSVersion (compliant_path);
}

else
Expand Down
16 changes: 8 additions & 8 deletions src/render/ngx/ngx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,23 +811,23 @@ SK_DLSS_Context::version_s SK_DLSS_Context::dlss_s::Version;
SK_DLSS_Context::version_s SK_DLSS_Context::dlssg_s::Version;

void
SK_NGX_EstablishDLSSVersion (void) noexcept
SK_NGX_EstablishDLSSVersion (const wchar_t* wszDLSS) noexcept
{
static bool bHasVersion = false;

if (bHasVersion && SK_GetFramesDrawn () > 0)
return;

if (! GetModuleHandleW (L"nvngx_dlss.dll"))
if (! GetModuleHandleW (wszDLSS))
return;

std::swscanf (
SK_GetDLLVersionShort (L"nvngx_dlss.dll").c_str (), L"%d,%d,%d,%d",
SK_GetDLLVersionShort (wszDLSS).c_str (), L"%d,%d,%d,%d",
&SK_DLSS_Context::dlss_s::Version.major, &SK_DLSS_Context::dlss_s::Version.minor,
&SK_DLSS_Context::dlss_s::Version.build, &SK_DLSS_Context::dlss_s::Version.revision
);

bHasVersion = true;
bHasVersion = SK_DLSS_Context::dlss_s::Version.major > 0;

// Turn off overrides before we break stuff!
if (SK_DLSS_Context::dlss_s::Version.major < 2)
Expand All @@ -840,23 +840,23 @@ SK_NGX_EstablishDLSSVersion (void) noexcept
}

void
SK_NGX_EstablishDLSSGVersion (void) noexcept
SK_NGX_EstablishDLSSGVersion (const wchar_t* wszDLSSG) noexcept
{
static bool bHasVersion = false;

if (bHasVersion && SK_GetFramesDrawn () > 0)
return;

if (! GetModuleHandleW (L"nvngx_dlssg.dll"))
if (! GetModuleHandleW (wszDLSSG))
return;

std::swscanf (
SK_GetDLLVersionShort (L"nvngx_dlssg.dll").c_str (), L"%d,%d,%d,%d",
SK_GetDLLVersionShort (wszDLSSG).c_str (), L"%d,%d,%d,%d",
&SK_DLSS_Context::dlssg_s::Version.major, &SK_DLSS_Context::dlssg_s::Version.minor,
&SK_DLSS_Context::dlssg_s::Version.build, &SK_DLSS_Context::dlssg_s::Version.revision
);

bHasVersion = true;
bHasVersion = SK_DLSS_Context::dlssg_s::Version.major > 0;
}

SK_DLSS_Context::version_s
Expand Down
4 changes: 2 additions & 2 deletions src/render/ngx/ngx_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ NVSDK_NGX_D3D11_CreateFeature_Detour ( ID3D11DeviceContext *InDevCtx,
{
if (InFeatureID == NVSDK_NGX_Feature_FrameGeneration)
{
SK_NGX_EstablishDLSSGVersion ();
SK_NGX_EstablishDLSSGVersion (L"nvngx_dlssg.dll");

SK_ReleaseAssert ( SK_NGX_DLSS11.frame_gen.Handle == *OutHandle ||
SK_NGX_DLSS11.frame_gen.Handle == nullptr );
Expand Down Expand Up @@ -553,7 +553,7 @@ SK_NGX_InitD3D11 (void)
{
SK_RunOnce (
{
SK_NGX_EstablishDLSSVersion ();
SK_NGX_EstablishDLSSVersion (L"nvngx_dlss.dll");

SK_CreateDLLHook2 ( L"_nvngx.dll",
"NVSDK_NGX_D3D11_Init",
Expand Down
4 changes: 2 additions & 2 deletions src/render/ngx/ngx_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ NVSDK_NGX_D3D12_CreateFeature_Detour ( ID3D12GraphicsCommandList *InCmdList,
{
if (InFeatureID == NVSDK_NGX_Feature_FrameGeneration)
{
SK_NGX_EstablishDLSSGVersion ();
SK_NGX_EstablishDLSSGVersion (L"nvngx_dlssg.dll");

SK_ReleaseAssert ( SK_NGX_DLSS12.frame_gen.Handle == *OutHandle ||
SK_NGX_DLSS12.frame_gen.Handle == nullptr );
Expand Down Expand Up @@ -583,7 +583,7 @@ SK_NGX_InitD3D12 (void)
{
SK_RunOnce (
{
SK_NGX_EstablishDLSSVersion ();
SK_NGX_EstablishDLSSVersion (L"nvngx_dlss.dll");

SK_CreateDLLHook2 ( L"_nvngx.dll",
"NVSDK_NGX_D3D12_Init",
Expand Down

0 comments on commit 35b8758

Please sign in to comment.