Hardware ray tracing: run the title's structure builder only where the title reads its result (VICTORY_HW_RT_LEAN_BUILDER=1, off by default) #274

Open
github-bot wants to merge 4 commits from github-bot/gh-274 into main AGit
Owner

@⁠LOCKhart07 on GitHub · 2026-12-03 00:21 UTC · original
LOCKhart07:hwrt-lean-builder → main · +18188 −86 · 31 files · 4 commits · open

These depend on each other. Merge order: #262, then #274 and #306 in either order, then #323, then #328.

  • #262: hardware ray tracing by ray queries and a builder tap (VICTORY_HW_RT=1). The base; merge first.
  • #274: run the title's structure builder only where its result is read (VICTORY_HW_RT_LEAN_BUILDER=1). On #262. (this one)
  • #306: card memory: send buffers used again, structures in shared blocks, textures placed tight. On #262.
  • #323: build idle updatable structures again as compact ones (VICTORY_HW_RT_DEMOTE=1). On #306.
  • #328: empty sparse blocks of long-lived structures and give them back (VICTORY_HW_RT_PACK=1). On #323.

All five together, current with main: #342.

#274 and #306 are both on #262 and not on each other. #323 has #306's commits in it until that merges.


Stacked on #262: only the last commit is new here. The first three are that pull request and drop out of this diff once it merges.

What

With VICTORY_HW_RT=1 every traversal loop is a ray query on the host structures, and those are built from the title's inputs. Nothing of ours reads what the title's structure builder writes any more, but it still runs every stage on the card.

The title itself reads one result of it: the compacted size a build is asked for through its postbuild descriptions. That number is the node count of the tree the build made, so only the builder can give it exactly.

VICTORY_HW_RT_LEAN_BUILDER=1 (off by default, ignored without VICTORY_HW_RT=1) keeps the builder for those requests and drops the rest:

  • Kept: a bottom-level build that carries postbuild descriptions, and a copy of a structure a kept build made. They run as before and the title reads its own size.
  • Skipped: every other build, update, top-level build, rehydrate and copy. The title's export is still called, so its checks and return values stay its own; the builder dispatches it records are dropped when the list is translated, before anything is bound. A batched call is given to the export as runs, in its order.
  • Lost: a request that asks a size and cannot be kept (a top-level build, or an update of a structure no kept build made). It is skipped, counted and logged as an error. None was seen.

The builder's stages run all or none, so whole calls are kept or skipped, and a kept stage only reads what a kept one wrote.

Checks in the log

  • A lean builder: line counts requests kept, skipped by kind, copies kept and skipped, losses, and builder dispatches dropped per frame.
  • An error is logged if any dispatch reads title memory by address while the switch is on (a program that was not lifted).

Measured

RX 9070 XT, 2560x1440, by the builder's own stamps (VICTORY_RT_STAMPS=rt), one run each:

Builder card time per frame
Standing still, before 2.05 ms
Standing still, with the switch 0.1 ms (98 dispatches dropped per frame)
Driving, with the switch 1.4 ms mean, 0.7 ms median

In both runs with the switch: 0 lost, every hardware ray-tracing loss counter 0, 0 dispatches reading title memory by address, no error lines. What is left while driving is the full builds that ask a size as the world streams in.

It frees no card memory: the title allocates a structure before it asks the builder.

Not checked

  • The two runs were made on my local branch, which carries the same change on top of other local work. On this branch the commit compiles (release and diagnostics) and its unit tests pass, but it has not been run in the title.
  • No frame-for-frame picture comparison; by eye nothing new showed in a short drive.
  • Only one scene standing still and one short drive.

🤖 Generated with Claude Code

**@⁠LOCKhart07** on GitHub · 2026-12-03 00:21 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/274) `LOCKhart07:hwrt-lean-builder` → `main` · +18188 −86 · 31 files · 4 commits · open ## Related pull requests These depend on each other. Merge order: #262, then #274 and #306 in either order, then #323, then #328. - #262: hardware ray tracing by ray queries and a builder tap (`VICTORY_HW_RT=1`). The base; merge first. - #274: run the title's structure builder only where its result is read (`VICTORY_HW_RT_LEAN_BUILDER=1`). On #262. **(this one)** - #306: card memory: send buffers used again, structures in shared blocks, textures placed tight. On #262. - #323: build idle updatable structures again as compact ones (`VICTORY_HW_RT_DEMOTE=1`). On #306. - #328: empty sparse blocks of long-lived structures and give them back (`VICTORY_HW_RT_PACK=1`). On #323. All five together, current with main: #342. #274 and #306 are both on #262 and not on each other. #323 has #306's commits in it until that merges. --- Stacked on #262: only the last commit is new here. The first three are that pull request and drop out of this diff once it merges. ## What With `VICTORY_HW_RT=1` every traversal loop is a ray query on the host structures, and those are built from the title's inputs. Nothing of ours reads what the title's structure builder writes any more, but it still runs every stage on the card. The title itself reads one result of it: the compacted size a build is asked for through its postbuild descriptions. That number is the node count of the tree the build made, so only the builder can give it exactly. `VICTORY_HW_RT_LEAN_BUILDER=1` (off by default, ignored without `VICTORY_HW_RT=1`) keeps the builder for those requests and drops the rest: - **Kept:** a bottom-level build that carries postbuild descriptions, and a copy of a structure a kept build made. They run as before and the title reads its own size. - **Skipped:** every other build, update, top-level build, rehydrate and copy. The title's export is still called, so its checks and return values stay its own; the builder dispatches it records are dropped when the list is translated, before anything is bound. A batched call is given to the export as runs, in its order. - **Lost:** a request that asks a size and cannot be kept (a top-level build, or an update of a structure no kept build made). It is skipped, counted and logged as an error. None was seen. The builder's stages run all or none, so whole calls are kept or skipped, and a kept stage only reads what a kept one wrote. ## Checks in the log - A `lean builder:` line counts requests kept, skipped by kind, copies kept and skipped, losses, and builder dispatches dropped per frame. - An error is logged if any dispatch reads title memory by address while the switch is on (a program that was not lifted). ## Measured RX 9070 XT, 2560x1440, by the builder's own stamps (`VICTORY_RT_STAMPS=rt`), one run each: | | Builder card time per frame | |---|---| | Standing still, before | 2.05 ms | | Standing still, with the switch | 0.1 ms (98 dispatches dropped per frame) | | Driving, with the switch | 1.4 ms mean, 0.7 ms median | In both runs with the switch: 0 lost, every hardware ray-tracing loss counter 0, 0 dispatches reading title memory by address, no error lines. What is left while driving is the full builds that ask a size as the world streams in. It frees no card memory: the title allocates a structure before it asks the builder. ## Not checked - The two runs were made on my local branch, which carries the same change on top of other local work. On this branch the commit compiles (release and diagnostics) and its unit tests pass, but it has not been run in the title. - No frame-for-frame picture comparison; by eye nothing new showed in a short drive. - Only one scene standing still and one short drive. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The title's ray-tracing programs walk the console's structures in a loop
of their own. With VICTORY_HW_RT=1 the translator recognises each such
loop and writes a DXIL RayQuery in its place, keeping the title's own
hit tests, masks and ordering rules as the candidate and commit steps.
A loop it cannot prove equivalent stays as translated before.

Ported from VIctory-NVIDIA PR #3706 (GPL-3.0), with the lifter's
exactness rules of dakisback2/VIctory-Nvidia-Linux (85b0b11b, 5485daf7)
by way of Leslie-d-a/VIctory-NVIDIA-HWRT; see the header of
emit/rayquery.rs.

New here: the 14 loops those leave unlifted (6 programs, given a forced
miss there). The console compiler reuses three registers as loop scratch
on the lanes that run the loop and reads their old values on the lanes
that do not; the lane sets pass through mask joins the lifter could not
relate. Joins whose inputs are all one mask now collapse to it, and the
reading lanes are refuted against the loop's entry lanes by an exact
search (Bools::sat_with; out of budget refuses). All 64 ray-tracing
programs and their 397 loops lift and pass the DXIL validator.

Two fixes on the way, with the switch off too (translator version up):
the sign of zero in v_mad_legacy, and partial stores through a counter
view. Apart from those, the output with the switch off is unchanged.

`victory translate` names an emit panic per program and prints a
ray-tracing summary. A run refuses the switch until the host side is in.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The host side of the lifted ray queries. Started from VIctory-NVIDIA
PR #3706 (GPL-3.0) as ported to RADV by
MJ26gaming/victory-rdna4-linux-rt-MJ26 365fad515; see the header of
hwrt.rs for what was taken and what was left out.

The title's structure builder keeps running (a tap, not a replacement):
its build, refit and copy calls are passed on, and the same triangles
and instances go into host bottom- and top-level structures that the
lifted programs trace.

- Inputs follow the console builder's rules: only a NaN in X makes a
  triangle inactive; infinite and far positions pass through; indices
  and meshlets past the stated counts read the title's real bytes.
  Every departure is counted by what it changed, and bytes that cannot
  be read are a counted loss, never a silent zero.
- No budget evicts a structure and no instance is masked.
- Host work is recorded in the title's lists at the title's call, and a
  ledger keeps it in the card's order. Structures that are not refit
  are compacted exactly.
- Loss counters are printed with the frame-rate lines; all 0 over the
  check runs.
- VICTORY_RT_STAMPS=rt (diagnostics) stamps only the ray-tracing
  dispatches and the host builds. Over two 5 minute runs in the same
  place: trace passes 5.4 ms a frame as translated loops, 0.9 ms as
  ray queries, plus 0.5 ms for the host builds.
- A run takes VICTORY_HW_RT=1. Not yet checked hit for hit against the
  console's own walk on a captured frame.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
In free play the host structures grew past 7 GB in a few minutes and
kept growing. Measured by what each buffer holds, almost all of it was
structures kept at the driver's largest size:

- An updatable structure costs about four times a compacted one's bytes
  a triangle on RADV (its refit needs a fixed leaf region), and the
  title allows updates of many structures it never updates, or updates
  once. A structure is now built without ALLOW_UPDATE on the host, and
  becomes updatable only when the title updates it again within a
  second of its last update; an update short of that is built in full,
  the same triangles.
- Every structure built without ALLOW_UPDATE is compacted by the host
  once built, through the tickets the title's own COMPACT copies use:
  rehydrates (ready-made on the console, never copied by the title) and
  the title's builds it does not copy.
- Structures the title builds over are dropped: the builder's own
  prebuild sizes are tapped, and a structure kept at an address inside
  the bytes a new build was given goes, as with freed title memory.

The report says where the bytes are: alive by what they hold, in the
tap's map or outside it, updatable ones by their last update and by
how many updates they had, the host's own cost (buffers made,
compaction points), and the console's bytes next to the host's where
the console's are known. An event the card's order refuses is logged
with what the ledger held there.

Over a 3 minute drive: 7.3 GB and growing before; steady between 2.1
and 2.5 GB after, every loss counter 0.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
With hardware ray tracing nothing of ours reads what the title's
structure builder writes: every traversal loop is a ray query on the
host's structures, and those are built from the title's inputs. The
title reads one result of it: the compacted size a build is asked for,
which is the node count of the tree that build made, read back a frame
or two later to size the copy. No other program can give that number.

With the switch (only with VICTORY_HW_RT=1) each request of a tapped
call is kept or skipped:

- A bottom-level build that carries postbuild descriptions is kept:
  the builder runs it as ever and the title reads its own size. A copy
  of a structure a kept build made is kept too.
- Every other build, update, top-level build, rehydrate and copy is
  skipped. The title's export is still called, so its checks and
  results stay its own, between two marks in the list: the builder's
  dispatches recorded between them are dropped when the list is
  translated, before anything is bound. A batch is given to the export
  as runs, in its order.
- A request that asks a size and cannot be kept (a top-level build, an
  update of a structure no kept build made) is skipped, counted and
  logged as an error. None was seen.

The builder's stages run all or none, so whole calls are kept or
skipped, and a kept stage reads only what a kept one wrote.

A report line counts requests kept, skipped by kind, copies, losses
and dispatches dropped; an error is logged if a dispatch reads title
memory by address while the switch is on (a program not lifted).

By the builder's own stamps, standing still: 2.05 ms of card time a
frame before, 0.1 ms with the switch (98 dispatches dropped a frame).
Driving: 1.4 ms mean. Losses 0 in both, every hardware ray-tracing
loss counter 0.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 00:27:13 +00:00
Author
Owner

@⁠lucamzanon on GitHub · 2026-12-03 12:37 UTC · original · edited 2026-12-03 13:25 UTC

Automated A/B/B/A Benchmark Feedback (RX 9070 XT / Linux RADV)

Test setup:

  • Hardware / OS: AMD Radeon RX 9070 XT 16 GB (RDNA4, RADV GFX1201), Ryzen 7 5700X, 46 GB RAM, Ubuntu 26.04.1 LTS (kernel 7.0.0-44-generic), repo-built Mesa 26.3.1 RADV + vkd3d-proton
  • Settings: VICTORY_BENCH=rt, VICTORY_BENCH_MINUTES=2 (first 60 s discarded, second 60 s measured), 2560x1440 → 4K FSR 4 Quality, no Frame Generation
  • Methodology: Interleaved A -> B -> B -> A (4 runs per scene), identical save restored before every run, shared warm pipeline cache (94,199 pipelines), HW RT shaders pre-translated (./run.sh shaders VICTORY_HW_RT=1, 25,694 shaders)
    • A (baseline): main (842767a, RDNA4 native ray-node test on=true)
    • B (candidate): PR #274 merged with main, VICTORY_HW_RT=1 VICTORY_HW_RT_LEAN_BUILDER=1

Results:

Scene Baseline A (avg / 1% low) Candidate B (avg / 1% low) Delta Pair wins
Boat (2m x 4) 30.30 fps (30.4 / 30.2) / 10.10 Timed out / hung on both B runs (361 s / 363 s, no bench_results.txt) — 0/2
Prison (2m x 4) 21.15 fps (20.9 / 21.4) / 6.35 19.05 fps (18.4 / 19.7) / 5.85 -9.93% avg / -7.87% 1% low 0/2

Per-run Prison breakdown:

  • Run 1 (A): 20.90 fps (1% low 6.00, peak 27.90, 142.3 s)
  • Run 2 (B): 18.40 fps (1% low 5.80, peak 24.20, 275.4 s — includes initial HW RT pipeline compile)
  • Run 3 (B): 19.70 fps (1% low 5.90, peak 26.20, 144.4 s — warm)
  • Run 4 (A): 21.40 fps (1% low 6.70, peak 28.00, 142.2 s)

Notes: Even on the warm B run (Run 3), Prison was ~7% slower than baseline A, and Boat did not complete within the timeout on either B run. Possibly because RDNA4 already runs native hardware ray-node tests on main, so the extra host TLAS/BLAS maintenance outweighs the traversal savings here. Happy to re-test if you push updates!

Caveat: These runs used default VICTORY_BENCH=rt without scripted gameplay movement (VICTORY_KEYS / VICTORY_KEYS_WORLD), so they mostly measure stationary/cutscene frames. Updating our harness to inject scripted movement via diag + VICTORY_KEYS_WORLD and will follow up with moving-gameplay numbers.

**@⁠lucamzanon** on GitHub · 2026-12-03 12:37 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/274#issuecomment-7378587543) · edited 2026-12-03 13:25 UTC ### Automated A/B/B/A Benchmark Feedback (RX 9070 XT / Linux RADV) **Test setup:** - **Hardware / OS:** AMD Radeon RX 9070 XT 16 GB (RDNA4, `RADV GFX1201`), Ryzen 7 5700X, 46 GB RAM, Ubuntu 26.04.1 LTS (kernel `7.0.0-44-generic`), repo-built Mesa 26.3.1 RADV + vkd3d-proton - **Settings:** `VICTORY_BENCH=rt`, `VICTORY_BENCH_MINUTES=2` (first 60 s discarded, second 60 s measured), 2560x1440 → 4K FSR 4 Quality, no Frame Generation - **Methodology:** Interleaved `A -> B -> B -> A` (4 runs per scene), identical save restored before every run, shared warm pipeline cache (94,199 pipelines), HW RT shaders pre-translated (`./run.sh shaders VICTORY_HW_RT=1`, 25,694 shaders) - **A (baseline):** `main` (`842767a`, RDNA4 native ray-node test `on=true`) - **B (candidate):** PR #274 merged with `main`, `VICTORY_HW_RT=1 VICTORY_HW_RT_LEAN_BUILDER=1` **Results:** | Scene | Baseline A (avg / 1% low) | Candidate B (avg / 1% low) | Delta | Pair wins | |---|---:|---:|---:|---:| | **Boat** (`2m x 4`) | **30.30 fps** (`30.4` / `30.2`) / **10.10** | **Timed out / hung** on both B runs (361 s / 363 s, no `bench_results.txt`) | — | 0/2 | | **Prison** (`2m x 4`) | **21.15 fps** (`20.9` / `21.4`) / **6.35** | **19.05 fps** (`18.4` / `19.7`) / **5.85** | **-9.93%** avg / **-7.87%** 1% low | 0/2 | **Per-run Prison breakdown:** - Run 1 (A): `20.90 fps` (1% low `6.00`, peak `27.90`, 142.3 s) - Run 2 (B): `18.40 fps` (1% low `5.80`, peak `24.20`, 275.4 s — includes initial HW RT pipeline compile) - Run 3 (B): `19.70 fps` (1% low `5.90`, peak `26.20`, 144.4 s — warm) - Run 4 (A): `21.40 fps` (1% low `6.70`, peak `28.00`, 142.2 s) **Notes:** Even on the warm B run (Run 3), Prison was ~7% slower than baseline A, and Boat did not complete within the timeout on either B run. Possibly because RDNA4 already runs native hardware ray-node tests on `main`, so the extra host TLAS/BLAS maintenance outweighs the traversal savings here. Happy to re-test if you push updates! > **Caveat:** These runs used default `VICTORY_BENCH=rt` without scripted gameplay movement (`VICTORY_KEYS` / `VICTORY_KEYS_WORLD`), so they mostly measure stationary/cutscene frames. Updating our harness to inject scripted movement via `diag` + `VICTORY_KEYS_WORLD` and will follow up with moving-gameplay numbers.
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 12:02 UTC · original · edited 2026-12-05 11:24 UTC

As I read it, this is superseded, like the rest of the stack: every later PR in it contains this PR's commits, so this diff is 18,188 lines of which ~18,000 are under review elsewhere.

One commit here should survive as its own small PR once the stack has a home: d766d8b / crates/victory-gpu/src/builder_lean.rs:45-55 reads the switch, warns loudly when it is set without VICTORY_HW_RT=1, and explains why. That is the model the rest of the stack should follow — with the exception that VICTORY_HW_RT_LEAN_BUILDER is, like VICTORY_HW_RT, documented nowhere.

Also, builder_lean.rs:284 tells the user to run without the switch when a build the title reads was skipped, i.e. the failure mode is a visibly wrong picture and the recovery is a restart. For an experimental switch that is acceptable only if the loss is also counted somewhere a tester can read afterwards; today it is printed, not counted.

Staleness is the worst of the six (251 commits behind, five conflicting files, all in the shader emitter where main is moving fastest), so rebasing this branch is a project rather than a task.

Whether it still has work of its own is the maintainer's call, not mine.

**@⁠Luxuride** on GitHub · 2026-12-04 12:02 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/274#issuecomment-7410887421) · edited 2026-12-05 11:24 UTC As I read it, this is superseded, like the rest of the stack: every later PR in it contains this PR's commits, so this diff is 18,188 lines of which ~18,000 are under review elsewhere. One commit here should survive as its own small PR once the stack has a home: `d766d8b` / `crates/victory-gpu/src/builder_lean.rs:45-55` reads the switch, warns loudly when it is set without `VICTORY_HW_RT=1`, and explains why. That is the model the rest of the stack should follow — with the exception that `VICTORY_HW_RT_LEAN_BUILDER` is, like `VICTORY_HW_RT`, documented nowhere. Also, `builder_lean.rs:284` tells the user to run without the switch when a build the title reads was skipped, i.e. the failure mode is a visibly wrong picture and the recovery is a restart. For an experimental switch that is acceptable only if the loss is also *counted* somewhere a tester can read afterwards; today it is printed, not counted. Staleness is the worst of the six (251 commits behind, five conflicting files, all in the shader emitter where main is moving fastest), so rebasing this branch is a project rather than a task. Whether it still has work of its own is the maintainer's call, not mine.
Author
Owner

@⁠LOCKhart07 on GitHub · 2026-12-04 14:34 UTC · original

Split as asked: the lean builder is one branch, rt-3-lean on my fork, on top of the two base branches (#468 is the first).

On your two points: VICTORY_HW_RT_LEAN_BUILDER is documented in both files. And the loss is now counted, not only said: the dispatches that read title memory by address while the builder was skipped go into the lean builder: report line ("a picture loss if not 0"). The requests it could not keep were already counted there.

The bench above (a hang on one scene, 10 % slower on another) is not answered: I have not reproduced it and have no run of this branch on current main.

This one can be closed.

**@⁠LOCKhart07** on GitHub · 2026-12-04 14:34 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/274#issuecomment-7414540088) Split as asked: the lean builder is one branch, `rt-3-lean` on my fork, on top of the two base branches (#468 is the first). On your two points: `VICTORY_HW_RT_LEAN_BUILDER` is documented in both files. And the loss is now counted, not only said: the dispatches that read title memory by address while the builder was skipped go into the `lean builder:` report line ("a picture loss if not 0"). The requests it could not keep were already counted there. The bench above (a hang on one scene, 10 % slower on another) is not answered: I have not reproduced it and have no run of this branch on current main. This one can be closed.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/intersect_tests.rs
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/mod.rs
  • crates/victory-shader/src/emit/size_tests.rs
  • crates/victory-shader/src/lib.rs
  • crates/victory-shader/src/structure.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/274/head:github-bot/gh-274'
git switch 'github-bot/gh-274'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-274'
git switch 'github-bot/gh-274'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-274'
git switch 'github-bot/gh-274'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-274'
git switch 'main'
git merge --squash 'github-bot/gh-274'
git switch 'main'
git merge --ff-only 'github-bot/gh-274'
git switch 'main'
git merge 'github-bot/gh-274'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.