Skip to content

Commit

Permalink
Version 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RavenSystem committed Dec 3, 2023
1 parent c0f705b commit 6a71511
Show file tree
Hide file tree
Showing 16 changed files with 538 additions and 89 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
VR Performance Toolkit RavenSystem's Fork
=========================================

[![Donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://paypal.me/ravensystem)

In an effort to continue this project, I have created this fork with updated components and SDKs. I added too some
improvements, like HRM and dynamic modes, and other compatibility options.

Expand All @@ -12,11 +14,15 @@ Included mods:
* AMD FidelityFX Super Resolution
* NVIDIA Image Scaling
* AMD Contrast Adaptive Sharpening
* FFR: Fixed foveated rendering (render center of image at full resolution, but drop resolution towards edges)
* Variable Rate Shading (only for NVIDIA RTX / GTX 16xx cards)
* FFR: Fixed foveated rendering: render center of image at full resolution, but drop resolution towards edges
* VRS: Variable Rate Shading (only for NVIDIA RTX / GTX 16xx cards)
* RDM: Radial Density Mask (all GPUs)
* HRM: Hidden radial mask: don't render pixels at the edges that are not visible in the headset.
Many games already use this mask, but not all. This mod will allow you to force its usage.
* Dynamic modes for FFR and HRM to apply only to keep target FPS.
* Dynamic modes for FFR and HRM based on FPS:
* Apply only when needed.
* Change the radius dinamically.
* Several extra compatibility options to work with more games.

Supported VR runtimes:

Expand Down
67 changes: 60 additions & 7 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ namespace vrperfkit {
case UpscaleMethod::CAS:
return "CAS";
}

return "Unknown";
}

FixedFoveatedMethod FFRMethodFromString(std::string s) {
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
if (s == "vrs") {
return FixedFoveatedMethod::VRS;
}
if (s == "rdm") {
return FixedFoveatedMethod::RDM;
}
LOG_INFO << "Unknown fixed foveated method " << s << ", defaulting to VRS";
return FixedFoveatedMethod::VRS;
}
Expand All @@ -47,7 +52,11 @@ namespace vrperfkit {
switch (method) {
case FixedFoveatedMethod::VRS:
return "VRS";
case FixedFoveatedMethod::RDM:
return "RDM";
}

return "Unknown";
}

GameMode GameModeFromString(std::string s) {
Expand Down Expand Up @@ -79,6 +88,8 @@ namespace vrperfkit {
case GameMode::RIGHT_EYE_FIRST:
return "right";
}

return "Unknown";
}

std::string PrintToggle(bool toggle) {
Expand Down Expand Up @@ -122,15 +133,22 @@ namespace vrperfkit {
FixedFoveatedConfig &ffr = g_config.ffr;
ffr.enabled = ffrCfg["enabled"].as<bool>(ffr.enabled);
ffr.apply = ffr.enabled;
ffr.method = FFRMethodFromString(ffrCfg["method"].as<std::string>(FFRMethodToString(ffr.method)));
ffr.favorHorizontal = ffrCfg["favorHorizontal"].as<bool>(ffr.favorHorizontal);
ffr.innerRadius = ffrCfg["innerRadius"].as<float>(ffr.innerRadius);
ffr.midRadius = ffrCfg["midRadius"].as<float>(ffr.midRadius);
ffr.outerRadius = ffrCfg["outerRadius"].as<float>(ffr.outerRadius);
ffr.edgeRadius = ffrCfg["edgeRadius"].as<float>(ffr.edgeRadius);
ffr.preciseResolution = ffrCfg["preciseResolution"].as<bool>(ffr.preciseResolution);
ffr.ignoreFirstTargetRenders = ffrCfg["ignoreFirstTargetRenders"].as<int>(ffr.ignoreFirstTargetRenders);
ffr.ignoreLastTargetRenders = ffrCfg["ignoreLastTargetRenders"].as<int>(ffr.ignoreLastTargetRenders);
ffr.maxRadius = ffr.innerRadius;
ffr.overrideSingleEyeOrder = ffrCfg["overrideSingleEyeOrder"].as<std::string>(ffr.overrideSingleEyeOrder);
ffr.fastMode = ffrCfg["fastMode"].as<bool>(ffr.fastMode);
g_config.ffrFastModeUsesHRMCount = ffrCfg["fastModeUsesHRMCount"].as<bool>(g_config.ffrFastModeUsesHRMCount);
if (!ffr.fastMode) {
g_config.ffrFastModeUsesHRMCount = false;
}
ffr.dynamic = ffrCfg["dynamic"].as<bool>(ffr.dynamic);
ffr.targetFrameTime = 1.f / ffrCfg["targetFPS"].as<float>(ffr.targetFrameTime);
ffr.marginFrameTime = 1.f / ffrCfg["marginFPS"].as<float>(ffr.marginFrameTime);
Expand All @@ -142,10 +160,11 @@ namespace vrperfkit {
YAML::Node hiddenMaskCfg = cfg["hiddenMask"];
HiddenRadialMask &hiddenMask= g_config.hiddenMask;
hiddenMask.enabled = hiddenMaskCfg["enabled"].as<bool>(hiddenMask.enabled);
hiddenMask.radius = std::max(0.f, hiddenMaskCfg["radius"].as<float>(hiddenMask.radius));
hiddenMask.maxRadius = hiddenMask.radius;
hiddenMask.edgeRadius = std::max(0.f, hiddenMaskCfg["edgeRadius"].as<float>(hiddenMask.edgeRadius));
hiddenMask.maxRadius = hiddenMask.edgeRadius;
hiddenMask.preciseResolution = hiddenMaskCfg["preciseResolution"].as<bool>(hiddenMask.preciseResolution);
hiddenMask.ignoreFirstTargetRenders = hiddenMaskCfg["ignoreFirstTargetRenders"].as<int>(hiddenMask.ignoreFirstTargetRenders);
hiddenMask.ignoreLastTargetRenders = hiddenMaskCfg["ignoreLastTargetRenders"].as<int>(hiddenMask.ignoreLastTargetRenders);
hiddenMask.dynamic = hiddenMaskCfg["dynamic"].as<bool>(hiddenMask.dynamic);
hiddenMask.targetFrameTime = 1.f / hiddenMaskCfg["targetFPS"].as<float>(hiddenMask.targetFrameTime);
hiddenMask.marginFrameTime = 1.f / hiddenMaskCfg["marginFPS"].as<float>(hiddenMask.marginFrameTime);
Expand All @@ -163,6 +182,31 @@ namespace vrperfkit {
if (g_config.dynamicFramesCheck < 1) {
g_config.dynamicFramesCheck = 1;
}

if (g_config.ffr.enabled) {
if (g_config.ffr.method == FixedFoveatedMethod::RDM) {
g_config.ffr.fastMode = false;
g_config.ffrFastModeUsesHRMCount = false;
g_config.hiddenMask.enabled = false;

if (!g_config.upscaling.enabled) {
g_config.upscaling.enabled = true;
g_config.upscaling.radius = g_config.ffr.edgeRadius;
g_config.upscaling.method = UpscaleMethod::CAS;
g_config.upscaling.renderScale = 1.0f;
g_config.upscaling.sharpness = 0.7f;
g_config.upscaling.applyMipBias = false;
}

} else if (g_config.ffr.method == FixedFoveatedMethod::VRS && !g_config.hiddenMask.enabled && g_config.ffrFastModeUsesHRMCount) {
g_config.hiddenMask.enabled = true;
g_config.hiddenMask.dynamic = false;
g_config.hiddenMask.edgeRadius = 1.15f;
g_config.hiddenMask.ignoreFirstTargetRenders = 0;
g_config.hiddenMask.ignoreLastTargetRenders = 0;
g_config.hiddenMask.preciseResolution = true;
}
}
}
catch (const YAML::Exception &e) {
LOG_ERROR << "Failed to load configuration file: " << e.msg;
Expand Down Expand Up @@ -190,12 +234,18 @@ namespace vrperfkit {
LOG_INFO << " * Inner radius: " << std::setprecision(6) << g_config.ffr.innerRadius;
LOG_INFO << " * Mid radius: " << std::setprecision(6) << g_config.ffr.midRadius;
LOG_INFO << " * Outer radius: " << std::setprecision(6) << g_config.ffr.outerRadius;
if (g_config.ffr.method == FixedFoveatedMethod::RDM) {
LOG_INFO << " * Edge radius: " << std::setprecision(6) << g_config.ffr.edgeRadius;
}
LOG_INFO << " * Precise res: " << PrintToggle(g_config.ffr.preciseResolution);
LOG_INFO << " * No renders: " << std::setprecision(6) << g_config.ffr.ignoreFirstTargetRenders;
if (!g_config.ffr.overrideSingleEyeOrder.empty()) {
LOG_INFO << " * No first rend: " << std::setprecision(6) << g_config.ffr.ignoreFirstTargetRenders;
LOG_INFO << " * No last rend: " << std::setprecision(6) << g_config.ffr.ignoreLastTargetRenders;
LOG_INFO << " * Fast mode: " << PrintToggle(g_config.ffr.fastMode);
if (g_config.ffr.fastMode) {
LOG_INFO << " * HRM counter: " << PrintToggle(g_config.ffrFastModeUsesHRMCount);
} else if (!g_config.ffr.overrideSingleEyeOrder.empty()) {
LOG_INFO << " * Eye order: " << g_config.ffr.overrideSingleEyeOrder;
}
LOG_INFO << " * Fast mode: " << PrintToggle(g_config.ffr.fastMode);
LOG_INFO << " * Dynamic: " << PrintToggle(g_config.ffr.dynamic);
if (g_config.ffr.dynamic) {
LOG_INFO << " * Target FPS: " << std::setprecision(6) << (1.f / g_config.ffr.targetFrameTime);
Expand All @@ -211,12 +261,15 @@ namespace vrperfkit {
}
} else {
g_config.ffr.dynamic = false;
g_config.ffr.fastMode = false;
}

LOG_INFO << " Hidden radial mask is " << PrintToggle(g_config.hiddenMask.enabled);
if (g_config.hiddenMask.enabled) {
LOG_INFO << " * Radius: " << std::setprecision(6) << g_config.hiddenMask.radius;
LOG_INFO << " * Edge radius: " << std::setprecision(6) << g_config.hiddenMask.edgeRadius;
LOG_INFO << " * Precise res: " << PrintToggle(g_config.hiddenMask.preciseResolution);
LOG_INFO << " * No renders: " << std::setprecision(6) << g_config.hiddenMask.ignoreFirstTargetRenders;
LOG_INFO << " * No first rend: " << std::setprecision(6) << g_config.hiddenMask.ignoreFirstTargetRenders;
LOG_INFO << " * No last rend: " << std::setprecision(6) << g_config.hiddenMask.ignoreLastTargetRenders;
LOG_INFO << " * Dynamic: " << PrintToggle(g_config.hiddenMask.dynamic);
if (g_config.hiddenMask.dynamic) {
LOG_INFO << " * Target FPS: " << std::setprecision(6) << (1.f / g_config.hiddenMask.targetFrameTime);
Expand Down
10 changes: 8 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace vrperfkit {
float innerRadius = 0.50f;
float midRadius = 0.65f;
float outerRadius = 0.80f;
float edgeRadius = 1.15f;
bool favorHorizontal = true;
std::string overrideSingleEyeOrder;
bool fastMode = false;
Expand All @@ -42,12 +43,13 @@ namespace vrperfkit {
float increaseRadiusStep = 0.03f;
bool preciseResolution = true;
int ignoreFirstTargetRenders = 0;
int ignoreLastTargetRenders = 0;
bool radiusChanged[2] = { true, true };
};

struct HiddenRadialMask {
bool enabled = false;
float radius = 1.15f;
float edgeRadius = 1.15f;
bool dynamic = false;
bool dynamicChangeRadius = false;
float targetFrameTime = 0.0167f;
Expand All @@ -58,14 +60,18 @@ namespace vrperfkit {
float increaseRadiusStep = 0.03f;
bool preciseResolution = true;
int ignoreFirstTargetRenders = 0;
int ignoreLastTargetRenders = 0;
};

struct Config {
UpscaleConfig upscaling;
DxvkConfig dxvk;
GameMode gameMode = GameMode::AUTO;
bool renderingSecondEye = false;
int ffrDepthClearCount = 0;
bool ffrFastModeUsesHRMCount = false;
bool ffrApplyFastMode = true;
int ffrRenderTargetCount = 0;
int ffrRenderTargetCountMax = 0;
FixedFoveatedConfig ffr;
HiddenRadialMask hiddenMask;
bool debugMode = false;
Expand Down
8 changes: 4 additions & 4 deletions src/d3d11/d3d11_injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,28 @@ namespace vrperfkit {
context->SetPrivateData(__uuidof(D3D11Injector), size, &instance);

// Upscaling and FFR
if (g_config.upscaling.enabled || g_config.ffr.enabled) {
if (g_config.upscaling.enabled || (g_config.ffr.enabled && g_config.ffr.method == FixedFoveatedMethod::VRS)) {
hooks::InstallVirtualFunctionHook("ID3D11DeviceContext::PSSetSamplers", context.Get(), 10, (void*)&D3D11ContextHook_PSSetSamplers);
hooks::InstallVirtualFunctionHook("ID3D11DeviceContext::OMSetRenderTargets", context.Get(), 33, (void*)&D3D11ContextHook_OMSetRenderTargets);
hooks::InstallVirtualFunctionHook("ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews", context.Get(), 34, (void*)&D3D11ContextHook_OMSetRenderTargetsAndUnorderedAccessViews);
}

// HRM
if (g_config.hiddenMask.enabled) {
if (g_config.hiddenMask.enabled || (g_config.ffr.enabled && g_config.ffr.method == FixedFoveatedMethod::RDM)) {
hooks::InstallVirtualFunctionHook("ID3D11DeviceContext::ClearDepthStencilView", context.Get(), 53, (void*)&D3D11ContextHook_ClearDepthStencilView);
}
}

D3D11Injector::~D3D11Injector() {
// Upscaling && FFR
if (g_config.upscaling.enabled || g_config.ffr.enabled) {
if (g_config.upscaling.enabled || (g_config.ffr.enabled && g_config.ffr.method == FixedFoveatedMethod::VRS)) {
hooks::RemoveHook((void*)&D3D11ContextHook_PSSetSamplers);
hooks::RemoveHook((void*)&D3D11ContextHook_OMSetRenderTargets);
hooks::RemoveHook((void*)&D3D11ContextHook_OMSetRenderTargetsAndUnorderedAccessViews);
}

// HRM
if (g_config.hiddenMask.enabled) {
if (g_config.hiddenMask.enabled || (g_config.ffr.enabled && g_config.ffr.method == FixedFoveatedMethod::RDM)) {
hooks::RemoveHook((void*)&D3D11ContextHook_ClearDepthStencilView);
}

Expand Down
Loading

0 comments on commit 6a71511

Please sign in to comment.