Skip to content

Commit ec46e0e

Browse files
committed
Merge branch 'fakenvapi-merge' into HEAD
2 parents f6d2e0c + 0d4e143 commit ec46e0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4834
-504
lines changed

OptiScaler.ini

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ SkipDispatchForHudless=auto
448448
; -------------------------------------------------------
449449
[Framerate]
450450
; -------------------------------------------------------
451-
; Frame rate limit that uses Reflex, therefore the game has to support Reflex and have it enabled
452-
; AMD users can use Fakenvapi to get this feature working
451+
; Frame rate limit that uses Reflex whenever possible
452+
; This includes any tech that replaces Reflex like XeLL or AntiLag 2
453453
; float - Default (auto) is 0.0 (disabled)
454454
FramerateLimit=auto
455455

@@ -886,29 +886,45 @@ LoadSpecialK=auto
886886
; true or false - Default (auto) is false
887887
LoadReshade=auto
888888

889+
; -------------------------------------------------------
890+
[fakenvapi]
891+
; -------------------------------------------------------
892+
; Use fakenvapi when nvapi64.dll is missing.
893+
; fakenvapi replaces nvapi calls allowing for features like AntiLag 2 or XeLL to replace Reflex
894+
; Sometimes also required for DLSS/DLSSG to show up
895+
; true or false - Default (auto) is true
896+
UseFakenvapi=auto
897+
898+
; Do not use fakenvapi for converting Reflex calls to XeLL calls when using XeFG
899+
; true or false - Default (auto) is false
900+
XeFGWithoutXeLL=auto
901+
902+
; Tries to use LatencyFlex even when better options are avaliable
903+
; Doesn't take effect when using XeFG
904+
; true or false - Default (auto) is false
905+
ForceLatencyFlex=auto
906+
907+
; Controls how latencyflex works
908+
; 0 = conservative
909+
; 1 = aggressive, will improve latency but in some cases will lower fps more than expected
910+
; 2 = use reflex frame ids, some games are not compatible (i.e. cyberpunk) and will fallback to aggressive
911+
; Default (auto) is 0
912+
LatencyFlexMode=auto
913+
914+
; Force Reflex state, useful for games that only enable Reflex when using DLSSG without a separate toggle for Reflex
915+
; 0 - follow in-game setting, 1 - force disable, 2 - force enable
916+
; Default (auto) is 0
917+
ForceReflex=auto
889918

890919

891920
; -------------------------------------------------------
892921
[NvApi]
893922
; -------------------------------------------------------
894-
; Override loading of nvapi64.dll
895-
; true or false - Default (auto) is false for Nvidia, true for others
896-
OverrideNvapiDll=auto
897-
898923
; Disable FlipMetering
899924
; Fix the thick frametime graph caused by Nvidia's Flip Metering when using NukemFG, needs Fakenvapi to work
900925
; true or false - Default (auto) is false for Nvidia, true for others
901926
DisableFlipMetering=auto
902927

903-
; If nvapi override enabled and file path defined here
904-
; will try to load it from here, otherwise will check current folder for nvapi64.dll
905-
; Default (auto) is local folder
906-
NvapiDllPath=auto
907-
908-
; Do not use fakenvapi for converting Reflex calls to XeLL calls on Nvidia GPUs
909-
; Default (auto) is false
910-
DontUseFakenvapiForXeLLOnNvidia=auto
911-
912928

913929

914930
; -------------------------------------------------------

OptiScaler/Config.cpp

Lines changed: 80 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <SimpleIni.h>
1111

1212
static CSimpleIniA ini;
13-
static CSimpleIniA fakenvapiIni;
1413

1514
static inline int64_t GetTicks()
1615
{
@@ -275,31 +274,31 @@ bool Config::Reload(std::filesystem::path iniPath)
275274
constexpr size_t presetCount = 17;
276275

277276
if (auto setting = readInt("DLSS", "RenderPresetForAll");
278-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
277+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
279278
RenderPresetForAll.set_from_config(setting);
280279

281280
if (auto setting = readInt("DLSS", "RenderPresetDLAA");
282-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
281+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
283282
RenderPresetDLAA.set_from_config(setting);
284283

285284
if (auto setting = readInt("DLSS", "RenderPresetUltraQuality");
286-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
285+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
287286
RenderPresetUltraQuality.set_from_config(setting);
288287

289288
if (auto setting = readInt("DLSS", "RenderPresetQuality");
290-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
289+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
291290
RenderPresetQuality.set_from_config(setting);
292291

293292
if (auto setting = readInt("DLSS", "RenderPresetBalanced");
294-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
293+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
295294
RenderPresetBalanced.set_from_config(setting);
296295

297296
if (auto setting = readInt("DLSS", "RenderPresetPerformance");
298-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
297+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
299298
RenderPresetPerformance.set_from_config(setting);
300299

301300
if (auto setting = readInt("DLSS", "RenderPresetUltraPerformance");
302-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
301+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
303302
RenderPresetUltraPerformance.set_from_config(setting);
304303
}
305304
// DLSSD
@@ -310,31 +309,31 @@ bool Config::Reload(std::filesystem::path iniPath)
310309
constexpr size_t presetCount = 6;
311310

312311
if (auto setting = readInt("DLSSD", "RenderPresetForAll");
313-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
312+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
314313
DLSSDRenderPresetForAll.set_from_config(setting);
315314

316315
if (auto setting = readInt("DLSSD", "RenderPresetDLAA");
317-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
316+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
318317
DLSSDRenderPresetDLAA.set_from_config(setting);
319318

320319
if (auto setting = readInt("DLSSD", "RenderPresetUltraQuality");
321-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
320+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
322321
DLSSDRenderPresetUltraQuality.set_from_config(setting);
323322

324323
if (auto setting = readInt("DLSSD", "RenderPresetQuality");
325-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
324+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
326325
DLSSDRenderPresetQuality.set_from_config(setting);
327326

328327
if (auto setting = readInt("DLSSD", "RenderPresetBalanced");
329-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
328+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
330329
DLSSDRenderPresetBalanced.set_from_config(setting);
331330

332331
if (auto setting = readInt("DLSSD", "RenderPresetPerformance");
333-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
332+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
334333
DLSSDRenderPresetPerformance.set_from_config(setting);
335334

336335
if (auto setting = readInt("DLSSD", "RenderPresetUltraPerformance");
337-
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
336+
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
338337
DLSSDRenderPresetUltraPerformance.set_from_config(setting);
339338
}
340339

@@ -462,13 +461,11 @@ bool Config::Reload(std::filesystem::path iniPath)
462461
// Output Scaling
463462
{
464463
OutputScalingEnabled.set_from_config(readBool("OutputScaling", "Enabled"));
465-
if (auto setting = readInt("OutputScaling", "Downscaler"); setting.has_value())
466-
{
467-
if (setting.value() >= 0 && setting.value() < static_cast<int>(Scaler::Count))
468-
OutputScalingDownscaler.set_from_config(static_cast<Scaler>(setting.value()));
469-
else
470-
OutputScalingDownscaler.reset();
471-
}
464+
465+
if (auto v = readEnum<Scaler>("OutputScaling", "Downscaler"))
466+
OutputScalingDownscaler.set_from_config(*v);
467+
else
468+
OutputScalingDownscaler.reset();
472469

473470
if (auto setting = readFloat("OutputScaling", "Multiplier"); setting.has_value())
474471
OutputScalingMultiplier.set_from_config(std::clamp(setting.value(), 0.5f, 3.0f));
@@ -575,9 +572,6 @@ bool Config::Reload(std::filesystem::path iniPath)
575572

576573
// NvApi
577574
{
578-
OverrideNvapiDll.set_from_config(readBool("NvApi", "OverrideNvapiDll"));
579-
DontUseFakenvapiForXeLLOnNvidia.set_from_config(readBool("NvApi", "DontUseFakenvapiForXeLLOnNvidia"));
580-
NvapiDllPath.set_from_config(readWString("NvApi", "NvapiDllPath", true));
581575
DisableFlipMetering.set_from_config(readBool("NvApi", "DisableFlipMetering"));
582576
}
583577

@@ -604,6 +598,23 @@ bool Config::Reload(std::filesystem::path iniPath)
604598
SpoofUser32.set_from_config(readBool("Spoofing", "User32"));
605599
}
606600

601+
// fakenvapi
602+
{
603+
UseFakenvapi.set_from_config(readBool("fakenvapi", "UseFakenvapi"));
604+
XeFGWithoutXeLL.set_from_config(readBool("fakenvapi", "XeFGWithoutXeLL"));
605+
FN_ForceLatencyFlex.set_from_config(readBool("fakenvapi", "ForceLatencyFlex"));
606+
607+
if (auto v = readEnum<LFXMode>("fakenvapi", "LatencyFlexMode"))
608+
FN_LatencyFlexMode.set_from_config(*v);
609+
else
610+
FN_LatencyFlexMode.reset();
611+
612+
if (auto v = readEnum<ForceReflex>("fakenvapi", "ForceReflex"))
613+
FN_ForceReflex.set_from_config(*v);
614+
else
615+
FN_ForceReflex.reset();
616+
}
617+
607618
// Inputs
608619
{
609620
EnableDlssInputs.set_from_config(readBool("Inputs", "EnableDlssInputs"));
@@ -668,9 +679,6 @@ bool Config::Reload(std::filesystem::path iniPath)
668679
VsyncInterval.set_from_config(readInt("V-Sync", "SyncInterval"));
669680
}
670681

671-
if (fakenvapi::isUsingFakenvapi())
672-
return ReloadFakenvapi();
673-
674682
return true;
675683
}
676684

@@ -699,23 +707,28 @@ std::string GetBoolValue(std::optional<bool> value)
699707
return value.value() ? "true" : "false";
700708
}
701709

702-
std::string GetIntValue(std::optional<int> value, bool getHex = false)
710+
template <typename T> std::string GetIntValue(std::optional<T> value, bool getHex = false)
703711
{
704712
if (!value.has_value())
705713
return "auto";
706714

707-
if (getHex)
708-
return std::format("{:#x}", value.value());
715+
if constexpr (std::is_enum_v<T>)
716+
{
717+
using Underlying = std::underlying_type_t<T>;
718+
Underlying v = static_cast<Underlying>(value.value());
709719

710-
return std::to_string(value.value());
711-
}
720+
if (getHex)
721+
return std::format("{:#x}", v);
712722

713-
std::string GetIntValue(std::optional<Scaler> value)
714-
{
715-
if (!value.has_value())
716-
return "auto";
723+
return std::to_string(v);
724+
}
725+
else
726+
{
727+
if (getHex)
728+
return std::format("{:#x}", value.value());
717729

718-
return std::to_string(static_cast<int>(value.value()));
730+
return std::to_string(value.value());
731+
}
719732
}
720733

721734
std::string GetFloatValue(std::optional<float> value)
@@ -1223,12 +1236,6 @@ bool Config::SaveIni()
12231236

12241237
// NvApi
12251238
{
1226-
ini.SetValue("NvApi", "OverrideNvapiDll",
1227-
GetBoolValue(Instance()->OverrideNvapiDll.value_for_config()).c_str());
1228-
ini.SetValue("NvApi", "DontUseFakenvapiForXeLLOnNvidia",
1229-
GetBoolValue(Instance()->DontUseFakenvapiForXeLLOnNvidia.value_for_config()).c_str());
1230-
ini.SetValue("NvApi", "NvapiDllPath",
1231-
wstring_to_string(Instance()->NvapiDllPath.value_for_config_or(L"auto")).c_str());
12321239
ini.SetValue("NvApi", "DisableFlipMetering",
12331240
GetBoolValue(Instance()->DisableFlipMetering.value_for_config()).c_str());
12341241
}
@@ -1297,6 +1304,18 @@ bool Config::SaveIni()
12971304
ini.SetValue("Plugins", "LoadAsiPlugins", GetBoolValue(Instance()->LoadAsiPlugins.value_for_config()).c_str());
12981305
}
12991306

1307+
// fakenvapi
1308+
{
1309+
ini.SetValue("fakenvapi", "UseFakenvapi", GetBoolValue(Instance()->UseFakenvapi.value_for_config()).c_str());
1310+
ini.SetValue("fakenvapi", "XeFGWithoutXeLL",
1311+
GetBoolValue(Instance()->XeFGWithoutXeLL.value_for_config()).c_str());
1312+
ini.SetValue("fakenvapi", "ForceLatencyFlex",
1313+
GetBoolValue(Instance()->FN_ForceLatencyFlex.value_for_config()).c_str());
1314+
ini.SetValue("fakenvapi", "LatencyFlexMode",
1315+
GetIntValue(Instance()->FN_LatencyFlexMode.value_for_config()).c_str());
1316+
ini.SetValue("fakenvapi", "ForceReflex", GetIntValue(Instance()->FN_ForceReflex.value_for_config()).c_str());
1317+
}
1318+
13001319
// inputs
13011320
{
13021321
ini.SetValue("Inputs", "EnableDlssInputs",
@@ -1342,51 +1361,6 @@ bool Config::SaveIni()
13421361
return ini.SaveFile(absoluteFileName.wstring().c_str()) >= 0;
13431362
}
13441363

1345-
bool Config::ReloadFakenvapi()
1346-
{
1347-
auto FN_iniPath = Util::DllPath().parent_path() / L"fakenvapi.ini";
1348-
if (NvapiDllPath.has_value())
1349-
FN_iniPath = std::filesystem::path(NvapiDllPath.value()).parent_path() / L"fakenvapi.ini";
1350-
1351-
auto pathWStr = FN_iniPath.wstring();
1352-
1353-
LOG_INFO("Trying to load fakenvapi's ini from: {0}", wstring_to_string(pathWStr));
1354-
1355-
if (fakenvapiIni.LoadFile(FN_iniPath.c_str()) == SI_OK)
1356-
{
1357-
FN_EnableLogs = fakenvapiIni.GetLongValue("fakenvapi", "enable_logs", true);
1358-
FN_EnableTraceLogs = fakenvapiIni.GetLongValue("fakenvapi", "enable_trace_logs", false);
1359-
FN_ForceLatencyFlex = fakenvapiIni.GetLongValue("fakenvapi", "force_latencyflex", false);
1360-
FN_LatencyFlexMode = fakenvapiIni.GetLongValue("fakenvapi", "latencyflex_mode", 0);
1361-
FN_ForceReflex = fakenvapiIni.GetLongValue("fakenvapi", "force_reflex", 0);
1362-
1363-
return true;
1364-
}
1365-
1366-
return false;
1367-
}
1368-
1369-
bool Config::SaveFakenvapiIni()
1370-
{
1371-
auto FN_iniPath = Util::DllPath().parent_path() / L"fakenvapi.ini";
1372-
if (NvapiDllPath.has_value())
1373-
FN_iniPath = std::filesystem::path(NvapiDllPath.value()).parent_path() / L"fakenvapi.ini";
1374-
1375-
auto pathWStr = FN_iniPath.wstring();
1376-
1377-
LOG_INFO("Trying to save fakenvapi's ini to: {0}", wstring_to_string(pathWStr));
1378-
1379-
fakenvapiIni.SetLongValue("fakenvapi", "enable_logs", FN_EnableLogs.value_or(true));
1380-
fakenvapiIni.SetLongValue("fakenvapi", "enable_trace_logs", FN_EnableTraceLogs.value_or(false));
1381-
fakenvapiIni.SetLongValue("fakenvapi", "force_latencyflex", FN_ForceLatencyFlex.value_or(false));
1382-
fakenvapiIni.SetLongValue("fakenvapi", "latencyflex_mode", FN_LatencyFlexMode.value_or(0));
1383-
fakenvapiIni.SetLongValue("fakenvapi", "force_reflex", FN_ForceReflex.value_or(0));
1384-
1385-
StreamlineHooks::updateForceReflex();
1386-
1387-
return fakenvapiIni.SaveFile(FN_iniPath.wstring().c_str()) >= 0;
1388-
}
1389-
13901364
bool Config::SaveXeFG()
13911365
{
13921366
ini.SetValue("XeFG", "DepthInverted", GetBoolValue(Instance()->FGXeFGDepthInverted.value_for_config()).c_str());
@@ -1600,6 +1574,23 @@ std::optional<bool> Config::readBool(std::string section, std::string key)
16001574
return std::nullopt;
16011575
}
16021576

1577+
// Only use for unsigned enums that have Enum::Count as the last entry
1578+
template <typename Enum> std::optional<Enum> Config::readEnum(std::string section, std::string key)
1579+
{
1580+
static_assert(std::is_enum_v<Enum>, "Enum type required");
1581+
1582+
auto value = readUInt(section, key);
1583+
if (!value.has_value())
1584+
return std::nullopt;
1585+
1586+
using Underlying = std::underlying_type_t<Enum>;
1587+
1588+
if (*value < static_cast<Underlying>(Enum::Count))
1589+
return static_cast<Enum>(*value);
1590+
1591+
return std::nullopt;
1592+
}
1593+
16031594
Config* Config::Instance()
16041595
{
16051596
if (!_config)

0 commit comments

Comments
 (0)