[pr-fix][memory] darner-gpu: the card ledger records when every listed kind was last used #430

Open
qnjk wants to merge 1 commit from qnjk/Darner:cardledger-idle-frames into main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: the full card-ledger report (DARNER_CARD_LEDGER=1, every 600 frames) lists the largest objects of nine LISTED kinds and prints ", made {} frames ago, unused for {} frames" with frame.saturating_sub(e.used) (cardledger.rs:554-558), then counts each kind's bytes into the "unused 60+ / 600+" columns when that difference passes the threshold (:568-572). Entry::used was only ever moved by touch, and touch had three callers, all in resource.rs for HostTexture uses. So Kind::Indirect (a HostList's kept indirect_args/batch_args buffers and its card budget), Kind::BeforeTwin (the hashes of every copy in the card's memory, read again by every submission's compare), Kind::Scratch, Kind::AheadStore and Kind::SwapChain kept the frame they were made in: buffers used every frame were reported as unused for as long as they had existed, and their bytes counted into the column whose purpose is to say what may be moved off the card. The module doc says that column exists so "what is moved off the card is the right thing"; the existing test only passed because it fed used by hand.

  • This change tells the use where it happens: touch now records through one bookkeeping function (cardledger::entry_used, tested), with new calls from HostList::indirect_scratch (the reused arguments buffer), HostList::batch_place (each batch's buffer), HostList::budget (the card budget the clamp's notes are written through), Host::record_twin_copy, and the three compare sites in Host::card_record through a new Shadow::card_before_used. Kinds that have no use site are not given a fake one; the report still lists them (they are listed because they can be large), and they keep the frame they were made in.

How it was tested

  • Tested revision: 1592d9e (one commit on f3840d7).
  • Commands and results:
    • cargo test --locked -p darner-gpu --lib -- cardledger — 26 passed, 0 failed.
    • The unit test cardledger::tests::uses_are_numbered_after_the_kinds_in_the_order_of_their_names pins the ordering and the new bookkeeping path; the existing report-format tests (the_lines_give_the_sum_dxgi_and_the_difference, the_waste_line_tells_asked_against_taken, the_report_tells_empty_blocks_from_slack, shared_lines_stay_under_400_characters_with_every_origin_and_use) still pass unchanged.
    • cargo clippy --locked -p darner-gpu --all-targets -- -D warnings passes.
  • Changes a default: no. Nothing about residency or eviction changes; only the frame numbers the diagnostics report prints, and only when DARNER_CARD_LEDGER is on.
  • A/B result: not applicable — no default changes and no speed claim. The report is a diagnostics print, not a decision the runtime makes.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not green on this machine, and not because of this change. Three pre-existing failures, each covered by an open pull request: darner-gpu stands still in parallel on the test deadlock #224 describes, and serially finishes 1772 passed and 1 failed (pipeline::make::tests::a_capped_draw_waits_once_then_drops, which passes on its own) beside the order-dependent flakes of #150; darner-shader fails emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, whose fixture #227 fixes.
  • Gameplay, when relevant: no gameplay run. The change affects only what the 600-frame report prints; a run is not needed to observe it and no frame-rate claim is made.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: the report was not read from a real run with DARNER_CARD_LEDGER=1; the bookkeeping and the formatting are pinned by tests. The five kinds still keep their creation frame when they genuinely have no use site — whether the report should print "n/a" for them instead is left to the maintainer.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay: this is the diagnostics report, and the change cannot alter behaviour; the evidence is the bookkeeping tests plus the report-format tests that still pass.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 555 files ok.)
  • 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: crates/darner-gpu/src/host.rs is changed by 40 open pull requests and crates/darner-gpu/src/shadow.rs by 10, so a textual conflict is possible; this change only adds call sites (no existing line is edited) at host.rs:3962, :10052, :10320, :10403, :15166-15170, :15302-15309, :15353-15360 and shadow.rs:10972-10982, which narrows what can collide. cardledger.rs itself is changed by no open pull request, and no open or closed issue mentions the card ledger, DARNER_CARD_LEDGER or the "unused for" column.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: the full card-ledger report (`DARNER_CARD_LEDGER=1`, every 600 frames) lists the largest objects of nine `LISTED` kinds and prints `", made {} frames ago, unused for {} frames"` with `frame.saturating_sub(e.used)` (`cardledger.rs:554-558`), then counts each kind's bytes into the "unused 60+ / 600+" columns when that difference passes the threshold (`:568-572`). `Entry::used` was only ever moved by `touch`, and `touch` had three callers, all in `resource.rs` for `HostTexture` uses. So `Kind::Indirect` (a `HostList`'s kept `indirect_args`/`batch_args` buffers and its card budget), `Kind::BeforeTwin` (the hashes of every copy in the card's memory, read again by every submission's compare), `Kind::Scratch`, `Kind::AheadStore` and `Kind::SwapChain` kept the frame they were **made** in: buffers used every frame were reported as unused for as long as they had existed, and their bytes counted into the column whose purpose is to say what may be moved off the card. The module doc says that column exists so "what is moved off the card is the right thing"; the existing test only passed because it fed `used` by hand. - This change tells the use where it happens: `touch` now records through one bookkeeping function (`cardledger::entry_used`, tested), with new calls from `HostList::indirect_scratch` (the reused arguments buffer), `HostList::batch_place` (each batch's buffer), `HostList::budget` (the card budget the clamp's notes are written through), `Host::record_twin_copy`, and the three compare sites in `Host::card_record` through a new `Shadow::card_before_used`. Kinds that have no use site are not given a fake one; the report still lists them (they are listed because they can be large), and they keep the frame they were made in. ## How it was tested - Tested revision: `1592d9e` (one commit on `f3840d7`). - Commands and results: - `cargo test --locked -p darner-gpu --lib -- cardledger` — 26 passed, 0 failed. - The unit test `cardledger::tests::uses_are_numbered_after_the_kinds_in_the_order_of_their_names` pins the ordering and the new bookkeeping path; the existing report-format tests (`the_lines_give_the_sum_dxgi_and_the_difference`, `the_waste_line_tells_asked_against_taken`, `the_report_tells_empty_blocks_from_slack`, `shared_lines_stay_under_400_characters_with_every_origin_and_use`) still pass unchanged. - `cargo clippy --locked -p darner-gpu --all-targets -- -D warnings` passes. - Changes a default: no. Nothing about residency or eviction changes; only the frame numbers the diagnostics report prints, and only when `DARNER_CARD_LEDGER` is on. - A/B result: not applicable — no default changes and no speed claim. The report is a diagnostics print, not a decision the runtime makes. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: **not green on this machine, and not because of this change.** Three pre-existing failures, each covered by an open pull request: `darner-gpu` stands still in parallel on the test deadlock #224 describes, and serially finishes 1772 passed and 1 failed (`pipeline::make::tests::a_capped_draw_waits_once_then_drops`, which passes on its own) beside the order-dependent flakes of #150; `darner-shader` fails `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, whose fixture #227 fixes. - Gameplay, when relevant: no gameplay run. The change affects only what the 600-frame report prints; a run is not needed to observe it and no frame-rate claim is made. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: the report was not read from a real run with `DARNER_CARD_LEDGER=1`; the bookkeeping and the formatting are pinned by tests. The five kinds still keep their creation frame when they genuinely have no use site — whether the report should print "n/a" for them instead is left to the maintainer. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay: this is the diagnostics report, and the change cannot alter behaviour; the evidence is the bookkeeping tests plus the report-format tests that still pass. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 555 files ok.) - [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: `crates/darner-gpu/src/host.rs` is changed by 40 open pull requests and `crates/darner-gpu/src/shadow.rs` by 10, so a textual conflict is possible; this change only **adds** call sites (no existing line is edited) at `host.rs:3962`, `:10052`, `:10320`, `:10403`, `:15166-15170`, `:15302-15309`, `:15353-15360` and `shadow.rs:10972-10982`, which narrows what can collide. `cardledger.rs` itself is changed by no open pull request, and no open or closed issue mentions the card ledger, `DARNER_CARD_LEDGER` or the "unused for" column. - Replaces or overlaps: none found
The 600-frame report tells, for the largest objects of each of the nine kinds
it lists, how many frames ago one was last used; but the frame a use is
recorded in was only ever fed for the four texture kinds, whose two sites call
`touch` from resource.rs. So the buffer of indirect arguments a list keeps
from recording to recording (indirect_scratch, batch_place), the list's card
budget for the clamp's notes, the "before" hashes a submission's compare reads
and the buffer a twin is copied through all kept the frame they were made in,
and were printed as unused since it. Their bytes went into the report's 60+ /
600+ columns, which exist to tell what may be moved off the card: the run
named the buffers in use every frame as the ones to move.

Tell the ledger of those uses at the site of each: the reused indirect
arguments, each batch's buffer and the card budget in host.rs; the compare's
hashes through shadow::card_before_used; the twin's buffer in
record_twin_copy. Two kinds need no new call: the retag that gives a pooled
buffer its kind already records the frame (the take that hands a Kind::Scratch
out, the frame a Kind::AheadStore buffer is set aside in, which is as long as
it has gone unused). The swap chain has no use site to point at: its entry
stands for the back buffers of the chain the presents show, no one place tells
the ledger of a present, and it hangs on no object of ours. The report says
"unused n/a" for it and leaves it out of the sums, rather than print the age
since it was made as if it had been idle all along.

The frame a use is recorded in is one function now, entry_used, which touch
calls. The new test builds one entry of every listed kind by hand (no device,
no title) and pins both halves: a kind with no use site is not told as idle,
and entry_used moves the frame a use is told in.
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 'cardledger-idle-frames:qnjk-cardledger-idle-frames'
git switch 'qnjk-cardledger-idle-frames'

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 'qnjk-cardledger-idle-frames'
git switch 'qnjk-cardledger-idle-frames'
git rebase 'main'
git switch 'main'
git merge --ff-only 'qnjk-cardledger-idle-frames'
git switch 'qnjk-cardledger-idle-frames'
git rebase 'main'
git switch 'main'
git merge --no-ff 'qnjk-cardledger-idle-frames'
git switch 'main'
git merge --squash 'qnjk-cardledger-idle-frames'
git switch 'main'
git merge --ff-only 'qnjk-cardledger-idle-frames'
git switch 'main'
git merge 'qnjk-cardledger-idle-frames'
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!430
No description provided.