Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clean/installer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
# payload folder are not built in (src/setup_route.h).
cmake_minimum_required(VERSION 3.16)
project(wronggpu_installer LANGUAGES CXX RC)
# MinGW's headers set _WIN32_WINNT to Windows 7 as soon as a standard header comes first (context.h includes
# <functional> before base.h), which hides the Windows 8+ declarations the core uses (FILE_ID_INFO in convert_ignore.cpp):
# the whole build gets base.h's Windows 10 instead. MSVC's headers leave it unset.
if(MINGW)
add_compile_definitions(_WIN32_WINNT=0x0A00 WINVER=0x0A00)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
5 changes: 4 additions & 1 deletion clean/installer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ With the defaults nothing of this section changes the installer.
conversion runs in memory during the checks and is written at install time to
`%LOCALAPPDATA%\WrongGPU\model\model.wgcm` with `model-source.txt` (which file, its version, where it was found,
`filter` = whether that file had the weights, and a `not-used` line for each file that converts too but was passed
over). The DLSS file is never copied or modified.
over). The DLSS file is never copied or modified. Under Wine (Linux), where Proton runs each game in a prefix of its
own, the game's settings name this folder and the Ray Reconstruction data file by their `Z:` paths, which relies on
`Z:` mapping the Linux root in the game's prefix (Wine's default). A path that can't be made a `Z:` path is written
as it is, logged, and reported in the install result.
- **A model file that is already on the PC.** A `model.wgcm` whose stage digests match the embedded map is valid. It
is reused without searching when it has the group `filter` and was written with the map this installer carries.
A valid model M file without the group (written before the group existed, or from a DLSS file whose filter was
Expand Down
10 changes: 7 additions & 3 deletions clean/installer/src/app/ui_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,10 +1648,14 @@ static float RrSection(Gfx& gx, float x, float y, float w) {
if (Rec() && on) {
wstring why;
const bool working = BusyHere() && v.busyVerb == L"Preparing Ray Reconstruction\u2026";
const GameRule* gr = GameRuleFor(e.exe);
const wstring bg = working ? L"" : RrBackgroundWords(e.exe); // 0.6.0 polish: prepared again after a driver update
if (gr && gr->rrKernelsInGame) // the game prepares them at its own first start (gamerules.h: its driver cache is its own)
yy += DotRow(gx, x, yy, w, false, L"Prepared by the game at its first start (about a minute after a graphics driver update)", pal.greyDot, pal.text);
// the game prepares them at its own first start (gamerules.h: its driver cache is its own; under Wine every game,
// rrprep.h): no Prepare button, which would do nothing there
if (RrKernelsInGame(e.exe))
yy += DotRow(gx, x, yy, w, false,
UnderWine() ? L"Prepared by the game at its first start (under Proton its shader caches are its own)"
: L"Prepared by the game at its first start (about a minute after a graphics driver update)",
pal.greyDot, pal.text);
else if (!bg.empty())
yy += NeedRow(gx, x, yy, w, false, bg, L"Not ready until it is done. Prepare does it now instead.",
pal.greyDot, pal.text, ID_G_RRPREP, L"Prepare", B_PLAIN, !Locked(), L"Prepare Ray Reconstruction", false);
Expand Down
56 changes: 56 additions & 0 deletions clean/installer/src/wg_core/checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,57 @@ WinInfo WindowsInfo() {
}

bool IsRdna4Name(const wstring& name) { return Contains(name, L"RX 90") || Contains(name, L"PRO R97") || Contains(name, L"PRO R96"); }
// Under Wine, Wine's own DXGI can name an RDNA 4 card after an old Radeon ("ATI Radeon HD 5600 Series"); the PCI ids of
// Linux's DRM devices (/sys/class/drm/cardN/device, reached through Z:) are the card's own. The RDNA 4 ids are the RR
// runtime's list (clean/rr_f/runtime/src/rr_runtime.cpp rdna4_device_id).
// sysfs reports 4096 bytes for files that hold a few (ReadAll's size check fails on them): read to the end of the file.
static bool ReadSysfs(const wstring& path, string& out) {
HANDLE h = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (h == INVALID_HANDLE_VALUE) return false;
char b[64];
DWORD got = 0;
out.clear();
while (out.size() < 256 && ReadFile(h, b, sizeof b, &got, nullptr) && got) out.append(b, got);
CloseHandle(h);
return !out.empty();
}
// Every DRM card the folder lists (card0, card1, ...; not the connectors such as card1-DP-1), in number order.
static std::vector<std::pair<unsigned long, wstring>> DrmCards(const wstring& drmRoot) {
std::vector<std::pair<unsigned long, wstring>> cards;
WIN32_FIND_DATAW fd;
HANDLE f = FindFirstFileW((drmRoot + L"\\card*").c_str(), &fd);
if (f == INVALID_HANDLE_VALUE) return cards;
do {
const wstring n = fd.cFileName;
if (n.size() <= 4 || n.size() > 12 || n.find_first_not_of(L"0123456789", 4) != wstring::npos) continue;
cards.push_back({std::wcstoul(n.c_str() + 4, nullptr, 10), Join(drmRoot, n)});
} while (FindNextFileW(f, &fd));
FindClose(f);
std::sort(cards.begin(), cards.end());
return cards;
}
static bool HexId(const string& text, unsigned long& id) {
const char* s = text.c_str();
char* end = nullptr;
id = strtoul(s, &end, 16);
while (end && (*end == '\n' || *end == '\r' || *end == ' ')) ++end;
return end && end != s && *end == '\0';
}
wstring LinuxRdna4Name(const wstring& drmRoot) {
for (const auto& card : DrmCards(drmRoot)) {
string vendor, device;
unsigned long v = 0, d = 0;
if (!ReadSysfs(Join(card.second, L"device\\vendor"), vendor) || !ReadSysfs(Join(card.second, L"device\\device"), device) ||
!HexId(vendor, v) || !HexId(device, d))
continue;
if (v == 0x1002 && (d == 0x7550 || d == 0x7551 || d == 0x7590 || d == 0x7591)) {
wchar_t b[160];
swprintf(b, 160, L"AMD Radeon RDNA 4 (PCI 1002:%04lX, found in Linux's device list; not confirmed as the adapter the game uses)", d);
return b;
}
}
return L"";
}
GpuInfo DetectGpu() {
GpuInfo best;
HMODULE dxgi = LoadSystemDll(L"dxgi.dll");
Expand Down Expand Up @@ -56,6 +107,11 @@ GpuInfo DetectGpu() {
if (!best.amd || (rdna4 && !best.rdna4)) { best.amd = true; best.rdna4 = rdna4; best.name = name; best.driver = driver; }
}
f->Release();
if (!best.rdna4 && UnderWine()) {
const wstring linuxName = LinuxRdna4Name();
// the driver version of the DXGI adapter is not this card's: left unknown rather than carried over
if (!linuxName.empty()) { best.amd = true; best.rdna4 = true; best.name = linuxName; best.driver.clear(); }
}
return best;
}

Expand Down
4 changes: 4 additions & 0 deletions clean/installer/src/wg_core/checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ struct SystemInfo { WinInfo win; GpuInfo gpu; HipInfo hip; };

WinInfo WindowsInfo();
bool IsRdna4Name(const wstring& name);
// Under Wine: the name DetectGpu gives an RDNA 4 card from Linux's PCI ids when Wine's DXGI names it otherwise; empty
// when Linux reports no RDNA 4 card (or outside Wine, where Z:\sys does not exist). drmRoot: the folder holding card0,
// card1, ... (Linux's /sys/class/drm; tests point it at a made-up folder). Every card is looked at, in number order.
wstring LinuxRdna4Name(const wstring& drmRoot = L"Z:\\sys\\class\\drm");
GpuInfo DetectGpu();
bool VersionLess(const wstring& a, const wstring& b);
std::vector<wstring> HipCandidates();
Expand Down
9 changes: 7 additions & 2 deletions clean/installer/src/wg_core/coexist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,15 @@ CoexistReport AssessCoexistence(Context& ctx, const wstring& exe, const wstring&
}
}

// DXVK / vkd3d-proton: native D3D12 is required
// DXVK / vkd3d-proton: native D3D12 is required on Windows. Under Wine (Proton on Linux) vkd3d-proton is the D3D12 a
// game runs on, and a copy of it next to the game (a newer build than the Proton's own) is how a player gets one.
for (Tool t : {Tool::Dxvk, Tool::Vkd3d}) {
const auto f = filesOf(t);
if (!f.empty())
if (!f.empty() && t == Tool::Vkd3d && UnderWine())
add(t, Decision::Inform, wstring(ToolName(t)) + L" as " + f[0], f, fpOf(t)->evidence,
L"Under Wine (Proton) vkd3d-proton is the game's Direct3D 12. Left alone; Model M needs a vkd3d-proton whose "
L"dxil-spirv has pull request #362 (AMD's matrix instructions as WrongGPU uses them).");
else if (!f.empty())
add(t, Decision::Refuse, wstring(ToolName(t)) + L" as " + f[0], f, fpOf(t)->evidence,
L"WrongGPU needs Windows' own Direct3D 12; " + wstring(ToolName(t)) + L" translates the game's graphics to Vulkan. Not installed.", EXIT_REFUSED);
}
Expand Down
23 changes: 22 additions & 1 deletion clean/installer/src/wg_core/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ wstring GameAmdFfxDll(Context& ctx, const wstring& dir, const wstring& exeDir) {
// ------------------------------------------------------------------------------------------------
// Install engine
// ------------------------------------------------------------------------------------------------
// Under Wine: a model path for the game's own Proton prefix (PathForGamePrefix). When it can't be made a Z: path (Wine's
// wine_get_unix_file_name missing, or no part of the path resolvable), the launcher-prefix path is written as it is and
// the game will most likely not find the model: logged, and a line in the install result.
static wstring ModelPathForGame(Context& ctx, Ui& ui, std::vector<wstring>& warnings, const wstring& path) {
const wstring z = PathForGamePrefix(path);
if (UnderWine() && !path.empty() && !StartsWithI(z, L"Z:\\")) {
const wstring w = L"The model path could not be made reachable from the game's own Proton prefix, so the game may "
L"not find the model: " + z + L" (a Z: path is needed; Z: maps the Linux root in every prefix).";
LogLine(ctx, w);
ui.log(w);
warnings.push_back(w);
}
return z;
}

std::vector<wstring> DoInstall(Context& ctx, const GameTarget& target, const ModelState& model, const Consent& consent, Ui& ui, const HipInfo& hip) {
std::vector<wstring> warnings;
const wstring dir = target.dir;
Expand Down Expand Up @@ -336,6 +351,12 @@ std::vector<wstring> DoInstall(Context& ctx, const GameTarget& target, const Mod
selectedOptions = OnlyModelM(selectedOptions);
#endif
selectedIni = IniSet(selectedIni, "fsr", "runtime_options", selectedOptions);
// Under Wine the game runs in a prefix of its own (Proton), where this launcher's %LOCALAPPDATA% does not exist: the
// model folder is named by its Z: path, which that prefix reaches too. A model_dir the player set stays.
string playerModelDir, playerModelDirSection;
IniGetFrontEnd(selectedIni, "model_dir", &playerModelDir, &playerModelDirSection);
if (UnderWine() && playerModelDir.empty())
selectedIni = IniSet(selectedIni, "fsr", "model_dir", ToUtf8(ModelPathForGame(ctx, ui, warnings, ModelBaseDir())));
const wstring selectedIniSrc = Join(OptiTempDir(ctx), L"WrongGPU.selected.ini");
WriteFileAtomic(selectedIniSrc, selectedIni.data(), selectedIni.size());
optiFiles.push_back({L"wronggpu.ini", selectedIniSrc});
Expand Down Expand Up @@ -485,7 +506,7 @@ std::vector<wstring> DoInstall(Context& ctx, const GameTarget& target, const Mod
WriteFileAtomic(src, d, sz);
optiFiles.push_back({IsRrPayloadPlugin(f.rel) ? Join(Parent(pluginRel), kRrPluginName) : wstring(f.rel), src});
}
const string rini = RrIniText(RrDataFile());
const string rini = RrIniText(ModelPathForGame(ctx, ui, warnings, RrDataFile())); // Z: under Wine, as model_dir above
const wstring rsrc = Join(tmp, kRrIni);
WriteFileAtomic(rsrc, rini.data(), rini.size());
optiFiles.push_back({kRrIni, rsrc});
Expand Down
13 changes: 12 additions & 1 deletion clean/installer/src/wg_core/rrprep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ wstring RrRuntimeSha(Context& ctx) {
int RrPassesFor(const string& mode) { return mode.empty() || mode == "accurate" ? 1 : 2; }

bool RrKernelsInGame(const wstring& exe) {
// Under Wine (Proton) a game's compiled kernels are kept by vkd3d-proton in the game folder (vkd3d-proton.cache, its
// working folder) and by Mesa in Steam's folder for the game, both under the game's own Proton: a helper in the
// launcher's prefix fills neither (measured 2026-11-13, Cyberpunk 2077 under GE-Proton 11-11).
if (UnderWine()) return true;
const GameRule* r = GameRuleFor(exe);
return r && r->rrKernelsInGame;
}
Expand All @@ -140,7 +144,8 @@ const wchar_t* RrPrepStateName(RrPrepState s) {

RrPrepState RrPrepStateOf(Context& ctx, const wstring& dataDir, const wstring& exe, int passes, wstring* why) {
if (RrKernelsInGame(exe)) {
if (why) *why = L"the game prepares them at its first start (its graphics driver cache is its own)";
if (why) *why = UnderWine() ? L"the game prepares them at its first start (under Proton its shader caches are its own)"
: L"the game prepares them at its first start (its graphics driver cache is its own)";
return RrPrepState::InGame;
}
const wstring name = BaseName(exe), driver = RrDriverVersion(), sha = RrRuntimeSha(ctx);
Expand All @@ -162,6 +167,12 @@ bool RrPrepared(Context& ctx, const wstring& dataDir, const wstring& exe, int pa
int PrepareRr(Context& ctx, const wstring& dataDir, const wstring& exe, const wstring& runtimeDll, int passes,
const std::function<bool(const RrPrepProgress&)>& progress, wstring* why) {
if (RrKernelsInGame(exe)) {
if (UnderWine()) {
if (why) *why = L"the game prepares them at its first start (under Proton its shader caches are its own)";
LogLine(ctx, L"Ray Reconstruction: " + BaseName(exe) + L" prepares its kernels at its first start (under Proton the game's shader caches are vkd3d-proton's "
L"file in the game folder and Steam's folder for the game, which the launcher's helper can't fill); nothing prepared ahead");
return 4;
}
if (why) *why = L"the game prepares them at its first start (its graphics driver cache is its own)";
LogLine(ctx, L"Ray Reconstruction: " + BaseName(exe) + L" prepares its kernels at its first start (the graphics driver keeps the game's shader cache under the game's own "
L"application name, which the launcher's helper can't reach); nothing prepared ahead");
Expand Down
3 changes: 2 additions & 1 deletion clean/installer/src/wg_core/rrprep.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ RrPrepState RrPrepStateOf(Context& ctx, const wstring& dataDir, const wstring& e
const wchar_t* RrPrepStateName(RrPrepState s); // "ready", "not-prepared", "driver-changed", ... (JSON, logs)
// What the launcher's start prepares again in the background: prepared before, and the driver or the runtime changed.
inline bool RrStaleAfterUpdate(RrPrepState s) { return s == RrPrepState::DriverChanged || s == RrPrepState::RuntimeChanged; }
// gamerules.h: the game prepares RR's kernels at its own first start (the launcher's helper can't reach its cache)
// gamerules.h, or any game under Wine (Proton): the game prepares RR's kernels at its own first start (the launcher's helper
// can't reach its cache)
bool RrKernelsInGame(const wstring& exe);
// The helper run: the launcher's own program copied as rr-prepare\run\<game exe name>, started with --rr-prepare
// <runtime dll> <passes>, its progress read line by line (progress answers false: cancel). 0 prepared (recorded), 1
Expand Down
23 changes: 23 additions & 0 deletions clean/installer/src/wg_core/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,29 @@ wstring EnvVar(const wchar_t* name) {
}
// System DLLs this exe uses only sometimes are loaded from System32 only, never from the download folder.
HMODULE LoadSystemDll(const wchar_t* name) { return LoadLibraryExW(name, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); }
bool UnderWine() { return GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "wine_get_version") != nullptr; }
wstring PathForGamePrefix(const wstring& path) {
if (path.empty() || !UnderWine()) return path;
// Wine's kernel32: the Unix name of a DOS path, allocated on the process heap (UTF-8). It fails when more than the last
// part is missing (the RR data's F\ folder before its first conversion), so the deepest folder that exists is converted
// and the missing rest appended.
using UnixNameFn = char*(CDECL*)(const wchar_t*);
auto unixName = reinterpret_cast<UnixNameFn>(reinterpret_cast<void*>(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "wine_get_unix_file_name")));
if (!unixName) return path;
wstring head = path, tail;
char* u = nullptr;
while (!(u = unixName(head.c_str()))) {
const size_t cut = head.find_last_of(L"\\/");
if (cut == wstring::npos || cut < 3) return path;
tail = head.substr(cut) + tail;
head.resize(cut);
}
wstring z = L"Z:" + FromUtf8(u) + tail;
HeapFree(GetProcessHeap(), 0, u);
for (wchar_t& c : z)
if (c == L'/') c = L'\\';
return z;
}
wstring SelfPath() { wchar_t b[MAX_PATH * 2]; DWORD n = GetModuleFileNameW(nullptr, b, (DWORD)std::size(b)); return wstring(b, n); }

} // namespace wg
5 changes: 5 additions & 0 deletions clean/installer/src/wg_core/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@ wstring Sha256File(const wstring& path);
wstring NowStamp(bool forFileName);
wstring EnvVar(const wchar_t* name);
HMODULE LoadSystemDll(const wchar_t* name);
// The launcher under Wine (Linux): Wine's ntdll exports wine_get_version.
bool UnderWine();
// A path for a game in another Wine prefix (Proton gives every game its own): under Wine the Z: path of the same file
// (Z: maps the Linux root in every prefix, C: does not), otherwise the path unchanged.
wstring PathForGamePrefix(const wstring& path);
wstring SelfPath();
} // namespace wg
15 changes: 15 additions & 0 deletions clean/installer/tests/coexist_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,21 @@ int main() {
for (auto& w : all.warnings) { xessWarn |= w.kind == L"xess-no-depth"; plug |= w.kind == L"plugin-not-hooked"; }
require(all.found && xessWarn && plug && all.plugin == L"not-hooked", "ReadLastRun: XeSS without depth (OptiScaler.log), the plugin's log in its own folder");

// ---- vkd3d-proton next to the game: refused on Windows, a note under Wine (where it is the game's D3D12) ----------
{
const wstring vg = Join(dir, L"vkd3d game");
Put(Join(vg, L"Game.exe"), "synthetic game exe");
Put(Join(vg, L"d3d12.dll"), "MZ synthetic vkd3d-proton d3d12");
Context vctx;
const CoexistReport vr = AssessCoexistence(vctx, Join(vg, L"Game.exe"), L"", nullptr);
const Finding* vf = nullptr;
for (auto& f : vr.findings) if (f.tool == Tool::Vkd3d) vf = &f;
if (UnderWine())
require(vf && vf->decision == Decision::Inform && !vr.refusal(), "vkd3d-proton next to the game under Wine: a note, not refused");
else
require(vf && vf->decision == Decision::Refuse && vr.refusal() == vf, "vkd3d-proton next to the game on Windows: refused");
}

RemoveTree(dir);
std::printf("coexist-core: %d checks passed\n", checks);
return 0;
Expand Down
Loading
Loading