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

Open
github-bot wants to merge 1 commit from github-bot/gh-140 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:26 UTC · original
ubiquitarianism:old-pr/9872 → main · +13510 −11 · 60 files · 1 commits · draft

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).

**@⁠Andretuta** on GitHub · 2026-11-24 02:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/140) `ubiquitarianism:old-pr/9872` → `main` · +13510 −11 · 60 files · 1 commits · draft > 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).
Brings together the native ports of rdna2_decode, spirv_asm, spirv_opt,
bvh_rehydrate, the BC7 decoder of dds_png, meshlet_page, anim_clips and
glb_writer (from #8761, #8751, #9645, #8638, #8447, #8808, #8654 and
#8936), rebased onto main:

- tools/native/Cargo.toml is a resolver-2 workspace over the eight crates,
  with the release profile and one shared Cargo.lock. No crate has an
  external dependency; each keeps its own directory, README and tests, and
  points back at the workspace with `package.workspace`.
- Each Python loader looks in tools/native/target/release/ first, then in
  its crate's own target/release/, and honours LEONIDA_NATIVE=0 as well as
  its per-module switch.
- The eight CI steps become one: build and test the workspace with
  -D warnings, assert every loader found its library, then run the eight
  parity suites and their Python-side suites.
- rdna2_decode_native ports b35a82662 (SCRATCH vaddr "off", no VDST for
  SCRATCH/GLOBAL direct-to-LDS loads) and takes the new fingerprint, so the
  library matches the decoder on main again.
- anim_clips keeps main's empty-sequence check on the native path too.
- tests/test_native_workspace.py checks the manifest, the workspace path
  and both switches; the parity suites drop an inherited LEONIDA_NATIVE so
  their own switches decide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:46:09 +00:00
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 05:28 UTC · original

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.

**@⁠QemmHD** on GitHub · 2026-11-24 05:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/140#issuecomment-7122986395) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/140/head:github-bot/gh-140'
git switch 'github-bot/gh-140'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-140'
git switch 'github-bot/gh-140'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-140'
git switch 'github-bot/gh-140'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-140'
git switch 'main'
git merge --squash 'github-bot/gh-140'
git switch 'main'
git merge --ff-only 'github-bot/gh-140'
git switch 'main'
git merge 'github-bot/gh-140'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.