Skip to content

Commit 68278bc

Browse files
committed
Convert internal string code into enums
1 parent aa9923b commit 68278bc

21 files changed

+537
-515
lines changed

OptiScaler/Config.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ bool Config::Reload(std::filesystem::path iniPath)
5858

5959
// Upscalers
6060
{
61-
Dx11Upscaler.set_from_config(readString("Upscalers", "Dx11Upscaler", true));
62-
Dx12Upscaler.set_from_config(readString("Upscalers", "Dx12Upscaler", true));
63-
VulkanUpscaler.set_from_config(readString("Upscalers", "VulkanUpscaler", true));
61+
// transform converts only when optional has a value
62+
Dx11Upscaler.set_from_config(readString("Upscalers", "Dx11Upscaler", true).transform(CodeToUpscaler));
63+
Dx12Upscaler.set_from_config(readString("Upscalers", "Dx12Upscaler", true).transform(CodeToUpscaler));
64+
VulkanUpscaler.set_from_config(readString("Upscalers", "VulkanUpscaler", true).transform(CodeToUpscaler));
6465
}
6566

6667
// Frame Generation
@@ -744,9 +745,18 @@ bool Config::SaveIni()
744745
{
745746
// Upscalers
746747
{
747-
ini.SetValue("Upscalers", "Dx11Upscaler", Instance()->Dx11Upscaler.value_for_config_or("auto").c_str());
748-
ini.SetValue("Upscalers", "Dx12Upscaler", Instance()->Dx12Upscaler.value_for_config_or("auto").c_str());
749-
ini.SetValue("Upscalers", "VulkanUpscaler", Instance()->VulkanUpscaler.value_for_config_or("auto").c_str());
748+
auto SaveUpscaler = [&](const char* key, auto& upscalerSetting)
749+
{
750+
std::string value = upscalerSetting.value_for_config()
751+
.transform(UpscalerToCode) // Turn enum into string
752+
.value_or("auto");
753+
754+
ini.SetValue("Upscalers", key, value.c_str());
755+
};
756+
757+
SaveUpscaler("Dx11Upscaler", Instance()->Dx11Upscaler);
758+
SaveUpscaler("Dx12Upscaler", Instance()->Dx12Upscaler);
759+
SaveUpscaler("VulkanUpscaler", Instance()->VulkanUpscaler);
750760
}
751761

752762
// Frame Generation

OptiScaler/Config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ class Config
355355
CustomOptional<bool> DontCreateD3D12DeviceForLuma { false };
356356

357357
// Upscalers
358-
CustomOptional<std::string, SoftDefault> Dx11Upscaler { std::string(OptiKeys::FSR22) };
359-
CustomOptional<std::string, SoftDefault> Dx12Upscaler { std::string(OptiKeys::XeSS) };
360-
CustomOptional<std::string, SoftDefault> VulkanUpscaler { std::string(OptiKeys::FSR22) };
358+
CustomOptional<Upscaler, SoftDefault> Dx11Upscaler { Upscaler::FSR22 };
359+
CustomOptional<Upscaler, SoftDefault> Dx12Upscaler { Upscaler::XeSS };
360+
CustomOptional<Upscaler, SoftDefault> VulkanUpscaler { Upscaler::FSR22 };
361361

362362
// Output Scaling
363363
CustomOptional<bool> OutputScalingEnabled { false };

OptiScaler/OptiScaler.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ copy NUL "$(SolutionDir)x64\Release\a\!! EXTRACT ALL FILES TO GAME FOLDER !!" /Y
342342
<ClInclude Include="inputs\FSR2_Vk.h" />
343343
<ClInclude Include="inputs\XeSS_Dx11.h" />
344344
<ClInclude Include="MathUtils.h" />
345-
<ClInclude Include="OptiTexts.h" />
345+
<ClInclude Include="OptiTypes.h" />
346346
<ClInclude Include="shaders\depth_invert\DI_Common.h" />
347347
<ClInclude Include="shaders\depth_invert\DI_Dx12.h" />
348348
<ClInclude Include="shaders\depth_invert\precompiled\DI_Shader.h" />
@@ -586,6 +586,7 @@ copy NUL "$(SolutionDir)x64\Release\a\!! EXTRACT ALL FILES TO GAME FOLDER !!" /Y
586586
<ClCompile Include="nvapi\fakenvapi\low_latency_tech\ll_xell.cpp" />
587587
<ClCompile Include="nvapi\fakenvapi\low_latency_vk.cpp" />
588588
<ClCompile Include="nvapi\fakenvapi\nvapi_calls.cpp" />
589+
<ClCompile Include="OptiTypes.cpp" />
589590
<ClCompile Include="pch.cpp">
590591
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
591592
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ReleaseDebug|x64'">Create</PrecompiledHeader>

OptiScaler/OptiScaler.vcxproj.filters

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@
728728
<ClInclude Include="shaders\render_ui\RUI_Dx12.h">
729729
<Filter>Header Files</Filter>
730730
</ClInclude>
731-
<ClInclude Include="OptiTexts.h">
731+
<ClInclude Include="OptiTypes.h">
732732
<Filter>Header Files</Filter>
733733
</ClInclude>
734734
<ClInclude Include="shaders\output_scaling\precompile\bcds_kaiser2_Shader.h">
@@ -812,6 +812,9 @@
812812
<ClInclude Include="misc\IdentifyGpu.h">
813813
<Filter>Header Files</Filter>
814814
</ClInclude>
815+
<ClInclude Include="shaders\hud_copy\precompile\HudCopy_Shader.h">
816+
<Filter>Header Files</Filter>
817+
</ClInclude>
815818
</ItemGroup>
816819
<ItemGroup>
817820
<ClCompile Include="Config.cpp">
@@ -1262,6 +1265,9 @@
12621265
<ClCompile Include="misc\IdentifyGpu.cpp">
12631266
<Filter>Source Files</Filter>
12641267
</ClCompile>
1268+
<ClCompile Include="OptiTypes.cpp">
1269+
<Filter>Source Files</Filter>
1270+
</ClCompile>
12651271
</ItemGroup>
12661272
<ItemGroup>
12671273
<ResourceCompile Include="OptiScaler.rc" />

OptiScaler/OptiTexts.h

Lines changed: 0 additions & 52 deletions
This file was deleted.

OptiScaler/OptiTypes.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include "pch.h"
2+
3+
#include "OptiTypes.h"
4+
#include <misc/IdentifyGpu.h>
5+
#include <unordered_map>
6+
7+
std::string UpscalerDisplayName(Upscaler upscaler, API api)
8+
{
9+
static bool fsr4Capable = IdentifyGpu::getPrimaryGpu().fsr4Capable;
10+
11+
switch (upscaler)
12+
{
13+
case Upscaler::FSR21:
14+
return "FSR 2.1.2";
15+
16+
case Upscaler::FSR22:
17+
return "FSR 2.2.1";
18+
19+
case Upscaler::FSR31:
20+
if (fsr4Capable && api != API::DX11)
21+
return "FSR 3.X/4";
22+
else
23+
return "FSR 3.X";
24+
25+
case Upscaler::FSR21_11on12:
26+
return "FSR 2.1.2 w/Dx12";
27+
28+
case Upscaler::FSR22_11on12:
29+
return "FSR 2.2.1 w/Dx12";
30+
31+
case Upscaler::FSR31_11on12:
32+
if (fsr4Capable)
33+
return "FSR 3.X/4 w/Dx12";
34+
else
35+
return "FSR 3.X w/Dx12";
36+
37+
case Upscaler::XeSS:
38+
return "XeSS";
39+
40+
case Upscaler::XeSS_11on12:
41+
return "XeSS w/Dx12";
42+
43+
case Upscaler::DLSS:
44+
return "DLSS";
45+
}
46+
47+
return "????";
48+
}
49+
50+
// Converts enum to the string codes for config
51+
std::string UpscalerToCode(Upscaler upscaler)
52+
{
53+
switch (upscaler)
54+
{
55+
case Upscaler::XeSS:
56+
return "xess";
57+
case Upscaler::XeSS_11on12:
58+
return "xess_12";
59+
case Upscaler::FSR21:
60+
return "fsr21";
61+
case Upscaler::FSR21_11on12:
62+
return "fsr21_12";
63+
case Upscaler::FSR22:
64+
return "fsr22";
65+
case Upscaler::FSR22_11on12:
66+
return "fsr22_12";
67+
case Upscaler::FSR31:
68+
return "fsr31";
69+
case Upscaler::FSR31_11on12:
70+
return "fsr31_12";
71+
case Upscaler::DLSS:
72+
return "dlss";
73+
case Upscaler::DLSSD:
74+
return "dlssd";
75+
default: // Upscaler::Reset and unknown
76+
return "";
77+
}
78+
}
79+
80+
// Converts string codes into enum for config
81+
Upscaler CodeToUpscaler(const std::string& code)
82+
{
83+
static const std::unordered_map<std::string, Upscaler> mapping = {
84+
{ "xess", Upscaler::XeSS }, { "xess_12", Upscaler::XeSS_11on12 },
85+
{ "fsr21", Upscaler::FSR21 }, { "fsr21_12", Upscaler::FSR21_11on12 },
86+
{ "fsr22", Upscaler::FSR22 }, { "fsr22_12", Upscaler::FSR22_11on12 },
87+
{ "fsr31", Upscaler::FSR31 }, { "fsr31_12", Upscaler::FSR31_11on12 },
88+
{ "dlss", Upscaler::DLSS }, { "dlssd", Upscaler::DLSSD }
89+
};
90+
91+
auto it = mapping.find(code);
92+
return (it != mapping.end()) ? it->second : Upscaler::Reset;
93+
}

OptiScaler/OptiTypes.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#pragma once
2+
#include <string>
3+
4+
/**
5+
* @brief Common strings and identifiers used internally by OptiScaler
6+
*/
7+
namespace OptiKeys
8+
{
9+
using CString = const char[];
10+
11+
// Application name provided to upscalers
12+
inline constexpr CString ProjectID = "OptiScaler";
13+
14+
// ID code used for the Vulkan input provider
15+
inline constexpr CString VkProvider = "OptiVk";
16+
// ID code used for the DX11 input provider
17+
inline constexpr CString Dx11Provider = "OptiDx11";
18+
// ID code used for the DX12 input provider
19+
inline constexpr CString Dx12Provider = "OptiDx12";
20+
21+
inline constexpr CString FSR_UpscaleWidth = "FSR.upscaleSize.width";
22+
inline constexpr CString FSR_UpscaleHeight = "FSR.upscaleSize.height";
23+
24+
inline constexpr CString FSR_NearPlane = "FSR.cameraNear";
25+
inline constexpr CString FSR_FarPlane = "FSR.cameraFar";
26+
inline constexpr CString FSR_CameraFovVertical = "FSR.cameraFovAngleVertical";
27+
inline constexpr CString FSR_FrameTimeDelta = "FSR.frameTimeDelta";
28+
inline constexpr CString FSR_ViewSpaceToMetersFactor = "FSR.viewSpaceToMetersFactor";
29+
inline constexpr CString FSR_TransparencyAndComp = "FSR.transparencyAndComposition";
30+
inline constexpr CString FSR_Reactive = "FSR.reactive";
31+
32+
} // namespace OptiKeys
33+
34+
typedef enum API
35+
{
36+
NotSelected = 0,
37+
DX11,
38+
DX12,
39+
Vulkan,
40+
} API;
41+
42+
enum class Upscaler
43+
{
44+
45+
XeSS, // "xess", used for the XeSS upscaler backend
46+
47+
XeSS_11on12, // "xess_12", used for the XeSS upscaler backend used with the DirectX 11 on 12 compatibility
48+
// layer
49+
50+
FSR21, // "fsr21", used for the FSR 2.1.x upscaler backend
51+
52+
FSR21_11on12, // "fsr21_12", used for the FSR 2.1.x upscaler backend used with the DirectX 11 on 12
53+
// compatibility layer
54+
55+
FSR22, // "fsr22", used for the FSR 2.2.x upscaler backend
56+
57+
FSR22_11on12, // "fsr22_12", used for the FSR 2.2.x upscaler backend used with the DirectX 11 on 12
58+
// compatibility layer
59+
60+
FSR31, // "fsr31", used for the FSR 3.1+ upscaler backend
61+
62+
FSR31_11on12, // "fsr31_12", used for the FSR 3.1+ upscaler backend used with the DirectX 11 on 12
63+
// compatibility layer
64+
65+
DLSS, // "dlss", used for the DLSS upscaler backend
66+
67+
DLSSD, // "dlssd", used for the DLSS-D/Ray Reconstruction upscaler+denoiser backend
68+
Reset
69+
};
70+
71+
std::string UpscalerDisplayName(Upscaler upscaler, API api = API::NotSelected);
72+
73+
// Converts enum to the string codes for config
74+
std::string UpscalerToCode(Upscaler upscaler);
75+
76+
// Converts string codes into enum for config
77+
Upscaler CodeToUpscaler(const std::string& code);

OptiScaler/State.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
#include <ankerl/unordered_dense.h>
1111
#include <mutex>
1212

13-
typedef enum API
14-
{
15-
NotSelected = 0,
16-
DX11,
17-
DX12,
18-
Vulkan,
19-
} API;
20-
2113
enum class FGPreset : uint32_t
2214
{
2315
NoFG,
@@ -160,7 +152,7 @@ class State
160152

161153
// for realtime changes
162154
ankerl::unordered_dense::map<unsigned int, bool> changeBackend;
163-
std::string newBackend = "";
155+
Upscaler newBackend = Upscaler::Reset;
164156

165157
// XeSS debug stuff
166158
bool xessDebug = false;

OptiScaler/SysUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,4 @@ inline static void to_lower_in_place(std::string& string)
210210
std::transform(string.begin(), string.end(), string.begin(), ::tolower);
211211
}
212212

213-
#include "OptiTexts.h"
213+
#include "OptiTypes.h"

0 commit comments

Comments
 (0)