After the merge the tree held this branch's older states of files main maintains. Run against main's code,
tests/test_acphal_abi.py and 11 of the 15 translator tests that differed failed, and the C++ runtime would have
been built from two generations of its sources. So that the merge cannot break what main builds and tests:
- runtime/ is main's, file for file (68 files only this branch had are not carried over);
- every file under tools/, tests/ and docs/ that both sides have is main's (80 files);
- ten translator tests only this branch has, which test rules main's translator does not have, and their
fixtures are left out.
What main gains: d3d12/ (the Rust D3D12 runtime), its launchers and helpers (Launcher.bat, scripts/play*.ps1,
play-linux.sh, port_ctl.py, smooth-motion.ps1, fetch_vkd3d_proton.py, sync_victory.py), mods/example_lua, eleven
notes under docs/, seven tools and the tests that pass with main's code, the README's sections and credits, and
the "Runtime traps" section of AGENTS.md. Everything left out here is on the branch port/d3d12-nvidia.
Checked: compileall; make_game.py --help; check_no_game_data.py over every file this adds to main; the
line-ending, docs-encoding, CI-registration and docs tests; each test file that differs from main, on its own.
Not run: the whole translator suite, the C++ build, cargo over d3d12/ after the merge (d3d12/ is byte for byte the
branch's), CI.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Brings the D3D12 runtime branch (d3d12/, its launcher scripts and notes, and the pull requests reviewed and applied
on it) together with mandy's main.
Conflicts (67 files, none under d3d12/): docs/, make_game.py, runtime/, scripts/build_runtime.ps1, tests/ and
tools/. Every one takes main's side: main is where that code is maintained, and this branch's copies were older
states of the same files or the same pull requests in another form. tests/test_fspx_unpack.py is main's too, as it
tests main's tools/fspx_unpack.py. Nothing under d3d12/ is changed by the merge.
Checked before pushing: python -m compileall over make_game.py, tools and tests; make_game.py --help;
scripts/check_no_game_data.py over the files this adds to main; tests/test_text_write_line_endings.py. The
translator suite, the C++ runtime build and CI have not run on the result.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The title has a cheat system of its own: a table of sixteen handlers without
arguments, and the functions those call take plain arguments. Ten places in
its code are found by short byte signatures (each once in the executable),
which give the cheat dispatcher and table, the title's deferred call, the
player's ped, the functions that set a ped's wanted level, the time of day
and the forced weather type, and the globals they work on.
The title's once-a-frame call of its cheat input function becomes a call of
ours (a near stub, written before any title code runs); the menu only queues
a request, and the hook hands the title's own deferred-call queue (the one
its cheats go through) the work. Wanted level, clear, never wanted, hour,
clock paused, sync with system, weather by name, freeze weather, the health
cheat and the nine vehicle cheats are wired; the player's position and
heading come from the ped itself. Moving the player, god mode and the rest
still say why they are not there.
Off unless LEONIDA_GAME_ACTIONS=1: built and unit-tested, not yet run in the
title. LEONIDA_GAME_ACTIONS_RUN scripts commands for a test without the
keyboard and logs to %TEMP%\leonida-actions.
docs/mod-menu.md: how it was found, with counts; the 6,811 script command
wrappers (each carries its own 64-bit hash) and what was tried to find the
table that binds them.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The title outputs 16:9 whatever its window is, and the swap chain was stretched
over the window.
LEONIDA_ASPECT=21:9|32:9|W:H|auto makes the title's window in that shape (at the
height it asks for, then fitted to the screen as before). LEONIDA_PRESENT_SCALE
=fit keeps the picture's shape in a window of another one: the swap chain
becomes a frame of the window's shape at the picture's height, cleared to
black, with the picture copied unscaled into its middle; =stretch is the
present as it was. Unset: fit with LEONIDA_ASPECT, else stretch, so nothing
changes without them (a 16:9 window's frame is the picture and the copy is the
same CopyResource). With bars, frame generation is told where the picture is
in the back buffer.
This is the fallback, not a wider view. For the real thing the title has to
output a wide size: LEONIDA_OUTPUT=WIDTHxHEIGHT (experimental) changes the
3840x2160 row of its mode table together with the scanout reservation that
has to fit it (the check LEONIDA_OUTPUT_1440 tripped, at rva 0x247af2d, wants
under 2 MiB of the reservation left) and the Settings viewport, after VIctory's
native 1440p profile as runtime/src/display_profile.h records it.
docs/ultrawide.md lists what the executable shows of the output size, the
render size and the shapes it knows, and what a run has to answer before this
can be called ultrawide (whether a wide row is taken, the projection, the HUD).
Unit tests: the frames and shapes (aspect.rs), the reservation sum and the
three places against the 1.0.2.1 executable (hooks.rs). Not run in the game.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ZiZc3's VI-Patch (github.com/ZiZc3/VI-Patch) is a patch set for the PS5 build of the title. It has no licence,
so nothing of it is copied: its lines are new bytes at PS5 addresses. What each patch does is taken, the places
were found in the Xbox executable, and the bytes written are our own (docs/vi_patch.md).
- 60 fps, no switch: the two places that turn the video settings' frame limit into the frame interval load 60
(RVA 0x224359a, 0x1e0fc62 in 1.0.2.1), so the title asks SetFrameIntervalX for 16 667 microseconds in place
of 33 333 and its own limiter follows.
- No vignette, LEONIDA_VIPATCH_NO_VIGNETTE=1: the jumps over the spotmeter_aiming and spotmeter_fast exposure
profiles are made unconditional (RVA 0x496ab6, 0x496b51).
- Skip intro logos, weather fix, first person, no clothing, Mandy replaces Lucia, no depth of field: not found
or not ported, each with its reason in the doc.
A place is a pattern of its bytes (?? for displacements), taken at the offset known for 1.0.2.1 or found by a
search of the image's code that must find it once; a patch is written only if all its places are found
(vipatch.rs, hooks::game_patches). Unit tests for the search, the plan, the table and the write into a made-up
image; with LEONIDA_GAME_DIR set the same run finds each pattern once in the retail executable.
Not run in the game.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
retire_orphan_windows frees the retired windows whose submissions have
completed after this submission's refresh_shadows, and freeing writes
the window's copy back to the title's pages once more
(free_retired_shadow). The refresh had already copied those pages to
the live copies, so the slot-133 buffer that replaced the window read
the older bytes until the next submission.
Moving the free ahead of the refresh, as suggested, is not enough on
its own: the write-back opens the pages it writes, and the refresh's own
copy back of the live copies' batches (write_back_titles) then takes
those pages for ones the title wrote and drops the buffer's GPU results
there (measured with this test: with the free moved first, the words
written through the buffer did not all reach the pages). So the free stays after the refresh, and a
retired copy's bytes that go back are written into every other copy over
them that still held the title's older bytes, as the next refresh would;
a copy that changed a byte keeps its own. Under lock_, in place, no
allocation. The epoch/ticket gating (src/command_list_epochs.h,
stamp_retired_windows) is untouched.
d3d12_title_va_test --window-orphans: the submission that frees the
window reads the held words through the buffer placed over the ring.
With LEONIDA_TITLE_WRITEBACK=0 (d3d12_title_window_orphans_free) it read
0 of 64 before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
ShadowPages::write_back compared the copies in 256-byte pieces and kept
one flag per piece: once a live copy had changed any byte of it, a
retired window's copy was left out of the whole piece. A retired window
and the slot-133 buffer that replaced it can have written disjoint
bytes of one piece (the window [384, 512), the buffer [256, 384)), so
the window's bytes were dropped. The batch path (`only` null) had the
same flag (`live = live || pass == 0`).
The piece now keeps a fixed 256-entry mask on the stack (no heap under
lock_) of the bytes a live copy changed, set in the first pass; a
retired copy goes back on every byte it changed that no live copy did,
in runs. Copies are still compared against the title's bytes as they
were before any copy went back, and a live copy now writes only the
bytes it changed, so one live copy no longer writes the title's older
bytes over another's result in the same piece.
d3d12_title_va_test --window-orphans: the held submission writes through
the window from ring + 384, a later one through the buffer placed over
the ring from ring + 128, and all the held words must reach the title's
pages (32 of 64 did before). The ring is write-combined so the buffer is
a copy on every driver. New ctest entry d3d12_title_window_orphans_free
runs it with LEONIDA_TITLE_WRITEBACK=0, where the window's free is the
only way back.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
cover_pool_request planned its cover (title_pool_cover) under short
shared locks of the alias table, then made the mapping and entered it
with replace_twin, which erased every range in the span unconditionally.
A slot-133 buffer is entered (Resource::alias_title_va) without
title_window_mutex, so one placed in either view of the span in between
was erased with the windows. And replace_twin's result was ignored: the
cover was recorded in pool_spans and returned as made either way.
replace_twin now takes the caller's predicate and, under the same
unique lock as the replacement, refuses with nothing changed when a
range it would erase is not one the caller planned to replace. The
cover passes the windows its plan found. On refusal the window it made
is dropped at once (drop_title_window: nothing answered from it, so no
submission names it) and the request falls back to the zero-size view
as before. The same drop now follows add_twin's refusal in
resolve_pool_memory, which left its new window charged to the budget
and refreshed with nothing answering from it.
title_window_plan_test: a non-window range entered in the cover's span
(CPU view, then twin view) between title_pool_cover and replace_twin is
refused and left intact.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
title_pool_cover translated a mapping found in the pool's other view back
with `x - (twin - va)` modulo 2^64. A window that starts below the twin
view (m.title_va < twin - va) wrapped to near UINT64_MAX, passed the
pool bounds check, and replace_twin then erased it whole, leaving the
part of it outside the cover unanswered. A twin view that does not fit
in 64 bits (twin < va - pool_lo, or pool_hi - va > UINT64_MAX - twin)
made the twin-view query wrap into an empty range, so a range in the way
was not seen at all.
The twin view's bounds [twin_lo, twin_hi) are now checked up front,
queried in non-wrapping coordinates, and a hit outside the view it was
found in refuses the cover like one outside the pool.
title_window_plan_test: check_pool_cover_bounds with the review's
example (pool [0x100000, 0x500000), va 0x120000, twin 0x420000, window
[0x200000, 0x440000)) and the two overflow cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
The user's PS5 copy is one .pkg (magic 7F 46 49 48); 64 KiB samples across it measure
7.85-8.00 bits/byte. Under the ground rules nothing is decrypted, so the PlayStation prompts stay
the replacement set built by tools/ps_prompt_glyphs.py.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With LEONIDA_ASYNC_PIPELINES=1, graphics and mesh pipelines (all their stages) now take
LEONIDA_ASYNC_MIN_BYTES_GRAPHICS when it is set, and LEONIDA_ASYNC_MIN_BYTES otherwise, so
nothing changes while it is unset. Compute keeps LEONIDA_ASYNC_MIN_BYTES. 0 makes every graphics
pipeline asynchronous. One startup line states both thresholds; text that is not a number is
ignored with a log line.
Thread dumps from a retail run showed the draw thread building lazy graphics variants under the
1 MiB threshold in place, 2.5-11 s each, back to back, with no present for about 100 s. A skipped
draw costs one draw. The image needs the small lighting and post compute programs, and those
are still built in place.
Tests: async_pipeline_size_test covers the per-kind decision and the unset fallback;
d3d12_pipeline_workers_test --async-graphics-zero / --async-graphics-unset (new ctests) hold
the compile worker with compute over its threshold.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve runtime/README.md conflict with #2220 (LEONIDA_PIPELINE_ORDER_LOG)
and note in docs/d3d12_vulkan.md that LEONIDA_COMPILE_GATE=adaptive and 1
gate graphics creates as well (#2412).
Review of #2462:
- An unclear calibration (a slow submission the create does not explain) is no
longer written to compile_gate_calibration.txt, and an unclear line an
earlier build wrote is not read as a cached verdict: the next launch measures
again instead of staying classic until the driver changes
(compile_gate_policy::cache_verdict, tested in compile_gate_policy_test).
- After a fence wait that fails, the fence and command pool are destroyed only
once the pending submission's fence signals (up to 60 s); on a lost device or
if it still has not, they are left alive. The verdict stays classic.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three soundness gaps the review reproduced against the round emulation:
- A region that is one block branching back to itself was emitted straight,
so it ran once. It now gets a sub-CFG like a multi-block region and is
emitted as a loop through cfg_structure.structure. This also covers the
read-only self-loop that was already folded before the one-lane rule.
- A write of one half of EXEC (v_cmp_eq_u32_e64 exec_lo, 0, v0) marked EXEC
at most one lane, though the emitter keeps the other half's lanes. A half
write now keeps the fact only when EXEC already had it and the half
written is within it (a compare).
- The short form v_add_co_ci_u32 vD, src0, src1 (also sub, subrev) wrote VCC
only in the emitter. explicit_carry_vcc now gives it its VCC carry-out and
carry-in operands when the listing is read, so every analysis sees the
write, and the emitter's special case is removed.
tests/semantic/test_wave64_one_lane_fold.py adds each case (8 subtests fail
before) and picks in lanes 32-63 of both waves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
With LEONIDA_COMPILE_GATE unset or `auto`, the device measures the driver once
before the VulkanContext exists: a worker creates a synthetic compute pipeline
(SPIR-V written in code, new specialization seed each run, no pipeline cache)
while the queue gets empty submissions waited on a fence. Quick submissions with
the create still in the driver give the adaptive gate; a held one, a create too
fast to tell, an unexplained slow submission or any failure give classic. The
verdict is cached per vendor/device/driver/pipelineCacheUUID in
compile_gate_calibration.txt beside the pipeline cache;
LEONIDA_COMPILE_GATE_RECALIBRATE=1 measures again. Only the title process
calibrates; build hosts and tests keep classic. `classic`, `adaptive`, `1`, `0`
still force a mode.
Tests: compile_gate_policy_test (no GPU: settings, NVIDIA version decode,
verdicts, cache file, SPIR-V shape) and vk_compile_gate_calibration_test (GPU:
a verdict within 20 s, adaptive on NVIDIA 621.40).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Second review on #2412:
- enter_submit no longer switches to the held limit for good once it sees a create of a kind that holds
submissions: each pass checks held_blocking(). With one in the driver the held limit applies on its own (also when
it is under the plain limit) and the budget is off; without, the plain limit and budget apply, so a submission
goes ahead at the plain limit once the holding create left while a create of a kind with no verdict stays. The
"reached the limit, but ..." notice comes once per wait, and the wait wakes when a holding create leaves.
- SubmitTurn passes `probe` into enter_submit: a present or wait never goes ahead at the probe budget, only at the
limit.
- VulkanPresenter::submit's turn does not probe (it covers the startup frame's fence wait and the present); the
nested queue_submit turn still probes the vkQueueSubmit alone.
- submit_mutex_test: gate_second_review covers the four cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- CreateKind, CreateInfo and GateAhead move out of SubmitMutex to namespace scope (CompileGateKind,
CompileGateCreate, CompileGateAhead), with using aliases so SubmitMutex::CreateInfo and the rest still work:
clang and GCC reject a `= {}` default argument of a nested class with default member initializers inside the
enclosing class (review on #2412).
- LEONIDA_COMPILE_GATE unset is the classic gate again, as on main: compute creates only, no limit, no probes;
graphics creates do not pass it. The adaptive gate is LEONIDA_COMPILE_GATE=adaptive: on a driver that holds
submissions (630.20) its first probe of a kind enters the driver after the 2.5 s probe budget and loses the
device if that create stays 10 s more, which the classic gate waits out. `1` and `0` are unchanged.
- submit_mutex_test: a classic-gate case (a graphics create holds nothing back, a 3 s compute create is waited out
with no verdict), the adaptive cases opt into graphics gating; passes unset, with `adaptive` and with `1`.
- README rows and docs/d3d12_vulkan.md say so; the "held verdict 2 s into the probe" wording is corrected (it comes
when the probe returns, and the probe holds the submit lock until then).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With LEONIDA_COMPILE_THREADS=1 (the layout of main: one general worker and
the graphics-only one) next_locked did not look at the owner, so two variants
of one graphics PSO could build at once, one on each worker. A last Release
meanwhile hands the PSO's deletion to the running build it finds first
(after_running), and that worker deleted the PSO while the other was still
in build() on it. The single-worker selection now skips a job whose PSO has
a build running, as the pool already did.
New test in d3d12_compile_pool_test: two graphics variants of one PSO with
one worker plus the graphics worker; the second must not start while the
first runs, another PSO's build still uses the free worker, and a last
Release runs after the first build with the second dropped. It fails
without the fix.
Docs: the heavy count also bounds LEONIDA_SERIAL_BIG_COMPILES=0 on the
workers; only compute creates pass the compile gate.
Found by qhukz13 in review of #2233.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>