Skip to content

Commit 251a58e

Browse files
authored
Feature freeze detection (#499)
1 parent 4d0d909 commit 251a58e

File tree

5 files changed

+75
-21
lines changed

5 files changed

+75
-21
lines changed

OptiScaler/hooks/HooksDx.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags
497497
return presentResult;
498498
}
499499

500+
// Tick feature to let it know if it's frozen
501+
if (auto currentFeature = State::Instance().currentFeature; currentFeature != nullptr)
502+
currentFeature->TickFrozenCheck();
503+
504+
// Draw overlay
500505
MenuOverlayDx::Present(pSwapChain, SyncInterval, Flags, pPresentParameters, pDevice, hWnd, isUWP);
501506

502507
if (State::Instance().activeFgType == OptiFG)

OptiScaler/hooks/HooksVk.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ static VkResult hkvkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInf
173173

174174
State::Instance().swapchainApi = Vulkan;
175175

176+
// Tick feature to let it know if it's frozen
177+
if (auto currentFeature = State::Instance().currentFeature; currentFeature != nullptr)
178+
currentFeature->TickFrozenCheck();
179+
176180
// render menu if needed
177181
if (!MenuOverlayVk::QueuePresent(queue, pPresentInfo))
178182
{

OptiScaler/menu/menu_common.cpp

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ bool MenuCommon::RenderMenu()
14581458

14591459
if (Config::Instance()->FpsOverlayType.value_or_default() == 0)
14601460
{
1461-
if (currentFeature != nullptr)
1461+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
14621462
ImGui::Text("%s | FPS: %5.1f, %6.2f ms | %s -> %s %d.%d.%d", api.c_str(), frameRate, frameTime,
14631463
State::Instance().currentInputApiName.c_str(), currentFeature->Name().c_str(),
14641464
State::Instance().currentFeature->Version().major,
@@ -1469,7 +1469,7 @@ bool MenuCommon::RenderMenu()
14691469
}
14701470
else
14711471
{
1472-
if (currentFeature != nullptr)
1472+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
14731473
ImGui::Text("%s | FPS: %5.1f, Avg: %5.1f | %s -> %s %d.%d.%d", api.c_str(), frameRate,
14741474
1000.0f / averageFrameTime, State::Instance().currentInputApiName.c_str(),
14751475
currentFeature->Name().c_str(), State::Instance().currentFeature->Version().major,
@@ -1710,6 +1710,7 @@ bool MenuCommon::RenderMenu()
17101710
? "Exists"
17111711
: "Doesn't Exist");
17121712
ImGui::Text("fsr: %s", State::Instance().fsrHooks ? "Exists" : "Doesn't Exist");
1713+
17131714
ImGui::Spacing();
17141715
}
17151716
else
@@ -1725,12 +1726,29 @@ bool MenuCommon::RenderMenu()
17251726
ImGui::SetWindowFontScale(Config::Instance()->MenuScale.value_or_default());
17261727
}
17271728
}
1729+
else if (currentFeature->IsFrozen())
1730+
{
1731+
ImGui::Spacing();
1732+
1733+
if (Config::Instance()->UseHQFont.value_or_default())
1734+
ImGui::PushFontSize(std::round(fontSize * Config::Instance()->MenuScale.value_or_default() * 3.0));
1735+
else
1736+
ImGui::SetWindowFontScale(Config::Instance()->MenuScale.value_or_default() * 3.0);
1737+
1738+
ImGui::Text("%s is active but not currently used by the game\nPlease enter the game",
1739+
currentFeature->Name().c_str());
1740+
1741+
if (Config::Instance()->UseHQFont.value_or_default())
1742+
ImGui::PopFont();
1743+
else
1744+
ImGui::SetWindowFontScale(Config::Instance()->MenuScale.value_or_default());
1745+
}
17281746

17291747
if (ImGui::BeginTable("main", 2, ImGuiTableFlags_SizingStretchSame))
17301748
{
17311749
ImGui::TableNextColumn();
17321750

1733-
if (currentFeature != nullptr)
1751+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
17341752
{
17351753
// UPSCALERS -----------------------------
17361754
ImGui::SeparatorText("Upscalers");
@@ -1879,7 +1897,7 @@ bool MenuCommon::RenderMenu()
18791897
{
18801898
ImGui::SeparatorText("Frame Generation (OptiFG)");
18811899

1882-
if (currentFeature != nullptr && FfxApiProxy::InitFfxDx12())
1900+
if (currentFeature != nullptr && !currentFeature->IsFrozen() && FfxApiProxy::InitFfxDx12())
18831901
{
18841902
bool fgActive = Config::Instance()->FGEnabled.value_or_default();
18851903
if (ImGui::Checkbox("FG Active", &fgActive))
@@ -2259,7 +2277,7 @@ bool MenuCommon::RenderMenu()
22592277
ImGui::Spacing();
22602278
ImGui::Spacing();
22612279
}
2262-
else if (currentFeature == nullptr)
2280+
else if (currentFeature == nullptr || currentFeature->IsFrozen())
22632281
{
22642282
ImGui::Text("Upscaler is not active"); // Probably never will be visible
22652283
}
@@ -2332,7 +2350,7 @@ bool MenuCommon::RenderMenu()
23322350
}
23332351
}
23342352

2335-
if (currentFeature != nullptr)
2353+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
23362354
{
23372355
// Dx11 with Dx12
23382356
if (State::Instance().api == DX11 &&
@@ -3080,7 +3098,7 @@ bool MenuCommon::RenderMenu()
30803098
}
30813099
}
30823100

3083-
if (currentFeature != nullptr)
3101+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
30843102
{
30853103
// OUTPUT SCALING -----------------------------
30863104
if (State::Instance().api == DX12 || State::Instance().api == DX11)
@@ -3165,7 +3183,7 @@ bool MenuCommon::RenderMenu()
31653183
ImGui::SliderFloat("Ratio", &_ssRatio, 0.5f, 3.0f, "%.2f");
31663184
ImGui::EndDisabled();
31673185

3168-
if (currentFeature != nullptr)
3186+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
31693187
{
31703188
ImGui::Text(
31713189
"Output Scaling is %s, Target Res: %dx%d\nJitter Count: %d",
@@ -3181,7 +3199,7 @@ bool MenuCommon::RenderMenu()
31813199
// NEXT COLUMN -----------------
31823200
ImGui::TableNextColumn();
31833201

3184-
if (currentFeature != nullptr)
3202+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
31853203
{
31863204
// SHARPNESS -----------------------------
31873205
ImGui::SeparatorText("Sharpness");
@@ -3487,7 +3505,7 @@ bool MenuCommon::RenderMenu()
34873505
{
34883506
ScopedIndent indent {};
34893507
ImGui::Spacing();
3490-
if (currentFeature != nullptr)
3508+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
34913509
{
34923510
bool extendedLimits = Config::Instance()->ExtendedLimits.value_or_default();
34933511
if (ImGui::Checkbox("Enable Extended Limits", &extendedLimits))
@@ -3628,8 +3646,9 @@ bool MenuCommon::RenderMenu()
36283646

36293647
// ADVANCED SETTINGS -----------------------------
36303648
ImGui::Spacing();
3631-
if (ImGui::CollapsingHeader("Upscaler Inputs",
3632-
currentFeature == nullptr ? ImGuiTreeNodeFlags_DefaultOpen : 0))
3649+
if (ImGui::CollapsingHeader("Upscaler Inputs", (currentFeature == nullptr || currentFeature->IsFrozen())
3650+
? ImGuiTreeNodeFlags_DefaultOpen
3651+
: 0))
36333652
{
36343653
ScopedIndent indent {};
36353654
ImGui::Spacing();
@@ -3662,8 +3681,9 @@ bool MenuCommon::RenderMenu()
36623681
{
36633682
// MIPMAP BIAS & Anisotropy -----------------------------
36643683
ImGui::Spacing();
3665-
if (ImGui::CollapsingHeader("Mipmap Bias",
3666-
currentFeature == nullptr ? ImGuiTreeNodeFlags_DefaultOpen : 0))
3684+
if (ImGui::CollapsingHeader("Mipmap Bias", (currentFeature == nullptr || currentFeature->IsFrozen())
3685+
? ImGuiTreeNodeFlags_DefaultOpen
3686+
: 0))
36673687
{
36683688
ScopedIndent indent {};
36693689
ImGui::Spacing();
@@ -3747,7 +3767,7 @@ bool MenuCommon::RenderMenu()
37473767
}
37483768
ImGui::EndDisabled();
37493769

3750-
if (currentFeature != nullptr)
3770+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
37513771
{
37523772
ImGui::SameLine(0.0f, 6.0f);
37533773

@@ -3787,7 +3807,9 @@ bool MenuCommon::RenderMenu()
37873807

37883808
ImGui::Spacing();
37893809
if (ImGui::CollapsingHeader("Anisotropic Filtering",
3790-
currentFeature == nullptr ? ImGuiTreeNodeFlags_DefaultOpen : 0))
3810+
(currentFeature == nullptr || currentFeature->IsFrozen())
3811+
? ImGuiTreeNodeFlags_DefaultOpen
3812+
: 0))
37913813
{
37923814
ScopedIndent indent {};
37933815
ImGui::Spacing();
@@ -3824,7 +3846,7 @@ bool MenuCommon::RenderMenu()
38243846
ImGui::Text("Will be applied after RESOLUTION/PRESET change !!!");
38253847
}
38263848

3827-
if (currentFeature != nullptr)
3849+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
38283850
{
38293851
// Non-DLSS hotfixes -----------------------------
38303852
if (currentBackend != "dlss")
@@ -3898,7 +3920,7 @@ bool MenuCommon::RenderMenu()
38983920
State::Instance().frameTimes.end());
38993921
ImGui::PlotLines(ft.c_str(), frameTimeArray.data(), (int) frameTimeArray.size());
39003922

3901-
if (currentFeature != nullptr)
3923+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
39023924
{
39033925
ImGui::TableNextColumn();
39043926
ImGui::Text("Upscaler");
@@ -3917,7 +3939,7 @@ bool MenuCommon::RenderMenu()
39173939
ImGui::Separator();
39183940
ImGui::Spacing();
39193941

3920-
if (currentFeature != nullptr)
3942+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
39213943
{
39223944
ImGui::Text("%dx%d -> %dx%d (%.1f) [%dx%d (%.1f)]", currentFeature->RenderWidth(),
39233945
currentFeature->RenderHeight(), currentFeature->TargetWidth(),
@@ -4007,7 +4029,7 @@ bool MenuCommon::RenderMenu()
40074029
float posX;
40084030
float posY;
40094031

4010-
if (currentFeature != nullptr)
4032+
if (currentFeature != nullptr && !currentFeature->IsFrozen())
40114033
{
40124034
posX = ((float) State::Instance().currentFeature->DisplayWidth() - winSize.x) / 2.0f;
40134035
posY = ((float) State::Instance().currentFeature->DisplayHeight() - winSize.y) / 2.0f;
@@ -4032,7 +4054,8 @@ bool MenuCommon::RenderMenu()
40324054
}
40334055

40344056
// Mipmap calculation window
4035-
if (_showMipmapCalcWindow && currentFeature != nullptr && currentFeature->IsInited())
4057+
if (_showMipmapCalcWindow && currentFeature != nullptr && !currentFeature->IsFrozen() &&
4058+
currentFeature->IsInited())
40364059
{
40374060
auto posX = (State::Instance().currentFeature->DisplayWidth() - 450.0f) / 2.0f;
40384061
auto posY = (State::Instance().currentFeature->DisplayHeight() - 200.0f) / 2.0f;

OptiScaler/upscalers/IFeature.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,25 @@ float IFeature::GetSharpness(const NVSDK_NGX_Parameter* InParameters)
247247
return sharpness;
248248
}
249249

250+
void IFeature::TickFrozenCheck()
251+
{
252+
static long updatesWithoutFramecountChange = 0;
253+
254+
if (_isInited)
255+
{
256+
static auto lastFrameCount = _frameCount;
257+
258+
if (_frameCount == lastFrameCount)
259+
updatesWithoutFramecountChange++;
260+
else
261+
updatesWithoutFramecountChange = 0;
262+
263+
lastFrameCount = _frameCount;
264+
265+
_featureFrozen = updatesWithoutFramecountChange > 10;
266+
}
267+
}
268+
250269
bool IFeature::UpdateOutputResolution(const NVSDK_NGX_Parameter* InParameters)
251270
{
252271
// Check for FSR's dynamic resolution output

OptiScaler/upscalers/IFeature.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class IFeature
6868
unsigned int _displayHeight = 0;
6969

7070
long _frameCount = 0;
71+
bool _featureFrozen = false;
7172
bool _moduleLoaded = false;
7273

7374
void SetHandle(unsigned int InHandleId);
@@ -88,6 +89,8 @@ class IFeature
8889

8990
size_t JitterCount() { return _jitterInfo.size(); }
9091

92+
void TickFrozenCheck();
93+
bool IsFrozen() const { return _featureFrozen; };
9194
bool UpdateOutputResolution(const NVSDK_NGX_Parameter* InParameters);
9295
unsigned int DisplayWidth() const { return _displayWidth; };
9396
unsigned int DisplayHeight() const { return _displayHeight; };

0 commit comments

Comments
 (0)