[pr-performance][memory] texback: texture read-backs wait only for remaps of their own range (DARNER_RANGE_LOCK=1) #341

Open
Yorivel wants to merge 1 commit from Yorivel/Darner:pr/texback-range-lock into main
First-time contributor

Refs #287

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: texback::land puts each texture read-back into title memory under watch::title_memory_reading(), which waits for every mapping change of the title's, even with DARNER_RANGE_LOCK=1 (it reads rangelock::ALL). It runs on the thread that lands flights (the relay), in the step the landing line calls "read-backs and lists". While the world streams, the title's mapping calls take hundreds of milliseconds a second, and the relay waits behind them for every read-back (about 600 a second in my runs).

It now takes watch::title_memory_reading_of(at, end - at) for the texture's own range, as texture.rs already does for its reads of a texture's memory. Everything it reads or writes under the lock lies in that range (read_previous, the tiled copy, copy_mapped), and nothing under it takes the lock again. With DARNER_RANGE_LOCK unset nothing changes: title_memory_reading_of is title_memory_reading then.

How it was found: a city run with DARNER_UNIFIED_STATS=1 and DARNER_DSTORAGE_LOG, seconds sorted by frames over 50 ms. Of the landing's steps only "read-backs and lists" grew in the bad seconds, and per second it followed the milliseconds of the title's mapping calls (the streaming log's M lines), correlation 0.85:

Seconds with "read-backs and lists" per frame, median title mapping calls, ms per second texture read-backs per second
no frame over 50 ms 1.6 ms 147 640
1-2 frames over 50 ms 7.6 ms 351 640
3 or more 19.9 ms 748 512

DirectStorage was not the cause in that run (no request stuck over 250 ms, p99 from enqueue to done 9 ms calm and 14 ms in the bad seconds), nor merging, fetching or the volume landed (all flat between those rows).

How it was tested

  • Tested revision: this commit's change on a local build of f3840d7 with #310, #274 and #283 merged (PGO); both runs below are on that tree, the A without this change. The gates are on this branch (25acf1b, on main f3840d7).

  • Commands and results: the two runs below; the gates below.

  • Changes a default: no (only with DARNER_RANGE_LOCK=1, off by default).

  • A/B result: RTX 4090, the same save, the same drive into the city, 10 min each, DARNER_UNIFIED_STATS=1, the same DARNER_LAND_LEAVE list in both. A = the tree without this change and DARNER_RANGE_LOCK unset; B = with this change and DARNER_RANGE_LOCK=1. (B is therefore the switch and this change together; I have no run of the switch alone.)

    A B
    frames over 50 ms, whole run 5.5 % of 17,155 1.5 % of 16,725
    frames over 50 ms, under 5,000 draws 1.7 % 0.5 %
    5,000-7,000 draws 8.5 % 1.5 %
    7,000-9,000 draws 8.3 % 3.7 %
    9,000 draws and more 18.6 % (361 frames) 2.0 % (2,159 frames)
    relay "landing in all" per frame, median 11.0 ms 6.8 ms
    "read-backs and lists" in seconds with 3+ frames over 50 ms, median 19.9 ms 1.5 ms
    its correlation with the title's mapping ms per second 0.85 0.13

    The title's mapping calls were as heavy in B (755 ms a second in its worst seconds against 748), so the streaming did not get lighter; the relay just no longer waits for it. B also spent six times as many frames at 9,000 draws and more.

  • Gates run on 25acf1b: the asset policy (555 files ok) and gates 1 and 2 (both clippy runs) pass. Gate 3: every crate passes except one darner-shader test, emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders (DXIL validation: "Not all elements of output SV_Depth were written"). It fails alone too, darner-shader does not depend on darner-gpu, and #227 fixes that test's fixture. darner-gpu's library tests: 1,773 passed, 81 ignored.

  • Gameplay: RTX 4090, i9-14900K, Series X, 1440p, DLSS Quality, DLSS frame generation 2x, hardware RT. No new kinds of warnings in B's log (the same kinds as A's, no errors). No visual faults seen; to my eye fewer short black spots on textures in the city in B, not measured.

  • Hardware dependence: the wait is the CPU's; any PC whose title streams while the relay lands should see it. Other PCs untested.

  • Coverage gaps: one run each; both with the leave list of #310 and with #274; the switch's other effects (the texture refresh's reads also wait only for their own range) are in B as well, so B is not this change alone.

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 (effective with DARNER_RANGE_LOCK=1)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none change texback.rs or the mapping locks. #321, #219, #150 and #50 change watch.rs elsewhere; trial merges with #321, #219 and #150 have no conflict (#50 conflicts with main already, in texture/ahead.rs). No open or closed PR or issue mentions DARNER_RANGE_LOCK; #331, #182 and #162 show texback lines only as routine log lines.
  • Replaces or overlaps: none found

🤖 Generated with Claude Code

Refs #287 ## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `texback::land` puts each texture read-back into title memory under `watch::title_memory_reading()`, which waits for every mapping change of the title's, even with `DARNER_RANGE_LOCK=1` (it reads `rangelock::ALL`). It runs on the thread that lands flights (the relay), in the step the landing line calls "read-backs and lists". While the world streams, the title's mapping calls take hundreds of milliseconds a second, and the relay waits behind them for every read-back (about 600 a second in my runs). It now takes `watch::title_memory_reading_of(at, end - at)` for the texture's own range, as `texture.rs` already does for its reads of a texture's memory. Everything it reads or writes under the lock lies in that range (`read_previous`, the tiled copy, `copy_mapped`), and nothing under it takes the lock again. With `DARNER_RANGE_LOCK` unset nothing changes: `title_memory_reading_of` is `title_memory_reading` then. How it was found: a city run with `DARNER_UNIFIED_STATS=1` and `DARNER_DSTORAGE_LOG`, seconds sorted by frames over 50 ms. Of the landing's steps only "read-backs and lists" grew in the bad seconds, and per second it followed the milliseconds of the title's mapping calls (the streaming log's `M` lines), correlation 0.85: | Seconds with | "read-backs and lists" per frame, median | title mapping calls, ms per second | texture read-backs per second | |---|---|---|---| | no frame over 50 ms | 1.6 ms | 147 | 640 | | 1-2 frames over 50 ms | 7.6 ms | 351 | 640 | | 3 or more | 19.9 ms | 748 | 512 | DirectStorage was not the cause in that run (no request stuck over 250 ms, p99 from enqueue to done 9 ms calm and 14 ms in the bad seconds), nor merging, fetching or the volume landed (all flat between those rows). ## How it was tested - Tested revision: this commit's change on a local build of `f3840d7` with #310, #274 and #283 merged (PGO); both runs below are on that tree, the A without this change. The gates are on this branch (`25acf1b`, on `main` `f3840d7`). - Commands and results: the two runs below; the gates below. - Changes a default: no (only with `DARNER_RANGE_LOCK=1`, off by default). - A/B result: RTX 4090, the same save, the same drive into the city, 10 min each, `DARNER_UNIFIED_STATS=1`, the same `DARNER_LAND_LEAVE` list in both. A = the tree without this change and `DARNER_RANGE_LOCK` unset; B = with this change and `DARNER_RANGE_LOCK=1`. (B is therefore the switch and this change together; I have no run of the switch alone.) | | A | B | |---|---|---| | frames over 50 ms, whole run | 5.5 % of 17,155 | 1.5 % of 16,725 | | frames over 50 ms, under 5,000 draws | 1.7 % | 0.5 % | | 5,000-7,000 draws | 8.5 % | 1.5 % | | 7,000-9,000 draws | 8.3 % | 3.7 % | | 9,000 draws and more | 18.6 % (361 frames) | 2.0 % (2,159 frames) | | relay "landing in all" per frame, median | 11.0 ms | 6.8 ms | | "read-backs and lists" in seconds with 3+ frames over 50 ms, median | 19.9 ms | 1.5 ms | | its correlation with the title's mapping ms per second | 0.85 | 0.13 | The title's mapping calls were as heavy in B (755 ms a second in its worst seconds against 748), so the streaming did not get lighter; the relay just no longer waits for it. B also spent six times as many frames at 9,000 draws and more. - Gates run on `25acf1b`: the asset policy (555 files ok) and gates 1 and 2 (both clippy runs) pass. Gate 3: every crate passes except one `darner-shader` test, `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders` (DXIL validation: "Not all elements of output SV_Depth were written"). It fails alone too, `darner-shader` does not depend on `darner-gpu`, and #227 fixes that test's fixture. `darner-gpu`'s library tests: 1,773 passed, 81 ignored. - Gameplay: RTX 4090, i9-14900K, Series X, 1440p, DLSS Quality, DLSS frame generation 2x, hardware RT. No new kinds of warnings in B's log (the same kinds as A's, no errors). No visual faults seen; to my eye fewer short black spots on textures in the city in B, not measured. - Hardware dependence: the wait is the CPU's; any PC whose title streams while the relay lands should see it. Other PCs untested. - Coverage gaps: one run each; both with the leave list of #310 and with #274; the switch's other effects (the texture refresh's reads also wait only for their own range) are in B as well, so B is not this change alone. ## 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 (effective with `DARNER_RANGE_LOCK=1`) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none change `texback.rs` or the mapping locks. #321, #219, #150 and #50 change `watch.rs` elsewhere; trial merges with #321, #219 and #150 have no conflict (#50 conflicts with `main` already, in `texture/ahead.rs`). No open or closed PR or issue mentions `DARNER_RANGE_LOCK`; #331, #182 and #162 show `texback` lines only as routine log lines. - Replaces or overlaps: none found 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With DARNER_RANGE_LOCK=1 the thread that lands flights no longer waits for
every mapping call of the title's while it puts a texture read-back into
title memory, only for those touching the texture.

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/texback-range-lock:Yorivel-pr/texback-range-lock'
git switch 'Yorivel-pr/texback-range-lock'

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 'Yorivel-pr/texback-range-lock'
git switch 'Yorivel-pr/texback-range-lock'
git rebase 'main'
git switch 'main'
git merge --ff-only 'Yorivel-pr/texback-range-lock'
git switch 'Yorivel-pr/texback-range-lock'
git rebase 'main'
git switch 'main'
git merge --no-ff 'Yorivel-pr/texback-range-lock'
git switch 'main'
git merge --squash 'Yorivel-pr/texback-range-lock'
git switch 'main'
git merge --ff-only 'Yorivel-pr/texback-range-lock'
git switch 'main'
git merge 'Yorivel-pr/texback-range-lock'
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!341
No description provided.