A CPU copy of a title buffer finds the card copies that hold it by their range #543

Open
EmberReD wants to merge 1 commit from EmberReD/Darner:perf/card-copies-by-range into Main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: read from a CPU profile of the game. After each CPU copy of a title buffer (Batch::flush_copy), shadow::send_copied calls carded_copies(), which upgrades every copy in the card's memory (about 4,000 here) into a new Vec, and then reads each copy's start and len to find the few that overlap the copied bytes. Each of those reads is a different heap object, so the loop mostly waits on memory. In a 30 s profile of downtown play, flush_copy was 12% of the submitting thread's samples (3,281 of 27,358): 1,587 in the collect of carded_copies and 1,636 in the loop itself.

What this does:

  • CARDED keeps each copy's title range beside its weak pointer: Vec<(u64, u64, Weak<Shadow>)>, filled in carded (a copy's start and len never change after it is made).
  • send_copied scans that array under the lock and upgrades only the copies whose range overlaps the copied bytes. What it does with them is unchanged.
  • The other readers of CARDED (carded_copies, release_idle_mirrors, card_stats, idle_cpu_mirrors) read the weak pointer from the tuple; they behave as before.

How it was tested

  • Tested revision: b668002 (one commit on main c8258f9). In the game: the same change on a build of main f3840d7 with other open performance pull requests merged, shadow.rs around the change being the same as on c8258f9.
  • Commands and results: see the gates below. No new test: the copies in the card's memory need a D3D12 host, and this PC's test processes can't make one (see below).
  • Changes a default: no.
  • A/B result: A (the same build without this commit) and B (with it), in two sessions of downtown play, median of the frame-rate line's "copies and fills" of the submitting thread: A 6.8 ms a frame (3,318 lines), B 2.4 ms (472 lines). The scenes were not the same, so the whole frame is not compared. In a 30 s CPU profile of each, flush_copy went from 3,281 samples of the submitting thread's 27,358 to 203 of 29,288.
  • Gates run on b668002 (Windows 10 22H2): gate 1 and gate 2 clean. Gate 3 only for the changed crate, cargo test --locked -p darner-gpu --lib -- shadow:: host::: every test that makes a D3D12 host stops the process with code 3 ("this PC's Direct3D 12 cannot run the translated shaders: they need Shader Model 6.6"; Windows 10's built-in D3D12 in a test process), so those tests don't run here, with or without this change. The other crates don't depend on this file and were not run.
  • Gameplay: RTX 3070 Ti, Series S profile, 1080p to 1440p, DLSS quality, DLSS frame generation x2, no ray tracing. B also had DARNER_ASK_FAST=1, which does not touch this path.
  • Shader wave sizes tested: not relevant (no shader change).
  • Hardware dependence: none expected. The saving grows with the number of copies in the card's memory.
  • Coverage gaps: no unit test ran the changed code (see above).

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.
    • None

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #218, #219, #221, #310, #319, #321, #332, #345, #440, #494, #508 also change shadow.rs, none of them send_copied, carded_copies or CARDED.
  • Replaces or overlaps: none found

🤖 Generated with Claude Code

## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: read from a CPU profile of the game. After each CPU copy of a title buffer (`Batch::flush_copy`), `shadow::send_copied` calls `carded_copies()`, which upgrades every copy in the card's memory (about 4,000 here) into a new `Vec`, and then reads each copy's `start` and `len` to find the few that overlap the copied bytes. Each of those reads is a different heap object, so the loop mostly waits on memory. In a 30 s profile of downtown play, `flush_copy` was 12% of the submitting thread's samples (3,281 of 27,358): 1,587 in the collect of `carded_copies` and 1,636 in the loop itself. What this does: - `CARDED` keeps each copy's title range beside its weak pointer: `Vec<(u64, u64, Weak<Shadow>)>`, filled in `carded` (a copy's `start` and `len` never change after it is made). - `send_copied` scans that array under the lock and upgrades only the copies whose range overlaps the copied bytes. What it does with them is unchanged. - The other readers of `CARDED` (`carded_copies`, `release_idle_mirrors`, `card_stats`, `idle_cpu_mirrors`) read the weak pointer from the tuple; they behave as before. ## How it was tested - Tested revision: b668002 (one commit on main c8258f9). In the game: the same change on a build of main f3840d7 with other open performance pull requests merged, `shadow.rs` around the change being the same as on c8258f9. - Commands and results: see the gates below. No new test: the copies in the card's memory need a D3D12 host, and this PC's test processes can't make one (see below). - Changes a default: no. - A/B result: A (the same build without this commit) and B (with it), in two sessions of downtown play, median of the frame-rate line's "copies and fills" of the submitting thread: A 6.8 ms a frame (3,318 lines), B 2.4 ms (472 lines). The scenes were not the same, so the whole frame is not compared. In a 30 s CPU profile of each, `flush_copy` went from 3,281 samples of the submitting thread's 27,358 to 203 of 29,288. - Gates run on b668002 (Windows 10 22H2): gate 1 and gate 2 clean. Gate 3 only for the changed crate, `cargo test --locked -p darner-gpu --lib -- shadow:: host::`: every test that makes a D3D12 host stops the process with code 3 ("this PC's Direct3D 12 cannot run the translated shaders: they need Shader Model 6.6"; Windows 10's built-in D3D12 in a test process), so those tests don't run here, with or without this change. The other crates don't depend on this file and were not run. - Gameplay: RTX 3070 Ti, Series S profile, 1080p to 1440p, DLSS quality, DLSS frame generation x2, no ray tracing. B also had `DARNER_ASK_FAST=1`, which does not touch this path. - Shader wave sizes tested: not relevant (no shader change). - Hardware dependence: none expected. The saving grows with the number of copies in the card's memory. - Coverage gaps: no unit test ran the changed code (see above). ## 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. - None ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #218, #219, #221, #310, #319, #321, #332, #345, #440, #494, #508 also change `shadow.rs`, none of them `send_copied`, `carded_copies` or `CARDED`. - Replaces or overlaps: none found 🤖 Generated with [Claude Code](https://claude.com/claude-code)
After each CPU copy of a title buffer, send_copied upgraded every copy in
the card's memory (about 4,000) and read its range to find the few that
hold the copied bytes. CARDED now keeps each copy's range beside its weak
pointer, so the look is a scan of one array and only the copies that hold
the bytes are upgraded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TrustNo1 changed title from [pr-performance][memory] A CPU copy of a title buffer finds the card copies that hold it by their range to A CPU copy of a title buffer finds the card copies that hold it by their range 2026-12-06 03:27:29 +00:00
Owner

Test needed — commit b668002e; what to check:

  • The problem on main: read from a CPU profile of the game. After each CPU copy of a title buffer (Batch::flush_copy), shadow::send_copied calls carded_copies(), which upgrades every copy in the card's memory (about 4,000 here) into a new Vec, and then reads each copy's start and len to find the few that overlap the copied bytes. Each of those reads is a different heap object, so the loop mostly waits on memory. In a 30 s profile of downtown play, flush_copy was 12% of the submitting thread's samples (3,281 of 27,358): 1,587 in the collect of carded_copies and 1,636 in the loop itself.

What this does:

  • CARDED keeps each copy's title range beside its weak pointer: Vec<(u64, u64, Weak<Shadow>)>, filled in carded (a copy's start and len never change after it is made).
  • send_copied scans that array under the lock and upgrades only the copies whose range overlaps the copied bytes. What it does with them is unchanged.
  • The other readers of CARDED (carded_copies, release_idle_mirrors, card_stats, idle_cpu_mirrors) read the weak pointer from the tuple; they behave as before.

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `b668002e`; what to check: - The problem on main: read from a CPU profile of the game. After each CPU copy of a title buffer (`Batch::flush_copy`), `shadow::send_copied` calls `carded_copies()`, which upgrades every copy in the card's memory (about 4,000 here) into a new `Vec`, and then reads each copy's `start` and `len` to find the few that overlap the copied bytes. Each of those reads is a different heap object, so the loop mostly waits on memory. In a 30 s profile of downtown play, `flush_copy` was 12% of the submitting thread's samples (3,281 of 27,358): 1,587 in the collect of `carded_copies` and 1,636 in the loop itself. What this does: - `CARDED` keeps each copy's title range beside its weak pointer: `Vec<(u64, u64, Weak<Shadow>)>`, filled in `carded` (a copy's `start` and `len` never change after it is made). - `send_copied` scans that array under the lock and upgrades only the copies whose range overlaps the copied bytes. What it does with them is unchanged. - The other readers of `CARDED` (`carded_copies`, `release_idle_mirrors`, `card_stats`, `idle_cpu_mirrors`) read the weak pointer from the tuple; they behave as before. Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
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 'perf/card-copies-by-range:EmberReD-perf/card-copies-by-range'
git switch 'EmberReD-perf/card-copies-by-range'

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 'EmberReD-perf/card-copies-by-range'
git switch 'EmberReD-perf/card-copies-by-range'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'EmberReD-perf/card-copies-by-range'
git switch 'EmberReD-perf/card-copies-by-range'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'EmberReD-perf/card-copies-by-range'
git switch 'Main'
git merge --squash 'EmberReD-perf/card-copies-by-range'
git switch 'Main'
git merge --ff-only 'EmberReD-perf/card-copies-by-range'
git switch 'Main'
git merge 'EmberReD-perf/card-copies-by-range'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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!543
No description provided.