b2ac8d2abbd9a55823f8a374727b91c8b4ded1bb
1296
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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) |
||
|
|
61a9508e92 |
Build visibilityResultType: Accumulate takes a pass's results into the buffer's words
RenderPassDescriptor gains visibility_result_type (MTLVisibilityResultType: Reset, the default and today's behaviour, and Accumulate). Under Accumulate no query result is copied over its offset's word: every query of an offset, the first one too, is copied into the upload region the continuations already use, and the crate-owned combine takes them into the word as the buffer holds it. The combine already loaded the destination word as its accumulator, so Accumulate is the first query becoming one more source. A `Boolean` word ORs the device's results in; a `Counting` word is summed in through a new table mode of the combine, into the word's low 32 bits alone, wrapping there, its high 32 bits kept (ContinuedResult::low_half / in_low_half). That last part is what the M3 Max answered when recorded: 0xffff_fff8 plus 16 samples writes 8, and 0xffff_ffff_ffff_fff8 plus 16 writes 0xffff_ffff_0000_0008. A plain 64-bit sum was divergent there. An offset set with no draw after it keeps its word, because a query with no draw adds 0. Where a no-copy buffer's bytes start off a multiple of 8, so the results land in an upload region, the words are now copied into that region before the combine (Landing::inward). Reset records exactly what it did before. Conformance: RenderPass gains visibility_type (typed()), and words() appends it only where it is not Reset, so existing fingerprints read as before. Both sides set it. There are four new visibility cases, recorded on the M3 Max (macOS 27.0.1): visibility-counting-accumulate (two command buffers; words 100/5/7/0xffff_fff8/u64::MAX-7), visibility-counting-accumulate-one-command-buffer (two passes in one command buffer, read once), visibility-counting-accumulate-revisit, and visibility-boolean-accumulate (words 0/2/3 under covering and non-covering draws, an offset set with no draw, then a second command buffer). The family's acts key states the type, and a joined shape adds a command-buffer input. Cost and timing records for the new cases are not written here. Lane tests (runtime_lane): accumulated_counts_add_to_the_words, accumulated_booleans_or_into_the_words, and host_bytes::accumulated_visibility_results_land_where_their_bytes_lie. Unit tests: the combine's accumulated_counts_are_summed_into_the_low_half, its plan's table mode, and the type's raw values. Coverage: coverage.tsv marks MTLRenderPassDescriptor.visibilityResultType implemented (its unused "visibility" group is removed), and METAL-COVERAGE.md is regenerated. MTLVisibilityResultType joins the enum table, so metal_enumerators.tsv and CONFORMANCE-COVERAGE.md are regenerated. The API signatures are re-blessed. REFUSALS.md is regenerated: VisibilityResultType::from_raw is one more UndefinedValue site. The regeneration also picks up two bind/graphics.rs sites the committed file was missing. The degrade docs (landed results, Boolean) state Accumulate. Verified on the M3 Max under MoltenVK 1.4.2: - The 52 visibility-touching lane tests pass: visibility, host_bytes, depth_never, amplified_draws, degrade_notices and the framebuffer_fetch split pass. - The visibility family's replay is all announced (no divergence), after the low-half change. - Negative control with Accumulate forced to Reset: all three Accumulate lane tests fail, and all four new cases replay divergent. - Negative control with no inward copy: the landing test fails at 4 bytes past a page (2 read 0, 100 read 16). - Before the low-half change, visibility-counting-accumulate replayed divergent at words 3 and 4. - The combine's low-half test fails on the interpreter without the high-half select ([8, 1] for [8, 0]). clippy (plain and --cfg m2v_gpu), rustdoc and scripts/api-docs are clean. SEMANTICS_VERSION: no translated shader changes, but the owned combine module's words do (main's call). RUNTIME_VERSION and the runtime-sources pin are not touched here. (cherry picked from commit 1c172968ad6492cebcae2a568fc99e90565d4d11) (cherry picked from commit 9f47ebcf006920f7561a16a77f77e422de7201c1) |
||
|
|
d806c0a792 |
Write Boolean visibility results as the device's nonzero query result, without the resolve
Metal's Boolean visibility result is nonzero where any sample passed and 0 otherwise. The Apple M3 Max writes 1; Metal on the AMD Radeon Pro 5300M and the Intel UHD Graphics 630 (macOS 26.7.1, the reims-vgpu team's probes) writes the samples that passed. The runtime had a crate-owned dispatch (bind::visibility_resolve_module) after every pass with a Boolean offset whose only job was to rewrite that word to exactly 1. Under AGENTS.md rule 1 the device's native answer is the only form: a Boolean result is now the imprecise occlusion query's own result, which Vulkan states as "When any samples are passed, boolean queries will return a non-zero result value, otherwise a result value of zero is returned" (occlusionQueryPrecise). Across a split pass's render pass instances the combine still ORs the continuations, so zero stays zero exactly where no instance passed a sample. Counting queries stay precise. - Runtime: the resolve's plan, uploads, sets and dispatch are gone from visibility.rs, and OwnedModule::VisibilityResolve from owned_kernel.rs. A pass with no continuation now records only vkCmdCopyQueryPoolResults. The combine's in-place words are declared as shader reads and writes for every combined offset (they were declared only for Boolean ones). A new precision degradation, DeviceBooleanVisibility (device-boolean-visibility), is announced where a pass's Boolean results record; its catalogue entry is in docs/API.md section 9 and a device-gaps row in docs/FAST-PATHS.md, as for the other native-answer kinds. - Translator: bind/visibility_resolve.rs and its tests are deleted (VisibilityResolve, VisibilityResolveModule, visibility_resolve_module leave the public surface). Its shared helpers (windows, words_buffer, u32_value) move into visibility_combine.rs; the combine's plan tests take the two refusal cases only the resolve's tests held. No translation output changes. - Conformance: a new Loosening::Nonzero, and an allowance may name one element of a byte region as <site>/<byte offset>. The visibility family loosens each Boolean result's word, and only that word, by Nonzero, justified by device-boolean-visibility, which its Boolean cases also declare at the notices site. Every other word still compares exactly. No recording changes. README and docs/CONFORMANCE-COVERAGE.md (regenerated) say so. - Validation lane: every Boolean expectation reads the word by its contract (visibility::by_contract: nonzero and not the buffer's starting word reads as 1), in visibility, framebuffer_fetch, host_bytes, depth_never and amplified_draws; the notice is a new lane site (visibility::BOOLEANS) taken by boolean_results_announce_the_device_s_value and expected where other tests' notice sets are exact. boolean_results_are_copied_with_no_dispatch counts one query result copy and no vkCmdDispatch for a pass of two Boolean offsets. Verified: cargo clippy --workspace --all-targets --all-features -D warnings with --cfg m2v_gpu; the runtime's degradation catalogue and site tests, the translator's combine, owned-division, resolve-helper users', api_surface and api_signatures tests; the conformance suite's 1024 device-free tests. The device lane tests run on the M3 with the next step. (cherry picked from commit a4976cdc3734c21c1b9ed4cf603bbf6bab2523f0) (cherry picked from commit 34e44e3a12a46e6ff4b651cc4689002690d680fc) |
||
|
|
b78025a08a |
Pin the runtime sources after the host RAM imported ahead and the draw path's steps
RUNTIME_VERSION 1755 says the host RAM's behaviour changed; the draw path's steps change how the runtime works out the same commands. Hash from the pin derivation over the listed runtime and translator sources. (cherry picked from commit e3444f32738ecd626ed6a46545ef693e18fd4117) |
||
|
|
3868162ee4 |
Bump RUNTIME_VERSION to 1755: a used host RAM's chunks are imported ahead
use_host_ram starts a device thread that imports every 64 MiB chunk of the RAM ahead of use, so an object made over it no longer imports its chunk on the making thread (WorkCounts::host_ram_chunks_imported_ahead). The draw path's steps in this stack (owned count shards, buffer uses patched in place, push writes pointing at their own info, rebinds without the command buffer's state lock, the lean recorder thunk) record and submit the same commands, uses and barriers, and need only the pin. (cherry picked from commit 89deb7f630984d8c296573c9f19ce51e57113a3a) |
||
|
|
68f095f652 |
Count a recorder command into the shard its thread holds, with no call in the thunk
Each recorder thunk looked its thread's shard up through a thread-local with a destructor (the one that gives the shard back), so the lookup checked the thread-local's state and, at a thread's first count, registered the destructor and took a shard inline. Those calls made every thunk save the command's arguments to the stack and restore them before handing on to the driver's command, at every command recorded (on the M3 Max: five register pairs saved and restored, twelve moves, in vkCmdPushDescriptorSet's thunk). The shard index now lives in a thread-local of its own with no destructor, which costs a load to read; the destructor lives in a second thread-local, touched once, as the thread takes its shard (shards::first_shard, out of line), and it hands the thread's later counts to the shared shard as it gives the shard back. A thunk counts into the shard its thread holds and takes none (shards::held): a thread's commands before its first other count (a draw's, which takes its shard) go to the shared shard, by an atomic add. The thunk is then as short as before step 1's owned shards, with a load and a store where it had an atomic add. tests::recorder_shards::a_thread_holds_the_shared_shard_until_it_takes_its_own checks that a thread that took none holds the shared shard, that holding takes none, and that a thread that took its own holds it. The api_signatures table is blessed again for the commands! macro body. Verified: on the M3 Max, the release thunk's disassembly (no saves, one tail call). The runtime's shard tests, plain; clippy over the runtime, plain; signatures.py --check after the bless. On the M3 Max, --cfg m2v_gpu, with debug assertions: the runtime's whole suite, 1551 of 1552; the one failure, tests::draw_again::draws_after_texture_and_sampler_changes_rebind_what_every_step_binds, counted one begin_command_buffer more in one run's window than the other's; it then passed in each of 15 reruns of tests::draw_again's 8 tests (its cause unaudited). The validation crate's runtime lanes frame_costs, draw_* and render: 106 of 106. 5080 (msi), interleaved A/B of 6 samples against the step before: a tie (static 0.058 against 0.054 us a draw, offset 0.458 against 0.464, bind 0.818 against 0.811, compositor 1.047 against 1.055; the medians within 8 ns, each pair's ranges overlapping). (cherry picked from commit 2d28f3aa1fb31c60032947d978e905472aa62820) (cherry picked from commit 6d251e5b526ba39d711f9a7c311dec2de673ea7f) |
||
|
|
d6731732dd |
Rebind a draw's buffer slots without locking its command buffer's state
A draw rebound locked its command buffer's state (CommandBuffer::state) to rewrite set 0's buffer descriptors, as binding::descriptor takes the state for the sources that upload bytes. The command buffer's encoders on other threads share that lock, and the 5080 profile put about 2.6% of a rebound draw in it. The rebind rewrites only slots' descriptors: a buffer slot's buffer, or the call's copy of a slot's bytes, neither of which uploads. binding::slot_descriptor now makes those two descriptors from the command's planned range alone (planned_range and in_space, shared with binding::descriptor, which takes them first), and rebind_into takes no state: a draw rebound locks none. In builds with debug assertions, CommandBuffer::state counts its locks on the locking thread (command_buffer::state_locks), and tests::shared_draw_locks::draws_rebound_at_another_offset_lock_no_command_buffer_state draws a rectangle at another offset of its vertex buffer 8 times and asserts that every draw counted rebound (WorkCounts::draws_rebound) locked no command buffer's state. Verified so far: clippy over the runtime, plain and --cfg m2v_gpu. Its run on the M3 Max (the runtime's whole suite and the validation crate's runtime lanes) and its negative control (a state lock put back into the rebind, so the new test should fail) are pending. 5080: expected faster on the rebound shapes; the interleaved A/B is pending. (cherry picked from commit a77b2629c6e5c9a0cda65332f1cacca29c4255da) (cherry picked from commit 49dd6820c6de412a7b3c744569c63390a1fbbbd3) |
||
|
|
d21d960cb1 |
Point a push's raw descriptor writes at each write's own info
binding::push_set copied each pushed write's info into one of three 16-entry arrays (buffer infos, image infos, texel views), zeroed whole first with a 16-entry array of raw writes, and pointed each raw write at its copy: about 1.9 KB zeroed and filled at every push of set 0, of a draw or a dispatch. write_sets did the same for each 16 writes it hands vkUpdateDescriptorSets. A raw write now points at the info its write holds where it lies (Info::written, SetWrite::raw): the infos are copied nowhere. The raw writes sit on the stack uninitialised past those written (binding::fill_raw), and only those are handed over; past 16, push_set collects them on the heap as before. Vulkan reads the infos during the call, while the writes they lie in live. The same descriptors reach the same commands. tests::push_raw_writes asserts it: of a buffer, an image and a texel write, each raw write is at its binding, element and type with one descriptor, and points at its own write's info (by address), and as many raw writes as writes are handed over. Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions: the runtime's whole suite, 1550 of 1550; the validation crate's runtime lanes (frame_costs, render, draw_*, compute, dispatch, tile, hazards, sync_coverage, shadows, attachments, executions, degrade_notices, push, descriptor, argument), 343 of 343. Clippy over the runtime, plain and --cfg m2v_gpu; signatures.py --check. 5080: expected faster at every push; the interleaved A/B is pending. Single lock holds read 0.483-0.502 us a draw on the offset shape with the steps before. (cherry picked from commit ecb9682fd1384d7d09dfc5d7634b052ddeb4a7e8) (cherry picked from commit 2d224ab1674e199de10900876e8257a79fa3602e) |
||
|
|
698988bdde |
Patch a rebound draw's buffer uses in place where only offsets moved
A draw rebound after buffer binds made its uses again whole (binding::command_uses_into): every use of every slot, texture and resource, and the attachment checks of the texture uses (render_target::shares_attachment). Where only buffer slots changed and each still binds the buffer it bound (its offset may have moved), only those slots' uses can differ. command_uses_into now records, for each use it makes, the index of the plan's or command's resource use it was made of (CommandUses::sources). binding::patch_buffer_uses rewrites in place the uses of the changed buffer slots, as bytes_use (factored out of the builder) makes them for the slot's buffer and offset now. It declines, and the draw makes its uses whole as before, where any changed slot is unbound or binds another buffer, where a use was added after the builder (its sources no longer match), or where a texture or sampler slot changed. Every other use is of a slot, buffer or texture no call changed, so the uses, and the keys the resident set reaches, are those command_uses_into makes, and the tracker sees the same uses and ranges: the same barriers. Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions, where the first rebound draw of a kept draw and every second after it take every step and compare the uses by digest: the runtime's whole suite, 1549 of 1549; the validation crate's runtime lanes (frame_costs, render, draw_*, hazards, sync_coverage, shadows, attachments, executions, degrade_notices), 292 of 292. Negative control (the patch skipping its rewrite, so the debug check should report other uses): built, its run pending. Clippy over the workspace, plain and --cfg m2v_gpu. 5080: expected faster on the offset shape; the interleaved A/B is pending. Single lock holds read 0.548-0.567 us a draw on the offset shape with the step before. (cherry picked from commit 678ded926bd21c1b52ecb693b7a6f5664500e017) (cherry picked from commit e11f9719d9bb500bf346cd5d2077788059011cc3) |
||
|
|
ac42123ade |
Own the count shards: a thread's adds are a load and a store, no locked add
The draw and recorder counts (shards.rs) each kept 16 shards, and a thread took shard (n mod 16) at its first count, so two threads could share one, and every add was an atomic fetch_add: a locked read-modify-write on x86 at every count. The 5080 profile of a rebound draw put about 6% of it in those adds (three thread-local lookups and five to seven locked adds a draw). A thread now owns its shard while it lives. At its first count it takes the lowest free one of 16 (a bitmask, by compare-exchange with acquire ordering) and gives it back as it ends (its thread-local's destructor, with release ordering). Only its owner writes a shard, so the owner's add is a plain load and store. The threads past 16, and a thread counting after its thread-locals ended, share a 17th shard by fetch_add. The counts a thread leaves in its shard survive its exit: the next owner adds on top of them, and a sum reads each shard's count as stored, so a hand-over moves no count and a reader sees none lost or doubled. A draw rebound adds all its counts into one shard lookup (Counters::draw_rebound now takes the states and writes it pushed), and the recorder's command thunks look their shard up once. The api_signatures table is blessed again: the body of the commands! macro, which the thunks come from, changed. No item a consumer calls changed. Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions: tests::recorder_shards (threads own distinct shards while they live, and a new thread takes one again; 19 threads x 100000 adds sum exactly; a reader summing through 40 rounds of 19 threads' hand-overs sees every sum monotone and at most the total, and the final sum exact), with tests::draw_again, shared_draw_locks, recorder, draw_shape_notices and exit_guard, 58 of 58; the validation crate's runtime lanes frame_costs and draw_*, 36 of 36. Negative control: with the shared shard also added to by a plain load and store, the 19-thread sum test fails (additions lost). Clippy over the workspace, plain and --cfg m2v_gpu; signatures.py --check. 5080 (msi, SCHED_OTHER): expected faster than the landed shards; the interleaved A/B is pending. Single lock holds, which the A/B is to settle, read 0.651-0.678 us a draw on the offset shape against 0.594-0.648 for the lane tip. (cherry picked from commit 4ae147ebb662f7ab3e76153337c6f9416c06e613) (cherry picked from commit 0e60618737d59d3c5bf58971358c12cf38395c7e) |
||
|
|
9b60da4bee |
host_ram: import a used RAM's chunks ahead, on a thread of the device's
What: Device::use_host_ram now starts a thread ("m2v-host-ram", through exit_guard::spawn)
that imports the RAM's 64 MiB chunks one after another, ahead of the objects over them. It
goes on from the chunk past the one an object last took, then from the RAM's start. It
skips a chunk whose lock is held (an object is importing it) and one it failed to import
(left to the first object over it, as before). It stops once every chunk is imported, the
use ends, the device goes or is lost, or the process exits (each import inside an
exit_guard section). It holds the device and the RAM weakly between chunks. An object over
a chunk the thread has not reached imports it on its own thread, as before. One over the
chunk being imported waits for that one import. New counter:
WorkCounts::host_ram_chunks_imported_ahead.
Why: a consumer makes 2 MiB heaps over consecutive fresh guest RAM (memfd). Each 32nd heap
was the first object over a chunk. Its making waited for the chunk's import, which faults
in and pins 64 MiB of fresh pages. That took ~7.5 ms exclusive on the RTX 5080 laptop, and
0.4-4.0 s in a shared boot with compaction (compact_stall +10,889). Keeping chunks imported
for the RAM's life already held at the start of this branch (a chunk stays in its slot
while the use lasts). Measured here: a heap made again after every heap was dropped
imported 0 chunks.
The trade-off: the whole RAM is resident and pinned from soon after use_host_ram, not only
the chunks objects touch. 16 GiB of fresh THP memfd RAM took 3.47 s on the thread, with
compact_stall 1152, compact_fail 56, pgmigrate_success 935291 and allocstall_normal 54,
all off the making threads. No kernel, boot or module parameter is needed. Recorded in
docs/HOWTO.md ("One run inside one chunk").
Vulkan rules relied on (checked against the 1.4.366 spec): the import itself is
Device::import_chunk, unchanged, under VUID-VkImportMemoryHostPointerInfoEXT-pHostPointer-01749
"pHostPointer must be a pointer aligned to an integer multiple of
VkPhysicalDeviceExternalMemoryHostPropertiesEXT::minImportedHostPointerAlignment",
VUID-VkImportMemoryHostPointerInfoEXT-handleType-01750 "pHostPointer must be a pointer to
allocationSize number of bytes of host memory", VUID-VkMemoryAllocateInfo-allocationSize-01745
"allocationSize must be an integer multiple of ...minImportedHostPointerAlignment", and
VUID-VkMemoryAllocateInfo-memoryTypeIndex-01744 "the value of memoryTypeIndex must be one of
those returned by vkGetMemoryHostPointerPropertiesEXT". The spec's "Externally Synchronized
Parameters" list names no parameter of vkAllocateMemory, so the thread's imports may run
while other threads use the device. Each chunk's import is made once, under the chunk's own
lock. A chunk is freed only on the existing path (vkFreeMemory's memory parameter is
externally synchronized: one owner frees it).
Verified on the RTX 5080 laptop (NVIDIA 615.71.09), release, --cfg m2v_gpu:
- All 21 host_ram tests pass, among them the new device test
chunks_are_imported_ahead_so_no_making_waits_for_one. It covers 4 chunks of fresh memfd
RAM under MADV_HUGEPAGE, imported ahead in 32.5 ms. Then 40 heaps of 2 MiB over
consecutive runs: 0 chunk imports, 0 host-pointer imports and 40 chunk-bound buffers
during the makings, the slowest making 78 us. Heap 33 passes a CPU write -> GPU read ->
GPU write -> CPU read round trip. A heap made again after all were dropped imports
nothing. The other device tests hold the thread back (Device::hold_host_ram_imports,
test-only), so they still see each chunk imported by its first object.
- Negative control: with the spawn disabled, the new test fails ("the device's thread
imported 0 of 4 chunks").
- On the M3 Max (MoltenVK, macOS 27.0.1), release, --cfg m2v_gpu: all 19 host_ram tests
pass (the two dma-buf tests are Linux-only). In the new test, 4 chunks were imported ahead
in 7.2 ms; across the 40 makings the slowest took 35 us.
- Unit test the_devices_thread_goes_on_past_the_chunk_an_object_took_then_from_the_start
covers the order, the skip of a held or failed chunk, and the end.
Heap makings, 128 heaps of 2 MiB over fresh THP memfd RAM (wall time per
new_heap_with_bytes_no_copy):
case p50 p90 max makings > 5 ms
before, 1 GiB RAM 0.001 ms 0.002 ms 7.39 ms heaps 0, 32, 64, 96
after, made at once 0.001 ms 0.003 ms 7.54 ms heaps 0, 32, 64, 96
after, made once the thread is done (122 ms) 0.001 ms 0.002 ms 0.05 ms none
before, 16 GiB RAM 0.001 ms 0.002 ms 7.54 ms heaps 0, 32, 64, 96
after, 16 GiB, made once done (3468 ms) 0.001 ms 0.002 ms 0.03 ms none
Made at once, the makings outran the thread: 5 chunks were imported during them, 4 of
them by the thread. Once the thread is done, no making waits for an import.
(cherry picked from commit 7baa553a75515909f2ce9701c1e1bea4c408845a)
(cherry picked from commit 97a69f70ab96d37dcdf269192a6935f8c4126749)
|
||
|
|
c9a2347fa6 |
Re-bless the conformance cost records on the M3 Max at 2b55ab415e, four ICB/mesh cases withheld
What: the M3 Max cost records of the whole case set re-measured on this tree (2b55ab415e: the compressed-extended-range scratch fix 2b5f0731c5 and the no-copy look fix 36ec3efc81 in), debug build, MoltenVK 1.4.2: `conformance cost --runs 8 --write` over the whole set (1123 cases, 1114 measured, 9 stopped), then `conformance cost --runs 8 --alone --write` over the 820 cases whose record gained a bound or a record, so every new bound carries its contrast. The draws class's ceiling in cost::the_creation_prediction rises 45 -> 47 (below), with its table re-read from these files. AFTER_THE_LAST_RUN names no case and stays empty. Four cases keep their committed recordings, whole files, new counters and all, because their gated rises came with stack18's indirect-command-buffer and host-step commits and are not yet explained: indirect-mesh-commands-object-threadgroup-lengths, mesh-commands-unordered-draws, mesh-commands-own-state and indirect-render-commands-inherited-state. A `cost --check` on this tree reads `over` on exactly those four until their cause is fixed or shown to be required and their records are written in a follow-up. Differences of this commit's records from the ones they replace, as `cost --check` counts them (cost::drift of each committed record against this write, before the contrast): 1522 over 558 cases, 45 of them numbers the gate reads. - 1452 counts newly gated (the counters the old records predate: heap_tables_worked_out in 551 cases, resident_textures_looked_at 320, dispatch_shapes_made 293, host_steps_recorded 155, dispatch_used_resources_listed 47, and others); 25 no longer gated. - 43 gated bounds moved: 16 fell (bound_notices_made in 14 cases, no_copy_lies_read in two) and 27 rose. 2 pipelines-per-state ratios rose. Each rise, bisected with each case alone (`cost --runs 8 --show`, debug builds, one selection at every candidate commit): - compressed-blits-bgra10xr and -srgb: command_barriers 5 -> 24, cmd_copy_buffer_to_image 7 -> 12, cmd_copy_image_to_buffer 6 -> 11, cmd_pipeline_barrier 18 -> 37. |
||
|
|
e0b0bbb700 |
Pin the runtime sources after the captured core's merge leases
A type-only fix in encoder.rs (no behaviour changed, so RUNTIME_VERSION stays 1754). (cherry picked from commit 2b55ab415e2972a1f6cff06536bd4c659193f4e2) |
||
|
|
4bfc52b6de |
Hold a captured core's merge leases as the encoder now does
The kept ICB recordings' Captured takes an encoder core's kept_leases, which the lent merge scratch turned from Vec<KeptLease> into Vec<MergeLease> (and dropped KeptLease's import): each branch built alone, the two together failed E0425 at encoder.rs. Captured now holds Vec<MergeLease>, the same leases the core held. No behaviour changes. Verified: cargo clippy --workspace --all-targets --all-features -D warnings passes on the stack. (cherry picked from commit bee669c0efdb0be77539f3be2c1dd2e6aac1f694) |
||
|
|
18f064f0ff |
Pin the runtime sources after host steps, kept ICB recordings, replay misses and lent merge scratch
RUNTIME_VERSION 1754 says the behaviour changed. Hash from the pin derivation over the listed runtime and translator sources. (cherry picked from commit e9300eecd461cc17c6d9f37d22106d0bf5a0d681) |
||
|
|
e748ef398b |
Bump RUNTIME_VERSION to 1754: host steps off the scheduler, kept ICB recordings, unbound replay misses, lent merge scratch
- Unchanged indirect commands run from kept recordings, chunk by chunk. - A device replay leaves an address no allocation holds unbound, counts the miss and runs the command (it faulted and dispatched nothing). - Host steps record on a steps thread off the scheduler's, order by what the execution reaches, and make only the states the CPU named. - A command buffer lends its finished encoders' linear-merge scratch to its later merges. - A new no-copy buffer's pages are looked at once as it is made. Each changes what a recorded run did. Stacking note: the host-steps commit (3831ba7e12) met checks at commit in scheduler/mod.rs. run_work takes the scheduler's Arc (to post a step to the steps thread) and keeps the committing-thread doc of claim_check; submit_at_commit's call passes &self.shared (a check, so it never takes the steps branch). cargo check of the runtime passed after the resolution. (cherry picked from commit d8c160edeba572b9500a04e228c4b79d1fd6492d) |
||
|
|
9c41c0b2a6 |
Lend a command buffer's merge scratch to its later encoders' merges
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) made a scratch of twice its box
for every pass's merge (LinearMerge:🆕 Device::scratch_buffer(2 * part)), and a shadow
merged back at each encoder's end (host pages, packed rows the device's linear images do not
lay out, such as an IOSurface's 4 * width) made one of its rows for every encoder: each held
until the command buffer completed, as the shadow's spares came back only then. A WebGPU frame
split at every indexed draw (stencilMask: 706 passes over a 1200x1200 canvas) so held 4 to
5.6 GiB, and the reims-vgpu lane's endEncoding failed out of device memory on the RTX 5080.
Now each command buffer keeps a pool of the scratch its ended encoders' merges are done with
(merge_scratch.rs, CommandBufferShared::merge_scratch): a linear merge takes the smallest free
scratch of its kind that holds its box, and gives it back once its pass's merge is recorded
(LinearMerge::record_merge); a shadow merge takes one the same way (before the shadow's
spares), held by a ScratchLease beside the encoder's kept-image leases (MergeLease) and given
back as the encoder goes. The pool holds weak references, so the bytes still go when the
command buffer completes, a shadow's back to its spares once the last merge that used it goes
(Scratch's drop, in place of ShadowMerge's). A new scratch takes at least twice the largest of
its kind the command buffer made, capped at a whole attachment's merge, so growing boxes make
a few. The memory a command buffer holds for merges follows its attachments, not its passes.
Why lending needs no wait (merge_scratch.rs's Order, against the barriers as recorded):
- a linear merge's scratch is touched only by its pass's fill and keep after the copy in
(record_keep: fill, Barrier::everything, keep, Barrier::everything), its reloads in the
pass's steps (reload_in), and its merge (record_merge: Barrier::everything, the changed copy,
Barrier::everything, the dispatches, Barrier::everything); a shadow merge's by its keeps and
merges, recorded before the encoder's next command that touches the bytes another way or at
its end, each merge ending with Barrier::everything after its dispatches (record_merge). All
lie in the encoder's own VkCommandBuffers or the segments it leaves between them;
- a command buffer's encoders go in order (one open at a time; a render end left to the
lowering thread is lowered before the next encoder opens) to its queue's one VkQueue, which
the queue keeps from the command buffer's making to its completion; reruns of a laying and
re-encodes after a rebind repeat or replace whole encoders. So two encoders' spans over one
scratch never interleave in submission order;
- each span writes what it reads before reading it, and the earlier one ends with
Barrier::everything (ALL_COMMANDS/MEMORY_WRITE to ALL_COMMANDS/MEMORY_READ|WRITE), whose
scopes are every command before and after it in submission order on the queue: the later
span's writes follow the earlier's reads and writes. A shadow's scratch is tracked besides.
Counted: WorkCounts::linear_merge_scratches_made and linear_merge_scratches_reused (new; the
api_signatures table blessed); shadow merges count the pool's loans in
shadow_merge_scratches_reused. A cfg(test) switch (DeviceShared::linear_rule_forced) makes
linear_attachment::bound answer the rule, so a device of no such rule (MoltenVK) reaches the
path in the runtime crate's own device tests.
Measured on the RTX 5080 Laptop GPU (msi-laptop, release, a scratch harness of
stencilprobe -P's sequence on the runtime: one command buffer, a clearing pass, 706 passes
loading colour and stencil beside a Depth32Float_Stencil8 attachment, a 1x1 attachmentless
encoder between them, 1400 encoders; three runs a process; peak = nvidia-smi's per-process
used memory, sampled every 50 ms), base 357a76f214 against this commit:
- texture over host pages, 1200x1200, rows 4800 (a shadow): before 3776 to 4096 MiB of device
memory allocated while encoding, peak 4333 MiB, commit to completion 87 to 89 ms; after 0 MiB,
peak 237 MiB, 57 to 65 ms;
- host pages, 1024x1024, rows 4096 (a shadow): before 2496 to 2816 MiB, peak 3053 MiB, 65 to
70 ms; after 0 MiB, peak 237 MiB, 53 to 59 ms;
- a Private buffer, 1024x1024, rows 4096 (the linear attachment rendered apart, 707 passes
through copies): before endEncoding failed, OutOfMemory(Device), peak 5485 MiB; after it
completes, 0 MiB, peak 237 MiB, 73 to 81 ms;
- a Shared buffer, 1200x1200, rows 4800 (a shadow): before 3776 to 4096 MiB, peak 4333 MiB, 80
to 88 ms; after 0 MiB, peak 237 MiB, 56 to 64 ms.
Measured on this Mac (M3 Max, MoltenVK 1.4.2, release, the same harness; peak = the process's
peak memory footprint, /usr/bin/time -l), base against this commit: host pages 1200x1200, rows
4800 (a shadow): before 3776 to 4096 MiB allocated while encoding, footprint 5087 MB, commit to
completion 117 to 151 ms; after 0 MiB, 795 MB, 104 to 138 ms. Host pages 1024x1024, rows 4096:
before 2496 to 2816 MiB, 3755 MB, 110 to 143 ms; after 0 MiB, 803 MB, 101 to 128 ms. The Private
and Shared cases render in place on MoltenVK (no rule, no shadow) and are unchanged (64 to 86
ms, 655 to 661 MB).
Tests (device tests, --cfg m2v_gpu):
- tests::merge_scratch (runtime crate): 240 passes beside a Depth32Float depth attachment in one
command buffer, over a Private buffer and a Shared buffer (packed rows of 1024 bytes), packed
rows of 1200 bytes, and host pages; the rule forced. Passed on the RTX 5080 as committed, and
on the M3 (MoltenVK) with a fifth case since dropped (below): each linear case 240 passes
apart, 1 scratch made and 239 reused; each shadow 239 reused; texels equal a private
texture's. Negative control (this tree with
MergeScratch::take lending nothing, on the M3): all four fail (240 made, 0 reused; 0 shadow
scratches reused). The base with the test copied in (its new counters left out) fails the
shadow cases on the 5080 too (0 reused).
- runtime_lane::linear_attachments::many_passes_* (validation crate): 706 passes over a Private
buffer (320x240, rows 1280), host pages (rows 1280 and 1200) and a Shared buffer of rows 1200,
colour bytes against a private texture's. Passed on the M3 and on the RTX 5080, where the
Private case is apart by the device's own rule: 706 passes through copies, 1 scratch made and
705 reused; each shadow 705 reused. The negative control fails the host pages case.
- clippy --all-targets --all-features -D warnings, plain and with --cfg m2v_gpu; the
api_signatures and api_surface tests.
Not fixed here, and not in the tests: over a Private buffer whose rows have bytes between them
(200 texels in rows of 1024 bytes, a shadow copied back), the same 240 passes leave 8800 (M3)
and 10516 (RTX 5080) of the 19200 texels unequal to a private texture's, at base 357a76f214 too
(the 5080, the test copied in): no merge runs there, so it is not this change's.
(cherry picked from commit b8fdd84f5c69546d1626fb994fd7d13756c1fc96)
(cherry picked from commit 6fa0708f5ef41bf2a599616a19d2da616492f032)
|
||
|
|
0e62eb1f72 |
host_replay_frames: HOST_REPLAY_VERTEX_OPS gives each state a vertex function of its own
With one vertex function for every state, the large-buffer form of the states' pipelines shares its vertex module, and the driver compiles it once: on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, its disk cache off) the parent's commit-time settle made 4,001 VkPipelines of 2,000 states in about 0.1 s, where a browser's states each bring their own vertex function. The knob gives each state its own: rt6_resolve_half's triangle, its depth a chain of that many dependent multiplies and adds on the vertex index, times zero, plus a half. Verified: the generated vertex function translates (metal2vulkan CLI, spirv-val PASS); clippy -D warnings with --cfg m2v_gpu for the validation crate. Needs no version bump: a test, ignored by default. (cherry picked from commit 7532a5fbc4ac6cad04a1b91186a8819952c7235c) (cherry picked from commit 59ea25b2d2894f467256420518445fe902e78deb) |
||
|
|
e51a3fa56d |
Name an ICB's per-command map CommandStates, not Commands
The kept recordings of unchanged indirect commands (four commits back) named the buffer's map of the states the CPU set, and of its kept chunks, Commands. tests::exit_guard's only_the_listed_modules_keep_the_device_s_functions reads the sources for copies of the device's functions and takes Commands for the generated-commands table that holds them, so it failed at indirect_command_buffer.rs's pipelines: Mutex<Commands>. The map holds no device function; its name now says what it holds. Verified: --cfg m2v_gpu, metal2vulkan-runtime's tests::exit_guard and kept_commands tests (42) pass; the exit-guard test failed on the commit before (the M3 Max run of the runtime's lib, 1,830 of 1,831 passing). Needs no version bump: a private rename. (cherry picked from commit 93c48b72a7a094d6c7cee93192070f7f99e77dea) (cherry picked from commit 831d54138016d0373b51e7c033e4c7665dbd65ce) |
||
|
|
51c7059a40 |
Regenerate docs/REFUSALS.md: KernelStageIn's site and the rebind_slots range refusals
python3 scripts/refusal-surface/refusal_surface.py on this tree. Two rows move: - KernelStageIn's runtime site is indirect_execute.rs's dispatch now, where the kept recordings of unchanged indirect commands moved the refusal (two commits back), not record; - BufferRange and DescriptorRangeExceeded gain bind/graphics.rs's rebind_slots, a site the base had added without regenerating the table. The device replay's ReplayFaults::ADDRESS was no refusal, so its removal moves no row; tests/api_surface.rs names ReplayFaults alone, and api_signatures.tsv dropped the constant with it (scripts/api-signatures --check passes). Needs no version bump: a generated document. (cherry picked from commit 07d7e05255a3d15ba98094389a680e96440eefa0) (cherry picked from commit 3d66d7436109ffbd80c5e6adf0ef1d92b26d70e5) |
||
|
|
2e0fb7b220 |
runtime_lane::host_replay_frames: what frames of GPU-writable render commands cost another queue
An ignored measurement (run by name, release, --cfg m2v_system_alloc), the shape of a browser's render bundle under a compositor: 256 render pipeline states made with supportIndirectCommandBuffers, each with a fragment function of its own, and an ICB of 5000 draws that sets the first 4 of them in turn, inheriting nothing. Each frame a compute encoder makes the ICB resident for writing and dispatches a kernel that writes no command, and a render pass executes every command; meanwhile another queue presents a clear every 8.33 ms. It prints HOST-REPLAY lines: the first 4 frames one by one, then the median, p90 and largest of 60 frames (the frame, its commit, first submission to last), the presenter's commit to completion and the ticks it missed, and the device's counters over them (host steps and their time, heads held, variant pipelines made, pipelines looked up, draws settled and dropped, records read). HOST_REPLAY_STATES sets the live states, HOST_REPLAY_OPS gives each fragment function that many dependent operations on the position (so the driver takes longer to compile it), and HOST_REPLAY_DROP_MS has the program release every state but the named ones that long into the first frame. Verified: the previous commit's M3 Max numbers come from it (run on the parent and on that commit's tree); clippy -D warnings with --cfg m2v_gpu for the validation crate. Needs no version bump: a test, ignored by default. (cherry picked from commit 42c7708b1ded77b1334812c7eb701764a5d69bd5) (cherry picked from commit afed271c358c30dcb1a7eddfe829c1518055998a) |
||
|
|
185bbd6328 |
Host steps: record off the scheduler's thread, order by what the execution reaches, make only named states
A batch executing indirect commands the GPU may write waits for its gate, then its host step records the commands from their records. Three costs fell on every other queue meanwhile: - The step ran on the scheduler's thread, which submitted nothing while it recorded (thousands of draws take milliseconds). - Its footprint was unknown (tracker::ordered's None), so every later batch of another queue that made a tracked use was held behind it until it was submitted. - At commit, the render settle made a VkPipeline for every live state that supports indirect command buffers, times the topology class's primitive types (1,280 lookups and 513 makings for 256 live states on the measured frame), and the step waited for all of them, up to the command buffer's bound. Now: - The scheduler hands each step to a steps' thread (scheduler/steps.rs, started at the first step, user-interactive like the scheduler's, recording inline where the host cannot start it), which records the steps in order, each a section of the exit guard, and wakes the scheduler. The batch is marked as stepping meanwhile (CommandBufferShared::begin_step/end_step), so it waits and no pass hands it over twice. - commit bounds a step's uses where it can (Segment::bound): for a compute execution, the resources the command buffer made resident and the ICB's storage (and an indirect range's copy); for a render pass, the pass's own uses, the resident resources and each execution's storage. CommandBufferShared::footprint uses that bound, so only a later batch sharing one of those is held. An execution that inherits buffers, is gated or preprocessed, reaches tile memory, has shadows or lends visibility stays unbounded (None), as before. - The render settle makes the states the CPU set on the executed commands (IndirectCommandBuffer::set_render_states, each state once), or the inherited one. A draw of a state a GPU-written record names that no settle made is begun at the step, made on its thread or handed to the device's pool and waited for until the command buffer's bound, as before; it holds no other queue's batch, and it is counted. On the kept recordings of the commit before (item 1), set_render_states reads the states the CPU set from the buffer's per-command map (Commands::states, a range of it), each state once. New counters: WorkCounts::host_steps_recorded, host_step_nanos, and host_step_pipelines_made (the VkPipelines a step began itself, made on its thread or handed to the device's pool and waited for: counted at the variant's making on the step's thread and at pipeline_pooled). The degrade notice host-replayed-indirect-commands states the new cost (degradation.rs and docs/API.md, same text). Verified on the M3 Max (MoltenVK 1.4.2), release, runtime_lane::host_replay_frames (the next commit: 256 live states, an ICB of 5000 draws naming 4, made resident for writing by a compute pass each frame, and a presenter clearing a texture on another queue every 8.33 ms), the parent and this tree run alternately twice, 60 frames each after 4 cold ones, on a loaded host: - the presenter: 80 of 244 and 73 of 192 ticks presented before (commit to completion median 16.9 and 16.4 ms, p90 40.8 and 23.7 ms), 186 of 186 and 185 of 189 after (1.13 and 1.13 ms, p90 1.49 and 2.23 ms); heads held behind earlier commits 23 and 13 before, 0 after; - the first frame's commit: 377 and 168 ms before (513 variant pipelines made, 1,284 looked up), 5.3 and 5.1 ms after (9 made, 24 looked up); a steady commit 2.38 and 2.33 ms before, 0.14 ms after; - the frame itself (commit to the last completion): median 28.7 and 24.4 ms before, 23.3 and 24.6 ms after, within the host's noise; the host step takes about 20 ms of it (host_step_nanos), recording the 5000 draws. The consumer's ICB repro (one state, 5001 draws, the ICB made resident for writing, another queue's one-dispatch command buffers meanwhile), same runs: that queue's commit to completion at the 99th percentile 53.5 and 24.3 ms before, 2.96 and 3.71 ms after, 140 and 119 command buffers in 40 frames before, 2,281 and 2,062 after; the frame alike (21 to 26 ms). Tests: runtime_lane::render_executions:: a_host_step_makes_the_pipeline_of_a_state_only_a_gpu_written_record_names (a blit-copied record naming a state, of another variant, that the CPU set on no executed command: both commands draw, the step's beginning of that state's VkPipeline is counted, and the step's time). --cfg m2v_gpu under the validation layer, on this tree before the pipeline_pooled count and the test: 234 tests of the indirect_*, kept_*, render_executions, render_gpu_executions, render_merged_executions, mesh_commands and executions lanes; 1,644 tests of the runtime crate's lib and the commands_recorded, dispatch_executions, generated_executions, kept_variants, device_commands, queue_order, submission_checks and grouped_submissions lanes. clippy -D warnings, plain and --cfg m2v_gpu; rustdoc -D warnings; scripts/api-signatures --check. Needs a RUNTIME_VERSION bump (what a run submits, when, and its counts) and a runtime-sources pin. (cherry picked from commit 4b05004999403684a2bdf4f3994108b53c7dc776) (cherry picked from commit 3831ba7e1298203779597feb0ea2943f77f9f5df) |