[pr-performance][memory][RAYTRACING] xmem: a scatter mapping's unmapped pages leave the RT tables once, at its end #334

Open
MesoPlz wants to merge 1 commit from MesoPlz/Darner:pr-xmem-scatter-freed-gathered into main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: with hardware RT, the title's streaming thread spends a large share of XMemMapPhysicalPagesScatter walking the ray tracing tables, once per page. xperf (CPU samples with stacks) of 3 s of a load, on main f3840d7: that thread had 1,100 samples, 620 of them under XMemMapPhysicalPagesScatter and 377 under watch::title_memory_unmapping → hwrt::title_memory_freed_many.

XMemMapPhysicalPagesScatter maps one page per address through XMemMapPhysicalPages, so every page's unmap went through title_memory_unmapping and walked every RT table on its own. #92 gathered those walks for the page-mapping copies (map_aliases) only. This runs XMemMapPhysicalPagesScatter inside the same darner_gpu::title_memory_freed_gathered scope, so the ranges it unmaps leave the tables once, before the call returns to the title. The tables end up as before; DARNER_HW_RT_FREED_GATHERED=0 restores the walk per page, as for #92. Only xmem.rs changes (8 lines).

How it was tested

  • Tested revision: 6bd653a on main f3840d7. The game runs used the same change on the same main (d5aa933).

  • 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 --no-fail-fast: 2,786 passed, 3 failed, 105 ignored. None is in darner-hle or near this change: emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders (#92 reports it failing on main 1a5286a too), host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end and shadow::wide_tests::nested_wide_each_scoped_handles_overflow_concurrency_and_panics (both timing-dependent; the second also failed once in two runs of cargo test -p darner-gpu --lib on clean main fc3642e). The darner-shader test binary hung while the game ran on the same card and was stopped, so not all of its tests ran.
    • cargo test --profile fast --locked -p darner-hle --lib xmem: 53 passed, 1 ignored (on d5aa933, the same diff)
  • Changes a default: no (it uses #92's switch, on by default).

  • A/B result: the same route twice (start from the same save, drive into the same busy part of the city right away), built with the fast profile, RTX 4080 16 GB, driver 621.40, 64 GB RAM, Series X profile, 1440p, DLSS quality, frame generation off, hardware RT. Both runs with the streaming log on (DARNER_DSTORAGE_LOG). Non-default rows in both: DARNER_CARD_WINDOWS_MB=1536, DARNER_WINDOWS_BAR_MB=0, DARNER_ASK_FAST=1, DARNER_HW_RT_BLAS_HEAPS=0, DARNER_KEEP_SHOWN=checked. One run each, hand-driven, so the routes differ a little:

    A (main, 134 s logged) B (this PR, 145 s logged)
    time in the title's mapping calls outside system calls 13.4 s (26 us a page) 4.0 s (8 us a page)
    slowest mapping call 113 ms 39 ms
    DirectStorage request, enqueued to done: median / p95 / p99 / max 11 / 179 / 337 / 573 ms 7 / 133 / 286 / 524 ms
    seconds with a frame over 200 ms 8 of 145 6 of 162
    median fps 40 43

    The mapping calls' system calls took longer in B (unmap 14.3 → 19.0 s, map 6.0 → 13.2 s, about as many calls), so the calls' total did not fall (34.4 → 36.9 s): those wait for the process's address-space lock, which a kernel thread rebuilding large pages (MiRebuildLargePages) held for most of a load in the traced runs. This PR only removes Darner's own work in them.

  • Gates run on that revision: all three, results above.

  • Gameplay: see the A/B row.

  • Shader wave sizes tested: not relevant (no shader change).

  • Hardware dependence: needs hardware RT (without it title_memory_freed returns early); the cost removed grows with the RT tables.

  • Coverage gaps: one card, one player, one run each; not tested with software RT, AMD, Series S or frame generation. The player saw less pop-in in B; no screenshot comparison.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • 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 pull requests for the same issue and for the files this touches.
  • Related PRs: #92 (merged; this extends its gathering to XMemMapPhysicalPagesScatter); #219 changes xmem.rs (other functions).
  • Replaces or overlaps: none found

🤖 Generated with Claude Code

## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: with hardware RT, the title's streaming thread spends a large share of `XMemMapPhysicalPagesScatter` walking the ray tracing tables, once per page. xperf (CPU samples with stacks) of 3 s of a load, on `main` `f3840d7`: that thread had 1,100 samples, 620 of them under `XMemMapPhysicalPagesScatter` and 377 under `watch::title_memory_unmapping` → `hwrt::title_memory_freed_many`. `XMemMapPhysicalPagesScatter` maps one page per address through `XMemMapPhysicalPages`, so every page's unmap went through `title_memory_unmapping` and walked every RT table on its own. #92 gathered those walks for the page-mapping copies (`map_aliases`) only. This runs `XMemMapPhysicalPagesScatter` inside the same `darner_gpu::title_memory_freed_gathered` scope, so the ranges it unmaps leave the tables once, before the call returns to the title. The tables end up as before; `DARNER_HW_RT_FREED_GATHERED=0` restores the walk per page, as for #92. Only `xmem.rs` changes (8 lines). ## How it was tested - Tested revision: `6bd653a` on `main` `f3840d7`. The game runs used the same change on the same `main` (`d5aa933`). - 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 --no-fail-fast`: 2,786 passed, 3 failed, 105 ignored. None is in `darner-hle` or near this change: `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders` (#92 reports it failing on `main` `1a5286a` too), `host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end` and `shadow::wide_tests::nested_wide_each_scoped_handles_overflow_concurrency_and_panics` (both timing-dependent; the second also failed once in two runs of `cargo test -p darner-gpu --lib` on clean `main` `fc3642e`). The `darner-shader` test binary hung while the game ran on the same card and was stopped, so not all of its tests ran. - `cargo test --profile fast --locked -p darner-hle --lib xmem`: 53 passed, 1 ignored (on `d5aa933`, the same diff) - Changes a default: no (it uses #92's switch, on by default). - A/B result: the same route twice (start from the same save, drive into the same busy part of the city right away), built with the `fast` profile, RTX 4080 16 GB, driver 621.40, 64 GB RAM, Series X profile, 1440p, DLSS quality, frame generation off, hardware RT. Both runs with the streaming log on (`DARNER_DSTORAGE_LOG`). Non-default rows in both: `DARNER_CARD_WINDOWS_MB=1536`, `DARNER_WINDOWS_BAR_MB=0`, `DARNER_ASK_FAST=1`, `DARNER_HW_RT_BLAS_HEAPS=0`, `DARNER_KEEP_SHOWN=checked`. One run each, hand-driven, so the routes differ a little: | | A (`main`, 134 s logged) | B (this PR, 145 s logged) | |---|---|---| | time in the title's mapping calls outside system calls | 13.4 s (26 us a page) | 4.0 s (8 us a page) | | slowest mapping call | 113 ms | 39 ms | | DirectStorage request, enqueued to done: median / p95 / p99 / max | 11 / 179 / 337 / 573 ms | 7 / 133 / 286 / 524 ms | | seconds with a frame over 200 ms | 8 of 145 | 6 of 162 | | median fps | 40 | 43 | The mapping calls' system calls took longer in B (unmap 14.3 → 19.0 s, map 6.0 → 13.2 s, about as many calls), so the calls' total did not fall (34.4 → 36.9 s): those wait for the process's address-space lock, which a kernel thread rebuilding large pages (`MiRebuildLargePages`) held for most of a load in the traced runs. This PR only removes Darner's own work in them. - Gates run on that revision: all three, results above. - Gameplay: see the A/B row. - Shader wave sizes tested: not relevant (no shader change). - Hardware dependence: needs hardware RT (without it `title_memory_freed` returns early); the cost removed grows with the RT tables. - Coverage gaps: one card, one player, one run each; not tested with software RT, AMD, Series S or frame generation. The player saw less pop-in in B; no screenshot comparison. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [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 pull requests for the same issue and for the files this touches. - Related PRs: #92 (merged; this extends its gathering to `XMemMapPhysicalPagesScatter`); #219 changes `xmem.rs` (other functions). - Replaces or overlaps: none found 🤖 Generated with [Claude Code](https://claude.com/claude-code)
XMemMapPhysicalPagesScatter maps one page per address through
XMemMapPhysicalPages, so each page's unmap walked every ray tracing table
(hwrt::title_memory_freed). In a load with hardware RT, the title's
streaming thread spent about a third of its CPU time there (xperf, RTX 4080).
The call now runs inside darner_gpu::title_memory_freed_gathered, as
map_aliases does since #92: the ranges leave the tables once, before the
call returns to the title. DARNER_HW_RT_FREED_GATHERED=0 restores the walk
per page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This pull request can be merged automatically.
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 'pr-xmem-scatter-freed-gathered:MesoPlz-pr-xmem-scatter-freed-gathered'
git switch 'MesoPlz-pr-xmem-scatter-freed-gathered'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'MesoPlz-pr-xmem-scatter-freed-gathered'
git switch 'MesoPlz-pr-xmem-scatter-freed-gathered'
git rebase 'main'
git switch 'main'
git merge --ff-only 'MesoPlz-pr-xmem-scatter-freed-gathered'
git switch 'MesoPlz-pr-xmem-scatter-freed-gathered'
git rebase 'main'
git switch 'main'
git merge --no-ff 'MesoPlz-pr-xmem-scatter-freed-gathered'
git switch 'main'
git merge --squash 'MesoPlz-pr-xmem-scatter-freed-gathered'
git switch 'main'
git merge --ff-only 'MesoPlz-pr-xmem-scatter-freed-gathered'
git switch 'main'
git merge 'MesoPlz-pr-xmem-scatter-freed-gathered'
git push origin 'main'
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!334
No description provided.