Hardware ray tracing: lift the structure walks to ray queries, host structures by a builder tap (VICTORY_HW_RT=1, off by default) #262
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!262
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-262"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@LOCKhart07 on GitHub · 2026-12-02 22:11 UTC · original
LOCKhart07:hw-rt-queries→main· +17618 −96 · 29 files · 4 commits · openRelated pull requests
These depend on each other. Merge order: #262, then #274 and #306 in either order, then #323, then #328.
VICTORY_HW_RT=1). The base; merge first. (this one)VICTORY_HW_RT_LEAN_BUILDER=1). On #262.VICTORY_HW_RT_DEMOTE=1). On #306.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.
What
Hardware ray tracing behind
VICTORY_HW_RT=1(off by default). With the switch off no host structure is made, and translations are what they were apart from two small translator fixes (point 6 below).With it on:
Translator (first commit): each loop in which a ray-tracing program walks the console's structures is recognised and written as a DXIL
RayQuery, keeping the title's own hit tests, masks and ordering as the candidate and commit steps. A loop that cannot be proven equivalent stays as translated before.Host (second commit): the title's structure builder keeps running; its build, refit and copy calls are tapped, and the same triangles and instances go into host bottom- and top-level structures that the lifted programs trace.
Host memory (third commit): keeps those structures small in free play (point 7 below).
Developed and measured on an RX 9070 XT with RADV and vkd3d-proton, on the unified-memory path.
Where it comes from
This is a port, not new invention, and the credit belongs upstream of us:
85b0b11b,5485daf7), by way of Leslie-d-a/VIctory-NVIDIA-HWRT.365fad515, which is #3706's host half on RADV.The file headers say the same. What follows is what is different here.
What is different from those
1. No forced misses: 64 of 64 programs, 397 of 397 loops lifted.
The earlier ports leave 6 programs partly lifted (14 loops) and give those rays a miss, which their notes put at about 1 % darker. All 14 are one shape: the console compiler reuses three registers as loop scratch on the "then" lanes and reads their original values on the "else" lanes, and the lifter could not relate the two lane sets because they pass through mask joins. The lifter now proves it exactly: joins whose inputs are all one mask collapse to that mask, and the read's lanes are then refuted against the loop's entry lanes by an exact search (
Bools::sat_with; out of budget means refuse, never guess). With that, all 397 loops lift and all 64 programs pass the DXIL validator.2. The title's builder is tapped, not replaced.
The console structures stay real, so sizes, compaction and validation the title asks about are its own answers, and anything that still walked them would walk real data. The cost is that the builder's dispatches still run (see the numbers).
3. Inputs follow the console builder, not a safer rule.
Read from the builder's own triangle loader: it has no bounds at all, and skips a triangle only when a vertex's X is NaN. So here:
Every one of these is counted by what it really changed (on the card and on the processor), and printed.
4. No eviction, no masked instances.
No budget drops a bottom-level structure and hides its instances. Memory is kept down by compaction and by not keeping structures updatable that are not updated (point 7), never by dropping one the title still holds.
5. Builds in the card's order.
Host builds, refits and copies are recorded inside the title's own lists at the point of the title's call, and a ledger keeps what each top-level structure refers to in the order the card will run it. This removed an ordering race between a top-level build and the bottom-level builds it refers to when lists are submitted in a different order than they were recorded.
6. Two translator fixes found on the way (both on the path with the switch off too, so the translator version goes up): the sign of zero in
v_mad_legacy, and partial stores through a counter view.7. Host structures stay small in free play (third commit).
In a first free-play session (driving through the city) the host structures passed 7 GB in a few minutes and kept growing, the card filled and the frame rate collapsed, with every loss counter still 0. Measured by what each buffer holds, it was not a leak but size: 86 % of the bytes were structures built with
ALLOW_UPDATEand uncompacted copies of them. Read from the driver's source: on RADV (BVH8) an updatable structure takes about 177 bytes a triangle against about 46 for a compacted one, and compacting an updatable one can trim only 15 to 20 %, because the refit needs a fixed leaf region. The title allows updates of many structures it never updates, or updates once. So:ALLOW_UPDATEon 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), so nothing about the hits changes, only the host's bytes and build time;ALLOW_UPDATEis compacted by the host once built, through the same tickets the title's own compact copies use: the streamed-in ("rehydrated") structures, which are ready-made on the console and never copied by the title, and the title's builds it does not copy;Over a 3 minute drive each (free play, so routes differ; read as sizes):
Where the console's own size of a build is known (3,836 builds), the console used 1,551 MB and the host's bound for the same builds was 992 MB. The report prints all of this: bytes alive by what they hold, updatable ones by their last update and by how many updates they had, and the host's own cost.
Numbers
Same build, same place, 5 minutes each, 1440p,
VICTORY_RT_STAMPS=rt(card time stamps around the ray-tracing dispatches only; added here, diagnostics build). Medians per frame:VICTORY_HW_RT=1One run each; a stamp pair spans overlapping work, so read these as sizes, not exact figures. The run with the switch on sits at the cap.
Loss counters over the check runs: all 0 (structures not built, instances without a structure, triangles zeroed, views not widened, device errors).
Not done
Tests
On this branch (
mainat32b136e+ the three commits), under Wine:victory-shader: 410 passed, 0 failed, 5 ignored (whole suite; includes the lifter and thesat_withtests).victory-gpu: 43 host-structure tests (decoders, input classes, refit rule, ledger, compaction tickets, the update rule, the accounting) and the stamps mode test pass. Of the whole suite, as run before the third commit, 5 tests indescriptor::host::testsfail here (a_structured_view_made_raw_passes_the_host_check,raw_twins_show_the_views_bytes,views_off_their_elements_are_told,slots_held_for_lack_of_room_come_back_when_there_is_room,views_are_made_beside_the_heap_and_copied_in); the same 5 fail the same way on plainmain(32b136e) on this machine, and this change does not touch what they test.victory-hle: 4 builder-tap tests pass.Not yet run in play on this exact branch. The fixed-place numbers were taken on a local branch that was 53 commits behind
main; the free-play runs of point 7 on a local branch with this work merged intomainat32b136e. Both carry other local changes, but the two files of the third commit are byte for byte the same there and here. A play run on this branch is still the thing to do before merging.🤖 Generated with Claude Code
883dd52904to56d254a9d7@Widget9337 on GitHub · 2026-12-03 04:04 UTC · original
Free-play data point on the same card: RX 9070 XT 16 GB, Ryzen 9 7950X3D, 64 GB RAM, CachyOS (kernel 7.2), this repo's patched Mesa and vkd3d-proton. Series X profile, 1920x1080 output with PC FSR 4 Balanced (1129x635 render), 30 fps cap, 3 shadow cascades (#211),
VICTORY_LATE_FENCE=1. Build:mainat8585cd4plus this PR (merged cleanly), compared with the same build without it. About 8 minutes of play: running on foot and very fast driving.It works as described. 64 of 64 programs lifted, every dispatch lifted (~17 per frame), and every loss counter stayed at 0 for the whole run.
Frame rate, medians of 1 s samples grouped by draws per frame (the first 2 minutes left out). The two runs without the PR are on the same build, one with less driving and one with more:
VICTORY_HW_RT=1Card memory: host structure memory reached 3,563 MB (compacted 2,552 MB, updatable 464 buffers / 781 MB, TLAS 160 MB; 558 MB lost to 64 KiB placement), more than the 2.1–2.5 GB in your drive. The card was down to 694 MB free, against about 3.2 GB without the PR.
Flicker looked worse with it on. I see the flickering and black textures from #69 in every build, including with ray tracing off, so this PR doesn't cause it. But it was noticeably worse with
VICTORY_HW_RT=1. Possibly a clue for #69: whatever the textures' problem is, it seems to show more when the trace passes are cheaper, or read from the host structures.Back on the build without it for now, because of the flicker and the card filling up. I'm happy to rerun once the structure buffers are pooled, or to run any switch or diagnostics build at the same spots.
@Luxuride on GitHub · 2026-12-04 12:02 UTC · original · edited 2026-12-05 11:24 UTC
This one is superseded as I read it, but not the work: the branch is real and it is the only hardware-RT implementation in the backlog.
The scheduling problem is that this PR's three commits (
3dacbed,56d254a,27f1a9b) appear with identical hashes in the five later PRs of the stack, so every review comment would have to be posted six times and none of the six is mergeable on its own. The tip contains all of it and merges clean, so the review effort belongs there once, not here.Two things that should be true of the PR that lands:
apps/victory/src/run.rs:61documents the switch only in a stderr banner.VICTORY_HW_RTneeds a line inrun.conf.defaultanddocs/SETTINGS.mdbefore it changes what the GPU is asked to draw for anyone.hwrt.rs:3071printing "hardware RT losses (each a bug to fix; 0 is parity)", and no fps, scene or card anywhere in the diff. A 17k-line PR whose correctness claim rests on a counter not yet driven to zero is a branch, not a PR.Also worth stating out loud in the body:
#[cfg(windows)] pub mod hwrtmeans none of this compiles on Linux; onlyemit/rayquery_tests.rsis platform-neutral.Whether it still has work of its own is the maintainer's call, not mine.
@LOCKhart07 on GitHub · 2026-12-04 14:34 UTC · original
Split as asked. The three commits here are now two branches, each showing only its own change:
rt-2-structureson my fork, to be opened when that one lands.On your two points:
VICTORY_HW_RT,_LIFT,_WHYand_REFITare indocs/SETTINGS.mdandrun.conf.default, each in the branch that adds it. And parity is still not checked hit for hit; the new PR says so and is a draft for that reason. It also states that the host side is#[cfg(windows)].This one can be closed.
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.Merge
Merge the changes and update on Forgejo.