[pr-performance][memory] dstorage: address destinations in views kept in the books are written through their sections #337

Open
MesoPlz wants to merge 1 commit from MesoPlz/Darner:pr-dstorage-soft-destinations into main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: with DARNER_SOFT_VIEWS=1 (or pool), the title's pool views are kept in our books alone, but almost all of them are made views of the host's anyway. In a drive on main plus #334: 538k views noted in the books, 198k made real, nearly all "asked for by the GPU side" (the log's title views kept in the books alone line). A temporary counter of the callers of watch::materialize (not in this PR) put 99.8 % of them (42,002 of 42,086 in its run) on dstorage.rs's into_destination: a DirectStorage request with an address destination is written at that address through the kernel, so darner_gpu::kernel_writing makes each view it covers a mapping of the host's first, a map now and an unmap later, each waiting for the process's address-space lock with the title's streaming thread.

A destination that views in our books alone cover wholly, one after another, is now written through the sections' own views of their pages, as a page destination already is (page_window): xmem::soft_targets collects those views (the title maps its pool a page a call, so a destination often spans several), and the bytes are written in place when the pages are one run of a section, else through a buffer that starts with the bytes there and gives back only the bytes the fill produced (a zlib stream may end short of the destination; the title packs small textures side by side). SoftTargets::written then tells the GPU side at every address that shows those pages, as pages_written does for page destinations. Any other destination is written at its address, as before. Nothing changes where no view is kept in the books (DARNER_SOFT_VIEWS=0). With the default, copies, only a destination inside the page-mapping copies' views would take the new path: in a 2-minute drive with copies and this change, none did (0 of 182,297 address destinations; 181,416 had no view in the books near them, 881 began outside one). The A/B runs below used 1.

How it was tested

  • Tested revision: 16a24e0 on main f3840d7. The game runs used the same change on top of #334 (d5aa933), and run B also carried the temporary counters named above.

  • 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,789 passed, 0 failed in the test binaries that finished, 105 ignored. In darner-shader, emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders failed (#92 reports it failing on main 1a5286a too), and the binary then hung after emit::valu_tests::cost_checks::the_median_of_a_value_and_two_constants_is_a_clamp with no game running; it was stopped, so not all of its tests ran. This change does not touch darner-shader.
    • cargo test --profile fast --locked -p darner-hle --lib -- xmem dstorage: 92 passed, 11 ignored (on the three unsquashed commits, the same diff)
    • New test: xmem::tests::writes_into_views_in_the_books_alone_go_to_their_pages (a write across two views of one section run, in place; across views of pages out of order, through the buffer; a fill that ends short leaves the rest as it was; nothing made a view of the host's; destinations past the views or with none written at the address).
  • Changes a default: no.

  • A/B result: the same route twice, 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, DARNER_SOFT_VIEWS=1 and the streaming log in both. 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:

    A (without this PR, 135 s logged) B (with it, 182 s logged)
    time in the title's mapping calls 28.1 s (21 % of the time) 5.9 s (3 %)
    of it waiting for the runtime's locks 6.8 s 0.3 s
    views noted in the books / made real 538k / 198k 643k / 94k (80k by a fault of the title's code, 6k asked for by the GPU side)
    DirectStorage request, enqueued to done: median / p95 / p99 / max 12 / 196 / 295 / 700 ms 5 / 122 / 267 / 486 ms
    seconds with a frame over 200 ms 5 of 151 4 of 191
    median fps 45 39

    Frame rate did not improve in these runs (B drove further into the city); what changed is how fast streamed data arrives. The player saw clearly less pop-in in B ("much better"); no screenshot comparison.

  • 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: likely general (it saves Windows calls, not GPU work); measured on one PC only.

  • Coverage gaps: one card, one player, one run each, about 3 minutes; not tested on AMD, Series S, Linux/Proton, or with frame generation. An earlier version wrote the whole destination back from a zeroed buffer and broke a face texture (dotted pattern, a zlib stream shorter than its destination); fixed and covered by the test before this commit. A refresh of a texture that copies it while the bytes are being written may read it half-written, until the next refresh, as for page destinations; not seen in the runs.

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: #219 shards the LAZY map this reads (would conflict textually); #334 (same drives; independent change).
  • Replaces or overlaps: none found

🤖 Generated with Claude Code

## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: with `DARNER_SOFT_VIEWS=1` (or `pool`), the title's pool views are kept in our books alone, but almost all of them are made views of the host's anyway. In a drive on `main` plus #334: 538k views noted in the books, 198k made real, nearly all "asked for by the GPU side" (the log's `title views kept in the books alone` line). A temporary counter of the callers of `watch::materialize` (not in this PR) put 99.8 % of them (42,002 of 42,086 in its run) on `dstorage.rs`'s `into_destination`: a DirectStorage request with an address destination is written at that address through the kernel, so `darner_gpu::kernel_writing` makes each view it covers a mapping of the host's first, a map now and an unmap later, each waiting for the process's address-space lock with the title's streaming thread. A destination that views in our books alone cover wholly, one after another, is now written through the sections' own views of their pages, as a page destination already is (`page_window`): `xmem::soft_targets` collects those views (the title maps its pool a page a call, so a destination often spans several), and the bytes are written in place when the pages are one run of a section, else through a buffer that starts with the bytes there and gives back only the bytes the fill produced (a zlib stream may end short of the destination; the title packs small textures side by side). `SoftTargets::written` then tells the GPU side at every address that shows those pages, as `pages_written` does for page destinations. Any other destination is written at its address, as before. Nothing changes where no view is kept in the books (`DARNER_SOFT_VIEWS=0`). With the default, `copies`, only a destination inside the page-mapping copies' views would take the new path: in a 2-minute drive with `copies` and this change, none did (0 of 182,297 address destinations; 181,416 had no view in the books near them, 881 began outside one). The A/B runs below used `1`. ## How it was tested - Tested revision: `16a24e0` on `main` `f3840d7`. The game runs used the same change on top of #334 (`d5aa933`), and run B also carried the temporary counters named above. - 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,789 passed, 0 failed in the test binaries that finished, 105 ignored. In `darner-shader`, `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders` failed (#92 reports it failing on `main` `1a5286a` too), and the binary then hung after `emit::valu_tests::cost_checks::the_median_of_a_value_and_two_constants_is_a_clamp` with no game running; it was stopped, so not all of its tests ran. This change does not touch `darner-shader`. - `cargo test --profile fast --locked -p darner-hle --lib -- xmem dstorage`: 92 passed, 11 ignored (on the three unsquashed commits, the same diff) - New test: `xmem::tests::writes_into_views_in_the_books_alone_go_to_their_pages` (a write across two views of one section run, in place; across views of pages out of order, through the buffer; a fill that ends short leaves the rest as it was; nothing made a view of the host's; destinations past the views or with none written at the address). - Changes a default: no. - A/B result: the same route twice, 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, `DARNER_SOFT_VIEWS=1` and the streaming log in both. 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: | | A (without this PR, 135 s logged) | B (with it, 182 s logged) | |---|---|---| | time in the title's mapping calls | 28.1 s (21 % of the time) | 5.9 s (3 %) | | of it waiting for the runtime's locks | 6.8 s | 0.3 s | | views noted in the books / made real | 538k / 198k | 643k / 94k (80k by a fault of the title's code, 6k asked for by the GPU side) | | DirectStorage request, enqueued to done: median / p95 / p99 / max | 12 / 196 / 295 / 700 ms | 5 / 122 / 267 / 486 ms | | seconds with a frame over 200 ms | 5 of 151 | 4 of 191 | | median fps | 45 | 39 | Frame rate did not improve in these runs (B drove further into the city); what changed is how fast streamed data arrives. The player saw clearly less pop-in in B ("much better"); no screenshot comparison. - 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: likely general (it saves Windows calls, not GPU work); measured on one PC only. - Coverage gaps: one card, one player, one run each, about 3 minutes; not tested on AMD, Series S, Linux/Proton, or with frame generation. An earlier version wrote the whole destination back from a zeroed buffer and broke a face texture (dotted pattern, a zlib stream shorter than its destination); fixed and covered by the test before this commit. A refresh of a texture that copies it while the bytes are being written may read it half-written, until the next refresh, as for page destinations; not seen in the runs. ## 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: #219 shards the `LAZY` map this reads (would conflict textually); #334 (same drives; independent change). - Replaces or overlaps: none found 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With DARNER_SOFT_VIEWS=pool or 1 the title's pool views stay in our books,
but a DirectStorage request with an address destination was written at
that address through the kernel, so darner_gpu::kernel_writing made each
view it covered one of the host's first: a map and later an unmap, each
waiting for the process's address-space lock with the title's streaming
thread. In a drive these were 99.8 % of the views made real.

xmem::soft_targets takes the views in the books a destination covers, one
after another (the title maps its pool a page a call), and gives the
section's own view of their pages, as page destinations get one
(page_window): written in place when the pages are one run of a section,
else through a buffer that starts with the bytes there and gives back only
the bytes the fill produced (a zlib stream may end short of the
destination). SoftTargets::written then tells the GPU side at every address
that shows those pages, as pages_written does. A destination not wholly in
such views is written at its address, as before.

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-dstorage-soft-destinations:MesoPlz-pr-dstorage-soft-destinations'
git switch 'MesoPlz-pr-dstorage-soft-destinations'

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-dstorage-soft-destinations'
git switch 'MesoPlz-pr-dstorage-soft-destinations'
git rebase 'main'
git switch 'main'
git merge --ff-only 'MesoPlz-pr-dstorage-soft-destinations'
git switch 'MesoPlz-pr-dstorage-soft-destinations'
git rebase 'main'
git switch 'main'
git merge --no-ff 'MesoPlz-pr-dstorage-soft-destinations'
git switch 'main'
git merge --squash 'MesoPlz-pr-dstorage-soft-destinations'
git switch 'main'
git merge --ff-only 'MesoPlz-pr-dstorage-soft-destinations'
git switch 'main'
git merge 'MesoPlz-pr-dstorage-soft-destinations'
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!337
No description provided.