Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Keep old settings data loading and one frame pacer

Leonardo Lobato06ee11eebacd
diff --git a/src/runtime/game_settings.cpp b/src/runtime/game_settings.cpp
index 18f727a..9d5388b 100644
--- a/src/runtime/game_settings.cpp
+++ b/src/runtime/game_settings.cpp
@@ -32,6 +32,10 @@ namespace storage_json = steam::json;
using platform::DirectoryPolicy;
using platform::ManagedDirectory;
+// Rows this build no longer has. Settings data written for an earlier build (presets, recipes) may still name them;
+// they are dropped where read, so the file still loads.
+bool RetiredSetting(std::string_view id) { return id == "opengl_thread"; }
+
SettingDefinition Choice(std::string id, std::string label, std::string effect, std::string also_called,
SettingTier tier, std::vector<SettingChoice> choices, std::string playden_default,
int phase = 1, ApplyMode apply = ApplyMode::kNextLaunch) {
@@ -353,6 +357,14 @@ std::string SoftwareFrameLimit(const EffectiveSettings& settings) {
return limit.value == "30" && refresh.available && refresh.value == "120" ? limit.value : std::string();
}
+// Whether Frame limit owns the game's frame cap: a cap set on a display-120hz runtime. One pacer at a time, so a
+// DXVK_FRAME_RATE or VKD3D_FRAME_RATE the player typed in Environment variables is then left out; with Off, or on an
+// older runtime, they apply as before.
+bool FrameLimitOwnsCap(const EffectiveSettings& settings) {
+ const auto& limit = OptionalValue(settings, "frame_limit");
+ return settings.display_120hz && limit.available && limit.value != "off";
+}
+
std::string Unavailable(const SettingDefinition& definition, const std::string& graphics, const KitCapabilities& kit,
const std::map<std::string, EffectiveValue>& values) {
const auto& id = definition.id;
@@ -944,6 +956,7 @@ bool RenderProsperoProfile(const GameRecipe& recipe, const EffectiveSettings& se
while (!item.empty() && item.front() == ' ') item.erase(0, 1);
while (!item.empty() && item.back() == ' ') item.pop_back();
if (!settings.environment_as_debug_env && IsProsperoEnvironmentEntry(name, item)) continue;
+ if (name == "DXVK_FRAME_RATE" && FrameLimitOwnsCap(settings)) continue;
if (!IsProsperoDebugEnvEntry(name, item) || count == kProsperoMaxDebugEnvEntries) continue;
lines += "env = " + name + "=" + item + "\n";
++count;
@@ -984,6 +997,7 @@ bool RenderProsperoProfile(const GameRecipe& recipe, const EffectiveSettings& se
while (!name.empty() && name.back() == ' ') name.pop_back();
while (!item.empty() && item.front() == ' ') item.erase(0, 1);
while (!item.empty() && item.back() == ' ') item.pop_back();
+ if (name == "DXVK_FRAME_RATE" && FrameLimitOwnsCap(settings)) continue;
if (!IsProsperoEnvironmentEntry(name, item) || environment_count == kProsperoMaxEnvironmentEntries) continue;
environment_lines += name + " = " + item + "\n";
++environment_count;
@@ -1192,10 +1206,12 @@ bool ParseGameRecipe(std::string_view text, GameRecipe* recipe, std::string* rea
out.launch_entries.push_back(std::move(entry));
}
if (!StringMap(root->get("defaults"), &out.defaults)) return fail("defaults must map setting ids to strings");
+ for (auto it = out.defaults.begin(); it != out.defaults.end();) it = RetiredSetting(it->first) ? out.defaults.erase(it) : std::next(it);
if (!StringMap(root->get("requirements"), &out.requirements)) return fail("requirements must map names to strings");
if (const auto* locked = root->get("locked")) {
if (!locked->array()) return fail("locked must be a list");
for (const auto& item : *locked->array()) {
+ if (item.string() && RetiredSetting(*item.string())) continue;
if (!item.string() || !FindSetting(*item.string())) return fail("locked names an unknown setting");
out.locked.insert(*item.string());
}
@@ -1246,6 +1262,7 @@ bool ParseSettingsPresets(std::string_view text, std::vector<SettingsPreset>* pr
!StringField(item, "try_when", &preset.try_when, false) ||
!StringField(item, "short_hint", &preset.short_hint, false) || !StringMap(item.get("settings"), &preset.settings))
return fail("preset needs id, name and string settings");
+ for (auto it = preset.settings.begin(); it != preset.settings.end();) it = RetiredSetting(it->first) ? preset.settings.erase(it) : std::next(it);
for (const auto& [id, value] : preset.settings) {
// Presets bundle choices and button bindings; launch entries, graphics and free text
// belong to the recipe or the player.
@@ -2238,10 +2255,13 @@ std::vector<RegistryValue> RenderBottleEnvironment(const EffectiveSettings& sett
while (!item.empty() && item.back() == ' ') item.pop_back();
if (IsBottleEnvironmentEntry(name, item)) listed[name] = item;
}
- // Frame limit 30 at 120 Hz output is vkd3d-proton's own limiter, since the display cannot pace it. It wins over a
- // VKD3D_FRAME_RATE typed in Environment variables, as the row the player sees.
- if (settings.display_120hz && settings.vkd3d_proton)
- if (const auto limit = SoftwareFrameLimit(settings); !limit.empty()) listed["VKD3D_FRAME_RATE"] = limit;
+ // A Frame limit on a display-120hz runtime replaces a VKD3D_FRAME_RATE typed in Environment variables: the display
+ // paces the cap, or, for 30 at 120 Hz output, vkd3d-proton's own limiter does.
+ if (FrameLimitOwnsCap(settings)) {
+ listed.erase("VKD3D_FRAME_RATE");
+ if (settings.vkd3d_proton)
+ if (const auto limit = SoftwareFrameLimit(settings); !limit.empty()) listed["VKD3D_FRAME_RATE"] = limit;
+ }
std::vector<RegistryValue> values;
for (const char* name : kBottleEnvironmentNames) {
const auto found = listed.find(name);
@@ -2955,6 +2975,8 @@ bool CommunityPresetSupported(const CommunityPreset& community, const KitCapabil
else if (feature == "input-tuning") { if (!kit.input_tuning) return false; }
else if (feature == "input-wheel") { if (!kit.input_wheel) return false; }
else if (feature == "audio-volume") { if (!kit.audio_volume) return false; }
+ // A runtime name, not a settings one: 120 Hz output counts only for a title on that runtime (KitForTitleRuntime).
+ else if (feature == "display-120hz") { if (!kit.display_120hz) return false; }
// Legacy PR references are informational sidecar provenance. Unknown feature
// names or version requirements need verified support before a preset is shown.
else if (feature.size() < 2 || feature.front() != '#' ||
diff --git a/src/runtime/game_settings.h b/src/runtime/game_settings.h
index 2b8a0b3..3b3217e 100644
--- a/src/runtime/game_settings.h
+++ b/src/runtime/game_settings.h
@@ -426,7 +426,8 @@ bool ParseCommunityRecipe(std::string_view json, CommunityRecipe* community, std
// Whether the kit's runtime has every newer profile feature the sidecar declares in
// requires.prospero_win: the kit capability names without "settings-" (profile-environment,
-// input-tuning, input-wheel, audio-volume; see prospero-win-profiles SIDECARS.md). Other entries
+// input-tuning, input-wheel, audio-volume; see prospero-win-profiles SIDECARS.md) and display-120hz, which needs the
+// game's own title on such a runtime: pass the kit as KitForTitleRuntime gives it for the game. Other entries
// (pull requests, versions) are not checked.
bool CommunityPresetSupported(const CommunityPreset& community, const KitCapabilities& kit);
diff --git a/tests/game_settings_test.cpp b/tests/game_settings_test.cpp
index f5b2d3f..deb0729 100644
--- a/tests/game_settings_test.cpp
+++ b/tests/game_settings_test.cpp
@@ -364,6 +364,29 @@ int main(int argc, char** argv) {
if (value.name == "VKD3D_FRAME_RATE") vkd3d_rate = value.data;
CHECK(vkd3d_rate.empty());
+ // One pacer: a Frame limit replaces frame-rate variables the player typed in Environment variables, both
+ // vkd3d-proton's (bottle environment) and DXVK's (profile); with Off they apply as before.
+ const auto bottle_rate = [](const EffectiveSettings& values) {
+ for (const auto& value : RenderBottleEnvironment(values))
+ if (value.name == "VKD3D_FRAME_RATE") return value.data;
+ return std::string();
+ };
+ CHECK(BuildEffectiveSettings(d3d12, nullptr, {{"refresh", "120"}, {"frame_limit", "60"},
+ {"environment", "VKD3D_FRAME_RATE=30; DXVK_FRAME_RATE=30"}}, display, &shown, &error));
+ CHECK(bottle_rate(shown).empty());
+ CHECK(RenderProsperoProfile(d3d12, shown, target, &profile, &reason));
+ CHECK(profile.text.find("DXVK_FRAME_RATE") == std::string::npos && profile.text.find("\nframe_rate = 60\n") != std::string::npos);
+ CHECK(BuildEffectiveSettings(d3d12, nullptr, {{"refresh", "120"}, {"frame_limit", "30"},
+ {"environment", "VKD3D_FRAME_RATE=60; DXVK_FRAME_RATE=60"}}, display, &shown, &error));
+ CHECK(bottle_rate(shown) == "\"30\"");
+ CHECK(RenderProsperoProfile(d3d12, shown, target, &profile, &reason));
+ CHECK(profile.text.find("DXVK_FRAME_RATE") == std::string::npos);
+ CHECK(BuildEffectiveSettings(d3d12, nullptr, {{"refresh", "120"},
+ {"environment", "VKD3D_FRAME_RATE=60; DXVK_FRAME_RATE=60"}}, display, &shown, &error));
+ CHECK(bottle_rate(shown) == "\"60\"");
+ CHECK(RenderProsperoProfile(d3d12, shown, target, &profile, &reason));
+ CHECK(profile.text.find("env = DXVK_FRAME_RATE=60\n") != std::string::npos);
+
// Mixed versions: the kit has the capability, the game's title still runs an older runtime. Frame limit keeps
// its DXVK behaviour, 120 Hz waits for Update, and the profile has no frame_rate an older runtime would refuse.
const auto stale = KitForTitleRuntime(display, false);
@@ -387,6 +410,10 @@ int main(int argc, char** argv) {
CHECK(BuildEffectiveSettings(d3d12, nullptr, {{"refresh", "120"}, {"frame_limit", "30"}}, stale, &shown, &error));
for (const auto& value : RenderBottleEnvironment(shown))
CHECK(value.name != "VKD3D_FRAME_RATE" || value.data.empty());
+ // An older runtime keeps the player's variables, as before.
+ CHECK(BuildEffectiveSettings(d3d12, nullptr, {{"frame_limit", "60"}, {"environment", "VKD3D_FRAME_RATE=30"}}, stale,
+ &shown, &error));
+ CHECK(bottle_rate(shown) == "\"30\"");
// Without the capability: 30 and 60 through maxFrameRate, 120 and 40 need a newer kit.
CHECK(BuildEffectiveSettings(hl2, nullptr, {{"frame_limit", "120"}}, dxvk_kit, &shown, &error));
CHECK(Value(shown, "frame_limit") == "off" && shown.values.at("frame_limit").reason == "Needs a runtime kit with 120 Hz output.");
@@ -400,7 +427,28 @@ int main(int argc, char** argv) {
CHECK(shown.values.at("vsync").reason == "The PS5 display always waits for the TV; VSync cannot be turned off yet.");
}
- // A record saved while the OpenGL worker thread row existed still loads, without it.
+ // A record saved while the OpenGL worker thread row existed still loads, without it, and so do settings data
+ // written for that build: the earlier presets.json, and a recipe that sets or locks the row.
+ {
+ std::vector<SettingsPreset> old_presets;
+ CHECK(ParseSettingsPresets(R"({"presets":[{"id":"playden-default","name":"Playden default","settings":{}},
+ {"id":"opengl-game","name":"OpenGL game","settings":{"refresh":"60","opengl_thread":"off"}}]})",
+ &old_presets, &reason));
+ CHECK(old_presets.size() == 2 &&
+ old_presets[1].settings == (std::map<std::string, std::string>{{"refresh", "60"}}));
+ // Other unknown settings are still refused.
+ CHECK(!ParseSettingsPresets(R"({"presets":[{"id":"x","name":"X","settings":{"opengl_threads":"off"}}]})",
+ &old_presets, &reason));
+ GameRecipe old_recipe;
+ CHECK(ParseGameRecipe(R"({"recipe_id":"old","recipe_version":1,"app_id":70,
+ "launch_entries":[{"id":"game","label":"Game","executable":"hl.exe"}],"graphics":"opengl",
+ "defaults":{"opengl_thread":"on","refresh":"60"},"locked":["opengl_thread","graphics"]})", &old_recipe, &reason));
+ CHECK(old_recipe.defaults == (std::map<std::string, std::string>{{"refresh", "60"}}) &&
+ old_recipe.locked == (std::set<std::string>{"graphics"}));
+ CHECK(!ParseGameRecipe(R"({"recipe_id":"old","recipe_version":1,"app_id":70,
+ "launch_entries":[{"id":"game","label":"Game","executable":"hl.exe"}],"locked":["opengl_threads"]})",
+ &old_recipe, &reason));
+ }
{
GameSettingsRecord old_record;
CHECK(ParseGameSettingsRecord(R"({"preset":"opengl-game","overrides":{"opengl_thread":"on","refresh":"120"}})",
@@ -770,6 +818,15 @@ int main(int argc, char** argv) {
CHECK(CommunityPresetSupported(needs_volume, KitCapabilitiesFromManifest({kKitAudioVolume}, false)));
needs_volume.requires_prospero_win.push_back("profile-environment");
CHECK(!CommunityPresetSupported(needs_volume, KitCapabilitiesFromManifest({kKitAudioVolume}, false)));
+ // 120 Hz output counts for a game whose title runs a display-120hz runtime.
+ {
+ auto needs_display = community;
+ needs_display.requires_prospero_win.push_back("display-120hz");
+ const auto display = KitCapabilitiesFromManifest({kKitDxvk, kKitDisplay120Hz}, false);
+ CHECK(CommunityPresetSupported(needs_display, display));
+ CHECK(!CommunityPresetSupported(needs_display, KitCapabilitiesFromManifest({kKitDxvk}, false)));
+ CHECK(!CommunityPresetSupported(needs_display, KitForTitleRuntime(display, false)));
+ }
CHECK(BuildEffectiveSettings(hl2, &community.preset, {}, KitCapabilities{}, &settings, &error));
CHECK(settings.values.at("controller").value == "keyboard");
CHECK(!ParseProfileSidecar(R"({"schema_version":2,"profile":"x","game":{"name":"X"},"checks":[{}]})", &community, &reason));