Review of 310c6eb: clwb race, skipped clzero loops, XCL licence, and a feature checklist. #682
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 theclwbpatch that can corrupt memory,clzeroloops 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 atffe310e.Proposed fixes
Do fix 1 first. Switching to upstream's instruction emulation removes the memory-corruption race, the skipped
clzeroloops 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.rsWhy. The fork's handler runs before upstream's (
crates/victory-loader/src/crash.rs:360-368) and brings three problems.clwbrace.console_insn.rs:140-150patchesclwbto NOPs in place, not in one atomic write, while other threads may be running that code. If only the leading66has been replaced,0F AE /6runs asXSAVEOPT. Depending on register values, that writes CPU state over the target memory or faults. Upstream atffe310ealready stepped overclwbwithout patching, so this is a regression.clzeroloops. A loop of 2 GiB or more, or one whose end is at or below its start, fails the check atconsole_insn.rs:171. It then reaches line 193 and is skipped without zeroing anything. Unaligned ranges zero less than the CPU would, andraxand the flags end up different. Upstream commit0de9efcruns the loop line by line, as the CPU does.console_insn.rs:5-6says 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, andREADME.md:22says the XCL-inspired fixes were written anew.Change.
console_insn.rsandconsole_insn_decode.rs,mod console_insn;(lib.rs:25) and the call atcrash.rs:360-368.crash.rschanges from0de9efc(clzero loops, rdpru) and274f698(clwb loop overflow guard), or get them by rebasing (fix 6).Rdpidin 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.README.md:22to say what came from XCL.Test.
extern "win64" fn(usize, usize) -> usize, with the handler installed:0xAAand run the loop over it. With n = max(1, ceil((end - start) / 64)), bytes fromstart & !63up to(start & !63) + 64nshould be zero and the rest untouched; the return value should bestart + 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,clzeroruns natively, so the test checks the expectation itself. On Intel it checks the emulation.clwbneeds a CPU without it, such as a 6th to 10th gen Intel Core desktop chip. Run a page holdingclwb [rcx]; retand check its bytes are unchanged afterwards.crashes.logwith the current build.2. Turn the unsafe-comment lint back on
Why.
Cargo.toml:65switches offundocumented_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 aSAFETY:note.Change. Write the eleven
SAFETY:comments and setundocumented_unsafe_blocks = "warn". The comment atCargo.toml:53says "two style lints" but eight are switched off; fix those as the code is tidied.Test.
cargo clippy --workspace --all-targets --locked -- -D warningspasses; CI already runs it.3. Check dump folders against the repository guard
Why.
crates/victory-core/src/policy.rs:5-6says every tool that writes game-derived output must callensure_outside_repofirst. Three new switches write the title's own shaders (.cdxil) without it, so a folder inside the clone puts game data onegit addfrom 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-gpuneedsvictory-core.workspace = truein itsCargo.toml; there's no cycle, becausevictory-corehas no internal dependencies.The other two sites follow the same pattern; for
VICTORY_DUMP_MATCH, check the folder part before the;.Test. Point
VICTORY_SHADER_SAVEat 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:149stores every opened file's name inWALLS_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.
Test. With
VICTORY_WALLS_TRACE=2, traced names match the files opened. With it unset, the list stays empty.5. Small cleanups
dstorage.rs:1064says 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:1083readslast_os_error()after the sleeps and logging, so it may not be the failed write's error. Capture the error wherewrite_physicalfails.VICTORY_*switches, up from 35 atffe310e. Log the ones that are set once at startup, so bug reports show which were on: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 areemit/lower.rs(27 commits) andvictory-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.
578d459into topic branches: shader translator, descriptors and heaps, performance switches, ray tracing.main, dropping what upstream now does itself (fix 1).Co-authored-by:lines.3bff182(from asdaasdsaddf's fork) and31714de(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.
ffe310e, so the base is exactly VIctory's.clwbrace and skippedclzeroloops (fix 1).shortcut:approximations grew from 99 to 156.zlib-rsis a genuine crate.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.mdthat isn't in either repo (display.rs:62); asking upstream's maintainer for it would fill gaps here.VICTORY_WINDOW_MAXonly scales the shown image.VICTORY_WAVE_WIDE=1.E_NOTIMPL.victory census --missinglists every missingdll!functionfor a dump.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
310c6eb: the commit reviewed.940d32f: upstreammainat review time. The fork point isffe310e.0de9efc(clzero loops, rdpru) and274f698(clwb loop overflow guard).Cargo.tomldeclares GPL-2.0-only, and itscrates/xcl/src/insn.rsshares 194 lines with the fork'sconsole_insn_decode.rs.Cargo.lockmatches the registry's.Imported from fxceless/victory-fork. Originally posted by kennymaakay on 2026-11-25T05:56:27Z.
On the
clwbrace (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: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
0Fturns 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 FA0F 01 FB(mwaitx) →0F 1F FB66 [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
AtomicU8compare-exchange afterVirtualProtectto RWX, restore the protection, thenFlushInstructionCache; 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, notpause, so that loop spins in user mode instead of trapping (gettingpauseback 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).
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?