779eb522b45615ab7a2e96f823502715238e472b
43
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
3a3d31c374 |
RUNTIME 2470: Rebinds: a rebind before the submission of an encoder no rebind encodes again is refused
A rebind between a command buffer's commit and the submission of its last event group, of a buffer an encoder of it named that keeps no log (a compute encoder its unit of command predication reaches past, a loop's laying, a render encoder opened while no buffer over host pages existed), failed that submission EncodedUseRebound: the commit let go of its holds, and nothing encodes the encoder again. The consumer's answer table ends the VM on that kind. Now the rebind is refused instead (EncodedUses), and the command buffer runs over the pages it was encoded over. - State::keep_replays also answers whether an encoder that keeps no log (not one its commit fails, which runs nothing) named a buffer over host pages, by its own commands or by work it left for later not recorded on the GPU alone (State::unlogged_names_a_pin). - Where so, the commit keeps the command buffer's holds (State::held_to_submission) instead of letting them go: Holds::hold_to_submission moves each from Entry::pending to a new Entry::unsubmitted under one lock of `buffers`, so no rebind falls between. They go as the last event group's first batch is submitted (State::first_submission, State::later_group), or at completion; a rebind after that keeps the old pages for the submitted work, as before. - replace and the rebind's first check refuse while `unsubmitted > 0`, counted as their own reason: WorkCounts::rebinds_refused_unsubmitted. - Cost: nothing new for a command buffer whose encoders a rebind encodes again (one pass over its ended encoders' flags at the commit, inside keep_replays). A host-step command buffer keeps holding to completion (steps_hold), unchanged. Deadlock audit, by lock: - Commit: hold_to_submission takes `buffers` under the command buffer's `state` lock: state -> buffers, the order encode_moved's Submitting and the commit's own clear of its holds already take. - Submission: the holds go under the scheduler's lock and `state`, after the `Submitting` guard (`buffers`) was dropped; each Holds' drop takes `buffers` alone: scheduler -> state -> buffers, the order the submission's judging already takes. Never under `buffers` itself. - Completion: moved out of `state` and dropped after its lock, with the submitted holds. - Nothing waits on them: a rebind finds `unsubmitted` and is refused; no wait is added anywhere, so no cycle can form. Tests (lavapipe): rebind_races gains a control (the predicated family committed behind an unsignaled shared-event wait, rebound before the signal: refused, completes over the old page, refused-unsubmitted 1), and the threaded run asserts no command buffer fails EncodedUseRebound. Tests that asserted the old outcome of such a rebind now assert the refusal and a completion over the old pages: pending_rebind, rebind_loop_check's rebind before the laying's submission, tile_rebind_making_wait's unlogged tile pass, and validation's rebind_reach test of a unit's encoder that laid its first step. The validation lane no longer has a test that announces encoded-use-rebound (degrade_notices says so). Docs: rebind.rs module docs (ordering rule, a predicated loop's laying), Buffer::rebind_bytes_no_copy, RebindProblem::EncodedUses, the encoded-use-rebound catalogue entry and its declaration, runtime README; api_signatures blessed. Follow-ups in the same landing: Rebinds: a state's reset takes held_to_submission fresh too; Rebinds: clippy (append, take) in the hold-to-submission moves. Checks (lane rebindsafe2): clippy plain (runtime, validation) 0 at 5bfab2beaa in m3-max-37364; lavapipe runtime tests 356/356 at a0fc57f283 (m3-max-37354: rebind, detach, host_page, host_step, indirect, predication, pending, holds, encoder_fold, deferred_calls), the new control refused with refused-unsubmitted 1 and the threaded run asserting 0 EncodedUseRebound. Validation lavapipe (m3-max-37365), rustdoc and the cfg clippy runs follow on development. |
||
|
|
5acd27cd0d |
RUNTIME 2468: Rebinds: a call of an encoder the runtime cannot encode again never races a rebind
After RUNTIME 2465 a rebind racing an encoder call on another thread is detected and the encoder encoded again; one the runtime cannot encode again (a compute encoder its predication unit reaches past, one that left a GPU-written indirect dispatch to its host step, a render encoder that keeps no log) failed EncodedUseRebound at submission instead, which a consumer's answer table treats as fatal. The protocol: those encoders' calls are gated, so no publish overlaps one. - Rebinds gains `calls` (gated calls under way). A gated call begins (`Holds::begin_call` -> `CallGate::enter`): calls += 1, then reads `open`; where a publish is open it backs off and waits for it to close (`wait_published`), before it reads anything of a buffer over host pages. - A rebind's publish now opens before its replace (`Rebinds::quiet_calls`): open += 1, then reads `calls`; where a call is under way it waits for the calls to end (`drain`/`drained`), up to CALLS_DRAIN (2 ms), and is refused past it (EncodedUses, Unreplaced::Calls), never failing the encoder later. The four accesses are SeqCst (a store-buffering handshake: of a rebind and a call that meet, at least one reads the other's rise), so each gated call reads the buffer wholly before the publish (holding it, which refuses a rebind until its commit) or wholly after its close. Chosen over the registry lock: the call side costs two atomics and takes no lock. - Which encoders: every compute encoder, and a render encoder that opened with no log. A compute encoder can become unreplayable mid-encoding (the call that records predication, a loop's record, an unbalanced record that leaves work out, a later encoder of its unit that lays a loop, a dispatch left to its host step), after earlier calls ran: a gate that started at that transition would leave those earlier calls racing. So the gate covers a compute encoder from its open. Blit encoders always log, and render encoders with a log, stay re-encodable and pay nothing new. A device with no buffer over host pages pays one Relaxed load per gated call (`any`). - Nesting: a thread-local depth, so a call an encoder's call makes of its own public calls (a blit's unlogged calls, a loop's copies) never waits. - WorkCounts: rebinds_refused_calls_in_flight (the retry rate), encoder_calls_held_by_rebind, and encoders_raced_unreplayable (raced encoders committed with no log: each fails EncodedUseRebound; zero now). Deadlock audit, extending 2465's, by lock: - `drain`: taken by a rebind waiting for the calls (no other runtime lock held: rebind_host_pages holds no lock across replace) and by a gated call's end, which holds none of the runtime's at its end. Nothing is taken under it. - `buffers`: `unopen` takes it alone to lower `open` and notify `closed` (so a waiter between its check and its wait cannot miss it); a gated call's back-off waits on `closed` under it, holding at most its render deferral's `lowerer` lock (lowerer -> buffers is the order holds already take). No publish step takes `lowerer`; the rebind's `lower_all` runs before the publish opens. - The rebind's wait for calls is bounded (2 ms), so a gated call under way that waits on a thread held at a gated begin (a render end waiting for its lowering) ends in a refusal, not a deadlock. A gated call waits only as it begins, never under way, and the publish waits for nothing an encoder holds (2465's audit), so every begin's wait ends when the open publishes close. Docs: the Safety text of Buffer::rebind_bytes_no_copy and Heap::rebind_bytes_no_copy, the rebind.rs **Other threads** bullet and RebindProblem::EncodedUses state the new outcome: refused, never failed later, for the gated kinds. api_signatures.tsv gains the three fields. Tests (src/tests/rebind_races.rs): a pause-point control (a predicated dispatch, Unlogged::Predicated, held at its hold while the main thread rebinds: the rebind refused, the command buffer completes over the old page, refused-for-calls 1); the threaded run gains a predicated family and a host-step family (an indirect stage-in region, Unlogged::Segments), and asserts encoders_raced_unreplayable == 0. Follow-up in the same landing (cc0b4592a3): Rebinds: the refusal reason carries no pages (clippy: field never read). Unreplaced::Held and Unreplaced::Calls no longer give the new pages back: replace drops them once the registry's lock went (unopen drops the guard first), as the caller's map_err dropped them before. Also the docs of the encoded-use-rebound notice (degradation.rs, docs/API.md) and the runtime README say which encoders still fail it after a race (a blit or logged render encoder whose commit failed it, or whose encoding again a call that answers otherwise refused) and that gated calls never race. Verified: m3-max-37298 (msi) clippy at ec3cbb49c7 failed on exactly these two fields; the next job checks this commit. Checks (lane rebindsafe2): clippy plain (runtime, all targets, all features) 0 at cc0b4592a3 in m3-max-37302; lavapipe rebind/detach/host-page/host-step/indirect/predication/pending/holds suites with the gated control and the six-family threaded run in m3-max-37299 (ec3cbb49c7, same library code), the gate-off negative control, clippy GPU/CPU-ICD cfgs and rustdoc follow on development. |
||
|
|
372cf95641 |
RUNTIME 2465: Rebinds: an encoder call that races a rebind on another thread is encoded again
rebind_bytes_no_copy (Buffer and Heap) may now run while other threads encode and
commit command buffers that use the buffer or heap. Before, the Safety contract
excluded that; this lifts it.
The windows found:
- W1: an encoder call reads a buffer's pages before it holds the buffer. A
dispatch builds its bind state, a draw its tables, and a blit reads the
VkBuffer for a copy run that records in a later call. A rebind can land
between that read and the hold. The hold then pins the new pages while the
commands name the old ones.
- W2: what lies over the bytes (aliasing images and their views, texel views,
the heap sets' elements) is made over the new pages only after `replace` has
let go of the registry's lock. A hold in that gap pins the new pages over
half-made state.
- W3: the render lowering thread does the same reads, later.
- W4: an encoding again (`replay.rs`) can run under a concurrent rebind of
another thread. This one is a live defect under today's contract: a commit's
rate-map or split re-encode, and one rebind's turn racing another buffer's
rebind.
- W5: a texture made over the bytes during the call stays excluded.
The change: detect, then encode again. Nothing waits on the encode path.
- Each rebind's publish runs from `Rebinds::replace` to a new
`Rebinds::published`. `published` is the close, after `renew_over`. It is
tracked by a per-device count of closed publishes (`published`), a count of
open ones (`open`), and `Entry::publishing` / `Entry::published`.
- Every encoder call loads that count as it begins (`Holds::begin_call`: one
Acquire load of an AtomicU64). The sites: compute and blit `logged`,
`end_encoding`, the five predication calls, render `Lowering::logged`, the
deferral's `at_call_unit`, the replay dispatcher and `open_render`, which
reads the count before it reads the attachments.
- A hold or pin finds the call raced when the entry's publish is open, or
closed after the call began. A raced Taken counts as rebound
(`Submitting::rebound`), so the commit encodes its encoders again before the
first submission (`State::raced_again`), as for a rate-map reset.
- `reencode` loops: when an encoding again itself raced, it waits until no
publish is open (`Rebinds::wait_published`, a condvar on `buffers`) and
encodes again.
- The close marks again the command buffers committed while the publish was
open, so their raced encoders are encoded again over finished state.
- An encoder the runtime cannot encode again whose call raced fails
EncodedUseRebound at its submission. These are the existing list: a compute
encoder its predication unit reaches past, one that left a GPU-written
indirect dispatch to its host step, a blit or render encoder opened while no
buffer over host pages existed, one whose commit fails it, and one with a
call that answers otherwise. A rebind that no encode overlaps changes
nothing for them.
- New WorkCounts::encoders_raced_rebind counts the encoders marked stale this
way.
- `blit_at` holds the buffer before it reads its VkBuffer, because a copy run
records in a later call.
- `replace` refuses a second rebind of a key whose publish is open
(EncodedUses).
What the publish window covers:
- Inside it: `live_buffers.rebound`, the alias leave/hold/place, the image
swaps and parking, the texel views, `forget_stale` and `renew_over`.
- Moved after the close: dropping the read twins (`drop(twins)`), dropping
the old pages (`drop(old)`, which reaches vkDestroyBuffer/vkFreeMemory and
the deallocator), `release_held_back`, `heap_sets::retire` and the
encodings again.
- What a later pin judges against: the old pages' twins and the stand-ins.
- Not covered: the import of the new pages and the images made again over
them before `replace`. These are the rebind's own and are invisible to
other threads until `replace`.
Deadlock audit, by lock:
- `rebinds.buffers`:
- `hold` and `pin` take `buffers`, then the cell's `pages` (`lying`), and
hold nothing across them.
- `replace` takes `buffers` -> `waiting` (`mark_waiting`) and `buffers` ->
`pages` (`cell.replace`).
- `published` takes `buffers` -> `waiting`. `mark_reencode` is an atomic.
- No thread holds `waiting` or `pages` and then takes `buffers`.
- The existing `state` -> `buffers` order (`encode_moved`'s `submitting`)
is unchanged. Neither publish step takes a command buffer's state lock.
- `wait_published`: its callers hold only the command buffer's `reencoding`
turn. These are the commit (after its state and slot locks are gone) and a
rebind's or commit's `reencode`. No publish step takes a `reencoding` lock
or waits for one. A publish waits for nothing: these take no lock an
encoder holds across a hold:
- `live_buffers.inner`;
- `aliases`;
- the image swap and view locks (`Image::swap_in`);
- HostPages `parked`;
- `rebinds.stale`;
- the texel views;
- `heap_sets`: `passing_hold` and `heaps`, whose writes are deferred while
`heaps.holds > 0`, with no wait.
So every wait ends as soon as the open publishes close.
- The test pause points (`rebind::pause`, cfg test) stop at the hold, with
no runtime lock held, and in the publish after `replace` has let go of
`buffers`.
Docs:
- The Safety text of Buffer::rebind_bytes_no_copy and
Heap::rebind_bytes_no_copy states the new contract and outcomes. Still
excluded: another rebind or a detach of the same buffer or heap, a texture
made over its bytes, and a resource placed in the heap, during the call.
- The rebind.rs module docs gain an **Other threads** bullet.
- Also updated: the EncodedUseRebound declaration and its docs/API.md
catalogue entry (the cost text is unchanged), the `renew_over` doc and the
runtime README.
- api_signatures.tsv gains the new field.
Tests (src/tests/rebind_races.rs, device tests):
- A pause-point control at the hold: a dispatch that read the bound buffer
before its hold, with a second buffer keeping the old import. Expected: the
new page's output and one raced encoder.
- A pause-point control in the publish: a dispatch reading a texture over the
buffer.
- A threaded run: four families (a dispatch of a texture over K, a draw with
K as a vertex buffer, a blit copy from K, and a dispatch bound a call
before) against a rebinding thread. Each output must be wholly one page of
those K lay in meanwhile, or EncodedUseRebound.
Hot path: one Acquire load per encoder call (begin_call) plus one compare
under the lock the hold already takes. Per-call numbers follow in the bench
commit or report.
Also folded: the threaded run reports the pages its outputs read and each wrong output's reason
(060e8219f0); and a publish's close counts as a move (buffer::host_cells_settled), so a binding read
during the publish (a texel view for one) is not kept under the post-replace count and reused
by a later encoder that did not race; debug checks (check_reading, compute check_whole,
KeptSpaces::of) hold off where a call may have raced (rebind::call_may_have_raced, debug only)
(0c7a7a5c98).
Verified (lavapipe, msi): m3-max-37154 at 0c7a7a5c98: clippy plain and --cfg m2v_cpu_icd 0;
rebind*, pending_rebind, degradation*, argument_table, live_bind 41 passed; the hold and publish
controls raced 1 and completed; the threaded run (4 threads x 25 command buffers: a dispatch over
a texture over the buffer, a draw with it as vertex buffer 1, a blit from it, a dispatch bound a
call before) read every output wholly from one page, 0 EncodedUseRebound, 63 rebinds made, 1,537
refused (EncodedUses), 5 encoders raced, 11 encoded again. Negative control m3-max-37156 with
Entry::raced forced false: the hold control fails (the dispatch read the pages the buffer left).
|
||
|
|
439b3b7280 |
RUNTIME 2452: Sparse scrubs: a rebind encodes the encoder of a scrub again
A blit or a render pass that writes a sparse texture leaves a scrub of the unmapped tiles it wrote, recorded at its batch's submission (Deferred::SparseScrub). Deferred::resolved_at_its_calls answered false for it, so the commit's steps_hold kept the pages of every buffer over host pages the command buffer used until completion, and a rebind of one before the first submission was refused with Invalid(Rebind(EncodedUses)). Had it not been, the encoder kept no log (Unlogged::Segments), and the submission would have failed EncodedUseRebound. The scrub zeroes tiles of its texture alone, as its batch mapped them, and reads no buffer. So it is now resolved at its calls, and left again by an encoding again: the blit or pass encoded again leaves its own scrub over the same texture, and the first's goes unrun (finish_replay prepares it; splice_replay retains the first's). Unlogged::Segments now names only a GPU-written indirect dispatch's host step. The docs of records_again, finish_replay and splice_replay name the scrub. The test is tests/rebind_sparse_scrub.rs. The texture's left tiles are mapped, then a blit writes the whole texture and fills a no-copy buffer behind a shared-event gate. The buffer is rebound before the signal, and the test asserts: - the command buffer completed with no error; - one encoder was encoded again; - the fill reached the new pages and not the old; - the mapped tiles hold the blit's texels. The control (this commit's deferred.rs reverted) fails at the rebind with Invalid(Rebind(EncodedUses)). Degradation kinds added or removed: none. Verified: m3-max-36396 at 8f4ce875f5 (same tree), clippy -D warnings of the runtime (all targets and features) 0 and rustdoc -D warnings 0. The cfg clippy, the control, the rebind tests, the suites on lavapipe and the sparse conformance replay run after the merge. |
||
|
|
5410cd5cf4 |
RUNTIME 2450: Shadows: a rebind encodes the encoder of a gated copy in again
An encoder that left a shadow's copy in to its batch's submission (Deferred::GatedCopyIn: over host pages a consumer logs, the regions its log decides; or a command buffer's first copy in of a shadow that may stand across command buffers) kept no log (Unlogged::Segments): no Segment::records_again test held for it. A rebind, before the command buffer's first submission, of a buffer over host pages that encoder used then failed the command buffer with EncodedUseRebound, where Metal resolves the use at the submission. Keeping the log alone would not do: the encoding again redoes the copy in for itself (a gate of the log taken again, a standing decided at the submission, ended_encoders_wrote answering false while replaying) and leaves a GatedCopyIn of its own, or records the copy in in place, but finish_replay asked every other segment to record on the GPU alone, which a gated copy in does not, and refused the encoding again. Now Deferred::left_again_by_an_encoding_again answers for GatedCopyIn too: the encoder keeps its log, its place takes the encoding again (splice_fits), finish_replay prepares the encoding again's segment as the commit prepares one (no recording, StepInputs::None), and the batch's submission records it (submit.rs's record_scrubs, which takes every unrecorded such segment). The first's goes unrun, retained. A gated copy in made by the encoding again holds a gate of the log made after the commit's decisions (DirtyShadows::committed), whose decision is none, so it copies every region (CopyInGate::regions): a superset of the rows the log reports changed, read at the submission, after every CPU write before the commit; the shadow's hold was advanced to the commit's stamp by the first gate's decision, and its image then holds at least that. Its cost, one whole copy in, falls only on a rebind of such an encoder. A standing gate is decided at the submission (stands), as the first's would be. GPU parts are unchanged: a gated copy in starts none. Unlogged::Segments now names a GPU-written indirect dispatch's host step and a scrub. Docs: deferred.rs, rebound_use.rs, encoder.rs, reencode.rs, shadow.rs (GatedCopyIn). Test: dirty_pages_device's a_rebind_before_the_first_submission_encodes_a_gated_copy_in_s_encoder_again: a kernel inverts a shadowed RGBA8 texture over a logged no-copy buffer into a plain texture, behind a shared event only the host signals; the buffer is detached and rebound over other pages, logged by the same log, before the signal. Asserts the command buffer completes with no error, the rebind encoded the encoder once, one gated copy in ran (the encoding again's) and copied every row (dirty_copies_in_gated +1, dirty_copies_in_whole +1), and the kernel read the new pages' texels. At development's files it is expected to fail on the error (EncodedUseRebound). Degradation kinds added or removed: none. Verified: m3-max-36334 at a7b5d28822 (same tree), clippy -D warnings of the runtime (all targets and features) 0. Rustdoc, the cfg clippy, both controls, the rebind tests and the touched suites run after the merge. |
||
|
|
dcac15a5c6 |
RUNTIME 2449: Host RAM: a rebind encodes the encoder of a gather staged past the imports again
An encoder that left a gather from a guest RAM staged through the CPU kept no log (Unlogged::Segments) where an encoding again could not copy the gather through the imports in its place: over a chunk that takes no import while it runs (Staging::cpu_only: a chunk the device refuses, or one an object's own import of its pages holds back), or in a part of its own after the GPU completed the work before it (Staging::after_the_gpu: a copy into those chunks was recorded, or a buffer over host pages lies over the bytes), which a copy through the imports would not start. A rebind, before the command buffer's first submission, of a buffer over host pages that encoder used then failed the command buffer with EncodedUseRebound, where Metal runs it over the new pages. Now such a gather is staged again as its first encoding staged it, as RUNTIME 2448 does for a staged scatter: HostRamCall::staged_again answers the first encoding's Staging for a gather that is not Staging::through_imports (StagedGather::encoded_again_through_imports), and Deferred::left_again_by_an_encoding_again answers for such a GatherStage, so the encoder keeps its log, its place takes the encoding again, and finish_replay leaves the step for its host step. Every other staged gather is copied through the imports by an encoding again, as before (Deferred::recorded_by_an_encoding_again). Unlogged::Segments now names a GPU-written indirect dispatch's host step, a scrub, and a shadow's copy in left to its batch's submission (shadow::GatedCopyIn, which no Segment::records_again test holds either; the doc did not name it). Docs: host_ram/copy.rs (First touch, the gather; Staging; StagedGather), deferred.rs, encoder.rs, reencode.rs, rebound_use.rs, and docs/HOWTO.md's two sentences on a gather's rebind. Test: host_ram_copy_device's a_rebind_before_the_first_submission_encodes_a_gather_staged_after_the_gpu_again, on the shape of a_first_gather_over_chunks_a_scatter_wrote_waits_for_no_import (each chunk import held in flight 300 ms by making_pause): one encoder scatters into scattered pages, gathers them back (staged after the GPU, the scatter having written the chunks) and fills a no-copy buffer, behind a shared event; the buffer is detached and rebound before the signal. Asserts the command buffer completes with no error, the first encoding staged both copies, the rebind encoded the encoder once and staged both again, the fill is in the new pages alone, the RAM's runs hold the scatter's bytes, and the gather's buffer holds them too. At RUNTIME 2448's files it is expected to fail on the error (EncodedUseRebound): the gather's step keeps the encoder from keeping its log. Degradation kinds added or removed: none. Verified: m3-max-36303 at 75b7873bc2 (same tree), clippy -D warnings of the runtime (all targets and features) 0 and rustdoc -D warnings 0. The cfg clippy, the lavapipe control at the old files, the staged rebind tests and the touched suites run after the merge. |
||
|
|
ce22739364 |
RUNTIME 2448: Host RAM: a rebind encodes a staged scatter's encoder again, staging it again
An encoder that left a scatter into a guest RAM staged through the CPU (Deferred::ScatterStage and ScatterDrain, host_ram/copy.rs) kept no log (Unlogged::Segments): no Segment::records_again test held for those steps. A rebind, before the command buffer's first submission, of a buffer over host pages that encoder used then failed the command buffer with EncodedUseRebound, where Metal resolves the use at the submission and runs it over the new pages. Keeping the log alone would not do: an encoding again took no chunk (takes() is empty there, and so is the kept plan's) and copied the scatter through the imports, which starts no part, while the staged scatter's CPU copy goes in a part of its own; splice_fits refuses an encoding again with fewer parts. And a scatter staged because a chunk takes no import while it runs (CopyTake::CpuOnly) cannot go through the imports at all. Now the call records how its first encoding staged it (HostRamCall::staged, set where the staging is decided), and an encoding again stages a scatter so marked again (HostRamCall::staged_again): no kept plan, no imports, record_staged_scatter from where the buffer lies then, its two steps and its part as the first's. It is the first encoding's own decision made again. Deferred::left_again_by_an_encoding_again answers for ScatterStage and ScatterDrain too, so such an encoder keeps its log (Segment::records_again), its place takes the encoding again (reencode.rs's splice_fits), and finish_replay leaves the two steps for their host steps as the commit left the first's. The first encoding's steps are retained unrun, as a replaced splice's are; the stage takes its arena region only at its step, so the unrun one takes none. Every other copy in an encoding again goes through the imports as before. Unlogged::Segments now names a GPU-written indirect dispatch's host step, a staged gather over a chunk that takes no import or in a part of its own, and a scrub. Docs: host_ram/copy.rs (First touch, the scatter; takes), deferred.rs, encoder.rs, reencode.rs, rebound_use.rs, and docs/HOWTO.md's sentence that such a rebind failed EncodedUseRebound. Test: host_ram_copy_device's a_rebind_before_the_first_submission_encodes_a_staged_scatter_s_encoder_again, on the shape of the staged gather's: a blit encoder scatters into scattered pages (a page named twice) and fills a no-copy buffer, behind a shared event; the buffer is detached and rebound before the signal. Asserts the command buffer completes with no error, the first encoding staged the scatter, the rebind encoded the encoder once and staged the scatter again, the fill is in the new pages alone, the RAM's runs hold the scatter's bytes (the later's for the page named twice), and the page beside them is unchanged. At development's files it fails on the error (EncodedUseRebound). Degradation kinds added or removed: none (EncodedUseRebound stays, for fewer encoders). Verified: m3-max-36269 at ebf9c7563f, clippy -D warnings of the runtime (all targets and features) 0. Rustdoc, the cfg clippy, the lavapipe control at the old files, the new test and the touched suites run after the merge. |
||
|
|
918a5e59fb |
RUNTIME 2435: Shadows: a rebind encodes an encoder with a host merge or splice again
What: an encoder that left a splice's or a merge on the host's CPU part
(Deferred::ShadowSplice) now keeps its log, and a rebind's encoding again replaces
that segment with the one it leaves itself over the new pages
(Deferred::left_again_by_an_encoding_again, in Segment::records_again and
reencode.rs's splice_fits). The first segment is retained unrun, as a replaced
pending dispatch's is. A rebind keeps the bytes' offset in their page, so the
copies back cut alike and the encoding again's parts match the first's.
This covers ShadowSplice only, not a staged scatter (Deferred::ScatterStage and
ScatterDrain, host_ram/copy.rs). An encoder that left a staged scatter still keeps
no log (Unlogged::Segments), so a rebind of its buffer fails the command buffer
with EncodedUseRebound as before. Whether a scatter's encoding again over the new
pages leaves segments of the same parts was not checked: its staging depends on
the chunks and imports the new pages lie in.
Why: after RUNTIME 2433 the rebind was no longer refused, but such an encoder kept
no log (Unlogged::Segments), so its command buffer failed EncodedUseRebound.
PHOENIX job m3-max-35745 at 343f4489d3 (RUNTIME 2433's tree) failed
tests::shadow_runs::passes_merged_on_the_host_are_encoded_again_at_a_rebind
("Error Some(EncodedUseRebound); encoders encoded again 0"), and so did lavapipe
job m3-max-35749. The other five tests that failed at RUNTIME 2432 passed there,
and so did 340 of 341 PHOENIX suite tests and 268 of 269 lavapipe ones.
Verified: cargo fmt only so far; the jobs reported with this tip run the tests.
Degradation kinds added: none.
Verified (fplend): msi m3-max-35769 at 4ac4c366b5 (same tree): clippy 0, clippy --cfg m2v_gpu 0, debug
archive 0. lavapipe 35749 at RUNTIME 2433's tree: 268/269, the one failure the rebind test this
fixes. PHOENIX shadow_runs / merge_scratch and the suites follow.
|
||
|
|
d8666d430f |
RUNTIME 2302: render encoders record into the VkCommandBuffer of the encoders before them
A render encoder took a VkCommandBuffer of its own at every open, so a compute, render and blit step began 2.71 and submitted 4 VkCommandBuffers per step (dispatch_chain renders, lavapipe). A render encoder with a log of its calls now takes part in the encoder fold: - One whose pass records at its end (draws in a secondary) joins the group before it; one whose first instance records inline joins none and may lead a group. - No barrier records inside a pass: a joined render encoder records one barrier from everything of the group's earlier encoders (FoldOrder::everything) at its open, counted in command_barriers. - Color groups, rasterization-rate maps and a depth attachment out of GENERAL take no group; segments, fence updates and Overwrites end the group after the encoder. Logless devices keep one VkCommandBuffer per render encoder. - A folded member's layout moves go before its group's first part (GroupPlaces). - A check splits a group with a render member at its pass's submission (as RUNTIME 2297 does for blits). - A group's order is built as its second encoder joins, not as its first ends. A/B (lavapipe, dispatch_chain, per step, base vs tip): renders 2.71 -> 1.35 VkCommandBuffers begun, 4 -> 2 submitted, GPU 119.5 -> 97.7 us; renders-apart 3.71 -> 1.00, 4 -> about 0, 143.6 -> 94.6 us; passes unchanged in buffers, the encoder's open about 250-480 ns more on the host (the group an inline pass begins), the whole pass within the host's noise. Tests: tests::render_fold (device), tests::held_depth, shadow_runs' rebind expectation (a rebind encodes a group whole). Docs: encoder_fold.rs, API.md, FAST-PATHS known gap and ANV row. Verified (msi, lavapipe): the full runtime suite 2683/2684 at c502efba29, the one failure the race test fixed in ca5042567b; clippy plain and --cfg m2v_cpu_icd, rustdoc, fast_paths 0. Negative control (the explicit order removed, renderfold-negctl): the hazard tests fail on their barrier counts; lavapipe shows no wrong texel because it completes each command as it runs, so the texel proof is a GPU that overlaps work. |
||
|
|
ca5042567b |
encoder_fold: the race test waits for the check's failure to be noted, not for its call
a_check_that_fails_a_submission_before_its_group_is_split_keeps_it_failed let the commit's encodings again go once the check closure signalled from inside its call. The scheduler notes the failure (State::fail_submission, which marks the encoders unrunnable) only after the closure returns, so the encodings again could build their units and splice the blit's in between: the full lavapipe runtime suite at the render fold's tip (m3-max-29520) counted 4 encoded again against 3. The blit still ran nothing there (the failure, noted after the splice, cleared its part), so this is the test's race, not the product's. The test now holds the turn until the command buffer's failure is noted (failure_noted, a test-only reading of State::failure, set under the state lock after the encoders are marked), then lets the encodings again go. Verified (msi lavapipe): encoder_fold 22/22; clippy 0 (--cfg m2v_cpu_icd and plain); control m3-max-29567 (unrunnable marks removed) fails the test (4 vs 3). |
||
|
|
38673ec995 |
RUNTIME 2299: a check that fails a submission before its group is split keeps it failed
A check may run on the scheduler's thread while a commit's encodings again are pending: the scheduler takes the checks of the batches it holds before the first submission, which waits for the encodings, is submitted. With a check split (RUNTIME 2297), a group whose VkCommandBuffer holds commands of two of Metal's submissions is encoded again apart at the commit; where the check failed one of those submissions first, the split's splice put the failed encoders' encodings into parts the failure had cleared, and they ran. Found by the render fold's check test (a render pass between two compute encoders: the pass drew). fail_submission now marks the failed encoders unrunnable, as a rebound or detached submission's are. The commit's split and a rebind's turn encode no unrunnable encoder again, and an encoding again whose encoder became unrunnable meanwhile takes no place while the unit's others take theirs (before, splice_fits refused the whole unit for a rebound one). Test: encoder_fold's a_check_that_fails_a_submission_before_its_group_is_split_keeps_it_failed holds the command buffer's turn of encodings again (a test-only guard) until the check failed the blit's submission, then expects the blit's fill not to have run and the three compute encoders to have. Verified (msi lavapipe): m3-max-29383 at the tip: clippy -D warnings (runtime, all features and targets) 0 under --cfg m2v_cpu_icd and plain; runtime fold/rebind/ reencode/check/commit tests 374/375 (the other: a queue_share idle-budget timing test under load, no check or re-encode, fixed apart); validation submission_checks and failed_commits 16/16. Negative control m3-max-29384 (unrunnable marks removed): the new test fails, the blit re-encoded (4 against 3). |
||
|
|
8c5a1d592a |
RUNTIME 2297: fold groups split at Metal's submissions where a check or a rebind fails one
RUNTIME 2293's blit fold records a blit encoder and the compute encoders around it into one VkCommandBuffer, and those are separate Metal submissions, which a submission check or a rebind's EncodedUseRebound fails one at a time. Pin 90's lavapipe suite failed two tests on it (m3-max-29286 at 2293's parent passes; m3-max-29287 at 2293 fails these two): - submission_checks::a_submission_detached_behind_a_wait_fails_alone: the check failed the blit's submission, whose part holds no VkCommandBuffer, and its fill ran inside the compute encoder's; - rebind_reach::a_unit_s_encoder_that_laid_its_first_step_fails_encoded_use_rebound: the group could not be encoded again whole (the compute encoder laid its unit's first predication step and keeps no log), so the rebind refused the blit too, which Metal runs over the new pages. Now: - Each encoder notes whether a command of its own recorded into the group's shared tail (EncoderCore::in_tail; a group's first encoder always does). With a submission check set, the commit encodes again apart only those tail encoders, where they span more than one Metal submission and each can be re-encoded exactly (log kept, no segment). Otherwise a check failing one of those submissions fails all of them (State::widened), so the tail runs whole or not at all. Encoders whose commands all lie in their own VkCommandBuffers fail with their own submission alone. - A rebind of a group that cannot be encoded again whole splits it where each encoder that cannot lies in a submission the rebind fails anyway (State::split_rebound); the group's other encoders are encoded again apart and run. The FAST-PATHS known gap and API.md's committed-as-failed section say what still differs from Metal: a shared recording that cannot be split fails every submission whose commands it holds, and a rebind is refused where an encoder that cannot be re-encoded sits in a submission that still runs. No application of ours sets a submission check (reims-vgpu does not). New test: submission_checks::a_check_failing_one_submission_a_shared_recording_holds_fails_each_it_holds. Verified (msi lavapipe, --cfg m2v_cpu_icd): m3-max-29331 at the tip: clippy -D warnings (all features and targets, runtime + validation) 0 under m2v_cpu_icd and plain; 402/402 tests (rebind_reach, submission_checks, failed_commits, predication, rebinds, indirect, encoder_fold, command_buffer, fast_paths and pin 90's four). Negative controls on development's runtime sources (m3-max-29315, 29330): rebind_reach, wcdc and the new test fail. |
||
|
|
12cd9c6f79 |
RUNTIME 2293: blit encoders fold into the shared VkCommandBuffer as compute encoders do
A command buffer that mixes compute and blit encoders (the image workloads:
Photo Filter, HDR, RAW) began a VkCommandBuffer for every blit encoder, which
also ended the compute encoders' fold: dispatch_chain's blits shape (200
one-dispatch compute encoders each followed by a blit copy) went to the queue
as 799 VkCommandBuffers in one vkQueueSubmit (542 begun) on lavapipe, against 1
for compute encoders alone. On ANV each begin costs 16-20 us of host time.
A blit encoder now joins the group of encoders its command buffer's tail holds
by the rules compute encoders follow (encoder_fold.rs): same batch, the earlier
member one part with no segment, no fence update and nothing failing, no
command predication yet, the encoder trail off, protection options 0; a
compute encoder joins where the group's compute encoders are of its dispatch
type (Joining::{Compute, Blit}). Blit commands take the per-command FoldOrder
barrier through track(). What differs for blits:
- Blit encoders now always log their calls (replay.rs), as compute encoders
do, so a failure that splits a mixed group encodes its running members
again apart.
- A blit encoder ends a unit of command predication, so a group can hold two
units' compute encoders: an unbalanced record whose left-out work begins
past the group's first encoder (State::left_out_from, set by
leave_out_ended) now splits the group at the commit as a partial failure
does, the shared VkCommandBuffer never submitted. split_failure and the
rebind's encoded_together take one check, State::encodes_again_apart: no
predication, a non-compute encoder, or Predication::alone. A rebind in a
command buffer that used predication now encodes a group again where each
member is alone, where before it refused (EncodedUseRebound).
- An encoder whose part writes an ASTC carrier (its second twin's decode goes
after the part) or notes an Overwrite (judged by its part's summary, which
a group widens) ends its group. A folded blit's Overwrite goes to the
group's first part only where every earlier member is a blit encoder that
named nothing of the texture (Fold::overwrites_join), which is what
first_overwrites decided before folding.
- Spares tests that need one VkCommandBuffer per blit encoder update a fence
in each.
Tests (tests::encoder_fold): a compute/blit/compute chain is one
VkCommandBuffer with every copy and read right; an event signal, a dispatch
type change across a blit, predication, a whole-texture overwrite and an ASTC
carrier write each end a group; failures inside a mixed group run exactly
the encoders they leave; an unbalanced End past a group's first encoder
splits it; a rebind encodes a group again in a predicated command buffer.
Also: dispatch_chain gains the `blits` shape (a blit copy after each one-dispatch compute encoder)
and the `copies` shape (a command buffer of blit encoders only).
Verified (blitfold, msi lavapipe): m3-max-29164 at 5845456c61: clippy (runtime, cfg m2v_cpu_icd,
all targets/features, -D warnings) 0; 185/185 including the encoder_fold tests and
a_rebind_encodes_a_group_again_in_a_command_buffer_of_command_predication (the narrowed refusal:
words right, reencodes_refused 0; REFUSALS.md regenerated, unchanged). A/B m3-max-29165 (own target
dirs, md5 c2157758 base 45fdc3e601 / a2214763 tip, ABAB): VkCommandBuffers begun/submitted per Metal
CB, 200 dispatches: blits 542/799 -> 1/1, copies 271/399 -> 1/1, encoders 1/1 -> 1/1; lavapipe GPU
us a dispatch blits 54.98 -> 37.35, copies 9.25 -> 2.36, encoders unchanged; host thread CPU blits
~-1.1 us a dispatch, copies even (logging ~+300 ns a blit encoder paid back by no new
VkCommandBuffer and a shorter commit). No WorkCounts field or Degradation kind. Negative control,
lint in the other configurations and the suites run after landing.
|
||
|
|
82ef730d1d |
reencode: take the split units whole, as clippy asks
clippy's drain_collect: draining all of split_units into a new Vec of the same type; std::mem::take moves them without a new allocation. |
||
|
|
7af3c4228a |
RUNTIME 2272: a failure inside a group of folded compute encoders fails only the encoders it names
RUNTIME 2268 failed a whole group of compute encoders recorded into one VkCommandBuffer when a failure (commit_failed's From(n) or Set, a fault, a recording failure) named only some of them. Metal runs every encoder the failure leaves, so a From(n) inside a group dropped the work of the encoders before n: a consumer's protection probe (a compute encoder, then one made under protection options it fails From) read the first encoder's words as never written. Now every compute encoder logs its calls (replay.rs), a closed group keeps its members' logs until the commit, and the commit splits a group its failure fails in part (State::split_failure): the members that run are encoded again from their logs, each into VkCommandBuffers of its own, in the commit's call before the scheduler sees the batches (the rebind's encode-again path, held by the same mark); the shared VkCommandBuffer is never submitted and the failed members run nothing. Groups no failure splits give their logs back at the commit. The split also works in a command buffer that used command predication where its encoders are alone. The one remaining difference (docs/API.md section 10, FAST-PATHS known gaps): a group whose predication unit later laid a loop (encode_start_while / encode_start_do_while) or left a record unbalanced still fails whole. pending_rebind's test reaches its no-log case through an If opened by the encoder before (Unlogged::Predicated), since compute encoders now always log; Unlogged::NoCalls's doc and notice text name what logs nothing now. Cost (dchain, 5080 node CPU, dispatch_chain --host 20 --runs 9 --only encoders --dispatches 2300, no host-page buffer, ABAB, ns a dispatch): thread_cpu 3393/3396 -> 3539/3809; commit 113-126 -> 221-223 (logs held until commit; a follow-up gives them back under one lock and keeps them as spares); bind 49-50 -> 96-97 (the log itself, stays). RUNTIME_VERSION 2272: folded groups split at a partial failure. Verified (dchain): lavapipe full runtime suite at c118ca6fb6 (m3-max-28648) 2581 passed, 1 failed (host_ram_copy_device private-bit, the same at |
||
|
|
d166086d92 |
RUNTIME 2270: an encoder's open looks at the encoders ended since the open before, not every earlier one
Every compute and render encoder's open built what it starts with (the shadowed textures its command buffer's ended encoders made resident) from scratch: the command buffer's joined residency, then each ended encoder not joined yet, one shadows_onto each. The joined residency advances only where the command buffer's own work reads it, so a command buffer of n compute encoders walked n(n-1)/2 ended encoders: at Geekbench Fluid's ~2300 one-dispatch encoders a command buffer, the open grew to ~2.9 us a dispatch on lavapipe (866 ns at 6 encoders), and reims's decodeperf profile (M3, MoltenVK) put inherited_residency and shadows_onto at 762 of open_compute's 874 samples. The command buffer now keeps what its next compute and its next render encoder start with, with the number of ended encoders it took in (State::inherits): an open takes in the encoders ended since, each once, in the order they ended, and hands out a copy (a count: the residency's resources are shared until one copy changes). It is let go of where the joined residency or an ended encoder's residency may change: joined_residency (every read that joins, the heaps' textures made since, the first submission, a re-encode) and a re-encode's splice of an encoder's residency. The result is the one the walk made: the joined residency's shadows first, then each ended encoder's onto them in order, usages and stages joined as before. Counted: WorkCounts::ended_residencies_looked_at (an ended encoder's residency looked at for an open's inherited shadows). Tests (tests::joined_residency): 64 encoders with a read of the residency after the 32nd look at 62 residencies (the walk: 992); a shadowed texture made resident for reading, then writing, reaches the next encoder with its usage widened. RUNTIME_VERSION 2270: an encoder open inherits residency incrementally (the same result). Also (compenc): dispatch_chain gains --host (each encoder call and the commit timed on the calling thread, commit_and_submit, per-thread CPU on Linux), --binds 4|tex (four buffers, or the Geekbench compute shape: 2 textures, a sampler, an output buffer and setBytes) and --pages (buffers over host pages). Verified (compenc, msi lavapipe): touched tests 165/165 (m3-max-28544) incl. tests::joined_residency: 64 encoders with a residency read after the 32nd look at 62 ended residencies; a shadowed texture made resident READ then WRITE reaches the next encoder as written. Negative control (drop the slots every open, m3-max-28547): 992 vs 62, fails. Release dispatch_chain --host --only encoders --dispatches 2300 --binds 4, ns a dispatch: open 2862 -> 573, encode 7332 -> 5004, thread CPU 7532 -> 5205 (jobs 28534/28545); ended_residencies_looked_at 1.00 a dispatch. SR-like (6 encoders a CB) unchanged (866 -> 913). Clippy x3 and rustdoc run after landing. Squashed from steelbrain/compenc d0d524b6de..84b304c5e3. |
||
|
|
dd286c7304 |
RUNTIME 2268: record consecutive compute encoders of a command buffer into one VkCommandBuffer
A command buffer of N one-dispatch compute encoders went to the queue as 2N - 1 command buffers (each encoder's primary and a kept barrier command buffer before it). A compute encoder now records on in the tail of the compute encoder before it where nothing needs a boundary: same dispatch type and logging, same batch (no event wait or signal, no host step), the earlier encoder one plain part (no segment, no fence update, nothing failing or faulting), no command predication, encoder trail off, protection options 0. The barrier between the two is recorded per command by the tracker's own rule between two encoders of a batch (encoder_fold::FoldOrder), joined with the encoder's own serial barrier into one vkCmdPipelineBarrier. The folded encoder's uses and fence waits join the group's first part's summary, so the batch's plan orders the group as a whole; its own part keeps its fence updates alone. A rebind encodes a group again whole or not at all; a failure that fails one encoder of a group fails the group (docs/API.md section 10, "A command buffer committed as failed"). Counted: WorkCounts::encoders_folded. FAST-PATHS: the ANV command-buffer row notes folded encoders begin none. Also: the dispatch_chain example (gbkern, dchain): a chain of dependent dispatches by how a command buffer holds them (encoders, serial, raw barrier, raw split), with each shape's first command buffer's counts. RUNTIME_VERSION 2268: compute encoders fold into one VkCommandBuffer. Verified (dchain, at d7e4a9ce51, the same diff before its rebase): - lavapipe (m2v_cpu_icd): 40 tests incl. 8 new tests::encoder_fold (dependent chain, independent encoders take no barrier, dispatch-type change, fence update ends a group, commit_failed inside/at a boundary, rebind re-encodes a group whole). - RTX 5080 (m2v_gpu, b5080): 190 touched-family tests; FOLD-CHAIN folded 23, begun 1, barriers 17, 0 wrong words. - 5080 dispatch_chain, encoders shape, GPU us a dispatch: 1000: 8.41 -> 2.92, 2300: 7.43 -> 2.92 (raw barrier 2.92); vkQueueSubmit per command buffer at 2300: 1007 -> 44.6 us; command buffers submitted 2N -> 2. Owed after landing: the negative control (fold barrier removed reads wrong words), clippy x3, rustdoc, the full lavapipe runtime suite at the rebased tip (m3-max-28507), the 780M and XTX before/after. Squashed from steelbrain/dchain f51ba34c37..2f2000cfbc. |
||
|
|
490db00052 |
Re-encode: the encoder's last part read from the back
Clippy's double_ended_iterator_last on 14854f2473's lint job. |
||
|
|
6014ad370d |
Faces: a logged pass turns, and an encoding again meets the faces as first met
While the device has a buffer over host pages, every render pass logs its calls for a rebind, and a pass with a log, or with an earlier encoder of its command buffer keeping one, turned no texture (Unturned::Pass): under a consumer that keeps host-page buffers alive, no attached read ever took the turn and every one copied in. A logged pass now turns as any other. A rebind's encoding again of the command buffer's encoders meets the faces as their first encodings met them: the encoding again runs with a thread-local context of the command buffer and the encoder's parts (with_faces_as_of); a texture a later pass of the command buffer turned presents the face from before that turn to it (Faces::face), and the turning pass encoded again takes its turn again (Texture::retake_turn: the shadow of the face from before the turn held current, no copy in). Any other pass encoded again turns nothing. TurnPoint drops logs_kept; SwapRecord keeps the face it turned from. The shadow log (METAL2VULKAN_LOG_SHADOWS) also names, once per shadowed texture, at the first draw that binds it after its shadow was made: the slot, whether the function fetches, samples or writes it, and each sampler's min, mag and mip filters (a sampler state's by Metal's names, a constexpr sampler's as the layout bakes it). Tests: the runtime's attached_read_faces gains a lane with a host-page buffer alive (a logged pass turns; a blit and a turning pass behind a shared-event wait, encoded again by a rebind, read the texels from before the turn), against the same lane beside an open command buffer (the copy route); the validation crate's runtime_lane::logged_face_turns runs the same under the layer. Not yet run: dispatched next. |
||
|
|
f10321aad5 |
A pass left for its draws' pipelines takes its encoding again once they are made
A render pass whose draw's VkPipeline was still being made as it was encoded records as a segment
of its encoder once the pipeline is made (render/pending.rs). A rate map's reset after that
making finished, before the command buffer's commit or after it while the command buffer waited,
encoded the pass again from its log, and the splice refused it: the segment in its place was
neither one whose pipelines are still being made nor work recorded on the GPU alone. The pass
then drew by the map it took and the reset announced rate-map-reset-unencoded, where Metal's GPU
draws by the map as reset. The rate-mapped multi-draw route made this common: its vertex variant
is made at a pass's first draw, so the reset lanes failed by timing
(a_reset_shows_in_a_pass_not_yet_submitted and a_reset_shows_in_every_pass_not_yet_submitted on
lavapipe, jobs m3-max-22179 and m3-max-22244).
The splice now also takes the place of a render pass left for its draws' or tile dispatches'
pipelines alone and executing no render commands (Deferred::left_for_pipelines,
DeferredPass::left_for_pipelines), made since or not: the encoding again recorded those draws
where it found their pipelines made, or left a segment of its own where they were still being
made, and what the first recording took stays retained, as for a segment still being made.
Verified, before the fix: a diagnostic on lavapipe (job m3-max-22327) waited a second after the
draw and refused the splice in both cases ("keeps false gpu_alone false ... making false"),
shading the identity's 64 by 64 pixels with the notice; without the wait the pipeline was still
being made and the splice took it. The new lane
a_reset_shows_in_a_pass_whose_pipeline_was_made_after_its_draw waits for the making
(WorkCounts::variant_pipelines_made) and checks the half map's 33 by 33 pixels and no notice.
|
||
|
|
5d2c21b79b |
Runtime: keep the encoding-again take mode; a rebind's segments decide no takes
The before-runs of the GPU-pass rebind leg passed on the pre-fix code (lavapipe, m3-max-16674 with the draw before the execution, m3-max-16689 with it after): the draw read the bytes. A render pass recorded in a segment has its shadowed textures' copies planned by its encoder's own core as the pass ends (render.rs end_pass, shadows::plan), the take among them, and the segment only records them. GPU-alone compute executions (gpu_execute) plan no shadows. The segment cores that plan their own (indirect dispatches, executions recorded from records) are host steps' recordings, which a rebind does not record again. So no segment a rebind records again decides a take, and the encoding again's main core already keeps them (ShadowSync::again). So this puts back shadow.rs's two modes, State::replaying_takes and step_takes, and reencode.rs and encoder.rs as development has them. The shared pool, the give-backs at a splice and Replayed::takes are gone. Kept: the failed-submission give-back (State::give_back_from, never_runs_from, place joining a segment's takes into its encoder's), its docs, the loop gap in FAST-PATHS, and the GPU-pass leg as a regression test, its doc now saying where the take is decided. |
||
|
|
4289823b20 |
Runtime: work recorded again keeps its tiled takes; a batch that fails at its submission gives them back
A tiled texture's copy taken at use is taken by the first use encoded after its mark; a recording that never runs must hand its take on or give it back. Three paths lost it: - A rebind that encodes an encoder again re-recorded the encoder's segments (a render pass recorded on the GPU alone, its shadowed textures' copies in the segment) into cores that asked the mark, which the first recording had cleared: the pass read a copy nothing made. The same held for work on the GPU alone a rebind records again without encoding its encoder again. - A host step whose recording failed, and a vkQueueSubmit that failed, failed the command buffer outside fail_part: the takes of the batch and the later ones were never given back, so the next use read stale levels. How: - shadow.rs: one way to decide. ShadowSync::again (take nothing unmet, note nothing) is gone; every recording in place of others is ShadowSync::over a shared Replaced pool: a use that meets a decision of the replaced recordings keeps its take, any other asks the mark. The cores recorded during one turn share the pool, so each decision is met once, in order. - State::replaced_takes (was step_takes and replaying_takes) holds the pool while a host step, a rebind's encoding again (the first encoding's takes and its segments' recordings' takes, State::takes_of) or a rebind's recording again on the GPU alone records. segment_raw hands it to every core. A spliced encoding again or segment gives back the takes of the first recordings it did not meet (Takes::give_back_unheld); a refused one gives back its own takes the first did not hold. The encoder's record keeps the encoding again's takes. - State::place joins a placed segment's takes into its encoder's record, and CommandBufferShared::never_runs_from (State::give_back_from) gives back the takes of every part from the failed batch on, called beside each of the scheduler's three failed() calls. - docs/FAST-PATHS.md, known gaps: a predicated loop's run again records its work apart as a new recording that asks the mark, so a did_modify_data during the loop is taken mid-loop and the next use after it takes nothing. Keeping the first run's takes (over) would copy in again at every run, so it stays a recorded gap. - docs/API.md and the shadow.rs and reencode.rs module docs say the above. Verified: see the next report (lavapipe before/after, the 780M, lint). |
||
|
|
eddd9112aa |
Runtime: an encoder encoded again takes a tiled texture's copy where its first encoding took it
A tiled texture of more than one level over a buffer is a copy of the bytes taken at use: the first use encoded after its making, a did_modify_data or a level-0 replace_region clears the texture's mark and records the copy in and the later levels. A rebind of a no-copy buffer (or heap) the encoder also named, before its command buffer's first submission, encodes the encoder again and puts that recording in place of the first, which is never submitted. The encoding again found the mark already cleared, recorded no copy, and the texture's levels kept zeros or an older copy for good; a did_modify_data made after the commit was cleared by the encoding again instead of the next use. The decision now belongs to the encoding. ShadowSync notes, in order, what each first use of a copy taken at use decided (shadow::Takes); the ended encoder's record keeps that with its log, and the core an encoding again records into (EncoderCore::replaying, fed by reencode.rs through State::replaying_takes) takes each copy where the use in its place took it, never touching the mark. Its forget gives nothing back to the mark either. Other per-encoding state checked for the same shape: the shadow carry (an encoding again starts with none and copies the truth in, which earlier encoders copied back to as they ended; drops-writes shadows are never carried), gated copy-ins and standings (decided at batch submission, which sees the recording put in place), heap tiled and multisample sample moves (planned per recording, no mark), and segments recorded again on the GPU alone or at a host step (their shadow copies were planned by the encoder, not decided again). None consumes a mark at encoding. Verified at the parent (66b00df138), lavapipe, jobs m3-max-16324/16333: all four tiled_texture_reencode tests fail (levels read zero through the encoding again; the next use after a did_modify_data took nothing). The new CPU unit test in tests/shadow.rs covers the decisions directly. Runs of this commit follow in the report. |
||
|
|
1c14b4b44a |
Staged gathers take their staging at their host step, not on the calling thread
A gather staged through the CPU (
|
||
|
|
48caeeb155 |
DegradeNotice::command_buffer: the command buffer whose work announced a notice
A consumer that makes some notices fatal (reims-vgpu's ReleasedCommandState, PrivateResourceOption, HostDeallocatorDelayed) could not tell which command buffer a notice was about: a ReleasedCommandState announced at a host step on the scheduler's steps thread ended its whole VM. Now every notice carries the ID of the command buffer whose work the runtime was doing on the announcing thread, so the consumer can fail that one command buffer. What changed: - CommandBuffer::object_id: an ObjectId, minted at the command buffer's making from the process-wide count buffers, textures and heaps use. - DegradeNotice::command_buffer: Option<ObjectId>, read at the notice's making from a thread-local scope (degradation::NoticesFor), as `call` reads the call being lowered. The scope is set where the runtime holds the command buffer and does its work: the compute and blit encoders' logged funnels and their other recording calls and ends, the render lowering's at-call funnel, its unit calls, its batches' lowering (on the lowering thread or a drain) and its end, the resource state encoder's calls, encoder openings, the commit (at the call or queued behind a render end), a batch's submission and the storage-form settle that rides on it, host steps, a rebind's encoding again, and GPU-time reads. Nested scopes name the innermost. - None, explicitly, for a recovery of the device (device-recovered), for grouped-completion (several command buffers' batches), and inside the program's code the runtime calls (exit_guard::program, indirect command checks, executed-commands handlers). - A bind's memoized notices, announced again at each later bind under announce_each, are named as that bind's: its command buffer and the call being lowered (the call was the first bind's before; same mechanism). - ObjectId docs, docs/API.md section 9, docs/RUNTIME-PORTING.md; API signatures re-blessed (two records: the field and the method). Tests (runtime crate, device tests): - notice_command_buffers: an ICB execution recorded at a host step announces released-command-state on the steps thread naming the executing command buffer; its commit's host-replayed-indirect-commands, on the program's thread, names it too; private-resource-option of an ICB made between the encoder's calls names none. - deferred_calls: the call-naming test also checks the command buffer under both lowering policies; a new test waits for the lowering thread to announce unsized-points after end_encoding and checks the thread, call and command buffer, and that a device notice between the encoder's calls names none. - vertex_conversion_notices: a memoized bind notice (device-nan-encoding) announced at a second command buffer's draw names that command buffer and its own call index, with bound_notices_made proving the memo was reused. (cherry picked from commit b4c2ba83ea726229f129a405ce6f432b0bdb0127) |
||
|
|
4368a35894 |
Let a linear run's passes name buffers over host pages; a pass a rebind encodes again alone reloads its run
A pass over a linear attachment rendered apart joined no run where its commands named a buffer
over host pages (render.rs's once rule): a rebind of one encodes the pass again alone, and a
linear run had no keep after such a pass. A consumer's setVertexBytes lands in an upload chunk in
its guest RAM, a no-copy buffer over host pages, so every pass of reims's many_passes merged
alone: 706 passes, 706 merges, 705 scratch reuses (11-05).
Measured at development
|
||
|
|
241ee2c0d1 |
Keep and merge a run of passes over one shadowed texture once, not once a pass
What: a render pass whose color is a shadowed texture merged back (its truth a buffer's bytes
another writer may write, such as a no-copy buffer's host pages or a Shared buffer's), loaded and
stored, now joins a run of passes (pass_runs.rs) where it may. The run's first pass copies in (or
takes the carried image) and keeps, as before. Each later pass goes on over the image the pass
before it left (ShadowSync::go_on) and keeps nothing. Each pass leaves its merge to its batch's
submission (Deferred::RunMerge, RunWork::Shadow), and the run's next pass takes it over, so the
merge recorded is the last pass's, compared against the first keep. The run holds the keep's
scratch or kept image (RunHeld::Shadow, its MergeLease) until it ends or the command buffer
commits.
Why: consecutive render passes over one merged-back shadowed texture each copied in, kept and
merged the whole texture. 700 one-rectangle passes over a 1024x1024 BGRA8Unorm texture over host
pages took 1,401 shadow copies and 700 merges.
The rule, structural, with no names: a run ends wherever something other than its own passes
could observe or change the bytes, as in the linear runs' list:
- any encoder between its passes that is not a render encoder;
- a render encoder that names the bytes' buffer or its host range, reaches memory it does not
name, fences, resolves, writes visibility results, records later or renders over a rate map;
- a render encoder with an attachment over those bytes, or whose draws or attachments take a
shadowed texture over them (the run's own texture bound to a draw included);
- a signal, a wait or a host step (a new batch), and the command buffer's end;
- for a shadow, the encoder no longer carrying the image (the carry dropped).
A shadowed color joins only when it is loaded and stored, has no stand-in and no planes, belongs
to a pass of one render pass instance that is not inline and not inside a predicated laying, is
laid out as one image's texels at level 0 and slice 0, and merges back.
Encoded again: unlike a linear attachment's run, a shadowed texture's run may hold passes over
host pages, which a rebind before the first submission encodes again. Such a pass leaves its run
(RunMerge::leave). The merge it took over records after all (given back), and the pass copies in,
keeps and merges for itself. Where a later pass took its merge over, it keeps the run's scratch
again after its own merge (RunMerge::keep_after), so that later pass's run merges what the passes
after it change. Run segments now record again (Segment::records_again) and splice. An encoder
encoded again takes no pooled scratch or kept image (ShadowMerge::new's `lent`). A run's merge is
resolved at its calls (Deferred::resolved_at_its_calls), so it holds no host pages past commit;
before this, a rebind of such a run was refused with Rebind(EncodedUses).
Two more changes. A run's keep that a later pass writes outside merges and keeps every texel next,
and a run's pass that needs texels the copy-in did not hold copies every texel in. A merge in whole
blocks stays in blocks where the keep holds the pass's area (stores_blocks), under the same
read-to-store window that shadow.rs's Stored attachments already state.
Counted with the existing counters: shadow_copies, shadow_texels_kept and
shadow_merge_dispatches_planned fall from one per pass to one per run. docs/FAST-PATHS.md records
the run and its costs.
Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, under maclock and memcap:
- tests::shadow_runs (new, all pass):
- runs_over_host_pages_keep_and_merge_once: 1024x1024 BGRA8Unorm over host pages, rows of 15360
bytes, with blits, foreign render encoders, reads, CPU byte writes, a signal and an aliasing
view between runs. Mid-sequence and final reads match a private texture byte for byte, and
the padding is untouched. Joined: 22 copies, 9 merges. Apart: 112 copies, 54 merges.
- rebound_passes_leave_their_runs: 3 encoders encoded again, 0 refused, bytes equal.
- scissored_runs_keep_again_once_and_merge_in_blocks: keeps at passes [0, 1], all in blocks.
- Runtime suites (shadow, merge_scratch, linear_runs): 69 of 69 passed.
- Validation runtime_lane (shadow, padded, linear): 91 of 91 passed.
- Negative controls, each a sabotaged build, source restored and touched after; each fails:
- go_on off: every pass keeps;
- follows across encoders: keeps [D0, D8, D9, D10, A11, D12];
- leave off: 961,469 bytes differ;
- stores_blocks reverted: every scissored pass keeps.
- Release probe, 700 passes in one command buffer, base a543f6428d against this commit: shadow
copies 3 against 1,401, texels kept 1,048,576 against 734,003,200, merges planned 1 against 700.
Commit to completion, runs 1-3: 31.6-35.3 ms against 69.3-99.9 ms. With a 1x1 render encoder
between every two: 61.6-65.0 ms against 107.4-118.6 ms.
On the RTX 5080 Laptop GPU (NVIDIA 615.71.09), the same probe, runs 1-3: 6.6-10.0 ms against
40.6-43.0 ms, and 9.7-12.3 ms against 44.5-47.1 ms. The same 11 shadow, merge and linear device
tests passed there.
clippy --all-targets --all-features -D warnings passed plain and with --cfg m2v_gpu, and cargo fmt
was run.
(cherry picked from commit bf783428131f46c7289518a50b8505e809ecc8e5)
(cherry picked from commit 99949a4cd08cd042e448484e0b1d2f5da1898db5)
|
||
|
|
2f9a3a3782 |
A command buffer joins its ended encoders' resources where its work reads them, not as each ends
Each compute or render encoder's end joined everything it made resident into its command buffer's
residency (Residency::join_encoder: a clone and a hash insert per resource), and each later
encoder's open walked every texture of that union for the shadowed ones. Most command buffers'
work never reads the union: only the commit's and host steps' recordings against every encoder's
resources (CommandBuffer::residency), the resident set of a GPU-alone recording, a texture made in
a heap since, and an encoder encoded again do.
- command_buffer/mod.rs: an encoder's end joins its heaps at once (join_encoder_heaps) and leaves
its resources in its record; State::joined_residency joins the records not joined yet, in the
order they ended, at the first read (CommandBuffer::residency, make_resident, fresh_ranges, a
splice of an encoder encoded again, before the textures its heaps made since). The union holds
what the eager join made, in the same token order: State::sync_heaps joins the records first
where a heap made textures, as each encoder's join came before them. The commit's sync of its
heaps and an encoder's open (State::inherited) read no resource list unless one did.
- residency.rs: each residency lists its shadowed textures' tokens (shadowed), found where an
open first asks for them (find_shadowed) and each texture looked at once, so making a texture
resident reads nothing of it, and an open starts with the shadowed textures of the joined union
and of the records not joined yet, in the order they were made resident, with the joined usage
and stages, at the cost of their count. The join's resource and heap halves and sync_heaps's
finding and joining halves are split out.
- WorkCounts::resident_resources_joined counts the joins (api_signatures.tsv blessed: one field).
The records hold what their encoders made resident until the command buffer completes, as before,
and the union goes with them, so nothing lives longer or shorter. The same resources, usages,
stages, tokens, shadows and heaps at every read.
Release numbers, M3 Max (host_ab --only encode, runtime side, median of 3 rounds, µs; before is
this landing without this commit, after with it, two or three interleaved runs each):
before (3 runs) after (3 runs)
resident_0 end_call 14.1 11.6 14.9 11.3 14.4 15.1
resident_256 end_call 34.7 25.6 37.3 11.1 13.3 15.4
resident_4096 end_call 230.3 152.3 244.3 11.4 14.1 15.5
resident_moving_4096 end_call 170.5 154.3 248.6 10.7 11.8 15.2
resident_textures_256 end_call 41.5 29.5 43.1 11.2 13.0 15.3
resident_textures_4096 end_call 287.8 193.5 294.6 11.5 12.9 15.8
resident_4096 use_call 346.1 379.3 335.1 326.1 297.3 342.0
resident_textures_256 use_call 38.0 37.0 36.9 35.1 35.1 37.2
resident_textures_4096 use_call 450.3 481.0 430.3 409.5 419.6 438.3
resident_4096 encode/dispatch 1.73 1.32 1.62 1.74 1.65 1.65
resident_textures_4096 encode 2.20 1.78 1.93 1.93 1.99 1.97
static encode/dispatch 1.75 1.74 1.61 1.62 1.64 1.60
The end call no longer grows with what the encoder made resident, and the useResources call does
not take the cost instead. A first form of this change looked for a texture's shadow as it was
made resident; that put about 80 µs into resident_textures_4096's use_call (260 to 317 against
188 to 200 before, four interleaved runs each), which is why the shadowed textures are found
where an open first asks for them. Percall's counts are the same with and without this commit;
the calls workload's end_compute allocates 5 a call where it allocated 8.5.
Checks that fail without it, in tests/joined_residency.rs:
- ended_encoders_join_their_command_buffer_s_residency_where_it_is_read: with the second
encoder's open joining the records (the eager join's timing), its first assert fails (16 joined
where 0).
- shadowed_textures_made_resident_reach_the_next_encoders_in_order: with find_shadowed looking
at none, its first assert fails (no shadowed texture inherited).
Verified: the runtime GPU suite on the M3 (1527 passed, 3 skipped); cargo clippy -p metal2vulkan
-p metal2vulkan-runtime --all-targets --all-features -D warnings, with and without --cfg m2v_gpu;
scripts/api-signatures/signatures.py --check.
(cherry picked from commit 18553c295c98dabe4c74fc226be6b45955c0c13a)
(cherry picked from commit ae56cfdfdd2e4cb1e9b189c7ce303d680fbc2b7f)
|
||
|
|
44d97aaa5e |
Record each command into the driver's command buffer at the call
Recording at the call replaces the deferred replay, with the pipeline-wait test settling the
device's in-place check that recording at the call made fall inside its run.
One work packet, landed as 2 commits on archive/development-linear-2026-10-29, in order:
* Record each command into the driver's command buffer at the call (6c9d1f4551)
An encoder's command buffers are the driver's VkCommandBuffers from the command
buffer's pool, recorded at each call on the program's thread. The deferral is
gone: the per-command log, the deferred handles, the replays and the recorder
thread, the scheduler's wake of it, the host pages' replay holds, and
WorkCounts::{command_buffers_deferred, command_buffers_replayed,
command_buffers_replayed_inline} (removed public fields; none is read by the
consumer). The slots' routed entry points stay as a counting door:
WorkCounts::commands_replayed counts each command at the call, across every
command buffer (the scheduler's barrier buffers and primaries begun ahead
included, so its totals rise: the drag frame's 1000 -> 1094). A shadow's copy in
over dirty-logged host pages becomes a segment its batch's submission records
(Deferred::GatedCopyIn), so its regions are still decided after the commit's
dirty-log stamp. Rebind re-encode (replay.rs, reencode.rs) is unchanged.
RUNTIME_VERSION 1692.
Verified on the Apple M3 Max (MoltenVK): runtime device suite 1392/1393 twice
(pipeline_wait_order's "a batch waiting for a pipeline holds only the batches
that share its resources" fails under suite load only, a known load flake that
now fails more often; 3/3 alone; the base passed 1395/1395 under the same
load); new recorded_at_the_call::a_fill_is_recorded_at_its_call; the three
dirty_pages_device tests through the gated segment; plain runtime 1145/1145;
conformance plain 1007/1007 (its racy-count test now reads wakes_spared and
command_buffers_submitted); clippy plain and --cfg m2v_gpu; rustdoc.
Release A/B on the M3 (5 interleaved pairs, host load 16-43): drag frame
commit-to-handler p50 3.416 -> 3.386 ms back to back, 4.185 -> 3.671 ms paced
at 60 Hz; encode per draw +7.9% back to back, +15.7% paced (the recording moved
onto the program's thread). Not run: the validation plain suite, the
validation lanes edited, lavapipe; conformance's MoltenVK cost records hold
begin/end/barrier bounds from the narrower count and need re-recording.
* Settle the device's in-place check before the pipeline-wait test frees its no-copy buffer (40c79d69e6)
The test's texture over a no-copy buffer starts the device's check of images
over host pages, whose rounds make internal submissions on the
m2v-in-place-check thread. On MoltenVK freed memory waits for every device-own
submission issued before it went (freed_memory.rs), so a check submission in
flight as the test drops the buffer delays its deallocator
(host_deallocators_delayed 1). That wait is the runtime's documented behaviour;
the unrelated batch holds no reference to the buffer (a temporary backtrace on
the device's internal submissions showed every one from the check thread, none
from barrier buffers, primaries begun ahead or gated copy segments). The test
assumed no other device work was in flight, and recording at the call made the
test about 2.5x faster, so the release fell inside the check's run. The test
now calls settle_in_place_checks (a condition-variable wait, no sleep) before
its work.
Verified on the Apple M3 Max (MoltenVK): with three heavy device tests beside
it, 10/10 pass (5/10 without the settle, each "the deallocator waited for the
import"); alone 5/5; the runtime device suite 1393/1393. Also run there, all
passing: the validation lane device tests record at the call edited
(commands_replayed, detach, hidden_depth, clear_reach, rate_mapped_passes,
frame_costs, and the row_copies/frame_costs_plain measurements).
|
||
|
|
a730cf1e96 |
Stop a rebind's re-encoded tile dispatch making or waiting for its pipeline
The steps this packet landed as, in order: - Let a rebind of a pending tile pass's buffer run, and place the pass it leaves - Say in the rebind rule that a pipeline being made does not hold a rebind off - Re-pin the runtime sources at the landing tip Content: the tree of `development` at 7da33c898d, unchanged. |
||
|
|
06be826c2f |
Leave a rebind's re-encoded dispatch its segment instead of waiting for a compile
The steps this packet landed as, in order: - Re-pin the runtime sources at the landing tip Content: the tree of `development` at f1bb798795, unchanged. |
||
|
|
089cc0a9e0 |
Encode a unit of predication's encoders again where each encodes again exactly
The steps this packet landed as, in order: - Bump RUNTIME_VERSION to 1580 and hold `Unit::fresh` to its invariant - Prove the kept refusal from an ungated dispatch, clear of an unrelated defect Content: the tree of `development` at a6ffe90b3e, unchanged. |
||
|
|
8294000cbf |
Encode a predicated compute encoder again at a rebind where it was its unit alone
The steps this packet landed as, in order: - Regenerate docs/REFUSALS.md over the twelfth stack - Pin the runtime sources and bless the golden table over the twelfth stack Content: the tree of `development` at 6ca8b9005a, unchanged. |
||
|
|
87eb8bc3b7 |
Reset and mutable rasterization-rate maps, as Metal's GPU reads them
The steps this packet landed as, in order: - Read a YCbCr texture's 2D-array view as Metal's, and drop packed 4:4:4 writes - Name bfloat attachments in the unreached-tiles notice - Let go of each predicated loop run's sets and uploads once the run completed - Check that a lent descriptor arena takes every set and reuses its reset pools - Bump the semantics, artifact format and runtime versions for the eighth stack - Pin the runtime sources of the eighth stack - Bless the golden hash tables over the eighth stack Content: the tree of `development` at ee0b90d176, unchanged. |
||
|
|
a653c11b49 |
Match Metal's detach timing: per submission, until the handlers ran
Content: the tree of `development` at 281583adb4, unchanged. |
||
|
|
b94953dfa9 |
Resolve GPU-alone work's resident set at the first submission, not by recording it again
Content: the tree of `development` at 3f5472f696, unchanged. |
||
|
|
d218c939a4 |
Encode again at a rebind an encoder whose only host-page use is its end copy back, and its GPU-alone work
Content: the tree of `development` at 3c7d40aea2, unchanged. |
||
|
|
8c96577b40 |
Record GPU-alone work again at a rebind before the first submission
Content: the tree of `development` at adea9e457c, unchanged. |
||
|
|
c9b0d74912 |
Record Vulkan commands off the encoding thread through deferred command buffers the recorder replays
Encoders log their commands into deferred command buffers, and the device's recorder thread replays them into Vulkan once the command buffer is committed, so the encoding thread no longer calls the driver for each command. Every recorded command goes through a slot of its device's; the recorder's queue and the scheduler's inbox are sized for a frame's commits and grow ahead of them on the recorder's thread; a commit's end allocates nothing; a render pass instance's secondary that nothing executes is never replayed. The replays' commands are counted by kind, and the recorder's modules are listed among those that may keep the device's functions. Folds in: - Route every command the runtime records through a slot of its device's - List recorder/mod.rs among the modules that keep the device's functions - List recorder/thunks.rs among the modules that keep the device's functions - Record Vulkan commands off the encoding thread: encoders log into deferred command buffers, the device's recorder thread replays them once committed - Grow the recorder's queue ahead of the commits, on the recorder's thread - Give the scheduler's inbox and the recorder's queue room for a frame's commits from their making - Count the commands the recorder's replays call, by kind - Give a commit's tail log its fold's room when its encoder ends - Never replay a render pass instance's secondary that nothing will execute - Give new replays room to end each deferred command buffer as it is made, so a commit's end allocates nothing Verified by each folded change's own checks; the tree this series ends on is the one verified at the tip on six GPUs, the CPU suites and lint (see the tables commit). |
||
|
|
3bb4722d9f |
Release idle pointer imports where they follow their address, keep deallocator timing Metal's across rebinds and detaches, and cut host-import work
No-copy buffers and host imports now cost the kernel and the encoding thread less, and their deallocators run in the call Metal runs them in, including when a detach races a commit. What changes: - Idle pointer imports. A no-copy buffer's own pointer import is releasable, as its dma-buf import was: while only blits read it and no pending command buffer holds it, the residency thread releases it after its idle window (2 s, doubling at each import again up to 64 s), and the next blit imports it again at the same pointer. Only where the new measured fact DriverFact::PointerImportsFollowTheirAddress holds (ANV 26.2.4 on the Iris Xe; lavapipe 26.0.8 to 26.2.4): there a pointer import reads the pages mapped at its address at each submission, so an import again reads what the kept one would. A refused re-import fails the blit's call, typed. - Deallocator timing. A released import hands its keep-alive and deallocators to the objects a command buffer still holds, so they run as that memory is freed (or parked and announced, as a kept import's). A committed but unsubmitted command buffer holds a blit's import objects weakly, so a rebind or detach before its first submission runs the deallocator in its call, as Metal does. A detach racing a commit on another thread runs the deallocator in one of the two calls: a let-go mark on the pages and the commit's hold count, both sequentially consistent, make each side see the other, and a commit that sees the mark replays its own command buffer at once. The live list re-reads a buffer's pages where a detach moved them meanwhile. HostDeallocatorDelayed is no longer announced for these races. - Fewer kernel queries. A no-copy buffer asks the kernel about its mappings (PROCMAP_QUERY) only where it makes its own import; a rebind onto a live buffer's bytes lies in that buffer's import and asks nothing; /proc/self/maps stays open for the queries (reopened in a forked process). Three blit paths that read the caller's buffer as a read apart now read it as blits, so their imports stay releasable. - Fewer rewrites and lookups. A rebind or detach rewrites only the heap slots of textures over the bytes it moved; host-page alias lookups visit only the length classes that hold ranges and keep each range's overlapping ranges; a binding and a descriptor each read where a no-copy buffer lies once. - Counters (WorkCounts): host_imports_used and host_imports_read_apart (with its six reasons), host_imports_kept_for_fds and kept imports by cause (of_heap, rebound, pointer, no_stand_in), heap_slots_rewritten, host_mappings_queried (Linux; 0 elsewhere), host_range_lookups, host_remaps_reported, host_remaps_over_imports, host_imports_remapped, host_pointer_imports_made and _bytes_made, no_copy_lies_read, host_imports_rebound_unlisted, host_rebind_imports_made and _covered. - Docs: docs/HOWTO.md on both kinds of release, the RLIMIT_NOFILE soft limit a program raises itself and the new gauges; a FAST-PATHS known gap that a buffer made before a remap reads the new pages on drivers whose pointer imports follow their address, where Metal keeps the old ones (HostMemory::new's contract forbids such a remap); the rustdoc of host_range_remapped. Why: ANV over i915 lists every VkDeviceMemory in every execbuffer, and a pointer import costs about 0.19 us an execbuffer; the consumer's guest keeps hundreds of no-copy buffers live and uses few in a frame. Its swap thread spent 1.54 ms of kernel time a frame querying mappings of a buffer that joined a live import. And a released import's deallocator unmapped pages under a live userptr, losing the device. Verified: - Iris Xe, a guest-shaped lane of 520 pointer imports and 43 command buffers a frame, the idle ones released: objects per execbuffer 536 -> 51, ioctl 4.24-4.31 -> 0.85-1.09 ms a frame, scheduler CPU 4.96-5.05 -> 1.33-1.74 ms a frame, frame p50 5.27-5.43 -> 2.70-3.11 ms. - The fact, probed outside the runtime on the Iris Xe and through tests::pointer_residency on it and lavapipe: a kept import read the pages a remap put at its address. - The detach race on the Iris Xe and RTX 5080 under the validation layer: without the fix 3 of 3 runs failed (deallocators late or on another thread); with it 12 of 12 runs, 15,360 races, each deallocator in the detach or the commit, never late. - A second no-copy buffer over 2040 scattered mappings: 415-418 us -> 0.3-0.6 us. A rebind with 1024 other live textures: 4766 -> 49 us. Alias lookups: a draw -5.3% instructions on host-page frames (RX 7900 XTX). - Device and unit tests: freed_memory, pointer_residency, host_residency, blit_holds, encoder_holds, host_import_counts, host_aliases (up to 45 passed per run); lanes rebinds, rebind_reach, detach, detach_textures, host_memory, no_copy_heaps, dma_buf_imports, draw_work (74 passed on lavapipe, 30 on the Iris Xe for the deallocator fixes). clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc. |
||
|
|
2423b8de61 |
Keep the Iris Xe's depth fast: DontCare stores, sampled usage for hierarchical depth, multisampled depth held out of GENERAL
Three measured cost facts for ANV (Mesa 26.2.4) on the Iris Xe of RPL-P (0xa7a0), each a pure fast
path that keeps every texel and the order of every use: no policy switch, notice or ledger row.
What changes:
- DriverFact::DontCareStoreIsOneOfMetals gains a row for this GPU: an attachment a pass stores
DontCare is Vulkan's DONT_CARE there, as on the UHD 770 and the Radeon 780M.
- New DriverFact::SampledDepthKeepsHiZ. ANV turns off a single-sample depth image's hierarchical
depth and compression in GENERAL (the layout every runtime image rests in) for an image of
transfer-source usage, but keeps its write-through form on for one of sampled usage. Where the
fact holds, a single-sample depth attachment plan the device samples takes SAMPLED too
(image_plan::hiz_candidate), heap textures and the runtime's own depth images included; the heap
size answer comes from the same plan. Memory size and alignment are equal with and without it.
- New DriverFact::MultisampledDepthFasterOutOfGeneral. A multisampled depth image renders very
slowly in GENERAL on this GPU, since the write-through hierarchical depth is single-sample only.
Where the fact holds:
- each render pass instance holds a multisampled depth attachment in
DEPTH_STENCIL_ATTACHMENT_OPTIMAL, moved from GENERAL by a barrier before it and back after
it (the feedback-loop mechanism, generalized to moved images; WorkCounts
depth_attachments_moved);
- the device's own Private multisampled depth texture stays in the attachment layout between
encoders that only render it (texture/held_depth.rs). The scheduler moves it at encoder
boundaries, before any encoder that uses it otherwise, as a tracked write of the whole image so
the hazard tracker orders it against every use on every queue. A pass holds only when nothing
else in its encoder touches the image; a later use breaking a hold fails the encoder's end
with a visible internal error. WorkCounts depth_instances_held and held_depths_released.
- An instance an execution of render commands joins, inline instances and the resolve-after
instance stay in GENERAL. Layout transitions preserve contents unless the old layout is
UNDEFINED (Vulkan, Synchronization, Image Layout Transitions).
- New measurement runtime_lane::depth_costs (ignored by default).
Why: in GENERAL these depth attachments lose the hierarchical depth test, so the depth test
rejects no fragment a block at a time; and moving back to GENERAL after every pass costs a full
hierarchical-depth resolve, about 1.95 ms a pass at 1080p with 4 samples.
Verified, release, on the Iris Xe:
- runtime_lane::dont_care_stores: every texel of its twelve kept cases was the earlier or the
stored one, none other.
- A 1080p heap Depth32Float at 32 layers: 4.72-5.66 -> 0.82-0.87 ms with sampled usage. A 4x
Depth32Float at 32 layers: 12.14 -> 1.44-1.52 ms moved per instance; held between encoders, 1
layer 2.56 -> 0.62 ms and 32 layers 4.35 -> 2.38 ms (GPU clock fixed at 300 MHz). Batches that do
not name the depth showed no CPU difference above noise.
- runtime_lane::msaa_depth_moves 9 of 9 under the validation layer with the counters checked (a
blit between passes, a resolve in its pass, frames, reads after each pass, two queues ordered by
an event, a split pass, an argument-buffer read with useResource, an encoder that also binds its
depth, an indirect-command-buffer execution); the depth, resolve, snapshot, clear-reach,
memoryless and fence-stage lanes passed. On the Radeon 780M and RTX 3090: msaa_depth_moves 9 of
9 with the fact off and every counter 0. Runtime unit filters 134 passed.
- The RTX 3090 measured neutral for both depth facts, and the RX 7900 XTX keeps DontCare as STORE
(not a measured identity), so neither is listed.
- Unaudited: no lane covers a tile dispatch in a held pass.
|
||
|
|
bd21b102f5 |
Cut a draw's and a pass open's allocations
Compare a draw's graphics key in place, keep a drawing state's routing for the pass colors it last met, write descriptors from the stack and allocate the set in place, keep a draw's small lists on the stack, hold what a draw retains by reference in one entry per encoder, find a draw's bind shape among its state's settles, fill push bytes in place, bound coverage without allocating, gather named keys only once a draw reaches the resident set, compare viewport compensations as they come, list argument samplers again only where the device's changed, and keep each pass shape's compatible render pass on the device (up to 64 shapes). The frame-cost lane bounds a draw at 27 allocations and a pass open at 14. Gain: allocations per draw from 67.5 to 24.5 and per pass open from 18 to 13 on RADV, ANV and lavapipe. Frame CPU on ANV (Iris Xe), clean rounds: 5.66 -> 5.02 ms. Verified on the original branch: the runtime lanes, 1313 of 1313 on RADV, ANV and lavapipe. This squashed commit (with the wake fix under it) was not re-tested on its own. |
||
|
|
13b279df1b |
Squash 11203 commits of translator, runtime, and validation work
Rolls up everything since
|