With hardware ray tracing on, VICTORY_HW_RT_LIFT=0 keeps the whole host side (HLE builder, BLAS/TLAS builds and refits, instance remap, index and vertex copies) but lifts no loop: every ray takes the software walk's forced miss. It tells a device removal in the structure work from one in the lifted traversal. Loops still found and counted (lifted 0, reason VICTORY_HW_RT_LIFT=0); in the shader-cache key when set; warned at load. Test: with LIFT=0 the translation equals the fallback-miss form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PVi6XmTj4ohPL7QwUeFgV4
14 KiB
Ray tracing in this fork: what the title does and what has been built
Status, 2026-11-25, midday: with VICTORY_BVH_BUILDER=1 rooms get their
indirect light (runs light-10, light-11, n19), for some 40 ms more of the
card's time a frame (the dorm: 75 of 90 ms busy against 34 of 64). Off by
default. VICTORY_AMBIENT=1 puts an estimate of that light in its place
for next to nothing (below).
On the card's ray-tracing hardware (VICTORY_HW_RT=1, off)
In place of VICTORY_BVH_BUILDER=1, on a card with DXR 1.1 (ported from
Leslie-d-a/VIctory-NVIDIA-HWRT 61e389e0 and 5f55bca8; original by dakisback2,
ecc49d5b and 72f8316a):
- the title's
XboxBvhBuilder.dllis ours (victory-hlexboxbvh.rs): its calls become host DXR 1.1 bottom and top levels keyed by the console structure's address (victory-gpuhwrt.rs), with refits, a scratch pool, the instances' addresses remapped on the card, and eviction when the title frees the memory. The title's own builder programs do not run; with both switches set, the hardware path is kept and the builder is turned off. - the translator lifts the traversal loops of the trace programs to
RayQuery(victory-shaderemit/rayquery.rs) where every value a loop leaves behind is accounted for. A loop that is not keeps the software walk below; a program whose lifted form is refused is translated again without lifting. The structure is bound as root SRVt230..t241. - the light stand-ins (
VICTORY_AMBIENT, the reflection estimate) stand aside, as with the title's builder. - the log has, per ray-tracing program, "ray queries lifted N of M ..., fell back: ", and every 5 s "ray queries: lifted shaders N, partly N, fell back N (software)" and "hardware RT: BLAS live ...".
VICTORY_HW_RT_REFIT=0 builds dynamic bottom levels whole every time instead
of refitting them; VICTORY_HW_RT_WHY=1 (=2: more) logs why a loop is not
lifted. VICTORY_HW_RT_LIFT=0 (diagnostic, #3706) keeps all of the
hardware path's structure work (the HLE builder, bottom/top level builds and
refits, the instances' remap, the index/vertex copies) but lifts no loop, so
every ray takes the software walk's forced miss: a device removal that stays
with it is in the structure work, one that goes is in the lifted traversal
(read in victory-shader emit/mod.rs hw_rt_lift, in the shader-cache key
when set). On an RTX 4090 (house scene, 300 s): Series S 35 to 37 ms a frame
against 43 to 94 for the builder and the software walk, Series X 1440p 46
against 70.
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_rayandimage_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=1asks for it;VICTORY_BVH_QUARANTINE=1also 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_HW_RT=1 |
the card's ray-tracing hardware in its place (above) |
VICTORY_BVH_FENCES=0 |
no fences around the builder's buffer atomics (beloooo's 72e748ea has them too) |
VICTORY_BVH_SIZES_WAIT=1 |
submissions that ask for structures' sizes are waited for (off: no help, slow) |
VICTORY_BVH_BOUNDS=0 |
the builder's accesses are not bounded |
VICTORY_BVH_TRACE=1 |
logs what sizes are asked, when they came, and the copies (diagnostics); every 600 frames a line "bvh trace summary" counts, for the whole run, the copies made while the size's place held another value and the copies that land on another |
VICTORY_BVH_TRACE=1 |
logs what sizes are asked, when they came, and the copies (diagnostics) |
VICTORY_BVH_SIZE_ANSWER=0 |
leaves compacted-size slots to the builder's own late store (on by default) |
VICTORY_BVH_QUARANTINE=1 |
nothing it stores comes back to title memory |
VICTORY_RT_FAULT_MB |
the budget for pages taken by faults (1024 MiB) |
VICTORY_RT_FAULT_KEEP=0 |
keep the old, once-only count of 2048 faulted pages |
VICTORY_MEMORY_CARD_MB |
the most of it on the card (4096) |
VICTORY_MEMORY_OWNED=0 |
the kernel is asked what was written in the arenas and the directory, as before (on: memory.rs tells its own writes) |
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
- Dynamic structures overlap each other (8 of 65 good in run light-10, 48 of
275 in light-15). Part of the cause, run light-11's trace (
VICTORY_BVH_TRACE=1): the title asks for a new structure's compacted size, reads it one or two frames later without looking whether it is there, takes memory of that size and has the structure copied into it. Our submissions land up to two frames late; the title read what the slot held before, another structure's size, and the copy wrote over the neighbours. Waiting for a submission that asks (VICTORY_BVH_SIZES_WAIT=1) did not mend it and costs some 20 ms a frame (light-15): the title asks in every frame, and what it read was as old as before. Open. WithVICTORY_THINthe title's submit calls return at once (VICTORY_ASYNC_SUBMIT) and the title runs up to a frame ahead of our submitting thread, so a wait there comes after the title has read the slot; the slot is reused by the next frame's asking, and the title reads it in the same frame. Holding the title at its present did not change it; holding its submit of the asking list until the size had landed gave up (30-150 ms): the asking submission is not sent while the title is held, and it runs behind the frame before on the one host queue (runs of 2026-11-28, RTX 5080, the summary line ofVICTORY_BVH_TRACE: hundreds of copies landing on others right after loading and at cutscene changes, next to none in a steady scene). - Dynamic structures could overlap each other (8 of 65 good in run light-10,
48 of 275 in light-15): the title asks for a new structure's compacted
size, reads it one or two frames later without looking whether it is there,
takes memory of that size and has the structure copied into it. Our
submissions land late, so it could read another structure's size. With
VICTORY_BVH_SIZE_ANSWER(on unless0), the builder's prebuild and batched-build methods are watched and its own maximum size for those inputs is in the slot when the title reads it. A slot that holds such an answer keeps it against the builder's late store until the title asks for another kind of information there. Waiting for a submission that asks (VICTORY_BVH_SIZES_WAIT=1) did not mend it and cost some 20 ms a frame (light-15). - What a structure that was written over says of its size sent the builder's
copy of it through gigabytes of other structures; bounded now
(
VICTORY_BVH_BOUNDS). Pages touched that are not there: 2,500 a frame before, 90 after (the dorm). - The card's time in the dorm with the builder (timing run light-13, title's
commands 84 ms):
CopyForBVHUpdate13.3 ms in 63 dispatches (before the bound), traces 24 ms (RaytraceVBuffer7.9, screen probes 6.4, irradiance cache 3.5, primary probes 2.3, shadows 1.6). - Captures made on 2026-11-25 (builder on or off) hang the card in a replay (cause unknown; do not try).
- 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). Pages taken by faults are now kept under a byte budget: the oldest that no structure owns and no shader has looked at lately go back first, so later faults can still be mapped.
- 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.
Without rays: the stand-in (crates/victory-gpu/src/ambient.rs)
Without structures every ray misses. The title's program that resolves the
diffuse light of its screen probes (CS_ScreenProbes_TemporalResolve_*, list
184 of a frame) then leaves the sky's light outdoors, nothing indoors, and in
blocks of tiles what the probes' memory held. VICTORY_AMBIENT=<share> raises
it to an estimate right after that program: the title keeps, for its own screen
traces, the light visible surfaces send out (CS_CacheScreenSpaceRadiance,
1280x720, the frame before); its mean in 64x36 cells is gathered at 160x90
points, each cell weighted by the share of the surroundings it covers, as a
directional value; each pixel takes it between the points by depth, with its
normal and a shade in creases. So level and tint follow the hour, the room and
its lamps. What the program left counts up to four times the estimate.
Where it can be put, and the crease shade, are beloooo's (VIctory-Belobug-AMD
06031237, 4f45ab88, cd9f78ce); VICTORY_AMBIENT=constant:<level> is that
fork's constant.
| variable | does |
|---|---|
VICTORY_AMBIENT=<share> |
the estimate, 1 all of it (unset: the title's own) |
VICTORY_AMBIENT=constant:<level> |
the same light everywhere |
VICTORY_AMBIENT_SHADE=<strength>,<metres> |
the creases (1,0.6) |
VICTORY_AMBIENT_AIR=<multiple> |
what the air scatters is bounded by a multiple of the light around (off: the brown veil in the day room stays with it, light-14) |
It is off while the builder runs.
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.