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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clean/rr_f/runtime/src/rr_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,8 @@ uint32_t set_device_locked(ID3D12Device* given) {
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;
}
const std::string wine = wgrt::wine_fallback_line(id); // Wine: how the adapter was identified (#248)
if (!wine.empty()) log_line(wine);
rt.adapter_name = id.dxgi_known ? id.description : who;
}
D3D12_COMMAND_QUEUE_DESC qd = {};
Expand Down
4 changes: 4 additions & 0 deletions clean/runtime/interop/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,16 @@ class Context {
q.kmt_known = ident.kmt_known;
q.kmt_vendor = ident.kmt_vendor;
q.kmt_device = ident.kmt_device;
q.wine_fallback = ident.wine_fallback;
q.wine_vendor = ident.wine_vendor;
q.wine_device = ident.wine_device;
}
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.adapter_note.empty()) say(WG_LOG_INFO, ch.adapter_note); // Wine: how the adapter was identified (#248)
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);
Expand Down
7 changes: 7 additions & 0 deletions clean/runtime/interop/executor_select.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct ExecutorRequest {
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 wine_fallback = false; // Wine only: the driver's query is not implemented there; the system DXGI's ids (#248)
uint32_t wine_vendor = 0, wine_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)
Expand All @@ -66,6 +68,7 @@ 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::string adapter_note; // the one line when the Wine fallback identified the adapter (rdna4.h, #248); else empty
std::vector<std::string> 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)
};
Expand Down Expand Up @@ -106,6 +109,9 @@ inline wgrt::AdapterIdentity adapter_identity(const ExecutorRequest& r) {
id.kmt_known = r.kmt_known;
id.kmt_vendor = r.kmt_vendor;
id.kmt_device = r.kmt_device;
id.wine_fallback = r.wine_fallback;
id.wine_vendor = r.wine_vendor;
id.wine_device = r.wine_device;
return id;
}

Expand All @@ -117,6 +123,7 @@ inline ExecutorChoice choose_executor(const ExecutorRequest& r, bool devRequeste
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
c.adapter_note = wgrt::wine_fallback_line(adapter_identity(r));
std::string e = r.executor;
bool capture = r.capture;
if (!dev) { // R1: a release build never starts HIP, whatever the game's files say
Expand Down
121 changes: 121 additions & 0 deletions clean/runtime/interop/tests/test_executor_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,127 @@ int main() {
expect("RR: the game's RX 9000 (spoofed name) is accepted", wgrt::rdna4_identity(id));
}

// ---- Wine and Proton (#248): the driver's query is not implemented there; the system DXGI's ids under the same rule ---
{
struct WineFake {
int32_t status = 0; // the driver query's answer
uint32_t kvendor = 0x1002, kdevice = 0x7550; // its ids when it answers 0
bool wine = false; // ntdll exports wine_get_version
bool dxgi_answers = true;
uint32_t dvendor = 0x1002, ddevice = 0x7550; // the system DXGI's ids
int asked_query = 0, asked_wine = 0, asked_dxgi_ids = 0;
wgrt::AdapterSources sources() {
wgrt::AdapterSources s;
s.find_adapter = [](const wgrt::AdapterLuid&, wgrt::AdapterRecord* out) {
out->vendor = 0x1002;
out->description = "AMD Radeon RX 9070 XT";
return true;
};
s.driver_query = [this](const wgrt::AdapterLuid&, uint32_t* v, uint32_t* d) -> int32_t {
++asked_query;
if (status == 0) {
*v = kvendor;
*d = kdevice;
}
return status;
};
s.under_wine = [this]() {
++asked_wine;
return wine;
};
s.dxgi_ids = [this](const wgrt::AdapterLuid&, uint32_t* v, uint32_t* d) {
++asked_dxgi_ids;
if (!dxgi_answers) return false;
*v = dvendor;
*d = ddevice;
return true;
};
return s;
}
};
const wgrt::AdapterLuid luid;
auto choice = [](const wgrt::AdapterIdentity& id) {
ExecutorRequest r = request_for(id);
r.wine_fallback = id.wine_fallback;
r.wine_vendor = id.wine_vendor;
r.wine_device = id.wine_device;
return choose_executor(r);
};

WineFake f;
f.status = wgrt::kStatusNotImplemented;
f.wine = true;
wgrt::AdapterIdentity id = wgrt::lookup_adapter(luid, f.sources());
ExecutorChoice c = choice(id);
expect("Wine: query not implemented + Wine + the system DXGI's 1002:7550: RDNA 4, the D3D12 executor",
!id.kmt_known && id.wine_fallback && wgrt::rdna4_identity(id) && c.executor == "dx12" && c.by_default);
expect("Wine: the one line says the Wine fallback identified the adapter, with the ids",
has(c.adapter_note, "Wine: the driver's adapter id query is not implemented") &&
has(c.adapter_note, "PCI 1002:7550 (Wine: the system DXGI's ids)") &&
c.adapter_note == wgrt::wine_fallback_line(id) && c.why.empty());
for (uint32_t dev : {0x7550u, 0x7551u, 0x7590u, 0x7591u}) {
f.ddevice = dev;
expect("Wine: every RDNA 4 id of the list is accepted", wgrt::rdna4_identity(wgrt::lookup_adapter(luid, f.sources())));
}
f.dvendor = 0x8086;
f.ddevice = 0x56A0;
id = wgrt::lookup_adapter(luid, f.sources());
c = choice(id);
expect("Wine: another vendor's ids are refused (the front end's upscaler), no Wine line",
id.wine_fallback && !wgrt::rdna4_identity(id) && c.executor == "fsr" && c.adapter_note.empty() &&
has(c.why, "PCI 8086:56A0"));
f.dvendor = 0x10DE;
f.ddevice = 0x7550;
id = wgrt::lookup_adapter(luid, f.sources());
expect("Wine: an RDNA 4 device id under another vendor's id (spoofed) is refused",
!wgrt::rdna4_identity(id) && choice(id).executor == "fsr");
f.dvendor = 0x1002;
f.ddevice = 0x744C;
id = wgrt::lookup_adapter(luid, f.sources());
expect("Wine: an AMD board outside the list is refused, and said so",
!wgrt::rdna4_identity(id) && has(wgrt::describe_identity(id), "outside the RDNA 4 id list"));
f.ddevice = 0x7550;
f.dxgi_answers = false;
id = wgrt::lookup_adapter(luid, f.sources());
expect("Wine: the system DXGI not answering: not identified, refused (fail closed)",
!id.wine_fallback && !wgrt::rdna4_identity(id) && choice(id).executor == "fsr");
f.dxgi_answers = true;

// outside Wine (Windows): the fallback is never asked
WineFake w;
w.status = wgrt::kStatusNotImplemented;
w.wine = false;
id = wgrt::lookup_adapter(luid, w.sources());
expect("not under Wine: query not implemented is refused, and the system DXGI's ids are never asked",
!id.wine_fallback && !wgrt::rdna4_identity(id) && w.asked_wine == 1 && w.asked_dxgi_ids == 0 &&
choice(id).executor == "fsr");
for (int32_t st : {wgrt::kStatusUnsuccessful, (int32_t)-1073741811 /* 0xC000000D */, (int32_t)-1073741790 /* 0xC0000022 */}) {
WineFake o;
o.status = st;
o.wine = true;
id = wgrt::lookup_adapter(luid, o.sources());
expect("another status from the query is refused, under Wine too: neither Wine nor the system DXGI's ids are asked",
!id.wine_fallback && !id.kmt_known && !wgrt::rdna4_identity(id) && o.asked_wine == 0 && o.asked_dxgi_ids == 0);
}
WineFake ok; // Windows: the driver's ids are read; nothing else is asked, whatever the system DXGI would say
ok.dvendor = 0x10DE;
id = wgrt::lookup_adapter(luid, ok.sources());
c = choice(id);
expect("the driver's ids read: they decide, the fallback is never asked, no Wine line",
id.kmt_known && !id.wine_fallback && wgrt::rdna4_identity(id) && ok.asked_wine == 0 && ok.asked_dxgi_ids == 0 &&
c.executor == "dx12" && c.adapter_note.empty());
ok.kdevice = 0x744C;
ok.ddevice = 0x7550;
ok.wine = true;
id = wgrt::lookup_adapter(luid, ok.sources());
expect("the driver's ids read under Wine (a future Wine): RDNA 3 ids are refused, the DXGI ids never override them",
!wgrt::rdna4_identity(id) && ok.asked_dxgi_ids == 0);
// the Ray Reconstruction runtime: the same lookup, rule and line (rr_runtime.cpp)
id = wgrt::lookup_adapter(luid, f.sources());
expect("RR: the Wine fallback's RX 9000 is accepted, with the one line",
wgrt::rdna4_identity(id) && !wgrt::wine_fallback_line(id).empty());
}

// ---- 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)";
Expand Down
65 changes: 59 additions & 6 deletions clean/runtime/rdna4.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
// 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
// Wine and Proton (#248): Wine does not implement the driver's id query (D3DKMTQueryAdapterInfo type 31 answers
// STATUS_NOT_IMPLEMENTED), so under Wine the rule above would refuse every board. Only in that case, the query answering
// exactly STATUS_NOT_IMPLEMENTED in a process that runs under Wine (ntdll exports wine_get_version), the system DXGI's
// vendor and device id of the adapter with the same LUID stand in for the driver's, against the same vendor and the same
// id list. Any other failure, and the same status outside Wine, fails closed as before. Windows never takes this path.
//
// Header only and portable: the lookup takes its sources as functions (AdapterSources), so that tests run on any host
// with fakes; rdna4_win.h supplies the system's.
#pragma once

Expand Down Expand Up @@ -42,6 +48,7 @@ struct AdapterLuid {
struct AdapterRecord {
AdapterLuid luid;
uint32_t vendor = 0;
uint32_t device = 0; // DXGI's DeviceId (read only for the Wine fallback)
bool software = false;
std::string description;
};
Expand All @@ -54,12 +61,27 @@ struct AdapterIdentity {
std::string description;
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;
// Wine only: the driver's query answered STATUS_NOT_IMPLEMENTED under Wine, and the system DXGI's ids were read instead
bool wine_fallback = false;
uint32_t wine_vendor = 0, wine_device = 0;
};

// The two sources (injectable; rdna4_win.h: the system's own DXGI by its full path, and D3DKMTQueryAdapterInfo).
// NTSTATUS 0xC0000002, STATUS_NOT_IMPLEMENTED: Wine's answer to the driver's id query.
constexpr int32_t kStatusNotImplemented = -1073741822;
// NTSTATUS 0xC0000001, STATUS_UNSUCCESSFUL: what rdna4_win.h's query reports when it could not ask at all (no thunks, the
// adapter not opened), so that only the query's own STATUS_NOT_IMPLEMENTED can lead to the Wine fallback.
constexpr int32_t kStatusUnsuccessful = -1073741823;

// The sources (injectable; rdna4_win.h: the system's own DXGI by its full path, and D3DKMTQueryAdapterInfo).
struct AdapterSources {
std::function<bool(const AdapterLuid&, AdapterRecord*)> find_adapter; // system DXGI, by LUID
std::function<bool(const AdapterLuid&, uint32_t* vendor, uint32_t* device)> driver_ids; // kernel-mode driver, by LUID
// The driver's query with its own status (0: the ids were read); when set, it is asked instead of driver_ids.
std::function<int32_t(const AdapterLuid&, uint32_t* vendor, uint32_t* device)> driver_query;
// The Wine fallback's two sources, asked only when driver_query answered kStatusNotImplemented: whether the process runs
// under Wine, then the system DXGI's vendor and device id of the adapter with this LUID.
std::function<bool()> under_wine;
std::function<bool(const AdapterLuid&, uint32_t* vendor, uint32_t* device)> dxgi_ids;
};

// The adapter with this LUID (the game device's): the same LUID goes to both sources, nothing is guessed; what a source
Expand All @@ -73,13 +95,32 @@ inline AdapterIdentity lookup_adapter(const AdapterLuid& luid, const AdapterSour
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);
if (s.driver_query) {
uint32_t v = 0, d = 0;
const int32_t status = s.driver_query(luid, &v, &d);
if (status == 0) {
id.kmt_known = true;
id.kmt_vendor = v;
id.kmt_device = d;
} else if (status == kStatusNotImplemented && s.under_wine && s.under_wine() && s.dxgi_ids) {
uint32_t wv = 0, wd = 0;
if (s.dxgi_ids(luid, &wv, &wd)) {
id.wine_fallback = true;
id.wine_vendor = wv;
id.wine_device = wd;
}
}
} else 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.
// Under Wine, when the driver's query is not implemented there, the system DXGI's ids under the same rule (#248).
inline bool rdna4_identity(const AdapterIdentity& a) {
return a.kmt_known && a.kmt_vendor == 0x1002 && rdna4_device_id(a.kmt_device);
if (a.kmt_known) return a.kmt_vendor == 0x1002 && rdna4_device_id(a.kmt_device);
return a.wine_fallback && a.wine_vendor == 0x1002 && rdna4_device_id(a.wine_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
Expand All @@ -90,12 +131,24 @@ inline std::string describe_identity(const AdapterIdentity& a) {
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);
const bool wine = !a.kmt_known && a.wine_fallback;
if (wine) {
std::snprintf(ids, sizeof ids, "PCI %04X:%04X", (unsigned)a.wine_vendor, (unsigned)a.wine_device);
s += (s.empty() ? "adapter " : ", ") + std::string(ids) + " (Wine: the system DXGI's 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";
const uint32_t vendor = wine ? a.wine_vendor : a.kmt_vendor, device = wine ? a.wine_device : a.kmt_device;
if ((a.kmt_known || wine) && vendor == 0x1002 && !rdna4_device_id(device)) s += "; an AMD board outside the RDNA 4 id list";
return s;
}

// The one line when an adapter was accepted by the Wine fallback (#248); empty otherwise.
inline std::string wine_fallback_line(const AdapterIdentity& a) {
if (a.kmt_known || !a.wine_fallback || !rdna4_identity(a)) return std::string();
return "Wine: the driver's adapter id query is not implemented; the adapter was identified from the system DXGI's ids (" +
describe_identity(a) + ")";
}

// 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).
Expand Down
Loading
Loading