On a device whose subgroups run narrower than 32 lanes at their least and 32 at their most (Iris
Xe-LP), pinning a kernel to 32 lanes makes the compiler run it SIMD32, and a kernel holding many
values at once then spills: its compile and GPU time grow by an order of magnitude. A kernel now
takes the Emulated simdgroup tier in place of that pin when its inlined entry holds more than 256
instructions (WIDEST_PIN_FLOOR) and its estimated peak of live 32-bit words exceeds 36
(WIDEST_PIN_WORDS). The estimate (lower/simd/pressure.rs) reads the IR's structure: live intervals
in layout order, a phi's input live to its predecessor's end, a value read in a loop live to the
loop's end, wide pointers at 8 words with the resident-set search's 14. A refused emulation keeps
the Direct pin (workgroup::check is atomic). Both tiers give the same answers, so this is not a
speed-for-accuracy choice and takes no switch; the calibration is in lower/simd's docs and
docs/API.md section 3. The tier a kernel takes changes translator output (SEMANTICS); the census
entry simd.emulated.widest-pin and WorkCounts::widest_pin_kernels_emulated are new (RUNTIME).
Verified by radvcompile's runs: Iris RPL-P, both tiers, one run each, answers bit-identical in
every run. At 34 words or fewer, compile within 1.8x either way and Direct GPU as fast or faster.
From 40 words, Direct compile is 1.6-24x Emulated's and GPU 1.5-25x (P1 K48 S32: 25.8 s vs 1.3 s
compile, 1.985 vs 0.081 ms GPU; job 25157's 56-word points 458 vs 38 ms and 1332 vs 85 ms). At or
below 256 instructions every Direct compile took at most 102 ms. Release cost on msi: the estimate
took 5.2 ms of a 3.41 s translation of a 162,914-instruction kernel at 225 MB peak RSS
(m3-max-25227), 1.18 ms on 64,546 instructions (25256). clippy for metal2vulkan and the runtime,
all targets and features, rc 0 (25313); metal2vulkan nextest 3537/3538 (25259), the one failure
golden_hashes_match_the_table on the rows whose tier moves, re-blessed at the next pin.
On a device whose compiler picks a kernel's SIMD width between a minSubgroupSize below 32 and a
maxSubgroupSize of 32 (ANV), the Direct tier's required subgroup size of 32 with full subgroups
compiles the kernel in the widest mode, where each lane's value takes four times the registers
of the narrowest one. A kernel with many live values spills there, and its driver compile grows
to seconds and past them; one real kernel never finished compiling on an Iris Xe.
The kernel stage now takes the Emulated tier (each simdgroup 32 consecutive threads, its
operations and lockstep barriers through workgroup memory and barriers, no required size) when
the device has those facts, the inlined entry holds more than 256 instructions, and an estimated
peak of live 32-bit words passes 36. Both tiers are exact; it is not a speed-for-accuracy choice.
- lower/simd/pressure.rs: the estimate. Live intervals in layout order (a value stays live across
both arms of a branch, as on a SIMT device), a phi's incoming value used at the end of its
predecessor, a value read in a loop held to the loop's end; widths are the lowered ones (a wide
pointer from a pointer load or inttoptr is 8 words, and its resident-set search holds 14 more
where it is made). Linear in the body, metered.
- lower/simd/mod.rs: widest_pin, WIDEST_PIN_FLOOR, WIDEST_PIN_WORDS, the census entry
simd.emulated.widest-pin, and the calibration table in the module docs.
- workgroup::check is atomic: divergent::plan returns its demotions, which join `cross` only
once nothing refuses, so a kernel the Emulated tier refuses keeps its Direct tier.
- Runtime: WorkCounts::widest_pin_kernels_emulated counts such translations.
- docs/API.md section 3 states the rule and the calibration.
Calibration: an authored kernel (S steps, K live float accumulators, a lockstep pair in divergent
flow each step, P = 1 the accesses through a loaded pointer) on an Iris Xe (RPL-P, ANV),
vkCreateComputePipelines and GPU time, both tiers, one run each. At 34 estimated words or fewer
the two compile alike and the pin runs as fast or faster; from 40 the pinned compile took 1.6 to
24 times the emulated one and its GPU time 1.5 to 25 times (P1 K48 S32: 25.8 s vs 1.3 s compile,
1.985 vs 0.081 ms GPU). Answers were the same bits on both tiers in every run. The estimate took
5.2 ms of a 3.41 s release translation (225 MB peak RSS) of a 162,914-instruction kernel.
Test: engine_simd_lockstep's a_pressured_kernel_takes_the_emulated_tier_in_place_of_the_widest_mode
(the Iris profile: unpadded, below the floor and a low-pressure chain stay Direct, a fan of
live values takes Emulated with the census entry; the RTX 5080 laptop and RDNA3 profiles and a
kernel the Emulated tier refuses stay Direct).
The census at the pin-68 tip (m3-max-25336): 2369 cases over 21 profiles, 48670 compiled, 1079
refused, 0 failed, 0 differences, 0 regressions, 348 uncovered cells as at pin 67. Only the
product hash line moves. The slowest compile took 3.1 s and the largest worker 236 MiB, inside
the 20 s and 500 MiB ceilings.
The golden tables at the pin-68 tip (m3-max-25335) add the rows of the new engine fixture
ccb_conv_array (RUNTIME_VERSION 2218's creation bench): its golden printout, its two golden hash
rows and its two engine expectation rows (ok on 16 profiles, NeedsInput{StorageTextureFormat} for
kernel texture 1 on 2). No existing row moves. Test data only.
What: overlapping_derived_slots.m's header records its run: Metal refuses
the function for kind 0 batch 0 ("texture argument src has invalid
location (<0,1>)"), and makes and runs it for kind 0 batch 1 (dst reads
1 2 3 4) and kind 2 batch 0 (dst gated off, reads 0 0 0 0).
Why: it settles that a runtime refusal of a kernel whose constants put
two present textures on one slot through derived constants is Metal's own
answer, made at the pipeline state where Metal makes it at the function.
Verified: potluck job m3-max-25307 on the M3 Max (macOS 27.0.1), one run.
What: probes/overlapping_derived_slots.m compiles an authored kernel of a
framework convolution kernel's interface: a write texture at texture(0)
gated by (kind & 3) == 0, and a sampled texture at texture(batch) gated by
((kind >> 6) & 3) == 0, batch and kind function constants 125 and 126.
It prints what Metal answers for kind 0 batch 0 (both present at texture
0), kind 0 batch 1, and kind 2 batch 0 (the write texture gated off).
Why: the runtime refuses a compute creation of such a kernel with every
constant 0 (OverlappingArgument, the sampled texture at slot 0). A refusal
of a program's work is a defect unless Metal refuses it too; this asks
Metal for this shape, with derived predicates and an expression index.
Verified: pending its run on the M3 Max.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
The six commits before this one cut a compute pipeline state's creation when the in-memory memo
has let the pipeline go and the creation reads its function and pipeline artifacts from disk:
- an integer sequence decodes in one step, not one u32 at a time;
- an artifact's frame checksum is XXH64, not SHA-256 (ARTIFACT_FORMAT_VERSION 517). It detects
damage to an entry, such as a torn write or a flipped bit; it never authenticated anything, since
whoever can write an entry can write its checksum. The keys, the profile fingerprint and the key
check stay SHA-256. No answer changes, so it is not a FAST-PATHS item;
- a device keeps its compiled pipelines' stage-word digests (LRU, 16384 entries) past their
variants, so a program's state made after its warm pass no longer re-hashes every word.
A release bench over an authored convolution fixture (ccb_conv_array: ten function constants, a
16K-word module) times these creations and their pieces. The digest map changes runtime
behaviour.
Verified on lavapipe on msi (selfread2's runs at 801e7cb8a6), ccb_conv_array, release, median
creation, before -> after: memo of 1 byte 108-119 us -> 57 us; new device 185-196 us -> 134 us;
after a warm pass with a 1-byte memo 134 us -> 115 us (the digest map); a warm memo unchanged at
9-13 us. The same SPIR-V, decoded field for field. clippy plain, m2v_cpu_icd and m2v_gpu exit 0;
Rustdoc -D warnings exit 0; lavapipe runtime suite 2478 pass, 1 fail (the msi primed_devices
failure fixed by RUNTIME_VERSION 2217); translator cache tests 65/65, including XXH64 vectors
checked against the specification's values. The new fixture's engine expectation row, inventory
entry, golden printout and golden_hashes cells are blessed at the next pin on development.
What: compute_create_bench gains a round, "after a warm pass, memo of
1 byte". It records the cold round's creations through the device's
record hook. Each of PASSES new devices, whose memo of one byte keeps
nothing, then warms over those records and makes the round's states.
That's the creation a program makes after its warm pass made the same
pipeline and its memo let the pipeline go, as in a run whose warm pass
covers more records than the memo holds: the translation found on disk
and the variant's objects made again, since the pass kept none.
Why: it's the creation the guest's measured 236 us host make comes
from. The other rounds don't make it: a new device has no pass, and
the one-device round takes its variants' objects back after its first
round.
Verified: ran in release on lavapipe on msi at the tree of this commit
(9262ddd00a). ccb_conv_array: 115.1 us at the median, 8 modules made
per device. kernel_inverse_hyperbolics_and_a_gated_bias: 33.5 us.
What: a variant whose objects are made new, with no kept instance to
give them back, names its modules by the SHA-256 of each stage's words
(words_digest). That's one pass over every word. The device now keeps
the digests a variant took in WordsDigests (DeviceShared::words_digests).
It's an LRU of at most 16384 compiled pipelines, keyed like the memo by
the compiled pipeline (kept::Compiled), holding one 32-byte digest per
stage and no Vulkan object. A later variant of the same compiled
pipeline that gets no digests from its caller takes them from there
and hashes nothing. A caller's own digests are used as before (a
render creation that linked its pipeline asks its functions).
Why: a warm pass makes each record's variant and keeps none of its
objects (warm/pass.rs), so the program's state of the same pipeline
makes its variant's objects again. Until now it also hashed every word
of every stage again, the same digest the pass had just taken. So does
any variant made again after its kept instance went, as when the memo
let its pipeline go. For ccb_conv_array's 16348 words that hash takes
17.1 us on lavapipe on msi (COMPUTE-CREATE-PARTS), on every such
creation. A key names one compiled pipeline in a process, which the
memo already trusts, so it names those words.
Verified: the_program_s_state_after_a_pass_hashes_no_stage_words
(tests/warm.rs) warms a recorded compute state's record, then has the
program create that state. The program's creation makes its variant's
objects (the shader-module counts move) and derives no digest
(words_digests_derived stays still). The pass itself derived one at
least, so the test fails without the map.
It passed with the warm, render_stage_digests, kept_variants and
functions_translated tests, 19 of 19, on lavapipe on msi at the tree
of this commit (9262ddd00a). I didn't run it with the map removed, so
the failure without the fix is by construction, not observed.
compute_create_bench's new round shows the time: for ccb_conv_array
on lavapipe, a program's states after a warm pass, memo of 1 byte,
take 115.1 us at the median, against 133.6 us on a new device with no
pass, which hashes. The gap matches the 17.1 us digest.
What: after its rounds, compute_create_bench prints COMPUTE-CREATE-PARTS
for each kernel: the size of the function's and the pipeline's
artifacts and each one's decode from its bytes (the frame's checks and
the body), the stage's word count, and the median of 64 runs of each
of the stage words' digest (the one that names their module) and the
driver's vkCreateShaderModule with its destroy.
Why: a creation that misses the memo and the kept variants pays all of
these, and the rounds show only their sum. The pieces say which one to
cut on each driver.
Verified: ran in release on lavapipe (msi-laptop, b73923b91). For
ccb_conv_array: function artifact 69425 bytes, decoded in 13.5 us;
pipeline artifact 68360 bytes, 10.7 us; 16348 words, digest 17.1 us;
vkCreateShaderModule and its destroy 21.7 us.
What: the frame around an encoded function or pipeline (cache/envelope.rs)
now ends with the XXH64 (seed 0) of every byte before it, 8 bytes
little-endian, where it held their SHA-256 in 32. It is computed in one
pass for seal and open, and fed a chunk at a time for seal_to. The new
cache/checksum.rs implements XXH64 as its specification defines it.
ARTIFACT_FORMAT_VERSION is 517. Keys stay SHA-256, and so do the
profile fingerprint and the key checks a load makes.
Why: open() checked the checksum on every artifact it read, and a
compute creation that misses the memo reads two, the function and the
pipeline. In a perf profile on lavapipe (ccb_conv_array, memo of one
byte, 16000 creations, at c8c148369a on msi), sha2's compress was 33%
of the creating thread.
The guarantee kept: the checksum finds an entry that was damaged on
disk or cut short, such as a torn write or a flipped bit. A random
change gets past a 64-bit checksum with probability 2^-64. It never
authenticated anything: whoever can write an entry can write its
checksum too, so SHA-256's collision resistance protected against
nothing a decode faces. Collisions between entries don't matter here,
because each entry is checked against its own checksum and named by its
SHA-256 key. Checking once per file instead would need the file's
identity, and other processes sharing the directory can replace an
entry, while XXH64 over a whole artifact costs about what reading it
costs.
Verified: the_checksum_is_xxh64 checks the specification's values for
"", "a", "abc" and a 39-byte string (one stripe and a tail).
pieces_sum_to_the_whole checks that pieces of 1 to 200 bytes give the
whole's checksum. the_frame_layout_is_pinned, corrupted_bytes_are_refused
and earlier_format_versions_are_stale are moved to the 8-byte checksum.
The cache tests passed, 65 of 65, at b73923b91 on msi-laptop.
Measured together with the bulk decode before it, on lavapipe on msi
(compute_create_bench, ccb_conv_array, release), against c8c148369a:
- memo of one byte: median creation 107.9 and 119.2 us (two runs)
before, 56.7 us after;
- new device: 185.2 and 195.9 us before, 140.4 us after;
- compute_create_profile: 88.8 and 97.9 us before, 43.9 us after.
The same device with a warm memo is unchanged (9.4 us before, 9.1 us
after).
What: the codec's integer impls (u16, u32, u64, i32, i64) give their own
get_items and get_shared. They take the sequence's n times size bytes
from the reader once and convert each chunk with from_le_bytes,
collected straight into the Vec or the Arc<[T]>. Before, the trait's
default looped over the items: one bounds check and one Result for
each word, and an extra copy for a shared sequence (Vec, then Arc).
The encoding is unchanged. A count that names more items than the
bytes left is still Malformed.
Why: a compute creation that misses the memo decodes two artifacts
from disk, the function and the compute pipeline, and most of each is
its module's words. In a perf profile on lavapipe (ccb_conv_array,
memo of one byte, 16000 creations, at c8c148369a on msi),
<u32 as Codec>::get_items was 25% of the creating thread.
Verified: integer_sequences_decode_item_for_item checks that every
integer width decodes to what reading the items one at a time gives,
as a Vec and as an Arc, and that a sequence one byte short is
Malformed. It passed with the cache tests, 65 of 65, at b73923b91 on
msi-laptop.
What: a new owned fixture, engine/ccb_conv_array.metal, compiled to .ll and .air.ll by
scripts/regen-air-fixtures; TOOLCHAIN names its compiler. It is a convolution over half
texture arrays with ten function constants (kernel size, strides, dilation, bias, activation,
offset, input slices, edges, alpha), a 3x3 path written out tap by tap, a general path and
eight activations; 101 KB of AIR text.
The bench (COMPUTE-CREATE):
- now runs both kernels: SMALL, the small one-constant kernel, and CONV, the new one;
- adds a round on one device whose memo holds one byte, so each round finds each translation
on disk, as on a device whose memo a run's many states evicted;
- the profile target now runs 2000 such rounds of the convolution on one device.
Why: the small kernel's warm creations cost about 5 us from the memo and 48 us from disk on
lavapipe. That is far below the guest's 236 us, so the size and shape of the kernel, and
creations from disk, are what to measure.
Verified: not run at this commit; next on lavapipe and the 2080.
What: tests/compute_create_bench.rs, two ignored release tests over the owned fixture
kernel_inverse_hyperbolics_and_a_gated_bias.
- compute_create_bench (COMPUTE-CREATE) times new_function_with_name_constant_values and
new_compute_pipeline_state for 8 states, one per value of the kernel's short function
constant, kept until the round ends and then dropped. It runs a cold round on a fresh
device, 4 warm rounds on that device (the memo) and 4 warm rounds on new devices over the
same shader cache directory (the disk). It prints the median and slowest times and each
round's work counts.
- compute_create_profile runs one cold round, then 2000 warm rounds on one device, for a
profiler.
Why: a guest's warm compute pipeline create costs about 236 us on the host, against about
20 us natively, with outliers of 7.8 and 9.5 ms. This measures our share of it through the
public API.
Verified: not run at this commit; run in release on lavapipe and the 2080 next.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
On a host with several Vulkan drivers, a device made again on what stays loaded was primed again.
The probe (msi: intel, intel_hasvk, lavapipe and nvidia drivers, three implicit layers, no Intel
GPU) showed the first device's making as: the device's instance loads every driver and the loader
unloads both Intel drivers again; the device is primed and registers the exit hook at 71 loads;
then the drivers' keeper's bare instance, made once the device was returned, loads both Intel
drivers again (73 loads). The next device saw 73 loads against the 71 its registration kept, so it
was the first after a load and was primed again, though its identity matched in every word. The
exit guard did what its rule says; keeper.rs's own claim that its instance "loads no driver
itself" did not hold there. The cost was one more priming a process (120 to 160 ms on NVIDIA's
driver), and tests::primed_devices failed on msi with every driver visible, at every commit back
to f0ceab6a30 (jobs 25199, 25211); with lavapipe alone it passed (25166).
The keeper is now made in create_on as soon as vkCreateDevice succeeds, before the device is
primed and registers the hook, so whatever the keeper's instance loads comes before the load count
the registration keeps. That relies on nothing about which drivers the loader keeps. The three
calls after a device was made (system_default_with, with_registry_id, all_with) are gone.
keeper.rs states when it is made and what was measured.
Test: tests::primed_devices::a_load_as_the_drivers_are_kept_primes_no_later_device forces one
load (a test-only count in loaded::count) as the keeper is made; the device made again must be
neither primed nor registered. With the keeper made where it was, after the device's
registration, the forced load makes the next device the first after a load.
Making the keeper at a different point changes runtime behaviour (RUNTIME_VERSION 2217).
Verified by the change's own runs on msi (m3-max-25250, at a2b5f71a6f): with every driver visible,
a_device_made_again remakes 4 of 4 devices with no load (primings 1, loads 73) and the new forced
test passes (primings 1); with lavapipe alone both pass (primings 1). clippy --cfg m2v_cpu_icd
exit 0. Negative control: create.rs from before the fix fails the forced test both ways at
primed_devices.rs:93 (primings 2 against 1).
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
Coverage readers now take their queries from one shared pool (SparePools) instead of a query pool
made for each pass: reims's Launchpad walk made 246 query pools in 8 s, about 13.8 ms of CPU a
second in vkCreateQueryPool and vkResetQueryPool. A texture's memorylessness is set when it is
made, so is_memoryless takes no hold (resource_options took two on every check). WorkCounts gains
encoders_uncarried_*, one count for each of the 13 ways a render encoder ends carrying no kept
draw, to name why the walk's encoders carry none. The pass and draw benches gain a window
server's small passes (draw_costs pass1/pass17, --states, --worker) and examples/pass_costs.rs
times a render pass instance by how it is recorded. That changes runtime work.
Verified by the change's own runs: learned_coverage::readers_in_flight_together_take_queries_of_one_pool
on the 780M gives 8 queries and 0 pools made with 8 passes in flight, and the old coverage.rs makes
7 pools and fails (25161); carried_draws::an_encoder_that_carries_nothing_counts_why passes; lint
green in every configuration (25150). Bench, lavapipe pinned (25046): a pass of one draw 85,100 ->
83,140 instructions, 10.99 -> 10.85 us; a draw of a pass of 17 27,258 -> 26,910 instructions.
Public surface: the coverage Query gains a Drop impl (a query goes back to its shared pool), blessed
in api_signatures.tsv; a consumer that destructures a Query by value can no longer move its fields out.
The walk's vkCmdBeginRenderPass took about 6.8 us each (profile), the
bench's 1024x1024 loaded instance well under 1 us: the extent and a clear
load are the first two of the walk's passes' differences to measure.
clippy's extend_with_drain on SparePools::release (c6d4cc8d18).
Verified: lint3 job m3-max-25060 named this as its only error under
all three configurations; rerun follows.
A bench of its own Vulkan 1.3 device, no runtime: 150 passes a frame of
one draw each, 6 to a vkQueueSubmit (the walk's averages), recorded as
the runtime records them (a primary per pass, its 17 dynamic states set,
a VkFramebuffer made per pass for vkCmdBeginRenderPass) and as the
alternatives: a primary per submission, a framebuffer kept, dynamic
rendering. It prints each shape's CPU time a pass to record, submit and
reclaim, and the differences between shapes that differ in one thing:
the costs of the structural items in one run on one device.
Verified: cargo fmt only so far; built and run in the 780M job.
Each pass that measured a reader took a whole pool of 64 occlusion queries, held until
its command buffer completed, from 16 spares: with a frame's many passes and frames in
flight, most passes made a pool (a window server's walk on the XTX made 222 in 14 s,
each a RADV buffer object, about 1.2% of its encoding threads with the host resets).
Readers now take the next query of the device's current pool, whichever pass and
command buffer they are of; a pool whose every query was taken waits for its last to
come back, then is a spare, reset on the host as it becomes the current one. Each
reader's query is read alone before it goes back. Answers unchanged.
Test: learned_coverage::readers_in_flight_together_take_queries_of_one_pool (8 passes'
command buffers encoded before any commit make at most one pool).
Every render pass asked each attachment whether it is memoryless five or more times
(the layout's actions and targets, the inline open and its area, the inline begin, each
draw's memoryless writes, each texture bind), each through resource_options, which takes
two holds of the texture's parts (four mutex round trips) and resolves the hazard
tracking mode too: about 3% of a small pass's encoding thread on lavapipe (draw_costs
pass1). No storage a texture moves to or presents changes its storage mode, so the
texture keeps it from its making and is_memoryless reads it with no hold; the render
path's checks (render_pass, render, clear_reach, sample_planes, resolve, resource) ask
it. Answers unchanged.
A Launchpad walk on RADV counted no kept draw carried and no carry let go: every
encoder's carried_out declined silently, so each of its first draws per state took
every step (draws_none_kept, 53% of its draws). The encoder now counts the first
reason it carries none (encoders_uncarried_*): no draw, no kept draw at its end, an
unsettled bind state, a split, colour groups or a rate map, a replay, executed
commands or pending pipelines or tile dispatches, shader-side tests, imageblocks, a
visibility result, an instance of reformats, views or storage, a kept draw that does
not rebind, or a failing depth/stencil state. What carries is unchanged.
Test: carried_draws::an_encoder_that_carries_nothing_counts_why.
The census at the pin-67 tip (m3-max-25189): 2369 cases over 21 profiles, 48670 compiled, 1079
refused, 0 failed, 56 differences, 0 regressions. The slowest compile took 2.4 s and the largest
worker 235 MiB, inside the 20 s and 500 MiB ceilings.
The golden tables at the pin-67 tip (m3-max-25188): 21 golden hash rows move under unchanged keys
with the native fp8 change (SEMANTICS_VERSION 2082, the shaderFloat8 device facts) and the
flagged rate-mapped parts (2083), and the engine fixture expectations' tns_mm_fp8 rows on the two
RTX 50 profiles go from Unsupported{Tensors; NotImplemented} to ok, since that refusal is gone.
Test data only.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
Under RateMapRegionPolicy::FanOut, the probe now also records each flagged draw's first and last
flagged triangle (PROBE_DRAW_WORDS 1+2*32 -> 1+4*32), and a flagged triangle list of one instance
that reads no [[primitive_id]] and writes no memory is drawn in its place in up to three parts:
the triangles before the flagged range fanned out, the range region by region, the rest fanned
out. Parts of a 16-bit index list begin at even triangles. Other flagged draws are drawn region by
region whole, as before. Wide marks count only triangles the probe does not flag, so the fanned
parts can take the four-copy variant. New counters: rate_map_parted_draws,
rate_map_parted_region_triangles and rate_map_probe_wait_nanos. Exact is unchanged. The probe
stage's SPIR-V changes (SEMANTICS) and the runtime draws flagged draws otherwise (RUNTIME).
Verified by the change's own runs: rate_mapped_fan_out's four flagged draws go in parts and match
the region-by-region frame pixel for pixel, and Exact draws none in parts with equal pixels; every
tests::rate_map* test 21/21 on an RTX 2080 and a Radeon 780M; nextest of metal2vulkan and the
runtime 5053 passed, the 2 failures the known golden re-bless rows; clippy clean. The pieces
lane's frame with wide triangles, warm GPU: RTX 2080 39.6 -> 30.9 ms (Exact 68.5), Radeon 780M
373 -> 223 ms (Exact 566, a shared machine); the frame without wide triangles unchanged.
docs/FAST-PATHS.md row 50 gains the pieces lane's frame with wide triangles
(rate_mapped_pieces_host_step_wide), warm, at ed46f36fba's change (built at its pre-rebase commit
22b6697ba0) against the lane-only commit (8bd88bf0ac's pre-rebase 8da477a56c), each one run:
- RTX 2080 (NVIDIA 620.70.06): 30.9 ms in parts, 39.6 ms with flagged draws region by region
whole, 68.5 ms under Exact.
- Radeon 780M (Mesa 26.2.6): 223, 373 and 566 ms, on a machine running other jobs.
23 of the 64 draws are flagged; 106,519 of their triangles lie between the first and the last
flagged one and are drawn region by region.
Under DevicePolicy's RateMapRegionPolicy::FanOut the probe flags a draw that has a triangle
crossing w = 0 or reaching more regions than the geometry stage's copies. The whole draw was then
recorded region by region, once per region of the map (2074 for a 61 by 34 map), however few of
its triangles were flagged.
The probe now also records each flagged draw's first and last flagged triangle. A flagged list of
triangles of one instance, whose pipeline reads no [[primitive_id]] and writes no memory (the
conditions under which a draw is already cut into index ranges), is drawn in up to three parts in
its place: the triangles before the first flagged one fanned out, those from it to the last
region by region, and those after fanned out. Each part is a range of the draw's vertices or
indices, so each triangle keeps its vertices, vertex_id and order. Parts of a 16-bit index list
begin at even triangles, so their ranges start 4-byte aligned as the draw does. Any other flagged
draw is drawn region by region whole, as before.
The probe words grow from 1 + 2*32 to 1 + 4*32 per draw (bind::fan_out::PROBE_DRAW_WORDS). For a
flagged triangle the probe raises one of 32 words to u32::MAX - PrimitiveId and one to
PrimitiveId + 1, picked by PrimitiveId as the counts are, so no single word takes every atomic.
The wide marks that choose the variant of four copies now come only from triangles the probe does
not flag, so the fanned-out parts can take that variant.
Also: WorkCounts::rate_map_probe_wait_nanos sums the host's wall time from each probe's
submission until it saw it complete, so a walk can split host_step_nanos into the probe's round
trip and the host's own recording. rate_map_parted_draws and rate_map_parted_region_triangles
count the draws in parts and their triangles drawn region by region.
An earlier attempt drew a flagged draw through a geometry stage of 32 invocations, each taking a
block of up to 16 regions, in 5 passes over the map. On the pieces lane's frame with wide
triangles it made no GPU gain on an RTX 2080 (41.0 against 42.9 ms warm). On a Radeon 780M (RADV)
it went from 182 to 1900 ms, with one piece of 1.1 s. That attempt is not in this change.
Tests: render::fan_out's unit tests check that the parts take each triangle once, in order, with
no flagged triangle in a fanned-out part, and that the probe's words decode to the first and last
flagged triangle. The link test checks the probe's two atomic raises. The runtime's
rate_mapped_fan_out test adds two commands that draw the grid with one triangle over half the
target, one indexed and one without indices, and a triangle across w = 0 over the whole target.
Under FanOut all four flagged draws are drawn in parts and the frame is compared pixel for pixel
with the encoder's region-by-region frame. The pieces lane's wide frame checks that every flagged
draw is drawn in parts.
One triangle of every 8192 of the lane's grid becomes one 48 quads a side, about 1061 by 504
pixels over the 3648 by 1734 screen, which touches more regions than the fan-out's copies. The
probe flags every command whose indices reach one, about a third of the 64, as a guest's
rate-mapped frame on an RTX 3090 and a Radeon 780M had about a quarter of its probed draws
flagged (rate_map_flagged_draws 698.8/s against rate_map_fanned_draws 1972.9/s; 280.4/s against
788.7/s). rate_mapped_pieces_host_step_wide fans the frame out and rate_mapped_pieces_host_step_wide_exact
draws it region by region; the fanned-out frame asserts that the probe flagged a draw, and the
small frames that it flagged none.
Measurement only (ignored, run by name); no product change.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
What: two fields on WarmStatistics, which stays Copy + Eq + Default.
- record_in_making: the record's place among every record handed to the device's
Device::warm calls, in the order handed (each call notes its first's place). While it is
made, that is the six record counts' sum. None between records and while no pass runs.
- record_in_making_nanos: how long that making has worked.
How the time is kept (warm/pass.rs):
- Each record's making now has its own Pass. The Pass shares the call's byte count and holds
a clock: the wall time while one thread or more works for it. That is the pass's thread
inside `within`, or a piece of the record's that it handed the pool, which captures that
record's Pass when handed.
- warm::waiting stops the clock around this thread's waits. It is wrapped around:
- a thread's wait for its budget turn (thread_turn_in);
- without_turn's lend and retake, which covers compile_memory's words wait and the flight
and library waits;
- making.rs's waits for a making in flight;
- pool.rs's full join.
A nested wait is the outer one's, and a thread works once for a pass it already works for.
- The warmer keeps the record in making (index and Pass) from just before its creation until
just before its outcome is counted, so the index and the counts' sum agree whenever it is
Some.
- A test-only gate (warm::gate) holds a chosen record's making, working, at its start.
Why: reims's warmbound lane needs to find a warm record whose making never ends (an ANV
making on ms01's Iris) and tombstone it once it has worked 60 s. A record starved by a
program's storm must never look like that.
Verified: not run at this commit. Tests added:
- pipeline::budget::tests::a_warm_making_s_time_holds_still_while_it_waits_for_a_turn
- pipeline::budget::tests::a_warm_making_s_time_holds_still_while_its_piece_waits_for_a_turn
- tests::warm::the_record_in_making_names_its_place_and_how_long_it_worked
Signatures blessed.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.
A Managed two-copy buffer whose host copy is its pages alone, where a guest RAM's chunk imports
hold every page of it (a buffer across a chunk end), now keeps pieces of those imports, and its
copies in are GPU copies from them: no CPU staging, no bound and no submission. Before, its named
ranges were staged by the CPU at each commit. AtCommit still stages a named range at the commit.
New WorkCounts name the path: managed_bytes_staged_in, managed_bytes_copied_in_from_ram,
managed_pages_alone_refused, managed_pages_alone_over_imports, managed_pages_alone_unwritable and
managed_pages_in_ram_chunks. That changes runtime behaviour.
Verified by the change's own runs on the RTX 2080: the equality tests (a 4 MiB buffer across a
chunk end, both policies) pass, checking the counts, the bytes the GPU reads after a CPU write
across the end and which path copied them; MANAGED-RAM-COPY-IN at 32 MiB across the end, commit
call 2.139 -> 0.035 ms and completion 19.41 -> 17.40 ms (0.257 -> 0.010 ms at 4 MiB);
host_ram_device 29/29, managed_copy_device 30 passed. lavapipe suite 2472/2472; clippy plain,
--cfg m2v_cpu_icd and --cfg m2v_gpu and rustdoc green.
What: a Managed no-copy buffer on a device without unified memory can have
a host copy that is its pages alone, because its own import would map pages
a live import holds or the device refused it. Where a guest RAM's chunk
imports hold all of those pages, it now keeps the pieces of those imports
(host_ram.rs RamOnDevice::pieces_of, ChunkPiece). The caller's resolver is
still asked once: its answer is kept for the pieces.
- Its copies in (as it is made, at a rebind, and each range
did_modify_range names under AtSubmission) are GPU copies from those
imports' VkBuffers, one per piece. They are held as a host copy
(Keeps::HostCopy): nothing is staged, no bound applies, no submission is
made. AtCommit still stages a named range on the CPU at the commit.
- New public WorkCounts, so a pass can tell the paths apart:
- managed_bytes_staged_in, the bytes the CPU staged for copies in;
- managed_bytes_copied_in_from_ram;
- managed_pages_alone_refused, managed_pages_alone_over_imports and
managed_pages_alone_unwritable, why a host copy is its pages alone;
- managed_pages_in_ram_chunks.
- Tests: tests/host_ram_managed.rs, a buffer across a chunk's end with
both chunks imported, under both policies. It checks the counts (pages
alone over imports, held by the chunks, nothing imported, gate unasked),
the bytes the GPU reads as the buffer is made and after a named CPU
write across the end, and which path copied them.
- Docs: managed_copy.rs, managed.rs, buffer.rs, HostMemory::with_runs,
docs/API.md, and FAST-PATHS row 51. Signatures blessed.
Why: such pages were staged by the CPU at every commit that took a named
range. That is a CPU copy and staging memory, on the commit's thread, for
bytes the device already maps through the chunk imports. Zero copy first.
Verified: not run at this commit. The 2080 equality tests and the bench
(before at the bench commit, after here) and lint follow on the rebased
branch.
What: tests/host_ram_managed.rs, a new device-test module for Managed
no-copy buffers over a guest RAM, with one ignored release bench,
MANAGED-RAM-COPY-IN. Its buffer is 32 MiB centred on the end of the RAM's
first chunk, and both chunks are imported. Ranges of 256 KiB, 4 MiB and
32 MiB across the chunk end are written and named before each of 20
commits. Each commit reads the range's first and last bytes, and they are
checked. It reports the commit-call and to-completion medians and the
bytes copied in, on the default device and on one of exact_answers().
host_ram_device.rs exposes its RAM helpers and gains held_device(policy).
Why: such a buffer's host copy is its pages alone, because its own import
would be over pages the chunks' imports hold. Its copies in are staged
by the CPU at the commit today. This bench measures that before the GPU
copies them from the chunks' imports.
Verified: not run at this commit. It is run on the 2080 before and after
the change.
A commit's take of the ranges did_modify_range named now asks its encoder records only about the
owners that have noted ranges (CommandBuffer::may_use, State::named_among), stopping once all are
found, and walks only those owners' keys: no scan of every noted range and no Weak upgrade of
unused ones. Noted ranges are indexed by buffer key and owner; those of buffers that are gone are
replaced on note and swept when the set doubles. Before, every split part of a commit scanned
every noted range: reims's Launchpad walk spent 14% of commit_and_submit there. That changes
runtime work.
Verified by the change's own runs on the RX 7900 XTX (MANAGED-STALE-TAKE, 200 commits of 24 blit
encoders and one Managed range each, bytes checked every commit), median commit call before ->
after: 0.0061 -> 0.0066 ms with no stale buffers, 0.874 -> 0.0070 ms with 1,000, 9.16 -> 0.0062 ms
with 10,000. managed_copy_device 30 passed on the XTX; lavapipe suite 2470/2470; clippy plain,
--cfg m2v_cpu_icd and --cfg m2v_gpu and rustdoc green.
What: managed.rs's Noted keeps each buffer's ranges by its key and indexes them by what owns
its memory (used_resources::owner_of, asked as the range is noted). Modified::take_at_commit
asks the committing command buffer once which of the noted owners it may use
(CommandBuffer::may_use, State::named_among: every encoder record's keys read once, under one
lock of each registry, until every noted owner is found; all where a command reaches memory no
use names or the last encoder's end is not lowered), then takes those owners' buffers' ranges
and those no owner holds, in the order each buffer was first noted. used_resources::names_of
and HeapKeys::names_of answer for a set of owners where names_any answered for one. A note
drops buffers gone once the buffers noted pass twice their count at the last sweep, and a key
noted again whose buffer went starts anew, so ranges of buffers no commit uses do not pile up.
A note looks at its own buffer's ranges alone (it compared every noted range's buffer).
Why: a consumer's compositor frame commits in 27 parts; the take was 14.9% of
commit_and_submit (Noted::take 14.1%, the uses closure 8.1%, HeapKeys::names_any ~5%): every
commit upgraded every noted range's buffer and asked every encoder record of each, and ranges of
buffers no commit uses stayed noted, scanned at every part. Now a commit costs one read of its
own uses where an owner's ranges are noted, and nothing where none are. Which ranges a commit
takes, and so which bytes each command buffer reads, is unchanged.
Verified: tests::managed's take-rule test rewritten for the new rule (stale gone buffers swept);
the bench before and after follows on the RX 7900 XTX.
What: tests::managed_copy_device::stale_ranges_take_bench (ignored, MANAGED-STALE-TAKE):
the median commit call of 200 command buffers of 25 blit encoders, one reading a Managed
buffer whose range each commit takes (its bytes checked at each), beside 0, 1,000 and
10,000 Managed buffers whose ranges are named and that no commit uses.
Why: a consumer's compositor frame commits in 27 parts; Modified::take_at_commit was 14.9%
of commit_and_submit there (Noted::take 14.1%, the uses closure 8.1%): every commit scans every
noted range and asks each encoder record of each, and ranges of buffers no commit uses stay
noted. This bench measures that per-commit cost before and after the next commit.
Verified: run with the next commit's change, before and after, on the RX 7900 XTX.
The landed packet changed a runtime-sources input, so the committed digest no
longer described the sources and `the_runtime_sources_are_the_committed_ones`
would fail. Recomputed over the same inputs and committed by land-pkt.sh.