2018-05-24 12:31:04 +02:00
|
|
|
#include "dxgi_options.h"
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace dxvk {
|
2018-08-07 17:33:19 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-01-09 11:36:30 +00:00
|
|
|
|
2023-08-24 22:08:06 +02:00
|
|
|
static bool isNvapiEnabled() {
|
|
|
|
return env::getEnvVar("DXVK_ENABLE_NVAPI") == "1";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-09 11:36:30 +00:00
|
|
|
static bool isHDRDisallowed() {
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Unreal Engine 4 titles use AGS/NVAPI to try and enable
|
|
|
|
// HDR globally.
|
|
|
|
// The game checks IDXGIOutput::GetDesc1's ColorSpace
|
|
|
|
// being HDR10 to see if it should enable HDR.
|
|
|
|
// Many of these UE4 games statically link against AGS.
|
|
|
|
//
|
|
|
|
// This is a problem as when UE4 tries to enable HDR via AGS,
|
|
|
|
// it does not check if AGSContext, and the display info etc
|
|
|
|
// are nullptr unlike the rest of the code using AGS.
|
|
|
|
// So we need to special-case UE4 titles to disable reporting a HDR
|
|
|
|
// when they are in DX11 mode.
|
|
|
|
//
|
|
|
|
// The simplest way to do this is to key off the fact that all
|
|
|
|
// UE4 titles have an executable ending with "-Win64-Shipping".
|
|
|
|
//
|
|
|
|
// We check if d3d12.dll is present, to determine what path in
|
|
|
|
// UE4 we are on, as there are some games that ship both and support HDR.
|
|
|
|
// (eg. The Dark Pictures: House of Ashes, 1281590)
|
|
|
|
// Luckily for us, they only load d3d12.dll on the D3D12 render path
|
|
|
|
// so we can key off that to force disable HDR only in D3D11.
|
|
|
|
std::string exeName = env::getExeName();
|
|
|
|
bool isUE4 = exeName.find("-Win64-Shipping") != std::string::npos;
|
|
|
|
bool hasD3D12 = GetModuleHandleA("d3d12") != nullptr;
|
|
|
|
|
2023-08-24 22:08:06 +02:00
|
|
|
if (isUE4 && !hasD3D12 && !isNvapiEnabled())
|
2023-01-09 11:36:30 +00:00
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-24 12:31:04 +02:00
|
|
|
|
2018-08-07 14:47:06 +02:00
|
|
|
DxgiOptions::DxgiOptions(const Config& config) {
|
2018-08-25 01:22:19 +02:00
|
|
|
// Fetch these as a string representing a hexadecimal number and parse it.
|
|
|
|
this->customVendorId = parsePciId(config.getOption<std::string>("dxgi.customVendorId"));
|
|
|
|
this->customDeviceId = parsePciId(config.getOption<std::string>("dxgi.customDeviceId"));
|
2021-05-11 23:32:41 +01:00
|
|
|
this->customDeviceDesc = config.getOption<std::string>("dxgi.customDeviceDesc", "");
|
2021-05-12 00:00:02 +01:00
|
|
|
|
|
|
|
// Emulate a UMA device
|
|
|
|
this->emulateUMA = config.getOption<bool>("dxgi.emulateUMA", false);
|
2018-08-25 01:22:19 +02:00
|
|
|
|
|
|
|
// Interpret the memory limits as Megabytes
|
|
|
|
this->maxDeviceMemory = VkDeviceSize(config.getOption<int32_t>("dxgi.maxDeviceMemory", 0)) << 20;
|
|
|
|
this->maxSharedMemory = VkDeviceSize(config.getOption<int32_t>("dxgi.maxSharedMemory", 0)) << 20;
|
2018-09-09 19:12:07 +02:00
|
|
|
|
2023-08-14 19:14:18 +02:00
|
|
|
// Expose Nvidia GPUs properly if NvAPI is enabled in environment
|
2023-08-24 22:08:06 +02:00
|
|
|
this->hideNvidiaGpu = !isNvapiEnabled();
|
2023-08-14 19:14:18 +02:00
|
|
|
|
|
|
|
Tristate hideNvidiaGpuOption = config.getOption<Tristate>("dxgi.hideNvidiaGpu", Tristate::Auto);
|
|
|
|
|
|
|
|
if (hideNvidiaGpuOption == Tristate::Auto && !config.getOption<bool>("dxgi.nvapiHack", true)) {
|
|
|
|
Logger::warn("dxgi.nvapiHack is deprecated, please set dxgi.hideNvidiaGpu instead.");
|
|
|
|
hideNvidiaGpuOption = Tristate::False;
|
|
|
|
}
|
|
|
|
|
|
|
|
applyTristate(this->hideNvidiaGpu, hideNvidiaGpuOption);
|
2023-01-06 14:41:30 +00:00
|
|
|
|
2023-08-14 19:44:07 +02:00
|
|
|
// Expose AMD and Intel GPU by default, unless a config override is active.
|
|
|
|
// Implement as a tristate so that we have the option to introduce similar
|
|
|
|
// logic to Nvidia later, if necessary.
|
|
|
|
this->hideAmdGpu = config.getOption<Tristate>("dxgi.hideAmdGpu", Tristate::Auto) == Tristate::True;
|
|
|
|
this->hideIntelGpu = config.getOption<Tristate>("dxgi.hideIntelGpu", Tristate::Auto) == Tristate::True;
|
|
|
|
|
2023-01-06 14:41:30 +00:00
|
|
|
this->enableHDR = config.getOption<bool>("dxgi.enableHDR", env::getEnvVar("DXVK_HDR") == "1");
|
2023-01-09 11:36:30 +00:00
|
|
|
if (this->enableHDR && isHDRDisallowed()) {
|
|
|
|
Logger::info("HDR was configured to be enabled, but has been force disabled as a UE4 DX11 game was detected.");
|
|
|
|
this->enableHDR = false;
|
|
|
|
}
|
2023-10-09 15:16:30 -06:00
|
|
|
|
|
|
|
this->useMonitorFallback = config.getOption<bool>("dxgi.useMonitorFallback", env::getEnvVar("DXVK_MONITOR_FALLBACK") == "1");
|
|
|
|
if (this->useMonitorFallback)
|
|
|
|
Logger::info("Enabled useMonitorFallback option");
|
2018-05-24 12:31:04 +02:00
|
|
|
}
|
|
|
|
|
2022-03-15 16:08:29 -07:00
|
|
|
}
|