From 663f976a2ff00c2fd80511919bc5fbaf595ca520 Mon Sep 17 00:00:00 2001 From: cdozdil Date: Fri, 22 May 2026 10:55:53 +0300 Subject: [PATCH] Changed DontCreateD3D12DeviceForLuma to CreateD3D12DeviceForLuma for more user controllable behaviour --- OptiScaler.ini | 8 ++++---- OptiScaler/Config.cpp | 6 +++--- OptiScaler/Config.h | 2 +- OptiScaler/Util.cpp | 6 +++--- OptiScaler/Util.h | 2 ++ OptiScaler/dllmain.cpp | 33 ++++++++++++++++++++------------- OptiScaler/hooks/Dxgi_Hooks.cpp | 4 ++-- 7 files changed, 35 insertions(+), 26 deletions(-) diff --git a/OptiScaler.ini b/OptiScaler.ini index 7d8261a9..f8a2f4d9 100644 --- a/OptiScaler.ini +++ b/OptiScaler.ini @@ -1403,11 +1403,11 @@ DisableOverlays=auto ; true or false - Default (auto) is false SimulateWaitableObject=auto -; When using Luma mod and Agility update is enabled -; OptiScaler will delay loading of Reshade and create D3D12 device for Luma first -; This option will prevent creation of D3D12 device for Luma mod +; OptiScaler will delay loading of Reshade and create D3D12 device first +; This option will prevent warnings/crashes with Luma and some other ReShade mods +; When using Luma mod and this will be enabled ; true or false - Default (auto) is false -DontCreateD3D12DeviceForLuma=auto +CreateD3D12DeviceForLuma=auto ; OptiScaler will try to force High Performance GPU ; true or false - Default (auto) is false diff --git a/OptiScaler/Config.cpp b/OptiScaler/Config.cpp index 77dddc40..688636b7 100644 --- a/OptiScaler/Config.cpp +++ b/OptiScaler/Config.cpp @@ -608,7 +608,7 @@ bool Config::Reload(std::filesystem::path iniPath) MaskResourceBarrier.set_from_config(readInt("Hotfix", "ColorMaskResourceBarrier")); ExposureResourceBarrier.set_from_config(readInt("Hotfix", "ExposureResourceBarrier")); OutputResourceBarrier.set_from_config(readInt("Hotfix", "OutputResourceBarrier")); - DontCreateD3D12DeviceForLuma.set_from_config(readBool("Hotfix", "DontCreateD3D12DeviceForLuma")); + CreateD3D12DeviceForLuma.set_from_config(readBool("Hotfix", "CreateD3D12DeviceForLuma")); } // Dx11 with Dx12 @@ -1276,8 +1276,8 @@ bool Config::SaveIni() // Hotfixes { - ini.SetValue("Hotfix", "DontCreateD3D12DeviceForLuma", - GetBoolValue(Instance()->DontCreateD3D12DeviceForLuma.value_for_config()).c_str()); + ini.SetValue("Hotfix", "CreateD3D12DeviceForLuma", + GetBoolValue(Instance()->CreateD3D12DeviceForLuma.value_for_config()).c_str()); ini.SetValue("Hotfix", "CheckForUpdate", GetBoolValue(Instance()->CheckForUpdate.value_for_config()).c_str()); ini.SetValue("Hotfix", "SimulateWaitableObject", GetBoolValue(Instance()->SimulateWaitableObject.value_for_config()).c_str()); diff --git a/OptiScaler/Config.h b/OptiScaler/Config.h index 3a58b627..69b01ef1 100644 --- a/OptiScaler/Config.h +++ b/OptiScaler/Config.h @@ -404,7 +404,7 @@ class Config CustomOptional MaskResourceBarrier; // disabled by default CustomOptional OutputResourceBarrier; // disabled by default - CustomOptional DontCreateD3D12DeviceForLuma { false }; + CustomOptional CreateD3D12DeviceForLuma { false }; // Upscalers CustomOptional Dx11Upscaler { Upscaler::FSR22 }; diff --git a/OptiScaler/Util.cpp b/OptiScaler/Util.cpp index 8bd575c8..cf445fe3 100644 --- a/OptiScaler/Util.cpp +++ b/OptiScaler/Util.cpp @@ -116,7 +116,7 @@ std::string Util::GetWindowsName(const OSVERSIONINFOW& os) return "Unknown Windows Version"; } -static std::wstring ToLower(std::wstring value) +std::wstring Util::ToLower(std::wstring value) { std::transform(value.begin(), value.end(), value.begin(), [](wchar_t c) { return static_cast(std::towlower(c)); }); @@ -147,14 +147,14 @@ static bool HasUnrealBinariesParentStructure(const std::filesystem::path& exePat if (binariesDir.empty()) return false; - std::wstring binariesName = ToLower(binariesDir.filename().wstring()); + std::wstring binariesName = Util::ToLower(binariesDir.filename().wstring()); bool isBinariesFolder = binariesName == L"binaries"; if (!isBinariesFolder) return false; - std::wstring platformName = ToLower(platformDir.filename().wstring()); + std::wstring platformName = Util::ToLower(platformDir.filename().wstring()); bool isWindowsPlatformFolder = platformName == L"win64" || platformName == L"win32" || platformName == L"wingdk" || platformName == L"windows" || platformName.starts_with(L"win"); diff --git a/OptiScaler/Util.h b/OptiScaler/Util.h index a57de5fd..42758cf1 100644 --- a/OptiScaler/Util.h +++ b/OptiScaler/Util.h @@ -63,7 +63,9 @@ struct MonitorInfo std::filesystem::path ExePath(); std::filesystem::path DllPath(); std::optional NvngxPath(); + double MillisecondsNow(); +std::wstring ToLower(std::wstring value); HWND GetProcessWindow(); bool GetFileVersion(std::wstring dllPath, version_t* fileVersionOut, version_t* productVersionOut = nullptr); diff --git a/OptiScaler/dllmain.cpp b/OptiScaler/dllmain.cpp index e89ddd79..a69f826c 100644 --- a/OptiScaler/dllmain.cpp +++ b/OptiScaler/dllmain.cpp @@ -1113,15 +1113,14 @@ static void CheckWorkingMode() LOG_INFO("Loading SpecialK64.dll, result: {0:X}", (UINT64) skModule); } - // ReShade - // Do not load Reshade here is Luma is active and we will create D3D12 device for it - // We will load Reshade after D3D12 device creation in that case - if (reshadeModule == nullptr && Config::Instance()->LoadReShade.value_or_default() && - (!(State::Instance().gameQuirks & GameQuirk::CreateD3D12DeviceForLuma) || - Config::Instance()->DontCreateD3D12DeviceForLuma.value_or_default())) - { - auto rsFile = Util::ExePath().parent_path() / L"ReShade64.dll"; - SetEnvironmentVariableW(L"RESHADE_DISABLE_LOADING_CHECK", L"1"); + // ReShade + // Do not load Reshade here is Luma is active and we will create D3D12 device for it + // We will load Reshade after D3D12 device creation in that case + if (reshadeModule == nullptr && Config::Instance()->LoadReShade.value_or_default() && + !Config::Instance()->CreateD3D12DeviceForLuma.value_or_default()) + { + auto rsFile = Util::ExePath().parent_path() / L"ReShade64.dll"; + SetEnvironmentVariableW(L"RESHADE_DISABLE_LOADING_CHECK", L"1"); if (skModule != nullptr) SetEnvironmentVariableW(L"RESHADE_DISABLE_GRAPHICS_HOOK", L"1"); @@ -1540,8 +1539,10 @@ static void CheckQuirks(bool isNvidia) const auto& path = entry.path(); if (path.extension() == L".addon") { - const auto fname = path.filename().wstring(); - if (fname.rfind(L"Luma-", 0) == 0) // starts with "Luma-" + const auto fname = Util::ToLower(path.filename().wstring()); + + // starts with "luma-" or "dlaa-inject." + if (fname.rfind(L"luma-", 0) == 0 || fname.rfind(L"dlaa-inject.", 0) == 0) { lumaDetected = true; break; @@ -1565,12 +1566,15 @@ static void CheckQuirks(bool isNvidia) Config::Instance()->DontUseNTShared.set_volatile_value(true); } - if (!Config::Instance()->DontCreateD3D12DeviceForLuma.value_or_default()) + if (!Config::Instance()->CreateD3D12DeviceForLuma.has_value()) { quirks |= GameQuirk::LoadD3D12Manually; if (Config::Instance()->LoadReShade.value_or_default()) + { + Config::Instance()->CreateD3D12DeviceForLuma.set_volatile_value(true); quirks |= GameQuirk::CreateD3D12DeviceForLuma; + } } } @@ -1591,12 +1595,15 @@ static void CheckQuirks(bool isNvidia) Config::Instance()->DontUseNTShared.set_volatile_value(true); } - if (!Config::Instance()->DontCreateD3D12DeviceForLuma.value_or_default()) + if (!Config::Instance()->CreateD3D12DeviceForLuma.has_value()) { quirks |= GameQuirk::LoadD3D12Manually; if (Config::Instance()->LoadReShade.value_or_default()) + { + Config::Instance()->CreateD3D12DeviceForLuma.set_volatile_value(true); quirks |= GameQuirk::CreateD3D12DeviceForLuma; + } } } diff --git a/OptiScaler/hooks/Dxgi_Hooks.cpp b/OptiScaler/hooks/Dxgi_Hooks.cpp index 3d9b26bf..4cc50e59 100644 --- a/OptiScaler/hooks/Dxgi_Hooks.cpp +++ b/OptiScaler/hooks/Dxgi_Hooks.cpp @@ -37,7 +37,7 @@ static void InitD3D12DeviceForLuma(IDXGIFactory* factory) static void CheckLumaAndReShade(IDXGIFactory* factory) { if (!Config::Instance()->LoadReShade.value_or_default() || - !(State::Instance().gameQuirks & GameQuirk::CreateD3D12DeviceForLuma) || + !Config::Instance()->CreateD3D12DeviceForLuma.value_or_default() || State::Instance().currentD3D12Device != nullptr || creatingD3D12DeviceForLuma) { return; @@ -55,7 +55,7 @@ static void CheckLumaAndReShade(IDXGIFactory* factory) } // For Luma mod + Agility update we are creating D3D12 device early to prevent issues with Luma - if (State::Instance().gameQuirks & GameQuirk::CreateD3D12DeviceForLuma && + if (Config::Instance()->CreateD3D12DeviceForLuma.value_or_default() && State::Instance().currentD3D12Device == nullptr) { ScopedSkipDxgiLoadChecks skipDxgiLoadChecks {};