mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-05-04 00:31:35 +00:00
Make use of enums for fakenvapi + expend enum support in the config
This commit is contained in:
+61
-33
@@ -274,31 +274,31 @@ bool Config::Reload(std::filesystem::path iniPath)
|
||||
constexpr size_t presetCount = 17;
|
||||
|
||||
if (auto setting = readInt("DLSS", "RenderPresetForAll");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
RenderPresetForAll.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSS", "RenderPresetDLAA");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
RenderPresetDLAA.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSS", "RenderPresetUltraQuality");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
RenderPresetUltraQuality.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSS", "RenderPresetQuality");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
RenderPresetQuality.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSS", "RenderPresetBalanced");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
RenderPresetBalanced.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSS", "RenderPresetPerformance");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
RenderPresetPerformance.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSS", "RenderPresetUltraPerformance");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
RenderPresetUltraPerformance.set_from_config(setting);
|
||||
}
|
||||
// DLSSD
|
||||
@@ -309,31 +309,31 @@ bool Config::Reload(std::filesystem::path iniPath)
|
||||
constexpr size_t presetCount = 6;
|
||||
|
||||
if (auto setting = readInt("DLSSD", "RenderPresetForAll");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
DLSSDRenderPresetForAll.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSSD", "RenderPresetDLAA");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
DLSSDRenderPresetDLAA.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSSD", "RenderPresetUltraQuality");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
DLSSDRenderPresetUltraQuality.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSSD", "RenderPresetQuality");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
DLSSDRenderPresetQuality.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSSD", "RenderPresetBalanced");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
DLSSDRenderPresetBalanced.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSSD", "RenderPresetPerformance");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
DLSSDRenderPresetPerformance.set_from_config(setting);
|
||||
|
||||
if (auto setting = readInt("DLSSD", "RenderPresetUltraPerformance");
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == 0x00FFFFFF))
|
||||
setting.has_value() && setting >= 0 && (setting < presetCount || setting == NV_PRESET_LATEST))
|
||||
DLSSDRenderPresetUltraPerformance.set_from_config(setting);
|
||||
}
|
||||
|
||||
@@ -461,13 +461,11 @@ bool Config::Reload(std::filesystem::path iniPath)
|
||||
// Output Scaling
|
||||
{
|
||||
OutputScalingEnabled.set_from_config(readBool("OutputScaling", "Enabled"));
|
||||
if (auto setting = readInt("OutputScaling", "Downscaler"); setting.has_value())
|
||||
{
|
||||
if (setting.value() >= 0 && setting.value() < static_cast<int>(Scaler::Count))
|
||||
OutputScalingDownscaler.set_from_config(static_cast<Scaler>(setting.value()));
|
||||
else
|
||||
OutputScalingDownscaler.reset();
|
||||
}
|
||||
|
||||
if (auto v = readEnum<Scaler>("OutputScaling", "Downscaler"))
|
||||
OutputScalingDownscaler.set_from_config(*v);
|
||||
else
|
||||
OutputScalingDownscaler.reset();
|
||||
|
||||
if (auto setting = readFloat("OutputScaling", "Multiplier"); setting.has_value())
|
||||
OutputScalingMultiplier.set_from_config(std::clamp(setting.value(), 0.5f, 3.0f));
|
||||
@@ -605,8 +603,16 @@ bool Config::Reload(std::filesystem::path iniPath)
|
||||
UseFakenvapi.set_from_config(readBool("fakenvapi", "UseFakenvapi"));
|
||||
XeFGWithoutXeLL.set_from_config(readBool("fakenvapi", "XeFGWithoutXeLL"));
|
||||
FN_ForceLatencyFlex.set_from_config(readBool("fakenvapi", "ForceLatencyFlex"));
|
||||
FN_LatencyFlexMode.set_from_config(readUInt("fakenvapi", "LatencyFlexMode"));
|
||||
FN_ForceReflex.set_from_config(readUInt("fakenvapi", "ForceReflex"));
|
||||
|
||||
if (auto v = readEnum<LFXMode>("fakenvapi", "LatencyFlexMode"))
|
||||
FN_LatencyFlexMode.set_from_config(*v);
|
||||
else
|
||||
FN_LatencyFlexMode.reset();
|
||||
|
||||
if (auto v = readEnum<ForceReflex>("fakenvapi", "ForceReflex"))
|
||||
FN_ForceReflex.set_from_config(*v);
|
||||
else
|
||||
FN_ForceReflex.reset();
|
||||
}
|
||||
|
||||
// Inputs
|
||||
@@ -701,23 +707,28 @@ std::string GetBoolValue(std::optional<bool> value)
|
||||
return value.value() ? "true" : "false";
|
||||
}
|
||||
|
||||
std::string GetIntValue(std::optional<int> value, bool getHex = false)
|
||||
template <typename T> std::string GetIntValue(std::optional<T> value, bool getHex = false)
|
||||
{
|
||||
if (!value.has_value())
|
||||
return "auto";
|
||||
|
||||
if (getHex)
|
||||
return std::format("{:#x}", value.value());
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
using Underlying = std::underlying_type_t<T>;
|
||||
Underlying v = static_cast<Underlying>(value.value());
|
||||
|
||||
return std::to_string(value.value());
|
||||
}
|
||||
if (getHex)
|
||||
return std::format("{:#x}", v);
|
||||
|
||||
std::string GetIntValue(std::optional<Scaler> value)
|
||||
{
|
||||
if (!value.has_value())
|
||||
return "auto";
|
||||
return std::to_string(v);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getHex)
|
||||
return std::format("{:#x}", value.value());
|
||||
|
||||
return std::to_string(static_cast<int>(value.value()));
|
||||
return std::to_string(value.value());
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetFloatValue(std::optional<float> value)
|
||||
@@ -1563,6 +1574,23 @@ std::optional<bool> Config::readBool(std::string section, std::string key)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Only use for unsigned enums that have Enum::Count as the last entry
|
||||
template <typename Enum> std::optional<Enum> Config::readEnum(std::string section, std::string key)
|
||||
{
|
||||
static_assert(std::is_enum_v<Enum>, "Enum type required");
|
||||
|
||||
auto value = readUInt(section, key);
|
||||
if (!value.has_value())
|
||||
return std::nullopt;
|
||||
|
||||
using Underlying = std::underlying_type_t<Enum>;
|
||||
|
||||
if (*value < static_cast<Underlying>(Enum::Count))
|
||||
return static_cast<Enum>(*value);
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Config* Config::Instance()
|
||||
{
|
||||
if (!_config)
|
||||
|
||||
+11
-6
@@ -157,6 +157,7 @@ template <class T, HasDefaultValue defaultState = WithDefault> class CustomOptio
|
||||
};
|
||||
|
||||
constexpr inline int UnboundKey = -1;
|
||||
constexpr uint32_t NV_PRESET_LATEST = 0x00FFFFFF;
|
||||
|
||||
enum FpsOverlay : uint32_t
|
||||
{
|
||||
@@ -184,18 +185,20 @@ enum class Scaler : uint32_t
|
||||
Count
|
||||
};
|
||||
|
||||
enum class ForceReflex
|
||||
enum class ForceReflex : uint32_t
|
||||
{
|
||||
InGame,
|
||||
ForceDisable,
|
||||
ForceEnable
|
||||
ForceEnable,
|
||||
Count
|
||||
};
|
||||
|
||||
enum class LFXMode
|
||||
enum class LFXMode : uint32_t
|
||||
{
|
||||
Conservative,
|
||||
Aggressive,
|
||||
ReflexIDs
|
||||
ReflexIDs,
|
||||
Count
|
||||
};
|
||||
|
||||
class Config
|
||||
@@ -531,8 +534,8 @@ class Config
|
||||
CustomOptional<bool> UseFakenvapi { true };
|
||||
CustomOptional<bool> XeFGWithoutXeLL { false };
|
||||
CustomOptional<bool> FN_ForceLatencyFlex { false };
|
||||
CustomOptional<uint32_t> FN_LatencyFlexMode { 0 }; // conservative - aggressive - reflex ids
|
||||
CustomOptional<uint32_t> FN_ForceReflex { 0 }; // in-game - force disable - force enable
|
||||
CustomOptional<LFXMode> FN_LatencyFlexMode { LFXMode::Conservative };
|
||||
CustomOptional<ForceReflex> FN_ForceReflex { ForceReflex::InGame };
|
||||
|
||||
// Inputs
|
||||
CustomOptional<bool> EnableDlssInputs { true };
|
||||
@@ -587,4 +590,6 @@ class Config
|
||||
std::optional<int> readInt(std::string section, std::string key);
|
||||
std::optional<uint32_t> readUInt(std::string section, std::string key);
|
||||
std::optional<bool> readBool(std::string section, std::string key);
|
||||
|
||||
template <typename Enum> std::optional<Enum> readEnum(std::string section, std::string key);
|
||||
};
|
||||
|
||||
@@ -730,7 +730,7 @@ sl::Result StreamlineHooks::hkslReflexSetOptions(const sl::ReflexOptions& option
|
||||
|
||||
sl::ReflexOptions newOptions = options;
|
||||
|
||||
if (Config::Instance()->FN_ForceReflex == 2)
|
||||
if (Config::Instance()->FN_ForceReflex == ForceReflex::ForceEnable)
|
||||
newOptions.mode = sl::ReflexMode::eLowLatencyWithBoost;
|
||||
|
||||
// Will cause a pink screen when used with DLSSG
|
||||
@@ -808,7 +808,7 @@ bool StreamlineHooks::hkreflex_slSetConstants_sl1(const void* data, uint32_t fra
|
||||
|
||||
LOG_DEBUG("mode: {}, frameIndex: {}, id: {}", (uint32_t) constants.mode, frameIndex, id);
|
||||
|
||||
if (Config::Instance()->FN_ForceReflex == 2)
|
||||
if (Config::Instance()->FN_ForceReflex == ForceReflex::ForceEnable)
|
||||
constants.mode = sl1::ReflexMode::eReflexModeLowLatencyWithBoost;
|
||||
|
||||
// Will cause a pink screen when used with DLSSG
|
||||
@@ -986,11 +986,11 @@ void StreamlineHooks::updateForceReflex()
|
||||
|
||||
auto forceReflex = Config::Instance()->FN_ForceReflex.value_or_default();
|
||||
|
||||
if (forceReflex == 2)
|
||||
if (forceReflex == ForceReflex::ForceEnable)
|
||||
options.mode = sl::ReflexMode::eLowLatencyWithBoost;
|
||||
else if (forceReflex == 1)
|
||||
else if (forceReflex == ForceReflex::ForceDisable)
|
||||
options.mode = sl::ReflexMode::eOff;
|
||||
else if (forceReflex == 0)
|
||||
else if (forceReflex == ForceReflex::InGame)
|
||||
options.mode = reflexGamesLastMode;
|
||||
|
||||
auto result = o_slReflexSetOptions(options);
|
||||
|
||||
@@ -1230,8 +1230,6 @@ template <HasDefaultValue B> void MenuCommon::AddResourceBarrier(std::string nam
|
||||
}
|
||||
}
|
||||
|
||||
constexpr uint32_t NV_PRESET_LATEST = 0x00FFFFFF;
|
||||
|
||||
// TODO: disable presets based on the detected DLSS version
|
||||
template <HasDefaultValue B> void MenuCommon::AddDLSSRenderPreset(std::string name, CustomOptional<uint32_t, B>* value)
|
||||
{
|
||||
@@ -4506,12 +4504,12 @@ bool MenuCommon::RenderMenu()
|
||||
ImGui::EndDisabled();
|
||||
|
||||
// clang-format off
|
||||
static const std::vector<MenuOption<uint32_t>> lfx_modes = {
|
||||
{ 0, "Conservative",
|
||||
static const std::vector<MenuOption<LFXMode>> lfx_modes = {
|
||||
{ LFXMode::Conservative, "Conservative",
|
||||
"The safest, but might not reduce latency well" },
|
||||
{ 1, "Aggressive",
|
||||
{ LFXMode::Aggressive, "Aggressive",
|
||||
"Improves latency, but in some cases will lower FPS more than expected" },
|
||||
{ 2, "Reflex ID",
|
||||
{ LFXMode::ReflexIDs, "Reflex ID",
|
||||
"Best when can be used, some games are not compatible (i.e. cyberpunk) and will fallback to Aggressive" }
|
||||
};
|
||||
|
||||
@@ -4522,9 +4520,9 @@ bool MenuCommon::RenderMenu()
|
||||
PopulateCombo("LatencyFlex mode", config->FN_LatencyFlexMode, lfx_modes);
|
||||
ImGui::EndDisabled();
|
||||
|
||||
static std::vector<MenuOption<uint32_t>> reflex_modes = { { 0, "Follow in-game" },
|
||||
{ 1, "Force Disable" },
|
||||
{ 2, "Force Enable" } };
|
||||
static std::vector<MenuOption<ForceReflex>> reflex_modes = { { ForceReflex::InGame, "Follow in-game" },
|
||||
{ ForceReflex::ForceDisable, "Force Disable" },
|
||||
{ ForceReflex::ForceEnable, "Force Enable" } };
|
||||
|
||||
if (state.activeFgOutput == FGOutput::XeFG)
|
||||
reflex_modes[1].set_disabled(true);
|
||||
|
||||
Reference in New Issue
Block a user