engine_access_size::a_device_access_of_whole_words_is_one_access held a direct access to the old
form's cost: a 64-bit add of the slot's base and the zero-extended biased offset. PR 22 replaced
that add with an OpIAddCarry on the low word and a carry into the high word, because AMD's Windows
driver folded the biased offset's 2^31 into a sign-extended 64-bit immediate and read 4 GiB below
the buffer. The structural pass (e2e76d8879) made the base and the slot's address once per slot;
the per-access remainder is the carry. The bounds move to the measured cost, never rounded up:
float4 load at a uint offset 16 -> 19
float4 store at a uint offset 16 -> 19
float4 load at a float4 offset 16 -> 18
pointer chase 24 -> 22 (the pass took it below the old form)
The loss, as measured:
- On a device that takes compute buffers by address (lavapipe, a states-only play of 25,942
states, refused 0 in both forms; m3-max-77799, a b a b): SPIR-V +7.0% (largest entry +6.2%),
driver compile +5.1% (same-arm spread 1.1% and 2.6%), translation +0.7%, pipeline-make time
+1.6%, play wall +0.8%.
- One translation by the compile worker's counting allocator (corpus-pipeline --compile-only,
lavapipe; m3-max-77820, m3-max-77825): the corpus's largest row by allocator peak, 184,135,107
bytes in both forms (PR 22 does not reach it); its largest by SPIR-V output, 62,572 -> 62,894
words and 2,905,472 -> 2,921,373 bytes (+0.5%), 11 ms in both.
- Runtime GPU time of the frames (a b a b, one job per card): XTX +0.09% (m3-max-77764). RTX 3090 (gem10, in a
Thunderbolt enclosure): m3-max-77854 not resolved, its arms at unequal clocks (one b play 81
samples at P8 210 MHz against 50 and 51, wall 144.4 s against 133.7-137.9 s); m3-max-77895, both
pairs counted (P8 samples 109/109 and 108/103), +1.90% and -2.72%, means -0.44%: inside. The
+0.21% at 2f5f35ca47 on that card was before it moved hosts and is not a before-run. Iris Xe: no loss shown, 3% not resolved by this measure there (pair spread 7.8% and
11.3%).
The carry form is unverified in the lab on the driver it fixes: no lab device runs AMD's Windows
driver; only the contributor's run (RX 6950 XT and an integrated Radeon, driver 26.11.2, offsets 0
and 256) covers it. A cheaper form for constant offsets was not taken for that reason; the cost is
a no-lane row that reopens on a venue running that driver or a pipeline-make cost of 5% or more on
a real device that takes buffers by address.
Verified: the measured values are m3-max-77757's size table at e2e76d8879 (no translator change
since); this commit's test runs in the merge check next.
every_device_reads_what_direct3d_11_drew_through_a_commit_ahead_of_external_writes_done (d68f165aae)
now asserts what it printed: every acquire of a plane, the first included, names the general
layout as its old layout (Work::acquired). Its byte checks stay.
Why the structural check: no wrong picture was reproduced. On the UHD 630 the read committed ahead
of the call matched picture 1 at 3072 of 3072 bytes at d68f165aae, the old code, whose acquires'
old layouts were [undefined, undefined, general, general] (job m3-max-77834); at cd5d7df2f0 the
same read matched 3072 of 3072 with [general, general, general, general] (job m3-max-77839). That
driver kept the bytes through an acquire from the undefined layout, which Vulkan does not promise
(section 12.5.1: "implying that the contents of the image subresource need not be preserved"), so
the bytes cannot fail there and the old layouts are the failing proof. cd5d7df2f0 stays as the
spec's form (sections 12.5.2, 12.10.1, Table 17).
How it is verified: one job on the UHD 630 runs tests::d3d11 from two Windows cross-builds, the
old code with this assertion (expected to fail on [0, 0, 1, 1]) and this commit (expected to
pass); its job is reported with the lane's tip.
A consumer's video path showed green frames. A plane's first acquire named the undefined layout
unless Surface::external_writes_done had been called before the first commit that used it, and a
transition from the undefined layout need not keep the bytes (section 12.5.1: "implying that the
contents of the image subresource need not be preserved"). What 9737a44d98 and its test 7c5df5a317
left open: whether that first acquire discards depended on the order the commit and the call
arrived in. The consumer's decode order today is fence wait, external_writes_done, then the
session's signal, so the hole is reached by a guest command buffer that reads a new cache's planes
without waiting on the session, committed between the draw's completion and the call.
Now Image::handed names the general layout as the old layout of every acquire, the first included,
and of every release. A Direct3D 11 plane is made owing no move (its homed flag set), so no upload
moves it, as before 9737a44d98. Surface::external_writes_done records nothing and changes nothing
for a Direct3D 11 surface; Image::external_access, which it called, is gone. No barrier, command
buffer, submission or wait is added or removed: the acquire is the same barrier with another old
layout.
The spec's form for this handle type. Section 12.5.2: "When images created with external memory
handle types listed in the external image implied layouts table are accessed outside of Vulkan,
they must be in the layout specified in the table, and can be assumed to be in that layout when
they are accessed in Vulkan after external access", and Table 17 gives
VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT the layout VK_IMAGE_LAYOUT_GENERAL. The conflict
9737a44d98 met (a plane rt uses before any Direct3D 11 access, whose image is made undefined) is
answered by section 12.10.1's note on an image bound to memory another API owns: "Such an image is
not usable until it acquires ownership of its memory from the existing owner. Therefore, the layout
specified as part of this transition will be the true initial layout of the image. The undefined
layout specified when creating it is a placeholder to simplify valid usage requirements."
Direct3D 11 made the texture, so it is that owner, and VUID-VkImageMemoryBarrier-
srcQueueFamilyIndex-12332 allows the general layout for any acquire of such an image from
VK_QUEUE_FAMILY_EXTERNAL ("oldLayout must be VK_IMAGE_LAYOUT_GENERAL or
VK_IMAGE_LAYOUT_UNDEFINED"). Left open by the text: whether Direct3D 11's making of a texture with
no initial data counts as an access "outside of Vulkan"; such a texture's bytes are undefined
either way, and the acquire that names the general layout is allowed by the VUID.
The suite now states this rule: every_device_acquires_a_direct3d_11_plane_from_the_general_layout_
first_included replaces the first-use test and reads the old layouts from Work::acquired, the
general layout for every acquire, with and without the call first. The d3d11 module's doc,
import_d3d11_surface's Layout, Ownership and precondition paragraphs, external_writes_done's doc
and the runtime README say so; the consumer's precondition no longer names the call.
Not yet run on a device: the red test's run at d68f165aae and this commit's run of tests::d3d11
on the UHD 630 wait for the card, which potluck does not list on the Windows host as this is
committed; their jobs are reported with the lane's tip. The Windows cross-build of this commit is
its compile check.
A consumer's video path showed green frames: planes Direct3D 11 wrote, read by rt, came back without
Direct3D 11's content. A plane's first acquire names the undefined layout unless
Surface::external_writes_done was called before the first commit that uses it, and section 12.5.1
lets a transition from the undefined layout discard ("implying that the contents of the image
subresource need not be preserved").
The new test draws picture 1 with Direct3D 11 and waits for it, imports the planes, commits and
waits for rt's read of them with no external_writes_done before it, then makes the consumer's call
and reads again. Both reads must be picture 1's exactly. It prints the first read's matching and
zero bytes and each acquire's old layout (Work::acquired).
Its run at this commit on the UHD 630 is named in the fix's message.
every_device_signals_each_member_of_a_group_sent_apart failed once on llvmpipe in the merge check
at 1da727a583 (m3-max-77710, lvp_rt: "no value between the busy work's 6 and the group's 9 before
L's end") and passed at 2f5f35ca47 (m3-max-77732) and in round 89fb420796-1202-0117. Its proof
needed a host thread polling the progress semaphore to catch A's value inside the 4-10 ms between
A's end and L's: on a loaded CPU device the thread can be off the CPU for the whole window. The
specification bounds when a timeline signal is seen only from below (a submission's signal
follows its own commands), so a device that showed the value late would also fail it.
The deterministic form the planner asked for, a wait on an event instead of the clock, has no
valid Vulkan shape here. A GPU wait on a host-set event is defunct: "Events signaled by the host
must be signaled before the command buffer waits on those events" (6.6; also
VUID-vkCmdWaitEvents2-pEvents-03840). The runtime's own shared-event wait holds L on the host
until the event is met, so L would never join A's group.
So the test now reads what the runtime gave each member as the group went: Work::assigned, a
record kept for the device tests (as Work::acquired is), of each group member's place in the
commit order and the progress value it retires at. It asserts A then L in commit order, the
busy work's last value < A's < L's = the group's last, and still one submission each. The
timings (A's handler and L's GPU end, from A's GPU end) are printed, not asserted, and so are the
values.
Verified: nothing run yet for this commit; the merge check's lvp_rt and clippy in the device
configurations run it next.
PR 22's carry form cost about 10 SPIR-V instructions for each direct access against 2 before,
and engine_access_size::a_device_access_of_whole_words_is_one_access failed its bounds at
2f5f35ca47 (m3-max-77753, first identity profile: the uint-offset float4 load and store 24
against a bound of 16, the float4-offset load 23 against 16, the pointer chase 33 against 24;
the old form 16, 16, 15 and 24). Most of that was work repeated on every access: the base's u64
bitcast back to words and its split, and an add of the offset's zero high word; and
slot_address added the bias with the same sequence at every use.
Now:
- pointer::direct_base: the slot's address less the bias as its two words (the SlotGuestBase
push word split, or in a replay variant that word less 2^31 with a borrow), remembered under
SlotMemo::DirectBase and recalled where its block dominates (EmitCx's invariant memo, as
slot_bounds does). Reach::Direct holds the words; biased_slot_address, which only the direct
reach called, goes.
- psb::add_slot_offset: OpIAddCarry of the low word and the offset, its two words, one add of the
carry to the high word, the words joined and bitcast: six instructions, with no add of a zero
word and no 64-bit add of a constant.
- pointer::slot_address: remembered under SlotMemo::Address, so a pointer compare, a converted
or stored pointer or an access from the word below adds the bias once where it dominates.
The arithmetic is unchanged: the address plus the unsigned biased offset modulo 2^64, carried
into the high word as PR 22 made it. SEMANTICS_VERSION 2309 -> 2310 (module bytes change).
Verified: nothing run yet for this commit; the access-size table, the engine suites and the merge
check run next, and the table is reported against the bounds.
PR 23 imported PUSH_STAGES into command.rs, so the explicit target of the link in Pushed's doc
became redundant, and CI's private intra-doc links step (cargo doc --document-private-items with
-D warnings) failed on metal2vulkan-runtime: "redundant explicit link target" at command.rs:290.
Verified: found by the merge check at 2f5f35ca47 (m3-max-77732, STEP privdoc EXIT=1, the one
error); the next merge check runs the step again.
PR 18 (rponeawa) reported that a shared-range uniform descriptor could start far below the bind
offset (a residual of 256 on a device with a 64-byte uniform offset alignment), past the fixed
array the uniform view declared, so the read left the declared array. Its fix sized the array to
the device's uniform range. 5e3477e60a (11-22) has since removed the uniform view: every buffer
slot's view is a storage word array whose OpArrayLength is the bound range, with no declared size.
So the PR is credited by an empty merge and this test pins its case on the view the tree has: the
last byte of a constant window, read with residuals 0, 256 and 4096 on every tested profile, is
exact.
Verified: run in the merge check at the integrated tip, and with the residual's push word forced
to 0 (the read lands in the 0xEE fill) to show it is not vacuous; results in the PR report.
PR 22 (vistaero) adds a slot's biased 32-bit offset into the low word of its 64-bit base and carries
into the high word, at both direct-reach sites and in slot_address, in place of a 64-bit add of
the zero-extended offset (or of the 64-bit constant 2^31). This commit brings the bias's own doc
comment to that form and words the test's comment by structure.
Which case it was: (b). The old form was right by the specification: the biased offset is
the signed offset plus 2^31, in [0, 2^32), so UConvert's zero extension and a 64-bit add give the
address plus the offset exactly, and IAdd of the 64-bit constant 2^31 is exact. The PR reports
that AMD's Windows Vulkan driver (26.11.2, RX 6950 XT and an integrated Radeon) turned the bias
into a 64-bit immediate add that read 4 GiB below the buffer: a driver compiler fault, noted for
a repro draft. The carry form is rung 1 of the workaround ladder: one form for every device, chosen
by no query. Its 3% check (the XTX, the 5080 and the Iris Xe, arms alternated in one job) is owed
before the integrated commit is called regression-less. The lab has no AMD Windows host, so
the fault itself is built, not run: no venue.
The two subtract sites (biased_slot_address's unbiased arm and the indirect command's stored
word) subtract 2^31, which a sign-extended 32-bit immediate represents exactly. They are left
as they are: no report names them, and the PR's own run on the faulting driver passed with them.
Verified: nothing run for this commit alone (comments only); the merge check at the integrated tip
covers it.
Windows Radeon shaders reading the first byte of a bound vertex buffer read
4 GiB below its address when the unsigned 2 GiB bias became a native
64-bit immediate add. Add the offset to the low word and carry into the
high word for direct accesses and recovered slot addresses. Keep the push
layout and invalidate translations emitted under the previous semantics.
`[`write`]` on the private Format enum (from 4bcb58dbb1) names both the module's private fn write and
std's write! macro, so rustdoc under -D warnings with --document-private-items refuses it as an
ambiguous intra-doc link: CI's "Private intra-doc links" step reads metal2vulkan-devtools at 1 over
its ceiling of 0. Link the function with [`write()`].
Found by the private-doc step timed for the merge check on x86_64 Linux (job m3-max-77704:
M2V-PRIVDOC metal2vulkan-devtools 1, every other crate 0; the diagnostic in m3-max-77707).
Track the last push length and record only the changed words for a draw. Keep Managed index and slot reaches on the full draw path, and leave device-wide alias and unslotted reads to the existing post-update checks.
Verified with cargo fmt and runtime Clippy, 207 runtime unit tests with the existing CRLF-sensitive stage test skipped, and the draw-offset regression on Intel Arc B390 including a Managed copy back.
Reuse retained buffers for offset-only binds and track changed slots by stage. Patch indexed push fields and fixed-function bindings for eligible direct draws, and use full validation and filling when the draw cannot reuse them.
Verified with runtime clippy, the 207 lib tests in a temporary copy with LF in stage.rs, and the offset regression on Intel Arc B390.
Windows Radeon shaders reading the first byte of a bound vertex buffer read
4 GiB below its address when the unsigned 2 GiB bias became a native
64-bit immediate add. Add the offset to the low word and carry into the
high word for direct accesses and recovered slot addresses. Keep the push
layout and invalidate translations emitted under the previous semantics.
a_value_the_host_sees_is_one_a_host_wait_confirmed signalled 2^40 over an event at 5. A device's
maxTimelineSemaphoreValueDifference may be as low as 2^31 - 1 (VUID-VkSubmitInfo2-semaphore-03883),
and AMDVLK 2025.Q2.1 on a Radeon 780M reports 4294967295: the submit broke that valid usage, the
validation layer reported it and the test failed there (job m3-max-76993, the rt suite under that
driver: 850 passed, 1 failed, 3 skipped). The signal is now 5 plus the device's limit, at most
2^40, which no progress value reaches and the limit allows, as the_largest_value_is_kept reads it.
Verified: see the jobs in the landing line (lavapipe, and the 780M under AMDVLK).
What: tests::layouts::on_device::a_whole_copy_in_moves_from_undefined_through_each_entry_and_a_short_one_from_home.
On every device, under a Recording: a Shared RGBA8Unorm texture of two levels takes a blit's
copy_from_buffer into the whole of level 0, one short of level 1's edge, then replace_region of
the whole of level 0; the recorded old layout of the last barrier naming the image before each
copy in is UNDEFINED, home, UNDEFINED.
Why: b1's guard 1 (whole_copy_in's discards) asks TextureObject::away_into directly, so a revert
of only the two call sites (blit.rs copy_from_buffer, texture.rs record for a replace) with the
helper kept leaves it green; guard 2 shows the tear on the 780M only. This assertion reads the
barrier the call sites record, on any device, lavapipe included.
Verified: see the lane's report (lavapipe at this commit and with the two call sites reverted).
What: the test-only command table tests::layouts::recorded (loaded at Device::new while a
Recording lives) now also takes vkMapMemory, vkFlushMappedMemoryRanges and
vkInvalidateMappedMemoryRanges: each call is passed to the driver and counted per device, with
the bytes of the ranges it names (a VK_WHOLE_SIZE range to the end of its memory's mapping as
vkMapMemory named it), in tests::layouts::coherence_calls. Every test in tests::coherence starts a
Recording, and each reading of a device's counters there (Seen::metrics) first asserts that
shared_flushes, shared_flushed_bytes, shared_invalidates and shared_invalidated_bytes equal those
calls and bytes since the device was made, so each per-point count the tests already assert is
of calls the device really made.
Why: the view tests counted only the runtime's own bookkeeping (Coherence::flush and settle
count after the call site, the time inside a call is two clock reads, and the view runs on memory
that is coherent in fact). With both Vulkan calls removed and the counters kept (scratch
188b2d0cee) they stayed green on the RX 550 (job m3-max-76941). No product line changes.
Verified: see the lane's report (the RX 550 at this commit and with the calls removed).
What: tests::event_values::each_value_a_gpu_signal_raises_is_confirmed_by_one_wait_before_the_host_sees_it.
For three signals in turn (3, 9, 20), once the command buffer completed and the completion thread
took the value in, signaledValue reads the value and the test-only wait count
(Counters::event_reads) rose by exactly one since the signal was committed.
Why: the rule of 58158f96a9 (a value the guest sees that a GPU signal raised is gated by
vkWaitSemaphores, never by the counter read alone) had only its cost test, which the old code
also meets. This assertion fails where EventInner::reached returns the counter's value without
the wait.
Verified: see the lane's report (lavapipe green at this commit, red in a scratch control).
Ticks::span cast its f64 nanoseconds to u64, which truncates, and so did
Calibration::at, the host time of a tick by the calibration. Ticks of a period
an f32 cannot state exactly come out a nanosecond short: 96 ticks of the Iris
Xe's 19.2 MHz clock, a period of 52.083332 ns as Vulkan states it, are 5000 ns,
and the cast gave 4999. Both now round to the nearest whole nanosecond, one
expression each, no branch; an end before the start still saturates at 0.
Every GPU span and placed time goes through these two: Calibration::place, the
completion thread's placement (complete.rs), the held-start gaps and
Metrics::runtime_command_buffer_gpu_nanos.
Metal states GPUStartTime and GPUEndTime as host seconds (CFTimeInterval, "the
host time in seconds that GPU starts executing this command buffer") with no
precision promise, so the nearest nanosecond the ticks allow is ours to give.
Verified: the ported durations_count_ticks_of_the_period_across_a_wrap
(tests/times.rs, its answer of 5000 as the deleted runtime's test stated it)
was red at the tree before this commit on lavapipe, job m3-max-76896 (left
4999, right 5000; the other four ported tests green). Green after it:
lavapipe run follows.
5d725aeec7 deleted the old runtime with its tests. Of its GPU-time tests
(tests/gpu_time.rs), these describe the new runtime's Calibration as they stood,
ported with their answers unchanged:
- a_pair_places_timestamps_on_the_hosts_clock_either_side_of_it, whole, as
a_calibration_places_timestamps_on_the_hosts_clock_either_side_of_it
(GpuClock::place, now Calibration::at);
- the calibrated case of a_span_is_placed_by_the_pair_or_ends_at_the_completion,
as a_span_is_placed_by_the_calibration (Calibration::place); its uncalibrated
cases do not port, since the floor requires calibrated timestamps;
- the 65 s-ahead case of a_pair_that_places_times_outside_the_life_is_set_aside
(the Radeon 780M's after two MODE2 resets), as
a_calibration_65_s_ahead_places_times_by_the_completion: the times end at the
completion seen. Its drift and deviation allowance and its lower bound at the
kernel start do not port: the new runtime bounds GPU times by the completion
seen alone.
Calibration's two fields become pub(crate) so the tests can build one; nothing
else changes.
Verified: lavapipe and lint runs follow, reported with their jobs.
5d725aeec7 deleted the old runtime with its tests. Two of its GPU-time tests
(tests/gpu_time.rs) describe the new runtime's design as they stood and need
nothing new, so they come back unchanged in their answers:
- durations_count_ticks_of_the_period_across_a_wrap: the old GpuClock::duration,
now Ticks::span (Ticks::new takes the period first, then the valid bits).
- the_host_time_rises: host_time, now u64 nanoseconds where it was f64.
Verified: baseline runs pending (the runtime's tree as it stands at
development's tip, with only these tests added).
The probe's notes gain what job m3-max-76861 measured for the kernels of the runtime's tests
opencl_shapes: a __local atomic_cmpxchg is air.atomic.local.cmpxchg.weak.i32 of orders 0 and 0
and scope 1 through an alloca of its expected value, as the __global one with scope 2; a read
through a sampler with integer coordinates converts them with air.convert and samples.
A constant sampler_t had no test in the shape Apple's OpenCL compiler writes: an
air.sampler_states global of Metal's two sampler words, never OpenCL's bits (our kernel
ocl_sampler, the probe opencl_operand_encodings, M3 Max, job m3-max-76861). Two of them, each
of OpenCL bits unlike Metal's words: CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE |
CLK_FILTER_NEAREST (0x7bff0000088049), read with integer coordinates (air.convert to float,
then air.sample_texture_2d of access 0), and CLK_NORMALIZED_COORDS_TRUE | CLK_ADDRESS_REPEAT |
CLK_FILTER_LINEAR (0x7bff0000080a92), read with float ones. Each work-item reads a 4 by 2
RGBA8Unorm image through both: the first at a texel coordinate on each side of the image
answers the texel clamped to the edge, the second half-way between a texel and the next one
across, wrapping to the row's first, answers their mean. Each address mode, filter and
coordinate space answers differently from the others there, and every byte of the image is
even so each mean is a whole byte: the answers are computed here and compared exactly.
Test only, at development's product code. Its runs follow this commit.
OpenCL 1.2's atomic_add and atomic_cmpxchg had no test in the shape Apple's OpenCL compiler
writes: air.atomic.{local,global}.{add.s,cmpxchg.weak}.i32 in the AIR 2.9 form, order 0, scope
1 on __local and 2 on __global, mem_flags 0, volatile, the exchange through its expected
value's alloca with the old value read back from it (our kernel ocl_atomics, the probe
opencl_operand_encodings, M3 Max, job m3-max-76861). Over 16 work-groups of 128 work-items each
work-item adds its global id into a __local word and counts itself into another through a
compare-exchange loop from 0, storing the old value its exchange succeeded on as a ticket, then
does the same into two __global words. The answers are computed here and no lost update can
give them: each work-group's sum and count of 128, the total sum and the count of 2048, each
work-group's __local tickets every value below 128 once and the __global tickets every value
below 2048 once.
Test only, at development's product code. Its runs follow this commit.
The OpenCL-mode image write had no device test since the swizzled-view write left the range
(229d9db40b). This one is in the shape Apple's OpenCL compiler writes for our own kernel
ocl_write (write_imagef on a write-only image: _Z12write_imagef14ocl_image2d_woDv2_iDv4_f
calling air.write_texture_2d of access 2; the probe opencl_operand_encodings, M3 Max, job
m3-max-76861): work-item i writes ((17, 81, 145, 209) + i) / 255 to texel (i & 3, i >> 2) of a
4 by 2 texture filled with 0xee, through two identity views, and the texture's bytes read back
are the written ones, computed here. The views: an RGBA8Unorm view of an RGBA8Unorm texture
made with the identity swizzle, whose OpenCL-mode writes the M3 Max stores as written (the
probe opencl_swizzled_images, job m3-max-16336), and an RGBA8Unorm view of an RGBA8Uint
texture, the texture Apple's OpenCL binds for a CL_RGBA, CL_UNORM_INT8 image (same job).
Test only, at development's product code. Its runs follow this commit.
Three kernels of our own join the probe: ocl_write (write_imagef through a write-only image),
ocl_atomics (OpenCL 1.2's atomic_add and atomic_cmpxchg on __global and __local memory) and
ocl_sampler (two constant samplers whose OpenCL bits differ from Metal's sampler words). The
runtime's tests opencl_shapes write their modules after what Apple's OpenCL compiler makes of
them, which this probe prints and leaves in out/. The run follows this commit.
Apple's OpenCL compiler (Metal's OpenCL mode) writes mem_fence(flags) as
air.atomic.fence(flags, 4, 1): order 4, acq_rel, after its trunc, llvm.bitreverse.i2 and zext
of the flags; read_mem_fence takes order 2 and write_mem_fence order 3 (the probe
opencl_operand_encodings, M3 Max, job m3-max-76799; the module text read again in job
m3-max-76855). The test modules that stand for mem_fence wrote order 3, a release fence, which
puts a fence weaker than Apple's on the side that reads: opencl_kernels's FENCE,
opencl_barriers's _Z9mem_fencej and unbound_immediates's fence. Each now writes order 4, and the
canon test asserts the fence it binds is acq_rel. None of the three stands for write_mem_fence,
so none keeps order 3.
A test correction only: no product code changes. The before and after runs of the two device
tests on one card per vendor follow this commit.
Run on the M3 Max under macOS 27.0.1 (job m3-max-76799), through Metal's
OpenCL mode (OpenCL.framework's program binary holds only the options
and the source): barrier passes cl_mem_fence_flags to air.wg.barrier
unconverted (1 local, 2 global, order 5, scope 1); mem_fence,
read_mem_fence and write_mem_fence convert them to Metal's mask through
llvm.bitreverse.i2 (orders 4, 2, 3, scope 1); the 1.2 atomics write
order 0, scope 2 or 1 and mem_flags 0; constant samplers become
air.sampler_states words in Metal's encoding; image accesses are
sample 0, read 1, write 2. The header records the words.
Our own OpenCL C kernels (barrier, mem_fence, read_mem_fence and
write_mem_fence of each cl_mem_fence_flags value, the 1.2 atomics on
__global and __local memory, constant samplers whose OpenCL bits differ
from Metal's sampler words, a sampler argument, a read without a
sampler, a write), each compiled through OpenCL.framework's program
binary and through Metal's OpenCL mode, the bitcode carved out and
disassembled so the operands can be read.
Not yet run.
new_texture_view's doc said the view keeps this texture "as Metal's parentTexture". For a view
of a view that is loose: the runtime keeps the texture that owns the image (the first ancestor
with an image of its own), while Metal's parentTexture answers the texture the view was made
from, the intermediate view (M3 Max, job m3-max-76856). The runtime has no parentTexture
accessor; the consumer answers it to the guest, as Metal does. Doc only, no behaviour change.
The header records what the usage path answered on the M3 Max, macOS 27.0.1: a view made
without a swizzle and one made with the identity passed answer the base's 0x17; a (Blue,
Green, Red, Alpha) view 0x11; every view of that view 0x11, made without a swizzle, with
the identity, with (Blue, Green, Red, Alpha) (combining to the identity) and with (Green,
Blue, Red, Alpha); a (Blue, Green, Red, Alpha) view of the plain view 0x11; the same with
MTL_DEBUG_LAYER=1. A view answers its parent's usage, less RenderTarget and ShaderWrite
where the swizzle passed is not the identity, and the swizzle passed, else its parent's.
The render and compute lines of the same run equal job m3-max-76829's.
Texture::descriptor's doc comment and the README's swizzle paragraph (Known gaps of
textures) state that a view's descriptor reports its base texture's usage, which is what
the view may be used with, so a draw into a swizzled view and a kernel's write through it
run, where Metal's usage answers only ShaderRead and PixelFormatView of a base of those,
ShaderWrite and RenderTarget, for a view made with a swizzle other than the identity and
for every view of such a view.
Measured on the M3 Max, macOS 27.0.1, job m3-max-76856 (swizzled_view_stores.m): a base of
0x17; a view made without a swizzle and one made with the identity passed answer 0x17; a
(Blue, Green, Red, Alpha) view 0x11; views of that view made without a swizzle, with the
identity, with (Blue, Green, Red, Alpha) and with (Green, Blue, Red, Alpha) all 0x11; a
(Blue, Green, Red, Alpha) view of the plain view 0x11; the same with MTL_DEBUG_LAYER=1.
The consumer answers a guest's read of a view's usage from its own descriptor, so the
runtime's answer is its own contract; nothing in the runtime changes. Docs only;
refusal_surface.py --check and signatures.py --check pass.
A usage path makes no draw or write: of an RGBA8Unorm Private base of ShaderRead |
ShaderWrite | RenderTarget | PixelFormatView it prints the usage, swizzle and parent of a
view made without a swizzle, one made with the identity swizzle passed, a (Blue, Green,
Red, Alpha) view, four views of that view (without a swizzle, with the identity, with
(Blue, Green, Red, Alpha), which combines to the identity, and with (Green, Blue, Red,
Alpha)), and a (Blue, Green, Red, Alpha) view of the plain view, then runs again in a
child under MTL_DEBUG_LAYER=1. Which views Metal reports without RenderTarget and
ShaderWrite is measured here rather than guessed.
Syntax-checked with xcrun clang -fsyntax-only; the M3 Max run follows.
Section 10's Kernels gains the accepted difference: the runtime stores a kernel's write
through a texture view whose swizzle permutes its format's channels as written, where the
M3 Max stores it through the swizzle (an RGBA8Unorm (Blue, Green, Red, Alpha) view's write
of (0x33, 0x66, 0xb3, 0xcc) leaves (0xb3, 0x66, 0x33, 0xcc); swizzled_view_stores.m, job
m3-max-76829) and Metal's validation refuses the write, the view reporting no ShaderWrite
usage. The OpenCL images paragraph said a write stores the value with the swizzle undone,
which is the M3's answer, not the runtime's; it now states the runtime's rule and points
to the entry.
Docs only; the rule is the runtime's README's ("A swizzle reaches a texture's sampled
element alone") and the lane's write test asserts it.
opencl_mode_writes_through_a_swizzled_image_store_the_value_as_written takes the write
test held on steelbrain/ocl-port-swizzle (e579f13a30) with its kernel and helpers, and
asserts the runtime's rule: a write-only image's write through a swizzled view stores
channel c from lane c (the runtime README's known gaps of textures, "A swizzle reaches a
texture's sampled element alone"). The M3 Max's answer is named in the module doc as the
difference: it stores the value with the swizzle undone (OpenCL probe, job m3-max-16336;
on rgba8/BGRA texel 0 [0x91, 0x51, 0x11, 0xd1] where the runtime stores [0x11, 0x51, 0x91,
0xd1]), as it does for a plain-Metal kernel's write (swizzled_view_stores.m, job
m3-max-76829), and Metal's validation refuses such a write, the view reporting no
ShaderWrite usage. The M3's write rule (write_rule) goes, since nothing asserts it now.
The held commit's runs showed the as-written bytes on lavapipe (job m3-max-76607), the
RX 7900 XTX (m3-max-76618), the 780M (m3-max-76619), the RTX 2080 (m3-max-76620) and the
RTX 5080 (m3-max-76614); this commit's own runs are in the lane's report.
A swizzled view used as colour attachment 0 stores the clear and the draw as written in all three
cases; a plain Metal kernel's access::write through the view stores the colour permuted by the
swizzle (channel s[l] takes lane l). Metal gives every swizzled view usage 0x11 over a base of
0x17, and its validation layer ends both uses for the missing RenderTarget and ShaderWrite usage.
Our own shaders over three cases: an RG32Float texture over a Shared buffer (usage ShaderRead |
ShaderWrite | RenderTarget | PixelFormatView) viewed as RG32Float with the swizzle (Red, Green,
Zero, One), the same base viewed with (Green, Red, Zero, One), and a Private RGBA8Unorm viewed
with (Blue, Green, Red, Alpha). Each view is cleared and drawn as colour attachment 0 and,
separately, written by a plain Metal kernel (access::write); the base's bytes are read back and
every texel is sampled through the view. Each case and path runs again in a child process under
Metal's validation layer. Not yet run.
the_largest_value_is_kept signals u64::MAX on a fresh event, a jump of 2^64-1, which Vulkan
bounds by the device's maxTimelineSemaphoreValueDifference (VUID-VkSubmitInfo2-semaphore-03883).
A suite test must not make a submission outside valid usage on any device the floor admits, and
Vulkan lets that limit be as low as 2,147,483,647. So the test reads the limit
(VkPhysicalDeviceVulkan12Properties) and runs where it covers the jump, printing the limit;
elsewhere it prints "not run: the device's limit is N" and checks nothing.
At 5481c1b88b, before this condition, it was green on lavapipe (m3-max-76802), the RX 7900 XTX
(m3-max-76807), the Iris Xe (m3-max-76806), the RTX 2080 (m3-max-76808) and the RTX 5080 Laptop
(m3-max-76814), each reporting a limit of 2^64-1.
The queues section's known gaps gain one line. The runtime puts Metal's event value on the
event's timeline semaphore as it is. Vulkan requires a signal's or wait's value to lie within
maxTimelineSemaphoreValueDifference of the semaphore's value and of every signal and wait pending
on it (VUID-VkSubmitInfo2-semaphore-03883, -03884), and lets a device report a limit as low as
2,147,483,647. On a device whose limit is below the jump, such a program is outside Vulkan's
valid usage. A host set_signaled_value never signals the semaphore, so it has no such limit
(event.rs's set_signaled_value).
The count behind the row: six recorded streams, largest jump an encoded signal or wait carried
178, none past the limit; the only values past it were host sets, which never reach the
semaphore. The lab cards the ported tests ran on (RX 7900 XTX, Iris Xe, RTX 2080, RTX 5080
Laptop) report 2^64-1.
The sentence saying that an event's value the host sees, where a GPU signal raised it, is one a
host wait with a timeout of 0 confirmed states how events behave; it is not a gap. It moves from
"Known gaps" (the timestamp-pool bullet, restored to its text before the fix) to the `Event` and
`SharedEvent` bullet of "Queues, command buffers and events", in the present tense. No code
changes.
The record of the fix's cost (58158f96a9, with the doc commit 4ab995b621 on it): the harness's
two_queues row (`harness --runtime new --only two_queues`), before = d50eeb3522, after =
4ab995b621, 5 pairs alternated in one exclusive job per card, the arm order swapped each pair.
Times in us (b_done_p50 in ms: B committed to completed in the signalling part). spr is an arm's
max / min - 1.
RTX 2080, job m3-max-76839: every event key within 1%, base spreads at most 4.0%.
run wait_p50 wait_p90 a_gap_p50 a_gap_p90 a_per_cb b_done_p50
before 1 19.840 20.192 41.376 42.336 20250.718 161.700
after 1 19.840 20.352 41.600 42.528 20263.368 161.800
after 2 19.872 20.128 41.312 42.176 20255.721 161.800
before 2 19.808 20.448 41.350 42.432 20251.343 161.800
before 3 19.872 20.480 41.120 42.144 20255.964 161.800
after 3 19.904 21.472 41.472 44.416 20255.081 161.800
after 4 20.000 20.416 41.344 43.040 20256.101 161.800
before 4 19.904 20.896 41.333 42.976 20258.708 161.800
before 5 19.904 20.992 41.440 43.776 20254.411 161.800
after 5 19.904 21.088 41.472 42.469 20252.510 161.800
before p50 19.872 20.480 41.350 42.432 20254.411 161.800
before spr 0.5% 4.0% 0.8% 3.9% 0.0% 0.1%
after p50 19.904 20.416 41.472 42.528 20255.721 161.800
after spr 0.8% 6.7% 0.7% 5.3% 0.1% 0.0%
after/before 1.002 0.997 1.003 1.002 1.000 1.000
Iris Xe (RPL-P), job m3-max-76844: every event key within 1%, base spreads at most 1.7%.
run wait_p50 wait_p90 a_gap_p50 a_gap_p90 a_per_cb b_done_p50
before 1 9.012 9.167 38.803 46.503 22598.215 180.500
after 1 9.063 9.324 38.854 46.564 22597.641 180.500
after 2 9.220 9.636 38.959 46.826 22609.295 180.500
before 2 9.064 9.271 38.855 46.663 22597.349 180.500
before 3 9.115 9.272 38.855 46.353 22610.056 180.500
after 3 9.115 9.272 38.856 46.625 22642.170 180.600
after 4 9.114 9.271 38.803 46.498 22597.597 180.400
before 4 9.115 9.271 38.855 46.410 22625.471 180.500
before 5 9.167 9.323 38.804 46.567 22606.507 180.400
after 5 9.115 9.272 38.855 46.574 22618.163 180.500
before p50 9.115 9.271 38.855 46.503 22606.507 180.500
before spr 1.7% 1.7% 0.1% 0.7% 0.1% 0.1%
after p50 9.115 9.272 38.855 46.574 22609.295 180.500
after spr 1.7% 3.9% 0.4% 0.7% 0.2% 0.1%
after/before 1.000 1.000 1.000 1.002 1.000 1.000
RX 7900 XTX (RADV), job m3-max-76837: every event key within 1%, base spreads at most 4.5%.
run wait_p50 wait_p90 a_gap_p50 a_gap_p90 a_per_cb b_done_p50
before 1 23.480 23.720 664.250 690.220 20664.500 165.100
after 1 23.560 23.800 665.520 685.240 20546.559 164.200
after 2 23.520 23.680 665.530 735.111 20645.568 165.000
before 2 23.520 23.680 663.780 697.990 20594.544 164.700
before 3 23.440 23.680 654.693 677.460 20495.322 164.300
after 3 23.480 23.680 665.810 670.200 20624.176 164.800
after 4 23.560 23.720 665.800 681.720 20659.588 165.100
before 4 23.560 23.720 661.400 688.170 20614.650 164.500
before 5 23.600 23.720 661.600 668.007 20625.205 164.700
after 5 23.520 23.720 665.078 697.190 20629.603 164.800
before p50 23.520 23.720 661.600 688.170 20614.650 164.700
before spr 0.7% 0.2% 1.5% 4.5% 0.8% 0.5%
after p50 23.520 23.720 665.530 685.240 20629.603 164.800
after spr 0.3% 0.5% 0.1% 9.7% 0.6% 0.5%
after/before 1.000 1.000 1.006 0.996 1.001 1.001
RTX 5080 Laptop, job m3-max-76834: VOID, its base arm spreads above 10% (41.4% on wait_p50,
41.8% on wait_a_gap_p50); its runs fall in two groups (8.3 to 9.1 us and 10.2 to 12.0 us on
wait_p50) in both arms.
run wait_p50 wait_p90 a_gap_p50 a_gap_p90 a_per_cb b_done_p50
before 1 12.032 12.768 23.872 26.016 20877.065 160.800
after 1 10.176 12.448 22.576 25.984 21461.131 163.600
after 2 11.264 12.768 22.719 26.464 21465.165 163.700
before 2 8.960 12.512 18.272 25.984 21513.619 163.900
before 3 8.672 12.352 17.984 25.952 21537.336 163.900
after 3 11.232 12.416 22.130 25.184 21585.253 164.100
after 4 8.320 12.256 16.544 24.736 21603.339 164.000
before 4 8.512 12.480 16.832 24.736 21658.572 165.000
before 5 8.672 12.448 17.568 26.016 21687.321 165.000
after 5 9.088 12.640 19.136 26.272 21728.232 164.900
before p50 8.672 12.480 17.984 25.984 21537.336 163.900
before spr 41.4% 3.4% 41.8% 5.2% 3.9% 2.6%
after p50 10.176 12.448 22.130 25.984 21585.253 164.000
after spr 35.4% 4.2% 37.3% 7.0% 1.2% 0.8%
after/before 1.173 0.997 1.231 1.000 1.002 1.001
Columns: wait_p50 and wait_p90 are B's GPU start after the signaller's GPU end; a_gap_p50 and
a_gap_p90 are the harness's wait_a_gap keys (A's GPU idle before each of its command buffers);
a_per_cb is wait_a_per_cb.
At 4ab995b621: lint job m3-max-76840 green (fmt, signatures, api_surface, clippy in all three
configurations, Rustdoc -D warnings); the runtime suite on lavapipe under the validation layer,
jobs m3-max-76841 (394 passed) and m3-max-76842 (444 passed), none failed. This commit
changes the README alone; its check is fmt and Rustdoc -D warnings, run on it once made.
complete.rs's module doc now states the planner's one reading for the tree: a retirement, a host
read of bytes the GPU wrote, a value the guest sees that a GPU signal raised, and a free are gated
by vkWaitSemaphores (a timeout of 0 allowed), never by vkGetSemaphoreCounterValue alone; the
counter read may find which value to confirm. It rests on the Vulkan specification's Fences
section (7.3: waiting on a fence, by vkWaitForFences or by polling vkGetFenceStatus, defines an
execution dependency), the semaphores' overview (7.4: a dependency "between a queue operation
and the host") and the memory model's System-Synchronizes-With note ("signal operations
happening before host operations that wait on them"); Host Operations on Semaphores (7.4.4)
carries no such sentence. The Queue Operation section (3.2.1) gives what came before a signal a
wait has seen. VK_KHR_timeline_semaphore's issue 5 is no longer cited: it states no order.
The host-visibility paragraph (record::end's Reach::Host barrier, then host coherence or
crate::coherence) stays. run()'s comment on the completion loop's zero-timeout wait is unchanged.
Doc only. Verification: cargo fmt here; Rustdoc with -D warnings in the lane's lint job.
A value the guest sees that a GPU signal raised (SharedEvent::signaled_value,
wait_until_signaled_value, a listener's value, and the completion thread's observation that ends
an event's watch and may free its semaphore) came from vkGetSemaphoreCounterValue alone. Vulkan
states an execution dependency only for a host wait on a semaphore (the memory model's "signal
operations happening before host operations that wait on them"), and the completion of command
buffers already retires only on a vkWaitSemaphores; the planner's reading: a retirement, a host
read of bytes the GPU wrote, a value the guest sees that a GPU signal raised and a free are gated
by vkWaitSemaphores (a timeout of 0 allowed), never by the counter read alone.
EventInner::reached replaces the bare counter read at every site that gates: the counter read
finds the value, complete::reached_by_wait (timeout 0) confirms it, and the highest value
confirmed is kept. A value read at or below it asks for no wait, so a steady event pays one
counter read as before. Where the wait does not confirm the value read, a lower candidate (the
completion thread's next pending value, a host wait's own value) is waited for, and otherwise the
last value confirmed stands: on the completion thread the event stays watched and the round's GPU
wait blocks on its next pending value, so a "not yet" never spins.
Test-only counts (Counters::event_reads: reads, waits, not yet, not yet on the completion
thread, the completion thread's wake-ups) and a test, a_value_the_host_sees_is_one_a_host_wait_
confirmed: 1,000 reads of a steady value make at most one wait, and with a signal pending behind
the busy gate the completion thread does not return from its GPU wait for 200 ms. No public item
changes; signaled_value's doc and the runtime README's timestamps paragraph say it.
Verification: not run when committed; lavapipe, the cards and the harness's cost rows follow on
this branch.
complete.rs's module doc now states the completion path's host side: a host wait
(vkWaitSemaphores) or a counter read (vkGetSemaphoreCounterValue) at or above the value a
submission signals means that signal operation has happened. It rests on the Vulkan
specification's Queue Operation section (3.2.1: a semaphore is signaled only once earlier queue
operations completed and their writes are available), Semaphore Signaling (7.4.1: a timeline
semaphore is signaled with respect to its counter value) and VK_KHR_timeline_semaphore's issue 5
(the payload query is one of the two documented host waits). It also says that Host Operations on
Semaphores (7.4.4) carries no execution-dependency sentence, unlike the fence wait, and that host
visibility comes from record::end's host-reaching barrier (Reach::Host), then host coherence or
the flush and invalidate of crate::coherence.
Doc only: no behaviour change, no version bump. Verification: cargo fmt here; Rustdoc with
-D warnings in the lane's lint job.
The deleted runtime's the_largest_value_is_kept, on the public API: a signal of u64::MAX
reaches a shared event, which reads it; a second is left out; a host set of it changes nothing.
Metal's event values are uint64_t (MTLEvent.h, signaledValue).
The runtime puts Metal's value on the event's timeline semaphore as it is, and Vulkan bounds a
signal's distance from the semaphore's value by maxTimelineSemaphoreValueDifference
(VUID-VkSubmitInfo2-semaphore-03883; Vulkan's minimum is 2^31-1), so on a device whose limit is
below 2^64-1 the validation layer is expected to report this signal: a separate commit, held off
landing until its runs are read.
Verification: not run when committed; the lavapipe run and one card per vendor follow on this
branch.
The runtime deleted with commit 5d725aeec7 took its event, completion and host-settable-wait
tests with it. Seven of its 38 tests describe what the new runtime still promises; this ports
them onto the public API (and EventState::pending where the old test read the pending signals),
keeping each one's observations and values:
- tests/event_values.rs: a signal not above what is known (a lower one on another queue, an
equal one) is left out, the value 7 once the GPU runs (Metal's answer, measured); a shared
event's host value reads at once below a pending GPU signal, lower and equal sets change
nothing (measured), the semaphore is never signalled by the host, a wait the floor met goes
unheld and one only the pending 7 meets completes after it; a host set above a pending signal
stays the value once it lands; listeners run off the posting thread, on one thread, in the
order posted.
- tests/completion_orders.rs: a command buffer that waited on the GPU for another queue's signal
completes after it (the signaller Completed when the waiter's wait returns and in its handlers,
the signaller's first handler first), over 50 rounds of each of 40 shapes; the orders within a
command buffer, a queue and across queues, over 80 rounds; and no commit of 1,800 on one of four
queues takes 50 ms or more less the thread's wait for a CPU.
Metal has no completion-seen handler: where a shape names one, it is a completed handler added
first. Device tests, under m2v_gpu and m2v_cpu_icd.
Verification: not run when committed; the lavapipe run and one card per vendor follow on this
branch.
The GL-mode half of the old runtime's void-vertex test. Metal on an Apple M3 Max (macOS 27.0.1,
probe conformance/probes/opengl_mode.m) makes, under the private OpenGL mode, a rasterizing state
whose vertex function returns void: its draw runs the vertex function and rasterizes nothing.
The runtime refuses it in either mode, as the translator's link does (pipeline/link.rs,
check_stages: DescriptorError::RasterizedVoidVertex whatever the mode).
The consumer counted the refusal over 812 runtime boots, 221 with guest GL-renderer content and 160
with a browser 3D scene: 0, while 737 of those logs carry other runtime refusal lines. On that zero
the planner ruled the refusal a known gap rather than a build: the test asserts today's typed
refusal with the mode on, Metal's answer stays in its doc as the difference, and the runtime's
README lists it under Known gaps of render pipeline states, as a guest meets it. The refusal test
without the mode now shares the assertion through one helper.
Verified: the same refusal, "invalid descriptor: RasterizedVoidVertex" with the mode on, was what
the Metal-valued form of this test met on lavapipe (job m3-max-76678), the Iris Xe (m3-max-76684),
a Radeon 780M (m3-max-76687) and an RTX 2080 (m3-max-76688); this form reruns on lavapipe at the
branch tip, reported to main with its job.
No runtime test asserted the point-size note on a render state: the old runtime's per-draw
notice test went with it, and the translator's CPU tests check the note on compiled artifacts
alone. The note is static, decided by the vertex function (a [[point_size]] output) and the
device (its pointSizeRange's whole-pixel bound below Metal's 511) in the translator's stage I/O
plan, never by a draw's primitive. The new device test asserts exactly that on every device of
the cfg's kind: the state of rt6_point carries it where the device's bound is below 511, the
state of rt6_full on no device.
Verified: to run on lavapipe at the branch tip (a CPU job), reported to main with its job.
The old runtime's OpenGL-mode device tests went with it on 11-20 and were never ported, so the
private render state the guest's GL renderer sets on every pipeline lost its guard. This ports
them onto the new runtime's device-test helpers, with the M3 Max's answers as they stood (probe
conformance/probes/opengl_mode.m, macOS 27.0.1):
- opengl_mode_makes_a_depth_output_without_a_depth_attachment: with the mode, a fragment function
writing depth without a depth attachment makes a state whose colors are those it draws with a
depth attachment. The old test's other half, the refusal without the mode, is not ported: only
the M3 Max's driver refuses it and no Metal document states it (MTLRenderPipeline.h, Apple's
pages for depthAttachmentPixelFormat and makeRenderPipelineState(descriptor:), the MSL spec's
depth output), so on the planner's ruling the runtime makes the state, recorded in
docs/API.md's accepted differences.
- without_opengl_mode_a_rasterizing_void_vertex_function_is_refused: the refusal half of the old
void-vertex test, as the translator's typed DescriptorError::RasterizedVoidVertex; Metal's text
stays in the module doc, as the runtime's errors carry none.
The module doc names the nine deleted tests not ported and why: point_size_notices' per-draw
notice is gone (the note is the state's), and private_properties' eight tests test Apple's private
device properties, which the consumer answers and the runtime holds none of.
Verified: to run on lavapipe at the branch tip (a CPU job), reported to main with its job.