d3d12 hwrt: walk the RT tables once per page-mapping copy (D3D12-HWRT-FREED-ONCE-PER-COPY) #3401

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "+refs/pull/3401/head:oreofr/hwrt-freed-once"
git switch "oreofr/hwrt-freed-once"
Open
leonida/mandy
OreoFR wants to merge 1 commit from oreofr/hwrt-freed-once into main AGit

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3401/head:oreofr/hwrt-freed-once'
git switch 'oreofr/hwrt-freed-once'
Member

Item: D3D12-HWRT-FREED-ONCE-PER-COPY (claimed in #3312).

What and why

With hardware ray tracing (LEONIDA_HW_RT=1), watch::title_memory_unmapping called hwrt::title_memory_freed for every view unmapped, and each call walks every RT table (as_map, the waiting queue, the BLAS LRU, decoded_ibs, validated_ibs) under its lock. Inside the runtime's page-mapping copies (xmem::map_aliases, and the second step of xmem::map_aliases_later) that is one full walk per page.

Now the ranges unmapped during one page-mapping copy are gathered on the calling thread, joined (overlapping/touching ranges merged, sorted), and the tables are walked once at the copy's end, before the call returns to the title. Outside a copy nothing changes (one walk per call, as before). Each table drops exactly the keys it dropped before; only the moment moves to the end of the same call.

Ported after Darner (TrustNo1/Darner, GPL-3.0-or-later) commit 7a9d3fd by f41 (merged as 775a0c7, their PR 92, DARNER_HW_RT_FREED_GATHERED). Darner measured the per-view walk at 97% of those copies' time with HW RT while driving (20-105 ms on the title thread, median 8.90 -> 9.75 fps): their numbers, not ours. Their pagemap/hide/MeshletCache parts have no counterpart here and were left out.

Switch

LEONIDA_HWRT_FREED_GATHERED: on by default (toggled!, so LEONIDA_AB can flip it in diagnostics builds); =0 restores the old walk per view for A/B. On by default because the change is behaviour-preserving for the tables' contents and covered by the tests below. d3d12/docs/switches.md regenerated; one line in d3d12/docs/fork-ray-tracing.md.

Tests

  • New hwrt::tests::freed_ranges_gathered_leave_the_tables_as_a_walk_per_view: same final state of the real table types (HashMap as_map/ibs, Backlog, BlasLru uses and recipes) per view vs gathered, for overlapping, adjacent, disjoint, nested, duplicate, empty and unordered ranges.
  • New hwrt::tests::freed_ranges_joined_name_what_each_alone_names: the joined spans and the membership test, including a range ending at u64::MAX.
  • New watch::tests::a_page_mapping_copys_unmapped_views_wait_for_its_end: nested copies hold the ranges, the outermost hands them on, nothing stays behind; outside a copy, at once.
  • Red/green: with in_spans broken (s.0 < va), both hwrt tests fail; restored, they pass.
  • cargo test -p leonida-gpu --locked: 732 passed, 0 failed (59 ignored)
  • cargo test -p leonida-hle --locked --lib xmem: 28 passed, 0 failed (1 ignored)
  • cargo clippy -p leonida-gpu -p leonida-hle --all-targets --locked -- -D warnings: clean (exit 0)
  • python -I tests/test_d3d12_switches.py, python -I tests/test_docs_links.py, python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: OK
  • python -I scripts/check_no_game_data.py on the changed files: OK
  • leonida.exe built with cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc (as scripts/build-nvidia.ps1): links (the one warning is the existing book.rs dead field)

In-game A/B pending (RTX 4070 Laptop, HW RT, driving).

AI-assisted (Claude Code). No game data, nothing from Darner except the idea and code shape (no binaries, no SDK files).

🤖 Generated with Claude Code

Item: **D3D12-HWRT-FREED-ONCE-PER-COPY** (claimed in #3312). ## What and why With hardware ray tracing (`LEONIDA_HW_RT=1`), `watch::title_memory_unmapping` called `hwrt::title_memory_freed` for every view unmapped, and each call walks every RT table (`as_map`, the waiting queue, the BLAS LRU, `decoded_ibs`, `validated_ibs`) under its lock. Inside the runtime's page-mapping copies (`xmem::map_aliases`, and the second step of `xmem::map_aliases_later`) that is one full walk per page. Now the ranges unmapped during one page-mapping copy are gathered on the calling thread, joined (overlapping/touching ranges merged, sorted), and the tables are walked **once** at the copy's end, before the call returns to the title. Outside a copy nothing changes (one walk per call, as before). Each table drops exactly the keys it dropped before; only the moment moves to the end of the same call. Ported after Darner (TrustNo1/Darner, GPL-3.0-or-later) commit `7a9d3fd` by f41 (merged as `775a0c7`, their PR 92, `DARNER_HW_RT_FREED_GATHERED`). Darner measured the per-view walk at 97% of those copies' time with HW RT while driving (20-105 ms on the title thread, median 8.90 -> 9.75 fps): **their numbers, not ours**. Their `pagemap`/`hide`/`MeshletCache` parts have no counterpart here and were left out. ## Switch `LEONIDA_HWRT_FREED_GATHERED`: **on by default** (`toggled!`, so `LEONIDA_AB` can flip it in diagnostics builds); `=0` restores the old walk per view for A/B. On by default because the change is behaviour-preserving for the tables' contents and covered by the tests below. `d3d12/docs/switches.md` regenerated; one line in `d3d12/docs/fork-ray-tracing.md`. ## Tests - New `hwrt::tests::freed_ranges_gathered_leave_the_tables_as_a_walk_per_view`: same final state of the real table types (`HashMap` as_map/ibs, `Backlog`, `BlasLru` uses and recipes) per view vs gathered, for overlapping, adjacent, disjoint, nested, duplicate, empty and unordered ranges. - New `hwrt::tests::freed_ranges_joined_name_what_each_alone_names`: the joined spans and the membership test, including a range ending at `u64::MAX`. - New `watch::tests::a_page_mapping_copys_unmapped_views_wait_for_its_end`: nested copies hold the ranges, the outermost hands them on, nothing stays behind; outside a copy, at once. - Red/green: with `in_spans` broken (`s.0 < va`), both hwrt tests fail; restored, they pass. - `cargo test -p leonida-gpu --locked`: 732 passed, 0 failed (59 ignored) - `cargo test -p leonida-hle --locked --lib xmem`: 28 passed, 0 failed (1 ignored) - `cargo clippy -p leonida-gpu -p leonida-hle --all-targets --locked -- -D warnings`: clean (exit 0) - `python -I tests/test_d3d12_switches.py`, `python -I tests/test_docs_links.py`, `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md`: OK - `python -I scripts/check_no_game_data.py` on the changed files: OK - `leonida.exe` built with `cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc` (as `scripts/build-nvidia.ps1`): links (the one warning is the existing `book.rs` dead field) In-game A/B pending (RTX 4070 Laptop, HW RT, driving). AI-assisted (Claude Code). No game data, nothing from Darner except the idea and code shape (no binaries, no SDK files). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With hardware ray tracing, title_memory_unmapping called
hwrt::title_memory_freed for every view unmapped, and each call walks
every RT table (structures, waiting requests, the LRU, decoded and
validated index buffers) under its lock: one full walk per page inside
the runtime's page-mapping copies.

The ranges unmapped in one copy (xmem::map_aliases, and alias_pages, the
second step of map_aliases_later) are now gathered on the thread, joined,
and the tables walked once at the copy's end, before it returns to the
title. Outside a copy nothing changes. LEONIDA_HWRT_FREED_GATHERED (on
unless 0) switches it; =0 restores the walk per view for A/B.

After Darner (TrustNo1/Darner, GPL-3.0-or-later) commit 7a9d3fd by f41.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Member

RUN hwrt-freed-gathered | 2026-12-04 | OreoFR | AI-assisted: Claude Code

  • What: head ca67a50c7, RTX 4070 Laptop 8 GB (driver 621.40), Core Ultra 7 155H, 40 GB RAM, Windows 11. Series S, -NoDlss -NoFrameGen -HardwareRT -PrecompileUsed, BAR 0, texture budget 1024, walking (W + turns, scripted keys), 300 s in the world per run, stats over the last 240 s. A = default (LEONIDA_HWRT_FREED_GATHERED on), B = LEONIDA_HWRT_FREED_GATHERED=0. Warm-up then A B B A, screen kept on.
run arm fps median frame p99 (median of windows) >100 ms >1 s longest
wA A (warm-up, not counted) 21.02 42.4 ms 73.8 12 0 573 ms
A1 A 20.56 47.0 ms 82.8 13 0 297 ms
B1 B 21.78 43.0 ms 72.7 12 0 188 ms
B2 B 21.22 44.1 ms 73.1 12 1 1348 ms
A2 A 24.41 38.9 ms 67.8 15 0 740 ms
  • Result: INCONCLUSIVE. A 22.5 fps (20.56 / 24.41) vs B 21.5 (21.78 / 21.22): the A runs differ by 3.9 fps, more than the A-B gap. Other builds (cargo) ran on this PC during A1, B1 and B2 and had stopped by A2, so A2 is not comparable. Walking only: Darner measured its gain while driving, where page-mapping copies are frequent.
  • No regression seen: no device removed or lost, no panic in 5 runs; same picture.
  • Next: a quiet re-run (nothing else on the PC) and a driving route if one can be scripted.
RUN hwrt-freed-gathered | 2026-12-04 | OreoFR | AI-assisted: Claude Code - **What:** head `ca67a50c7`, RTX 4070 Laptop 8 GB (driver 621.40), Core Ultra 7 155H, 40 GB RAM, Windows 11. Series S, `-NoDlss -NoFrameGen -HardwareRT -PrecompileUsed`, BAR 0, texture budget 1024, walking (W + turns, scripted keys), 300 s in the world per run, stats over the last 240 s. A = default (`LEONIDA_HWRT_FREED_GATHERED` on), B = `LEONIDA_HWRT_FREED_GATHERED=0`. Warm-up then A B B A, screen kept on. | run | arm | fps | median frame | p99 (median of windows) | >100 ms | >1 s | longest | |---|---|---|---|---|---|---|---| | wA | A (warm-up, not counted) | 21.02 | 42.4 ms | 73.8 | 12 | 0 | 573 ms | | A1 | A | 20.56 | 47.0 ms | 82.8 | 13 | 0 | 297 ms | | B1 | B | 21.78 | 43.0 ms | 72.7 | 12 | 0 | 188 ms | | B2 | B | 21.22 | 44.1 ms | 73.1 | 12 | 1 | 1348 ms | | A2 | A | 24.41 | 38.9 ms | 67.8 | 15 | 0 | 740 ms | - **Result: INCONCLUSIVE.** A 22.5 fps (20.56 / 24.41) vs B 21.5 (21.78 / 21.22): the A runs differ by 3.9 fps, more than the A-B gap. Other builds (cargo) ran on this PC during A1, B1 and B2 and had stopped by A2, so A2 is not comparable. Walking only: Darner measured its gain while driving, where page-mapping copies are frequent. - **No regression seen:** no device removed or lost, no panic in 5 runs; same picture. - **Next:** a quiet re-run (nothing else on the PC) and a driving route if one can be scripted.
OreoFR referenced this pull request from a commit 2026-12-04 02:26:46 +00:00
First-time contributor

Independent local verification of this change (I changed no code).

  • Head ca67a50c, merge base 52861466. All three new tests are absent on the base: git grep -F <test> 52861466 -- <path> -> exit 1 for each.
  • On the PR head, with module-qualified names, -- --exact and a private CARGO_TARGET_DIR: hwrt::tests::freed_ranges_gathered_leave_the_tables_as_a_walk_per_view, hwrt::tests::freed_ranges_joined_name_what_each_alone_names and watch::tests::a_page_mapping_copys_unmapped_views_wait_for_its_end -> 1 passed / 790 filtered each.
  • git diff --check 52861466 ca67a50c -> clean. python -I scripts/check_no_game_data.py on the six changed files -> clean. I did not repeat the author's in-game run.

GPUs tested: none (CPU-only unit tests, no device-gated test counted). Driver: n/a. No game data, assets or extracted shaders were used or attached.

AI-assisted: yes, Hy4 flash (verification only). No approval implied; this is a local test report.

Independent local verification of this change (I changed no code). - Head `ca67a50c`, merge base `52861466`. All three new tests are absent on the base: `git grep -F <test> 52861466 -- <path>` -> exit 1 for each. - On the PR head, with module-qualified names, `-- --exact` and a private `CARGO_TARGET_DIR`: `hwrt::tests::freed_ranges_gathered_leave_the_tables_as_a_walk_per_view`, `hwrt::tests::freed_ranges_joined_name_what_each_alone_names` and `watch::tests::a_page_mapping_copys_unmapped_views_wait_for_its_end` -> 1 passed / 790 filtered each. - `git diff --check 52861466 ca67a50c` -> clean. `python -I scripts/check_no_game_data.py` on the six changed files -> clean. I did not repeat the author's in-game run. GPUs tested: none (CPU-only unit tests, no device-gated test counted). Driver: n/a. No game data, assets or extracted shaders were used or attached. AI-assisted: yes, Hy4 flash (verification only). No approval implied; this is a local test report.
First-time contributor

RUN — In-game Regression & Unit Test Gate (NVIDIA RTX 5070 12 GB, Windows 11)

Tested PR head ca67a50c71 merged cleanly onto main (6b0498d37), diagnostic release build (-SeriesS, no frame generation, 315 s automated run from the same save), compared against our recent main (30c683055) baseline:

Metric main baseline (30c683055) PR #3401 (ca67a50c71)
World samples (>=1000 draws) 36 (max_draws=5187) 39 (max_draws=5316)
Median FPS / frame time 23.0 fps (43.5 ms) 24.8 fps (40.2 ms)
Slowest 10% / fastest 10% 13.7 / 25.0 fps 17.3 / 25.9 fps
3000-4999 draws/frame median 23.2 fps (28 samples) 25.1 fps (30 samples)
Errors / warnings / device lost 0 / 0 / 0 0 / 0 / 0

Unit & Repo Checks

  • cargo test -p leonida-gpu --lib --locked hwrt:: — 24/24 PASS (including freed_ranges_joined_name_what_each_alone_names and freed_ranges_gathered_leave_the_tables_as_a_walk_per_view)
  • cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings — 0 warnings
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md — PASS
  • python -I scripts/check_no_game_data.py — PASS

Verdict

PASS — clean merge onto 6b0498d37, all 24/24 hwrt:: tests and clippy/switch checks pass, and the 315 s in-game run completed cleanly with zero errors/warnings and no regression. (Note: -SeriesS regression gate here, without -HardwareRT.)

AI-assisted.

### RUN — In-game Regression & Unit Test Gate (NVIDIA RTX 5070 12 GB, Windows 11) Tested PR head `ca67a50c71` merged cleanly onto `main` (`6b0498d37`), diagnostic release build (`-SeriesS`, no frame generation, 315 s automated run from the same save), compared against our recent `main` (`30c683055`) baseline: | Metric | `main` baseline (`30c683055`) | PR `#3401` (`ca67a50c71`) | | --- | --- | --- | | World samples (`>=1000` draws) | `36` (`max_draws=5187`) | `39` (`max_draws=5316`) | | Median FPS / frame time | `23.0 fps` (`43.5 ms`) | `24.8 fps` (`40.2 ms`) | | Slowest 10% / fastest 10% | `13.7` / `25.0 fps` | `17.3` / `25.9 fps` | | `3000-4999` draws/frame median | `23.2 fps` (`28` samples) | `25.1 fps` (`30` samples) | | Errors / warnings / device lost | `0` / `0` / `0` | `0` / `0` / `0` | ### Unit & Repo Checks - `cargo test -p leonida-gpu --lib --locked hwrt::` — **`24/24` PASS** (including `freed_ranges_joined_name_what_each_alone_names` and `freed_ranges_gathered_leave_the_tables_as_a_walk_per_view`) - `cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings` — `0` warnings - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md` — PASS - `python -I scripts/check_no_game_data.py` — PASS ### Verdict **PASS** — clean merge onto `6b0498d37`, all `24/24` `hwrt::` tests and `clippy`/switch checks pass, and the 315 s in-game run completed cleanly with zero errors/warnings and no regression. (Note: `-SeriesS` regression gate here, without `-HardwareRT`.) AI-assisted.
Sign in to join this conversation.
No description provided.