OLD-7640: restore old upstream PR 7640 - docs/bvh.md: the BVH4 parent table's start and extent (BUILD-1390) #748

Manually merged
github merged 1 commit from gh-pr/748/head into gh-pr/748/base 2026-11-26 09:19:19 +00:00
Owner

@⁠aslan2142 on GitHub · 2026-11-24 13:26 UTC · original
aslan2142:build1390-bvh4-parent-table → main · +117 −12 · 3 files · 1 commits · merged 2026-11-25 22:29 UTC

Claimed in the coordination issue as: OLD-7640 #14

Restoration of my original pull request, old upstream PR 7640 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 2d73c242fd. The cherry-pick applied cleanly. Changes in the rebase:

  • The worked example from the §3.1 sample header is gone from the new text.
  • The unit test that used those header values now uses synthetic ones.

#690 and #626 also touch docs/bvh.md, but both merge cleanly with this branch.

What and why

  • docs/bvh.md §3.1 replaced the console BVH4 parent table's start and size with an "Open:" line. This pull request puts the rules there instead:
    • Start: offsetToParents = 0x40 - (((offsetToNodes - offsetToElements) / 16) & ~127). The leaf entries' whole 128-byte blocks fall below the header end, so the first box node's entry lands in [0x40, 0xc0).
    • Extent: one entry per box unit (one for BOX16, two for BOX32) from the first box entry. offsetToElements is the end of the last entry, rounded up to 128.
    • Not shipped: the bytes from the header end to offsetToElements are all zero.
    • Header count: totalSizeIn64BNodes + 1 also counts the level table's units, which have no entry. That is why an end computed from the header alone missed on about 13,400 streams.
  • Measured on all 272,874 streams of the two bvh4 packs. Each rule holds on every stream it applies to. The doc's table has counts only.
  • tools/bvh_packing_check.py checks three new rules: parent_offset, parent_area_nonzero and parent_extent. It also gets two helpers, parent_table and elements_after_parents.
  • tests/test_bvh_packing_check.py:
    • The synthetic fixture moves to the console layout for its four leaves and three BOX16 units.
    • Six tests are added for the helpers and the three new failures.
  • The section ends with a hypothesis: whether updatable or top-level structures lay the table out the same way. Every measured stream is a non-updatable BLAS, so this is not measured.

Tested

  • python -I tests/test_bvh_packing_check.py:
    • Before (main with only this branch's test file): the 31 existing tests pass and the 6 new ones fail (3 failures, 3 errors).
    • After (this branch): all 37 pass.
  • tests/test_docs_*.py (12 files): all pass.
  • python -m compileall -q tools tests: ok.
  • git diff --check: clean.
  • python -I scripts/check_no_game_data.py on the three changed files: clean.
  • The corpus counts come from the original pull request's run over the user's own copy. They were not re-measured for this rebase.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main 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 (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 13:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/748) `aslan2142:build1390-bvh4-parent-table` → `main` · +117 −12 · 3 files · 1 commits · merged 2026-11-25 22:29 UTC Claimed in the coordination issue as: OLD-7640 https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 Restoration of my original pull request, old upstream PR 7640 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 2d73c242fddfe26d57b52ee150704e6c3b23cff4. The cherry-pick applied cleanly. Changes in the rebase: - The worked example from the §3.1 sample header is gone from the new text. - The unit test that used those header values now uses synthetic ones. #690 and #626 also touch `docs/bvh.md`, but both merge cleanly with this branch. ### What and why - `docs/bvh.md` §3.1 replaced the console BVH4 parent table's start and size with an "**Open:**" line. This pull request puts the rules there instead: - *Start:* `offsetToParents = 0x40 - (((offsetToNodes - offsetToElements) / 16) & ~127)`. The leaf entries' whole 128-byte blocks fall below the header end, so the first box node's entry lands in `[0x40, 0xc0)`. - *Extent:* one entry per box unit (one for BOX16, two for BOX32) from the first box entry. `offsetToElements` is the end of the last entry, rounded up to 128. - *Not shipped:* the bytes from the header end to `offsetToElements` are all zero. - *Header count:* `totalSizeIn64BNodes + 1` also counts the level table's units, which have no entry. That is why an end computed from the header alone missed on about 13,400 streams. - Measured on all 272,874 streams of the two `bvh4` packs. Each rule holds on every stream it applies to. The doc's table has counts only. - `tools/bvh_packing_check.py` checks three new rules: `parent_offset`, `parent_area_nonzero` and `parent_extent`. It also gets two helpers, `parent_table` and `elements_after_parents`. - `tests/test_bvh_packing_check.py`: - The synthetic fixture moves to the console layout for its four leaves and three BOX16 units. - Six tests are added for the helpers and the three new failures. - The section ends with a hypothesis: whether updatable or top-level structures lay the table out the same way. Every measured stream is a non-updatable BLAS, so this is not measured. ### Tested - `python -I tests/test_bvh_packing_check.py`: - Before (main with only this branch's test file): the 31 existing tests pass and the 6 new ones fail (3 failures, 3 errors). - After (this branch): all 37 pass. - `tests/test_docs_*.py` (12 files): all pass. - `python -m compileall -q tools tests`: ok. - `git diff --check`: clean. - `python -I scripts/check_no_game_data.py` on the three changed files: clean. - The corpus counts come from the original pull request's run over the user's own copy. They were not re-measured for this rebase. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) AI-assisted (Claude Code, Claude Opus 5.5).
offsetToParents = 0x40 - (((offsetToNodes - offsetToElements) / 16) & ~127),
so the first box node's entry lands in [0x40, 0xc0); one entry per box unit
follows, and offsetToElements is their end rounded up to 128. The bytes
from 0x40 to offsetToElements are zero. Holds on all 272,874 streams of
core_bvh4.rpf and shared_minigame000_bvh4.rpf (272,858 box roots for the
extent); counts only.

totalSizeIn64BNodes + 1 also counts the level table's units, which have no
entry: that is why the header-only end missed on about 13,400 streams.

tools/bvh_packing_check.py checks the three rules (parent_offset,
parent_area_nonzero, parent_extent); the synthetic fixture moves to the
console layout for its four leaves and three BOX16 units.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:19:18 +00:00
github manually merged commit 2e4ef18d85 into gh-pr/748/base 2026-11-26 09:19:19 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 13:30 UTC · original · approved these changes

Audited and verified. Clean-room compliant.

  • Measures and documents BVH parent table layout and zero-padded region before offsetToElements in docs/bvh.md.
  • Implements parent_table and elements_after_parents in tools/bvh_packing_check.py with full test coverage in tests/test_bvh_packing_check.py.
**@⁠abnalstlll-byte** on GitHub · 2026-11-24 13:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/748#pullrequestreview-6040062749) · **approved these changes** Audited and verified. Clean-room compliant. - Measures and documents BVH parent table layout and zero-padded region before offsetToElements in docs/bvh.md. - Implements parent_table and elements_after_parents in tools/bvh_packing_check.py with full test coverage in tests/test_bvh_packing_check.py.
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 13:30 UTC · original · approved these changes

LGTM. Thoroughly verified reverse-engineering of the BVH4 parent table layout (offsetToParents and offsetToElements calculations) across 272,874 streams in docs/bvh.md, validated in ools/bvh_packing_check.py with synthetic tests in ests/test_bvh_packing_check.py.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 13:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/748#pullrequestreview-6040066566) · **approved these changes** LGTM. Thoroughly verified reverse-engineering of the BVH4 parent table layout (offsetToParents and offsetToElements calculations) across 272,874 streams in docs/bvh.md, validated in ools/bvh_packing_check.py with synthetic tests in ests/test_bvh_packing_check.py.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 22:29 UTC · original

Merged: docs/bvh.md: the BVH4 parent table's start and extent.

  • Changed since review: Nothing. It merges cleanly with main, and no review point is open.
  • Tested: tests/test_bvh_packing_check.py passes on main + this head (Linux, CPython 3.14).
  • Checked on main 45129e6bc + 2e4ef18d8: the semantic suite passes (492 files, 6,315 tests, 0 files failed); test_bvh_packing_check pass; the 15 docs and writer tests pass; check_no_game_data.py is clean on the 3 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 22:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/748#issuecomment-7176423497) Merged: `docs/bvh.md`: the BVH4 parent table's start and extent. - **Changed since review:** Nothing. It merges cleanly with `main`, and no review point is open. - **Tested:** `tests/test_bvh_packing_check.py` passes on `main` + this head (Linux, CPython 3.14). - **Checked on `main` `45129e6bc` + `2e4ef18d8`:** the semantic suite passes (492 files, 6,315 tests, 0 files failed); `test_bvh_packing_check` pass; the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 3 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.