An update whose source is not a structure of this layout (one the title never
built, which D3D12 leaves undefined) made the refit follow its parent table
anywhere. MODE_CHECK now compares the copied header with the layout, and the
update records both tails: the refit runs when the check passes, a full build
when it fails. The refit walk follows only pointers to the layout's nodes.
A vertex index at or past the geometry's VertexCount is no longer read: its
triangle is inactive. XdxrTriangles carries vertex_count from the desc.
vk_xdxr_build_test: blas_vertex_count and eight update-source cases (zero,
random, another element count, garbage tree; large and small-sort).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gt9hwRYcpySx4P4ncQ3wD5
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>
The summary now says, per category, how many sites have a some-paths read
before the next call in program order and how many have them all after a
later call. strip() also drops the saved-mask SGPRs, so a mask saved in one
pass of an inner loop cannot place a read in the next. The docs quote the
split instead of guessing causes, name the integer mnemonics, and no longer
mention word 0 (the base field belongs to #3794).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
docs/design.md, Ray tracing row: the tie rule as measured with x, y and z dominant; that the first fit was
confounded (winding vs the sign of d[kz]) and wrong in the cells it never measured; that the rule was read off the
x/y rows post hoc and then predicted the z-dominant bridge kernel before it ran (32/32, 10 rows discriminating); the
256 new rows; which equal-|d| sign patterns the measured rows tell apart (all consistent with the translator's
>= order). Still gfx1030 only and dyadic inputs. docs/bvh.md 7a: one paragraph on the tie rule.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/design.md: the triangle sentences of the Ray tracing row now give the rule measured on an RX 6800 (gfx1030,
AMD 26.11.2, 2026-11-22, the kernels tools/bvh_tri_probe.py builds, 1,204 results): the invalid-ray result, the shear from the
direction, k = |d[kz]|^3 times (T, det, b_i, b_j), the miss words, t >= 0 without an extent test, +0 and
0xFFC00000, RDNA2's tie rule, how the translator computes them, what a consumer dividing by word 1 sees and where
the earlier normalised words differed, and what was not measured. The box sentences are unchanged.
docs/bvh.md 7a: the translator's triangle words against the software step's. cs_bvh32.asm: the derivation of the
scene's triangle words follows the measured rule; the words are unchanged (k = 1 and |det| = 1 there).
Co-Authored-By: Claude Opus <noreply@anthropic.com>
The first 10 streams are the whole first nested pack (9FPR tag); the other
121 BLAS of the interior lie in 31 other nested packs. Counts only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured over all 269,106 instance descriptors of core_bvh4.rpf: the key is
two uniform populations (below 2^55 and full 64-bit) that follow the BLAS,
is not a hash of any drawable name (name set validated against 228,610 of
228,681 archetype keys), not an entity id or archetype key, and not shared
with the other descriptor streams. What it hashes stays Open.
Counts only; no keys, names or game bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first 10 streams of core_bvh4.rpf cover 10 of the interior's 242 entities.
Matching every BVH stream of core_bvh4.rpf and shared_minigame000_bvh4.rpf
against the interior's drawables, at all four LODs, finds a BLAS for 124 of its
143 archetypes (220 entities), all in core_bvh4.rpf: 23 built from the first
LOD and 101 from the second, which rpf9dump models does not export. One BLAS
per drawable, not per entity; the 115 archetypes past the first 10 streams lie
in a band of streams 231,012 to 261,585. 16 exported archetypes have none, 11
of them as the shader rule predicts, and one shader hash is both kept and left
out. Counts only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All 10 sample BLAS of core_bvh4.rpf match exactly one drawable each on a full
levels.rpf export with per-geometry counts; the two read as aggregated rooms are
baked room-dressing drawables. All 10 are entities of one interior archetype
(base list and two entity sets); a BLAS sits in interior space at E * M^-1.
The shader skip covers 7 hashes over these samples, not 2. The descriptor key
at +0x40 always comes with one transform, and distinct keys can share a BLAS
and its transform (whole pack, single-BLAS descriptors). Counts only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Joined continuation streams are counted as `continuation`; one that starts
in a later window is no longer counted there again as `raw`. Five more
synthetic cases cover too_many_children, child_not_a_node, invalid_child,
root_not_a_box and leaves_past_end. core_bvh4.rpf: kinds now sum to
565,596 as in docs/bvh.md §1, 271,637/271,637 still pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 24,832 "other descriptor" streams of core_bvh4.rpf are two templates,
told apart by the page word in the block that the 0x08 pointer addresses:
* 2,531 instance descriptors with N > 1 slots (the 208-byte record is the
N = 1 case). The stream after each holds the BLAS of its non-zero entries
back to back; each entry's low u32 is that BLAS's declared end rounded up
to 256. 2,531/2,531 pass and 6,701 BLAS are tied; the N = 1 entry rule
holds for 269,106/269,106 records.
* 22,301 table streams (page word 0x1): K sorted u32 values and K 32-byte
items. None is followed by a BVH stream, and no key or value matches
anything beyond chance.
tools/bvh_groups.py reproduces the template and buffer counts, with
synthetic tests. docs/bvh.md gains §3.2a with the layouts, the rule,
the tested non-links and what stays open.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Counted over all 272,864 complete bvh4 streams with tools/bvh_index.py:
offsetToPrimRemap is 0 on every one; rootNodePtr lands in the node region on
all but 16 single-leaf streams (tri0 root); the element region is numElements *
64 rounded up to 128; offsetToParents is a multiple of 4, negative on 237,347.
The section 4 "u16 table at 0x130" is those words read as u16s. Where the
parent array starts stays open.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A geometry-free check of the dehydrated packing that bvh_rehydrate reads:
level table, group fit, child counts and override masks, child pointer
targets and widths, one parent per node and leaf, vertex-order bytes and
stored overrides inside sceneBounds. 272,874 of 272,874 streams of
core_bvh4.rpf and shared_minigame000_bvh4.rpf pass; docs/bvh.md gets the
counts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The GPU builder grouped four consecutive Morton-sorted elements per node,
level by level. Those groups ignore where the Morton prefix changes, so
sibling boxes overlapped and a ray took about twice the traversal steps.
It now builds a binary radix tree over the same sorted keys (Karras 2012,
ties broken by sorted position) and keeps the inner nodes at an even depth
as the BOX32/BOX16 nodes, each taking its children's children (2 to 4),
numbered in sorted order by a scan (root = node 0). Boxes are filled by one
bottom-up pass: each element writes its slot box and merges it into its
parent's accumulator with atomics; the last child to arrive carries on.
The arrival counter's atomicAdd has acquire-release semantics instead of a
memoryBarrierBuffer, since the pass is divergent and SPIRV-Cross before
MSL 3.2 lowers memory barriers to threadgroup_barrier. Refit reuses the pass
through the parent table.
TRI1 pairing (#3315) pairs triangle children of one node; the build records
each element's tree pointer so a paired sibling finds its TRI1 slot. The
node count depends on the keys: the layout reserves (3N - 2) / 4 nodes, the
header counts the nodes written (plus the BOX16 spare unit after the last
one), so compaction gives the rest back. Refit copies a source by its
header size. check-build reports traversal steps per ray.
Steps per ray: 5,000 random triangles 42.0 -> 23.0, BOX16 43.9 -> 23.7,
paired 7,200-triangle grid 37.6 -> 19.5. Build 1M triangles: RTX 5090
5.50 -> 5.99 ms, Radeon gfx1036 iGPU 133 -> 180 ms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TheMrBeez ran image_bvh_intersect_ray and image_bvh64_intersect_ray through
tools/hw_oracle on gfx1036 over hand-built box32 nodes: dword0 (P >> 8) + 0x10
with node 0|5 and (P >> 8) + 0x08 with node 0x800>>3|5 both traverse the node at
P + 0x1000, so address = base * 256 + (node & ~7) * 8 and the base and the node
offset add; the control reads the decoy. Recorded in bvh.md 7b. The Ray tracing
row drops the "a GPU can't confirm the rule" sentence: it was about the triangle
rule, and hw_oracle can run the native instruction, so that measurement is a
follow-up rather than an impossibility.
Docs only; test_docs_links, test_docs_repo_paths, test_docs_design_rows,
test_docs_table_rows and test_docs_list_items pass.
tools/rdna2spirv.py's image_bvh_intersect_ray loads a box node's BOX32
bounds (112 bytes) before it selects BOX16 or BOX32, and the root is the
last node, so a BOX16 root was read 48 bytes past the structure. A BOX16
layout now ends with one zeroed 64-byte unit (MODE_INIT clears it); the
D3D12 test's BOX16 BLAS is 39,040 bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- xdxr_check refuses PERFORM_UPDATE without ALLOW_UPDATE (D3D12 requires
it): a structure built without it may be paired, and a refit would leave
its TRI1 children reading wrong vertices.
- blas_paired_rotations: a grid whose triangles start at varied vertices,
so pairs use all nine (TRI0, TRI1) rotations; check-build asserts it
("all_rotations"). Before, the sibling rotation kd = 1 never occurred.
- BOX32 cases now say "box16": false, so a stray BOX16 is caught too.
- docs/bvh.md cites the one traced BOX16-related datum (docs/xdxr.md: a
bottom-level path needing MINIMIZE_MEMORY and a stream value above 10),
notes that world-space BLASes only get looser boxes; README says pairing
saves no memory yet and the BOX16 switch is assumed; comments rewrapped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bottom-level build without ALLOW_UPDATE now pairs triangles, as the
console builder does in its offline BLASes. The pass that writes the nodes
above the leaves pairs a triangle with a later sibling (among that node's at
most four children) that shares an edge in the opposite direction (the same
vertex bits), from the same geometry, both active. The first triangle is
rotated to put the shared edge in slots 1 -> 2, the sibling's third vertex
goes in slot 3, its primitive in PrimitiveIndex2, and each node type's remap
byte returns D3D12's barycentrics for its own vertex order.
The node keeps one child per triangle with its own box, so the tree, the
layout and the sizes do not change; the TRI1 child points at the first
leaf and the sibling's leaf is left unused. Pairs never cross nodes: one
thread owns each rewritten leaf and each parent-table entry. A refit
rewrites the leaves one triangle each, so the layer does not pair builds
with ALLOW_UPDATE (xdxr_pair), and record_blas ignores `pair` for updates.
check-build now compares barycentrics as well as hits, and checks a case's
"pairs" field: at least one TRI1 node, or none. New cases: paired grids
(BOX32 and BOX16), a transform, a mixed scene, the radix path, and two that
must not pair (pairs split across geometries, edges shared in the same
direction), plus a D3D12 BLAS without ALLOW_UPDATE. Mutating the geometry or
the direction rule, or the remap byte, fails check-build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bottom-level BuildRaytracingAccelerationStructure with MINIMIZE_MEMORY now
writes BOX16 inner nodes (64 bytes, half boxes) instead of BOX32 (128 bytes):
the same tree, about a fifth smaller. Prebuild info, the build and its refits
take the choice from the same flags (xdxr_box16), so the sizes stay exact.
Top-level builds keep BOX32 (world space: a half's step is 2 m at 2 km).
Each child box is rounded outward from the exact box kept in scratch, in
integer code (packHalf2x16's rounding is implementation-defined; AMD rounds
toward zero). Past the half range a bound goes to +-inf outward and +-65504
inward, so empty slots stay empty; below the smallest normal half it goes to
0 or +-2^-14, never a denormal a flushing decoder would shrink.
tools/xdxr_bvh.py half_round gets the same denormal rule, and check-build now
compares every BOX16 word bit for bit with encode_box16 of the exact box of
the triangles under it.
Tests: five blas_box16_* cases in vk_xdxr_build_test (radix and small sort,
an inactive triangle, values past 65504 and below 2^-14, a refit), and a
MINIMIZE_MEMORY BLAS plus its in-place update through the D3D12 API in
d3d12_xdxr_rt_test (prebuild and postbuild sizes).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The nonzero-base measurement falsifies the earlier mask. The game passes
ptr >> 8 in the descriptor's dword0 (0x10 for a structure at VA 0x1000), and
the |0x30 its shader ORs is only the temporary root-load address. The original
<< 8 is correct at base 0 and at 0x1000; the GPU returns the CPU walker's
children at both. This commit restores the translator and the test fixture to
main and keeps the measured result in docs/bvh.md 7b and the Ray tracing row.
The game's RT shaders build the BVH descriptor base as (ptr & ~0xFF) | 0x30: a
byte address with flags in the low bits, not the 256-byte-unit field the
emulation assumed (base40 << 8). Masking the low byte fixes the address; a
non-zero base moved every node by 256x the flags.
The semantic test now runs the masked-base case (dword0 0x1030 -> base 0x1000,
node at 0x1040) and fails under the old shift. Measured with the first real
core_bvh4 BLAS (docs/bvh.md 7b): header at VA 0, root 0x4CABC; the game RT
shadow CS returns the CPU walker's children in the same order on the RTX 2060.
The matcher could identify the drawable's geometries but had no way to hand them to tools/bvh_rehydrate.py,
so the recipe §4a implies could not be followed end to end. --write DIR now writes one float3 buffer and one
uint32 index buffer per matched geometry plus an export.json (the instance transform recorded, not applied to
the vertices), which is the shape bvh_rehydrate.py already takes.
docs/bvh.md §7 gains the four steps to rebuild the sample set from the user's own copy - bvh_index, a
levels.rpf window, bvh_match with --write, bvh_rehydrate - with the counts to check them against, and the root
parent-table entry the runtime layout must hold (0xFFFFFFFF, as the GPU builder writes and #2625 validates).
Nothing of the samples enters the repository; the two excluded shader hashes stay with the user.
Checked on the sample pack: --write on one identified sample produced buffers of the same sizes as the earlier
reference export of that BLAS (732/816, 2,736/2,808, 492/576 bytes), and rehydrating them with the recorded
transform gave the declared 18,880 bytes. Synthetic tests: two cases added (the buffers and export.json; nothing
written when no candidate is consistent), 18 in total.
The scan read each digit count and stored its prefix sum over it. MoltenVK 1.4.2's SPIRV-Cross
(6c09849f; MoltenVK main pins aa217aeb, also affected) moves a load through a pointer bitcast
from a uvec2 past a later store to the same address, so the MSL read back the sum it had just
written. The radix path (more than 1,024 elements) then lost and duplicated elements:
blas_three_sort_tiles and blas_refit_in_place failed xdxr_build_check in 10 runs out of 10.
SPIRV-Cross 38abe362 fixes it upstream.
The prefix sums now go to their own scratch array (XdxrLayout::scratch grows by 64 bytes per
tile), so no invocation stores to a word whose loaded value it still uses. xdxr_build.inc
regenerated with glslc (shaderc 2026.4) --target-env=vulkan1.2 -O -mfmt=c.
Tested on an Apple M3 Max, macOS 27.3: xdxr_build_check passes 10 runs out of 10 on Homebrew
MoltenVK 1.4.2 (0/10 before), MoltenVK 5189f8de with SPIRV-Cross 57e4efcc, KosmicKrisp and
llvmpipe. The full native ctest passes 36/36 on each driver, with the same two skips as before.
AI-assisted.