Fix crash, add quality preset, fix shader cache key (Issue #1504), ad… #1522

Open
pug205gti6 wants to merge 9 commits from upstream-pr/1522 into main
pug205gti6 commented 2026-11-28 23:44:49 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by pug205gti6 on 2026-11-28T23:44:49Z.


…d PC memory override

  • host.rs: Replace OnceLock with Mutex + retry for state prelude (fixes deterministic watchdog crash at +0x23cf683 on VRAM pressure; was poisoning on first OOM)
  • menu.rs: Add QUALITY PRESET item (LOW/MEDIUM/HIGH/MAX) with write_quality_preset() that updates game's settings.xml for next start
  • shader_cache.rs: Add VICTORY_WATER_TILE_SLOTS, VICTORY_WAVE_LOOP_SKIPS, VICTORY_MEMORY_NEAR, VICTORY_LDS_START to cache key (Issue #1504)
  • console.rs: Add VICTORY_TITLE_MEMORY_MB env var so layer reports real PC RAM

Tested: 11-15 fps stable, 0 crashes, 0 VRAM warnings on RTX 5050 8GB / Ryzen 7 260

<!-- greyfinch-sync:fxceless/victory-fork:issue:5545737710 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1522). Originally posted by [pug205gti6](https://github.com/pug205gti6) on 2026-11-28T23:44:49Z. --- …d PC memory override - host.rs: Replace OnceLock with Mutex + retry for state prelude (fixes deterministic watchdog crash at +0x23cf683 on VRAM pressure; was poisoning on first OOM) - menu.rs: Add QUALITY PRESET item (LOW/MEDIUM/HIGH/MAX) with write_quality_preset() that updates game's settings.xml for next start - shader_cache.rs: Add VICTORY_WATER_TILE_SLOTS, VICTORY_WAVE_LOOP_SKIPS, VICTORY_MEMORY_NEAR, VICTORY_LDS_START to cache key (Issue #1504) - console.rs: Add VICTORY_TITLE_MEMORY_MB env var so layer reports real PC RAM Tested: 11-15 fps stable, 0 crashes, 0 VRAM warnings on RTX 5050 8GB / Ryzen 7 260
ArturoWolff commented 2026-11-29 02:37:33 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ArturoWolff on 2026-11-29T02:37:33Z.


Thanks for addressing the cache key in #1504. One concern with the retry path in fe962e7, from source inspection (not a runtime test): None from HostList::prelude now means both “no work needed” and “required prelude could not be allocated.”

  • Line 6972 updates the depth-twin behind flags before allocation.
  • Line 7040 advances the tracked texture state before allocation as well.
  • Lines 7053–7063 can then return None without recording the barriers, twin copies or pending uploads. The caller still appends the dependent command list for submission.

So the skipped syncs are not necessarily retried on the next frame: the bookkeeping may already say the textures have been synchronized or transitioned, even though the GPU never saw that work. This could trade the original crash for incorrect rendering or resource-state errors under memory pressure.

Could the allocation failure be kept distinct from the no-work case, and the required prelude/state updates and dependent submission either succeed together or be deferred together? Until that behavior is established, I would keep the cache-key correction separate from the OOM recovery. No game or GPU testing was performed here.

— Written by Hermes Agent (Nous Research), on behalf of ArturoWolff.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7249545361 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1522#issuecomment-7249545361). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-29T02:37:33Z. --- Thanks for addressing the cache key in #1504. One concern with the retry path in `fe962e7`, from source inspection (not a runtime test): `None` from `HostList::prelude` now means both “no work needed” and “required prelude could not be allocated.” - [Line 6972](https://github.com/fxceless/victory-fork/blob/fe962e75db0eeda482a239908a390e46b866ca02/crates/victory-gpu/src/host.rs#L6960-L6973) updates the depth-twin `behind` flags before allocation. - [Line 7040](https://github.com/fxceless/victory-fork/blob/fe962e75db0eeda482a239908a390e46b866ca02/crates/victory-gpu/src/host.rs#L7039-L7047) advances the tracked texture state before allocation as well. - [Lines 7053–7063](https://github.com/fxceless/victory-fork/blob/fe962e75db0eeda482a239908a390e46b866ca02/crates/victory-gpu/src/host.rs#L7053-L7065) can then return `None` without recording the barriers, twin copies or pending uploads. The [caller](https://github.com/fxceless/victory-fork/blob/fe962e75db0eeda482a239908a390e46b866ca02/crates/victory-gpu/src/host.rs#L5818-L5828) still appends the dependent command list for submission. So the skipped syncs are not necessarily retried on the next frame: the bookkeeping may already say the textures have been synchronized or transitioned, even though the GPU never saw that work. This could trade the original crash for incorrect rendering or resource-state errors under memory pressure. Could the allocation failure be kept distinct from the no-work case, and the required prelude/state updates and dependent submission either succeed together or be deferred together? Until that behavior is established, I would keep the cache-key correction separate from the OOM recovery. No game or GPU testing was performed here. — Written by Hermes Agent (Nous Research), on behalf of ArturoWolff.
gingerninja85 commented 2026-11-29 04:16:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by gingerninja85 on 2026-11-29T04:16:36Z.


I independently reproduced #1504 on Windows at 368967f. The test calls the production cache-key function in a fresh child process for each setting because the key caches process settings in a OnceLock. On main, all three active switches (VICTORY_WATER_TILE_SLOTS, VICTORY_WAVE_LOOP_SKIPS, VICTORY_LDS_START) collided with the default key when set to 0. Applying only this PR’s cache-key hunk from 2c75336 made the regression pass. I did not exercise warm-cache shader loading or gameplay.

VICTORY_MEMORY_NEAR also changes the key with the hunk applied, but I found no code reading that switch on 368967f. I’d omit that entry unless the translator switch is being restored.

Reproduce with cargo test --locked -p victory-gpu --lib translation_switches_change_the_cache_key.

Regression test patch
diff --git a/crates/victory-gpu/src/shader_cache.rs b/crates/victory-gpu/src/shader_cache.rs
index 016c4dd..3ce0e16 100644
--- a/crates/victory-gpu/src/shader_cache.rs
+++ b/crates/victory-gpu/src/shader_cache.rs
@@ -448,3 +448,56 @@ mod tests {
         assert_eq!(decode(b"VSH0"), None);
     }
 }
+
+#[cfg(test)]
+#[test]
+fn translation_switches_change_the_cache_key() {
+    use std::process::Command;
+
+    const CHILD: &str = "VICTORY_TEST_SHADER_CACHE_KEY_CHILD";
+    const MARKER: &str = "VICTORY_TEST_SHADER_CACHE_KEY=";
+    const SWITCHES: [&str; 3] = [
+        "VICTORY_WATER_TILE_SLOTS",
+        "VICTORY_WAVE_LOOP_SKIPS",
+        "VICTORY_LDS_START",
+    ];
+
+    if std::env::var_os(CHILD).is_some() {
+        let hash = blake3::Hash::from_bytes(build());
+        println!("{MARKER}{}", hash.to_hex());
+        return;
+    }
+
+    // The production key caches process settings in a OnceLock.
+    let key = |disabled: Option<&str>| {
+        let mut command = Command::new(std::env::current_exe().unwrap());
+        command.args([
+            "--exact",
+            "shader_cache::translation_switches_change_the_cache_key",
+            "--nocapture",
+        ]);
+        command.env(CHILD, "1");
+        for name in SWITCHES {
+            command.env_remove(name);
+        }
+        if let Some(name) = disabled {
+            command.env(name, "0");
+        }
+        let output = command.output().expect("run cache-key child process");
+        assert!(output.status.success(), "{output:?}");
+        let stdout = String::from_utf8(output.stdout).unwrap();
+        stdout
+            .lines()
+            .find_map(|line| line.strip_prefix(MARKER))
+            .expect("child printed its shader cache key")
+            .to_owned()
+    };
+
+    let default = key(None);
+    let collisions: Vec<_> = SWITCHES
+        .into_iter()
+        .filter(|name| key(Some(name)) == default)
+        .collect();
+    assert_eq!(key(None), default, "default key changed between processes");
+    assert!(collisions.is_empty(), "switches missing from the cache key: {collisions:?}");
+}

Prepared with AI assistance.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7250555231 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1522#issuecomment-7250555231). Originally posted by [gingerninja85](https://github.com/gingerninja85) on 2026-11-29T04:16:36Z. --- I independently reproduced #1504 on Windows at `368967f`. The test calls the production cache-key function in a fresh child process for each setting because the key caches process settings in a `OnceLock`. On `main`, all three active switches (`VICTORY_WATER_TILE_SLOTS`, `VICTORY_WAVE_LOOP_SKIPS`, `VICTORY_LDS_START`) collided with the default key when set to `0`. Applying only this PR’s cache-key hunk from `2c75336` made the regression pass. I did not exercise warm-cache shader loading or gameplay. `VICTORY_MEMORY_NEAR` also changes the key with the hunk applied, but I found no code reading that switch on `368967f`. I’d omit that entry unless the translator switch is being restored. Reproduce with `cargo test --locked -p victory-gpu --lib translation_switches_change_the_cache_key`. <details> <summary>Regression test patch</summary> ```diff diff --git a/crates/victory-gpu/src/shader_cache.rs b/crates/victory-gpu/src/shader_cache.rs index 016c4dd..3ce0e16 100644 --- a/crates/victory-gpu/src/shader_cache.rs +++ b/crates/victory-gpu/src/shader_cache.rs @@ -448,3 +448,56 @@ mod tests { assert_eq!(decode(b"VSH0"), None); } } + +#[cfg(test)] +#[test] +fn translation_switches_change_the_cache_key() { + use std::process::Command; + + const CHILD: &str = "VICTORY_TEST_SHADER_CACHE_KEY_CHILD"; + const MARKER: &str = "VICTORY_TEST_SHADER_CACHE_KEY="; + const SWITCHES: [&str; 3] = [ + "VICTORY_WATER_TILE_SLOTS", + "VICTORY_WAVE_LOOP_SKIPS", + "VICTORY_LDS_START", + ]; + + if std::env::var_os(CHILD).is_some() { + let hash = blake3::Hash::from_bytes(build()); + println!("{MARKER}{}", hash.to_hex()); + return; + } + + // The production key caches process settings in a OnceLock. + let key = |disabled: Option<&str>| { + let mut command = Command::new(std::env::current_exe().unwrap()); + command.args([ + "--exact", + "shader_cache::translation_switches_change_the_cache_key", + "--nocapture", + ]); + command.env(CHILD, "1"); + for name in SWITCHES { + command.env_remove(name); + } + if let Some(name) = disabled { + command.env(name, "0"); + } + let output = command.output().expect("run cache-key child process"); + assert!(output.status.success(), "{output:?}"); + let stdout = String::from_utf8(output.stdout).unwrap(); + stdout + .lines() + .find_map(|line| line.strip_prefix(MARKER)) + .expect("child printed its shader cache key") + .to_owned() + }; + + let default = key(None); + let collisions: Vec<_> = SWITCHES + .into_iter() + .filter(|name| key(Some(name)) == default) + .collect(); + assert_eq!(key(None), default, "default key changed between processes"); + assert!(collisions.is_empty(), "switches missing from the cache key: {collisions:?}"); +} ``` </details> Prepared with AI assistance.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1522:upstream-pr/1522'
git switch 'upstream-pr/1522'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1522'
git switch 'upstream-pr/1522'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1522'
git switch 'upstream-pr/1522'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1522'
git switch 'main'
git merge --squash 'upstream-pr/1522'
git switch 'main'
git merge --ff-only 'upstream-pr/1522'
git switch 'main'
git merge 'upstream-pr/1522'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!1522
No description provided.