diff --git a/clean/installer/CMakeLists.txt b/clean/installer/CMakeLists.txt index 92b299a2..bca556bb 100644 --- a/clean/installer/CMakeLists.txt +++ b/clean/installer/CMakeLists.txt @@ -33,6 +33,17 @@ set(WRONGGPU_MAP_K "${CMAKE_CURRENT_SOURCE_DIR}/../../data/preset-K.v1.map.json" # team's synthetic preset-F map, so its tests never need a real RR file. set(WRONGGPU_RR_DIR "" CACHE PATH "Folder with the RR plugin (plugins/WrongGPU-RR.asi) and the RR runtime (wronggpu_rr_runtime.dll)") set(WRONGGPU_MAP_F "" CACHE FILEPATH "RR converter map (preset F); empty: data/preset-F.v1.map.json (test builds: the synthetic rr-f-synth/synth-r0 map)") +# Model L (#89): its converter map, embedded for "model convert --preset=L" (the model's folder: \L). Default: the +# shipped map (data/preset-L.v1.map.json, the spec side's revision v1.1). Tests of the conversion itself give a map of +# its exact layout with their own digests (tests/run_model_l_tests.py --write-test-map); empty: a build without Model L. +set(WRONGGPU_MAP_L "${CMAKE_CURRENT_SOURCE_DIR}/../../data/preset-L.v1.map.json" CACHE FILEPATH "Model L converter map (preset L); empty: none") +if(WRONGGPU_MAP_L AND EXISTS "${WRONGGPU_MAP_L}") + set(MAP_L_ARGS --map-l ${WRONGGPU_MAP_L}) + set(MAP_L_FILE ${WRONGGPU_MAP_L}) +else() + set(MAP_L_ARGS) + set(MAP_L_FILE) +endif() option(WRONGGPU_PRESET_K "Preset K in the installer (second model choice, /PRESET=K, its converter map); OFF = Model M only" ON) if(WRONGGPU_PRESET_K) set(PRESET_K_MAP_ARGS --map-k ${WRONGGPU_MAP_K}) @@ -143,8 +154,8 @@ add_custom_command( COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/make_payload.py --payload ${WRONGGPU_PAYLOAD_DIR} --map ${WRONGGPU_MAP} ${PRESET_K_MAP_ARGS} --version ${WRONGGPU_VERSION} --build-id=${WRONGGPU_BUILD_ID} --payload-name=${WRONGGPU_PAYLOAD_NAME} - ${DIRECT_ROUTE_PAYLOAD_ARGS} ${RR_PAYLOAD_ARGS} ${MAP_F_ARGS} ${MANIFEST_ARGS} --out ${GEN} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/make_payload.py ${MANIFEST} ${WRONGGPU_MAP} ${PRESET_K_MAP_FILE} ${MAP_F_FILE} ${WRONGGPU_PAYLOAD_FILES} ${WRONGGPU_RR_FILES} + ${DIRECT_ROUTE_PAYLOAD_ARGS} ${RR_PAYLOAD_ARGS} ${MAP_F_ARGS} ${MAP_L_ARGS} ${MANIFEST_ARGS} --out ${GEN} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/make_payload.py ${MANIFEST} ${WRONGGPU_MAP} ${PRESET_K_MAP_FILE} ${MAP_F_FILE} ${MAP_L_FILE} ${WRONGGPU_PAYLOAD_FILES} ${WRONGGPU_RR_FILES} COMMENT "Embedding the payload and the converter map") # WrongGPU-Restore.exe: the per-game restorer (uninstall.exe in each game's wronggpu-setup folder): wg_core without the diff --git a/clean/installer/README.md b/clean/installer/README.md index 8b74d3c5..be0c3882 100644 --- a/clean/installer/README.md +++ b/clean/installer/README.md @@ -318,7 +318,8 @@ ctest `source-size`. the window itself never runs elevated. - **Command line** (a verb as the first argument; `src/app/cli.cpp`): `scan`, `status [game]`, `install`, `repair`, `update`, `uninstall`, `rollback`, `adopt [game | --all]`, `set key=value ...`, `set --global key=value`, - `get [key]`, `get --global`, `collect [--zip=]`, `hipcheck`, `model status|convert`, + `get [key]`, `get --global`, `collect [--zip=]`, `hipcheck`, `model status|convert [--preset=M|L]` + ("Model L by name" below), `rr-data status|convert [--dll=]` (both converts also take `--ignore=`, `--ignore-list=` and `--library=`: "Ignore lists" below), `self-install [--dir=] [--startmenu=|-]`, `self-uninstall [--keep-games]`, `play `, `update-check`, @@ -372,6 +373,19 @@ keep the games, which then get their own entries back); its data (`launcher.ini` `%LOCALAPPDATA%\WrongGPU\model` in both modes (the runtime reads it there). `managed-games.txt` in that folder lists the managed games, so an uninstaller keeps the model while another game uses it. +**Model L by name** (#89; `src/wg_core/context.h` `SelectPreset`): `model status --preset=L` and +`model convert --preset=L [--model=]` use Model L's converter map and model folder. The launcher embeds the +map (CMake `WRONGGPU_MAP_L`, default `data/preset-L.v1.map.json`, the spec side's revision v1.1; empty: a build without +Model L) and loads it as preset L, so a map that names another preset is "converter data damaged". The model goes to +`%LOCALAPPDATA%\WrongGPU\model\L\model.wgcm` with its own `model-source.txt`, the folder where the runtime looks for +`model=L`. Model M's files are never touched by it. A file without Model L's data is refused: "Model L can't be prepared: +no DLSS model file with Model L's data was found.", followed by the converter's reason for the file the player chose +(exit 5). An unknown name, or Model L in a build without its map, is a bad command line (exit 10). The JSON result names +the model (`preset`) and the converter map in use (`model.map_sha256`). Without `--preset` nothing changes. The window's +model choice and the runtime settings for Model L are not part of this step. `tests/run_model_l_tests.py` checks it +end to end: once with a build of the shipped map, and once with a build of a test map in its exact layout +(`--write-test-map`). + **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/app/cli.cpp b/clean/installer/src/app/cli.cpp index abc09f7d..e4d9017d 100644 --- a/clean/installer/src/app/cli.cpp +++ b/clean/installer/src/app/cli.cpp @@ -18,7 +18,8 @@ // fingerprint ... what a DLL is (version resource, exports, text; never its name) // collect [--out=] logs into a zip // hipcheck the HIP runtime check alone -// model status | model convert [--model=] +// model status | model convert [--model=] [--preset=M|L]: the model by name (its converter map and folder; K too in +// a build with Preset K) // rr-data status | rr-data convert [--dll=] the Ray Reconstruction data (shared by the RR games) // both converts: --ignore= | --ignore= sha256= (both must match) | // --ignore=sha256= (every identical copy), --ignore-list= (repeatable; added @@ -886,6 +887,13 @@ int Verb(const wstring& verb, const Args& a, Output& o) { } if (verb == L"model") { const wstring sub = a.pos.empty() ? L"status" : a.pos[0]; + // --preset=: the model by its name (M, L; K in a build with Preset K). Its converter map, model folder and + // messages; without it, the launcher's model as before. + if (a.opt.count(L"preset") || a.has(L"preset")) { // --preset=; a bare --preset (no name) is refused + wstring why; + if (!SelectPreset(g.ctx, a.get(L"preset"), why)) { o.j.S("error", why); Print(why); return EXIT_USAGE; } + } + o.j.S("preset", wstring(1, SelectedPreset(g.ctx))); if (sub == L"convert") { if (!ConvertIgnoreArgs(a, o)) return o.code; OpLogBegin(); @@ -911,7 +919,10 @@ int Verb(const wstring& verb, const Args& a, Output& o) { wstring why; wgc::ModelFileInfo info{}; const bool valid = ExistingModelValid(g.ctx, &why, &info); - o.j.Key("model").Obj().S("file", ModelFile(g.ctx)).B("valid", valid).S("source", ReadModelSource(g.ctx)).S("why", why).End(); + // map_sha256: the converter map of the selected model (embedded; the file it was built from has the same SHA-256) + const wstring mapSha = g.ctx.map.map ? FromUtf8(wgc::to_hex(g.ctx.map.map->file_sha256)) : wstring(); + o.j.Key("model").Obj().S("file", ModelFile(g.ctx)).B("valid", valid).S("source", ReadModelSource(g.ctx)).S("why", why) + .S("map_sha256", mapSha).S("map_error", g.ctx.mapError).End(); Print(wstring(L"model data: ") + (valid ? L"ready (" + ModelFile(g.ctx) + L")" : L"not ready" + (why.empty() ? wstring() : L" (" + why + L")"))); return valid || sub == L"status" ? EXIT_OK : EXIT_NO_MODEL; } diff --git a/clean/installer/src/app/payload_embed.cpp b/clean/installer/src/app/payload_embed.cpp index e32e004c..8425b0e1 100644 --- a/clean/installer/src/app/payload_embed.cpp +++ b/clean/installer/src/app/payload_embed.cpp @@ -15,6 +15,6 @@ const wg::EmbeddedData& EmbeddedPayload() { #endif kLogoResourceId, SETUP_VERSION, SETUP_BUILD_ID, SETUP_PAYLOAD_NAME, kRrPayload, kRrPayloadCount, kFMapResourceId, kFMapSha256, // Ray Reconstruction (rr.h) - kRrInterfaceFile}; + kRrInterfaceFile, kLMapResourceId, kLMapSha256}; // Model L's converter map return data; } diff --git a/clean/installer/src/wg_core/context.cpp b/clean/installer/src/wg_core/context.cpp index 350e5fc7..fc41f019 100644 --- a/clean/installer/src/wg_core/context.cpp +++ b/clean/installer/src/wg_core/context.cpp @@ -2,6 +2,7 @@ // WrongGPU launcher core: the Context, the log file, the model data folder and the embedded converter map. Written for // this project. #include "context.h" +#include #include "payload.h" namespace wg { @@ -47,12 +48,39 @@ wstring ModelBaseDir() { return Join(AppDataPath(), L"model"); } #if WRONGGPU_PRESET_K int MapResourceId(Context& ctx, bool k) { return k ? ctx.data->kMapId : ctx.data->mapId; } const wchar_t* MapSha256(Context& ctx, bool k) { return k ? ctx.data->kMapSha256 : ctx.data->mapSha256; } -wstring ModelDir(Context& ctx) { return ctx.presetK ? Join(ModelBaseDir(), L"K") : ModelBaseDir(); } +wstring ModelDir(Context& ctx) { return ctx.presetL ? Join(ModelBaseDir(), L"L") : ctx.presetK ? Join(ModelBaseDir(), L"K") : ModelBaseDir(); } #else int MapResourceId(Context& ctx, bool) { return ctx.data->mapId; } const wchar_t* MapSha256(Context& ctx, bool) { return ctx.data->mapSha256; } -wstring ModelDir(Context&) { return ModelBaseDir(); } +wstring ModelDir(Context& ctx) { return ctx.presetL ? Join(ModelBaseDir(), L"L") : ModelBaseDir(); } #endif +wchar_t SelectedPreset(const Context& ctx) { return ctx.presetL ? L'L' : ctx.presetK ? L'K' : L'M'; } +bool SelectPreset(Context& ctx, const wstring& name, wstring& error) { + const wchar_t c = name.size() == 1 ? static_cast(towupper(name[0])) : L'\0'; +#if WRONGGPU_PRESET_K + const wstring known = L"M, L or K"; + const bool isK = c == L'K'; +#else + const wstring known = L"M or L"; + const bool isK = false; +#endif + if (c != L'M' && c != L'L' && !isK) { + error = L"Unknown model \"" + name + L"\" (the models of this build: " + known + L")."; + return false; + } + if (c == L'L' && (!ctx.data || !ctx.data->lMapId)) { + error = L"This build of WrongGPU has no converter data for Model L."; + return false; + } + if (c == SelectedPreset(ctx)) return true; + ctx.presetL = c == L'L'; +#if WRONGGPU_PRESET_K + ctx.presetK = c == L'K'; +#endif + ctx.map = wgc::LoadedMap(); // the other model's map is loaded on first use (LoadEmbeddedMap) + ctx.mapError.clear(); + return true; +} wstring ModelFile(Context& ctx) { return Join(ModelDir(ctx), FromUtf8(wgc::kModelFileName)); } wstring ModelSourceFile(Context& ctx) { return Join(ModelDir(ctx), L"model-source.txt"); } @@ -62,11 +90,15 @@ bool LoadEmbeddedMap(Context& ctx) { static std::mutex loading; std::lock_guard lock(loading); if (ctx.map.map) return true; + // Model L: its own map, loaded as preset L (the converter refuses a map that names another preset: "converter data + // damaged"). Models M and K: as before (the map's own preset). + const bool l = ctx.presetL; + if (l && !ctx.data->lMapId) { ctx.mapError = L"this build has no converter data for Model L"; return false; } DWORD sz = 0; - const void* d = ResourceData(MapResourceId(ctx, ctx.presetK), sz); - if (!d || Sha256Bytes(d, sz) != MapSha256(ctx, ctx.presetK)) { ctx.mapError = L"the converter data is missing or damaged"; return false; } + const void* d = ResourceData(l ? ctx.data->lMapId : MapResourceId(ctx, ctx.presetK), sz); + if (!d || Sha256Bytes(d, sz) != (l ? ctx.data->lMapSha256 : MapSha256(ctx, ctx.presetK))) { ctx.mapError = L"the converter data is missing or damaged"; return false; } const wgc::Result r = wgc::load_map_bytes(string(static_cast(d), sz), ctx.map, - [&ctx](const string& s) { LogLine(ctx, L"converter: " + FromUtf8(s)); }); + [&ctx](const string& s) { LogLine(ctx, L"converter: " + FromUtf8(s)); }, l ? "L" : ""); if (r.code != wgc::kOk) { ctx.mapError = FromUtf8(r.message); return false; } return true; } diff --git a/clean/installer/src/wg_core/context.h b/clean/installer/src/wg_core/context.h index 2d34ca40..47395fa0 100644 --- a/clean/installer/src/wg_core/context.h +++ b/clean/installer/src/wg_core/context.h @@ -37,6 +37,10 @@ struct EmbeddedData { // the file name of the game interface the RR plugin hooks (the RR folder's interposer.json; empty: none given): which // build of the plugin a game gets follows its version (rr.h, RrPluginFor) const wchar_t* rrInterface = L""; + // Model L (#89): its converter map (data/preset-L.v1.map.json, revision v1.1; CMake WRONGGPU_MAP_L). lMapId 0: not in + // this build. + int lMapId = 0; + const wchar_t* lMapSha256 = L""; const PayloadFile* begin() const { return files; } const PayloadFile* end() const { return files + count; } }; @@ -70,6 +74,9 @@ struct Context { #else static constexpr bool presetK = false; // CMake WRONGGPU_PRESET_K=OFF: Model M only #endif + // Model L (#89): the converter map and model folder (\L, the runtime's folder for model=L) are Model L's. + // Chosen by name (SelectPreset); it takes precedence over presetK. + bool presetL = false; // The converter map of the selected preset, loaded and validated once (spec 08 section 5; LoadEmbeddedMap). wgc::LoadedMap map; wstring mapError; @@ -110,6 +117,12 @@ wstring DefaultLogPath(); wstring ModelBaseDir(); int MapResourceId(Context& ctx, bool k); const wchar_t* MapSha256(Context& ctx, bool k); +// The selected model's name: L'L' (presetL), L'K' (presetK) or L'M'. +wchar_t SelectedPreset(const Context& ctx); +// Selects a model by its name (M, L, and K in a build with Preset K; either case) for the converter map, the model folder +// and the conversion. A different model than before drops the loaded map. False: `error` says why (an unknown name, or a +// model whose converter data this build does not have); nothing changes. +bool SelectPreset(Context& ctx, const wstring& name, wstring& error); wstring ModelDir(Context& ctx); wstring ModelFile(Context& ctx); wstring ModelSourceFile(Context& ctx); diff --git a/clean/installer/src/wg_core/model.cpp b/clean/installer/src/wg_core/model.cpp index 19a56d3a..388629e0 100644 --- a/clean/installer/src/wg_core/model.cpp +++ b/clean/installer/src/wg_core/model.cpp @@ -207,6 +207,19 @@ ModelState FindModel(Context& ctx, const GameTarget* t, const wstring& userDll, LogLine(ctx, L"model: every DLSS model file found is on an ignore list; nothing converted"); return m; } + const wstring skippedText = skipped ? L" " + std::to_wstring(skipped) + L" file(s) on an ignore list were not tried. " + IgnoredExample(ctx, m.ignored) : wstring(); + if (ctx.presetL) { // Model L: said by name, with the converter's reason for the file the player chose + const wstring picked = userDll.empty() ? wstring() : FullPath(userDll); + wstring why; + for (auto& r : m.rejections) + if (!picked.empty() && r.size() > picked.size() + 2 && IEq(r.substr(0, picked.size() + 2), picked + L": ")) { why = r.substr(picked.size() + 2); break; } + m.error = L"Model L can't be prepared: no DLSS model file with Model L's data was found." + + (why.empty() ? wstring() : L" The file you chose (" + picked + L"): " + why) + + L" Model L is converted from the DLSS model file (nvngx_dlss.dll) of version 310.5 or newer. The file stays where it is: " + L"only the model data is read, on this PC." + skippedText + (m.chosenSkipped.empty() ? wstring() : L" " + m.chosenSkipped); + LogLine(ctx, L"model: " + m.error); + return m; + } m.error = L"No DLSS model file that WrongGPU can use was found. WrongGPU needs the DLSS model file (nvngx_dlss.dll) of " L"version 310.5 or newer, which comes with many recent games and apps. Install or update such a game, or choose its " L"nvngx_dlss.dll yourself. The file stays where it is: only the model data is read, on this PC." + diff --git a/clean/installer/tests/launcher_core_tests.cpp b/clean/installer/tests/launcher_core_tests.cpp index c1fde078..f58e6f66 100644 --- a/clean/installer/tests/launcher_core_tests.cpp +++ b/clean/installer/tests/launcher_core_tests.cpp @@ -74,6 +74,29 @@ int main() { require(!HasConverterData(rc, false) && !HasConverterData(rc, true) && HasConverterData(lc, false), "the converter data: uninstall.exe none, WrongGPU.exe its map"); RemoveTree(cl); } + // ---- Model L (#89): the model by name (model convert/status --preset=); its converter map and model folder -------- + { + static const EmbeddedData withL{nullptr, 0, 900, L"00", 0, L"", 0, L"0.7.0", L"0.7.0", L"0.7.0", nullptr, 0, 0, L"", L"", 903, L"00"}; + static const EmbeddedData noL{nullptr, 0, 900, L"00", 0, L"", 0, L"0.7.0"}; + Context lc, nc; + lc.data = &withL; + nc.data = &noL; + wstring err; + require(SelectedPreset(lc) == L'M' && ModelDir(lc) == ModelBaseDir(), "Model M by default: the model folder itself"); + lc.mapError = L"an earlier load"; + require(SelectPreset(lc, L"l", err) && lc.presetL && SelectedPreset(lc) == L'L' && ModelDir(lc) == Join(ModelBaseDir(), L"L") && + ModelFile(lc) == Join(Join(ModelBaseDir(), L"L"), L"model.wgcm") && lc.mapError.empty(), + "--preset=l: Model L, its folder \\L (the runtime's folder for model=L); the earlier map state is dropped"); + require(SelectPreset(lc, L"L", err) && lc.presetL, "the same model again: nothing changes"); + require(SelectPreset(lc, L"M", err) && !lc.presetL && SelectedPreset(lc) == L'M' && ModelDir(lc) == ModelBaseDir(), "back to Model M: the model folder itself"); + require(!SelectPreset(lc, L"Q", err) && err.rfind(L"Unknown model \"Q\"", 0) == 0 && SelectedPreset(lc) == L'M', "an unknown name is refused; nothing changes"); + require(!SelectPreset(lc, L"ML", err) && !SelectPreset(lc, L"", err) && SelectedPreset(lc) == L'M', "a model name is one letter"); + require(!SelectPreset(nc, L"L", err) && err == L"This build of WrongGPU has no converter data for Model L." && !nc.presetL && ModelDir(nc) == ModelBaseDir(), + "a build without Model L's map refuses L by name; nothing changes"); +#if !WRONGGPU_PRESET_K + require(!SelectPreset(lc, L"K", err) && err.find(L"M or L") != wstring::npos, "K is not a model of a build without Preset K"); +#endif + } // ---- validation ----------------------------------------------------------------------------------------- string n; wstring why; const SettingDef* exec = FindSetting("executor"); diff --git a/clean/installer/tests/run_model_l_tests.py b/clean/installer/tests/run_model_l_tests.py new file mode 100644 index 00000000..980d9b32 --- /dev/null +++ b/clean/installer/tests/run_model_l_tests.py @@ -0,0 +1,240 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +"""Model L (#89) by name through the launcher's command line: `model status --preset=L` and `model convert --preset=L` +pick Model L's converter map (data/preset-L.v1.map.json, the spec side's revision v1.1) and its model folder +(%LOCALAPPDATA%\\WrongGPU\\model\\L, the runtime's folder for model=L); a file without Model L's data is refused with +Model L's words; Model M stays as it was, byte for byte. + +Written for this project; Python standard library only. Runs WrongGPU.exe (WRONGGPU_TESTING builds made from the +installer suite's prepared payload and test map) against generated files only: synthetic model files from the +converter's test generator. Only the model verbs run: no install, no window, no GPU; --noscan always. + + python run_model_l_tests.py --write-test-map + the test map for --launcher-synth's build (-DWRONGGPU_MAP_L=): the exact layout of + data/preset-L.v1.map.json with digests of our own random content + python run_model_l_tests.py --launcher [--launcher-synth ] [--reference-launcher ] --work + --launcher: built with the shipped preset-L map (the default WRONGGPU_MAP_L) + --launcher-synth: built with the test map above (the conversion itself) + --reference-launcher: a launcher built from the base branch with the same payload and test map; Model M's file + from both must be the same bytes +""" +import argparse +import hashlib +import json +import os +import shutil +import subprocess +import sys + +os.environ["WRONGGPU_TESTING"] = "1" +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, HERE) +import run_installer_tests as suite # noqa: E402 (cases, read_container, read, write) +from run_installer_tests import read, write # noqa: E402 +from synth import shipped_like_case # noqa: E402 (converter tests: a shipped map's exact layout, our own content) + +L_MAP = os.path.normpath(os.path.join(HERE, "..", "..", "..", "data", "preset-L.v1.map.json")) +L_SEED, L_W_OFFSET = 31, 4096 + 6 +NO_L = "This DLSS file has no preset-L model." +NOT_MODEL = "This is not a DLSS model file." # the converter's reason for a file smaller than Model L's parameter block + + +def l_case(): + """The synthetic Model L source of the test map (the same every time).""" + return shipped_like_case(L_MAP, seed=L_SEED, w_offset=L_W_OFFSET) + + +def map_bytes(case): + return json.dumps(case.map, indent=1).encode("utf-8") + + +def m_case(): + """The installer suite's synthetic Model M source and the map its prepared test map is (run_installer_tests main).""" + return suite.cases.f_mini_case(present=0) + + +class T: + def __init__(self, exe, work): + self.exe, self.work = exe, work + self.passed, self.failures = 0, [] + self.log = os.path.join(work, "launcher-test.log") + self.out = os.path.join(work, "out.json") + self.lad = os.path.join(work, "localappdata") + shutil.rmtree(self.lad, ignore_errors=True) + os.makedirs(self.lad) + self.env = dict(os.environ, LOCALAPPDATA=self.lad, ProgramData=os.path.join(work, "programdata")) + for k in [k for k in self.env if k.upper().startswith("WG_") or k.upper() in ("HIP_PATH", "ROCM_PATH", "LLVM_PATH", "HIP_DEVICE_LIB_PATH")]: + self.env.pop(k) + self.j, self.stdout = {}, "" + + def check(self, name, cond, detail=""): + if cond: + self.passed += 1 + print(" PASS ", name) + else: + self.failures.append(name + (": " + str(detail)[:1500] if detail else "")) + print(" FAIL ", name, str(detail)[:1500]) + + def run(self, *args): + """WrongGPU.exe --noscan --data --log --out; the JSON result in self.j; returns the exit code.""" + for p in (self.out, self.log): + if os.path.exists(p): + os.remove(p) + cmd = [self.exe] + list(args) + ["--noscan", "--log=" + self.log, "--out=" + self.out, "--data=" + os.path.join(self.work, "data")] + p = subprocess.run(cmd, env=self.env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=600) + self.stdout = p.stdout.decode("utf-8", "replace") + try: + with open(self.out, encoding="utf-8") as f: + self.j = json.load(f) + except (OSError, ValueError): + self.j = {} + return p.returncode + + def model(self, *rel): + return os.path.join(self.lad, "WrongGPU", "model", *rel) + + def m_files(self): + """Model M's files (the model folder itself, without the per-model sub-folders) with their bytes.""" + d = self.model() + return {n: read(os.path.join(d, n)) for n in sorted(os.listdir(d)) if os.path.isfile(os.path.join(d, n))} if os.path.isdir(d) else {} + + +def holds(path, case): + """The model file holds the reference tensors of `case`: the key, the stages in map order, each digest, every tensor.""" + try: + key, _, stages = suite.read_container(path) + except Exception: # noqa: BLE001 + return False + want = [st for st in case.map["stages"] if st["stage"] in case.expected] + if key != case.key or [s[0] for s in stages] != [st["stage"] for st in want]: + return False + for (name, digest, tensors), st in zip(stages, want): + # a stage with a digest list (Model M's output filter, map version 4): the variant the file holds + expected = st["digest"] if isinstance(st["digest"], str) else st["digest"][case.found[name]] + if digest.hex() != expected or [t[3] for t in tensors] != [b for _, b in case.expected[name]]: + return False + return True + + +def test_shipped_map(t): + """The launcher built with the shipped preset-L map: Model L by name reads that map (v1.1) and Model L's folder.""" + print("\n[1] the shipped preset-L map (v1.1): chosen by name, a file without Model L refused") + with open(L_MAP, "rb") as f: + shipped = f.read() + m = json.loads(shipped) + t.check("data/preset-L.v1.map.json is revision v1.1: \"preset\": \"L\", map version 1, a 13-entry dec0_values", + m.get("preset") == "L" and m["version"] == 1 and len(m["perms"]["dec0_values"]) == 13, (m.get("preset"), m["version"])) + rc = t.run("model", "status", "--preset=L") + mj = t.j.get("model", {}) + t.check("model status --preset=L: exit 0, model L, its file in model\\L, not valid yet", + rc == 0 and t.j.get("preset") == "L" and mj.get("file", "").lower() == t.model("L", "model.wgcm").lower() and mj.get("valid") is False, (rc, t.j)) + t.check("...the converter map in use is the shipped preset-L map (its SHA-256), loaded without an error", + mj.get("map_sha256") == hashlib.sha256(shipped).hexdigest() and not mj.get("map_error"), mj) + rc = t.run("model", "status", "--preset=l") + t.check("--preset=l (lower case): the same model", rc == 0 and t.j.get("preset") == "L", (rc, t.j)) + rc = t.run("model", "status") + mm = t.j.get("model", {}) + t.check("model status without --preset: Model M, the model folder itself, another map", + rc == 0 and t.j.get("preset") == "M" and mm.get("file", "").lower() == t.model("model.wgcm").lower() and + mm.get("map_sha256") not in ("", hashlib.sha256(shipped).hexdigest()), (rc, t.j)) + # Model M converted first: what a refused Model L conversion must leave as it is + mc = m_case() + msrc = os.path.join(t.work, "m-source", "nvngx_dlss.dll") + write(msrc, mc.file) + rc = t.run("model", "convert", "--model=" + msrc) + t.check("Model M converts from the suite's synthetic file (as before)", rc == 0 and holds(t.model("model.wgcm"), mc), (rc, t.j, t.stdout[-400:])) + before = t.m_files() + rc = t.run("model", "convert", "--preset=L", "--model=" + msrc) + err = t.j.get("error", "") + t.check("model convert --preset=L of Model M's small stand-in: exit 5, refused with Model L's words and the converter's reason for that file", + rc == 5 and err.startswith("Model L can't be prepared: no DLSS model file with Model L's data was found.") and + ("The file you chose (" + msrc + "): " + NOT_MODEL).lower() in err.lower() and "310.5 or newer" in err, (rc, err, t.stdout[-400:])) + t.check("...nothing written for Model L", not os.path.exists(t.model("L")), os.listdir(t.model())) + t.check("...Model M's files unchanged, byte for byte", t.m_files() == before, sorted(t.m_files())) + big = os.path.join(t.work, "random-source", "nvngx_dlss.dll") + write(big, hashlib.sha256(b"model L, random").digest() * (m["sources"]["W"]["length"] // 32 + 4096)) + rc = t.run("model", "convert", "--preset=L", "--model=" + big) + t.check("a random file larger than Model L's parameter block: exit 5, the converter's reason is Model L's (\"no preset-L model\")", + rc == 5 and ("The file you chose (" + big + "): " + NO_L).lower() in t.j.get("error", "").lower(), (rc, t.j.get("error"))) + for bad, why in (("Q", "Unknown model \"Q\""), ("ML", "Unknown model \"ML\""), ("", "Unknown model \"\"")): + rc = t.run("model", "convert", "--preset=" + bad, "--model=" + msrc) + t.check("--preset=%s: a bad command line (exit 10), named, nothing converted" % bad, + rc == 10 and t.j.get("error", "").startswith(why) and t.m_files() == before and not os.path.exists(t.model("L")), (rc, t.j)) + rc = t.run("model", "status", "--preset=K") + t.check("--preset=K in a build without Preset K: exit 10, the models of this build named", rc == 10 and "M or L" in t.j.get("error", ""), (rc, t.j)) + + +def test_conversion(t, ref): + """The launcher built with the test map: Model L converts into model\\L, bit-exact; Model M is untouched.""" + print("\n[2] Model L converted by name (a test map of the shipped layout, our own content)") + lc, mc = l_case(), m_case() + rc = t.run("model", "status", "--preset=L") + t.check("the build's Model L map is the test map of the shipped layout", rc == 0 and t.j.get("model", {}).get("map_sha256") == hashlib.sha256(map_bytes(lc)).hexdigest(), t.j) + msrc = os.path.join(t.work, "m-source", "nvngx_dlss.dll") + write(msrc, mc.file) + lsrc = os.path.join(t.work, "l-source", "nvngx_dlss.dll") + write(lsrc, lc.file) + rc = t.run("model", "convert", "--model=" + msrc) + t.check("Model M first (no --preset): converted, bit-exact", rc == 0 and holds(t.model("model.wgcm"), mc), (rc, t.j)) + m_before = t.m_files() + rc = t.run("model", "convert", "--preset=L", "--model=" + lsrc) + t.check("model convert --preset=L: exit 0, converted from the chosen file", rc == 0 and t.j.get("outcome", "").startswith("converted from " + lsrc), (rc, t.j, t.stdout[-600:])) + t.check("...model\\L\\model.wgcm holds Model L's tensors, bit-exact with the reference (every stage, digest and tensor)", holds(t.model("L", "model.wgcm"), lc)) + src = read(t.model("L", "model-source.txt")).decode("utf-8", "replace") if os.path.isfile(t.model("L", "model-source.txt")) else "" + t.check("...model\\L\\model-source.txt names the file and the map (its SHA-256), no output-filter line (Model L has none)", + ("source\t" + lsrc + "\r\n") in src and ("map\t" + hashlib.sha256(map_bytes(lc)).hexdigest()) in src and "filter\t" not in src, src) + t.check("...Model M's files unchanged, byte for byte", t.m_files() == m_before, sorted(t.m_files())) + rc = t.run("model", "status", "--preset=L") + t.check("model status --preset=L: ready", rc == 0 and t.j.get("model", {}).get("valid") is True, t.j) + l_bytes = read(t.model("L", "model.wgcm")) + rc = t.run("model", "convert", "--preset=L", "--model=" + msrc) + t.check("Model L again (a file without L chosen): the valid file on this PC is reused, unchanged", + rc == 0 and t.j.get("outcome", "").startswith("reused") and read(t.model("L", "model.wgcm")) == l_bytes, (rc, t.j)) + rc = t.run("model", "convert", "--preset=M", "--model=" + msrc) + t.check("--preset=M: Model M's file reused, byte for byte as before", rc == 0 and t.m_files() == m_before and t.j.get("preset") == "M", (rc, t.j)) + shutil.rmtree(t.model("L")) + rc = t.run("model", "convert", "--preset=L", "--model=" + msrc) + t.check("Model L with only Model M's file given: exit 5, refused with Model L's words; Model M untouched", + rc == 5 and t.j.get("error", "").startswith("Model L can't be prepared:") and NOT_MODEL in t.j.get("error", "") and not os.path.exists(t.model("L", "model.wgcm")) and t.m_files() == m_before, (rc, t.j)) + if ref: + r = T(ref, os.path.join(t.work, "reference")) + rc = r.run("model", "convert", "--model=" + msrc) + t.check("the base branch's launcher converts Model M from the same file into the same bytes (model.wgcm)", + rc == 0 and r.m_files().get("model.wgcm") == m_before.get("model.wgcm") and m_before.get("model.wgcm"), (rc, r.j)) + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--write-test-map", help="write the test map (the shipped preset-L layout, our own digests) and stop") + ap.add_argument("--launcher", help="WrongGPU.exe built with the shipped preset-L map") + ap.add_argument("--launcher-synth", help="WrongGPU.exe built with --write-test-map's map (-DWRONGGPU_MAP_L=)") + ap.add_argument("--reference-launcher", help="WrongGPU.exe of the base branch (same payload and test map)") + ap.add_argument("--work", default=os.path.join(HERE, "..", "build-tests", "model-l")) + a = ap.parse_args() + if a.write_test_map: + write(a.write_test_map, map_bytes(l_case())) + print("test map: " + a.write_test_map) + return 0 + if not a.launcher and not a.launcher_synth: + ap.error("--launcher or --launcher-synth is needed") + work = os.path.abspath(a.work) + passed, failures = 0, [] + for exe, part, fn in ((a.launcher, "shipped", test_shipped_map), (a.launcher_synth, "synth", lambda t: test_conversion(t, a.reference_launcher))): + if not exe: + print("\n(%s: no launcher given, skipped)" % part) + continue + d = os.path.join(work, part) + shutil.rmtree(d, ignore_errors=True) + os.makedirs(d) + t = T(os.path.abspath(exe), d) + fn(t) + passed += t.passed + failures += t.failures + print("\n%d checks passed, %d failed" % (passed, len(failures))) + for f in failures: + print(" FAILED: " + f) + return 1 if failures else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/clean/installer/tools/make_payload.py b/clean/installer/tools/make_payload.py index 6694e593..aa9dcb60 100644 --- a/clean/installer/tools/make_payload.py +++ b/clean/installer/tools/make_payload.py @@ -27,6 +27,7 @@ RESERVED = ("amd_fidelityfx_dx12.wronggpu-original.dll", "wronggpu-setup") MAP_ID = 900 MAP_F_ID = 902 # the RR converter map (preset F) +MAP_L_ID = 903 # Model L's converter map (preset L, #89) RR_FIRST_ID = 1601 # the Ray Reconstruction files (--rr) RR_FILES = ("plugins\\wronggpu-rr.asi",) # what an RR folder holds (lower case) # release 0.6.0 (owner 2026-11-02: one runtime DLL): the RR runtime is part of the payload's wronggpu_runtime.dll; an RR folder @@ -192,6 +193,7 @@ def main(): "(plugins\\.\\WrongGPU-RR.asi, with interposer.json); never OptiScaler; omit for an " "installer without them") ap.add_argument("--map-f", help="the RR converter map (preset F); omit for an installer without it") + ap.add_argument("--map-l", help="Model L's converter map (preset L); omit for an installer without Model L") ap.add_argument("--out", required=True) a = ap.parse_args() root = os.path.abspath(a.payload) @@ -209,6 +211,10 @@ def main(): if a.map_f: with open(a.map_f, "rb") as f: map_f_bytes = f.read() + map_l_bytes = None + if a.map_l: + with open(a.map_l, "rb") as f: + map_l_bytes = f.read() os.makedirs(a.out, exist_ok=True) h = ["// Generated by tools/make_payload.py - do not edit.", "#pragma once", @@ -230,7 +236,9 @@ def main(): h += [' {0, L"", L"", 0ull}, // (an array is never empty)', "};", "static const size_t kRrPayloadCount = %d;" % len(rr_rows), 'static const wchar_t kRrInterfaceFile[] = L"%s";' % rr_interface, "static const int kFMapResourceId = %d;" % (MAP_F_ID if map_f_bytes is not None else 0), - 'static const wchar_t kFMapSha256[] = L"%s";' % (hashlib.sha256(map_f_bytes).hexdigest() if map_f_bytes is not None else "")] + 'static const wchar_t kFMapSha256[] = L"%s";' % (hashlib.sha256(map_f_bytes).hexdigest() if map_f_bytes is not None else ""), + "static const int kLMapResourceId = %d;" % (MAP_L_ID if map_l_bytes is not None else 0), + 'static const wchar_t kLMapSha256[] = L"%s";' % (hashlib.sha256(map_l_bytes).hexdigest() if map_l_bytes is not None else "")] h += ["static const int kMapResourceId = %d;" % MAP_ID, "static const int kLogoResourceId = %d;" % (LOGO_ID if os.path.isfile(logo) else 0), 'static const wchar_t kMapSha256[] = L"%s";' % hashlib.sha256(map_bytes).hexdigest(), ""] @@ -259,6 +267,8 @@ def main(): rc.append('901 RCDATA "%s"' % fwd(a.map_k)) if a.map_f: rc.append('%d RCDATA "%s"' % (MAP_F_ID, fwd(a.map_f))) + if a.map_l: + rc.append('%d RCDATA "%s"' % (MAP_L_ID, fwd(a.map_l))) for i, (_, _, _, full) in enumerate(rr_rows): rc.append('%d RCDATA "%s"' % (RR_FIRST_ID + i, fwd(full))) if os.path.isfile(logo): @@ -271,6 +281,7 @@ def main(): f.write("\n".join(rc) + "\n") print("payload: %d files, %.1f MB from %s; map %s" % (len(rows), sum(r[2] for r in rows) / 1048576.0, root, a.map)) print("Ray Reconstruction: %s; RR converter map %s" % ("%d files from %s" % (len(rr_rows), a.rr) if rr_rows else "none", a.map_f or "none")) + print("Model L converter map: %s" % (a.map_l or "none")) if __name__ == "__main__":