Clear windows branch; preserve previous contents in win-old

This commit is contained in:
ayo committed 2026-10-16 05:20:08 -04:00
1 parent f0c881985b
commit 73994d4634
311 files changed
-57018

No files matched your search

@@ -1,328 +0,0 @@
From 33bbac250ac7e2ca4eff67e8817ada9dad578208 Mon Sep 17 00:00:00 2001
From: Codex <codex@localhost>
Date: Thu, 1 Oct 2026 16:10:08 +0300
Subject: [PATCH] Support explicitly selected Windows d4r DLSS backend on
physical AMD adapters
---
OptiScaler/Config.cpp | 3 ++
OptiScaler/Config.h | 1 +
OptiScaler/OptiScaler.vcxproj | 4 +--
OptiScaler/State.h | 1 +
OptiScaler/Util.cpp | 12 +++++--
OptiScaler/dllmain.cpp | 33 +++++++++++++++++--
OptiScaler/hooks/LibraryLoad_Hooks.cpp | 17 ++++++++++
OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp | 17 ++++++++++
OptiScaler/misc/IdentifyGpu.cpp | 20 +++++++++++
OptiScaler/proxies/NVNGX_Proxy.h | 5 ++-
OptiScaler/upscalers/FeatureProvider_Dx12.cpp | 10 ++++++
11 files changed, 115 insertions(+), 8 deletions(-)
diff --git a/OptiScaler/Config.cpp b/OptiScaler/Config.cpp
index d8c62d3..f444387 100644
--- a/OptiScaler/Config.cpp
+++ b/OptiScaler/Config.cpp
@@ -323,6 +323,7 @@ bool Config::Reload(std::filesystem::path iniPath)
{
// Don't enable again if set false because of no nvngx found
DLSSEnabled.set_from_config(readBool("DLSS", "Enabled"));
+ DLSSAllowExternalBackend.set_from_config(readBool("DLSS", "AllowExternalBackend"));
UseGenericAppIdWithDlss.set_from_config(readBool("DLSS", "UseGenericAppIdWithDlss"));
RenderPresetOverride.set_from_config(readBool("DLSS", "RenderPresetOverride"));
@@ -1168,6 +1169,8 @@ bool Config::SaveIni()
// DLSS
{
ini.SetValue("DLSS", "Enabled", GetBoolValue(Instance()->DLSSEnabled.value_for_config()).c_str());
+ ini.SetValue("DLSS", "AllowExternalBackend",
+ GetBoolValue(Instance()->DLSSAllowExternalBackend.value_for_config()).c_str());
ini.SetValue("DLSS", "RenderPresetOverride",
GetBoolValue(Instance()->RenderPresetOverride.value_for_config()).c_str());
ini.SetValue("DLSS", "RenderPresetForAll",
diff --git a/OptiScaler/Config.h b/OptiScaler/Config.h
index 4ab62a4..0caf8c8 100644
--- a/OptiScaler/Config.h
+++ b/OptiScaler/Config.h
@@ -275,6 +275,7 @@ class Config
// DLSS
CustomOptional<bool> DLSSEnabled { true };
+ CustomOptional<bool> DLSSAllowExternalBackend { false };
CustomOptional<bool> RenderPresetOverride { false };
CustomOptional<uint32_t> RenderPresetForAll { 0 };
CustomOptional<uint32_t> RenderPresetDLAA { 0 };
diff --git a/OptiScaler/OptiScaler.vcxproj b/OptiScaler/OptiScaler.vcxproj
index 24ca80b..dfbfc97 100644
--- a/OptiScaler/OptiScaler.vcxproj
+++ b/OptiScaler/OptiScaler.vcxproj
@@ -236,7 +236,7 @@
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
- <GenerateDebugInformation>false</GenerateDebugInformation>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalDependencies>winhttp.lib;WindowsApp.lib;Dbghelp.lib;dxgi.lib;d3d11.lib;d3d12.lib;vulkan-1.lib;dxguid.lib;freetype.lib;ffx_fsr2_api_x64.lib;ffx_fsr2_api_dx11_x64.lib;ffx_fsr2_api_dx12_x64.lib;ffx_fsr2_api_vk_x64.lib;ffx_fsr2_212_api_dx12_x64.lib;ffx_fsr2_212_api_vk_x64.lib;ffx_fsr2_212_api_x64.lib;d3dcompiler.lib;ffx_backend_dx11_x64.lib;ffx_fsr3_x64.lib;ffx_frameinterpolation_x64.lib;ffx_fsr3upscaler_x64.lib;ffx_opticalflow_x64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
@@ -873,4 +873,4 @@ copy NUL "$(SolutionDir)x64\Release\a\!! EXTRACT ALL FILES TO GAME FOLDER !!" /Y
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/OptiScaler/State.h b/OptiScaler/State.h
index 42164de..84f8263 100644
--- a/OptiScaler/State.h
+++ b/OptiScaler/State.h
@@ -265,6 +265,7 @@ class State
int dlssgDetectedInterpolationCount = 0;
// DLSS
+ bool dlssExternalBackend = false;
bool dlssPresetsOverriddenExternally = false;
bool dlssPresetsOverridenByOpti = false;
uint32_t dlssRenderPresetExternal = 0;
diff --git a/OptiScaler/Util.cpp b/OptiScaler/Util.cpp
index f7ac6fa..7367a91 100644
--- a/OptiScaler/Util.cpp
+++ b/OptiScaler/Util.cpp
@@ -486,8 +486,16 @@ bool Util::GetFileVersion(std::wstring dllPath, version_t* fileVersionOut, versi
bool Util::IsSubpath(const std::filesystem::path& path, const std::filesystem::path& base)
{
- auto rel = std::filesystem::relative(path, base);
- auto first = *rel.begin();
+ // Called by LdrLoadDll hooks: relative()/weakly_canonical() perform file
+ // queries, can re-enter the hooks, and throw when an optional directory or
+ // a bare DLL search name cannot be resolved. This is a lexical routing
+ // check, not a filesystem access control decision.
+ auto normalizedPath = std::filesystem::path(ToLower(path.lexically_normal().wstring()));
+ auto normalizedBase = std::filesystem::path(ToLower(base.lexically_normal().wstring()));
+ auto rel = normalizedPath.lexically_relative(normalizedBase);
+ if (rel.empty())
+ return false;
+ const auto first = *rel.begin();
return first != "." && first != "..";
}
diff --git a/OptiScaler/dllmain.cpp b/OptiScaler/dllmain.cpp
index cba14b1..b4b786e 100644
--- a/OptiScaler/dllmain.cpp
+++ b/OptiScaler/dllmain.cpp
@@ -948,7 +948,7 @@ static void CheckWorkingMode()
// NVAPI
// Doesn't seem to like GetModuleHandle for some reason, so call our load to make sure
- if (GetDllNameWModule(&nvapiNamesW) != nullptr)
+ if (!State::Instance().dlssExternalBackend && GetDllNameWModule(&nvapiNamesW) != nullptr)
{
// This hooks nvapi as well when possible
auto nvapi64 = LibraryLoadHooks::LoadNvApi();
@@ -1958,7 +1958,33 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
return nvidiaDetected;
};
- bool possibleNvidia = isNvidiaViaNvapi();
+ // Opt in only to a configured, versioned Windows d4r backend. The
+ // marker performs no HIP/NGX initialization under DLL_PROCESS_ATTACH.
+ // GPU support is still checked by its public NGX requirements API.
+ if (Config::Instance()->DLSSEnabled.value_or_default() &&
+ Config::Instance()->DLSSAllowExternalBackend.value_or_default() &&
+ Config::Instance()->NvngxPath.has_value())
+ {
+ auto backendPath = std::filesystem::path(Config::Instance()->NvngxPath.value()) / L"_nvngx.dll";
+ if (backendPath.is_absolute())
+ {
+ auto module = NtdllProxy::LoadLibraryExW_Ldr(backendPath.c_str(), nullptr,
+ LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
+ if (module)
+ {
+ using BackendVersion = unsigned (*)();
+ auto version = reinterpret_cast<BackendVersion>(
+ KernelBaseProxy::GetProcAddress_()(module, "d4r_WindowsBackendVersion"));
+ State::Instance().dlssExternalBackend = version && version() == 1;
+ NtdllProxy::FreeLibrary_Ldr(module);
+ }
+ }
+ if (State::Instance().dlssExternalBackend)
+ spdlog::info("Validated external Windows d4r DLSS backend; retaining physical GPU identity");
+ else
+ spdlog::error("AllowExternalBackend requires an absolute NvngxPath containing Windows d4r ABI 1");
+ }
+ bool possibleNvidia = !State::Instance().dlssExternalBackend && isNvidiaViaNvapi();
spdlog::info("");
spdlog::info("Check for DLSS files");
@@ -1992,7 +2018,8 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
State::Instance().NVNGX_DLSSG_Path = Util::FindFilePath(exePath, "nvngx_dlssg.dll");
// Not 100% accurate for Nvidia cards without DLSS
- if (Config::Instance()->DLSSEnabled.value_or_default() && possibleNvidia)
+ if (Config::Instance()->DLSSEnabled.value_or_default() &&
+ (possibleNvidia || State::Instance().dlssExternalBackend))
{
if (State::Instance().NVNGX_DLSS_Path.has_value())
{
diff --git a/OptiScaler/hooks/LibraryLoad_Hooks.cpp b/OptiScaler/hooks/LibraryLoad_Hooks.cpp
index 90bdb89..108ea5b 100644
--- a/OptiScaler/hooks/LibraryLoad_Hooks.cpp
+++ b/OptiScaler/hooks/LibraryLoad_Hooks.cpp
@@ -46,6 +46,18 @@ HMODULE LibraryLoadHooks::LoadLibraryCheckW(std::wstring libName, LPCWSTR lpLibF
{
auto libNameA = wstring_to_string(libName);
+ // The external D3D12 shim itself uses a locally supplied CUDA NGX core.
+ // Keep that exact absolute path distinct from game-facing NGX interception.
+ if (State::Instance().dlssExternalBackend)
+ {
+ wchar_t corePath[32768] {};
+ const auto length = GetEnvironmentVariableW(L"D4R_NGX_CORE", corePath, 32768);
+ if (length && length < 32768 &&
+ Util::ToLower(std::filesystem::path(libName).lexically_normal().wstring()) ==
+ Util::ToLower(std::filesystem::path(corePath).lexically_normal().wstring()))
+ return nullptr;
+ }
+
#ifdef LOG_LIB_OPERATIONS
LOG_TRACE("{}", libNameA);
#endif
@@ -132,6 +144,11 @@ HMODULE LibraryLoadHooks::LoadLibraryCheckW(std::wstring libName, LPCWSTR lpLibF
// NvApi64.dll
if (CheckDllNameW(&libName, &nvapiNamesW))
{
+ // An explicit external CUDA backend owns its NVAPI topology provider.
+ // Returning OptiScaler's fake-NVAPI would replace that provider and can
+ // recurse into DXGI while the NGX loader holds the loader lock.
+ if (State::Instance().dlssExternalBackend)
+ return nullptr; // Continue through the original loader.
LOG_INFO("{} call!", libNameA);
return LibraryLoadHooks::LoadNvApi();
diff --git a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp
index 68e1b42..89c9ba8 100644
--- a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp
+++ b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp
@@ -687,6 +687,7 @@ static NVSDK_NGX_Result TryCreateOptiFeature(ID3D12GraphicsCommandList* InCmdLis
}
// Assign handle
+ const bool allocatedHandle = *OutHandle == nullptr;
if (*OutHandle == nullptr)
*OutHandle = new NVSDK_NGX_Handle { handleId };
else
@@ -705,6 +706,16 @@ static NVSDK_NGX_Result TryCreateOptiFeature(ID3D12GraphicsCommandList* InCmdLis
}
else
{
+ if (state.dlssExternalBackend && upscalerBackend == Upscaler::DLSS)
+ {
+ LOG_ERROR("External DLSS initialization failed; refusing FSR fallback");
+ if (shouldRestoreSigs)
+ D3D12Hooks::RestoreRoot(InCmdList);
+ D3D12Hooks::SetRootSignatureTracking(true);
+ Dx12Contexts.erase(handleId);
+ if (allocatedHandle) { delete *OutHandle; *OutHandle = nullptr; }
+ return NVSDK_NGX_Result_Fail;
+ }
LOG_ERROR("Feature '{}' initialization failed falling back to FSR 2.1.2", UpscalerDisplayName(upscalerBackend));
state.newBackend = Upscaler::FSR21;
state.changeBackend[handleId] = true;
@@ -1027,6 +1038,12 @@ static NVSDK_NGX_Result TryEvaluateOptiFeature(ID3D12GraphicsCommandList* InCmdL
// Fallback to FSR 2.1.2 if feature failed to initialize and user didn't explicitly request it
if (!feature->IsInited() && cfg.Dx12Upscaler.value_or_default() != Upscaler::FSR21)
{
+ if (state.dlssExternalBackend && cfg.Dx12Upscaler.value_or_default() == Upscaler::DLSS)
+ {
+ LOG_ERROR("External DLSS feature is not initialized; refusing FSR fallback");
+ D3D12Hooks::SetRootSignatureTracking(true);
+ return NVSDK_NGX_Result_Fail;
+ }
LOG_WARN("Feature '{}' failed to initialize. Falling back to FSR 2.1.2", feature->Name());
ImGui::InsertNotification({ ImGuiToastType::Warning, 10000, "Falling back to FSR 2.1.2" });
diff --git a/OptiScaler/misc/IdentifyGpu.cpp b/OptiScaler/misc/IdentifyGpu.cpp
index 3877f9f..6c05904 100644
--- a/OptiScaler/misc/IdentifyGpu.cpp
+++ b/OptiScaler/misc/IdentifyGpu.cpp
@@ -8,6 +8,7 @@
#include <proxies/D3d12_Proxy.h>
#include "nvapi/NvApiTypes.h"
#include <hooks/Amdxc64_Hooks.h>
+#include <proxies/NVNGX_Proxy.h>
using Microsoft::WRL::ComPtr;
@@ -187,6 +188,25 @@ std::vector<GpuInformation> IdentifyGpu::checkGpuInfo()
for (auto& gpuInfo : localCachedInfo)
{
+ if (State::Instance().dlssExternalBackend && !gpuInfo.softwareAdapter)
+ {
+ // Query the configured D3D12 backend outside DLL_PROCESS_ATTACH.
+ // Preserve vendor/device/architecture data obtained from DXGI.
+ auto requirements = NVNGXProxy::D3D12_GetFeatureRequirements();
+ ComPtr<IDXGIAdapter1> physicalAdapter;
+ if (requirements && SUCCEEDED(factory->EnumAdapterByLuid(gpuInfo.luid, IID_PPV_ARGS(&physicalAdapter))))
+ {
+ NVSDK_NGX_FeatureDiscoveryInfo discovery {};
+ discovery.SDKVersion = NVSDK_NGX_Version_API;
+ discovery.FeatureID = NVSDK_NGX_Feature_SuperSampling;
+ NVSDK_NGX_FeatureRequirement supported {};
+ const auto result = requirements(physicalAdapter.Get(), &discovery, &supported);
+ gpuInfo.dlssCapable = result == NVSDK_NGX_Result_Success &&
+ supported.FeatureSupported == NVSDK_NGX_FeatureSupportResult_Supported;
+ LOG_INFO("External D3D12 DLSS backend: {} support={} result={:X}",
+ gpuInfo.name, gpuInfo.dlssCapable, (unsigned) result);
+ }
+ }
if (gpuInfo.vendorId == VendorId::Nvidia)
{
queryNvapi(gpuInfo);
diff --git a/OptiScaler/proxies/NVNGX_Proxy.h b/OptiScaler/proxies/NVNGX_Proxy.h
index f6c08e5..7892009 100644
--- a/OptiScaler/proxies/NVNGX_Proxy.h
+++ b/OptiScaler/proxies/NVNGX_Proxy.h
@@ -500,7 +500,10 @@ class NVNGXProxy
{
LOG_INFO("Getting nvngx method addresses");
- HookNgxApi(_module.dll);
+ // The external bridge reports physical adapter support itself.
+ // Do not overwrite its unsupported result with NVIDIA spoofing.
+ if (!State::Instance().dlssExternalBackend)
+ HookNgxApi(_module.dll);
_module.D3D11_Init =
(PFN_D3D11_Init) KernelBaseProxy::GetProcAddress_()(_module.dll, "NVSDK_NGX_D3D11_Init");
diff --git a/OptiScaler/upscalers/FeatureProvider_Dx12.cpp b/OptiScaler/upscalers/FeatureProvider_Dx12.cpp
index d738498..1191b29 100644
--- a/OptiScaler/upscalers/FeatureProvider_Dx12.cpp
+++ b/OptiScaler/upscalers/FeatureProvider_Dx12.cpp
@@ -42,6 +42,11 @@ bool FeatureProvider_Dx12::GetFeature(Upscaler upscaler, UINT handleId, NVSDK_NG
break;
case Upscaler::DLSS:
+ if (state.dlssExternalBackend && (!primaryGpu.dlssCapable || !state.NVNGX_DLSS_Path.has_value()))
+ {
+ LOG_ERROR("Configured external D3D12 DLSS backend is unavailable; refusing FSR fallback");
+ return false;
+ }
if (primaryGpu.dlssCapable && state.NVNGX_DLSS_Path.has_value())
{
*feature = std::make_unique<DLSSFeatureDx12>(handleId, parameters);
@@ -77,6 +82,11 @@ bool FeatureProvider_Dx12::GetFeature(Upscaler upscaler, UINT handleId, NVSDK_NG
if (!loaded)
{
+ if (state.dlssExternalBackend && upscaler == Upscaler::DLSS)
+ {
+ LOG_ERROR("External D3D12 DLSS module failed to load; refusing FSR fallback");
+ return false;
+ }
// Fail after the constructor
ImGui::InsertNotification({ ImGuiToastType::Warning, 10000, "Falling back to FSR 2.1.2" });
*feature = std::make_unique<FSR2FeatureDx12_212>(handleId, parameters);
--
2.55.0.windows.5
@@ -1,45 +0,0 @@
From 7ed1f1d66b430ba35a197fbd9880cd6a76af8f06 Mon Sep 17 00:00:00 2001
From: Codex <codex@localhost>
Date: Thu, 1 Oct 2026 16:45:01 +0300
Subject: [PATCH] Install the external d4r command backend before NGX
initialization
---
OptiScaler/hooks/D3D12_Hooks.cpp | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/OptiScaler/hooks/D3D12_Hooks.cpp b/OptiScaler/hooks/D3D12_Hooks.cpp
index 29c0bec..3b757be 100644
--- a/OptiScaler/hooks/D3D12_Hooks.cpp
+++ b/OptiScaler/hooks/D3D12_Hooks.cpp
@@ -14,6 +14,7 @@
#include <proxies/IGDExt_Proxy.h>
#include <proxies/Streamline_Proxy.h>
#include <proxies/KernelBase_Proxy.h>
+#include <proxies/NVNGX_Proxy.h>
#include <detours/detours.h>
@@ -2230,6 +2231,19 @@ static void HookToDevice(ID3D12Device* InDevice)
if (Util::CheckForRealObject(__FUNCTION__, InDevice, (IUnknown**) &realDevice))
pVTable = *(PVOID**) realDevice;
+ if (State::Instance().dlssExternalBackend)
+ {
+ // Capture command signatures/resources created before the game's NGX
+ // Init. Install before adding OptiScaler's own method trampolines.
+ using InstallCommandBackend = unsigned (*)(ID3D12Device*);
+ auto install = reinterpret_cast<InstallCommandBackend>(KernelBaseProxy::GetProcAddress_()(
+ NVNGXProxy::NVNGXModule(), "d4r_D3D12_InstallCommandBackend"));
+ auto result = install ? install(realDevice ? realDevice : InDevice) : 0;
+ LOG_INFO("External d4r command backend installed at device discovery: result={:X}", result);
+ if (result != 1)
+ LOG_ERROR("External d4r early command tracking failed; DLSS initialization must be checked");
+ }
+
// hudless
o_D3D12DeviceRelease = (PFN_Release) pVTable[2];
o_CreateSampler = (PFN_CreateSampler) pVTable[22];
--
2.55.0.windows.5
@@ -1,37 +0,0 @@
From 09488c47855aadbf85f68ab8c72c0f3ac5f915e9 Mon Sep 17 00:00:00 2001
From: Codex <codex@localhost>
Date: Thu, 1 Oct 2026 17:01:32 +0300
Subject: [PATCH] Preserve legacy ProjectID initialization in the external
backend
---
OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp
index 89c9ba8..1f723f1 100644
--- a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp
+++ b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp
@@ -313,6 +313,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_ProjectID(const char* InProj
if (result == NVSDK_NGX_Result_Success)
NVNGXProxy::SetDx12Inited(true);
+ else if (State::Instance().dlssExternalBackend)
+ return result;
}
}
@@ -343,6 +345,10 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_with_ProjectID(
{
LOG_FUNC();
+ if (State::Instance().dlssExternalBackend)
+ return NVSDK_NGX_D3D12_Init_ProjectID(InProjectId, InEngineType, InEngineVersion,
+ InApplicationDataPath, InDevice, InSDKVersion, InFeatureInfo);
+
LOG_INFO("InProjectId: {0}", InProjectId);
LOG_INFO("InEngineType: {0}", (int) InEngineType);
LOG_INFO("InEngineVersion: {0}", InEngineVersion);
--
2.55.0.windows.5
@@ -1,34 +0,0 @@
diff --git a/OptiScaler/hooks/D3D12_Hooks.cpp b/OptiScaler/hooks/D3D12_Hooks.cpp
index 3b757be..05fc194 100644
--- a/OptiScaler/hooks/D3D12_Hooks.cpp
+++ b/OptiScaler/hooks/D3D12_Hooks.cpp
@@ -2217,11 +2217,20 @@ static HRESULT hkD3D12GetInterface(REFCLSID rclsid, REFIID riid, void** ppvDebug
return result;
}
+// Device discovery and NGX initialization can overlap. Installing d4r's
+// command hooks can also create a device and re-enter this function. Never
+// overwrite live Detours trampolines from a second installation attempt.
+static std::recursive_mutex deviceHookMutex;
+static bool deviceHookInstalling = false;
static void HookToDevice(ID3D12Device* InDevice)
{
- if (o_CreateSampler != nullptr || InDevice == nullptr)
+ std::lock_guard<std::recursive_mutex> lock(deviceHookMutex);
+ if (o_CreateSampler != nullptr || InDevice == nullptr || deviceHookInstalling)
return;
+ deviceHookInstalling = true;
+ struct InstallationGuard { ~InstallationGuard() { deviceHookInstalling = false; } } installationGuard;
+
LOG_DEBUG("Dx12");
// Get the vtable pointer
@@ -2334,6 +2343,7 @@ static void HookToDevice(ID3D12Device* InDevice)
static void UnhookDevice()
{
+ std::lock_guard<std::recursive_mutex> lock(deviceHookMutex);
LOG_FUNC();
DetourTransactionBegin();
@@ -1,22 +0,0 @@
diff --git a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp
index 1f723f1..ef5ec77 100644
--- a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp
+++ b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp
@@ -184,6 +184,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(unsigned long long InApp
if (result == NVSDK_NGX_Result_Success)
NVNGXProxy::SetDx12Inited(true);
+ else if (State::Instance().dlssExternalBackend)
+ return result;
}
else
{
@@ -254,6 +256,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init(unsigned long long InApplica
if (result == NVSDK_NGX_Result_Success)
NVNGXProxy::SetDx12Inited(true);
+ else if (State::Instance().dlssExternalBackend)
+ return result;
}
}
@@ -1,30 +0,0 @@
Subject: [PATCH] Resolve relative d4r library paths against the OptiScaler folder
Lets a drag-in d4r install ship OptiScaler.ini with NvngxPath=d4r instead of
an absolute path that only an installer could know. Absolute paths behave
exactly as before.
---
diff --git a/OptiScaler/Config.cpp b/OptiScaler/Config.cpp
--- a/OptiScaler/Config.cpp
+++ b/OptiScaler/Config.cpp
@@ -787,9 +787,17 @@
{
MainDllPath.set_from_config(readWString("Libraries", "OptiDllPath"));
- NvngxPath.set_from_config(readWString("Libraries", "NvngxPath"));
- NVNGX_DLSS_Library.set_from_config(readWString("Libraries", "NvngxDlssPath"));
- DLSSFeaturePath.set_from_config(readWString("Libraries", "NvngxFeaturePath"));
+ // A relative library folder (d4r drag-in installs use "d4r") is resolved
+ // against this DLL's folder, as LogFileName is. Absolute paths are unchanged.
+ auto libraryPath = [](std::optional<std::wstring> value) -> std::optional<std::wstring>
+ {
+ if (!value.has_value() || value->empty() || std::filesystem::path(*value).is_absolute())
+ return value;
+ return (Util::DllPath().parent_path() / *value).lexically_normal().wstring();
+ };
+ NvngxPath.set_from_config(libraryPath(readWString("Libraries", "NvngxPath")));
+ NVNGX_DLSS_Library.set_from_config(libraryPath(readWString("Libraries", "NvngxDlssPath")));
+ DLSSFeaturePath.set_from_config(libraryPath(readWString("Libraries", "NvngxFeaturePath")));
NvapiDllPath.set_from_config(readWString("Libraries", "NvapiPath"));
FfxDx12Path.set_from_config(readWString("Libraries", "FfxDx12Path"));
-62
View File
@@ -1,62 +0,0 @@
# Explicit Windows d4r backend
Base: OptiScaler `45a2001303ddff632e279f77aef85ceede5832cb` (2026-09-30).
`0004` serializes D3D12 device hook installation/removal and guards recursive
device discovery while the d4r command backend installs. The previous frontend
can start two installations, fail a Detours transaction with `0x10dd`, clear
live original-function pointers and call null. This was reproduced in the
numeric-ID standalone harness; no game was required.
`0005` propagates numeric Init/Init_Ext failures for the explicitly selected
external backend, matching the existing ProjectID behavior. FeatureNotFound
must fail initialization instead of being hidden until repeated CreateFeature
attempts. `Libraries.NvngxDlssPath` takes a directory, not the DLL filename;
the Windows installer and standalone runner now use that directory.
The modifications to OptiScaler are GPL-3.0, matching its upstream license.
No NVIDIA DLL is supplied or patched.
`0001` introduces `[DLSS] AllowExternalBackend=true`, default false. Set
`[Libraries] NvngxPath` to the absolute directory containing the Windows d4r
shim as `_nvngx.dll`. Discovery requires its GPU-free ABI-1 marker. Physical
adapter support is queried through the bridge's D3D12 requirements API after
DLL startup; vendor, LUID and HIP architecture are retained.
The configured `D4R_NGX_CORE` absolute path bypasses game-facing NGX DLL
redirection. The external backend loads its own NVAPI provider. An explicitly
selected external DLSS backend reports initialization/load errors instead of
silently switching to FSR. The patch fixes the upstream loader's filesystem
exception by making IsSubpath a lexical check, and retains a PDB for diagnosis.
`0002` installs the command backend at D3D12 device discovery, before NGX Init
and before OptiScaler's own method hooks. Command signatures created during
game startup therefore retain their public argument descriptions for replay.
The standalone runner's `-EarlyIndirectProbe` exercises this startup order.
`0003` preserves the Project ID and engine identity through OptiScaler's
older `Init_with_ProjectID` entry point used by its XeSS/FSR inputs. It also
propagates an explicit external backend initialization failure. Reproduce
with the D3D12 runner's `-NgxAbi project-legacy`.
Build with Microsoft Build Tools 2022, v143 and Windows SDK 10.0.26100:
```powershell
.\scripts\windows\build-optiscaler-windows.ps1
```
The script clones the pinned source if absent, checks/applies the patch,
initializes pinned submodules, invokes MSBuild and writes the DLL, PDB, license
and build metadata into `dist/optiscaler-windows-d4r`. Existing source is not
reset. The upstream packaging post-build event is disabled for this build.
The official bootstrapper is https://aka.ms/vs/17/release/vs_buildtools.exe;
install the `Microsoft.VisualStudio.Workload.VCTools`,
`Microsoft.VisualStudio.Component.VC.Tools.x86.x64` and
`Microsoft.VisualStudio.Component.Windows11SDK.26100` components. The audited
local build uses MSVC 14.44.35207 / Build Tools 17.14.
For standalone verification add
`-OptiScalerDll <absolute-dist-path>/OptiScaler.dll -CaptureExceptions`
to the documented K/M runner. Its private INI selects DLSS, disables frame
generation and keeps RestoreComputeSignature, RestoreGraphicSignature and
ExtendedStateRestore false. Use `-RequireNativeNetwork`; finite output alone
cannot distinguish DLSS from an unwanted FSR replacement.