Repository navigation
tools/bvh_rehydrate.py: CPU reference that rehydrates a dehydrated BLAS (PROC-114) - #2205
Conversation
…BLAS Written from the packing in docs/bvh.md §4a, standard library only. Inputs are float3 vertices with uint16, uint32 or no indices, and an optional 3x4 geometry transform. It does the header copy, the leaf chunks (vertex-order slots, the paired fourth vertex), the box groups by level with their stored overrides, BOX16 outward rounding with the +-inf overflow, the parent entries and the compressionParams leaf frame. Float arithmetic is rounded to float32 per operation. On the 8 measured samples whose geometry is identified, the output is byte-identical to XboxBvhBuilder.dll's RehydrateRaytracingAccelerationStructureX (checked locally; no sample is in the repository). The 15 tests in tests/test_bvh_rehydrate.py are synthetic. docs/bvh.md §7 documents it, including the console's size convention, 64 * (totalSizeIn64BNodes + 1) bytes, which xdxr_bvh.py validate reads as one unit less.
|
Tested
All 15 tests passed with synthetic BVH cases. This checks the CPU reference, with no external binary comparison. Independent Windows 11 validation. AI-assisted. |
A redirected stdout on Windows is encoded with the console's ANSI code page, and `python -I` ignores PYTHONUTF8, so a path outside that code page ended the run. tests/test_tool_stdout_encoding.py requires the guard in every tool's __main__ block, and it fails on this branch without it. Synthetic data only; no game files.
2a2461e to
dab5e2c
Compare
|
Pushed AI-assisted. |
|
Independent counts-only CPU validation of dab5e2c on Windows. I scanned one complete retail pack with bvh_index, ran Header and leaf_records on every complete BLAS, and ran levels on box-root BLAS. Of 2,560 compressed streams, 1,237 classified as complete BLAS. All 1,237 yielded their declared leaf count and completed the applicable level-table parse. Across 8,213,842 leaf records, 7,078,883 carried a second primitive. 686 BLAS referenced multiple geometry indices and 414 spanned multiple 2,048-leaf chunks. The level tables described 226,076 BOX16 and 2,965,004 BOX32 nodes. This measures structural decoding only. Geometry matching and runtime output equality were outside this run. AI-assisted. |
|
For context: TEST-376 (running |
|
Two corrections to the sequencing, from my side:
Two things that cost time on these samples:
If you need the geometry buffers for a sample, AI-assisted. |
…built from Reads the leaf signature (triangles per geometry index, a leaf that holds two primitives counting as two), keeps every (drawable, model) of an `rpf9dump models` manifest whose per-geometry triangle counts contain it as an ordered subsequence, and checks the survivors with tools/bvh_geometry_check.py from the model's exported OBJ and the 3x4 at +0x50 of the instance descriptor. The geometries of the two shaders the BVH leaves out are filtered with --skip-shaders (those name hashes are game data, so the rule is off unless the user passes them); a drawable whose shader indices the manifest cannot resolve keeps every geometry and the checks decide. All the BVH logic stays in Python: the C# side is only the model decoding and the export. Measured on the ten BLAS of the sample pack against one 1 GiB window of levels.rpf: 1,228 models exported, 1 to 374 candidates per BLAS from the signature, and exactly one consistent candidate for each of the ten. The tool prints no drawable names unless --names is given. The two tools that came with #2205 and #2428 lacked the stdout errors="replace" guard every CLI tool needs (tests/test_tool_stdout_encoding.py), so this also adds it there; without it that test fails for both. Tests are synthetic (tests/test_bvh_match.py, 14 cases): the right geometry is found and verified, a wrong one, a wrong shader rule and a missing transform are not, geometries are matched inside one model, and a manifest without per-geometry counts is an input error.
PROC-114. Claim: #2078 (comment)
Depends on: #2034. The tool follows the packing that PR documents in
docs/bvh.md§4a.tools/bvh_rehydrate.pyis a standard-library CPU reference that turns a dehydrated XDXR BLAS, as stored in the*_bvh4.rpfpacks, back into the runtime layout. The input geometry is float3 vertices withuint16,uint32or no indices, plus an optional 3x4 geometry transform (the instance descriptor's+0x50matrix).It does:
+-infon overflow;compressionParamsleaf frame.Every float operation is rounded to float32, so the output is meant to be byte-exact.
Why it is useful: it is the reference for the builder's own
Box16Rehydration,Box32RehydrationandLeafRehydrationprograms. Once #1968 and #1864 land, those can run on a GPU. My test on the real programs is in #1968 (comment).Licence: the tool is written from the §4a spec. No code comes from americas-recomp, which
docs/d3d12_vulkan.md§7.3 rules out.Testing
python -I tests/test_bvh_rehydrate.pyruns 15 synthetic tests and passes. They cover single and paired leaves, vertex-order slots, the fourth-vertex choice, no indices / 16-bit indices / stride, the geometry transform, the second 2,048-leaf chunk, BOX32 bounds with parents and overrides, BOX16 rounding and overflow, the leaf frame's scale and translation, the rotation table, errors and the command line.test_bvh_index,test_xdxr_bvh,test_docs_links,test_docs_repo_paths,test_docs_list_itemsandtest_text_write_line_endingspass.python -m compileallis clean.XboxBvhBuilder.dll'sRehydrateRaytracingAccelerationStructureXwrites (384 to 2,512,512 bytes, 0 differing bytes each). No sample or output is in the PR. This ran on the CPU only, on Windows 11.One thing this surfaced (not changed here): the console's size convention differs from this repo's builder.
64 * (totalSizeIn64BNodes + 1)bytes from the header. That matches §3.1, where the end is0x140 + 64 * nwith the header at0x100.tools/xdxr_bvh.py validateand the GPU builder (xdxr_build.comp:439,total_size / 64) use64 * totalSizeIn64BNodesfor the whole structure.validaterejects all 8 rehydrated console structures with "totalSizeIn64BNodes n does not cover the buffer".That is consistent inside Leonida, but a copy or compaction that sizes a console-built structure from its header would be one unit short. I'll post it as a finding for the builder's owner rather than change it here.
AI-assisted.