Skip to content

loader/hooks: cap mode table rows larger than LEONIDA_OUTPUT (D3D12-LOADER-OUTPUT-1440-CAP) - #2889

Open
djrolfes wants to merge 1 commit into
ProjectLeonida:mainfrom
djrolfes:djrolfes/loader-hooks-output-1440-cap
Open

djrolfes wants to merge 1 commit into
ProjectLeonida:mainfrom
djrolfes:djrolfes/loader-hooks-output-1440-cap

Conversation

@djrolfes

@djrolfes djrolfes commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-LOADER-OUTPUT-1440-CAP.

What and why

When LEONIDA_OUTPUT asks for an output size smaller than intermediate rows of the title's mode table (2560x1440, 1920x1080, 1664x936, documented in docs/ultrawide.md at .rdata 0x615c0c0..=0x615c100), also cap every lower mode-table row larger than (width, height) in d3d12/crates/leonida-loader/src/hooks.rs.

  • Why: output_patches(width, height) previously patched only the 3840x2160 mode row (OUTPUT_ROW = 0x615c100), the scanout pool reservation (SCANOUT_RESERVATION), and the Settings viewport (SETTINGS_VIEWPORT). Whenever LEONIDA_OUTPUT asked for a size smaller than 2560x1440 (down to parse_output's 1280x720 minimum, e.g. 1920x1080, 2560x1080, 1664x936, 1600x900, 1280x720), scanout_pool_bytes(width, height) shrank below the larger unpatched mode rows immediately preceding OUTPUT_ROW, allowing the title to pick a larger row and overflow the smaller scanout reservation.
  • Change:
    • Adds LOWER_OUTPUT_ROWS covering all three intermediate rows (OUTPUT_ROW - 0x10 = 0x615c0f0 for 2560x1440, OUTPUT_ROW - 0x20 = 0x615c0e0 for 1920x1080, OUTPUT_ROW - 0x30 = 0x615c0d0 for 1664x936; the 1280x720 row at OUTPUT_ROW - 0x40 is already parse_output's minimum).
    • Appends a capping OwnedPatch for every row where width < row_w || height < row_h. Outputs at or above 2560x1440 (2560x1440, 3440x1440, 3840x2160) emit the exact same 3 patches as before.
    • Updates the_resolution_places_are_in_the_retail_executable to check output_patches(1280, 720) so all 6 patches (the 3 base patches plus all 3 LOWER_OUTPUT_ROWS) are validated directly against the 1.0.2.1 executable when LEONIDA_GAME_DIR is set.
  • Overlap check: Completely disjoint from open PR #2756 (D3D12-SERIESX-FSR-MAX-SCALED, which touches render_scale_patches, not output_patches).
  • Evidence classification: READ IN CODE (d3d12/crates/leonida-loader/src/hooks.rs, docs/ultrawide.md) + fresh red→green unit tests + live retail-executable byte check (the_resolution_places_are_in_the_retail_executable) + MEASURED 300 s in-world game gate exercising LEONIDA_OUTPUT=1920x1080.

Tested

  • python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/hooks.rs → exit 0.
  • Freshly compiled (cargo clean -p leonida-loader --target x86_64-pc-windows-msvc) leonida-loader unit test binary (x86_64-pc-windows-msvc) and ran under Wine:
    • RED on origin/main (only the new test hooks::tests::output_below_table_rows_caps_every_larger_mode_row applied):
      running 1 test
      thread 'hooks::tests::output_below_table_rows_caps_every_larger_mode_row' panicked:
      assertion `left == right` failed
        left: 3
       right: 4
      test result: FAILED. 0 passed; 1 failed; 0 ignored
      
    • GREEN on PR head 6b4f77222 (rebased onto 3e7b34a52):
      • Retail executable validation (LEONIDA_GAME_DIR set, no SKIP:):
        test hooks::tests::the_resolution_places_are_in_the_retail_executable ... ok (all 6 output patches verified against 1.0.2.1 binary).
      • Full crate suite: test result: ok. 85 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out.
  • 300 s in-world game gate (MEASURED on exact PR head 6b4f77222, Series S + DLSS Quality 1280×720 → 1920×1080, LEONIDA_OUTPUT=1920x1080 exercising the 2560x1440 row cap live, Option A mods/gate_driver mode = roam loaded):
    • Verdict: PASS (310.78 s in-world after world entry at 62.62 s; also passed an earlier cold-cache 310.93 s run with 0 errors).
    • Frames & pacing: 3,319 frames after +60 s (3,427 total world presents), 15.89 median FPS (16.22 end median FPS), 111.28 ms p95 frame time, 4.677 s longest present gap (<= 10.0 s).
    • Memory & stability: 6,678 MiB peak VRAM (<= 7,400 MiB), 0 device losses (0x887A0005), 0 crashes, 0 panics, 0 faults before stop, 0 kernel NVRM: Xid errors.
    • Option A gate_driver note: mods/gate_driver loaded in mode = roam with 0 GATE FAIL; its 10 s menu-press cadence missed the brief world-entry probe window so the 310.78 s run stayed on the in-world camera cleanly at 15.89 FPS.

GPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0).

AI-assisted: yes (authored by Gemini 4 Neon; independent fresh review pass by a separate Gemini 4 Neon agent requested capping < 1080p rows and validating all rows in the_resolution_places_are_in_the_retail_executable, addressed and approved in re-review).

Checklist

  • Based on current main (3e7b34a52) and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (check_no_game_data.py clean on both source and PR description).
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — loader output-mode table patch)

@merzleckeier

Copy link
Copy Markdown
Contributor

Readback of the complete synthetic output table after apply_all at 6b4f772 + 0ff8a53. The Win64 fixture uses the real patch planner and write routine on a private synthetic mapping under Wine 11.22.

Requested output Main: oversized table rows left Main + PR: oversized rows left
1600×900 3 0
3440×1080 1 0
1280×720 3 0

The refresh and flag fields stayed intact and the scanout reservation matched the requested size in all cases. Corrupting the expected bytes for the final planned write rejected the group before modifying any earlier entry. The same readback assertion fails on main and passes on the PR. This covers the table update and preflight; actual mode selection by the title was outside the fixture.

MEASURED with synthetic inputs. AI-assisted (Codex).

@Kal0s-design

Copy link
Copy Markdown
Contributor

Verified on native Windows 11 (MSVC target, rustc 1.98.1), since the runs in the description are under Wine.

Head 6b4f77222 merged with main d2a564b66 (clean merge):

  • cargo test -p leonida-loader --lib: 85 passed, 0 failed.
  • cargo clippy -p leonida-loader --all-targets: no warnings.
  • the_resolution_places_are_in_the_retail_executable prints SKIP: LEONIDA_GAME_DIR is not set here (no game files on this machine), so the retail byte check rests on the author's run.

The new test catches the change:

  • with the cap condition replaced by false (the main behaviour), output_below_table_rows_caps_every_larger_mode_row fails at hooks.rs:604, left: 3, right: 4;
  • with || turned into &&, it fails at hooks.rs:610 on the 2560x1080 case, left: 3, right: 4. So the ultrawide case with only one dimension below the row is covered too.

Not checked: the game itself, and what the title does with several identical rows after capping (for example 1280x720 turns the three rows above it into 1280x720 too).

GPUs tested: n/a (CPU unit tests only).

AI-assisted: yes (Claude Code).

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is right: width < row_w || height < row_h (hooks.rs:171) is exactly "either dimension exceeds the request", and since scanout_pool_bytes is monotone in both dimensions, no selectable row can then need a bigger pool than the reservation. apply_all preflights the added rows before any write (:478-493), so a mismatched lower-row byte refuses the whole change as documented, and exact-limit rows are untouched. The <= mutation fails the new test at hooks.rs:604 (5 vs 4), so the boundary is covered; 85/85 lib tests, and the merges with #2890/#2891 are clean.

Two nits:

  • docs/ultrawide.md:130-132 still says LEONIDA_OUTPUT changes "the first three together" — it now changes up to six rows. Update it in this PR.
  • At 1280x720 the three lower rows all become 1280x720 (five identical modes), which is intended but not exercised: the live gate only covers 1920x1080. A 720p or 1600x900 smoke run, or a sentence that duplicate rows are expected, would close the remaining gap.

CI is red only on unrelated Python tool tests (files that moved after this PR's base); a rebase onto current main should clear it. Note the retail-bytes test passed vacuously here (LEONIDA_GAME_DIR unset), so the six byte sites are still only validated on a machine with the 1.0.2.1 executable.

@andrew-ai

Copy link
Copy Markdown

CI diagnosis for the dependency discussion on #2958. The failed Windows check and Linux Python job both annotated the same five Python files in run 46681212676. The base commit 0ff8a53 had its own failed push run (46678721362): both jobs already reported test_wave_diff.py, test_wave_trace.py, test_x64_recomp.py and test_x64_recomp_qemu_runner.py there. The fifth file, test_piecewise_parse.py, was only annotated on the PR run. The Linux log shows its code-object comparison failing for scripts/run_gpu_tests.py. I checked the actual CI merge commit 24d9f64 against its first parent: only d3d12/crates/leonida-loader/src/hooks.rs changed, so the Python test and script are identical. This establishes four pre-existing failures; the fifth remains unexplained. A fresh CI run after updating the base would give a current verdict. Base run · PR run. Codex-assisted.

@andrew-ai

andrew-ai commented Dec 2, 2026 •

Copy link
Copy Markdown

Follow-up: I reproduced the fifth failure on the base alone (0ff8a53), with Windows CPython 3.12.10 and PYTHONHASHSEED=0. For scripts/run_gpu_tests.py, the piece sizes 1, 40 and 300 all failed the code_facts comparison. An equal frozenset constant had a different repr iteration order. Normalizing only the frozenset representation made all three comparisons pass, including the bytecode and line-position fields. Both historical Linux CI runs used CPython 3.12.16. Main already contains the corresponding normalization in 9b7674d. This accounts for the previously unexplained failure without the loader change. A new hosted run is still needed for current CI status. Codex-assisted.

Local integration check: PR head 6b4f772 merged cleanly into main 5b03c68 (tree 29a8f1b82). I ran all five previously failing suites on Windows with CPython 3.12.10. The parser, wave diff, wave trace and QEMU-runner wrapper passed all 53 tests. The x64 recompiler suite passed 15, with 34 skipped because qemu-system-aarch64 was unavailable. Total: 68 passed, 34 skipped, zero failures. This is a local result; the hosted check still needs a fresh run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants