[pr-performance][RAYTRACING] Hardware RT: readable_len probes the pages instead of asking VirtualQuery #115

Manually merged
TrustNo1 merged 1 commit from MesoPlz/Darner:hwrt-readable-probe into main 2026-12-04 02:13:46 +00:00
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

With hardware ray tracing on, play stuttered in bursts of BLAS builds and rehydrates: frames of 200 ms to 2.5 s with the card idle. The submitting thread's write-watch asking (preparing per frame, the submitting thread: ... asking the write watch) went up to 1,311 ms a frame, also with DARNER_ASK_FAST=1. Its askline showed the calls on the processor for only 12-18 % of their time: they were waiting, not spinning.

An xperf trace (context switches with ReadyThread stacks) of one such second: the submitting thread waited 375 + 103 ms in WrPushLock. It was readied from MiUnlockVadShared ← MmQueryVirtualMemory ← VirtualQuery ← darner_gpu::hwrt::read_geometries ← darner_hle::modules::xboxbvh::rehydrate_batched2, on two title threads that spent almost all their CPU samples in NtQueryVirtualMemory. VirtualQuery walks the page tables to the end of the region under the process's address-space lock: milliseconds a call in the title's big pools (as host::copy_mapped already notes), and GetWriteWatch waits for that lock.

readable_len now reads one byte of each 4 KiB page with crate::safecopy::copy (the kernel's read with DARNER_SAFE_COPY=0), and stops at the first page that cannot be read, as before. A range past the end of all addresses is unreadable, as VirtualQuery said. Only hwrt.rs changes.

How it was tested

  • Tested revision: 6dbe5dd on main fc3642e. The game runs were on main 1a5286a with the same hwrt.rs change (release build).
  • Commands and results:
    • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
    • cargo test --workspace --locked: 2076 passed, 7 failed, 89 ignored. The failures are in darner-gpu write-watch and timing tests (watch_pipe, card_steps, gpu_owned, watch::tests::ask_once_by_res_splits_reservations_without_refusals); none in hwrt. Reruns of cargo test --locked -p darner-gpu --lib: on main fc3642e 1 failure in 2 runs (shadow::wide_tests::nested_wide_each_scoped_handles_overflow_concurrency_and_panics); on this branch ask_once_by_res_splits_reservations_without_refusals failed in 3 of 3 runs, and in 2 of 3 runs with the new test skipped (--skip readable_bytes_end). Alone or together with the new test it passes (3 of 3). Not found out why.
    • cargo xtask policy --staged (at commit): 1 file ok
  • New test: readable_bytes_end_at_the_first_page_that_cannot_be_read (committed, reserved and past-the-end pages, all ones, the kernel's half, a non-canonical address): ok.
  • Gameplay: RTX 4080 (16 GB), Series X profile, DLSS performance, frame generation off, hardware RT. Non-default rows in both runs: DARNER_WINDOWS_BAR_MB=0, DARNER_CARD_WINDOWS_MB=1536, DARNER_ASK_FAST=1, DARNER_KEEP_SHOWN=checked.
  • Before and after, hand-played sessions, not a matched benchmark:
main (477 s) this PR (531 s)
median fps 26 31
seconds under 15 fps 124 (26 %) 80 (15 %)
seconds with a frame over 200 ms 166 (35 %) 115 (22 %)
seconds with a frame over 1 s 19 6
worst write-watch asking per frame 1,311 ms 14 ms
  • Coverage gaps: one card and one player; not tested on AMD, Series S, frame generation or software RT. The remaining frames over 200 ms are at loads (first pipeline binds) and in RT build bursts on the title threads; not looked at here. An earlier version of this change crashed on an all-ones transform address (a saturating end let it through); fixed and covered by the test before this commit.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open and closed pull requests and issues for the same issue and for the files this touches.
  • Related PRs: #23 changes the same path (it reads the BLAS inputs through host::read_into, so its hot paths no longer call readable_len; its fallbacks still do). The two conflict textually in readable_len. #92 and #3 also touch hardware RT.

🤖 Generated with Claude Code

## Contributor role (optional) - Fluxer ID: ## What it changes With hardware ray tracing on, play stuttered in bursts of BLAS builds and rehydrates: frames of 200 ms to 2.5 s with the card idle. The submitting thread's write-watch asking (`preparing per frame, the submitting thread: ... asking the write watch`) went up to 1,311 ms a frame, also with `DARNER_ASK_FAST=1`. Its `askline` showed the calls on the processor for only 12-18 % of their time: they were waiting, not spinning. An xperf trace (context switches with ReadyThread stacks) of one such second: the submitting thread waited 375 + 103 ms in `WrPushLock`. It was readied from `MiUnlockVadShared` ← `MmQueryVirtualMemory` ← `VirtualQuery` ← `darner_gpu::hwrt::read_geometries` ← `darner_hle::modules::xboxbvh::rehydrate_batched2`, on two title threads that spent almost all their CPU samples in `NtQueryVirtualMemory`. `VirtualQuery` walks the page tables to the end of the region under the process's address-space lock: milliseconds a call in the title's big pools (as `host::copy_mapped` already notes), and `GetWriteWatch` waits for that lock. `readable_len` now reads one byte of each 4 KiB page with `crate::safecopy::copy` (the kernel's read with `DARNER_SAFE_COPY=0`), and stops at the first page that cannot be read, as before. A range past the end of all addresses is unreadable, as `VirtualQuery` said. Only `hwrt.rs` changes. ## How it was tested - Tested revision: `6dbe5dd` on `main` `fc3642e`. The game runs were on `main` `1a5286a` with the same `hwrt.rs` change (release build). - Commands and results: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test --workspace --locked`: 2076 passed, 7 failed, 89 ignored. The failures are in `darner-gpu` write-watch and timing tests (`watch_pipe`, `card_steps`, `gpu_owned`, `watch::tests::ask_once_by_res_splits_reservations_without_refusals`); none in `hwrt`. Reruns of `cargo test --locked -p darner-gpu --lib`: on `main` `fc3642e` 1 failure in 2 runs (`shadow::wide_tests::nested_wide_each_scoped_handles_overflow_concurrency_and_panics`); on this branch `ask_once_by_res_splits_reservations_without_refusals` failed in 3 of 3 runs, and in 2 of 3 runs with the new test skipped (`--skip readable_bytes_end`). Alone or together with the new test it passes (3 of 3). Not found out why. - `cargo xtask policy --staged` (at commit): 1 file ok - New test: `readable_bytes_end_at_the_first_page_that_cannot_be_read` (committed, reserved and past-the-end pages, all ones, the kernel's half, a non-canonical address): ok. - Gameplay: RTX 4080 (16 GB), Series X profile, DLSS performance, frame generation off, hardware RT. Non-default rows in both runs: `DARNER_WINDOWS_BAR_MB=0`, `DARNER_CARD_WINDOWS_MB=1536`, `DARNER_ASK_FAST=1`, `DARNER_KEEP_SHOWN=checked`. - Before and after, hand-played sessions, not a matched benchmark: | | `main` (477 s) | this PR (531 s) | |---|---|---| | median fps | 26 | 31 | | seconds under 15 fps | 124 (26 %) | 80 (15 %) | | seconds with a frame over 200 ms | 166 (35 %) | 115 (22 %) | | seconds with a frame over 1 s | 19 | 6 | | worst write-watch asking per frame | 1,311 ms | 14 ms | - Coverage gaps: one card and one player; not tested on AMD, Series S, frame generation or software RT. The remaining frames over 200 ms are at loads (first pipeline binds) and in RT build bursts on the title threads; not looked at here. An earlier version of this change crashed on an all-ones transform address (a saturating end let it through); fixed and covered by the test before this commit. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open and closed pull requests and issues for the same issue and for the files this touches. - Related PRs: #23 changes the same path (it reads the BLAS inputs through `host::read_into`, so its hot paths no longer call `readable_len`; its fallbacks still do). The two conflict textually in `readable_len`. #92 and #3 also touch hardware RT. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
VirtualQuery walks the page tables to the end of the region under the
process's address-space lock, which in the title's big pools takes
milliseconds a call. The structure rehydrates (read_geometries and the
decoders, on title threads under XboxBvhBuilder) kept two title threads in
it for whole seconds, and the submitting thread's write-watch asking
waited for the lock behind them: in an xperf trace (RTX 4080, hardware
RT) it sat in WrPushLock, readied from MiUnlockVadShared by those threads,
up to 1.3 s a frame. readable_len now reads one byte of each 4 KiB page
with crate::safecopy (the kernel's read with DARNER_SAFE_COPY=0); a range
past the end of all addresses is unreadable, as VirtualQuery said.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TrustNo1 manually merged commit a1eac5ef37 into main 2026-12-04 02:13:33 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
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
TrustNo1/Darner!115
No description provided.