[pr-performance][memory] card steps: read sources in place in card memory (DARNER_CARD_STEPS_IN_PLACE=1, off by default) #1

Merged
Lucid merged 6 commits from theforgotten669/Darner:rebar-card-steps-in-place into rebar 2026-12-05 15:07:36 +00:00
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

Roadmap open problem 2 (docs/roadmap-plan.md): about 350 pool fills a frame still went through rebar_pool::read_via_card (about 3 ms of round trips). The title copy they were taken along with had a source in place, and holder() refused every copy in place.

New switch DARNER_CARD_STEPS_IN_PLACE=1, off by default. With it off, the only change is the refusal text on the frame line.

  • Heap twin sources. holder() lets a copy in place serve as a source when its placed buffer is in the graphics heap's twin. Our list reads the placed buffer.
    • It records the all-resources UAV barrier first: aliases of one heap aren't ordered by per-buffer barriers.
    • It holds the placed buffer until the list has run. A twin copy asks for no refresh, so the list didn't keep it alive.
  • Pool sources, for any title copy. A title copy whose source lies in a pool reads the pool's whole buffer (Src::Pool), whatever its destination. Before, that only happened for fills and for copies into a pool. This bullet goes beyond the twin fix and can be dropped on its own if you'd rather.
  • The sync check from the roadmap. Both send paths (host.rs, sender and submitting thread) call heap_twin::sync before ExecuteCommandLists, our list included. Steps of ours that write title memory force that sync (heap_twin::ours, wrote_through).
  • Still refused: destinations in place (the next twin sync would overwrite a card write, and it would never reach the title's side), and sources over title memory in place.
  • Refusal reasons. Each refusal of a copy in place now names its backing. The reasons go to the release log line "ReBAR pools (DARNER_REBAR_POOLS=1): pool fills with a target left to the CPU by card steps, per frame, by why". One run shows how many of the 350 were twin sources. If most say "its host copy is title memory in place", this switch doesn't reach them. The same argument would cover that backing in a follow-up.
  • Why the bytes are right.
    • The twin may hold bytes newer than at submission, where the title wrote again since.
    • It also holds what earlier flights' shaders wrote, which the CPU path never saw. The console reads one memory when the GPU runs, the same argument as for fills out of a pool (fills_in_pools).
    • Risk (heap_twin risk 2): a 4 KiB sync can land over bytes a flight in the air writes. The card step then reads whichever write wins.
  • Also fixed: a pool → host-copy copy is not counted as a pool fill.
  • Docs. README row added. The roadmap entry for problem 2 is updated: code done, not run.

How it was tested

  • Tested revision: e562db6
  • Commands and results:
    • cargo test -p darner-gpu --lib --locked -- host::card_steps::tests::copies_in_place host::card_steps::tests::what_no_host host::card_steps::tests::flight_texture: 3 passed. One of them is new (copies_in_place_serve_only_as_twin_sources_when_asked).
    • cargo xtask policy --staged: 4 files ok.
    • cargo clippy -p darner-gpu --all-targets --locked -- -D warnings: fails with 15 errors, none on a line this change touches (rebar_pool.rs, memprobe_rebar.rs, indirect/mesh_bench.rs, touch_audit.rs, poolcensus/reads.rs, draw.rs, card_steps.rs:2304). Not run on the base commit.
  • Gameplay: not run.
  • Before and after: not measured. Next step: one run with DARNER_REBAR_POOLS=1 (and DARNER_HEAP_TWIN=1), with the switch on and off. Compare the read_via_card round trips, the pool fills taken, and the refusal reasons. Then a picture check.
  • Coverage gaps: no game run, no full darner-gpu suite, CI gates 2 and 3 not run, no diagnostics build.

Checklist

  • This PR contains one change based on main. (It's based on rebar, as the roadmap asks.)
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none (targets rebar at fae95b1)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found (Lucid/Darner has no pull requests)

🤖 Generated with Claude Code

## Contributor role (optional) - Fluxer ID: ## What it changes Roadmap open problem 2 (`docs/roadmap-plan.md`): about 350 pool fills a frame still went through `rebar_pool::read_via_card` (about 3 ms of round trips). The title copy they were taken along with had a source in place, and `holder()` refused every copy in place. New switch `DARNER_CARD_STEPS_IN_PLACE=1`, off by default. With it off, the only change is the refusal text on the frame line. - **Heap twin sources.** `holder()` lets a copy in place serve as a *source* when its placed buffer is in the graphics heap's twin. Our list reads the placed buffer. - It records the all-resources UAV barrier first: aliases of one heap aren't ordered by per-buffer barriers. - It holds the placed buffer until the list has run. A twin copy asks for no refresh, so the list didn't keep it alive. - **Pool sources, for any title copy.** A title copy whose source lies in a pool reads the pool's whole buffer (`Src::Pool`), whatever its destination. Before, that only happened for fills and for copies into a pool. This bullet goes beyond the twin fix and can be dropped on its own if you'd rather. - **The sync check from the roadmap.** Both send paths (`host.rs`, sender and submitting thread) call `heap_twin::sync` before `ExecuteCommandLists`, our list included. Steps of ours that write title memory force that sync (`heap_twin::ours`, `wrote_through`). - **Still refused:** destinations in place (the next twin sync would overwrite a card write, and it would never reach the title's side), and sources over title memory in place. - **Refusal reasons.** Each refusal of a copy in place now names its backing. The reasons go to the release log line "ReBAR pools (DARNER_REBAR_POOLS=1): pool fills with a target left to the CPU by card steps, per frame, by why". One run shows how many of the 350 were twin sources. If most say "its host copy is title memory in place", this switch doesn't reach them. The same argument would cover that backing in a follow-up. - **Why the bytes are right.** - The twin may hold bytes newer than at submission, where the title wrote again since. - It also holds what earlier flights' shaders wrote, which the CPU path never saw. The console reads one memory when the GPU runs, the same argument as for fills out of a pool (`fills_in_pools`). - Risk (`heap_twin` risk 2): a 4 KiB sync can land over bytes a flight in the air writes. The card step then reads whichever write wins. - **Also fixed:** a pool → host-copy copy is not counted as a pool fill. - **Docs.** README row added. The roadmap entry for problem 2 is updated: code done, not run. ## How it was tested - Tested revision: `e562db6` - Commands and results: - `cargo test -p darner-gpu --lib --locked -- host::card_steps::tests::copies_in_place host::card_steps::tests::what_no_host host::card_steps::tests::flight_texture`: 3 passed. One of them is new (`copies_in_place_serve_only_as_twin_sources_when_asked`). - `cargo xtask policy --staged`: 4 files ok. - `cargo clippy -p darner-gpu --all-targets --locked -- -D warnings`: fails with 15 errors, none on a line this change touches (`rebar_pool.rs`, `memprobe_rebar.rs`, `indirect/mesh_bench.rs`, `touch_audit.rs`, `poolcensus/reads.rs`, `draw.rs`, `card_steps.rs:2304`). Not run on the base commit. - Gameplay: not run. - Before and after: not measured. Next step: one run with `DARNER_REBAR_POOLS=1` (and `DARNER_HEAP_TWIN=1`), with the switch on and off. Compare the `read_via_card` round trips, the pool fills taken, and the refusal reasons. Then a picture check. - Coverage gaps: no game run, no full `darner-gpu` suite, CI gates 2 and 3 not run, no diagnostics build. ## Checklist - [ ] This PR contains one change based on `main`. (It's based on `rebar`, as the roadmap asks.) - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none (targets `rebar` at `fae95b1`) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found (Lucid/Darner has no pull requests) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DARNER_REBAR_POOLS=1: the game's large write-combined pool (reserved and
committed at once, 64 MiB to 3 GiB; 2.2 GB at 0xd80400000 in the known build)
lives in card memory the CPU maps (a GPU_UPLOAD heap) at the address Darner
chooses for it, so the game writes where the card reads: no copies, no
write watch, no refresh for it (rebar_pool.rs; xmem, port, shadow, watch,
texture, texback, gpudetile, card_steps, dstorage, pagebuf hooks). Darner's
own CPU reads of the pool go through the card (card steps take pool fills
and title copies into the pool; texture read-backs are retiled by the card
into the pool; pool textures are detiled by the card from it).

Also: CNF-Larp's callable-original entry detours (darner-loader detour.rs)
and its hook table for the known build (darner-game hooks.rs, 165 of 165
sites match the executable, DARNER_HOOKS_CHECK=1), credited in the README
and in each file; the in-place placement index (shadow.rs) that made each
remap walk every placed copy; pool census and read sampling
(DARNER_POOL_CENSUS, DARNER_POOL_READS); probes and benches as ignored tests;
earlier counters and switches (touch audit, submit detail, ask line 2,
prelude send, strides/scratch in card memory, texback cache, ref stats).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The roadmap's open problem 2: about 350 pool fills a frame went through
rebar_pool::read_via_card (about 3 ms of round trips) because the title copy
they were taken along with had a source in place, which holder() refused.

With the switch, holder() lets a copy in place serve as a source when its
placed buffer is in the graphics heap's twin. Pool sources are read through
the pool's whole buffer (Src::Pool) for a title copy whatever its destination.
Twin reads get the all-resources UAV barrier first (aliases of one heap), and
the placed buffer is held until the list has run (a twin copy asks for no
refresh, so the list did not keep it alive). Both send paths sync the twin
before ExecuteCommandLists, our list included. Destinations in place and
sources over title memory in place stay refused. Each refusal of a copy in
place now names its backing on the frame line, so one run shows whether the
350 were the twin.

Not run in the game. cargo test of the three holder tests passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
theforgotten669 changed target branch from main to rebar 2026-12-05 13:39:59 +00:00
The roadmap's open problem 4. A copy into a pool done on the card declares no
write (the pool is the title's memory itself), so nothing held up a later
submission whose fill out of the pool was left to the CPU: read_via_card reads
on a queue of its own, not ordered with the copy. A CPU buffer copy reading or
writing those bytes, or a texture upload reading them, had the same gap.

card_steps::pool_copy_read looks at the pool destinations in flight
(Taken::pool_copied, already tracked) for the steps the card does not take.
The submission then waits for those flights to land: through late_blocked
with no card steps (beside stands aside), or for the steps left over when card
steps took part of it. Counted on the pool copies line. No switch: it only
acts on copies into pools, which exist only with DARNER_REBAR_POOLS=1.

Not run in the game. The darner-gpu card_steps tests pass (36, one new).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The wait added for steps left to the CPU after card steps took part of a
submission now bumps the write-watch settle epoch as the other wait does: the
landings wrote title memory, so an earlier answer must not be reused. The
cut heuristics (free_cut, cut_waiting) are left as they are: each part goes
back through the same prepare-time wait. README row for the switch. Drops the
in-place refusal table test (it restated the match).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The roadmap's open problem 3. The card retiles a texture read-back into the
pool when the list runs; a ticket invalidated after recording (the texture
released, its memory remapped or given to another resource) stopped a CPU
landing but not the card, which wrote old texels over memory that was no
longer the texture's.

The retile now runs under SetPredication on a value in upload memory, a slot
of the upload guard's ring (texture::predicate_slot, factored out of
guard_upload). The ticket keeps the live slots of its landings; invalidation
sets them to skip, and a list that has not reached the retile leaves the
memory alone. Counted on the read-backs line. DARNER_REBAR_BACK_SKIP=0 records
it unpredicated, as before.

texback's ignored card test now records a landing again, invalidates it before
the list runs, and checks the pool kept its bytes: passes, and fails with
DARNER_REBAR_BACK_SKIP=0 (run on an RTX 4090).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The roadmap's open problem 1, the long phase of 100+ ms frames in some ReBAR
runs. The handoff's profile of the relay in that phase (relay-prof-1) had it
97 % busy, 39 % in descriptor::release_dynamic_batch: a lock per slot for
what it keeps, contending with the list threads' keep_ref, and a shard lock
and queue push per retired resource. DARNER_RELAY_LATE_RELEASE only moved
that after the telling, on the same thread.

- host::retire_resources: a batch retired with one look at the counts and
  one hold of a shard's lock (HostHeap::release and release_batch use it).
  Same semantics, fewer lock trips; always on.
- DARNER_RELEASE_ASIDE=1 (off): the relay hands a landed flight's dynamic
  slot ranges to a darner-release thread. Slots are given back no earlier
  than before; ranges name their heap and its identity, so a dropped heap is
  left alone. HostHeap::dynamic, finding no free slot, releases what waits
  aside on its own thread and asks again.

Not run in the game. darner-gpu descriptor tests pass (146).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
HostHeap::dynamic drained the whole release-aside queue through
release_dynamic_batch, which takes SHADER_HEAPS for reading; its callers may
already hold that registry, and a second shared hold with a writer queued can
deadlock. It now takes this heap's ranges out of the queue
(release_aside_take, by the heap's identity) and gives them back through
self.release_batch: no registry lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
First-time contributor

Hi theforgotten669, are you already planning coverage for Taken in pool_copy_read? Would a small game-free extension to your existing test be useful for #1? Using generated ranges and the real ownership map, it would check four cases:

  • An unclaimed overlap waits.
  • An overlap claimed by Taken is skipped when it’s the only overlap.
  • A second, unclaimed overlap in the same list still waits.
  • A claim at the same step index on a different list leaves the overlap waiting.

I’d keep the proposal to those assertions on #1. The ReBAR base in #561 can stay separate.

Hi theforgotten669, are you already planning coverage for `Taken` in `pool_copy_read`? Would a small game-free extension to your existing test be useful for #1? Using generated ranges and the real ownership map, it would check four cases: - An unclaimed overlap waits. - An overlap claimed by `Taken` is skipped when it’s the only overlap. - A second, unclaimed overlap in the same list still waits. - A claim at the same step index on a different list leaves the overlap waiting. I’d keep the proposal to those assertions on #1. The ReBAR base in #561 can stay separate.
Lucid merged commit 48b9f9a610 into rebar 2026-12-05 15:07:36 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
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
Lucid/Darner!1
No description provided.