The two commits before this one: canon compiles the uint2 overloads of map_screen_to_physical_
coordinates and map_physical_to_screen_coordinates beside the float2 ones, reusing the float2
decoder. Screen to physical is the float2 answer at the pixel's centre, converted to uint
(saturating, NaN 0); physical to screen is the bits of the float (0 - offset) * reciprocal of the
entry of granule c >> 5, as an Apple M3 Max answers (the coordinate's place inside its granule is
not read). The maths is the device's float (owner rule 1), under the existing denormals note. A
table entry's boundary byte is compared on its low seven bits, as Metal does, for float2 too.
Until now a fragment or kernel using the uint2 forms was refused Unsupported{RasterizationRateMap,
NotImplemented}, where Metal makes it (the consumer's Modern Rendering sample's light-heatmap
pipeline). Translator output changes (SEMANTICS); docs/REFUSALS.md is regenerated.
Verified by heapchunk's runs: the M3 probe rate_map_integer_overloads (m3-max-25539, macOS
27.0.1): 20,114 coordinates over 4 maps, at each map's layers and two past them, every one
matching both formulas; 1,561 of those answers kept as test vectors (Metal's answers to our probe
on our maps). At 247e8b66b2 (25640): metal2vulkan-air rate_map 7/7, metal2vulkan 54/54
(bind::rate_map, engine_rate_map with the integer tests, public_fixtures_engine::llvm_as,
engine_refused_families, refusal_surface); the translated kernel in the interpreter equals the
M3's recorded answers at all 587 points on the maps' own layers on 4 profiles. Negative control:
without the seven-bit mask 2 of the 1,561 answers differ. clippy plain, m2v_gpu and m2v_cpu_icd
and rustdoc clean (25607, the same diff before the rebase). Release: the uint2 kernel 0.24 s cold,
about 32 MiB, on moltenvk-m3. The fixture's two .air.ll rows (macOS-only metal-as) run at the
next pin's checks.
A fragment shader's map_screen_to_physical_coordinates and
map_physical_to_screen_coordinates with uint2 arguments were refused
(Unsupported{RasterizationRateMap, NotImplemented} at the lowering of
Fragment::MapCoordinates). Canon now expands them beside the float2
overloads, reusing the float2 decoder:
- screen to physical: the float2 decoder at the pixel's centre (c + 1/2),
converted to uint saturating (a NaN to 0), the conversion the float2
index path already uses;
- physical to screen: the bits of the float (0 - offset) * reciprocal of
the entry of granule c >> 5 on the axis's to-screen table; the
coordinate's value within the granule is not read.
Both are Metal's answers as our probe rate_map_integer_overloads measured
them on an Apple M3 Max under macOS 27.0.1: 20,114 coordinates over four
maps (one of two layers), at each map's layers and two past them, every
one equal to these formulas. The arithmetic is float and the device's own
(owner rule 1); where a device's denormals differ from Metal's flushed
ones the existing PrecisionNote::DeviceDenormals reading applies, as for
the float2 decoder. The boundary byte of a table entry is compared on its
low seven bits, as Metal's decoder does (the probe's maps hit an entry
with the high bit set).
The decoder's Rust models gain shader_screen_to_physical_integer and
shader_physical_to_screen_integer. Lowering's MapCoordinates arm is now an
invariant error: canon compiles every overload before lowering.
Tests:
- bind::rate_map::apple_tests::metals_integer_answers: 1,561 of the M3's
answers (apple_integer_vectors.txt: Metal's answers to our probe on our
maps, no Apple binary) against the Rust models, each map's bytes
checked by sha-256;
- tests::engine_rate_map::integer: the fixture rate_map_integer (kernel
and fragment) compiles on every tested profile, robust and not, passes
L3 with no RasterizationRateMap note; the interpreter's answers equal
the decoder's arithmetic at every layer and two past, and Metal's on a
map's own layers; and the translated kernel's answers equal the M3's
recorded ones at all 587 recorded points of the maps' own layers, bit
for bit;
- the fixture's four expectation rows go from the refusal to ok on all
profiles; integer_rasterization_rate_maps_are_refused is removed.
docs/REFUSALS.md regenerated: the fragment select site leaves the
RasterizationRateMap sites.
What: rate_map_integer.metal, MSL of ours compiled by scripts/regen-air-fixtures
(.ll and .air.ll companions, TOOLCHAIN line), holding the uint2 overloads of
rasterization_rate_map_decoder's map_screen_to_physical_coordinates and
map_physical_to_screen_coordinates in both directions: a kernel over
coordinates a buffer holds, and a fragment function over its own pixel, the
shape of the consumer's light-heatmap fragment shader. Its rows in
public_fixture_expectations_engine.tsv state today's answer on every committed
profile: Unsupported{RasterizationRateMap; NotImplemented}, the refusal at
lower/fragment/mod.rs's Fragment::MapCoordinates (canon compiles only the
float2 overloads).
And probes/rate_map_integer_overloads.m (conformance): plain Metal's answers
of both uint2 overloads beside the float2 ones and the map's CPU answers, at
every integer coordinate along each axis of four maps, at each map's layers
and two past them.
Why: the consumer's Modern Rendering sample's light-heatmap pipeline is
refused for these calls; Metal accepts them. This commit records the refusal;
the next lowers the overloads.
Verified: not run at this commit; the fixture rows are checked by
public_fixtures_engine at the next commits' runs.
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 commit before this one adds WorkCounts::indirect_record_bytes_gpu_copied and
indirect_record_bytes_gpu_reset: a blit's copyIndirectCommandBuffer and resetCommandsInBuffer
count their records' bytes (COMMAND_BYTES, 2248 a command) as each is encoded. On the RTX 2080 a
copy of 8162 records (18.3 MB) took 16.25 ms of GPU time against 0.66 ms for executing them (the
commit body's table), so a guest walk's counts decide whether sizing records by their descriptor
pays. Counting is runtime behaviour (RUNTIME).
Verified by ratemap's runs on msi (25624, before the rebase onto 65ad8ba049): clippy clean
workspace-wide and on the runtime under --cfg m2v_gpu; the new device test (a copy of 3 commands,
an empty copy and a reset of 2: 3 and 2 records' bytes) and the ICB setters test pass on
lavapipe; signatures --check passes.
A blit's copyIndirectCommandBuffer and resetCommandsInBuffer move whole
records on the GPU, COMMAND_BYTES (2248) a command whatever the
buffers' descriptor, and nothing counted them. One timestamp-split run
showed they can dominate a command buffer: the 8162-command indexed
merged GPU form of the trail tests, each part its own command buffer on
one device with the trail off (RTX 2080, NVIDIA 620.70.06, a release
build at c9c7b364fb, a measurement not landed):
part GPU time (ms)
blit of the 8162 records into a Shared ICB 16.253
the same into a Private ICB 16.779
execution of the Shared ICB, cold 0.659
execution of the Shared ICB, warm 0.658, 0.657
execution through an empty range (the preprocess
and both merge passes over every command) 0.151, 0.151
execution of the Private ICB 0.657, 0.661
blit and execution in one command buffer, Shared 16.854, 17.838
blit and execution in one command buffer, Private 17.282, 17.877
the trail test's own command buffer 17.051
The 18.3 MB of records the blit reads from the Shared source over the
bus (about 1.1 GB/s there, whatever the destination) are 95% of the
command buffer; the execution's preprocess and merge passes are
0.15 ms, and reading the records from a Shared or a Private buffer
changes nothing measurable.
Whether a workload moves records this way decides whether records
sized by their buffer's descriptor are worth their cost, so the blits
now count what they move, as each is encoded:
WorkCounts::indirect_record_bytes_gpu_copied and
indirect_record_bytes_gpu_reset. A device test encodes a copy of 3
commands, an empty copy and a reset of 2, and checks 3 and 2 records'
bytes.
The commit before this one replaces Reach with a search (lower/simd/lockstep/search.rs) that tries
no pair whose barrier is already a want, answers from one side where a block is uniform, walks
breadth-first, and stops expanding a block whose dominator (forward) or post-dominator (backward)
subtree is closed, barrier-free and acyclic once every divergent block in it is answered, trying
the uniform blocks inside by preorder interval. The wants are unchanged by construction, but
kernels refused as FALLBACK WorkUnits now translate, so a cached refusal must be computed again
(SEMANTICS).
Verified by radvcompile's runs: golden_hashes_match_the_table passes at the change and at
b60fd75969, engine_simd_lockstep 27/27 (m3-max-25588). a_long_barrier_free_kernel_s_work_grows_
with_its_blocks: whole-compile work for P0 K1 2.84M at S1024 and 11.38M at S4096 (4.0x, bound
6x); the_authored_4096_step_kernel_compiles_inside_the_budget (P1 K16) takes 36.98M units. On the
old search both fail LimitExceeded(WorkUnits) at 134,217,729 units (negative control 25582).
Unbounded work: P0 K1 S4096 313M -> 11.4M, P1 K16 S4096 328M -> 37.0M. Release command line on
msi (25596): P1 K16 S4096 1.41 s / 264 MB (RTX 5080 profile), 1.69 s / 279 MB (Iris); P0 K1 S4096
0.40 s / 73 MB; P1 K16 S2048 1.27 -> 0.70 s. Known open: a pair that never conflicts and whose
answer is never a want (many divergent writes to distinct objects all reaching each other) is
still tried against every access it reaches.
The pair search walked every block each written block reaches, forward from its writes and back
from its writes to the reads, and tried each reached pair. On a long barrier-free body whose
pairs conflict that is quadratic in the blocks: the authored `grow` kernel of 4,096 steps (P1 K16,
about 258,000 instructions, 12,000 blocks; and P0 K1, about 57,000 instructions) was refused with
FALLBACK WorkUnits, though under the inline cap.
What changes (lower/simd/lockstep/search.rs):
- A pair whose barrier is already wanted is not tried. Place's answer depends on one side only
when a block is uniform across the threadgroup (after `a`, or before `b`), and on the source
block alone for a divergent target that its crossing block dominates (the first uniform block on
its post-dominator chain that does not dominate it, with no earlier chain block under it). Wants
only grow, so a skipped pair stays answered.
- Walks are breadth-first and stop expanding a block whose dominator subtree no edge leaves, with
no barrier and no retreating edge (forward), or whose post-dominator subtree no edge enters from
outside (backward), once every divergent block in it has its pairs answered. The uniform blocks
inside it whose barrier is not wanted yet are tried directly, found by preorder numbers. A walk
from a uniform block ends once each of its writes has its barrier.
- A block's own end reaches its start (a loop around it) from the strongly connected components
of the barrier-free body, walked only for a block with a barrier.
- conflict() is monotone in the back-edge flag for two different accesses, so trying a pair once
per way it is reached gives the wants trying it once with every way would.
The wants, and so every barrier, are unchanged.
Verified (msi, nextest):
- golden_hashes_match_the_table passes at this change and at b60fd75969 (m3-max-25588).
- engine_simd_lockstep: 27/27, with the two new tests; clippy -p metal2vulkan --all-targets
--all-features -D warnings rc 0 (m3-max-25588).
- New test a_long_barrier_free_kernel_s_work_grows_with_its_blocks: whole-compile work 2.84M at
1,024 steps (P0 K1), 11.38M at 4,096 (4.0x; the test allows 6x). New test
the_authored_4096_step_kernel_compiles_inside_the_budget: 36.98M work units. Both fail on the
old search (m3-max-25582): LimitExceeded(WorkUnits) at 134,217,729 units.
- Unbounded work, old -> new: P0 K1 S4096 313M -> 11.4M; P1 K16 S4096 328M -> 37.0M.
- Release command line (m3-max-25596): P1 K16 S4096 1.41 s / 264 MB (RTX 5080 profile), 1.69 s /
279 MB (Iris); P0 K1 S4096 0.40 s / 73 MB, 0.45 s / 73 MB; P1 K16 S2048 0.70 s (was 1.27 s).
The census at the pin-70 tip (m3-max-25568): 2369 cases over 21 profiles, 48670 compiled, 1079
refused, 0 failed, 0 differences, 0 regressions, 348 uncovered cells as at pin 69. 188 cells'
artifact hashes move with SEMANTICS_VERSION 2086-2088, each still compiled. The slowest compile
took 3.2 s and the largest worker 222 MiB, inside the 20 s and 500 MiB ceilings.
The golden tables at the pin-70 tip (m3-max-25567): 3 golden hash rows move under unchanged keys
with SEMANTICS_VERSION 2088 (a loop's AIR unroll request reaches its OpLoopMerge):
engine/hnq_half_layer_composite (.ll and .air.ll; #pragma unroll asks Unroll) and
kernel_threadgroup_float_bbox_atomics (unroll(disable) asks DontUnroll). The inventory and the
golden printouts are unchanged. 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.
The two commits before this one carry a loop's llvm.loop unroll metadata from the AIR latch to
its SPIR-V OpLoopMerge: unroll.full and unroll.enable ask Unroll (clang's enable: fully where the
trip count is known, partly otherwise, SPIR-V's "to the degree possible"), unroll.count N asks
PartialCount N (SPIRV_VERSION 1.5 has it, held by a const assertion), unroll.disable asks
DontUnroll, and a count of 0 or no request asks nothing. Metal's compiler honours the same
requests; until now every OpLoopMerge carried None. It changes no answer, so it is not a
speed-for-accuracy choice. Translator output changes (SEMANTICS). docs/REFUSALS.md follows a
renamed site (structure_loops).
Verified by imgleak's runs: engine_loop_unrolling, one test per form (5/5 at ba2b803e57, 25358);
negative control with e7ea80f1bb's lower/view.rs, so no request is read: the four form tests fail
(unroll_count [[0]] where [[256, 4]] is expected), the no-request test passes (25376). Before the
rebase, clippy -p metal2vulkan all targets and features clean and 585/586 touched tests, the one
failure golden_hashes on kernel_threadgroup_float_bbox_atomics (unroll(disable)) and
engine/hnq_half_layer_composite (#pragma unroll), re-blessed at the next pin (25343).
Cold creation (driver caches off) and GPU time of the SR conv kernel 199ed, read in place on
um790, base b4a3e4e91c -> nuw e7ea80f1bb -> unroll (25521-25523): RTX 2080 creation 0.076 ->
0.083 -> 0.448 s, GPU 119.8 -> 120.3 -> 6.46 ms a dispatch (binary 23936 -> 106368 B); RX 7900
XTX 0.021 -> 0.116 -> 0.044 s, 12.7 -> 0.72 -> 0.71 ms; Radeon 780M 0.019 -> 0.043 -> 0.042 s,
over 6 s -> 6.08 -> 6.04 ms. On the 2080 the hint costs 0.37 s of cold creation once and saves
113 ms a dispatch; on the AMD devices it keeps nuw's creation and cuts code 15404 -> 12448 B.
Authored fixtures on all three: creation within run-to-run noise.
The coordinator widened the rule: Metal's compiler honours a plain
#pragma unroll, which it writes as llvm.loop.unroll.enable, so leaving it
unhinted dropped the source's intent. clang's enable means unroll fully
where the trip count is known, else partly: SPIR-V's Unroll, "to the
degree possible". The mapping now:
- unroll.full, unroll.enable: Unroll (0x1);
- unroll.count N, N >= 1: PartialCount (0x100) with N, a SPIR-V 1.4
control; every module is 1.5, held by a const assertion beside
SPIRV_VERSION;
- unroll.disable: DontUnroll (0x2);
- nothing else, a count of 0 included, asks anything.
Unrolling gains PartialCount(u32) and literal(); the serializer keeps
each loop's Unrolling and writes the literal after the control, and its
lookup takes .get() (clippy's indexing_slicing, from m3-max-25303).
Tests: engine_loop_unrolling, one test per form (full, enable, count 4,
disable, count 0 and no request), each checking its loop's OpLoopMerge
words after the targets and the interpreter's answer (10) on four
profiles, with spirv-val. m3-max-25303 passed the first test and every
touched test but the golden table, whose 19 bbox-fixture cells move
with its unroll(disable) loop (main re-blesses at landing).
The AIR states a loop's unroll request on its latch (!llvm.loop), and the
front end decoded it (LoopHints) but every OpLoopMerge asked LoopControl
None. A latch carrying llvm.loop.unroll.full now makes its loop ask
Unroll, and one carrying llvm.loop.unroll.disable DontUnroll; nothing else
asks anything. Metal's compiler writes unroll.full for #pragma clang loop
unroll(full), unroll.disable for #pragma nounroll, unroll.enable for
#pragma unroll and unroll.count N for #pragma unroll N (xcrun metal -O2,
checked on the M3); the last two still ask nothing.
The hint changes no answer, so there is no switch and no FAST-PATHS row.
It changes translator output, so SEMANTICS moves at landing.
How: LoopMeta's dont_unroll bool becomes Unrolling {Driver, Unroll,
DontUnroll}, carried by Stmt::Loop and LoopSpec; the serializer writes
each loop's control from a sorted table. CfgView::unrolling reads a
block's terminator hints (EntryView: the latch's LoopHints); the
structurizer takes, per loop, the request of the first of its own blocks
that makes one, metered. The rolled regions, the dispatch loop, the
anisotropic routine loop and the fan-out loop keep DontUnroll.
Test: engine_loop_unrolling, four kernels summing words 1..4 (full,
disable, enable, no request), checks each OpLoopMerge's control and the
interpreter's answer (10) on four profiles. Verification: msi job 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.
The commit before this one adds a fifth 32-lane set to the rate-map fan-out probe: a flagged
triangle adds 1 into the word its PrimitiveId picks, Probed::flagged_triangles sums the set, and
WorkCounts::rate_map_flagged_triangles counts every flagged triangle of every instance once.
PROBE_DRAW_WORDS = 1 + PROBE_SETS * PROBE_COUNT_WORDS is the one place the word count is stated.
flagged_triangles over parted_region_triangles is the density that decides whether drawing blocks
of flagged triangles pays. The probe's SPIR-V changes (SEMANTICS); the counter is new (RUNTIME).
Verified by ratemap's runs: rate_map_probe_gpu_nanos on lavapipe, 3 alternating rounds, the first
cold, before (44eda17f1d) 20.63, 3.44, 2.43 ms against after (44665e1bce, the same diff) 16.36,
2.60, 1.79 ms, after below before in every round (25310). clippy all targets and features clean;
translator and runtime suites 5066/5067 (25455), the one failure golden_hashes on 40 rows its
base 65ca5fc387 fails the same (re-blessed at pin 69); signatures and the refusal surface
checked. The link test now counts 2 AtomicIAdd, the probe-words unit test sums the fifth set, and
the fan-out device test counts 4 flagged triangles.
A flagged draw drawn in parts draws its triangles from the first the
probe flagged to the last region by region
(rate_map_parted_region_triangles), but nothing said how many of those
are flagged themselves: the probe kept only the first and the last.
That density decides whether drawing blocks of flagged triangles apart
would cut the region-by-region triangles.
The probe's geometry stage now adds one, for a flagged triangle, into
the word its PrimitiveId picks of a fifth set of PROBE_COUNT_WORDS after
the flag (PROBE_SETS = 5, PROBE_DRAW_WORDS = 1 + PROBE_SETS *
PROBE_COUNT_WORDS, the only place the word count is stated). The
runtime sums that set (Probed::flagged_triangles) and counts it at the
probe: WorkCounts::rate_map_flagged_triangles. The pieces lane prints
it beside the parted draws' region-by-region triangles and checks it
is non-zero exactly where draws were flagged, and no more than those
triangles.
Tests: the probe's link test counts two atomic adds (the copies', the
flagged count's); the probe words' unit test sums the fifth set; the
fan-out device test checks its four flagged triangles.
The probe's GPU time, verified on lavapipe (LP_NUM_THREADS=1, as CI)
by the fan-out device test (rate_mapped_fan_out::a_host_step_fans_out_
the_commands_the_probe_does_not_flag, one probe of 8 draws, 4 flagged),
release runtime binaries under --cfg m2v_cpu_icd at 44eda17f1d (before)
and this change on that base (after, 44665e1bce), taking turns on msi,
rate_map_probe_gpu_nanos:
before 20.63, 3.44, 2.43 ms; after 16.36, 2.60, 1.79 ms (the first
round of each cold). No growth past the noise: each round's after is
below its before.
Also, from the landed device-local replay scratch (RUNTIME 2220): its
resident root table now lies at a multiple of 32 bytes, which fixes the
internal refusal (RootTable::resident_fields, a moved resident set)
that the old scratch could meet where the upload alignment is 16
(RADV, lavapipe), read from the code, not observed; the compute replay's
scratch (gpu_execute.rs) is upload_aligned to 32 with its table at
slots * SLOT_TABLE_BYTES + PARAMS_BYTES, a multiple of 32, so it has
none.
What: a known-gaps entry for the copied-host-pages copy of a no-copy object
whose pages cross the end of a guest RAM's chunk with both chunks imported
(CopiedBecause::OverRamChunk). The consumer's boot makes one on the RTX 2080
and the RTX 3090: a 2 MiB Shared heap 0xde000 bytes before a 64 MiB chunk's
end. It names why only NVIDIA meets it and why no in-place form exists there.
Why only NVIDIA: the plan, not alignment. NVIDIA's held pointer imports cost
a submission nothing, so its plan is Plan::AHEAD: the device's thread imports
the RAM's chunks by pointer before the objects over them exist, and a
straddling object finds both imported. RADV and ANV take the listed plan
(the consumer's RAM has a dma-buf source and each held import costs every
submission there): a chunk is imported only for a copy over it, and an object
over chunks no copy imported takes its own import.
Routes judged:
- Sparse binding over both chunks' imports: VUID-VkSparseMemoryBind-memory-01096
needs a memory type the sparse buffer takes; on the RTX 2080 (620.70.06)
that is type 1 alone (device-local, 64 KiB alignment), every usage, with the
host handle type or without, where host pointers import as types 3 and 4
(system memory). The intersection is empty.
- A plain buffer binds one memory, its whole size inside it
(VUID-vkBindBufferMemory-buffer-07459, -None-10741).
- Chunk ends that follow objects: each chunk is imported before the objects
over it and binds others by the time a straddling one comes; no cut or
extension puts the object in one memory without a page imported twice.
- An own import beside the chunks: of the pointer, a second import of the
same pages (VK_EXT_external_memory_host issue 6); of dma-bufs, an alias of
a pointer import Vulkan does not define (the beside route exists only for
dma-bufs beside dma-bufs on the listed plan).
- The Managed route's GPU copy in (003dc10fee) rests on Managed's explicit
synchronization; a Shared copy's coherence is the three-way merge at every
commit and completion, which a GPU form would run over the host pages at
each batch's start and end.
Verified on the RTX 2080 (620.70.06, um790, potluck m3-max-25500, at
65ca5fc387): tests::sparse_host_pages printed the types above ("the
intersection is empty: no bind"); host_ram_device's
a_heap_across_two_imported_chunks_is_a_copy_and_imports_nothing passed, its
copied-host-pages notice naming the chunk cause. Docs only; no code changed.
The commit before this one keeps one block's reachable list at a time in the lockstep pair
search, so a long barrier-free kernel no longer runs out of its ledger. The pairs, wants and
barriers are unchanged, but kernels that were refused (FALLBACK LedgerBytes) now translate, so a
cached refusal must be computed again (SEMANTICS).
Verified by radvcompile's runs: release on msi, the authored P1 K16 S2048 kernel (about 129,000
instructions) from FALLBACK LedgerBytes in 0.71 s to translated in 1.27 s at 139 MB resident on
the RTX 5080 profile and 1.30 s / 149 MB on Iris; S1024 unchanged at 0.50 s / 78 MB
(m3-max-25407). Negative control (25404, the new tests on the old search): ledger peak 10.3 MB at
256 steps against 144.5 MB at 1024 (14x), so the at-most-5x test fails, and the 2048-step test is
refused at 471.85 MB. At 0e4f537ef7, fmt and clippy rc 0 and the metal2vulkan suite 3545/3546
(25405). The one failure, golden_hashes_match_the_table, lists the same 837 cells at the tip and
at its base 65ca5fc387 alone (25442), all re-blessed at pin 69. Known open: a 4096-step kernel
is still refused (WorkUnits), the pair search's work being quadratic; that is next.
The lockstep pair search (lower/simd/lockstep.rs, pairs) asked Reach for each block's blocks
reachable on barrier-free paths and kept every list it computed, cloned each list it walked
(charged and never released), collected each written block's writes into a charged vector, and
left each walk's touched list on the ledger. On a long barrier-free body every block reaches
every later one, so the kept lists and the leaked charges grew with the square of the blocks: an
authored kernel of 2,048 steps (about 129,000 instructions, 6,000 blocks) was refused
LedgerBytes in 0.7 s with 135 MB resident, the ledger at 471.8 MB of its 471.9 MB bound when
Reach::of grew one more list.
Reach now keeps only the last block's list (pairs asks one block at a time, its accesses in
block order, so a block is walked at most once a pass) and releases the one before; pairs
borrows the lists instead of cloning them, filters a block's writes before its first barrier on
the fly, and releases Reach's tables as it ends; a walk releases its touched list. The answers
are the lists as before, so the pairs, wants and barriers are the same.
Tests (engine_simd_lockstep): a long barrier-free kernel's ledger peak grows at most five times
for four times its steps (a_long_barrier_free_kernel_s_ledger_grows_with_its_blocks), and the
authored 2,048-step kernel compiles inside the standard budget
(the_authored_2048_step_kernel_compiles_inside_the_budget).
The census at the pin-69 tip (m3-max-25454): 2369 cases over 21 profiles, 48670 compiled, 1079
refused, 0 failed, 0 differences, 0 regressions, 348 uncovered cells as at pin 68. 462 cells'
artifact hashes move with SEMANTICS_VERSION 2084 and 2085, each still compiled. The slowest
compile took 2.1 s and the largest worker 231 MiB, inside the 20 s and 500 MiB ceilings.
The golden tables at the pin-69 tip (m3-max-25453): 88 golden hash rows move under unchanged keys
with SEMANTICS_VERSION 2084 (a pressured kernel takes the Emulated tier in place of the widest
mode's pin on the four ANV profiles) and 2085 (a narrow integer operation the AIR marks nuw keeps
no mask). The inventory and the golden printouts are unchanged. 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.
The commits before this one: a spare command pool keeps, past its last RECENT_USES uses, as many
command buffers of each level as its uses in the last two RECENT_FOR spans handed out, and
RECENT_FOR goes from 1 s to 5 s. A frame's count of command buffers varies over seconds, so with
1 s spans a pool freed command buffers a later frame took again, trimmed, and made them anew: on a
guest's walk on the RX 7900 XTX (RADV), 60-110 command buffers a second freed past recent uses,
10-14 trims a second, about 43 ms a second in allocate_command_buffers and 39 ms a second on the
free thread. HELD (4096) and IDLE_FOR (10 s) still bound what is kept. tests::spares_walk is a
walk-shaped load (a frame of 47-141 passes about 41 times a second beside about 1,600 small
command buffers a second from three queues); pass_costs gains fresh primaries per pass and
--begins. Keeping more spares changes runtime behaviour (RUNTIME).
Verified by perdraw5's runs, release, two rounds per side: 780M (RADV, 25293) 24.8 and 5.2
command buffers allocated a second before, 14.2 and 2.4 freed, 4.2 and 1.4 trims; 0, 0 and 0
after. lavapipe (25352): 2.6 and 7.4 allocated a second before, 0.4 and 0 after. Thread time per
command buffer within noise; spares held 554-623 command buffers after against 504-726 before.
clippy plain and m2v_cpu_icd, Rustdoc and the 23 spares tests on lavapipe pass (25418). The proof
on the real load is a guest walk, where the frees and trims counters should fall to near zero.
A guest's Launchpad walk on the RX 7900 XTX freed 60 to 110 command
buffers a second past their pools' recent uses (spare_command_buffers_
freed_past_recent_uses), with 10 to 14 trims a second, and made them
again: its profile had about 43 ms a second inside allocate_command_buffers
(secondaries for passes not inline, encoder primaries, continuations,
barrier primaries, stocked secondaries) and 39 ms a second in the free
thread's frees and trims. pass_costs on the 780M: a primary made new (its
pool trimmed) costs about 13 us to allocate, 14 to 16 us to begin and 23
to 26 us to free and trim, against 0.6 to 0.9 us to begin one kept.
A frame's count of command buffers varies over seconds, and spans of 1 s
forgot what a pool handed out within two. RECENT_FOR is now 5 s; HELD
(4096) and IDLE_FOR (10 s) still bound what the spares keep.
Verified: tests::spares_walk on lavapipe (msi, job m3-max-25352, release,
two rounds each): spans of 1 s allocated 2.6 and 7.4 command buffers a
second and freed 7.2 and 5.2, with 1.0 and 1.2 trims; spans of 5 s
allocated 0.4 and 0 and freed none. The thread time of each command
buffer did not move past the run's noise (compositor 1,673 and 1,559 us
against 1,677 and 1,563; small 74 and 63 against 65 and 69). The RADV run
(780M) is queued; the walk itself is reims's.
A steady shape settles to no churn (a model of the spares' policy agrees);
the walk's frames vary, and a pool's share of a varying frame is what its
recent uses forget. A fixed sequence keeps the runs comparable.
Verified: cargo fmt; the run is the next potluck job.
An ignored measurement: a compositor queue commits a command buffer of 94
render passes about 41 times a second while three queues commit about
1,600 small command buffers a second together (one pass, one blit or two),
two in flight each. Over 5 s after 3 s it prints the command buffers the
device allocated a second by place, the spares' frees by why and the
trims, the spares' count, each kind's thread time and the process's CPU.
The walk's counters show the spares freeing about 100 command buffers a
second (past recent uses, idle sheds) with about 10 trims, and its profile
about 43 ms a second inside allocate_command_buffers and 39 ms a second
on the free thread; this reproduces the shape to find why and test a fix.
Verified: cargo fmt; the run is the next potluck job.
Two shapes allocate each pass's primary and free it once its frame
completed: per-pass-fresh leaves the pool untrimmed (Mesa's common pool
recycles a freed command buffer), per-pass-fresh-trimmed trims it, so each
allocation makes a new command buffer with no command stream memory yet.
--begins times each vkBeginCommandBuffer and each instance's begin alone.
They test whether a fresh primary's command stream memory is the walk's
6.8 us vkCmdBeginRenderPass, which the reused primaries do not show.
Verified: cargo fmt; the build and the run are the next potluck job.
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 two commits before this one: a draw that samples a color attachment's texture after a barrier
inside its instance stays in the instance when nothing the instance drew meets the texels it
reads. It reads the copy taken before the instance, which holds what a split's copy would. It
stays only when the instance holds draws alone (no continuation, execution or reformat), no rate
map or views, each presented color is loaded and changes only inside the draws' scissors, no
other write reaches the texture's truth, and the read rectangle misses every drawn rectangle.
WorkCounts::attachment_read_splits_spared counts it. Answers are unchanged by construction; the
instance's form changes (RUNTIME).
Verified by radvcompile's runs: at d29f41e71b, fmt, runtime clippy (all targets and features)
and runtime doc -D warnings rc 0, the CPU-ICD runtime device subset 312/312 (attached_read,
self_read, learned_coverage, kept_shadowed, snapshot, own_pixel, shadow, render, pass) and
conformance replay --cpu rc 0 with the known-gaps rows only (m3-max-25375); api_signatures and
api_surface 15/15 (25422). attached_read_standing's new test on lavapipe: spared 1, splits 0, the
bytes from before the pass; its overlapping control splits and reads the draw's texels; before
the fix the test failed (split 1). Not yet measured on NVIDIA.
A draw that samples a color attachment's texture after a memory barrier inside its render pass
instance records into a new instance, before which the texture's copy is taken. Where the
instance drew none of the texels the draw reads, the copy taken before the instance already holds
every one of them as the split's copy would, so the split only costs an end and a restart of the
pass (and the stores and loads between).
The draw now stays in its instance there (render.rs, reads_what_the_instance_drew): the instance
is one of draws alone (not continuing another, no execution, no stand-in of another format) in a
pass of no rasterization-rate map or views; each color the texture presents is one the instance
loads and changes only inside its draws' scissors (render/shadows.rs, drawn_alone, split out of
bounded_color); no draw of the instance wrote the texture's truth another way
(InstanceShadows::writes_truth); and the instance's drawn area (clear_reach::DrawnArea::meets)
meets none of the texels the draw reads: those around its scissors where it reads the texture at
its fragments' own pixels alone (read_at_own_pixels, split out of bound_own_pixel_reads), else
every one. WorkCounts::attachment_read_splits_spared counts such draws.
Answers are unchanged by construction: the texels read are the same in both copies.
Test: attached_read_standing's
a_reader_after_a_barrier_of_texels_its_instance_never_drew_spares_the_split (a draw of rows 10
to 16, a barrier, an own-pixel read of rows 4 to 8: no split, one spared, the bytes the texels
from before the pass; a draw of rows 6 to 12 then splits and the read takes its texels).
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 three commits before this one move a merged GPU-form execution's draw replay scratch from
upload memory into Device::scratch_buffer, Private class (DEVICE_LOCAL, not HOST_VISIBLE, by the
documented memory property flags), retained until the command buffer completes. The host uploads
only the head (parameters, the resident root table and its set, extents, encoder buffers, the
merged header) and one vkCmdCopyBuffer between barriers carries it in before the range copy and
the preprocess. The root table sits at a multiple of 32 in the scratch, as
RootTable::resident_fields requires. The preprocess writes every byte the merge passes, draws and
trail read, so no clear is needed. With the trail on, the GPU copies the sections the line reads
into an upload region after the passes. WorkCounts::gpu_form_device_local_bytes is new. The
translator is unchanged; the runtime's placement changes (RUNTIME).
Verified by ratemap's runs: RTX 2080 (620.70.06), whole command buffer GPU time, release lib-test
binaries before (069ad0c586) and after (39eeb6a40a, the same diff), 3 alternating rounds (25248):
the indexed merged form over 8162 commands 18.63/18.70/18.62 ms -> 17.08/17.06/17.11 ms (-8%,
1,897,280 scratch bytes device-local); the 4-command merged form 0.344/0.391/0.397 ->
0.337/0.373/0.375 ms. Both tests assert their exact expected texts; all 12 runs pass. At
46ba4e215a: clippy all targets and features clean (25257); suites 5058 pass, 2 fail (25258,
golden_hashes and part_5_of_8 on the tns_mm_fp8 rtx50 rows, blessed at pin 67). The GPU-form pixel
lanes on the 2080 and 780M are pending.
An execution of render commands recorded in its GPU form wrote its whole
scratch into the command buffer's upload arena, which on a discrete GPU
is system memory. The preprocess wrote its slot tables, arguments and
index entries there, the two merge passes' serial loops read and wrote
the prefix and block sums there many times a command, and every draw
read its slot tables and arguments there, all across the bus.
The scratch is now a buffer of the runtime's own in Private memory
(Device::scratch_buffer), held by the segment's encoder until the
command buffer completes. The host still writes the head alone (the
parameters, the resident root table and its set, the extents, the
encoder's buffers and a merged replay's header) into an upload region,
and a copy carries it into the scratch between barriers before the
range's copy and the preprocess. The command buffer's first submission
still points the table in that region at the resident set as it lies
then, before the copy runs. The table lies at a multiple of an entry in
the scratch (the buffer takes 32 more bytes and the scratch starts
where that holds), as RootTable::resident_fields needs of a table and
its set.
The translator is unchanged: the kernels still address every section
from the resident table's address, so the scratch stays one buffer.
The preprocess writes every byte the merge passes, the draws and the
trail read (every command's arguments, zero where it draws nothing; a
merged replay's index entries, prefix, block sums and draws), so the
unzeroed buffer needs no clear.
With the encoder trail on, the GPU copies the words the trail's line
reads (GpuForm::sections: the range copied, the merged draws, the first
2^20 commands' arguments and their index entries) into an upload region
at the scratch's offsets once the passes that write them ended, and
the line reads that copy. Off, nothing is copied.
WorkCounts::gpu_form_device_local_bytes counts the scratch bytes the
device placed in device-local memory (checked on the buffer's pages),
and the trail GPU-form tests assert it is non-zero where a GPU form was
recorded, with their texts unchanged.
The two commits before this one: an add, sub, mul or shl of a narrow integer that the AIR marks
nuw no longer masks its result to its width, since any result that would carry is poison; where
a poison value meets something that must stay defined (freeze, a store's words, a narrow
atomic's operand, a bitcast's packed lanes) it is masked. A chunked vector of padded integer lanes
is frozen chunk by chunk, which the moltenvk-m3 profile had refused. Translator output changes
(SEMANTICS).
Verified by imgleak's runs on msi: at ed8468c686, 471/471 touched tests pass (25294; engine_nuw,
lower::arith, engine_arith, engine_atomics, engine_access, engine_arena, engine_aggregate_access,
engine_pointer_memory, memory::, engine_bit_manipulation, engine_copy, fuzz_interp), and clippy -p
metal2vulkan --all-targets --all-features -D warnings is clean. Negative controls: the poison
test with the first commit's chunk.rs fails ("frozen_wrap_chunked on amd-rdna3-radv: 0x10000");
engine_nuw with the base's lower/ and memory/ fails a_nuw_loop_counter_is_not_masked
("nuw_i16_loops on amd-rdna3-radv: 2 masks to 16 bits", 25338). The SR conv kernel's timing in
the first commit's body is from the dumped module with its masks removed; the timing of the
kernel translated by this change is pending. Golden tables move wherever a fixture has a narrow
nuw op and are re-blessed at the next pin.
The nuw change made a padded integer freeze mask its operand, and chose
it from the operand's form. A chunked vector's freeze is selected whole,
where its type has no form, so the choice refused
chunked_math_convert_and_whole_select (an <8 x i32> freeze) on every
profile that chunks it (m3-max-25252, moltenvk-m3).
A chunked vector frozen whole now stays a copy, and one whose lanes are
integers held narrower than their container (no undef) is frozen per
chunk, each chunk masked, as a poison lane of a nuw operation per chunk
may exceed its width. engine_nuw gains frozen_wrap_chunked: lane 5 of
an <8 x i16> wraps under add nuw, is frozen, extracted and zero-extended;
the answer must be a value of i16.
Verification: the touched tests, clippy, and the poison test with the
previous chunk.rs (must fail) on msi, in the next job.
A narrow integer is held zero-extended in a u32 or u64 container, and an add, sub, mul or shl
that can carry above its width masks its result. One the AIR marks `nuw` no longer does: each
result that would carry is poison, so every other already fits the width. The common case is a
loop counter's increment: an i16-counted loop's latch read `((i + 1) & 0xFFFF) == N`, which hides
the trip count from RADV's loop analysis, so the loop stayed rolled and a private array it indexes
stayed in scratch. In the Super Resolution conv kernel 199ed62a647fd6f2 (a perfscout2 dump, read
on um790 only), removing those masks from the dumped module took the XTX from 12.5 to 0.69 ms a
dispatch and its scratch from 32768 to 0 bytes (job 25066), and the 780M from over 6 s to 6.0 ms
(25114). The inputs were synthetic and the kernel's stores never ran under them (25112, 25131),
so those times are loop cost only. `nsw` alone keeps the mask: `-1 + 1` carries out of the
zero-extended bits.
With that, a value's bits above its width are zero unless the value is poison. Where a poison
value meets something that must stay defined, it is masked:
- `freeze` of a narrow integer, which must answer a value of its type;
- the words a store writes (memory/leaf.rs words_of and vector_words), so a poison lane reaches
no neighbouring byte or lane;
- a narrow atomic's operand (atomic/narrow.rs);
- a bitcast's packed integer lanes (ops::lane_bits, chunk::words_of).
The two-word form of i33..i63 without shaderInt64 keeps its masks.
Tests: engine_nuw, an i16 and an i8 loop counted by `add nuw` over a private array, with no
mask to the width in the module, against the same loops with a plain `add`, which keep it; both
sum to 18 on the interpreter, on four profiles. Kernels of a poison `add nuw`: its freeze stays in
range, and a store, a vector store, an atomic exchange and a bitcast of it keep the neighbouring
i16 0x1234. arith tests: nuw add, sub, mul and shl match LLVM wherever they are defined, at i5, i8,
i16 and i40.
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 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.