Review of 310c6eb: clwb race, skipped clzero loops, XCL licence, and a feature checklist. #682

Open
opened 2026-11-25 04:22:00 +00:00 by KeithDude · 2 comments
KeithDude commented 2026-11-25 04:22:00 +00:00 (Migrated from github.com)
Contributor

Imported from fxceless/victory-fork. Originally posted by KeithDude on 2026-11-25T04:22:00Z.


Three things in this fork (at 310c6eb) need fixing first: a race in the clwb patch that can corrupt memory, clzero loops that get skipped, and GPL-2.0-only code.

This is for you to test and push back on. The patches haven't been built or run inside the project, which only builds for Windows and needs the game. On their own, the snippets for fixes 3 to 5 compile, and fix 1's expected results match a simulation of the CPU's loop. Line numbers refer to 310c6eb; the base is Marvisak/VIctory at ffe310e.

Proposed fixes

Do fix 1 first. Switching to upstream's instruction emulation removes the memory-corruption race, the skipped clzero loops and the licence problem in one change. Fixes 2 to 5 are small; fix 6 is a plan for catching up with upstream.

1. Use upstream's instruction emulation instead of console_insn.rs

Why. The fork's handler runs before upstream's (crates/victory-loader/src/crash.rs:360-368) and brings three problems.

  • clwb race. console_insn.rs:140-150 patches clwb to NOPs in place, not in one atomic write, while other threads may be running that code. If only the leading 66 has been replaced, 0F AE /6 runs as XSAVEOPT. Depending on register values, that writes CPU state over the target memory or faults. Upstream at ffe310e already stepped over clwb without patching, so this is a regression.
  • clzero loops. A loop of 2 GiB or more, or one whose end is at or below its start, fails the check at console_insn.rs:171. It then reaches line 193 and is skipped without zeroing anything. Unaligned ranges zero less than the CPU would, and rax and the flags end up different. Upstream commit 0de9efc runs the loop line by line, as the CPU does.
  • Licence. console_insn.rs:5-6 says the decoder is XCL's code, unchanged, and XCL is GPL-2.0-only. That code can't ship in a GPL-3.0-or-later project, and README.md:22 says the XCL-inspired fixes were written anew.

Change.

  1. Delete console_insn.rs and console_insn_decode.rs, mod console_insn; (lib.rs:25) and the call at crash.rs:360-368.
  2. Take upstream's crash.rs changes from 0de9efc (clzero loops, rdpru) and 274f698 (clwb loop overflow guard), or get them by rebasing (fix 6).
  3. Search a run's log for Rdpid in the "a console CPU instruction this CPU lacks" line. Upstream has no RDPID emulation. If the title uses it, add it to upstream's handler as new code written from the CPU manuals, not from XCL.
  4. Correct README.md:22 to say what came from XCL.

Test.

  • A loop test that works on both CPU makers. Put these bytes in an executable page and call them as extern "win64" fn(usize, usize) -> usize, with the handler installed:
48 89 C8       mov rax, rcx
0F 01 FC       clzero
48 83 C0 40    add rax, 0x40
48 39 D0       cmp rax, rdx
72 F4          jb  (back to clzero)
C3             ret
  • Fill a buffer with 0xAA and run the loop over it. With n = max(1, ceil((end - start) / 64)), bytes from start & !63 up to (start & !63) + 64n should be zero and the rest untouched; the return value should be start + 64n. Cases: aligned, start + 10, end + 100, end at or below start, and a 3 GiB range (check the lines near its end). On AMD, clzero runs natively, so the test checks the expectation itself. On Intel it checks the emulation.
  • clwb needs a CPU without it, such as a 6th to 10th gen Intel Core desktop chip. Run a page holding clwb [rcx]; ret and check its bytes are unchanged afterwards.
  • Run to the prologue on your Intel machine and compare frame times and crashes.log with the current build.

2. Turn the unsafe-comment lint back on

Why. Cargo.toml:65 switches off undocumented_unsafe_blocks, which upstream keeps as a warning. Unsafe blocks grew from 808 to 1,118, many of them changing page protection or running inside exception handlers. The comment above that line says eleven blocks still lack a SAFETY: note.

Change. Write the eleven SAFETY: comments and set undocumented_unsafe_blocks = "warn". The comment at Cargo.toml:53 says "two style lints" but eight are switched off; fix those as the code is tidied.

Test. cargo clippy --workspace --all-targets --locked -- -D warnings passes; CI already runs it.

3. Check dump folders against the repository guard

Why. crates/victory-core/src/policy.rs:5-6 says every tool that writes game-derived output must call ensure_outside_repo first. Three new switches write the title's own shaders (.cdxil) without it, so a folder inside the clone puts game data one git add from a public repo:

  • VICTORY_SHADER_SAVE (crates/victory-gpu/src/pipeline.rs:141)
  • VICTORY_DUMP_MATCH (apps/victory/src/translate.rs:352)
  • VICTORY_FAIL_DUMP (apps/victory/src/translate.rs:381)

Upstream's VICTORY_CAPTURE (crates/victory-gpu/src/capture.rs:15) has the same gap, which would make a good upstream pull request.

Change. Check each folder once, before the first write, and skip the dump with a warning if the check fails. victory-gpu needs victory-core.workspace = true in its Cargo.toml; there's no cycle, because victory-core has no internal dependencies.

/// The folder VICTORY_SHADER_SAVE names, checked once: None when unset or
/// inside a VIctory source tree (docs/asset-policy.md).
fn shader_save_dir() -> Option<&'static std::path::Path> {
    static DIR: std::sync::OnceLock<Option<std::path::PathBuf>> = std::sync::OnceLock::new();
    DIR.get_or_init(|| {
        let dir = std::path::PathBuf::from(std::env::var_os("VICTORY_SHADER_SAVE")?);
        match victory_core::ensure_outside_repo(&dir) {
            Ok(()) => Some(dir),
            Err(e) => {
                tracing::warn!(%e, "VICTORY_SHADER_SAVE ignored");
                None
            }
        }
    })
    .as_deref()
}

// pipeline.rs:141, in place of the env lookup:
if let Some(dir) = shader_save_dir() {
    let _ = std::fs::create_dir_all(dir);
    // ...the existing writes, unchanged...
}

The other two sites follow the same pattern; for VICTORY_DUMP_MATCH, check the folder part before the ;.

Test. Point VICTORY_SHADER_SAVE at a folder inside the clone: expect one warning and no files. Point it outside: files appear as before.

4. Keep DirectStorage trace data only while tracing

Why. crates/victory-hle/src/modules/dstorage.rs:149 stores every opened file's name in WALLS_FILES, traced or not, and nothing removes entries. The lookup at line 471 takes the first match, so a reused address reports an old file's name.

Change.

// open_file: clone the name only when tracing
let kept = (walls_trace() > 0).then(|| name.clone());
// ...
if let Some(kept) = kept {
    WALLS_FILES.lock().unwrap_or_else(|e| e.into_inner()).push((file as usize, kept));
}

// walls_request, line 471: the newest entry for this address
files.iter().rev().find(|f| f.0 == source)

Test. With VICTORY_WALLS_TRACE=2, traced names match the files opened. With it unset, the list stays empty.

5. Small cleanups

  • dstorage.rs:1064 says the retries take "about 1.5 s in all". The sleeps add up to about 0.9 s: 2 to 64 ms, then 128 ms six times.
  • dstorage.rs:1083 reads last_os_error() after the sleeps and logging, so it may not be the failed write's error. Capture the error where write_physical fails.
  • There are now 146 VICTORY_* switches, up from 35 at ffe310e. Log the ones that are set once at startup, so bug reports show which were on:
/// Logs once, at startup, every VICTORY_* switch that is set. Path values are
/// left out: they name the user's folders.
pub fn log_switches() {
    let set: Vec<String> = std::env::vars()
        .filter(|(k, _)| k.starts_with("VICTORY_"))
        .map(|(k, v)| if v.contains(['/', '\\']) { k } else { format!("{k}={v}") })
        .collect();
    if !set.is_empty() {
        tracing::info!(switches = %set.join(" "), "switches set for this run");
    }
}

6. Catch up with upstream and keep authorship

Why. The fork is 319 commits behind upstream main (940d32f), and 250 of those commits touch files the fork changed. The most touched are emit/lower.rs (27 commits) and victory-gpu/src/host.rs (19). The fork's own work sits in one 32,334-line commit (578d459), so none of it can be reviewed, bisected or sent upstream piece by piece.

Change.

  1. Split 578d459 into topic branches: shader translator, descriptors and heaps, performance switches, ray tracing.
  2. Rebase each onto upstream main, dropping what upstream now does itself (fix 1).
  3. Send the general fixes upstream as pull requests, after checking upstream doesn't have them, so the fork's diff shrinks.
  4. When taking another fork's branch, keep its commits or add Co-authored-by: lines. 3bff182 (from asdaasdsaddf's fork) and 31714de (from triippywhale's fork) lost their authors when squashed.

Test. After each rebase, CI's clippy and test jobs pass, and a run reaches the prologue with the same frame times.

What the fork does well and what needs work

The fork's rendering and speed work is real and carefully measured. Its weak spots are engineering hygiene: history, checks and licensing.

Area Done well Needs work
Base and history Upstream's history is kept intact up to ffe310e, so the base is exactly VIctory's. Its own work is one 32,334-line commit, and the fork is 319 commits behind upstream (fix 6).
Rendering Per its README: the opening cutscene plays lit, the prologue shows characters, textures and sky, and HUD, pause and pad input work. Fixes include meshlet culling, descriptor exhaustion and 730 compute programs with invalid DXIL. Everything in shadow is black, and the first room's interior sometimes isn't drawn. It was tested on one PC (RTX 4070). By its own account, many changes suit only this title and GPU.
Ray tracing It emulates the one hardware ray-test instruction in DXIL rather than forcing DXR. A Rust reference is compared bit for bit with the GPU over 311 cases, and the builder stays off unless all its pipelines exist. Nothing is lit by it yet: the builder stays off in real runs, and 5 of 64 trace programs don't translate. Rounding and tie-break behaviour are assumed, and GPU cost is unmeasured.
Speed Changes are measured: 36 notes cite numbered runs. Examples: GPU idle time down from 136 to 30 ms per frame, and shader instructions down 43 %, worth about 20 ms of GPU time. It still runs at 2 to 4 fps. Most gains sit behind 146 switches that are off by default, with no central list.
Stability An intermittent device loss was traced to replacing the mapped pipeline library, then fixed and tested. A hang from the wave64 change was found and switched off. The clwb race and skipped clzero loops (fix 1). shortcut: approximations grew from 99 to 156.
Tests Tests grew from 352 to 527, including edge cases for truncated and oversized zlib streams. GPU tests skip without a hardware adapter, which CI's hosted runners don't have. The instruction emulation itself has no tests.
Safety The offline sandbox is untouched, and there are no binaries, downloads or build-script changes. The swap to zlib-rs is a genuine crate. Unsafe blocks grew from 808 to 1,118 with the comment lint off (fix 2). New dump switches skip the repo guard (fix 3).
Licence and credit It credits VIctory, XCL and Claude Code, and has taken the game's name out of the code. It ships GPL-2.0-only code, and the README says otherwise (fix 1). Merged branches lost their authors (fix 6).
Reviewability Comments explain why, with measurements and what was tried. 41,500 lines in about nine hours is more than anyone can review. Splitting the work (fix 6) is the way out.

Rendering and speed figures come from the fork's README and code comments. Confirming them needs the game and a GPU.

Feature-complete checklist

Thirty-one items stand between the fork and a complete build. The three that matter most for play are light in shadow, frame rate (2 to 4 fps against the title's 30) and memory (about 24 GB).

Upstream's code points to a TODO.md that isn't in either repo (display.rs:62); asking upstream's maintainer for it would fill gaps here.

Area Item Status What's left Source
Rendering Light in shadow Missing Anything the sun doesn't hit directly is black: the title's ray-traced bounce light and lamp and sun shadows don't run yet. fork README, ray-tracing notes
Rendering Ray-tracing structure builder Partial 49 of 52 builder programs translate, but the builder stays off in real runs: some pipelines need 64-lane waves or don't translate. ray-tracing notes
Rendering Shadow-mask trace programs Partial 59 of 64 trace programs translate; five shadow-mask ones don't. ray-tracing notes
Rendering Title pages without a host copy Missing A shader read of such a page gives zero, and a store to it is dropped. ray-tracing notes
Rendering Missing geometry Partial Upstream: a band of distant geometry. Fork: the first room's interior, sometimes, after the cutscene. upstream README, fork README
Rendering GPU queries Missing Real queries aren't implemented. upstream README
Rendering HDR output Missing Presentation is SDR only, and the title is told HDR is off. display.rs:61
Rendering Resolution scaling Missing Not done; VICTORY_WINDOW_MAX only scales the shown image. upstream README
Rendering Frame pacing Partial Drifts on one screen in release builds. upstream README
Rendering Render-target metadata planes Missing HTILE, CMASK, FMASK and DCC aren't added. Only needed if a title sizes a memory pool from console sizes and runs out. texture.rs:782
Shaders Merged geometry stages Missing 195 programs don't translate, and their draws are dropped. upstream README
Shaders Other untranslated programs Partial About 100 more, by upstream's count; the fork doesn't publish its own. upstream README
Shaders 64-lane programs on 32-lane GPUs Partial Some compute programs need 64-lane waves, which 32-lane GPUs such as NVIDIA's lack. The fork's wide barrier form hung, so it's off unless VICTORY_WAVE_WIDE=1. upstream README, fork README
Shaders Fused multiply-adds Partial Results follow the host GPU, not the console. upstream README
Performance World frame rate Partial 240 to 450 ms per frame (2 to 4 fps); the title targets 30 fps, about 33 ms. fork README
Performance Memory use Partial About 24 GB in use during play. fork README
Performance Loading Partial About 50 s into the world, limited by writes into title memory. upstream README
Performance Speed switches as defaults Partial Most speed changes sit behind switches that are off by default; promote the proven ones. fork README
Audio Reverb Missing Outputs are silence, so reverb returns are dry; the hardware's impulse-response layout is unknown. dsp.rs:12
Audio Narration (speech synthesis) Missing Silent. Needs SAPI or WinRT speech bindings, a voice list and the SSML the title sends. speech.rs:4
Audio Opus decoding Partial Decodes, but results aren't checked against the title. upstream README
Input Mouse Missing The GameInput mouse slot returns nothing, and the keyboard only stands in for a pad. gameinput.rs:1047; suggested
Input Trigger rumble Missing Not implemented. upstream README
Runtime services Text entry dialog and relaunch Partial Built, but not tested in a live run. upstream README
Runtime services Unimplemented interface methods Partial 144 log their slot when called (most in xstore, dstorage and xpackage), and 16 return E_NOTIMPL. victory census --missing lists every missing dll!function for a dump. dstorage.rs:5
Platform Series S mode Partial Reaches the loading screen; the world doesn't run yet. upstream README
Platform Console-only CPU instructions Partial Upstream emulates clzero, clwb, rdpru, monitorx, mwaitx and SSE4a, but not RDPID. The fork's RDPID is XCL code (fix 1). upstream crash.rs
Stability GPU hangs Partial Upstream warns a run can hang the GPU and reset the driver; the fork reports none in normal runs. upstream README, fork README
Stability Hardware coverage Missing Each project is tested on one PC: an AMD RX 6700 XT upstream, and an RTX 4070 with an i7-14700KF in the fork. Both READMEs; suggested
Release Running without building Missing Users must build from source with Rust and the MSVC tools. A signed official build would also give people a safe alternative to re-uploads. Suggested
Release GPU tests in CI Missing Hosted runners have no GPU, so GPU tests skip; a self-hosted runner with one would run them. Suggested

Online play is out of scope: the layer keeps the title offline by design. Rows marked "suggested" are on neither project's list; they're what a public release would need.

Sources

<!-- greyfinch-sync:fxceless/victory-fork:issue:6597147099 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/682). Originally posted by [KeithDude](https://github.com/KeithDude) on 2026-11-25T04:22:00Z. --- Three things in this fork (at `310c6eb`) need fixing first: a race in the `clwb` patch that can corrupt memory, `clzero` loops that get skipped, and GPL-2.0-only code. This is for you to test and push back on. The patches haven't been built or run inside the project, which only builds for Windows and needs the game. On their own, the snippets for fixes 3 to 5 compile, and fix 1's expected results match a simulation of the CPU's loop. Line numbers refer to `310c6eb`; the base is [Marvisak/VIctory](https://github.com/Marvisak/VIctory) at `ffe310e`. ## Proposed fixes Do fix 1 first. Switching to upstream's instruction emulation removes the memory-corruption race, the skipped `clzero` loops and the licence problem in one change. Fixes 2 to 5 are small; fix 6 is a plan for catching up with upstream. ### 1. Use upstream's instruction emulation instead of `console_insn.rs` **Why.** The fork's handler runs before upstream's (`crates/victory-loader/src/crash.rs:360-368`) and brings three problems. - **`clwb` race.** `console_insn.rs:140-150` patches `clwb` to NOPs in place, not in one atomic write, while other threads may be running that code. If only the leading `66` has been replaced, `0F AE /6` runs as `XSAVEOPT`. Depending on register values, that writes CPU state over the target memory or faults. Upstream at `ffe310e` already stepped over `clwb` without patching, so this is a regression. - **`clzero` loops.** A loop of 2 GiB or more, or one whose end is at or below its start, fails the check at `console_insn.rs:171`. It then reaches line 193 and is skipped without zeroing anything. Unaligned ranges zero less than the CPU would, and `rax` and the flags end up different. Upstream commit `0de9efc` runs the loop line by line, as the CPU does. - **Licence.** `console_insn.rs:5-6` says the decoder is XCL's code, unchanged, and XCL is GPL-2.0-only. That code can't ship in a GPL-3.0-or-later project, and `README.md:22` says the XCL-inspired fixes were written anew. **Change.** 1. Delete `console_insn.rs` and `console_insn_decode.rs`, `mod console_insn;` (`lib.rs:25`) and the call at `crash.rs:360-368`. 2. Take upstream's `crash.rs` changes from `0de9efc` (clzero loops, rdpru) and `274f698` (clwb loop overflow guard), or get them by rebasing (fix 6). 3. Search a run's log for `Rdpid` in the "a console CPU instruction this CPU lacks" line. Upstream has no RDPID emulation. If the title uses it, add it to upstream's handler as new code written from the CPU manuals, not from XCL. 4. Correct `README.md:22` to say what came from XCL. **Test.** - A loop test that works on both CPU makers. Put these bytes in an executable page and call them as `extern "win64" fn(usize, usize) -> usize`, with the handler installed: ```text 48 89 C8 mov rax, rcx 0F 01 FC clzero 48 83 C0 40 add rax, 0x40 48 39 D0 cmp rax, rdx 72 F4 jb (back to clzero) C3 ret ``` - Fill a buffer with `0xAA` and run the loop over it. With n = max(1, ceil((end - start) / 64)), bytes from `start & !63` up to `(start & !63) + 64n` should be zero and the rest untouched; the return value should be `start + 64n`. Cases: aligned, start + 10, end + 100, end at or below start, and a 3 GiB range (check the lines near its end). On AMD, `clzero` runs natively, so the test checks the expectation itself. On Intel it checks the emulation. - `clwb` needs a CPU without it, such as a 6th to 10th gen Intel Core desktop chip. Run a page holding `clwb [rcx]; ret` and check its bytes are unchanged afterwards. - Run to the prologue on your Intel machine and compare frame times and `crashes.log` with the current build. ### 2. Turn the unsafe-comment lint back on **Why.** `Cargo.toml:65` switches off `undocumented_unsafe_blocks`, which upstream keeps as a warning. Unsafe blocks grew from 808 to 1,118, many of them changing page protection or running inside exception handlers. The comment above that line says eleven blocks still lack a `SAFETY:` note. **Change.** Write the eleven `SAFETY:` comments and set `undocumented_unsafe_blocks = "warn"`. The comment at `Cargo.toml:53` says "two style lints" but eight are switched off; fix those as the code is tidied. **Test.** `cargo clippy --workspace --all-targets --locked -- -D warnings` passes; CI already runs it. ### 3. Check dump folders against the repository guard **Why.** `crates/victory-core/src/policy.rs:5-6` says every tool that writes game-derived output must call `ensure_outside_repo` first. Three new switches write the title's own shaders (`.cdxil`) without it, so a folder inside the clone puts game data one `git add` from a public repo: - `VICTORY_SHADER_SAVE` (`crates/victory-gpu/src/pipeline.rs:141`) - `VICTORY_DUMP_MATCH` (`apps/victory/src/translate.rs:352`) - `VICTORY_FAIL_DUMP` (`apps/victory/src/translate.rs:381`) Upstream's `VICTORY_CAPTURE` (`crates/victory-gpu/src/capture.rs:15`) has the same gap, which would make a good upstream pull request. **Change.** Check each folder once, before the first write, and skip the dump with a warning if the check fails. `victory-gpu` needs `victory-core.workspace = true` in its `Cargo.toml`; there's no cycle, because `victory-core` has no internal dependencies. ```rust /// The folder VICTORY_SHADER_SAVE names, checked once: None when unset or /// inside a VIctory source tree (docs/asset-policy.md). fn shader_save_dir() -> Option<&'static std::path::Path> { static DIR: std::sync::OnceLock<Option<std::path::PathBuf>> = std::sync::OnceLock::new(); DIR.get_or_init(|| { let dir = std::path::PathBuf::from(std::env::var_os("VICTORY_SHADER_SAVE")?); match victory_core::ensure_outside_repo(&dir) { Ok(()) => Some(dir), Err(e) => { tracing::warn!(%e, "VICTORY_SHADER_SAVE ignored"); None } } }) .as_deref() } // pipeline.rs:141, in place of the env lookup: if let Some(dir) = shader_save_dir() { let _ = std::fs::create_dir_all(dir); // ...the existing writes, unchanged... } ``` The other two sites follow the same pattern; for `VICTORY_DUMP_MATCH`, check the folder part before the `;`. **Test.** Point `VICTORY_SHADER_SAVE` at a folder inside the clone: expect one warning and no files. Point it outside: files appear as before. ### 4. Keep DirectStorage trace data only while tracing **Why.** `crates/victory-hle/src/modules/dstorage.rs:149` stores every opened file's name in `WALLS_FILES`, traced or not, and nothing removes entries. The lookup at line 471 takes the first match, so a reused address reports an old file's name. **Change.** ```rust // open_file: clone the name only when tracing let kept = (walls_trace() > 0).then(|| name.clone()); // ... if let Some(kept) = kept { WALLS_FILES.lock().unwrap_or_else(|e| e.into_inner()).push((file as usize, kept)); } // walls_request, line 471: the newest entry for this address files.iter().rev().find(|f| f.0 == source) ``` **Test.** With `VICTORY_WALLS_TRACE=2`, traced names match the files opened. With it unset, the list stays empty. ### 5. Small cleanups - `dstorage.rs:1064` says the retries take "about 1.5 s in all". The sleeps add up to about 0.9 s: 2 to 64 ms, then 128 ms six times. - `dstorage.rs:1083` reads `last_os_error()` after the sleeps and logging, so it may not be the failed write's error. Capture the error where `write_physical` fails. - There are now 146 `VICTORY_*` switches, up from 35 at `ffe310e`. Log the ones that are set once at startup, so bug reports show which were on: ```rust /// Logs once, at startup, every VICTORY_* switch that is set. Path values are /// left out: they name the user's folders. pub fn log_switches() { let set: Vec<String> = std::env::vars() .filter(|(k, _)| k.starts_with("VICTORY_")) .map(|(k, v)| if v.contains(['/', '\\']) { k } else { format!("{k}={v}") }) .collect(); if !set.is_empty() { tracing::info!(switches = %set.join(" "), "switches set for this run"); } } ``` ### 6. Catch up with upstream and keep authorship **Why.** The fork is 319 commits behind upstream `main` (`940d32f`), and 250 of those commits touch files the fork changed. The most touched are `emit/lower.rs` (27 commits) and `victory-gpu/src/host.rs` (19). The fork's own work sits in one 32,334-line commit (`578d459`), so none of it can be reviewed, bisected or sent upstream piece by piece. **Change.** 1. Split `578d459` into topic branches: shader translator, descriptors and heaps, performance switches, ray tracing. 2. Rebase each onto upstream `main`, dropping what upstream now does itself (fix 1). 3. Send the general fixes upstream as pull requests, after checking upstream doesn't have them, so the fork's diff shrinks. 4. When taking another fork's branch, keep its commits or add `Co-authored-by:` lines. `3bff182` (from asdaasdsaddf's fork) and `31714de` (from triippywhale's fork) lost their authors when squashed. **Test.** After each rebase, CI's clippy and test jobs pass, and a run reaches the prologue with the same frame times. ## What the fork does well and what needs work The fork's rendering and speed work is real and carefully measured. Its weak spots are engineering hygiene: history, checks and licensing. | Area | Done well | Needs work | | --- | --- | --- | | Base and history | Upstream's history is kept intact up to `ffe310e`, so the base is exactly VIctory's. | Its own work is one 32,334-line commit, and the fork is 319 commits behind upstream (fix 6). | | Rendering | Per its README: the opening cutscene plays lit, the prologue shows characters, textures and sky, and HUD, pause and pad input work. Fixes include meshlet culling, descriptor exhaustion and 730 compute programs with invalid DXIL. | Everything in shadow is black, and the first room's interior sometimes isn't drawn. It was tested on one PC (RTX 4070). By its own account, many changes suit only this title and GPU. | | Ray tracing | It emulates the one hardware ray-test instruction in DXIL rather than forcing DXR. A Rust reference is compared bit for bit with the GPU over 311 cases, and the builder stays off unless all its pipelines exist. | Nothing is lit by it yet: the builder stays off in real runs, and 5 of 64 trace programs don't translate. Rounding and tie-break behaviour are assumed, and GPU cost is unmeasured. | | Speed | Changes are measured: 36 notes cite numbered runs. Examples: GPU idle time down from 136 to 30 ms per frame, and shader instructions down 43 %, worth about 20 ms of GPU time. | It still runs at 2 to 4 fps. Most gains sit behind 146 switches that are off by default, with no central list. | | Stability | An intermittent device loss was traced to replacing the mapped pipeline library, then fixed and tested. A hang from the wave64 change was found and switched off. | The `clwb` race and skipped `clzero` loops (fix 1). `shortcut:` approximations grew from 99 to 156. | | Tests | Tests grew from 352 to 527, including edge cases for truncated and oversized zlib streams. | GPU tests skip without a hardware adapter, which CI's hosted runners don't have. The instruction emulation itself has no tests. | | Safety | The offline sandbox is untouched, and there are no binaries, downloads or build-script changes. The swap to `zlib-rs` is a genuine crate. | Unsafe blocks grew from 808 to 1,118 with the comment lint off (fix 2). New dump switches skip the repo guard (fix 3). | | Licence and credit | It credits VIctory, XCL and Claude Code, and has taken the game's name out of the code. | It ships GPL-2.0-only code, and the README says otherwise (fix 1). Merged branches lost their authors (fix 6). | | Reviewability | Comments explain why, with measurements and what was tried. | 41,500 lines in about nine hours is more than anyone can review. Splitting the work (fix 6) is the way out. | Rendering and speed figures come from the fork's README and code comments. Confirming them needs the game and a GPU. ## Feature-complete checklist Thirty-one items stand between the fork and a complete build. The three that matter most for play are light in shadow, frame rate (2 to 4 fps against the title's 30) and memory (about 24 GB). Upstream's code points to a `TODO.md` that isn't in either repo ([display.rs:62](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/crates/victory-hle/src/modules/display.rs#L62)); asking upstream's maintainer for it would fill gaps here. | Area | Item | Status | What's left | Source | | --- | --- | --- | --- | --- | | Rendering | Light in shadow | Missing | Anything the sun doesn't hit directly is black: the title's ray-traced bounce light and lamp and sun shadows don't run yet. | [fork README](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/README.md), [ray-tracing notes](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/docs/fork-ray-tracing.md) | | Rendering | Ray-tracing structure builder | Partial | 49 of 52 builder programs translate, but the builder stays off in real runs: some pipelines need 64-lane waves or don't translate. | [ray-tracing notes](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/docs/fork-ray-tracing.md) | | Rendering | Shadow-mask trace programs | Partial | 59 of 64 trace programs translate; five shadow-mask ones don't. | [ray-tracing notes](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/docs/fork-ray-tracing.md) | | Rendering | Title pages without a host copy | Missing | A shader read of such a page gives zero, and a store to it is dropped. | [ray-tracing notes](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/docs/fork-ray-tracing.md) | | Rendering | Missing geometry | Partial | Upstream: a band of distant geometry. Fork: the first room's interior, sometimes, after the cutscene. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md), [fork README](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/README.md) | | Rendering | GPU queries | Missing | Real queries aren't implemented. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Rendering | HDR output | Missing | Presentation is SDR only, and the title is told HDR is off. | [display.rs:61](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/crates/victory-hle/src/modules/display.rs#L61) | | Rendering | Resolution scaling | Missing | Not done; `VICTORY_WINDOW_MAX` only scales the shown image. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Rendering | Frame pacing | Partial | Drifts on one screen in release builds. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Rendering | Render-target metadata planes | Missing | HTILE, CMASK, FMASK and DCC aren't added. Only needed if a title sizes a memory pool from console sizes and runs out. | [texture.rs:782](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/crates/victory-formats/src/texture.rs#L782) | | Shaders | Merged geometry stages | Missing | 195 programs don't translate, and their draws are dropped. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Shaders | Other untranslated programs | Partial | About 100 more, by upstream's count; the fork doesn't publish its own. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Shaders | 64-lane programs on 32-lane GPUs | Partial | Some compute programs need 64-lane waves, which 32-lane GPUs such as NVIDIA's lack. The fork's wide barrier form hung, so it's off unless `VICTORY_WAVE_WIDE=1`. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md), [fork README](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/README.md) | | Shaders | Fused multiply-adds | Partial | Results follow the host GPU, not the console. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Performance | World frame rate | Partial | 240 to 450 ms per frame (2 to 4 fps); the title targets 30 fps, about 33 ms. | [fork README](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/README.md) | | Performance | Memory use | Partial | About 24 GB in use during play. | [fork README](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/README.md) | | Performance | Loading | Partial | About 50 s into the world, limited by writes into title memory. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Performance | Speed switches as defaults | Partial | Most speed changes sit behind switches that are off by default; promote the proven ones. | [fork README](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/README.md) | | Audio | Reverb | Missing | Outputs are silence, so reverb returns are dry; the hardware's impulse-response layout is unknown. | [dsp.rs:12](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/crates/victory-hle/src/modules/dsp.rs#L12) | | Audio | Narration (speech synthesis) | Missing | Silent. Needs SAPI or WinRT speech bindings, a voice list and the SSML the title sends. | [speech.rs:4](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/crates/victory-hle/src/modules/speech.rs#L4) | | Audio | Opus decoding | Partial | Decodes, but results aren't checked against the title. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Input | Mouse | Missing | The GameInput mouse slot returns nothing, and the keyboard only stands in for a pad. | [gameinput.rs:1047](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/crates/victory-hle/src/modules/gameinput.rs#L1047); suggested | | Input | Trigger rumble | Missing | Not implemented. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Runtime services | Text entry dialog and relaunch | Partial | Built, but not tested in a live run. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Runtime services | Unimplemented interface methods | Partial | 144 log their slot when called (most in xstore, dstorage and xpackage), and 16 return `E_NOTIMPL`. `victory census --missing` lists every missing `dll!function` for a dump. | [dstorage.rs:5](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/crates/victory-hle/src/modules/dstorage.rs#L5) | | Platform | Series S mode | Partial | Reaches the loading screen; the world doesn't run yet. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md) | | Platform | Console-only CPU instructions | Partial | Upstream emulates clzero, clwb, rdpru, monitorx, mwaitx and SSE4a, but not RDPID. The fork's RDPID is XCL code (fix 1). | [upstream crash.rs](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/crates/victory-loader/src/crash.rs#L200) | | Stability | GPU hangs | Partial | Upstream warns a run can hang the GPU and reset the driver; the fork reports none in normal runs. | [upstream README](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/README.md), [fork README](https://github.com/fxceless/victory-fork/blob/310c6eb6c16822ab95076aad61fce19bba86bb98/README.md) | | Stability | Hardware coverage | Missing | Each project is tested on one PC: an AMD RX 6700 XT upstream, and an RTX 4070 with an i7-14700KF in the fork. | Both READMEs; suggested | | Release | Running without building | Missing | Users must build from source with Rust and the MSVC tools. A signed official build would also give people a safe alternative to re-uploads. | Suggested | | Release | GPU tests in CI | Missing | Hosted runners have no GPU, so GPU tests skip; a self-hosted runner with one would run them. | Suggested | Online play is out of scope: the layer keeps the title offline by design. Rows marked "suggested" are on neither project's list; they're what a public release would need. ## Sources - [fxceless/victory-fork at `310c6eb`](https://github.com/fxceless/victory-fork/tree/310c6eb6c16822ab95076aad61fce19bba86bb98): the commit reviewed. - [Marvisak/VIctory at `940d32f`](https://github.com/Marvisak/VIctory/tree/940d32f69b22265690a0b5a15d6ded572ba33baf): upstream `main` at review time. The fork point is [`ffe310e`](https://github.com/Marvisak/VIctory/commit/ffe310eb2098e52169f4c44db5ffdabf43a72622). - Upstream commits [`0de9efc`](https://github.com/Marvisak/VIctory/commit/0de9efced179dfb523748f21cf4bdbe0d3aa7533) (clzero loops, rdpru) and [`274f698`](https://github.com/Marvisak/VIctory/commit/274f6988c9779b0612186c3448123e5e157d56e4) (clwb loop overflow guard). - [ivall/xcl](https://github.com/ivall/xcl): its `Cargo.toml` declares GPL-2.0-only, and its `crates/xcl/src/insn.rs` shares 194 lines with the fork's `console_insn_decode.rs`. - [zlib-rs 0.6.8 on crates.io](https://crates.io/crates/zlib-rs/0.6.8): the checksum in the fork's `Cargo.lock` matches the registry's.
kennymaakay commented 2026-11-25 06:06:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from fxceless/victory-fork. Originally posted by kennymaakay on 2026-11-25T05:56:27Z.


On the clwb race (fix 1) and on what the trapped waits cost on Intel, measured on an i9-9900 (Coffee Lake, no MONITORX/MWAITX/CLZERO/CLWB) + RTX 2080 SUPER 8 GB, Windows 11, first gameplay scene, standing still.

How often the handler runs. I added a per-second count by instruction kind to the loader (one line every 5 s, plus the process's user/kernel time from GetProcessTimes). With today's emulation:

per second monitorx mwaitx clzero loops insertq process CPU
emulated every time 95,000–133,000 95,000–133,000 ~8,000 ~300–600 0.45–0.55 cores user, 0.34–0.48 kernel
monitorx/mwaitx patched in place 0 0 ~8,000 ~300–600 0.4–0.6 user, 0.07–0.21 kernel

All of it comes from the two monitorx and two mwaitx sites in one wait loop of the title. So almost all of the process's kernel time was these traps. The frame rate did not change measurably (the loop is not on the submitting thread's path), but it frees about a third of a core.

A patch that cannot be seen half-done. Changing only the opcode byte after 0F turns each of these into a hint NOP of the same length, with the same prefixes, ModRM, SIB and displacement:

  • 0F 01 FA (monitorx) → 0F 1F FA
  • 0F 01 FB (mwaitx) → 0F 1F FB
  • 66 [REX] 0F AE /6 m (clwb) → 66 [REX] 0F 1F /6 m (a NOP Ew; it reads no memory)

A one-byte store is seen whole by every observer, instruction fetch included, so another thread runs either the old instruction (which traps and is handled as now) or the new one, never a mix, at any alignment. One of the four wait sites crosses an aligned 8-byte word, so a wider atomic store would not cover it. I do it with an AtomicU8 compare-exchange after VirtualProtect to RWX, restore the protection, then FlushInstructionCache; a thread that trapped on the old bytes but is handled after the patch sees the new bytes and runs them again. The trade-off: the patched mwaitx is a plain NOP, not pause, so that loop spins in user mode instead of trapping (getting pause back would need two bytes changed).

This sits on top of the current console_insn.rs. If the file goes away for upstream's handler as you propose, the same one-byte idea applies there for clwb (and for monitorx/mwaitx, if upstream ever traps them). I can open it as a PR against either base if that is useful.


Measured and written with AI assistance (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7154283596 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/682#issuecomment-7154283596). Originally posted by [kennymaakay](https://github.com/kennymaakay) on 2026-11-25T05:56:27Z. --- On the `clwb` race (fix 1) and on what the trapped waits cost on Intel, measured on an i9-9900 (Coffee Lake, no MONITORX/MWAITX/CLZERO/CLWB) + RTX 2080 SUPER 8 GB, Windows 11, first gameplay scene, standing still. **How often the handler runs.** I added a per-second count by instruction kind to the loader (one line every 5 s, plus the process's user/kernel time from `GetProcessTimes`). With today's emulation: | per second | monitorx | mwaitx | clzero loops | insertq | process CPU | |---|---|---|---|---|---| | emulated every time | 95,000–133,000 | 95,000–133,000 | ~8,000 | ~300–600 | 0.45–0.55 cores user, **0.34–0.48 kernel** | | monitorx/mwaitx patched in place | 0 | 0 | ~8,000 | ~300–600 | 0.4–0.6 user, **0.07–0.21 kernel** | All of it comes from the two monitorx and two mwaitx sites in one wait loop of the title. So almost all of the process's kernel time was these traps. The frame rate did not change measurably (the loop is not on the submitting thread's path), but it frees about a third of a core. **A patch that cannot be seen half-done.** Changing only the opcode byte after `0F` turns each of these into a hint NOP of the same length, with the same prefixes, ModRM, SIB and displacement: - `0F 01 FA` (monitorx) → `0F 1F FA` - `0F 01 FB` (mwaitx) → `0F 1F FB` - `66 [REX] 0F AE /6 m` (clwb) → `66 [REX] 0F 1F /6 m` (a NOP Ew; it reads no memory) A one-byte store is seen whole by every observer, instruction fetch included, so another thread runs either the old instruction (which traps and is handled as now) or the new one, never a mix, at any alignment. One of the four wait sites crosses an aligned 8-byte word, so a wider atomic store would not cover it. I do it with an `AtomicU8` compare-exchange after `VirtualProtect` to RWX, restore the protection, then `FlushInstructionCache`; a thread that trapped on the old bytes but is handled after the patch sees the new bytes and runs them again. The trade-off: the patched mwaitx is a plain NOP, not `pause`, so that loop spins in user mode instead of trapping (getting `pause` back would need two bytes changed). This sits on top of the current `console_insn.rs`. If the file goes away for upstream's handler as you propose, the same one-byte idea applies there for clwb (and for monitorx/mwaitx, if upstream ever traps them). I can open it as a PR against either base if that is useful. --- *Measured and written with AI assistance (Claude Code, Claude Opus 5.5).*
xyzMikah commented 2026-11-25 19:09:48 +00:00 (Migrated from github.com)
Author
Contributor

Imported from fxceless/victory-fork. Originally posted by xyzMikah on 2026-11-25T18:59:34Z.


Fix 3 is done on my branch.

All three dump writes now check the folder before writing and skip with a warning if it is inside the repo:

VICTORY_SHADER_SAVE
VICTORY_DUMP_MATCH
VICTORY_FAIL_DUMP

Each has a test. Tested on RTX 5060 Ti, Windows 11, Rust 1.98.1. Not tested with the game, since I don't own a copy.

How do outside contributors submit PRs here?

<!-- greyfinch-sync:fxceless/victory-fork:comment:7171676116 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/682#issuecomment-7171676116). Originally posted by [xyzMikah](https://github.com/xyzMikah) on 2026-11-25T18:59:34Z. --- Fix 3 is done on my branch. All three dump writes now check the folder before writing and skip with a warning if it is inside the repo: VICTORY_SHADER_SAVE VICTORY_DUMP_MATCH VICTORY_FAIL_DUMP Each has a test. Tested on RTX 5060 Ti, Windows 11, Rust 1.98.1. Not tested with the game, since I don't own a copy. How do outside contributors submit PRs here?
Sign in to join this conversation.
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#682
No description provided.