From 8d516207f3f5a9291ea0861a69d6a8ef427133f4 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 20:38:01 -0500 Subject: [PATCH 01/20] R1: non-RDNA-4 adapters use the front end's upscaler; GPU identity from the driver Executor choice (executor_select.h, backend.cpp): "auto" on an adapter that is not an RDNA 4 Radeon RX 9000-series card, or one that cannot be identified, no longer tries the HIP executor (its kernels are RX 9000-only and the attempt only failed at kernel load): the context is not created, one warning line says "WrongGPU's models need an RX 9000-series GPU; using AMD FSR (adapter ...)", and the front end's own upscaler takes the game. The same for every model. RDNA 4 auto is unchanged (models M, L, K on the D3D12 executor); explicit executor=hip stays a loud diagnostic; the sparkle guard (M, L) and the frame capture choose HIP with a warning line. GPU identity (rdna4.h, new rdna4_win.h, device_d3d12.cpp): the adapter is identified from the system's own dxgi.dll (loaded by its full path, not the proxy a game folder may hold under that name) and from the kernel-mode driver's vendor and device id, never from the description OptiScaler's GPU spoofing can rewrite. A real RX 9000 keeps WrongGPU under any displayed name; another board does not become one. The native D3D12 device uses the same rule, so a spoofed name no longer makes it refuse a real RX 9000. Launcher: the toolbar's GPU line and the first-run check say the same sentence on other cards (GpuRuntimeLine, NeedsRx9000Sentence in wg_core, with tests); the old "HIP" and "Not supported" words are gone. Tests: test_executor_select.cpp (non-RDNA-4, unidentified, spoofed name on a real RX 9000 id, real non-RDNA-4 id, RDNA 4 auto unchanged, warning levels), wg_core_tests.cpp (the launcher line). Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/src/app/launcher_ui.cpp | 2 +- clean/installer/src/app/ui_checks.cpp | 2 +- clean/installer/src/wg_core/checks.cpp | 2 + clean/installer/src/wg_core/checks.h | 6 + clean/installer/tests/wg_core_tests.cpp | 16 ++ clean/runtime/device_d3d12.cpp | 13 +- clean/runtime/interop/backend.cpp | 52 +++---- clean/runtime/interop/executor_select.h | 64 ++++++-- .../interop/tests/test_executor_select.cpp | 143 ++++++++++++++++-- clean/runtime/model_select.h | 2 + clean/runtime/rdna4.h | 27 ++++ clean/runtime/rdna4_win.h | 137 +++++++++++++++++ 12 files changed, 405 insertions(+), 61 deletions(-) create mode 100644 clean/runtime/rdna4_win.h diff --git a/clean/installer/src/app/launcher_ui.cpp b/clean/installer/src/app/launcher_ui.cpp index ff05b4e5..d1080cc9 100644 --- a/clean/installer/src/app/launcher_ui.cpp +++ b/clean/installer/src/app/launcher_ui.cpp @@ -1098,7 +1098,7 @@ void SetGpu(const GpuInfo& gpu) { wstring n = gpu.name; for (const wchar_t* p : {L"AMD Radeon ", L"AMD "}) if (n.rfind(p, 0) == 0) { n = n.substr(wcslen(p)); break; } v.gpuName = n; - v.executorLine = n.empty() ? L"No graphics card found" : n + (gpu.rdna4 ? L" \u00b7 Direct3D 12" : gpu.amd ? L" \u00b7 HIP" : L" \u00b7 Not supported"); + v.executorLine = n.empty() ? L"No graphics card found" : n + GpuRuntimeLine(gpu); } void SetHealth(bool model, const GpuInfo& gpu) { v.modelReady = model; SetGpu(gpu); } // The model data's state for the toolbar and Settings (any thread): ready or why not, the DLSS file it came from, the HIP diff --git a/clean/installer/src/app/ui_checks.cpp b/clean/installer/src/app/ui_checks.cpp index 11d36322..08ac6674 100644 --- a/clean/installer/src/app/ui_checks.cpp +++ b/clean/installer/src/app/ui_checks.cpp @@ -42,7 +42,7 @@ void FirstRunChecks(HWND hwnd, const GlobalSettings& gs, const wstring& dll, boo // the RX 9070 XT's time there (an estimate), and its 8 GB cards are untested const bool rx9060 = gpu.rdna4 && gpu.name.find(L"9060") != wstring::npos; m->lines.push_back({gpu.rdna4 ? 0 : 2, L"Graphics card: " + (gpu.name.empty() ? wstring(L"Not found") : gpu.name) + - (!gpu.rdna4 ? L". WrongGPU needs a Radeon\u00a0RX\u00a09000-series card." + (!gpu.rdna4 ? L". WrongGPU's models need an RX\u00a09000-series GPU; games use AMD FSR." : rx9060 ? L". Supported, not yet tested on this card. Ray Reconstruction takes about twice as long as on an RX\u00a09070\u00a0XT." : L"")}); // short words behind the sheet's Show details (how Model M runs is the game page's Runs on); without the card, only diff --git a/clean/installer/src/wg_core/checks.cpp b/clean/installer/src/wg_core/checks.cpp index bdcf8ceb..b4a2a9f3 100644 --- a/clean/installer/src/wg_core/checks.cpp +++ b/clean/installer/src/wg_core/checks.cpp @@ -27,6 +27,8 @@ WinInfo WindowsInfo() { return w; } +wstring NeedsRx9000Sentence() { return L"WrongGPU's models need an RX 9000-series GPU; using AMD FSR"; } +wstring GpuRuntimeLine(const GpuInfo& gpu) { return gpu.rdna4 ? wstring(L" \u00b7 Direct3D 12") : L" \u00b7 " + NeedsRx9000Sentence(); } 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 diff --git a/clean/installer/src/wg_core/checks.h b/clean/installer/src/wg_core/checks.h index 82a377cf..e7070e8e 100644 --- a/clean/installer/src/wg_core/checks.h +++ b/clean/installer/src/wg_core/checks.h @@ -28,6 +28,12 @@ struct SystemInfo { WinInfo win; GpuInfo gpu; HipInfo hip; }; WinInfo WindowsInfo(); bool IsRdna4Name(const wstring& name); +// The sentence the runtime logs when it hands a game to AMD FSR on a GPU that is not an RX 9000-series card, or on one it +// cannot identify (clean/runtime/interop/executor_select.h needs_rx9000_line); the launcher says the same. +wstring NeedsRx9000Sentence(); +// The toolbar's words after the GPU's name: how WrongGPU runs on it. Direct3D 12 on an RDNA 4 card; on any other card (or +// none) the sentence above. The old "HIP" and "Not supported" words are gone: no model runs on HIP in a game. +wstring GpuRuntimeLine(const GpuInfo& gpu); // 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. diff --git a/clean/installer/tests/wg_core_tests.cpp b/clean/installer/tests/wg_core_tests.cpp index d0663270..bf0acffa 100644 --- a/clean/installer/tests/wg_core_tests.cpp +++ b/clean/installer/tests/wg_core_tests.cpp @@ -205,6 +205,22 @@ int main() { "ShortenMiddle keeps the drive and the marker"); } + // R1: the launcher's GPU line is the runtime's sentence on every card that is not RDNA 4 (clean/runtime/interop/tests/ + // test_executor_select.cpp checks the runtime's side of the same sentence) + { + require(NeedsRx9000Sentence() == L"WrongGPU's models need an RX 9000-series GPU; using AMD FSR", "NeedsRx9000Sentence: the runtime's sentence"); + GpuInfo rdna4; + rdna4.amd = rdna4.rdna4 = true; + require(GpuRuntimeLine(rdna4) == L" \u00b7 Direct3D 12", "GpuRuntimeLine: RDNA 4 runs on Direct3D 12"); + GpuInfo rdna3; + rdna3.amd = true; + require(GpuRuntimeLine(rdna3).find(NeedsRx9000Sentence()) != wstring::npos && !Contains(GpuRuntimeLine(rdna3), L"HIP"), + "GpuRuntimeLine: another AMD card gets the sentence, no HIP"); + GpuInfo other; + require(GpuRuntimeLine(other).find(NeedsRx9000Sentence()) != wstring::npos && !Contains(GpuRuntimeLine(other), L"Not supported"), + "GpuRuntimeLine: another vendor, or no card, gets the sentence"); + } + // Linux's device list from a made-up folder (any host): every card in number order, connectors skipped, junk and // missing files ignored, the reported name says the card was not confirmed as the game's adapter { diff --git a/clean/runtime/device_d3d12.cpp b/clean/runtime/device_d3d12.cpp index 9d738819..42cd6a7a 100644 --- a/clean/runtime/device_d3d12.cpp +++ b/clean/runtime/device_d3d12.cpp @@ -19,6 +19,7 @@ #include "native_direct_pi.h" #include "embedded.h" #include "rdna4.h" +#include "rdna4_win.h" #include "wmma_probe.h" #include @@ -1347,7 +1348,7 @@ class NativeD3D12Device final : public Device, public NativeD3D12Ext { supplied_queue->AddRef(); queue_.p = supplied_queue; adapter_luid_ = device_->GetAdapterLuid(); - dxgi_dll_ = LoadLibraryExW(L"dxgi.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + dxgi_dll_ = wgrt::load_system_dll(L"dxgi.dll"); // the system's own (not a proxy of the game folder, rdna4_win.h) d3d12_dll_ = LoadLibraryExW(L"d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); if (!dxgi_dll_ || !d3d12_dll_) return fail("native D3D12: system DXGI/D3D12 unavailable"); using MakeFactory = HRESULT(WINAPI*)(REFIID, void**); @@ -1364,7 +1365,11 @@ class NativeD3D12Device final : public Device, public NativeD3D12Ext { char name[256] = {}; WideCharToMultiByte(CP_UTF8, 0, details.Description, -1, name, sizeof name - 1, nullptr, nullptr); adapter_name_ = name; - if (!rdna4_adapter(details.VendorId, (details.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0, adapter_name_)) + // the adapter's identity from the system's DXGI and the kernel-mode driver, never from a description a layer in the + // game process rewrote (rdna4_win.h): a real RX 9000 keeps WrongGPU whatever name it is shown under + const wgrt::AdapterIdentity identity = wgrt::read_adapter_identity(adapter_luid_); + if (identity.dxgi_known) adapter_name_ = identity.description; + if (!wgrt::rdna4_identity(identity)) return fail("native D3D12 borrowed device requires the supported Radeon RX 9070/9060 adapter"); D3D12_FEATURE_DATA_SHADER_MODEL sm{D3D_SHADER_MODEL_6_6}; if (!check(device_->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &sm, sizeof sm), "CheckFeatureSupport(shader model)") || @@ -1408,7 +1413,7 @@ class NativeD3D12Device final : public Device, public NativeD3D12Ext { return ok; } bool create_device() { - dxgi_dll_ = LoadLibraryExW(L"dxgi.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + dxgi_dll_ = wgrt::load_system_dll(L"dxgi.dll"); // the system's own (not a proxy of the game folder, rdna4_win.h) d3d12_dll_ = LoadLibraryExW(L"d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); if (!dxgi_dll_ || !d3d12_dll_) return fail("native D3D12: system DXGI/D3D12 unavailable"); using MakeFactory = HRESULT(WINAPI*)(REFIID, void**); @@ -1437,7 +1442,7 @@ class NativeD3D12Device final : public Device, public NativeD3D12Ext { char name[256] = {}; WideCharToMultiByte(CP_UTF8, 0, description.Description, -1, name, sizeof name - 1, nullptr, nullptr); // The driver-channel WMMA ports are qualified only for the project's RDNA4 target. Do not select an AMD iGPU. - if (rdna4_adapter(description.VendorId, (description.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0, name)) { + if (wgrt::rdna4_identity(wgrt::read_adapter_identity(description.AdapterLuid))) { selected = std::move(adapter); adapter_name_ = name; adapter_luid_ = description.AdapterLuid; break; } } diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 31486b09..ff4b715a 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -40,6 +40,8 @@ #include +#include "../rdna4_win.h" + struct WgUpscaler; namespace wgi { @@ -119,31 +121,19 @@ std::string local_appdata() { return n > 0 && n < 32768 ? utf8(buf) : std::string(); } -// The device's adapter as DXGI reports it (description, vendor, software flag); false when it cannot be read. -bool adapter_info(ID3D12Device* device, std::string* name, uint32_t* vendor_id = nullptr, bool* software = nullptr) { - typedef HRESULT(WINAPI * PfnCreateFactory)(REFIID, void**); - HMODULE dxgi = LoadLibraryW(L"dxgi.dll"); - auto create = - dxgi ? reinterpret_cast(reinterpret_cast(GetProcAddress(dxgi, "CreateDXGIFactory1"))) - : nullptr; - bool ok = false; +// The device's adapter as the SYSTEM's DXGI and the kernel-mode driver report it (rdna4_win.h): never the description the +// game's own dxgi.dll presents, which OptiScaler's GPU spoofing can rewrite. False when neither source could read it. +bool adapter_info(ID3D12Device* device, std::string* name, uint32_t* vendor_id = nullptr, bool* software = nullptr, + wgrt::AdapterIdentity* identity = nullptr) { name->clear(); - IDXGIFactory4* f = nullptr; - if (create && SUCCEEDED(create(__uuidof(IDXGIFactory4), (void**)&f)) && f) { - IDXGIAdapter1* a = nullptr; - if (SUCCEEDED(f->EnumAdapterByLuid(device->GetAdapterLuid(), __uuidof(IDXGIAdapter1), (void**)&a)) && a) { - DXGI_ADAPTER_DESC1 d = {}; - if (SUCCEEDED(a->GetDesc1(&d))) { - ok = true; - *name = utf8(d.Description); - if (vendor_id) *vendor_id = d.VendorId; - if (software) *software = (d.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0; - } - a->Release(); - } - f->Release(); + const wgrt::AdapterIdentity id = wgrt::read_adapter_identity(device->GetAdapterLuid()); + if (identity) *identity = id; + if (id.dxgi_known) { + *name = id.description; + if (vendor_id) *vendor_id = id.dxgi_vendor; + if (software) *software = id.software; } - return ok; + return id.dxgi_known || id.kmt_known; } std::string adapter_description(ID3D12Device* device) { @@ -157,7 +147,7 @@ std::string adapter_description(ID3D12Device* device) { struct Options { std::string sync = "inline"; // inline | pipelined std::string hip_switch; // on | off (executor_select.h refused_frame_policy); empty: the default - std::string executor = "auto"; // auto (not named: dx12 for model M on RDNA 4, else hip; executor_select.h) | hip | + std::string executor = "auto"; // auto (not named: dx12 for every model on RDNA 4, else no executor: the front end's upscaler; executor_select.h) | hip | // dx12 (the network on the game's D3D12 device, no HIP) | d3d12-test (tests) std::string model_dir; // default %LOCALAPPDATA%\WrongGPU\model (installer contract, spec 30) std::string kernels_dir; // default: the folder of this DLL @@ -600,7 +590,7 @@ class Context { say(WG_LOG_WARN, "WG_RUNTIME_OPTIONS is longer than 4095 characters and is ignored"); } Options o = parse_options(text.c_str()); - { // the executor (executor_select.h): the option, else the default (dx12 for model M on RDNA 4); one log line why + { // the executor (executor_select.h): the option, else the default (dx12 for models M, L, K on RDNA 4, the front end's upscaler on any other adapter); one log line why ExecutorRequest q; q.executor = o.executor; WgRtConfig probe = WgRtConfig(); @@ -609,12 +599,22 @@ class Context { std::string merr; // model K only (Model L runs on the D3D12 executor in builds with it: runtime.cpp, native D3D12 backend 3) q.model_k = wgrt::model_from_options(probe, &model, &merr) && model == wgrt::ModelId::K; - q.adapter_known = adapter_info(device_, &q.adapter, &q.vendor_id, &q.software); + { + wgrt::AdapterIdentity ident; + adapter_info(device_, &q.adapter, &q.vendor_id, &q.software, &ident); + q.adapter_known = ident.dxgi_known; + q.kmt_known = ident.kmt_known; + q.kmt_vendor = ident.kmt_vendor; + q.kmt_device = ident.kmt_device; + } q.sparkle_guard = o.sparkle_guard > 0.0f; q.capture = !o.capture_dir.empty(); const ExecutorChoice ch = choose_executor(q); if (ch.executor.empty()) return fail(WG_ERROR_PARAMETER, "unknown executor " + o.executor); if (!ch.why.empty()) say(ch.warn ? WG_LOG_WARN : WG_LOG_INFO, ch.why); + // an adapter that is not an RDNA 4 Radeon RX 9000-series card (or not identified): no executor, no kernel load, + // no HIP attempt; the one line above is the whole report and the front end's own upscaler takes the game + if (ch.executor == "fsr") return WG_ERROR_UNSUPPORTED; o.executor = ch.executor; // model K's default mode below applies with the HIP executor if (ch.sparkle_off) o.sparkle_guard = 0.0f; // model K: the guard is HIP only; K stays on D3D12 dx12_default_ = ch.by_default && ch.executor == "dx12"; diff --git a/clean/runtime/interop/executor_select.h b/clean/runtime/interop/executor_select.h index 5dc379bd..34524b50 100644 --- a/clean/runtime/interop/executor_select.h +++ b/clean/runtime/interop/executor_select.h @@ -3,9 +3,12 @@ // tests/test_executor_select.cpp checks it on any host. WrongGPU's own code. // // Option `executor` (wronggpu.ini runtime_options, an [fsr] line, WG_RUNTIME_OPTIONS): -// - not named (or `auto`): Model M and model K on an RDNA 4 adapter (../rdna4.h) run on the D3D12 executor -// (executor_d3d12.cpp), everything else on the HIP executor, with one log line saying why (other GPU, the sparkle -// guard or the frame capture, which run on HIP only). The D3D12 executor can still refuse the context at create +// - not named (or `auto`): every model (M, L, K) on an RDNA 4 adapter (../rdna4.h) runs on the D3D12 executor +// (executor_d3d12.cpp). On an adapter that is not an RDNA 4 Radeon RX 9000-series card, or one that cannot be +// identified, the context is not created: the front end's own upscaler (AMD FSR, else its stand-in) takes the +// game, with one warning line (R1, oversight 2026-11-15: the networks' kernels are RX 9000-only, a HIP attempt +// only fails at kernel load). The sparkle guard (M, L) and the frame capture, which run on HIP only, select the HIP +// executor with a warning line. The D3D12 executor can still refuse the context at create // (its driver-channel probe, the network's create, a context its kernels do not take): then the HIP executor runs // it, again with one line (backend.cpp; model K: no HIP route, the context is not created and the game keeps its own // upscaler, dx12_refused_line_k). Model K is taken only when every kernel the context can launch has a @@ -23,12 +26,13 @@ // - Model K (REVIEW-215b, oversight 2026-11-14): never moved to HIP by the sparkle guard (HIP-only: it is turned off // for K, one line, K runs on D3D12), never by hip_switch (ignored for K, one line if set), never by a refused frame // (the frame goes to the front end's own upscaler, AMD FSR, else its stand-in, the same path as model M's refused -// frames; a create-level refusal ends the context with one line and the game keeps its own upscaler). The frame capture and executor=hip stay opt-in diagnostics with a loud -// line. Auto on an adapter that is not an RDNA 4 Radeon keeps its rule for every model, logged (owner question). +// frames; a create-level refusal ends the context with one line and the game keeps its own upscaler). The frame +// capture and executor=hip stay opt-in diagnostics with a loud line. // - `d3d12-test`: the offline test executor. #pragma once #include +#include #include #include "../rdna4.h" @@ -38,16 +42,20 @@ namespace wgi { struct ExecutorRequest { std::string executor = "auto"; // the option's value ("auto" when not named) bool model_k = false; // the runtime options select model K (D3D12 executor: ports checked at its create) - bool adapter_known = false; // the game device's adapter could be read (DXGI) + // The game device's adapter, from sources a layer in the game cannot rewrite (rdna4_win.h read_adapter_identity): + bool adapter_known = false; // the SYSTEM's DXGI described the adapter (never the game's dxgi.dll) uint32_t vendor_id = 0; bool software = false; // DXGI_ADAPTER_FLAG_SOFTWARE - std::string adapter; // DXGI description + std::string adapter; // that DXGI description + bool kmt_known = false; // the kernel-mode driver's PCI ids were read (they decide first) + uint32_t kmt_vendor = 0, kmt_device = 0; bool sparkle_guard = false; // option sparkle_guard on bool capture = false; // option capture_dir set }; struct ExecutorChoice { - std::string executor; // hip | dx12 | d3d12-test; empty: unknown option value (create fails) + std::string executor; // hip | dx12 | d3d12-test | fsr (no executor: create ends, the front end's own upscaler + // takes the game); empty: unknown option value (create fails) bool by_default = false; // chosen by the default rule (option not named): frames the D3D12 executor does not take // move the context to the HIP executor bool warn = false; // log `why` as a warning (else information) @@ -55,11 +63,32 @@ struct ExecutorChoice { std::string why; // the one log line about the choice; empty: nothing to log here }; +// The one line when "auto" meets an adapter that is not an RDNA 4 Radeon RX 9000-series card or is not identified (the +// launcher shows the same sentence): no HIP attempt, no kernel load, the front end's own upscaler takes the game. +inline std::string needs_rx9000_line(bool adapter_known, const std::string& adapter) { + return "WrongGPU's models need an RX 9000-series GPU; using AMD FSR (" + + (adapter_known ? "adapter " + (adapter.empty() ? std::string("(no name)") : adapter) : std::string("adapter not identified")) + + ")"; +} + // The one line when model K meets the sparkle guard: the guard is HIP-only, so it is off for K. inline std::string k_sparkle_off_line() { return "model K: the sparkle guard runs on HIP only and is turned off for model K; model K runs on the D3D12 executor"; } +// rdna4.h's identity rule on a request. +inline wgrt::AdapterIdentity adapter_identity(const ExecutorRequest& r) { + wgrt::AdapterIdentity id; + id.dxgi_known = r.adapter_known; + id.dxgi_vendor = r.vendor_id; + id.software = r.software; + id.description = r.adapter; + id.kmt_known = r.kmt_known; + id.kmt_vendor = r.kmt_vendor; + id.kmt_device = r.kmt_device; + return id; +} + inline ExecutorChoice choose_executor(const ExecutorRequest& r) { ExecutorChoice c; const std::string& e = r.executor; @@ -98,13 +127,14 @@ inline ExecutorChoice choose_executor(const ExecutorRequest& r) { } if (e != "auto" && !e.empty()) return c; // unknown value c.by_default = true; - const std::string gpu = r.adapter_known ? "the adapter " + (r.adapter.empty() ? std::string("(no name)") : r.adapter) - : std::string("the adapter (not identified)"); const char* why = nullptr; - std::string text; - if (!r.adapter_known || !wgrt::rdna4_adapter(r.vendor_id, r.software, r.adapter)) { - text = gpu + " is not an RDNA 4 Radeon RX 9070 / RX 9060, where the D3D12 executor runs"; - why = text.c_str(); + if (!wgrt::rdna4_identity(adapter_identity(r))) { + c.executor = "fsr"; // every model: the kernels are RX 9000-only; the front end's own upscaler takes the game + c.warn = true; + char ids[32] = ""; + if (!r.adapter_known && r.kmt_known) std::snprintf(ids, sizeof ids, "PCI %04X:%04X", (unsigned)r.kmt_vendor, (unsigned)r.kmt_device); + c.why = needs_rx9000_line(r.adapter_known || r.kmt_known, r.adapter_known ? r.adapter : std::string(ids)); + return c; } else if (r.model_k && r.capture) { // an opt-in diagnostic, never on by default c.executor = "hip"; c.warn = true; @@ -121,9 +151,11 @@ inline ExecutorChoice choose_executor(const ExecutorRequest& r) { } else if (r.capture) { why = "the frame capture runs on HIP only"; } - if (why) { + if (why) { // models M, L: the sparkle guard and the frame capture are HIP only (opt-in): a warning, never silent c.executor = "hip"; - c.why = std::string("executor hip (default): ") + why + " (executor=dx12 / executor=hip in the options force a choice)"; + c.warn = true; + c.why = std::string("diagnostic: executor hip (default): ") + why + + " (executor=dx12 / executor=hip in the options force a choice)"; return c; } c.executor = "dx12"; // the success line is logged once the D3D12 executor has taken the context diff --git a/clean/runtime/interop/tests/test_executor_select.cpp b/clean/runtime/interop/tests/test_executor_select.cpp index 2f5a9c0f..349919fe 100644 --- a/clean/runtime/interop/tests/test_executor_select.cpp +++ b/clean/runtime/interop/tests/test_executor_select.cpp @@ -59,19 +59,60 @@ int main() { r.executor = ""; expect("executor= (empty): as not named", choose_executor(r).executor == "dx12"); } - // default on other GPUs -> hip, one information line naming the adapter + // R1 (oversight 2026-11-15): auto on an adapter that is not an RDNA 4 Radeon RX 9000-series card goes straight to the + // front end's own upscaler (AMD FSR, else its stand-in), for every model, with one warning line: no executor, no HIP + // attempt, no kernel load { + const char* const sentence = "WrongGPU's models need an RX 9000-series GPU; using AMD FSR"; ExecutorChoice c = choose_executor(gpu("AMD Radeon RX 7900 XTX")); - expect("default: RDNA 3 -> hip", c.executor == "hip" && c.by_default && !c.warn); - expect("default: RDNA 3 line names the adapter and the reason", - has(c.why, "executor hip (default)") && has(c.why, "RX 7900 XTX") && has(c.why, "not an RDNA 4")); + expect("auto: RDNA 3 -> the front end's upscaler (fsr), not hip", c.executor == "fsr" && c.by_default && c.warn); + expect("auto: RDNA 3 line is the sentence and names the adapter", + c.why.rfind(sentence, 0) == 0 && has(c.why, "RX 7900 XTX") && c.why.find('\n') == std::string::npos); + c = choose_executor(gpu("AMD Radeon RX 6800")); + expect("auto: RDNA 2 -> fsr", c.executor == "fsr" && has(c.why, sentence)); + c = choose_executor(gpu("Other Vendor Graphics 4070", 0x10DE)); + expect("auto: another vendor -> fsr", c.executor == "fsr" && has(c.why, sentence)); + c = choose_executor(gpu("AMD Radeon(TM) Graphics")); + expect("auto: an integrated Radeon -> fsr", c.executor == "fsr" && has(c.why, sentence)); c = choose_executor(gpu("Microsoft Basic Render Driver", 0x1414, true)); - expect("default: WARP -> hip", c.executor == "hip" && !c.why.empty()); + expect("auto: WARP -> fsr", c.executor == "fsr" && has(c.why, sentence)); c = choose_executor(gpu("AMD Radeon RX 9070 XT", 0x1002, true)); - expect("default: software adapter named RX 9070 -> hip", c.executor == "hip"); + expect("auto: software adapter named RX 9070 -> fsr", c.executor == "fsr"); ExecutorRequest r; // adapter not identified (DXGI failed) c = choose_executor(r); - expect("default: unknown adapter -> hip", c.executor == "hip" && has(c.why, "not identified")); + expect("auto: unidentified adapter -> fsr with the same sentence", + c.executor == "fsr" && c.warn && c.why.rfind(sentence, 0) == 0 && has(c.why, "adapter not identified")); + r.model_k = true; + c = choose_executor(r); + expect("auto: unidentified adapter + model K -> fsr", c.executor == "fsr" && has(c.why, sentence)); + r = gpu("AMD Radeon RX 7900 XTX"); + r.sparkle_guard = true; + r.capture = true; + c = choose_executor(r); + expect("auto: RDNA 3 with the sparkle guard or the capture -> fsr too (the kernels are RX 9000-only)", + c.executor == "fsr"); + r = gpu("AMD Radeon RX 7900 XTX"); + r.executor = ""; + expect("executor= (empty) on RDNA 3: as auto", choose_executor(r).executor == "fsr"); + expect("the line helper: sentence first, then the adapter", + wgi::needs_rx9000_line(true, "AMD Radeon RX 7900 XTX") == + "WrongGPU's models need an RX 9000-series GPU; using AMD FSR (adapter AMD Radeon RX 7900 XTX)"); + expect("the line helper: unidentified", + wgi::needs_rx9000_line(false, "") == + "WrongGPU's models need an RX 9000-series GPU; using AMD FSR (adapter not identified)"); + } + // RDNA 4: auto is unchanged for every model (the selector cannot see L: M and L share the not-K request) + { + for (const char* name : {"AMD Radeon RX 9070 XT", "AMD Radeon RX 9070", "AMD Radeon RX 9070 GRE", "AMD Radeon RX 9060 XT"}) { + ExecutorRequest r = gpu(name); + ExecutorChoice c = choose_executor(r); + expect((std::string("RDNA 4 auto, model M or L -> dx12: ") + name).c_str(), + c.executor == "dx12" && c.by_default && c.why.empty() && !c.warn); + r.model_k = true; + c = choose_executor(r); + expect((std::string("RDNA 4 auto, model K -> dx12: ") + name).c_str(), + c.executor == "dx12" && c.by_default && c.why.empty() && !c.warn); + } } // default with model K on RDNA 4 -> dx12 by the default rule (the D3D12 executor's create checks K's ports and // refuses the context when one is missing: dx12_refused_line, then the HIP executor); on other GPUs -> hip @@ -83,7 +124,7 @@ int main() { r = gpu("AMD Radeon RX 7900 XTX"); r.model_k = true; c = choose_executor(r); - expect("default: model K on RDNA 3 -> hip", c.executor == "hip" && has(c.why, "not an RDNA 4")); + expect("default: model K on RDNA 3 -> the front end's upscaler", c.executor == "fsr" && has(c.why, "RX 9000-series")); r = gpu("AMD Radeon RX 9070 XT"); r.model_k = true; r.capture = true; @@ -96,11 +137,13 @@ int main() { ExecutorChoice c; r.sparkle_guard = true; c = choose_executor(r); - expect("default: sparkle guard -> hip", c.executor == "hip" && has(c.why, "sparkle guard")); + expect("default: sparkle guard -> hip, with a warning (model M, L: an opt-in HIP feature)", + c.executor == "hip" && c.warn && has(c.why, "sparkle guard") && has(c.why, "diagnostic")); r = gpu("AMD Radeon RX 9070 XT"); r.capture = true; c = choose_executor(r); - expect("default: frame capture -> hip", c.executor == "hip" && has(c.why, "frame capture")); + expect("default: frame capture -> hip, with a warning (an opt-in diagnostic)", + c.executor == "hip" && c.warn && has(c.why, "frame capture") && has(c.why, "diagnostic")); } // forced: executor=hip on RDNA 4 -> hip, nothing logged, no switch rule { @@ -114,6 +157,14 @@ int main() { expect("executor=hip + model K -> hip, the same diagnostic line (never a game route)", c.executor == "hip" && !c.by_default && c.warn && has(c.why, "not the in-game runtime")); } + // explicit executor=hip stays a loud diagnostic on any adapter (the front end's HIP attempt is the user's own request) + { + ExecutorRequest r = gpu("AMD Radeon RX 7900 XTX"); + r.executor = "hip"; + ExecutorChoice c = choose_executor(r); + expect("executor=hip on RDNA 3 -> hip, the loud diagnostic line", + c.executor == "hip" && !c.by_default && c.warn && has(c.why, "diagnostic: executor=hip")); + } // forced: executor=dx12 (or d3d12) -> dx12 on any adapter (the device refuses unsupported ones), not by default { ExecutorRequest r = gpu("AMD Radeon RX 7900 XTX"); @@ -215,12 +266,13 @@ int main() { r = gpu("AMD Radeon RX 7900 XTX"); r.model_k = true; c = choose_executor(r); - expect("K auto on a non-RDNA 4 adapter: today's rule, logged (owner question)", - c.executor == "hip" && has(c.why, "not an RDNA 4")); + expect("K auto on a non-RDNA 4 adapter: the front end's upscaler, one line", + c.executor == "fsr" && has(c.why, "RX 9000-series GPU; using AMD FSR")); r = wgi::ExecutorRequest(); r.model_k = true; c = choose_executor(r); - expect("K auto on an unidentified adapter: today's rule, logged", c.executor == "hip" && has(c.why, "not identified")); + expect("K auto on an unidentified adapter: the front end's upscaler, one line", + c.executor == "fsr" && has(c.why, "not identified")); // hip_switch: ignored for K, one line when it is set expect("K: no line when hip_switch is not set", wgi::k_hip_switch_note("").empty()); @@ -263,6 +315,71 @@ int main() { expect("K and M (hip_switch=off) take the same path: the same action", wgi::refused_frame_action(true, true, true) == wgi::refused_frame_action(false, true, false)); } + // R1 (oversight 2026-11-15): the GPU's identity comes from the system's DXGI and the kernel-mode driver's ids, never from + // a description a layer in the game (OptiScaler's GPU spoofing) presents. A real RX 9000 keeps WrongGPU whatever name it + // is shown under; another board, or no identity at all, goes to the front end's upscaler with the one line. + { + const char* const sentence = "WrongGPU's models need an RX 9000-series GPU; using AMD FSR"; + for (uint32_t id : {0x7550u, 0x7551u, 0x7590u, 0x7591u}) + expect("RDNA 4 device id", wgrt::rdna4_device_id(id)); + for (uint32_t id : {0x744Cu, 0x73BFu, 0x7480u, 0x164Eu, 0x13C0u, 0u}) + expect("not an RDNA 4 device id", !wgrt::rdna4_device_id(id)); + auto spoof = [](const char* shown, uint32_t shown_vendor, uint32_t kvendor, uint32_t kdevice) { + ExecutorRequest r = gpu(shown, shown_vendor); + r.kmt_known = true; + r.kmt_vendor = kvendor; + r.kmt_device = kdevice; + return r; + }; + // a SPOOFED name on a real RX 9000 id: still the D3D12 executor, WrongGPU active, nothing to log (every model) + ExecutorRequest r = spoof("Other Vendor Graphics 4090", 0x10DE, 0x1002, 0x7550); + ExecutorChoice c = choose_executor(r); + expect("spoofed other-vendor name on a real RX 9070 id -> dx12", c.executor == "dx12" && c.by_default && c.why.empty()); + r.model_k = true; + expect("the same, model K -> dx12", choose_executor(r).executor == "dx12"); + r = spoof("AMD Radeon RX 7900 XTX", 0x1002, 0x1002, 0x7590); + expect("spoofed RDNA 3 name on a real RX 9060 id -> dx12", choose_executor(r).executor == "dx12"); + r = spoof("Microsoft Basic Render Driver", 0x1414, 0x1002, 0x7551); + r.software = true; + expect("a software-looking description on a real RDNA 4 id -> dx12 (the driver's id decides)", choose_executor(r).executor == "dx12"); + // the driver's ids name the board; the description reported by the system's DXGI agrees + r = spoof("AMD Radeon RX 9070 XT", 0x1002, 0x1002, 0x7550); + expect("real RX 9070 XT: dx12", choose_executor(r).executor == "dx12"); + // a real non-RDNA-4 id: the front end's upscaler with the one line + r = spoof("AMD Radeon RX 7900 XTX", 0x1002, 0x1002, 0x744C); + c = choose_executor(r); + expect("real RDNA 3 id -> fsr with the line", c.executor == "fsr" && c.warn && c.why.rfind(sentence, 0) == 0); + r = spoof("Other Vendor Graphics 4070", 0x10DE, 0x10DE, 0x2786); + expect("real other-vendor id -> fsr", choose_executor(r).executor == "fsr"); + // an unidentified adapter: no description, no driver ids + c = choose_executor(ExecutorRequest()); + expect("nothing known -> fsr with the line and 'not identified'", + c.executor == "fsr" && c.why.rfind(sentence, 0) == 0 && has(c.why, "adapter not identified")); + // only the driver's ids known (the system DXGI could not be read) + r = ExecutorRequest(); + r.kmt_known = true; + r.kmt_vendor = 0x1002; + r.kmt_device = 0x744C; + c = choose_executor(r); + expect("only a real RDNA 3 id known -> fsr, the line names the ids", c.executor == "fsr" && has(c.why, "PCI 1002:744C")); + r.kmt_device = 0x7550; + expect("only a real RX 9070 id known -> dx12", choose_executor(r).executor == "dx12"); + // the pure rule + wgrt::AdapterIdentity id; + expect("identity: nothing known -> not RDNA 4", !wgrt::rdna4_identity(id)); + id.dxgi_known = true; + id.dxgi_vendor = 0x1002; + id.description = "AMD Radeon RX 9060 XT"; + expect("identity: the system DXGI's description alone (no driver ids) -> RDNA 4", wgrt::rdna4_identity(id)); + id.software = true; + expect("identity: a software adapter is not RDNA 4", !wgrt::rdna4_identity(id)); + // forced executors are not affected by the identity (a forced dx12 on a real RX 9000 under a spoof stays dx12) + r = spoof("Other Vendor Graphics 4090", 0x10DE, 0x1002, 0x7550); + r.executor = "dx12"; + expect("executor=dx12 under a spoof on a real RX 9000 -> dx12", choose_executor(r).executor == "dx12" && !choose_executor(r).by_default); + r.executor = "hip"; + expect("executor=hip under a spoof -> the loud diagnostic", choose_executor(r).executor == "hip" && choose_executor(r).warn); + } // test executor and unknown values { ExecutorRequest r = gpu("AMD Radeon RX 9070 XT"); diff --git a/clean/runtime/model_select.h b/clean/runtime/model_select.h index 91c71c97..8296cc3d 100644 --- a/clean/runtime/model_select.h +++ b/clean/runtime/model_select.h @@ -27,6 +27,8 @@ struct ModelInfo { constexpr ModelInfo kModelTable[] = { {ModelId::M, "M", "preset-M.v1.map.json", "", true}, {ModelId::K, "K", "preset-K.v1.map.json", "K", true}, + // L: false here is the table's default for builds without Model L; runtime.cpp admits L onto the native D3D12 backend + // in builds with WG_MODEL_L (model_l_built()), and the D3D12 executor is the default for L on RDNA 4 (executor_select.h) {ModelId::L, "L", "preset-L.v1.map.json", "L", false}, }; constexpr size_t kModelCount = sizeof kModelTable / sizeof kModelTable[0]; diff --git a/clean/runtime/rdna4.h b/clean/runtime/rdna4.h index 9122358b..d74d6951 100644 --- a/clean/runtime/rdna4.h +++ b/clean/runtime/rdna4.h @@ -18,4 +18,31 @@ inline bool rdna4_adapter(uint32_t vendor_id, bool software, const std::string& (description.find("RX 9070") != std::string::npos || description.find("RX 9060") != std::string::npos); } +// RDNA 4 PCI device ids (Navi 48: RX 9070 XT / 9070 / 9070 GRE; Navi 44: RX 9060 XT / 9060), the same list as the +// Ray Reconstruction runtime's (clean/rr_f/runtime/src/rr_runtime.cpp). +inline bool rdna4_device_id(uint32_t device) { + return device == 0x7550 || device == 0x7551 || device == 0x7590 || device == 0x7591; +} + +// What is known about an adapter, from sources another layer in the game process cannot rewrite (rdna4_win.h reads +// them): the system's own DXGI (description, vendor id, software flag) and the kernel-mode driver's vendor and device id. +// OptiScaler's GPU spoofing rewrites what the GAME's dxgi.dll reports, so a description read there is never used. +struct AdapterIdentity { + bool dxgi_known = false; // the system's DXGI described the adapter + uint32_t dxgi_vendor = 0; + bool software = false; + std::string description; + bool kmt_known = false; // the kernel-mode driver's ids were read + uint32_t kmt_vendor = 0, kmt_device = 0; +}; + +// An RDNA 4 Radeon RX 9000-series board: the driver's own ids first (a real RX 9000 is one whatever name a layer +// presents, a spoofed name on another board is not one), else the system DXGI's description (rdna4_adapter). Nothing +// known: not identified, so not RDNA 4. +inline bool rdna4_identity(const AdapterIdentity& a) { + if (a.kmt_known && a.kmt_vendor == 0x1002 && rdna4_device_id(a.kmt_device)) return true; + if (a.dxgi_known) return rdna4_adapter(a.dxgi_vendor, a.software, a.description) && (!a.kmt_known || a.kmt_vendor == 0x1002); + return false; +} + } // namespace wgrt diff --git a/clean/runtime/rdna4_win.h b/clean/runtime/rdna4_win.h new file mode 100644 index 00000000..9c334ad2 --- /dev/null +++ b/clean/runtime/rdna4_win.h @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: MIT +// The identity of the adapter a D3D12 device runs on, read where another layer in the game process cannot rewrite it +// (R1, oversight 2026-11-15; R1-AUDIT H8). WrongGPU's own code. Header only, Windows only: every caller (the interop +// backend's executor choice, the native D3D12 device) includes it; nothing here needs an import library (the kernel-mode +// thunks come from gdi32.dll at run time), so the many small test builds of device_d3d12.cpp link as before. +// +// Why: OptiScaler (and other proxies) can sit in the game folder as dxgi.dll and rewrite DXGI's adapter description and +// vendor id, to make a game offer another vendor's options (the launcher's GPU-report switch in its OptiScaler tab; an +// experimental RR game profile). Reading the adapter through the game's dxgi.dll then shows another GPU, and a real RX 9000 +// would lose WrongGPU. Two sources are used instead: +// - the system's own DXGI: \dxgi.dll loaded by its full path (a bare "dxgi.dll", with or without +// LOAD_LIBRARY_SEARCH_SYSTEM32, returns a proxy that is already loaded under that name), enumerated by the device's +// LUID; +// - the kernel-mode driver's vendor and device id for that LUID (D3DKMTQueryAdapterInfo, PHYSICALADAPTERDEVICEIDS), +// which does not go through DXGI at all. +// wgrt::rdna4_identity (rdna4.h) decides from them. +#pragma once + +#include +#include + +#include +#include + +#include "rdna4.h" + +namespace wgrt { + +namespace kmt { +// The few kernel-mode thunk declarations needed (d3dkmthk.h names and layouts), so that no WDK header and no import +// library is required. +struct OpenAdapterFromLuid { + LUID AdapterLuid; + UINT hAdapter; +}; +struct QueryAdapterInfo { + UINT hAdapter; + UINT Type; // KMTQAITYPE_PHYSICALADAPTERDEVICEIDS = 31 + void* pPrivateDriverData; + UINT PrivateDriverDataSize; +}; +struct DeviceIds { + UINT VendorID, DeviceID, SubVendorID, SubSystemID, RevisionID, BusType; +}; +struct QueryDeviceIds { + UINT PhysicalAdapterIndex; + DeviceIds Ids; +}; +struct CloseAdapter { + UINT hAdapter; +}; +constexpr UINT kPhysicalAdapterDeviceIds = 31; +} // namespace kmt + +// The kernel-mode driver's PCI vendor and device id of the adapter with this LUID. False when the query is not +// available (Wine without the thunks, a software adapter, a refused call). +inline bool driver_device_ids(const LUID& luid, uint32_t* vendor, uint32_t* device) { + using OpenFn = LONG(WINAPI*)(kmt::OpenAdapterFromLuid*); + using QueryFn = LONG(WINAPI*)(kmt::QueryAdapterInfo*); + using CloseFn = LONG(WINAPI*)(kmt::CloseAdapter*); + HMODULE gdi = GetModuleHandleW(L"gdi32.dll"); + if (!gdi) gdi = LoadLibraryExW(L"gdi32.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (!gdi) return false; + auto open = reinterpret_cast(reinterpret_cast(GetProcAddress(gdi, "D3DKMTOpenAdapterFromLuid"))); + auto query = reinterpret_cast(reinterpret_cast(GetProcAddress(gdi, "D3DKMTQueryAdapterInfo"))); + auto close = reinterpret_cast(reinterpret_cast(GetProcAddress(gdi, "D3DKMTCloseAdapter"))); + if (!open || !query || !close) return false; + kmt::OpenAdapterFromLuid o = {}; + o.AdapterLuid = luid; + if (open(&o) != 0) return false; + kmt::QueryDeviceIds ids = {}; + kmt::QueryAdapterInfo q = {}; + q.hAdapter = o.hAdapter; + q.Type = kmt::kPhysicalAdapterDeviceIds; + q.pPrivateDriverData = &ids; + q.PrivateDriverDataSize = sizeof ids; + const LONG st = query(&q); + kmt::CloseAdapter c = {}; + c.hAdapter = o.hAdapter; + close(&c); + if (st != 0) return false; + *vendor = ids.Ids.VendorID; + *device = ids.Ids.DeviceID; + return true; +} + +inline std::string wide_to_utf8(const wchar_t* w) { + char buf[512] = {}; + WideCharToMultiByte(CP_UTF8, 0, w, -1, buf, (int)sizeof buf - 1, nullptr, nullptr); + return buf; +} + +// A DLL of the system directory by its full path: a bare name returns a module of that name that is already loaded, a proxy +// in the game folder included. nullptr when it cannot be loaded. +inline HMODULE load_system_dll(const wchar_t* name) { + wchar_t dir[MAX_PATH] = {}; + const UINT n = GetSystemDirectoryW(dir, MAX_PATH); + if (n == 0 || n >= MAX_PATH) return nullptr; + const std::wstring path = std::wstring(dir) + L"\\" + name; + return LoadLibraryW(path.c_str()); +} + +// The adapter with this LUID as the SYSTEM's DXGI describes it (never the game's dxgi.dll). +inline bool system_dxgi_description(const LUID& luid, uint32_t* vendor, bool* software, std::string* description) { + HMODULE dxgi = load_system_dll(L"dxgi.dll"); + if (!dxgi) return false; + using MakeFactory = HRESULT(WINAPI*)(REFIID, void**); + auto create = reinterpret_cast(reinterpret_cast(GetProcAddress(dxgi, "CreateDXGIFactory1"))); + if (!create) return false; + bool ok = false; + IDXGIFactory4* f = nullptr; + if (SUCCEEDED(create(__uuidof(IDXGIFactory4), reinterpret_cast(&f))) && f) { + IDXGIAdapter1* a = nullptr; + if (SUCCEEDED(f->EnumAdapterByLuid(luid, __uuidof(IDXGIAdapter1), reinterpret_cast(&a))) && a) { + DXGI_ADAPTER_DESC1 d = {}; + if (SUCCEEDED(a->GetDesc1(&d))) { + ok = true; + *vendor = d.VendorId; + *software = (d.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0; + *description = wide_to_utf8(d.Description); + } + a->Release(); + } + f->Release(); + } + return ok; +} + +// Everything the executor choice and the native device need to know about the adapter with this LUID. +inline AdapterIdentity read_adapter_identity(const LUID& luid) { + AdapterIdentity id; + id.dxgi_known = system_dxgi_description(luid, &id.dxgi_vendor, &id.software, &id.description); + id.kmt_known = driver_device_ids(luid, &id.kmt_vendor, &id.kmt_device); + return id; +} + +} // namespace wgrt From de91e1799312dfc6d51f12b8f35a9a49d160d074 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:00:08 -0500 Subject: [PATCH 02/20] R1: identity by the driver's PCI ids only, fail closed; no HIP route for any model; RR uses it too (REVIEW-225) Identity (rdna4.h, rdna4_win.h): an adapter is RDNA 4 when the kernel-mode driver's vendor and device id for the game device's LUID say so, and for no other reason. The description never accepts or rejects (not even "KMT failed but the name says RX 9070"); ids that cannot be read, or are not RDNA 4's, are refused with the one line, which carries the description and the ids so that a board missing from the id list shows in a log. The lookup takes its two sources as functions (AdapterSources), so the CPU tests cover several adapters with the game's LUID selecting one, a spoofed name on an RX 9000 id, a supported-looking name on another id, and a failing driver query or DXGI. The AMD AGS library is not part of this project's build (the "AGS" in the repository is the WMMA intrinsic channel of the shaders), so the id list is the only source; it is noted in the pull request. Executor choice (executor_select.h, backend.cpp): a D3D12 refusal at create (driver probe, device preparation, network init) is the front end's fallback for every model, one line, never the HIP executor; the sparkle guard is turned off for every model with one line and the model stays on D3D12; HIP only with an explicit executor=hip or the frame capture, both loud. hip_switch=on for models M and L (an explicit ini option) is unchanged. RR (rr_runtime.cpp): set-device identifies the game device's adapter by the same ids before anything is created and refuses an unknown or unsupported one with the shared sentence; its other adapter checks use the same rule. Launcher: the toolbar line is worded "detected" and shows the sentence for no card and for an unidentified one too (GpuToolbarLine). Tests: clean/tests/test_executor_select.py builds and runs the selector test in the Python tests (CI) and pins the order of Context::create from the source; the GPU interop harness expects WG_TEST_EXPECT=refused instead of a HIP context. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/dx12/tests/native_probe_test.cpp | 3 +- clean/installer/src/app/launcher_ui.cpp | 2 +- clean/installer/src/app/ui_checks.cpp | 2 +- clean/installer/src/wg_core/checks.cpp | 5 +- clean/installer/src/wg_core/checks.h | 9 +- clean/installer/tests/wg_core_tests.cpp | 20 +- clean/rr_f/runtime/src/rr_runtime.cpp | 91 +-- clean/runtime/interop/backend.cpp | 12 +- clean/runtime/interop/executor_select.h | 151 ++--- .../interop/tests/test_executor_select.cpp | 602 +++++++++--------- .../interop/tests/test_interop_d3d12.cpp | 22 +- clean/runtime/rdna4.h | 106 ++- clean/runtime/rdna4_win.h | 68 +- clean/tests/test_executor_select.py | 141 ++++ 14 files changed, 692 insertions(+), 542 deletions(-) create mode 100644 clean/tests/test_executor_select.py diff --git a/clean/dx12/tests/native_probe_test.cpp b/clean/dx12/tests/native_probe_test.cpp index 58249468..4998782b 100644 --- a/clean/dx12/tests/native_probe_test.cpp +++ b/clean/dx12/tests/native_probe_test.cpp @@ -18,6 +18,7 @@ #include #include "../../runtime/device_d3d12.h" +#include "../../runtime/rdna4_win.h" #include "../../runtime/rdna4.h" int main(int argc, char** argv) { @@ -45,7 +46,7 @@ int main(int argc, char** argv) { DXGI_ADAPTER_DESC1 desc{}; char n[256] = {}; if (SUCCEEDED(a->GetDesc1(&desc))) WideCharToMultiByte(CP_UTF8, 0, desc.Description, -1, n, sizeof n - 1, nullptr, nullptr); - if (wgrt::rdna4_adapter(desc.VendorId, (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0, n)) { + if (wgrt::rdna4_identity(wgrt::read_adapter_identity(desc.AdapterLuid))) { // the driver's ids (rdna4_win.h) adapter = a; name = n; break; diff --git a/clean/installer/src/app/launcher_ui.cpp b/clean/installer/src/app/launcher_ui.cpp index d1080cc9..81859da8 100644 --- a/clean/installer/src/app/launcher_ui.cpp +++ b/clean/installer/src/app/launcher_ui.cpp @@ -1098,7 +1098,7 @@ void SetGpu(const GpuInfo& gpu) { wstring n = gpu.name; for (const wchar_t* p : {L"AMD Radeon ", L"AMD "}) if (n.rfind(p, 0) == 0) { n = n.substr(wcslen(p)); break; } v.gpuName = n; - v.executorLine = n.empty() ? L"No graphics card found" : n + GpuRuntimeLine(gpu); + v.executorLine = GpuToolbarLine(n, gpu); } void SetHealth(bool model, const GpuInfo& gpu) { v.modelReady = model; SetGpu(gpu); } // The model data's state for the toolbar and Settings (any thread): ready or why not, the DLSS file it came from, the HIP diff --git a/clean/installer/src/app/ui_checks.cpp b/clean/installer/src/app/ui_checks.cpp index 08ac6674..c309bfb4 100644 --- a/clean/installer/src/app/ui_checks.cpp +++ b/clean/installer/src/app/ui_checks.cpp @@ -41,7 +41,7 @@ void FirstRunChecks(HWND hwnd, const GlobalSettings& gs, const wstring& dll, boo // release 0.6.0 (owner 2026-11-02): the RX 9060 series is supported but not yet tested on hardware; RR takes about twice // the RX 9070 XT's time there (an estimate), and its 8 GB cards are untested const bool rx9060 = gpu.rdna4 && gpu.name.find(L"9060") != wstring::npos; - m->lines.push_back({gpu.rdna4 ? 0 : 2, L"Graphics card: " + (gpu.name.empty() ? wstring(L"Not found") : gpu.name) + + m->lines.push_back({gpu.rdna4 ? 0 : 2, L"Graphics card detected: " + (gpu.name.empty() ? wstring(L"none") : gpu.name) + (!gpu.rdna4 ? L". WrongGPU's models need an RX\u00a09000-series GPU; games use AMD FSR." : rx9060 ? L". Supported, not yet tested on this card. Ray Reconstruction takes about twice as long as on an RX\u00a09070\u00a0XT." : L"")}); diff --git a/clean/installer/src/wg_core/checks.cpp b/clean/installer/src/wg_core/checks.cpp index b4a2a9f3..37709316 100644 --- a/clean/installer/src/wg_core/checks.cpp +++ b/clean/installer/src/wg_core/checks.cpp @@ -28,7 +28,10 @@ WinInfo WindowsInfo() { } wstring NeedsRx9000Sentence() { return L"WrongGPU's models need an RX 9000-series GPU; using AMD FSR"; } -wstring GpuRuntimeLine(const GpuInfo& gpu) { return gpu.rdna4 ? wstring(L" \u00b7 Direct3D 12") : L" \u00b7 " + NeedsRx9000Sentence(); } +wstring GpuToolbarLine(const wstring& shortName, const GpuInfo& gpu) { + if (shortName.empty()) return L"No graphics card detected \u00b7 " + NeedsRx9000Sentence(); + return shortName + L" (detected) \u00b7 " + (gpu.rdna4 ? wstring(L"Direct3D 12") : NeedsRx9000Sentence()); +} 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 diff --git a/clean/installer/src/wg_core/checks.h b/clean/installer/src/wg_core/checks.h index e7070e8e..1ac24d3d 100644 --- a/clean/installer/src/wg_core/checks.h +++ b/clean/installer/src/wg_core/checks.h @@ -31,9 +31,12 @@ bool IsRdna4Name(const wstring& name); // The sentence the runtime logs when it hands a game to AMD FSR on a GPU that is not an RX 9000-series card, or on one it // cannot identify (clean/runtime/interop/executor_select.h needs_rx9000_line); the launcher says the same. wstring NeedsRx9000Sentence(); -// The toolbar's words after the GPU's name: how WrongGPU runs on it. Direct3D 12 on an RDNA 4 card; on any other card (or -// none) the sentence above. The old "HIP" and "Not supported" words are gone: no model runs on HIP in a game. -wstring GpuRuntimeLine(const GpuInfo& gpu); +// The toolbar's line for the card the launcher detected (shortName: its name without "AMD Radeon "; empty when none was +// found). The launcher looks at the system, not at the adapter a game uses (the game decides in its own process, and a +// system with two GPUs may use the other one), so the words say "detected". Direct3D 12 on an RDNA 4 card; on any other +// card, or none (an unidentified card too), the sentence above. The old "HIP" and "Not supported" words are gone: no +// model runs on HIP in a game. +wstring GpuToolbarLine(const wstring& shortName, const GpuInfo& gpu); // 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. diff --git a/clean/installer/tests/wg_core_tests.cpp b/clean/installer/tests/wg_core_tests.cpp index bf0acffa..80d99edd 100644 --- a/clean/installer/tests/wg_core_tests.cpp +++ b/clean/installer/tests/wg_core_tests.cpp @@ -211,14 +211,24 @@ int main() { require(NeedsRx9000Sentence() == L"WrongGPU's models need an RX 9000-series GPU; using AMD FSR", "NeedsRx9000Sentence: the runtime's sentence"); GpuInfo rdna4; rdna4.amd = rdna4.rdna4 = true; - require(GpuRuntimeLine(rdna4) == L" \u00b7 Direct3D 12", "GpuRuntimeLine: RDNA 4 runs on Direct3D 12"); + require(GpuToolbarLine(L"RX 9070 XT", rdna4) == L"RX 9070 XT (detected) \u00b7 Direct3D 12", + "GpuToolbarLine: RDNA 4 is detected and runs on Direct3D 12"); GpuInfo rdna3; rdna3.amd = true; - require(GpuRuntimeLine(rdna3).find(NeedsRx9000Sentence()) != wstring::npos && !Contains(GpuRuntimeLine(rdna3), L"HIP"), - "GpuRuntimeLine: another AMD card gets the sentence, no HIP"); + const wstring l3 = GpuToolbarLine(L"RX 7900 XTX", rdna3); + require(l3.find(NeedsRx9000Sentence()) != wstring::npos && !Contains(l3, L"HIP") && Contains(l3, L"(detected)"), + "GpuToolbarLine: another AMD card gets the sentence, no HIP"); GpuInfo other; - require(GpuRuntimeLine(other).find(NeedsRx9000Sentence()) != wstring::npos && !Contains(GpuRuntimeLine(other), L"Not supported"), - "GpuRuntimeLine: another vendor, or no card, gets the sentence"); + const wstring lo = GpuToolbarLine(L"Other Vendor 4070", other); + require(lo.find(NeedsRx9000Sentence()) != wstring::npos && !Contains(lo, L"Not supported"), + "GpuToolbarLine: another vendor gets the sentence"); + const wstring none = GpuToolbarLine(L"", other); + require(none == L"No graphics card detected \u00b7 " + NeedsRx9000Sentence(), + "GpuToolbarLine: no card, an unidentified one, gets the sentence too"); + GpuInfo unnamed; // found, but its name could not be read + unnamed.amd = true; + require(GpuToolbarLine(L"", unnamed).find(NeedsRx9000Sentence()) != wstring::npos, + "GpuToolbarLine: an unnamed AMD card gets the sentence"); } // Linux's device list from a made-up folder (any host): every card in number order, connectors skipped, junk and diff --git a/clean/rr_f/runtime/src/rr_runtime.cpp b/clean/rr_f/runtime/src/rr_runtime.cpp index 5572f9d0..9c039346 100644 --- a/clean/rr_f/runtime/src/rr_runtime.cpp +++ b/clean/rr_f/runtime/src/rr_runtime.cpp @@ -49,6 +49,7 @@ #include "../../host/rr_input_host.h" #include "../../../runtime/interop/texture_shape.h" +#include "../../../runtime/rdna4_win.h" #include "../../proxy/include/rr_proxy_abi.h" #include "../../proxy/include/wg_rr_adapter.h" #include "rr_kernels.h" @@ -181,54 +182,18 @@ class CompileThread { std::function fn_; }; -// RDNA 4 boards (the rule of clean/runtime/rdna4.h on clean/rdna4-dx12, WrongGPU's own code) -bool rdna4_adapter(uint32_t vendor, bool software, const std::string& d) { - return vendor == 0x1002 && !software && (d.find("RX 9070") != std::string::npos || d.find("RX 9060") != std::string::npos); +// RDNA 4 boards: the rule of the network runtime (clean/runtime/rdna4.h, rdna4_win.h): the adapter with this LUID is +// identified by the kernel-mode driver's PCI vendor and device id and by nothing else, never by a description another layer +// in the game (OptiScaler's GPU spoofing) can rewrite, and it fails closed: ids that cannot be read, or are not RDNA 4's, +// are not RDNA 4. *who gets the adapter as a log line shows it (the system DXGI's description and the ids). +bool rdna4_luid(const LUID& luid, std::string* who) { + const wgrt::AdapterIdentity id = wgrt::read_adapter_identity(luid); + if (who) *who = wgrt::describe_identity(id); + return wgrt::rdna4_identity(id); } -// The adapter's PCI vendor / device id as the kernel-mode display driver reports it, looked up by LUID. DXGI's -// description can be rewritten by other layers in the game process (OptiScaler's GPU spoofing, for games that only -// offer their upscaler options for another vendor id); this path does not go through DXGI. -bool kmt_device_ids(LUID luid, uint32_t* vendor, uint32_t* device) { - D3DKMT_OPENADAPTERFROMLUID o = {}; - o.AdapterLuid = luid; - if (D3DKMTOpenAdapterFromLuid(&o) != 0) return false; - D3DKMT_QUERY_DEVICE_IDS ids = {}; - ids.PhysicalAdapterIndex = 0; - D3DKMT_QUERYADAPTERINFO q = {}; - q.hAdapter = o.hAdapter; - q.Type = KMTQAITYPE_PHYSICALADAPTERDEVICEIDS; - q.pPrivateDriverData = &ids; - q.PrivateDriverDataSize = sizeof ids; - const NTSTATUS st = D3DKMTQueryAdapterInfo(&q); - D3DKMT_CLOSEADAPTER c = {}; - c.hAdapter = o.hAdapter; - D3DKMTCloseAdapter(&c); - if (st != 0) return false; - *vendor = ids.DeviceIds.VendorID; - *device = ids.DeviceIds.DeviceID; - return true; -} - -// RDNA 4 PCI device ids (Navi 48: RX 9070 XT / 9070 / 9070 GRE; Navi 44: RX 9060 XT / 9060). -bool rdna4_device_id(uint32_t device) { - return device == 0x7550 || device == 0x7551 || device == 0x7590 || device == 0x7591; -} - -// RDNA 4 check for one adapter: DXGI's description first; when that does not say RDNA 4 (or was rewritten), the -// kernel driver's ids decide. *note gets a log line when the two disagree. -bool rdna4_adapter_desc(const DXGI_ADAPTER_DESC1& d, std::string* note) { - const bool software = (d.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0; - if (rdna4_adapter(d.VendorId, software, narrow(d.Description))) return true; - uint32_t ven = 0, dev = 0; - if (software || !kmt_device_ids(d.AdapterLuid, &ven, &dev)) return false; - if (ven != 0x1002 || !rdna4_device_id(dev)) return false; - if (note) - *note = fmt("DXGI reports \"%s\" (vendor 0x%04x, likely spoofed by another layer in the game); the kernel driver " - "reports %04x:%04x, an RDNA 4 board: using the driver's identity", - narrow(d.Description).c_str(), d.VendorId, ven, dev); - return true; -} +// The same for an adapter DXGI listed (by its LUID; the description in `d` is never looked at). +bool rdna4_adapter_desc(const DXGI_ADAPTER_DESC1& d, std::string* note) { return rdna4_luid(d.AdapterLuid, note); } // ---------------------------------------------------------------------------------------------------- formats (62.5) DXGI_FORMAT srv_format(DXGI_FORMAT f, bool depth) { @@ -1326,35 +1291,23 @@ uint32_t set_device_locked(ID3D12Device* given) { } rt.device_failed = true; std::string err; + { // R1: the game device's adapter is identified by the driver's ids before anything is created; unknown or not RDNA 4 + // is refused with the network runtime's sentence (the game keeps its own denoiser) + std::string who; + const wgrt::AdapterIdentity id = wgrt::read_adapter_identity(given->GetAdapterLuid()); + who = wgrt::describe_identity(id); + if (!wgrt::rdna4_identity(id)) { + log_line(std::string(wgrt::needs_rx9000_sentence()) + " (" + who + "): Ray Reconstruction is not available; the game keeps its own denoiser"); + return WG_E_ADAPTER_NOT_SUPPORTED; + } + rt.adapter_name = id.dxgi_known ? id.description : who; + } D3D12_COMMAND_QUEUE_DESC qd = {}; qd.Type = D3D12_COMMAND_LIST_TYPE_COMPUTE; if (FAILED(given->CreateCommandQueue(&qd, IID_PPV_ARGS(&rt.q))) || FAILED(rt.q->GetDevice(IID_PPV_ARGS(&rt.dev)))) { log_line("set-device: no compute queue on the game's device"); return WG_E_D3D_API; } - { - LUID luid = rt.dev->GetAdapterLuid(); - IDXGIFactory4* fac = nullptr; - IDXGIAdapter1* a = nullptr; - if (SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&fac))) && SUCCEEDED(fac->EnumAdapterByLuid(luid, IID_PPV_ARGS(&a)))) { - DXGI_ADAPTER_DESC1 d; - a->GetDesc1(&d); - rt.adapter_name = narrow(d.Description); - std::string note; - const bool rdna4 = rdna4_adapter_desc(d, ¬e); - if (!note.empty()) log_line("set-device: " + note); - if (!rdna4) { - log_line("set-device: adapter \"" + rt.adapter_name + "\" is not an RDNA 4 board: RR not available"); - release(a); - release(fac); - drop_device(); - rt.device_failed = true; - return WG_E_ADAPTER_NOT_SUPPORTED; - } - } - release(a); - release(fac); - } rt.inc = rt.dev->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); rt.q->GetTimestampFrequency(&rt.ts_freq); bool ok = SUCCEEDED(rt.dev->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&rt.al))) && diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index ff4b715a..9de91f39 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -668,15 +668,9 @@ class Context { no_slots_ = true; // its kernels read the game's textures: no slot buffers (fences and a 128 KB flag arena only) if (!exec_->prepare(&err) || !exec_->prepare_device(device_, &err) || !make_shared_objects(false, "arena", &err) || !exec_->init(device_, set_, &err)) { - // model K: no HIP route in a game; the one error line below is the whole report, the game keeps its own upscaler - if (model_k_) return fail(WG_ERROR_UNSUPPORTED, dx12_refused_line_k(dx12_default_, err)); - say(WG_LOG_WARN, dx12_refused_line(dx12_default_, err)); - exec_.reset(); - release_set(); - no_slots_ = false; - dx12 = false; - dx12_default_ = false; - err.clear(); + // R1, every model: no HIP route in a game. The context is not created; the one error line is the whole report + // and the front end's own upscaler (AMD FSR, else its stand-in) keeps the game + return fail(WG_ERROR_UNSUPPORTED, dx12_refused_line(dx12_default_, err)); } else { say(WG_LOG_INFO, std::string("executor dx12: the network runs on the game's D3D12 device, recorded into the " "game's command list; its kernels read the game's colour, depth and motion and " diff --git a/clean/runtime/interop/executor_select.h b/clean/runtime/interop/executor_select.h index 34524b50..89addd76 100644 --- a/clean/runtime/interop/executor_select.h +++ b/clean/runtime/interop/executor_select.h @@ -2,32 +2,28 @@ // Which executor runs a context (backend.cpp Context::create): the decision alone, free of D3D12, so that // tests/test_executor_select.cpp checks it on any host. WrongGPU's own code. // -// Option `executor` (wronggpu.ini runtime_options, an [fsr] line, WG_RUNTIME_OPTIONS): -// - not named (or `auto`): every model (M, L, K) on an RDNA 4 adapter (../rdna4.h) runs on the D3D12 executor -// (executor_d3d12.cpp). On an adapter that is not an RDNA 4 Radeon RX 9000-series card, or one that cannot be -// identified, the context is not created: the front end's own upscaler (AMD FSR, else its stand-in) takes the -// game, with one warning line (R1, oversight 2026-11-15: the networks' kernels are RX 9000-only, a HIP attempt -// only fails at kernel load). The sparkle guard (M, L) and the frame capture, which run on HIP only, select the HIP -// executor with a warning line. The D3D12 executor can still refuse the context at create -// (its driver-channel probe, the network's create, a context its kernels do not take): then the HIP executor runs -// it, again with one line (backend.cpp; model K: no HIP route, the context is not created and the game keeps its own -// upscaler, dx12_refused_line_k). Model K is taken only when every kernel the context can launch has a -// D3D12 port in the build's dx12/manifest.json and its options select the exact default path (KRuntime::create on -// backend 3 checks both before it loads the model; clean/k/runtime/runtime_k.h); else the refusal line names what -// is missing. A frame it does not take later (e.g. above the checked render size; native AA -// and every ratio between 1.0 and 1.5 run on it since Brief 15) goes back to the front end -// (AMD FSR, else its stand-in; hip_switch=off, the default since the owner's decision of 2026-11-04); with -// hip_switch=on the context moves to the HIP executor for good (backend.cpp switch_to_hip; one line). -// - `hip`: the HIP executor, always: a diagnostic, not the in-game runtime (owner 2026-11-14: every model runs on the -// D3D12 runtime in a game); one warning line says so. -// - `dx12` (or `d3d12`): the D3D12 executor on any adapter (the device refuses unsupported ones and the HIP executor -// takes the context; model K as above); the sparkle guard and the frame capture keep the HIP executor (warnings, as -// before) except for model K; frames it does not take get the bilinear fallback (no switch). -// - Model K (REVIEW-215b, oversight 2026-11-14): never moved to HIP by the sparkle guard (HIP-only: it is turned off -// for K, one line, K runs on D3D12), never by hip_switch (ignored for K, one line if set), never by a refused frame -// (the frame goes to the front end's own upscaler, AMD FSR, else its stand-in, the same path as model M's refused -// frames; a create-level refusal ends the context with one line and the game keeps its own upscaler). The frame -// capture and executor=hip stay opt-in diagnostics with a loud line. +// Option `executor` (wronggpu.ini runtime_options, an [fsr] line, WG_RUNTIME_OPTIONS). R1 (owner 2026-11-14, oversight +// 2026-11-15): in a game every model (M, L, K) runs on the D3D12 executor; HIP is a test reference and, with an explicit +// option, a diagnostic. So: +// - not named (or `auto`): the D3D12 executor (executor_d3d12.cpp) on an RDNA 4 adapter (../rdna4.h: the PCI vendor and +// device id from the kernel-mode driver, never a description a layer in the game can rewrite, failing closed). On any +// other adapter, or one whose ids cannot be read, the context is not created: one warning line (the sentence of +// wgrt::needs_rx9000_sentence with the adapter's description and ids) and the front end's own upscaler (AMD FSR, else +// its stand-in) takes the game; no HIP attempt, no kernel load. When the D3D12 executor refuses the context at create +// (its driver-channel probe, device preparation, the network's create, a context its kernels do not take; model K: +// every kernel must have a port in the build's dx12/manifest.json and its options select the exact default path), the +// context is not created either: one error line and the front end's upscaler; never the HIP executor. The sparkle guard +// (HIP only) is turned off for every model with one line; the model stays on D3D12. +// - `hip`: the HIP executor, always: a diagnostic, not the in-game runtime; one warning line says so. +// - the frame capture (option capture_dir), which runs on HIP only, selects the HIP executor with a loud diagnostic line, +// never by default. +// - `dx12` (or `d3d12`): the D3D12 executor on any adapter (the device refuses unsupported ones, and the context is not +// created); frames it does not take get the bilinear fallback (no switch). +// - A frame the D3D12 executor does not take later (e.g. above the checked render size; native AA and every ratio +// between 1.0 and 1.5 run on it since Brief 15) is answered WG_ERROR_UNSUPPORTED and goes back to the front end (AMD +// FSR, else its stand-in; hip_switch=off, the default since the owner's decision of 2026-11-04); with hip_switch=on a +// model M or L context moves to the HIP executor for good (backend.cpp switch_to_hip; one line, an explicit ini option). +// Model K ignores hip_switch (one line if set). A refused K frame takes exactly model M's front-end path. // - `d3d12-test`: the offline test executor. #pragma once @@ -59,24 +55,28 @@ struct ExecutorChoice { bool by_default = false; // chosen by the default rule (option not named): frames the D3D12 executor does not take // move the context to the HIP executor bool warn = false; // log `why` as a warning (else information) - bool sparkle_off = false; // model K: the sparkle guard (HIP only) is turned off; the context stays on D3D12 + bool sparkle_off = false; // the sparkle guard (HIP only) is turned off, whatever the model; the context stays on D3D12 std::string why; // the one log line about the choice; empty: nothing to log here }; -// The one line when "auto" meets an adapter that is not an RDNA 4 Radeon RX 9000-series card or is not identified (the -// launcher shows the same sentence): no HIP attempt, no kernel load, the front end's own upscaler takes the game. -inline std::string needs_rx9000_line(bool adapter_known, const std::string& adapter) { - return "WrongGPU's models need an RX 9000-series GPU; using AMD FSR (" + - (adapter_known ? "adapter " + (adapter.empty() ? std::string("(no name)") : adapter) : std::string("adapter not identified")) + - ")"; +// The one line when "auto" meets an adapter that is not an RDNA 4 Radeon RX 9000-series card or cannot be identified (the +// launcher shows the same sentence): no HIP attempt, no kernel load, the front end's own upscaler takes the game. The +// description (the system DXGI's) and the driver's ids are in it, so that a board missing from the id list shows in a log. +inline std::string needs_rx9000_line(const wgrt::AdapterIdentity& id) { + return std::string(wgrt::needs_rx9000_sentence()) + " (" + wgrt::describe_identity(id) + ")"; } -// The one line when model K meets the sparkle guard: the guard is HIP-only, so it is off for K. -inline std::string k_sparkle_off_line() { - return "model K: the sparkle guard runs on HIP only and is turned off for model K; model K runs on the D3D12 executor"; +// The one line when the sparkle guard is on: it runs on HIP only, so it is off, whatever the model; the model stays on D3D12. +inline std::string sparkle_off_line() { + return "the sparkle guard runs on HIP only and is turned off; the model runs on the D3D12 executor"; } -// rdna4.h's identity rule on a request. +// The one line for the frame capture (an opt-in diagnostic that needs the HIP executor). +inline std::string capture_hip_line() { + return "diagnostic: frame capture forces the HIP executor (the model runs on the D3D12 executor without it)"; +} + +// rdna4.h's identity of a request. inline wgrt::AdapterIdentity adapter_identity(const ExecutorRequest& r) { wgrt::AdapterIdentity id; id.dxgi_known = r.adapter_known; @@ -103,62 +103,29 @@ inline ExecutorChoice choose_executor(const ExecutorRequest& r) { "executor=dx12 run on the D3D12 executor)"; return c; } - if (e == "dx12" || e == "d3d12") { // forced (the messages of the option before it had a default) - if (r.model_k && r.capture) { - c.executor = "hip"; - c.warn = true; - c.why = "diagnostic: frame capture forces the HIP executor (model K runs on the D3D12 executor without it)"; - return c; - } - if (r.model_k && r.sparkle_guard) { - c.executor = "dx12"; - c.sparkle_off = true; + const bool forced = e == "dx12" || e == "d3d12"; + if (!forced && e != "auto" && !e.empty()) return c; // unknown value + if (!forced) { + c.by_default = true; + if (!wgrt::rdna4_identity(adapter_identity(r))) { + c.executor = "fsr"; // every model: the kernels are RX 9000-only; the front end's own upscaler takes the game c.warn = true; - c.why = k_sparkle_off_line(); + c.why = needs_rx9000_line(adapter_identity(r)); return c; } - const char* why = r.sparkle_guard ? "the sparkle guard runs on HIP only" - : r.capture ? "the frame capture runs on HIP only" - : nullptr; - c.executor = why ? "hip" : "dx12"; - c.warn = c.executor == "hip"; - if (why) c.why = std::string("executor=dx12 not available for this context: ") + why + "; the HIP executor runs it"; - return c; } - if (e != "auto" && !e.empty()) return c; // unknown value - c.by_default = true; - const char* why = nullptr; - if (!wgrt::rdna4_identity(adapter_identity(r))) { - c.executor = "fsr"; // every model: the kernels are RX 9000-only; the front end's own upscaler takes the game - c.warn = true; - char ids[32] = ""; - if (!r.adapter_known && r.kmt_known) std::snprintf(ids, sizeof ids, "PCI %04X:%04X", (unsigned)r.kmt_vendor, (unsigned)r.kmt_device); - c.why = needs_rx9000_line(r.adapter_known || r.kmt_known, r.adapter_known ? r.adapter : std::string(ids)); - return c; - } else if (r.model_k && r.capture) { // an opt-in diagnostic, never on by default + if (r.capture) { // an opt-in diagnostic, never on by default c.executor = "hip"; c.warn = true; - c.why = "diagnostic: frame capture forces the HIP executor (model K runs on the D3D12 executor without it)"; - return c; - } else if (r.model_k && r.sparkle_guard) { // the guard never moves model K to HIP: it is turned off - c.executor = "dx12"; - c.sparkle_off = true; - c.warn = true; - c.why = k_sparkle_off_line(); + c.why = capture_hip_line(); return c; - } else if (r.sparkle_guard) { - why = "the sparkle guard runs on HIP only"; - } else if (r.capture) { - why = "the frame capture runs on HIP only"; } - if (why) { // models M, L: the sparkle guard and the frame capture are HIP only (opt-in): a warning, never silent - c.executor = "hip"; + c.executor = "dx12"; // the success line is logged once the D3D12 executor has taken the context + if (r.sparkle_guard) { // the guard is HIP only: it is off, the model stays on D3D12 + c.sparkle_off = true; c.warn = true; - c.why = std::string("diagnostic: executor hip (default): ") + why + - " (executor=dx12 / executor=hip in the options force a choice)"; - return c; + c.why = sparkle_off_line(); } - c.executor = "dx12"; // the success line is logged once the D3D12 executor has taken the context return c; } @@ -228,20 +195,14 @@ inline std::string no_switch_line(uint64_t frame, const std::string& why) { "(AMD FSR, else its stand-in)"; } -// After choose_executor gave dx12: the D3D12 executor did not take the context at create (`err`: the driver-channel -// probe, the network's create on the D3D12 device, a context its kernels do not take). The HIP executor runs it; this -// is the one warning line about it. -// Model K has no HIP route in a game (owner 2026-11-14: models run on the D3D12 runtime, HIP is a test reference and an -// opt-in diagnostic): the context is not created, the one line says why, and the game keeps its own upscaler. -inline std::string dx12_refused_line_k(bool by_default, const std::string& err) { - return std::string("model K: ") + (by_default ? "executor dx12 (default on RDNA 4)" : "executor=dx12") + - " could not take this context (" + err + "); model K has no HIP route in a game (executor=hip selects it as a " - "diagnostic): the game keeps its own upscaler"; -} - +// After choose_executor gave dx12: the D3D12 executor did not take the context at create (`err`: the driver-channel probe, +// device preparation, the network's create on the D3D12 device, a context its kernels do not take). Every model has the +// same answer (R1: no HIP route in a game): the context is not created, this is the one line, and the front end's own +// upscaler (AMD FSR, else its stand-in) keeps the game. inline std::string dx12_refused_line(bool by_default, const std::string& err) { return std::string(by_default ? "executor dx12 (default on RDNA 4)" : "executor=dx12") + - " could not take this context (" + err + "); the HIP executor runs it"; + " could not take this context (" + err + "); there is no HIP route in a game (executor=hip selects the HIP " + "executor as a diagnostic): the front end's own upscaler (AMD FSR) keeps the game"; } } // namespace wgi diff --git a/clean/runtime/interop/tests/test_executor_select.cpp b/clean/runtime/interop/tests/test_executor_select.cpp index 349919fe..e3693e60 100644 --- a/clean/runtime/interop/tests/test_executor_select.cpp +++ b/clean/runtime/interop/tests/test_executor_select.cpp @@ -1,11 +1,14 @@ // SPDX-License-Identifier: MIT -// Executor choice (interop/executor_select.h): the default rule and the forcing options, on any host (no GPU, no -// D3D12). WrongGPU's own code. +// Executor choice (interop/executor_select.h) and the GPU identity rule it stands on (rdna4.h): the default rule, the +// forcing options and the refusal paths, on any host (no GPU, no D3D12). WrongGPU's own code. // clang++ -std=c++17 test_executor_select.cpp -o test_executor_select.exe && test_executor_select.exe -// Exit status 0 when every case passed. The interop test (test_interop_d3d12 dx12same with WG_TEST_DX12_DEFAULT=1) -// checks the same rule through the runtime DLL on the GPU. +// Exit status 0 when every case passed. clean/tests/test_executor_select.py builds and runs it in the Python tests (CI). +// The interop test (test_interop_d3d12 dx12same with WG_TEST_DX12_DEFAULT=1) checks the same rule through the runtime DLL on +// the GPU. #include +#include #include +#include #include "../executor_select.h" @@ -17,17 +20,54 @@ void expect(const char* name, bool ok) { std::printf("%s %s\n", ok ? "pass" : "FAIL", name); if (!ok) ++failures; } +void expect(const std::string& name, bool ok) { expect(name.c_str(), ok); } -wgi::ExecutorRequest gpu(const char* adapter, uint32_t vendor = 0x1002, bool software = false) { +bool has(const std::string& s, const char* part) { return s.find(part) != std::string::npos; } + +// A request for an adapter as the lookup found it (what backend.cpp builds from wgrt::lookup_adapter) +wgi::ExecutorRequest request_for(const wgrt::AdapterIdentity& id) { wgi::ExecutorRequest r; - r.adapter_known = true; - r.adapter = adapter; - r.vendor_id = vendor; - r.software = software; + r.adapter_known = id.dxgi_known; + r.vendor_id = id.dxgi_vendor; + r.software = id.software; + r.adapter = id.description; + r.kmt_known = id.kmt_known; + r.kmt_vendor = id.kmt_vendor; + r.kmt_device = id.kmt_device; return r; } -bool has(const std::string& s, const char* part) { return s.find(part) != std::string::npos; } +// An adapter: the description the system DXGI gives (shown vendor / name) and the driver's ids +wgrt::AdapterIdentity adapter(const char* shown_name, uint32_t shown_vendor, uint32_t kvendor, uint32_t kdevice, + bool software = false) { + wgrt::AdapterIdentity id; + id.dxgi_known = true; + id.dxgi_vendor = shown_vendor; + id.software = software; + id.description = shown_name; + id.kmt_known = true; + id.kmt_vendor = kvendor; + id.kmt_device = kdevice; + return id; +} + +// A real board: its own name and ids +wgi::ExecutorRequest board(const char* name, uint32_t vendor, uint32_t device, bool software = false) { + return request_for(adapter(name, vendor, vendor, device, software)); +} + +struct RealBoard { + const char* name; + uint32_t vendor, device; +}; +const RealBoard kRdna4[] = {{"AMD Radeon RX 9070 XT", 0x1002, 0x7550}, + {"AMD Radeon RX 9070 GRE", 0x1002, 0x7551}, + {"AMD Radeon RX 9060 XT", 0x1002, 0x7590}, + {"AMD Radeon RX 9060", 0x1002, 0x7591}}; +const RealBoard kOthers[] = {{"AMD Radeon RX 7900 XTX", 0x1002, 0x744C}, + {"AMD Radeon RX 6800", 0x1002, 0x73BF}, + {"AMD Radeon(TM) Graphics", 0x1002, 0x15BF}, + {"Other Vendor Graphics 4070", 0x10DE, 0x2786}}; } // namespace @@ -35,188 +75,273 @@ int main() { using wgi::choose_executor; using wgi::ExecutorChoice; using wgi::ExecutorRequest; + const char* const sentence = "WrongGPU's models need an RX 9000-series GPU; using AMD FSR"; - // RDNA 4 adapter recognition (the native device's rule, ../rdna4.h) - expect("rdna4: RX 9070 XT", wgrt::rdna4_adapter(0x1002, false, "AMD Radeon RX 9070 XT")); - expect("rdna4: RX 9070", wgrt::rdna4_adapter(0x1002, false, "AMD Radeon RX 9070")); - expect("rdna4: RX 9070 GRE", wgrt::rdna4_adapter(0x1002, false, "AMD Radeon RX 9070 GRE")); - expect("rdna4: RX 9060 XT", wgrt::rdna4_adapter(0x1002, false, "AMD Radeon RX 9060 XT")); - expect("not rdna4: RX 7900 XTX", !wgrt::rdna4_adapter(0x1002, false, "AMD Radeon RX 7900 XTX")); - expect("not rdna4: RX 6800", !wgrt::rdna4_adapter(0x1002, false, "AMD Radeon RX 6800")); - expect("not rdna4: integrated Radeon", !wgrt::rdna4_adapter(0x1002, false, "AMD Radeon(TM) Graphics")); - expect("not rdna4: other vendor with the name", !wgrt::rdna4_adapter(0x10DE, false, "RX 9070")); - expect("not rdna4: software adapter", !wgrt::rdna4_adapter(0x1002, true, "AMD Radeon RX 9070 XT")); - expect("not rdna4: WARP", !wgrt::rdna4_adapter(0x1414, true, "Microsoft Basic Render Driver")); - - // default (option not named): RDNA 4 + model M + supported context -> dx12, by the default rule, nothing logged yet + // ---- the identity rule (rdna4.h): the driver's vendor and device id, nothing else, failing closed ------------------- + for (const RealBoard& b : kRdna4) expect(std::string("RDNA 4 device id: ") + b.name, wgrt::rdna4_device_id(b.device)); + for (const RealBoard& b : kOthers) + expect(std::string("not an RDNA 4 board: ") + b.name, + !wgrt::rdna4_identity(adapter(b.name, b.vendor, b.vendor, b.device))); + for (const RealBoard& b : kRdna4) + expect(std::string("RDNA 4 identity: ") + b.name, wgrt::rdna4_identity(adapter(b.name, b.vendor, b.vendor, b.device))); { - ExecutorChoice c = choose_executor(gpu("AMD Radeon RX 9070 XT")); - expect("default: RDNA 4 -> dx12", c.executor == "dx12" && c.by_default && c.why.empty()); - ExecutorRequest r = gpu("AMD Radeon RX 9060 XT"); - r.executor = "auto"; - c = choose_executor(r); - expect("executor=auto: RDNA 4 (9060) -> dx12", c.executor == "dx12" && c.by_default); - r.executor = ""; - expect("executor= (empty): as not named", choose_executor(r).executor == "dx12"); + expect("a spoofed other-vendor name on a real RX 9070 id is RDNA 4", + wgrt::rdna4_identity(adapter("Other Vendor Graphics 4090", 0x10DE, 0x1002, 0x7550))); + expect("a spoofed software-looking description on a real RDNA 4 id is RDNA 4", + wgrt::rdna4_identity(adapter("Microsoft Basic Render Driver", 0x1414, 0x1002, 0x7551, true))); + expect("a supported-looking name on a real RDNA 3 id is NOT RDNA 4 (the description never accepts)", + !wgrt::rdna4_identity(adapter("AMD Radeon RX 9070 XT", 0x1002, 0x1002, 0x744C))); + expect("a supported-looking name on a real other-vendor id is NOT RDNA 4", + !wgrt::rdna4_identity(adapter("AMD Radeon RX 9070 XT", 0x1002, 0x10DE, 0x2786))); + expect("an RDNA 4 device id under another vendor's id is NOT RDNA 4", !wgrt::rdna4_identity(adapter("x", 0x1002, 0x10DE, 0x7550))); + wgrt::AdapterIdentity id = adapter("AMD Radeon RX 9070 XT", 0x1002, 0x1002, 0x7550); + id.kmt_known = false; + expect("the driver's ids unreadable: NOT RDNA 4 even with an RX 9070 description (fail closed)", !wgrt::rdna4_identity(id)); + id.dxgi_known = false; + expect("nothing known: NOT RDNA 4", !wgrt::rdna4_identity(id) && !wgrt::rdna4_identity(wgrt::AdapterIdentity())); + expect("the unknown-id AMD board is named in the line", + has(wgrt::describe_identity(adapter("AMD Radeon RX 9070 XT", 0x1002, 0x1002, 0x7592)), "outside the RDNA 4 id list") && + has(wgrt::describe_identity(adapter("x", 0x1002, 0x1002, 0x7592)), "PCI 1002:7592")); + expect("describe: unidentified", wgrt::describe_identity(wgrt::AdapterIdentity()) == "adapter not identified"); + expect("describe: description and ids", + wgrt::describe_identity(adapter("AMD Radeon RX 7900 XTX", 0x1002, 0x1002, 0x744C)) == + "adapter AMD Radeon RX 7900 XTX, PCI 1002:744C; an AMD board outside the RDNA 4 id list"); } - // R1 (oversight 2026-11-15): auto on an adapter that is not an RDNA 4 Radeon RX 9000-series card goes straight to the - // front end's own upscaler (AMD FSR, else its stand-in), for every model, with one warning line: no executor, no HIP - // attempt, no kernel load - { - const char* const sentence = "WrongGPU's models need an RX 9000-series GPU; using AMD FSR"; - ExecutorChoice c = choose_executor(gpu("AMD Radeon RX 7900 XTX")); - expect("auto: RDNA 3 -> the front end's upscaler (fsr), not hip", c.executor == "fsr" && c.by_default && c.warn); - expect("auto: RDNA 3 line is the sentence and names the adapter", - c.why.rfind(sentence, 0) == 0 && has(c.why, "RX 7900 XTX") && c.why.find('\n') == std::string::npos); - c = choose_executor(gpu("AMD Radeon RX 6800")); - expect("auto: RDNA 2 -> fsr", c.executor == "fsr" && has(c.why, sentence)); - c = choose_executor(gpu("Other Vendor Graphics 4070", 0x10DE)); - expect("auto: another vendor -> fsr", c.executor == "fsr" && has(c.why, sentence)); - c = choose_executor(gpu("AMD Radeon(TM) Graphics")); - expect("auto: an integrated Radeon -> fsr", c.executor == "fsr" && has(c.why, sentence)); - c = choose_executor(gpu("Microsoft Basic Render Driver", 0x1414, true)); - expect("auto: WARP -> fsr", c.executor == "fsr" && has(c.why, sentence)); - c = choose_executor(gpu("AMD Radeon RX 9070 XT", 0x1002, true)); - expect("auto: software adapter named RX 9070 -> fsr", c.executor == "fsr"); - ExecutorRequest r; // adapter not identified (DXGI failed) - c = choose_executor(r); - expect("auto: unidentified adapter -> fsr with the same sentence", - c.executor == "fsr" && c.warn && c.why.rfind(sentence, 0) == 0 && has(c.why, "adapter not identified")); - r.model_k = true; - c = choose_executor(r); - expect("auto: unidentified adapter + model K -> fsr", c.executor == "fsr" && has(c.why, sentence)); - r = gpu("AMD Radeon RX 7900 XTX"); - r.sparkle_guard = true; - r.capture = true; - c = choose_executor(r); - expect("auto: RDNA 3 with the sparkle guard or the capture -> fsr too (the kernels are RX 9000-only)", - c.executor == "fsr"); - r = gpu("AMD Radeon RX 7900 XTX"); - r.executor = ""; - expect("executor= (empty) on RDNA 3: as auto", choose_executor(r).executor == "fsr"); - expect("the line helper: sentence first, then the adapter", - wgi::needs_rx9000_line(true, "AMD Radeon RX 7900 XTX") == - "WrongGPU's models need an RX 9000-series GPU; using AMD FSR (adapter AMD Radeon RX 7900 XTX)"); - expect("the line helper: unidentified", - wgi::needs_rx9000_line(false, "") == - "WrongGPU's models need an RX 9000-series GPU; using AMD FSR (adapter not identified)"); - } - // RDNA 4: auto is unchanged for every model (the selector cannot see L: M and L share the not-K request) + + // ---- the lookup with injectable sources: the game device's LUID selects the adapter ----------------------------- { - for (const char* name : {"AMD Radeon RX 9070 XT", "AMD Radeon RX 9070", "AMD Radeon RX 9070 GRE", "AMD Radeon RX 9060 XT"}) { - ExecutorRequest r = gpu(name); + struct Fake { + std::map, wgrt::AdapterRecord> dxgi; + std::map, std::pair> ids; + std::vector> asked_dxgi, asked_driver; + bool dxgi_fails = false, driver_fails = false; + wgrt::AdapterSources sources() { + wgrt::AdapterSources s; + s.find_adapter = [this](const wgrt::AdapterLuid& l, wgrt::AdapterRecord* out) { + asked_dxgi.push_back({l.low, l.high}); + auto it = dxgi.find({l.low, l.high}); + if (dxgi_fails || it == dxgi.end()) return false; + *out = it->second; + return true; + }; + s.driver_ids = [this](const wgrt::AdapterLuid& l, uint32_t* v, uint32_t* d) { + asked_driver.push_back({l.low, l.high}); + auto it = ids.find({l.low, l.high}); + if (driver_fails || it == ids.end()) return false; + *v = it->second.first; + *d = it->second.second; + return true; + }; + return s; + } + }; + auto record = [](uint32_t low, int32_t high, uint32_t vendor, bool software, const char* name) { + wgrt::AdapterRecord r; + r.luid.low = low; + r.luid.high = high; + r.vendor = vendor; + r.software = software; + r.description = name; + return r; + }; + Fake f; // two adapters: WARP (LUID 1:0) and an RX 9070 XT (LUID 2:0) that a layer in the game shows as another vendor + f.dxgi[{1, 0}] = record(1, 0, 0x1414, true, "Microsoft Basic Render Driver"); + f.dxgi[{2, 0}] = record(2, 0, 0x10DE, false, "Other Vendor Graphics 4090"); + f.ids[{1, 0}] = {0x1414, 0x008C}; + f.ids[{2, 0}] = {0x1002, 0x7550}; + wgrt::AdapterLuid warp, gpu2, nobody; + warp.low = 1; + gpu2.low = 2; + nobody.low = 9; + nobody.high = 3; + wgrt::AdapterIdentity id = wgrt::lookup_adapter(gpu2, f.sources()); + expect("lookup: the game's LUID picks the RX 9000 among two adapters, with its own ids and description", + id.kmt_known && id.kmt_device == 0x7550 && id.dxgi_known && id.description == "Other Vendor Graphics 4090" && + wgrt::rdna4_identity(id)); + id = wgrt::lookup_adapter(warp, f.sources()); + expect("lookup: the other LUID picks the software adapter, not RDNA 4", + id.kmt_known && id.kmt_vendor == 0x1414 && id.software && !wgrt::rdna4_identity(id)); + expect("lookup: the same LUID went to both sources", f.asked_dxgi == f.asked_driver && + f.asked_dxgi.size() == 2 && f.asked_dxgi[0].first == 2 && + f.asked_dxgi[1].first == 1); + id = wgrt::lookup_adapter(nobody, f.sources()); + expect("lookup: a LUID neither source knows is not identified", !id.dxgi_known && !id.kmt_known && !wgrt::rdna4_identity(id)); + f.driver_fails = true; + id = wgrt::lookup_adapter(gpu2, f.sources()); + expect("lookup: the driver query failing leaves the board unidentified and refused (fail closed)", + id.dxgi_known && !id.kmt_known && !wgrt::rdna4_identity(id)); + f.driver_fails = false; + f.dxgi_fails = true; + id = wgrt::lookup_adapter(gpu2, f.sources()); + expect("lookup: the system DXGI failing does not matter, the driver's ids decide", + !id.dxgi_known && id.kmt_known && wgrt::rdna4_identity(id)); + f.dxgi_fails = false; + f.ids[{2, 0}] = {0x1002, 0x744C}; // a conflicting pair: the description says RX 9070 XT, the ids say RDNA 3 + f.dxgi[{2, 0}] = record(2, 0, 0x1002, false, "AMD Radeon RX 9070 XT"); + id = wgrt::lookup_adapter(gpu2, f.sources()); + expect("lookup: a supported-looking description with RDNA 3 ids is refused", !wgrt::rdna4_identity(id)); + + // the same cases through the executor choice and the one line (every model) + f.ids[{2, 0}] = {0x1002, 0x7550}; + f.dxgi[{2, 0}] = record(2, 0, 0x10DE, false, "Other Vendor Graphics 4090"); + for (bool model_k : {false, true}) { + const char* tag = model_k ? " (model K)" : " (model M or L)"; + ExecutorRequest r = request_for(wgrt::lookup_adapter(gpu2, f.sources())); + r.model_k = model_k; ExecutorChoice c = choose_executor(r); - expect((std::string("RDNA 4 auto, model M or L -> dx12: ") + name).c_str(), + expect(std::string("spoofed name on a real RX 9000 id: the D3D12 executor, nothing logged") + tag, c.executor == "dx12" && c.by_default && c.why.empty() && !c.warn); - r.model_k = true; + r = request_for(wgrt::lookup_adapter(warp, f.sources())); + r.model_k = model_k; + c = choose_executor(r); + expect(std::string("software adapter: the front end's upscaler with the sentence and the ids") + tag, + c.executor == "fsr" && c.warn && c.why.rfind(sentence, 0) == 0 && has(c.why, "PCI 1414:008C")); + f.driver_fails = true; + r = request_for(wgrt::lookup_adapter(gpu2, f.sources())); + r.model_k = model_k; + c = choose_executor(r); + expect(std::string("driver ids unreadable: the front end's upscaler (fail closed), no ids in the line") + tag, + c.executor == "fsr" && c.why.rfind(sentence, 0) == 0 && !has(c.why, "PCI ")); + f.driver_fails = false; + f.dxgi_fails = f.driver_fails = true; + r = request_for(wgrt::lookup_adapter(gpu2, f.sources())); + r.model_k = model_k; c = choose_executor(r); - expect((std::string("RDNA 4 auto, model K -> dx12: ") + name).c_str(), + expect(std::string("nothing readable: the front end's upscaler, 'adapter not identified'") + tag, + c.executor == "fsr" && has(c.why, "adapter not identified") && c.why.rfind(sentence, 0) == 0); + f.dxgi_fails = f.driver_fails = false; + } + // the Ray Reconstruction runtime uses the same lookup, rule and sentence (rr_runtime.cpp rdna4_luid) + f.driver_fails = true; + id = wgrt::lookup_adapter(gpu2, f.sources()); + expect("RR: ids unreadable -> refused before anything is created, with the shared sentence", + !wgrt::rdna4_identity(id) && std::string(wgrt::needs_rx9000_sentence()) == sentence && + wgi::needs_rx9000_line(id).rfind(sentence, 0) == 0); + f.driver_fails = false; + id = wgrt::lookup_adapter(gpu2, f.sources()); + expect("RR: the game's RX 9000 (spoofed name) is accepted", wgrt::rdna4_identity(id)); + } + + // ---- the default rule on real boards, every model ----------------------------------------------------------------- + for (bool model_k : {false, true}) { + const char* tag = model_k ? " (model K)" : " (model M or L)"; + for (const RealBoard& b : kRdna4) { + ExecutorRequest r = board(b.name, b.vendor, b.device); + r.model_k = model_k; + ExecutorChoice c = choose_executor(r); + expect(std::string("RDNA 4 auto -> dx12, by default, nothing logged: ") + b.name + tag, c.executor == "dx12" && c.by_default && c.why.empty() && !c.warn); + r.executor = "auto"; + expect(std::string("executor=auto: ") + b.name + tag, choose_executor(r).executor == "dx12"); + r.executor = ""; + expect(std::string("executor= (empty): ") + b.name + tag, choose_executor(r).executor == "dx12"); + } + for (const RealBoard& b : kOthers) { + ExecutorRequest r = board(b.name, b.vendor, b.device); + r.model_k = model_k; + ExecutorChoice c = choose_executor(r); + expect(std::string("other board auto -> the front end's upscaler with the sentence: ") + b.name + tag, + c.executor == "fsr" && c.by_default && c.warn && c.why.rfind(sentence, 0) == 0 && has(c.why, b.name) && + c.why.find('\n') == std::string::npos); + r.sparkle_guard = r.capture = true; + expect(std::string("... also with the sparkle guard or the capture set: ") + b.name + tag, + choose_executor(r).executor == "fsr"); } + ExecutorRequest r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550, true); // software flag with an RDNA 4 id: the id decides + r.model_k = model_k; + expect(std::string("a software flag does not decide, the ids do") + tag, choose_executor(r).executor == "dx12"); + r = ExecutorRequest(); + r.model_k = model_k; + ExecutorChoice c = choose_executor(r); + expect(std::string("an unidentified adapter -> the front end's upscaler") + tag, + c.executor == "fsr" && c.warn && has(c.why, "adapter not identified")); + expect(std::string("the supported-looking description with no ids -> the front end's upscaler") + tag, [&] { + ExecutorRequest q; + q.model_k = model_k; + q.adapter_known = true; + q.vendor_id = 0x1002; + q.adapter = "AMD Radeon RX 9070 XT"; + return choose_executor(q).executor == "fsr"; + }()); + expect(std::string("the supported-looking description on RDNA 3 ids -> the front end's upscaler") + tag, [&] { + ExecutorRequest q = request_for(adapter("AMD Radeon RX 9070 XT", 0x1002, 0x1002, 0x744C)); + q.model_k = model_k; + return choose_executor(q).executor == "fsr"; + }()); } - // default with model K on RDNA 4 -> dx12 by the default rule (the D3D12 executor's create checks K's ports and - // refuses the context when one is missing: dx12_refused_line, then the HIP executor); on other GPUs -> hip - { - ExecutorRequest r = gpu("AMD Radeon RX 9070 XT"); - r.model_k = true; + + // ---- diagnostics and the sparkle guard (every model) -------------------------------------------------------------- + for (bool model_k : {false, true}) { + const char* tag = model_k ? " (model K)" : " (model M or L)"; + ExecutorRequest r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = model_k; + r.executor = "hip"; ExecutorChoice c = choose_executor(r); - expect("default: model K on RDNA 4 -> dx12 (by default)", c.executor == "dx12" && c.by_default && c.why.empty()); - r = gpu("AMD Radeon RX 7900 XTX"); - r.model_k = true; + expect(std::string("executor=hip: the HIP executor as a loud diagnostic") + tag, + c.executor == "hip" && !c.by_default && c.warn && has(c.why, "diagnostic: executor=hip") && + has(c.why, "not the in-game runtime")); + r = board("AMD Radeon RX 7900 XTX", 0x1002, 0x744C); + r.model_k = model_k; + r.executor = "hip"; c = choose_executor(r); - expect("default: model K on RDNA 3 -> the front end's upscaler", c.executor == "fsr" && has(c.why, "RX 9000-series")); - r = gpu("AMD Radeon RX 9070 XT"); - r.model_k = true; + expect(std::string("executor=hip on another board: the same diagnostic") + tag, + c.executor == "hip" && c.warn && has(c.why, "diagnostic: executor=hip")); + r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = model_k; r.capture = true; c = choose_executor(r); - expect("default: model K + frame capture -> hip", c.executor == "hip" && has(c.why, "frame capture")); - } - // default with what has no D3D12 port -> hip, one line with the reason - { - ExecutorRequest r = gpu("AMD Radeon RX 9070 XT"); - ExecutorChoice c; + expect(std::string("auto + frame capture: HIP with the loud diagnostic line") + tag, + c.executor == "hip" && c.warn && c.why == wgi::capture_hip_line() && has(c.why, "diagnostic: frame capture")); + r.executor = "dx12"; + expect(std::string("executor=dx12 + frame capture: the same diagnostic") + tag, + choose_executor(r).executor == "hip" && choose_executor(r).why == wgi::capture_hip_line()); + r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = model_k; r.sparkle_guard = true; c = choose_executor(r); - expect("default: sparkle guard -> hip, with a warning (model M, L: an opt-in HIP feature)", - c.executor == "hip" && c.warn && has(c.why, "sparkle guard") && has(c.why, "diagnostic")); - r = gpu("AMD Radeon RX 9070 XT"); - r.capture = true; - c = choose_executor(r); - expect("default: frame capture -> hip, with a warning (an opt-in diagnostic)", - c.executor == "hip" && c.warn && has(c.why, "frame capture") && has(c.why, "diagnostic")); - } - // forced: executor=hip on RDNA 4 -> hip, nothing logged, no switch rule - { - ExecutorRequest r = gpu("AMD Radeon RX 9070 XT"); - r.executor = "hip"; - ExecutorChoice c = choose_executor(r); - expect("executor=hip on RDNA 4 -> hip, as a loud diagnostic", - c.executor == "hip" && !c.by_default && c.warn && has(c.why, "diagnostic: executor=hip")); - r.model_k = true; - c = choose_executor(r); - expect("executor=hip + model K -> hip, the same diagnostic line (never a game route)", - c.executor == "hip" && !c.by_default && c.warn && has(c.why, "not the in-game runtime")); - } - // explicit executor=hip stays a loud diagnostic on any adapter (the front end's HIP attempt is the user's own request) - { - ExecutorRequest r = gpu("AMD Radeon RX 7900 XTX"); - r.executor = "hip"; - ExecutorChoice c = choose_executor(r); - expect("executor=hip on RDNA 3 -> hip, the loud diagnostic line", - c.executor == "hip" && !c.by_default && c.warn && has(c.why, "diagnostic: executor=hip")); - } - // forced: executor=dx12 (or d3d12) -> dx12 on any adapter (the device refuses unsupported ones), not by default - { - ExecutorRequest r = gpu("AMD Radeon RX 7900 XTX"); - r.executor = "dx12"; - ExecutorChoice c = choose_executor(r); - expect("executor=dx12 on RDNA 3 -> dx12 (forced)", c.executor == "dx12" && !c.by_default && c.why.empty()); - r = gpu("AMD Radeon RX 9070 XT"); + expect(std::string("auto + sparkle guard: still the D3D12 executor, the guard turned off, one line") + tag, + c.executor == "dx12" && c.by_default && c.sparkle_off && c.warn && c.why == wgi::sparkle_off_line() && + has(c.why, "turned off") && has(c.why, "D3D12")); r.executor = "dx12"; c = choose_executor(r); - expect("executor=dx12 on RDNA 4 -> dx12, not by default (no switch to HIP)", c.executor == "dx12" && !c.by_default); - r.executor = "d3d12"; - expect("executor=d3d12 = dx12", choose_executor(r).executor == "dx12"); + expect(std::string("executor=dx12 + sparkle guard: the same") + tag, c.executor == "dx12" && c.sparkle_off && !c.by_default); + r.capture = true; + expect(std::string("the sparkle guard with the capture: the capture's diagnostic wins") + tag, + choose_executor(r).executor == "hip"); + r = board("AMD Radeon RX 7900 XTX", 0x1002, 0x744C); + r.model_k = model_k; r.executor = "dx12"; - r.model_k = true; c = choose_executor(r); - expect("executor=dx12 + model K -> dx12 (forced; ports checked at the executor's create)", + expect(std::string("executor=dx12 on another board: dx12 (the device refuses it at create)") + tag, c.executor == "dx12" && !c.by_default && c.why.empty()); - { - const std::string e = "D3D12 runtime: model K: the D3D12 build has no port of k_out_color_direct"; - expect("model K port missing (default): the refusal line names it", - has(wgi::dx12_refused_line_k(true, e), "no port of k_out_color_direct") && - has(wgi::dx12_refused_line_k(true, e), "model K has no HIP route") && - has(wgi::dx12_refused_line_k(true, e), "the game keeps its own upscaler") && - !has(wgi::dx12_refused_line_k(true, e), "the HIP executor runs it") && - wgi::dx12_refused_line_k(true, e).find('\n') == std::string::npos); - } - r.model_k = false; - r.sparkle_guard = true; - c = choose_executor(r); - expect("executor=dx12 + sparkle guard -> hip with the earlier warning", - c.executor == "hip" && c.warn && - c.why == "executor=dx12 not available for this context: the sparkle guard runs on HIP only; the HIP " - "executor runs it"); - r.sparkle_guard = false; - r.capture = true; - c = choose_executor(r); - expect("executor=dx12 + capture -> hip", c.executor == "hip" && c.warn && has(c.why, "frame capture")); + r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = model_k; + r.executor = "d3d12"; + expect(std::string("executor=d3d12 = dx12") + tag, choose_executor(r).executor == "dx12"); + r.executor = "d3d12-test"; + expect(std::string("executor=d3d12-test") + tag, choose_executor(r).executor == "d3d12-test"); + r.executor = "vulkan"; + expect(std::string("unknown executor -> empty (create fails)") + tag, choose_executor(r).executor.empty()); } - // the D3D12 executor refuses the context at create (driver-channel probe failure, ...): the HIP executor, one line + + // ---- the D3D12 executor refuses the context at create: every model, the front end's upscaler, never HIP ------------- { const std::string e = "D3D12 device: native D3D12 borrowed driver-channel probe mismatch at float 7"; const std::string d = wgi::dx12_refused_line(true, e), f = wgi::dx12_refused_line(false, e); - expect("probe failure (default): one line naming the default, the reason and the HIP executor", + expect("create refusal (default): one line with the reason, no HIP route, the front end's upscaler", has(d, "executor dx12 (default on RDNA 4) could not take this context") && has(d, "probe mismatch") && - has(d, "the HIP executor runs it")); - expect("probe failure (executor=dx12): the earlier line", - f == "executor=dx12 could not take this context (" + e + "); the HIP executor runs it"); + has(d, "there is no HIP route in a game") && has(d, "the front end's own upscaler (AMD FSR) keeps the game") && + !has(d, "the HIP executor runs it") && d.find('\n') == std::string::npos); + expect("create refusal (executor=dx12): the same", has(f, "executor=dx12 could not take this context") && has(f, "no HIP route")); + const std::string k = "D3D12 runtime: model K: the D3D12 build has no port of k_out_color_direct"; + expect("model K port missing: the same line names it", has(wgi::dx12_refused_line(true, k), "no port of k_out_color_direct")); } - // clean/fe-wrapped-list: hip_switch (what the default D3D12 executor does with a frame it does not take mid-session) + + // ---- clean/fe-wrapped-list: hip_switch, and a frame the D3D12 executor does not take ----------------------------- { using wgi::refused_frame_policy; - expect("hip_switch not named -> the default: off (owner 2026-11-04, no mid-session HIP)", + using wgi::RefusedAction; + expect("hip_switch not named -> the default: off (owner 2026-11-04)", !wgi::kHipSwitchDefault && !refused_frame_policy("").switch_to_hip && refused_frame_policy("").note.empty()); expect("hip_switch=on -> switch", refused_frame_policy("on").switch_to_hip && refused_frame_policy("1").switch_to_hip); expect("hip_switch=off -> no switch", !refused_frame_policy("off").switch_to_hip && !refused_frame_policy("0").switch_to_hip && @@ -228,61 +353,9 @@ int main() { expect("the hip_switch=off line names the frame, the reason, no HIP and the front end's fallback", has(l, "frame 2: executor dx12 (default on RDNA 4) does not take this frame") && has(l, "native direct frame") && has(l, "does not move to the HIP executor") && has(l, "AMD FSR, else its stand-in")); - } - // REVIEW-215b P1-a: model K's executor selection - { - using wgi::RefusedAction; - ExecutorRequest r = gpu("AMD Radeon RX 9070 XT"); - r.model_k = true; - ExecutorChoice c = choose_executor(r); - expect("K auto on RDNA 4 -> dx12 (by default), nothing to log", c.executor == "dx12" && c.by_default && c.why.empty()); - r.sparkle_guard = true; - c = choose_executor(r); - expect("K auto + sparkle guard -> dx12 with the guard turned off, one line", - c.executor == "dx12" && c.by_default && c.sparkle_off && c.warn && has(c.why, "turned off for model K") && - has(c.why, "runs on the D3D12 executor")); - r.executor = "dx12"; - c = choose_executor(r); - expect("K executor=dx12 + sparkle guard -> dx12, guard off", c.executor == "dx12" && c.sparkle_off && c.warn); - r = gpu("AMD Radeon RX 9070 XT"); - r.model_k = true; - r.sparkle_guard = false; - r.capture = true; - c = choose_executor(r); - expect("K auto + capture -> hip with the loud diagnostic line", - c.executor == "hip" && c.warn && c.why == "diagnostic: frame capture forces the HIP executor (model K runs on the " - "D3D12 executor without it)"); - r.executor = "dx12"; - c = choose_executor(r); - expect("K executor=dx12 + capture -> hip, the same diagnostic line", - c.executor == "hip" && c.warn && has(c.why, "diagnostic: frame capture forces the HIP executor")); - r.capture = false; - r.executor = "auto"; - r.sparkle_guard = true; - r.model_k = false; - c = choose_executor(r); - expect("model M + sparkle guard -> hip as before (the guard rule is K's exception only)", - c.executor == "hip" && !c.sparkle_off && has(c.why, "sparkle guard")); - r = gpu("AMD Radeon RX 7900 XTX"); - r.model_k = true; - c = choose_executor(r); - expect("K auto on a non-RDNA 4 adapter: the front end's upscaler, one line", - c.executor == "fsr" && has(c.why, "RX 9000-series GPU; using AMD FSR")); - r = wgi::ExecutorRequest(); - r.model_k = true; - c = choose_executor(r); - expect("K auto on an unidentified adapter: the front end's upscaler, one line", - c.executor == "fsr" && has(c.why, "not identified")); - - // hip_switch: ignored for K, one line when it is set expect("K: no line when hip_switch is not set", wgi::k_hip_switch_note("").empty()); expect("K: hip_switch=on is ignored with one line", - has(wgi::k_hip_switch_note("on"), "model K ignores hip_switch=on") && - has(wgi::k_hip_switch_note("on"), "never to HIP")); - - // REVIEW-215b P1-b: a frame the D3D12 executor did not take. The three paths of the review and the messages the - // executor gives them: no output texture, a render size outside the configured maximum, an unsupported frame (an - // output texture without unordered access); each with hip_switch off and on, by default and forced. + has(wgi::k_hip_switch_note("on"), "model K ignores hip_switch=on") && has(wgi::k_hip_switch_note("on"), "never to HIP")); const char* const refusals[] = { "frame not taken (nothing recorded): no output texture", "frame not taken (nothing recorded): model K direct frame: render size outside the configured maximum", @@ -290,104 +363,27 @@ int main() { }; for (const char* why : refusals) { const std::string w = why; - expect(("refused frame recognised: " + w).c_str(), wgi::frame_refused(w)); - for (bool by_default : {true, false}) { - for (bool hip_switch : {false, true}) { - const std::string tag = w.substr(0, 40) + (by_default ? " default" : " forced") + (hip_switch ? " switch=on" : " switch=off"); - // no counter, no state: every refused K frame is answered the same way (WG_ERROR_UNSUPPORTED), whatever came before - expect(("K refused frame -> WG_ERROR_UNSUPPORTED, the front end's upscaler: " + tag).c_str(), + expect("refused frame recognised: " + w, wgi::frame_refused(w)); + for (bool by_default : {true, false}) + for (bool hip_switch : {false, true}) + expect("K refused frame -> WG_ERROR_UNSUPPORTED, the front end's upscaler: " + w.substr(0, 40) + + (by_default ? " default" : " forced") + (hip_switch ? " switch=on" : " switch=off"), wgi::refused_frame_action(true, by_default, hip_switch) == RefusedAction::kNoSwitch); - } - } } expect("a frame that is not a refusal is not a 'frame not taken'", !wgi::frame_refused("input refused: texture format") && !wgi::frame_refused("model K: kernel failed")); - // the other models keep their rules - expect("M default + hip_switch=on -> switch to HIP (the 0.6.0 option)", + expect("M default + hip_switch=on -> switch to HIP (the explicit 0.6.0 option)", wgi::refused_frame_action(false, true, true) == RefusedAction::kSwitchToHip); - expect("M default + hip_switch=off -> front end's upscaler", - wgi::refused_frame_action(false, true, false) == RefusedAction::kNoSwitch); + expect("M default + hip_switch=off -> front end's upscaler", wgi::refused_frame_action(false, true, false) == RefusedAction::kNoSwitch); expect("M executor=dx12 -> bilinear fallback", wgi::refused_frame_action(false, false, true) == RefusedAction::kBilinear); + expect("K and M (hip_switch=off) take the same path: the same action", + wgi::refused_frame_action(true, true, true) == wgi::refused_frame_action(false, true, false)); const std::string rl = wgi::k_refusal_line(7, "frame not taken (nothing recorded): no output texture"); expect("the refusal line names the frame, the reason, the front end's upscaler and 'never to the HIP executor'", has(rl, "frame 7: model K") && has(rl, "no output texture") && has(rl, "AMD FSR, else its stand-in") && has(rl, "never to the HIP executor") && rl.find('\n') == std::string::npos); - expect("K and M (hip_switch=off) take the same path: the same action", - wgi::refused_frame_action(true, true, true) == wgi::refused_frame_action(false, true, false)); - } - // R1 (oversight 2026-11-15): the GPU's identity comes from the system's DXGI and the kernel-mode driver's ids, never from - // a description a layer in the game (OptiScaler's GPU spoofing) presents. A real RX 9000 keeps WrongGPU whatever name it - // is shown under; another board, or no identity at all, goes to the front end's upscaler with the one line. - { - const char* const sentence = "WrongGPU's models need an RX 9000-series GPU; using AMD FSR"; - for (uint32_t id : {0x7550u, 0x7551u, 0x7590u, 0x7591u}) - expect("RDNA 4 device id", wgrt::rdna4_device_id(id)); - for (uint32_t id : {0x744Cu, 0x73BFu, 0x7480u, 0x164Eu, 0x13C0u, 0u}) - expect("not an RDNA 4 device id", !wgrt::rdna4_device_id(id)); - auto spoof = [](const char* shown, uint32_t shown_vendor, uint32_t kvendor, uint32_t kdevice) { - ExecutorRequest r = gpu(shown, shown_vendor); - r.kmt_known = true; - r.kmt_vendor = kvendor; - r.kmt_device = kdevice; - return r; - }; - // a SPOOFED name on a real RX 9000 id: still the D3D12 executor, WrongGPU active, nothing to log (every model) - ExecutorRequest r = spoof("Other Vendor Graphics 4090", 0x10DE, 0x1002, 0x7550); - ExecutorChoice c = choose_executor(r); - expect("spoofed other-vendor name on a real RX 9070 id -> dx12", c.executor == "dx12" && c.by_default && c.why.empty()); - r.model_k = true; - expect("the same, model K -> dx12", choose_executor(r).executor == "dx12"); - r = spoof("AMD Radeon RX 7900 XTX", 0x1002, 0x1002, 0x7590); - expect("spoofed RDNA 3 name on a real RX 9060 id -> dx12", choose_executor(r).executor == "dx12"); - r = spoof("Microsoft Basic Render Driver", 0x1414, 0x1002, 0x7551); - r.software = true; - expect("a software-looking description on a real RDNA 4 id -> dx12 (the driver's id decides)", choose_executor(r).executor == "dx12"); - // the driver's ids name the board; the description reported by the system's DXGI agrees - r = spoof("AMD Radeon RX 9070 XT", 0x1002, 0x1002, 0x7550); - expect("real RX 9070 XT: dx12", choose_executor(r).executor == "dx12"); - // a real non-RDNA-4 id: the front end's upscaler with the one line - r = spoof("AMD Radeon RX 7900 XTX", 0x1002, 0x1002, 0x744C); - c = choose_executor(r); - expect("real RDNA 3 id -> fsr with the line", c.executor == "fsr" && c.warn && c.why.rfind(sentence, 0) == 0); - r = spoof("Other Vendor Graphics 4070", 0x10DE, 0x10DE, 0x2786); - expect("real other-vendor id -> fsr", choose_executor(r).executor == "fsr"); - // an unidentified adapter: no description, no driver ids - c = choose_executor(ExecutorRequest()); - expect("nothing known -> fsr with the line and 'not identified'", - c.executor == "fsr" && c.why.rfind(sentence, 0) == 0 && has(c.why, "adapter not identified")); - // only the driver's ids known (the system DXGI could not be read) - r = ExecutorRequest(); - r.kmt_known = true; - r.kmt_vendor = 0x1002; - r.kmt_device = 0x744C; - c = choose_executor(r); - expect("only a real RDNA 3 id known -> fsr, the line names the ids", c.executor == "fsr" && has(c.why, "PCI 1002:744C")); - r.kmt_device = 0x7550; - expect("only a real RX 9070 id known -> dx12", choose_executor(r).executor == "dx12"); - // the pure rule - wgrt::AdapterIdentity id; - expect("identity: nothing known -> not RDNA 4", !wgrt::rdna4_identity(id)); - id.dxgi_known = true; - id.dxgi_vendor = 0x1002; - id.description = "AMD Radeon RX 9060 XT"; - expect("identity: the system DXGI's description alone (no driver ids) -> RDNA 4", wgrt::rdna4_identity(id)); - id.software = true; - expect("identity: a software adapter is not RDNA 4", !wgrt::rdna4_identity(id)); - // forced executors are not affected by the identity (a forced dx12 on a real RX 9000 under a spoof stays dx12) - r = spoof("Other Vendor Graphics 4090", 0x10DE, 0x1002, 0x7550); - r.executor = "dx12"; - expect("executor=dx12 under a spoof on a real RX 9000 -> dx12", choose_executor(r).executor == "dx12" && !choose_executor(r).by_default); - r.executor = "hip"; - expect("executor=hip under a spoof -> the loud diagnostic", choose_executor(r).executor == "hip" && choose_executor(r).warn); - } - // test executor and unknown values - { - ExecutorRequest r = gpu("AMD Radeon RX 9070 XT"); - r.executor = "d3d12-test"; - expect("executor=d3d12-test", choose_executor(r).executor == "d3d12-test"); - r.executor = "vulkan"; - expect("unknown executor -> empty (create fails)", choose_executor(r).executor.empty()); } + std::printf(failures ? "%d FAILED\n" : "ALL TESTS PASSED\n", failures); return failures ? 1 : 0; } diff --git a/clean/runtime/interop/tests/test_interop_d3d12.cpp b/clean/runtime/interop/tests/test_interop_d3d12.cpp index c40c7042..96a22c67 100644 --- a/clean/runtime/interop/tests/test_interop_d3d12.cpp +++ b/clean/runtime/interop/tests/test_interop_d3d12.cpp @@ -1846,6 +1846,21 @@ bool case_dx12_same(Gpu& g, const char* dll, const std::string& common, int fram w ? " (through a device wrapper)" : ""); if (w) w->Release(); // the context holds its own references CHECK(debug_messages(g, mode ? "dx12 create" : "hip create") == 0); + // WG_TEST_EXPECT=refused (R1): the D3D12 executor cannot take this context and create answers WG_ERROR_UNSUPPORTED with + // one line, no HIP executor and no context: the front end's upscaler keeps the game + { + const char* ex0 = std::getenv("WG_TEST_EXPECT"); + if (mode == 1 && ex0 && std::string(ex0) == "refused") { + bool line = false, hip_started = false; + for (const auto& m : g_log) { + line |= m.find("could not take this context") != std::string::npos && m.find("no HIP route") != std::string::npos; + hip_started |= m.find("about to start the HIP runtime") != std::string::npos; + } + std::printf(" second context: create %d, refusal line %d, HIP started %d\n", (int)r, (int)line, (int)hip_started); + CHECK(r == WG_ERROR_UNSUPPORTED && line && !hip_started); + return true; + } + } CHECK(r == WG_OK); if (r != WG_OK) return false; for (int t = 1; t <= frames; ++t) { @@ -1881,8 +1896,7 @@ bool case_dx12_same(Gpu& g, const char* dll, const std::string& common, int fram } // WG_TEST_EXPECT (second context): dx12 (default: the D3D12 executor ran every frame and wrote the output), switch // (the default executor met a frame it does not take and the HIP executor took over the context; since the owner's - // decision of 2026-11-04 only with hip_switch=on in the options), hip (the HIP executor from create on, after the - // D3D12 executor refused the context) + // decision of 2026-11-04 only with hip_switch=on in the options), refused (create answered WG_ERROR_UNSUPPORTED, above) const char* ex = std::getenv("WG_TEST_EXPECT"); const std::string expect = ex ? ex : "dx12"; if (mode == 1 && expect != "dx12") { @@ -1895,8 +1909,8 @@ bool case_dx12_same(Gpu& g, const char* dll, const std::string& common, int fram } std::printf(" second context: ready dx12 %d, ready hip %d, switched to HIP %d, refused at create %d\n", (int)ready_dx12, (int)ready_hip, (int)switched, (int)refused); - if (expect == "switch") CHECK(ready_dx12 && switched && !refused); - else CHECK(ready_hip && refused && !switched); + CHECK(expect == "switch"); // (any other value is a typo: "refused" returned above) + CHECK(ready_dx12 && switched && !refused && !ready_hip); } if (mode == 1 && expect == "dx12") { bool ran = false, direct_in = false, wrote = false; diff --git a/clean/runtime/rdna4.h b/clean/runtime/rdna4.h index d74d6951..3e86efee 100644 --- a/clean/runtime/rdna4.h +++ b/clean/runtime/rdna4.h @@ -1,48 +1,104 @@ // SPDX-License-Identifier: MIT -// The adapters Model M's D3D12 path runs on: AMD RDNA 4 (gfx1200 / gfx1201) Radeon RX 9070 and RX 9060 series. -// WrongGPU's own code. One rule for every place that asks: the native D3D12 device (device_d3d12.cpp, borrowed and -// own device) refuses other adapters, and the interop's executor choice (interop/executor_select.h) makes the D3D12 -// executor the default on exactly these. The driver-channel WMMA ports are qualified only on this target; the -// device's driver-channel probe (native_driver_probe) still has to pass on it at create. -// Identification as DXGI reports the adapter: vendor 0x1002, a hardware adapter (not DXGI_ADAPTER_FLAG_SOFTWARE), and -// a description naming an RX 9070 or RX 9060 board (RX 9070 XT / 9070 / 9070 GRE: gfx1201; RX 9060 XT / 9060: gfx1200). +// The adapters WrongGPU's networks run on: AMD RDNA 4 (gfx1200 / gfx1201) Radeon RX 9070 and RX 9060 series. +// WrongGPU's own code. One rule for every place that asks: the native D3D12 device (device_d3d12.cpp, borrowed and own +// device), the interop's executor choice (interop/executor_select.h, backend.cpp) and the Ray Reconstruction runtime +// (rr_f/runtime). The driver-channel WMMA ports are qualified only on this target; the device's driver-channel probe +// (native_driver_probe) still has to pass on it at create. +// +// Identity is decided by the adapter's PCI VENDOR and DEVICE id as the kernel-mode driver reports them, and by nothing +// else (R1, oversight 2026-11-15; R1-AUDIT H8). A description or a vendor id read through the game's dxgi.dll can be +// rewritten by a layer in the game process (OptiScaler's GPU spoofing), and a name tells nothing about the silicon, so no +// name ever accepts or rejects an adapter; the system DXGI's description is read only to be shown in a log line. The rule +// FAILS CLOSED: an adapter whose ids could not be read, or whose ids are not RDNA 4's, is not RDNA 4, and the caller hands +// the game to the front end's upscaler (AMD FSR) with one line that carries the ids, so that an RDNA 4 board missing from +// the list below shows up in a log and can be added. (The AMD AGS library's family query would be a second, family-level +// source; it is not part of this project's build, see the notes of the R1 pull request.) +// +// Header only and portable: the lookup takes its two sources as functions (AdapterSources), so that tests run on any host +// with fakes; rdna4_win.h supplies the system's. #pragma once #include +#include +#include #include +#include namespace wgrt { -inline bool rdna4_adapter(uint32_t vendor_id, bool software, const std::string& description) { - return vendor_id == 0x1002 && !software && - (description.find("RX 9070") != std::string::npos || description.find("RX 9060") != std::string::npos); -} - -// RDNA 4 PCI device ids (Navi 48: RX 9070 XT / 9070 / 9070 GRE; Navi 44: RX 9060 XT / 9060), the same list as the -// Ray Reconstruction runtime's (clean/rr_f/runtime/src/rr_runtime.cpp). +// RDNA 4 PCI device ids (Navi 48: RX 9070 XT / 9070 / 9070 GRE; Navi 44: RX 9060 XT / 9060), the Ray Reconstruction +// runtime's list, now the only one. AMD's vendor id is 0x1002. inline bool rdna4_device_id(uint32_t device) { return device == 0x7550 || device == 0x7551 || device == 0x7590 || device == 0x7591; } -// What is known about an adapter, from sources another layer in the game process cannot rewrite (rdna4_win.h reads -// them): the system's own DXGI (description, vendor id, software flag) and the kernel-mode driver's vendor and device id. -// OptiScaler's GPU spoofing rewrites what the GAME's dxgi.dll reports, so a description read there is never used. +struct AdapterLuid { + uint32_t low = 0; + int32_t high = 0; + bool operator==(const AdapterLuid& o) const { return low == o.low && high == o.high; } +}; + +// An adapter the system's DXGI lists (its description is for log lines only). +struct AdapterRecord { + AdapterLuid luid; + uint32_t vendor = 0; + bool software = false; + std::string description; +}; + +// What is known about one adapter. struct AdapterIdentity { - bool dxgi_known = false; // the system's DXGI described the adapter + bool dxgi_known = false; // the system's DXGI listed the adapter (never the game's dxgi.dll): for log lines only uint32_t dxgi_vendor = 0; bool software = false; std::string description; - bool kmt_known = false; // the kernel-mode driver's ids were read + bool kmt_known = false; // the kernel-mode driver's ids were read: the only evidence that decides uint32_t kmt_vendor = 0, kmt_device = 0; }; -// An RDNA 4 Radeon RX 9000-series board: the driver's own ids first (a real RX 9000 is one whatever name a layer -// presents, a spoofed name on another board is not one), else the system DXGI's description (rdna4_adapter). Nothing -// known: not identified, so not RDNA 4. +// The two sources (injectable; rdna4_win.h: the system's own DXGI by its full path, and D3DKMTQueryAdapterInfo). +struct AdapterSources { + std::function find_adapter; // system DXGI, by LUID + std::function driver_ids; // kernel-mode driver, by LUID +}; + +// The adapter with this LUID (the game device's): the same LUID goes to both sources, nothing is guessed; what a source +// cannot answer stays unknown. +inline AdapterIdentity lookup_adapter(const AdapterLuid& luid, const AdapterSources& s) { + AdapterIdentity id; + AdapterRecord rec; + if (s.find_adapter && s.find_adapter(luid, &rec)) { + id.dxgi_known = true; + id.dxgi_vendor = rec.vendor; + id.software = rec.software; + id.description = rec.description; + } + if (s.driver_ids) id.kmt_known = s.driver_ids(luid, &id.kmt_vendor, &id.kmt_device); + return id; +} + +// An RDNA 4 Radeon RX 9000-series board: the driver's vendor and device id, nothing else; unknown ids are not RDNA 4. inline bool rdna4_identity(const AdapterIdentity& a) { - if (a.kmt_known && a.kmt_vendor == 0x1002 && rdna4_device_id(a.kmt_device)) return true; - if (a.dxgi_known) return rdna4_adapter(a.dxgi_vendor, a.software, a.description) && (!a.kmt_known || a.kmt_vendor == 0x1002); - return false; + return a.kmt_known && a.kmt_vendor == 0x1002 && rdna4_device_id(a.kmt_device); } +// The adapter as a log line shows it: the system DXGI's description when it has one, the driver's ids when known, and the +// words "not identified" when neither is. +inline std::string describe_identity(const AdapterIdentity& a) { + char ids[32] = ""; + if (a.kmt_known) std::snprintf(ids, sizeof ids, "PCI %04X:%04X", (unsigned)a.kmt_vendor, (unsigned)a.kmt_device); + std::string s; + if (a.dxgi_known) s = "adapter " + (a.description.empty() ? std::string("(no name)") : a.description); + if (a.kmt_known) s += (s.empty() ? "adapter " : ", ") + std::string(ids); + if (s.empty()) s = "adapter not identified"; + if (a.kmt_known && a.kmt_vendor == 0x1002 && !rdna4_device_id(a.kmt_device)) + s += "; an AMD board outside the RDNA 4 id list"; + return s; +} + +// The sentence every refusal of a GPU that is not RDNA 4 (or not identified) starts with: the runtime's log line when it +// hands the game to AMD FSR, the Ray Reconstruction runtime's, and the launcher's (clean/installer wg_core +// NeedsRx9000Sentence is the same words). +inline const char* needs_rx9000_sentence() { return "WrongGPU's models need an RX 9000-series GPU; using AMD FSR"; } + } // namespace wgrt diff --git a/clean/runtime/rdna4_win.h b/clean/runtime/rdna4_win.h index 9c334ad2..d92edcd9 100644 --- a/clean/runtime/rdna4_win.h +++ b/clean/runtime/rdna4_win.h @@ -1,19 +1,17 @@ // SPDX-License-Identifier: MIT -// The identity of the adapter a D3D12 device runs on, read where another layer in the game process cannot rewrite it -// (R1, oversight 2026-11-15; R1-AUDIT H8). WrongGPU's own code. Header only, Windows only: every caller (the interop -// backend's executor choice, the native D3D12 device) includes it; nothing here needs an import library (the kernel-mode +// The system's sources for an adapter's identity (rdna4.h has the rule and the injectable lookup). R1, oversight +// 2026-11-15; R1-AUDIT H8. WrongGPU's own code. Header only, Windows only: the interop backend's executor choice, the +// native D3D12 device and the Ray Reconstruction runtime include it; nothing here needs an import library (the kernel-mode // thunks come from gdi32.dll at run time), so the many small test builds of device_d3d12.cpp link as before. // // Why: OptiScaler (and other proxies) can sit in the game folder as dxgi.dll and rewrite DXGI's adapter description and // vendor id, to make a game offer another vendor's options (the launcher's GPU-report switch in its OptiScaler tab; an -// experimental RR game profile). Reading the adapter through the game's dxgi.dll then shows another GPU, and a real RX 9000 -// would lose WrongGPU. Two sources are used instead: -// - the system's own DXGI: \dxgi.dll loaded by its full path (a bare "dxgi.dll", with or without -// LOAD_LIBRARY_SEARCH_SYSTEM32, returns a proxy that is already loaded under that name), enumerated by the device's -// LUID; -// - the kernel-mode driver's vendor and device id for that LUID (D3DKMTQueryAdapterInfo, PHYSICALADAPTERDEVICEIDS), -// which does not go through DXGI at all. -// wgrt::rdna4_identity (rdna4.h) decides from them. +// experimental RR game profile). Two sources a layer in the game process does not reach are used: +// - the kernel-mode driver's vendor and device id for the adapter's LUID (D3DKMTQueryAdapterInfo, +// PHYSICALADAPTERDEVICEIDS), which does not go through DXGI at all: this decides; +// - the system's own DXGI, \dxgi.dll loaded by its full path (a bare "dxgi.dll", with or without +// LOAD_LIBRARY_SEARCH_SYSTEM32, returns a proxy that is already loaded under that name), enumerated by the same LUID: +// its description is shown in log lines, it never decides. #pragma once #include @@ -52,9 +50,23 @@ struct CloseAdapter { constexpr UINT kPhysicalAdapterDeviceIds = 31; } // namespace kmt +inline AdapterLuid to_luid(const LUID& l) { + AdapterLuid r; + r.low = l.LowPart; + r.high = l.HighPart; + return r; +} + +inline LUID to_win_luid(const AdapterLuid& l) { + LUID r; + r.LowPart = l.low; + r.HighPart = l.high; + return r; +} + // The kernel-mode driver's PCI vendor and device id of the adapter with this LUID. False when the query is not -// available (Wine without the thunks, a software adapter, a refused call). -inline bool driver_device_ids(const LUID& luid, uint32_t* vendor, uint32_t* device) { +// available (Wine without the thunks, a refused call). +inline bool driver_device_ids(const AdapterLuid& luid, uint32_t* vendor, uint32_t* device) { using OpenFn = LONG(WINAPI*)(kmt::OpenAdapterFromLuid*); using QueryFn = LONG(WINAPI*)(kmt::QueryAdapterInfo*); using CloseFn = LONG(WINAPI*)(kmt::CloseAdapter*); @@ -66,7 +78,7 @@ inline bool driver_device_ids(const LUID& luid, uint32_t* vendor, uint32_t* devi auto close = reinterpret_cast(reinterpret_cast(GetProcAddress(gdi, "D3DKMTCloseAdapter"))); if (!open || !query || !close) return false; kmt::OpenAdapterFromLuid o = {}; - o.AdapterLuid = luid; + o.AdapterLuid = to_win_luid(luid); if (open(&o) != 0) return false; kmt::QueryDeviceIds ids = {}; kmt::QueryAdapterInfo q = {}; @@ -100,8 +112,8 @@ inline HMODULE load_system_dll(const wchar_t* name) { return LoadLibraryW(path.c_str()); } -// The adapter with this LUID as the SYSTEM's DXGI describes it (never the game's dxgi.dll). -inline bool system_dxgi_description(const LUID& luid, uint32_t* vendor, bool* software, std::string* description) { +// The adapter with this LUID as the SYSTEM's DXGI describes it (never the game's dxgi.dll): for log lines. +inline bool system_dxgi_adapter(const AdapterLuid& luid, AdapterRecord* out) { HMODULE dxgi = load_system_dll(L"dxgi.dll"); if (!dxgi) return false; using MakeFactory = HRESULT(WINAPI*)(REFIID, void**); @@ -111,13 +123,14 @@ inline bool system_dxgi_description(const LUID& luid, uint32_t* vendor, bool* so IDXGIFactory4* f = nullptr; if (SUCCEEDED(create(__uuidof(IDXGIFactory4), reinterpret_cast(&f))) && f) { IDXGIAdapter1* a = nullptr; - if (SUCCEEDED(f->EnumAdapterByLuid(luid, __uuidof(IDXGIAdapter1), reinterpret_cast(&a))) && a) { + if (SUCCEEDED(f->EnumAdapterByLuid(to_win_luid(luid), __uuidof(IDXGIAdapter1), reinterpret_cast(&a))) && a) { DXGI_ADAPTER_DESC1 d = {}; if (SUCCEEDED(a->GetDesc1(&d))) { ok = true; - *vendor = d.VendorId; - *software = (d.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0; - *description = wide_to_utf8(d.Description); + out->luid = to_luid(d.AdapterLuid); + out->vendor = d.VendorId; + out->software = (d.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0; + out->description = wide_to_utf8(d.Description); } a->Release(); } @@ -126,12 +139,17 @@ inline bool system_dxgi_description(const LUID& luid, uint32_t* vendor, bool* so return ok; } -// Everything the executor choice and the native device need to know about the adapter with this LUID. +inline AdapterSources system_sources() { + AdapterSources s; + s.find_adapter = system_dxgi_adapter; + s.driver_ids = driver_device_ids; + return s; +} + +// Everything the executor choice, the native device and the RR runtime need to know about the adapter with this LUID +// (the game device's GetAdapterLuid()). inline AdapterIdentity read_adapter_identity(const LUID& luid) { - AdapterIdentity id; - id.dxgi_known = system_dxgi_description(luid, &id.dxgi_vendor, &id.software, &id.description); - id.kmt_known = driver_device_ids(luid, &id.kmt_vendor, &id.kmt_device); - return id; + return lookup_adapter(to_luid(luid), system_sources()); } } // namespace wgrt diff --git a/clean/tests/test_executor_select.py b/clean/tests/test_executor_select.py new file mode 100644 index 00000000..a9bde820 --- /dev/null +++ b/clean/tests/test_executor_select.py @@ -0,0 +1,141 @@ +# SPDX-License-Identifier: MIT +"""R1: which executor runs a context, and who is an RDNA 4 GPU (clean/runtime/interop/executor_select.h, clean/runtime/rdna4.h). + +No GPU: clean/runtime/interop/tests/test_executor_select.cpp is built with the host C++ compiler (CXX, clang++ or g++; on +Windows MSVC cl after them, from PATH or through vcvars64.bat; skipped without one) and run. It covers the identity rule (the +kernel-mode driver's vendor and device id, nothing else, failing closed), the lookup with injectable sources (the game +device's LUID selects the adapter among several, a spoofed name on an RX 9000 id, a supported-looking name on another id, +a failing driver query or DXGI), the executor choice for every model, the diagnostics, the sparkle guard and the refusal +paths. + +The create path itself needs a D3D12 device, so its ORDER is pinned from the source here: Context::create answers +WG_ERROR_UNSUPPORTED for an adapter that is not RDNA 4 (or not identified) before any converter, kernel, HIP or D3D12 +executor is made, a D3D12 refusal of any model is the same answer and never builds the HIP executor, and the RR runtime +and the native device identify the adapter by the shared id rule before anything is created. + +Run: python -m unittest clean.tests.test_executor_select +""" +import os +import re +import shutil +import subprocess +import tempfile +import unittest + +ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +TEST = os.path.join("clean", "runtime", "interop", "tests", "test_executor_select.cpp") + + +def read(*p): + with open(os.path.join(ROOT, *p), encoding="utf-8") as f: + return f.read() + + +def _vcvars64(): + vswhere = os.path.join(os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)"), + "Microsoft Visual Studio", "Installer", "vswhere.exe") + if not os.path.exists(vswhere): + return None + r = subprocess.run([vswhere, "-latest", "-products", "*", "-property", "installationPath"], capture_output=True, + text=True) + vcvars = os.path.join(r.stdout.strip(), "VC", "Auxiliary", "Build", "vcvars64.bat") + return vcvars if r.returncode == 0 and r.stdout.strip() and os.path.exists(vcvars) else None + + +def _build(exe): + cxx = os.environ.get("CXX") or shutil.which("clang++") or shutil.which("g++") + if cxx: + cmd = [cxx, "-std=c++17", "-O1", os.path.join(ROOT, TEST), "-o", exe] + return subprocess.run(cmd, capture_output=True, text=True) + vcvars = None if shutil.which("cl") else _vcvars64() + if os.name != "nt" or not (shutil.which("cl") or vcvars): + raise unittest.SkipTest("no host C++ compiler (CXX, clang++, g++ or MSVC cl)") + objdir = os.path.join(os.path.dirname(exe), "obj") + os.makedirs(objdir, exist_ok=True) + cl = 'cl /nologo /std:c++17 /O1 /EHsc /utf-8 /D_CRT_SECURE_NO_WARNINGS "%s" /Fo"%s\\\\" /Fe"%s"' % ( + os.path.join(ROOT, TEST), objdir, exe) + bat = exe + ".bat" + with open(bat, "w") as f: + f.write("@echo off\r\n") + if vcvars: + f.write('call "%s" >nul || exit /b 1\r\n' % vcvars) + f.write(cl + " || exit /b 1\r\n") + return subprocess.run(["cmd", "/d", "/c", bat], capture_output=True, text=True) + + +class ExecutorSelect(unittest.TestCase): + def test_cpp_cases(self): + tmp = tempfile.mkdtemp(prefix="wg_es_") + exe = os.path.join(tmp, "test_executor_select" + (".exe" if os.name == "nt" else "")) + r = _build(exe) + self.assertEqual(r.returncode, 0, "build failed:\n" + r.stdout + r.stderr) + r = subprocess.run([exe], capture_output=True, text=True) + self.assertEqual(r.returncode, 0, "\n".join(l for l in r.stdout.splitlines() if l.startswith("FAIL")) + r.stderr) + self.assertIn("ALL TESTS PASSED", r.stdout) + self.assertGreater(r.stdout.count("pass "), 100) + + +class CreateOrder(unittest.TestCase): + """The order of Context::create (backend.cpp): a pin on the source, as the create needs a D3D12 device.""" + + def setUp(self): + self.b = read("clean", "runtime", "interop", "backend.cpp") + + def at(self, text, start=0): + i = self.b.find(text, start) + self.assertGreaterEqual(i, 0, text) + return i + + def test_unsupported_adapter_before_anything_is_made(self): + refuse = self.at('if (ch.executor == "fsr") return WG_ERROR_UNSUPPORTED;') + for later in ("conv_.init(", "configure_hip(", "make_hip_executor(", "make_d3d12_executor(", "make_shared_objects(", + "make_test_executor("): + self.assertLess(refuse, self.at(later, refuse), later + " comes before the unsupported answer") + # the decision itself is made from the game device's LUID: the system DXGI and the driver's ids (all three models: + # the choice does not look at the model, only at the identity) + self.assertIn("adapter_info(device_, &q.adapter, &q.vendor_id, &q.software, &ident)", self.b) + self.assertIn("wgrt::read_adapter_identity(device->GetAdapterLuid())", self.b) + + def test_d3d12_refusal_is_the_front_end_fallback_for_every_model(self): + self.assertIn("return fail(WG_ERROR_UNSUPPORTED, dx12_refused_line(dx12_default_, err));", self.b) + self.assertNotIn("dx12_refused_line_k", self.b) + self.assertNotIn("the HIP executor runs it", read("clean", "runtime", "interop", "executor_select.h")) + # the HIP executor is made in two places only: at create for the explicit diagnostics (executor=hip, the frame + # capture), and in switch_to_hip, which only an explicit hip_switch=on reaches (never model K) + self.assertEqual(self.b.count("make_hip_executor("), 2) + branch = self.at("if (!dx12 && !exec_) {") + first = self.at("make_hip_executor(") + self.assertLess(branch, first) + self.assertGreater(self.at("make_hip_executor(", first + 1), self.at("bool switch_to_hip(")) + refusal = self.at("dx12_refused_line(dx12_default_, err)") + self.assertLess(refusal, branch) + # the refusal returns: nothing between it and the HIP branch resets the D3D12 executor to fall through + self.assertNotIn("exec_.reset();", self.b[refusal:branch]) + + def test_rr_and_native_device_use_the_shared_id_rule(self): + rr = read("clean", "rr_f", "runtime", "src", "rr_runtime.cpp") + self.assertIn('#include "../../../runtime/rdna4_win.h"', rr) + self.assertNotIn("bool rdna4_adapter(", rr) + self.assertNotIn("kmt_device_ids", rr) + self.assertNotIn('find("RX 90', rr) + # set-device: the identity check comes before the compute queue (nothing is created for another GPU) + start = rr.index("rt.device_failed = true;\n std::string err;") + check = rr.index("wgrt::rdna4_identity(id)", start) + self.assertLess(check, rr.index("CreateCommandQueue(&qd", start)) + self.assertIn("wgrt::needs_rx9000_sentence()", rr[check:check + 400]) + dev = read("clean", "runtime", "device_d3d12.cpp") + self.assertNotIn("rdna4_adapter(", dev) + self.assertEqual(dev.count("wgrt::rdna4_identity("), 2) + self.assertNotIn('LoadLibraryExW(L"dxgi.dll"', dev) + + def test_no_name_rule_left(self): + h = read("clean", "runtime", "rdna4.h") + self.assertNotIn("RX 9070", re.sub(r"//[^\n]*", "", h)) + self.assertNotIn("find(", re.sub(r"//[^\n]*", "", h)) + w = read("clean", "runtime", "rdna4_win.h") + self.assertIn("GetSystemDirectoryW", w) + self.assertNotIn('LoadLibraryW(L"dxgi.dll")', w) + + +if __name__ == "__main__": + unittest.main() From 9584e52c594d3202365fa9cf884fb5b77d4abcf5 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:41:07 -0500 Subject: [PATCH 03/20] R1: hip_switch is ignored for every model (one line); no move to HIP in a game The 0.6.0 option hip_switch=on moved a model M or L context to the HIP executor for good. Under R1 the only HIP left is an explicit executor=hip and the frame capture, so the option is ignored for models M, L and K alike, with one log line at create. The switch code, its retired-executor bookkeeping and the policy type are gone; the selector tests and a source pin cover the three models. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/README.md | 8 +- clean/fsr/src/frontend.cpp | 2 +- clean/fsr/tests/test_frontend.cpp | 6 +- clean/runtime/interop/backend.cpp | 114 ++---------------- clean/runtime/interop/executor_select.h | 69 ++++------- .../interop/tests/test_executor_select.cpp | 77 ++++++++---- .../interop/tests/test_interop_d3d12.cpp | 17 +-- clean/tests/test_executor_select.py | 23 +++- 8 files changed, 128 insertions(+), 188 deletions(-) diff --git a/clean/fsr/README.md b/clean/fsr/README.md index 278cff08..9213ea9c 100644 --- a/clean/fsr/README.md +++ b/clean/fsr/README.md @@ -266,10 +266,10 @@ OptiScaler folder ships `amd_fidelityfx_upscaler_dx12.dll`; OptiScaler.ini `[Lib otherwise it is refused with one line and the context gets AMD's FSR (else the stand-in). WrongGPU's queue is never made on another device (`test_wrapped_list` case F). The front end writes its log to disk right after an upscaler's `about to ...` line (HIP start-up, the shared-memory import) and before the first split's submission. -- **Frames the upscaler does not take:** `WG_ERROR_UNSUPPORTED` from the upscaler's dispatch (the network runtime with - `hip_switch=off`, its default since 2026-11-04: frames above the render size checked at create) hands the context to - AMD's FSR at once; - without AMD's FSR the stand-in upscales such frames. +- **Frames the upscaler does not take:** `WG_ERROR_UNSUPPORTED` from the upscaler's dispatch (the network runtime's + D3D12 executor: frames above the render size checked at create) hands the context to AMD's FSR at once; without + AMD's FSR the stand-in upscales such frames. No model moves to the HIP executor in a game; the old option + `hip_switch=on` is ignored with one log line. - **Model location:** the front end looks for the converted model (`model.wgcm`, Model K in `K\`) in `[fsr] model_dir` of `wronggpu.ini` (relative: from the data folder), then `\WrongGPU\model`, and passes the first folder that has it to the runtime as `model_dir=`; otherwise the runtime's own default (`%LOCALAPPDATA%\WrongGPU\model`, diff --git a/clean/fsr/src/frontend.cpp b/clean/fsr/src/frontend.cpp index ace7a686..bf7ddadc 100644 --- a/clean/fsr/src/frontend.cpp +++ b/clean/fsr/src/frontend.cpp @@ -1619,7 +1619,7 @@ ffxReturnCode_t FrontEnd::DispatchUpscale(UpscaleContext& u, const ffxDispatchDe problem = std::string("upscaler \"") + u.backend->name + "\" dispatch failed: " + WgResultText(r); if (platform_.diagnosticFailure) platform_.diagnosticFailure(u.id, frameIndex, u.device); // clean/fe-wrapped-list: WG_ERROR_UNSUPPORTED from the upscaler itself: it does not take this context's frames - // (the network runtime with hip_switch=off when its D3D12 executor refuses a frame, e.g. native resolution). + // (the network runtime when its D3D12 executor refuses a frame, e.g. native resolution). // AMD's FSR takes the context over now; without it the stand-in upscales such frames (below) and the context // stays the upscaler's. Said once per context. if (r == WG_ERROR_UNSUPPORTED && !u.unsupportedSaid) { diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index e38a0c55..5e733173 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -2349,7 +2349,7 @@ static void TestHostVersionHandling() { // backend that needs the split goes to AMD's FSR with one line in the log; without AMD the backend keeps being asked // (its split answers WG_ERROR_NOT_READY and the stand-in draws); a backend that needs no split is not affected. // clean/fe-wrapped-list: frames the upscaler does not take (WG_ERROR_UNSUPPORTED, the network runtime with -// hip_switch=off at native resolution): AMD's FSR takes the context over at once; without it the stand-in upscales +// no HIP switch, at native resolution): AMD's FSR takes the context over at once; without it the stand-in upscales // those frames and the context stays WrongGPU's. And an upscaler's "about to ..." line flushes the log. static void TestUnsupportedFrames() { Reset(); @@ -2393,7 +2393,7 @@ static void TestUnsupportedFrames() { } // REVIEW-215c: a refused frame of model K takes the same front-end path as model M's. The backend's answer comes from the -// real policy (wgi::refused_frame_action, executor_select.h: a refused K frame, and a refused M frame with hip_switch=off, +// real policy (wgi::refused_frame_action, executor_select.h: a refused K frame, and a refused M frame, // are answered WG_ERROR_UNSUPPORTED, never a switch to HIP and never a bilinear fallback), the fake upscaler answers // that for the refused frames, and the front end must give every frame an upscaler: AMD's FSR when it exists (it takes // the context over at the first refusal, as for model M), else the stand-in for each refused frame (any number in a row, @@ -2401,7 +2401,7 @@ static void TestUnsupportedFrames() { static void TestRefusedFrames() { for (const bool model_k : {true, false}) { // model K, and model M as the control const bool unsupported = - wgi::refused_frame_action(model_k, /*by_default=*/true, /*hip_switch=*/false) == wgi::RefusedAction::kNoSwitch; + wgi::refused_frame_action(model_k, /*by_default=*/true) == wgi::RefusedAction::kNoSwitch; CHECK(unsupported); // the backend's answer for a refused frame is WG_ERROR_UNSUPPORTED const std::set pattern = unsupported ? std::set{1, 2, 3, 5, 6} : std::set{}; // with AMD's FSR: the first refused frame hands the context to it; no later frame is lost diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 9de91f39..76e8497b 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -146,7 +146,7 @@ std::string adapter_description(ID3D12Device* device) { struct Options { std::string sync = "inline"; // inline | pipelined - std::string hip_switch; // on | off (executor_select.h refused_frame_policy); empty: the default + std::string hip_switch; // ignored by every model (executor_select.h: one line when set) std::string executor = "auto"; // auto (not named: dx12 for every model on RDNA 4, else no executor: the front end's upscaler; executor_select.h) | hip | // dx12 (the network on the game's D3D12 device, no HIP) | d3d12-test (tests) std::string model_dir; // default %LOCALAPPDATA%\WrongGPU\model (installer contract, spec 30) @@ -609,6 +609,7 @@ class Context { } q.sparkle_guard = o.sparkle_guard > 0.0f; q.capture = !o.capture_dir.empty(); + q.hip_switch = o.hip_switch; const ExecutorChoice ch = choose_executor(q); if (ch.executor.empty()) return fail(WG_ERROR_PARAMETER, "unknown executor " + o.executor); if (!ch.why.empty()) say(ch.warn ? WG_LOG_WARN : WG_LOG_INFO, ch.why); @@ -618,20 +619,11 @@ class Context { o.executor = ch.executor; // model K's default mode below applies with the HIP executor if (ch.sparkle_off) o.sparkle_guard = 0.0f; // model K: the guard is HIP only; K stays on D3D12 dx12_default_ = ch.by_default && ch.executor == "dx12"; - const RefusedFramePolicy pol = refused_frame_policy(o.hip_switch); // clean/fe-wrapped-list - hip_switch_ = pol.switch_to_hip; - if (!pol.note.empty()) say(WG_LOG_WARN, pol.note); - if (q.model_k) { // model K never moves to HIP, whatever hip_switch says - hip_switch_ = false; - const std::string kn = k_hip_switch_note(o.hip_switch); - if (!kn.empty()) say(WG_LOG_INFO, kn); - } + // R1: no model moves to HIP in a game, whatever hip_switch says (the 0.6.0 option is ignored, with one line) + if (!ch.hip_note.empty()) say(WG_LOG_INFO, ch.hip_note); } k_default_ = model_k_default(o); const bool split = services_ && services_->struct_size >= sizeof(WgFrontEndServices) && services_->split_command_list; - split_ = split; - share_path_opt_ = o.share_path; - input_copy_opt_ = o.input_copy; if (!split && o.executor != "dx12") return fail(WG_ERROR_UNSUPPORTED, "the front end offers no command-list split (interface version 2)"); if (!o.unknown.empty()) say(WG_LOG_INFO, "options passed on to the network runtime: " + o.unknown); @@ -884,14 +876,7 @@ class Context { } } const uint64_t v = ++value_; - // the D3D12 executor after a switch to HIP (switch_to_hip): released once the game's lists with its frames are done - if (retired_ && retired_->completed() >= retired_last_) retired_.reset(); - if (exec_->records_into_list()) { - bool moved = false; - const WgResult r = dispatch_record(f, list, v, &moved); - if (!moved) return r; - // moved: the HIP executor runs this frame (below) and every later one - } + if (exec_->records_into_list()) return dispatch_record(f, list, v); // Slots alternate with every network frame enqueued (not with v: a frame without the network must not make two // consecutive network frames share a slot). The slot written now was last used two network frames ago, and the // game's queue has waited for that frame (inline) or a later one (pipelined) before this frame's first part. @@ -1096,10 +1081,7 @@ class Context { // executor=dx12: the network and its output, recorded into the game's list L (no split). The network's kernels read // the game's textures and write its output texture themselves: no input pass, no output pass (executor_d3d12.cpp). - // *moved: the executor did not take the frame and the context now runs on the HIP executor (switch_to_hip); nothing - // of the frame's own work is recorded yet (the caller records it on the HIP path). - WgResult dispatch_record(const WgFrame& f, ID3D12GraphicsCommandList* list, uint64_t v, bool* moved) { - *moved = false; + WgResult dispatch_record(const WgFrame& f, ID3D12GraphicsCommandList* list, uint64_t v) { Job job; job.slot = 0; job.value = v; @@ -1129,12 +1111,12 @@ class Context { phase(4); const bool ok = exec_->record(job, list, &wrote, &err); phase(5); - // a frame the executor did not take (nothing of it recorded, e.g. native AA): with the default executor the HIP - // executor takes over the context; with executor=dx12 the frame gets the bilinear fallback below + // a frame the executor did not take (nothing of it recorded, e.g. native AA): with the default executor the frame + // is answered WG_ERROR_UNSUPPORTED (no HIP, any model); with executor=dx12 it gets the bilinear fallback below const bool refused = !ok && frame_refused(err); - // a refused frame (executor_select.h refused_frame_action): model K, and model M with hip_switch=off, answer + // a refused frame (executor_select.h refused_frame_action): every model on the default executor answers // WG_ERROR_UNSUPPORTED and the front end takes the frame (AMD FSR, else its stand-in); the context stays usable - const RefusedAction refused_action = refused_frame_action(model_k_, dx12_default_, hip_switch_); + const RefusedAction refused_action = refused_frame_action(model_k_, dx12_default_); if (refused && refused_action == RefusedAction::kNoSwitch) { // clean/fe-wrapped-list: no move to HIP; nothing recorded if (!no_switch_said_) { no_switch_said_ = true; @@ -1142,8 +1124,6 @@ class Context { } return WG_ERROR_UNSUPPORTED; // one frame's answer: the context stays usable (failed_ not set) } - if (refused && refused_action == RefusedAction::kSwitchToHip && switch_to_hip(v, err)) return *moved = true, WG_OK; - if (!refused) dx12_last_ = v; note_path(&input_path_, "input: read directly by the network's D3D12 kernels (executor dx12, no input pass)"); if ((flags_ & WG_CREATE_MOTION_OUTPUT_RES) && model_k_) note_path(&motion_path_, "motion: output resolution, the texel under each render pixel's centre picked by the " @@ -1186,66 +1166,6 @@ class Context { return WG_OK; } - // The default executor on RDNA 4 (dx12_default_) met a frame its kernels do not take (nothing of it recorded, e.g. - // native AA, a render size above the one checked at create): the HIP executor runs this frame and every later one - // of the context, starting over (reset), as if it had been chosen at create (shared buffers, split, fences; the - // options input_copy and share_path apply). The D3D12 executor stays alive until the game's lists holding its - // frames have finished (retired_). One log line; tried once (on failure: the bilinear fallback for such frames). - bool switch_to_hip(uint64_t v, const std::string& why) { - dx12_default_ = false; - std::string err; - std::unique_ptr hip; - if (!split_) { - err = "the front end offers no command-list split (interface version 2)"; - } else { - hip = make_hip_executor(rt_cfg_, adapter_); - hip->set_log_sink([this](bool warning, const std::string& m) { - say(warning ? WG_LOG_WARN : WG_LOG_INFO, "destroy: " + m); - }); - say(WG_LOG_INFO, "about to start the HIP runtime (frame " + std::to_string(v) + ": the context moves to the HIP executor)"); - if (!hip->prepare(&err)) hip.reset(); - } - if (hip) { - std::unique_ptr d3d = std::move(exec_); - release_set(); // the D3D12 context's fences and flag range (no frame of it uses them) - no_slots_ = false; - exec_ = std::move(hip); - bool shared = make_shared_objects(exec_->needs_handles(), share_path_opt_, &err); - if (shared) say(WG_LOG_INFO, "about to import the shared buffers and fences into HIP (" + share_path_ + ")"); - if (!shared || !exec_->init(device_, set_, &err)) { - exec_.reset(); - release_set(); - no_slots_ = true; - exec_ = std::move(d3d); - } else { - close_handles(); - retired_ = std::move(d3d); - retired_last_ = dx12_last_; - if (!retired_last_ || retired_->completed() >= retired_last_) retired_.reset(); - } - } - if (exec_->records_into_list()) { - say(WG_LOG_WARN, "frame " + std::to_string(v) + ": executor dx12 (default on RDNA 4) does not take this frame (" + - why + ") and the HIP executor could not take over (" + err + - "); frames it does not take get the bilinear fallback"); - return false; - } - input_copy_ = input_copy_opt_; - next_slot_ = 0; - last_run_ = last_submitted_ = 0; - force_reset_ = true; // the HIP network starts over with this frame - if (timing_) { - const bool net = exec_->enable_timing(); - timing_->set_info(net ? exec_->timing_info() : std::string()); - timing_->set_labels(exec_->timing_labels()); - } - say(WG_LOG_WARN, "frame " + std::to_string(v) + ": executor dx12 (default on RDNA 4) does not take this frame (" + - why + "); the HIP executor runs this context from now on (shared buffers and fences: " + - share_path_ + ", GPU memory " + std::to_string(gpu_memory() >> 20) + - " MiB; executor=dx12 keeps the D3D12 executor with the bilinear fallback for such frames)"); - return true; - } - uint64_t gpu_memory() const { uint64_t b = 0; std::vector seen; // arena buffers share one resource @@ -1981,7 +1901,6 @@ class Context { say(WG_LOG_WARN, "destroy: the network's last frame did not finish within 5 s"); } if (exec_) exec_->drain(); - retired_.reset(); // (drains the game's lists that hold its frames, bounded) if (rescue_ && device_ && ev) { ID3D12Fence* f = nullptr; if (SUCCEEDED(device_->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), (void**)&f))) { @@ -2138,17 +2057,10 @@ class Context { #endif bool k_default_ = false; // model K's default mode was applied (model_k_default) // executor choice (executor_select.h): dx12_default_ = the D3D12 executor runs the context by the default rule (not - // the option), so a frame it does not take moves the context to the HIP executor (switch_to_hip); what that switch - // needs from create: the split service and the options share_path / input_copy + // the option); a frame it does not take is answered WG_ERROR_UNSUPPORTED (no HIP in a game), with executor=dx12 + // forced it gets the bilinear fallback bool dx12_default_ = false; - bool hip_switch_ = kHipSwitchDefault; // refused_frame_policy (option hip_switch; clean/fe-wrapped-list) - bool no_switch_said_ = false; // the hip_switch=off line was logged - bool split_ = false; - std::string share_path_opt_ = "auto"; - bool input_copy_opt_ = false; - uint64_t dx12_last_ = 0; // last frame the D3D12 executor recorded something of - std::unique_ptr retired_; // the D3D12 executor after switch_to_hip, until its frames have finished - uint64_t retired_last_ = 0; + bool no_switch_said_ = false; // the refused-frame line was logged bool k_input16_ = true; // model K: compact input pass (runtime option k_input=f32: the FP32 pass) std::string n_kernels_, n_model_, n_map_, n_rocm_, n_swin_, n_rtopts_; WgRtConfig rt_cfg_ = {}; diff --git a/clean/runtime/interop/executor_select.h b/clean/runtime/interop/executor_select.h index 89addd76..d4aca52c 100644 --- a/clean/runtime/interop/executor_select.h +++ b/clean/runtime/interop/executor_select.h @@ -21,9 +21,9 @@ // created); frames it does not take get the bilinear fallback (no switch). // - A frame the D3D12 executor does not take later (e.g. above the checked render size; native AA and every ratio // between 1.0 and 1.5 run on it since Brief 15) is answered WG_ERROR_UNSUPPORTED and goes back to the front end (AMD -// FSR, else its stand-in; hip_switch=off, the default since the owner's decision of 2026-11-04); with hip_switch=on a -// model M or L context moves to the HIP executor for good (backend.cpp switch_to_hip; one line, an explicit ini option). -// Model K ignores hip_switch (one line if set). A refused K frame takes exactly model M's front-end path. +// FSR, else its stand-in); no model moves to HIP in a game (R1). The 0.6.0 option hip_switch=on, which moved a model M +// or L context to the HIP executor, is ignored for every model (one line if set). Every model's refused frame takes +// the same front-end path. // - `d3d12-test`: the offline test executor. #pragma once @@ -47,6 +47,7 @@ struct ExecutorRequest { uint32_t kmt_vendor = 0, kmt_device = 0; bool sparkle_guard = false; // option sparkle_guard on bool capture = false; // option capture_dir set + std::string hip_switch; // the 0.6.0 option hip_switch (ignored for every model: hip_switch_note) }; struct ExecutorChoice { @@ -57,6 +58,7 @@ struct ExecutorChoice { bool warn = false; // log `why` as a warning (else information) bool sparkle_off = false; // the sparkle guard (HIP only) is turned off, whatever the model; the context stays on D3D12 std::string why; // the one log line about the choice; empty: nothing to log here + std::string hip_note; // the one line when the option hip_switch asks for a move to HIP (ignored, any model) }; // The one line when "auto" meets an adapter that is not an RDNA 4 Radeon RX 9000-series card or cannot be identified (the @@ -89,8 +91,11 @@ inline wgrt::AdapterIdentity adapter_identity(const ExecutorRequest& r) { return id; } +inline std::string hip_switch_note(const std::string& option); // below + inline ExecutorChoice choose_executor(const ExecutorRequest& r) { ExecutorChoice c; + c.hip_note = hip_switch_note(r.hip_switch); // the same for every model: the option is ignored const std::string& e = r.executor; if (e == "d3d12-test") { c.executor = e; @@ -129,54 +134,30 @@ inline ExecutorChoice choose_executor(const ExecutorRequest& r) { return c; } -// clean/fe-wrapped-list (Brief 12): what a context on the default D3D12 executor does when that executor does not take a -// frame mid-session (a render size above the one checked at create). Option `hip_switch`: -// - `on`: the HIP executor runs this frame and every later one of the context (switch_to_hip; the 0.6.0 behaviour); -// - `off`: no switch. The frame is answered WG_ERROR_UNSUPPORTED with nothing recorded; the front end hands the context -// to AMD's FSR, else its stand-in upscales such frames. The context stays on the D3D12 executor. -// Not named: kHipSwitchDefault, off (owner 2026-11-04, Brief 14: no mid-session HIP; oversize frames go to -// AMD FSR, else the stand-in). Another value: the default, with a note. Forced executors (executor=dx12 / -// executor=hip) are not affected. -inline constexpr bool kHipSwitchDefault = false; - -struct RefusedFramePolicy { - bool switch_to_hip = kHipSwitchDefault; - std::string note; // a log line about the option's value; empty: nothing to say -}; - -inline RefusedFramePolicy refused_frame_policy(const std::string& option) { - RefusedFramePolicy p; - if (option.empty()) return p; - if (option == "on" || option == "1" || option == "true") { - p.switch_to_hip = true; - } else if (option == "off" || option == "0" || option == "false") { - p.switch_to_hip = false; - } else { - p.note = "hip_switch=" + option + " not recognised (on or off); using " + (kHipSwitchDefault ? "on" : "off"); - } - return p; -} - -// Model K ignores hip_switch (it never runs on HIP in a game): the option's line, empty when the option is not set. -inline std::string k_hip_switch_note(const std::string& option) { - if (option.empty()) return ""; - return "model K ignores hip_switch=" + option + - ": a frame the D3D12 executor does not take goes to the front end's own upscaler, never to HIP"; +// What a context on the default D3D12 executor does when that executor does not take a frame mid-session (a render size +// above the one checked at create): the frame is answered WG_ERROR_UNSUPPORTED with nothing recorded; the front end hands +// the context to AMD's FSR, else its stand-in upscales such frames. The context stays on the D3D12 executor: no model +// moves to HIP in a game (R1). The 0.6.0 option `hip_switch=on` (a model M or L context moved to HIP for good) is ignored +// for every model, with one line; `off` (the default since the owner's decision of 2026-11-04) is the behaviour. +// executor=hip is the explicit diagnostic and is not affected. +inline std::string hip_switch_note(const std::string& option) { + if (option.empty() || option == "off" || option == "0" || option == "false") return ""; + return "hip_switch=" + option + + " is ignored: a frame the D3D12 executor does not take goes to the front end's own upscaler, never to HIP " + "(executor=hip is the explicit diagnostic)"; } // What a context does with a frame the D3D12 executor did not take (nothing of it recorded). // kNoSwitch the frame is answered WG_ERROR_UNSUPPORTED, the context stays usable: the front end takes it from there // (AMD's FSR when it exists, else its stand-in; the same path for every model); -// kSwitchToHip the default executor with hip_switch=on moves the context to HIP (never for model K); // kBilinear executor=dx12 (forced): the frame gets the bilinear fallback (never for model K). // Model K has no state of its own here: every refused K frame is answered WG_ERROR_UNSUPPORTED, exactly as model M's -// refused frames are with hip_switch=off, and the front end does the rest (REVIEW-215c, oversight 2026-11-15). -enum class RefusedAction { kNoSwitch, kSwitchToHip, kBilinear }; +// refused frames are, and the front end does the rest (REVIEW-215c, oversight 2026-11-15). +enum class RefusedAction { kNoSwitch, kBilinear }; -inline RefusedAction refused_frame_action(bool model_k, bool by_default, bool hip_switch) { +inline RefusedAction refused_frame_action(bool model_k, bool by_default) { if (model_k) return RefusedAction::kNoSwitch; - if (by_default) return hip_switch ? RefusedAction::kSwitchToHip : RefusedAction::kNoSwitch; - return RefusedAction::kBilinear; + return by_default ? RefusedAction::kNoSwitch : RefusedAction::kBilinear; } // A frame the executor did not take (nothing recorded) carries this prefix in its error (executor_d3d12.cpp, convert.cpp: @@ -188,10 +169,10 @@ inline std::string k_refusal_line(uint64_t frame, const std::string& why) { "); the frame goes to the front end's own upscaler (AMD FSR, else its stand-in), never to the HIP executor"; } -// The one warning line of a context with hip_switch=off whose D3D12 executor does not take a frame. +// The one warning line of a context whose default D3D12 executor does not take a frame. inline std::string no_switch_line(uint64_t frame, const std::string& why) { return "frame " + std::to_string(frame) + ": executor dx12 (default on RDNA 4) does not take this frame (" + why + - "); hip_switch=off: the context does not move to the HIP executor; such frames go back to the front end " + "); the context does not move to the HIP executor; such frames go back to the front end " "(AMD FSR, else its stand-in)"; } diff --git a/clean/runtime/interop/tests/test_executor_select.cpp b/clean/runtime/interop/tests/test_executor_select.cpp index e3693e60..e710aa96 100644 --- a/clean/runtime/interop/tests/test_executor_select.cpp +++ b/clean/runtime/interop/tests/test_executor_select.cpp @@ -23,6 +23,7 @@ void expect(const char* name, bool ok) { void expect(const std::string& name, bool ok) { expect(name.c_str(), ok); } bool has(const std::string& s, const char* part) { return s.find(part) != std::string::npos; } +bool has(const std::string& s, const std::string& part) { return s.find(part) != std::string::npos; } // A request for an adapter as the lookup found it (what backend.cpp builds from wgrt::lookup_adapter) wgi::ExecutorRequest request_for(const wgrt::AdapterIdentity& id) { @@ -339,23 +340,19 @@ int main() { // ---- clean/fe-wrapped-list: hip_switch, and a frame the D3D12 executor does not take ----------------------------- { - using wgi::refused_frame_policy; using wgi::RefusedAction; - expect("hip_switch not named -> the default: off (owner 2026-11-04)", - !wgi::kHipSwitchDefault && !refused_frame_policy("").switch_to_hip && refused_frame_policy("").note.empty()); - expect("hip_switch=on -> switch", refused_frame_policy("on").switch_to_hip && refused_frame_policy("1").switch_to_hip); - expect("hip_switch=off -> no switch", !refused_frame_policy("off").switch_to_hip && !refused_frame_policy("0").switch_to_hip && - refused_frame_policy("off").note.empty()); - const wgi::RefusedFramePolicy odd = refused_frame_policy("maybe"); - expect("hip_switch=maybe -> the default with a note", - odd.switch_to_hip == wgi::kHipSwitchDefault && has(odd.note, "hip_switch=maybe not recognised")); + expect("hip_switch not set, off, 0 or false -> no line", wgi::hip_switch_note("").empty() && + wgi::hip_switch_note("off").empty() && + wgi::hip_switch_note("0").empty() && + wgi::hip_switch_note("false").empty()); + for (const char* v : {"on", "1", "true", "maybe"}) + expect(std::string("hip_switch=") + v + " is ignored with one line, no HIP", + has(wgi::hip_switch_note(v), std::string("hip_switch=") + v + " is ignored") && + has(wgi::hip_switch_note(v), "never to HIP") && wgi::hip_switch_note(v).find('\n') == std::string::npos); const std::string l = wgi::no_switch_line(2, "frame not taken (nothing recorded): native direct frame geometry"); - expect("the hip_switch=off line names the frame, the reason, no HIP and the front end's fallback", + expect("the refused-frame line names the frame, the reason, no HIP and the front end's fallback", has(l, "frame 2: executor dx12 (default on RDNA 4) does not take this frame") && has(l, "native direct frame") && has(l, "does not move to the HIP executor") && has(l, "AMD FSR, else its stand-in")); - expect("K: no line when hip_switch is not set", wgi::k_hip_switch_note("").empty()); - expect("K: hip_switch=on is ignored with one line", - has(wgi::k_hip_switch_note("on"), "model K ignores hip_switch=on") && has(wgi::k_hip_switch_note("on"), "never to HIP")); const char* const refusals[] = { "frame not taken (nothing recorded): no output texture", "frame not taken (nothing recorded): model K direct frame: render size outside the configured maximum", @@ -365,25 +362,59 @@ int main() { const std::string w = why; expect("refused frame recognised: " + w, wgi::frame_refused(w)); for (bool by_default : {true, false}) - for (bool hip_switch : {false, true}) - expect("K refused frame -> WG_ERROR_UNSUPPORTED, the front end's upscaler: " + w.substr(0, 40) + - (by_default ? " default" : " forced") + (hip_switch ? " switch=on" : " switch=off"), - wgi::refused_frame_action(true, by_default, hip_switch) == RefusedAction::kNoSwitch); + expect("K refused frame -> WG_ERROR_UNSUPPORTED, the front end's upscaler: " + w.substr(0, 40) + + (by_default ? " default" : " forced"), + wgi::refused_frame_action(true, by_default) == RefusedAction::kNoSwitch); } expect("a frame that is not a refusal is not a 'frame not taken'", !wgi::frame_refused("input refused: texture format") && !wgi::frame_refused("model K: kernel failed")); - expect("M default + hip_switch=on -> switch to HIP (the explicit 0.6.0 option)", - wgi::refused_frame_action(false, true, true) == RefusedAction::kSwitchToHip); - expect("M default + hip_switch=off -> front end's upscaler", wgi::refused_frame_action(false, true, false) == RefusedAction::kNoSwitch); - expect("M executor=dx12 -> bilinear fallback", wgi::refused_frame_action(false, false, true) == RefusedAction::kBilinear); - expect("K and M (hip_switch=off) take the same path: the same action", - wgi::refused_frame_action(true, true, true) == wgi::refused_frame_action(false, true, false)); + expect("M default -> front end's upscaler (no move to HIP)", wgi::refused_frame_action(false, true) == RefusedAction::kNoSwitch); + expect("M executor=dx12 -> bilinear fallback", wgi::refused_frame_action(false, false) == RefusedAction::kBilinear); + expect("K and M take the same path: the same action", + wgi::refused_frame_action(true, true) == wgi::refused_frame_action(false, true)); const std::string rl = wgi::k_refusal_line(7, "frame not taken (nothing recorded): no output texture"); expect("the refusal line names the frame, the reason, the front end's upscaler and 'never to the HIP executor'", has(rl, "frame 7: model K") && has(rl, "no output texture") && has(rl, "AMD FSR, else its stand-in") && has(rl, "never to the HIP executor") && rl.find('\n') == std::string::npos); } + // ---- R1 (oversight): hip_switch=on is ignored for models M, L and K alike ---------------------------------------- + // The selector sees a model only as "is it K"; M and L are the same request. For each of the three: on an RX 9000 board + // the default stays the D3D12 executor with one line about the option, a refused frame never moves to HIP, and the + // option changes nothing about the choice (the same executor, default flag and log text with and without it). + { + struct Model { + const char* name; + bool k; + }; + for (const Model m : {Model{"M", false}, Model{"L", false}, Model{"K", true}}) { + for (const char* value : {"on", "1", "true"}) { + wgi::ExecutorRequest r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = m.k; + wgi::ExecutorRequest plain = r; + r.hip_switch = value; + const wgi::ExecutorChoice c = choose_executor(r); + const wgi::ExecutorChoice p = choose_executor(plain); + const std::string tag = std::string("model ") + m.name + " hip_switch=" + value; + expect(tag + ": stays on the D3D12 executor by default", c.executor == "dx12" && c.by_default); + expect(tag + ": one line, no HIP", has(c.hip_note, (std::string("hip_switch=") + value + " is ignored").c_str()) && + has(c.hip_note, "never to HIP") && c.hip_note.find('\n') == std::string::npos); + expect(tag + ": the choice is the one without the option", + c.executor == p.executor && c.by_default == p.by_default && c.why == p.why && c.warn == p.warn && + c.sparkle_off == p.sparkle_off && p.hip_note.empty()); + expect(tag + ": a refused frame goes to the front end, not to HIP", + wgi::refused_frame_action(m.k, c.by_default) == wgi::RefusedAction::kNoSwitch); + } + for (const char* value : {"off", "0", "false", ""}) { + wgi::ExecutorRequest r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = m.k; + r.hip_switch = value; + expect(std::string("model ") + m.name + " hip_switch=" + value + ": nothing to say", + choose_executor(r).hip_note.empty()); + } + } + } + std::printf(failures ? "%d FAILED\n" : "ALL TESTS PASSED\n", failures); return failures ? 1 : 0; } diff --git a/clean/runtime/interop/tests/test_interop_d3d12.cpp b/clean/runtime/interop/tests/test_interop_d3d12.cpp index 96a22c67..d68a12bf 100644 --- a/clean/runtime/interop/tests/test_interop_d3d12.cpp +++ b/clean/runtime/interop/tests/test_interop_d3d12.cpp @@ -1894,23 +1894,24 @@ bool case_dx12_same(Gpu& g, const char* dll, const std::string& common, int fram CHECK(rr == WG_OK); CHECK(debug_messages(g, mode ? "dx12 frame" : "hip frame") == 0); } - // WG_TEST_EXPECT (second context): dx12 (default: the D3D12 executor ran every frame and wrote the output), switch - // (the default executor met a frame it does not take and the HIP executor took over the context; since the owner's - // decision of 2026-11-04 only with hip_switch=on in the options), refused (create answered WG_ERROR_UNSUPPORTED, above) + // WG_TEST_EXPECT (second context): dx12 (default: the D3D12 executor ran every frame and wrote the output), + // ignored (hip_switch=on in the options is ignored with one line: the context stays on the D3D12 executor, no HIP), + // refused (create answered WG_ERROR_UNSUPPORTED, above) const char* ex = std::getenv("WG_TEST_EXPECT"); const std::string expect = ex ? ex : "dx12"; if (mode == 1 && expect != "dx12") { - bool ready_dx12 = false, ready_hip = false, switched = false, refused = false; + bool ready_dx12 = false, ready_hip = false, switched = false, refused = false, ignored = false; for (const auto& m : g_log) { ready_dx12 |= m.find("network runtime ready: executor dx12") != std::string::npos; ready_hip |= m.find("network runtime ready: executor hip") != std::string::npos; switched |= m.find("the HIP executor runs this context from now on") != std::string::npos; refused |= m.find("executor dx12 (default on RDNA 4) could not take this context") != std::string::npos; + ignored |= m.find("hip_switch=on is ignored") != std::string::npos; } - std::printf(" second context: ready dx12 %d, ready hip %d, switched to HIP %d, refused at create %d\n", - (int)ready_dx12, (int)ready_hip, (int)switched, (int)refused); - CHECK(expect == "switch"); // (any other value is a typo: "refused" returned above) - CHECK(ready_dx12 && switched && !refused && !ready_hip); + std::printf(" second context: ready dx12 %d, ready hip %d, switched to HIP %d, hip_switch ignored %d, refused at create %d\n", + (int)ready_dx12, (int)ready_hip, (int)switched, (int)ignored, (int)refused); + CHECK(expect == "ignored"); // (any other value is a typo: "refused" returned above) + CHECK(ready_dx12 && ignored && !switched && !refused && !ready_hip); } if (mode == 1 && expect == "dx12") { bool ran = false, direct_in = false, wrote = false; diff --git a/clean/tests/test_executor_select.py b/clean/tests/test_executor_select.py index a9bde820..6c510fac 100644 --- a/clean/tests/test_executor_select.py +++ b/clean/tests/test_executor_select.py @@ -100,18 +100,33 @@ def test_d3d12_refusal_is_the_front_end_fallback_for_every_model(self): self.assertIn("return fail(WG_ERROR_UNSUPPORTED, dx12_refused_line(dx12_default_, err));", self.b) self.assertNotIn("dx12_refused_line_k", self.b) self.assertNotIn("the HIP executor runs it", read("clean", "runtime", "interop", "executor_select.h")) - # the HIP executor is made in two places only: at create for the explicit diagnostics (executor=hip, the frame - # capture), and in switch_to_hip, which only an explicit hip_switch=on reaches (never model K) - self.assertEqual(self.b.count("make_hip_executor("), 2) + # the HIP executor is made in one place, at create, for the explicit diagnostics (executor=hip, the frame capture); there is + # no switch to it mid-session (no switch_to_hip, no hip_switch policy: the option is ignored with one line) + self.assertNotIn("switch_to_hip", self.b) + self.assertNotIn("refused_frame_policy", self.b) + self.assertEqual(self.b.count("make_hip_executor("), 1) branch = self.at("if (!dx12 && !exec_) {") first = self.at("make_hip_executor(") self.assertLess(branch, first) - self.assertGreater(self.at("make_hip_executor(", first + 1), self.at("bool switch_to_hip(")) refusal = self.at("dx12_refused_line(dx12_default_, err)") self.assertLess(refusal, branch) # the refusal returns: nothing between it and the HIP branch resets the D3D12 executor to fall through self.assertNotIn("exec_.reset();", self.b[refusal:branch]) + def test_hip_switch_is_ignored_once_for_every_model(self): + # the option reaches the selector, its one line is logged once at create, and nothing in the create path is + # conditional on the model (M, L and K are treated alike); no code reads the option to move a context to HIP + self.assertEqual(self.b.count("q.hip_switch = o.hip_switch;"), 1) + self.assertEqual(self.b.count("say(WG_LOG_INFO, ch.hip_note)"), 1) + note = self.at("say(WG_LOG_INFO, ch.hip_note)") + window = self.b[max(0, note - 200):note + 60] + self.assertNotIn("model_k", window) + self.assertNotIn("model_k", self.b[self.at("q.hip_switch = o.hip_switch;"):note]) + self.assertEqual(self.b.count("o.hip_switch"), 1 + 1) # parse_options' assignment and the request + self.assertNotIn("hip_switch_", self.b) + sel = read("clean", "runtime", "interop", "executor_select.h") + self.assertNotIn("kSwitchToHip", sel) + def test_rr_and_native_device_use_the_shared_id_rule(self): rr = read("clean", "rr_f", "runtime", "src", "rr_runtime.cpp") self.assertIn('#include "../../../runtime/rdna4_win.h"', rr) From 13f1b28db8030102f069283dd391462d2cb5b851 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 05:12:20 -0500 Subject: [PATCH 04/20] R1: Quality 5/9 fall back to the default filter on D3D12; launcher shows HIP-only choices as not available The runtime drops output_filter=quality5|quality9 for a context on the D3D12 executor (default filter, one line, no HIP). The launcher offers Auto and Direct3D 12 only under Runs on, greys the two filters and the sparkle guard with 'Not available on the DX12 runtime yet'. Selector tests and source pins cover the filter fallback. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/src/app/ui_activate.cpp | 2 +- clean/installer/src/app/ui_game.cpp | 24 +++++++---- clean/installer/src/wg_core/profile.cpp | 16 +++++-- clean/installer/src/wg_core/profile.h | 8 ++++ clean/runtime/interop/backend.cpp | 5 +++ clean/runtime/interop/executor_select.h | 42 +++++++++++++++++++ .../interop/tests/test_executor_select.cpp | 33 +++++++++++++++ clean/tests/test_executor_select.py | 11 +++++ 8 files changed, 129 insertions(+), 12 deletions(-) diff --git a/clean/installer/src/app/ui_activate.cpp b/clean/installer/src/app/ui_activate.cpp index 55ab1584..90deb4e9 100644 --- a/clean/installer/src/app/ui_activate.cpp +++ b/clean/installer/src/app/ui_activate.cpp @@ -125,7 +125,7 @@ void ActivateWidget(int id) { default: OpenGame(i); return; } } - if (id >= ID_G_EXEC0 && id < ID_G_EXEC0 + 3) { static const char* const x[] = {"auto", "dx12", "hip"}; SetSetting(v.edit, "executor", x[id - ID_G_EXEC0], nullptr); Invalidate(); return; } + if (id >= ID_G_EXEC0 && id < ID_G_EXEC0 + 2) { static const char* const x[] = {"auto", "dx12"}; // R1: no HIP choice SetSetting(v.edit, "executor", x[id - ID_G_EXEC0], nullptr); Invalidate(); return; } if (id >= ID_G_PRE0 && id < ID_G_PRE0 + 2) { static const char* const x[] = {"scale", "original"}; SetSetting(v.edit, "pre_exposure", x[id - ID_G_PRE0], nullptr); Invalidate(); return; } if (id >= ID_G_RRMODE0 && id < ID_G_RRMODE0 + 3) { static const char* const x[] = {"exact", "accurate", "fast"}; SetSetting(v.edit, "rr_mode", x[id - ID_G_RRMODE0], nullptr); Invalidate(); return; } if (id >= ID_G_FPS0 && id < ID_G_FPS0 + 3) { static const char* const x[] = {"keep", "on", "off"}; SetSetting(v.edit, "fps_overlay", x[id - ID_G_FPS0], nullptr); Invalidate(); return; } diff --git a/clean/installer/src/app/ui_game.cpp b/clean/installer/src/app/ui_game.cpp index 8dd35454..82656909 100644 --- a/clean/installer/src/app/ui_game.cpp +++ b/clean/installer/src/app/ui_game.cpp @@ -609,8 +609,9 @@ std::vector FilterMenu() { std::vector items; const string cur = v.edit.get("output_filter"); for (int i = 0; i < 5; ++i) { - MenuItem it{kFilterNames[i], M_FILTER0 + i, true, false, false, cur == kFilter[i]}; - it.help = kFilterHelp[i]; + const bool hipOnly = NeedsHipRuntime("output_filter", kFilter[i]); // R1: greyed, with the words + MenuItem it{kFilterNames[i], M_FILTER0 + i, !hipOnly, false, false, cur == kFilter[i]}; + it.help = hipOnly ? wstring(NotOnDx12Text()) : wstring(kFilterHelp[i]); items.push_back(it); } return items; @@ -1351,23 +1352,30 @@ static float UpscalerSection(Gfx& gx, float x, float y, float w) { yy += ActRow(gx, x, yy, w, false, true, ID_G_ADVMORE, L"Advanced settings (4)", ic::down, true, R_LINK); return yy - top; } - const std::vector ex{L"Auto", L"Direct3D\u00a012", L"HIP"}; - const int exi = Index(kExec, v.edit.get("executor")); - yy += SRow(gx, x, yy, w, false, L"Runs on", L"Auto uses Direct3D\u00a012 on RX\u00a09000-series cards. HIP is the other way Model\u00a0M can run.", SegmentedW(gx, ex, segW), 36, + // R1: every model runs on Direct3D 12 in a game. HIP is a diagnostic set in wronggpu.ini (executor=hip), not a choice here; + // a profile that holds it says so in the row's sentence and shows no segment chosen + const std::vector ex{L"Auto", L"Direct3D\u00a012"}; + const bool hipSet = NeedsHipRuntime("executor", v.edit.get("executor")); + const int exi = hipSet ? -1 : Index(kExec, v.edit.get("executor")); + yy += SRow(gx, x, yy, w, false, L"Runs on", + hipSet ? L"The profile asks for the HIP runtime, a diagnostic. Pick Auto or Direct3D\u00a012 to run the way the game is meant to." + : L"Auto uses Direct3D\u00a012 on RX\u00a09000-series cards.", + SegmentedW(gx, ex, segW), 36, [&](const Rc& r) { Segmented(gx, ID_G_EXEC0, r.r(), r.y, ex, exi, sub, L"Runs on", 28, {}, true, segW); }, !sub); const int fi = Index(kFilter, v.edit.get("output_filter")); float fw = 170; // .select min-width 170, wider when a name needs it for (auto* n : kFilterNames) fw = std::max(fw, std::ceil(gx.TextW(n, Ts(13, 600, pal.text)) + 12 + 30)); // the sentence says what the chosen filter does (each choice's line is in its menu too) - yy += SRow(gx, x, yy, w, false, L"Output filter", kFilterHelp[fi], fw, 30, + yy += SRow(gx, x, yy, w, false, L"Output filter", + NeedsHipRuntime("output_filter", v.edit.get("output_filter")) ? NotOnDx12Text() : kFilterHelp[fi], fw, 30, [&](const Rc& r) { Select(gx, ID_G_FILTER, r, kFilterNames[fi], sub, L"Output filter"); }, !sub); const std::vector pre{L"Scale", L"Original"}; const int pi = Index(kPre, v.edit.get("pre_exposure")); yy += SRow(gx, x, yy, w, false, L"Pre-exposure", L"Scale keeps hair and fine detail steady. Original uses the game's brightness value as it is; in some games that makes hair and fine detail flicker.", SegmentedW(gx, pre, segW), 36, [&](const Rc& r) { Segmented(gx, ID_G_PRE0, r.r(), r.y, pre, pi, sub, L"Pre-exposure", 28, {}, true, segW); }, !sub); const bool sp = v.edit.get("sparkle_guard") != "off"; - yy += SRow(gx, x, yy, w, false, L"Sparkle guard", L"Calms single-pixel flashes on foliage. Uses HIP, even when Model M runs on Direct3D\u00a012.", kSwitchW, kSwitchH, - [&](const Rc& r) { Switch(gx, ID_G_SPARKLE, r, sp, sub, L"Sparkle guard"); }, !sub, L"+0.11 ms"); + yy += SRow(gx, x, yy, w, false, L"Sparkle guard", NotOnDx12Text(), kSwitchW, kSwitchH, + [&](const Rc& r) { Switch(gx, ID_G_SPARKLE, r, sp, false, L"Sparkle guard"); }, true); // R1: no D3D12 port yet: off if (!outsideAdv) yy += ActRow(gx, x, yy, w, false, true, ID_G_ADVMORE, L"Fewer settings", ic::up, true, R_LINK); return yy - top; }); diff --git a/clean/installer/src/wg_core/profile.cpp b/clean/installer/src/wg_core/profile.cpp index 2e967c33..05c80ff2 100644 --- a/clean/installer/src/wg_core/profile.cpp +++ b/clean/installer/src/wg_core/profile.cpp @@ -16,13 +16,13 @@ const SettingDef kSettings[] = { {"wronggpu", Layer::Fe, Tier::Basic, "on", "on|off", L"WrongGPU", L"On: Model M upscales. Off: AMD's FSR upscales (WrongGPU stays installed and only logs)."}, {"executor", Layer::Rt, Tier::Basic, "auto", "auto|dx12|hip", L"Executor", - L"Auto: D3D12 on RX 9000 cards. HIP is used anyway for sparkle guard and frame capture."}, + L"Auto: Direct3D 12 on RX 9000 cards. HIP is a diagnostic set in wronggpu.ini; it is not offered here."}, {"output_filter", Layer::Rt, Tier::Basic, "default", "default|original|analytic|quality5|quality9", L"Output filter", - L"Default and Original: native output. Quality 5 / Quality 9: WrongGPU variations."}, + L"Default and Original: native output. Quality 5 / Quality 9: not available on the DX12 runtime yet (the default is used)."}, {"pre_exposure", Layer::Rt, Tier::Basic, "scale", "scale|original", L"Pre-exposure", L"Scale (default). Original can change hair and fine detail in some games (Hogwarts Legacy)."}, {"sparkle_guard", Layer::Rt, Tier::Basic, "off", "off|on|#rate", L"Sparkle guard", - L"Calms single bright pixels (about +0.11 ms). Needs the HIP runtime."}, + L"Calms single bright pixels. Not available on the DX12 runtime yet (it stays off)."}, {"fps_overlay", Layer::Opti, Tier::Basic, "keep", "keep|on|off", L"OptiScaler FPS overlay", L"OptiScaler's own FPS counter (only for OptiScaler builds that have the setting)."}, // Ray Reconstruction (games that use it, rr.h): the RR plugin's settings file @@ -72,6 +72,16 @@ static string TrimA(string t) { } static string LowerA(string s) { for (auto& c : s) if (c >= 'A' && c <= 'Z') c = (char)(c - 'A' + 'a'); return s; } +bool NeedsHipRuntime(const string& key, const string& value) { + const string v = LowerA(TrimA(value)); + if (key == "executor") return v == "hip"; + if (key == "output_filter") return v == "quality5" || v == "quality9"; + if (key == "sparkle_guard") return !v.empty() && v != "off" && v != "0"; + return false; +} + +const wchar_t* NotOnDx12Text() { return L"Not available on the DX12 runtime yet"; } + bool ValidateSetting(const SettingDef& d, const string& valueIn, string* normal, wstring* why) { string v = LowerA(TrimA(valueIn)); if (!strcmp(d.key, "executor") && (v == "d3d12" || v.empty())) v = v.empty() ? "auto" : "dx12"; diff --git a/clean/installer/src/wg_core/profile.h b/clean/installer/src/wg_core/profile.h index 77212617..8b572065 100644 --- a/clean/installer/src/wg_core/profile.h +++ b/clean/installer/src/wg_core/profile.h @@ -30,6 +30,14 @@ extern const SettingDef kSettings[]; extern const size_t kSettingCount; const SettingDef* FindSetting(const string& key); +// R1: every model runs on the Direct3D 12 runtime in a game; HIP is an explicit diagnostic (executor=hip in wronggpu.ini) +// and the frame capture only. These choices exist on the HIP runtime only, so the launcher does not offer them on an RX +// 9000-series card (it shows NotOnDx12Text() instead): executor=hip, the output filters Quality 5 and Quality 9, and the +// sparkle guard. A profile or an ini that already holds one still starts the game: the runtime uses the default output +// filter or turns the sparkle guard off, with one log line, and never starts HIP for it. +bool NeedsHipRuntime(const string& key, const string& value); +const wchar_t* NotOnDx12Text(); + // Checks and normalises one value ("d3d12" -> "dx12", "0" -> "off", "0.50" -> "0.5"); false with *why when it is not // allowed. bool ValidateSetting(const SettingDef& d, const string& value, string* normal, wstring* why); diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 76e8497b..1d7431a3 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -621,6 +621,11 @@ class Context { dx12_default_ = ch.by_default && ch.executor == "dx12"; // R1: no model moves to HIP in a game, whatever hip_switch says (the 0.6.0 option is ignored, with one line) if (!ch.hip_note.empty()) say(WG_LOG_INFO, ch.hip_note); + if (ch.executor == "dx12") { // H3: the HIP-only output filters (Quality 5 / 9) give the default filter, never HIP + std::string fnote; + o.runtime = drop_hip_only_filter(o.runtime, &fnote); + if (!fnote.empty()) say(WG_LOG_WARN, fnote); + } } k_default_ = model_k_default(o); const bool split = services_ && services_->struct_size >= sizeof(WgFrontEndServices) && services_->split_command_list; diff --git a/clean/runtime/interop/executor_select.h b/clean/runtime/interop/executor_select.h index d4aca52c..b69e05ab 100644 --- a/clean/runtime/interop/executor_select.h +++ b/clean/runtime/interop/executor_select.h @@ -30,6 +30,7 @@ #include #include #include +#include #include "../rdna4.h" @@ -160,6 +161,47 @@ inline RefusedAction refused_frame_action(bool model_k, bool by_default) { return by_default ? RefusedAction::kNoSwitch : RefusedAction::kBilinear; } +// H3 (R1): the output filters Quality 5 and Quality 9 (runtime option output_filter=quality5 | quality9) exist on the HIP +// executor only; the D3D12 executor refuses them at create. A context on the D3D12 executor never goes to HIP because of +// them: the option is dropped, the default filter runs, and `*note` is the one log line. `options` is the network +// runtime's "key=value;..." string; the last output_filter wins there, so a later quality value drops every output_filter +// item (an earlier quality value followed by another filter is only a leftover and is dropped too). Nothing else changes. +inline std::string drop_hip_only_filter(const std::string& options, std::string* note) { + struct Item { + std::string text, key, value; + }; + auto trim = [](const std::string& t) { + const size_t a = t.find_first_not_of(" \t"), b = t.find_last_not_of(" \t"); + return a == std::string::npos ? std::string() : t.substr(a, b - a + 1); + }; + std::vector items; + size_t pos = 0; + while (pos <= options.size()) { + size_t end = options.find(';', pos); + if (end == std::string::npos) end = options.size(); + Item it; + it.text = options.substr(pos, end - pos); + pos = end + 1; + const size_t eq = it.text.find('='); + it.key = trim(it.text.substr(0, eq)); + it.value = eq == std::string::npos ? std::string() : trim(it.text.substr(eq + 1)); + if (!it.key.empty()) items.push_back(it); + } + std::string last; + for (const Item& it : items) + if (it.key == "output_filter") last = it.value; + if (last != "quality5" && last != "quality9") return options; + std::string out; + for (const Item& it : items) { + if (it.key == "output_filter") continue; + out += (out.empty() ? "" : ";") + it.text; + } + if (note) + *note = "output_filter=" + last + " is not available on the D3D12 runtime yet; the default output filter is used " + "(the HIP executor is not started for it)"; + return out; +} + // A frame the executor did not take (nothing recorded) carries this prefix in its error (executor_d3d12.cpp, convert.cpp: // no output texture, a render size outside the configured maximum, an output texture without unordered access, ...). inline bool frame_refused(const std::string& err) { return err.rfind("frame not taken", 0) == 0; } diff --git a/clean/runtime/interop/tests/test_executor_select.cpp b/clean/runtime/interop/tests/test_executor_select.cpp index e710aa96..addda935 100644 --- a/clean/runtime/interop/tests/test_executor_select.cpp +++ b/clean/runtime/interop/tests/test_executor_select.cpp @@ -378,6 +378,39 @@ int main() { has(rl, "never to the HIP executor") && rl.find('\n') == std::string::npos); } + // ---- H3 (R1): the HIP-only output filters give the default filter on the D3D12 runtime, never HIP -------------------- + { + std::string note; + expect("no output_filter: nothing changes, no line", + wgi::drop_hip_only_filter("post_diet=0;k_input=16", ¬e) == "post_diet=0;k_input=16" && note.empty()); + expect("default / original / analytic stay as they are", + wgi::drop_hip_only_filter("output_filter=default", ¬e) == "output_filter=default" && + wgi::drop_hip_only_filter("a=1;output_filter=original;b=2", ¬e) == "a=1;output_filter=original;b=2" && + wgi::drop_hip_only_filter("output_filter=analytic", ¬e) == "output_filter=analytic" && note.empty()); + for (const char* q : {"quality5", "quality9"}) { + note.clear(); + const std::string out = wgi::drop_hip_only_filter(std::string("a=1;output_filter=") + q + ";b=2", ¬e); + expect(std::string(q) + ": the item is dropped, the others stay, one line, no HIP", + out == "a=1;b=2" && has(note, std::string("output_filter=") + q + " is not available on the D3D12 runtime yet") && + has(note, "default output filter") && note.find('\n') == std::string::npos); + } + note.clear(); + expect("spaces around the key and value are read as the runtime reads them", + wgi::drop_hip_only_filter("a=1; output_filter = quality9 ;b=2", ¬e) == "a=1;b=2" && !note.empty()); + note.clear(); + expect("the last output_filter wins: quality5 then analytic stays analytic", + wgi::drop_hip_only_filter("output_filter=quality5;output_filter=analytic", ¬e) == + "output_filter=quality5;output_filter=analytic" && note.empty()); + note.clear(); + expect("the last output_filter wins: analytic then quality9 gives the default filter", + wgi::drop_hip_only_filter("output_filter=analytic;x=1;output_filter=quality9", ¬e) == "x=1" && !note.empty()); + note.clear(); + expect("only the option's name is read: a value that merely contains it is not touched", + wgi::drop_hip_only_filter("model_dir=C:\\output_filter=quality5", ¬e) == "model_dir=C:\\output_filter=quality5" && + note.empty()); + expect("an empty option string gives an empty one", wgi::drop_hip_only_filter("", nullptr).empty()); + } + // ---- R1 (oversight): hip_switch=on is ignored for models M, L and K alike ---------------------------------------- // The selector sees a model only as "is it K"; M and L are the same request. For each of the three: on an RX 9000 board // the default stays the D3D12 executor with one line about the option, a refused frame never moves to HIP, and the diff --git a/clean/tests/test_executor_select.py b/clean/tests/test_executor_select.py index 6c510fac..ade6ebd5 100644 --- a/clean/tests/test_executor_select.py +++ b/clean/tests/test_executor_select.py @@ -127,6 +127,17 @@ def test_hip_switch_is_ignored_once_for_every_model(self): sel = read("clean", "runtime", "interop", "executor_select.h") self.assertNotIn("kSwitchToHip", sel) + def test_sparkle_guard_is_off_and_hip_only_filters_fall_back_for_every_model(self): + # R1-a / H4: the choice turns the guard off before anything is made, whatever the model + off = self.at("if (ch.sparkle_off) o.sparkle_guard = 0.0f;") + self.assertGreater(off, self.at("choose_executor(q)")) + self.assertNotIn("model_k", self.b[self.at("choose_executor(q)"):off]) + # H3: the HIP-only filters are dropped for a context on the D3D12 executor only, before the runtime reads them + drop = self.at("o.runtime = drop_hip_only_filter(o.runtime, &fnote);") + self.assertEqual(self.b.count("drop_hip_only_filter("), 1) + self.assertIn('if (ch.executor == "dx12")', self.b[drop - 200:drop]) + self.assertLess(drop, self.at("n_rtopts_ = o.runtime;")) + def test_rr_and_native_device_use_the_shared_id_rule(self): rr = read("clean", "rr_f", "runtime", "src", "rr_runtime.cpp") self.assertIn('#include "../../../runtime/rdna4_win.h"', rr) From ec0d3b6cc16a5fc365522e2503d720cdee7a6537 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 05:12:20 -0500 Subject: [PATCH 05/20] R1: launcher HIP-only tests, interop matrix case for the create refusal (H2) launcher_core_tests: NeedsHipRuntime and the help texts. test_interop_d3d12: matrix case (every DLSS-style ratio x output x declared maximum x HDR/LDR gets a default-executor context and a frame; none may reach the create refusal or a HIP line); clean/k/runner/k_refusal_matrix.py drives it with a synthetic model K. ui_activate: Runs on has two segments. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/installer/src/app/ui_activate.cpp | 3 +- clean/installer/tests/launcher_core_tests.cpp | 25 ++++++ clean/k/runner/k_refusal_matrix.py | 47 +++++++++++ .../interop/tests/test_interop_d3d12.cpp | 84 +++++++++++++++++++ 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 clean/k/runner/k_refusal_matrix.py diff --git a/clean/installer/src/app/ui_activate.cpp b/clean/installer/src/app/ui_activate.cpp index 90deb4e9..2e3d0e8e 100644 --- a/clean/installer/src/app/ui_activate.cpp +++ b/clean/installer/src/app/ui_activate.cpp @@ -125,7 +125,8 @@ void ActivateWidget(int id) { default: OpenGame(i); return; } } - if (id >= ID_G_EXEC0 && id < ID_G_EXEC0 + 2) { static const char* const x[] = {"auto", "dx12"}; // R1: no HIP choice SetSetting(v.edit, "executor", x[id - ID_G_EXEC0], nullptr); Invalidate(); return; } + // R1: Runs on offers Auto and Direct3D 12 only (HIP is a diagnostic in wronggpu.ini) + if (id >= ID_G_EXEC0 && id < ID_G_EXEC0 + 2) { static const char* const x[] = {"auto", "dx12"}; SetSetting(v.edit, "executor", x[id - ID_G_EXEC0], nullptr); Invalidate(); return; } if (id >= ID_G_PRE0 && id < ID_G_PRE0 + 2) { static const char* const x[] = {"scale", "original"}; SetSetting(v.edit, "pre_exposure", x[id - ID_G_PRE0], nullptr); Invalidate(); return; } if (id >= ID_G_RRMODE0 && id < ID_G_RRMODE0 + 3) { static const char* const x[] = {"exact", "accurate", "fast"}; SetSetting(v.edit, "rr_mode", x[id - ID_G_RRMODE0], nullptr); Invalidate(); return; } if (id >= ID_G_FPS0 && id < ID_G_FPS0 + 3) { static const char* const x[] = {"keep", "on", "off"}; SetSetting(v.edit, "fps_overlay", x[id - ID_G_FPS0], nullptr); Invalidate(); return; } diff --git a/clean/installer/tests/launcher_core_tests.cpp b/clean/installer/tests/launcher_core_tests.cpp index 66368d23..89ee4fb4 100644 --- a/clean/installer/tests/launcher_core_tests.cpp +++ b/clean/installer/tests/launcher_core_tests.cpp @@ -187,6 +187,31 @@ int main() { require(!SetSetting(p, "nosuchkey", "1", &why) && !SetSetting(p, "pre_exposure", "bright", &why), "unknown keys and bad values are refused by set"); require(SetSetting(p, "Executor", " HIP ", &why) && p.get("executor") == "hip", "set trims and lowers"); + // ---- R1: the choices that exist on the HIP runtime only are not offered on an RX 9000 card ---------------- + require(NeedsHipRuntime("executor", "hip") && NeedsHipRuntime("executor", " HIP "), "executor=hip needs the HIP runtime"); + require(!NeedsHipRuntime("executor", "auto") && !NeedsHipRuntime("executor", "dx12"), "auto and dx12 run on Direct3D 12"); + require(NeedsHipRuntime("output_filter", "quality5") && NeedsHipRuntime("output_filter", "quality9"), "Quality 5 / 9 need the HIP runtime"); + require(!NeedsHipRuntime("output_filter", "default") && !NeedsHipRuntime("output_filter", "original") && !NeedsHipRuntime("output_filter", "analytic"), + "the other output filters run on Direct3D 12"); + require(NeedsHipRuntime("sparkle_guard", "on") && NeedsHipRuntime("sparkle_guard", "0.25") && !NeedsHipRuntime("sparkle_guard", "off") && !NeedsHipRuntime("sparkle_guard", "0"), + "the sparkle guard needs the HIP runtime, off does not"); + require(!NeedsHipRuntime("pre_exposure", "original") && !NeedsHipRuntime("wronggpu", "off") && !NeedsHipRuntime("nosuchkey", "hip"), "no other key is HIP-only"); + require(wstring(NotOnDx12Text()) == L"Not available on the DX12 runtime yet", "the words the launcher shows"); + for (const char* key : {"executor", "output_filter", "sparkle_guard"}) { + const SettingDef* d = FindSetting(key); + const wstring help = d ? d->help : L""; + require(d && help.find(L"Uses HIP") == wstring::npos && help.find(L"Needs the HIP runtime") == wstring::npos && help.find(L"HIP is used anyway") == wstring::npos, + "the help text of a HIP-only setting no longer promises HIP"); + } + require(wstring(FindSetting("output_filter")->help).find(L"not available on the DX12 runtime yet") != wstring::npos && + wstring(FindSetting("sparkle_guard")->help).find(L"Not available on the DX12 runtime yet") != wstring::npos, + "the help texts say the same words"); + // a profile or ini that already holds one still renders (the runtime falls back with one log line; no HIP) + { + Profile q = DefaultProfile(); + require(SetSetting(q, "output_filter", "quality9", nullptr) && q.get("output_filter") == "quality9", "an existing quality9 profile is still valid"); + } + // ---- rendering wronggpu.ini --------------------------------------------------------------------------- const string front = "# WrongGPU settings\r\n[fsr]\r\n# who upscales\r\nupscaler = network\r\nruntime_dll = wronggpu_runtime.dll\r\n" "runtime_options = model=M ; the model\r\nfoo_unknown = 7\r\n[overlay]\r\nexecutor = keep-me\r\n"; diff --git a/clean/k/runner/k_refusal_matrix.py b/clean/k/runner/k_refusal_matrix.py new file mode 100644 index 00000000..2c93c273 --- /dev/null +++ b/clean/k/runner/k_refusal_matrix.py @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: MIT +"""R1 / H2: no supported Model K context reaches the D3D12 create refusal. Run under the shared GPU lock. + +Runs test_interop_d3d12.exe's `matrix` case against a runtime build with a synthetic Model K (generated here from random +parameters; an installed model is never read): every DLSS-style render ratio x output size x declared maximum x HDR / LDR +gets a default-executor context and one frame, and each must be taken by the D3D12 executor with no create refusal and no +HIP line. The same case takes the options of another model (Model M, L) when its files are given by the caller. + + python -m clean.k.runner.k_refusal_matrix --exe test_interop_d3d12.exe --build [--outputs 1080,1440,2160] +""" +import argparse +import os +from pathlib import Path +import subprocess + +from clean.k.reference.network import random_network_params +from clean.k.tests.test_k_runtime_gpu import write_k_model + + +def main(): + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("--exe", required=True) + ap.add_argument("--build", required=True, help="directory with wronggpu_runtime.dll and the kernels") + ap.add_argument("--out", required=True, help="folder for the synthetic model and the log") + ap.add_argument("--outputs", default="1080,1440,2160", help="output heights, comma separated") + a = ap.parse_args() + out = Path(a.out).resolve() + out.mkdir(parents=True, exist_ok=True) + model = out / "synthetic" + wgcm, mapfile = write_k_model(str(model), random_network_params(11)) + build = Path(a.build).resolve() + opts = ";".join(("model=K", "network=fused", f"kernels_dir={build}", f"model_dir={model}", + f"model_k_dir={Path(wgcm).parent}", f"model_k_map={mapfile}")) + env = os.environ.copy() + env.pop("WG_RUNTIME_OPTIONS", None) + proc = subprocess.run([str(Path(a.exe).resolve()), str(build / "wronggpu_runtime.dll"), "matrix", opts, a.outputs], + capture_output=True, text=True, env=env, check=False, timeout=160) + log = proc.stdout + proc.stderr + (out / "matrix.log").write_text(log, encoding="utf-8") + print("\n".join(l for l in log.splitlines() if "matrix" in l and ("FAIL" in l or "contexts" in l))) + ok = proc.returncode == 0 and log.rstrip().endswith("PASS") + print("PASS" if ok else "FAIL (see %s)" % (out / "matrix.log")) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/clean/runtime/interop/tests/test_interop_d3d12.cpp b/clean/runtime/interop/tests/test_interop_d3d12.cpp index d68a12bf..c6e7abd2 100644 --- a/clean/runtime/interop/tests/test_interop_d3d12.cpp +++ b/clean/runtime/interop/tests/test_interop_d3d12.cpp @@ -20,6 +20,9 @@ // WG_CREATE_MOTION_OUTPUT_RES), WG_TEST_MOTIONFMT=rg16f|rg32f, WG_TEST_PI (pre-exposure). // test_interop_d3d12.exe asyncsim "" [frames] [pre] [post] [iters] // A simulated game frame on the DIRECT queue and the network (executor=dx12) in its list or on a COMPUTE queue. +// test_interop_d3d12.exe matrix "" [output heights, default 1080,1440,2160] +// R1 / H2: every DLSS-style ratio x output size x declared maximum x HDR / LDR gets a default-executor context and a +// frame: each must be taken by the D3D12 executor (no create refusal, no HIP line); see case_matrix. // test_interop_d3d12.exe hipswitch "" "" // Creates, dispatches, destroys M -> K -> M in one process and verifies the HIP DLL stays loaded between them. // test_interop_d3d12.exe hipleak "" ["" | -] [cycles] [frames] [MiB per cycle] [hold] [thread] @@ -1783,6 +1786,82 @@ int debug_messages(Gpu& g, const char* when) { return errors; } +// "matrix" "" [outputs]: R1 / H2. No supported context may reach the create refusal (the D3D12 executor refusing a +// context: one warning line, no context, the front end's own upscaler keeps the game). Every launcher-reachable shape of a +// default-executor context is created on this device and given a frame: the DLSS-style render ratios (DLAA 1.0, Quality +// 0.667, Balanced 0.58, Performance 0.5, Ultra Performance 0.333) of each output size (`outputs`: a comma list of heights, +// default 1080,1440,2160), the declared maximum render size both as the game usually gives it (a little above the render +// size) and equal to the output (as Cyberpunk declares it), HDR (RGBA16F output) and LDR (RGBA8 output). Each context must +// log "network runtime ready: executor dx12" and none of "could not take this context", "does not take this frame", +// "about to start the HIP runtime" or "the HIP executor"; its frame must be WG_OK. No `executor` key is given: the +// default rule (D3D12 on an RX 9000 card) is what is tested. The options name the model (a synthetic model for K). +bool case_matrix(Gpu& g, const char* dll, const std::string& options, const std::string& outputs) { + struct Mode { + const char* name; + double ratio; + }; + const Mode modes[] = {{"DLAA", 1.0}, {"Quality", 0.667}, {"Balanced", 0.58}, {"Performance", 0.5}, {"UltraPerformance", 0.333}}; + std::vector heights; + for (size_t pos = 0; pos <= outputs.size();) { + size_t end = outputs.find(',', pos); + if (end == std::string::npos) end = outputs.size(); + if (end > pos) heights.push_back((UINT)std::atoi(outputs.substr(pos, end - pos).c_str())); + pos = end + 1; + } + int contexts = 0, refused = 0; + for (const UINT oh : heights) { + const UINT ow = oh * 16 / 9; + for (const Mode& m : modes) { + for (const bool hdr : {true, false}) { + Scene s; + s.ow = ow, s.oh = oh; + s.rw = (UINT)(ow * m.ratio + 0.5), s.rh = (UINT)(oh * m.ratio + 0.5); + s.tw = s.mw = s.rw, s.th = s.mh = s.rh, s.rx = s.ry = 0; + if (!hdr) s.outRes = s.outFmt = DXGI_FORMAT_R8G8B8A8_UNORM; + s.make(g); + for (const bool declared_output : {false, true}) { + const UINT mw = declared_output ? ow : s.rw + 8, mh = declared_output ? oh : s.rh + 8; + _putenv_s("WG_TEST_MAX_RENDER_WIDTH", std::to_string(mw).c_str()); + _putenv_s("WG_TEST_MAX_RENDER_HEIGHT", std::to_string(mh).c_str()); + g_log.clear(); + Ctx c; + c.g = &g; + if (!c.be.load(dll)) return false; + const std::string label = std::string(m.name) + " " + std::to_string(s.rw) + "x" + std::to_string(s.rh) + " -> " + + std::to_string(ow) + "x" + std::to_string(oh) + (hdr ? " HDR" : " LDR") + + (declared_output ? " max=output" : " max=render+8"); + const WgResult r = c.create(s, (hdr ? WG_CREATE_HDR : 0u) | WG_CREATE_DEPTH_INVERTED, options.c_str()); + ++contexts; + WgResult rr = WG_ERROR; + if (r == WG_OK) { + s.set_color(g, 1); + WgFrame f = s.frame(g, 1); + f.motion_scale[0] = f.motion_scale[1] = 1.0f; + f.reset = 1; + c.run(s, f, &rr); + } + bool ready = false, bad = false; + for (const auto& line : g_log) { + ready |= line.find("network runtime ready: executor dx12") != std::string::npos; + const bool refusal = line.find("could not take this context") != std::string::npos; + refused += refusal; + bad |= refusal || line.find("does not take this frame") != std::string::npos || + line.find("about to start the HIP runtime") != std::string::npos || + line.find("the HIP executor") != std::string::npos; + } + const bool ok = r == WG_OK && rr == WG_OK && ready && !bad; + std::printf(" matrix %s: create %d, frame %d, ready dx12 %d, refusal or HIP line %d%s\n", label.c_str(), (int)r, (int)rr, + (int)ready, (int)bad, ok ? "" : " <-- FAIL"); + CHECK(ok); + } + } + } + } + std::printf(" matrix: %d contexts, %d create refusals\n", contexts, refused); + CHECK(refused == 0 && contexts > 0); + return refused == 0 && !g_fail; +} + bool case_dx12_same(Gpu& g, const char* dll, const std::string& common, int frames, bool outsrv) { Scene s; s.tw = 1707, s.th = 960, s.rx = 0, s.ry = 0, s.rw = 1707, s.rh = 960, s.ow = 2560, s.oh = 1440, s.mw = 1707, @@ -2496,6 +2575,11 @@ int main(int argc, char** argv) { std::puts(ok && !g_fail ? "PASS" : "FAIL"); return ok && !g_fail ? 0 : 1; } + if (only == "matrix") { + const bool ok = case_matrix(g, dll, argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "1080,1440,2160"); + std::puts(ok && !g_fail ? "PASS" : "FAIL"); + return ok && !g_fail ? 0 : 1; + } if (only == "hipswitch") { if (argc < 5) { std::puts("hipswitch requires Model M and Model K option strings"); return 2; } const bool ok = case_hipswitch(g, dll, argv[3], argv[4]); From dd381b04e9843faa9bc0208b3ec8098715a48556 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 05:04:16 -0500 Subject: [PATCH 06/20] H2 matrix: format-agnostic readback, narrower HIP-line check, hip_switch=on case The matrix case reads the output with the any-format readback (the LDR output is RGBA8), recognises a HIP executor by its ready line and the switch line by its text, and with hip_switch=on in the options requires the one 'ignored' line per context. The driver takes --hip-switch-on. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/k/runner/k_refusal_matrix.py | 5 +++- .../interop/tests/test_interop_d3d12.cpp | 27 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/clean/k/runner/k_refusal_matrix.py b/clean/k/runner/k_refusal_matrix.py index 2c93c273..0a19e6d3 100644 --- a/clean/k/runner/k_refusal_matrix.py +++ b/clean/k/runner/k_refusal_matrix.py @@ -23,6 +23,8 @@ def main(): ap.add_argument("--build", required=True, help="directory with wronggpu_runtime.dll and the kernels") ap.add_argument("--out", required=True, help="folder for the synthetic model and the log") ap.add_argument("--outputs", default="1080,1440,2160", help="output heights, comma separated") + ap.add_argument("--hip-switch-on", action="store_true", + help="add hip_switch=on (ignored for every model): one log line per context, still Direct3D 12") a = ap.parse_args() out = Path(a.out).resolve() out.mkdir(parents=True, exist_ok=True) @@ -30,7 +32,8 @@ def main(): wgcm, mapfile = write_k_model(str(model), random_network_params(11)) build = Path(a.build).resolve() opts = ";".join(("model=K", "network=fused", f"kernels_dir={build}", f"model_dir={model}", - f"model_k_dir={Path(wgcm).parent}", f"model_k_map={mapfile}")) + f"model_k_dir={Path(wgcm).parent}", f"model_k_map={mapfile}") + + (("hip_switch=on",) if a.hip_switch_on else ())) env = os.environ.copy() env.pop("WG_RUNTIME_OPTIONS", None) proc = subprocess.run([str(Path(a.exe).resolve()), str(build / "wronggpu_runtime.dll"), "matrix", opts, a.outputs], diff --git a/clean/runtime/interop/tests/test_interop_d3d12.cpp b/clean/runtime/interop/tests/test_interop_d3d12.cpp index c6e7abd2..db169b52 100644 --- a/clean/runtime/interop/tests/test_interop_d3d12.cpp +++ b/clean/runtime/interop/tests/test_interop_d3d12.cpp @@ -1793,8 +1793,9 @@ int debug_messages(Gpu& g, const char* when) { // default 1080,1440,2160), the declared maximum render size both as the game usually gives it (a little above the render // size) and equal to the output (as Cyberpunk declares it), HDR (RGBA16F output) and LDR (RGBA8 output). Each context must // log "network runtime ready: executor dx12" and none of "could not take this context", "does not take this frame", -// "about to start the HIP runtime" or "the HIP executor"; its frame must be WG_OK. No `executor` key is given: the -// default rule (D3D12 on an RX 9000 card) is what is tested. The options name the model (a synthetic model for K). +// "about to start the HIP runtime", "network runtime ready: executor hip" or "the HIP executor runs"; its frame must be WG_OK. No `executor` key is given: the +// default rule (D3D12 on an RX 9000 card) is what is tested. The options name the model (a synthetic model for K). With +// hip_switch=on in the options (R1: ignored for every model) each context must log the one "hip_switch=on is ignored" line. bool case_matrix(Gpu& g, const char* dll, const std::string& options, const std::string& outputs) { struct Mode { const char* name; @@ -1809,6 +1810,7 @@ bool case_matrix(Gpu& g, const char* dll, const std::string& options, const std: pos = end + 1; } int contexts = 0, refused = 0; + const bool switch_on = options.find("hip_switch=on") != std::string::npos; // R1: ignored, one line, no HIP for (const UINT oh : heights) { const UINT ow = oh * 16 / 9; for (const Mode& m : modes) { @@ -1838,20 +1840,31 @@ bool case_matrix(Gpu& g, const char* dll, const std::string& options, const std: WgFrame f = s.frame(g, 1); f.motion_scale[0] = f.motion_scale[1] = 1.0f; f.reset = 1; - c.run(s, f, &rr); + g.begin(); + f.command_list = g.list; + rr = c.be.b->dispatch(c.u, &f); + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp = {}; // any output format: the bytes are not read here, the copy + UINT64 rowBytes = 0; // makes the game's next pass touch the output + UINT rows = 0; + ID3D12Resource* rb = record_readback_any(g, s.out, s.outState, &fp, &rowBytes, &rows); + c.fe.submit(); + rb->Release(); } bool ready = false, bad = false; + int ignored = 0; for (const auto& line : g_log) { + ignored += line.find("hip_switch=on is ignored") != std::string::npos; ready |= line.find("network runtime ready: executor dx12") != std::string::npos; const bool refusal = line.find("could not take this context") != std::string::npos; refused += refusal; bad |= refusal || line.find("does not take this frame") != std::string::npos || line.find("about to start the HIP runtime") != std::string::npos || - line.find("the HIP executor") != std::string::npos; + line.find("network runtime ready: executor hip") != std::string::npos || + line.find("the HIP executor runs") != std::string::npos; } - const bool ok = r == WG_OK && rr == WG_OK && ready && !bad; - std::printf(" matrix %s: create %d, frame %d, ready dx12 %d, refusal or HIP line %d%s\n", label.c_str(), (int)r, (int)rr, - (int)ready, (int)bad, ok ? "" : " <-- FAIL"); + const bool ok = r == WG_OK && rr == WG_OK && ready && !bad && ignored == (switch_on ? 1 : 0); + std::printf(" matrix %s: create %d, frame %d, ready dx12 %d, refusal or HIP line %d, hip_switch line %d%s\n", + label.c_str(), (int)r, (int)rr, (int)ready, (int)bad, ignored, ok ? "" : " <-- FAIL"); CHECK(ok); } } From 81248363166831daff2cc34119494755dbb6c745 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 05:09:15 -0500 Subject: [PATCH 07/20] Matrix comments: reword the mode names for the leak scan Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/k/runner/k_refusal_matrix.py | 2 +- clean/runtime/interop/tests/test_interop_d3d12.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clean/k/runner/k_refusal_matrix.py b/clean/k/runner/k_refusal_matrix.py index 0a19e6d3..aef762d2 100644 --- a/clean/k/runner/k_refusal_matrix.py +++ b/clean/k/runner/k_refusal_matrix.py @@ -2,7 +2,7 @@ """R1 / H2: no supported Model K context reaches the D3D12 create refusal. Run under the shared GPU lock. Runs test_interop_d3d12.exe's `matrix` case against a runtime build with a synthetic Model K (generated here from random -parameters; an installed model is never read): every DLSS-style render ratio x output size x declared maximum x HDR / LDR +parameters; an installed model is never read): every usual upscaler-mode render ratio x output size x declared maximum x HDR / LDR gets a default-executor context and one frame, and each must be taken by the D3D12 executor with no create refusal and no HIP line. The same case takes the options of another model (Model M, L) when its files are given by the caller. diff --git a/clean/runtime/interop/tests/test_interop_d3d12.cpp b/clean/runtime/interop/tests/test_interop_d3d12.cpp index db169b52..e14a1cc7 100644 --- a/clean/runtime/interop/tests/test_interop_d3d12.cpp +++ b/clean/runtime/interop/tests/test_interop_d3d12.cpp @@ -21,7 +21,7 @@ // test_interop_d3d12.exe asyncsim "" [frames] [pre] [post] [iters] // A simulated game frame on the DIRECT queue and the network (executor=dx12) in its list or on a COMPUTE queue. // test_interop_d3d12.exe matrix "" [output heights, default 1080,1440,2160] -// R1 / H2: every DLSS-style ratio x output size x declared maximum x HDR / LDR gets a default-executor context and a +// R1 / H2: every usual upscaler-mode ratio x output size x declared maximum x HDR / LDR gets a default-executor context and a // frame: each must be taken by the D3D12 executor (no create refusal, no HIP line); see case_matrix. // test_interop_d3d12.exe hipswitch "" "" // Creates, dispatches, destroys M -> K -> M in one process and verifies the HIP DLL stays loaded between them. @@ -1788,7 +1788,7 @@ int debug_messages(Gpu& g, const char* when) { // "matrix" "" [outputs]: R1 / H2. No supported context may reach the create refusal (the D3D12 executor refusing a // context: one warning line, no context, the front end's own upscaler keeps the game). Every launcher-reachable shape of a -// default-executor context is created on this device and given a frame: the DLSS-style render ratios (DLAA 1.0, Quality +// default-executor context is created on this device and given a frame: the usual upscaler-mode render ratios (DLAA 1.0, Quality // 0.667, Balanced 0.58, Performance 0.5, Ultra Performance 0.333) of each output size (`outputs`: a comma list of heights, // default 1080,1440,2160), the declared maximum render size both as the game usually gives it (a little above the render // size) and equal to the output (as Cyberpunk declares it), HDR (RGBA16F output) and LDR (RGBA8 output). Each context must From 713b86f9e05c503d6f4be8f06a7119acbd4ee97d Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 06:35:12 -0500 Subject: [PATCH 08/20] H2 matrix driver: Model M and L with converted model files (read only) --model M|L --model-dir runs the same contexts with the files the caller names (M: model.wgcm in the folder; L: L/model.wgcm); K keeps the synthetic model. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/k/runner/k_refusal_matrix.py | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/clean/k/runner/k_refusal_matrix.py b/clean/k/runner/k_refusal_matrix.py index aef762d2..bd07fae3 100644 --- a/clean/k/runner/k_refusal_matrix.py +++ b/clean/k/runner/k_refusal_matrix.py @@ -1,12 +1,14 @@ # SPDX-License-Identifier: MIT -"""R1 / H2: no supported Model K context reaches the D3D12 create refusal. Run under the shared GPU lock. +"""R1 / H2: no supported context reaches the D3D12 create refusal. Run under the shared GPU lock. -Runs test_interop_d3d12.exe's `matrix` case against a runtime build with a synthetic Model K (generated here from random -parameters; an installed model is never read): every usual upscaler-mode render ratio x output size x declared maximum x HDR / LDR -gets a default-executor context and one frame, and each must be taken by the D3D12 executor with no create refusal and no -HIP line. The same case takes the options of another model (Model M, L) when its files are given by the caller. +Runs test_interop_d3d12.exe's `matrix` case against a runtime build: every usual upscaler-mode render ratio x output size x +declared maximum x HDR / LDR gets a default-executor context and one frame, and each must be taken by the D3D12 executor +with no create refusal and no HIP line. Model K runs with a synthetic model (generated here from random parameters; an +installed model is never read). Model M and Model L run with converted model files the caller names (--model-dir: the +folder with model.wgcm for M, the folder with L\\model.wgcm for L); the files are only read. - python -m clean.k.runner.k_refusal_matrix --exe test_interop_d3d12.exe --build [--outputs 1080,1440,2160] + python -m clean.k.runner.k_refusal_matrix --exe test_interop_d3d12.exe --build --out [--outputs 1080,1440,2160] + python -m clean.k.runner.k_refusal_matrix ... --model M --model-dir (or --model L) """ import argparse import os @@ -23,17 +25,24 @@ def main(): ap.add_argument("--build", required=True, help="directory with wronggpu_runtime.dll and the kernels") ap.add_argument("--out", required=True, help="folder for the synthetic model and the log") ap.add_argument("--outputs", default="1080,1440,2160", help="output heights, comma separated") + ap.add_argument("--model", choices=("K", "M", "L"), default="K") + ap.add_argument("--model-dir", help="M, L: the folder with the converted model (M: model.wgcm; L: L\\model.wgcm)") ap.add_argument("--hip-switch-on", action="store_true", help="add hip_switch=on (ignored for every model): one log line per context, still Direct3D 12") a = ap.parse_args() out = Path(a.out).resolve() out.mkdir(parents=True, exist_ok=True) - model = out / "synthetic" - wgcm, mapfile = write_k_model(str(model), random_network_params(11)) build = Path(a.build).resolve() - opts = ";".join(("model=K", "network=fused", f"kernels_dir={build}", f"model_dir={model}", - f"model_k_dir={Path(wgcm).parent}", f"model_k_map={mapfile}") + - (("hip_switch=on",) if a.hip_switch_on else ())) + if a.model == "K": + model = out / "synthetic" + wgcm, mapfile = write_k_model(str(model), random_network_params(11)) + base = ("model=K", "network=fused", f"kernels_dir={build}", f"model_dir={model}", + f"model_k_dir={Path(wgcm).parent}", f"model_k_map={mapfile}") + else: + if not a.model_dir: + ap.error("--model-dir is required for model M and L") + base = (f"model={a.model}", f"kernels_dir={build}", f"model_dir={Path(a.model_dir).resolve()}") + opts = ";".join(base + (("hip_switch=on",) if a.hip_switch_on else ())) env = os.environ.copy() env.pop("WG_RUNTIME_OPTIONS", None) proc = subprocess.run([str(Path(a.exe).resolve()), str(build / "wronggpu_runtime.dll"), "matrix", opts, a.outputs], From 442fcd8371a43e7d61f8f39458a0981cceeccaef Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 06:50:41 -0500 Subject: [PATCH 09/20] R1: no in-game route to HIP; refused frames and creates always go to the front end Release builds ignore executor=hip and capture_dir with one logged line each ('ignored: diagnostic key, release build') and keep the context on Direct3D 12; the two diagnostics exist only in a developer build (WG_DEV_DIAGNOSTICS, build.py --dev-diagnostics). The library says which kind it is (wgBuildMarker) and check_no_dev_diagnostics.py checks it. A profile.ini or wronggpu.ini that holds executor=hip loses the key (install, repair and update log it). A refused frame is answered WG_ERROR_UNSUPPORTED for every model and every executor choice, also a forced executor=dx12: no bilinear substitute. A create the runtime refuses as a hard incompatibility (WG_ERROR_UNSUPPORTED) goes to the front end's upscaler whatever fallback_to_amd says; a create that does not finish in create_giveup_ms (30 s) is refused and handed over instead of waiting for ever. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/README.md | 12 ++ clean/fsr/src/config.cpp | 7 +- clean/fsr/src/config.h | 4 + clean/fsr/src/frontend.cpp | 27 ++- clean/fsr/tests/test_frontend.cpp | 74 +++++++- clean/installer/src/app/ui_game.cpp | 12 +- clean/installer/src/wg_core/launcher.cpp | 7 +- clean/installer/src/wg_core/profile.cpp | 13 +- clean/installer/src/wg_core/profile.h | 5 + clean/installer/tests/launcher_core_tests.cpp | 41 ++++- clean/runner/build.py | 10 ++ clean/runtime/interop/backend.cpp | 24 ++- clean/runtime/interop/executor_select.h | 77 +++++--- .../interop/tests/test_executor_select.cpp | 168 +++++++++++------- clean/tests/check_no_dev_diagnostics.py | 69 +++++++ clean/tests/test_dev_diagnostics_off.py | 82 +++++++++ clean/tests/test_executor_select.py | 38 +++- 17 files changed, 540 insertions(+), 130 deletions(-) create mode 100644 clean/tests/check_no_dev_diagnostics.py create mode 100644 clean/tests/test_dev_diagnostics_off.py diff --git a/clean/fsr/README.md b/clean/fsr/README.md index 9213ea9c..3e541c4f 100644 --- a/clean/fsr/README.md +++ b/clean/fsr/README.md @@ -270,6 +270,18 @@ OptiScaler folder ships `amd_fidelityfx_upscaler_dx12.dll`; OptiScaler.ini `[Lib D3D12 executor: frames above the render size checked at create) hands the context to AMD's FSR at once; without AMD's FSR the stand-in upscales such frames. No model moves to the HIP executor in a game; the old option `hip_switch=on` is ignored with one log line. +- **Creates the runtime refuses:** a create the runtime answers `WG_ERROR_UNSUPPORTED` (an adapter that is not an RX 9000-series + card, a build without its Direct3D 12 kernel set, a Direct3D 12 executor that cannot take the context) is a hard + incompatibility, not a runtime failure: the context goes to AMD's FSR whatever `fallback_to_amd` says (`fallback_to_amd = 0` + governs runtime failures only). With no AMD provider the answer is `NO_PROVIDER`, explicitly: the game gets no context from + WrongGPU and no silent substitute (OptiScaler's custom slot hands the game back to its host). A create that does not finish + in `create_giveup_ms` (default 30000; only when nothing could upscale meanwhile: `fallback_to_amd = 0`, or a custom slot + without an AMD DLL of its own) is refused, logged, and the context goes to AMD's FSR for now (the late result takes over, as + for a create that outlasts `create_wait_ms`); the game's thread does not wait for ever. +- **Developer diagnostics are not in a game:** `executor=hip` and `capture_dir` are ignored in a release build of the runtime + (one log line: `ignored: diagnostic key, release build`); the context stays on Direct3D 12. They work in a developer build + only (`clean/runner/build.py --dev-diagnostics`, `WG_DEV_DIAGNOSTICS`), which no release or package is; the library says which + kind it is (`wg-build dev-diagnostics=0|1`, `clean/tests/check_no_dev_diagnostics.py`). - **Model location:** the front end looks for the converted model (`model.wgcm`, Model K in `K\`) in `[fsr] model_dir` of `wronggpu.ini` (relative: from the data folder), then `\WrongGPU\model`, and passes the first folder that has it to the runtime as `model_dir=`; otherwise the runtime's own default (`%LOCALAPPDATA%\WrongGPU\model`, diff --git a/clean/fsr/src/config.cpp b/clean/fsr/src/config.cpp index 62ad2301..507f491c 100644 --- a/clean/fsr/src/config.cpp +++ b/clean/fsr/src/config.cpp @@ -335,6 +335,10 @@ Config ParseConfig(const std::string& text, std::string* warnings) { float f = 0; ok = ParseFloat(value, f) && f >= 0.0f && f <= 600000.0f; if (ok) c.createWaitMs = static_cast(f); + } else if (key == "create_giveup_ms") { + float f = 0; + ok = ParseFloat(value, f) && f >= 1.0f && f <= 600000.0f; + if (ok) c.createGiveUpMs = static_cast(f); } else if (key == "context_park_ms") { float f = 0; ok = ParseFloat(value, f) && f >= 0.0f && f <= 60000.0f; @@ -512,7 +516,8 @@ std::string Config::Describe() const { // Paths (runtime_dll, runtime_options) can be long: no fixed-size buffer for them. return std::string("upscaler=") + up + " runtime_dll=" + runtimeDll + (modelDir.empty() ? "" : " model_dir=" + modelDir) + " fallback_to_amd=" + (fallbackToAmd ? "1" : "0") + - " create_wait_ms=" + std::to_string(createWaitMs) + " context_park_ms=" + std::to_string(contextParkMs) + " " + + " create_wait_ms=" + std::to_string(createWaitMs) + " create_giveup_ms=" + std::to_string(createGiveUpMs) + + " context_park_ms=" + std::to_string(contextParkMs) + " " + BackendOptions() + buffer; } diff --git a/clean/fsr/src/config.h b/clean/fsr/src/config.h index e91422f5..f496c70a 100644 --- a/clean/fsr/src/config.h +++ b/clean/fsr/src/config.h @@ -37,6 +37,10 @@ struct Config { // How long a game thread waits for the upscaler's create (async_create.h); after that AMD's FSR upscales until the // create finishes (with fallbackToAmd; without it the game thread waits until the create finishes). uint32_t createWaitMs = 3000; + // The longest a game thread waits for the upscaler's create when AMD's FSR cannot upscale meanwhile (fallback_to_amd = 0, + // or a custom slot without an AMD DLL of its own). After that the create is refused, logged, and the context goes to + // the front end's upscaler (a create that hangs must not hang the game). create_giveup_ms. + uint32_t createGiveUpMs = 30000; // A destroyed upscaler context keeps its upscaler warm ("parked") for this long; a context created with the same // device, sizes, flags, options and model within that time takes it over instead of creating one (games that // re-create their upscaler at every step of a dynamic resolution). One parked upscaler at most; 0: never. diff --git a/clean/fsr/src/frontend.cpp b/clean/fsr/src/frontend.cpp index bf7ddadc..be280970 100644 --- a/clean/fsr/src/frontend.cpp +++ b/clean/fsr/src/frontend.cpp @@ -657,6 +657,10 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes } std::string why; + // R1: a create the runtime refuses as a HARD INCOMPATIBILITY (WG_ERROR_UNSUPPORTED: an adapter that is not an RDNA 4 + // card, a build without its D3D12 kernel set, a D3D12 executor that cannot take the context) or that does not finish in + // time always goes to the front end's upscaler, whatever fallback_to_amd says: that option governs runtime failures only. + bool hardIncompat = false; bool repeatedFailure = false; // custom slot: a failure remembered for the session, not tried again if (forceAmd) { why = "OptiScaler plugin: AMD FSR selected"; @@ -748,13 +752,13 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes ms + " ms ago): nothing is created, the first frame starts without history"); } else { // On a worker thread: the game's thread waits create_wait_ms at most (async_create.h). Without the fallback to - // AMD there is nothing else to upscale with, so it waits until the create finishes. + // AMD there is nothing else to upscale with, so it waits for the create, but not for ever: create_giveup_ms. // Custom slot without an AMD DLL of its own there is nothing to upscale with meanwhile: it waits as with // fallback_to_amd = 0. const bool amdMeanwhile = config_.fallbackToAmd && (!config_.customSlot || UpscaleFallbackApi()); u->creating = true; auto pending = PendingCreate::Start(backend, u->createInfo); - if (pending->Wait(amdMeanwhile ? config_.createWaitMs : UINT32_MAX)) { + if (pending->Wait(amdMeanwhile ? config_.createWaitMs : config_.createGiveUpMs)) { u->creating = false; if (u->failReason.empty()) u->failReason = u->createError; const WgResult r = pending->Result(); @@ -780,11 +784,13 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes if (again) backend->destroy(again); if (u->failReason.empty()) u->failReason = u->createError; why = std::string("upscaler \"") + backend->name + "\" create without the split service failed: " + WgResultText(r2); + hardIncompat = hardIncompat || r2 == WG_ERROR_UNSUPPORTED; } } } else { why = std::string("upscaler \"") + backend->name + "\" create failed: " + WgResultText(r); u->upscaler = nullptr; + hardIncompat = r == WG_ERROR_UNSUPPORTED; } if (!u->backend && config_.customSlot) { const std::string reason = u->createError.empty() ? why : why + ": " + u->createError; @@ -798,8 +804,16 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes } else { u->pending = pending; u->pendingBackend = backend; - why = std::string("upscaler \"") + backend->name + "\" is still starting after " + std::to_string(config_.createWaitMs) + - " ms (create_wait_ms); it takes over when it has started"; + if (amdMeanwhile) { + why = std::string("upscaler \"") + backend->name + "\" is still starting after " + std::to_string(config_.createWaitMs) + + " ms (create_wait_ms); it takes over when it has started"; + } else { + // nothing could upscale meanwhile and the create did not finish: refused (create_giveup_ms), the context goes + // to the front end's upscaler; the late result takes over if it comes (as for a bounded create) + hardIncompat = true; + why = std::string("upscaler \"") + backend->name + "\" did not finish its create in " + + std::to_string(config_.createGiveUpMs) + " ms (create_giveup_ms): refused"; + } } } } else if (why.empty()) { @@ -816,7 +830,7 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes delete u; return FFX_API_RETURN_ERROR_RUNTIME_ERROR; } - if (config_.upscaler != UpscalerChoice::Amd && !config_.fallbackToAmd) { + if (config_.upscaler != UpscalerChoice::Amd && !config_.fallbackToAmd && !hardIncompat) { Log(tag + " -> ERROR_RUNTIME_ERROR: " + why + " (fallback_to_amd = 0)"); delete u; return FFX_API_RETURN_ERROR_RUNTIME_ERROR; @@ -837,7 +851,8 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes } return FFX_API_RETURN_NO_PROVIDER; } - Log(tag + " upscaler context goes to AMD FSR" + (u->pending ? " for now" : "") + ": " + why); + Log(tag + " upscaler context goes to AMD FSR" + (u->pending ? " for now" : "") + ": " + why + + (hardIncompat && !config_.fallbackToAmd ? " (a hard incompatibility or a create that did not finish: fallback_to_amd = 0 does not apply)" : "")); if (!u->pending && (u->failReason.empty() || config_.upscaler == UpscalerChoice::Amd)) u->failReason = why; const ffxReturnCode_t rc = config_.hosted ? CreateAmdWithoutPrivateVersion(*original, &u->amd, desc, memCb) : original->createContext(&u->amd, desc, memCb); diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 5e733173..57390c18 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -157,6 +157,7 @@ static std::function g_timerFn; static int g_timersStarted = 0; static std::atomic g_createGate{true}; // FakeCreate (on the front end's create thread) waits while false static std::atomic g_createCalls{0}; // every FakeCreate call (made an upscaler or not) +static bool g_failCreateUnsupported = false; // FakeCreate answers WG_ERROR_UNSUPPORTED (a hard incompatibility, R1) static WgResult FakeCreate(const WgCreateInfo* info, WgUpscaler** out) { ++g_createCalls; g_createInfo = *info; @@ -164,6 +165,7 @@ static WgResult FakeCreate(const WgCreateInfo* info, WgUpscaler** out) { while (!g_createGate) std::this_thread::sleep_for(std::chrono::milliseconds(1)); if (g_aboutTo) info->log(info->log_user, WG_LOG_INFO, "about to start the HIP runtime (test)"); info->log(info->log_user, WG_LOG_INFO, "fake upscaler created"); + if (g_failCreateUnsupported) return WG_ERROR_UNSUPPORTED; if (g_failCreate || (g_failCreateOutputWidth && info->output_width == g_failCreateOutputWidth)) return WG_ERROR_DEVICE; *out = reinterpret_cast(new FakeUpscaler{1}); ++g_created; @@ -341,6 +343,7 @@ static void Reset() { g_log.clear(); g_destroyed = 0; g_failCreate = false; + g_failCreateUnsupported = false; g_failCreateOutputWidth = 0; g_failDispatchAt = -1; g_notReadyUntil = 0; @@ -1187,6 +1190,72 @@ static void TestHostedSwitchNotParked() { CHECK(fe->DestroyContext(&a, kMemCb) == FFX_API_RETURN_OK); } +// R1 (Codex review of #225): a create the runtime refuses as a HARD INCOMPATIBILITY (WG_ERROR_UNSUPPORTED: an adapter that is not +// an RDNA 4 card, a build without its D3D12 kernel set, a D3D12 executor that cannot take the context) always goes to the front +// end's upscaler, whatever fallback_to_amd says; a runtime failure still obeys fallback_to_amd; with no AMD provider the answer +// is the explicit NO_PROVIDER; and a create that does not finish within create_giveup_ms (nothing could upscale meanwhile) is +// refused and goes to AMD's FSR too: the game's thread does not wait for ever. +static void TestHardIncompatibilityHandover() { + UpscaleCreate c(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE); + for (const bool fallback : {true, false}) { // unsupported: AMD's FSR with and without fallback_to_amd + Reset(); + g_failCreateUnsupported = true; + Config config; + config.fallbackToAmd = fallback; + auto fe = MakeFrontEnd(config); + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_OK); + CHECK(ctx != nullptr && g_amd.size() == 1 && g_amd[0].fn == "create" && CountLog("goes to AMD FSR") == 1); + CHECK((CountLog("fallback_to_amd = 0 does not apply") == 1) == !fallback); + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + } + { // a runtime failure (not UNSUPPORTED) still obeys fallback_to_amd = 0 + Reset(); + g_failCreate = true; + Config config; + config.fallbackToAmd = false; + auto fe = MakeFrontEnd(config); + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_ERROR_RUNTIME_ERROR); + CHECK(ctx == nullptr && g_amd.empty()); + } + for (const bool fallback : {true, false}) { // unsupported and no AMD provider: explicit, never a silent success + Reset(); + g_failCreateUnsupported = true; + g_originalAvailable = false; + Config config; + config.fallbackToAmd = fallback; + auto fe = MakeFrontEnd(config); + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_NO_PROVIDER); + CHECK(ctx == nullptr && g_amd.empty() && CountLog("-> NO_PROVIDER") == 1); + g_originalAvailable = true; + } + for (const bool fallback : {false}) { // a create that never finishes: bounded, refused, handed over (fallback_to_amd = 0) + Reset(); + Config config; + config.fallbackToAmd = fallback; + config.createGiveUpMs = 60; + auto fe = MakeFrontEnd(config); + ffxContext ctx = nullptr; + g_createGate = false; + const auto t0 = std::chrono::steady_clock::now(); + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_OK); + const auto ms = std::chrono::duration_cast(std::chrono::steady_clock::now() - t0).count(); + CHECK(ms >= 50 && ms < 5000); // waited for the bound, not for ever + CHECK(ctx != nullptr && g_amd.size() == 1 && g_amd[0].fn == "create"); + CHECK(CountLog("did not finish its create in 60 ms (create_giveup_ms): refused") == 1 && CountLog("goes to AMD FSR for now") == 1); + g_createGate = true; // the late create finishes; the context is destroyed cleanly + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + for (int i = 0; i < 400 && g_destroyed == 0; ++i) std::this_thread::sleep_for(std::chrono::milliseconds(5)); + CHECK(g_destroyed == 1); + } + { // the default bound is generous (a create takes seconds, not tens of seconds) and the key parses + Config config; + CHECK(config.createGiveUpMs == 30000); + } +} + // The upscaler's create takes longer than create_wait_ms (Borderlands 4: HIP's start blocked while the game's thread // waited for it): the game's create returns with AMD's FSR upscaling; the first dispatch after the create finished takes // the upscaler over (with a reset frame). A context destroyed while its create runs is cleaned up when it finishes. @@ -2393,7 +2462,7 @@ static void TestUnsupportedFrames() { } // REVIEW-215c: a refused frame of model K takes the same front-end path as model M's. The backend's answer comes from the -// real policy (wgi::refused_frame_action, executor_select.h: a refused K frame, and a refused M frame, +// real policy (wgi::kRefusedFrameGoesToFrontEnd, executor_select.h: a refused K frame, and a refused M frame, // are answered WG_ERROR_UNSUPPORTED, never a switch to HIP and never a bilinear fallback), the fake upscaler answers // that for the refused frames, and the front end must give every frame an upscaler: AMD's FSR when it exists (it takes // the context over at the first refusal, as for model M), else the stand-in for each refused frame (any number in a row, @@ -2401,7 +2470,7 @@ static void TestUnsupportedFrames() { static void TestRefusedFrames() { for (const bool model_k : {true, false}) { // model K, and model M as the control const bool unsupported = - wgi::refused_frame_action(model_k, /*by_default=*/true) == wgi::RefusedAction::kNoSwitch; + wgi::kRefusedFrameGoesToFrontEnd; CHECK(unsupported); // the backend's answer for a refused frame is WG_ERROR_UNSUPPORTED const std::set pattern = unsupported ? std::set{1, 2, 3, 5, 6} : std::set{}; // with AMD's FSR: the first refused frame hands the context to it; no later frame is lost @@ -3574,6 +3643,7 @@ int main() { TestCompare(); TestReactiveMaskForwarded(); TestSlowCreate(); + TestHardIncompatibilityHandover(); TestInterfaceVersions(); TestAmdMode(); TestNonLinearColour(); diff --git a/clean/installer/src/app/ui_game.cpp b/clean/installer/src/app/ui_game.cpp index 82656909..75ea37de 100644 --- a/clean/installer/src/app/ui_game.cpp +++ b/clean/installer/src/app/ui_game.cpp @@ -55,7 +55,7 @@ namespace { TS Ts(float size, int weight, Col c, FontFace f = F_TEXT) { TS s; s.size = size; s.weight = weight; s.color = c; s.face = f; return s; } TS Wrap(float size, Col c, float lineH) { TS s; s.size = size; s.color = c; s.wrap = true; s.lineH = lineH; return s; } -const char* const kExec[] = {"auto", "dx12", "hip"}; +const char* const kExec[] = {"auto", "dx12"}; const char* const kFilter[] = {"default", "original", "analytic", "quality5", "quality9"}; // one name per choice wherever it shows (the row, its menu, the outside-change note), and what it does in a line: the // menu item's second line and help text, and the row's sentence for the chosen one @@ -1352,14 +1352,10 @@ static float UpscalerSection(Gfx& gx, float x, float y, float w) { yy += ActRow(gx, x, yy, w, false, true, ID_G_ADVMORE, L"Advanced settings (4)", ic::down, true, R_LINK); return yy - top; } - // R1: every model runs on Direct3D 12 in a game. HIP is a diagnostic set in wronggpu.ini (executor=hip), not a choice here; - // a profile that holds it says so in the row's sentence and shows no segment chosen + // R1: every model runs on Direct3D 12 in a game; HIP is not a game setting (a profile that held it lost it when it was read) const std::vector ex{L"Auto", L"Direct3D\u00a012"}; - const bool hipSet = NeedsHipRuntime("executor", v.edit.get("executor")); - const int exi = hipSet ? -1 : Index(kExec, v.edit.get("executor")); - yy += SRow(gx, x, yy, w, false, L"Runs on", - hipSet ? L"The profile asks for the HIP runtime, a diagnostic. Pick Auto or Direct3D\u00a012 to run the way the game is meant to." - : L"Auto uses Direct3D\u00a012 on RX\u00a09000-series cards.", + const int exi = Index(kExec, v.edit.get("executor")); + yy += SRow(gx, x, yy, w, false, L"Runs on", L"Auto uses Direct3D\u00a012 on RX\u00a09000-series cards.", SegmentedW(gx, ex, segW), 36, [&](const Rc& r) { Segmented(gx, ID_G_EXEC0, r.r(), r.y, ex, exi, sub, L"Runs on", 28, {}, true, segW); }, !sub); const int fi = Index(kFilter, v.edit.get("output_filter")); diff --git a/clean/installer/src/wg_core/launcher.cpp b/clean/installer/src/wg_core/launcher.cpp index 56cfae07..3bdc7023 100644 --- a/clean/installer/src/wg_core/launcher.cpp +++ b/clean/installer/src/wg_core/launcher.cpp @@ -1333,11 +1333,14 @@ static void InstallOp(Context& ctx, const OpRequest& r, Ui& ui, OpResult& res) { for (auto& n : CleanLeftovers(ctx, dir, leftovers)) res.notes.push_back(n); // what the game had before: its profile (kept through the update) and, for Update, the installed version Profile profile; - bool haveProfile = LoadProfile(ProfilePath(dir), profile); + std::vector profileNotes; // (R1: executor=hip is not kept; install, repair and update log its removal) + bool haveProfile = LoadProfile(ProfilePath(dir), profile, &profileNotes); if (!haveProfile) { string wini, oini; - if (IsFile(Join(dir, L"wronggpu.ini"))) { wini = EffectiveWronggpuIni(dir); ReadAll(Join(dir, L"OptiScaler.ini"), oini); profile = ImportProfile(wini, oini); haveProfile = true; } + if (IsFile(Join(dir, L"wronggpu.ini"))) { wini = EffectiveWronggpuIni(dir); ReadAll(Join(dir, L"OptiScaler.ini"), oini); profile = ImportProfile(wini, oini, &profileNotes); haveProfile = true; } } + for (auto& n : profileNotes) + if (n.find(kRetiredHipNote) != wstring::npos) LogLine(ctx, L"launcher: " + n); if (!haveProfile) profile = r.hasProfile ? r.profile : DefaultProfile(); MigrateRrState(ctx, dir); // #219: an older plugin's or the player's edit of WrongGPU\wronggpu.ini: its mode into the state folder FoldRrFromGame(dir, profile); // a Ray Reconstruction mode chosen in the game stays (the state folder keeps it through the install) diff --git a/clean/installer/src/wg_core/profile.cpp b/clean/installer/src/wg_core/profile.cpp index 05c80ff2..e8986878 100644 --- a/clean/installer/src/wg_core/profile.cpp +++ b/clean/installer/src/wg_core/profile.cpp @@ -15,8 +15,8 @@ namespace wg { const SettingDef kSettings[] = { {"wronggpu", Layer::Fe, Tier::Basic, "on", "on|off", L"WrongGPU", L"On: Model M upscales. Off: AMD's FSR upscales (WrongGPU stays installed and only logs)."}, - {"executor", Layer::Rt, Tier::Basic, "auto", "auto|dx12|hip", L"Executor", - L"Auto: Direct3D 12 on RX 9000 cards. HIP is a diagnostic set in wronggpu.ini; it is not offered here."}, + {"executor", Layer::Rt, Tier::Basic, "auto", "auto|dx12", L"Executor", + L"Auto: Direct3D 12 on RX 9000 cards. HIP is not a game setting."}, {"output_filter", Layer::Rt, Tier::Basic, "default", "default|original|analytic|quality5|quality9", L"Output filter", L"Default and Original: native output. Quality 5 / Quality 9: not available on the DX12 runtime yet (the default is used)."}, {"pre_exposure", Layer::Rt, Tier::Basic, "scale", "scale|original", L"Pre-exposure", @@ -163,6 +163,10 @@ bool LoadProfile(const wstring& path, Profile& p, std::vector* problems if (eq == string::npos) continue; const string k = LowerA(TrimA(t.substr(0, eq))), val = TrimA(t.substr(eq + 1)); if (k == "format") continue; + if (k == "executor" && LowerA(val) == "hip") { // R1: removed, and said + if (problems) problems->push_back(wstring(L"profile.ini: ") + kRetiredHipNote); + continue; + } const SettingDef* d = FindSetting(k); if (!d) { p.v[k] = val; continue; } // a key of a later launcher: kept string n; wstring why; @@ -418,6 +422,10 @@ Profile ImportProfile(const string& wronggpuIni, const string& optiIni, std::vec for (auto& d : kSettings) { auto it = eff.find(d.key); if (it == eff.end() || it->second == d.def) continue; + if (!strcmp(d.key, "executor") && LowerA(TrimA(it->second)) == "hip") { // R1: removed, and said + if (notes) notes->push_back(wstring(L"wronggpu.ini: ") + kRetiredHipNote); + continue; + } if (!strcmp(d.key, "sm2_rr_experimental") || !strcmp(d.key, "rr_config_fix")) continue; // never imported: the player chooses string n; wstring why; if (ValidateSetting(d, it->second, &n, &why)) { @@ -441,6 +449,7 @@ std::vector OutsideEdits(const Profile& p, const string& wronggpuIn auto it = eff.find(d.key); if (it == eff.end()) continue; if (it->second == d.def || it->second == p.get(d.key)) continue; + if (!strcmp(d.key, "executor") && LowerA(TrimA(it->second)) == "hip") continue; // retired: the next Apply removes it r.push_back({d.key, it->second, p.get(d.key)}); } return r; diff --git a/clean/installer/src/wg_core/profile.h b/clean/installer/src/wg_core/profile.h index 8b572065..27329577 100644 --- a/clean/installer/src/wg_core/profile.h +++ b/clean/installer/src/wg_core/profile.h @@ -36,6 +36,11 @@ const SettingDef* FindSetting(const string& key); // sparkle guard. A profile or an ini that already holds one still starts the game: the runtime uses the default output // filter or turns the sparkle guard off, with one log line, and never starts HIP for it. bool NeedsHipRuntime(const string& key, const string& value); +// executor=hip is not a game setting (R1: nothing in a game starts HIP; the diagnostic exists in developer builds only). A +// profile.ini or a wronggpu.ini that holds it loses it when it is read (LoadProfile, ImportProfile; the next Apply writes +// wronggpu.ini without it), and this sentence says so: install, repair and update log it. +inline const wchar_t* const kRetiredHipNote = + L"executor=hip removed: HIP is a developer diagnostic, not a game setting; every model runs on Direct3D 12"; const wchar_t* NotOnDx12Text(); // Checks and normalises one value ("d3d12" -> "dx12", "0" -> "off", "0.50" -> "0.5"); false with *why when it is not diff --git a/clean/installer/tests/launcher_core_tests.cpp b/clean/installer/tests/launcher_core_tests.cpp index 89ee4fb4..768e7ce4 100644 --- a/clean/installer/tests/launcher_core_tests.cpp +++ b/clean/installer/tests/launcher_core_tests.cpp @@ -177,7 +177,8 @@ int main() { const SettingDef* sparkle = FindSetting("sparkle_guard"); require(exec && filter && sparkle && FindSetting("wronggpu") && FindSetting("pre_exposure") && FindSetting("fps_overlay"), "the Basic tier has its six settings"); require(ValidateSetting(*exec, "D3D12", &n, &why) && n == "dx12", "executor d3d12 -> dx12"); - require(!ValidateSetting(*exec, "vulkan", &n, &why) && why.find(L"auto, dx12, hip") != wstring::npos, "a bad executor is refused and the allowed values named"); + require(!ValidateSetting(*exec, "vulkan", &n, &why) && why.find(L"auto, dx12") != wstring::npos && why.find(L"hip") == wstring::npos, "a bad executor is refused and the allowed values named (no hip)"); + require(!ValidateSetting(*exec, "hip", &n, &why), "executor=hip is no value of the setting any more (R1)"); require(!ValidateSetting(*filter, "quality7", &n, &why), "output_filter: only the runtime's values"); require(ValidateSetting(*filter, "quality9", &n, &why) && n == "quality9", "output_filter quality9"); require(ValidateSetting(*sparkle, "0.25", &n, &why) && n == "0.25", "sparkle_guard rate"); @@ -185,7 +186,8 @@ int main() { require(!ValidateSetting(*sparkle, "1.5", &n, &why) && !ValidateSetting(*sparkle, "-0.1", &n, &why) && !ValidateSetting(*sparkle, "abc", &n, &why), "sparkle_guard rate must be in (0, 1)"); Profile p = DefaultProfile(); require(!SetSetting(p, "nosuchkey", "1", &why) && !SetSetting(p, "pre_exposure", "bright", &why), "unknown keys and bad values are refused by set"); - require(SetSetting(p, "Executor", " HIP ", &why) && p.get("executor") == "hip", "set trims and lowers"); + require(SetSetting(p, "Executor", " DX12 ", &why) && p.get("executor") == "dx12", "set trims and lowers"); + require(!SetSetting(p, "Executor", " HIP ", &why) && p.get("executor") == "dx12", "set refuses executor=hip: not a game setting"); // ---- R1: the choices that exist on the HIP runtime only are not offered on an RX 9000 card ---------------- require(NeedsHipRuntime("executor", "hip") && NeedsHipRuntime("executor", " HIP "), "executor=hip needs the HIP runtime"); @@ -293,6 +295,37 @@ int main() { std::vector problems; require(LoadProfile(pp, loaded, &problems) && loaded.get("executor") == "auto" && problems.size() == 1, "a bad profile value falls back to the default, reported"); + { // R1: executor=hip is not a game setting: a profile or an ini that holds it loses it, and the removal is reported + const string hipProfile = "[profile]\r\nformat=1\r\nexecutor=hip\r\noutput_filter=analytic\r\n"; + WriteFileAtomic(pp, hipProfile.data(), hipProfile.size()); + std::vector pr; + Profile lp; + require(LoadProfile(pp, lp, &pr) && lp.get("executor") == "auto" && lp.get("output_filter") == "analytic" && pr.size() == 1 && + pr[0].find(kRetiredHipNote) != wstring::npos, + "profile.ini with executor=hip: the key is removed (Auto), the rest is kept, the removal is reported"); + SaveProfile(pp, lp); + string savedText; + ReadAll(pp, savedText); + require(savedText.find("hip") == string::npos && savedText.find("executor=auto") != string::npos, "the saved profile no longer holds hip"); + const string hipIni = "[fsr]\r\nupscaler = network\r\nruntime_options = model=M;executor=hip;pre_exposure=original\r\n"; + std::vector notes; + const Profile imp2 = ImportProfile(hipIni, "", ¬es); + bool said = false; + for (auto& n : notes) said = said || n.find(kRetiredHipNote) != wstring::npos; + require(imp2.get("executor") == "auto" && imp2.get("pre_exposure") == "original" && said, + "a wronggpu.ini with executor=hip: not imported, the removal is reported, the other settings are kept"); + string rendered; + wstring rwhy; + require(RenderWronggpuIni(imp2, hipIni, rendered, &rwhy) && rendered.find("executor") == string::npos && rendered.find("pre_exposure=original") != string::npos, + "the next Apply writes wronggpu.ini without executor=hip"); + bool listed = false; + for (auto& e : OutsideEdits(imp2, hipIni, "")) listed = listed || e.key == "executor"; + require(!listed, "a retired executor=hip is not offered as a change made outside the launcher"); + const string dx = "[fsr]\r\nruntime_options = executor=dx12\r\n"; + std::vector n2; + require(ImportProfile(dx, "", &n2).get("executor") == "dx12", "executor=dx12 is still imported"); + } + // ---- record v1 -> v2 ------------------------------------------------------------------------------------------- const wstring game = Join(dir, L"game"); EnsureDir(StateDir(game)); @@ -1750,11 +1783,11 @@ int main() { // ---- job and result files ----------------------------------------------------------------------------------------- OpRequest job; job.op = Op::Update; job.exe = L"C:\\Games\\X\\x.exe"; job.dir = L"C:\\Games\\X"; job.optiPackage = L"C:\\dl\\Opti.7z"; job.moveMods = true; - job.hasProfile = true; job.profile = DefaultProfile(); SetSetting(job.profile, "executor", "hip", nullptr); + job.hasProfile = true; job.profile = DefaultProfile(); SetSetting(job.profile, "executor", "dx12", nullptr); const string jt = JobText(job, L"C:\\Users\\p\\AppData\\Local", L"C:\\log.txt"); OpRequest back; wstring lad, lf; require(ParseJob(jt, back, lad, lf, &why) && back.op == Op::Update && back.exe == job.exe && back.dir == job.dir && back.moveMods && !back.removeOld && - back.hasProfile && back.profile.get("executor") == "hip" && lad == L"C:\\Users\\p\\AppData\\Local" && lf == L"C:\\log.txt", "job file round trip"); + back.hasProfile && back.profile.get("executor") == "dx12" && lad == L"C:\\Users\\p\\AppData\\Local" && lf == L"C:\\log.txt", "job file round trip"); { // the player's account and whether a new install gets its own entry: carried to the worker (another account may run it) wstring sid; int per = 7; require(ParseJob(JobText(job, L"C:\\Users\\p\\AppData\\Local", L"", L"S-1-5-21-1-2-3-1001", 0), back, lad, lf, &why, &sid, &per) && sid == L"S-1-5-21-1-2-3-1001" && per == 0 && diff --git a/clean/runner/build.py b/clean/runner/build.py index 7ea08c2c..80867a6b 100644 --- a/clean/runner/build.py +++ b/clean/runner/build.py @@ -79,6 +79,9 @@ # l_post from clean/l/kernels, l_enc_values = encoder.hip with WG_ENC_VALUES_OUT=1) and its map built in. The D3D12 # ports of Model L's kernels are built by clean/dx12/build_dx12.py --model-l. MODEL_L = False +# R1: a developer build only (--dev-diagnostics): executor=hip and the frame capture work in the runtime library. Never a +# release build or a package: the library says which it is (wgBuildMarker), clean/tests/check_no_dev_diagnostics.py checks. +DEV_DIAGNOSTICS = False L_RUNTIME_SOURCES = [os.path.join("..", "l", "runtime", "l_model.cpp"), os.path.join("..", "l", "runtime", "l_pack.cpp")] L_MAP_FILE = os.path.join(os.path.dirname(os.path.dirname(HERE)), "data", "preset-L.v1.map.json") L_KERNEL_DIR = os.path.join(os.path.dirname(HERE), "l", "kernels") @@ -326,6 +329,8 @@ def runtime_command(cxx, out, embedded=None): cmd += ["-D" + m["define"]] if MODEL_L: cmd += ["-DWG_MODEL_L"] + if DEV_DIAGNOSTICS: + cmd += ["-DWG_DEV_DIAGNOSTICS=1"] cmd += srcs if RR_OBJECTS and sys.platform == "win32": # release 0.6.0 (owner 2026-11-02: one runtime DLL, "just like before"): the RR runtime (clean/rr_f/runtime, built by @@ -487,7 +492,12 @@ def main(argv=None): help="Model L in the runtime library (#89; off by default): its runtime sources with WG_MODEL_L, its " "code objects and its map built in (with --runtime-only and --rocm its code objects are built " "first, for every target); its D3D12 kernels come from clean/dx12/build_dx12.py --model-l") + ap.add_argument("--dev-diagnostics", action="store_true", + help="developer build: executor=hip and the frame capture work in the runtime library (WG_DEV_DIAGNOSTICS; " + "off in every release build and package, R1)") args = ap.parse_args(argv) + global DEV_DIAGNOSTICS + DEV_DIAGNOSTICS = args.dev_diagnostics for name in OPTIONAL_MODELS: set_model(name, not getattr(args, "no_model_" + name.lower())) set_model_l(args.model_l) diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 1d7431a3..38d466a3 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -613,6 +613,9 @@ class Context { const ExecutorChoice ch = choose_executor(q); if (ch.executor.empty()) return fail(WG_ERROR_PARAMETER, "unknown executor " + o.executor); if (!ch.why.empty()) say(ch.warn ? WG_LOG_WARN : WG_LOG_INFO, ch.why); + // R1: a release build ignores the diagnostic keys (executor=hip, capture_dir): one line each, the context stays on D3D12 + for (const std::string& line : ch.ignored) say(WG_LOG_WARN, line); + if (!kDevDiagnostics) o.capture_dir.clear(); // (the capture runs on HIP only; no capture buffers are made either) // an adapter that is not an RDNA 4 Radeon RX 9000-series card (or not identified): no executor, no kernel load, // no HIP attempt; the one line above is the whole report and the front end's own upscaler takes the game if (ch.executor == "fsr") return WG_ERROR_UNSUPPORTED; @@ -1116,13 +1119,11 @@ class Context { phase(4); const bool ok = exec_->record(job, list, &wrote, &err); phase(5); - // a frame the executor did not take (nothing of it recorded, e.g. native AA): with the default executor the frame - // is answered WG_ERROR_UNSUPPORTED (no HIP, any model); with executor=dx12 it gets the bilinear fallback below + // a frame the executor did not take (nothing of it recorded, e.g. native AA): every model and every executor choice + // (also a forced executor=dx12) answers WG_ERROR_UNSUPPORTED and the front end takes the frame (AMD FSR, else its + // stand-in); never a substitute image made here, never a move to HIP (executor_select.h kRefusedFrameGoesToFrontEnd) const bool refused = !ok && frame_refused(err); - // a refused frame (executor_select.h refused_frame_action): every model on the default executor answers - // WG_ERROR_UNSUPPORTED and the front end takes the frame (AMD FSR, else its stand-in); the context stays usable - const RefusedAction refused_action = refused_frame_action(model_k_, dx12_default_); - if (refused && refused_action == RefusedAction::kNoSwitch) { // clean/fe-wrapped-list: no move to HIP; nothing recorded + if (refused) { // nothing recorded; the context stays usable if (!no_switch_said_) { no_switch_said_ = true; say(WG_LOG_WARN, model_k_ ? k_refusal_line(v, err) : no_switch_line(v, err)); @@ -2130,3 +2131,14 @@ const WgUpscalerBackend kBackend = {sizeof(WgUpscalerBackend), WG_UPSCALER_INTER extern "C" __declspec(dllexport) const WgUpscalerBackend* wgGetUpscalerBackend(uint32_t interface_version) { return interface_version == WG_UPSCALER_INTERFACE_VERSION ? &kBackend : nullptr; } + +// Which kind of build this library is (R1): "wg-build dev-diagnostics=0" in every release build and package, +// "wg-build dev-diagnostics=1" only in a developer build (WG_DEV_DIAGNOSTICS: executor=hip and the frame capture work). +// clean/tests/check_no_dev_diagnostics.py looks for this text in a built library. +extern "C" __declspec(dllexport) const char* wgBuildMarker() { +#ifdef WG_DEV_DIAGNOSTICS + return "wg-build dev-diagnostics=1"; +#else + return "wg-build dev-diagnostics=0"; +#endif +} diff --git a/clean/runtime/interop/executor_select.h b/clean/runtime/interop/executor_select.h index b69e05ab..cf16e932 100644 --- a/clean/runtime/interop/executor_select.h +++ b/clean/runtime/interop/executor_select.h @@ -3,27 +3,26 @@ // tests/test_executor_select.cpp checks it on any host. WrongGPU's own code. // // Option `executor` (wronggpu.ini runtime_options, an [fsr] line, WG_RUNTIME_OPTIONS). R1 (owner 2026-11-14, oversight -// 2026-11-15): in a game every model (M, L, K) runs on the D3D12 executor; HIP is a test reference and, with an explicit -// option, a diagnostic. So: +// 2026-11-15): in a game every model (M, L, K) runs on the D3D12 executor and NOTHING in a game starts HIP. So: // - not named (or `auto`): the D3D12 executor (executor_d3d12.cpp) on an RDNA 4 adapter (../rdna4.h: the PCI vendor and // device id from the kernel-mode driver, never a description a layer in the game can rewrite, failing closed). On any // other adapter, or one whose ids cannot be read, the context is not created: one warning line (the sentence of // wgrt::needs_rx9000_sentence with the adapter's description and ids) and the front end's own upscaler (AMD FSR, else -// its stand-in) takes the game; no HIP attempt, no kernel load. When the D3D12 executor refuses the context at create -// (its driver-channel probe, device preparation, the network's create, a context its kernels do not take; model K: +// its stand-in) takes the game, whatever fallback_to_amd says (a hard incompatibility, not a runtime failure); no HIP +// attempt, no kernel load. When the D3D12 executor refuses the context at create (its driver-channel probe, device +// preparation, the network's create, a context its kernels do not take; a build without its D3D12 kernel set; model K: // every kernel must have a port in the build's dx12/manifest.json and its options select the exact default path), the // context is not created either: one error line and the front end's upscaler; never the HIP executor. The sparkle guard // (HIP only) is turned off for every model with one line; the model stays on D3D12. -// - `hip`: the HIP executor, always: a diagnostic, not the in-game runtime; one warning line says so. -// - the frame capture (option capture_dir), which runs on HIP only, selects the HIP executor with a loud diagnostic line, -// never by default. // - `dx12` (or `d3d12`): the D3D12 executor on any adapter (the device refuses unsupported ones, and the context is not -// created); frames it does not take get the bilinear fallback (no switch). -// - A frame the D3D12 executor does not take later (e.g. above the checked render size; native AA and every ratio -// between 1.0 and 1.5 run on it since Brief 15) is answered WG_ERROR_UNSUPPORTED and goes back to the front end (AMD -// FSR, else its stand-in); no model moves to HIP in a game (R1). The 0.6.0 option hip_switch=on, which moved a model M -// or L context to the HIP executor, is ignored for every model (one line if set). Every model's refused frame takes -// the same front-end path. +// created). +// - A frame the D3D12 executor does not take later (e.g. above the checked render size) is answered WG_ERROR_UNSUPPORTED +// for every model and every executor choice and goes back to the front end (AMD FSR, else its stand-in): never a +// substitute image made here, never a move to HIP. The 0.6.0 option hip_switch=on is ignored for every model (one line). +// - `executor=hip` (the HIP executor, a test reference) and the frame capture (option capture_dir, HIP only) are developer +// diagnostics: IGNORED in a release build, with one warning line ("ignored: diagnostic key, release build"); the context +// stays on D3D12. They work only in a build made with WG_DEV_DIAGNOSTICS (clean/runner/build.py --dev-diagnostics), +// which no release build and no package is: tests/check_no_dev_diagnostics.py checks the built library for the marker. // - `d3d12-test`: the offline test executor. #pragma once @@ -36,6 +35,13 @@ namespace wgi { +// A developer build (WG_DEV_DIAGNOSTICS): executor=hip and the frame capture work. Never in a release build. +#ifdef WG_DEV_DIAGNOSTICS +inline constexpr bool kDevDiagnostics = true; +#else +inline constexpr bool kDevDiagnostics = false; +#endif + struct ExecutorRequest { std::string executor = "auto"; // the option's value ("auto" when not named) bool model_k = false; // the runtime options select model K (D3D12 executor: ports checked at its create) @@ -60,8 +66,16 @@ struct ExecutorChoice { bool sparkle_off = false; // the sparkle guard (HIP only) is turned off, whatever the model; the context stays on D3D12 std::string why; // the one log line about the choice; empty: nothing to log here std::string hip_note; // the one line when the option hip_switch asks for a move to HIP (ignored, any model) + std::vector ignored; // release build: one warning line per diagnostic key that was ignored (executor=hip, + // capture_dir); the context stays on D3D12 (the backend also drops capture_dir) }; +// A diagnostic key of a developer build asked for in a release build. +inline std::string ignored_key_line(const std::string& key) { + return key + " ignored: diagnostic key, release build; the context runs on the D3D12 executor (a game never starts the " + "HIP runtime)"; +} + // The one line when "auto" meets an adapter that is not an RDNA 4 Radeon RX 9000-series card or cannot be identified (the // launcher shows the same sentence): no HIP attempt, no kernel load, the front end's own upscaler takes the game. The // description (the system DXGI's) and the driver's ids are in it, so that a board missing from the id list shows in a log. @@ -94,15 +108,27 @@ inline wgrt::AdapterIdentity adapter_identity(const ExecutorRequest& r) { inline std::string hip_switch_note(const std::string& option); // below -inline ExecutorChoice choose_executor(const ExecutorRequest& r) { +// `dev`: the build's WG_DEV_DIAGNOSTICS (tests pass both values to check both configurations). +inline ExecutorChoice choose_executor(const ExecutorRequest& r, bool dev = kDevDiagnostics) { ExecutorChoice c; c.hip_note = hip_switch_note(r.hip_switch); // the same for every model: the option is ignored - const std::string& e = r.executor; + std::string e = r.executor; + bool capture = r.capture; + if (!dev) { // R1: a release build never starts HIP, whatever the game's files say + if (e == "hip") { + c.ignored.push_back(ignored_key_line("executor=hip")); + e = "auto"; + } + if (capture) { + c.ignored.push_back(ignored_key_line("capture_dir")); + capture = false; + } + } if (e == "d3d12-test") { c.executor = e; return c; } - if (e == "hip") { // a diagnostic for every model: loud, never the default + if (e == "hip") { // developer build only: a diagnostic for every model, loud, never the default c.executor = e; c.warn = true; c.why = "diagnostic: executor=hip selects the HIP executor; it is not the in-game runtime (the default and " @@ -120,7 +146,7 @@ inline ExecutorChoice choose_executor(const ExecutorRequest& r) { return c; } } - if (r.capture) { // an opt-in diagnostic, never on by default + if (capture) { // developer build only: an opt-in diagnostic, never on by default c.executor = "hip"; c.warn = true; c.why = capture_hip_line(); @@ -148,18 +174,11 @@ inline std::string hip_switch_note(const std::string& option) { "(executor=hip is the explicit diagnostic)"; } -// What a context does with a frame the D3D12 executor did not take (nothing of it recorded). -// kNoSwitch the frame is answered WG_ERROR_UNSUPPORTED, the context stays usable: the front end takes it from there -// (AMD's FSR when it exists, else its stand-in; the same path for every model); -// kBilinear executor=dx12 (forced): the frame gets the bilinear fallback (never for model K). -// Model K has no state of its own here: every refused K frame is answered WG_ERROR_UNSUPPORTED, exactly as model M's -// refused frames are, and the front end does the rest (REVIEW-215c, oversight 2026-11-15). -enum class RefusedAction { kNoSwitch, kBilinear }; - -inline RefusedAction refused_frame_action(bool model_k, bool by_default) { - if (model_k) return RefusedAction::kNoSwitch; - return by_default ? RefusedAction::kNoSwitch : RefusedAction::kBilinear; -} +// What a context does with a frame the D3D12 executor did not take (nothing of it recorded): the frame is answered +// WG_ERROR_UNSUPPORTED, the context stays usable, and the front end takes it from there (AMD's FSR when it exists, else its +// stand-in). The same for every model and for a forced executor=dx12: never an image made here (no bilinear substitute), +// never a move to HIP (REVIEW-215c, oversight 2026-11-15; Codex review of #225). +inline constexpr bool kRefusedFrameGoesToFrontEnd = true; // H3 (R1): the output filters Quality 5 and Quality 9 (runtime option output_filter=quality5 | quality9) exist on the HIP // executor only; the D3D12 executor refuses them at create. A context on the D3D12 executor never goes to HIP because of diff --git a/clean/runtime/interop/tests/test_executor_select.cpp b/clean/runtime/interop/tests/test_executor_select.cpp index addda935..5d58e27f 100644 --- a/clean/runtime/interop/tests/test_executor_select.cpp +++ b/clean/runtime/interop/tests/test_executor_select.cpp @@ -271,59 +271,105 @@ int main() { }()); } - // ---- diagnostics and the sparkle guard (every model) -------------------------------------------------------------- - for (bool model_k : {false, true}) { - const char* tag = model_k ? " (model K)" : " (model M or L)"; - ExecutorRequest r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); - r.model_k = model_k; - r.executor = "hip"; - ExecutorChoice c = choose_executor(r); - expect(std::string("executor=hip: the HIP executor as a loud diagnostic") + tag, - c.executor == "hip" && !c.by_default && c.warn && has(c.why, "diagnostic: executor=hip") && - has(c.why, "not the in-game runtime")); - r = board("AMD Radeon RX 7900 XTX", 0x1002, 0x744C); - r.model_k = model_k; - r.executor = "hip"; - c = choose_executor(r); - expect(std::string("executor=hip on another board: the same diagnostic") + tag, - c.executor == "hip" && c.warn && has(c.why, "diagnostic: executor=hip")); - r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); - r.model_k = model_k; - r.capture = true; - c = choose_executor(r); - expect(std::string("auto + frame capture: HIP with the loud diagnostic line") + tag, - c.executor == "hip" && c.warn && c.why == wgi::capture_hip_line() && has(c.why, "diagnostic: frame capture")); - r.executor = "dx12"; - expect(std::string("executor=dx12 + frame capture: the same diagnostic") + tag, - choose_executor(r).executor == "hip" && choose_executor(r).why == wgi::capture_hip_line()); - r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); - r.model_k = model_k; - r.sparkle_guard = true; - c = choose_executor(r); - expect(std::string("auto + sparkle guard: still the D3D12 executor, the guard turned off, one line") + tag, - c.executor == "dx12" && c.by_default && c.sparkle_off && c.warn && c.why == wgi::sparkle_off_line() && - has(c.why, "turned off") && has(c.why, "D3D12")); - r.executor = "dx12"; - c = choose_executor(r); - expect(std::string("executor=dx12 + sparkle guard: the same") + tag, c.executor == "dx12" && c.sparkle_off && !c.by_default); - r.capture = true; - expect(std::string("the sparkle guard with the capture: the capture's diagnostic wins") + tag, - choose_executor(r).executor == "hip"); - r = board("AMD Radeon RX 7900 XTX", 0x1002, 0x744C); - r.model_k = model_k; - r.executor = "dx12"; - c = choose_executor(r); - expect(std::string("executor=dx12 on another board: dx12 (the device refuses it at create)") + tag, - c.executor == "dx12" && !c.by_default && c.why.empty()); - r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); - r.model_k = model_k; - r.executor = "d3d12"; - expect(std::string("executor=d3d12 = dx12") + tag, choose_executor(r).executor == "dx12"); - r.executor = "d3d12-test"; - expect(std::string("executor=d3d12-test") + tag, choose_executor(r).executor == "d3d12-test"); - r.executor = "vulkan"; - expect(std::string("unknown executor -> empty (create fails)") + tag, choose_executor(r).executor.empty()); - } + // ---- diagnostics and the sparkle guard (every model, both configurations) ------------------------------------------ + // `dev` = a developer build (WG_DEV_DIAGNOSTICS: executor=hip and the frame capture work, as loud diagnostics); a release + // build IGNORES both with one line each and the context stays on D3D12 (R1: nothing in a game starts HIP). +#ifdef WG_DEV_DIAGNOSTICS + expect("this test binary is a developer build: kDevDiagnostics is on", wgi::kDevDiagnostics); +#else + expect("this test binary is a release build: kDevDiagnostics is off", !wgi::kDevDiagnostics); +#endif + for (bool model_k : {false, true}) + for (bool dev : {true, false}) { + const std::string tag = std::string(model_k ? " (model K)" : " (model M or L)") + (dev ? " [dev]" : " [release]"); + auto choose = [&](const ExecutorRequest& q) { return choose_executor(q, dev); }; + auto only_ignored = [](const ExecutorChoice& c, const char* key) { + return c.ignored.size() == 1 && has(c.ignored[0], key) && has(c.ignored[0], "ignored: diagnostic key, release build") && + c.ignored[0].find('\n') == std::string::npos; + }; + ExecutorRequest r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = model_k; + r.executor = "hip"; + ExecutorChoice c = choose(r); + if (dev) + expect("executor=hip: the HIP executor as a loud diagnostic" + tag, + c.executor == "hip" && !c.by_default && c.warn && has(c.why, "diagnostic: executor=hip") && + has(c.why, "not the in-game runtime") && c.ignored.empty()); + else + expect("executor=hip is IGNORED: the D3D12 executor by default, one line, no HIP" + tag, + c.executor == "dx12" && c.by_default && c.why.empty() && only_ignored(c, "executor=hip")); + r = board("AMD Radeon RX 7900 XTX", 0x1002, 0x744C); + r.model_k = model_k; + r.executor = "hip"; + c = choose(r); + if (dev) + expect("executor=hip on another board: the same diagnostic" + tag, + c.executor == "hip" && c.warn && has(c.why, "diagnostic: executor=hip")); + else + expect("executor=hip on another board is ignored: no executor, the front end's upscaler (the card sentence)" + tag, + c.executor == "fsr" && c.warn && c.why.rfind(sentence, 0) == 0 && only_ignored(c, "executor=hip")); + r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = model_k; + r.capture = true; + c = choose(r); + if (dev) + expect("auto + frame capture: HIP with the loud diagnostic line" + tag, + c.executor == "hip" && c.warn && c.why == wgi::capture_hip_line() && has(c.why, "diagnostic: frame capture") && + c.ignored.empty()); + else + expect("auto + frame capture is IGNORED: the D3D12 executor, one line, no HIP" + tag, + c.executor == "dx12" && c.by_default && c.why.empty() && only_ignored(c, "capture_dir")); + r.executor = "dx12"; + c = choose(r); + if (dev) + expect("executor=dx12 + frame capture: the same diagnostic (HIP)" + tag, + c.executor == "hip" && c.why == wgi::capture_hip_line()); + else + expect("executor=dx12 + capture_dir is ignored: the D3D12 executor, one line" + tag, + c.executor == "dx12" && !c.by_default && only_ignored(c, "capture_dir")); + r.executor = "hip"; + c = choose(r); + if (dev) + expect("executor=hip + capture (developer build): HIP" + tag, c.executor == "hip"); + else + expect("executor=hip + capture_dir in a release build: both ignored, two lines, D3D12" + tag, + c.executor == "dx12" && c.ignored.size() == 2 && has(c.ignored[0], "executor=hip") && has(c.ignored[1], "capture_dir")); + r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = model_k; + r.sparkle_guard = true; + c = choose(r); + expect("auto + sparkle guard: the D3D12 executor, the guard turned off, one line (both configurations)" + tag, + c.executor == "dx12" && c.by_default && c.sparkle_off && c.warn && c.why == wgi::sparkle_off_line() && + has(c.why, "turned off") && has(c.why, "D3D12") && c.ignored.empty()); + r.executor = "dx12"; + c = choose(r); + expect("executor=dx12 + sparkle guard: the same" + tag, c.executor == "dx12" && c.sparkle_off && !c.by_default); + r.capture = true; + c = choose(r); + if (dev) + expect("the sparkle guard with the capture (developer build): the capture's diagnostic wins" + tag, c.executor == "hip"); + else + expect("the sparkle guard with capture_dir (release): D3D12, the guard off, the key ignored" + tag, + c.executor == "dx12" && c.sparkle_off && only_ignored(c, "capture_dir")); + r = board("AMD Radeon RX 7900 XTX", 0x1002, 0x744C); + r.model_k = model_k; + r.executor = "dx12"; + c = choose(r); + expect("executor=dx12 on another board: dx12 (the device refuses it at create)" + tag, + c.executor == "dx12" && !c.by_default && c.why.empty() && c.ignored.empty()); + r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = model_k; + r.executor = "d3d12"; + expect("executor=d3d12 = dx12" + tag, choose(r).executor == "dx12"); + r.executor = "d3d12-test"; + expect("executor=d3d12-test" + tag, choose(r).executor == "d3d12-test"); + r.executor = "vulkan"; + expect("unknown executor -> empty (create fails)" + tag, choose(r).executor.empty()); + r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); + r.model_k = model_k; + expect("a plain RDNA 4 auto context has nothing ignored and nothing to log" + tag, + choose(r).executor == "dx12" && choose(r).ignored.empty() && choose(r).why.empty()); + } // ---- the D3D12 executor refuses the context at create: every model, the front end's upscaler, never HIP ------------- { @@ -340,7 +386,6 @@ int main() { // ---- clean/fe-wrapped-list: hip_switch, and a frame the D3D12 executor does not take ----------------------------- { - using wgi::RefusedAction; expect("hip_switch not set, off, 0 or false -> no line", wgi::hip_switch_note("").empty() && wgi::hip_switch_note("off").empty() && wgi::hip_switch_note("0").empty() && @@ -361,17 +406,13 @@ int main() { for (const char* why : refusals) { const std::string w = why; expect("refused frame recognised: " + w, wgi::frame_refused(w)); - for (bool by_default : {true, false}) - expect("K refused frame -> WG_ERROR_UNSUPPORTED, the front end's upscaler: " + w.substr(0, 40) + - (by_default ? " default" : " forced"), - wgi::refused_frame_action(true, by_default) == RefusedAction::kNoSwitch); + expect("a refused frame (every model, default and forced executor) goes back to the front end: " + w.substr(0, 40), + wgi::kRefusedFrameGoesToFrontEnd); } expect("a frame that is not a refusal is not a 'frame not taken'", !wgi::frame_refused("input refused: texture format") && !wgi::frame_refused("model K: kernel failed")); - expect("M default -> front end's upscaler (no move to HIP)", wgi::refused_frame_action(false, true) == RefusedAction::kNoSwitch); - expect("M executor=dx12 -> bilinear fallback", wgi::refused_frame_action(false, false) == RefusedAction::kBilinear); - expect("K and M take the same path: the same action", - wgi::refused_frame_action(true, true) == wgi::refused_frame_action(false, true)); + expect("no bilinear or other substitute exists in the selector any more (a forced executor=dx12 included)", + wgi::kRefusedFrameGoesToFrontEnd); const std::string rl = wgi::k_refusal_line(7, "frame not taken (nothing recorded): no output texture"); expect("the refusal line names the frame, the reason, the front end's upscaler and 'never to the HIP executor'", has(rl, "frame 7: model K") && has(rl, "no output texture") && has(rl, "AMD FSR, else its stand-in") && @@ -435,8 +476,7 @@ int main() { expect(tag + ": the choice is the one without the option", c.executor == p.executor && c.by_default == p.by_default && c.why == p.why && c.warn == p.warn && c.sparkle_off == p.sparkle_off && p.hip_note.empty()); - expect(tag + ": a refused frame goes to the front end, not to HIP", - wgi::refused_frame_action(m.k, c.by_default) == wgi::RefusedAction::kNoSwitch); + expect(tag + ": a refused frame goes to the front end, not to HIP", wgi::kRefusedFrameGoesToFrontEnd); } for (const char* value : {"off", "0", "false", ""}) { wgi::ExecutorRequest r = board("AMD Radeon RX 9070 XT", 0x1002, 0x7550); diff --git a/clean/tests/check_no_dev_diagnostics.py b/clean/tests/check_no_dev_diagnostics.py new file mode 100644 index 00000000..1a4d6372 --- /dev/null +++ b/clean/tests/check_no_dev_diagnostics.py @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: MIT +"""R1: a release build or a package never holds the developer diagnostics (executor=hip, the frame capture). + +The runtime library says which kind of build it is: the text "wg-build dev-diagnostics=0" (release) or +"wg-build dev-diagnostics=1" (a developer build made with --dev-diagnostics; clean/runtime/interop/backend.cpp +wgBuildMarker). This checks libraries for it: + + python clean/tests/check_no_dev_diagnostics.py [...] + +Exit status 0 only when every library found says dev-diagnostics=0. A library that has no marker (an older build), says +dev-diagnostics=1, or a path with no library at all fails: a package check that finds nothing must not pass. The release +script runs this on the packaged library (the same function is used by clean/tests/test_dev_diagnostics_off.py in CI). +""" +import os +import re +import sys + +MARKER = re.compile(rb"wg-build dev-diagnostics=([01])") + + +def check_bytes(data): + """(True, text) when the library data says dev-diagnostics=0 once and never =1.""" + found = MARKER.findall(data) + if not found: + return False, "no 'wg-build dev-diagnostics=' marker (a build older than R1, or not the runtime library)" + if any(v == b"1" for v in found): + return False, "built with WG_DEV_DIAGNOSTICS (dev-diagnostics=1)" + return True, "dev-diagnostics=0" + + +def libraries(path): + if os.path.isfile(path): + return [path] + out = [] + for dirpath, _, names in os.walk(path): + for n in names: + if n.lower().startswith("wronggpu_runtime") and n.lower().endswith(".dll"): + out.append(os.path.join(dirpath, n)) + return sorted(out) + + +def check_path(path): + """[(library, ok, text)]; an empty list is a failure of the caller to find a library.""" + results = [] + for lib in libraries(path): + with open(lib, "rb") as f: + ok, text = check_bytes(f.read()) + results.append((lib, ok, text)) + return results + + +def main(argv): + if not argv: + print(__doc__) + return 2 + bad = False + for path in argv: + results = check_path(path) + if not results: + print(f"FAIL {path}: no wronggpu_runtime library found") + bad = True + for lib, ok, text in results: + print(("ok " if ok else "FAIL ") + f"{lib}: {text}") + bad = bad or not ok + return 1 if bad else 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/clean/tests/test_dev_diagnostics_off.py b/clean/tests/test_dev_diagnostics_off.py new file mode 100644 index 00000000..c196a8d0 --- /dev/null +++ b/clean/tests/test_dev_diagnostics_off.py @@ -0,0 +1,82 @@ +# SPDX-License-Identifier: MIT +"""R1: WG_DEV_DIAGNOSTICS (executor=hip and the frame capture in a game) is off in every release build and package. + +No GPU, no compiler needed: the build script's runtime command, the CI and release files, and the library check are read. +Run: python -m unittest clean.tests.test_dev_diagnostics_off +""" +import importlib.util +import os +import sys +import tempfile +import unittest + +HERE = os.path.dirname(os.path.abspath(__file__)) +ROOT = os.path.dirname(os.path.dirname(HERE)) +sys.path.insert(0, HERE) +import check_no_dev_diagnostics as chk # noqa: E402 + + +def read(*p): + with open(os.path.join(ROOT, *p), encoding="utf-8", errors="replace") as f: + return f.read() + + +def load_build(): + sys.path.insert(0, ROOT) + spec = importlib.util.spec_from_file_location("wg_build_for_test", os.path.join(ROOT, "clean", "runner", "build.py")) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod + + +class DevDiagnosticsOff(unittest.TestCase): + def test_the_runtime_command_has_the_define_only_on_request(self): + b = load_build() + self.assertFalse(b.DEV_DIAGNOSTICS) + self.assertFalse([a for a in b.runtime_command("clang++", "out.dll") if "WG_DEV_DIAGNOSTICS" in a]) + b.DEV_DIAGNOSTICS = True + try: + self.assertTrue([a for a in b.runtime_command("clang++", "out.dll") if a.startswith("-DWG_DEV_DIAGNOSTICS")]) + finally: + b.DEV_DIAGNOSTICS = False + + def test_no_release_path_turns_it_on(self): + # the define and the build flag appear in the source of the build script and the backend only; no CI workflow, + # CMake file, release script or packaging file asks for it + offenders = [] + for base in (".github", os.path.join("tools", "release"), os.path.join("clean", "installer")): + full = os.path.join(ROOT, base) + if not os.path.isdir(full): + continue + for dp, _, names in os.walk(full): + for n in names: + if n.endswith((".yml", ".yaml", ".txt", ".cmake", ".py", ".sh", ".bat", ".ps1", ".cpp", ".h", ".json")): + p = os.path.join(dp, n) + with open(p, encoding="utf-8", errors="replace") as f: + t = f.read() + if "WG_DEV_DIAGNOSTICS" in t or "--dev-diagnostics" in t: + offenders.append(os.path.relpath(p, ROOT)) + self.assertEqual(offenders, [], "a CI, release or installer file turns the developer diagnostics on") + + def test_the_library_marker_and_its_check(self): + backend = read("clean", "runtime", "interop", "backend.cpp") + self.assertIn('"wg-build dev-diagnostics=0"', backend) + self.assertIn('"wg-build dev-diagnostics=1"', backend) + self.assertIn("#ifdef WG_DEV_DIAGNOSTICS", backend) + ok, _ = chk.check_bytes(b"MZ\x00..wg-build dev-diagnostics=0\x00..") + self.assertTrue(ok) + for bad in (b"wg-build dev-diagnostics=1", b"no marker here", b"wg-build dev-diagnostics=0 wg-build dev-diagnostics=1"): + self.assertFalse(chk.check_bytes(bad)[0], bad) + with tempfile.TemporaryDirectory() as d: + self.assertEqual(chk.main([d]), 1, "a folder with no library must not pass") + good = os.path.join(d, "wronggpu_runtime.dll") + with open(good, "wb") as f: + f.write(b"x" * 100 + b"wg-build dev-diagnostics=0" + b"y") + self.assertEqual(chk.main([d]), 0) + with open(os.path.join(d, "wronggpu_runtime_dev.dll"), "wb") as f: + f.write(b"wg-build dev-diagnostics=1") + self.assertEqual(chk.main([d]), 1, "one developer library among the packaged ones fails the folder") + + +if __name__ == "__main__": + unittest.main() diff --git a/clean/tests/test_executor_select.py b/clean/tests/test_executor_select.py index ade6ebd5..73100002 100644 --- a/clean/tests/test_executor_select.py +++ b/clean/tests/test_executor_select.py @@ -42,18 +42,18 @@ def _vcvars64(): return vcvars if r.returncode == 0 and r.stdout.strip() and os.path.exists(vcvars) else None -def _build(exe): +def _build(exe, defines=()): cxx = os.environ.get("CXX") or shutil.which("clang++") or shutil.which("g++") if cxx: - cmd = [cxx, "-std=c++17", "-O1", os.path.join(ROOT, TEST), "-o", exe] + cmd = [cxx, "-std=c++17", "-O1"] + ["-D" + d for d in defines] + [os.path.join(ROOT, TEST), "-o", exe] return subprocess.run(cmd, capture_output=True, text=True) vcvars = None if shutil.which("cl") else _vcvars64() if os.name != "nt" or not (shutil.which("cl") or vcvars): raise unittest.SkipTest("no host C++ compiler (CXX, clang++, g++ or MSVC cl)") objdir = os.path.join(os.path.dirname(exe), "obj") os.makedirs(objdir, exist_ok=True) - cl = 'cl /nologo /std:c++17 /O1 /EHsc /utf-8 /D_CRT_SECURE_NO_WARNINGS "%s" /Fo"%s\\\\" /Fe"%s"' % ( - os.path.join(ROOT, TEST), objdir, exe) + cl = 'cl /nologo /std:c++17 /O1 /EHsc /utf-8 /D_CRT_SECURE_NO_WARNINGS %s "%s" /Fo"%s\\\\" /Fe"%s"' % ( + " ".join("/D" + d for d in defines), os.path.join(ROOT, TEST), objdir, exe) bat = exe + ".bat" with open(bat, "w") as f: f.write("@echo off\r\n") @@ -64,16 +64,25 @@ def _build(exe): class ExecutorSelect(unittest.TestCase): - def test_cpp_cases(self): + def _run(self, defines, expect_line): tmp = tempfile.mkdtemp(prefix="wg_es_") exe = os.path.join(tmp, "test_executor_select" + (".exe" if os.name == "nt" else "")) - r = _build(exe) + r = _build(exe, defines) self.assertEqual(r.returncode, 0, "build failed:\n" + r.stdout + r.stderr) r = subprocess.run([exe], capture_output=True, text=True) self.assertEqual(r.returncode, 0, "\n".join(l for l in r.stdout.splitlines() if l.startswith("FAIL")) + r.stderr) self.assertIn("ALL TESTS PASSED", r.stdout) + self.assertIn(expect_line, r.stdout) self.assertGreater(r.stdout.count("pass "), 100) + def test_cpp_cases_release_build(self): + # the shipped configuration (no WG_DEV_DIAGNOSTICS); both configurations of the selector are checked in the binary + self._run((), "this test binary is a release build: kDevDiagnostics is off") + + def test_cpp_cases_developer_build(self): + # the same cases with the developer define on: the build's own default is then the developer one + self._run(("WG_DEV_DIAGNOSTICS=1",), "this test binary is a developer build: kDevDiagnostics is on") + class CreateOrder(unittest.TestCase): """The order of Context::create (backend.cpp): a pin on the source, as the create needs a D3D12 device.""" @@ -127,6 +136,23 @@ def test_hip_switch_is_ignored_once_for_every_model(self): sel = read("clean", "runtime", "interop", "executor_select.h") self.assertNotIn("kSwitchToHip", sel) + def test_release_ignores_hip_and_capture_and_never_makes_a_substitute_image(self): + sel = read("clean", "runtime", "interop", "executor_select.h") + # the selector returns "hip" only for a developer build; a release build ignores executor=hip and capture_dir + self.assertIn("kDevDiagnostics", sel) + self.assertIn("ignored: diagnostic key, release build", sel) + self.assertIn("bool dev = kDevDiagnostics", sel) + # the backend logs the ignored keys and drops capture_dir in a release build, before anything is made + drop = self.at("if (!kDevDiagnostics) o.capture_dir.clear();") + self.assertIn("for (const std::string& line : ch.ignored) say(WG_LOG_WARN, line);", self.b[drop - 200:drop]) + self.assertGreater(drop, self.at("choose_executor(q)")) + self.assertLess(drop, self.at("make_hip_executor(")) + # a refused frame (every model, forced dx12 too) is answered WG_ERROR_UNSUPPORTED: no policy function, no bilinear branch + self.assertNotIn("refused_frame_action", self.b + sel) + self.assertNotIn("kBilinear", self.b + sel) + refused = self.at("if (refused) {") + self.assertIn("return WG_ERROR_UNSUPPORTED;", self.b[refused:refused + 400]) + def test_sparkle_guard_is_off_and_hip_only_filters_fall_back_for_every_model(self): # R1-a / H4: the choice turns the guard off before anything is made, whatever the model off = self.at("if (ch.sparkle_off) o.sparkle_guard = 0.0f;") From 516e3a9c5bccac2b332388a79e6f221fba8ddc7c Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 07:33:47 -0500 Subject: [PATCH 10/20] H2 matrix: a leg with executor=hip and capture_dir in the options A release build of the runtime ignores both keys (one line each) and every context stays on Direct3D 12; --diag-keys in the driver adds them. The case fails on a developer build, which runs them. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/k/runner/k_refusal_matrix.py | 7 ++++++- .../interop/tests/test_interop_d3d12.cpp | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/clean/k/runner/k_refusal_matrix.py b/clean/k/runner/k_refusal_matrix.py index bd07fae3..72819b6c 100644 --- a/clean/k/runner/k_refusal_matrix.py +++ b/clean/k/runner/k_refusal_matrix.py @@ -27,6 +27,9 @@ def main(): ap.add_argument("--outputs", default="1080,1440,2160", help="output heights, comma separated") ap.add_argument("--model", choices=("K", "M", "L"), default="K") ap.add_argument("--model-dir", help="M, L: the folder with the converted model (M: model.wgcm; L: L\\model.wgcm)") + ap.add_argument("--diag-keys", action="store_true", + help="add executor=hip and capture_dir=/capture (diagnostic keys): a release build of the library must " + "ignore both (one line each) and stay on Direct3D 12; the case fails on a developer build") ap.add_argument("--hip-switch-on", action="store_true", help="add hip_switch=on (ignored for every model): one log line per context, still Direct3D 12") a = ap.parse_args() @@ -42,7 +45,9 @@ def main(): if not a.model_dir: ap.error("--model-dir is required for model M and L") base = (f"model={a.model}", f"kernels_dir={build}", f"model_dir={Path(a.model_dir).resolve()}") - opts = ";".join(base + (("hip_switch=on",) if a.hip_switch_on else ())) + extra = (("hip_switch=on",) if a.hip_switch_on else ()) + \ + (("executor=hip", f"capture_dir={out / 'capture'}") if a.diag_keys else ()) + opts = ";".join(base + extra) env = os.environ.copy() env.pop("WG_RUNTIME_OPTIONS", None) proc = subprocess.run([str(Path(a.exe).resolve()), str(build / "wronggpu_runtime.dll"), "matrix", opts, a.outputs], diff --git a/clean/runtime/interop/tests/test_interop_d3d12.cpp b/clean/runtime/interop/tests/test_interop_d3d12.cpp index e14a1cc7..f3d102e7 100644 --- a/clean/runtime/interop/tests/test_interop_d3d12.cpp +++ b/clean/runtime/interop/tests/test_interop_d3d12.cpp @@ -1795,7 +1795,8 @@ int debug_messages(Gpu& g, const char* when) { // log "network runtime ready: executor dx12" and none of "could not take this context", "does not take this frame", // "about to start the HIP runtime", "network runtime ready: executor hip" or "the HIP executor runs"; its frame must be WG_OK. No `executor` key is given: the // default rule (D3D12 on an RX 9000 card) is what is tested. The options name the model (a synthetic model for K). With -// hip_switch=on in the options (R1: ignored for every model) each context must log the one "hip_switch=on is ignored" line. +// hip_switch=on in the options (R1: ignored for every model) each context must log the one "hip_switch=on is ignored" line; with executor=hip and / or capture_dir=... in the options +// (R1: diagnostic keys, ignored by a release build of the library) the one "ignored: diagnostic key, release build" line each. bool case_matrix(Gpu& g, const char* dll, const std::string& options, const std::string& outputs) { struct Mode { const char* name; @@ -1811,6 +1812,10 @@ bool case_matrix(Gpu& g, const char* dll, const std::string& options, const std: } int contexts = 0, refused = 0; const bool switch_on = options.find("hip_switch=on") != std::string::npos; // R1: ignored, one line, no HIP + // R1: executor=hip and capture_dir in a release build of the library: ignored, one line each, still D3D12 (the case then + // fails on a developer build, which runs them, as it should) + const bool hip_key = options.find("executor=hip") != std::string::npos; + const bool cap_key = options.find("capture_dir=") != std::string::npos; for (const UINT oh : heights) { const UINT ow = oh * 16 / 9; for (const Mode& m : modes) { @@ -1851,9 +1856,11 @@ bool case_matrix(Gpu& g, const char* dll, const std::string& options, const std: rb->Release(); } bool ready = false, bad = false; - int ignored = 0; + int ignored = 0, ignored_hip = 0, ignored_cap = 0; for (const auto& line : g_log) { ignored += line.find("hip_switch=on is ignored") != std::string::npos; + ignored_hip += line.find("executor=hip ignored: diagnostic key, release build") != std::string::npos; + ignored_cap += line.find("capture_dir ignored: diagnostic key, release build") != std::string::npos; ready |= line.find("network runtime ready: executor dx12") != std::string::npos; const bool refusal = line.find("could not take this context") != std::string::npos; refused += refusal; @@ -1862,9 +1869,11 @@ bool case_matrix(Gpu& g, const char* dll, const std::string& options, const std: line.find("network runtime ready: executor hip") != std::string::npos || line.find("the HIP executor runs") != std::string::npos; } - const bool ok = r == WG_OK && rr == WG_OK && ready && !bad && ignored == (switch_on ? 1 : 0); - std::printf(" matrix %s: create %d, frame %d, ready dx12 %d, refusal or HIP line %d, hip_switch line %d%s\n", - label.c_str(), (int)r, (int)rr, (int)ready, (int)bad, ignored, ok ? "" : " <-- FAIL"); + const bool ok = r == WG_OK && rr == WG_OK && ready && !bad && ignored == (switch_on ? 1 : 0) && + ignored_hip == (hip_key ? 1 : 0) && ignored_cap == (cap_key ? 1 : 0); + std::printf(" matrix %s: create %d, frame %d, ready dx12 %d, refusal or HIP line %d, hip_switch line %d, ignored diagnostic keys %d%s\n", + label.c_str(), (int)r, (int)rr, (int)ready, (int)bad, ignored, ignored_hip + ignored_cap, + ok ? "" : " <-- FAIL"); CHECK(ok); } } From 22639020d192d02cd46ac8598d43226dc8031139 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 08:34:52 -0500 Subject: [PATCH 11/20] R1: the package never holds developer diagnostics; create worker owns the device; bounded retry; remembered refusals keep their class make_payload.py runs check_no_dev_diagnostics on every embedded file and refuses the payload for a runtime that says dev-diagnostics=1 or has no marker; the checker reads zips and executables; tools/release/check_package_diagnostics.py runs it on the final package; a CI step runs the real packager on both markers. The create worker takes a COM reference on the game's D3D12 device before it starts and releases it as its last step (also after a timeout), for the FidelityFX route and the FSR 3.0 route. The retry without the split service goes through the same bounded asynchronous path as the first create. A remembered custom-slot refusal keeps its classification: a hard incompatibility hands over to the available provider on a repeat exactly as on the first create. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- .github/workflows/ci.yml | 8 ++ clean/fsr/src/async_create.cpp | 9 +- clean/fsr/src/async_create.h | 8 +- clean/fsr/src/dll_fsr3.cpp | 2 + clean/fsr/src/dll_fsr3upscaler.cpp | 2 + clean/fsr/src/dllmain.cpp | 2 + clean/fsr/src/frontend.cpp | 55 ++++++-- clean/fsr/src/frontend.h | 7 ++ clean/fsr/src/fsr30_hook.cpp | 8 +- clean/fsr/src/fsr30_hook.h | 4 + clean/fsr/src/win_util.cpp | 8 ++ clean/fsr/src/win_util.h | 2 + clean/fsr/tests/test_frontend.cpp | 138 ++++++++++++++++++++- clean/installer/tools/make_payload.py | 16 +++ clean/tests/check_no_dev_diagnostics.py | 81 ++++++++---- clean/tests/test_dev_diagnostics_off.py | 84 ++++++++++++- tools/release/check_package_diagnostics.py | 20 +++ 17 files changed, 412 insertions(+), 42 deletions(-) create mode 100644 tools/release/check_package_diagnostics.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 199f9c06..a06f1e80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -155,6 +155,14 @@ jobs: cmake -S clean/installer -B out/launcher-models -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=ON -DWRONGGPU_MODEL_K=ON -DWRONGGPU_MODEL_L=ON -DWRONGGPU_DIRECT_ROUTE=OFF cmake --build out/launcher-models --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-models --output-on-failure -R "^(wg-core|launcher-core|coexist-core|convert-ignore|model-choice|model-choice-k|model-choice-k-only|source-size|wording)$" + - name: Payload packager and package check refuse a developer runtime (R1) + # The packager (clean/installer/tools/make_payload.py) runs clean/tests/check_no_dev_diagnostics.py on every runtime + # library it embeds and refuses the payload for dev-diagnostics=1 or a missing marker; tools/release runs the same + # check on the final package. Here the real packager is run on runtime files carrying each marker, and the check on + # packages (zip, launcher executable): what is tested are the bytes that would ship, not source strings. + run: | + $PSNativeCommandUseErrorActionPreference = $true + python -m unittest clean.tests.test_dev_diagnostics_off -v rr-plugin: name: "CPU: Ray Reconstruction plugin" diff --git a/clean/fsr/src/async_create.cpp b/clean/fsr/src/async_create.cpp index ffcc21c1..850503aa 100644 --- a/clean/fsr/src/async_create.cpp +++ b/clean/fsr/src/async_create.cpp @@ -5,10 +5,12 @@ namespace wgfsr { -std::shared_ptr PendingCreate::Start(const WgUpscalerBackend* backend, const WgCreateInfo& info) { +std::shared_ptr PendingCreate::Start(const WgUpscalerBackend* backend, const WgCreateInfo& info, + std::function releaseWhenDone) { auto p = std::make_shared(); p->backend_ = backend; p->info_ = info; + p->release_ = std::move(releaseWhenDone); p->start_ = std::chrono::steady_clock::now(); std::thread([p] { p->Run(p); }).detach(); return p; @@ -29,6 +31,11 @@ void PendingCreate::Run(std::shared_ptr self) { } cv_.notify_all(); if (cleanup) cleanup(r == WG_OK ? upscaler : nullptr); // the context went away while the create ran + if (release_) { // the last step: nothing of this worker touches the game's device after it + std::function release = std::move(release_); + release_ = nullptr; + release(); + } } bool PendingCreate::Wait(uint32_t ms) { diff --git a/clean/fsr/src/async_create.h b/clean/fsr/src/async_create.h index 3a4e40a9..8a633f6b 100644 --- a/clean/fsr/src/async_create.h +++ b/clean/fsr/src/async_create.h @@ -20,8 +20,11 @@ namespace wgfsr { class PendingCreate { public: // Starts backend->create(info) on a new thread. `info` and what it points to (options, log user) must stay valid - // until the create finished, or until the cleanup given to Abandon ran. - static std::shared_ptr Start(const WgUpscalerBackend* backend, const WgCreateInfo& info); + // until the create finished, or until the cleanup given to Abandon ran. `releaseWhenDone`: runs on the worker thread as + // its last step, also after a timeout and after the context went away (the front end takes a COM reference on the + // game's D3D12 device before the worker starts and gives it back here, so a late worker never meets a released device). + static std::shared_ptr Start(const WgUpscalerBackend* backend, const WgCreateInfo& info, + std::function releaseWhenDone = {}); // Waits up to `ms` milliseconds (UINT32_MAX: until it finishes); true when the create has finished. bool Wait(uint32_t ms); @@ -49,6 +52,7 @@ class PendingCreate { WgResult result_ = WG_ERROR_DEVICE; WgUpscaler* upscaler_ = nullptr; std::function cleanup_; // set by Abandon while the create runs + std::function release_; // the worker's last step (Start's releaseWhenDone) double reported_ = 0; // highest threshold PassedThreshold answered true for std::chrono::steady_clock::time_point start_, end_; }; diff --git a/clean/fsr/src/dll_fsr3.cpp b/clean/fsr/src/dll_fsr3.cpp index 5372ed83..743353d3 100644 --- a/clean/fsr/src/dll_fsr3.cpp +++ b/clean/fsr/src/dll_fsr3.cpp @@ -84,6 +84,8 @@ Hook& H() { p.logBytes = [] { return wronggpu::Log::Get().Bytes(); }; p.resourceInfo = &D3D12ResourceInfo; p.deviceFromCommandList = &DeviceFromCommandList; + p.retainDevice = &RetainDevice; + p.releaseDevice = &ReleaseDevice; AddSplitServices(p, config); // How many upscaler dispatches WrongGPU's ffx_fsr3upscaler_x64.dll has seen on this thread (0 if not ours). p.upscalerSeenOnThread = [] { diff --git a/clean/fsr/src/dll_fsr3upscaler.cpp b/clean/fsr/src/dll_fsr3upscaler.cpp index 77d55c7e..13eb957c 100644 --- a/clean/fsr/src/dll_fsr3upscaler.cpp +++ b/clean/fsr/src/dll_fsr3upscaler.cpp @@ -82,6 +82,8 @@ Hook& H() { p.logBytes = [] { return wronggpu::Log::Get().Bytes(); }; p.resourceInfo = &D3D12ResourceInfo; p.deviceFromCommandList = &DeviceFromCommandList; + p.retainDevice = &RetainDevice; + p.releaseDevice = &ReleaseDevice; AddSplitServices(p, config); g_hook = new Hook(p, config, ""); LoadOriginal(); diff --git a/clean/fsr/src/dllmain.cpp b/clean/fsr/src/dllmain.cpp index 0043b32d..5afd77c1 100644 --- a/clean/fsr/src/dllmain.cpp +++ b/clean/fsr/src/dllmain.cpp @@ -176,6 +176,8 @@ FrontEnd& Get() { p.logBytes = [] { return L().Bytes(); }; p.resourceInfo = &D3D12ResourceInfo; p.timer = &StartTimer; + p.retainDevice = &RetainDevice; + p.releaseDevice = &ReleaseDevice; p.deviceLost = [](void* device) { return device && static_cast(device)->GetDeviceRemovedReason() != S_OK; }; diff --git a/clean/fsr/src/frontend.cpp b/clean/fsr/src/frontend.cpp index be280970..ff6952b6 100644 --- a/clean/fsr/src/frontend.cpp +++ b/clean/fsr/src/frontend.cpp @@ -696,11 +696,13 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes // Custom slot: the same upscaler with the same options failed earlier in this session: no new attempt. std::string remembered; uint64_t repeats = 0; + bool rememberedHard = false; // the remembered failure was a hard incompatibility (R1): the repeat hands over too if (config_.customSlot && refusal.empty()) { std::lock_guard lock(mutex_); auto it = failedCreates_.find(FailureKey(backend, *u)); if (it != failedCreates_.end()) { remembered = it->second.reason; + rememberedHard = it->second.hardIncompat; repeats = ++it->second.repeats; } } @@ -723,6 +725,7 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes "); it is not created again until the game restarts"; u->failReason = remembered; repeatedFailure = true; + hardIncompat = rememberedHard; if (LogPoint(repeats)) Log(tag + " custom slot: create " + std::to_string(repeats) + " since the failure: " + why); } else if (t_held) { @@ -757,7 +760,7 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes // fallback_to_amd = 0. const bool amdMeanwhile = config_.fallbackToAmd && (!config_.customSlot || UpscaleFallbackApi()); u->creating = true; - auto pending = PendingCreate::Start(backend, u->createInfo); + auto pending = PendingCreate::Start(backend, u->createInfo, HoldDevice(u->createInfo.d3d12_device)); if (pending->Wait(amdMeanwhile ? config_.createWaitMs : config_.createGiveUpMs)) { u->creating = false; if (u->failReason.empty()) u->failReason = u->createError; @@ -774,17 +777,32 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes u->createInfo.services = nullptr; Log(tag + " U" + std::to_string(u->id) + ": created again without the command-list split service"); u->creating = true; - WgUpscaler* again = nullptr; - const WgResult r2 = backend->create(&u->createInfo, &again); - u->creating = false; - if (r2 == WG_OK && again) { - u->upscaler = again; - u->backend = backend; + // the same bounded path as the first create: a stalled retry hands over, it does not hang the game + auto again2 = PendingCreate::Start(backend, u->createInfo, HoldDevice(u->createInfo.d3d12_device)); + if (again2->Wait(amdMeanwhile ? config_.createWaitMs : config_.createGiveUpMs)) { + u->creating = false; + const WgResult r2 = again2->Result(); + WgUpscaler* again = again2->Take(); + if (r2 == WG_OK && again) { + u->upscaler = again; + u->backend = backend; + } else { + if (again) backend->destroy(again); + if (u->failReason.empty()) u->failReason = u->createError; + why = std::string("upscaler \"") + backend->name + "\" create without the split service failed: " + WgResultText(r2); + hardIncompat = hardIncompat || r2 == WG_ERROR_UNSUPPORTED; + } } else { - if (again) backend->destroy(again); - if (u->failReason.empty()) u->failReason = u->createError; - why = std::string("upscaler \"") + backend->name + "\" create without the split service failed: " + WgResultText(r2); - hardIncompat = hardIncompat || r2 == WG_ERROR_UNSUPPORTED; + u->pending = again2; + u->pendingBackend = backend; + if (amdMeanwhile) { + why = std::string("upscaler \"") + backend->name + "\" is still starting (without the split service) after " + + std::to_string(config_.createWaitMs) + " ms (create_wait_ms); it takes over when it has started"; + } else { + hardIncompat = true; + why = std::string("upscaler \"") + backend->name + "\" did not finish its create (without the split service) in " + + std::to_string(config_.createGiveUpMs) + " ms (create_giveup_ms): refused"; + } } } } else { @@ -796,7 +814,7 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes const std::string reason = u->createError.empty() ? why : why + ": " + u->createError; { std::lock_guard lock(mutex_); - failedCreates_[FailureKey(backend, *u)] = RememberedFailure{reason, 0}; + failedCreates_[FailureKey(backend, *u)] = RememberedFailure{reason, 0, hardIncompat}; } Log(tag + " custom slot: this failure is remembered for the session: a create of upscaler \"" + backend->name + "\" with the same options fails at once from now on, without a new attempt (logged now and then)"); @@ -950,12 +968,23 @@ void FrontEnd::CheckPending(UpscaleContext& u, uint64_t call) { "; AMD FSR keeps upscaling"); if (config_.customSlot) { std::lock_guard lock(mutex_); - failedCreates_[FailureKey(u.pendingBackend, u)] = RememberedFailure{u.failReason, 0}; + failedCreates_[FailureKey(u.pendingBackend, u)] = RememberedFailure{u.failReason, 0, r == WG_ERROR_UNSUPPORTED}; } } u.pending.reset(); } +// R1: the create worker's own COM reference on the game's D3D12 device, taken here (on the game's thread) before the worker +// starts and released by the worker as its last step, so a worker that outlives a timeout, the AMD context and the host's +// own device reference never touches a released device. The release is a copy of the platform's function: it does not +// depend on this object. +std::function FrontEnd::HoldDevice(void* device) { + if (!device || !platform_.retainDevice || !platform_.releaseDevice) return {}; + platform_.retainDevice(device); + std::function release = platform_.releaseDevice; + return [release, device] { release(device); }; +} + bool FrontEnd::ActivateSplit(UpscaleContext& u, const WgUpscalerBackend* backend, const std::string& tag) { if (!u.createInfo.services || !platform_.activateServices) return true; if (platform_.activateServices(backend, u.device)) return true; diff --git a/clean/fsr/src/frontend.h b/clean/fsr/src/frontend.h index e33a9b74..09459578 100644 --- a/clean/fsr/src/frontend.h +++ b/clean/fsr/src/frontend.h @@ -87,6 +87,11 @@ struct Platform { std::function fn)> timer; // The D3D12 device was removed (device lost): nothing of it is parked or taken over. May be empty. std::function deviceLost; + // The create worker's hold on the game's D3D12 device (async_create.h): retainDevice (AddRef) runs on the game's thread + // before the worker starts, releaseDevice (Release) on the worker when its create is over, also after a timeout. + // Empty: no hold is taken (tests without a COM device). + std::function retainDevice; + std::function releaseDevice; // OptiScaler ASI plugin bridge (clean/fsr/asi): when WrongGPU.asi is loaded and has hooked OptiScaler's menu, // WrongGPU is its own entry in the host's MAIN upscaler list, not a version in the FFX sub-box. Returns true when // hooked (then the version query lists AMD only and this plugin, not an FFX override, chooses the model) and sets @@ -209,6 +214,7 @@ class FrontEnd { void CheckPending(UpscaleContext& u, uint64_t call); // After a successful create of `u`'s upscaler: installs the D3D12 hooks its split service needs // (Platform::activateServices). False: they could not be installed (nothing of them is left patched). + std::function HoldDevice(void* device); // async_create.h: the create worker's hold on the game's device bool ActivateSplit(UpscaleContext& u, const WgUpscalerBackend* backend, const std::string& tag); // The model folder for `u`'s options (Platform::modelPlaces): appends ";model_dir=" when the model is found // in a place before the runtime's own default; nothing when runtime_options / WG_RUNTIME_OPTIONS name model_dir. @@ -253,6 +259,7 @@ class FrontEnd { struct RememberedFailure { std::string reason; // the first failure's reason (logged once in full) uint64_t repeats = 0; // creates refused since, without a new attempt + bool hardIncompat = false; // WG_ERROR_UNSUPPORTED (a hard incompatibility): a repeat hands over like the first create }; std::map failedCreates_; // custom slot: FailureKey -> the failure (mutex_) // Custom slot, WG_ERROR_INPUT (0.6.0 follow-up, bug hunt A): remembered for the session only after kInputRefusedRun refusals diff --git a/clean/fsr/src/fsr30_hook.cpp b/clean/fsr/src/fsr30_hook.cpp index e6d70306..0bfd2278 100644 --- a/clean/fsr/src/fsr30_hook.cpp +++ b/clean/fsr/src/fsr30_hook.cpp @@ -222,7 +222,13 @@ bool Hook::RunStandIn(Context& c, const ffxDispatchDescUpscale& dispatch, const // On a worker thread: the game's thread waits create_wait_ms at most (async_create.h); AMD's FSR upscales the // frames until the create has finished. c.creating = true; - auto pending = PendingCreate::Start(backend, c.createInfo); + std::function hold; // the create worker's own reference on the game's device (async_create.h) + if (device && platform_.retainDevice && platform_.releaseDevice) { + platform_.retainDevice(device); + std::function release = platform_.releaseDevice; + hold = [release, device] { release(device); }; + } + auto pending = PendingCreate::Start(backend, c.createInfo, hold); if (!pending->Wait(config_.createWaitMs)) { c.pending = pending; c.pendingBackend = backend; diff --git a/clean/fsr/src/fsr30_hook.h b/clean/fsr/src/fsr30_hook.h index ae438fa2..94fd3602 100644 --- a/clean/fsr/src/fsr30_hook.h +++ b/clean/fsr/src/fsr30_hook.h @@ -73,6 +73,10 @@ struct Platform { std::function logBytes; ResourceInfoFn resourceInfo = nullptr; std::function deviceFromCommandList; // ID3D12Device* of an ID3D12GraphicsCommandList* + // The create worker's own COM reference on the game's device (async_create.h): AddRef before the worker starts, Release by + // the worker when its create is over (also after a timeout). Empty: no hold (tests without a COM device). + std::function retainDevice; + std::function releaseDevice; // ffx_fsr3 side: how many ffxFsr3UpscalerContextDispatch calls WrongGPU's upscaler DLL has seen on this thread // (empty or 0 when WrongGPU's upscaler DLL is not loaded). std::function upscalerSeenOnThread; diff --git a/clean/fsr/src/win_util.cpp b/clean/fsr/src/win_util.cpp index a1b98cc6..eeff953c 100644 --- a/clean/fsr/src/win_util.cpp +++ b/clean/fsr/src/win_util.cpp @@ -612,6 +612,14 @@ void* DeviceFromCommandList(void* commandList) { return device; } +void RetainDevice(void* device) { + if (device) static_cast(device)->AddRef(); +} + +void ReleaseDevice(void* device) { + if (device) static_cast(device)->Release(); +} + const char* ModuleNameOf(const void* address) { thread_local const void* lastBase = nullptr; thread_local char lastName[MAX_PATH] = "?"; diff --git a/clean/fsr/src/win_util.h b/clean/fsr/src/win_util.h index 0e72e086..7f5f64fa 100644 --- a/clean/fsr/src/win_util.h +++ b/clean/fsr/src/win_util.h @@ -113,6 +113,8 @@ void AddSplitServices(PlatformT& p, const wgfsr::Config& config) { bool D3D12ResourceInfo(void* resource, wgfsr::ResourceInfo* out); void* DeviceFromCommandList(void* commandList); // ID3D12Device* (the game keeps it alive), or null +void RetainDevice(void* device); // AddRef on the game's ID3D12Device: a create worker's own reference (async_create.h) +void ReleaseDevice(void* device); // its Release, by the worker when its create is over // "name.dll" of the module that contains `address` (cached per thread for repeated callers). const char* ModuleNameOf(const void* address); diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 57390c18..859fdb2e 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -158,11 +158,18 @@ static int g_timersStarted = 0; static std::atomic g_createGate{true}; // FakeCreate (on the front end's create thread) waits while false static std::atomic g_createCalls{0}; // every FakeCreate call (made an upscaler or not) static bool g_failCreateUnsupported = false; // FakeCreate answers WG_ERROR_UNSUPPORTED (a hard incompatibility, R1) +static std::atomic g_holdFromCall{0}; // FakeCreate waits for the gate from this call on (1-based); 0: every call +static bool g_deviceHoldOn = false; // the platform gives the create worker a hold on the device (retain / release) +static bool g_deviceTrack = false; // FakeCreate checks that the game's device is still alive when it runs +static std::atomic g_deviceRefs{0}, g_deviceRetains{0}, g_deviceReleases{0}; +static std::atomic g_deviceUsedAfterFree{false}; static WgResult FakeCreate(const WgCreateInfo* info, WgUpscaler** out) { ++g_createCalls; g_createInfo = *info; g_createOptions = info->options; - while (!g_createGate) std::this_thread::sleep_for(std::chrono::milliseconds(1)); + while (!g_createGate && (g_holdFromCall == 0 || g_createCalls >= g_holdFromCall)) + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + if (g_deviceTrack && g_deviceRefs.load() <= 0) g_deviceUsedAfterFree = true; // (the worker's QueryInterface on a freed device) if (g_aboutTo) info->log(info->log_user, WG_LOG_INFO, "about to start the HIP runtime (test)"); info->log(info->log_user, WG_LOG_INFO, "fake upscaler created"); if (g_failCreateUnsupported) return WG_ERROR_UNSUPPORTED; @@ -282,6 +289,10 @@ static std::unique_ptr MakeFrontEnd(const Config& config) { p.menu.folderEntry = g_folderEntry; } p.original = []() -> const OriginalApi* { return g_originalAvailable ? g_originalApi : nullptr; }; + if (g_deviceHoldOn) { + p.retainDevice = [](void*) { ++g_deviceRetains; ++g_deviceRefs; }; + p.releaseDevice = [](void*) { ++g_deviceReleases; --g_deviceRefs; }; + } if (g_asiPresent) p.asiPlugin = [](char* model) { if (model) *model = g_asiModel; return g_asiHooked; }; p.compareApi = []() -> const OriginalApi* { return g_compareApi; }; @@ -343,6 +354,10 @@ static void Reset() { g_log.clear(); g_destroyed = 0; g_failCreate = false; + g_holdFromCall = 0; + g_deviceHoldOn = g_deviceTrack = false; + g_deviceRefs = g_deviceRetains = g_deviceReleases = 0; + g_deviceUsedAfterFree = false; g_failCreateUnsupported = false; g_failCreateOutputWidth = 0; g_failDispatchAt = -1; @@ -1256,6 +1271,124 @@ static void TestHardIncompatibilityHandover() { } } +// R1 (second Codex check of #225): the create worker owns a reference on the game's D3D12 device, taken on the game's thread +// before the worker starts and given back by the worker when its create is over: a stalled worker that outlives the timeout, +// the AMD context (or NO_PROVIDER) and the host's own device reference never touches a released device. +static void TestCreateWorkerHoldsDevice() { + UpscaleCreate c(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE); + for (const bool withAmd : {true, false}) { + Reset(); + g_deviceHoldOn = g_deviceTrack = true; + g_deviceRefs = 1; // the host's own reference + g_originalAvailable = withAmd; + Config config; + config.createWaitMs = 20; + config.createGiveUpMs = 40; + config.fallbackToAmd = withAmd; + auto fe = MakeFrontEnd(config); + ffxContext ctx = nullptr; + g_createGate = false; // the create stalls past the timeout + const ffxReturnCode_t rc = fe->CreateContext(&ctx, &c.upscale.header, kMemCb); + CHECK(rc == (withAmd ? FFX_API_RETURN_OK : FFX_API_RETURN_NO_PROVIDER)); + CHECK(g_deviceRetains == 1 && g_deviceReleases == 0 && g_deviceRefs == 2); // the worker holds its own reference + --g_deviceRefs; // the host releases its device (the stalled create is still running) + if (withAmd) CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + g_createGate = true; // the late worker runs its create now, with the host's reference gone + for (int i = 0; i < 600 && g_deviceReleases == 0; ++i) std::this_thread::sleep_for(std::chrono::milliseconds(5)); + CHECK(g_deviceReleases == 1 && g_deviceRefs == 0); + CHECK(!g_deviceUsedAfterFree); + g_originalAvailable = true; + } + { // negative control: without the hold the same sequence IS caught (the harness sees a worker on a released device) + Reset(); + g_deviceTrack = true; // no platform hold + g_deviceRefs = 1; + Config config; + config.createWaitMs = 20; + auto fe = MakeFrontEnd(config); + ffxContext ctx = nullptr; + g_createGate = false; + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_OK); + --g_deviceRefs; // the host releases its device + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + g_createGate = true; + for (int i = 0; i < 600 && g_destroyed == 0; ++i) std::this_thread::sleep_for(std::chrono::milliseconds(5)); + CHECK(g_deviceUsedAfterFree); + } +} + +// R1: the retry without the split service (the first create worked, the hooks could not be installed) goes through the same +// bounded path as the first create: a stalled retry hands over after create_giveup_ms (no AMD to upscale meanwhile) or +// create_wait_ms (with AMD), it does not hang the game's thread. +static void TestSplitRetryIsBounded() { + UpscaleCreate c(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE); + for (const bool fallback : {false, true}) { + Reset(); + g_activateOn = true; + g_activateResult = false; // the hooks cannot be installed: the create is made again without the service + g_holdFromCall = 2; // the second create stalls + g_createGate = false; + g_deviceHoldOn = g_deviceTrack = true; + g_deviceRefs = 1; + Config config; + config.fallbackToAmd = fallback; + config.createWaitMs = 40; + config.createGiveUpMs = 40; + auto fe = MakeFrontEnd(config); + ffxContext ctx = nullptr; + const auto t0 = std::chrono::steady_clock::now(); + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_OK); + const auto ms = std::chrono::duration_cast(std::chrono::steady_clock::now() - t0).count(); + CHECK(ms >= 30 && ms < 5000); // the bound, not for ever + CHECK(ctx != nullptr && g_amd.size() == 1 && g_amd[0].fn == "create"); // AMD's FSR has the context + CHECK(g_createCalls == 2 && CountLog("created again without the command-list split service") == 1); + CHECK(CountLog("(without the split service)") == 1 && CountLog("goes to AMD FSR for now") == 1); + CHECK(g_deviceRetains == 2 && g_deviceReleases == 1); // the first worker is done, the stalled one still holds + g_createGate = true; + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + for (int i = 0; i < 600 && g_deviceReleases < 2; ++i) std::this_thread::sleep_for(std::chrono::milliseconds(5)); + CHECK(g_deviceReleases == 2 && g_deviceRefs == 1 && !g_deviceUsedAfterFree); + } +} + +// R1: a remembered refusal keeps its classification (custom slot): a hard incompatibility hands over to the available provider +// on the repeat exactly as on the first create (also with fallback_to_amd = 0), without a new attempt; a runtime failure +// stays what it was. +static void TestRememberedHardIncompatibility() { + UpscaleCreate c(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE); + { // WG_ERROR_UNSUPPORTED, custom slot, an AMD provider, fallback_to_amd = 0 + Reset(); + g_failCreateUnsupported = true; + Config config; + config.customSlot = true; + config.fallbackToAmd = false; + auto fe = MakeFrontEnd(config); + for (int i = 0; i < 3; ++i) { + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_OK && ctx); + size_t amdCreates = 0; + for (const auto& call : g_amd) amdCreates += call.fn == "create"; + CHECK(amdCreates == size_t(i + 1)); // AMD's FSR, every time + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + } + CHECK(g_createCalls == 1); // one real attempt: the repeats use the remembered classification + CHECK(CountLog("a hard incompatibility or a create that did not finish") >= 1); + } + { // a runtime failure with fallback_to_amd = 0 is still an error on the repeat, with no new attempt + Reset(); + g_failCreate = true; + Config config; + config.customSlot = true; + config.fallbackToAmd = false; + auto fe = MakeFrontEnd(config); + for (int i = 0; i < 3; ++i) { + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_ERROR_RUNTIME_ERROR && ctx == nullptr); + } + CHECK(g_createCalls == 1 && g_amd.empty()); + } +} + // The upscaler's create takes longer than create_wait_ms (Borderlands 4: HIP's start blocked while the game's thread // waited for it): the game's create returns with AMD's FSR upscaling; the first dispatch after the create finished takes // the upscaler over (with a reset frame). A context destroyed while its create runs is cleaned up when it finishes. @@ -3644,6 +3777,9 @@ int main() { TestReactiveMaskForwarded(); TestSlowCreate(); TestHardIncompatibilityHandover(); + TestCreateWorkerHoldsDevice(); + TestSplitRetryIsBounded(); + TestRememberedHardIncompatibility(); TestInterfaceVersions(); TestAmdMode(); TestNonLinearColour(); diff --git a/clean/installer/tools/make_payload.py b/clean/installer/tools/make_payload.py index aa9dcb60..9083ea69 100644 --- a/clean/installer/tools/make_payload.py +++ b/clean/installer/tools/make_payload.py @@ -62,6 +62,20 @@ def fail(msg): sys.exit("make_payload: " + msg) +# R1: nothing in a game starts HIP, so a payload never carries a developer runtime (executor=hip / capture_dir work only in a +# build made with WG_DEV_DIAGNOSTICS). Every runtime library the payload embeds must say "wg-build dev-diagnostics=0"; a +# developer build or a library without the marker (older than R1) refuses the payload, failing closed, and so does any other +# embedded file that carries a developer runtime. The same check runs on the final package (tools/release). +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "tests")) +import check_no_dev_diagnostics as devcheck # noqa: E402 + + +def refuse_developer_runtime(rel, data): + ok, text, _ = devcheck.check_artifact(rel, data) + if not ok: + fail("%s: %s: a payload never carries the developer diagnostics (build the runtime without --dev-diagnostics)" % (rel, text)) + + def payload_files(root, hosted_only=False): rows = [] for dirpath, dirnames, filenames in os.walk(root): @@ -84,6 +98,7 @@ def payload_files(root, hosted_only=False): data = f.read() if optiscaler_file(rel, data): fail("payload file %s is OptiScaler: WrongGPU never ships OptiScaler (the launcher downloads its edition)" % rel) + refuse_developer_runtime(rel, data) rows.append((rel, hashlib.sha256(data).hexdigest(), len(data), full)) rows.sort(key=lambda r: r[0].lower()) if not any(r[0].lower() == FRONT_END for r in rows): @@ -111,6 +126,7 @@ def rr_files(root): data = f.read() if optiscaler_file(rel, data): fail("RR folder file %s is OptiScaler: WrongGPU never ships OptiScaler (the launcher downloads its edition)" % rel) + refuse_developer_runtime(rel, data) if os.path.basename(rel).lower() == RR_LEGACY_RUNTIME: fail("%s: the RR runtime is part of wronggpu_runtime.dll (release 0.6.0: one runtime DLL); no RR runtime of its own" % rel) if rel.lower() not in RR_FILES and not RR_VARIANT.match(rel.lower()): diff --git a/clean/tests/check_no_dev_diagnostics.py b/clean/tests/check_no_dev_diagnostics.py index 1a4d6372..0e3f2f4e 100644 --- a/clean/tests/check_no_dev_diagnostics.py +++ b/clean/tests/check_no_dev_diagnostics.py @@ -3,23 +3,33 @@ The runtime library says which kind of build it is: the text "wg-build dev-diagnostics=0" (release) or "wg-build dev-diagnostics=1" (a developer build made with --dev-diagnostics; clean/runtime/interop/backend.cpp -wgBuildMarker). This checks libraries for it: +wgBuildMarker). This checks libraries and packages for it: - python clean/tests/check_no_dev_diagnostics.py [...] + python clean/tests/check_no_dev_diagnostics.py [...] -Exit status 0 only when every library found says dev-diagnostics=0. A library that has no marker (an older build), says -dev-diagnostics=1, or a path with no library at all fails: a package check that finds nothing must not pass. The release -script runs this on the packaged library (the same function is used by clean/tests/test_dev_diagnostics_off.py in CI). +A path is a runtime library (wronggpu_runtime*.dll), a folder (searched for libraries, zip files and executables), a zip +file (every member), or an executable (the launcher embeds the payload's files as they are, so its bytes hold the marker). +Exit status 0 only when every runtime library found says dev-diagnostics=0, no other file says =1, and each path gave +evidence of at least one "dev-diagnostics=0" library: a library with no marker (an older build), a developer build, or a +path with nothing to check fails. This is the gate of the payload packager (clean/installer/tools/make_payload.py, which +refuses the payload) and of the release script on the final package (tools/release/check_package_diagnostics.py); the same +functions are used by clean/tests/test_dev_diagnostics_off.py in CI. """ import os import re import sys +import zipfile MARKER = re.compile(rb"wg-build dev-diagnostics=([01])") +def is_runtime_name(name): + n = os.path.basename(name).lower() + return n.startswith("wronggpu_runtime") and n.endswith(".dll") + + def check_bytes(data): - """(True, text) when the library data says dev-diagnostics=0 once and never =1.""" + """(True, text) when the library data says dev-diagnostics=0 once and never =1 (a runtime library).""" found = MARKER.findall(data) if not found: return False, "no 'wg-build dev-diagnostics=' marker (a build older than R1, or not the runtime library)" @@ -28,24 +38,49 @@ def check_bytes(data): return True, "dev-diagnostics=0" -def libraries(path): - if os.path.isfile(path): - return [path] +def check_artifact(name, data): + """(ok, text, evidence) for one file by its name: a runtime library must carry the =0 marker; any other file only + must not say =1. evidence: the file says dev-diagnostics=0 (so a package check knows it looked at a runtime).""" + found = MARKER.findall(data) + zero = any(v == b"0" for v in found) + if is_runtime_name(name): + ok, text = check_bytes(data) + return ok, text, ok + if any(v == b"1" for v in found): + return False, "carries a developer runtime (dev-diagnostics=1)", False + return True, "dev-diagnostics=0" if zero else "nothing to check", zero + + +def artifacts(path): + """[(label, name, data)] of one path: the file itself, a folder's libraries / zips / executables, a zip's members.""" out = [] - for dirpath, _, names in os.walk(path): - for n in names: - if n.lower().startswith("wronggpu_runtime") and n.lower().endswith(".dll"): - out.append(os.path.join(dirpath, n)) - return sorted(out) + if os.path.isdir(path): + for dirpath, _, names in os.walk(path): + for n in sorted(names): + low = n.lower() + if is_runtime_name(n) or low.endswith((".zip", ".exe", ".asi")): + out += artifacts(os.path.join(dirpath, n)) + return out + if path.lower().endswith(".zip"): + with zipfile.ZipFile(path) as z: + for info in z.infolist(): + if info.is_dir(): + continue + out.append((path + "!" + info.filename, info.filename, z.read(info))) + return out + with open(path, "rb") as f: + out.append((path, path, f.read())) + return out def check_path(path): - """[(library, ok, text)]; an empty list is a failure of the caller to find a library.""" + """[(label, ok, text, evidence)]; an empty list or no evidence is a failure of the caller to find a library.""" results = [] - for lib in libraries(path): - with open(lib, "rb") as f: - ok, text = check_bytes(f.read()) - results.append((lib, ok, text)) + for label, name, data in artifacts(path): + ok, text, evidence = check_artifact(name, data) + if ok and text == "nothing to check": + continue # a file that is neither a runtime nor says anything: not listed + results.append((label, ok, text, evidence)) return results @@ -56,11 +91,11 @@ def main(argv): bad = False for path in argv: results = check_path(path) - if not results: - print(f"FAIL {path}: no wronggpu_runtime library found") + if not any(e for _, _, _, e in results): + print(f"FAIL {path}: no runtime library with a 'dev-diagnostics=0' marker found") bad = True - for lib, ok, text in results: - print(("ok " if ok else "FAIL ") + f"{lib}: {text}") + for label, ok, text, _ in results: + print(("ok " if ok else "FAIL ") + f"{label}: {text}") bad = bad or not ok return 1 if bad else 0 diff --git a/clean/tests/test_dev_diagnostics_off.py b/clean/tests/test_dev_diagnostics_off.py index c196a8d0..d8e12437 100644 --- a/clean/tests/test_dev_diagnostics_off.py +++ b/clean/tests/test_dev_diagnostics_off.py @@ -6,9 +6,11 @@ """ import importlib.util import os +import subprocess import sys import tempfile import unittest +import zipfile HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(os.path.dirname(HERE)) @@ -50,7 +52,9 @@ def test_no_release_path_turns_it_on(self): continue for dp, _, names in os.walk(full): for n in names: - if n.endswith((".yml", ".yaml", ".txt", ".cmake", ".py", ".sh", ".bat", ".ps1", ".cpp", ".h", ".json")): + # (build and packaging scripts and configuration; the packager and the checks only NAME the flag to refuse it) + if n.endswith((".yml", ".yaml", ".txt", ".cmake", ".sh", ".bat", ".ps1", ".json")) or ( + n.endswith(".py") and "release" in dp and n != "check_package_diagnostics.py"): p = os.path.join(dp, n) with open(p, encoding="utf-8", errors="replace") as f: t = f.read() @@ -78,5 +82,83 @@ def test_the_library_marker_and_its_check(self): self.assertEqual(chk.main([d]), 1, "one developer library among the packaged ones fails the folder") +MARK0 = b"wg-build dev-diagnostics=0" +MARK1 = b"wg-build dev-diagnostics=1" +PACKAGER = os.path.join(ROOT, "clean", "installer", "tools", "make_payload.py") +RELEASE_CHECK = os.path.join(ROOT, "tools", "release", "check_package_diagnostics.py") + + +class PackagerRefusesDeveloperRuntime(unittest.TestCase): + """The payload packager and the release check look at the BYTES of the runtime that would ship.""" + + def _pack(self, files, extra_args=()): + """Runs make_payload.py on a payload folder holding `files` ({relative name: bytes}) next to a front end.""" + d = tempfile.mkdtemp(prefix="wg_pl_") + payload = os.path.join(d, "payload") + os.makedirs(payload) + for rel, data in {"amd_fidelityfx_dx12.dll": b"front end", **files}.items(): + p = os.path.join(payload, *rel.split("/")) + os.makedirs(os.path.dirname(p), exist_ok=True) + with open(p, "wb") as f: + f.write(data) + with open(os.path.join(d, "map.json"), "wb") as f: + f.write(b"{}") + out = os.path.join(d, "out") + r = subprocess.run([sys.executable, PACKAGER, "--payload", payload, "--map", os.path.join(d, "map.json"), "--version", "0.0.1", + "--out", out, *extra_args], capture_output=True, text=True) + return r, out + + def test_a_release_runtime_is_packaged(self): + r, out = self._pack({"wronggpu_runtime.dll": b"MZ" + b"x" * 64 + MARK0}) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + self.assertTrue(os.path.isfile(os.path.join(out, "payload_table.h"))) + + def test_a_developer_runtime_refuses_the_payload(self): + r, out = self._pack({"wronggpu_runtime.dll": b"MZ" + MARK1}) + self.assertNotEqual(r.returncode, 0) + self.assertIn("dev-diagnostics=1", r.stderr + r.stdout) + self.assertFalse(os.path.isfile(os.path.join(out, "payload_table.h")), "no payload table is written for a refused payload") + + def test_a_runtime_without_the_marker_refuses_the_payload(self): # fails closed: a build older than R1 + r, _ = self._pack({"wronggpu_runtime.dll": b"MZ" + b"x" * 64}) + self.assertNotEqual(r.returncode, 0) + self.assertIn("no 'wg-build dev-diagnostics=' marker", r.stderr + r.stdout) + + def test_every_runtime_library_is_checked_wherever_it_is(self): + r, _ = self._pack({"wronggpu_runtime.dll": MARK0, "sub/wronggpu_runtime_extra.dll": MARK1}) + self.assertNotEqual(r.returncode, 0, "a second library that is a developer build refuses the payload") + r, _ = self._pack({"wronggpu_runtime.dll": MARK0, "sub/other.dll": b"carries a developer runtime " + MARK1}) + self.assertNotEqual(r.returncode, 0, "any other embedded file that says dev-diagnostics=1 refuses it too") + r, _ = self._pack({"wronggpu_runtime.dll": MARK0, "sub/other.dll": b"plain"}) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + + def test_the_final_package_check(self): + with tempfile.TemporaryDirectory() as d: + good_zip, bad_zip = os.path.join(d, "good.zip"), os.path.join(d, "bad.zip") + with zipfile.ZipFile(good_zip, "w") as z: + z.writestr("WrongGPU/wronggpu_runtime.dll", b"MZ" + MARK0) + z.writestr("WrongGPU/readme.txt", b"text") + with zipfile.ZipFile(bad_zip, "w") as z: + z.writestr("WrongGPU/wronggpu_runtime.dll", b"MZ" + MARK1) + empty_zip = os.path.join(d, "empty.zip") + with zipfile.ZipFile(empty_zip, "w") as z: + z.writestr("readme.txt", b"no runtime in here") + exe_good, exe_bad = os.path.join(d, "WrongGPU.exe"), os.path.join(d, "WrongGPU-dev.exe") + with open(exe_good, "wb") as f: + f.write(b"MZ" + b"payload " + MARK0 + b" more") + with open(exe_bad, "wb") as f: + f.write(b"MZ" + b"payload " + MARK1) + + def run(path): + return subprocess.run([sys.executable, RELEASE_CHECK, path], capture_output=True, text=True).returncode + + self.assertEqual(run(good_zip), 0) + self.assertEqual(run(bad_zip), 1, "a developer runtime inside the package zip fails") + self.assertEqual(run(empty_zip), 1, "a package with no runtime found must not pass") + self.assertEqual(run(exe_good), 0, "the launcher embeds the payload's runtime as it is: its marker is found") + self.assertEqual(run(exe_bad), 1) + self.assertEqual(run(d), 1, "a folder holding any developer package fails") + + if __name__ == "__main__": unittest.main() diff --git a/tools/release/check_package_diagnostics.py b/tools/release/check_package_diagnostics.py new file mode 100644 index 00000000..6b9c4399 --- /dev/null +++ b/tools/release/check_package_diagnostics.py @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: MIT +"""Release step (R1): the FINAL package holds no developer diagnostics (executor=hip, the frame capture). + + python tools/release/check_package_diagnostics.py [...] + +Runs clean/tests/check_no_dev_diagnostics.py on each path: every runtime library found (also inside a zip, and inside the +launcher executable, which embeds the payload's files as they are) must say "wg-build dev-diagnostics=0"; a developer build, +a library without the marker, or a path with no runtime library fails (exit 1). Run it on the package that is published, +after it is made: the payload packager (clean/installer/tools/make_payload.py) refuses a developer runtime at build time, this +checks what was actually produced. +""" +import os +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "..", "clean", "tests")) +import check_no_dev_diagnostics # noqa: E402 + +if __name__ == "__main__": + sys.exit(check_no_dev_diagnostics.main(sys.argv[1:])) From 9ccadf982f193b438e44b9ae2a3dfb7f0c4e2a0d Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 08:47:54 -0500 Subject: [PATCH 12/20] Comments: neutral wording for review findings Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/tests/test_frontend.cpp | 4 ++-- clean/runtime/interop/executor_select.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 859fdb2e..132945d9 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -1205,7 +1205,7 @@ static void TestHostedSwitchNotParked() { CHECK(fe->DestroyContext(&a, kMemCb) == FFX_API_RETURN_OK); } -// R1 (Codex review of #225): a create the runtime refuses as a HARD INCOMPATIBILITY (WG_ERROR_UNSUPPORTED: an adapter that is not +// R1 (review finding on #225): a create the runtime refuses as a HARD INCOMPATIBILITY (WG_ERROR_UNSUPPORTED: an adapter that is not // an RDNA 4 card, a build without its D3D12 kernel set, a D3D12 executor that cannot take the context) always goes to the front // end's upscaler, whatever fallback_to_amd says; a runtime failure still obeys fallback_to_amd; with no AMD provider the answer // is the explicit NO_PROVIDER; and a create that does not finish within create_giveup_ms (nothing could upscale meanwhile) is @@ -1271,7 +1271,7 @@ static void TestHardIncompatibilityHandover() { } } -// R1 (second Codex check of #225): the create worker owns a reference on the game's D3D12 device, taken on the game's thread +// R1 (second review of #225): the create worker owns a reference on the game's D3D12 device, taken on the game's thread // before the worker starts and given back by the worker when its create is over: a stalled worker that outlives the timeout, // the AMD context (or NO_PROVIDER) and the host's own device reference never touches a released device. static void TestCreateWorkerHoldsDevice() { diff --git a/clean/runtime/interop/executor_select.h b/clean/runtime/interop/executor_select.h index cf16e932..ac7b50de 100644 --- a/clean/runtime/interop/executor_select.h +++ b/clean/runtime/interop/executor_select.h @@ -177,7 +177,7 @@ inline std::string hip_switch_note(const std::string& option) { // What a context does with a frame the D3D12 executor did not take (nothing of it recorded): the frame is answered // WG_ERROR_UNSUPPORTED, the context stays usable, and the front end takes it from there (AMD's FSR when it exists, else its // stand-in). The same for every model and for a forced executor=dx12: never an image made here (no bilinear substitute), -// never a move to HIP (REVIEW-215c, oversight 2026-11-15; Codex review of #225). +// never a move to HIP (REVIEW-215c, oversight 2026-11-15; review finding on #225). inline constexpr bool kRefusedFrameGoesToFrontEnd = true; // H3 (R1): the output filters Quality 5 and Quality 9 (runtime option output_filter=quality5 | quality9) exist on the HIP From 50e809df2085851b8028ccd32b1835902530464f Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 09:27:22 -0500 Subject: [PATCH 13/20] R1: the package gate rests on the build, not on marker bytes; retry failures; owned device reference build.py writes .build.json (configuration, SHA-256 of the library). The payload packager accepts a runtime library only when its SHA-256 matches a manifest that says dev_diagnostics is false, the marker says =0 and none of the texts that exist only in the diagnostics' code is found (those texts are now compiled only into a developer build); the manifest itself is not shipped. tools/ci/check_release_runtime.py builds the runtime in release and developer configuration and checks both, with a forged marker, a stripped library and a changed library. A split retry that is still running stores no session failure and a late success clears one. The create worker's device reference is owned by an RAII object: given back when the worker finishes, when it could not be started (the create then fails, nothing throws) and on any exception before it starts. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/src/async_create.cpp | 33 +++-- clean/fsr/src/async_create.h | 47 ++++++- clean/fsr/src/frontend.cpp | 10 +- clean/fsr/src/frontend.h | 2 +- clean/fsr/src/fsr30_hook.cpp | 6 +- clean/fsr/tests/test_frontend.cpp | 83 ++++++++++++ clean/installer/tools/make_payload.py | 23 +++- clean/runner/build.py | 30 ++++- clean/runtime/interop/backend.cpp | 2 + clean/runtime/interop/executor_select.h | 15 ++- .../interop/tests/test_executor_select.cpp | 23 ++-- clean/tests/check_no_dev_diagnostics.py | 53 ++++++++ clean/tests/test_dev_diagnostics_off.py | 120 ++++++++++++++--- clean/tests/test_executor_select.py | 5 +- tools/ci/check_release_runtime.py | 121 ++++++++++++++++++ 15 files changed, 515 insertions(+), 58 deletions(-) create mode 100644 tools/ci/check_release_runtime.py diff --git a/clean/fsr/src/async_create.cpp b/clean/fsr/src/async_create.cpp index 850503aa..6128aadb 100644 --- a/clean/fsr/src/async_create.cpp +++ b/clean/fsr/src/async_create.cpp @@ -5,14 +5,33 @@ namespace wgfsr { +namespace { +PendingCreate::Launcher g_launcher = nullptr; +} + +void PendingCreate::SetLauncherForTest(Launcher launcher) { g_launcher = launcher; } + std::shared_ptr PendingCreate::Start(const WgUpscalerBackend* backend, const WgCreateInfo& info, - std::function releaseWhenDone) { - auto p = std::make_shared(); + ScopedRelease hold) { + auto p = std::make_shared(); // (if this throws, `hold` is released as the argument goes away) p->backend_ = backend; p->info_ = info; - p->release_ = std::move(releaseWhenDone); + p->release_ = std::move(hold); p->start_ = std::chrono::steady_clock::now(); - std::thread([p] { p->Run(p); }).detach(); + try { + std::function work = [p] { p->Run(p); }; + if (g_launcher) g_launcher(work); + else std::thread(work).detach(); + } catch (...) { // the worker could not be started: the create did not run and failed; the hold is given back now + { + std::lock_guard lock(p->mutex_); + p->result_ = WG_ERROR_DEVICE; + p->end_ = std::chrono::steady_clock::now(); + p->done_ = true; + } + p->cv_.notify_all(); + p->release_.Release(); + } return p; } @@ -31,11 +50,7 @@ void PendingCreate::Run(std::shared_ptr self) { } cv_.notify_all(); if (cleanup) cleanup(r == WG_OK ? upscaler : nullptr); // the context went away while the create ran - if (release_) { // the last step: nothing of this worker touches the game's device after it - std::function release = std::move(release_); - release_ = nullptr; - release(); - } + release_.Release(); // the last step: nothing of this worker touches the game's device after it } bool PendingCreate::Wait(uint32_t ms) { diff --git a/clean/fsr/src/async_create.h b/clean/fsr/src/async_create.h index 8a633f6b..8869a5ec 100644 --- a/clean/fsr/src/async_create.h +++ b/clean/fsr/src/async_create.h @@ -17,14 +17,51 @@ namespace wgfsr { +// Owns one thing to give back (the create worker's COM reference on the game's device, taken by the front end before the +// worker starts): released exactly once, by Release() or, if nobody did, when the owner goes away. So the reference is +// given back when the worker finishes, when the worker could not be started at all (Start), and when anything between taking +// the reference and starting the worker throws. Move-only. +class ScopedRelease { +public: + ScopedRelease() = default; + explicit ScopedRelease(std::function release) : release_(std::move(release)) {} + ScopedRelease(ScopedRelease&& o) noexcept : release_(std::move(o.release_)) { o.release_ = nullptr; } + ScopedRelease& operator=(ScopedRelease&& o) noexcept { + if (this != &o) { + Release(); + release_ = std::move(o.release_); + o.release_ = nullptr; + } + return *this; + } + ScopedRelease(const ScopedRelease&) = delete; + ScopedRelease& operator=(const ScopedRelease&) = delete; + ~ScopedRelease() { Release(); } + void Release() { + std::function f = std::move(release_); + release_ = nullptr; + if (f) f(); + } + explicit operator bool() const { return static_cast(release_); } + +private: + std::function release_; +}; + class PendingCreate { public: // Starts backend->create(info) on a new thread. `info` and what it points to (options, log user) must stay valid - // until the create finished, or until the cleanup given to Abandon ran. `releaseWhenDone`: runs on the worker thread as - // its last step, also after a timeout and after the context went away (the front end takes a COM reference on the - // game's D3D12 device before the worker starts and gives it back here, so a late worker never meets a released device). + // until the create finished, or until the cleanup given to Abandon ran. `hold`: released by the worker as its last step, + // also after a timeout and after the context went away; released at once when the worker cannot be started (the create + // then counts as failed: WG_ERROR_DEVICE, no exception reaches the game's thread) or when anything before it throws (the + // front end takes a COM reference on the game's D3D12 device before the worker starts and gives it back through this, so a + // late worker never meets a released device and a worker that never ran never leaks it). static std::shared_ptr Start(const WgUpscalerBackend* backend, const WgCreateInfo& info, - std::function releaseWhenDone = {}); + ScopedRelease hold = {}); + // Tests: how the worker thread is launched (default: a detached std::thread). A launcher that throws is a worker that + // could not be started. Null restores the default. + using Launcher = void (*)(std::function work); + static void SetLauncherForTest(Launcher launcher); // Waits up to `ms` milliseconds (UINT32_MAX: until it finishes); true when the create has finished. bool Wait(uint32_t ms); @@ -52,7 +89,7 @@ class PendingCreate { WgResult result_ = WG_ERROR_DEVICE; WgUpscaler* upscaler_ = nullptr; std::function cleanup_; // set by Abandon while the create runs - std::function release_; // the worker's last step (Start's releaseWhenDone) + ScopedRelease release_; // the worker's last step (Start's hold) double reported_ = 0; // highest threshold PassedThreshold answered true for std::chrono::steady_clock::time_point start_, end_; }; diff --git a/clean/fsr/src/frontend.cpp b/clean/fsr/src/frontend.cpp index ff6952b6..5591b32b 100644 --- a/clean/fsr/src/frontend.cpp +++ b/clean/fsr/src/frontend.cpp @@ -810,7 +810,7 @@ ffxReturnCode_t FrontEnd::CreateUpscale(ffxContext* context, ffxCreateContextDes u->upscaler = nullptr; hardIncompat = r == WG_ERROR_UNSUPPORTED; } - if (!u->backend && config_.customSlot) { + if (!u->backend && config_.customSlot && !u->pending) { // (a retry still running is no failure yet) const std::string reason = u->createError.empty() ? why : why + ": " + u->createError; { std::lock_guard lock(mutex_); @@ -960,6 +960,10 @@ void FrontEnd::CheckPending(UpscaleContext& u, uint64_t call) { u.mode = UpscaleContext::Mode::Own; u.compared = true; // the network starts with a reset frame; AMD keeps its history for comparisons u.failReason.clear(); + if (config_.customSlot) { // a late success clears any session failure stored for these options + std::lock_guard lock(mutex_); + failedCreates_.erase(FailureKey(u.pendingBackend, u)); + } Log(tag + ": WrongGPU's upscaler \"" + u.backend->name + "\" started after " + seconds + "; it upscales from this frame on"); } else { u.failReason = u.createError.empty() ? std::string("upscaler \"") + u.pendingBackend->name + "\" create failed: " + WgResultText(r) @@ -978,11 +982,11 @@ void FrontEnd::CheckPending(UpscaleContext& u, uint64_t call) { // starts and released by the worker as its last step, so a worker that outlives a timeout, the AMD context and the host's // own device reference never touches a released device. The release is a copy of the platform's function: it does not // depend on this object. -std::function FrontEnd::HoldDevice(void* device) { +ScopedRelease FrontEnd::HoldDevice(void* device) { if (!device || !platform_.retainDevice || !platform_.releaseDevice) return {}; platform_.retainDevice(device); std::function release = platform_.releaseDevice; - return [release, device] { release(device); }; + return ScopedRelease([release, device] { release(device); }); } bool FrontEnd::ActivateSplit(UpscaleContext& u, const WgUpscalerBackend* backend, const std::string& tag) { diff --git a/clean/fsr/src/frontend.h b/clean/fsr/src/frontend.h index 09459578..48d587d3 100644 --- a/clean/fsr/src/frontend.h +++ b/clean/fsr/src/frontend.h @@ -214,7 +214,7 @@ class FrontEnd { void CheckPending(UpscaleContext& u, uint64_t call); // After a successful create of `u`'s upscaler: installs the D3D12 hooks its split service needs // (Platform::activateServices). False: they could not be installed (nothing of them is left patched). - std::function HoldDevice(void* device); // async_create.h: the create worker's hold on the game's device + ScopedRelease HoldDevice(void* device); // async_create.h: the create worker's hold on the game's device (RAII) bool ActivateSplit(UpscaleContext& u, const WgUpscalerBackend* backend, const std::string& tag); // The model folder for `u`'s options (Platform::modelPlaces): appends ";model_dir=" when the model is found // in a place before the runtime's own default; nothing when runtime_options / WG_RUNTIME_OPTIONS name model_dir. diff --git a/clean/fsr/src/fsr30_hook.cpp b/clean/fsr/src/fsr30_hook.cpp index 0bfd2278..25dbec56 100644 --- a/clean/fsr/src/fsr30_hook.cpp +++ b/clean/fsr/src/fsr30_hook.cpp @@ -222,13 +222,13 @@ bool Hook::RunStandIn(Context& c, const ffxDispatchDescUpscale& dispatch, const // On a worker thread: the game's thread waits create_wait_ms at most (async_create.h); AMD's FSR upscales the // frames until the create has finished. c.creating = true; - std::function hold; // the create worker's own reference on the game's device (async_create.h) + ScopedRelease hold; // the create worker's own reference on the game's device (async_create.h; RAII) if (device && platform_.retainDevice && platform_.releaseDevice) { platform_.retainDevice(device); std::function release = platform_.releaseDevice; - hold = [release, device] { release(device); }; + hold = ScopedRelease([release, device] { release(device); }); } - auto pending = PendingCreate::Start(backend, c.createInfo, hold); + auto pending = PendingCreate::Start(backend, c.createInfo, std::move(hold)); if (!pending->Wait(config_.createWaitMs)) { c.pending = pending; c.pendingBackend = backend; diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 132945d9..e63837df 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1389,6 +1390,86 @@ static void TestRememberedHardIncompatibility() { } } +// R1: a retry without the split service that is still running is no failure yet: nothing is stored for the session while it +// runs (a custom slot would then refuse every later create of these options), and when it succeeds late the context upscales +// with WrongGPU and the next create uses WrongGPU too. +static void TestSplitRetryPendingStoresNoFailure() { + Reset(); + g_resources[kColor] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; + g_resources[kDepth] = {dxgi::R32_FLOAT, 2560, 1440}; + g_resources[kMotion] = {dxgi::R16G16_FLOAT, 2560, 1440}; + g_resources[kOutput] = {dxgi::R16G16B16A16_FLOAT, 2560, 1440}; + g_activateOn = true; + g_activateResult = false; // the hooks cannot be installed: the create is made again without the service + g_holdFromCall = 2; // the retry runs past the wait limit + g_createGate = false; + Config config; + config.customSlot = true; + config.createWaitMs = 20; + auto fe = MakeFrontEnd(config); + UpscaleCreate c(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE); + ffxContext ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_OK && ctx); + CHECK(CountLog("is still starting (without the split service)") == 1 && CountLog("goes to AMD FSR for now") == 1); + CHECK(CountLog("this failure is remembered for the session") == 0); // nothing is stored while the retry runs + g_createGate = true; // the retry finishes late and succeeds + ffxDispatchDescUpscale d = MakeDispatch(); + for (int i = 0; i < 400 && g_frames.empty(); ++i) { + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK); + } + CHECK(!g_frames.empty() && CountLog("started after") == 1); // WrongGPU took the context over + CHECK(CountLog("this failure is remembered for the session") == 0); + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + const int callsBefore = g_createCalls; + const size_t framesBefore = g_frames.size(); + ctx = nullptr; + CHECK(fe->CreateContext(&ctx, &c.upscale.header, kMemCb) == FFX_API_RETURN_OK && ctx); // the next create: a real attempt + CHECK(g_createCalls > callsBefore && CountLog("failed earlier in this session") == 0); + CHECK(fe->Dispatch(&ctx, &d.header) == FFX_API_RETURN_OK && g_frames.size() == framesBefore + 1); // and WrongGPU upscales + CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); +} + +// R1: the create worker's device reference is owned (RAII): it is given back when the worker could not be started at all +// (the create then counts as failed, nothing throws into the game's thread) and exactly once whatever happens to the owner. +static void FailingLauncher(std::function) { throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)); } + +static void TestWorkerLaunchFailureGivesTheDeviceBack() { + UpscaleCreate c(FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE); + for (const bool fallback : {true, false}) { + Reset(); + g_deviceHoldOn = g_deviceTrack = true; + g_deviceRefs = 1; // the host's own reference + PendingCreate::SetLauncherForTest(&FailingLauncher); + Config config; + config.fallbackToAmd = fallback; + auto fe = MakeFrontEnd(config); + ffxContext ctx = nullptr; + const ffxReturnCode_t rc = fe->CreateContext(&ctx, &c.upscale.header, kMemCb); + PendingCreate::SetLauncherForTest(nullptr); + CHECK(rc == (fallback ? FFX_API_RETURN_OK : FFX_API_RETURN_ERROR_RUNTIME_ERROR)); // a failed create, no exception + CHECK(g_createCalls == 0 && CountLog("create failed") >= 1); // no worker ever ran + CHECK(g_deviceRetains == 1 && g_deviceReleases == 1 && g_deviceRefs == 1); // the reference came back at once + if (fallback) CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); + } + { // the owner itself: released once, by Release() or by the destructor, never twice; a move transfers it + int released = 0; + { + ScopedRelease a([&released] { ++released; }); + ScopedRelease b(std::move(a)); + CHECK(!a && b); + ScopedRelease d; + d = std::move(b); + CHECK(!b && d && released == 0); + } + CHECK(released == 1); + ScopedRelease e([&released] { ++released; }); + e.Release(); + e.Release(); + CHECK(released == 2 && !e); + } +} + // The upscaler's create takes longer than create_wait_ms (Borderlands 4: HIP's start blocked while the game's thread // waited for it): the game's create returns with AMD's FSR upscaling; the first dispatch after the create finished takes // the upscaler over (with a reset frame). A context destroyed while its create runs is cleaned up when it finishes. @@ -3780,6 +3861,8 @@ int main() { TestCreateWorkerHoldsDevice(); TestSplitRetryIsBounded(); TestRememberedHardIncompatibility(); + TestSplitRetryPendingStoresNoFailure(); + TestWorkerLaunchFailureGivesTheDeviceBack(); TestInterfaceVersions(); TestAmdMode(); TestNonLinearColour(); diff --git a/clean/installer/tools/make_payload.py b/clean/installer/tools/make_payload.py index 9083ea69..550dace7 100644 --- a/clean/installer/tools/make_payload.py +++ b/clean/installer/tools/make_payload.py @@ -70,10 +70,23 @@ def fail(msg): import check_no_dev_diagnostics as devcheck # noqa: E402 -def refuse_developer_runtime(rel, data): - ok, text, _ = devcheck.check_artifact(rel, data) +def refuse_developer_runtime(rel, data, full=None): + """A runtime library is accepted only with its build manifest (clean/runner/build.py writes .build.json next to + it): the SHA-256 of the library must match a manifest that says dev_diagnostics = false, as well as the marker and the + negative scan; anything else refuses the payload (failing closed). Other embedded files must not carry a developer + runtime.""" + if devcheck.is_runtime_name(rel): + manifest = None + mpath = os.path.splitext(full)[0] + ".build.json" if full else None + if mpath and os.path.isfile(mpath): + with open(mpath, "rb") as f: + manifest = f.read() + ok, text = devcheck.check_runtime_with_manifest(rel, data, manifest) + else: + ok, text, _ = devcheck.check_artifact(rel, data) if not ok: - fail("%s: %s: a payload never carries the developer diagnostics (build the runtime without --dev-diagnostics)" % (rel, text)) + fail("%s: %s: a payload never carries the developer diagnostics (build the runtime with clean/runner/build.py " + "without --dev-diagnostics and keep its .build.json next to it)" % (rel, text)) def payload_files(root, hosted_only=False): @@ -92,13 +105,15 @@ def payload_files(root, hosted_only=False): continue if low[0] in RESERVED: fail("payload file %s uses a name reserved for the installer" % rel) + if low[-1].endswith(".build.json"): # a runtime library's build manifest (build.py): read for the gate, not shipped + continue if any(p in ("", ".", "..") or ":" in p for p in parts): fail("bad payload path %s" % rel) with open(full, "rb") as f: data = f.read() if optiscaler_file(rel, data): fail("payload file %s is OptiScaler: WrongGPU never ships OptiScaler (the launcher downloads its edition)" % rel) - refuse_developer_runtime(rel, data) + refuse_developer_runtime(rel, data, full) rows.append((rel, hashlib.sha256(data).hexdigest(), len(data), full)) rows.sort(key=lambda r: r[0].lower()) if not any(r[0].lower() == FRONT_END for r in rows): diff --git a/clean/runner/build.py b/clean/runner/build.py index 80867a6b..3b0dc137 100644 --- a/clean/runner/build.py +++ b/clean/runner/build.py @@ -17,6 +17,7 @@ """ import argparse import json +import hashlib import os import re import shutil @@ -355,7 +356,34 @@ def build_runtime(cxx, out_dir, embed=True): ([L_MAP_FILE] if MODEL_L else []): shutil.copyfile(m, os.path.join(out_dir, os.path.basename(m))) embedded = write_embedded(out_dir) if embed else None - run(runtime_command(cxx, os.path.join(out_dir, runtime_library_name()), embedded)) + cmd = runtime_command(cxx, os.path.join(out_dir, runtime_library_name()), embedded) + run(cmd) + write_build_manifest(out_dir, cmd, embedded is not None) + + +def write_build_manifest(out_dir, cmd, embedded): + """.build.json next to the library: what this build is (R1). The payload packager accepts a runtime + library only when its SHA-256 matches a manifest that says dev_diagnostics = false (make_payload.py, failing closed); + any later change of the library (stripping, signing, a copy from another build) breaks the match.""" + dll = os.path.join(out_dir, runtime_library_name()) + with open(dll, "rb") as f: + data = f.read() + manifest = { + "format": 1, + "file": os.path.basename(dll), + "sha256": hashlib.sha256(data).hexdigest(), + "size": len(data), + "dev_diagnostics": bool(DEV_DIAGNOSTICS), + "model_l": bool(MODEL_L), + "models_left_out": sorted(n for n in OPTIONAL_MODELS if not MODELS_BUILT[n]), + "embedded_files": bool(embedded), + "defines": sorted(a for a in cmd if a.startswith("-D")), + } + path = os.path.splitext(dll)[0] + ".build.json" + with open(path, "w", encoding="utf-8", newline="\n") as f: + json.dump(manifest, f, indent=2, sort_keys=True) + f.write("\n") + print(f"build manifest: {path} (dev_diagnostics={str(manifest['dev_diagnostics']).lower()}, sha256 {manifest['sha256'][:16]}...)", flush=True) def run(cmd): diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 38d466a3..297bc76c 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -749,11 +749,13 @@ class Context { " (motion-compensated, disocclusion by depth; WrongGPU's own addition)" : std::string("sparkle guard not available with this executor")); } +#ifdef WG_DEV_DIAGNOSTICS // developer build only (a release build has dropped capture_dir at create) if (!o.capture_dir.empty()) { exec_->set_capture(o.capture_dir, o.capture_frames > 0 ? o.capture_frames : 30); say(WG_LOG_INFO, "frame capture armed: create " + o.capture_dir + "\\capture.go to write the next " + std::to_string(o.capture_frames) + " network frames there (diagnostics; stalls the GPU)"); } +#endif if (o.timing_log) { timing_.reset(new TimingLog()); if (!timing_->init(device_, &err)) return fail(WG_ERROR_DEVICE, err); diff --git a/clean/runtime/interop/executor_select.h b/clean/runtime/interop/executor_select.h index ac7b50de..e73b9898 100644 --- a/clean/runtime/interop/executor_select.h +++ b/clean/runtime/interop/executor_select.h @@ -88,10 +88,13 @@ inline std::string sparkle_off_line() { return "the sparkle guard runs on HIP only and is turned off; the model runs on the D3D12 executor"; } -// The one line for the frame capture (an opt-in diagnostic that needs the HIP executor). +// The one line for the frame capture (an opt-in diagnostic that needs the HIP executor). Developer builds only: the text is +// not in a release build's library at all (the package gate looks for it: clean/tests/check_no_dev_diagnostics.py). +#ifdef WG_DEV_DIAGNOSTICS inline std::string capture_hip_line() { return "diagnostic: frame capture forces the HIP executor (the model runs on the D3D12 executor without it)"; } +#endif // rdna4.h's identity of a request. inline wgrt::AdapterIdentity adapter_identity(const ExecutorRequest& r) { @@ -108,8 +111,10 @@ inline wgrt::AdapterIdentity adapter_identity(const ExecutorRequest& r) { inline std::string hip_switch_note(const std::string& option); // below -// `dev`: the build's WG_DEV_DIAGNOSTICS (tests pass both values to check both configurations). -inline ExecutorChoice choose_executor(const ExecutorRequest& r, bool dev = kDevDiagnostics) { +// `dev`: whether the developer diagnostics are on. They can only be on in a build made with WG_DEV_DIAGNOSTICS (a release +// build has no code or text for them whatever is passed), so the tests pass both values and the two build configurations. +inline ExecutorChoice choose_executor(const ExecutorRequest& r, bool devRequested = kDevDiagnostics) { + const bool dev = kDevDiagnostics && devRequested; ExecutorChoice c; c.hip_note = hip_switch_note(r.hip_switch); // the same for every model: the option is ignored std::string e = r.executor; @@ -128,6 +133,7 @@ inline ExecutorChoice choose_executor(const ExecutorRequest& r, bool dev = kDevD c.executor = e; return c; } +#ifdef WG_DEV_DIAGNOSTICS if (e == "hip") { // developer build only: a diagnostic for every model, loud, never the default c.executor = e; c.warn = true; @@ -135,6 +141,7 @@ inline ExecutorChoice choose_executor(const ExecutorRequest& r, bool dev = kDevD "executor=dx12 run on the D3D12 executor)"; return c; } +#endif const bool forced = e == "dx12" || e == "d3d12"; if (!forced && e != "auto" && !e.empty()) return c; // unknown value if (!forced) { @@ -146,12 +153,14 @@ inline ExecutorChoice choose_executor(const ExecutorRequest& r, bool dev = kDevD return c; } } +#ifdef WG_DEV_DIAGNOSTICS if (capture) { // developer build only: an opt-in diagnostic, never on by default c.executor = "hip"; c.warn = true; c.why = capture_hip_line(); return c; } +#endif c.executor = "dx12"; // the success line is logged once the D3D12 executor has taken the context if (r.sparkle_guard) { // the guard is HIP only: it is off, the model stays on D3D12 c.sparkle_off = true; diff --git a/clean/runtime/interop/tests/test_executor_select.cpp b/clean/runtime/interop/tests/test_executor_select.cpp index 5d58e27f..7d02a897 100644 --- a/clean/runtime/interop/tests/test_executor_select.cpp +++ b/clean/runtime/interop/tests/test_executor_select.cpp @@ -281,7 +281,10 @@ int main() { #endif for (bool model_k : {false, true}) for (bool dev : {true, false}) { - const std::string tag = std::string(model_k ? " (model K)" : " (model M or L)") + (dev ? " [dev]" : " [release]"); + // (a release build has no developer code at all: dev=true then behaves as a release build; the developer routes are + // asserted by the binary built with WG_DEV_DIAGNOSTICS, which test_executor_select.py also runs) + const bool devEff = dev && wgi::kDevDiagnostics; + const std::string tag = std::string(model_k ? " (model K)" : " (model M or L)") + (devEff ? " [dev]" : " [release]"); auto choose = [&](const ExecutorRequest& q) { return choose_executor(q, dev); }; auto only_ignored = [](const ExecutorChoice& c, const char* key) { return c.ignored.size() == 1 && has(c.ignored[0], key) && has(c.ignored[0], "ignored: diagnostic key, release build") && @@ -291,7 +294,7 @@ int main() { r.model_k = model_k; r.executor = "hip"; ExecutorChoice c = choose(r); - if (dev) + if (devEff) expect("executor=hip: the HIP executor as a loud diagnostic" + tag, c.executor == "hip" && !c.by_default && c.warn && has(c.why, "diagnostic: executor=hip") && has(c.why, "not the in-game runtime") && c.ignored.empty()); @@ -302,7 +305,7 @@ int main() { r.model_k = model_k; r.executor = "hip"; c = choose(r); - if (dev) + if (devEff) expect("executor=hip on another board: the same diagnostic" + tag, c.executor == "hip" && c.warn && has(c.why, "diagnostic: executor=hip")); else @@ -312,24 +315,22 @@ int main() { r.model_k = model_k; r.capture = true; c = choose(r); - if (dev) + if (devEff) expect("auto + frame capture: HIP with the loud diagnostic line" + tag, - c.executor == "hip" && c.warn && c.why == wgi::capture_hip_line() && has(c.why, "diagnostic: frame capture") && - c.ignored.empty()); + c.executor == "hip" && c.warn && has(c.why, "diagnostic: frame capture") && c.ignored.empty()); else expect("auto + frame capture is IGNORED: the D3D12 executor, one line, no HIP" + tag, c.executor == "dx12" && c.by_default && c.why.empty() && only_ignored(c, "capture_dir")); r.executor = "dx12"; c = choose(r); - if (dev) - expect("executor=dx12 + frame capture: the same diagnostic (HIP)" + tag, - c.executor == "hip" && c.why == wgi::capture_hip_line()); + if (devEff) + expect("executor=dx12 + frame capture: the same diagnostic (HIP)" + tag, c.executor == "hip" && has(c.why, "diagnostic: frame capture")); else expect("executor=dx12 + capture_dir is ignored: the D3D12 executor, one line" + tag, c.executor == "dx12" && !c.by_default && only_ignored(c, "capture_dir")); r.executor = "hip"; c = choose(r); - if (dev) + if (devEff) expect("executor=hip + capture (developer build): HIP" + tag, c.executor == "hip"); else expect("executor=hip + capture_dir in a release build: both ignored, two lines, D3D12" + tag, @@ -346,7 +347,7 @@ int main() { expect("executor=dx12 + sparkle guard: the same" + tag, c.executor == "dx12" && c.sparkle_off && !c.by_default); r.capture = true; c = choose(r); - if (dev) + if (devEff) expect("the sparkle guard with the capture (developer build): the capture's diagnostic wins" + tag, c.executor == "hip"); else expect("the sparkle guard with capture_dir (release): D3D12, the guard off, the key ignored" + tag, diff --git a/clean/tests/check_no_dev_diagnostics.py b/clean/tests/check_no_dev_diagnostics.py index 0e3f2f4e..c71252c4 100644 --- a/clean/tests/check_no_dev_diagnostics.py +++ b/clean/tests/check_no_dev_diagnostics.py @@ -7,6 +7,13 @@ python clean/tests/check_no_dev_diagnostics.py [...] +The marker is a statement of the build; the gate does not rest on it alone. Two more layers: (1) a library built without +WG_DEV_DIAGNOSTICS has no code or text for the diagnostics at all, so none of the texts that exist only in that code may be +found in it (DEV_ONLY_STRINGS: a developer build whose marker was forged to =0 still carries them); (2) the payload packager +also demands the library's BUILD MANIFEST (clean/runner/build.py writes .build.json: the build's configuration and the +SHA-256 of the library) and accepts a library only when its SHA-256 matches a manifest that says dev_diagnostics = false +(check_runtime_with_manifest). + A path is a runtime library (wronggpu_runtime*.dll), a folder (searched for libraries, zip files and executables), a zip file (every member), or an executable (the launcher embeds the payload's files as they are, so its bytes hold the marker). Exit status 0 only when every runtime library found says dev-diagnostics=0, no other file says =1, and each path gave @@ -15,6 +22,8 @@ refuses the payload) and of the release script on the final package (tools/release/check_package_diagnostics.py); the same functions are used by clean/tests/test_dev_diagnostics_off.py in CI. """ +import hashlib +import json import os import re import sys @@ -22,6 +31,18 @@ MARKER = re.compile(rb"wg-build dev-diagnostics=([01])") +# Texts that exist only in the developer diagnostics' code (clean/runtime/interop/executor_select.h, backend.cpp, all behind +# WG_DEV_DIAGNOSTICS): a release build's library contains none of them. +DEV_ONLY_STRINGS = ( + b"diagnostic: executor=hip selects the HIP executor", + b"diagnostic: frame capture forces the HIP executor", + b"frame capture armed: create ", +) + + +def dev_only_strings_in(data): + return [t.decode("ascii") for t in DEV_ONLY_STRINGS if t in data] + def is_runtime_name(name): n = os.path.basename(name).lower() @@ -35,9 +56,38 @@ def check_bytes(data): return False, "no 'wg-build dev-diagnostics=' marker (a build older than R1, or not the runtime library)" if any(v == b"1" for v in found): return False, "built with WG_DEV_DIAGNOSTICS (dev-diagnostics=1)" + carried = dev_only_strings_in(data) + if carried: + return False, "says dev-diagnostics=0 but carries developer-diagnostic code (%r): a forged marker" % carried[0] return True, "dev-diagnostics=0" +def check_runtime_with_manifest(name, data, manifest_bytes): + """(ok, text) for a runtime library the packager is about to embed: the marker and the negative scan (check_bytes) AND + the build manifest next to the library: present, format 1, for this file, SHA-256 equal to the library's, and + dev_diagnostics false. Fails closed on anything else (no manifest, unreadable, another library's, a library that was + changed after its build: stripped, signed, replaced).""" + ok, text = check_bytes(data) + if not ok: + return False, text + if manifest_bytes is None: + return False, "no build manifest (%s.build.json next to the library): build it with clean/runner/build.py" % os.path.splitext(os.path.basename(name))[0] + try: + m = json.loads(manifest_bytes.decode("utf-8")) + assert isinstance(m, dict) + except Exception: + return False, "the build manifest is not readable JSON" + if m.get("format") != 1: + return False, "the build manifest has an unknown format" + if str(m.get("file", "")).lower() != os.path.basename(name).lower(): + return False, "the build manifest is for another file (%s)" % m.get("file") + if str(m.get("sha256", "")).lower() != hashlib.sha256(data).hexdigest(): + return False, "the library does not match its build manifest (SHA-256): changed after its build, or another build's file" + if m.get("dev_diagnostics") is not False: + return False, "the build manifest says dev_diagnostics is not false" + return True, "dev-diagnostics=0, matches its build manifest" + + def check_artifact(name, data): """(ok, text, evidence) for one file by its name: a runtime library must carry the =0 marker; any other file only must not say =1. evidence: the file says dev-diagnostics=0 (so a package check knows it looked at a runtime).""" @@ -48,6 +98,9 @@ def check_artifact(name, data): return ok, text, ok if any(v == b"1" for v in found): return False, "carries a developer runtime (dev-diagnostics=1)", False + carried = dev_only_strings_in(data) + if carried: + return False, "carries developer-diagnostic code (%r)" % carried[0], False return True, "dev-diagnostics=0" if zero else "nothing to check", zero diff --git a/clean/tests/test_dev_diagnostics_off.py b/clean/tests/test_dev_diagnostics_off.py index d8e12437..d2ba4549 100644 --- a/clean/tests/test_dev_diagnostics_off.py +++ b/clean/tests/test_dev_diagnostics_off.py @@ -4,7 +4,9 @@ No GPU, no compiler needed: the build script's runtime command, the CI and release files, and the library check are read. Run: python -m unittest clean.tests.test_dev_diagnostics_off """ +import hashlib import importlib.util +import json import os import subprocess import sys @@ -84,23 +86,57 @@ def test_the_library_marker_and_its_check(self): MARK0 = b"wg-build dev-diagnostics=0" MARK1 = b"wg-build dev-diagnostics=1" +DEV_TEXT = b"diagnostic: executor=hip selects the HIP executor; it is not the in-game runtime" # exists only in the diagnostics' code PACKAGER = os.path.join(ROOT, "clean", "installer", "tools", "make_payload.py") RELEASE_CHECK = os.path.join(ROOT, "tools", "release", "check_package_diagnostics.py") +def manifest_for(name, data, dev=False, **over): + m = {"format": 1, "file": name, "sha256": hashlib.sha256(data).hexdigest(), "size": len(data), "dev_diagnostics": dev} + m.update(over) + return json.dumps(m).encode() + + +class BuildManifest(unittest.TestCase): + def test_build_py_writes_the_manifest_of_what_it_built(self): + b = load_build() + with tempfile.TemporaryDirectory() as d: + dll = os.path.join(d, b.runtime_library_name()) + with open(dll, "wb") as f: + f.write(b"MZ library " + MARK0) + for dev in (False, True): + b.DEV_DIAGNOSTICS = dev + try: + b.write_build_manifest(d, ["clang++", "-DWG_MODEL_L"] + (["-DWG_DEV_DIAGNOSTICS=1"] if dev else []), False) + finally: + b.DEV_DIAGNOSTICS = False + with open(os.path.splitext(dll)[0] + ".build.json", encoding="utf-8") as f: + m = json.load(f) + self.assertEqual(m["format"], 1) + self.assertEqual(m["file"], os.path.basename(dll)) + self.assertEqual(m["sha256"], hashlib.sha256(open(dll, "rb").read()).hexdigest()) + self.assertEqual(m["dev_diagnostics"], dev) + self.assertEqual("-DWG_DEV_DIAGNOSTICS=1" in m["defines"], dev) + + class PackagerRefusesDeveloperRuntime(unittest.TestCase): - """The payload packager and the release check look at the BYTES of the runtime that would ship.""" + """The payload packager and the release check look at the BYTES of the runtime that would ship, and at its build manifest.""" - def _pack(self, files, extra_args=()): - """Runs make_payload.py on a payload folder holding `files` ({relative name: bytes}) next to a front end.""" + def _pack(self, files, manifests=None, extra_args=()): + """Runs make_payload.py on a payload folder holding `files` ({relative name: bytes}) next to a front end; + `manifests` ({library relative name: manifest bytes}) are written as .build.json beside the library.""" d = tempfile.mkdtemp(prefix="wg_pl_") payload = os.path.join(d, "payload") os.makedirs(payload) - for rel, data in {"amd_fidelityfx_dx12.dll": b"front end", **files}.items(): + everything = {"amd_fidelityfx_dx12.dll": b"front end", **files} + for rel, data in everything.items(): p = os.path.join(payload, *rel.split("/")) os.makedirs(os.path.dirname(p), exist_ok=True) with open(p, "wb") as f: f.write(data) + for rel, mdata in (manifests or {}).items(): + with open(os.path.splitext(os.path.join(payload, *rel.split("/")))[0] + ".build.json", "wb") as f: + f.write(mdata) with open(os.path.join(d, "map.json"), "wb") as f: f.write(b"{}") out = os.path.join(d, "out") @@ -108,28 +144,74 @@ def _pack(self, files, extra_args=()): "--out", out, *extra_args], capture_output=True, text=True) return r, out - def test_a_release_runtime_is_packaged(self): - r, out = self._pack({"wronggpu_runtime.dll": b"MZ" + b"x" * 64 + MARK0}) + def _release(self, extra=b""): + return b"MZ" + b"x" * 64 + extra + MARK0 + + def test_a_release_runtime_with_its_manifest_is_packaged(self): + lib = self._release() + r, out = self._pack({"wronggpu_runtime.dll": lib}, {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", lib)}) self.assertEqual(r.returncode, 0, r.stdout + r.stderr) - self.assertTrue(os.path.isfile(os.path.join(out, "payload_table.h"))) + table = open(os.path.join(out, "payload_table.h"), encoding="utf-8").read() + self.assertIn("wronggpu_runtime.dll", table) + self.assertNotIn("build.json", table, "the manifest is read for the gate and is not shipped") - def test_a_developer_runtime_refuses_the_payload(self): - r, out = self._pack({"wronggpu_runtime.dll": b"MZ" + MARK1}) + def test_no_manifest_refuses_the_payload(self): + r, out = self._pack({"wronggpu_runtime.dll": self._release()}) self.assertNotEqual(r.returncode, 0) - self.assertIn("dev-diagnostics=1", r.stderr + r.stdout) + self.assertIn("no build manifest", r.stderr + r.stdout) self.assertFalse(os.path.isfile(os.path.join(out, "payload_table.h")), "no payload table is written for a refused payload") - def test_a_runtime_without_the_marker_refuses_the_payload(self): # fails closed: a build older than R1 - r, _ = self._pack({"wronggpu_runtime.dll": b"MZ" + b"x" * 64}) + def test_a_developer_build_is_refused(self): + lib = b"MZ" + MARK1 + r, _ = self._pack({"wronggpu_runtime.dll": lib}, {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", lib, dev=True)}) self.assertNotEqual(r.returncode, 0) - self.assertIn("no 'wg-build dev-diagnostics=' marker", r.stderr + r.stdout) + self.assertIn("dev-diagnostics=1", r.stderr + r.stdout) - def test_every_runtime_library_is_checked_wherever_it_is(self): - r, _ = self._pack({"wronggpu_runtime.dll": MARK0, "sub/wronggpu_runtime_extra.dll": MARK1}) + def test_a_diagnostics_build_with_a_forged_marker_is_refused(self): + # the marker says =0, but the library carries the diagnostics' code text (a developer build whose marker was patched) + forged = self._release(DEV_TEXT) + r, _ = self._pack({"wronggpu_runtime.dll": forged}, {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", forged)}) + self.assertNotEqual(r.returncode, 0) + self.assertIn("forged marker", r.stderr + r.stdout) + # the honest manifest of that developer build says dev_diagnostics true: refused even if the text were absent + lib = self._release() + r, _ = self._pack({"wronggpu_runtime.dll": lib}, {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", lib, dev=True)}) + self.assertNotEqual(r.returncode, 0) + self.assertIn("dev_diagnostics is not false", r.stderr + r.stdout) + + def test_a_stripped_or_changed_library_is_refused(self): + lib = self._release() + stripped = b"MZ" + b"x" * 64 # the marker removed + r, _ = self._pack({"wronggpu_runtime.dll": stripped}, {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", stripped)}) + self.assertNotEqual(r.returncode, 0) + self.assertIn("no 'wg-build dev-diagnostics=' marker", r.stderr + r.stdout) + changed = lib + b" signed after the build" # a good library changed after its manifest was written + r, _ = self._pack({"wronggpu_runtime.dll": changed}, {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", lib)}) + self.assertNotEqual(r.returncode, 0) + self.assertIn("does not match its build manifest", r.stderr + r.stdout) + other = b"MZ another build " + MARK0 # the manifest of another library + r, _ = self._pack({"wronggpu_runtime.dll": lib}, {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", other)}) + self.assertNotEqual(r.returncode, 0) + r, _ = self._pack({"wronggpu_runtime.dll": lib}, {"wronggpu_runtime.dll": b"not json"}) + self.assertNotEqual(r.returncode, 0) + self.assertIn("not readable JSON", r.stderr + r.stdout) + r, _ = self._pack({"wronggpu_runtime.dll": lib}, {"wronggpu_runtime.dll": manifest_for("another.dll", lib)}) + self.assertNotEqual(r.returncode, 0) + self.assertIn("another file", r.stderr + r.stdout) + + def test_every_runtime_library_and_every_file_is_checked(self): + good = self._release() + bad = b"MZ" + MARK1 + r, _ = self._pack({"wronggpu_runtime.dll": good, "sub/wronggpu_runtime_extra.dll": bad}, + {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", good), + "sub/wronggpu_runtime_extra.dll": manifest_for("wronggpu_runtime_extra.dll", bad)}) self.assertNotEqual(r.returncode, 0, "a second library that is a developer build refuses the payload") - r, _ = self._pack({"wronggpu_runtime.dll": MARK0, "sub/other.dll": b"carries a developer runtime " + MARK1}) + mf = {"wronggpu_runtime.dll": manifest_for("wronggpu_runtime.dll", good)} + r, _ = self._pack({"wronggpu_runtime.dll": good, "sub/other.dll": b"carries a developer runtime " + MARK1}, mf) self.assertNotEqual(r.returncode, 0, "any other embedded file that says dev-diagnostics=1 refuses it too") - r, _ = self._pack({"wronggpu_runtime.dll": MARK0, "sub/other.dll": b"plain"}) + r, _ = self._pack({"wronggpu_runtime.dll": good, "sub/other.dll": b"has " + DEV_TEXT}, mf) + self.assertNotEqual(r.returncode, 0, "or carries the diagnostics' code text") + r, _ = self._pack({"wronggpu_runtime.dll": good, "sub/other.dll": b"plain"}, mf) self.assertEqual(r.returncode, 0, r.stdout + r.stderr) def test_the_final_package_check(self): @@ -140,6 +222,9 @@ def test_the_final_package_check(self): z.writestr("WrongGPU/readme.txt", b"text") with zipfile.ZipFile(bad_zip, "w") as z: z.writestr("WrongGPU/wronggpu_runtime.dll", b"MZ" + MARK1) + forged_zip = os.path.join(d, "forged.zip") + with zipfile.ZipFile(forged_zip, "w") as z: + z.writestr("WrongGPU/wronggpu_runtime.dll", b"MZ" + DEV_TEXT + MARK0) empty_zip = os.path.join(d, "empty.zip") with zipfile.ZipFile(empty_zip, "w") as z: z.writestr("readme.txt", b"no runtime in here") @@ -154,6 +239,7 @@ def run(path): self.assertEqual(run(good_zip), 0) self.assertEqual(run(bad_zip), 1, "a developer runtime inside the package zip fails") + self.assertEqual(run(forged_zip), 1, "a forged marker (developer code text present) fails") self.assertEqual(run(empty_zip), 1, "a package with no runtime found must not pass") self.assertEqual(run(exe_good), 0, "the launcher embeds the payload's runtime as it is: its marker is found") self.assertEqual(run(exe_bad), 1) diff --git a/clean/tests/test_executor_select.py b/clean/tests/test_executor_select.py index 73100002..a8ed2194 100644 --- a/clean/tests/test_executor_select.py +++ b/clean/tests/test_executor_select.py @@ -141,7 +141,10 @@ def test_release_ignores_hip_and_capture_and_never_makes_a_substitute_image(self # the selector returns "hip" only for a developer build; a release build ignores executor=hip and capture_dir self.assertIn("kDevDiagnostics", sel) self.assertIn("ignored: diagnostic key, release build", sel) - self.assertIn("bool dev = kDevDiagnostics", sel) + self.assertIn("bool devRequested = kDevDiagnostics", sel) + self.assertIn("const bool dev = kDevDiagnostics && devRequested;", sel) + # the developer texts exist only behind WG_DEV_DIAGNOSTICS (the package gate scans a release library for them) + self.assertEqual(sel.count("#ifdef WG_DEV_DIAGNOSTICS"), 3) # the backend logs the ignored keys and drops capture_dir in a release build, before anything is made drop = self.at("if (!kDevDiagnostics) o.capture_dir.clear();") self.assertIn("for (const std::string& line : ch.ignored) say(WG_LOG_WARN, line);", self.b[drop - 200:drop]) diff --git a/tools/ci/check_release_runtime.py b/tools/ci/check_release_runtime.py new file mode 100644 index 00000000..cc9b45d8 --- /dev/null +++ b/tools/ci/check_release_runtime.py @@ -0,0 +1,121 @@ +# SPDX-License-Identifier: MIT +"""CI (R1): the package gate, run on the REAL runtime library built from this tree, not on made-up files. + + python tools/ci/check_release_runtime.py --out --cxx + +Builds the runtime library twice with clean/runner/build.py (--runtime-only --no-embed: the C++ runtime without the GPU code +objects, which CI cannot build): in the RELEASE configuration (what the package gets: Model L and Model K on) and as a +developer build (--dev-diagnostics). Then checks, with the functions the packager uses (clean/tests/check_no_dev_diagnostics.py): + + * the release library says dev-diagnostics=0, carries none of the developer-diagnostic code texts, has a build manifest + with dev_diagnostics false and a matching SHA-256, and the real payload packager (clean/installer/tools/make_payload.py) + accepts it; + * the developer library carries those texts (so the scan means something), says dev-diagnostics=1, has a manifest saying + dev_diagnostics true, and the packager refuses it; with its marker forged to =0 it is still refused (the code texts and + its manifest); a release library stripped of its marker, or changed after its build, is refused. +""" +import argparse +import hashlib +import os +import subprocess +import sys +import tempfile + +ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +sys.path.insert(0, os.path.join(ROOT, "clean", "tests")) +import check_no_dev_diagnostics as chk # noqa: E402 + +BUILD = os.path.join(ROOT, "clean", "runner", "build.py") +PACKAGER = os.path.join(ROOT, "clean", "installer", "tools", "make_payload.py") +FAILURES = [] + + +def check(cond, what): + print(("ok " if cond else "FAIL ") + what, flush=True) + if not cond: + FAILURES.append(what) + + +def build(out, cxx, dev): + cmd = [sys.executable, BUILD, "--out", out, "--runtime-only", "--no-embed", "--model-l", "--runtime-cxx", cxx] + if dev: + cmd.append("--dev-diagnostics") + print("+ " + " ".join(cmd), flush=True) + r = subprocess.run(cmd, cwd=ROOT) + if r.returncode: + sys.exit("the runtime build failed (%d)" % r.returncode) + dll = os.path.join(out, "wronggpu_runtime.dll" if sys.platform == "win32" else "libwg_runtime.so") + with open(dll, "rb") as f: + data = f.read() + with open(os.path.splitext(dll)[0] + ".build.json", "rb") as f: + manifest = f.read() + return dll, data, manifest + + +def pack(dll_name, data, manifest): + """Runs the real packager on a payload folder holding the library (and its manifest) next to a front end.""" + d = tempfile.mkdtemp(prefix="wg_gate_") + payload = os.path.join(d, "payload") + os.makedirs(payload) + with open(os.path.join(payload, "amd_fidelityfx_dx12.dll"), "wb") as f: + f.write(b"front end") + with open(os.path.join(payload, dll_name), "wb") as f: + f.write(data) + if manifest is not None: + with open(os.path.join(payload, os.path.splitext(dll_name)[0] + ".build.json"), "wb") as f: + f.write(manifest) + with open(os.path.join(d, "map.json"), "wb") as f: + f.write(b"{}") + r = subprocess.run([sys.executable, PACKAGER, "--payload", payload, "--map", os.path.join(d, "map.json"), "--version", "0.0.1", + "--out", os.path.join(d, "out")], capture_output=True, text=True) + return r.returncode, r.stdout + r.stderr + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--out", required=True) + ap.add_argument("--cxx", required=True, help="the host C++ compiler (clang++)") + a = ap.parse_args() + name = "wronggpu_runtime.dll" + + rel_dll, rel, rel_m = build(os.path.join(a.out, "release"), a.cxx, False) + dev_dll, dev, dev_m = build(os.path.join(a.out, "dev"), a.cxx, True) + + ok, text = chk.check_runtime_with_manifest(name, rel, rel_m) + check(ok, "release library: " + text) + check(not chk.dev_only_strings_in(rel), "release library carries none of the developer-diagnostic code texts") + check(chk.main([os.path.dirname(rel_dll)]) == 0, "check_no_dev_diagnostics on the release build folder") + code, out = pack(name, rel, rel_m) + check(code == 0, "the payload packager accepts the release library (%s)" % ("ok" if code == 0 else out[-300:])) + + check(bool(chk.dev_only_strings_in(dev)), "the developer library carries the developer-diagnostic code texts (the scan means something)") + ok, text = chk.check_runtime_with_manifest(name, dev, dev_m) + check(not ok and "dev-diagnostics=1" in text, "developer library refused: " + text) + code, out = pack(name, dev, dev_m) + check(code != 0 and "dev-diagnostics=1" in out, "the payload packager refuses the developer library") + forged = dev.replace(b"wg-build dev-diagnostics=1", b"wg-build dev-diagnostics=0") + check(forged != dev, "the marker of the developer library was forged to =0") + ok, text = chk.check_runtime_with_manifest(name, forged, dev_m) + check(not ok, "forged marker: refused (" + text + ")") + code, out = pack(name, forged, dev_m) + check(code != 0, "the payload packager refuses the forged developer library") + code, out = pack(name, forged, None) + check(code != 0 and "forged marker" in out, "forged marker, no manifest: refused by the code-text scan") + stripped = rel.replace(b"wg-build dev-diagnostics=0", b"wg-build dev-diagnostics=?") + code, out = pack(name, stripped, rel_m) + check(code != 0 and "marker" in out, "a stripped release library is refused") + code, out = pack(name, rel + b"\0", rel_m) + check(code != 0 and "does not match its build manifest" in out, "a release library changed after its build is refused") + code, out = pack(name, rel, None) + check(code != 0 and "no build manifest" in out, "a release library without its manifest is refused") + + print("release sha256 %s" % hashlib.sha256(rel).hexdigest()[:16]) + if FAILURES: + print("FAILED: %d check(s)" % len(FAILURES)) + return 1 + print("package gate: all checks passed") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) From 3ba977bc31d5554d4cdf0889172117b43384bf15 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 13:02:06 -0500 Subject: [PATCH 14/20] CI: the package gate runs on the real runtime library; selector pin Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- .github/workflows/ci.yml | 11 +++++++++++ clean/tests/test_executor_select.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a06f1e80..0623badf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,6 +163,17 @@ jobs: run: | $PSNativeCommandUseErrorActionPreference = $true python -m unittest clean.tests.test_dev_diagnostics_off -v + - name: Package gate on the real runtime library (R1) + # The runtime library is built from this tree (clean/runner/build.py --runtime-only --no-embed: the C++ runtime without + # the GPU code objects) in the release configuration the package gets, and as a developer build; the gate's functions + # then check THOSE libraries: the release one passes the real packager (marker, no developer-diagnostic code text, + # build manifest with its SHA-256); the developer one, the same with a forged marker, a stripped and a changed + # library are refused. + run: | + $PSNativeCommandUseErrorActionPreference = $true + $clang = (Get-Command clang++ -ErrorAction SilentlyContinue).Source + if (-not $clang) { $clang = "C:\Program Files\LLVM\bin\clang++.exe" } + python tools/ci/check_release_runtime.py --out out/runtime-gate --cxx $clang rr-plugin: name: "CPU: Ray Reconstruction plugin" diff --git a/clean/tests/test_executor_select.py b/clean/tests/test_executor_select.py index a8ed2194..ac76c3c2 100644 --- a/clean/tests/test_executor_select.py +++ b/clean/tests/test_executor_select.py @@ -144,7 +144,7 @@ def test_release_ignores_hip_and_capture_and_never_makes_a_substitute_image(self self.assertIn("bool devRequested = kDevDiagnostics", sel) self.assertIn("const bool dev = kDevDiagnostics && devRequested;", sel) # the developer texts exist only behind WG_DEV_DIAGNOSTICS (the package gate scans a release library for them) - self.assertEqual(sel.count("#ifdef WG_DEV_DIAGNOSTICS"), 3) + self.assertEqual(sel.count("#ifdef WG_DEV_DIAGNOSTICS"), 4) # the constant, the capture text, the two routes # the backend logs the ignored keys and drops capture_dir in a release build, before anything is made drop = self.at("if (!kDevDiagnostics) o.capture_dir.clear();") self.assertIn("for (const std::string& line : ch.ignored) say(WG_LOG_WARN, line);", self.b[drop - 200:drop]) From 9076349745a63d5cf9a9939ab34e9e99899f4202 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:14:24 -0500 Subject: [PATCH 15/20] Tests: the hard rule (no release choice is HIP); build.py writes the manifest only when the library exists Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/runner/build.py | 3 +- .../interop/tests/test_executor_select.cpp | 36 +++++++++++++++++++ clean/tests/test_executor_select.py | 25 +++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/clean/runner/build.py b/clean/runner/build.py index 3b0dc137..b4d9d827 100644 --- a/clean/runner/build.py +++ b/clean/runner/build.py @@ -358,7 +358,8 @@ def build_runtime(cxx, out_dir, embed=True): embedded = write_embedded(out_dir) if embed else None cmd = runtime_command(cxx, os.path.join(out_dir, runtime_library_name()), embedded) run(cmd) - write_build_manifest(out_dir, cmd, embedded is not None) + if os.path.isfile(os.path.join(out_dir, runtime_library_name())): # (a build that failed raised in run) + write_build_manifest(out_dir, cmd, embedded is not None) def write_build_manifest(out_dir, cmd, embedded): diff --git a/clean/runtime/interop/tests/test_executor_select.cpp b/clean/runtime/interop/tests/test_executor_select.cpp index 7d02a897..a9e199a5 100644 --- a/clean/runtime/interop/tests/test_executor_select.cpp +++ b/clean/runtime/interop/tests/test_executor_select.cpp @@ -372,6 +372,42 @@ int main() { choose(r).executor == "dx12" && choose(r).ignored.empty() && choose(r).why.empty()); } + // ---- HARD RULE (R1, oversight): a refused or unwanted D3D12 route never falls back silently to HIP or a reference path -------- + // Whatever a release configuration is asked for (every executor word, the capture, the sparkle guard, every model, a board + // that is RDNA 4, one that is not and one that cannot be identified), the choice is the D3D12 executor, "fsr" (no context: + // the front end's upscaler takes the game, loudly) or the explicit offline test executor: never "hip". The refusal paths + // after the choice are the create refusal (no context, the front end's upscaler) and the refused frame (WG_ERROR_UNSUPPORTED): + // the source pins in test_executor_select.py check that neither of them builds an executor of its own. + { + const char* const words[] = {"", "auto", "dx12", "d3d12", "hip", "d3d12-test", "vulkan", "reference", "cpu", "bilinear"}; + const std::vector boards = {board("AMD Radeon RX 9070 XT", 0x1002, 0x7550), + board("AMD Radeon RX 7900 XTX", 0x1002, 0x744C), ExecutorRequest()}; + int checked = 0, hip = 0, other = 0; + for (bool dev : {false, true}) + for (const std::string w : words) + for (const ExecutorRequest& b : boards) + for (bool model_k : {false, true}) + for (bool capture : {false, true}) + for (bool sparkle : {false, true}) { + ExecutorRequest r = b; + r.executor = w; + r.model_k = model_k; + r.capture = capture; + r.sparkle_guard = sparkle; + const ExecutorChoice ch = choose_executor(r, dev); + ++checked; + const bool devOn = dev && wgi::kDevDiagnostics; // only a developer build can be asked for HIP + if (ch.executor == "hip" && !devOn) ++hip; + if (!(ch.executor == "dx12" || ch.executor == "fsr" || ch.executor == "d3d12-test" || ch.executor.empty() || + (ch.executor == "hip" && devOn))) + ++other; + } + expect(std::string("no release choice is HIP, whatever is asked (") + std::to_string(checked) + " requests)", hip == 0); + expect("every choice is the D3D12 executor, no context ('fsr'), the offline test executor, an unknown word (create fails) " + "or, in a developer build only, HIP", + other == 0); + } + // ---- the D3D12 executor refuses the context at create: every model, the front end's upscaler, never HIP ------------- { const std::string e = "D3D12 device: native D3D12 borrowed driver-channel probe mismatch at float 7"; diff --git a/clean/tests/test_executor_select.py b/clean/tests/test_executor_select.py index ac76c3c2..a9baabf2 100644 --- a/clean/tests/test_executor_select.py +++ b/clean/tests/test_executor_select.py @@ -156,6 +156,31 @@ def test_release_ignores_hip_and_capture_and_never_makes_a_substitute_image(self refused = self.at("if (refused) {") self.assertIn("return WG_ERROR_UNSUPPORTED;", self.b[refused:refused + 400]) + def test_hard_rule_the_hip_route_exists_only_in_a_developer_build(self): + # R1 hard rule: a refused or unwanted D3D12 route never falls back to HIP or a reference path in a release build. The + # selector's only way to the HIP executor ('c.executor = "hip"') is inside a WG_DEV_DIAGNOSTICS block (a release + # library does not even contain it; the package gate scans for its texts), and the backend builds the HIP executor in + # one place, behind that choice. + sel = read("clean", "runtime", "interop", "executor_select.h").split("\n") + depth, at = 0, [] + for line in sel: + t = line.strip() + if t.startswith("#ifdef WG_DEV_DIAGNOSTICS"): + depth += 1 + elif t.startswith("#if") and depth: + depth += 1 + elif t.startswith("#endif") and depth: + depth -= 1 + if 'c.executor = "hip"' in line or 'if (e == "hip") { // developer build only' in line: + at.append(depth) + self.assertEqual(len(at), 2) # the executor=hip route (its test) and the capture route + self.assertTrue(all(d >= 1 for d in at), "a route to HIP outside WG_DEV_DIAGNOSTICS") + self.assertEqual(self.b.count("make_hip_executor("), 1) + # the create refusal and the refused frame build no executor of their own and fall back to nothing but the front end + refusal = self.at("dx12_refused_line(dx12_default_, err)") + self.assertNotIn("make_hip_executor", self.b[refusal - 300:refusal + 300]) + self.assertNotIn("bilinear", read("clean", "runtime", "interop", "executor_select.h").lower().replace("no bilinear", "")) + def test_sparkle_guard_is_off_and_hip_only_filters_fall_back_for_every_model(self): # R1-a / H4: the choice turns the guard off before anything is made, whatever the model off = self.at("if (ch.sparkle_off) o.sparkle_guard = 0.0f;") From 9c91f7a0c00b1d936f978b897ba9b47d041b665b Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:44:54 -0500 Subject: [PATCH 16/20] The create worker's device hold: owner first, retain after (no leak if an allocation throws) Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/src/async_create.h | 9 ++++++++ clean/fsr/src/frontend.cpp | 4 +--- clean/fsr/src/fsr30_hook.cpp | 9 +++----- clean/fsr/tests/test_frontend.cpp | 38 +++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/clean/fsr/src/async_create.h b/clean/fsr/src/async_create.h index 8869a5ec..f2f1f528 100644 --- a/clean/fsr/src/async_create.h +++ b/clean/fsr/src/async_create.h @@ -48,6 +48,15 @@ class ScopedRelease { std::function release_; }; +// Takes the create worker's hold on the game's device: the owner is built FIRST (its callable is the only allocation), the +// reference is retained AFTER it, and the owner is returned by a noexcept move: nothing that can throw lies between the +// retain and the owner, so a throwing allocation never leaks the reference (it throws before anything was retained). +inline ScopedRelease AcquireHold(void* device, const std::function& retain, const std::function& release) { + ScopedRelease hold([release, device] { release(device); }); + retain(device); + return hold; +} + class PendingCreate { public: // Starts backend->create(info) on a new thread. `info` and what it points to (options, log user) must stay valid diff --git a/clean/fsr/src/frontend.cpp b/clean/fsr/src/frontend.cpp index 5591b32b..0d83165d 100644 --- a/clean/fsr/src/frontend.cpp +++ b/clean/fsr/src/frontend.cpp @@ -984,9 +984,7 @@ void FrontEnd::CheckPending(UpscaleContext& u, uint64_t call) { // depend on this object. ScopedRelease FrontEnd::HoldDevice(void* device) { if (!device || !platform_.retainDevice || !platform_.releaseDevice) return {}; - platform_.retainDevice(device); - std::function release = platform_.releaseDevice; - return ScopedRelease([release, device] { release(device); }); + return AcquireHold(device, platform_.retainDevice, platform_.releaseDevice); // (owner first, retain after: no leak if an allocation throws) } bool FrontEnd::ActivateSplit(UpscaleContext& u, const WgUpscalerBackend* backend, const std::string& tag) { diff --git a/clean/fsr/src/fsr30_hook.cpp b/clean/fsr/src/fsr30_hook.cpp index 25dbec56..98bc0742 100644 --- a/clean/fsr/src/fsr30_hook.cpp +++ b/clean/fsr/src/fsr30_hook.cpp @@ -222,12 +222,9 @@ bool Hook::RunStandIn(Context& c, const ffxDispatchDescUpscale& dispatch, const // On a worker thread: the game's thread waits create_wait_ms at most (async_create.h); AMD's FSR upscales the // frames until the create has finished. c.creating = true; - ScopedRelease hold; // the create worker's own reference on the game's device (async_create.h; RAII) - if (device && platform_.retainDevice && platform_.releaseDevice) { - platform_.retainDevice(device); - std::function release = platform_.releaseDevice; - hold = ScopedRelease([release, device] { release(device); }); - } + ScopedRelease hold; // the create worker's own reference on the game's device (async_create.h; RAII, owner first) + if (device && platform_.retainDevice && platform_.releaseDevice) + hold = AcquireHold(device, platform_.retainDevice, platform_.releaseDevice); auto pending = PendingCreate::Start(backend, c.createInfo, std::move(hold)); if (!pending->Wait(config_.createWaitMs)) { c.pending = pending; diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index e63837df..eb3fe007 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -158,6 +158,16 @@ static std::function g_timerFn; static int g_timersStarted = 0; static std::atomic g_createGate{true}; // FakeCreate (on the front end's create thread) waits while false static std::atomic g_createCalls{0}; // every FakeCreate call (made an upscaler or not) +// Allocation failure injection (TestDeviceHoldAllocationFailure): while set, every `new` in the process throws std::bad_alloc. +static std::atomic g_throwOnNew{false}; +void* operator new(std::size_t n) { + if (g_throwOnNew.load()) throw std::bad_alloc(); + if (void* p = std::malloc(n ? n : 1)) return p; + throw std::bad_alloc(); +} +void operator delete(void* p) noexcept { std::free(p); } +void operator delete(void* p, std::size_t) noexcept { std::free(p); } + static bool g_failCreateUnsupported = false; // FakeCreate answers WG_ERROR_UNSUPPORTED (a hard incompatibility, R1) static std::atomic g_holdFromCall{0}; // FakeCreate waits for the gate from this call on (1-based); 0: every call static bool g_deviceHoldOn = false; // the platform gives the create worker a hold on the device (retain / release) @@ -1430,6 +1440,33 @@ static void TestSplitRetryPendingStoresNoFailure() { CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); } +// R1: the hold is taken owner first, retain after: an allocation that throws while the hold is made leaks nothing (it throws +// before anything was retained); the normal path retains once and gives it back once. +static void TestDeviceHoldAllocationFailure() { + static int retains = 0, releases = 0; + retains = releases = 0; + std::function retain = [](void*) { ++retains; }; + std::function release = [](void*) { ++releases; }; + unsigned char big[256] = {}; // callables too big for a small buffer: copying them allocates + std::function bigRelease = [big](void*) { (void)big[0]; ++releases; }; + { + ScopedRelease hold = AcquireHold(reinterpret_cast(0x1), retain, release); + CHECK(hold && retains == 1 && releases == 0); + } + CHECK(retains == 1 && releases == 1); // given back once, by the owner going away + retains = releases = 0; + bool threw = false; + g_throwOnNew = true; // every allocation fails from here: building the owner throws before the retain + try { + ScopedRelease hold = AcquireHold(reinterpret_cast(0x1), retain, bigRelease); + } catch (const std::bad_alloc&) { + threw = true; + } + g_throwOnNew = false; + CHECK(threw); // the allocation did fail (the injection works on this code) + CHECK(retains == 0 && releases == 0); // and no reference was taken, so none is leaked +} + // R1: the create worker's device reference is owned (RAII): it is given back when the worker could not be started at all // (the create then counts as failed, nothing throws into the game's thread) and exactly once whatever happens to the owner. static void FailingLauncher(std::function) { throw std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again)); } @@ -3863,6 +3900,7 @@ int main() { TestRememberedHardIncompatibility(); TestSplitRetryPendingStoresNoFailure(); TestWorkerLaunchFailureGivesTheDeviceBack(); + TestDeviceHoldAllocationFailure(); TestInterfaceVersions(); TestAmdMode(); TestNonLinearColour(); From bce4a4ed2862f8e78f659ee1c7fc8c272fae68d9 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:09:58 -0500 Subject: [PATCH 17/20] Test: the allocation failure injection is thread-local Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/tests/test_frontend.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index eb3fe007..6af83add 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -158,10 +158,11 @@ static std::function g_timerFn; static int g_timersStarted = 0; static std::atomic g_createGate{true}; // FakeCreate (on the front end's create thread) waits while false static std::atomic g_createCalls{0}; // every FakeCreate call (made an upscaler or not) -// Allocation failure injection (TestDeviceHoldAllocationFailure): while set, every `new` in the process throws std::bad_alloc. -static std::atomic g_throwOnNew{false}; +// Allocation failure injection (TestDeviceHoldAllocationFailure): while set, every `new` on THIS thread throws std::bad_alloc +// (thread-local: a worker thread still finishing an earlier test must not be hit by it). +static thread_local bool g_throwOnNew = false; void* operator new(std::size_t n) { - if (g_throwOnNew.load()) throw std::bad_alloc(); + if (g_throwOnNew) throw std::bad_alloc(); if (void* p = std::malloc(n ? n : 1)) return p; throw std::bad_alloc(); } From 23dda8bd9fb4806cad03486b89a94ec289070e76 Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:37:24 -0500 Subject: [PATCH 18/20] Test: the allocation-order check uses a callable whose copy throws; unbuffered output Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/tests/test_frontend.cpp | 35 +++++++++++++------------------ 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 6af83add..7e9d23b9 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -158,17 +158,6 @@ static std::function g_timerFn; static int g_timersStarted = 0; static std::atomic g_createGate{true}; // FakeCreate (on the front end's create thread) waits while false static std::atomic g_createCalls{0}; // every FakeCreate call (made an upscaler or not) -// Allocation failure injection (TestDeviceHoldAllocationFailure): while set, every `new` on THIS thread throws std::bad_alloc -// (thread-local: a worker thread still finishing an earlier test must not be hit by it). -static thread_local bool g_throwOnNew = false; -void* operator new(std::size_t n) { - if (g_throwOnNew) throw std::bad_alloc(); - if (void* p = std::malloc(n ? n : 1)) return p; - throw std::bad_alloc(); -} -void operator delete(void* p) noexcept { std::free(p); } -void operator delete(void* p, std::size_t) noexcept { std::free(p); } - static bool g_failCreateUnsupported = false; // FakeCreate answers WG_ERROR_UNSUPPORTED (a hard incompatibility, R1) static std::atomic g_holdFromCall{0}; // FakeCreate waits for the gate from this call on (1-based); 0: every call static bool g_deviceHoldOn = false; // the platform gives the create worker a hold on the device (retain / release) @@ -1441,15 +1430,21 @@ static void TestSplitRetryPendingStoresNoFailure() { CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); } -// R1: the hold is taken owner first, retain after: an allocation that throws while the hold is made leaks nothing (it throws -// before anything was retained); the normal path retains once and gives it back once. +// R1: the hold is taken owner first, retain after: whatever fails while the owner is built (an allocation: a callable whose copy +// throws stands for it) fails before anything was retained, so nothing is leaked; the normal path retains once and gives it +// back once. +struct ThrowsOnCopy { + ThrowsOnCopy() = default; + ThrowsOnCopy(ThrowsOnCopy&&) noexcept = default; + ThrowsOnCopy(const ThrowsOnCopy&) { throw std::bad_alloc(); } + void operator()(void*) const {} +}; + static void TestDeviceHoldAllocationFailure() { static int retains = 0, releases = 0; retains = releases = 0; std::function retain = [](void*) { ++retains; }; std::function release = [](void*) { ++releases; }; - unsigned char big[256] = {}; // callables too big for a small buffer: copying them allocates - std::function bigRelease = [big](void*) { (void)big[0]; ++releases; }; { ScopedRelease hold = AcquireHold(reinterpret_cast(0x1), retain, release); CHECK(hold && retains == 1 && releases == 0); @@ -1457,15 +1452,14 @@ static void TestDeviceHoldAllocationFailure() { CHECK(retains == 1 && releases == 1); // given back once, by the owner going away retains = releases = 0; bool threw = false; - g_throwOnNew = true; // every allocation fails from here: building the owner throws before the retain + std::function failing = ThrowsOnCopy(); // building the owner copies it: that throws, as a failed allocation would try { - ScopedRelease hold = AcquireHold(reinterpret_cast(0x1), retain, bigRelease); + ScopedRelease hold = AcquireHold(reinterpret_cast(0x1), retain, failing); } catch (const std::bad_alloc&) { threw = true; } - g_throwOnNew = false; - CHECK(threw); // the allocation did fail (the injection works on this code) - CHECK(retains == 0 && releases == 0); // and no reference was taken, so none is leaked + CHECK(threw); // the failure reached the caller + CHECK(retains == 0 && releases == 0); // and no reference was taken, so none is leaked } // R1: the create worker's device reference is owned (RAII): it is given back when the worker could not be started at all @@ -3817,6 +3811,7 @@ static void TestStateSettings() { } int main() { + std::setvbuf(stdout, nullptr, _IONBF, 0); // unbuffered: if a check aborts the process, the output so far is not lost TestCustomSlotFailedCreate(); TestCustomSlotFailureKeyHasSize(); TestCustomSlotInputRefused(); From f75acd681c9d93e5499596f04abcc250a7d3e98c Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:11:11 -0500 Subject: [PATCH 19/20] Test: the hold's order is observed without an exception (the CI configuration aborted on one) Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/tests/test_frontend.cpp | 40 ++++++++++++++++++------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 7e9d23b9..006a2e11 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -1430,13 +1430,19 @@ static void TestSplitRetryPendingStoresNoFailure() { CHECK(fe->DestroyContext(&ctx, kMemCb) == FFX_API_RETURN_OK); } -// R1: the hold is taken owner first, retain after: whatever fails while the owner is built (an allocation: a callable whose copy -// throws stands for it) fails before anything was retained, so nothing is leaked; the normal path retains once and gives it -// back once. -struct ThrowsOnCopy { - ThrowsOnCopy() = default; - ThrowsOnCopy(ThrowsOnCopy&&) noexcept = default; - ThrowsOnCopy(const ThrowsOnCopy&) { throw std::bad_alloc(); } +// R1: the hold is taken owner first, retain after: everything that can throw (the allocations that build the owner) happens +// before the reference is retained, so a failure there leaks nothing; and the normal path retains once and gives it back once. +// The order is observed without throwing: a release callable that records, each time it is copied (building the owner copies +// it), whether the reference had already been retained at that moment. +struct RecordsRetainsWhenCopied { + int* retains; + int* copies; + int* copiesAfterRetain; + RecordsRetainsWhenCopied(int* r, int* c, int* a) : retains(r), copies(c), copiesAfterRetain(a) {} + RecordsRetainsWhenCopied(const RecordsRetainsWhenCopied& o) : retains(o.retains), copies(o.copies), copiesAfterRetain(o.copiesAfterRetain) { + ++*copies; + if (*retains > 0) ++*copiesAfterRetain; + } void operator()(void*) const {} }; @@ -1450,16 +1456,16 @@ static void TestDeviceHoldAllocationFailure() { CHECK(hold && retains == 1 && releases == 0); } CHECK(retains == 1 && releases == 1); // given back once, by the owner going away - retains = releases = 0; - bool threw = false; - std::function failing = ThrowsOnCopy(); // building the owner copies it: that throws, as a failed allocation would - try { - ScopedRelease hold = AcquireHold(reinterpret_cast(0x1), retain, failing); - } catch (const std::bad_alloc&) { - threw = true; - } - CHECK(threw); // the failure reached the caller - CHECK(retains == 0 && releases == 0); // and no reference was taken, so none is leaked + retains = 0; + int copies = 0, copiesAfterRetain = 0; + std::function observed = RecordsRetainsWhenCopied(&retains, &copies, &copiesAfterRetain); + copies = copiesAfterRetain = 0; // (building `observed` itself is not part of AcquireHold) + { + ScopedRelease hold = AcquireHold(reinterpret_cast(0x1), retain, observed); + CHECK(hold && retains == 1); + } + CHECK(copies >= 1); // building the owner did copy the callable (the observation is real) + CHECK(copiesAfterRetain == 0); // and every copy happened before the retain: the owner is built first } // R1: the create worker's device reference is owned (RAII): it is given back when the worker could not be started at all From 00aa1e12351f0956c9bd1d449df0bcc1503e995b Mon Sep 17 00:00:00 2001 From: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:18:05 -0500 Subject: [PATCH 20/20] The hold's owner callable is a named class: a lambda capturing a throwing copy terminates under /Zc:lambda MSVC's /Zc:lambda (on with /permissive-, as in the CI builds) terminates the process when the copy of a lambda's capture throws, instead of unwinding. AcquireHold's lambda captured a std::function by copy, so a failed allocation while the owner is built (std::bad_alloc from copying a large callable) would have been a std::terminate in a release build. The callable is now a class whose constructor does the copy (that unwinds normally), and the test that drives a throwing copy is back: it passes in the CI configuration. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com> --- clean/fsr/src/async_create.h | 13 ++++++++++++- clean/fsr/tests/test_frontend.cpp | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/clean/fsr/src/async_create.h b/clean/fsr/src/async_create.h index f2f1f528..c1590b59 100644 --- a/clean/fsr/src/async_create.h +++ b/clean/fsr/src/async_create.h @@ -51,8 +51,19 @@ class ScopedRelease { // Takes the create worker's hold on the game's device: the owner is built FIRST (its callable is the only allocation), the // reference is retained AFTER it, and the owner is returned by a noexcept move: nothing that can throw lies between the // retain and the owner, so a throwing allocation never leaks the reference (it throws before anything was retained). +// The owner's callable is a named class, not a lambda that captures `release` by copy: with MSVC's /Zc:lambda (on whenever +// /permissive- is, as in the CI builds) a lambda whose capture copy throws terminates the process instead of unwinding (a +// defect in the closure's unwind state; reproduced with a callable whose copy throws, and std::bad_alloc from copying a large +// callable is the same case), while the same copy inside a class constructor unwinds normally. +struct DeviceRelease { + std::function release; + void* device; + DeviceRelease(const std::function& r, void* d) : release(r), device(d) {} + void operator()() const { release(device); } +}; + inline ScopedRelease AcquireHold(void* device, const std::function& retain, const std::function& release) { - ScopedRelease hold([release, device] { release(device); }); + ScopedRelease hold{std::function(DeviceRelease(release, device))}; retain(device); return hold; } diff --git a/clean/fsr/tests/test_frontend.cpp b/clean/fsr/tests/test_frontend.cpp index 006a2e11..64bee896 100644 --- a/clean/fsr/tests/test_frontend.cpp +++ b/clean/fsr/tests/test_frontend.cpp @@ -1434,6 +1434,13 @@ static void TestSplitRetryPendingStoresNoFailure() { // before the reference is retained, so a failure there leaks nothing; and the normal path retains once and gives it back once. // The order is observed without throwing: a release callable that records, each time it is copied (building the owner copies // it), whether the reference had already been retained at that moment. +struct ThrowsOnCopy { // a callable whose copy throws (a failed allocation while the owner is built, as bad_alloc from copying a large one) + ThrowsOnCopy() = default; + ThrowsOnCopy(ThrowsOnCopy&&) noexcept = default; + ThrowsOnCopy(const ThrowsOnCopy&) { throw std::bad_alloc(); } + void operator()(void*) const {} +}; + struct RecordsRetainsWhenCopied { int* retains; int* copies; @@ -1466,6 +1473,18 @@ static void TestDeviceHoldAllocationFailure() { } CHECK(copies >= 1); // building the owner did copy the callable (the observation is real) CHECK(copiesAfterRetain == 0); // and every copy happened before the retain: the owner is built first + // and a throwing copy reaches the caller as an exception (it must not terminate the process: it did when the owner's callable + // was a lambda capturing it, under MSVC's /Zc:lambda, which the CI builds have on), with nothing retained + retains = releases = 0; + std::function failing = ThrowsOnCopy(); + bool threw = false; + try { + ScopedRelease hold = AcquireHold(reinterpret_cast(0x1), retain, failing); + } catch (const std::bad_alloc&) { + threw = true; + } + CHECK(threw); // the failure reached the caller + CHECK(retains == 0 && releases == 0); // and no reference was taken, so none is leaked } // R1: the create worker's device reference is owned (RAII): it is given back when the worker could not be started at all