2018-08-07 16:58:16 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
2018-08-07 14:13:57 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-08-07 16:58:16 +02:00
|
|
|
#include "../log/log.h"
|
|
|
|
|
|
|
|
#include "../util_env.h"
|
|
|
|
|
2018-08-07 14:13:57 +02:00
|
|
|
namespace dxvk {
|
|
|
|
|
2018-08-07 16:58:16 +02:00
|
|
|
const static std::unordered_map<std::string, Config> g_appDefaults = {{
|
2018-09-12 14:10:49 +02:00
|
|
|
/* Assassin's Creed Syndicate - amdags issues */
|
|
|
|
{ "ACS.exe", {{
|
2018-09-09 13:46:57 +02:00
|
|
|
{ "dxgi.customVendorId", "10de" },
|
2018-09-12 14:10:49 +02:00
|
|
|
}} },
|
2018-08-10 12:50:31 +02:00
|
|
|
/* Dishonored 2 */
|
2018-08-07 16:58:16 +02:00
|
|
|
{ "Dishonored2.exe", {{
|
|
|
|
{ "d3d11.allowMapFlagNoWait", "True" }
|
|
|
|
}} },
|
2018-11-06 17:03:01 +01:00
|
|
|
/* Elite Dangerous */
|
|
|
|
{ "EliteDangerous64.exe", {{
|
|
|
|
{ "dxgi.customVendorId", "10de" },
|
|
|
|
}} },
|
2018-10-25 17:49:42 +02:00
|
|
|
/* The Vanishing of Ethan Carter Redux */
|
|
|
|
{ "EthanCarter-Win64-Shipping.exe", {{
|
|
|
|
{ "dxgi.customVendorId", "10de" },
|
|
|
|
}} },
|
2018-10-09 16:29:50 +02:00
|
|
|
/* The Evil Within */
|
|
|
|
{ "EvilWithin.exe", {{
|
2018-11-20 10:51:09 +01:00
|
|
|
{ "d3d11.dcSingleUseMode", "False" },
|
2018-10-09 16:29:50 +02:00
|
|
|
}} },
|
|
|
|
/* The Evil Within Demo */
|
|
|
|
{ "EvilWithinDemo.exe", {{
|
2018-11-20 10:51:09 +01:00
|
|
|
{ "d3d11.dcSingleUseMode", "False" },
|
2018-10-09 16:29:50 +02:00
|
|
|
}} },
|
2018-08-10 12:50:31 +02:00
|
|
|
/* F1 2015 */
|
2018-08-07 16:58:16 +02:00
|
|
|
{ "F1_2015.exe", {{
|
|
|
|
{ "d3d11.fakeStreamOutSupport", "True" },
|
|
|
|
}} },
|
2018-08-10 12:50:31 +02:00
|
|
|
/* Far Cry 5 */
|
2018-08-07 16:58:16 +02:00
|
|
|
{ "FarCry5.exe", {{
|
|
|
|
{ "d3d11.allowMapFlagNoWait", "True" }
|
|
|
|
}} },
|
2018-08-10 12:50:31 +02:00
|
|
|
/* Final Fantasy XV */
|
|
|
|
{ "ffxv_s.exe", {{
|
|
|
|
{ "d3d11.fakeStreamOutSupport", "True" },
|
|
|
|
}} },
|
|
|
|
/* Frostpunk */
|
2018-08-07 16:58:16 +02:00
|
|
|
{ "Frostpunk.exe", {{
|
|
|
|
{ "dxgi.deferSurfaceCreation", "True" },
|
|
|
|
}} },
|
2018-08-10 12:50:31 +02:00
|
|
|
/* Mafia 3 */
|
|
|
|
{ "mafia3.exe", {{
|
|
|
|
{ "d3d11.fakeStreamOutSupport", "True" },
|
|
|
|
}} },
|
|
|
|
/* Overwatch */
|
2018-08-07 16:58:16 +02:00
|
|
|
{ "Overwatch.exe", {{
|
|
|
|
{ "d3d11.fakeStreamOutSupport", "True" },
|
|
|
|
}} },
|
2018-11-23 16:12:09 +01:00
|
|
|
/* Quantum Break */
|
|
|
|
{ "QuantumBreak.exe", {{
|
|
|
|
{ "d3d11.zeroInitWorkgroupMemory", "True" },
|
|
|
|
}} },
|
2018-11-24 20:04:21 +01:00
|
|
|
/* Anno 2205 */
|
|
|
|
{ "anno2205.exe", {{
|
|
|
|
{ "dxvk.enableStateCache", "False" },
|
|
|
|
}} },
|
2018-08-07 16:58:16 +02:00
|
|
|
}};
|
|
|
|
|
|
|
|
|
|
|
|
static bool isWhitespace(char ch) {
|
|
|
|
return ch == ' ' || ch == '\x9' || ch == '\r';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool isValidKeyChar(char ch) {
|
|
|
|
return (ch >= '0' && ch <= '9')
|
|
|
|
|| (ch >= 'A' && ch <= 'Z')
|
|
|
|
|| (ch >= 'a' && ch <= 'z')
|
|
|
|
|| (ch == '.' || ch == '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static size_t skipWhitespace(const std::string& line, size_t n) {
|
|
|
|
while (n < line.size() && isWhitespace(line[n]))
|
|
|
|
n += 1;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void parseUserConfigLine(Config& config, const std::string& line) {
|
|
|
|
std::stringstream key;
|
|
|
|
std::stringstream value;
|
|
|
|
|
|
|
|
// Extract the key
|
|
|
|
size_t n = skipWhitespace(line, 0);
|
|
|
|
while (n < line.size() && isValidKeyChar(line[n]))
|
|
|
|
key << line[n++];
|
|
|
|
|
|
|
|
// Check whether the next char is a '='
|
|
|
|
n = skipWhitespace(line, n);
|
|
|
|
if (n >= line.size() || line[n] != '=')
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Extract the value
|
|
|
|
n = skipWhitespace(line, n + 1);
|
|
|
|
while (n < line.size() && !isWhitespace(line[n]))
|
|
|
|
value << line[n++];
|
|
|
|
|
|
|
|
config.setOption(key.str(), value.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-07 14:13:57 +02:00
|
|
|
Config::Config() { }
|
|
|
|
Config::~Config() { }
|
|
|
|
|
|
|
|
|
|
|
|
Config::Config(OptionMap&& options)
|
|
|
|
: m_options(std::move(options)) { }
|
|
|
|
|
|
|
|
|
|
|
|
void Config::merge(const Config& other) {
|
|
|
|
for (auto& pair : other.m_options)
|
|
|
|
m_options.insert(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Config::setOption(const std::string& key, const std::string& value) {
|
|
|
|
m_options.insert_or_assign(key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string Config::getOptionValue(const char* option) const {
|
|
|
|
auto iter = m_options.find(option);
|
|
|
|
|
|
|
|
return iter != m_options.end()
|
|
|
|
? iter->second : std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Config::parseOptionValue(
|
|
|
|
const std::string& value,
|
|
|
|
std::string& result) {
|
|
|
|
result = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Config::parseOptionValue(
|
|
|
|
const std::string& value,
|
|
|
|
bool& result) {
|
|
|
|
if (value == "True") {
|
|
|
|
result = true;
|
|
|
|
return true;
|
|
|
|
} else if (value == "False") {
|
|
|
|
result = false;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Config::parseOptionValue(
|
|
|
|
const std::string& value,
|
|
|
|
int32_t& result) {
|
|
|
|
if (value.size() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Parse sign, don't allow '+'
|
|
|
|
int32_t sign = 1;
|
|
|
|
size_t start = 0;
|
|
|
|
|
|
|
|
if (value[0] == '-') {
|
|
|
|
sign = -1;
|
|
|
|
start = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse absolute number
|
|
|
|
int32_t intval = 0;
|
|
|
|
|
|
|
|
for (size_t i = start; i < value.size(); i++) {
|
|
|
|
if (value[i] < '0' || value[i] > '9')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
intval *= 10;
|
|
|
|
intval += value[i] - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply sign and return
|
|
|
|
result = sign * intval;
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-08 20:57:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
bool Config::parseOptionValue(
|
|
|
|
const std::string& value,
|
|
|
|
Tristate& result) {
|
|
|
|
if (value == "True") {
|
|
|
|
result = Tristate::True;
|
|
|
|
return true;
|
|
|
|
} else if (value == "False") {
|
|
|
|
result = Tristate::False;
|
|
|
|
return true;
|
|
|
|
} else if (value == "Auto") {
|
|
|
|
result = Tristate::Auto;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-08-07 14:13:57 +02:00
|
|
|
|
2018-08-07 16:58:16 +02:00
|
|
|
|
|
|
|
Config Config::getAppConfig(const std::string& appName) {
|
|
|
|
auto appConfig = g_appDefaults.find(appName);
|
2018-09-09 13:46:57 +02:00
|
|
|
if (appConfig != g_appDefaults.end()) {
|
|
|
|
// Inform the user that we loaded a default config
|
|
|
|
Logger::info(str::format("Found built-in config: ", appName));
|
|
|
|
|
2018-08-07 16:58:16 +02:00
|
|
|
return appConfig->second;
|
2018-09-09 13:46:57 +02:00
|
|
|
}
|
|
|
|
|
2018-08-07 16:58:16 +02:00
|
|
|
return Config();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Config Config::getUserConfig() {
|
|
|
|
Config config;
|
|
|
|
|
|
|
|
// Load either $DXVK_CONFIG_FILE or $PWD/dxvk.conf
|
2018-11-15 17:12:09 -05:00
|
|
|
std::string filePath = env::getEnvVar("DXVK_CONFIG_FILE");
|
2018-08-07 16:58:16 +02:00
|
|
|
|
|
|
|
if (filePath == "")
|
|
|
|
filePath = "dxvk.conf";
|
|
|
|
|
|
|
|
// Open the file if it exists
|
|
|
|
std::ifstream stream(filePath);
|
|
|
|
|
|
|
|
if (!stream)
|
|
|
|
return config;
|
2018-08-17 19:42:32 +02:00
|
|
|
|
|
|
|
// Inform the user that we loaded a file, might
|
|
|
|
// help when debugging configuration issues
|
|
|
|
Logger::info(str::format("Found config file: ", filePath));
|
2018-08-07 16:58:16 +02:00
|
|
|
|
|
|
|
// Parse the file line by line
|
|
|
|
std::string line;
|
|
|
|
|
|
|
|
while (std::getline(stream, line))
|
|
|
|
parseUserConfigLine(config, line);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2018-09-09 13:46:57 +02:00
|
|
|
|
|
|
|
void Config::logOptions() const {
|
|
|
|
if (!m_options.empty()) {
|
|
|
|
Logger::info("Effective configuration:");
|
|
|
|
|
|
|
|
for (auto& pair : m_options)
|
|
|
|
Logger::info(str::format(" ", pair.first, " = ", pair.second));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-08 12:46:21 +02:00
|
|
|
}
|