f32168731dae2dfeb79f0dfda122c191eb593ec8
1317
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
f32168731d |
Pin the runtime sources after shadowed-texture pass runs and kept resident uses
Re-hashed with the runtime sources at RUNTIME_VERSION 1760. (cherry picked from commit a3b2691758c379468f3613147d2e393b85837181) |
||
|
|
b840a64a3d |
Bump RUNTIME_VERSION to 1760: shadowed-texture pass runs, kept resident uses
Consecutive passes over one shadowed texture copy in, keep and merge once per run (99949a4cd0), and a draw keeps its uses of what its encoder made resident while its plan and residency stay the same, listing them first among its uses (02ef82edcb), which can reorder entries within one barrier. Both change what a run of an unchanged artifact records, so recorded runs are held to the new version. (cherry picked from commit 4ef52e714128d318329ab722df91b22210a66a6a) |
||
|
|
626bd347d2 |
Keep a draw's uses of what its encoder made resident while its plan and residency stay the same
A draw's uses (binding::command_uses_into) held a use for each resource the encoder made
resident that its binding plan lists (UseTarget::Used), made again at every draw with two sets
of the keys reached through the resident set and named otherwise: work of the count of the
resources made resident, at each draw. On the resident-draws lane (runtime_lane::resident_draws:
each draw binds a resource of its own among N made resident), that made a frame of N draws
quadratic in N.
A draw's CommandUses (kept in LiveBind::uses) now holds those uses first, with the keys of the
buffers among them that no texture use of them names, and what they were made for: the plan,
compared by address through a Weak (so no other plan has that address while it is kept), and
the residency's generation. A draw of the same plan under a residency of the same generation
keeps them, makes its other uses, and works the resident keys out again only where the keys
its other uses name changed, or a use added since took one out (CommandUses::settle_resident).
Those uses are a function of what is compared: each one's resource is the residency's under its
token, whose contents a generation names (residency.rs), its access and stages are the plan's,
and its key and range are the resource's identity and length, which no call changes. The key
leaves out buffer::host_cells_moved: a no-copy buffer's move (HostCell::replace, at a rebind or
a detach) changes where its bytes lie, its pages' base and device address, which a binding
reads; a use's key is the buffer's identity and its range its length from 0, shifted for a heap
buffer by its fixed offset in the heap (Buffer::tracked), and neither is under the cell.
The uses of what the encoder made resident now come first among a command's uses, where they
came at their place in its plan's list. The consumers that compare a command's uses by position
with the last command's (EncoderCore::touch_reaching, NotedApart::fresh, InstanceShadows::add)
compare like with like across draws of one plan. With that order every suite and lane below
passes, and the lane's cases draw the same pixels and move the same counters.
Counted: WorkCounts::resident_uses_made, the uses of resources made resident that draws worked
out (0 at a draw that kept them). WorkCounts gains that field, so a struct literal of it (the
lanes' counters, not part of the API) must name it; the signature table is blessed. Builds with
debug assertions check every draw that kept them against the uses command_uses makes whole, and
count the checks (binding::kept_resident_checks).
Tests (--cfg m2v_gpu, with debug assertions):
- tests::resident_uses::draws_keep_the_uses_of_what_their_encoder_made_resident_until_it_or_their_plan_changes:
two encoders over the resident-draws fixture's entry shape, the second over other resources
of the same residency's shape. Each draw after the first keeps the uses (0 made, its kept uses
checked against those made whole) but the draw after a use_resource between draws, the draw
after one of another plan (which lists none), and the second encoder's first draw, of the
first's last plan under another generation, which make them again. With ResidentOf::holds ignoring the
generation, the debug check fails at the second encoder's first draw ("a command kept uses of
what the encoder made resident not its own"); with it ignoring the plan, the draw after the
other plan's indexes another plan's uses and panics (index out of bounds).
Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions: the runtime's
whole suite, 1588 of 1588; the validation crate's runtime lanes over residency, argument
buffers, indirect command buffers, executions, draws, frame costs, heaps, handles, attachment
reads and degrade notices (resident_draws::each_path_draws_what_the_encoder_draws among them,
300 draws a case under the debug check), 234 of 234; clippy over the workspace with all targets
and features, plain and at --cfg m2v_gpu; cargo check of the runtime's tests in release at
--cfg m2v_gpu, no warning; the signature table checked.
Measured, M3 Max, release (--cfg m2v_gpu --cfg m2v_system_alloc), resident_draws, a frame's
median of 5 (ms), at the parent and with this:
| case | N 500 | N 1000 | N 2000 | N 5000 |
|---|---|---|---|---|
| entry own encoder | 20.2 -> 7.7 | 81.1 -> 25.0 | 351 -> 91.8 | 2576 -> 525 |
| entry own read | 20.9 -> 8.6 | 80.0 -> 27.9 | 355 -> 96.2 | 2542 -> 550 |
| entry own write | 22.0 -> 9.5 | 83.2 -> 29.0 | 355 -> 98.9 | 2597 -> 549 |
The slot shape and the entry shape at offsets of one buffer move within their noise. Every
case drew the same pixels (its hash) and moved the same counters but those of timing (arena
recycling and eviction, scheduler sleeps) and resident_uses_made (its plan's uses at each
frame's first draw: 502 a frame at N 500, 0 at every later draw). Still quadratic: 15.4, 25.0,
45.9 and 105 us a draw; at N 2000 the draws' noting of the kept uses (EncoderCore::note_reaching,
46% of the samples), the instance's gathering (InstanceShadows::add, 17%) and the pass's reads
(PassStartReads, 12%) walk them at each draw, and uses_into is 0.3%.
reims-vgpu's draws.10k (its draw_cost harness, the runtime leg, through its run.sh on the M3
Max; median [range] of 9 runs, two interleaved runs each), instructions a draw: 11473.9
[11463.0, 11480.2] and 11478.8 [11471.2, 11481.6] at the parent, 11387.0 [11373.8, 11392.7] and
11387.1 [11378.9, 11404.4] with this: 87 fewer (0.8%), the two sets no longer made at each draw.
host_ab on the RTX 5080 Laptop (encode, us a draw, median and range of 6 runs over two exclusive
holds), at the parent and with this: static 0.059 and 0.059, offset 0.462 and 0.465, bind 0.753
and 0.740, compositor 1.012 and 1.002, host 0.518 and 0.515: within their ranges, as those
shapes make nothing resident.
(cherry picked from commit f6bc17a568bd6b1424089faf8e26584bd159fbb8)
(cherry picked from commit 02ef82edcb8c8042b313d8773a58575447e07795)
|
||
|
|
241ee2c0d1 |
Keep and merge a run of passes over one shadowed texture once, not once a pass
What: a render pass whose color is a shadowed texture merged back (its truth a buffer's bytes
another writer may write, such as a no-copy buffer's host pages or a Shared buffer's), loaded and
stored, now joins a run of passes (pass_runs.rs) where it may. The run's first pass copies in (or
takes the carried image) and keeps, as before. Each later pass goes on over the image the pass
before it left (ShadowSync::go_on) and keeps nothing. Each pass leaves its merge to its batch's
submission (Deferred::RunMerge, RunWork::Shadow), and the run's next pass takes it over, so the
merge recorded is the last pass's, compared against the first keep. The run holds the keep's
scratch or kept image (RunHeld::Shadow, its MergeLease) until it ends or the command buffer
commits.
Why: consecutive render passes over one merged-back shadowed texture each copied in, kept and
merged the whole texture. 700 one-rectangle passes over a 1024x1024 BGRA8Unorm texture over host
pages took 1,401 shadow copies and 700 merges.
The rule, structural, with no names: a run ends wherever something other than its own passes
could observe or change the bytes, as in the linear runs' list:
- any encoder between its passes that is not a render encoder;
- a render encoder that names the bytes' buffer or its host range, reaches memory it does not
name, fences, resolves, writes visibility results, records later or renders over a rate map;
- a render encoder with an attachment over those bytes, or whose draws or attachments take a
shadowed texture over them (the run's own texture bound to a draw included);
- a signal, a wait or a host step (a new batch), and the command buffer's end;
- for a shadow, the encoder no longer carrying the image (the carry dropped).
A shadowed color joins only when it is loaded and stored, has no stand-in and no planes, belongs
to a pass of one render pass instance that is not inline and not inside a predicated laying, is
laid out as one image's texels at level 0 and slice 0, and merges back.
Encoded again: unlike a linear attachment's run, a shadowed texture's run may hold passes over
host pages, which a rebind before the first submission encodes again. Such a pass leaves its run
(RunMerge::leave). The merge it took over records after all (given back), and the pass copies in,
keeps and merges for itself. Where a later pass took its merge over, it keeps the run's scratch
again after its own merge (RunMerge::keep_after), so that later pass's run merges what the passes
after it change. Run segments now record again (Segment::records_again) and splice. An encoder
encoded again takes no pooled scratch or kept image (ShadowMerge::new's `lent`). A run's merge is
resolved at its calls (Deferred::resolved_at_its_calls), so it holds no host pages past commit;
before this, a rebind of such a run was refused with Rebind(EncodedUses).
Two more changes. A run's keep that a later pass writes outside merges and keeps every texel next,
and a run's pass that needs texels the copy-in did not hold copies every texel in. A merge in whole
blocks stays in blocks where the keep holds the pass's area (stores_blocks), under the same
read-to-store window that shadow.rs's Stored attachments already state.
Counted with the existing counters: shadow_copies, shadow_texels_kept and
shadow_merge_dispatches_planned fall from one per pass to one per run. docs/FAST-PATHS.md records
the run and its costs.
Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, under maclock and memcap:
- tests::shadow_runs (new, all pass):
- runs_over_host_pages_keep_and_merge_once: 1024x1024 BGRA8Unorm over host pages, rows of 15360
bytes, with blits, foreign render encoders, reads, CPU byte writes, a signal and an aliasing
view between runs. Mid-sequence and final reads match a private texture byte for byte, and
the padding is untouched. Joined: 22 copies, 9 merges. Apart: 112 copies, 54 merges.
- rebound_passes_leave_their_runs: 3 encoders encoded again, 0 refused, bytes equal.
- scissored_runs_keep_again_once_and_merge_in_blocks: keeps at passes [0, 1], all in blocks.
- Runtime suites (shadow, merge_scratch, linear_runs): 69 of 69 passed.
- Validation runtime_lane (shadow, padded, linear): 91 of 91 passed.
- Negative controls, each a sabotaged build, source restored and touched after; each fails:
- go_on off: every pass keeps;
- follows across encoders: keeps [D0, D8, D9, D10, A11, D12];
- leave off: 961,469 bytes differ;
- stores_blocks reverted: every scissored pass keeps.
- Release probe, 700 passes in one command buffer, base a543f6428d against this commit: shadow
copies 3 against 1,401, texels kept 1,048,576 against 734,003,200, merges planned 1 against 700.
Commit to completion, runs 1-3: 31.6-35.3 ms against 69.3-99.9 ms. With a 1x1 render encoder
between every two: 61.6-65.0 ms against 107.4-118.6 ms.
On the RTX 5080 Laptop GPU (NVIDIA 615.71.09), the same probe, runs 1-3: 6.6-10.0 ms against
40.6-43.0 ms, and 9.7-12.3 ms against 44.5-47.1 ms. The same 11 shadow, merge and linear device
tests passed there.
clippy --all-targets --all-features -D warnings passed plain and with --cfg m2v_gpu, and cargo fmt
was run.
(cherry picked from commit bf783428131f46c7289518a50b8505e809ecc8e5)
(cherry picked from commit 99949a4cd08cd042e448484e0b1d2f5da1898db5)
|
||
|
|
eab0350e04 |
Rename linear_run.rs to pass_runs.rs: runs of passes merged once, not only linear ones
What: the module that merges a run of passes over one linear attachment once (5d2b237e1a) becomes pass_runs.rs, its LinearRuns PassRuns, the command buffer state's linear_runs pass_runs, and Deferred::LinearMerge Deferred::RunMerge. No behaviour changes; the docs and code otherwise read as before. Why: the next commit lets a run be one of passes over a shadowed texture merged back too, through the same machinery, so the names stop saying "linear". Verified: cargo clippy -p metal2vulkan-runtime --all-targets --all-features -D warnings is clean on this tree (plain cfg); cargo fmt --all. (cherry picked from commit 3d902362669724a733f59e6dc1b16f05ea3c088e) (cherry picked from commit f7f91bb05d64b172c01d44a8a73d1ba3de5194e0) |
||
|
|
462e45784c |
Pin the runtime sources after the steps' threads pool
Re-hashed; the pool of steps' threads rides this stack's RUNTIME_VERSION 1759, which no landed tree carries yet. (cherry picked from commit 4bbafa667db0bb9b4d62821d877f161c178c88e9) |
||
|
|
79fc675104 |
Check that another queue's work goes on while a host step records, and measure it
What: runtime_lane::steps_apart. Queue A executes resident_draws' entry shape (an argument-table entry a draw, each position in a buffer of its own, made resident, the commands resident for writing), so a host step records it; its executed-commands handler, which runs inside the step, holds the step. Meanwhile B, a queue a kind, commits work that shares nothing with it: a blit fill read back (plain), its own execution, a host step of its own (stepped), and a copy out of a texture A rendered before, after an event A signalled (ordered). The test checks each completes within 10 s with what it wrote while A's step is held, both with A's objects kept and with every one of them (command buffer, draws' resources and commands, queue) let go of while the step is held, A's completed handler still running. It checks too that two steps Metal orders after A's, one after an event A's command buffer signals and one a pass into A's target, each on a queue of its own, begin only after A's step ends. The ignored `steps_apart` measures each kind's commit-to-completion, without the layer, idle and while a real step of STEPS_APART_DRAWS (5000) draws records, A's objects kept and let go of once committed (`STEPS-APART` lines). Why: the consumer's WindowServer present waited 13.6 s behind a closed page's host step; the previous commit moves steps onto a pool of threads, and this is the check that fails without it. Verified on the M3 Max (--cfg m2v_gpu, maclock+memcap), debug: fails before the previous commit (stepped did not complete, kept and released; plain 1-3 ms, ordered 4-8 ms) and with its THREADS set to 1; passes after it (stepped 18.6 / 18.9 ms). Release, during a 5000-draw step of 2.7 to 5.0 s, before -> after: stepped 3580 ms -> p50 1.49 / max 15.6 ms (released 3359 -> 1.65 / 40.4); plain p50 0.44 -> 0.26 ms, max 22.5 -> 20.0; ordered p50 0.45 -> 0.27, max 18.3 -> 20.7; idle (4000 each, after) plain 0.22 / 0.79, stepped 1.32 / 10.98, ordered 0.25 / 0.49. The release check wrote the debug assertion of compute/live.rs out of the way only by its base, 7583fe5d99, which carries 2d8616c747. (cherry picked from commit 8a34da8a90f12b270c5db821e0c5139b093776bd) (cherry picked from commit bc500877c42a4dd36826b845b84253dbd729c585) |
||
|
|
385a2ed40f |
Record host steps on up to eight threads, so one queue's long step holds back no other queue's
What: scheduler/steps.rs had one thread per device record every host step of every queue, in hand-over order. It now hands each step to a free thread of a pool, or starts one for it below THREADS (8); past the cap a step waits for the first thread free, in hand-over order. The first thread stays until the scheduler stops, as the one thread did; each later one ends after 2 s with no step. All start at the user-interactive class, each step is still a section of the exit guard, and where the host cannot start the first thread the scheduler's thread records the step itself, as before. Why: the consumer (one device for every guest process) saw WindowServer's present wait 13.6 s in the host after the page's context had closed. A page's render-bundle ICB execution was recording a seconds-long host step, and any command buffer whose draw or dispatch has a pipeline still being made takes a host step too (deferred.rs: RenderPass with making(), Pending), which queued behind the page's on the one thread. A dead context's step keeps recording, as its command buffer holds what it uses. Order is still the scheduler's: only a line's head is handed over, marked stepping until its step ends, so a logical queue's steps are recorded one at a time in its order, and a head that waits for an event value, or is behind an earlier commit's conflicting batch (order.rs), is not gated or handed over (gate_heads takes `behind`). Audit of what assumed one step at a time device-wide: - kept chunks (kept_commands.rs): no host step uses them (render executions keep only when !step, compute executions only when states.is_none()); - upload and descriptor arenas: per command buffer (State::uploads, State::descriptors); their spares are the device's, under a lock; the command pool is per command buffer, recorded under its `reencoding` turn, which host_step takes; - pipeline making: the pool, the budget's turns and the making maps already serve concurrent encoders; the in_host_step()-gated branches (Urgency::HostStep, keep_room skipped, kept variants not taken back, takes_multi_variable_dynamic, make_at_creation skipped, sampler-set count) read a thread-local, so they hold per thread; kept.rs StepNumbers is thread-local and per command buffer, whose steps stay sequential, `made` handed on through end_step and the scheduler's locks; - residency: a command buffer's own value, its address index made per residency; - the scheduler's wake and hand-over: record() marks the inbox under its lock and wakes, as a committing thread does; begin_step/end_step are the command buffer's atomics; post pushes under the steps' lock; - the exit guard: sections are counted per thread and in atomics, HOST_STEPS is thread-local, called() is atomic; many sections at once were already normal; - interior mutability used by the steps thread alone: none besides the steps' own state (every shared object is Sync and shared with committing threads already); - notices: every-occurrence notices announced inside steps (each_in_order) of two queues may now interleave; Metal orders nothing between such queues. Docs: the scheduler's "Host steps" section, left.rs, WorkCounts' host-step counters, kept.rs, RecordsRead::HostStep and FAST-PATHS.md's pipeline-wait row say steps' threads. The host-replayed-indirect-commands notice already says only resources the execution may reach hold later batches back, so it is unchanged. Verified on the M3 Max (MoltenVK, --cfg m2v_gpu, maclock+memcap), with the next commit's lane test runtime_lane::steps_apart::another_queue_goes_on_while_a_host_step_records: before, queue B's own stepped command buffer did not complete within 10 s while queue A's step was held (A's objects kept, and released); after, 18.6 / 18.9 ms in debug. Its ordered checks (a step after an event A signals, and a pass into A's target) begin only after A's step ends, before and after. Negative control: THREADS = 1 fails the test again (Stepped, kept and released); restored and touched. Release, A a real 5000-draw step (2.7 to 5.0 s), B's stepped kind went from 3580 ms (released: 3359) to p50 1.49 / max 15.6 ms (released: 1.65 / 40.4); idle 1.32 ms p50. Runtime tests::(scheduler|inbox|host_step|waiter_submits|commit_and_submit|completion_order| unsubmitted|pipeline_wait_order|blit_order): 50 passed. Lane cases (indirect, kept, *executions, *host_steps, submi*, steps_apart, resident_draws, event_round_trips, command_queues): 272 passed. clippy --workspace --all-targets --all-features -D warnings, plain and with --cfg m2v_gpu: clean. (cherry picked from commit e15fd6752fe4f714b73dab0ee72d15fce686f3d7) (cherry picked from commit 229f407b2abe2de5b85bf3d98b2080d0a0667e9d) |
||
|
|
fada224c2a |
Pin the runtime sources after keeping checked executions their checks cannot see
Re-hashed; the change rides this stack's RUNTIME_VERSION 1759. (cherry picked from commit 67590d6dd404806fd75e8662cc0d86c40e4d32dd) |
||
|
|
f6692d84e5 |
Keep an ICB execution's chunks where its check can see nothing among its commands
Before, any execution given a check (execute_commands_in_buffer_checked) recorded every command at every commit and kept no chunk, even when the check's needs ruled out everything the buffer's records may hold. In that case commit never calls the check: RenderExecution::check_sees and Execute::check_sees answer from the needs and IndirectCommandBuffer::command_writes. A consumer that hands every execution of own-state commands a check for draws of points, and draws triangles, never had its unchanged commands run from kept recordings. Now RenderExecution::keeping declines where `self.check_sees_now()` holds, and Execute::keeping where `self.check_sees()` holds. The decision is the structural one commit makes for the check, the check's needs against what the records may hold. When a later write makes the records hold something the check looks for, it forgets the chunks it reaches. At the next execution check_sees is true, so keeping declines and the execution records inline, calling the check with every command. Docs: the "Which executions" lists in render/executions/kept.rs and indirect_execute/kept.rs, and docs/FAST-PATHS.md's kept-recordings row. Tests (runtime_lane::kept_commands), counting records read, chunks and commands kept and contexts made (WorkCounts::indirect_chunks_kept and kept_contexts_made show the kept path ran), and the commands the check was called with: - a_checked_execution_keeps_where_its_check_sees_nothing (render). With needs for states that may encode indirect commands, which the inherited state can't, the check sees nothing: [N, 0, 0, 0], then [N, 0, 0, 3], then [0, 3, N, 0], and the check is called 0 times. With needs for draws of points, which the records hold, the check sees: [N, 0, 0, 0] three times, and the check is called with all 3N commands. - a_checked_compute_execution_keeps_where_its_check_sees_nothing: a compute execution checked for every kind. Its records hold no draw and no state that may encode, so it keeps as above, and the check is called 0 times. No fixture kernel encodes indirect commands, so compute has no "check sees" leg. Verified on the M3 Max, debug (--cfg m2v_gpu), on lane 7583fe5d99 with the first-execution ruling cherry-picked beneath it: - nextest -j 8 over every runtime_lane module that executes an indirect command buffer: 39 modules, 473 tests, all pass. - Negative control: keep only with no check at all (the condition before). Both new tests fail at "the second records three chunks to keep" ([600, 0, 0, 0] where [600, 0, 0, 3] is expected). - Negative control: keep whatever the check (render). The render test fails at "a check that sees keeps nothing" ([0, 3, 600, 0] where [600, 0, 0, 0] is expected). - fmt --check, clippy -D warnings (runtime and validation, all targets and features, m2v_gpu), metal2vulkan tests::fast_paths 19/19. Needs a RUNTIME_VERSION bump. No SEMANTICS_VERSION: no translated module changes. (cherry picked from commit d75cb04ac8ed9d4616b10aa13d26af869a32d405) (cherry picked from commit efafed587dd062f7d87bd9c9868ccb035e9ddc26) |
||
|
|
b47ff009ed |
Pin the runtime sources after first-execution keeping and the sampler listing count
Re-hashed with the runtime sources at RUNTIME_VERSION 1759. (cherry picked from commit bfbbb2262ccc683625a243ac2f513bf8b8733ae7) |
||
|
|
9fa0967d11 |
Bump RUNTIME_VERSION to 1759: an ICB range keeps from its second execution, sampler listings count a going state
An indirect command buffer range's first execution now records inline and keeps nothing, its second keeps (71e798c081), and a listing of the sampler states that finds one going counts a slot change first (16afd35fa0). Both change what a run of an unchanged artifact records or binds, so recorded runs are held to the new version. (cherry picked from commit 367ca0fe5695510df3dc5e89aa69348cf45cd9ce) |
||
|
|
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)
|
||
|
|
96e42d349f |
Count a sampler slot change where a listing finds a state going
A compute dispatch's debug check (LiveDispatch::check_whole) panicked once in seven runs of runtime_lane::cache::makings_on_several_threads_each_read_their_own_cache: "a dispatch's bind state brought in place that is not the one made: its argument samplers". Cause. ResourceIds::samplers lists sampler slots' holders by Weak::upgrade, keyed by the count of slot changes. A state whose last handle is gone on another thread no longer upgrades, but its ID's slot is given back, and the change counted, only later, in IdHold's drop (after SamplerShared's drop and heap_sets::sampler_gone). A listing taken in that window left the state out at the count a listing taken while it lived was taken at. A compute encoder's kept bind state (kept across encoders through SpareLiveDispatches) kept its listing while listed_at == Some(changed), so it went on listing the going state, and the check, which lists again, found the two apart. Fix. A listing that finds a slot whose state no longer upgrades counts a slot change before it reads the count. Every listing returned at one count then lists the same states, and a listing kept from before the state started going is at an older count. The render side's raw-count check (LiveBind::listed_at against Device::sampler_slots_changed) and the dispatch memo key need no change: a memo holds its states strongly, so none of them can be going, and a render draw that keeps a listing without taking one is ordered before a release that has not finished. Release builds bound the stale listing without the check. It reached only the bind state's listing: the device heap set skips argument-sampler writes, and every layout binds the device's sampler table. So no live state read another sampler. The extra entry could change the argument samplers' shape class, and so the plan, until the slot was given back. Test: tests::sampler_release (a device test). A cfg(test) hook (sampler::going) holds the dropping thread inside SamplerShared's drop, so the order is the same at every run. The test lists a state through a compute dispatch, ends the encoder, drops the state on another thread, held mid-release, then dispatches from the kept state and lists again. Verified on the M3 Max, MoltenVK, --cfg m2v_gpu, debug: - Without the fix the test fails with the lane's panic (compute/live.rs:254:9, "its argument samplers"). With it, the test passes 5 of 5. - The runtime's and validation's sampler, argument-buffer, resource-ID, heap-set and draw-again tests: 177 of 177 pass. - The lane test passes 20 of 20 (nextest --stress-count 20) under the GPU lock. - cargo clippy --workspace --all-targets --all-features -D warnings is clean, plain and with --cfg m2v_gpu. (cherry picked from commit d0f906514415c05e21b5f5851c61a1866f33808d) (cherry picked from commit 16afd35fa0b536a75289e8e8d08b9f72490a6a82) |
||
|
|
589b3e3223 |
Build the settled-record tests only with debug assertions, as the counter they read
tests::draw_again's two settled-record tests read render::bound::dynamic_compares, a counter that exists only in builds with debug assertions, so a release build of the runtime's tests under --cfg m2v_gpu failed to compile (an unresolved import). The import, their helper (compared_by_each) and the two tests now carry #[cfg(debug_assertions)], as tests::shared_draw_locks does for its counter. Verified on the M3 Max: cargo check -p metal2vulkan-runtime --all-features --tests --release with --cfg m2v_gpu fails at the parent with error E0432 on that import, and passes with this change; clippy over the runtime's tests at --cfg m2v_gpu passes. (cherry picked from commit 92d96723e4ae02c8c162de0b87539d2d8a8a86f3) (cherry picked from commit c6b22216a5b9903cbc25498196afbe9605cf5abb) |
||
|
|
7626ab77fa |
Pin the runtime sources after the kept compute state's flags
Re-hashed; the change rides this stack's RUNTIME_VERSION 1758. (cherry picked from commit 7583fe5d99c0d0c584d0e70475a6dae74c923ba1) |
||
|
|
62b0650c1a |
Set a kept compute state's token-order and resident-apart flags as its whole state has them
LiveDispatch::refresh brings a compute dispatch's bind state in place, but left BindState::used_in_token_order and resident_apart at false, where DispatchTables::bind_state (d6f17f77ab, a38aeff464) sets both. The debug check check_whole then failed on every kept compute dispatch (616 of 1837 lane cases and 11 runtime device tests), and release builds bound kept compute states without the search and the trimmed root tables. Neither flag is part of the bind shape, the residency lists its used resources in token order, and a dispatch's memo is filled only after refresh, so nothing kept predates them. Verified: the indirect_dispatches, predication, first_use and stage_in_strides lane cases, 37 of them, pass under --cfg m2v_gpu on the M3 Max (debug). (cherry picked from commit 2d8616c74700cce4a28bcad52229a49e82aa9567) |
||
|
|
7333ad21e6 |
Bless the golden tables and printout for the resident_draws fixture
The resident-draws lane's fixture (engine/resident_draws, b023bcd97f) is new: its rows of the engine fixture inventory, its golden hashes and its golden AIR printout are blessed from the tests (bless_engine_inventory, the air_input ignored test, bless_golden_hashes). Only rows of the new fixture were added; no other cell moved. (cherry picked from commit a74a825bbf23c8ad347212cfc0d0ed4d6c819a0d) |
||
|
|
52cd1f328d |
Pin the runtime sources after the paced ahead import and the allocation-count limit
Re-hashed. The paced ahead import (9bbe4518ce) and the device's hold to maxMemoryAllocationCount (3766b1338e) change runtime behaviour, and ride this stack's RUNTIME_VERSION 1758, which no landed tree carries yet. (cherry picked from commit f38faec4d71a5866120b916bed24feac20d23376) |
||
|
|
cf7eae4420 |
Hold each device to maxMemoryAllocationCount; the ahead import stops short of it and gives back
What: - allocations.rs (new) counts each device's live VkDeviceMemory allocations, by its handle, at the runtime's two doors: - creation::allocate_memory, where every allocation goes; - release::object for vkFreeMemory, where every free goes. tests/exit_guard.rs already holds every allocation and free to those doors. So the count covers pooled and dedicated blocks, every host-pointer import (no-copy objects' own, guest RAM chunks, fresh pages) and every dma-buf import, with no caller passing it. A device is registered once its priming, which frees all it allocates, is done. Its registration goes with it. - At the limit, creation::allocate_memory refuses with ERROR_TOO_MANY_OBJECTS and does not call the driver. The refusal is counted in WorkCounts::memory_allocations_refused_at_limit. Callers handle it as they handle the driver's own refusal (memory.rs frees kept empty blocks and tries again). - The ahead-import thread stops where one more import would leave the device fewer than a quarter of its limit (Allocations::room_ahead). The remaining chunks are left to the objects over them, imported on demand as before. - Once an allocation leaves the device fewer than that quarter, a thread is spawned (Device::give_back_ahead_near_the_limit). It runs with no lock of the allocating caller held, and frees every chunk the ahead thread imported that no object took and only its slot holds. Counted in WorkCounts::host_ram_chunks_given_back. An object over such a chunk later imports it as it is made. - Scope: the ahead thread is started only in Device::use_host_ram (host_ram.rs, the one exit_guard::spawn of import_ahead). That call refuses a device without VK_EXT_external_memory_host, and its chunks are host-pointer imports (import_chunk -> memory::import_host). A no-copy object's own imports, by pointer or of the caller's dma-bufs (dma_buf.rs), never touch the RAM source and never start the thread. So RADV's per-object dma-buf imports are unchanged and never put all of RAM in GTT. That holds as long as the consumer calls use_host_ram only on devices that refuse dma-buf views, which reims-vgpu does: its os/linux/host_ram.rs hands the RAM only to devices that need imported pages mapped from their files. Why: - VUID-vkAllocateMemory-maxMemoryAllocationCount-04101: "There must be less than VkPhysicalDeviceLimits::maxMemoryAllocationCount device memory allocations currently allocated on the device". Nothing counted allocations before. - Importing ahead makes one allocation per 64 MiB of guest RAM whether or not an object ever uses the chunk. So the thread must leave the limit to the objects and never be the reason an allocation is refused. - The spec's minimum limit is 4096, so the margin is at least 1024 allocations. - The give-back runs on its own thread because the door may be called under the device's memory lock, which a chunk's free takes. A free of device-address memory can also wait for batches in flight (freed_memory.rs). Limits: - RTX 5080 laptop (NVIDIA 615.71.09): maxMemoryAllocationCount 4294967295, read by the device test. - M3 Max (MoltenVK 1.4.2, macOS 27.0.1): 1073741824, read by the same test. - At those limits, the margin and the refusal never come into play in practice. They hold for a device with a small limit. Verified on the RTX 5080 laptop, release, --cfg m2v_gpu: all 25 host_ram and allocations tests pass. Among them, the new device test the_ahead_thread_leaves_the_allocation_limit_to_the_objects: - It holds the device to a small limit (Allocations::limit_to, test-only). With 0 live, the limit is 5 and the margin 1. - The thread imports 4 chunks of a 12-chunk fresh RAM and stops. - An object over the 5th chunk imports it on demand. That allocation brings the device within the margin, and the 4 untaken chunks are given back (host_ram_chunks_given_back 4, host_ram_chunks_live +1). - Buffers of blocks of their own are then made until the device holds its limit. The next is refused at the door (Vulkan(VkResultCode(-10)), memory_allocations_refused_at_limit +1), with none of the thread's chunks live. On the M3 Max, release, --cfg m2v_gpu, the same test passes, the same way: limit 5, 4 chunks ahead, given back, then 2 buffers made and the next refused at the door. The runtime's whole host-side suite passes (1218 tests). The unit tests allocations::tests cover the refusal and room, the margin and the single give-back, and a registration's life. Not verified: a real device with a small limit (none of ours has one). The case where more than a quarter of the limit's allocations land before the give-back thread frees the chunks. That case is a race, bounded by the margin. (cherry picked from commit 15543aa261afa12b13bcda954fc5cb51063a6b0f) (cherry picked from commit 3766b1338e9b92367712cc4e9cf8f9a19dbe85e8) |
||
|
|
f739bea1eb |
host_ram: pace the ahead import, and import host pointers with the memory lock released
What:
- The thread that imports a used RAM's chunks ahead now runs as the system's batch work:
SCHED_BATCH on Linux, with its nice value kept, and the utility QoS class on Apple's systems.
- It yields between chunks.
- On Linux, before each chunk's import, it faults the chunk's pages in 2 MiB at a time with
MADV_POPULATE_WRITE, yielding between steps. That changes no byte. A kernel that refuses
the advice leaves the faults to the import, as before.
- memory::import_host (it was Memory::import_host) makes the vkAllocateMemory import with
the device's memory lock released, as import_own_pages and new blocks already do. It
re-locks only to record the block. Its callers are the chunk import (host_ram.rs) and a
no-copy object's own import (buffer_descriptor.rs).
- No CPU pinning, and no kernel, boot or module parameter.
Why: a reviewer accepted pinning all of guest RAM ahead on condition that the thread does
not stall the host while a VM starts.
- The pin of a 64 MiB chunk holds the VMM process's mmap lock while it faults in fresh pages.
Every mmap, munmap, and every page fault queued behind one, waits on that lock.
- The chunk import used to run under the device's memory lock, so every other placement on
the device waited for it too.
- A low-weight thread that holds those locks is worse, not better. On the RTX 5080 laptop
(24 threads, kernel 7.2), a thread faulting in 64 MiB pieces of a fresh THP memfd ran
against 24 or 48 spinning threads at nice 0. Another thread's mmap+munmap waited:
policy 24 busy: p99 / max 48 busy: p99 / max chunks faulted in 6 s
default 0.23 / 12.4 ms 3.6 / 26.9 ms 883 / 276
SCHED_BATCH 1.4 / 12.4 ms 11.2 / 13.9 ms 850 / 581
nice 19 131 / 511 ms 164 / 1012 ms 4 / 2
SCHED_IDLE 0.004 / 1039 ms 0.005 / 1419 ms 1 / 1
So the thread keeps the default weight (SCHED_BATCH only marks it as batch work) and paces
itself by yielding and by faulting in small steps.
Measured on the same laptop, release build, 16 GiB of fresh THP memfd RAM imported ahead
whole. "Unpaced" is the parent commit (df5beeecaa, in stack19 as 97a69f70ab). A sampler
thread timed mmap+munmap of one page every millisecond:
run time mmap p99 / max >10 ms compact_stall / fail / allocstall_normal
unpaced, idle, first run of a hold 5088 ms 57.8 / 98.8 ms 76 2411 / 183 / 67
paced, idle, right after it 8374 ms 7.5 / 45.9 ms 32 930 / 209 / 0
unpaced, idle, calm memory (x3) 1515-1824 ms 5.2-6.4 / 6.7-6.8 0 none
paced, idle, calm memory (x3) 1552-1600 ms 4.9-5.0 / 5.3-6.6 0 none
unpaced, 24 threads busy (x3) 2212-5649 ms 9.7-19.2 / 12.3-24.9 7-238 none
paced, 24 threads busy (x3) 3720-6693 ms 0.27-1.6 / 1.9-7.7 0 none
- The earlier unpaced measurement (batch at df5beeecaa) was 3.47 s, with compact_stall 1152
and allocstall_normal 54.
- Compaction follows the host's memory state, not the pace. Only the first run of each hold
met page cache to reclaim and fragmented free memory, and the hold that had it ran unpaced
first. So the compaction rows are not a like-for-like comparison.
- The pace costs time only when the CPUs are busy, where the thread now shares them. In
return, the process's other threads wait at most a few ms for the memory map lock.
- In calm memory, the remaining ~5 ms p99 is the import's pin of 64 MiB of resident pages.
Verified at the tip of this branch (this commit and the next), on the RTX 5080 laptop with
--cfg m2v_gpu, release: the host_ram device tests pass, including
chunks_are_imported_ahead_so_no_making_waits_for_one (4 chunks ahead in 31.6 ms, the slowest
of 40 heap makings 52 us). Clippy is clean with all targets and features, plain and with
--cfg m2v_gpu.
(cherry picked from commit aff66f6a5dc424d97854c0908dee022475e8dc01)
(cherry picked from commit 9bbe4518ceff598e5fa0172d5624f6af7a75b6a2)
|
||
|
|
b2ac8d2abb |
Pin the runtime sources after the settled draw record
Re-hashed: the settled record records the same commands, so RUNTIME_VERSION stays 1758. (cherry picked from commit d760d09a0a5022720876860825fa9d55f82b7e4a) |
||
|
|
7479e83c7a |
Compare no dynamic state on a rebound draw whose command buffer's record holds what it sets
A rebound draw recorded through the kept draw's recording, whose loop over the pipeline's dynamic states compared each state's value with what the command buffer's record (render/bound.rs) holds, at every draw: on reims-vgpu's draws.10k shape on the M3 Max that loop was 11.1% of the runtime leg's time (1760 of Recording::record's 2267 self samples of 15874, by its code range in the disassembly), every compare answering that the state is set already. A record now counts the recordings recorded through it and its beginnings again (Bound::records), and a kept draw keeps the count just after its recording, or the last draw rebound after it, recorded through its instance's record (Kept::settled). Where the record's count is still that, nothing was recorded through it since, so it holds the pipeline and the dynamic states that recording set, of the values a rebound draw sets again (the kept draw's state, topology and primitive restart, through the kept recording): the rebound draw records with the states no value of a record holds (KeptStorage::unheld, which every draw sets as before) and compares none of the rest (Recording::settled). The pipeline's check stays. The commands recorded are the same; only the compares are left out. Tests (--cfg m2v_gpu): - tests::draw_again::draws_rebound_compare_no_dynamic_state_their_record_holds counts, per draw, the compares of a dynamic state's value the encoding thread made (render::bound::dynamic_compares, builds with debug assertions): 0 at each rebound draw, some at a draw taking every step. With the rebound draw's settled check made never to hold, it fails: each rebound draw compared 16. - tests::draw_again::draws_after_a_state_set_or_a_barrier_set_what_every_step_sets: 15 draws with another blend color before the 3rd, a barrier inside the pass before the 7th and a barrier that splits the pass before the 11th, draws rebound between them, record the same commands of every kind, state commands and pixels as the same draws each taking every step, and the draws after the blend color and the in-pass barrier compare their states again (the one after the blend color records a state command). - render::bound::tests::a_record_counts_its_recordings_and_its_beginnings_again. The debug cross-check of a draw again carries the count over as it does the stamps. Measured: reims-vgpu's draws.10k (its draw_cost harness, the runtime leg, through its run.sh on the M3 Max; median [range] of 9 runs), instructions a draw: 12357.6 [12352.4, 12373.1] and 12356.9 [12351.1, 12392.5] at the step before (two runs), 11339.5 [11336.2, 11353.0] with this: 1018 fewer (8.2%). CPU ns a draw stayed within its ranges on a loaded host. The 5080 A/B (static, offset, bind, compositor, host) had not run when this was committed. Verified at its first base (691332c6c3) on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions: the runtime's whole suite, 1566 of 1567, the one failure the second test above as first written (its split case asserted per-draw compares where the draws after a split record after their calls; changed to check them by commands and pixels), then tests::draw_again's 10 of 10; clippy over the workspace, plain and at --cfg m2v_gpu. The validation crate's runtime lanes (frame_costs, render, draw_*, hazards, sync coverage, shadows, attachments, executions, degrade_notices): 299 of 300, the one failure a lane of compute and blit commands alone (degrade_notices::a_kernel_s_stores_into_private_bit_memory_reach_only_its_own_command_buffer), which passed alone at the step before and in a rerun of degrade_notices' 18 lanes with this. (cherry picked from commit 43094ca1b960f8b006b320d3cb569e1fb67a8921) (cherry picked from commit 20f53150d91087e92de9ad06404e6f6cbb780425) |
||
|
|
35110091d4 |
icb_setters --kept: the setters' cost after executions that kept every chunk
A consumer's frame executes the buffer and then encodes it again. After an execution kept its chunks' recordings (kept_commands.rs), each CPU write forgets the chunk it lies in through KeptChunks::wrote. With the --kept flag, the compute row now also times its encoding in that state. Before each repetition, untimed, a compute encoder executes every command twice, each time in a command buffer that is committed and waited for. The second execution runs every chunk from the first's recordings, and the bench prints indirect_chunks_kept for each second execution. This mode submits GPU work; the other modes still submit nothing. Verified on the M3 Max (MoltenVK, release) under maclock, one run, median of 6 repetitions x 16384 commands, every second execution running all 64 chunks from kept recordings: - parent e3444f3273: compute command 10187.8 instructions (589.3 ns), after the kept executions 13788.8 (826.3 ns); a set_kernel_buffer pass after them 2728.2 a call. - df69cd7b7a: compute command 2528.7 (163.4 ns), after the kept executions 6140.9 (406.7 ns); set_kernel_buffer after them 1168.2 a call, against 441.1 with nothing kept. Both sides pay about 725 instructions more per setter while chunks are kept: KeptChunks::wrote's retain walks over the kept chunks and the stepped set. That is the figure to compare a one-store invalidation against. (cherry picked from commit ac8eae71c9d063369c6568a2b38fb2fd30e22f47) (cherry picked from commit 2c542021bff8d4bb7f500b63e69cf35e6005bf3c) |
||
|
|
c667003ee6 |
Pin the runtime sources after the resident-draws costs and the cross-queue handler order note
Re-hashed with the runtime sources at RUNTIME_VERSION 1758; the translator's bind/ sources are among the hashed files. (cherry picked from commit cbb8bfbc5b8a1c52315c4919841e13187a95e215) |
||
|
|
bf7420081a |
Bump RUNTIME_VERSION to 1758: resident buffers by address index, heap members by search, root tables without the used resources
Residency::resolve looks addresses up in an index (9b680cf8da), a state in token order finds its heap members by search (a38aeff464), and root tables the commit points elsewhere no longer embed the used resources (d6f17f77ab). The last changes what a run of an unchanged artifact records (smaller root tables, fewer upload-arena buffers), so recorded runs are held to the new version. (cherry picked from commit 014ecaea6f4482c4a561bc3f7ed95d5cef6b6c64) |
||
|
|
34a49930d4 |
Say that two queues' completed handlers start in no guaranteed order, as on Metal
What: one sentence in follow.rs's module docs. A command buffer and the command buffer of another queue it waited for run their completed handlers on two handler threads. The signaller's are dispatched first, but which starts first is not guaranteed, as on Metal. Why: the docs said the signaller's handlers are dispatched first, which a reader could take as a start order. Metal gives none. Verified on the M3 Max under macOS 27.0.1, with a Swift probe of the same shape as submit_path's cross row (A fills 16 bytes and signals an MTLEvent, B on another queue waits for it and fills 16 bytes, each with a scheduled and a completed handler), 2000 rounds per row at gaps of 0, 100 us, 300 us and 2 ms, over three legs: - MTLEvent: Metal started B's completed handler first in 2-127 of 2000 rounds (0.1-6%), and B read A's status short of Completed in 0-73. - MTLSharedEvent: Metal started B's first in 0-2 of 2000. - In the same session the runtime at 13a5607aff started B's first in 0 of 2000 on every row. The status and completion-seen order the runtime keeps is unchanged. Comment only. (cherry picked from commit 67aa3ecaea7c2696372767c30dfc3cde820c4f61) (cherry picked from commit b75ff3ee9c4f5534cc666ff5e5789be9dfc82f1a) |
||
|
|
48036daff0 |
Hold the resident-draws lane to the draws' own bindings
The resident-draws lane checks what a frame costs of the resources made resident, whatever their count (assert_bounded). Root-table ranges noted are at most two a draw for the entry shape: its own binding in each stage that reads through it. The slot shape notes none, since its functions read no pointer. At most one address index is made per indirect command buffer execution, and none for the encoder's own draws. The check (each_path_draws_what_the_encoder_draws, N 300, both shapes and bindings, all three paths) asserts it a frame; the measurement asserts it over each case's timed frames. Verified on the M3 (release, --cfg m2v_gpu --cfg m2v_system_alloc): - The check passes under the validation layer. - The measurement at N 500, 1000, 2000 and 5000, 3 frames, passes its bounds. Each ICB frame made one index. The entry shape noted N ranges a frame (one a draw), the slot shape none. - At N 300, with RESIDENT_DRAWS_DUMP, every counter matches the parent's, apart from the new counters and the upload arena's buffers parked and recycled. The pixel hashes match too. Frame medians, parent (dd56c64399) -> this tip: | case | N 500 | N 1000 | N 2000 | N 5000 | |---|---|---|---|---| | entry own encoder | 46.8 -> 19.6 | 207 -> 78.6 | 915 -> 331 | 6636 -> 2502 | | entry own READ | 46.8 -> 20.8 | 211 -> 77.3 | 978 -> 344 | 6682 -> 2492 | | entry own WRITE | 45.4 -> 21.6 | 204 -> 80.7 | 970 -> 341 | 8408 -> 2474 | | entry one encoder | 8.8 -> 3.0 | 11.7 -> 5.0 | 15.9 -> 8.9 | 33.2 -> 20.6 | | slot own READ | 1.3 -> 1.3 | 2.3 -> 1.7 | 4.9 -> 4.0 | 27.7 -> 15.9 | | slot own WRITE | 3.9 -> 3.6 | 6.1 -> 5.6 | 12.3 -> 11.1 | 47.4 -> 33.2 | The slot shape's encoder path and its one-buffer binding are unchanged. The entry shape with a buffer a draw is still quadratic: 2.7x faster, not linear. What remains is each draw's walk of the plan's Used(token) uses (binding::command_uses_into and the code that consumes those uses), which is the draw path's to note once per change of the residency. (cherry picked from commit 671b5886674abe5861d5b9a5f1cc6d81f7f28ca9) (cherry picked from commit b55feb05a51910c40552e425772bb8e539d31c6c) |
||
|
|
81531d6c10 |
Keep the used resources out of root tables the commit points elsewhere
Every draw and dispatch whose functions read loaded pointers uploads a root table per stage
that reads one. Each table embedded the whole resident set: every bound buffer, every
Buffer and Heap made resident, every listed range, sorted and coalesced per command
(resident_entries). The runtime then copied and uploaded those bytes and added each range
to its command buffer's root_ranges. Yet the commit points every table at the command
buffer's own resident set (State::point_root_tables; a host step's table is pointed at
once), so the GPU never reads the embedded copy. With N draws among N resident resources
that was N^2 work and bytes: 13% of the M3 profile of the argument-table shape at N 2000.
BindState::resident_apart is a consumer's opt-in, not part of the shape. It says the
consumer points every root table of the command at a resident set it uploads apart
(ResidentSet, RootTable::resident_fields). That set must hold every Buffer and Heap of
used_resources and every listed range, as well as the table's own ranges. With the flag, a
root table's own resident set holds the bound buffers alone (resident::table_entries), and
RootTable::resident_ranges lists only those. Without it, nothing changes, and replay
preprocess tables keep resident_entries either way.
The runtime sets the flag on the states whose tables go through binding::root_table:
RenderLowering::refresh_bind_state, the compute bind_state and dispatch_tiles_resident. It
leaves it off for gpu_execute and the GPU form, whose tables carry live ranges and are
pointed nowhere. The set the commit points at already holds what was dropped:
State::make_resident adds the joined residency's resident_ranges (every encoder's used
buffers and heaps) beyond the live buffers, and first_submission's remake does too.
Counted: WorkCounts::root_table_ranges_noted (State::root_table).
Functions: bind::resident::{table_entries (new), coalesced (new), bound_allocations (new),
resident_allocations, resident_entries}; bind::graphics and bind::dispatch build root tables
from table_entries; BindState gains resident_apart; State::root_table counts its ranges.
docs/API.md says what the flag asks of the consumer.
Verified:
- bind::resident::tests::a_state_resident_apart_keeps_the_used_resources_out_of_its_tables
(300 pseudo-random states whose bound buffers, used buffers and heaps and listed ranges
nest, overlap, touch and repeat): without the flag the table holds resident_entries; with
it, the bound buffers' set. A set made of the table's ranges plus the used and listed
ranges, as the runtime makes its own, resolves every address alike either way. The shape
is unchanged. A negative control (an empty table under the flag) fails it.
- bind::resident, bind::heap, bind::graphics, bind::dispatch and pipeline::api_tests pass
(74 tests).
- M3 numbers at the tip of this series are in its last commit. At N 300, every counter but
the new ones is the parent's on every path and binding of both shapes, barriers and uses
included, except the upload arena's buffers parked and recycled (54 -> 4: smaller tables).
The pixels are the parent's too.
(cherry picked from commit dcda2dc0368867436fb37ac78af79265088d6596)
(cherry picked from commit d6f17f77ab484eef479aa15df9c08055cf1101da)
|
||
|
|
5b5f1847d8 |
Find a state's heap members by search where it lists them in token order
A handle table's bytes (bind::heap::table_bytes, inside every draw's and dispatch's
instantiation) and a plan's heap elements (BindingPlan::heap_elements, which the runtime
asks for at each draw) found each heap member's used-resource entries through a map built
for the call over every used resource: a BTreeMap entry and a Vec a token, for every
resource made resident, at every command. A pass of N draws among N resident resources so
cost N^2. In the M3 profile of the argument-table shape at N 2000 these two were 44% of the
frame.
BindState::used_in_token_order is a consumer's opt-in, not part of the shape. It says it
lists used_resources in token order (each entry's token at least the one before, so a
token's entries lie together; a debug build asserts it). The binder then finds a member's
entries by search, O(members x log n), and without the flag it gathers them as before
(UsedByToken::{Listed, Gathered}). The runtime sets the flag on every state it lists from a
residency: Residency::used_resources lists in token order, and tile_resources keeps that
order.
Functions: bind::heap::{UsedByToken::of, UsedByToken::get, member_id, handle_table_bytes,
heap_elements}; BindState gains used_in_token_order; the runtime sets it in
RenderLowering::refresh_bind_state, the compute bind_state, dispatch_tiles_resident,
gpu_execute's total and the GPU form's preprocess. docs/API.md says what it does.
Verified:
- bind::heap::tests::a_state_in_token_order_finds_its_members_by_search: 200 used
resources, members among buffers, one listed twice under one ID. The ordered state is
searched (Listed), the same state without the flag is gathered, and both give equal
tables and heap elements and the same internal errors for a member with two IDs and a
member not listed.
- The rest of bind::heap and pipeline::api_tests (the serde round trip names the field)
pass.
- M3 frame times at the tip of this series are in its last commit.
(cherry picked from commit d23e702339ce57f4a75cfae9f4a8247ff6875bd4)
(cherry picked from commit a38aeff46479332628c5350d73f7fc319635c713)
|
||
|
|
af7da0a0c0 |
Look resident buffers up by Metal address in an index, not a scan
Residency::resolve finds the resident buffer a Metal address lies in, for each binding
address of an indirect command buffer's records that commit or a host step records
(RenderExecution::buffers, indirect_execute's dispatches, kept_commands' resolutions and
runs_again). It scanned every resource made resident for each address, so a pass whose N
draws each bind a buffer of their own among N resident cost N^2 compares.
Now a residency holds an AddressIndex of its buffers and heaps' own buffers by Metal
address, made at the first resolve after a resource was made resident (Residency::join
resets it): the pieces of the space between their starts and ends, each with the first made
resident of those holding it, and each end with the first made resident ending there. It is
made in n log n, and a look costs log n. It answers exactly what the scan answered: the
first resource made resident holding the address, else the first whose end it is (an empty
binding), else the live table. Counted: WorkCounts::resident_address_indexes_made.
Functions: Residency::resolve, Residency::join (resets the index); new AddressIndex::
{of_used, of, first_holding}; WorkCounts::resident_address_index_made.
Verified:
- tests::residency (CPU) compares the index with the scan at every start, end and their
neighbours, over disjoint, adjacent, nested (heap before and after its buffers),
overlapping, empty and overflowing sets and 200 pseudo-random ones; it passes.
- M3, release, runtime_lane::resident_draws at the tip of this series: each_path_draws_
what_the_encoder_draws passes under the validation layer. One index is made per ICB
frame at N 300 to 5000. Slot shape, a buffer a draw, N 5000, frame medians against the
parent: ICB READ 27.7 -> 15.9 ms, WRITE 47.4 -> 33.2 ms. At N 300 every counter but the
new ones, and the pixels, are the parent's.
(cherry picked from commit 570058d7a0a36377d7511efb7829a7d86ead672b)
(cherry picked from commit 9b680cf8da27ee4eb163d5b7d695cfd61d4162af)
|
||
|
|
ff48dcac15 |
Check that resident-draws paths draw alike, and dump their counters
The resident-draws lane gains a check and a comparison knob. - each_path_draws_what_the_encoder_draws (a device test, under the validation layer): for both shapes, 300 draws (past a chunk of an indirect command buffer's records) with a position buffer a draw and with one buffer at offsets, on the encoder, ICB READ and ICB WRITE paths, draw exactly the pixels the encoder's draws of one buffer draw. The WRITE path's host step resolves each record's binding among the resources made resident, so this is the device leg of that resolution. - RESIDENT_DRAWS_DUMP=1 prints every counter a measured case's frames moved (from WorkCounts' Debug form, the time counters left out) and a hash of what its last frame drew, to compare two builds' uses, barriers and output. - The target is shared and read back; the sampled texture is filled. Verified: built (release, --cfg m2v_gpu); the device test's run is reported with the residency changes that follow. (cherry picked from commit dd56c64399b19589c1538e2173b41efccaed216f) (cherry picked from commit bb0dac90c20c862a13f84198c8208833df6cc3e5) |
||
|
|
c08e280864 |
Measure draws that each bind a resource of their own among many resident
A lane measurement (ignored, release, --cfg m2v_system_alloc) of a pass whose draws each bind a resource of their own while the pass makes every one resident, as a page's render bundle does with a bind group a draw: runtime_lane::resident_draws, over the new public fixture resident_draws.metal. Two shapes: slot (draw i binds position i as vertex buffer 0) and entry (draw i binds entry i, 24 bytes, of one argument table: a position pointer, a texture ID and a sampler ID, as vertex and fragment buffer 0, which both functions read through; the pass makes the positions, the table and the texture resident). Each with a position buffer a draw or one buffer at offsets, and on three paths: the encoder's own draws, an indirect command buffer's execution made resident for reading (commit records it) and for writing (a host step records it). It prints each case's frame time (encoding to completion), per-draw time and the device's counters; RESIDENT_DRAWS_COUNTS, _FRAMES and _ONLY narrow it. Verified on the M3 (release, 3 timed frames): the entry shape with a buffer a draw is quadratic on every path (frame medians N 500 47 ms, N 1000 201 ms, N 2000 898 ms, encoder, READ and WRITE alike), against 3.1 ms and 9.3 ms at N 500 and 2000 with one buffer; the slot shape stays linear (1.5 us a draw on the encoder at N 2000). (cherry picked from commit 8f27ac59877cec5b6c1286954ba3f9c8d1207644) (cherry picked from commit b023bcd97ffe9762b1dbe4e5cbff6957ac7ddc5e) |
||
|
|
410990ead6 |
Pin the runtime sources after linear merge runs, runtime-own check textures and in-place ICB setters
Re-hashed with the runtime sources at RUNTIME_VERSION 1757. (cherry picked from commit 2eb90a284f6400b964249762665e4e1f88dee105) |
||
|
|
408763813b |
Bump RUNTIME_VERSION to 1757: linear merge runs, runtime-own check textures, ID after refusals, in-place ICB setters
A run of passes over one linear attachment now merges once after its last pass (0bf36f1a1c), zeroed shadow merges borrow pooled scratch (83d6cb557e), the in-place check's textures take no texture ID (9c75fb4774), a texture takes its ID only once its making cannot be refused (8b3fc9ec8b), and an indirect command's setters write its field in place (d507c87849). Each changes what a run of an unchanged artifact records or answers, so recorded runs are held to the new version. (cherry picked from commit 3575e053d8d75cb685f93ed45b26552f831f0de3) |
||
|
|
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 |
||
|
|
da7b285ec7 |
icb_setters: the CPU cost of an indirect command buffer's setters
A bench for the cost a consumer pays to encode indirect commands on the CPU, every field of each command set by its own Metal-shaped setter, one thread, nothing executing. It has the shape of the consumer's report (rgk-icb-2): - render: a buffer of 16384 commands of DRAW alone, 2 vertex buffers and 1 fragment buffer, nothing inherited. Each command is indirect_render_command_at, set_render_pipeline_state, set_vertex_buffer twice, set_fragment_buffer and draw_primitives. - compute: CONCURRENT_DISPATCH, 3 kernel buffers. Each command is indirect_compute_command_at, set_compute_pipeline_state, set_kernel_buffer three times and concurrent_dispatch_threadgroups. Each repetition encodes every command once, over the last repetition's, and is timed as a whole: wall time, and on macOS the thread's own instructions and cycles (libSystem's thread_selfcounts, readable unprivileged). It prints the median a command with the lowest and highest. `--calls` also times each call kind alone, and the record format's own write_field of the same fields (no lock, no check): the floor of a setter's write. The pipeline states come from the owned fixture runtime_examples.ll through llvm-as. Nothing is submitted. Verified on the M3 Max (MoltenVK, release) at this commit's parent e3444f3273: median of 5 runs x 6 repetitions x 16384 commands, each run's median a command: render 588.0-599.4 ns, 10350.9-10351.9 instructions, 2107-2145 cycles; compute 578.3-588.1 ns, 10176.3-10177.5 instructions, 2083-2105 cycles. --calls: about 2000 instructions a buffer setter and 2288 for set_render_pipeline_state, where write_field of a field costs 130-213. (cherry picked from commit 5a88c91634f289aaaf9d866ecdf36b949f3ee45d) (cherry picked from commit 46a4a5d15cb7423a031650f9fc136e7470912174) |
||
|
|
74beed3761 |
Take a texture's ID only once its making cannot be refused
Four makings took the program's texture ID (Texture::made) before a last step that could still fail: - Device::texture_as and new_shared_texture: the decoded twin's start. - Both sparse makings: the tile map's first bytes. - A heap's texture: its twin's whole decode. A failure dropped the texture, and with it the ID, so the next ID came out as Metal's. Still, the ID was held while the step ran, where another thread's making could see it taken. The pool was also started, so a later reservation was ignored, for a making that returned an error. Each step now runs on the shared image before the texture is made: - Image::start_decoded_twin and Image::decode_whole replace the Texture methods. - Device::start_tile_map takes the image. On a fresh image, view_shadow::truth is the image itself, so the steps do the same work in the same order with the image's first moves. A heap texture's decode now comes before heap.hold_texture and the multisample tile planning. A decoded twin is never multisampled, and the decode needs neither. What still follows the ID there fails only on the runtime's own fault (internal). The resource_ids.rs module docs state the contract: a program's texture takes its ID as its making's last step. Verified on this M3 Max, through maclock and memcap, with the in-place check fix (the commit before): - 151 device tests of the touched families passed idle, among them sparse, heap, heap_tiled, twin_reads, twin_flights, bc_own_image, resource_ids and the ID tests. twin_reads' ASTC_4x2 texture lies in a carrier with a twin on every device. - The ID tests passed under load x3. - The runtime's static suite passed (1218 tests). Clippy -D warnings passed, plain and --cfg m2v_gpu. Rustdoc -D warnings and the api-signatures check passed. Not shown: a test where one of these steps fails, since none of them fails on a working device. (cherry picked from commit cea4dd4b0525e11babce87b899c7791614e28c08) (cherry picked from commit 8b3fc9ec8b20ff9bc1a81405699eb67bd4224f4a) |
||
|
|
de7ca47842 |
Make the in-place check's textures the runtime's own: they take no texture ID
The device's check of the first move in place (in_place_check.rs) runs on its own thread,
m2v-in-place-check. It made each texture through the public Buffer::new_texture at the default
placement, so each one took a plain program texture ID and held it through settle_in_place's
submit and wait. That is 3 page classes x 11 shapes x 3 rounds. The check starts when a texture
over host pages first asks for a verdict. Its verdicts are kept in the shader cache's content
store, keyed by driver, check version and RUNTIME_VERSION, so after a runtime bump the first
process runs the check again while the program goes on making textures.
A program texture made while a check texture held an ID got the next one. In the consumer's
texture_identifiers_are_metals on the M3, the check started at its texture over a surface
(ID 9). Under load its first texture landed between t7 and t8 and held 12, so t8 took 13 where
Metal gives 12, and every ID after it moved by one. The refused format-263 texture just before
t8 took no ID: descriptor.check() refuses it before any ID is taken. A check texture also
started the texture pool, so a program's reservation made after it was ignored ("reserve()
must be called before any allocation takes place").
The fix: Buffer::new_runtime_texture (pub(crate)) makes a texture over a buffer that takes no
ID (IdUse::Runtime). make_texture_over takes Whose::Program or Whose::Runtime, and the public
new_texture, new_linear_texture and surface-plane paths pass Program as before. The in-place
check makes its textures through it.
The tests (device tests, m2v_gpu):
- tests::in_place_check::the_in_place_check_takes_no_texture_id (deterministic). Settle the
check, reserve texture ID 5, make 5 textures: Metal's IDs are [1, 2, 3, 4, 6].
- tests::in_place_check::texture_ids_keep_metals_order_while_the_in_place_check_runs (the
race). Make and drop a texture until the check settles; every one must take ID 1.
- tests::internal_texture_ids::the_runtime_s_own_textures_take_no_texture_id (guard). Program
textures made around a pass of separate depth and stencil textures (combined scratch) and a
memoryless attachment's pass (kept backing) take 1 to 7 in order.
Verified on this M3 Max, through maclock and memcap:
- The test binary built before the fix, idle, failed both in-place tests:
- [1, 2, 3, 4, 5] instead of [1, 2, 3, 4, 6].
- 53981 textures made while the check ran, 325 of them at ID 2 ({1: 53656, 2: 325}).
- internal_texture_ids passed.
- The same binary under 16 `yes` loops, the race test x3, failed all three: ID 2 for 829,
868 and 2698 textures.
- The fixed tree passed all 4 in_place_check and internal_texture_ids tests under the same
load x3. The race test saw only ID 1, for 62779, 54485 and 61885 textures. The deterministic
test ran the check each time (no "made no texture" skip line).
- The fixed tree passed 151 device tests of the touched families idle (in_place_check,
internal_texture_ids, resource_ids, sparse, heap, heap_tiled, twin_reads, twin_flights,
bc_own_image, buffer_texture, in_place, freed_memory, wrapped, texture, surface_two_planes,
rotated, ycbcr_device, texture_descriptor, kept_images, surface_depth).
- The runtime's static suite passed (1218 tests). Clippy -D warnings passed, plain and
--cfg m2v_gpu, all targets and features. Rustdoc -D warnings passed. The api-signatures check
passed (no public item changed).
RUNTIME_VERSION and the runtime-sources pin are not bumped here: that is the owner's step.
(cherry picked from commit bc5421fa54621bdb954cb457fd1e2cbc36b8406e)
(cherry picked from commit 9c75fb477421278b8ea20c50d77bf59d4cc7c318)
|
||
|
|
f7f4e11859 |
Lend shadow merges that need zeroed scratch too, filling it with zero before each keep
A shadow merge whose kernel reads bytes no copy writes (one not cut to rows of whole words: a merge through a copy, as for a command that writes a texture's bytes two ways, or one over several regions) made a new zero buffer of up to three times the texture's bytes for every merge, held until the command buffer completed. A command buffer of many such encoders so held one a merge, as the lent scratch of the other merges no longer does (merge_scratch.rs). Now such a merge takes its scratch as every other does (the command buffer's pool, then the shadow's spares, else a new one unzeroed) and fills its parts with zero before each keep (ShadowMerge::record_zero: vkCmdFillBuffer of its parts, then Barrier::everything), on both keep paths (record_keep and the keep from the staging buffer). The keep's tracked uses include the fill's write of the parts. A scratch past the device's largest buffer is still a new zero buffer a part. The shadow's spare is now taken only where the pool lends none (it was taken and dropped when the pool lent one). WorkCounts::shadow_merge_scratches_zeroed keeps counting these merges; shadow_merge_scratches_reused counts their loans. Test (device, --cfg m2v_gpu): tests::merge_scratch::two_ways_merges_take_few_scratches: 64 compute encoders in one command buffer, each writing texel (0, 0) of a shadowed texture over a Private buffer of padded rows (200 texels in rows of 1024 bytes) and 4 bytes of the same buffer another way: every merge needs zero, the merges after the first take a lent scratch, encoding them grows the device's memory by less than an eighth of one scratch a merge, and the bytes hold both writes of every encoder and every other byte its first. Passed on the M3 Max (64 zeroed, 63 reused) and on the RTX 5080 Laptop GPU (64 zeroed, 63 reused), with tests::linear_runs and the rest of tests::merge_scratch (8/8 on each). Negative control (this test against shadow_merge.rs and shadow.rs as before, on the M3): it fails, 64 zeroed and 0 reused. clippy --all-targets --all-features -D warnings, plain and --cfg m2v_gpu. (cherry picked from commit a543f6428de4c1d6d95a6afa181975b0a1e453ef) (cherry picked from commit 83d6cb557ed3a464fcb2531a99a3704847ad0313) |
||
|
|
d1eb2b8ccd |
Merge a run of passes over one linear attachment once, after its last pass
A linear attachment rendered apart (a texture over a buffer's bytes beside a depth or stencil attachment on NVIDIA, VK_NV_linear_color_attachment's rule) copied its box into the kept image, kept it, rendered, and merged the changed words back, every pass, each step between barriers from every command to every command. A WebGPU frame split at every indexed draw (stencilprobe -P: 706 passes over one surface in one command buffer) paid that 706 times. Now consecutive passes over one attachment form a run (linear_run.rs) under a conservative rule: the run's first pass copies in and keeps as before; each later pass whose box lies in the run's renders over what the pass before left in the kept image, with no copy in and no keep; and each pass leaves its merge to its batch's submission (Deferred::LinearMerge, a segment after its own command buffers), which the next pass of the run takes over, so only the last pass's merge is recorded, in that pass's place, between the same barriers. The merge compares the first keep with the image the last pass left, so it writes every word one of the passes changed. Its uses are noted as each pass ends (EncoderCore::note_left_uses), so the tracker orders later work after a write of the bytes as before. A run ends (its merge recorded where its last pass left it, its scratch lent on) at: - any encoder between its passes but a render encoder (blit, compute, resource state); - a render encoder whose commands name the surface's buffer or its host range, reach memory they do not name (root or handle tables, heaps, executions, a barrier inside the pass), wait for or update a fence, resolve, write visibility results, record later (pending draws, tile dispatches, later color groups), or that attaches those bytes or renders that kept image; - an event or semaphore wait or signal, or a host step (any new batch, RunPoint); - a pass whose box reaches past the run's (the next run then covers the whole render area); - the command buffer's end. A pass joins only where it is encoded once: neither its commands nor its attachments name a buffer over host pages (which a rebind encodes again), no rasterization-rate map, no execution, outside a predicated loop's laying. An encoder encoded again changes no run, and its linear merges borrow no scratch from the pool, since its place may lie inside a run's span. The 1x1 attachmentless encoders of stencilprobe -P name nothing of the surface and pass a run. LinearMerge::lend is now once only (a run's merge is lent when the run ends). Counted: WorkCounts::linear_merges_recorded and linear_merges_taken_over (new; api_signatures blessed). Touched pass-end and submission code (kept small): render.rs end_pass (the run decision before the copies in, the keep skipped for a pass going on, the merge left to submission), encoder.rs (RecordedSegment::submitted, note_left_uses, encodes_again), command_buffer/submit.rs record_scrubs (records a run's merge, a taken-over one records nothing), deferred.rs (the variant), command_buffer/mod.rs (State::run_point, linear_runs), tracker.rs (EncoderUses::fenced). Tests (device, --cfg m2v_gpu): - tests::linear_runs (runtime crate, new): one command buffer of 26 steps over a linear target (Shared and Private buffers, packed rows of 1024 bytes), the rule forced: passes over it beside a cleared depth attachment, 1x1 attachmentless encoders, passes over another texture, a pass binding the target's buffer, blits reading its texels mid-sequence, an event signal, and a pass whose box reaches past its run's. 17 passes, 7 runs: 7 merges recorded and 10 taken over; with a blit between every two encoders (every pass merging after itself) 17 and 0; the texels each blit read and those left at the end equal a private texture's under the same steps, both ways. Passed on the M3 Max (MoltenVK 1.4.2) and the RTX 5080 Laptop GPU. - tests::merge_scratch (runtime crate): 240 passes over Shared and Private targets now one run each on both devices (1 merge recorded, 239 taken over, one scratch made); texels equal the private texture's. Passed on the M3 and the 5080 (8/8 with the next commit's test). - Negative control (this tree with the run decision off, run_point always None, on the M3): both linear_runs tests fail (17 merges recorded, 7 expected) and the three linear merge_scratch cases fail (240 recorded). - runtime_lane::linear_attachments::many_passes_* (validation): assertions moved to runs. - clippy --all-targets --all-features -D warnings, plain and --cfg m2v_gpu (runtime and validation); the runtime's plain unit tests (1213 passed); api_surface and api_signatures. Measured: RTX 5080 Laptop GPU (msi-laptop, release, the stencilprobe -P harness: one command buffer, a clearing pass and 706 passes loading colour and stencil beside a Depth32Float_Stencil8 attachment, a 1x1 attachmentless encoder between them, 1400 encoders; target over a Private buffer, 1024x1024 BGRA8Unorm, rows 4096; three runs a process; SCHED_OTHER under the GPU locks), base 896214a5b0 against this commit: commit to completion 81.9, 74.4, 71.2 ms before; 18.1, 11.2, 9.5 ms after (3 runs then 1 run a command buffer: 3 then 1 merge recorded, 703 then 705 taken over); encoding 63.0, 22.5, 21.2 ms before, 50.2, 19.5, 19.1 ms after. The M3 renders this target in place (no rule), so it has no such passes to measure. (cherry picked from commit 5d2b237e1a561153b3bcce58c459768e2a83e38a) (cherry picked from commit 0bf36f1a1cad63fe37da128db30d86580fcd4528) |
||
|
|
d240b99a7c |
tests::merge_scratch: put the padded Private rows case back, its texels laid out as the reference's
The case of a Private buffer whose rows hold bytes between them (200 texels in rows of 1024 bytes) was dropped from 6fa0708f5e as a runtime bug the base shared: after 240 passes 8800 (M3) and 10516 (RTX 5080) of its 76800 texel bytes differed from a private texture's. The fault was the test's: its first bytes were a pattern of each byte's place in the buffer, so a target with bytes between its rows started with other texels than the reference, whose rows are packed; blending at alpha 0.5 hid the difference wherever enough passes covered a texel. The pattern is now of each texel byte's place among the texels, the same in any rows, and the bytes between the rows hold 0xa5 again, checked unchanged after the passes. What the runtime does there (the RTX 5080, a scratch experiment against a private texture, pattern by texel): the texture is a shadow on every device (an image over the rows would hold the bytes between them), copied back rather than merged (a tracked Private buffer's bytes have no other writer): 19200 texels copied in once, 19200 copied back each pass; with 1, 2, 3 and 240 passes, with and without a depth attachment, in one command buffer or one each, over a Private buffer or a Shared one (merged back there): 0 texel bytes differ, 0 bytes between the rows change. The copies move the texels' rows alone, never the bytes between them. Verified: tests::merge_scratch (--cfg m2v_gpu) on the RTX 5080, 5 of 5, the padded case among them; clippy -p metal2vulkan-runtime --all-targets --all-features -D warnings with --cfg m2v_gpu. (cherry picked from commit 896214a5b05a652cbf9ae49fae1c2f44f2b0dc3b) (cherry picked from commit f296b0eef66b3663f1901d09a0f4fb72f87ed282) |
||
|
|
f73718882a |
Re-bless the conformance cost records on the M3 Max at 13a5607aff, with timing for the four Accumulate cases
Measured on the M3 Max (macOS 27.0.1, MoltenVK 1.4.2), with a debug build of 13a5607aff's tree, under one maclock hold: - cost --runs 8 --write over the whole set: 1127 cases, 1118 measured, and the same 9 the venue cannot measure, each stopping where its committed record says. - cost --runs 8 --alone --write over the 331 cases newly covered, newly bounded or moved. Most of them moved only in counts the race rule names (scheduler_*, object_churn.*, wakes_*). - times --runs 8 --write over visibility-counting-accumulate, visibility-counting-accumulate-one-command-buffer, visibility-counting-accumulate-revisit and visibility-boolean-accumulate. On time, visibility-boolean-accumulate is unmeasured: our leg announces metal2vulkan-degrade-device-boolean-visibility. Against 13a5607aff's records, by cost::drift on the M3 venue: 38 differences over 15 cases, plus 4 cases newly covered (the four Accumulate cases). - 18 gated bounds: 16 fell, 2 rose. - 14 counts the gate gives up. - 6 counts it takes on. - No ceiling or per-state ratio moved. The gated bounds: - Fell, 34e44e3a12 (Boolean results without the resolve): visibility-boolean-indirect-no-instances, -occluded, -offsets, -revisit-after-covering and -revisit-after-nothing, and visibility-counting-offsets. Their cmd_bind_pipeline and cmd_bind_descriptor_sets fall (offsets 4 -> 2, the others by 1). In the two revisit cases, cmd_dispatch 2 -> 1 and owned_descriptor_pools 2 -> 1. - Rose, required by 9f47ebcf00: host-page-writes-visibility-read-only and -writable, replay_log_bytes 1488 -> 1496. A kept render log counts size_of::<RenderPassDescriptor>() (render/replay.rs, RenderLog::bytes), and the descriptor gained visibility_result_type, a one-byte enum padded to one more 8-byte word. Each case keeps one render log. No other commit in 2b55ab415e..13a5607aff touches render_pass.rs. The three mesh cases withheld at 2b55ab415e, indirect-mesh-commands-object-threadgroup-lengths, mesh-commands-unordered-draws and mesh-commands-own-state, are written here. With 2a23d1882c, their gated counts read as their committed records do, from before 922caf3199. The counts the gate takes on are theirs (heap_tables_worked_out, resident_resources_joined). Withheld: indirect-render-commands-inherited-state keeps its committed file whole. Its rise is 922caf3199's chunk contexts (arena_pools_made 1 -> 3, argument_objects_retained 2 -> 6, argument_tables_retained 1 -> 3), and stays visible until that execution records apart only from its second unchanged run. cost --runs 8 --check over the whole set on these files exits 1. Its 3 gated differences are exactly inherited-state's three, and nothing else is load-bearing. The reach is 4 counts given up and 2 taken on: inherited-state's two new counters, and four racy counts dropped from gating at an equal value (visibility-counting-accumulate batches_submitted_by_waiters, detach-in-a-completed-handler memory_frees.blocks and .host_import, fresh-pattern-70 gate_waits_slept). (cherry picked from commit 3b60c7e185156f42471fe6e1fb30910ebe9f8c5b) |
||
|
|
64b07293af |
Pin the runtime sources after visibility results, mesh chunks, cross-queue completion and the step-2 fix
SEMANTICS 1957 and RUNTIME 1756 say what changed. Hash from the pin derivation over the listed runtime and translator sources. (cherry picked from commit 13a5607affadf1c83a6562ae619faeb1e041ce72) |
||
|
|
e346a8f7f5 |
Bump SEMANTICS_VERSION to 1957 and RUNTIME_VERSION to 1756: visibility results, mesh chunks, cross-queue completion
- SEMANTICS 1957: the binder's visibility combine module's words change (Boolean results are the device's nonzero query result with no resolve; Accumulate takes the buffer's words in, Counting in their low 32 bits as the M3 does), and the Boolean result is a new precision notice. - RUNTIME 1756: visibilityResultType is built; a buffer of mesh or patch draws alone keeps no chunk; a command buffer that waited on another queue's GPU signal completes after that queue's command buffer. Stacking note: the cross-queue measurement commit met checks at commit's --checked flag in the submit_path example (its usage line and imports); both are kept. The draw path's step-2 fix is pin-only. (cherry picked from commit 9e1ccf432beacdea484c8797a530d0707fb78e62) |
||
|
|
0b7aba796c |
Measure cross-queue completion order and latency in submit_path
What: submit_path gains a `cross` mode. Command buffer A on one queue signals an event at its end and command buffer B on a second queue waits for it on the GPU. The mode prints A's commit to A's handler and to B's handler (p50, p90, p99), and how many of 2000 rounds ran B's handler before A's. It covers shared and plain events, completed or completion-seen handlers (`--seen`), and gaps of 0 and 2000 us between rounds. Why: it measures the completion order the previous commit fixes, and its cost, on any device the example runs on. Verified on the M3 under MoltenVK 1.4.2: it ran before and after the fix, two pairs each. Before, 3/2000 rounds ran B's handler first (plain events, 2 ms gap); after, 0. The latencies are in the previous commit's message. (cherry picked from commit 521479bb0bf6324131f4fcf0fe9519b84d011160) (cherry picked from commit 85c5343c65375ef437ff17bb5328bda381cc1438) |
||
|
|
30deedf1d1 |
Complete a command buffer after the other queue's one whose GPU signal it waited for
What: a command buffer B whose work waits on the GPU, through an event, for a signal that command buffer A of another queue keeps at its end now never completes ahead of A. Its status, its completion-seen handlers and its completed handlers come after A's, as Metal's completion follows the GPU's. Why: on the M3 under MoltenVK, reims saw B's completion handler run before A's in 20 of 20 runs (Metal: A first, 8 of 8). There were three causes, the first by far the most frequent: - A's and B's transitions were posted to two handler-pool threads, so B's could finish first. - B's transition ran on the waiter while A's was still posted. - The completion turns took B's batch before A's: the takes ran in queue-index order, or B's waiter turned first. How: - Take order (completion.rs): a batch lists the other queues' batches whose kept GPU signals met its waits and were unfinished when it was submitted (`Submitted::after`, through `EventTimeline::signallers`). The completion turns take it only after those. The test is per front batch, O(1) where nothing is listed. Counter: `batches_held_for_another_queue`. - Transition order (follow.rs, contexts/lines.rs): A carries a `Follow` that the events hold beside its kept signals. Where A's transition leads its context (it was posted and nothing there runs before it), B's transition is posted behind a gate in its own context, keeping its place. The gate opens once A's transition has its status final and has run its completion-seen handlers, which never block. While waiting, B holds no thread. Where A's transition is behind any other item, B goes on: a blocked handler of A's queue does not hold back another queue, as with Metal. Counter: `command_buffers_completed_after_another_queue`. - A `Follow` names its command buffer by address alone, so the waiter never holds A's last reference, nor the device's. - No new lock on the completion path: the gate check takes the context lock only for a command buffer that waited for another queue's kept signal. Verified on the M3 (MoltenVK 1.4.2): - New device test `completion_order` (50 rounds per shape, over shared and plain events, both queue orders and five handler shapes). It asserts that A is Completed when B's handlers run and when B's wait returns, and that A's handlers come first. A second test checks that a blocked handler on A's queue holds back A and not B. - Fixed tree: 12 of 12 runs passed both tests. Counters per run: held 0 to 3, completed after 1 to 10. - Negative controls, 2 runs each: - the gate off: failed with status and seen-order breaks; - the take order off: failed with status breaks; - both off: failed. - Device-free: runtime and conformance suites 2225/2225; api_signatures, fast_paths and api_surface pass. clippy is clean (plain and --cfg m2v_gpu). The private rustdoc count stays at its ceiling of 70. - Latency, submit_path on the M3, two base/fixed pairs: single-queue commit-to-handler p50 at gap 0 is 205-239 us before and 245 us after (completed), 199-206 before and 235-239 after (seen); the pairs overlap and swap at gap 2000 (607/605 before, 628/564 after). - Cross-queue, A's commit to B's handler p50 at gap 0: shared 405-482 us before, 506-558 after (A's handler itself moved alike, 212-254 to 265-295); plain 364-375 before, 346-350 after. - B ahead of A in that probe: 3/2000 twice before (plain events, 2 ms gap), 0 after. - Not run on NVIDIA: the 5080 had a VM running at every check. (cherry picked from commit dc164b7608a184420aef1a4d5573218a5c4b0466) (cherry picked from commit 53f6f039d0d8b7cefee48c800cd4b90f43c50d57) |
||
|
|
7148b9518f |
host_ab: draw_host, each draw's vertex buffer bound at the next 256 bytes of no-copy host chunks
The encode workload gains a variant over the buffer kind a guest's setVertexBytes: reaches the runtime through: no-copy buffers of 64 KiB over host pages (one mapping, a buffer a chunk, 256 draws' rectangles each), each draw binding the chunk its rectangle lies in at its offset (setVertexBuffer:offset:atIndex:), as reims-vgpu's draws.10k measurement does. The other variants draw as before (encode_draws takes the chunks, empty for them). Verified: clippy over host_ab, all features. Run on the RTX 5080 Laptop GPU at the lane base and at the draw path's step 4 (one run each, 3000 and 9000 draws a pass, encode us a draw): draw_host 0.642 / 0.617 and 0.584 / 0.528, draw_offset 0.536 / 0.532 and 0.490 / 0.516. (cherry picked from commit 691332c6c3076d78b68abed22960227d3c220e27) (cherry picked from commit 07145d5cfde93f81acf46fe8ae84e306cd2760ae) |
||
|
|
32b1920f21 |
Work a buffer use's access out at its callers, with bytes_use infallible and inline
Step 2 (patching a rebound draw's buffer uses in place) moved the making of one buffer use into binding::bytes_use, which command_uses_into calls for each buffer use of every draw that takes every step, and which returned a Result: it worked out the use's access flags from its class (fallibly) and checked its source index's width per use. On the 5080 the shapes that never take the patch read slower after step 2 in two A/Bs (bind 0.848 -> 0.884 and 0.960 -> 1.014 us a draw, compositor 1.089 -> 1.127 and 1.207 -> 1.266, medians of 6 samples each, wide ranges). bytes_use now takes the use's reads and writes as its callers work them out and returns the use: command_uses_into works the access out from the class as before every step did, and patch_buffer_uses keeps the accesses of the use it patches, which its class made. The source index's width is checked once a command, for its whole count of uses, where it was checked per use. The uses made are the same. Measured. M3 Max, whole-process instructions a draw (two runs of 3000 and 9000 draws a pass, 23 passes each), step 1 / step 2 / step 2 with this: bind 16601 / 16882 / 16338, compositor 19039 / 18466 / 18852, offset 12430 / 11940 / 11871: mixed signs within about 600, so no cost of step 2 on those shapes stands out of the noise there, nor any gain of this. 5080, interleaved A/B of 6 samples in 2 exclusive holds, us a draw, median (range): bind 0.960 (0.871-1.406) / 1.014 (0.908-2.585) / 0.988 (0.909-1.790), compositor 1.207 (1.133-3.339) / 1.266 (1.190-2.271) / 1.258 (1.168-2.254), offset 0.629 / 0.616 / 0.602. The 5080's main-thread perf counts spread too far to read (offset 11770 to 21885 instructions a draw across binaries whose encode times sit within 0.05 us). A neutral change, kept as correct and built. Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions, on step 4's tree with this: the runtime's whole suite, 1551 of 1551; the validation crate's runtime lanes frame_costs, draw_* and render, all passing; clippy over the workspace at --cfg m2v_gpu. (cherry picked from commit f44082d4e309bbc18e5cdac3cb232b560c7134a6) (cherry picked from commit a087c926bcf9f250436db564d1645ff122f9c560) |
||
|
|
12f58a227f |
Keep no chunk of a buffer of mesh or patch draws alone: none of their draws is plain
922caf3199 records an execution of commands the CPU encoded chunk by chunk, each chunk apart from a KeptContext of its own (a command pool, descriptor arena and uploads), and keeps a chunk whose draws are all plain. A mesh draw and a patch draw are never plain (render/executions.rs clears RenderLowering::replay_plain for both), so on a buffer whose command types hold neither DRAW nor DRAW_INDEXED every chunk recorded apart was found not plain, noted, and its execution finished through the apart encoder. That cost a command pool and two more primaries, each with a barrier, on the first execution, and kept nothing. RenderExecution::keeping now admits only a buffer whose command types intersect DRAW | DRAW_INDEXED (the test settle already makes). A buffer of mesh or patch draws alone records as it did before 922caf3199. A buffer that mixes them with draws of primitives keeps today's path. docs/FAST-PATHS.md's known gap lists the buffers that still record at every commit. Runtime behaviour: such a buffer's executions record no chunk apart. An execution of a chunk of resets alone on one of them, which draws nothing, is no longer kept either. The cost gate showed the redundant work as three conformance rises, now withheld in the records, all from 922caf3199. Each case measured alone, debug, M3 Max, over 8 runs: - indirect-mesh-commands-object-threadgroup-lengths: command_buffers_begun 11 -> 9, continuations 3 -> 1, submitted 8 -> 6, cmd_pipeline_barrier 14 -> 12, end_command_buffer 11 -> 9, encoder_command_buffers_begun 9 -> 7. - mesh-commands-unordered-draws: 9 -> 7, 3 -> 1, 6 -> 4, 11 -> 9, 9 -> 7, 8 -> 6. - mesh-commands-own-state: 10 -> 8, 3 -> 1, 7 -> 5, 13 -> 11, 10 -> 8, 8 -> 6. command_pools_made fell 2 -> 1 in each. Every gated count equals its value at c00efdc7c0, 922caf3199's parent. The remaining differences are scheduler_sleeps, scheduler_wakes_host and submit_stalls_on_work, which the race rule names. Test: runtime_lane::mesh_commands::a_buffer_of_mesh_draws_alone_records_no_chunk_apart executes the CPU's own commands on a buffer of both mesh kinds twice, after another buffer's execution. It asserts the first execution begins as many command buffers as the second, and that both draw Metal's words. Verified on the M3 Max (--cfg m2v_gpu): it passes with the fix, and fails without it (left 9, right 7). own_commands_draw_metals_words, which now shares encode_own, passes. clippy -D warnings, all targets and features, with --cfg m2v_gpu, is clean for metal2vulkan-runtime and metal2vulkan-validation. RUNTIME_VERSION and the runtime-sources pin are left to the stack. (cherry picked from commit 132d0aeea055b9a3819c82619a12e3c4adf32646) (cherry picked from commit 2a23d1882ceb4cd21506af2a66f92f8258b5b2b2) |