d3d12: hardware ray tracing on DXR 1.1 (LEONIDA_HW_RT, off: a trial) - carry of #2972 #3058

Manually merged
github merged 7 commits from github-bot/gh-3058 into gh-pr/3058/base 2026-12-02 07:08:48 +00:00 AGit
Owner

@⁠OreoFR on GitHub · 2026-12-02 06:39 UTC · original
OreoFR:carry/hwrt-2972 → main · +14133 −35 · 42 files · 7 commits · merged 2026-12-02 07:04 UTC

Carry of #2972 (Callimann8's hardware ray tracing). Claimed as D3D12-HW-RT-CARRY: #2570

The #2972 head 923a4e98f2711683061f88001172e24cddea1c6e with main merged in (merge daf7242f2). Every commit is Callimann8's, with the credits listed below. The only conflicts were the launcher switch lists in scripts/play-d3d12.ps1 and d3d12/scripts/play-nvidia.ps1, where #2986 had added -PrecompileAll; both switches are kept. Nothing else was changed.

In-game result

RTX 4070 Laptop 8 GB, driver 621.40, Windows 11. Series S, no DLSS, no frame generation, the same warm data. Walk 330 s (lift at 340 s).

Mode at +120 s at +300 s last 200 s of the run
-RayTracing (main, software traversal) 2 fps, 624 ms 11 fps, 95 ms 2.3 fps, 442 ms
-HardwareRT (this PR) 24 fps, 42 ms 15 fps, 68 ms 21.6 fps, 46 ms
  • About 9.5 times the frame rate of the software path.
  • Same scene at +120 s in both runs (local screenshots, not attached): same lighting and reflections, no missing geometry or artefacts visible.
  • Logs: 0 device lost or removed and 0 panics in both runs.
  • Off by default (LEONIDA_HW_RT), so nothing changes for anyone who does not turn it on.

Not done yet

  • The Rust test suites were not run locally. The game was running; CI runs them.
  • One card only. A run on AMD or Intel (DXR 1.1 inline ray queries) would be welcome.

AI-assisted (oreofr-agent for OreoFR, Claude).


The original description of #2972 (Callimann8)

Claimed in the coordination issue as: claiming: D3D12 runtime: hardware ray tracing (DXR 1.1, LEONIDA_HW_RT)

What and why

Hardware ray tracing for the D3D12 runtime (d3d12/), off by default, a trial: LEONIDA_HW_RT=1
(-HardwareRT of the play scripts, a launcher checkbox, the F1 menu's HARDWARE RAY TRACING (TRIAL)), in place of
-RayTracing / LEONIDA_BVH_BUILDER=1.

With -RayTracing the title's own structure builder and its software traversal run as translated shaders, which is
slow (6 frames a second on the test PC below). With this, the title's rays run on the card's ray-tracing hardware
(DXR 1.1 inline ray queries).

It is a port of trustno1-coder/VIctory-NVIDIA's hardware ray tracing (its #3706; from
Leslie-d-a/VIctory-NVIDIA-HWRT 61e389e0 and 5f55bca8, original by dakisback2 ecc49d5b and 72f8316a; GPL-3.0, as this
repository), fitted to this tree, which had diverged from VIctory-NVIDIA since bafb0e25b:

  • leonida-shader: emit/rayquery.rs lifts the traversal loops of the trace programs to RayQuery, wired into
    this tree's lower.rs (the plan, the handles, TLAS root SRVs t230..t241, the analyses that leave the lifted
    loops out). Written for this tree: a program in the paired form is not lifted; with LEONIDA_HW_RT=1 the node
    test of a loop that is not lifted misses every node (emit/intersect.rs bvh_miss), since the console
    structures are never written then.
  • leonida-gpu: hwrt.rs builds host bottom and top levels from the title's XboxBvhBuilder calls. Written
    for this tree: list::external (work of ours at its place in a title list, with a LEONIDA_THIN op), the TLAS
    views in the descriptor heaps, Deferred::held, the ray queries in the shader cache's entries, the counters in
    the frame log. dxr.rs comes with it for the records hwrt.rs uses; its LEONIDA_BVH_SIZE_ANSWER wrappers are
    not bound here.
  • leonida-hle: modules/xboxbvh.rs replaces the exports of the title's XboxBvhBuilder.dll when the switch
    is on (export names only; no title bytes).
  • With the switch on, the light stand-in stands aside and the passes left out without structures run, as with the
    builder; the play script leaves DLSS frame generation off, as with -RayTracing.
  • One difference from VIctory-NVIDIA: it copies every shader write back to title memory under hardware ray tracing.
    Here that stretched and flickered textures and cost 30 to 45 ms a frame, so it is opt-in
    (LEONIDA_HW_RT_COPY_BACK=1) and LEONIDA_WC_NO_BACK stays as the play script sets it.
  • Docs: d3d12/docs/fork-ray-tracing.md (new section), README.md (-HardwareRT), d3d12/docs/switches.md
    regenerated.

Nothing changes with the switch off, except that shader cache entries can carry a ray-query record (none for a
program without one, so existing entries read as before).

Tested

  • cargo build --workspace --all-targets --locked, cargo build -p leonida --features diagnostics,mimalloc --locked,
    cargo test --workspace --exclude xtask --locked -- --skip depth_bounds_pipeline_loads_and_filters_draws,
    cargo test -p leonida-gpu --features diagnostics --test replay --locked: TEST_RESULT
  • New tests: emit::rayquery_tests (the lifted form validates and makes a pipeline on WARP; the fallback misses
    with the switch on; LEONIDA_HW_RT_LIFT=0), shader_cache (a program's ray queries come back, one without them
    reads as before).
  • The ignored corpus test the_local_shader_cache_lifts_its_ray_queries over one local known-shaders.bin
    (counts only): 64 ray-tracing programs, 56 wholly lifted, 6 partly (bvh32: unrecognized live-out value), 2 that
    do not translate without this either, none lifted that does not validate; loops 76 of 76 (64-bit nodes) and 299
    of 315 (32-bit).
  • python -I tests/test_leonida_launcher.py, python -I tests/test_d3d12_switches.py,
    python -I scripts/check_no_game_data.py <changed files>: pass.
  • In the game, one PC, the requester playing (open world, Series X profile, no frame generation, the frame log's
    own lines): 22 to 25 frames a second with hardware ray tracing, 14 of 14 ray-tracing programs in use wholly
    lifted, about 4,900 bottom levels and 5 top levels alive; the same save with -RayTracing 6 frames a second
    (104 to 118 ms of the card a frame). The picture was judged by eye only ("texture problems are gone" after the
    copy-back change); it was not compared with the builder's picture frame by frame.
  • Known limit: that run ended after six minutes with the device removed and the card's memory full (10,989 MB
    in use of a budget of 10,793 MB, 1,095 MB of it bottom levels; the PC had 125 MB left to commit). The Series X
    profile fills this 12 GB card without the structures too. The bottom levels' budget is a tenth of the card's.
  • Not tested: AMD and Intel cards, the Series S profile, Linux, a long session, LEONIDA_HW_RT_COPY_BACK=1 after
    the change.

GPUs tested: NVIDIA GeForce RTX 4070 (12 GB), driver 621.40, Windows 11

AI-assisted: yes (ported and written by Claude at the requester's direction; the requester ran the game)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no rule
    of the Python translator changes; this is the D3D12 runtime's own translator.)

🤖 Generated with Claude Code

**@⁠OreoFR** on GitHub · 2026-12-02 06:39 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3058) `OreoFR:carry/hwrt-2972` → `main` · +14133 −35 · 42 files · 7 commits · merged 2026-12-02 07:04 UTC **Carry of #2972** (Callimann8's hardware ray tracing). Claimed as `D3D12-HW-RT-CARRY`: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/2570 The #2972 head `923a4e98f2711683061f88001172e24cddea1c6e` with main merged in (merge `daf7242f2`). Every commit is Callimann8's, with the credits listed below. The only conflicts were the launcher switch lists in `scripts/play-d3d12.ps1` and `d3d12/scripts/play-nvidia.ps1`, where #2986 had added `-PrecompileAll`; both switches are kept. Nothing else was changed. ### In-game result RTX 4070 Laptop 8 GB, driver 621.40, Windows 11. Series S, no DLSS, no frame generation, the same warm data. Walk 330 s (lift at 340 s). | Mode | at +120 s | at +300 s | last 200 s of the run | |---|---|---|---| | `-RayTracing` (main, software traversal) | 2 fps, 624 ms | 11 fps, 95 ms | **2.3 fps**, 442 ms | | `-HardwareRT` (this PR) | 24 fps, 42 ms | 15 fps, 68 ms | **21.6 fps**, 46 ms | - About 9.5 times the frame rate of the software path. - Same scene at +120 s in both runs (local screenshots, not attached): same lighting and reflections, no missing geometry or artefacts visible. - Logs: 0 device lost or removed and 0 panics in both runs. - Off by default (`LEONIDA_HW_RT`), so nothing changes for anyone who does not turn it on. ### Not done yet - The Rust test suites were not run locally. The game was running; CI runs them. - One card only. A run on AMD or Intel (DXR 1.1 inline ray queries) would be welcome. AI-assisted (oreofr-agent for OreoFR, Claude). --- ### The original description of #2972 (Callimann8) Claimed in the coordination issue as: claiming: D3D12 runtime: hardware ray tracing (DXR 1.1, LEONIDA_HW_RT) ### What and why Hardware ray tracing for the D3D12 runtime (`d3d12/`), **off by default, a trial**: `LEONIDA_HW_RT=1` (`-HardwareRT` of the play scripts, a launcher checkbox, the F1 menu's HARDWARE RAY TRACING (TRIAL)), in place of `-RayTracing` / `LEONIDA_BVH_BUILDER=1`. With `-RayTracing` the title's own structure builder and its software traversal run as translated shaders, which is slow (6 frames a second on the test PC below). With this, the title's rays run on the card's ray-tracing hardware (DXR 1.1 inline ray queries). It is a port of trustno1-coder/VIctory-NVIDIA's hardware ray tracing (its #3706; from Leslie-d-a/VIctory-NVIDIA-HWRT 61e389e0 and 5f55bca8, original by dakisback2 ecc49d5b and 72f8316a; GPL-3.0, as this repository), fitted to this tree, which had diverged from VIctory-NVIDIA since `bafb0e25b`: - **`leonida-shader`**: `emit/rayquery.rs` lifts the traversal loops of the trace programs to `RayQuery`, wired into this tree's `lower.rs` (the plan, the handles, TLAS root SRVs `t230..t241`, the analyses that leave the lifted loops out). Written for this tree: a program in the paired form is not lifted; with `LEONIDA_HW_RT=1` the node test of a loop that is not lifted misses every node (`emit/intersect.rs` `bvh_miss`), since the console structures are never written then. - **`leonida-gpu`**: `hwrt.rs` builds host bottom and top levels from the title's `XboxBvhBuilder` calls. Written for this tree: `list::external` (work of ours at its place in a title list, with a `LEONIDA_THIN` op), the TLAS views in the descriptor heaps, `Deferred::held`, the ray queries in the shader cache's entries, the counters in the frame log. `dxr.rs` comes with it for the records `hwrt.rs` uses; its `LEONIDA_BVH_SIZE_ANSWER` wrappers are not bound here. - **`leonida-hle`**: `modules/xboxbvh.rs` replaces the exports of the title's `XboxBvhBuilder.dll` when the switch is on (export names only; no title bytes). - With the switch on, the light stand-in stands aside and the passes left out without structures run, as with the builder; the play script leaves DLSS frame generation off, as with `-RayTracing`. - One difference from VIctory-NVIDIA: it copies every shader write back to title memory under hardware ray tracing. Here that stretched and flickered textures and cost 30 to 45 ms a frame, so it is opt-in (`LEONIDA_HW_RT_COPY_BACK=1`) and `LEONIDA_WC_NO_BACK` stays as the play script sets it. - Docs: `d3d12/docs/fork-ray-tracing.md` (new section), `README.md` (`-HardwareRT`), `d3d12/docs/switches.md` regenerated. Nothing changes with the switch off, except that shader cache entries can carry a ray-query record (none for a program without one, so existing entries read as before). ### Tested - `cargo build --workspace --all-targets --locked`, `cargo build -p leonida --features diagnostics,mimalloc --locked`, `cargo test --workspace --exclude xtask --locked -- --skip depth_bounds_pipeline_loads_and_filters_draws`, `cargo test -p leonida-gpu --features diagnostics --test replay --locked`: TEST_RESULT - New tests: `emit::rayquery_tests` (the lifted form validates and makes a pipeline on WARP; the fallback misses with the switch on; `LEONIDA_HW_RT_LIFT=0`), `shader_cache` (a program's ray queries come back, one without them reads as before). - The ignored corpus test `the_local_shader_cache_lifts_its_ray_queries` over one local `known-shaders.bin` (counts only): 64 ray-tracing programs, 56 wholly lifted, 6 partly (`bvh32: unrecognized live-out value`), 2 that do not translate without this either, none lifted that does not validate; loops 76 of 76 (64-bit nodes) and 299 of 315 (32-bit). - `python -I tests/test_leonida_launcher.py`, `python -I tests/test_d3d12_switches.py`, `python -I scripts/check_no_game_data.py <changed files>`: pass. - In the game, one PC, the requester playing (open world, Series X profile, no frame generation, the frame log's own lines): 22 to 25 frames a second with hardware ray tracing, 14 of 14 ray-tracing programs in use wholly lifted, about 4,900 bottom levels and 5 top levels alive; the same save with `-RayTracing` 6 frames a second (104 to 118 ms of the card a frame). The picture was judged by eye only ("texture problems are gone" after the copy-back change); it was not compared with the builder's picture frame by frame. - **Known limit:** that run ended after six minutes with the device removed and the card's memory full (10,989 MB in use of a budget of 10,793 MB, 1,095 MB of it bottom levels; the PC had 125 MB left to commit). The Series X profile fills this 12 GB card without the structures too. The bottom levels' budget is a tenth of the card's. - Not tested: AMD and Intel cards, the Series S profile, Linux, a long session, `LEONIDA_HW_RT_COPY_BACK=1` after the change. GPUs tested: NVIDIA GeForce RTX 4070 (12 GB), driver 621.40, Windows 11 AI-assisted: yes (ported and written by Claude at the requester's direction; the requester ran the game) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no rule of the Python translator changes; this is the D3D12 runtime's own translator.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
In place of -RayTracing (the title's structure builder and software traversal as translated
shaders): the title's XboxBvhBuilder calls become host DXR 1.1 bottom and top levels, and the
traversal loops of its trace programs become inline ray queries.

Ported from trustno1-coder/VIctory-NVIDIA (its #3706; from Leslie-d-a/VIctory-NVIDIA-HWRT 61e389e0
and 5f55bca8, original by dakisback2 ecc49d5b and 72f8316a), GPL-3.0, and fitted to this tree:

- leonida-shader: emit/rayquery.rs wired into lower.rs (the plan, the handles, TLAS root SRVs
  t230..t241, the analyses that leave the lifted loops out). A program in the paired form is not
  lifted. With LEONIDA_HW_RT=1 the node test of a loop left unlifted misses every node
  (emit/intersect.rs bvh_miss): the console structures are never written then.
- leonida-gpu: hwrt.rs (and dxr.rs for its records); list::external with a LEONIDA_THIN op for the
  structure work at its place in a title list; the TLAS views in the descriptor heaps;
  Deferred::held; the ray queries in the shader cache's entries; counters in the frame log.
- leonida-hle: modules/xboxbvh.rs replaces the exports of the title's XboxBvhBuilder.dll when on.
- With it on the light stand-in stands aside and the passes left out without structures run.
  Shader writes are not all copied back as VIctory-NVIDIA does (LEONIDA_HW_RT_COPY_BACK=1 asks for
  it): here that stretched and flickered textures and cost 30 to 45 ms a frame.
- F1: HARDWARE RAY TRACING (TRIAL); play scripts: -HardwareRT (frame generation left off with it,
  as with -RayTracing); launcher: a checkbox. Docs: fork-ray-tracing.md, README.md, switches.md.

One PC (RTX 4070 12 GB, driver 621.40, Series X profile, no frame generation): 22 to 25 frames a
second against 6 with -RayTracing; the run ended after six minutes with the card's memory full.

Co-authored-by: dakisback2 <[email protected]>
Co-authored-by: Leslie-d-a <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
- rq_op: 187 is CandidateWorldToObject3x4 and 188 CommittedObjectToWorld3x4 (they were
  swapped; checked against dxc 10.0.26100). the_ray_query_opcodes_are_dxils pins all 35.
- Hardware ray tracing runs only where it can: hwrt::active() (asked for, and a DXR 1.1
  manager made) gates the HLE module, the left-out passes, the copy-back rule and the counters;
  the translator lifts loops only when the host says it runs inline ray tracing
  (set_host_inline_rt, in host_settings and so in the shader cache's key). Elsewhere the title
  keeps its own XboxBvhBuilder.dll and the software walk.
- No env write: builder_allowed() is LEONIDA_BVH_BUILDER=1 and not hwrt::active().
- dxr.rs removed (nothing bound its wrappers); TLAS views are kept out of the list views only
  with the path on; the off16 diagnostics and the xmem log lines are gone.
- as_sizes split out of alloc_or_reuse_as, with a test; the known gaps are in
  fork-ray-tracing.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- One gate for both halves: supported() also asks for shader model 6.6, and the translator is
  told inline ray tracing runs (set_host_inline_rt) only once the DXR manager is made.
- AABB geometries take stride 0 (packed 24-byte boxes) and multiples of 8 of 24 or more, as
  DXR does; others are refused.
- A TLAS of instances by pointer (ARRAY_OF_POINTERS) is not built: the remap reads 64-byte
  instances in a row.
- Structure copies other than clone and compact are not done (said once).
- A TLAS clone points the heap slots that view the destination at the shared structure.
- The points not fixed here are listed in fork-ray-tracing.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	d3d12/crates/leonida-gpu/src/descriptor/host.rs
#	d3d12/docs/switches.md
The shadow lookup and refresh asked for count * max(stride, 24) bytes, past the last box
(two boxes at 0 and 64: 128 bytes where 88 are used). aabb_span takes (count - 1) * stride + 24
with checked arithmetic; a test covers the last box ending at a buffer's end and overflow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	d3d12/scripts/play-nvidia.ps1
#	scripts/play-d3d12.ps1
# Conflicts:
#	d3d12/docs/switches.md
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 06:41:52 +00:00
Author
Owner

@⁠OreoFR on GitHub · 2026-12-02 06:53 UTC · original

Merging (oreofr-agent, with OreoFR's written OK as maintainer): head 43af833d195edf1e6987ae5582c3913a31e55b28, CI green including d3d12 (windows-latest); merges cleanly into main f37c4a87d. Off by default (LEONIDA_HW_RT). Measured on the RTX 4070 Laptop at daf7242f2 (this head minus #2756 and the regenerated switches page): 21.6 fps with -HardwareRT against 2.3 fps with -RayTracing, 0 device lost.

**@⁠OreoFR** on GitHub · 2026-12-02 06:53 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3058#issuecomment-7337534897) Merging (oreofr-agent, with OreoFR's written OK as maintainer): head `43af833d195edf1e6987ae5582c3913a31e55b28`, CI green including d3d12 (windows-latest); merges cleanly into main `f37c4a87d`. Off by default (`LEONIDA_HW_RT`). Measured on the RTX 4070 Laptop at `daf7242f2` (this head minus #2756 and the regenerated switches page): 21.6 fps with `-HardwareRT` against 2.3 fps with `-RayTracing`, 0 device lost.
github-bot changed target branch from main to gh-pr/3058/base 2026-12-02 07:08:47 +00:00
github manually merged commit 43af833d19 into gh-pr/3058/base 2026-12-02 07:08:48 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!3058
No description provided.