From 7b4dff3e1dbb4ed8cbaab22838b10f9c68acaf9b Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:40:53 -0500 Subject: [PATCH] Model K: the launcher's per-game model choice K and the front end's K build state, off by default Launcher: CMake WRONGGPU_MODEL_K (default OFF, needs WRONGGPU_PRESET_K) makes `model` accept k like the Model L choice (set model=K writes wronggpu.ini's model=K last and OptiScaler's UpscalerIndex 1; the data check, the refusal, the repair fallback and the way back to Model M are Model L's). Model L's entry is 2 whenever Model K is built in. Front end: Model K's state is a property of wg_fsr_core like Model L's, so a build with WG_MODEL_K=OFF (releases, CI) also tests a front end with Model K and a build with it ON also tests one without. The default of WG_MODEL_K is unchanged. Tests: model-choice-k (with and without the Model L choice) in CI, tests/run_model_k_tests.py end to end, an L and an M control. BUILDING.md section 8 and the launcher README describe the K build. CI and releases keep Model K off. No other mode of Model K is offered, written or documented. Refs #15 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- .github/workflows/ci.yml | 4 +- BUILDING.md | 26 ++++ clean/fsr/CMakeLists.txt | 46 +++++- clean/installer/CMakeLists.txt | 32 +++- clean/installer/README.md | 24 +++ clean/installer/src/wg_core/launcher.cpp | 23 +-- clean/installer/src/wg_core/model.h | 8 + clean/installer/src/wg_core/profile.cpp | 58 +++++-- clean/installer/src/wg_core/profile.h | 10 +- clean/installer/src/wizard_policy.h | 7 + .../installer/tests/model_choice_k_tests.cpp | 137 +++++++++++++++++ clean/installer/tests/run_model_k_tests.py | 144 ++++++++++++++++++ 12 files changed, 478 insertions(+), 41 deletions(-) create mode 100644 clean/installer/tests/model_choice_k_tests.cpp create mode 100644 clean/installer/tests/run_model_k_tests.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc6cb476..dcd8b556 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,8 +115,8 @@ jobs: run: | $PSNativeCommandUseErrorActionPreference = $true cmake -S clean/installer -B out/launcher-tests -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DWRONGGPU_PAYLOAD_DIR="$PWD/out/no-payload" -DWRONGGPU_TESTING=OFF -DWRONGGPU_PRESET_K=OFF -DWRONGGPU_DIRECT_ROUTE=OFF - cmake --build out/launcher-tests --target wg-core-tests launcher-core-tests coexist-core-tests convert-ignore-tests model-choice-tests - ctest --test-dir out/launcher-tests --output-on-failure -R "^(wg-core|launcher-core|coexist-core|convert-ignore|model-choice|source-size|wording)$" + cmake --build out/launcher-tests --target wg-core-tests launcher-core-tests coexist-core-tests convert-ignore-tests model-choice-tests model-choice-k-tests model-choice-k-only-tests + ctest --test-dir out/launcher-tests --output-on-failure -R "^(wg-core|launcher-core|coexist-core|convert-ignore|model-choice|model-choice-k|model-choice-k-only|source-size|wording)$" rr-plugin: name: "CPU: Ray Reconstruction plugin" diff --git a/BUILDING.md b/BUILDING.md index ce82a0fa..84491432 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -201,3 +201,29 @@ These load a Direct3D 12 or HIP device: the front end's D3D12 tests (`ctest --te without `--no-tests`), `clean\runtime\interop\tests` (the D3D12 interop harness), `clean\dx12\tests`, the Ray Reconstruction end-to-end test (`clean\rr_f\runtime\tests\e2e.py`), the timing tools, and the GPU test modules listed in 6. Run them on an RX 9000-series card; `WG_GPU_LOCK` can serialise them when several shells share one GPU. + +## 8. A build with Model K (development; not part of any release) + +Model K is off in every build that players get: the release commands above pass `--no-model-k`, `-DWG_MODEL_K=OFF` and +`-DWRONGGPU_PRESET_K=OFF`, and CI builds them the same way. To build all three parts with Model K, change those lines: + +```bat +rem 3.3 runtime: leave out --no-model-k (Model K's code objects and map are then built in) +python clean\runner\build.py --rocm "%ROCM_PATH%" --out out\runtime --extra-archs gfx1200 --with-rr out\rr-rt\obj + +rem 4.1 front end: Model K's entry in the hosted list and model=K (the option's default is ON; CI and releases say OFF) +cmake -S clean\fsr -B out\frontend %CMAKE_FLAGS% -DWG_MODEL_K=ON -DWG_BUILD_ID=dev-k -DWG_BUILD_ASI=ON + +rem 5.2 launcher: Preset K (Model K's converter map) and the per-game model choice K (set model=K) +cmake -S clean\installer -B out\launcher %CMAKE_FLAGS% -DWRONGGPU_PAYLOAD_DIR=%CD%\out\payload -DWRONGGPU_RR_DIR=%CD%\out\rr ^ + -DWRONGGPU_VERSION=0.6.0 -DWRONGGPU_BUILD_ID=dev-k -DWRONGGPU_PAYLOAD_NAME=0.6.0 -DWRONGGPU_TESTING=OFF ^ + -DWRONGGPU_PRESET_K=ON -DWRONGGPU_MODEL_K=ON -DWRONGGPU_DIRECT_ROUTE=OFF +``` + +`-DWRONGGPU_MODEL_K=ON` needs `-DWRONGGPU_PRESET_K=ON` (configuring without it stops with an error) and the front end and +runtime of the same build. Model K runs its exact network: nothing in these builds, the launcher or the front end offers or +sets another mode of it. The CPU tests of section 6 cover the K-less builds; the front end's build also tests the other +state of Model K (`fsr_frontend_model_k_unit` in a build with `-DWG_MODEL_K=OFF`, `fsr_frontend_no_model_k_unit` in one with +it ON), and the launcher's `model-choice-k` and `model-choice-k-only` tests run the K choice whatever the build's option is. +`clean\installer\tests\run_model_k_tests.py` (its header says how to prepare the payload, the test maps and a launcher with +the choices on) runs the choice end to end on generated fixtures, with no game and no GPU. diff --git a/clean/fsr/CMakeLists.txt b/clean/fsr/CMakeLists.txt index c9ad07d3..0f5af475 100644 --- a/clean/fsr/CMakeLists.txt +++ b/clean/fsr/CMakeLists.txt @@ -27,11 +27,17 @@ option(WG_SPLIT_PROGRESS_QA "Private read-only split fence diagnostics; no produ # provider label. OFF (a release that ships Model M only): none of that; the list is "3.1.5 WrongGPU (Model M)" and # AMD's versions, the Model K id is an unknown override like any other, model=K from wronggpu.ini or # WG_RUNTIME_OPTIONS is dropped with one log line and Model M runs (src/model_k.h). +# Like Model L's definition below, it is set on wg_fsr_core (and so on everything that links it) and not for the whole +# directory, so that the tests can also build a front end with the other state: a build with Model K OFF (releases, CI) +# also tests a front end with Model K, a build with it ON also tests one without. The few targets that do not link +# wg_fsr_core get the definition from the loop at the end of this file. option(WG_MODEL_K "Offer Model K (hosted list entry, model=K); OFF = Model M only" ON) if(WG_MODEL_K) - add_compile_definitions(WRONGGPU_MODEL_K=1) + set(WG_MODEL_K_VALUE 1) + set(WG_OTHER_K_VALUE 0) else() - add_compile_definitions(WRONGGPU_MODEL_K=0) + set(WG_MODEL_K_VALUE 0) + set(WG_OTHER_K_VALUE 1) endif() # Model L in the front end (#89; src/model_l.h): its entry "WrongGPU Model L" in the hosted version list, its id, # sr_model=L / model=L passed to the runtime (which needs WG_MODEL_L too), the model lookup's \L\model.wgcm, its @@ -52,7 +58,7 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../wgshared ${CMAKE_BINARY_DIR}/wgs # folder, spec 65.6): not built unless asked for. Its header-only unit tests still run. option(WG_BUILD_ASI "Build the retired OptiScaler menu-patching plugin WrongGPU.asi" OFF) add_executable(test_provider_label tests/test_provider_label.cpp) -target_compile_definitions(test_provider_label PRIVATE WRONGGPU_MODEL_L=${WG_MODEL_L_VALUE}) +target_compile_definitions(test_provider_label PRIVATE WRONGGPU_MODEL_L=${WG_MODEL_L_VALUE} WRONGGPU_MODEL_K=${WG_MODEL_K_VALUE}) if(MSVC) set_property(TARGET test_provider_label PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() @@ -69,12 +75,12 @@ set(WG_FSR_CORE_SOURCES src/fsr30_hook.cpp src/fsr30_map.cpp src/param_map.cpp) -function(wg_fsr_core_library name model_l) +function(wg_fsr_core_library name model_l model_k) add_library(${name} STATIC ${WG_FSR_CORE_SOURCES}) target_include_directories(${name} SYSTEM PUBLIC ${FFX_SDK_DIR}) target_include_directories(${name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(${name} PUBLIC wg_shared_headers) - target_compile_definitions(${name} PUBLIC WRONGGPU_MODEL_L=${model_l}) + target_compile_definitions(${name} PUBLIC WRONGGPU_MODEL_L=${model_l} WRONGGPU_MODEL_K=${model_k}) set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE ON) if(MSVC) target_compile_options(${name} PRIVATE /Zi) @@ -88,7 +94,7 @@ function(wg_fsr_core_library name model_l) target_compile_definitions(${name} PUBLIC WIDL_EXPLICIT_AGGREGATE_RETURNS) endif() endfunction() -wg_fsr_core_library(wg_fsr_core ${WG_MODEL_L_VALUE}) +wg_fsr_core_library(wg_fsr_core ${WG_MODEL_L_VALUE} ${WG_MODEL_K_VALUE}) # Host unit tests (any platform). add_executable(test_amd_provider tests/test_amd_provider.cpp) @@ -102,11 +108,26 @@ target_link_libraries(test_fsr30 PRIVATE wg_fsr_core) add_test(NAME fsr30_hook_unit COMMAND test_fsr30) # A build without Model L (the default) also tests a front end with it: the same tests, Model L built in. if(NOT WG_MODEL_L) - wg_fsr_core_library(wg_fsr_core_model_l 1) + wg_fsr_core_library(wg_fsr_core_model_l 1 ${WG_MODEL_K_VALUE}) add_executable(test_frontend_model_l tests/test_frontend.cpp) target_link_libraries(test_frontend_model_l PRIVATE wg_fsr_core_model_l) add_test(NAME fsr_frontend_model_l_unit COMMAND test_frontend_model_l) endif() +# The same for Model K (the other state than this build's): a release build (WG_MODEL_K=OFF, also CI) tests a front end +# with Model K built in (its list entry, id and overlay names, model=K), a build with it tests one without (no entry, +# model=K dropped with one log line). The product front end and its DLLs stay as WG_MODEL_K says. +if(WG_MODEL_K) + set(WG_OTHER_K_NAME no_model_k) +else() + set(WG_OTHER_K_NAME model_k) +endif() +wg_fsr_core_library(wg_fsr_core_${WG_OTHER_K_NAME} ${WG_MODEL_L_VALUE} ${WG_OTHER_K_VALUE}) +add_executable(test_frontend_${WG_OTHER_K_NAME} tests/test_frontend.cpp) +target_link_libraries(test_frontend_${WG_OTHER_K_NAME} PRIVATE wg_fsr_core_${WG_OTHER_K_NAME}) +add_test(NAME fsr_frontend_${WG_OTHER_K_NAME}_unit COMMAND test_frontend_${WG_OTHER_K_NAME}) +add_executable(test_fsr30_${WG_OTHER_K_NAME} tests/test_fsr30.cpp) +target_link_libraries(test_fsr30_${WG_OTHER_K_NAME} PRIVATE wg_fsr_core_${WG_OTHER_K_NAME}) +add_test(NAME fsr30_hook_${WG_OTHER_K_NAME}_unit COMMAND test_fsr30_${WG_OTHER_K_NAME}) # WrongGPU OptiScaler ASI plugin: thunk logic (any OS) and the offline anchor scan of an OptiScaler binary # (any OS; skips when WRONGGPU_OPTISCALER_BIN is not set). Header-only resolver/thunk, no extra libraries. @@ -133,12 +154,16 @@ if(WIN32) if(TARGET test_frontend_model_l) set_property(TARGET wg_fsr_core_model_l test_frontend_model_l PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() + set_property(TARGET wg_fsr_core_${WG_OTHER_K_NAME} test_frontend_${WG_OTHER_K_NAME} test_fsr30_${WG_OTHER_K_NAME} + PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() if(MINGW) target_link_options(test_frontend PRIVATE ${WG_STATIC_RUNTIME}) if(TARGET test_frontend_model_l) target_link_options(test_frontend_model_l PRIVATE ${WG_STATIC_RUNTIME}) endif() + target_link_options(test_frontend_${WG_OTHER_K_NAME} PRIVATE ${WG_STATIC_RUNTIME}) + target_link_options(test_fsr30_${WG_OTHER_K_NAME} PRIVATE ${WG_STATIC_RUNTIME}) target_link_options(test_fsr30 PRIVATE ${WG_STATIC_RUNTIME}) target_link_options(test_asi_thunk PRIVATE ${WG_STATIC_RUNTIME}) target_link_options(test_asi_scan PRIVATE ${WG_STATIC_RUNTIME}) @@ -425,3 +450,10 @@ if(WIN32) endforeach() endif() endif() + +# Targets that do not link wg_fsr_core but read Model K's state (the ASI plugin's header and its tests): the build's value. +foreach(wg_k_target test_asi_thunk test_asi_status wronggpu_asi) + if(TARGET ${wg_k_target}) + target_compile_definitions(${wg_k_target} PRIVATE WRONGGPU_MODEL_K=${WG_MODEL_K_VALUE}) + endif() +endforeach() diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index ff3180db..b7bea24a 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -67,6 +67,19 @@ if(WRONGGPU_MODEL_L) else() set(MODEL_L_DEFINITION WRONGGPU_MODEL_L=0) endif() +# The Model K choice in the launcher (src/wizard_policy.h): a development build for a front end with WG_MODEL_K and a runtime +# with Model K, never for a release that players get (K is off by default). `model` becomes a setting with the value k +# (m|k, m|k|l with WRONGGPU_MODEL_L) and `set model=K` writes wronggpu.ini's model=K and OptiScaler's UpscalerIndex. +# It needs Preset K's converter map and model folder (WRONGGPU_PRESET_K). +option(WRONGGPU_MODEL_K "The Model K choice in the launcher (model=K, the OptiScaler entry; needs WRONGGPU_PRESET_K); OFF = no Model K choice" OFF) +if(WRONGGPU_MODEL_K) + if(NOT WRONGGPU_PRESET_K) + message(FATAL_ERROR "WRONGGPU_MODEL_K needs WRONGGPU_PRESET_K=ON (Model K's converter map and model folder).") + endif() + set(MODEL_K_DEFINITION WRONGGPU_MODEL_K=1) +else() + set(MODEL_K_DEFINITION WRONGGPU_MODEL_K=0) +endif() option(WRONGGPU_DIRECT_ROUTE "The direct FSR route in the installer (the wizard's advanced choice, /DIRECTFSR, a silent install without /OPTISCALER=); OFF = OptiScaler is required" ON) if(WRONGGPU_DIRECT_ROUTE) set(DIRECT_ROUTE_PAYLOAD_ARGS) @@ -133,7 +146,7 @@ add_library(wg_core STATIC target_include_directories(wg_core PUBLIC src) target_compile_definitions(wg_core PUBLIC ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION}) # (private: model-choice-tests compiles profile.cpp with the Model L choice on, against this library) -target_compile_definitions(wg_core PRIVATE ${MODEL_L_DEFINITION}) +target_compile_definitions(wg_core PRIVATE ${MODEL_L_DEFINITION} ${MODEL_K_DEFINITION}) if(WRONGGPU_TESTING) target_compile_definitions(wg_core PUBLIC WRONGGPU_TESTING) endif() @@ -199,7 +212,7 @@ add_executable(WrongGPU WIN32 src/app/main.cpp src/app/wizard.cpp src/app/cli.cp add_dependencies(WrongGPU WrongGPU-Restore) if(WRONGGPU_TESTING) add_executable(wizard-policy-tests tests/wizard_policy_tests.cpp) - target_compile_definitions(wizard-policy-tests PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION} ${MODEL_L_DEFINITION}) + target_compile_definitions(wizard-policy-tests PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION} ${MODEL_L_DEFINITION} ${MODEL_K_DEFINITION}) endif() # wg_core's unit tests (strings and paths, install record, wronggpu.ini keys, the log file; no game, payload or GPU). add_executable(wg-core-tests tests/wg_core_tests.cpp) @@ -208,7 +221,7 @@ target_link_libraries(wg-core-tests PRIVATE wg_core) # job files, the update reply, the game environment; no game, payload or GPU). add_executable(launcher-core-tests tests/launcher_core_tests.cpp) target_link_libraries(launcher-core-tests PRIVATE wg_core) -target_compile_definitions(launcher-core-tests PRIVATE ${MODEL_L_DEFINITION}) +target_compile_definitions(launcher-core-tests PRIVATE ${MODEL_L_DEFINITION} ${MODEL_K_DEFINITION}) # The coexistence tests (M2): fingerprints on synthetic bytes, the proxy picker, byte-exact OptiScaler.ini edits and the # inikey journal, the OptiScaler tab's key rules, the record's inikey and coexist lines, the log warnings. add_executable(coexist-core-tests tests/coexist_tests.cpp) @@ -230,15 +243,26 @@ add_test(NAME wg-core COMMAND wg-core-tests) add_executable(model-choice-tests tests/model_choice_tests.cpp src/wg_core/profile.cpp) target_compile_definitions(model-choice-tests PRIVATE WRONGGPU_MODEL_L=1) target_link_libraries(model-choice-tests PRIVATE wg_core) +# The Model K choice (profile.cpp with WRONGGPU_MODEL_K on, whatever this build's switch, so that CI, which keeps Model K off, +# runs it): with the Model L choice too (the setting m|k|l: K, and an L and an M control) and without (m|k). Each has its own +# copy of profile.cpp. +add_executable(model-choice-k-tests tests/model_choice_k_tests.cpp src/wg_core/profile.cpp) +target_compile_definitions(model-choice-k-tests PRIVATE WRONGGPU_MODEL_K=1 WRONGGPU_MODEL_L=1) +target_link_libraries(model-choice-k-tests PRIVATE wg_core) +add_executable(model-choice-k-only-tests tests/model_choice_k_tests.cpp src/wg_core/profile.cpp) +target_compile_definitions(model-choice-k-only-tests PRIVATE WRONGGPU_MODEL_K=1 WRONGGPU_MODEL_L=0) +target_link_libraries(model-choice-k-only-tests PRIVATE wg_core) add_test(NAME launcher-core COMMAND launcher-core-tests) add_test(NAME model-choice COMMAND model-choice-tests) +add_test(NAME model-choice-k COMMAND model-choice-k-tests) +add_test(NAME model-choice-k-only COMMAND model-choice-k-only-tests) add_test(NAME coexist-core COMMAND coexist-core-tests) add_test(NAME convert-ignore COMMAND convert-ignore-tests) if(WRONGGPU_TESTING) add_test(NAME wizard-policy COMMAND wizard-policy-tests) endif() target_include_directories(WrongGPU PRIVATE ${GEN}) -target_compile_definitions(WrongGPU PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION} ${MODEL_L_DEFINITION}) +target_compile_definitions(WrongGPU PRIVATE ${PRESET_K_DEFINITION} ${DIRECT_ROUTE_DEFINITION} ${MODEL_L_DEFINITION} ${MODEL_K_DEFINITION}) target_link_libraries(WrongGPU PRIVATE wg_ui wg_core wgc_core comctl32 shell32 ole32 oleaut32 uuid advapi32 user32 gdi32 gdiplus dwmapi uxtheme d2d1 d3d11 dxgi dwrite windowscodecs uiautomationcore) if(MSVC) target_compile_options(WrongGPU PRIVATE /Zi) diff --git a/clean/installer/README.md b/clean/installer/README.md index d942f926..d080d864 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -474,6 +474,30 @@ Tested by `model-choice` (ctest: profile.cpp built with the choice on) and `test (a build with the choice on: refusal, both files, record hashes, back to M byte for byte, repair without the data, uninstall), and with it off by `launcher-core` and the same script's build without the choice. +**The Model K choice** (CMake `WRONGGPU_MODEL_K`, default `OFF`; a development build for a front end built with +`WG_MODEL_K=ON` and a runtime with Model K, never part of a release that players get; it needs `WRONGGPU_PRESET_K=ON`, +whose converter map and model folder Model K's data uses, and configuring without it stops with an error). It is the Model +L choice again for one more value: `model` is a setting with the values `m|k` (`m|k|l` together with `WRONGGPU_MODEL_L`), +and with it off `model=K` is not a value (the setting's refusal names the allowed ones). `set model=K`: +- is accepted only while Model K's data on this PC (`model\K\model.wgcm`) passes its check against Model K's converter + data; otherwise "Model K can't be chosen. Model K's data on this PC is not ready (...). Convert it first: WrongGPU.exe + model convert --preset=K ..." (exit 5, nothing changed); +- writes wronggpu.ini's `runtime_options`: every model item out, `model=K` last, and OptiScaler.ini's `UpscalerIndex`: 1, + Model K's entry right after Model M's (`[WrongGPU]` in OptiScaler 10's slot, else `[FSR]`), as the installer's Preset K + start has always written it. With the K choice built in, Model L's entry is 2 in every build (it follows Model K's). +- `set model=M` (the profile says M) puts Model K's item back to `model=M` and an index naming Model K's entry back to + 0, as for Model L; the profile has a `model` line only for K and L. The profile is the truth in a build with the K + choice: an install that starts on Preset K (`/PRESET=K`) writes no profile, so the game's profile is imported from its + files (`model=K` becomes `model=k`), but a `profile.ini` saved by a build without the K choice has no model line and + says M, so the next settings apply puts the game's Model K item back to M. A game saved on K whose Model K data is gone + is not refused: its files say Model M with a warning, the profile keeps K. + +The network is Model K's exact one: the launcher does not offer, write or document any other mode of Model K (the +runtime's `network` and `k_fast` options stay at their defaults; nothing here sets them). Tested by `model-choice-k` and +`model-choice-k-only` (ctest: profile.cpp built with the K choice, with and without the L choice; they run in CI, which +keeps the product builds K-less) and by `tests/run_model_k_tests.py` (a build with both choices: refusal, both files, +record hashes, an L control, back to M byte for byte, repair without the data, uninstall). + **Ignore lists** (`src/wg_core/convert_ignore.*`): WrongGPU converts only the vendor DLL files that came with the player's own games, never a copy that another program's installer placed in a game. Such an installer registers the files it placed in a list the launcher always reads, and the player does nothing. Every search for a file to convert (the model and the Ray diff --git a/clean/installer/src/wg_core/launcher.cpp b/clean/installer/src/wg_core/launcher.cpp index fd02519d..61a1a01d 100644 --- a/clean/installer/src/wg_core/launcher.cpp +++ b/clean/installer/src/wg_core/launcher.cpp @@ -755,14 +755,15 @@ void ApplyProfile(Context& ctx, const wstring& dir, const Profile& p, std::vecto if (!LoadRecord(RecordPath(dir), m) || m.legacy) Fail(L"WrongGPU is not installed in " + dir + L".", EXIT_NOT_INSTALLED); InferOwners(ctx, m); bool recordChanged = m.format < 2; - // Model L saved while its data on this PC is not ready (removed since, or an install of a game set to L before the data - // was converted): the game's files say Model M until it is; the profile keeps the player's choice + // Model L (or Model K, a build with its choice) saved while its data on this PC is not ready (removed since, or an install + // of a game set to it before the data was converted): the game's files say Model M until it is; the profile keeps the + // player's choice Profile q = p; - if (p.get("model") == "l") { + if (const wchar_t chosen = ChosenPreset(p.get("model"))) { wstring why; - if (!ModelFileReady(ctx, L'L', &why)) { + if (!ModelFileReady(ctx, chosen, &why)) { q.v["model"] = "m"; - const wstring w = ModelLNotReady(why) + L" Until then the game starts on Model M."; + const wstring w = ModelNotReady(chosen, why) + L" Until then the game starts on Model M."; notes.push_back(w); if (warnings) warnings->push_back(w); } @@ -1141,10 +1142,14 @@ OpResult RunOp(Context& ctx, const OpRequest& r, Ui& ui) { res.message = L"Engine.ini setting applied; it takes effect the next time the game starts"; break; } - // Model L chosen now (it was not the game's model before): only with its data on this PC; nothing changes otherwise - if (!r.optiOnly && r.hasProfile && r.profile.get("model") == "l" && GameProfile(r.dir).get("model") != "l") { - wstring why; - if (!ModelFileReady(ctx, L'L', &why)) Fail(L"Model L can't be chosen. " + ModelLNotReady(why) + L" Nothing was changed.", EXIT_NO_MODEL); + // Model L (or Model K) chosen now (it was not the game's model before): only with its data on this PC; nothing + // changes otherwise + if (!r.optiOnly && r.hasProfile && r.profile.get("model") != GameProfile(r.dir).get("model")) { + if (const wchar_t chosen = ChosenPreset(r.profile.get("model"))) { + wstring why; + if (!ModelFileReady(ctx, chosen, &why)) + Fail(wstring(L"Model ") + chosen + L" can't be chosen. " + ModelNotReady(chosen, why) + L" Nothing was changed.", EXIT_NO_MODEL); + } } if (!r.optiOnly) ApplyProfile(ctx, r.dir, r.hasProfile ? r.profile : GameProfile(r.dir), res.notes, &res.warnings); ApplyOptiTab(ctx, r.dir, r, res.notes); diff --git a/clean/installer/src/wg_core/model.h b/clean/installer/src/wg_core/model.h index 94bfee22..8a40d534 100644 --- a/clean/installer/src/wg_core/model.h +++ b/clean/installer/src/wg_core/model.h @@ -50,6 +50,14 @@ inline wstring ModelLNotReady(const wstring& why) { return L"Model L's data on this PC is not ready (" + why + L"). Convert it first: WrongGPU.exe model convert --preset=L " L"(optionally --model=)."; } +// The same for Model K (a build with the Model K choice, WRONGGPU_MODEL_K). +inline wstring ModelKNotReady(const wstring& why) { + return L"Model K's data on this PC is not ready (" + why + L"). Convert it first: WrongGPU.exe model convert --preset=K " + L"(optionally --model=)."; +} +// The model a profile asks for besides Model M: L'L' or L'K' (a build with that choice), else 0 (Model M). +inline wchar_t ChosenPreset(const std::string& model) { return model == "l" ? L'L' : model == "k" ? L'K' : L'\0'; } +inline wstring ModelNotReady(wchar_t preset, const wstring& why) { return preset == L'K' ? ModelKNotReady(why) : ModelLNotReady(why); } bool MapHasOptionalGroup(const wgc::Map& map); wstring FilterText(Context& ctx, bool present); std::vector ModelCandidates(const GameTarget* t, const wstring& userDll, const std::vector& libraries); diff --git a/clean/installer/src/wg_core/profile.cpp b/clean/installer/src/wg_core/profile.cpp index 2a05199a..2e967c33 100644 --- a/clean/installer/src/wg_core/profile.cpp +++ b/clean/installer/src/wg_core/profile.cpp @@ -40,12 +40,22 @@ const SettingDef kSettings[] = { // (not decided yet: the launcher asks after the install) and off leave the file alone. {"rr_config_fix", Layer::Rr, Tier::Advanced, "ask", "ask|on|off", L"Ray Reconstruction engine setting", L"On: WrongGPU adds the one Engine.ini line this game's Ray Reconstruction needs (and takes it out again on uninstall)."}, -#if WRONGGPU_MODEL_L - // Model L (#89; only in a release whose front end and runtime run it): the model the game starts with. L needs Model L's - // data on this PC (model\L\model.wgcm, checked against Model L's converter data); M changes nothing in the game's files. +#if WRONGGPU_MODEL_L || WRONGGPU_MODEL_K + // Model L (#89; only in a release whose front end and runtime run it) and Model K (only in a build with its choice, + // WRONGGPU_MODEL_K): the model the game starts with. L and K need their data on this PC (model\L\model.wgcm and + // model\K\model.wgcm, each checked against its own converter data); M changes nothing in the game's files. +#if WRONGGPU_MODEL_K && WRONGGPU_MODEL_L + {"model", Layer::Model, Tier::Basic, "m", "m|k|l", L"Model", + L"M: Model M (default). K: Model K, converted on this PC from a DLSS file of one of your games. " + L"L: Model L, converted from a DLSS file of version 310.5 or newer that has it."}, +#elif WRONGGPU_MODEL_K + {"model", Layer::Model, Tier::Basic, "m", "m|k", L"Model", + L"M: Model M (default). K: Model K, converted on this PC from a DLSS file of one of your games."}, +#else {"model", Layer::Model, Tier::Basic, "m", "m|l", L"Model", L"M: Model M (default). L: Model L, converted from a DLSS file of version 310.5 or newer that has it."}, #endif +#endif }; const size_t kSettingCount = sizeof(kSettings) / sizeof(kSettings[0]); @@ -259,7 +269,7 @@ std::map EffectiveSettings(const string& wronggpuIni, const stri if (FindSetting("model")) { // the last model item of runtime_options (the one the front end uses): Model L or not string model; for (auto& kv : SplitOptions(options)) if (LowerA(kv.first) == "model") model = LowerA(kv.second); - eff["model"] = model == "l" ? "l" : "m"; + eff["model"] = (WRONGGPU_MODEL_L && model == "l") ? "l" : (WRONGGPU_MODEL_K && model == "k") ? "k" : "m"; } string fps; if (IniHasKey(optiIni, "Menu", "ShowFps", &fps)) { @@ -303,17 +313,25 @@ bool RenderWronggpuIni(const Profile& p, const string& in, string& out, wstring* const string rv = RuntimeValue(d.key, p.get(d.key)); if (!p.isDefault(d.key) && !rv.empty()) items.push_back({d.key, rv}); } - // the model (WRONGGPU_MODEL_L builds): L, every model item out and model=L last (the last model item wins); M, only Model - // L's items go back to model=M (the installer's model=M, and Model K's item of a build with it, stay as they are) + // the model (WRONGGPU_MODEL_L / WRONGGPU_MODEL_K builds): L or K, every model item out and model=L / model=K last (the last + // model item wins); M, only the items of the models this build can choose go back to model=M: Model L's, and in a build + // with the Model K choice Model K's too (the profile says M, so a K item is not wanted; an install that starts on Preset K + // has no profile yet, so one is imported from its files: K). The installer's model=M, and Model K's item of a build + // without the K choice, stay as they are. if (FindSetting("model")) { auto isModel = [](const std::pair& kv) { return LowerA(kv.first) == "model"; }; - if (p.get("model") == "l") { + const string want = p.get("model"); + if (want == "l" || want == "k") { std::vector> kept; for (auto& kv : items) if (!isModel(kv)) kept.push_back(kv); - kept.push_back({"model", "L"}); + kept.push_back({"model", want == "k" ? "K" : "L"}); items = kept; } else { - for (auto& kv : items) if (isModel(kv) && LowerA(kv.second) == "l") kv.second = "M"; + for (auto& kv : items) { + if (!isModel(kv)) continue; + const string v = LowerA(kv.second); + if ((WRONGGPU_MODEL_L && v == "l") || (WRONGGPU_MODEL_K && v == "k")) kv.second = "M"; + } } } const string joined = JoinOptions(items); @@ -325,18 +343,26 @@ bool RenderWronggpuIni(const Profile& p, const string& in, string& out, wstring* bool RenderOptiIni(const Profile& p, const string& in, string& out, std::vector* notes) { out = in; - // the model (WRONGGPU_MODEL_L builds): the entry of WrongGPU's list OptiScaler starts with. OptiScaler 10's custom - // upscaler slot: [WrongGPU] UpscalerIndex; else [FSR] UpscalerIndex (the list of WrongGPU's FFX DLL). L: Model L's entry; - // M: back to Model M's entry (0) only when the file names Model L's (another value, such as Model K's, stays). + // the model (WRONGGPU_MODEL_L / WRONGGPU_MODEL_K builds): the entry of WrongGPU's list OptiScaler starts with. OptiScaler + // 10's custom upscaler slot: [WrongGPU] UpscalerIndex; else [FSR] UpscalerIndex (the list of WrongGPU's FFX DLL). L: Model + // L's entry; K: Model K's; M: back to Model M's entry (0) only when the file names the entry of a model this build can + // choose (L's; in a build with the K choice K's too); another value, such as Model K's in a build without the K choice, + // or an entry the player chose in OptiScaler's menu, stays. if (FindSetting("model")) { + const string want = p.get("model"); + const char* wantIndex = want == "l" ? kModelLEntryIndex : want == "k" ? kModelKEntryIndex : nullptr; string cur; const char* sec = IniHasKey(out, "WrongGPU", "UpscalerIndex", &cur) ? "WrongGPU" : IniHasKey(out, "FSR", "UpscalerIndex", &cur) ? "FSR" : nullptr; if (sec) { cur = TrimA(cur); - if (p.get("model") == "l" && cur != kModelLEntryIndex) out = IniSet(out, sec, "UpscalerIndex", kModelLEntryIndex); - else if (p.get("model") != "l" && cur == kModelLEntryIndex) out = IniSet(out, sec, "UpscalerIndex", "0"); - } else if (p.get("model") == "l" && notes) { - notes->push_back(L"Model L: this OptiScaler.ini has no UpscalerIndex key; choose WrongGPU Model L in OptiScaler's menu"); + if (wantIndex) { + if (cur != wantIndex) out = IniSet(out, sec, "UpscalerIndex", wantIndex); + } else if ((WRONGGPU_MODEL_L && cur == kModelLEntryIndex) || (WRONGGPU_MODEL_K && cur == kModelKEntryIndex)) { + out = IniSet(out, sec, "UpscalerIndex", "0"); + } + } else if (wantIndex && notes) { + notes->push_back(want == "k" ? L"Model K: this OptiScaler.ini has no UpscalerIndex key; choose WrongGPU (Model K) in OptiScaler's menu" + : L"Model L: this OptiScaler.ini has no UpscalerIndex key; choose WrongGPU Model L in OptiScaler's menu"); } } const string fps = p.get("fps_overlay"); diff --git a/clean/installer/src/wg_core/profile.h b/clean/installer/src/wg_core/profile.h index 61a1bf82..77212617 100644 --- a/clean/installer/src/wg_core/profile.h +++ b/clean/installer/src/wg_core/profile.h @@ -10,8 +10,9 @@ namespace wg { // wronggpu.ini [fsr] key, runtime_options item, OptiScaler.ini key, the RR plugin's WrongGPU\wronggpu.ini [wronggpu] key // (Ray Reconstruction games only, rr.h: RenderRrSettings writes them; wronggpu.ini and OptiScaler.ini never hold them) -// Model: the model the game starts with (WRONGGPU_MODEL_L builds only): wronggpu.ini's runtime_options model item and the -// OptiScaler entry OptiScaler starts with (UpscalerIndex); with M nothing is changed in either file. +// Model: the model the game starts with (WRONGGPU_MODEL_L / WRONGGPU_MODEL_K builds only): wronggpu.ini's runtime_options +// model item and the OptiScaler entry OptiScaler starts with (UpscalerIndex); with M nothing is changed in either file +// (except that Model K's or Model L's own item and entry go back to Model M's when the profile leaves them). enum class Layer { Fe, Rt, Opti, Rr, Model }; enum class Tier { Basic, Advanced, Diagnostics }; @@ -52,11 +53,14 @@ inline const wchar_t* const kNoModelChoice = L"Model L isn't part of this build of WrongGPU: it comes with a release that runs Model L. The game stays on Model M."; // The index of Model L's entry in the list of upscalers WrongGPU's front end gives OptiScaler (its UpscalerIndex): after // Model M and, in a build with Preset K, Model K. -#if WRONGGPU_PRESET_K +#if WRONGGPU_PRESET_K || WRONGGPU_MODEL_K inline const char* const kModelLEntryIndex = "2"; #else inline const char* const kModelLEntryIndex = "1"; #endif +// Model K's entry (a build with the Model K choice, WRONGGPU_MODEL_K): right after Model M's, as the installer's Preset K +// start has always written it. +inline const char* const kModelKEntryIndex = "1"; // ---- wronggpu.ini -------------------------------------------------------------------------------------------- // The runtime_options items in order (split at ';', trimmed, empty items dropped). diff --git a/clean/installer/src/wizard_policy.h b/clean/installer/src/wizard_policy.h index 72cf29f3..e3a9d45b 100644 --- a/clean/installer/src/wizard_policy.h +++ b/clean/installer/src/wizard_policy.h @@ -17,6 +17,13 @@ #ifndef WRONGGPU_MODEL_L #define WRONGGPU_MODEL_L 0 #endif +// The Model K choice in the launcher (CMake option WRONGGPU_MODEL_K, default OFF: a development build, for a front end and +// runtime that run Model K; it needs WRONGGPU_PRESET_K, whose converter map and model folder Model K's data uses). It makes +// `model` a setting too (values m|k, m|k|l with the Model L choice) and adds `set model=K`. OFF: `model=K` is not a +// value of the setting. Converting Model K's data (`model convert --preset=K`) does not depend on it. +#ifndef WRONGGPU_MODEL_K +#define WRONGGPU_MODEL_K 0 +#endif // UI policy only. Silent installations keep their existing explicit command-line contract. namespace wg_wizard { diff --git a/clean/installer/tests/model_choice_k_tests.cpp b/clean/installer/tests/model_choice_k_tests.cpp new file mode 100644 index 00000000..f27a9c32 --- /dev/null +++ b/clean/installer/tests/model_choice_k_tests.cpp @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: MIT +// The Model K choice of the launcher (profile.cpp built with WRONGGPU_MODEL_K on, whatever the launcher build's switch; +// CMake builds this file twice: with the Model L choice too, and without it). The model setting accepts k, profile.ini +// says model=k, wronggpu.ini's model item is model=K (last, every other model item out) and OptiScaler's UpscalerIndex +// names Model K's entry. Model M changes nothing in either file, byte for byte; Model L (when built in) behaves as in +// model_choice_tests.cpp. Written for this project. Run by ctest ("model-choice-k", "model-choice-k-only"). +#include +#include + +#include "wg_core/profile.h" + +using namespace wg; + +namespace { +int checks = 0; +void require(bool ok, const char* what) { + if (!ok) throw std::runtime_error(what); + ++checks; +} +Profile With(const char* model) { + Profile p = DefaultProfile(); + wstring why; + if (!SetSetting(p, "model", model, &why)) throw std::runtime_error("test setup: model"); + return p; +} +string Wini(const Profile& p, const string& in) { + string out; + wstring why; + if (!RenderWronggpuIni(p, in, out, &why)) throw std::runtime_error("test setup: render"); + return out; +} +string Oini(const Profile& p, const string& in, std::vector* notes = nullptr) { + string out; + RenderOptiIni(p, in, out, notes); + return out; +} +} // namespace + +int main() { + try { + const bool withL = WRONGGPU_MODEL_L != 0; + const string K = kModelKEntryIndex, L = kModelLEntryIndex; + require(K == "1" && L == "2", "Model K's entry is 1 (after Model M's), Model L's is 2 (after Model K's)"); + + // ---- the setting --------------------------------------------------------------------------------------------- + const SettingDef* d = FindSetting("model"); + require(d && d->layer == Layer::Model && string(d->def) == "m", "the model setting: Model M by default"); + require(string(d->values) == (withL ? "m|k|l" : "m|k"), "the values: m|k, and l with the Model L choice"); + Profile p = DefaultProfile(); + wstring why; + require(SetSetting(p, "model", "K", &why) && p.get("model") == "k", "model=K accepted (either case)"); + require(SetSetting(p, "model", " k ", &why) && p.get("model") == "k", "model=k with spaces accepted"); + require(!SetSetting(p, "model", "Q", &why) && p.get("model") == "k" && why.find(withL ? L"allowed: m, k, l" : L"allowed: m, k") != wstring::npos, + "a bad value is refused with the allowed ones named; the choice stays"); + if (withL) { + require(SetSetting(p, "model", "L", &why) && p.get("model") == "l", "model=L still accepted (the Model L control)"); + } else { + require(!SetSetting(p, "model", "L", &why) && why.find(L"allowed: m, k") != wstring::npos, "without the Model L choice, model=L is not a value"); + } + require(SetSetting(p, "model", "M", &why) && p.get("model") == "m" && p.isDefault("model"), "model=M accepted, the default again"); + + // ---- profile.ini: Model M as before the choice existed; K written and read back ----------------------------------- + require(ProfileText(DefaultProfile()).find("model=") == string::npos, "profile.ini of a Model M game: no model line (as before)"); + require(ProfileText(With("k")).find("model=k\r\n") != string::npos, "profile.ini of a Model K game: model=k"); + + // ---- wronggpu.ini -------------------------------------------------------------------------------------------- + const string fresh = "# WrongGPU settings\r\n[fsr]\r\nupscaler = network\r\nruntime_dll = wronggpu_runtime.dll\r\nruntime_options = model=M ; the model\r\n"; + require(Wini(DefaultProfile(), fresh) == fresh, "Model M: the installer's wronggpu.ini unchanged, byte for byte"); + const string toK = Wini(With("k"), fresh); + require(toK.find("runtime_options=model=K") != string::npos && toK.find("model=M") == string::npos && + toK.find("upscaler = network") != string::npos && toK.find("# WrongGPU settings") != string::npos, + "Model K: the model item is model=K; the other lines stay"); + require(Wini(With("k"), toK) == toK, "Model K again: unchanged (the line is rewritten only when its items change)"); + const string mixed = "[fsr]\r\nruntime_options = model=M;timing_log=1;model=L\r\n"; + require(Wini(With("k"), mixed).find("runtime_options=timing_log=1;model=K\r\n") != string::npos, + "Model K: every model item out (an L item too), model=K last (the last one wins); timing_log kept"); + const string backM = Wini(DefaultProfile(), "[fsr]\r\nruntime_options = timing_log=1;model=K\r\n"); + require(backM.find("runtime_options=timing_log=1;model=M\r\n") != string::npos, "back to Model M: Model K's item becomes model=M"); + require(Wini(DefaultProfile(), toK) == fresh.substr(0, fresh.find("runtime_options")) + "runtime_options=model=M\r\n", + "K then M: only the runtime_options line is rewritten (the installer's comment on it is gone as it is for L)"); + const string withLItem = "[fsr]\r\nruntime_options = model=L\r\n"; + if (withL) { + require(Wini(DefaultProfile(), withLItem).find("model=M") != string::npos, "Model M control: Model L's item still goes back to model=M"); + require(Wini(With("l"), toK).find("runtime_options=model=L") != string::npos && Wini(With("l"), toK).find("model=K") == string::npos, + "Model L control: K to L, the K item is out, model=L is last"); + require(Wini(With("k"), Wini(With("l"), toK)).find("runtime_options=model=K") != string::npos, "L to K again: model=K"); + } else { + require(Wini(DefaultProfile(), withLItem) == withLItem, "without the Model L choice, Model L's item is not managed: it stays"); + } + require(EffectiveSettings(toK, "")["model"] == "k" && EffectiveSettings(fresh, "")["model"] == "m", + "the file's model: K from its last model item, M otherwise"); + require(EffectiveSettings("[fsr]\r\nruntime_options = model=K;model=M\r\n", "")["model"] == "m", "the file's model: the last model item counts"); + require(EffectiveSettings(withLItem, "")["model"] == (withL ? "l" : "m"), "the file's model: L only with the Model L choice"); + // the profile a game's files imply (no profile.ini): K when the files say K (an install that started on Preset K) + require(ImportProfile(toK, "").get("model") == "k" && ImportProfile(fresh, "").get("model") == "m", "the imported profile: model=k from model=K"); + require(OutsideEdits(With("k"), toK, "").empty() && OutsideEdits(DefaultProfile(), fresh, "").empty(), + "files that say what the profile says (K and K, M and M) are no outside edit"); + require(OutsideEdits(DefaultProfile(), toK, "").size() == 1 && OutsideEdits(DefaultProfile(), toK, "")[0].key == "model", + "a file that says model=K under a profile of Model M is an outside edit (an install that starts on Preset K saves K)"); + + // ---- OptiScaler.ini: the entry OptiScaler starts with ----------------------------------------------------------- + const string slot = "[WrongGPU]\r\nUpscalerIndex=0\r\n[FSR]\r\nUpscalerIndex=0\r\n[Menu]\r\nShowFps=auto\r\n"; + require(Oini(DefaultProfile(), slot) == slot, "Model M: OptiScaler.ini unchanged, byte for byte"); + const string slotK = Oini(With("k"), slot); + require(slotK.find("[WrongGPU]\r\nUpscalerIndex=" + K + "\r\n") != string::npos && slotK.find("[FSR]\r\nUpscalerIndex=0\r\n") != string::npos, + "Model K, OptiScaler 10's slot: [WrongGPU] UpscalerIndex names Model K's entry; AMD's [FSR] entry is left to OptiScaler"); + require(Oini(With("k"), slotK) == slotK, "Model K again: unchanged"); + require(Oini(DefaultProfile(), slotK) == slot, "back to Model M: [WrongGPU] UpscalerIndex=0 again, the rest as it was"); + const string other = "[WrongGPU]\r\nUpscalerIndex=7\r\n"; + require(Oini(DefaultProfile(), other) == other, "Model M: another entry the player chose in OptiScaler's menu stays"); + require(Oini(With("k"), "[FSR]\r\nUpscalerIndex=0\r\n") == "[FSR]\r\nUpscalerIndex=" + K + "\r\n", + "Model K, WrongGPU's FFX DLL as OptiScaler's FSR: [FSR] UpscalerIndex"); + const string slotLEntry = "[WrongGPU]\r\nUpscalerIndex=" + L + "\r\n"; + if (withL) { + require(Oini(DefaultProfile(), slotLEntry) == "[WrongGPU]\r\nUpscalerIndex=0\r\n", "Model M control: Model L's entry still goes back to 0"); + require(Oini(With("l"), slotK) == "[WrongGPU]\r\nUpscalerIndex=" + L + "\r\n[FSR]\r\nUpscalerIndex=0\r\n[Menu]\r\nShowFps=auto\r\n", + "Model L control: K's entry to L's"); + require(Oini(With("k"), Oini(With("l"), slot)) == slotK, "L to K: K's entry again"); + } else { + require(Oini(DefaultProfile(), slotLEntry) == slotLEntry, "without the Model L choice, Model L's entry is not managed: it stays"); + } + std::vector notes; + const string none = "[Menu]\r\nShowFps=auto\r\n"; + require(Oini(With("k"), none, ¬es) == none && notes.size() == 1 && notes[0].find(L"Model K") != wstring::npos && + notes[0].find(L"no UpscalerIndex key") != wstring::npos, + "Model K without an UpscalerIndex key: nothing written, the player is told to choose it in OptiScaler's menu"); + Profile fps = With("k"); + SetSetting(fps, "fps_overlay", "on", &why); + require(Oini(fps, slot).find("ShowFps=true") != string::npos && Oini(fps, slot).find("UpscalerIndex=" + K) != string::npos, + "the FPS overlay setting still applies with the model"); + } catch (const std::exception& e) { + std::cerr << "model-choice-k FAILED after " << checks << " checks: " << e.what() << std::endl; + return 1; + } + std::cout << "model-choice-k (" << (WRONGGPU_MODEL_L ? "with" : "without") << " the Model L choice): " << checks << " checks passed" << std::endl; + return 0; +} diff --git a/clean/installer/tests/run_model_k_tests.py b/clean/installer/tests/run_model_k_tests.py new file mode 100644 index 00000000..105f23ca --- /dev/null +++ b/clean/installer/tests/run_model_k_tests.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +"""The launcher's Model K choice (CMake WRONGGPU_MODEL_K, a development build) through its command line: `set +model=K|M` on an installed fixture game. K only with Model K's data on this PC; it writes wronggpu.ini's model item and +OptiScaler's UpscalerIndex (1, Model K's entry right after Model M's), the install record's hashes follow, M puts both files +back byte for byte, an L control (a build with the Model L choice too) is unchanged, uninstall restores the game. + +Written for this project; Python standard library only. Runs WrongGPU.exe (a WRONGGPU_TESTING build made from the installer +suite's prepared payload and maps, with -DWRONGGPU_PRESET_K=ON -DWRONGGPU_MODEL_K=ON -DWRONGGPU_MODEL_L=ON -DWRONGGPU_DIRECT_ROUTE=OFF +and the two test maps below) against generated files only: synthetic model files from the converter's test generator. No +game, no GPU, no window; --noscan always. + + python run_installer_tests.py --prepare-only --work (the payload and test-map.json for -DWRONGGPU_PAYLOAD_DIR / -DWRONGGPU_MAP) + python run_model_k_tests.py --write-test-maps (test-map-k.json for -DWRONGGPU_MAP_K=, test-map-l.json for -DWRONGGPU_MAP_L=) + python run_model_k_tests.py --launcher --work +""" +import argparse +import hashlib +import json +import os +import shutil +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, HERE) +import run_model_l_tests as ml # noqa: E402 (T, the Model L case and the install helpers; it sets WRONGGPU_TESTING) +from run_installer_tests import read, write # noqa: E402 +from run_model_l_tests import m_case, l_case, recorded_hash, suite, suite_options_model, upscaler_index # noqa: E402 + + +def k_case(): + """The synthetic Model K source of the test map (the same every time).""" + return suite.cases.k_mini_case(file_version=(310, 98, 2, 0)) + + +def profile_text(b): + return read(os.path.join(b, "wronggpu-setup", "profile.ini")) + + +def test_choice(t): + print("\n[1] the model choice: set model=K / model=M / model=L (a build with the K and L choices)") + import run_launcher_tests as rl # (its game and OptiScaler fixtures: names and synthetic bytes only) + t.model = m_case() # rl.game() writes t.model.file as the game's DLSS file (this hides T.model, the path helper) + root, b, exe = rl.game(t, "K Choice Game", validated=True) + before = suite.snapshot(root) + opti = rl.opti_package(t) + rc = t.run("install", exe, "--opti=" + opti, "--force") + t.check("install: exit 0", rc == 0, (rc, t.j.get("message"), t.stdout[-400:])) + if rc != 0: + return + wini, oini = os.path.join(b, "wronggpu.ini"), os.path.join(b, "OptiScaler.ini") + m_w, m_o = read(wini), read(oini) + rc = t.run("get", exe, "model") + t.check("get model: m (Model M, the default)", rc == 0 and t.j.get("settings", {}).get("model", {}).get("profile") == "m", t.j.get("settings")) + rc = t.run("set", exe, "model=Q") + t.check("set model=Q: refused, the allowed values named (m, k, l); nothing changed", + rc != 0 and "allowed: m, k, l" in t.j.get("message", "") + t.j.get("error", "") and read(wini) == m_w and read(oini) == m_o, + (rc, t.j.get("message"), t.j.get("error"))) + rc = t.run("set", exe, "model=K") + t.check("set model=K without Model K's data: exit 5, refused by name, nothing changed", + rc == 5 and "Model K can't be chosen" in t.j.get("message", "") + t.j.get("error", "") and + "model convert --preset=K" in t.j.get("message", "") + t.j.get("error", "") and read(wini) == m_w and read(oini) == m_o and + b"model=" not in profile_text(b), (rc, t.j.get("message"), t.j.get("error"))) + ksrc = os.path.join(t.work, "k-source", "nvngx_dlss.dll") + write(ksrc, k_case().file) + rc = t.run("model", "convert", "--preset=K", "--model=" + ksrc) + t.check("Model K's data converted (model convert --preset=K)", rc == 0 and ml.holds(t.model_path("K", "model.wgcm"), k_case()), (rc, t.j)) + rc = t.run("set", exe, "model=K") + w = read(wini).decode("utf-8", "replace") + t.check("set model=K: exit 0; wronggpu.ini's last model item is model=K", rc == 0 and suite_options_model(w) == "K", (rc, t.j.get("message"), w)) + o = read(oini).decode("utf-8", "replace") + t.check("...OptiScaler's UpscalerIndex names Model K's entry (1: right after Model M)", upscaler_index(o) == "1", o) + t.check("...the record's hashes follow both files (the file-ownership rule: they are WrongGPU's writes)", + recorded_hash(b, "wronggpu.ini") == hashlib.sha256(read(wini)).hexdigest() and recorded_hash(b, "OptiScaler.ini") == hashlib.sha256(read(oini)).hexdigest(), + (recorded_hash(b, "wronggpu.ini"), recorded_hash(b, "OptiScaler.ini"))) + t.check("...profile.ini says model=k", b"model=k\r\n" in profile_text(b)) + k_w, k_o = read(wini), read(oini) + rc = t.run("set", exe, "model=K") + t.check("set model=K again: nothing changes", rc == 0 and read(wini) == k_w and read(oini) == k_o, rc) + rc = t.run("get", exe, "model") + t.check("get model: k", rc == 0 and t.j.get("settings", {}).get("model", {}).get("profile") == "k", t.j.get("settings")) + rc = t.run("set", exe, "model=M") + t.check("set model=M: wronggpu.ini and OptiScaler.ini back byte for byte as the install wrote them", + rc == 0 and read(wini) == m_w and read(oini) == m_o, (rc, read(wini)[-200:], read(oini)[-200:])) + t.check("...profile.ini has no model line again", b"model=" not in profile_text(b)) + # the Model L control: unchanged by the K choice (its entry follows Model K's, so it is 2) + lsrc = os.path.join(t.work, "l-source", "nvngx_dlss.dll") + write(lsrc, l_case().file) + rc = t.run("model", "convert", "--preset=L", "--model=" + lsrc) + t.check("L control: Model L's data converted", rc == 0, (rc, t.j)) + rc = t.run("set", exe, "model=L") + t.check("L control: set model=L writes model=L and index 2 (after Model K's entry)", + rc == 0 and suite_options_model(read(wini).decode("utf-8", "replace")) == "L" and upscaler_index(read(oini).decode("utf-8", "replace")) == "2", + (rc, t.j.get("message"), read(wini), read(oini))) + rc = t.run("set", exe, "model=K") + t.check("L to K: model=K and index 1", rc == 0 and suite_options_model(read(wini).decode("utf-8", "replace")) == "K" and + upscaler_index(read(oini).decode("utf-8", "replace")) == "1", (rc, t.j.get("message"))) + rc = t.run("set", exe, "model=L") + rc2 = t.run("set", exe, "model=M") + t.check("K to L to M: back byte for byte as the install wrote them", rc == 0 and rc2 == 0 and read(wini) == m_w and read(oini) == m_o, (rc, rc2)) + # a game saved on K whose data goes away: a repair keeps the player's choice, the files say Model M with a warning + rc = t.run("set", exe, "model=K") + os.remove(os.path.join(t.lad, "WrongGPU", "model", "K", "model.wgcm")) + rc = t.run("repair", exe, "--opti=" + opti, "--force") + msgs = " ".join(t.j.get("warnings", []) + t.j.get("notes", [])) + t.check("repair of a game set to K without Model K's data: exit 0, the files say Model M, the player is told how to convert it", + rc == 0 and suite_options_model(read(wini).decode("utf-8", "replace")) == "M" and "Model K's data on this PC is not ready" in msgs and + "model convert --preset=K" in msgs, (rc, t.j.get("message"), msgs[:600])) + t.check("...the choice stays in profile.ini (model=k)", b"model=k\r\n" in profile_text(b)) + rc = t.run("uninstall", exe) + # A build with Preset K seeds the plugin's own settings file wronggpu-asi.ini on every OptiScaler install; an uninstall leaves + # it in place and lists it (optiscaler.h SeedAsiSelection), as it did before the K choice. Nothing else may differ. + left = suite.diff(before, suite.snapshot(root)) + t.check("uninstall: the game folder byte for byte as before the install, except the plugin's own wronggpu-asi.ini", + rc == 0 and left.startswith("bin/x64/wronggpu-asi.ini: absent -> ") and ";" not in left, (rc, left)) + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--write-test-maps", help="write test-map-k.json and test-map-l.json into this folder and stop") + ap.add_argument("--launcher", help="WrongGPU.exe built with the K, L and Preset K choices and the test maps") + ap.add_argument("--work", default=os.path.join(HERE, "..", "build-tests", "model-k")) + a = ap.parse_args() + if a.write_test_maps: + write(os.path.join(a.write_test_maps, "test-map-k.json"), json.dumps(k_case().map, indent=1)) + write(os.path.join(a.write_test_maps, "test-map-l.json"), ml.map_bytes(l_case())) + print("test maps: " + a.write_test_maps) + return 0 + if not a.launcher: + ap.error("--launcher or --write-test-maps is needed") + d = os.path.join(os.path.abspath(a.work), "choice") + shutil.rmtree(d, ignore_errors=True) + os.makedirs(d) + t = ml.T(os.path.abspath(a.launcher), d) + t.model_path = t.model # (test_choice replaces t.model with the Model M case, as the Model L script does) + test_choice(t) + print("\n%d checks passed, %d failed" % (t.passed, len(t.failures))) + for f in t.failures: + print(" FAILED: " + f) + return 1 if t.failures else 0 + + +if __name__ == "__main__": + sys.exit(main())