Ray tracing in this fork: what the title does and what has been built
Status, 2026-11-25, 06:00: with VICTORY_BVH_BUILDER=1 the builder runs on
the RX 7900 XTX and rooms get their indirect light (run light-6, the dorm:
bunk, locker, window frame, posters; 100-116 ms a frame against 84-95 without).
Some structures are still wrong; one run of four with it lost the device early,
in a list without a builder stage. Off by default.
What the title does
The title's indirect light (probes, bounce, reflections) and the
shadows of its lamps and sun are ray traced. Without them, anything the sun
does not hit directly is black: interiors, the shadowed side of a face, rooms
lit only by lamps.
The title does not use a ray-tracing API:
- Traversal is ordinary compute-shader code: a per-thread stack in shared
memory, and loads through raw 40-bit addresses of title memory.
- The static world's acceleration structures ship pre-built in the title's
data, in the console GPU's native node format (64-byte nodes: box nodes with
four children and 16-bit float bounds, 128-byte box nodes with 32-bit float
bounds, triangle nodes, instance nodes). They are unpacked on the GPU.
- A set of builder programs (from the title's
XboxBvhBuilder.dll, 52 compute
programs) builds and refits the dynamic structures on the GPU every frame.
- Only the per-node test is hardware: the instructions
image_bvh64_intersect_ray and image_bvh_intersect_ray. One call tests a
ray against a box node's four children (returning the hit children, nearest
first) or against a triangle node (returning the intersection's numerator,
denominator and barycentric numerators).
So mapping this onto the host's own ray tracing (DXR) is not practical: the
layer would have to know the geometry behind structures the title never
describes to it, and the traversal loops live in 64 of the title's own
programs. This fork runs the title's builder and traversal as translated
shaders and emulates the one instruction.
What this fork adds
- The builder programs translate (all 52, with host pipelines on the RX
7900 XTX; the title creates 53 such pipelines). They pass buffer addresses in a spilled parameter table
rather than in descriptors. Added: the spilled user-data table, root
unordered-access views (translator and host binding), byte and 16-bit buffer
accesses, and several control-flow shapes.
- Title memory by raw address from shaders. A directory with one entry per
64 KiB of title address space leads a shader to the layer's host copy of
that memory; loads, stores, atomic add/sub and float min/max go through it.
Before a dispatch the host makes ready the memory its root views and root
constants name.
- The ray test, emulated in DXIL. Four slab tests and a sorting network
for box nodes; a watertight ray/triangle test for triangle nodes; both forms
of the instruction. A plain Rust reference lives in
crates/victory-shader/src/bvh.rs; tests run the emitted DXIL on the GPU
over 311 ray/node cases and compare with the reference bit for bit.
- The trace and shading programs translate (59 of 64 trace programs, and
the irradiance-cache shading program). This needed lane masks treated as
plain numbers on some paths, and exact forms for programs written for
64-lane waves running on a GPU with 32-lane waves.
- A safety rule on the host side. The builder's stages run only while
every builder pipeline the title has created has a host pipeline; otherwise
none run (
VICTORY_BVH_BUILDER=1 asks for it; VICTORY_BVH_QUARANTINE=1
also keeps the builder's stores out of title memory, for a first test). A
partly working builder wrote garbage bounds into title memory and crashed
the title.
The structures (from dumps of the arenas, VICTORY_MEMORY_DUMP)
- Header, 64 bytes: dword 0 the version 6 in the low half and marks in the high
(0x8000 bottom level, 0x4 compacted, 0x2 rehydrated, 0x100 still packed),
dword 1 the size in 64-byte nodes, 3 the number of elements, 4-9 the bounds,
10 the offset of the box nodes, 12 the root's node pointer, 13 the offset of
the elements, 14 the offset of the parent table (from the header; the static
ones' index counts the leaves too, so it is negative).
- An instance is 128 bytes at the top level's offset 13: a 3x4 matrix in dwords
0-11, id and mask, flags, the root pointer (bit 30 set for static ones), the
bottom level's address in 256-byte units.
- The static world's structures are shipped packed ("dehydrated") and
unpacked in place, once, by DecompressHeader, Box32/Box16Rehydration and
LeafRehydration when they have been streamed in (3,000 in the opening).
- Dynamic ones are built, their compacted size read back by the title from a
small buffer, and copied to a place of that size.
How title memory by address is held (memory.rs)
Pages of 64 KiB in arenas on the card, whole title buffers in their own copies,
pages with small title buffers as windows of title memory. The module's
comment has the rules. In short: what the builder stores stays on the card
(only small title buffers it was given to write come back); a packed structure
goes up whole when the builder comes to it; title buffers take its stores only
after it was given them as an unordered access view.
| variable |
does |
VICTORY_BVH_BUILDER=1 |
the builder's stages run |
VICTORY_BVH_QUARANTINE=1 |
nothing it stores comes back to title memory |
VICTORY_MEMORY_CARD_MB |
the most of it on the card (4096) |
VICTORY_MEMORY_DUMP=<folder> |
a file go there writes the arenas out (diagnostics) |
VICTORY_UPLOAD_LOW=0, VICTORY_LENT_HEAP=0 |
lists' upload memory above 2^40, no view heap for lists without one, as before |
Every ten seconds the log has a line "title memory by address: ..." with pages,
dispatches, faults and what came.
Known gaps
- About 4,000 pages a frame that are not there are still touched (the notes'
limit): some structures are wrong and rays go anywhere in them. Guess: sizes
that came back late or not (fixed after light-6, not seen working), so places
overlap.
- Five shadow-mask trace programs do not translate (a structure's address out
of a descriptor picked from the heap by a computed index: the host would have
to give a table of addresses by slot). The title did not create them in any
run so far.
- An access to a page that is not there is lost (a read gives zero, a store is
dropped).
- Not publicly documented, and assumed: the instruction's rounding, the order
of two boxes entered at the same distance, and the result for a ray exactly
through an edge.
Where to look
crates/victory-shader/src/bvh.rs: the reference for the node test.
crates/victory-shader/src/emit/lower.rs: the lowering of the two
instructions and of memory by address (Lower::memory).
crates/victory-shader/src/resource.rs: address tracking for descriptors
and raw addresses.
crates/victory-gpu/src/pipeline.rs, draw.rs: the builder rule and the
host side of root views and title memory.