tools/native: unified zero-dependency Rust workspace for 8 hot accelerators (13x-228x, Python fallback) #140

Closed
Andretuta wants to merge 1 commit from upstream-pr/140 into main
Andretuta commented 2026-11-24 02:26:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:26:41Z.


Carried over from old PR 9872 by TG0000 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9872, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
TG0000: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Unified zero-dependency Rust Cargo workspace (tools/native/Cargo.toml) consolidating our 8 highest-impact optional native accelerators (replacing closed PRs #8447, #8638, #8654, #8751, #8761, #8808, #8936, and #9645) into one single workspace build, one CI step, and one global LEONIDA_NATIVE=0 kill-switch (plus per-module LEONIDA_*_NATIVE=0), with automatic byte-identical pure-Python fallback everywhere.

Included Crates (0 external dependencies, Rust 1.85+, catch_unwind FFI guards, try_reserve_exact)

Crate Accelerates Measured Speedup Real-Corpus / Fuzz Parity
rdna2_decode_native tools/rdna2_decode.py 50.7x real (32.33 s -> 0.64 s on 2,000 real shaders) 2,000/2,000 real shaders + 634k fuzzed streams (0 mismatches)
spirv_asm_native tools/spirv_asm.py 13.8x real (24.59 s -> 1.78 s on 500 modules / 408 MiB) 500/500 real modules + 6.7M fuzzed cases (0 mismatches)
spirv_opt_native tools/spirv_opt.py 13.8x real (102.35 s -> 7.41 s on 500 modules) 500/500 real modules + 6.5k random modules (0 mismatches)
bvh_native tools/bvh_rehydrate.py 86x real (0.344 s -> 0.004 s) / 130–228x synthetic 8/8 real console BLAS + 8,192 random trees (0 mismatches)
bc7_native tools/dds_png.py 136x (5.9 s -> 43 ms on 2048x2048 BC7) 1.31M random blocks byte-identical
meshlet_native tools/meshlet_page.py 94.5x (25.2 s -> 0.27 s on 2.03M tris) 2,400 random pages bit-identical + shared-block sparse fix
anim_clips_native tools/anim_clips.py 15–17x end-to-end / 77–85x kernel 2,400 random sequences bit-identical
glb_native tools/glb_writer.py 16–30x pack_primitive / 10–18x build_glb 17.68M hypot + 1.37M mesh calls (0 mismatches)

(Real-corpus checks were read-only on personal 1.0.2.1 copies — counts and timings only, no game data.)

Unified Build & Fallback

  • Build all 8 crates in one command: cargo build --release --workspace --locked --offline --manifest-path tools/native/Cargo.toml
  • Every loader checks tools/native/target/release/ first, then per-crate target/release/, and falls back transparently to pure Python if unbuilt, LEONIDA_NATIVE=0, or LEONIDA_<MODULE>_NATIVE=0.
  • Includes one unified CI step in .github/workflows/ci.yml (--locked --offline with -D warnings) and tests/test_native_workspace.py.

Testing (Windows 11, Ryzen 9 5900X, Rust 1.100.0, Python 3.12.10, CPU only)

  • RUSTFLAGS="-D warnings" cargo build --release --workspace --locked --offline --manifest-path tools/native/Cargo.toml: 0 warnings.
  • RUSTFLAGS="-D warnings" cargo test --release --workspace --locked --offline --manifest-path tools/native/Cargo.toml: 45/45 passed.
  • All 8 Python native parity suites pass with 0 skipped (102/102 tests OK) + test_native_workspace.py (4/4 OK) + all 9 pure-Python reference suites pass.
  • compileall, make_game.py --help, scripts/check_no_game_data.py, and git diff --check all clean. No game data used.

AI-assisted (Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464920400 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/140). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:26:41Z. --- > Carried over from **old PR 9872** by `TG0000` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9872`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `TG0000`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Unified zero-dependency Rust Cargo workspace (`tools/native/Cargo.toml`) consolidating our 8 highest-impact optional native accelerators (replacing closed PRs `#8447`, `#8638`, `#8654`, `#8751`, `#8761`, `#8808`, `#8936`, and `#9645`) into **one single workspace build**, **one CI step**, and **one global `LEONIDA_NATIVE=0` kill-switch** (plus per-module `LEONIDA_*_NATIVE=0`), with automatic byte-identical pure-Python fallback everywhere. ### Included Crates (0 external dependencies, Rust 1.85+, `catch_unwind` FFI guards, `try_reserve_exact`) | Crate | Accelerates | Measured Speedup | Real-Corpus / Fuzz Parity | |---|---|---|---| | `rdna2_decode_native` | `tools/rdna2_decode.py` | **50.7x** real (`32.33 s -> 0.64 s` on 2,000 real shaders) | **2,000/2,000** real shaders + 634k fuzzed streams (0 mismatches) | | `spirv_asm_native` | `tools/spirv_asm.py` | **13.8x** real (`24.59 s -> 1.78 s` on 500 modules / 408 MiB) | **500/500** real modules + 6.7M fuzzed cases (0 mismatches) | | `spirv_opt_native` | `tools/spirv_opt.py` | **13.8x** real (`102.35 s -> 7.41 s` on 500 modules) | **500/500** real modules + 6.5k random modules (0 mismatches) | | `bvh_native` | `tools/bvh_rehydrate.py` | **86x** real (`0.344 s -> 0.004 s`) / **130–228x** synthetic | **8/8** real console BLAS + 8,192 random trees (0 mismatches) | | `bc7_native` | `tools/dds_png.py` | **136x** (`5.9 s -> 43 ms` on 2048x2048 BC7) | 1.31M random blocks byte-identical | | `meshlet_native` | `tools/meshlet_page.py` | **94.5x** (`25.2 s -> 0.27 s` on 2.03M tris) | 2,400 random pages bit-identical + shared-block sparse fix | | `anim_clips_native` | `tools/anim_clips.py` | **15–17x** end-to-end / **77–85x** kernel | 2,400 random sequences bit-identical | | `glb_native` | `tools/glb_writer.py` | **16–30x** `pack_primitive` / **10–18x** `build_glb` | 17.68M `hypot` + 1.37M mesh calls (0 mismatches) | *(Real-corpus checks were read-only on personal 1.0.2.1 copies — counts and timings only, no game data.)* ### Unified Build & Fallback - Build all 8 crates in one command: `cargo build --release --workspace --locked --offline --manifest-path tools/native/Cargo.toml` - Every loader checks `tools/native/target/release/` first, then per-crate `target/release/`, and falls back transparently to pure Python if unbuilt, `LEONIDA_NATIVE=0`, or `LEONIDA_<MODULE>_NATIVE=0`. - Includes one unified CI step in `.github/workflows/ci.yml` (`--locked --offline` with `-D warnings`) and `tests/test_native_workspace.py`. ### Testing (Windows 11, Ryzen 9 5900X, Rust 1.100.0, Python 3.12.10, CPU only) - `RUSTFLAGS="-D warnings" cargo build --release --workspace --locked --offline --manifest-path tools/native/Cargo.toml`: **0 warnings**. - `RUSTFLAGS="-D warnings" cargo test --release --workspace --locked --offline --manifest-path tools/native/Cargo.toml`: **45/45 passed**. - All 8 Python native parity suites pass with **0 skipped** (`102/102` tests OK) + `test_native_workspace.py` (`4/4` OK) + all 9 pure-Python reference suites pass. - `compileall`, `make_game.py --help`, `scripts/check_no_game_data.py`, and `git diff --check` all clean. No game data used. AI-assisted (Claude Opus 5.5).
QemmHD commented 2026-11-24 05:28:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T05:28:48Z.


Supply chain is clean: all 8 crates have zero dependencies (Cargo.lock lists only workspace members), there's no build.rs, proc-macro, .cargo config or toolchain file, and CI builds --locked --offline with a fresh CARGO_HOME, adds no actions and keeps contents: read. The loaders use absolute module-relative paths, so there's no DLL search-order hijack. What's left is functional review: 76 lines of raw-pointer unsafe FFI, and glb_native reading CPython object internals behind runtime layout probes deserve a careful look. With -D warnings in CI, pinning the Rust toolchain would avoid breakage on a new stable release.

Security review; read only, nothing run.
AI-assisted (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7122986395 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/140#issuecomment-7122986395). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T05:28:48Z. --- Supply chain is clean: all 8 crates have zero dependencies (Cargo.lock lists only workspace members), there's no build.rs, proc-macro, `.cargo` config or toolchain file, and CI builds `--locked --offline` with a fresh `CARGO_HOME`, adds no actions and keeps `contents: read`. The loaders use absolute module-relative paths, so there's no DLL search-order hijack. What's left is functional review: 76 lines of raw-pointer `unsafe` FFI, and `glb_native` reading CPython object internals behind runtime layout probes deserve a careful look. With `-D warnings` in CI, pinning the Rust toolchain would avoid breakage on a new stable release. Security review; read only, nothing run. AI-assisted (Claude Code, Claude Opus 5.5). Discord: bigpeppa.
MoonEyes commented 2026-11-30 19:13:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T19:13:02Z.


This is not merge-ready. It remains a draft and mergeStateStatus is DIRTY; gh pr checks currently reports failures across every listed check. The existing supply-chain review is positive, but it explicitly leaves functional review of the unsafe FFI and CPython object-layout probes outstanding. Please rebase, resolve the conflicts, obtain green current-base CI (including the locked/offline workspace build and tests), and complete that functional review before requesting merge.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7289029364 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/140#issuecomment-7289029364). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T19:13:02Z. --- This is not merge-ready. It remains a draft and `mergeStateStatus` is `DIRTY`; `gh pr checks` currently reports failures across every listed check. The existing supply-chain review is positive, but it explicitly leaves functional review of the unsafe FFI and CPython object-layout probes outstanding. Please rebase, resolve the conflicts, obtain green current-base CI (including the locked/offline workspace build and tests), and complete that functional review before requesting merge.
aslan2142 commented 2026-12-01 11:15:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:15:27Z.

Review: COMMENTED


This carried-over 60-file Rust native accelerator workspace remains a draft with merge conflicts (DIRTY) and failing/cancelled CI checks. While the zero-dependency supply-chain audit by @QemmHD was positive, it cannot be evaluated for merge until an owner rebases onto current main, gets CI green, and marks it ready for review.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130128771 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/140#pullrequestreview-6130128771). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:15:27Z. **Review:** COMMENTED --- This carried-over 60-file Rust native accelerator workspace remains a draft with merge conflicts (`DIRTY`) and failing/cancelled CI checks. While the zero-dependency supply-chain audit by @QemmHD was positive, it cannot be evaluated for merge until an owner rebases onto current `main`, gets CI green, and marks it ready for review. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 12:10:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:10:27Z.


Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310756533 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/140#issuecomment-7310756533). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:10:27Z. --- Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 12:57:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:57:31Z.

Review: CHANGES_REQUESTED


Now ready for review, requesting changes before merge:

  • Merge conflicts (CONFLICTING/DIRTY): conflicts with main across the 60-file diff (including .github/workflows/ci.yml and tool hooks).
  • CI: all checks from 2026-11-24 were cancelled/failing. Please rebase onto current main (or split into focused PRs) and get fresh green CI.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6131695312 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/140#pullrequestreview-6131695312). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:57:31Z. **Review:** CHANGES_REQUESTED --- Now ready for review, requesting changes before merge: - **Merge conflicts (`CONFLICTING`/`DIRTY`)**: conflicts with `main` across the 60-file diff (including `.github/workflows/ci.yml` and tool hooks). - **CI**: all checks from 2026-11-24 were cancelled/failing. Please rebase onto current `main` (or split into focused PRs) and get fresh green CI. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 17:20:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:20:03Z.


Closing this carry-over PR because it is ~6,600 commits behind main with merge conflicts and bundles 3 deprecated legacy Python shader-compiler crates with 5 active asset-exporter crates that have heavily drifted on main. Thank you for the contribution! If you still want to pursue native acceleration for the active exporter crates, please feel free to reopen or submit a fresh PR against current main targeting only the active exporter crates.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7319132487 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/140#issuecomment-7319132487). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:20:03Z. --- Closing this carry-over PR because it is ~6,600 commits behind `main` with merge conflicts and bundles 3 deprecated legacy Python shader-compiler crates with 5 active asset-exporter crates that have heavily drifted on `main`. Thank you for the contribution! If you still want to pursue native acceleration for the active exporter crates, please feel free to reopen or submit a fresh PR against current `main` targeting only the active exporter crates.

Pull request closed

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
ProjectLeonida/mandy!140
No description provided.