From d3ac321a8ef1b93c84583ff2785ad6d5941ea0c3 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 20:53:05 -0500 Subject: [PATCH 1/3] Version box: tell the upscaler's DLL which version the player selected When the player selects a version in the version box, the upscaler's DLL is told first through WrongGpuHostSelectedV1(versionId), if it exports it. WrongGPU's FFX DLL does, and records a selection of one of its models as the player's model choice. The upscaler is then recreated as before, so the choice runs at once. If WrongGPU recorded the choice, selecting the entry that is already selected recreates the upscaler too, because the model that ran may have been chosen elsewhere (WrongGPU's launcher or menu plugin). A notification says when WrongGPU could not save the choice. The call is made only for a selection in the menu, never for the index read from the ini. A DLL without the export is never called. WRONGGPU-EDITION.md: item 6. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- OptiScaler/menu/menu_common.cpp | 48 +++++++++++++++++++++++++++++++-- WRONGGPU-EDITION.md | 8 ++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/OptiScaler/menu/menu_common.cpp b/OptiScaler/menu/menu_common.cpp index 508ca5ea7b..69ee16956e 100644 --- a/OptiScaler/menu/menu_common.cpp +++ b/OptiScaler/menu/menu_common.cpp @@ -1073,6 +1073,39 @@ static bool IsOn12(Upscaler upscaler) } } +// WrongGPU edition: the player selected version `versionId` in the version box. WrongGPU's FFX dll exports +// WrongGpuHostSelectedV1 (WrongGPU's include/wronggpu_host_event.h) and records a selection of one of its models as the +// player's model choice, so it is called before the backend change recreates the upscaler. Only a selection made here +// calls it, never an index read from the ini. A dll without the export is not called (returns 0, nothing to recreate). +// Returns WrongGPU's result: 1 recorded, 2 this session only, 0 no model choice, -1 not saved yet, -2 refused. +static int32_t NotifyHostSelected(HMODULE module, uint64_t versionId) +{ + if (module == nullptr) + return 0; + + using PfnWrongGpuHostSelectedV1 = int32_t (*)(uint64_t versionId); + auto hostSelected = reinterpret_cast(GetProcAddress(module, "WrongGpuHostSelectedV1")); + + if (hostSelected == nullptr) + return 0; + + const int32_t result = hostSelected(versionId); + LOG_INFO("WrongGPU: the player selected version {:X}, result {}", versionId, result); + + if (result == -1 || result == -2) + { + ImGuiToast notification { result == -1 ? ImGuiToastType::Warning : ImGuiToastType::Error, 10000 }; + notification.setTitle("WrongGPU model choice"); + notification.setContent(result == -1 + ? "Not saved yet: the model runs now and is saved at the next start of the " + "upscaler. See WrongGPU's log." + : "Not saved: WrongGPU refused it. See WrongGPU's log."); + ImGui::InsertNotification(notification); + } + + return result; +} + // Name without the w/Dx12 suffix, that one is shown as a tag in the list instead static std::string ShortUpscalerName(Upscaler upscaler, API api, int ffxIndex) { @@ -3834,8 +3867,19 @@ void MenuCommon::RenderActiveUpscalerSettings(RenderMenuContext& ctx) { for (auto n : FfxVersionsNewestFirst(*versions)) { - if (ImGui::Selectable(StrFmt("%s%s##%d", prefix, versions->names[n], n).c_str(), ffxIndex == n) && - ffxIndex != n) + if (!ImGui::Selectable(StrFmt("%s%s##%d", prefix, versions->names[n], n).c_str(), ffxIndex == n)) + continue; + + // WrongGPU edition: the selection goes to the upscaler's dll first (NotifyHostSelected). A model + // choice WrongGPU recorded recreates the upscaler also when the entry was already selected: the + // model that ran may have been chosen elsewhere (WrongGPU's launcher or menu plugin). + HMODULE module = customUpscaler != nullptr ? customUpscaler->module.dll + : state.api == API::DX12 || currentBackend == Upscaler::FFX_on12 + ? FfxApiProxy::UpscalerModule(versions->ids[n]) + : nullptr; + const int32_t wrongGpu = NotifyHostSelected(module, versions->ids[n]); + + if (ffxIndex != n || wrongGpu == 1) { upscalerIndex = n; state.newBackend = currentBackend; diff --git a/WRONGGPU-EDITION.md b/WRONGGPU-EDITION.md index 8df26885d8..c2cd9c7e22 100644 --- a/WRONGGPU-EDITION.md +++ b/WRONGGPU-EDITION.md @@ -29,5 +29,13 @@ This branch is OptiScaler with a few changes for the WrongGPU upscaler. It is bu 5. **Diagnostics, off by default.** `[Hotfix] DredDiagnostics=true` (D3D12 DRED breadcrumbs and page-fault data, dumped once when the device is removed) and `[Hotfix] NullRootViewFix=true` (null root views logged and replaced by a zero buffer). +6. **The player's selection in the version box is told to the upscaler.** When the player selects a version in + the version box, the upscaler's DLL is told first, through `WrongGpuHostSelectedV1(versionId)`, if it + exports it (WrongGPU's FFX DLL does, and records a selection of one of its models as the player's model + choice). Then the upscaler is recreated as before, so the new choice runs at once. If WrongGPU recorded the + choice, selecting the entry that is already selected recreates the upscaler too, because the model that + ran may have been chosen elsewhere (WrongGPU's launcher or menu plugin). If WrongGPU could not save the + choice, a notification says so. The call is made only for a selection in the menu, never for the index + read from `OptiScaler.ini`. A DLL without the export is never called. Nothing else is changed. WrongGPU itself is a separate program; it is not part of this repository. From 5656bbbcd3082abd4165a9cc8e9293b845e1d501 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:38:57 -0500 Subject: [PATCH 2/3] Version box: act on WrongGPU's result (recreate on 1, nothing when not saved) The result of WrongGpuHostSelectedV1 decides: - 1, the selected model runs from now on: the upscaler is recreated, also when the entry was already selected; - 0, nothing changed for WrongGPU: as before, a new entry recreates the upscaler; - negative, not saved: nothing changes (no new index, no recreate), and a notification says "Not saved, try again". There is no "not saved yet" or session-only case any more. WRONGGPU-EDITION.md item 6 is updated to match. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- OptiScaler/menu/menu_common.cpp | 23 +++++++++++------------ WRONGGPU-EDITION.md | 11 ++++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/OptiScaler/menu/menu_common.cpp b/OptiScaler/menu/menu_common.cpp index 69ee16956e..69e84eb48c 100644 --- a/OptiScaler/menu/menu_common.cpp +++ b/OptiScaler/menu/menu_common.cpp @@ -1076,8 +1076,9 @@ static bool IsOn12(Upscaler upscaler) // WrongGPU edition: the player selected version `versionId` in the version box. WrongGPU's FFX dll exports // WrongGpuHostSelectedV1 (WrongGPU's include/wronggpu_host_event.h) and records a selection of one of its models as the // player's model choice, so it is called before the backend change recreates the upscaler. Only a selection made here -// calls it, never an index read from the ini. A dll without the export is not called (returns 0, nothing to recreate). -// Returns WrongGPU's result: 1 recorded, 2 this session only, 0 no model choice, -1 not saved yet, -2 refused. +// calls it, never an index read from the ini. A dll without the export is not called (0). +// Returns WrongGPU's result: 1 this model runs from now on (recreate, also when the entry was already selected), 0 +// nothing changed, negative not saved (nothing changes: no new index, no recreate; the player is told to try again). static int32_t NotifyHostSelected(HMODULE module, uint64_t versionId) { if (module == nullptr) @@ -1092,14 +1093,11 @@ static int32_t NotifyHostSelected(HMODULE module, uint64_t versionId) const int32_t result = hostSelected(versionId); LOG_INFO("WrongGPU: the player selected version {:X}, result {}", versionId, result); - if (result == -1 || result == -2) + if (result < 0) { - ImGuiToast notification { result == -1 ? ImGuiToastType::Warning : ImGuiToastType::Error, 10000 }; + ImGuiToast notification { ImGuiToastType::Warning, 10000 }; notification.setTitle("WrongGPU model choice"); - notification.setContent(result == -1 - ? "Not saved yet: the model runs now and is saved at the next start of the " - "upscaler. See WrongGPU's log." - : "Not saved: WrongGPU refused it. See WrongGPU's log."); + notification.setContent("Not saved, try again. The model that runs did not change. See WrongGPU's log."); ImGui::InsertNotification(notification); } @@ -3870,16 +3868,17 @@ void MenuCommon::RenderActiveUpscalerSettings(RenderMenuContext& ctx) if (!ImGui::Selectable(StrFmt("%s%s##%d", prefix, versions->names[n], n).c_str(), ffxIndex == n)) continue; - // WrongGPU edition: the selection goes to the upscaler's dll first (NotifyHostSelected). A model - // choice WrongGPU recorded recreates the upscaler also when the entry was already selected: the - // model that ran may have been chosen elsewhere (WrongGPU's launcher or menu plugin). + // WrongGPU edition: the selection goes to the upscaler's dll first (NotifyHostSelected). 1: this + // model runs from now on, so the upscaler is recreated also when the entry was already selected + // (the model that ran may have been chosen elsewhere: WrongGPU's launcher or menu plugin). Not + // saved: nothing changes, not even the index. 0: as before, a new entry recreates the upscaler. HMODULE module = customUpscaler != nullptr ? customUpscaler->module.dll : state.api == API::DX12 || currentBackend == Upscaler::FFX_on12 ? FfxApiProxy::UpscalerModule(versions->ids[n]) : nullptr; const int32_t wrongGpu = NotifyHostSelected(module, versions->ids[n]); - if (ffxIndex != n || wrongGpu == 1) + if (wrongGpu >= 0 && (ffxIndex != n || wrongGpu == 1)) { upscalerIndex = n; state.newBackend = currentBackend; diff --git a/WRONGGPU-EDITION.md b/WRONGGPU-EDITION.md index c2cd9c7e22..8270ddf47d 100644 --- a/WRONGGPU-EDITION.md +++ b/WRONGGPU-EDITION.md @@ -32,10 +32,11 @@ This branch is OptiScaler with a few changes for the WrongGPU upscaler. It is bu 6. **The player's selection in the version box is told to the upscaler.** When the player selects a version in the version box, the upscaler's DLL is told first, through `WrongGpuHostSelectedV1(versionId)`, if it exports it (WrongGPU's FFX DLL does, and records a selection of one of its models as the player's model - choice). Then the upscaler is recreated as before, so the new choice runs at once. If WrongGPU recorded the - choice, selecting the entry that is already selected recreates the upscaler too, because the model that - ran may have been chosen elsewhere (WrongGPU's launcher or menu plugin). If WrongGPU could not save the - choice, a notification says so. The call is made only for a selection in the menu, never for the index - read from `OptiScaler.ini`. A DLL without the export is never called. + choice). The result decides: 1, the selected model runs from now on: the upscaler is recreated, also when + the entry was already selected (the model that ran may have been chosen elsewhere, in WrongGPU's launcher + or menu plugin); 0, nothing changed for WrongGPU: as before, a new entry recreates the upscaler; negative, + not saved: nothing changes (no new index, no recreate) and a notification says "Not saved, try again". The + call is made only for a selection in the menu, never for the index read from `OptiScaler.ini`. A DLL + without the export is never called. Nothing else is changed. WrongGPU itself is a separate program; it is not part of this repository. From f31d091df2989f70c1e4ab296942de69240af227 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:48:40 -0500 Subject: [PATCH 3/3] Version box: WrongGPU's entry order and the selection logic in a tested header - OptiScaler/misc/WrongGpuHostEvent.h: OnVersionSelected (what the version box does with WrongGPU's result: 1 recreate, also for the entry already selected; 0 as before; negative "not saved", nothing changes), CallHostSelected (the export, or 0), and ListOrderMatches (WrongGPU's model entries in a version list against the copied header). - OptiScaler/include/wronggpu/wg_model_entries.h: a byte-identical copy of WrongGPU's clean/wgshared/include/wg_model_entries.h (the order of its model entries); static_asserts on it; a list in another order is logged. WrongGPU's CI checks the copy's hash. - wronggpu-edition-tests/host_event_test.cpp and the "WrongGPU edition tests" workflow build and run the header's tests. - WRONGGPU-EDITION.md item 6 says so. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- .github/workflows/wronggpu-edition-tests.yml | 16 +++ .../include/wronggpu/wg_model_entries.h | 23 ++++ OptiScaler/menu/menu_common.cpp | 71 +++++++----- OptiScaler/misc/WrongGpuHostEvent.h | 105 ++++++++++++++++++ WRONGGPU-EDITION.md | 16 ++- wronggpu-edition-tests/host_event_test.cpp | 72 ++++++++++++ 6 files changed, 270 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/wronggpu-edition-tests.yml create mode 100644 OptiScaler/include/wronggpu/wg_model_entries.h create mode 100644 OptiScaler/misc/WrongGpuHostEvent.h create mode 100644 wronggpu-edition-tests/host_event_test.cpp diff --git a/.github/workflows/wronggpu-edition-tests.yml b/.github/workflows/wronggpu-edition-tests.yml new file mode 100644 index 0000000000..8d19e2a94f --- /dev/null +++ b/.github/workflows/wronggpu-edition-tests.yml @@ -0,0 +1,16 @@ +name: WrongGPU edition tests +on: [push, pull_request] +jobs: + host-event: + name: Version box and WrongGPU's list order + runs-on: windows-latest + steps: + - uses: actions/checkout@v4.2.2 + - uses: ilammy/msvc-dev-cmd@v1.13.0 + with: + arch: x64 + - name: Build and run wronggpu-edition-tests/host_event_test.cpp + run: | + $PSNativeCommandUseErrorActionPreference = $true + cl /nologo /EHsc /std:c++17 /W4 /WX /I OptiScaler/misc wronggpu-edition-tests/host_event_test.cpp /Fe:host_event_test.exe + ./host_event_test.exe diff --git a/OptiScaler/include/wronggpu/wg_model_entries.h b/OptiScaler/include/wronggpu/wg_model_entries.h new file mode 100644 index 0000000000..b0966641e2 --- /dev/null +++ b/OptiScaler/include/wronggpu/wg_model_entries.h @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MIT +#pragma once +// The ONE definition of where WrongGPU's model entries are in the list of upscaler versions the front end gives a host +// (FFX_API_QUERY_DESC_TYPE_GET_VERSIONS: frontend.cpp ListVersions, from the registry's SR model rows). A host such as +// OptiScaler stores the player's entry as its position in that list (UpscalerIndex; OptiScaler shows the list sorted, but +// the index it stores is the position in the list the DLL returned), so this order is what the launcher writes: +// Model M first, then Model K (a build with Model K), then Model L (a build with Model L). +// The launcher (profile.h: kModelKEntryIndex / kModelLEntryIndex) and the front end use it; test_frontend +// (TestModelEntryOrder) fails when the list ListVersions returns and this order disagree, for each build's K / L flags. +// The index is for display only: which model runs is the model choice record's (clean/fsr/src/model_choice_record.h). + +namespace wgentries { + +// The position of `model`'s entry ('M', 'K', 'L') in a build with or without Model K and Model L; -1 when the build does +// not list that model. +constexpr int ModelEntryIndex(char model, bool withK, bool withL) { + return model == 'M' ? 0 : model == 'K' ? (withK ? 1 : -1) : model == 'L' ? (withL ? (withK ? 2 : 1) : -1) : -1; +} + +// The same as the decimal text an ini holds ("0", "1", "2"; nullptr for -1). +constexpr const char* IndexText(int index) { return index == 0 ? "0" : index == 1 ? "1" : index == 2 ? "2" : nullptr; } + +} // namespace wgentries diff --git a/OptiScaler/menu/menu_common.cpp b/OptiScaler/menu/menu_common.cpp index 69e84eb48c..93363559a2 100644 --- a/OptiScaler/menu/menu_common.cpp +++ b/OptiScaler/menu/menu_common.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -1076,30 +1077,22 @@ static bool IsOn12(Upscaler upscaler) // WrongGPU edition: the player selected version `versionId` in the version box. WrongGPU's FFX dll exports // WrongGpuHostSelectedV1 (WrongGPU's include/wronggpu_host_event.h) and records a selection of one of its models as the // player's model choice, so it is called before the backend change recreates the upscaler. Only a selection made here -// calls it, never an index read from the ini. A dll without the export is not called (0). -// Returns WrongGPU's result: 1 this model runs from now on (recreate, also when the entry was already selected), 0 -// nothing changed, negative not saved (nothing changes: no new index, no recreate; the player is told to try again). +// calls it, never an index read from the ini. A dll without the export is not called (0). What the box then does is +// misc/WrongGpuHostEvent.h's OnVersionSelected: 1 recreate (also for the entry already selected), 0 as before, negative +// not saved (nothing changes; the player is told to try again). static int32_t NotifyHostSelected(HMODULE module, uint64_t versionId) { - if (module == nullptr) - return 0; - - using PfnWrongGpuHostSelectedV1 = int32_t (*)(uint64_t versionId); - auto hostSelected = reinterpret_cast(GetProcAddress(module, "WrongGpuHostSelectedV1")); - - if (hostSelected == nullptr) - return 0; + const int32_t result = wronggpu_edition::CallHostSelected( + [module]() -> wronggpu_edition::PfnHostSelected + { + return module != nullptr ? reinterpret_cast( + GetProcAddress(module, "WrongGpuHostSelectedV1")) + : nullptr; + }, + versionId); - const int32_t result = hostSelected(versionId); - LOG_INFO("WrongGPU: the player selected version {:X}, result {}", versionId, result); - - if (result < 0) - { - ImGuiToast notification { ImGuiToastType::Warning, 10000 }; - notification.setTitle("WrongGPU model choice"); - notification.setContent("Not saved, try again. The model that runs did not change. See WrongGPU's log."); - ImGui::InsertNotification(notification); - } + if (result != 0) + LOG_INFO("WrongGPU: the player selected version {:X}, result {}", versionId, result); return result; } @@ -3852,6 +3845,18 @@ void MenuCommon::RenderActiveUpscalerSettings(RenderMenuContext& ctx) ImGui::Spacing(); const int ffxIndex = upscalerIndex.value_or_default(); + + // WrongGPU edition: WrongGPU's model entries must be where misc/wg_model_entries.h says (the index this box + // stores is a position in this list); a mismatch is logged once per list + static const void* checkedList = nullptr; + if (checkedList != versions) + { + checkedList = versions; + if (!wronggpu_edition::ListOrderMatches(versions->names)) + LOG_WARN( + "WrongGPU: the version list's model entries are not in the order wg_model_entries.h defines"); + } + // A custom upscaler's versions carry its own names (no "FSR " in front) and the box carries its name const char* prefix = customName.empty() ? "FSR " : ""; auto currentName = ffxIndex >= 0 && ffxIndex < versions->names.size() @@ -3868,19 +3873,31 @@ void MenuCommon::RenderActiveUpscalerSettings(RenderMenuContext& ctx) if (!ImGui::Selectable(StrFmt("%s%s##%d", prefix, versions->names[n], n).c_str(), ffxIndex == n)) continue; - // WrongGPU edition: the selection goes to the upscaler's dll first (NotifyHostSelected). 1: this - // model runs from now on, so the upscaler is recreated also when the entry was already selected - // (the model that ran may have been chosen elsewhere: WrongGPU's launcher or menu plugin). Not - // saved: nothing changes, not even the index. 0: as before, a new entry recreates the upscaler. + // WrongGPU edition: the selection goes to the upscaler's dll first (NotifyHostSelected), then + // OnVersionSelected decides (misc/WrongGpuHostEvent.h): 1 recreate, also when the entry was already + // selected (the model that ran may have been chosen elsewhere: WrongGPU's launcher or menu plugin); + // not saved: nothing changes, not even the index; 0: as before, a new entry recreates the upscaler. HMODULE module = customUpscaler != nullptr ? customUpscaler->module.dll : state.api == API::DX12 || currentBackend == Upscaler::FFX_on12 ? FfxApiProxy::UpscalerModule(versions->ids[n]) : nullptr; - const int32_t wrongGpu = NotifyHostSelected(module, versions->ids[n]); + const auto action = + wronggpu_edition::OnVersionSelected(ffxIndex, n, NotifyHostSelected(module, versions->ids[n])); - if (wrongGpu >= 0 && (ffxIndex != n || wrongGpu == 1)) + if (action.notSaved) { + ImGuiToast notification { ImGuiToastType::Warning, 10000 }; + notification.setTitle("WrongGPU model choice"); + notification.setContent( + "Not saved, try again. The model that runs did not change. See WrongGPU's log."); + ImGui::InsertNotification(notification); + } + + if (action.setIndex) upscalerIndex = n; + + if (action.recreate) + { state.newBackend = currentBackend; MARK_ALL_BACKENDS_CHANGED(); } diff --git a/OptiScaler/misc/WrongGpuHostEvent.h b/OptiScaler/misc/WrongGpuHostEvent.h new file mode 100644 index 0000000000..c710069282 --- /dev/null +++ b/OptiScaler/misc/WrongGpuHostEvent.h @@ -0,0 +1,105 @@ +#pragma once + +// WrongGPU edition: what the version box does with the player's selection when the upscaler's dll is WrongGPU's FFX dll +// (WRONGGPU-EDITION.md item 6). Kept free of ImGui and Windows so wronggpu-edition-tests/host_event_test.cpp can test +// it. +// +// include/wronggpu/wg_model_entries.h is a byte-identical copy of WrongGPU's clean/wgshared/include/wg_model_entries.h +// (the order of WrongGPU's model entries in the list its dll returns); WrongGPU's CI checks that the copies match. + +#include "../include/wronggpu/wg_model_entries.h" + +#include +#include +#include + +namespace wronggpu_edition +{ + +// The order the copied header defines, as this edition expects it. +static_assert(wgentries::ModelEntryIndex('M', true, true) == 0, "Model M is the first WrongGPU entry"); +static_assert(wgentries::ModelEntryIndex('K', true, true) == 1, "Model K follows Model M"); +static_assert(wgentries::ModelEntryIndex('L', true, true) == 2, "Model L follows Model K"); +static_assert(wgentries::ModelEntryIndex('L', false, true) == 1, "without Model K, Model L follows Model M"); +static_assert(wgentries::ModelEntryIndex('K', false, true) == -1, "a build without Model K lists none"); + +// WrongGpuHostSelectedV1's results (WrongGPU's include/wronggpu_host_event.h). +constexpr int32_t kRecorded = 1; // the selected model runs from now on: recreate, also for the entry already selected +constexpr int32_t kNothingChanged = 0; + +// What the version box does after the player selected entry `selected` while `current` is selected, given WrongGPU's +// result (0 for a dll without the export). +struct VersionBoxAction +{ + bool setIndex = false; // store `selected` as the index + bool recreate = false; // recreate the upscaler (the backend change) + bool notSaved = false; // tell the player "Not saved, try again" +}; + +inline VersionBoxAction OnVersionSelected(int current, int selected, int32_t result) +{ + VersionBoxAction a; + + if (result < 0) + { + a.notSaved = true; // nothing changes: no new index, no recreate + return a; + } + + if (current != selected || result == kRecorded) + { + a.setIndex = true; + a.recreate = true; + } + + return a; +} + +// Calls the dll's WrongGpuHostSelectedV1 when `resolve` finds it (a function returning the export's address or +// nullptr), else returns 0. +using PfnHostSelected = int32_t (*)(uint64_t versionId); + +template int32_t CallHostSelected(Resolve&& resolve, uint64_t versionId) +{ + const PfnHostSelected fn = resolve(); + return fn != nullptr ? fn(versionId) : kNothingChanged; +} + +// The model of a listed version name ("WrongGPU Model K##3.1.0" -> 'K'), else 0. +inline char ModelOfName(const char* name) +{ + static const char kPrefix[] = "WrongGPU Model "; + const size_t n = sizeof(kPrefix) - 1; + + if (name == nullptr || std::strncmp(name, kPrefix, n) != 0) + return 0; + + const char m = name[n]; + return (m == 'M' || m == 'K' || m == 'L') && (name[n + 1] == 0 || name[n + 1] == '#') ? m : 0; +} + +// True when WrongGPU's model entries in a version list (the names the dll returned, in its order: the index stored in +// OptiScaler.ini is a position in this list) are at the positions wg_model_entries.h defines. A list without WrongGPU's +// entries is true (not WrongGPU's dll). +inline bool ListOrderMatches(const std::vector& names) +{ + bool hasK = false, hasL = false; + + for (auto name : names) + { + hasK = hasK || ModelOfName(name) == 'K'; + hasL = hasL || ModelOfName(name) == 'L'; + } + + for (size_t i = 0; i < names.size(); i++) + { + const char m = ModelOfName(names[i]); + + if (m != 0 && wgentries::ModelEntryIndex(m, hasK, hasL) != static_cast(i)) + return false; + } + + return true; +} + +} // namespace wronggpu_edition diff --git a/WRONGGPU-EDITION.md b/WRONGGPU-EDITION.md index 8270ddf47d..b0442d75a1 100644 --- a/WRONGGPU-EDITION.md +++ b/WRONGGPU-EDITION.md @@ -32,11 +32,15 @@ This branch is OptiScaler with a few changes for the WrongGPU upscaler. It is bu 6. **The player's selection in the version box is told to the upscaler.** When the player selects a version in the version box, the upscaler's DLL is told first, through `WrongGpuHostSelectedV1(versionId)`, if it exports it (WrongGPU's FFX DLL does, and records a selection of one of its models as the player's model - choice). The result decides: 1, the selected model runs from now on: the upscaler is recreated, also when - the entry was already selected (the model that ran may have been chosen elsewhere, in WrongGPU's launcher - or menu plugin); 0, nothing changed for WrongGPU: as before, a new entry recreates the upscaler; negative, - not saved: nothing changes (no new index, no recreate) and a notification says "Not saved, try again". The - call is made only for a selection in the menu, never for the index read from `OptiScaler.ini`. A DLL - without the export is never called. + choice). The result decides (`OptiScaler/misc/WrongGpuHostEvent.h`, `OnVersionSelected`): 1, the selected + model runs from now on: the upscaler is recreated, also when the entry was already selected (the model that + ran may have been chosen elsewhere, in WrongGPU's launcher or menu plugin); 0, nothing changed for WrongGPU: + as before, a new entry recreates the upscaler; negative, not saved: nothing changes (no new index, no + recreate) and a notification says "Not saved, try again". The call is made only for a selection in the + menu, never for the index read from `OptiScaler.ini`. A DLL without the export is never called. The order of + WrongGPU's model entries in the list its DLL returns (the index this box stores is a position in that list) + is WrongGPU's `wg_model_entries.h`, copied byte for byte to `OptiScaler/include/wronggpu/` (WrongGPU's CI + checks the copy); a list in another order is logged. `wronggpu-edition-tests/host_event_test.cpp` tests both, + built and run by the `WrongGPU edition tests` workflow. Nothing else is changed. WrongGPU itself is a separate program; it is not part of this repository. diff --git a/wronggpu-edition-tests/host_event_test.cpp b/wronggpu-edition-tests/host_event_test.cpp new file mode 100644 index 0000000000..a19ce37c7b --- /dev/null +++ b/wronggpu-edition-tests/host_event_test.cpp @@ -0,0 +1,72 @@ +// WrongGPU edition: tests of OptiScaler/misc/WrongGpuHostEvent.h (what the version box does with WrongGPU's result, and +// the list order of WrongGPU's model entries against the copied wg_model_entries.h). Built and run by +// .github/workflows/wronggpu-edition-tests.yml: cl /EHsc /std:c++17 /I OptiScaler/misc host_event_test.cpp + +#include "WrongGpuHostEvent.h" + +#include + +static int g_checks = 0, g_failures = 0; +#define CHECK(c) \ + do \ + { \ + ++g_checks; \ + if (!(c)) \ + { \ + ++g_failures; \ + std::printf("FAIL line %d: %s\n", __LINE__, #c); \ + } \ + } while (0) + +using namespace wronggpu_edition; + +static int32_t g_lastVersion = 0; +static int32_t FakeHostSelected(uint64_t versionId) +{ + g_lastVersion = static_cast(versionId); + return versionId == 7 ? 1 : versionId == 9 ? -1 : 0; +} + +int main() +{ + // 1: this model runs from now on: recreate, also when the entry was already selected + auto a = OnVersionSelected(2, 2, 1); + CHECK(a.setIndex && a.recreate && !a.notSaved); + a = OnVersionSelected(0, 2, 1); + CHECK(a.setIndex && a.recreate && !a.notSaved); + // 0: as before: a new entry recreates, the entry already selected does nothing + a = OnVersionSelected(0, 2, 0); + CHECK(a.setIndex && a.recreate && !a.notSaved); + a = OnVersionSelected(2, 2, 0); + CHECK(!a.setIndex && !a.recreate && !a.notSaved); + // negative: not saved: nothing changes (no new index, no recreate), the player is told + for (int32_t r : { -1, -2, -3 }) + { + a = OnVersionSelected(0, 2, r); + CHECK(!a.setIndex && !a.recreate && a.notSaved); + a = OnVersionSelected(2, 2, r); + CHECK(!a.setIndex && !a.recreate && a.notSaved); + } + + // the export: called when found, 0 without it + CHECK(CallHostSelected([]() -> PfnHostSelected { return nullptr; }, 7) == 0); + CHECK(CallHostSelected([]() -> PfnHostSelected { return &FakeHostSelected; }, 7) == 1 && g_lastVersion == 7); + CHECK(CallHostSelected([]() -> PfnHostSelected { return &FakeHostSelected; }, 9) == -1 && g_lastVersion == 9); + + // the names WrongGPU's dll lists + CHECK(ModelOfName("WrongGPU Model K##3.1.0") == 'K' && ModelOfName("WrongGPU Model M") == 'M'); + CHECK(ModelOfName("WrongGPU Model Q") == 0 && ModelOfName("FSR 3.1.4") == 0 && ModelOfName(nullptr) == 0); + CHECK(ModelOfName("WrongGPU Model LX") == 0); + + // the list order against wg_model_entries.h: M, then K, then L, as each build lists them (AMD's versions follow) + CHECK(ListOrderMatches({ "WrongGPU Model M##3.1.0", "WrongGPU Model K##3.1.0", "WrongGPU Model L##3.1.0", "3.1.5" })); + CHECK(ListOrderMatches({ "WrongGPU Model M##3.1.0", "WrongGPU Model L##3.1.0", "3.1.5", "2.3.4" })); + CHECK(ListOrderMatches({ "WrongGPU Model M##3.1.0", "WrongGPU Model K##3.1.0" })); + CHECK(ListOrderMatches({ "FSR 3.1.4", "FSR 2.3.4" })); // not WrongGPU's dll + CHECK(!ListOrderMatches({ "WrongGPU Model K##3.1.0", "WrongGPU Model M##3.1.0" })); + CHECK(!ListOrderMatches({ "WrongGPU Model M##3.1.0", "WrongGPU Model L##3.1.0", "WrongGPU Model K##3.1.0" })); + CHECK(!ListOrderMatches({ "3.1.5", "WrongGPU Model M##3.1.0" })); + + std::printf("%d checks, %d failures\n", g_checks, g_failures); + return g_failures ? 1 : 0; +}