Preserve physical window aliases across remaps, order console list values,
and replay bounded indirect graphics with captured draw state. Coordinate
pipeline lifetime, texture refresh and queue teardown. Add synthetic CPU
and GPU coverage for the integrated paths.
Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-authored-by: ivanepsilondelta <264061546+ivanepsilondelta@users.noreply.github.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>
- GetRaytracingAccelerationStructurePrebuildInfo's KHR path passes
LOW_MEMORY for MINIMIZE_MEMORY, as the build now does (Vulkan sizes a build
with identical flags).
- check-build enforces a case's "box16" field (only BOX16 or only BOX32
inner nodes), so a BOX16 case that came out BOX32 cannot pass the bit
check vacuously; the vk and D3D12 BOX16 cases set it.
- Comments: half_round's inward overflow, the remap byte's positions, what
the half-rounding table test covers, and what an update that breaks
D3D12's flag or ALLOW_UPDATE rules would do.
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>
docs/bvh.md 3.1: u32@0x20 = 0x140 + 64 * totalSizeIn64BNodes, 271,627 of
271,627 streams. xdxr_build.comp wrote total_size / 64; the copy and
postbuild paths read the field as the whole size, and tools/xdxr_bvh.py
wrote and validated it the same way. Now the header writes total / 64 - 1,
MODE_COPY_AS and MODE_POSTBUILD use (field + 1) * 64, validate() and the
reference builder agree, xdxr_build.inc is regenerated (glslc 2026.4) and
d3d12_xdxr_rt_test reads the size the same way.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
CopyRaytracingAccelerationStructure and EmitRaytracingAccelerationStructure-
PostbuildInfo were not implemented, and the postbuild descs of
BuildRaytracingAccelerationStructure were ignored.
- CLONE and COMPACT copy the structure's bytes (MODE_COPY_AS). XDXR records
are position-independent: node pointers count from the structure's start
and a TLAS names its BLASes by address. The size comes from the source
header, so a copy can follow a build in the same list; the destination
resource bounds it.
- COMPACTED_SIZE and CURRENT_SIZE (MODE_POSTBUILD) are totalSizeIn64BNodes *
64: a build is already exactly its layout's size. Written for
EmitRaytracingAccelerationStructurePostbuildInfo and for each postbuild
desc of a build, after it.
- New IR commands CopyAccelerationStructure and AccelerationStructurePostbuild.
Serialization, deserialization and tools visualization are refused at
replay. With LEONIDA_RT_AS=khr the postbuild descs stay ignored, as before.
- vk_xdxr_build_test: a clone of blas_random, its COMPACTED_SIZE (== layout
size), a compaction into exactly that size with a guard word after it, and
a clone of the refitted TLAS.
- d3d12_xdxr_rt_test: EmitRaytracingAccelerationStructurePostbuildInfo for
both structures and a TLAS rebuild with a CURRENT_SIZE desc (all equal to
the prebuild sizes), then COMPACT into a buffer of that size, checked as
d3d12_blas_compacted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An update (same topology, new positions or instance transforms) now keeps the
source's tree and recomputes its boxes: the source is copied to the
destination unless it is the destination (MODE_COPY), the elements are
rewritten at their slots, MODE_LEVEL with arg2 = 1 recomputes each node's
boxes from the children it already points to, and the header gets the new
bounds. No Morton pass, no sort, and the parent table is kept.
RTX 2050: 1,000 triangles 0.07 ms (build 0.19), 100,000 1.02 ms (2.24),
1,000,000 9.8 ms (22.0); Iris Xe 13.1 ms for 1M (47.9).
- XdxrBuilder::record_blas / record_tlas take `update_from`; the Vulkan
backend passes the source (or the destination, for an in-place update)
when the D3D12 build has PERFORM_UPDATE.
- vk_xdxr_build_test: a 3,000-triangle BLAS refitted in place (radix-sort
tree), an R32-indexed grid refitted into another buffer (its untouched
source is checked too), and the TLAS refitted after its instances move;
the timing mode also times refits.
- d3d12_xdxr_rt_test: the BLAS is built with ALLOW_UPDATE, its soup moves,
and a PERFORM_UPDATE in place is checked as d3d12_blas_update.
- tools/xdxr_bvh.py check-build: the case being checked answers reads at its
address first (an in-place update leaves two dumps at one address).
A sabotaged refit (no box pass) fails every update case.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The game's translated RT shaders read the console's XDXR records, which a
VkAccelerationStructureKHR is not (docs/d3d12_vulkan.md 4.8). The standalone
Vulkan device now builds them with src/xdxr_build.h, unless LEONIDA_RT_AS=khr
keeps #743's KHR builds (the proposal in the maintainer decisions of #1548).
- VulkanDeviceInfo::xdxr_acceleration_structures; the standalone device sets
it with bufferDeviceAddress and then leaves the KHR extensions off, so
acceleration-structure buffers keep their console VAs.
- VulkanContext owns an XdxrBuilder; replay checks the inputs while the list
is prepared (R32G32B32/R32G32 vertices, none/R16/R32 indices, addresses,
counts) and records the build with heap_base added to every VA and as the
bias for instance BLAS addresses.
- GetRaytracingAccelerationStructurePrebuildInfo answers from XdxrLayout,
exactly; an update rebuilds, so it needs the same scratch.
- The geometry's vertex format is mapped per DXGI format (an unknown one is
refused instead of read as R32G32B32), and its D3D12 flags reach the build.
- test/d3d12_xdxr_rt_test.cpp: a two-geometry BLAS (a soup; an R16-indexed
grid with stride 16 and a transform) and a TLAS of three instances through
the D3D12 API; ctest d3d12_xdxr_rt + d3d12_xdxr_rt_check.
- tools/xdxr_bvh.py: check-build compares TLAS hits by (geometry, primitive),
and skips (77) when the build step wrote no cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>