Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/dxgi/dxgi_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,11 @@ namespace dxvk {

bool hideNvidiaGpu = adapterInfo.driverId == VK_DRIVER_ID_NVIDIA_PROPRIETARY
? options->hideNvidiaGpu : options->hideNvkGpu;
bool hideIntelGpu = options->shouldHideIntelGpu();
Comment thread
doitsujin marked this conversation as resolved.
Resolved

bool hideGpu = (adapterInfo.vendorId == uint16_t(DxvkGpuVendor::Nvidia) && hideNvidiaGpu)
|| (adapterInfo.vendorId == uint16_t(DxvkGpuVendor::Amd) && options->hideAmdGpu)
|| (adapterInfo.vendorId == uint16_t(DxvkGpuVendor::Intel) && options->hideIntelGpu);
|| (adapterInfo.vendorId == uint16_t(DxvkGpuVendor::Intel) && hideIntelGpu);

if (hideGpu) {
adapterInfo.vendorId = fallbackVendor;
Expand Down
91 changes: 67 additions & 24 deletions src/dxgi/dxgi_options.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "dxgi_options.h"

#include <cstring>
#include <unordered_map>

namespace dxvk {
Expand Down Expand Up @@ -39,20 +40,37 @@ namespace dxvk {
return id;
}

/**
* \brief Whether old XeSS versions need the Intel vendor ID hidden
*/
enum class XessVendorWa : uint32_t {
Unknown, ///< No XeSS loaded yet
NotNeeded, ///< Wine builtin XeSS or a fixed XeSS version
Needed, ///< XeSS version that fails on the Intel path
};

/* Some XeSS versions crash on Proton for Intel due to missing Intel
* interfaces. Avoid crash by pretending to be non-Intel if the libxess.dll
* module is loaded by an application. */
static bool isXessVendorWaNeeded() {
* interfaces. Avoid the crash by pretending to be non-Intel once such
* a libxess.dll module is loaded by the application. Applications may
* load XeSS late, e.g. the Unreal Engine plugin loads it only after the
* D3D12 device is created, so this can't be decided up front. */
static XessVendorWa getXessVendorWa() {
#ifdef _WIN32
HMODULE libxess = nullptr;

// Use Ex variant here to keep the library loaded while we use the handle
if (!GetModuleHandleExA(0u, "libxess", &libxess)
&& !GetModuleHandleExA(0u, "libxess_dx11", &libxess))
return false;
return XessVendorWa::Unknown;

if (!libxess)
return false;
return XessVendorWa::Unknown;

// Wine builtin XeSS (e.g. Proton forwarding to a native libxess.so)
// doesn't use the Intel path that needs the workaround.
static const char builtinSignature[] = "Wine builtin DLL";
bool isBuiltin = !std::memcmp(reinterpret_cast<const char*>(libxess) + 0x40,
builtinSignature, sizeof(builtinSignature));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a more robust way to detect this (e.g. some export that's only available in the built-in dll or something)?

This hack looks like the kind of thing that's just going to blow up either on Windows or at some point in the future, and when it does then the only real option is to remove the code.


// For some reason it seems to be impossible to just query
// the length, need to pre-allocate for the worst case
Expand All @@ -63,56 +81,57 @@ namespace dxvk {
// on the actual file from now on
FreeLibrary(libxess);

if (isBuiltin)
return XessVendorWa::NotNeeded;

if (!nameLen) {
Logger::warn("DXGI: Failed to get file name for XeSS module");
return true;
return XessVendorWa::Needed;
}

// Query version info blob size...
auto fiSize = GetFileVersionInfoSizeA(fileName.data(), nullptr);

if (!fiSize) {
Logger::warn("DXGI: Failed to get XeSS version info size");
return true;
return XessVendorWa::Needed;
}

// Retrieve actual version info blob
std::vector<char> fiData(fiSize);

if (!GetFileVersionInfoA(fileName.data(), 0u, fiSize, fiData.data())) {
Logger::warn("DXGI: Failed to get XeSS version info");
return true;
return XessVendorWa::Needed;
}

void* fiBlock = nullptr;
UINT fiBlockSize = 0u;

if (!VerQueryValueA(fiData.data(), "\\", &fiBlock, &fiBlockSize)) {
Logger::warn("DXGI: Failed to get XeSS version info block");
return true;
return XessVendorWa::Needed;
}

auto fiBlockTyped = reinterpret_cast<const VS_FIXEDFILEINFO*>(fiBlock);

if (!fiBlockTyped || fiBlockSize < sizeof(*fiBlockTyped)) {
Logger::warn("DXGI: Invalid XeSS version info block");
return true;
return XessVendorWa::Needed;
}

const uint32_t major = fiBlockTyped->dwProductVersionMS >> 16;
const uint32_t minor = fiBlockTyped->dwProductVersionMS & 0xffffu;
const uint32_t patch = fiBlockTyped->dwProductVersionLS >> 16;
const uint32_t build = fiBlockTyped->dwProductVersionLS & 0xffffu;

// Some early 2.0 builds are still affected, keep the workaround enabled
// until at least 2.0.2.68.
const bool isKnownGood = isVersionAtLeast(
major, minor, patch, build,
bool isKnownGood = isVersionAtLeast(
fiBlockTyped->dwProductVersionMS >> 16,
fiBlockTyped->dwProductVersionMS & 0xffffu,
fiBlockTyped->dwProductVersionLS >> 16,
fiBlockTyped->dwProductVersionLS & 0xffffu,
2u, 0u, 2u, 68u);

return !isKnownGood;
return isKnownGood ? XessVendorWa::NotNeeded : XessVendorWa::Needed;
#else
return false;
return XessVendorWa::NotNeeded;
#endif
}

Expand All @@ -121,6 +140,35 @@ namespace dxvk {
}


bool DxgiOptions::shouldHideIntelGpu() const {
if (this->hideIntelGpu)
return true;

// XeSS is loaded once per process, so the decision is shared by all
// DXGI factories. Keep checking until XeSS is loaded, then stick with
// the decision so the reported vendor doesn't change again.
static std::atomic<XessVendorWa> s_xessVendorWa = { XessVendorWa::Unknown };

XessVendorWa wa = s_xessVendorWa.load();
if (wa == XessVendorWa::Unknown) {
wa = getXessVendorWa();

if (wa != XessVendorWa::Unknown) {
XessVendorWa expected = XessVendorWa::Unknown;

if (s_xessVendorWa.compare_exchange_strong(expected, wa)) {
if (wa == XessVendorWa::Needed)
Logger::info("DXGI: Detected XeSS usage, hiding Intel GPU Vendor");
} else {
wa = expected;
}
}
}

return wa == XessVendorWa::Needed;
}


static bool isHDRDisallowed(bool enableUe4Workarounds) {
#ifdef _WIN32
// Unreal Engine 4 titles use AGS/NVAPI to try and enable
Expand Down Expand Up @@ -187,11 +235,6 @@ namespace dxvk {
this->hideAmdGpu = config.getOption<Tristate>("dxgi.hideAmdGpu", Tristate::Auto) == Tristate::True;
this->hideIntelGpu = config.getOption<Tristate>("dxgi.hideIntelGpu", Tristate::Auto) == Tristate::True;

if (isXessVendorWaNeeded()) {
Logger::info(str::format("XeSS: hiding Intel GPU Vendor ID"));
this->hideIntelGpu = true;
}

this->enableHDR = config.getOption<bool>("dxgi.enableHDR", env::getEnvVar("DXVK_HDR") == "1");

bool enableUe4Workarounds = config.getOption<bool>("dxgi.enableUe4Workarounds", false);
Expand Down
4 changes: 3 additions & 1 deletion src/dxgi/dxgi_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace dxvk {
struct DxgiOptions {
DxgiOptions(const Config& config);

bool shouldHideIntelGpu() const;

void incRef() {
m_useCount.fetch_add(1u);
}
Expand Down Expand Up @@ -73,5 +75,5 @@ namespace dxvk {
std::atomic<uint32_t> m_useCount = { 0u };

};

}
Loading