From f08add9c341e5b5b35e26242bfe3c0201f457ef8 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 7 Aug 2018 17:33:19 +0200 Subject: [PATCH] [dxgi] Add custom device/vendor IDs to DxgiOptions --- README.md | 2 -- src/dxgi/dxgi_adapter.cpp | 18 +++++++++--------- src/dxgi/dxgi_options.cpp | 25 +++++++++++++++++++++++++ src/dxgi/dxgi_options.h | 6 ++++++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index cd1eaafe0..3e5b1ed4d 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,6 @@ Additionally, `DXVK_HUD=1` has the same effect as `DXVK_HUD=devinfo,fps`. ### Debugging The following environment variables can be used for **debugging** purposes. - `VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_standard_validation` Enables Vulkan debug layers. Highly recommended for troubleshooting rendering issues and driver crashes. Requires the Vulkan SDK to be installed on the host system. -- `DXVK_CUSTOM_VENDOR_ID=` Specifies a custom PCI vendor ID -- `DXVK_CUSTOM_DEVICE_ID=` Specifies a custom PCI device ID - `DXVK_LOG_LEVEL=none|error|warn|info|debug` Controls message logging ## Troubleshooting diff --git a/src/dxgi/dxgi_adapter.cpp b/src/dxgi/dxgi_adapter.cpp index 27448e7d1..3ef400a7f 100644 --- a/src/dxgi/dxgi_adapter.cpp +++ b/src/dxgi/dxgi_adapter.cpp @@ -150,18 +150,18 @@ namespace dxvk { auto deviceProp = m_adapter->deviceProperties(); auto memoryProp = m_adapter->memoryProperties(); - // Custom Vendor ID - const std::string customVendorID = env::getEnvVar(L"DXVK_CUSTOM_VENDOR_ID"); - const std::string customDeviceID = env::getEnvVar(L"DXVK_CUSTOM_DEVICE_ID"); + // Custom Vendor / Device ID + const int32_t customVendorID = m_factory->GetOptions()->customVendorId; + const int32_t customDeviceID = m_factory->GetOptions()->customDeviceId; - if (!customVendorID.empty()) { - Logger::info("Using Custom PCI Vendor ID " + customVendorID + " instead of " + str::format(std::hex, deviceProp.vendorID)); - deviceProp.vendorID = std::stoul(customVendorID, nullptr, 16); + if (customVendorID >= 0) { + Logger::info(str::format("Using Custom PCI Vendor ID ", std::hex, customVendorID)); + deviceProp.vendorID = customVendorID; } - if (!customDeviceID.empty()) { - Logger::info("Using Custom PCI Device ID " + customDeviceID + " instead of " + str::format(std::hex, deviceProp.deviceID)); - deviceProp.deviceID = std::stoul(customDeviceID, nullptr, 16); + if (customDeviceID >= 0) { + Logger::info(str::format("Using Custom PCI Device ID ", std::hex, customDeviceID)); + deviceProp.deviceID = customDeviceID; } std::memset(pDesc->Description, 0, sizeof(pDesc->Description)); diff --git a/src/dxgi/dxgi_options.cpp b/src/dxgi/dxgi_options.cpp index a251b3656..1da6a738c 100644 --- a/src/dxgi/dxgi_options.cpp +++ b/src/dxgi/dxgi_options.cpp @@ -3,11 +3,36 @@ #include namespace dxvk { + + static int32_t parsePciId(const std::string& str) { + if (str.size() != 4) + return -1; + + int32_t id = 0; + + for (size_t i = 0; i < str.size(); i++) { + id *= 16; + + if (str[i] >= '0' && str[i] <= '9') + id += str[i] - '0'; + else if (str[i] >= 'A' && str[i] <= 'F') + id += str[i] - 'A' + 10; + else if (str[i] >= 'a' && str[i] <= 'f') + id += str[i] - 'a' + 10; + else + return -1; + } + + return id; + } + DxgiOptions::DxgiOptions(const Config& config) { this->deferSurfaceCreation = config.getOption ("dxgi.deferSurfaceCreation", false); this->fakeDx10Support = config.getOption ("dxgi.fakeDx10Support", false); this->maxFrameLatency = config.getOption ("dxgi.maxFrameLatency", 0); + this->customVendorId = parsePciId(config.getOption("dxgi.customVendorId")); + this->customDeviceId = parsePciId(config.getOption("dxgi.customDeviceId")); } } \ No newline at end of file diff --git a/src/dxgi/dxgi_options.h b/src/dxgi/dxgi_options.h index 86bea890f..5a6392aad 100644 --- a/src/dxgi/dxgi_options.h +++ b/src/dxgi/dxgi_options.h @@ -28,6 +28,12 @@ namespace dxvk { /// Override maximum frame latency if the app specifies /// a higher value. May help with frame timing issues. int32_t maxFrameLatency; + + /// Override PCI vendor and device IDs reported to the + /// application. This may make apps think they are running + /// on a different GPU than they do and behave differently. + int32_t customVendorId; + int32_t customDeviceId; }; }