Skip to content

Commit

Permalink
nvapi: Support setting NGX debug registry tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jp7677 committed Feb 10, 2025
1 parent 5cb68ad commit 3ed9a0a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 71 deletions.
4 changes: 2 additions & 2 deletions src/nvapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "util/util_string.h"
#include "util/util_env.h"
#include "util/util_log.h"
#include "util/util_dlss.h"
#include "util/util_ngx_debug.h"
#include "../version.h"
#include "../config.h"

Expand Down Expand Up @@ -385,7 +385,7 @@ extern "C" {
nvapiD3dInstance = std::make_unique<NvapiD3dInstance>(*resourceFactory);
nvapiD3dInstance->Initialize();

setDlssIndicator();
SetNgxDebugOptions();

return Ok(n);
}
Expand Down
50 changes: 0 additions & 50 deletions src/util/util_dlss.h

This file was deleted.

53 changes: 53 additions & 0 deletions src/util/util_ngx_debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once

#include "../nvapi_private.h"
#include "util_log.h"
#include "util_env.h"

namespace dxvk {
inline void SetNgxDebugOptions() {
constexpr static auto setNgxIndicatorEnvName = "DXVK_NVAPI_SET_NGX_DEBUG_OPTIONS";
const static std::unordered_map<std::string_view, std::string_view> settings = {
{"Logging", "EnableConsoleLogging"},
{"LogLevel", "LogLevel"},
{"DLSSIndicator", "ShowDlssIndicator"},
{"DLSSGIndicator", "DLSSG_IndicatorText"},
};
const static auto setNgxIndicator = env::getEnvVariable(setNgxIndicatorEnvName);

if (setNgxIndicator.empty())
return;

std::set<std::string_view, str::CaseInsensitiveCompare<std::string_view>> keys;
std::transform(settings.begin(), settings.end(), std::inserter(keys, keys.begin()), [](const auto& s) { return s.first; });

auto setNgxIndicatorMap = str::parsestrdwords(setNgxIndicator, keys);

if (setNgxIndicatorMap.empty()) {
log::info(str::format(setNgxIndicatorEnvName, " is set to an invalid value, please use the format 'key=value,key=value'"));
return;
}

HKEY key{};
auto status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\NVIDIA Corporation\\Global\\NGXCore", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, &key);
if (status != NO_ERROR || !key) {
log::info(str::format(R"(Failed to open SOFTWARE\NVIDIA Corporation\Global\NGXCore registry key: )", status));
return;
}

std::for_each(settings.begin(), settings.end(),
[&](const auto& pair) {
if (!setNgxIndicatorMap.contains(pair.first))
return;

auto value = setNgxIndicatorMap.at(pair.first);
log::info(str::format("Set ", pair.second, " in registry to 0x", std::hex, value));

std::wstring name = std::wstring(pair.second.begin(), pair.second.end());
if (RegSetValueExW(key, name.c_str(), 0, REG_DWORD, reinterpret_cast<const BYTE*>(&value), sizeof(DWORD)) != NO_ERROR)
log::info(str::format("Failed to set ", pair.second, " registry key"));
});

RegCloseKey(key);
}
}
21 changes: 4 additions & 17 deletions src/util/util_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,8 @@ namespace dxvk::str {
return result;
}

auto equals_ci(const std::string_view& a) {
return [&a](const auto& b) {
if (a.size() != b.size())
return false;

for (auto i = 0U; i < a.size(); i++)
if (std::toupper(a[i], std::locale::classic()) != std::toupper(b[i], std::locale::classic()))
return false;

return true;
};
}

std::unordered_map<std::string, NvU32> parsestrdwords(const std::string& str, const std::set<std::string_view>& keys) {
std::unordered_map<std::string, NvU32> result;
std::unordered_map<std::string_view, NvU32> parsestrdwords(const std::string& str, const std::set<std::string_view, str::CaseInsensitiveCompare<std::string_view>>& keys) {
std::unordered_map<std::string_view, NvU32> result;
auto entries = str::split<std::vector<std::string_view>>(str, std::regex(","));

for (auto entry : entries) {
Expand All @@ -109,13 +96,13 @@ namespace dxvk::str {
continue;

auto key = entry.substr(0, eq);
auto it = std::find_if(keys.begin(), keys.end(), equals_ci(key));
auto it = keys.find(key);
if (it == keys.end())
continue;

NvU32 value;
if (str::parsedword(entry.substr(eq + 1), value))
result[std::string(*it)] = value;
result[*it] = value;
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/util/util_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ namespace dxvk::str {

std::unordered_map<NvU32, NvU32> parsedwords(const std::string& str);

std::unordered_map<std::string, NvU32> parsestrdwords(const std::string& str, const std::set<std::string_view>& keys);
std::unordered_map<std::string_view, NvU32> parsestrdwords(const std::string& str, const std::set<std::string_view, str::CaseInsensitiveCompare<std::string_view>>& keys);
}
2 changes: 1 addition & 1 deletion tests/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST_CASE("String", "[.util]") {
}

SECTION("parsestrdwords") {
std::set<std::string_view> keys = {"DLSS", "DLSSG"};
std::set<std::string_view, dxvk::str::CaseInsensitiveCompare<std::string_view>> keys = {"DLSS", "DLSSG"};
auto map = dxvk::str::parsestrdwords(",dlss=1,DLSSG=0x2,invalid,,9,=,4=,=5,,0x104D6667=3", keys);
keys.clear();

Expand Down

0 comments on commit 3ed9a0a

Please sign in to comment.