dfda37628d3ad39bde79c2c96abe31320815db33
71
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
dfda37628d |
RUNTIME 2311: ICB records lie in pooled memory where a held pointer import taxes every submission
What: DevicePolicy gains indirect_records (IndirectRecordsPolicy, a runtime
choice no profile carries). Under the default, Untaxed, an indirect command
buffer's records and overflow slots take fresh pages of the runtime's own
(a pointer import held for the buffer's life) only where the device's import
tax check has not found that a held pointer import costs every submission, or
has not answered; where it has (RADV, ANV on i915), they lie in pooled
host-visible memory as the runtime's other buffers do. Under Carried, which
exact_answers() selects, they lie in fresh pages wherever the device imports
host pointers, as before, so a recovery keeps them. A recovery of a taxed
device under the default loses pooled records and rewrites them as a new
buffer's (carry.rs's existing pooled path); the device-recovered notice
already counts such buffers ("N indirect command buffers, M of them whose
records were lost"), as on a device without pointer imports and for
device-local records on discrete GPUs. No new Degradation kind.
Why: on a Radeon 780M (RADV, Mesa 26.2.6, Linux 7.3.3) beside a guest game
whose ICB records were the process's only pointer imports (3 buffers, 19.6 MB),
the submission thread had 5 windows of 65-140 ms in 12 s in which every
amdgpu_cs_ioctl waited in mmu_interval_read_begin or returned EAGAIN (373 of
the run's 382 failed calls, retried at once by libdrm). RADV lists every
imported memory in every CS, amdgpu re-faults every userptr page each CS and
adds the CS fence to every listed BO, so a page migration of one of those
pages (kcompactd, khugepaged, and the runtime's own block making in direct
compaction) waits in amdgpu_hmm_invalidate_gfx for all the process's GPU work
in flight while every submission waits behind it. With no userptr BO listed,
compaction migrates pages without waiting on any fence.
Docs: the FAST-PATHS ledger row (default, switch, the recovery cost, the
measured chain), API.md's device-recovered text, HOWTO's residency section,
fresh_pages.rs, indirect_command_buffer.rs and carry.rs, the conformance
crate's Policy::Exact list. API: signatures blessed, api_surface row,
REFUSALS.md regenerated.
Tests: tests::icb_records_policy (Linux, cpu_icd/gpu): the import tax forced
Holds/Fails; under Untaxed+Holds the records lie in pooled memory, no fresh
pages made, a recovery moves them and its notice counts 1 lost; under
Untaxed+Fails and Carried+Holds in the runtime's own pages, kept, 0 lost. The
translator's fast_paths names the choice, checks it keys no profile and that
exact_answers() takes Carried. icb_carry_race's own-pages cases run on a
Carried device (device_recovery::carried_device), so they assert the carry of
own pages whatever the device's verdict.
RUNTIME_VERSION moves: where records lie and what a recovery keeps change on taxed devices.
New public items: metal2vulkan::device::IndirectRecordsPolicy { Untaxed, Carried } and
DevicePolicy::indirect_records.
Verified, msi m3-max-30127 at cba1ec585a (the fix plus a test-only fix: DevicePolicy is
non-exhaustive, so the tests set the field on a copy):
- clippy -D warnings --all-targets --all-features: metal2vulkan + runtime plain 0, runtime
--cfg m2v_cpu_icd 0;
- translator tests 49/49 (fast_paths with the new choice, its no-profile key and exact_answers
tests, api_surface, api_signatures);
- runtime under cpu_icd on llvmpipe 34/34: icb_records_policy, icb_carry_race, icb_records_home,
indirect_command_buffer*, device_recovery_every_kind, device_recovery_carry.
ICB-RECORDS lines:
- Untaxed with the tax forced Holds: records not in own pages, 0 fresh-page buffers, the
carry moved them, notice "1 of them whose records were lost";
- Untaxed with the tax forced Fails: own pages, 2 fresh-page buffers, kept;
- Carried with the tax forced Holds: own pages, 2, kept.
Workload proof owed: reims's traced loaded-desktop walk on the 780M (per-CS get_user_pages 0, no
-EAGAIN windows).
|
||
|
|
5dd3668a4f |
RUNTIME 2294: indirect command buffer records are placed by first use on discrete GPUs
On a device without unified memory, an indirect command buffer's records lived in host-visible system memory. A kernel writing 8192 records and the render encoder executing them both crossed the PCIe link: on a 3090 behind an x4 link, 17 ms and 26 ms a frame at the link's ceiling, where device memory takes about 0.004 and 0.03 us a command. Now the first use decides where the records live: - a GPU use (an encoder executing, encoding through an argument buffer, or a blit resetting, copying or optimizing it) places them in device memory, written with a header and zeroed flags through the staging queue; - a Shared buffer's first host access moves them to host memory once, while no unfinished command buffer holds them: an empty move when the GPU wrote nothing, else one copy waited for; - a host access while a command buffer holds them, and every host access of a Private buffer, is staged through the staging queue (read back, written back), counted and announced once per device as the new `staged-indirect-records` (performance) degradation. The host never writes device memory. Every encoder use takes a hold that its command buffer drops at completion. Counters: icb_records_moved_to_host, icb_record_bytes_moved, icb_records_staged_accesses. docs/API.md has the catalogue entry; the API table is re-blessed. Tests: src/tests/icb_records_home.rs (GPU-encoded Shared records stay on the device across executions; CPU-encoded move once with no bytes; a getter after a GPU encode moves the bytes; Private records never move; a held buffer stages until its holder completes; a blit reset between GPU encodes keeps them on the device, with a reset-then-execute negative control) and a runtime-lane test for the Private form's notice. Verification: the msi build, clippy and the lavapipe and 5080 runs follow in the next commits' messages. Also: examples draw_reads (the GPU time a draw pays for reading its own data: bytes, a bound buffer, a pointer resolved in the resident set) and icb_reads (an ICB's records' cost on the GPU and host, GPU- and CPU-encoded, Shared and Private). Follow-ups folded in: placing fills only the storage's bytes; a setter's in-place access allocates nothing and its batch carries the access in two words. New Degradation kind: staged-indirect-records (Performance, once per device; docs/API.md catalogue: touch a Shared ICB from the CPU before the GPU uses it, or use Shared rather than Private for CPU access). New WorkCounts: icb_records_moved_to_host, icb_record_bytes_moved, icb_records_staged_accesses. api_signatures.tsv re-blessed; refusal surface unchanged. Verified (arenavram): msi m3-max-29217 at bd9994a6a3: clippy plain (runtime + validation, all targets/features, -D warnings) 0; lavapipe ICB/indirect/degradation/carry tests 65/65. m3-max-29188 at 0980b78c47: clippy plain/m2v_gpu/m2v_cpu_icd 0, rustdoc 0, lavapipe 65 + icb_records_home 6 + catalogue/sites + 30 lane tests, api tables 15/15. 5080 (m3-max-29179) at 87ea86309b: 95/95 incl. the 6 icb_records_home tests (GPU-encoded Shared stays, 0 moves; CPU-encoded moves once, 0 bytes; getter after a GPU write moves with bytes; Private never moves and is staged; held then staged then moved; blit reset between GPU encodes, with a negative control) and runtime_lane::blits::private_indirect_records_follow_the_memory_model. 3090 A/B m3-max-29178 (base 17a0355935 md5 cac5b460 / tip 87ea86309b md5 4322acb2, two alternated rounds, 8192 commands): GPU-encoded Shared encode 0.448 -> 0.0039 us a command, execute 3.03 -> 0.031; link rx about 3-4 GB -> 12 MB a shape run; tip counts moved 0, staged 0. CPU setters on lavapipe: base vs tip within noise at bd9994a6a3 (not separable; not shown zero). The suites run after landing. |
||
|
|
76855fc0ba |
SEMANTICS_VERSION 2106, ARTIFACT_FORMAT_VERSION 522, RUNTIME_VERSION 2256: GPU-written indirect command buffers that inherit the encoder's buffers run on the GPU; write routes reach the indirect command buffers of their own command kind
A GPU-encoded indirect command buffer whose records inherit the encoder's buffers took the host step: the render GPU form refused inherit_buffers (DrawReplayRule::InheritedBuffers) and the compute GPU form had no inherited-bytes path, so every frame read the records back and replayed them on the host (gameload's icb: 8,192 indexed draws, ~44 ms of host step a frame on the Iris against 0.29 ms natively). - Render (da75a4602f..f3745fd69c): a draw replay's variant takes the encoder's vertex and fragment buffers by index as its parent buffers, resolved to device addresses past the parent's record; inline bytes (set*Bytes) are planned at their slots; an unaddressed inherited buffer keeps the host step with its cause named (parent_entries refuses it rather than writing a zero entry). The executor's draw preprocess binds the encoder's vertex buffers. - Compute (7c148c3995..0a68ac5f15): a GPU-written buffer of dispatches that inherits the encoder's kernel buffers runs on the GPU the same way; the new fixture icb_inherited_dispatches (our MSL) and its golden. - Route kinds (2d9f4ac597..2e206952c2): every route of a command buffer joined every indirect command buffer it made resident for writing, so a compute ICB's writer (DISPATCH|RESET) refused the render ICB's GPU form in the same command buffer (DrawReplayRule::Operations): gameload -b's render ICB host-stepped although nothing refused its own shape. A write route now reaches only the ICBs of its command kind (render or compute); CommandWrites carries the kinds (ARTIFACT_FORMAT 522). - host-replayed-indirect-commands is announced once per cause instead of once per device (a660b2fe8d), naming the rule that keeps a pass from the GPU form, as copied-host-pages announces per reason; no new Degradation kind or WorkCounts field. Verified on the branch (steelbrain/icbinherit2 at a660b2fe8d): clippy plain, m2v_gpu and m2v_cpu_icd and rustdoc exit 0 (27886); runtime suite 1538/1539, the one failure the catalogue text RUNTIME 2253 already fixed on development (27884); lavapipe ICB and notice lanes 214/219 with render_inherited_buffers, compute_inherited_buffers, write_routes, written_commands and the beside test (inherited and own buffers: cold (8,8,0), warm (8,8,0,0), pixels as alone) passing, the 5 failures failing the same at the branch's base (27926, 27927); before route kinds the beside test fails as designed, (0,0,8) against (8,8,0) (27764); XTX 90/101 at 60c85035e3 (27853), the 11 failures fixture paths under msi's compile-time path only, all 11 passing on lavapipe (27807). |
||
|
|
cbd2898434 |
RUNTIME 2249: a recovery's carry of pooled ICB records waits out the setters' unlocked writes; getters hold the overflow slots; reset GPU time counted
RUNTIME 2225 and 2242 let an indirect command buffer's setters write without the lock. RUNTIME
2247 put the records in the runtime's own imported pages wherever the device imports host
pointers, so every carry there keeps the pages, the pointer and the records (Kept; the carry's
forget_keys sends the next named set under the lock), and an unlocked write needs no tracking.
Records that still lie in pooled memory (a device without host-pointer import, or a failed
import) move at a recovery (Lost, every command reset), and an unlocked write could hold their
old pointer across the carry's release: a use-after-free.
- Pooled records only: each unlocked setter call counts itself with one read-modify-write
(decided per ICB at creation, counted_write #[cold]); the carry waits the count out before it
releases the old parts. Own-pages records write as before RUNTIME 2247, behind one branch.
- A getter's read of the slots past the records (overflow) holds their parts, as record reads do.
- WorkCounts::indirect_record_reset_gpu_nanos: the GPU time of each resetCommandsInBuffer
dispatch, timed with the rate-map pieces' timestamp slots (a third kind), read when the command
buffer lets go of what it retained; no sync added; 0 where timestamps are absent or wait for
every queue's.
- set_each's setters run inlined in its loop (#[inline(always)] on set_one): the consumer saw the
set passed by pointer read wide after narrow writes (a store-forwarding stall).
- HOWTO: each live ICB's records are one held import.
Verified (carryrace, 13fd624294 on
|
||
|
|
0ee5fb1b9b |
RUNTIME 2247: an indirect command buffer's records lie in the runtime's own pages, so a device recovery keeps them
A device recovery's carry of an indirect command buffer whose records lay in pooled host-visible
memory moved them to new memory and reset every command (a lost device's mapped memory has
undefined contents), where Metal keeps a Shared buffer's records across its GPU's restart. On ANV
(i915), whose held host-pointer imports cost every submission, the runtime's own small buffers
never lay in imported pages, so every ICB took that path. The consumer's test (four senders
setting nil vertex and fragment buffers while the device recovers, Iris Xe) read back a suffix of
a command's sets as 0 in 10/10 runs, at pin 75 and with RUNTIME 2245 alike.
Now the records (Device::records_buffer, FreshPages::Always) and the slots past them lie in fresh
pages of their own at any length, whatever a held import costs, where the device imports host
pointers into the Shared class's best type. The carry imports the same pages again
(Contents::Kept): records and contents pointer as they were, the CPU's and the GPU's writes kept.
Such a buffer is parked and taken again as a pooled one is. Only a device without the import, or
a failed import, keeps the pooled placement and its reset, which the recovery notice counts.
docs/API.md's recovery section says so.
Cost: one held import per live ICB, about 0.35 us a submission on ANV i915 (submit_check.rs's
measured figure), by its pages on RADV; an import at creation 17-43 us where no parked one is
taken (fresh_pages.rs).
Verified (carryrace, 362d920e11 on
|
||
|
|
71e088b900 |
RUNTIME 2245: an ICB setter's write under the lock reads the records' bytes under it
RUNTIME 2242 ( |
||
|
|
20d04dbd5e |
RUNTIME 2242: an ICB's setters write through one batch, mostly without the lock; set_render_command and set_compute_command
An indirect command buffer's CPU setters, after RUNTIME 2238's dense table and one hold: every setter write now goes through one per-command batch (one storage pointer, one count of the writes made without the lock), written into in place rather than handing back a ~180-byte plan (which made a first form slower than before). The written flag (SEMANTICS 2097) is set in the one write helper, write_field, by the rule unchanged: every setter write sets it, a write of the reset record clears it. A draw, a dispatch, a set barrier and a cleared barrier the edits' summary already holds, like a buffer slot before, take no lock where the GPU may not have written the buffer, checked against an atomic mirror of the summary set under the lock; a pipeline state the command already names is set again with no lock and no CallHold (an atomic (id, serial, kind) mirror per command; a recovery's carry forgets it, so the next set redoes every check). New public calls IndirectCommandBuffer::set_render_command / set_compute_command (an index and a list of sets, no handle and no Arc clone; index and kind refusals at place 0) and the handle's set_each; borrowed RenderAt/ComputeAt views. docs/API.md says which setter writes take no lock; the carry docs say a write made without the lock does not wait for a carry (as buffer slots' did; a set racing a device recovery may write through the old mapping). Verified (icbset, f403b6e922 on |
||
|
|
67fb4a7902 |
SEMANTICS 2097 / RUNTIME 2239: an ICB's blit reset writes only the commands written since the last
An indirect command buffer's records live in Shared host memory by design (the host step reads
them on the CPU, and plain Metal lets the CPU write a Private ICB's commands), so a blit's reset
of a whole ICB was a vkCmdFillBuffer over every record across the link: on the consumer's Modern
Rendering sample (45k commands, 101 MB of records) 56.9 ms of GPU time a frame on an RTX 2080
over PCIe x4, against 0.26 ms for the same fill in device-local memory, while the sample writes
~1.3k commands a frame.
Each command now has a u32 written flag in an optional tail after the records (16 +
capacity*2248 + 4*i; CommandBuffer::initialize and decode unchanged). The lowered encode
operations and copy_command store 1 through the contained wide_at (no tail: the sink; a faulting
operation stores nothing); the CPU setters and edit mark it, and a CPU write of the reset record
(reset_with_range) clears it; a blit copy fills the destination's flags with 1. A blit reset is
one dispatch of the new owned kernel bind::icb_reset_module per run of commands, a workgroup a
command that zeroes a flagged record with 8-byte stores and clears its flag; the overflow clear
stays a fill. The carry copies the whole storage, flags included; a lost carry rewrites the header
and zeroes the flags.
Verified (radvcompile, at 273dbba28c on
|
||
|
|
ed9b745d20 |
RUNTIME 2238: an ICB's per-command pipeline states in a dense table, and one hold a pipeline set
An indirect command buffer's CPU setters cost ~290 ns a command in the runtime alone on lavapipe (the consumer's icb_slots_cost at pin 72: 16384 render commands of 5 fields; a Mac does ~5 ns), the largest frames CallHold's drop, the setters' edit, and a BTreeMap<u32, CommandState> insert per command. Two cuts: - The per-command state is a dense table: a u32 a command indexing a small table of distinct CommandStates, each counted by the commands that name it (set_states.rs); a set checks the last state it set, then a map. A recovery's carry walks the distinct states. An entry goes when its count reaches 0, so nothing is held past what the map held. - A render or compute pipeline set took 4 CallHolds (the setter's, program(), can_encode_indirect_commands(), indirect_command_writes()), 8 mutex takes; it now takes one, and a set of a state the table already names reads no program at all. Also: icb_encode_bench gains a full render slot (pipeline + 2 vertex + fragment + draw) and a compute slot (pipeline + 2 kernel buffers + dispatch) a command. Verified (icbset, msi lavapipe release, one A/B job m3-max-26475, binaries alternated, two passes, host load ~20 so passes drift; median ns a command at 16384 commands): full render slot base 232.7/291.6 -> dense 215.7/253.9 -> + one hold 135.2/185.8 (-42%/-36%); compute slot 212.0/263.4 -> 196.8/217.6 -> 116.6/151.5 (-45%/-42%). ICB, released-program, write-route, recovery and kept tests on lavapipe running (26484) at the branch tip. The batched setter (set_each) and the unlocked action/pipeline setters follow after the ICB reset's dirty flags land. RUNTIME_VERSION 2237 -> 2238. |
||
|
|
986f7c3249 |
ICB: edit maps a refused field in place, as on development
Through a shared fn (field_error), the draw's edit was about 1 ns slower
(tests::icb_encode_bench on lavapipe, msi, P-cores): the closure stays in
edit, and field_error serves edit_unlocked alone.
Quiet run (job 25690, load 1.5), dev
|
||
|
|
a3127ef9c7 |
ICB: the unlocked writes counted apart, the locked ones by a load and a store again
The lock-free buffer setters made every write under pipelines count itself by an atomic add (a locked instruction), so the unlocked writes would not lose one; a draw took 45.9 ns a command on development and 49.7 with the lock-free setters (lavapipe, msi, job m3-max-25413). The unlocked writes now add to a counter of their own, the locked ones count as before, and cpu_writes() answers the sum: each part only grows, so a change of either moves it. Verified: cargo fmt; measured next. |
||
|
|
67c98e656c |
ICB: a buffer slot's write takes edit_slot, edit the locked write alone
The unlocked branch at the top of edit slowed the setters that take the lock: on lavapipe (msi, jobs m3-max-25314, 25351, 25384) a draw took 45.8 ns a command on development and 50.4 to 51.9 with the lock-free buffer setters. The buffer's set_buffer now calls edit_slot (unlocked on a buffer the GPU may not have written, else edit), and edit is development's locked write. Verified: cargo fmt; measured next. |
||
|
|
3a7eea4cf5 |
ICB buffer setters write without the buffer's lock
A buffer slot's setter on a buffer the GPU may not have written names no state and adds nothing to what the records may hold, so only the count of the CPU's writes and the kept recordings of its chunk follow it. It now writes the field without pipelines' lock: - the chunk is noted in UnlockedWrites (a flag a chunk and one for any), published before the write is counted; - cpu_writes counts every write by an atomic add (Release), under the lock or not (a load and a store under the lock alone no longer count every write once writers race); - KeptChunks::settle forgets the noted chunks, as a locked write forgets them, at the next look: kept_chunks reads the count before it settles, so every write the count counts is forgotten and one it does not moves the count; keep_chunk keeps nothing of a chunk a note still names. Writes of the same command from two threads at once are the program's race, as on Metal; the SAFETY comments say so. Probe (job 24544, Iris Xe host, icb_encode_bench, earlier base): the lock-free path with every count an atomic add took two buffer setters from 117 to 82 ns a command and three fields from 216/192 to 164 ns. Before/after on this commit follows. Test: kept_commands' a_write_without_the_lock_is_forgotten_at_the_next_settle. |
||
|
|
2c21b3e6f1 |
A recovery carries indirect command buffers, visible function tables and argument encoders; one test over every kind
What: a device's recovery now carries the three kinds a program makes that it left the lost generation's, so each is the same object on the new VkDevice, as Metal keeps its objects: - An indirect command buffer (`indirect_command_buffer/carry.rs`). Its records' storage and its slots past them are buffers of the runtime's own whose `contents` pointer no program holds, carried as such (`Buffer::carry_runtime`): in the runtime's own pages, the same pages and the records as they are; in pooled host-visible memory, new memory, the records lost with the VkDevice (vkspec 5.2.3), written again as a new buffer's: its header, every command reset. The program each command's state runs is the state's program there (made by the state's carry, after it), or a released state's made again there, as are the programs it keeps for GPU-written records (`released_programs.rs`); its kept chunk recordings go; the new generation's keepers list it where the GPU may write it. Its records ID, address, gpuResourceID, uniqueIdentifier and label are the line's and stay. - A visible function table (`function_table/carry.rs`), after its pipeline state: its words buffer carried the same way; where it went to new memory, the words written again from a host copy the table now keeps of what the CPU wrote (`TableShared::writes`), so its entries call what they called; listed among the new generation's tables. A table whose state stays the lost generation's stays with it. - An argument encoder: it holds no Vulkan object, so its device becomes a `LineDevice`, the handle carried; `ArgumentEncoder::device` answers the generation handle by value (it answered a borrow). The registry keeps both buffer kinds weakly (`Carry::indirect_command_buffer`, `Carry::function_table`), the recovery carries them after the pipeline states, and its notice counts them (`", and N indirect command buffers, M of them whose records were lost (every command reset)"`, `", and N visible function tables with their entries"`). The docs of what a recovery carries and leaves say so: `RuntimeGap::MadeBeforeRecovery`, `Degradation::DeviceRecovered`, docs/API.md, the runtime's README, `device/carry.rs`. Why: after a 3090 recovery, `resetCommandsInBuffer:withRange:` on an indirect command buffer made before it was refused (`MadeBeforeRecovery`) thousands of times and every later command buffer of the pass failed, where Metal's buffer goes on. The whole class at once: every kind a program can make, each with its carry status, was listed for the change (none other was left uncarried that holds only what the program could make again; sparse heaps and textures and pooled `Shared` buffers stay left, as documented). Test: `device_recovery_every_kind::every_kind_of_object_made_before_a_recovery_serves_after_it` makes one of each kind (a queue, a `Private` buffer, a heap and a placed buffer, a texture, an event, a shared event, a fence, a sampler state, a depth/stencil state, a library and function, a compute and a drawing state, an address pool, a rasterization rate map, a binary archive, a dynamic library, an indirect command buffer of dispatches executed before and one of draws, an argument encoder, a visible function table called before), recovers, uses each on the next generation by command buffers that complete (the indirect buffers reset by a blit and encoded again, the table called and set, the encoder writing), and ends with the lost VkDevice gone while all live. Helpers made `pub(super)` in the pipelines and states recovery tests. Verified, at the change on |
||
|
|
ae77d1b882 |
ICB setters: cpu_writes counted by a load and a store under the lock; write_field reads the stage-in region and lengths only for an action
reims measured a render ICB's encode at 120-130 ns a command in the runtime alone (a guest's 16384-command commit about 11 ms on the 780M against 0.06-0.1 ms natively). The release bench (tests::icb_encode_bench, the same loop: indirect_render_command_at, a vertex buffer, a fragment buffer, a draw) profiled on the Iris Xe of RPL-P's host (i9-13900H) put 44-48% of the self time in IndirectCommandBuffer::edit, three quarters of it on its three locked instructions: the pipelines lock, cpu_writes' fetch_add and the unlock, each waiting for the setter's stores. - cpu_writes: every writer holds pipelines, so a Relaxed load and a Release store count it, with no locked instruction; it stays an AtomicU64 its readers (indirect_execute.rs, render/executions.rs) load with Acquire without the lock, as before. - CommandRecord::write_field read the stage-in region and the first two threadgroup lengths (the record's tail line) for every field; only an action's checks use them, so they are read there alone. The refusals are unchanged: RecordView::new still validates the record first. Measured once each (least of 20 loops of 16384 commands, ns a command): three fields 150.8 -> 117.7 (median 162.9 -> 120.7), a draw alone 61.7 -> 56.6, a 256-command buffer whose records fit in L2 137.3 -> 113.1; the command alone 11-15 either way. No behaviour changes: what a setter writes, refuses and counts is the same. |
||
|
|
c7362776d0 |
Let carried textures' and pipeline states' parts go at the lost generation's rest
What: a recovery's carried textures and pipeline states let go of their parts on the lost generation once it comes to rest, as buffers already did, so the lost VkDevice goes while they live. - device/carry.rs: LetGo<T>, the let-go cell MadeOn was (MadeOn is now LetGo<Device>), and PartsCalls/CallHold, one guard generalised from the buffer's calls and HeldParts: a call outside command buffers' work counts itself, and a release at rest waits for the last call to end. Buffers use it unchanged in behaviour (Buffer::held_parts, LostBuffer, LostPlaced, LostHost). - Pipeline states: StateShared.program and ProgramLink.program are LetGo cells. The carry hands the lost generation a LostProgram, which drops the state's program there in place at rest (its variants' objects, plans, makings and its Device). reached() skips programs let go of. The state keeps its own copy of its label, so label()'s borrow outlives the program. Holds: the public state methods that reach the program, program(), Debug, and the argument encoder's and indirect commands' set paths. - Textures: TextureShared's per-generation parts (storage, moved, pending_move, usage_shadow(_making), faces, snapshot, kept_backings, render_shadow, facts, planes_in_place) move into Parts in a LetGo cell, read through Deref. The carry hands the lost generation a LostTexture. At rest it leaves the texture's slot in the lost generation's table and heap sets, hands the caller's range token to the parts on the next generation, and drops the parts in place. Parts with a handed-out VkImage (Texture::vk_image) stay until the texture goes. Texture::s() skips parts let go of. Holds: the public texture methods that reach parts, and vk_image; a view's hold holds its root texture too. slot_keeper names a texture buffer's generation by its texel views, not by the buffer's serving generation. - WorkCounts::lost_programs_released and lost_textures_released, counted on the line. - Public signatures: ComputePipelineState::device, RenderPipelineState::device, FunctionHandle::device and VisibleFunctionTable::device now answer an owned Device. The last two also borrowed from the state's program. Command-buffer paths use the crate-private borrowing generation(). api_signatures is blessed. - Docs: the carry module docs (device, pipeline, texture), docs/API.md's recovery entry, the runtime README's recovery paragraph, vk_image's doc. - Tests: the four recovery tests in 99dbc69666 also assert the counters. Why: a carried texture kept its images on the lost generation, and a carried state its program there, until the object went, so the lost VkDevice lived as long as any of them. A long-lived program kept it for good. Verified: cargo check of the workspace, all targets and features, under no cfg, m2v_gpu and m2v_cpu_icd, clean but for one validation call site fixed here (jobs m3-max-23824, 23852). The lavapipe lane (the tests of 99dbc69666 before and after), the suite, lint and the 780M run follow. |
||
|
|
0f400463bf |
Say the device handle is owned, as Metal's device answers a retained one
What: the 14 device() accessors that answer an owned handle say so in their docs, after Metal's retained device; the rest of each doc stands. Why: the docs should name the change a caller sees (an owned Device where a borrow was). Verified: docs only; the lane and lint that follow build them. |
||
|
|
2b8b56617d |
An object a recovery carries answers the caller's own device handle
What: the public device() of every object whose borrow reached a handle a recovery lets go of answers an owned Device, a clone of the generation handle it read: Buffer, Texture, Heap, IndirectCommandBuffer, Event, Fence, SamplerState, Library, Function, DepthStencilState, AddressPool, DynamicLibrary, BinaryArchive and SharedTextureHandle (whose device is its texture's). The runtime's own reads keep a borrow through a crate-private generation() on the types they read it of (Buffer, Texture, Heap, IndirectCommandBuffer, SamplerState, Function, BinaryArchive): 301 call sites, so no hot path pays a clone. Each changed item's doc says the handle is the caller's and keeps its generation, VkDevice included, while held, past a recovery that carries the object on; MadeOn's doc states that no borrow of it reaches the program. The validation lane's four callers that passed the borrow on take a reference of the handle. Signature table re-blessed (14 rows). Why: these accessors answered a borrow into device/carry.rs's MadeOn (a Buffer's or Event's parts, or a LineDevice's GenerationLink), whose let_go drops that Device at the lost generation's rest while the object lives. Safe code that held the borrow across a recovery and that rest read a dropped Device. Metal's device property answers a retained device. The other objects' device() (queues, command buffers, argument encoders, rate maps, pipeline states and their function tables) answer a borrow of a handle the object owns for its life, which no recovery lets go of. Verified: the lane that follows runs tests::device_recovery_handles before (it fails: one live VkDevice while the borrow is held) and after the fix; a workspace check of the accessor change was clean under the plain cfg and found the four validation callers under m2v_gpu and m2v_cpu_icd (job m3-max-23584 on a probe commit). |
||
|
|
6b79a77730 |
A recovery carries drawing and mesh pipeline states
What: a drawing state (a mesh one, and a twin of a color group, a single-sample or a factor-scaling state among them) keeps a chain of programs per generation as a compute state does (pipeline/carry.rs): its StateShared Deref reaches the program of the generation whose command buffer's work the thread does, else the last; its ID, uniqueIdentifier, label and sampler numbers stay. Each state is kept by its generation's carry registry (GraphicsState::kept at the end of a render or mesh creation, with its color groups' twins); the recovery carries them after the compute states (pipeline/render/carry.rs): its base variant, and its large-buffer form's, made again from the pipelines its creation compiled or the live variants of them the new generation holds, no translation; then, under the new generation's reach (NoticesFor::of_generation), its neutrals, its predicted first draw's VkPipeline handed to the pool with nothing waiting for it (make_at_creation(false)), and its depth stand-in copies. Its descriptors, keys, label and twins are kept; its other variants, plans, settles and routings are made as its draws need them. A failed making is counted and refused where bound (RemadeAfterRecoveryFailed) through RenderPipelineState::bound_device, at set_render_pipeline_state (encoder, call checks, indirect command buffer) and an argument encoder's render word; a tile state's bind now answers its kernel's failed making the same way. A state is made again only where both generations compile alike (compiles_alike, the profile fingerprint the memo carry checked already); else its making is refused as failed. Docs: device/carry.rs, pipeline/carry.rs, MadeBeforeRecovery (render states no longer listed refused) and RemadeAfterRecoveryFailed, the DeviceRecovered cost (degradation.rs and API.md, equal), API.md's recovery entry, the runtime README; REFUSALS.md regenerated. Why: drawing states made before a recovery were refused where bound after it; Metal's go on. Verified: see the lane run reported with this sha (the test commit before it fails, this one passes), with the recovery's wall time for 0, 200 compute and 200 drawing states. |
||
|
|
98db2b33e6 |
A recovery carries compute and tile pipeline states
What: a compute state (and so a tile state's kernel) keeps a chain of programs, one per generation (pipeline/carry.rs): the state object, its ID, uniqueIdentifier, label and sampler numbers stay, and its Deref reaches the program of the generation whose command buffer's work the thread does, else the last. Each state is kept by its generation's carry registry; the recovery, after the textures, makes its program again on the new generation: the base variant's objects from the pipeline its creation compiled (Variant::of with the compiled pipeline, or the live variant the new memo already holds), no translation, and the VkPipeline its creation predicted queued on the making pool with no wait (make_predicted with waited false). The lost generation's memo of compiled functions and pipelines is carried first where both generations' profile fingerprints match (PipelineMemo::carry_from), so later variants and creations translate nothing again. A state whose making there fails stays the lost generation's, is counted by the notice and refused where bound with the new RuntimeGap::RemadeAfterRecoveryFailed (compute encoder, argument encoder and indirect command buffer checks, through ComputePipelineState::bound_device). The notice says how many states were made again and how many failed. An indirect command buffer's depth/stencil check now matches the state by its line too, as the encoders' do since the regression fix. Docs: carry.rs, MadeBeforeRecovery, the new gap, the DeviceRecovered cost (degradation.rs and docs/API.md, equal), the runtime README; REFUSALS.md, reach.tsv and the API signature table regenerated. Why: compute and tile states made before a recovery were refused where bound after it; Metal's go on. Verified: see the lane run reported with this sha (the test commit before it fails, this one passes), with the recovery's wall time for 0 and 200 live states. |
||
|
|
a610b58b8a |
A replayed draw whose making outlasts the commit's bound leaves its pass to the host step
The last draw dropped for its making's time: a draw of an execution's replay at commit (render commands the CPU writes) whose pipeline the replay began itself and that was still being made at the command buffer's bound recorded nothing. Metal cannot encode a draw before its pipeline exists, so every encoded draw runs. Now the replay at commit stops there, keeps the making on the command buffer (CommandBuffer::leave_unmade), and the pass takes it into the makings its host step waits for (DeferredPass::left_for_makings): the commit leaves the pass to the host step with its pipelines pending, as it already did for a pass whose settled makings were still being made, and the step records it from the records as they stand then once the making lands. A replay inside a host step waits for its making until made, on the step's thread. record_on_gpu declines to the host step the same way. The commit still returns at its bound at most. Removed: DrawDroppedStillMaking, WorkCounts::draws_dropped_still_making, CommandBuffer::drop_late_draw, RenderLowering::drop_late_replayed_draw, the execution's encoder place that only named the dropped draw, and the open-gap text in FAST-PATHS row 43, API.md (the bullet and the catalogue entry), the runtime README and the PipelineWaitPolicy docs (api_signatures.tsv -2). The IndirectCommandCheck and executed-commands docs name the new case in which an execution read at commit is read and checked again in its host step. The gap's test flips: a_replayed_draw_whose_pipeline_is_still_being_made_at_its_bound_renders_once_made (commit returns after the bound and before the 10 s watchdog; the command buffer is not complete a second past its bound while another queue completes; once the hold goes it completes with the rectangle drawn and nothing dropped). Checked by the lint and lavapipe jobs reported with it. |
||
|
|
f30d2c42a2 |
IcbShared states its Send and Sync, so a handler that keeps its reports builds at the default limit
The validation crate's release build of its tests under --cfg m2v_cpu_icd stopped building on
development (
|
||
|
|
6d9bc9f096 |
RuntimeGap::IndirectRenderCommands names the rule that refused it (IndirectRule)
One gap stood for a dozen rules: an execution of the other encoder kind's commands, a range a draw of the encoder may write, a command's memoryless texture slot, a color in another format, the shader-side depth test, a shadowed texture the call did not gather, residency past the call meeting a shadow's truth, an emulated mesh command's ordering, a memoryless attachment read past the pass, and on an Apple10 device the render states the commands set themselves. A consumer's log said "IndirectRenderCommands" for all of them, so a report could not say which one a program met (a public GPU-culling sample's host step on an RX 550 did not). The variant now carries IndirectRule (public, non-exhaustive, Copy), one value per site, and the error's text prints it: "not implemented in the runtime yet: IndirectRenderCommands(UngatheredShadow)". A family row of indirect render commands names FamilyRow, the summary of the others. No behavior changes: every site refuses where it did, typed as before. Tests that expected the gap now expect its rule: the other encoder kind (render_executions, indirect_command_buffers), a range a draw wrote (render_executions), residency past the call (buffer_texture_renders), mesh ordering (mesh_commands) and the Apple10 states (state_ids, command_render_states, families). docs/REFUSALS.md and api_signatures.tsv regenerated. A consumer that names RuntimeGap::IndirectRenderCommands names a rule now, or matches IndirectRenderCommands(_). |
||
|
|
07a21899ed |
Runtime: contents of a detached no-copy buffer answers the caller's pointer of the pages it lay in last
Metal's contents answers the last pointer across a detach (the caller's pointer of the last replace), and the consumer's host library expects contents unchanged across detach and replace; the runtime answered None. Buffer::contents now answers that pointer while a no-copy buffer, a two-copy Managed buffer (either host copy route) or a no-copy heap's buffer is detached. The runtime itself reads and writes nothing through it: every internal caller takes the new crate-private mapped_contents, which keeps the old answer (None while detached), and buffer::Detached keeps the old mapping's address only to answer contents. Tests: tests::detached_contents (Shared and Managed no-copy buffers, and a no-copy heap's buffer) maps the pages with no access while detached and runs a blit and a synchronize of the buffer; managed_copy_device's detach legs and the validation detach lane assert the pointer. Docs: Buffer::contents, detach.rs, docs/API.md, the runtime README. |
||
|
|
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) |
||
|
|
ab8651ae38 |
Run a device call again on the serving generation where its own was lost under it
tests::device_recovery::each_recovery_announces_its_own_wait failed on the M3
in 10 of 30 runs at
|
||
|
|
ec9706e6e3 |
Survive the loss of the VkDevice: the device is a line of generations
Metal's MTLDevice survives a GPU recovery; the runtime's device refused every call with DeviceLost from the first loss on, and the consumer ends its VM at the first refusal. Now a device the runtime made is a line of generations (device/line.rs), each a DeviceShared over its own VkDevice, and the first call that needs the device after a loss makes a new VkDevice of the same physical device, options, queue families and extensions. - Two kinds of handle. The program's device (and its clones) is a root handle: it holds the line, pins no generation, and every public Device call goes to the generation that serves (each public method forwards to its *_now body). Objects hold generation handles, so their Vulkan calls, drops included, reach their own VkDevice alone. A generation handle's check is one relaxed load of the line's generation (Device::generation_serves). - A draw pays nothing for it. A command buffer takes its generation once, as it is made (CommandBuffer::generation); its encoders' per-draw reaches (work counts, fresh-unwritten and alias records, sampler-slot changes, attachment read notices) read it there, not through a device handle's kind. A bind's device check is one compare of the cells the two handles hold, inlined, its refusal (Device::foreign) out of line. - The state machine (Live, Lost, Failed): the claiming call recovers, every other call waits (a notice past 10 s, waiting on); threads command buffers' completion depends on never wait. Recovery: the lost generation's command buffers in flight fail through its completion path, its queues drain under their locks, create_on makes the next VkDevice, the queues are retired. - Command-buffer answers, as a real loss is one more hang: the oldest incomplete batch's command buffer fails GpuHang (exact on one VkQueue; on two or more the queue whose oldest incomplete batch was submitted first, said so in the notice), counted against its queue so the second revokes it (AccessRevoked); the others GpuRecoveryVictim; one committed on the hang's queue before the recovery runs nothing and completes with no error; one made before and committed after fails GpuRecoveryVictim. One loss names one hang: a batch that went to the driver just before the loss and reached the lost device's completion after the loss took the pending batches fails with it, as a victim (its own wait need not fail: the test hook's VkDevice runs it), and no later failure of the lost device names a second hang. - Command queues survive: a queue is a root handle and a cell of its place on one generation (VkQueue, slots, pools, hangs), which a recovery retires and the next command buffer re-makes; label and GPU-error count go on. - Objects made before a recovery are refused where they meet the new VkDevice or need their lost one: RuntimeGap::MadeBeforeRecovery, at the 38 lost-device checks (Device::lost_refusal) and at every foreign-object check of one line (Device::foreign). DeviceLost stays for a device the consumer made. - Carried across generations: the address space, resource IDs and the passing holds a making waits out before it takes one, unique identifiers, counters and the announced notice kinds. - A device handle is an enum of the two kinds (24 bytes, was 16): the shadow merge's copy-back dispatch, which holds handles, is boxed (clippy's large_enum_variant). - Device::recover_for_test (public, documented) runs the whole path with no GPU fault; RuntimeGap::AdoptedDeviceRecovery on an adopted device. - Degradation::DeviceRecovered (device-recovered), announced at each recovery with the culprit and its time. WorkCounts::vk_devices_live, vk_devices_made, device_recoveries: two VkDevices while objects of the lost one live, one after. Docs: docs/API.md catalogue entry, the runtime README's device-loss section, FAST-PATHS known gap (a make whose own submission first meets the loss is refused DeviceLost), docs/REFUSALS.md regenerated (refusal_surface.py names a forwarded body's sites by its public method), api_signatures blessed. Tests: runtime_lane::device_recovery (hang and victims, command buffers on their way to the driver at a recovery, MadeBeforeRecovery and the VkDevice bound, revocation at the second hang, a command buffer made before fails as victim, all under the validation layer; a recovery that finds nothing of the queue scheduled names no hang, its command buffers victims), tests::device_recovery (the hold of the hang's queue between a loss and the recovery), detach_lost and the MoltenVK lost-device lanes updated to the recovery's answers. Verified: - lavapipe: runtime suite and touched validation tests 1850/1850, surface 19/19 (m3-max-5695, gem10, before the rebase onto |
||
|
|
8e65408e85 |
Resolve the runtime's broken private intra-doc links, and lower its ceiling to 0
CI's private intra-doc link step reported 148 for metal2vulkan-runtime on
macOS and 149 on Linux at
|
||
|
|
40a1558ff6 |
Decode a host step's records in place, through RecordView::record_into
A host step decoded each record (CommandRecord::decode: a record made, then moved out of its Result, its Option and the filter, and into the pair the list holds) and pushed it: about 3 KB moved several times a record, 5001 records a frame on the replayed textured page, where the decodes' and pushes' moves were 37 of the steps thread's _platform_memmove samples in a 6 s window on the M3 at 43114cb72b. RecordView::record_into (new, public) writes a record's every field over a record the caller holds, as `*record = view.record()` leaves it; record() is it over a default record. The runtime's reads (written_records_of, decode_written) push each record's slot first and decode into it (push_written), dropping it to None where it does not decode or the descriptor does not allow it, as before. API table: one line added, RecordView::record_into; nothing removed. Verified (M3, potluck): indirect_commands::tests::records:: a_field_written_alone_is_the_record_encoded_again also writes each of its 20 000 records over the last round's with record_into and finds it equal to decode's; the translator's indirect_commands tests 41/41. Negative control: record_into leaving the imageblock size as the record held it fails it (and 4 other tests that decode through record()). Timing, the replayed textured page, against 43114cb72b, interleaved, two rounds of 3 frames: warm host_step_ms 27.8-29.9 -> 26.0-27.4, encoding to completion 58.4-61.5 -> 56.7-59.3 ms, pixels e3306dc52a1c9e86 at every frame of both. Sampled: the reads' moves 37 -> 10 samples (2069 and 2070). The runtime's suite 1656/1656 and the residency and draw lanes 248/248 with --cfg m2v_gpu; the frame-cost lane passes (19.39 allocations a draw, bound 20; release 7.55, bound 9). clippy -D warnings with --cfg m2v_gpu over the translator, the runtime and validation; api_signatures blessed. (cherry picked from commit b960f51b05a1dac33816b96fd88d04a8565ae02c) |
||
|
|
259615b94d |
Name a host step's render and compute states beside the records it read, in place
A host step read each command's record (a CommandRecord, about 3 KB: its four stages' 32 buffer slots) into a list, named each record's state into a second, then zipped both into a third list of (record, state) pairs; an execution recorded apart flattened that into a fourth, and replay moved each pair out by value. On the replayed textured page (5001 records a frame) those moves were most of the steps thread's _platform_memmove on the M3 (106 samples of 2039 in a 6 s window at 3a4b3e74e2: named_commands' collect 29, replay's moves by value 19, record_kept's flatten 13). The records are now read into the list they are returned in, each beside an unnamed state (WrittenRecords<S>), and step_states / step_render_states name each state in place; record_apart replays the host step's list or the CPU's through one iterator of references, and replay and resolutions take the commands by reference (the state an Arc clone, as the encoder's already was). Verified (M3, potluck): Timing, the replayed textured page on the M3 (5001 draws a frame), this commit with the one before (they were measured together), against 3a4b3e74e2, interleaved, two rounds of 3 frames: warm host_step_ms 33.7-35.3 -> 28.5-30.9, encoding to completion 66.6-70.3 -> 59.6-63.8 ms, peak resident 309-311 -> 289-291 MB, pixels e3306dc52a1c9e86 at every frame of both. Sampled (macOS sample, 6 s, steps thread): _platform_memmove 106 -> 94 samples in a window of 32 frames -> 43 (named_commands' collect 29 -> 0, replay's moves by value 19 -> 0, record_kept's flatten 13 -> 0; the decode's 18 and the reads' pushes 22 stay). The runtime's suite 1656/1656 with --cfg m2v_gpu; the frame-cost lane passes (debug 19.38 allocations a draw, bound 20; release 7.55, bound 9); the residency and draw lanes 247/248, the one other (indirect_executions::...as_its_dispatch_17) stalled past 180 s once and passed in 4.6 s on a rerun of its 64 shards (64/64). clippy -D warnings with --cfg m2v_gpu over the translator, the runtime and validation. (cherry picked from commit 63248dfbbfd5f8b97ea0edce88313dc8260f80f3) |
||
|
|
8fcff2117f |
Put a host step's copy of a chunk's records off where they changed at two steps in a row
On the 5080, a page whose GPU-written records change at every frame (replayed_frames at K=0, 5000 records, CHANGE_EACH) paid about 0.9 ms more a host step than the baseline: base 19.15 ms, the tip 20.05, means of 3 interleaved runs of 22 warm frames each (b5080 entry icb-p-010218). The same tip with the host step's keeping cut off (no comparison, no copy) ran 19.31. perf of the steps thread put the difference in memmove: each step copied every chunk's records, 11 MB, into the copy the next step compares with, 575 KB a chunk, past the caches (h 501 Mcycles of memmove against 416 with no keeping). The comparison itself is a few hundred microseconds less than that and the single read (ff4610cd46) already left one read a record. A host step that records inline now copies a chunk's records only where it needs them (kept_commands::StepCopy, held in each chunk's state beside the bytes it last read): - where the records hold the bytes the last step read, it records from those bytes and copies nothing (ReadFrom::Held); - where they changed since, it copies them again, as before; - where they changed at the step before too, it reads them in place, record by record, as an execution that keeps nothing does (ReadFrom::InPlace, RecordSource::Storage), and copies them at one step in eight only (COPY_EVERY), each chunk at a step of its own among the eight, until a comparison finds them as the step before read them. A CPU write to the chunk, or a recording of it kept or forgotten, starts it over. So records that change at each step are copied for an eighth of their chunks a step, and a chunk whose records stop changing is copied again within eight steps and compared at the next. What a step keeps is unchanged: a chunk is kept only where its records compared equal, byte for byte. WorkCounts::host_step_chunk_copies_put_off counts the chunks read in place. Tests: kept_commands::tests::records_that_change_at_each_step_are_copied_at_one_step_in_eight_a_chunk (the schedule: chunk 0 copied at steps 0, 1, 10, 18, 26, chunk 7 at 0, 1, 3, 11, 19, 27, one chunk in eight a step from step 3, a held comparison and a write start it over). The kept-steps lane's changing case asserts each chunk's copy put off from the records' second change on, each record still read once (indirect_record_bytes_copied), the pixels a fresh page's, and that once the records hold again a step within ten records apart and keeps every chunk, the next running them kept. replayed_frames' split prints host_step_chunk_copies_put_off and indirect_record_bytes_copied. Verified: nothing yet; the M3 clippy, units and lanes, the negative control (always copy) and the 5080 timings follow. (cherry picked from commit cd7b2a7e74f2a6aeef4e8080689bb4bab50c0a2f) |
||
|
|
40e884bd85 |
Box the kept arm of Keeps and read a step's copies as fixed-size records
Clippy (m3-max-586 at ff4610cd46): Keeps::Kept was 784 bytes against 24 for Inline (large_enum_variant), and chunks_exact of a constant length is as_chunks. Behaviour is unchanged. (cherry picked from commit ae5b372e7a66aac5ea762ae4c020abd915e0ee24) |
||
|
|
3ab5303945 |
Have a host step that records inline read its records once, into the copy it keeps
A step whose records change at each frame copied every chunk's records for the next step's comparison (written_bytes_into) and then read each record again to decode it (record_now): 11 MB copied twice a frame on a page of 5000 commands. On the 5080, three interleaved runs at K=0 with records changing every frame stepped 19.6 ms on average against 19.0 ms at 04115e977f, with libc's copy at 13.4% of the steps thread's cycles against 11.2%. steady now hands such a step StepReads, what it reads its records into, chunk by chunk: the bytes the last step read where it has them, else a fresh copy, and a chunk whose kept recording's records hold reads those. The inline recording decodes its records from those copies (IndirectCommandBuffer::written_records_in), and keeps them for the next comparison once it recorded. keeping answers Keeps: kept, or inline with or without reads. WorkCounts::indirect_record_bytes_copied counts the bytes copied out of a buffer's record storage. The kept_steps lane's changing frames now expect each record copied once (DRAWS x COMMAND_BYTES); copying them again besides fails it. Not built or run yet. (cherry picked from commit ff4610cd4660b94835af7841e24114d6ee89fae2) |
||
|
|
347b9870c4 |
Keep a host step's chunks only where two steps read the records alike, and copy the residency once an execution
A host step that compared a kept chunk's records and found them changed recorded every chunk apart again, each into a secondary of its own, to keep: on the replayed-frames page at 5000 resident pairs on the M3 that cost 23.3 ms a step where the records changed at each frame, against 18.3 ms recorded inline (one binary, keeping switched off by a temporary patch). Phase timers put the difference in a copy of the residency per chunk and its drop (2.9 ms over 20 chunks), a fresh 11 MB copy of the records (about 1.1 ms more read), resolutions and contexts. Two changes: - RenderExecution::steady decides before recording. A step keeps chunks only where the records hold, chunk by chunk, the bytes a kept recording was made from or else those the last step read, compared whole. Else the execution records inline, as before keeping, and each chunk's records are copied into the bytes the last step read (IndirectCommandBuffer:: written_bytes_into, no new pages after the first), for the next step's comparison; a recording whose records changed is forgotten and counted recorded again. So records that change at each step cost the step one copy of them beside today's inline recording, and a step records apart and keeps only what two steps read alike. The chunk store keeps those bytes per chunk (KeptChunks::look_up_step, read); a chunk recorded apart keeps them as its recording's bytes, copying nothing again. - The chunks an execution records apart carry the encoder's residency from one to the next with the bind state (replay_encoder takes it owned), so an execution copies the command buffer's residency once, as one recorded inline does. The kept-steps lane now counts chunks recorded apart to keep (WorkCounts::kept_contexts_made): the first frame records inline, the second apart, the third runs kept; a records change records inline, then apart, then kept; another input's change records apart at once; and records that change at each step record inline each frame, keeping nothing, each frame drawing what a fresh page draws. Verified: clippy, plain and under --cfg m2v_gpu, on this Mac. The lanes and the page's timings on the M3 follow. (cherry picked from commit b9b1c0aab9728e57e517cb6f0abdfc1df44e9b03) |
||
|
|
042ec0a481 |
Keep a host step's recordings of GPU-written render commands, compared with the records
A host step of a render execution whose records the GPU may write recorded every command at every step: about 12 to 17 ms for the replayed-frames page's 5000 indexed draws on the M3, every frame, though the page's records are the same bytes each frame. The step now keeps its chunks as commit keeps the CPU's (render/executions/kept.rs, kept_commands.rs): from a chunk's second step on it records the chunk apart into a context of its own and keeps it with a copy of the bytes of its records; a later step runs the kept recording where the records hold those bytes now, compared whole, and its key is equal, and records it again otherwise. No write forgets such a chunk: the comparison decides. The key is everything the recording reads beside the records: the RenderKey commit's chunks use (inherited pipeline state, pass shape and layout, encoder state, scissors, amplification, attachments among the resident resources, the resident set compared whole once a list), plus the inherited tables' buffers by key with offsets and attribute strides (new: commit's chunks need tables that bind nothing), plus KeptChunk::runs_again's checks (each address named resolves as it did, no no-copy buffer moved, nothing detached, everything held alive). The step keeps only where the commands inherit the pipeline state and the inherited tables bind buffers alone; a record barrier makes its chunk not plain instead of ruling the execution out. Its chunks draw in the large-buffer form, as the step's other draws do. The step's round trip stays: the records are known only once the work before them completed. Counters: WorkCounts::host_step_chunks_kept, host_step_chunks_recorded_again, host_step_records_compared and host_step_compare_nanos (api_signatures rows added). The replayed_frames lane prints them and a hash of the target's pixels per frame (a blit copies the target out); the new kept_steps lane changes one input at a time (the records the GPU wrote, the inherited buffer and its offset, the inherited state, the scissor, the resident set, the buffer an index address names at the same address, the inherited no-copy buffer's pages) and checks a re-record, the pixels of a page that kept nothing, and keeping again after. FAST-PATHS' entry on kept recordings states the host step's. Verified: cargo check and clippy -D warnings, all features, plain and --cfg m2v_gpu, for the runtime and validation crates; api_signatures/api_surface 15/15; fast_paths 19/19; the runtime's kept and indirect-command unit tests 32/32. The device tests (kept_steps, replayed_frames, the ICB lane modules) are not run yet. (cherry picked from commit 9b3d13a6d22fba484cce4923fd87ad503f7bc060) |
||
|
|
cc6b083fc2 |
Let what every write route of a command buffer may write reach every buffer it made resident for writing
What: what an indirect command buffer's records may hold (WrittenCommands, command_writes) took a writer's writes only from the encoder that made the buffer resident for writing (Writers: the state set then, each set after, and that encoder's executions). The routes that mark the buffer (write_routes.rs) were already the command buffer's. Routes now keeps what all of its routes may write (states set in any encoder, before the residency or after it, and what executed buffers' records may name) and adds it to every buffer made resident for writing, at the call that brings either; an encoder opens with what the ended ones met. For two encoders open together (a parallel render encoder's) the commit adds what each did not see of the other, and the followers that sets off are marked outside the command buffer's lock, as the commit's marks are. Writers is gone: Routes holds a superset of what it held. Why: Metal runs what a kernel wrote with the buffer resident for writing in any encoder of the command buffer, before the kernel's or after it (the probe icb_routed_writes.m, M3 Max, macOS 27.0.1). The marks matched that; the summary did not, and an execution of a buffer that inherits the encoder's state decides on the summary whether the GPU alone runs it, as draws of the one primitive type it allows. With the residency in another encoder than the kernel's, the GPU alone ran the kernel's point as a draw of the CPU's triangles, which drew nothing (the previous commit's lane). The bug is older than the write routes: the summary was per encoder before them too. What it moves: an execution of a buffer whose command buffer sets, in another encoder than the one that made the buffer resident, a state that may write what the GPU-alone forms rule out: a render execution takes the host step where that state may write more than draws of one primitive type, buffers, resets and cleared barriers; a compute execution in a concurrent encoder orders its commands where it may set a barrier, and a checked one calls its check where the records may name a state that may encode. The lanes that made a buffer writable with a state set in an encoder of its own (indirect_host_steps::encoding_state_set: icb_replay_encode's, which may set pipelines, dispatch, set threadgroup lengths and barriers) showed it: with it, 6 of the 480 tests of the 40 modules changed (render_merged_executions' GPU forms into a shadowed target took the host step, 6 executions; five dispatch_executions tests saw barriers, check calls and a host step), all others as before, resident_draws among them (its writer and residency share an encoder: no host step on its write path, its chunks kept). Those lanes are about the GPU-written path, not about what the state writes, so the lever now sets icb_reset_encode's state (resets alone, which no GPU-alone form rules out). Docs: written_commands.rs and write_routes.rs module docs, IndirectCommandBuffer::command_writes, render/executions/gpu.rs, the runtime README and docs/API.md section 10. How verified (debug, --cfg m2v_gpu, M3 Max under MoltenVK): runtime_lane::write_routes passes (it failed before this commit: After and Before drew no point); the 39 ICB lane modules and write_routes, 480 tests, pass with the reset lever; the runtime's tests::write_routes_device::a_route_reaches_every_buffer_its_command_buffer_made_writable (new: a later encoder's state, one set before the residency, and a parallel encoder's at the commit) and tests::written_commands pass; clippy -D warnings with --cfg m2v_gpu is clean. (cherry picked from commit 7d13a4dee21162a972b40fd9868e3e2f9112a677) (cherry picked from commit 13b9646e48b767defdd189bf156a2a9130b3b857) |
||
|
|
f35128eb43 |
Mark an indirect command buffer at the call that completes a write route, and let the routes go at the commit
The write routes marked a buffer at its command buffer's commit. An execution's segment is cut into a part of its own, which waits for the work before it, as it is encoded (`Segment::host`, from `gpu_written` then), so an execution encoded after the writer in the same command buffer, in its encoder or a later one, was recorded with the writer's part and ran the CPU's records: indirect_host_steps' commands_a_kernel_writes_run_after_it and 19 other lanes drew nothing. The routes now mark at the call that completes the pair: a write use where a state that may encode, or an execution whose records may name one, was met in the command buffer; such a state set, or such an execution encoded, where a write use was. An encoder opens with what its command buffer's ended encoders met (`Routes::carried`), so a later encoder's execution is encoded as one the GPU may write, as it was when a write use marked the buffer at its call. The commit still decides again from what the records name then, and still leaves the followers. The command buffer's routes held each buffer made resident for writing or executed until the command buffer itself dropped, past its completion: a released buffer's range and resource ID stayed taken (indirect_command_buffers' buffer_identifiers_follow_metal_s_encoders, resource_ids' an_indirect_command_buffer_s_id_is_held_as_metal_holds_it). The commit now clears them once it decided; what it leaves unmarked is held until completion, as before. Docs: the gpu_written contract, write_routes.rs, docs/API.md and the runtime README say when. Verified with the lane commit after this one (debug, --cfg m2v_gpu, this M3 Max on MoltenVK): the 39 lane modules that execute indirect command buffers, 479 tests, all pass, where B alone failed 35; the runtime's written_commands, degradation, degradation_catalogue and degradation_sites unit tests pass; fmt; clippy -D warnings of the runtime and validation crates, all targets and features, under --cfg m2v_gpu. (cherry picked from commit e8e85c6936ecc731fa557440033ac9d3e40953e2) (cherry picked from commit 106af168144e7a76fcc5366e39fec10a3693611c) (cherry picked from commit 38605155f851abdf697c818c5387c1980af6a0bd) |
||
|
|
66c9163ce3 |
Mark an indirect command buffer written by the GPU only where a route that may write its records meets it
A write residency of an indirect command buffer (useResource:usage: with MTLResourceUsageWrite) marked it written by the GPU at the call, whatever the encoder's functions could do. Every execution of it then waited for the work before it and was recorded by a host step, and kept no chunk. A page whose kernel only counts, with the buffer made resident for writing, paid the host step every frame (51 to 61% of the write frame in the kept-steps measurement), though no function of it can reach a record: a function writes records only through an indirect-command operation. The mark now comes from the routes that can write records (write_routes.rs), decided by structure alone: - the commit of a command buffer that made the buffer resident for writing in any of its compute or render encoders (residency is the command buffer's) and also set, in any of them, before or after, a pipeline state whose functions' indirect_command_writes is not empty (the translator's answer from their AIR: the indirect-command operations their bodies may call, every one where a body makes a call the translator cannot see into), or executed commands whose records may name such a state; - after a commit that found neither, the first CPU or GPU write that leaves such a state in the records of a buffer it executed (the executed buffers hold the commit's unmarked buffers weakly until then, released as the command buffer completes; the marks run once the setter let its locks go); - a blit's copy into the buffer or reset of a range in it, at the call, as before. A heap holds no indirect command buffer and residency sets are refused, so neither is a route. The mark is for good, as before. It keeps the route that met the buffer first, which the host-replay notice names: for a state, its functions' names and the kinds of indirect-command operation they may call; else the route. WorkCounts::indirect_write_residencies_unmarked counts each commit's write-resident buffers it left unmarked. The resident_draws fixture gains rd_encode, a kernel that may reset a command and resets none, regenerated with scripts/regen-air-fixtures; the lane's `encode` path uses it, off the measured paths. Docs: the gpu_written contract, the runtime README, docs/API.md (the catalogue's HostReplayedIndirectCommands trigger and cost, and the contract), the module docs that named the old rule. api_signatures.tsv blessed (one field). Verified (debug, --cfg m2v_gpu, this M3 Max on MoltenVK): the resident_draws lane's three tests pass: a kernel that cannot encode (rd_touch) leaves the buffer unmarked, with no host step in any of three frames, its two chunks run from the kept recording in the third, one unmarked residency counted a commit, and the read path's pixels; a kernel that may encode (rd_encode) marks it at the first commit, a host step every frame, no chunk kept, the same pixels, and the notice names rd_encode and its reset; every path draws the encoder's pixels. Negative control (neg.py: every state counted as calling no operation, and no executed buffer's records as naming one): the encoding test fails (no host step in frame 0), the other passes. The runtime's written_commands (a new test of the followers), degradation, degradation_catalogue and degradation_sites unit tests pass. fmt; clippy -D warnings of the runtime and validation crates, all targets and features, under --cfg m2v_gpu. (cherry picked from commit 6e1b62a03039dd81a2005afa26a3001de2064110) (cherry picked from commit 13dac865f4096559a5b97841d893e1da02e160ec) (cherry picked from commit 862a72c76e82b657ef158ee1c7cbf789240ea745) |
||
|
|
27f052e7ec |
Read an inline ICB execution's records a chunk at a time, each run collected once
An execution of commands the CPU re-encoded before it is a first execution, which records inline. A consumer that sets every command again before each execution has only those. Before, such an execution read its whole range's records at commit before it recorded any: IndirectCommandBuffer::read_records collected them into a Vec grown by doubling, named_records zipped them with their states into a second, and Execute::commands and RenderExecution::commands wrapped each in Some into a third. A CommandRecord holds 4 stages of 32 buffer bindings, about 3 KB, so 16384 commands are some 50 MB a copy, out of the cache by the time they are recorded. On the RTX 5080 laptop, compute n=16384 all re-encoded committed in 64.8 and 67.7 ms with a54756c6a4 against 48.6 and 47.8 ms for its parent, which recorded each 256-command chunk apart in a kept context. Now: - kept_commands::pieces gives the runs of an inline range an execution reads and records in turn: its chunks of 256, or the range whole where every command must be seen before any is recorded (the caller's check where it may see something, and the command buffer's executed-commands handlers, which hear of the execution once) and for the host step, which reads the records as the GPU and the CPU left them. - Execute::record and RenderExecution::record read a piece, announce the commands of it that run otherwise than Metal's may, call the check, report to the handlers and record it, before they read the next. The host step's read is written_commands, as before. A kept render execution's rest of the range, after a chunk that is not plain, reads a chunk at a time too. - read_records makes its lists at their length and takes each record as its caller holds it; named_records names the states in place in the list it returns, and the commit path records from that list, with no Option a command. - WorkCounts::indirect_record_runs_read counts the runs of records read at once (api_signatures.tsv). - Degradation::ReleasedCommandState is announced once a piece, as a kept execution announces it once a chunk. - Docs: the "When." bullets of indirect_execute.rs and render/executions.rs, and pieces' own. Tests: - kept_commands::tests::pieces_are_the_chunks_or_the_range_whole. - runtime_lane::kept_commands::an_inline_execution_reads_its_records_a_chunk_at_a_time (render, 600 commands, [records read, runs read]): the first execution [600, 3]; with a check that sees (draws of points) [600, 1], the check called with 600 commands. - an_inline_compute_execution_reads_its_records_a_chunk_at_a_time: [600, 3]; with an executed-commands handler [600, 1], the handler hearing once of commands 0 to 599. Verified: - On the M3 Max, debug (--cfg m2v_gpu), nextest -j 8 over every runtime_lane module that executes an indirect command buffer: 39 modules, 477 tests, all pass. - Negative control, debug (pieces gives every range whole): both new lane tests fail at "the first execution, a chunk at a time" ([600, 1] where [600, 3] is expected). - metal2vulkan-runtime kept_commands::tests 3/3; fmt --check; clippy -D warnings (runtime and validation, all targets and features, m2v_gpu). - M3 Max, release, Time Profiler of execution_costs compute n=16384 all re-encoded, 2 untimed and 20 timed executions, inclusive CPU, lane 7583fe5d99 (keeps from the first execution) / d75cb04ac8 (before) / this change: CommandBuffer::commit 1077 / 1186 / 928 ms (49.0 / 53.9 / 42.2 ms an execution), IndirectCommandBuffer::records 274 / 336 / 142 ms, memmove 213 / 297 / 117 ms. execution_costs on this loaded host, commit medians of two rounds: compute n=16384 all re-encoded 47.65, 47.00 / 52.93, 57.44 / 44.32, 42.98 ms; compute n=1024 all re-encoded 8.34, 3.48 / 3.05, 3.95 / 3.82, 3.26 ms; render n=1024 all re-encoded 2.31, 6.59 / 2.49, 2.97 / 2.07, 2.19 ms. The M3's render n=16384 all re-encoded row is load-dominated (ranges reaching 77, 97 and 156 ms), so the 5080's below is that row's evidence. - RTX 5080 laptop (NVIDIA), release, execution_costs compute and render, 2c542021bf (parent), a54756c6a4 (before) and a54756c6a4 with this change's runtime part, interleaved, commit medians of two rounds: compute n=16384 all re-encoded 47.01, 46.41 / 63.07, 61.83 / 44.24, 43.79 ms; render n=16384 all re-encoded 39.96, 39.38 / 56.40, 56.27 / 36.88, 36.89 ms; compute n=1024 all re-encoded 2.86, 2.82 / 3.15, 3.10 / 2.66, 2.70 ms; render n=1024 all re-encoded 2.40, 2.46 / 2.52, 2.47 / 2.23, 2.23 ms; the one re-encoded and unchanged rows within 0.1 ms of each other but one 0.97 ms reading of this change's compute n=1024 one re-encoded (its range 0.68 to 0.97, the other round 0.73). Needs a RUNTIME_VERSION bump. No SEMANTICS_VERSION: no translated module changes. (cherry picked from commit 678b2925c08269249a1aad3ef3d126d94bbf460a) (cherry picked from commit 327cb5f3837ae38e055a4273e5254987601e43cf) |
||
|
|
24dc3f20bb |
Keep an ICB range's chunks from their second execution, and forget a written chunk in one store
A range's first execution no longer pays for keeping. Before, every execution of CPU-encoded
commands recorded each 256-command chunk apart, in a KeptContext of its own (a command pool, a
descriptor arena and uploads), so it could run that recording again later, even when no later
execution came. Now a chunk is recorded to keep only from its second execution with no write
reaching it since. The first execution since a write records inline, as before 922caf3199, and
keeps nothing. A consumer that re-encodes every command each frame now pays nothing for keeping.
- kept_commands.rs: KeptChunks notes which chunks an execution that may keep its commands ran
since a write last reached them. look_up answers each chunk of a range as Kept::Recording (a
kept recording), Kept::Again (run before, nothing kept) or Kept::First, and notes each as run.
IndirectCommandBuffer::kept_chunks answers None, so the execution records inline, when every
chunk is First. When some chunks are kept and others are not, a First chunk records apart from
its command buffer's own pool and arenas, with no KeptContext, and is not kept. An Again chunk
records apart in a KeptContext and is kept.
- KeptChunks is dense: one ChunkState per chunk (kept recording, stepped, seen) up to the
furthest chunk looked up, plus a flag for whether any chunk holds a state. KeptChunks::wrote
costs one store per chunk the written range covers, whatever the number of kept chunks, and
returns at once while no chunk holds a state. Before, it ran BTreeMap/BTreeSet::retain over
every kept and stepped chunk on each setter call.
- WorkCounts::kept_contexts_made counts the KeptContexts made (api_signatures.tsv).
- Docs: kept_commands.rs, render/executions/kept.rs, indirect_execute/kept.rs and
docs/FAST-PATHS.md (the kept-recordings row).
- examples/icb_setters.rs --kept now executes three times before each repetition: the first
keeps nothing, the second records every chunk to keep, and the third runs all of them from
those recordings.
Tests:
- runtime_lane::kept_commands asserts kept_contexts_made beside the records read and the chunks
and commands kept.
- A once-executed range makes no context: [N, 0, 0, 0].
- Its second execution keeps every chunk: [N, 0, 0, 3].
- Its third runs them: [0, 3, N, 0].
- After a write, the written chunk records inline again and the next execution keeps it.
- kept_commands::tests::a_write_costs_the_chunks_it_covers asserts the count of chunk states
wrote() looks at.
Verified on the M3 Max:
- Debug device lanes (--cfg m2v_gpu, nextest), with the live compute flags fix from stack22
applied locally (not part of this commit): every runtime_lane module that executes an indirect
command buffer (39 modules, 471 tests) pass.
- Negative control for the ruling (each chunk keeps from its first execution), debug:
3 of the 5 kept_commands tests fail, a first execution making 3 contexts where 0 are expected
and a written chunk making 2.
- Negative control for wrote() (it walks every chunk state): a_write_costs_the_chunks_it_covers
fails, looking at 1000 states where 1 is expected.
- Unit tests: kept_commands::tests 2/2 and metal2vulkan tests::fast_paths 19/19.
- cargo fmt --check and clippy -D warnings (runtime and validation, all targets and features,
--cfg m2v_gpu) are clean.
- icb_setters compute --kept (release, instructions per command, median of 30, two runs each):
| | before (2c542021bf) | after |
|---|---|---|
| compute command, nothing kept | 2528.7 / 2529.1 | 2428.1 / 2427.7 |
| compute command, 64 chunks kept | 5947.8 / 5945.5 | 2586.5 / 2583.9 |
| set_kernel_buffer, 64 chunks kept | 1129.6 / 1129.6 | 456.9 / 456.3 |
With three executions, the third runs all 64 chunks from kept recordings (the
bench prints [64]), at 2583.9 and 456.3 instructions.
- conformance cost --alone indirect-render-commands-inherited-state reads arena_pools_made 1,
argument_objects_retained 2 and argument_tables_retained 1, the recorded bounds. With a first
execution's KeptContext these read 3, 6 and 3 (the cost run that held its record back).
- execution_costs (release) on a loaded host: wall times are dominated by host load. An earlier
pair of runs read the first execution as slower (render n=1024 all re-encoded commit 2.88 to
6.55 ms), but the parent then read 6.55 ms itself under the same load. Time Profiler, test
thread CPU, same case and count, this change on 2b55ab415e against its parent:
- render n=1024 one re-encoded, 300 executions: 611 to 610 ms;
- compute n=1024 all re-encoded, 80 executions: 336 to 333 ms;
- render n=1024 all re-encoded, 120 executions: 782 to 859 ms. This is the inline path's
whole-range read: RenderExecution::commands collects the range into a second
Vec<Option<Command>> (memmove 0 to 25 ms in RenderExecution::record), and render_records
reallocates as it grows. The same profile has IndirectCommandBuffer::edit, whose code is
the same in both builds, up 31 to 40 ms, so part of the difference is load.
A later run of this commit's tree read render n=1024 all re-encoded at 2.37 ms commit, one re-encoded
at 0.61 ms, and compute n=1024 all re-encoded at 3.49 ms.
Needs a RUNTIME_VERSION bump. No SEMANTICS_VERSION: no translated module changes.
(cherry picked from commit a54756c6a4f7fbe9ae82d732e8de46a19f4f86e5)
(cherry picked from commit 71e798c081648ea3818abbffc7538a3061456c75)
|
||
|
|
be686f18a0 |
Write an indirect command's field in place, adding to what its records hold only what is new
Each Metal-shaped setter (IndirectCommandBuffer::edit) paid about 2000 instructions, almost all for bookkeeping around a write that costs 130-213. It copied the whole 2248-byte record out of the mapped storage (zeroed, then moved through a Result), wrote the field into the copy, copied the field back, decoded the copy again for its action and barrier, looked the command up in the per-command BTreeMap of states (16384 entries), then took the summary's own mutex to add what usually was there already. The 41% of its time in memmove and 30% in edit's own copy loops were those copies. The BTreeMap lookup came in with |
||
|
|
e51a3fa56d |
Name an ICB's per-command map CommandStates, not Commands
The kept recordings of unchanged indirect commands (four commits back) named the buffer's map of the states the CPU set, and of its kept chunks, Commands. tests::exit_guard's only_the_listed_modules_keep_the_device_s_functions reads the sources for copies of the device's functions and takes Commands for the generated-commands table that holds them, so it failed at indirect_command_buffer.rs's pipelines: Mutex<Commands>. The map holds no device function; its name now says what it holds. Verified: --cfg m2v_gpu, metal2vulkan-runtime's tests::exit_guard and kept_commands tests (42) pass; the exit-guard test failed on the commit before (the M3 Max run of the runtime's lib, 1,830 of 1,831 passing). Needs no version bump: a private rename. (cherry picked from commit 93c48b72a7a094d6c7cee93192070f7f99e77dea) (cherry picked from commit 831d54138016d0373b51e7c033e4c7665dbd65ce) |
||
|
|
185bbd6328 |
Host steps: record off the scheduler's thread, order by what the execution reaches, make only named states
A batch executing indirect commands the GPU may write waits for its gate, then its host step records the commands from their records. Three costs fell on every other queue meanwhile: - The step ran on the scheduler's thread, which submitted nothing while it recorded (thousands of draws take milliseconds). - Its footprint was unknown (tracker::ordered's None), so every later batch of another queue that made a tracked use was held behind it until it was submitted. - At commit, the render settle made a VkPipeline for every live state that supports indirect command buffers, times the topology class's primitive types (1,280 lookups and 513 makings for 256 live states on the measured frame), and the step waited for all of them, up to the command buffer's bound. Now: - The scheduler hands each step to a steps' thread (scheduler/steps.rs, started at the first step, user-interactive like the scheduler's, recording inline where the host cannot start it), which records the steps in order, each a section of the exit guard, and wakes the scheduler. The batch is marked as stepping meanwhile (CommandBufferShared::begin_step/end_step), so it waits and no pass hands it over twice. - commit bounds a step's uses where it can (Segment::bound): for a compute execution, the resources the command buffer made resident and the ICB's storage (and an indirect range's copy); for a render pass, the pass's own uses, the resident resources and each execution's storage. CommandBufferShared::footprint uses that bound, so only a later batch sharing one of those is held. An execution that inherits buffers, is gated or preprocessed, reaches tile memory, has shadows or lends visibility stays unbounded (None), as before. - The render settle makes the states the CPU set on the executed commands (IndirectCommandBuffer::set_render_states, each state once), or the inherited one. A draw of a state a GPU-written record names that no settle made is begun at the step, made on its thread or handed to the device's pool and waited for until the command buffer's bound, as before; it holds no other queue's batch, and it is counted. On the kept recordings of the commit before (item 1), set_render_states reads the states the CPU set from the buffer's per-command map (Commands::states, a range of it), each state once. New counters: WorkCounts::host_steps_recorded, host_step_nanos, and host_step_pipelines_made (the VkPipelines a step began itself, made on its thread or handed to the device's pool and waited for: counted at the variant's making on the step's thread and at pipeline_pooled). The degrade notice host-replayed-indirect-commands states the new cost (degradation.rs and docs/API.md, same text). Verified on the M3 Max (MoltenVK 1.4.2), release, runtime_lane::host_replay_frames (the next commit: 256 live states, an ICB of 5000 draws naming 4, made resident for writing by a compute pass each frame, and a presenter clearing a texture on another queue every 8.33 ms), the parent and this tree run alternately twice, 60 frames each after 4 cold ones, on a loaded host: - the presenter: 80 of 244 and 73 of 192 ticks presented before (commit to completion median 16.9 and 16.4 ms, p90 40.8 and 23.7 ms), 186 of 186 and 185 of 189 after (1.13 and 1.13 ms, p90 1.49 and 2.23 ms); heads held behind earlier commits 23 and 13 before, 0 after; - the first frame's commit: 377 and 168 ms before (513 variant pipelines made, 1,284 looked up), 5.3 and 5.1 ms after (9 made, 24 looked up); a steady commit 2.38 and 2.33 ms before, 0.14 ms after; - the frame itself (commit to the last completion): median 28.7 and 24.4 ms before, 23.3 and 24.6 ms after, within the host's noise; the host step takes about 20 ms of it (host_step_nanos), recording the 5000 draws. The consumer's ICB repro (one state, 5001 draws, the ICB made resident for writing, another queue's one-dispatch command buffers meanwhile), same runs: that queue's commit to completion at the 99th percentile 53.5 and 24.3 ms before, 2.96 and 3.71 ms after, 140 and 119 command buffers in 40 frames before, 2,281 and 2,062 after; the frame alike (21 to 26 ms). Tests: runtime_lane::render_executions:: a_host_step_makes_the_pipeline_of_a_state_only_a_gpu_written_record_names (a blit-copied record naming a state, of another variant, that the CPU set on no executed command: both commands draw, the step's beginning of that state's VkPipeline is counted, and the step's time). --cfg m2v_gpu under the validation layer, on this tree before the pipeline_pooled count and the test: 234 tests of the indirect_*, kept_*, render_executions, render_gpu_executions, render_merged_executions, mesh_commands and executions lanes; 1,644 tests of the runtime crate's lib and the commands_recorded, dispatch_executions, generated_executions, kept_variants, device_commands, queue_order, submission_checks and grouped_submissions lanes. clippy -D warnings, plain and --cfg m2v_gpu; rustdoc -D warnings; scripts/api-signatures --check. Needs a RUNTIME_VERSION bump (what a run submits, when, and its counts) and a runtime-sources pin. (cherry picked from commit 4b05004999403684a2bdf4f3994108b53c7dc776) (cherry picked from commit 3831ba7e1298203779597feb0ea2943f77f9f5df) |
||
|
|
565fbd9153 |
Run unchanged indirect commands from kept recordings, chunk by chunk
An execution of an indirect command buffer read, decoded and recorded every command again at every commit, so an unchanged execution of 16384 draws cost about 44 ms of commit on the M3 Max and 64 ms on the RTX 5080 laptop, where Metal's costs 2 ms. A profile of the render case put a third of it in the records' decode and moves and the rest in recording the draws. Now an execution of commands the CPU encoded records them in chunks of 256 (kept_commands.rs). A render chunk records into a secondary of its own, begun for simultaneous use against the instance's compatible pass, through an encoder over a core of its own whose effects the pass's core takes (EncoderCore::capture, absorb); a compute chunk records as a segment of its own, behind a barrier from everything before. Each chunk takes its command pool, descriptor arena and uploads from a context of its own, lent to the command buffer while it records and held by every command buffer that runs it. A chunk whose recording is plain (every draw passes draw_again's keep test but for being replayed, no step outside its command buffer, nothing its command buffer alone holds, no released state) is kept on the buffer with what it was recorded from: the encoder's inputs (RenderKey, ComputeKey: the inherited state, the pass's compatible pass, shape, extent and sample positions, the encoder's state and scissors, the resident resources), each address its commands named and what it resolved to, and the no-copy moves. A later execution of the chunk under equal inputs, every address resolving as before, nothing detached and every held object alive, runs the kept command buffer and notes its uses, keys, holds and executions again (EncoderCore::run_kept), reading no record. Every CPU write of a command forgets its chunk under the lock the write takes; the buffer's first GPU write forgets them all; a recording from records written meanwhile is not kept. A chunk that is not plain records the rest of the range as before and is noted, so later executions of it record as before until a write reaches it. The buffer's per-command state moves to a map, so a buffer of commands never encoded holds nothing for them. WorkCounts::indirect_chunks_kept and indirect_commands_kept count the kept path. docs/FAST-PATHS.md's known gaps list the executions that still record every command at every commit. Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, under the validation layer: runtime_lane::kept_commands, 5 tests: unchanged render commands run 3 kept chunks of 600 commands reading no record, into another target and twice in one pass; a command written again or reset records its chunk alone; a blit's reset runs no kept chunk and its commands draw nothing; another residency or range records again; compute commands the same, with a command written again and a blit reset. 446 of 448 tests of the 33 lanes that execute indirect commands pass; the two others (extended_range_blends half outputs, padded_loads loading pass) are among the MoltenVK reds the parent already has. clippy -D warnings, plain and --cfg m2v_gpu, for the runtime and validation crates; the runtime's kept_commands unit test; the translator's fast_paths, api_signatures and api_surface tests. Needs a RUNTIME_VERSION bump and a runtime-sources pin. (cherry picked from commit 21b9438ec5b8cbf7a1e79c5dfbf84cdad7b43d91) (cherry picked from commit 922caf3199378b029bafc201429f80b0d43bb048) |
||
|
|
3cb648543f |
Take the indexed draw a buffer of DRAW alone runs as nothing
The steps this packet landed as, in order: - Re-derive the generated documents at the landing tip - Record the runtime sources' hash after the indexed draw on a DRAW-only buffer Content: the tree of `development` at 4d0b93e5a3, unchanged. |
||
|
|
d83182d197 |
Record the runtime sources' hash after the two indirect over-refusals
The steps this packet landed as, in order: - Stop claiming two indirect calls are refused when the runtime takes them Content: the tree of `development` at 161fd37a49, unchanged. |
||
|
|
04bc130a4c |
Make the indirect buffer and bind counts plain Metal makes, and refuse only what its process does not survive
The steps this packet landed as, in order: - Measure the slots past the records before anything is taken, and read the taken calls at commit - Bless the public signature table after the bind-count refusal's variant - Take runtime version 1605 and re-derive the generated documents at the rebase tip Content: the tree of `development` at 7f47d5fffe, unchanged. |
||
|
|
26c7aad1d0 |
Name the device and release behind twenty-one forwarded refusals' measurements
Content: the tree of `development` at ead49055ec, unchanged. |
||
|
|
1366be1718 |
Read the problems a Problem forwards to, and hold each to a basis
The steps this packet landed as, in order: - Keep the quoted Metal messages out of rustdoc's link syntax - Record the runtime sources' hash after the sub-problem basis lines Content: the tree of `development` at 3ade9d9999, unchanged. |
||
|
|
ce22858836 |
Move the fill's empty pattern and the unstrided indirect buffer out of Invalid
Content: the tree of `development` at cac3120433, unchanged. |