Skip to content

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

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
aslan2142:build1390-bvh4-parent-table
Nov 25, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
aslan2142:build1390-bvh4-parent-table

Conversation

@aslan2142

Copy link
Copy Markdown
Collaborator

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

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

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 <noreply@anthropic.com>

@abnalstlll-byte abnalstlll-byte 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.

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 abnalstlll-byte 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.

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.

@aslan2142
aslan2142 merged commit 0422120 into ProjectLeonida:main Nov 25, 2026
7 of 9 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator Author

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

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.

2 participants