upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-23 12:11:27 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 08:24:55 -0500
commit2e4ef18d858c1966a7b345f4e6c2ab306f1c420e (patch)
treedc5d5eb23b2fa2d8708cc0b0b5e951dbc2904e0e /docs
parent2d73c242fddfe26d57b52ee150704e6c3b23cff4 (diff)
docs/bvh.md: the BVH4 parent table's start and extent (BUILD-1390)
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>
Diffstat (limited to 'docs')
-rw-r--r--docs/bvh.md39
1 files changed, 37 insertions, 2 deletions
diff --git a/docs/bvh.md b/docs/bvh.md
index 203a88c2d..ee4316672 100644
--- a/docs/bvh.md
+++ b/docs/bvh.md
@@ -123,8 +123,42 @@ So the "`u16` table at header `0x130`" of section 4 is not a table: it is these
123(a root pointer, the element offset and the parent offset, the last usually negative; hence "often monotonic"). With `offsetToPrimRemap` 0 everywhere there is no 123(a root pointer, the element offset and the parent offset, the last usually negative; hence "often monotonic"). With `offsetToPrimRemap` 0 everywhere there is no
124primitive remap table either, and the element region allocates 64 bytes per element, `numElements` of them, padded 124primitive remap table either, and the element region allocates 64 bytes per element, `numElements` of them, padded
125to 128 bytes (a stride, not a record layout: section 4a describes the packed arrays inside it). 125to 128 bytes (a stride, not a record layout: section 4a describes the packed arrays inside it).
126**Open:** where the parent array starts and how big it is. Neither `offsetToParents + 4 * unit` against the header end 126**The parent table (BUILD-1390).** The traversal shader finds the entry for the 64-byte unit `u` at
127or `offsetToElements`, nor a size of `4 *` the node or element count, holds on every stream. 127`offsetToParents + 4 * (u - offsetToElements / 64)` (`XboxBvh4Node_GetParentTableOffset` and
128`XboxBvh4Node_LoadParentPointer`, L3254-L3275 of the `.hlsli` above, 32-bit arithmetic). It only looks up the
129parent of a box node: the node it climbs from is the last non-triangle node (L6212), asserted to be above `TRI3`
130(L6265). The table is laid out for the box nodes only:
131
132* *Start:* `offsetToParents = 0x40 - (((offsetToNodes - offsetToElements) / 16) & ~127)`. The element units'
133 entries take `(offsetToNodes - offsetToElements) / 16` bytes; their whole 128-byte blocks sit below the header
134 end, which is why the word is negative from 32 element units up. The first box node's entry is then at
135 `offsetToParents + (offsetToNodes - offsetToElements) / 16`, in `[0x40, 0xc0)`.
136* *Extent:* one entry per box unit (a BOX16 node takes one, a BOX32 node two) from the first box entry, and
137 `offsetToElements` is the end of the last one rounded up to 128 bytes. The bytes between the header end and the
138 first box entry, and after the last one, are the only slack.
139* *Not shipped:* the bytes from `0x40` to `offsetToElements` are all zero; rehydration writes the entries
140 (`tools/bvh_rehydrate.py`, which matches the library byte for byte on 8 samples, §4a).
141* *The units the header counts:* `totalSizeIn64BNodes + 1` is the end of the last box group in 64-byte units plus
142 `ceil((4 + 8 * levels) / 64)` units for the level table (§4a). The level table's units have no entry, so the end
143 `offsetToParents + 4 * (totalSizeIn64BNodes + 1 - offsetToElements / 64)` taken from the header alone, rounded up
144 to 128, lands on `offsetToElements` on only 259,456 of the 272,858 box-rooted streams.
145
146Measured over every stream of both packs, with a scratch probe over the `tools/bvh_index.py` scan and then with
147`tools/bvh_packing_check.py`, which now checks all three (§4a): 272,874 streams (271,627 complete and 10 joined in
148`core_bvh4.rpf`, 1,237 in `shared_minigame000_bvh4.rpf`). Counts only.
149
150| rule | holds on |
151|---|---|
152| `[0x40, offsetToElements)` is zero | 272,874 / 272,874 |
153| `offsetToParents` from the start rule | 272,874 / 272,874 |
154| `offsetToElements` from the extent rule (box root) | 272,858 / 272,858 |
155| `totalSizeIn64BNodes + 1` = box groups' end plus the level table's units (box root) | 272,858 / 272,858 |
156| leaf root (`numElements` 1): `offsetToElements` `0x80`, `offsetToNodes` `0x100`, `offsetToParents` `0x40`, `totalSizeIn64BNodes` 3 | 16 / 16 |
157| no slack after the last box entry | 8,973 (1 to 31 entries on the rest) |
158
159**Hypothesis:** the console builder sizes the table from the box nodes it wrote and aligns it the same way for
160updatable or top-level structures. Every measured stream has `flags` `0x81020006`, a BLAS without the updatable
161bit `0x00040000`, so where an updatable structure keeps its leaves' entries is not measured.
128 162
129The `flags` word has version `6` in its low 16 bits. It also sets `0x80000000` (bottom level), `0x00020000` 163The `flags` word has version `6` in its low 16 bits. It also sets `0x80000000` (bottom level), `0x00020000`
130(offline) and `0x01000000` (dehydrated). It does not set `0x00010000` (compressed). The sample is therefore a 164(offline) and `0x01000000` (dehydrated). It does not set `0x00010000` (compressed). The sample is therefore a
@@ -506,6 +540,7 @@ bytes form exactly one tree:
506* a box pointer names a node of its own width on a lower level; 540* a box pointer names a node of its own width on a lower level;
507* a TRI0 pointer names a leaf slot `offsetToElements + 64 * k` with `k < numElements`; 541* a TRI0 pointer names a leaf slot `offsetToElements + 64 * k` with `k < numElements`;
508* nothing points to the root, and every other node and every leaf has exactly one parent; 542* nothing points to the root, and every other node and every leaf has exactly one parent;
543* the parent table is not shipped and its start and extent follow the element and box regions (§3.1);
509* every vertex-order byte is a permutation; 544* every vertex-order byte is a permutation;
510* every stored override lies inside `sceneBounds` in the leaf frame. 545* every stored override lies inside `sceneBounds` in the leaf frame.
511 546