The runtime's device tests held threadgroup_barrier(mem_threadgroup) alone above one wave with
data crossing waves, and nothing else: no mem_device barrier whose data crosses a 64-wide wave
(row_barrier's 32-wide rows pair within one wave on a wave64 device), no barrier of both flags, and
no air.atomic.fence. Four tests beside the originals, which stay unchanged, each with its answer
computed in the test:
- every_device_reads_another_simd_groups_device_word_past_a_device_memory_barrier: the harness
fixture's row_barrier (mem_device alone) in rows of 64 and 128, threadgroups of 128 and 256,
so thread t reads what thread t ^ 64 (or t ^ 128) stored in the device buffer: 512 x 4,
512 x 3 (ragged in y) and 200 x 4 (ragged in x) in 64 x 2, 512 x 4 in 128 x 2, 192 x 8 in 64 x 4.
- every_device_reads_another_simd_groups_device_words_across_a_float_arenas_barrier:
float_arena_reader, FLOAT_ARENA whose last loop reads the device words the loop before its
mem_device barrier stored (thread t reads threads 4t..4t+3 mod 256's) in place of the arena.
- every_device_orders_both_memories_across_simd_groups_through_one_barrier: both_flags, a loop of
four over one barrier of mem_device | mem_threadgroup, thread t reading the threadgroup word of
t ^ 64 and the device word of (t + 64) % 256, in 8 threadgroups of 256 and 4 of 1,024.
- every_device_gathers_every_simd_groups_word_past_a_fence_and_an_atomic_count: Metal's fence
pattern (MSL 6.16.1, 6.16.3), the last of 256 threads to add to a relaxed atomic count, after a
seq_cst air.atomic.fence of mem_device, fences again and copies every thread's word; at
thread_scope_threadgroup and thread_scope_device, 16 threadgroups. No thread waits for another.
The kernels are LLVM text in the test, as FLOAT_ARENA and VOTE_WORD are; row_barrier is the
harness fixture's own.
The module doc now says what the file runs: lsum also at 256 threads a
group, and the tiled multiply also behind both fence flags and through
global tiles behind the global flag alone. Doc only.
The scratch buffer of the global-tile multiply is held until the work
completes; its binding now begins with an underscore, so the build of
the runtime's tests carries no unused-variable warning (lavapipe build,
job m3-max-76603).
Every test of a barrier now also runs at a threadgroup larger than one
wave and with each fence flag alone and both:
- lsum in 64 threadgroups of 256 threads (each group's sum reads
__local words other waves wrote), against the CPU's sums
(65536 g + 32640, exact in f32); the ported lsum stays as it stood.
- the tiled multiply behind barrier(CLK_LOCAL_MEM_FENCE |
CLK_GLOBAL_MEM_FENCE), and with its tiles in the threadgroup's own
part of a __global scratch buffer (buffer index 5) behind
barrier(CLK_GLOBAL_MEM_FENCE) alone, so the data crossing waves goes
through device memory; both compared exactly with the CPU's product.
Verification follows (lavapipe and RADV and NVIDIA cards).
The OpenCL-mode tiled multiply now calls barrier(CLK_LOCAL_MEM_FENCE)
as Apple's OpenCL compiler writes it (llvm-dis of a kernel it
compiled): `tail call fastcc void @_Z7barrierj(i32 noundef 1)`, the
wrapper passing OpenCL's flags on unchanged to the two-operand
air.wg.barrier (flags, threadgroup). CLK_LOCAL_MEM_FENCE is 1 in
OpenCL's encoding, which Metal's mem_flags read as mem_device. lsum
keeps the three-operand form the deleted test wrote, a second route
to the same flags. The bit-reversed variant goes: Apple's compiler
does not write barrier that way.
Verified: the two modules assemble with llvm-as (regenerated from the
test's strings); device runs follow.
Device tests of the runtime, on every device of the cfg's kind, of
kernels in the shape Apple's OpenCL compiler writes (an __entry_ wrapper
loading the values passed by value, the internal kernel, the work-item
functions and barrier as internal wrappers), bound as a pipeline of
OpenCL mode is bound: the global offset and dimension count by setBytes
at index 0, the kernel's buffers and values 3 past their indices, and
each __local argument's length by setThreadgroupMemoryLength at its own
index.
- lsum, ported from the deleted runtime's OpenCL-mode tests with its
answers (2016, 6112, 10208, 14304): a threadgroup of 64 sums its
inputs through __local memory and a barrier.
- Our own tiled matrix multiply: c = a b through two __local tiles of
32 by 32 floats (4096 bytes each, threadgroup indices 0 and 1), in
threadgroups of 32 by 4, each thread accumulating 8 rows, a barrier
after each tile's load and another before the next, dispatched over
160 by 3200 threads (whole threadgroups) 8 times in one command
buffer, each into its own c of 25600 by 160, k = 128. The values are
multiples of 1/64 below 4 in magnitude, so every product and partial
sum is exact in f32 and c is compared with the CPU's exactly; each
repeat prints how many elements differ and by how much. It runs with
barrier passing OpenCL's flags on to air.wg.barrier unchanged (as the
deleted tests wrote it) and with them reversed through
llvm.bitreverse.i2 (as mem_fence's are).
The guard for wrong values of an OpenCL-mode tiled multiply on RADV.
Verified so far: the three modules assemble with llvm-as (regenerated
from the test's strings); device runs follow.
The pass that reads an OpenCL-mode air.wg.barrier's flags as OpenCL's
(canon::opencl::barriers) runs in specialization, after the last SCCP
and before the post-check (canon/mod.rs, specialize_linked). Our
passes that write a barrier:
- canon::async_copy writes air.simdgroup.barrier(mem_threadgroup)
(async_copy.rs, NAME at line 295). It runs before the pass, but the
pass takes air.wg.barrier alone, so this barrier keeps Metal's flags.
- lower::simd::lockstep::insert writes air.wg.barrier and
air.simdgroup.barrier with Metal's mask (lockstep.rs, at lines 1133
to 1149). It runs from pipeline::compile's order_specialized
(compile.rs, at line 2832), on the entry specialization returns, so
after the pass.
- The partial-threadgroups variant's vote (lower/simd/workgroup.rs,
at lines 549 and 552), the mesh and object barrier
(lower/mesh/mod.rs, at line 1253), tile staging
(lower/access/tile.rs, at line 1122) and cooperative imageblock
staging (lower/texture/emit.rs, at line 3289) emit OpControlBarrier
in lowering directly, with no air.wg.barrier call the pass could
see.
The new test runs where a pass of ours does add barriers: the
lockstep pass under the resident-table domains, on the 780M's profile.
These are the barriers that broke the refusal test's control at
cb77b3f60d: two air.wg.barrier calls with mem_device and
mem_threadgroup (UniformMemory | WorkgroupMemory). The kernel holds
OpenCL barriers 1, 2 and 3, then stores to its __local slot again
right before reading it. In a threadgroup narrower than 32, two
threads of a simdgroup can share that slot, and no barrier orders the
pair, so the pass inserts one. In the ordered entry the program's
barriers read as OpenCL's (threadgroup, device, both), and every
inserted barrier's decoded flags are Metal's reading of its own
operand, threadgroup memory among them. Without the fix the first
assertion fails, as the program's 1 and 2 read as mem_device and
mem_threadgroup. If the pass ran after lockstep, the inserted
barriers' mem_threadgroup (2) would read as CLK_GLOBAL_MEM_FENCE, and
the second assertion would fail.
The OpenCL-mode reading of barrier flags (canon::opencl::barriers)
takes air.wg.barrier alone. Of the canonicalization passes that run
before it, only async_copy writes a barrier, and that barrier is
air.simdgroup.barrier with Metal's mem_threadgroup: its
simdgroup_barrier writes one name only, NAME = "air.simdgroup.barrier"
(async_copy.rs, at line 295). No canon pass writes air.wg.barrier, none
expands wait_group_events or async_work_group_copy, and the OpenCL
work-item, image and hidden-buffer rewrites write loads, arithmetic,
selects and texture calls. The lockstep pass writes air.wg.barrier
(lower/simd/lockstep.rs, at line 1149), but it is lowering's and runs
after specialization.
This test pins the half of that the pass decides: a kernel's
air.simdgroup.barrier(mem_threadgroup) orders threadgroup memory alone
(WorkgroupMemory) in OpenCL mode and without it, on the 780M's profile
under the runtime's policy. If the pass took simdgroup barriers, OpenCL
mode would read 2 as CLK_GLOBAL_MEM_FENCE and the test would see
UniformMemory.
Its control (the same AIR without the mode orders texture memory) built
the 780M's device under the resident-table domains, where the lockstep
pass inserts two barriers of its own after the program's, so the module
held three barriers where the test asked for one (job m3-max-76626 on
the commit before). The runtime compiles under DevicePolicy::default(),
whose identity domains order no lockstep pair, as the other new test
already does; the refusal test now takes the 780M's profile from the
same devices.
At the commit before, job m3-max-76628 ran both new tests with that
commit's sources in canon and intrinsics reverted to its parent: the
flags test fails, CLK_LOCAL_MEM_FENCE lowering to UniformMemory (64)
and CLK_GLOBAL_MEM_FENCE to WorkgroupMemory (256) on the 780M HawkPoint
profile, and the refusal test fails as the flags-4 barrier compiles.
With them (job m3-max-76626) the flags test passes on every committed
profile under the runtime's policy.
OpenCL C's barrier(flags) takes cl_mem_fence_flags, which Apple's
cl_kernel.h (OpenCL.framework, "5.9.7 - Synchronization") defines as
CLK_LOCAL_MEM_FENCE = 1U << 0 and CLK_GLOBAL_MEM_FENCE = 1U << 1, and
Apple's OpenCL compiler passes them to air.wg.barrier unconverted (an
internal function passing its parameter on as the barrier's flags).
Metal's mem_flags read the same bits as mem_device (1) and
mem_threadgroup (2), and decode reads every barrier as Metal's, so in a
kernel linked for OpenCL mode barrier(CLK_LOCAL_MEM_FENCE) lowered to
OpControlBarrier(Workgroup, Workgroup, AcquireRelease | UniformMemory):
nothing ordered the __local tiles, and RADV reordered them (a tiled
multiply's outputs wrong on the RX 550, the RX 7900 XTX and the 780M).
CLK_GLOBAL_MEM_FENCE likewise ordered threadgroup memory and left device
memory unfenced.
Specialization now reads each air.wg.barrier's flags again as OpenCL's
in a kernel of OpenCL mode (canon::opencl::barriers, from the
SpecRequest::open_cl_mode fact), after the last SCCP, so an out-of-line
barrier has its own call site's flags: CLK_LOCAL_MEM_FENCE is
mem_threadgroup and CLK_GLOBAL_MEM_FENCE mem_device
(MemFlags::from_cl_mem_fence_flags). It rewrites the call's decoded
operation in the entry's body, which lowering, the lockstep analysis,
the partial-threadgroups variant and the strategy census all read. A
flag outside the two leaves the call an unknown intrinsic, which the
post-check refuses (Unsupported, UnknownIntrinsic, naming
air.wg.barrier), as one outside Metal's mem_flags is. Nothing keys on a
function name. Metal-mode kernels, air.simdgroup.barrier (the header
declares no work_group_barrier or sub_group_barrier) and
air.atomic.fence (mem_fence's flags, which Apple's compiler converts
itself through llvm.bitreverse.i2) keep Metal's reading.
SEMANTICS_VERSION 2308. canon::opencl's module doc, docs/API.md (OpenCL
mode) and docs/ARCHITECTURE.md say what the flags mean and on what that
rests. docs/REFUSALS.md regenerates unchanged: the refusal is the
existing UnknownIntrinsic site.
Tests (tests::engine_opencl_mode):
- an_opencl_mode_barrier_orders_the_memory_its_opencl_flags_name: a
kernel of barriers 1, 2 and 3 by four routes (air.wg.barrier with the
constant, the wrapper of two operands, of three, and a parameter each
of three call sites binds), compiled as a pipeline on every committed
profile under the runtime's policy: in OpenCL mode WorkgroupMemory
alone, UniformMemory alone, both; without the mode UniformMemory,
WorkgroupMemory, both.
- an_opencl_mode_barrier_of_a_flag_opencl_does_not_name_is_refused:
flags 4, inline and through the wrapper, refused in OpenCL mode and
ImageMemory without it.
A job at this tip runs them, and once more with this commit's sources
in canon and intrinsics reverted to its parent, where the first fails.
The round's device legs run every rt_replay test on every card, so the
OpenCL-mode test also plays where the device binds a kernel's buffers
(the twelfth form). It now asks the device's own answer,
device.translator().profile().binds_kernel_buffers(), the query the
runtime makes the form from, and asserts one bound dispatch and no
address dispatch where it binds them, else one address dispatch and no
bound one; it prints the form as "REPLAY opencl-mode form ..." for the
round's log. play_then is split so a test can make the device first
(play_on) and ask it before the play.
Lavapipe takes the address form; the check job at this tip runs it.
compare-dumps said which word of a buffer differed first outside every
cover, but not what either play held there, so telling a NaN from a
rounding step or a stale word meant reading both dumps by hand. A
Difference now carries that word in each play's dump (first_values,
little-endian; a short end's bytes with zeros above them, none past a
dump's end), and its line prints them after the word's index:
"the first word W (a 0x........, b 0x........)". The stream doc says so.
The three compare tests take the values in their expected lines and
Differences, and a new unit test compares three buffers whose second
word differs in b, ends 2 bytes into it, or ends before it.
The player refused a compute descriptor whose openClMode was true, so a
stream that makes an OpenCL-mode pipeline (a guest running OpenCL C on
Metal) stopped at its first one. The runtime's descriptor carries the
mode (open_cl_mode_enabled), and the translator links the kernel for it:
the three hidden buffers ahead of the kernel's own, its buffer indices 3
on, get_global_id with the dispatch's offset. The player now gives the
stream's value to the descriptor, off where absent, and the stream doc
says so.
The previous commit's test is its check on lavapipe: red before this
commit, green with it.
A device test of the player on the runtime: a stream makes a compute
pipeline state with openClMode true from our own kernel in the shape
Apple's OpenCL compiler writes (the translator's by-value kernel:
o[get_global_id(0)] = k + s.a), binds the first hidden buffer with a
global offset of 1 and one dimension, o at 3 and k and s by setBytes at 4
and 5, and dispatches three threads. o[1..4] must read 3.75 and o[0]
keep its -1, nothing skipped.
The player refuses openClMode true today, so this test fails at this
commit (the play stops at the pipeline state); the next commit gives the
key to the pipeline descriptor.
No content change: the evidence for the form (a473ab8c92) and its layouts test (3df886d8f1,
418ff4c348).
rt's own copy tore 6 of 4,000 at R8Unorm 1920x1080 through rt before the form and 0 of 4,000
after (780M, RADV, validation layer not loaded); the recordings hold in-reach textures by
descriptor, whose copied form on the device files do not show.
The layouts test an_over_image_is_copied_in_from_undefined_and_back_from_home: red on lavapipe
at the commit before the form (job m3-max-76431), green with it (job m3-max-76432).
The arms, Radeon 780M (RADV PHOENIX, Mesa 26.2.6), through the runtime, validation layer not
loaded, 4,000 repeats an arm, every byte of a repeat unlike the last repeat's, read back whole:
- R8Unorm 1920x1080 ShaderRead|RenderTarget over a Shared buffer at a pitch of 2304 (cause
Pitch), job m3-max-76446:
- old form: refill 6 of 4,000 stale (repeats 418, 1367, 1484, 2674, 3318, 3807; 8 bytes each,
every one the last repeat's), first use 0 of 4,000;
- new form: refill 0 of 4,000, first use 0 of 4,000;
- over_copies 4000, over_copies_pitch 4000, over_copy_bytes_shared 8294400000 in every arm.
- BGRA8Unorm 1024x1024 ShaderRead|RenderTarget at rows of 7680, offset 0, over a Shared buffer
of 8,294,400 bytes, refill, job m3-max-76454: old form 0 of 4,000, new form 0 of 4,000;
over_copies 4000, over_copies_pitch 4000 in each (the copied form ran).
The timed check, command-replay at 779fd31192 (old) and at 418ff4c348 (new), alternated in one
job (new, old, old, new), each play with a fresh shader cache; the sum of the frames' wall time
and GPU busy time per play. Deterministic counts (submissions, barriers, bytes copied, over-copy
bytes Shared, passes) equal in every play unless noted.
- Radeon 780M, glbench-780m-r2, job m3-max-76454 (exclusive): wall new 117.935 / 119.705 s,
old 118.742 / 117.946 s, new +0.40% on the mean (the old pair 0.67% apart); GPU busy new
16.998 / 17.022 s, old 17.061 / 17.040 s (-0.24%).
- RTX 5080 Laptop, gb-3090-r2 with --managed two-copy, job m3-max-76456 (exclusive): wall new
85.560 / 86.018 s, old 84.570 / 83.330 s, new +2.19% (the old pair 1.48% apart); GPU busy new
21.931 / 21.416 s, old 21.367 / 20.810 s (+2.77%). Both new plays slower than both old ones on
both measures. Barriers 702306 / 702315 / 702312 / 702311: they move between plays of one
build.
- Iris Xe (RPL-P, ANV), glbench-780m-r2, job m3-max-76477 (exclusive): wall new 131.978 /
132.296 s, old 132.248 / 132.112 s, new -0.03% (the old pair 0.10% apart); GPU busy new
32.386 / 32.392 s, old 32.380 / 32.364 s (+0.05%).
Values, one old and one new play with --check-presents, compared by compare-plays:
- Radeon 780M, glbench-780m-r2, job m3-max-76476: 15 frames checked in both, 0 differ; counts
equal in 792 of 792 frames.
- RTX 5080 Laptop, gb-3090-r2, job m3-max-76470: 22 frames checked in both, 0 differ; counts
equal in 1115 of 1115 frames.
- Iris Xe, glbench-780m-r2, job m3-max-76478: 15 frames checked in both, 0 differ; counts equal
in 792 of 792 frames.
The branch's check, job m3-max-76451 at 418ff4c348: fmt, signatures, clippy (plain, m2v_gpu,
m2v_cpu_icd), Rustdoc, and the runtime's device suite on lavapipe with validation layer 1.4.363.0
(788 passed, 3 skipped).
The test at 3df886d8f1 did not compile on lavapipe (job m3-max-76429): ash::vk::ImageLayout
implements no Debug in this build. Its print and assertion messages now show each layout's
number (VkImageLayout).
A texture over a buffer that the device's linear image does not hold lives in an optimal image of
the runtime's (the copied form, crate::over), refreshed by one vkCmdCopyBufferToImage of the
texture's whole level and slice. Its move to the transfer layout started from the image's home,
which keeps the image's earlier contents: the whole-refill shape that leaves a stale 4 x 2 cell on
a Radeon 780M under RADV (Mesa 26.2.6; 7 of 4,000 R8Unorm 1920 x 1080 refills in plain Vulkan).
The landed form (TextureObject::away_into) covered only the blit encoder's copies.
A copy into the image now moves it from the undefined layout, discarding what it held, as the
copy writes every texel of the image's one level, slice and aspect: texture::over_texel refuses
any texture over a buffer but a 2D one of one level, sample and slice of a colour format of one
texel an element (texture.rs over_texel, the unit's aspect COLOR), so the region always covers the
barrier's one aspect. A copy back keeps the move from home. The runtime README's gap sentence and
over.rs's module doc say so.
Verified: the layouts test an_over_image_is_copied_in_from_undefined_and_back_from_home, red at
the commit before, green here, on lavapipe (jobs in the next report).
A layouts test for rt's own copies between a texture over a Shared buffer and the image of its
own that the copied form keeps (crate::over): every copy of the buffer's bytes into the image is
to move the image from the undefined layout, as the copy writes its whole level and slice, and
every copy back from home. On this commit's form the copy in moves from home, so the test fails:
the red half of the over-copy discard.
The layouts recorder learns the discard's shape. A move of an image's first level from the
undefined layout after its move home was always counted as a second move home that drops the
image's bytes. It is now a discard, made good only when the image's next step is a copy from a
buffer into its whole first level (the recorder keeps each image's extent, as made), and counted
in Moves::discards; any other next step is still a step out of order. The landed whole copy in
(TextureObject::away_into) has the same shape.
Verified in the next job on lavapipe (red here by design).
The known gap of a copy from a buffer into part of a texture on a Radeon 780M under RADV
(Mesa 26.2.6) now says where the stale 4 x 2 cells lay at 1920 x 1080, in its own numbers:
refilling rows 864 to 1079, rows 1026 to 1058 (through the runtime, job m3-max-76165, both
archives; the plain Vulkan repro, job m3-max-76256: rows 1042 to 1058). It adds the plain Vulkan
repro's other sizes, the bottom 216 rows refilled 4,000 times each (job m3-max-76256): at
1920 x 1088, 4 stale in rows 882 to 890; at 1024 x 1024, 3 in rows 818 to 826; at 2048 x 2048,
none.
The form's steady price, measured in the rung-1 timed check (copy_from_buffer of a whole
1920 x 1080 level, 16 a command buffer, its GPU span; replace_region of a whole Shared
texture, 16 a command buffer, its upload's GPU time; old form against new, alternated in one
job), which the form's commit, already made, does not carry:
- RTX 3090: every row within 0.3% (job m3-max-76188).
- Iris Xe: every row within its spread; the RGBA8 upload's p10, its noisiest row, 132.75 us
against 132.78, 0.02% (job m3-max-76213, 4 pairs of 200 rounds).
- Radeon 780M (job m3-max-76214, 4 pairs of 200 rounds, mean of each pair's p10): R8 upload
95.05 us against 96.55, +1.6% (about 1.5 us, slower in every pair); RGBA8 copy 216.9 against
219.1, +1.0%, slower in every pair; RGBA8 upload +0.7%; R8 copy +0.2%. All within 3%.
README only.
Clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd refused chunks_exact_mut with a constant
size in whole_copy_in.rs (check job m3-max-76207). The step is unchanged: each byte adds 37,
eight at a time, the remainder one at a time.
A copy from a buffer into part of a one-sample colour texture can leave one aligned 4 x 2 cell
of the texture's earlier contents on the Radeon 780M under RADV (Mesa 26.2.6), measured on
R8Unorm at 1920 x 1080 only: in proof job m3-max-76165, refills of the bottom band of 1920 x 216
tore 17 of 4000 through rt and 9 of 4000 in plain Vulkan on rt's create info; refills of
480 x 216 rectangles of a 4 x 5 grid in turn, 1 of 4000 through rt and 0 of 4000 plain, the
bottom band reached in 800 of them. A whole-level copy discards first and does not (0 of 4000
through rt). No recording form covers a partial copy: no layout of the copy and no barrier
stopped the whole-refill form (job m3-max-76144).
Each refill's bytes are the last's plus 37, added a word at a time, where the test computed each
byte from its column and row, which a debug build spends most of a refill on.
ash is built without its debug feature here, so the layouts and aspects are compared as values
and printed raw. The m2v_gpu build of ff0e8e78c1 failed on it (job m3-max-76191).
A copy from a buffer into a texture whose region starts at the level's first texel and reaches
its edge on every axis (a 3D level's depth included; a compressed level's edge as place clamps
the region), of every aspect of the image, moves that level and layer to TRANSFER_DST_OPTIMAL
from VK_IMAGE_LAYOUT_UNDEFINED in place of its home layout. Only the old layout changes: the
barrier's range is the one level and layer the copy writes (all slices of a 3D level, which the
copy then writes whole), and its source scope stays ALL_COMMANDS, MEMORY_WRITE over every earlier
access of the image, so the copy is still ordered after every earlier read and write. A copy of
one aspect of a depth-stencil image, a region short of the level on any axis, and an image whose
bytes another reaches (in place over a buffer, a surface plane's, an import's) keep the old form.
A heap-placed texture takes the form as a texture of its own memory does. Copies between
textures are not touched.
Both upload entries share it: the blit encoder's copy from a buffer into a texture
(copyFromBuffer:...toTexture:, record_buffer_copies) and the staged upload of replaceRegion and
a Managed texture's writes (TextureInner::record), each through TextureInner::away_into.
Why it is right for Metal: a copy that writes the whole level and slice leaves none of the
earlier contents for a program to see, so discarding them first is unobservable. Why Vulkan
allows it, vkspec 1.4.366 line 9241: "The old layout must either be VK_IMAGE_LAYOUT_UNDEFINED,
or match the current layout of the image subresource range. If the old layout matches the
current layout of the image subresource range, the transition preserves the contents of that
range. If the old layout is VK_IMAGE_LAYOUT_UNDEFINED, the contents of that range may be
discarded." The range is the subresource the copy then writes whole. For a heap-placed texture,
line 32552: "If the first alias is not host-accessible, then the bytes affected are those
overlapped by the image subresources that were written": the copy writes those bytes in any
form, so the discard leaves nothing undefined that the copy's write would not.
Why: on the Radeon 780M (RADV PHOENIX, Mesa 26.2.6, kernel 7.3.3), a buffer-to-image copy that
refilled an R8 1920 x 1080 DCC-compressed image in place left one whole aligned 4x2 cell of the
previous contents in about 2 to 4 of 1000 refills, measured on R8 at 1920 x 1080; no layout of
the copy and no barrier stopped it (GENERAL 6 of 3000, no move between refills 11 of 3000, job
m3-max-76144), and the validation layer 1.4.363.0 with synchronization validation reported
nothing while it reported a hazard planted for it. A pure C repro of the calls (job
m3-max-76150, 4000 repeats an arm): the move from home 7 stale, from undefined 0,
RADV_DEBUG=nodcc 0, without COLOR_ATTACHMENT 0. Through ash in job m3-max-76165 (archives of
build m3-max-76163): the same image refilled with the move from undefined 0 of 4000, beside the
move from home 14 of 4000; through rt with this form, CONTROL, W2048 and H (the consumer's
shapes) 0 of 4000 each. Mesa's source was not read for this change.
whole_copy_in.rs holds the move's old layout for whole and short regions, levels past the
first, a 3D level's depth, one aspect of depth and stencil, and a texture over a buffer; and
1000 whole refills of an R8 1920 x 1080 render target through rt, each read back whole and
compared byte for byte.
Block::_chunks is on every target, but sparse_block is #[cfg(unix)], so a private-items rustdoc
for a Windows target could not resolve the intra-doc link (found by the Direct3D 11 hand-over
lane's rustdoc of x86_64-pc-windows-gnullvm at 57dcc7f826). The field's doc now names the
function as code, on Unix, and the comment is rewrapped to 100 columns. Docs only.
Checked by a private-items rustdoc of metal2vulkan-runtime with -D warnings for
x86_64-pc-windows-gnullvm, x86_64-pc-windows-msvc and the Linux host.
The planner's two additions before landing.
The maxExtent refusal had only a Windows device test, and on the UHD 630 the import query answers
what the plain query does, so no card in the lab fails without the check. The check is now one
function, texture::plane_within (a plane of one 2D layer against the import query's answer, which
d3d11_plane_form calls), compiled for Windows and the tests, and
a_plane_past_its_import_s_max_extent_is_texture_size (no device, every leg) gives it an import
answer one texel narrower, then one shorter, than a 64x32 plane: each is Limit::TextureSize
carrying the import's extent; an answer of the plane's own extent passes. Replacing the check
with Ok fails it. Removing d3d11_plane_form's call is not caught on Linux, where that function
is not compiled; no card in the lab shows the import check firing on its own.
The Khronos validation layer does not track a Direct3D 11 import's layout: on the UHD 630, layer
1.4.363.0 reported neither the old form's first acquire from the general layout (job
m3-max-76170) nor the new form's from the undefined layout (job m3-max-76174). The Layout
paragraph of import_d3d11_surface and the first-use test's doc say so, so its silence is not read
as evidence.
Clippy under --cfg m2v_gpu at 9737a44d98 (job m3-max-76168) refused plane_parts' `shape` return
type as too complex (clippy::type_complexity, denied by -D warnings). The parts and the hand-overs
asked for are now named types. No test changes what it checks.
A plane's image is made undefined (VUID-VkImageCreateInfo-pNext-01443) and Vulkan takes it as
general only "when they are accessed in Vulkan after external access" (section 12.5.2). Every
acquire named the general layout as its old layout, so where rt used a plane before any
Direct3D 11 access (the consumer's transfer fill of a new target, or a guest command buffer that
writes the plane first), the acquire's old layout was neither the image's current layout nor
undefined, past section 12.5.1 ("the old layout value must either equal the current layout of the
image subresource (at the time the transition executes), or else be VK_IMAGE_LAYOUT_UNDEFINED").
Now a plane's first acquire recorded, in recording order on the submit thread, names the
undefined layout, unless the surface's external_writes_done was called before it; every later
acquire, and every release, names the general layout, as before. The plane's existing once-only
move-home flag (Image::homed) carries it: a Direct3D 11 plane, which no upload moves, is now made
with the flag clear and `first` undefined, its first acquire sets it as it moves the plane from
undefined, and external_writes_done sets it on the host for each plane of a Direct3D 11 surface,
with no GPU work. homing() never moves such a plane, so an upload that copies into one leaves its
move to the acquire ahead of it. VUID-VkImageMemoryBarrier-srcQueueFamilyIndex-12332 allows either
old layout, so the barrier is the same one with another old layout: no wait, copy, clear or
submission is added.
The consumer's precondition now includes external_writes_done after every Direct3D 11 access,
before the commit of the command buffers that use the plane: without it, the plane's first
acquire names the undefined layout, which need not preserve the contents (section 12.5.1), so the
device may discard what Direct3D 11 wrote. The Layout, Ownership and precondition paragraphs of
import_d3d11_surface, the d3d11 module's doc, external_writes_done's doc and the runtime README
say so.
The test commit's every_device_acquires_a_direct3d_11_plane_from_undefined_only_before_any_access
states this rule; its red run is of 74c3940054.
Three fixes the Windows cross-build of 7c5df5a317 found (the gnullvm target under --cfg m2v_gpu,
job m3-max-76160):
- The maxExtent refusal test printed a vk::Extent3D and the first-use test compared and printed
vk::ImageLayout values with Debug, which ash's types do not implement here: the extent prints
as its three numbers, and the layouts compare and print as their raw values.
- Since the part builder returns the parts, the only change to them after it is the sparse bind's
wait, made on Unix hosts alone, so `let mut parts` was an unused mut on Windows (a warning, an
error under -D warnings). The owed wait is now read into one binding on every host, None where
the host has no such import, and the mutation compiles everywhere.
No behaviour changes.
A plane's image is made undefined (VUID-VkImageCreateInfo-pNext-01443), and Vulkan takes it as
general only "when they are accessed in Vulkan after external access" (section 12.5.2). Every
acquire of a plane names the general layout as its old layout, the first included, so where rt
uses a plane before any Direct3D 11 access (a transfer fill of a new target, or a command buffer
that writes the plane first), that acquire's old layout is neither the image's current layout nor
undefined (section 12.5.1: "the old layout value must either equal the current layout of the
image subresource (at the time the transition executes), or else be VK_IMAGE_LAYOUT_UNDEFINED").
This test states the rule and fails on this tree:
every_device_acquires_a_direct3d_11_plane_from_undefined_only_before_any_access (Windows, m2v_gpu).
rt writes picture 3 into a new surface's planes before any Direct3D 11 access: each plane's first
acquire must name the undefined layout, and the acquire of rt's next read, after Direct3D 11 read
picture 3 exactly, the general layout. On a surface Direct3D 11 drew first and the consumer
reported by external_writes_done, every acquire names the general layout, the first included, and
rt reads picture 1 exactly: the control, which passes here.
The acquires are read from Work::acquired, a record only the device tests compile: each plane
acquire's image and old layout as the hand-over records it, in recording order.
A plane's extent was checked only against the image format query without the handle type
(plane_plan's prepare). VUID-VkImageCreateInfo-extent-02252 bounds an image's extent by
imageCreateMaxExtent, which for an image made with VkExternalMemoryImageCreateInfo is the query's
answer with VkPhysicalDeviceExternalImageFormatInfo naming the handle type: a device may make an
imported image smaller than a plain one, and a plane between the two would be created past the
limit.
The import query (d3d11::import_query) now answers the image's properties with the handle too, and
d3d11_plane_form checks the plane's extent against them once its usage and format list are
final: past it, Limit::TextureSize carries the import's maxExtent. The existing kind has the
same meaning (an extent past what the device makes of the image), so no new variant; its doc and
basis name the import's query, and docs/REFUSALS.md is regenerated (a second NoImport site, the
query failing at the final form, which the earlier checks make unreachable on a conforming
driver). The extent check itself is one function now (texture::size_within), the plain path's
included, unchanged there.
The Windows refusal test asks for a luma one texel wider than the import query's maxExtent and
expects TextureSize at that answer or the plain query's below it, printing both. On a device
whose two answers are equal the plain check refuses first, so that run does not show the import
check firing on its own.
A group sent member by member is one vkQueueSubmit2 a part, each with a progress value of its own,
and each command buffer retires at its own part's value. The planes' hand-over was per group: one
acquire ahead of the first part and one release at the end of the last, taking the last part's
signals. A member ahead of the last that used a plane was then seen complete before that plane's
release had run, and the consumer's precondition (rt's command buffers that use a plane have
completed before Direct3D 11 accesses it) let Direct3D 11 take the plane while rt still owned it,
its release still queued (Vulkan 1.4, section 12.10.1: "Ensure the release operation has completed
using semaphores or fences"; 7.7.6: an ownership transfer may access all memory bound to the
subresource). Found by reading; whether any run met it, and whether it made a hang on any driver,
is not known.
Now a group records which planes each part's segments use, by the part the segment is in (the
leads before it), from what each segment keeps (Segment::planes), and the part builder hands each
plane-using part's planes over in that part: the acquire at its head, after the global barrier as
before, and the release at its end, taking that part's last signals, its progress value among
them, so it adds no submit info and no submission. The uploads' planes go with the first part. A
group sent as one part is unchanged: one acquire ahead of everything, one release after
everything. Each plane-using part of a group sent apart adds one acquire and one release command
buffer, with no wait, copy or submission added.
Metrics::d3d11_plane_submissions now counts vkQueueSubmit2 calls that hand planes over: a group
sent as one counts once, a group sent apart once for each of its calls that uses a plane. The new
Metrics::d3d11_plane_parts (no Metal counterpart) counts the calls among those that are parts of a
group sent member by member: the path's evidence. The Ownership paragraph (d3d11.rs), the runtime
README, Segment::planes, external_writes_done, release_surface_to_external and the metric docs
say per vkQueueSubmit2 where it was per submission. api_signatures.tsv blessed for the new field;
docs/REFUSALS.md unchanged by its regeneration.
The test commit's plane_parts tests (no device), red on that commit (job m3-max-76147), and its
Direct3D 11 apart test state this form; the apart test now asserts d3d11_plane_parts too.
A group sent member by member is one vkQueueSubmit2 a part, each part signalling a progress value of
its own, and each command buffer retires at its own part's value. The Direct3D 11 planes' hand-over
is still per group: one acquire ahead of the first part and one release at the end of the last, so
a member ahead of the last that used a plane is seen complete before that plane's release has run,
and the consumer's precondition (rt's command buffers that use a plane have completed) lets
Direct3D 11 take the plane while rt still owns it (Vulkan 1.4, section 12.10.1: "Ensure the release
operation has completed"). Found by reading; whether any run met it is not known.
These tests state the per-part form and fail on this tree:
- plane_parts (no device, every leg): the part builder, now its own function (`submit::parts`)
with the per-group placement unchanged, given a group of an upload and two leads and the planes
each part uses. Each plane-using part must acquire at its head and release at its end, the
release taking the part's signals and progress value; a part using no plane takes neither; the
uploads' planes go with the part ahead of the first lead. The negative control, a group sent as
one part, hands over once ahead of everything and once after, as today, and passes here.
- every_device_hands_direct3d_11_planes_over_in_each_part_of_a_group_sent_apart (Windows,
m2v_gpu): behind a queue's busy work, a read of the planes and a second command buffer join one
group; a run of 1 s seen before it goes (QueueInner::ran, the state retirements set) sends it
member by member. Two reads must hand over twice each way and make two vkQueueSubmit2 calls; a
read and a buffer copy once each way in two calls. Sent as one part (send_now), the two reads
hand over once: the control.
The extraction moves no command buffer: the acquire still leads the uploads and the release still
takes the last part's last signals.
6ae4d7dbaf left one line of the AttachmentFormats bullet at 123 characters. The bullet's
last seven lines are wrapped again to 100; no word changes.
Verified: no line of the bullet passes 100 characters (python -I check); docs only.
Every render state now keeps its descriptor (the state drawn without the colours past its
pass's last attachment is made of it), so every make copies it and every drop frees the copy.
The README's line said what a set and a draw cost and what the kept descriptor holds alive,
but not this. It now states it: a make of a content the device already holds takes about
13,500 user-space instructions on lavapipe against about 11,800 without the keep, once a
state and never a draw.
Verified: the figures are the lane's scratch count test, release, lavapipe (llvmpipe, LLVM
23.1.1), mean of 200 calls, 5 runs each: m3-max-75974 at the branch (13,494 to 13,506) and
m3-max-75975 at development 0ae823f5e7 (11,806); read from both jobs' logs. Docs only.
clippy (needless_range_loop, -D warnings) refused the loop that indexed targets[at] by the
colour's index (job m3-max-75986, msi, plain configuration); the loop now walks the array
it fills. The calls and their order are unchanged, so the recording stands.
Verified: formatted; clippy in all three configurations runs next.
`conformance replay --cpu` of both unattached-colour cases on lavapipe (job m3-max-75983,
at 981d1c0d81) read:
- pass-pipeline-color-unattached: announced, every value equal to Metal's; the one
difference is the native note native-nan-encoding, which the suite's native set holds.
- pass-pipeline-color-unattached-between: refused at case/drawn/pass:lacking
(DrawKind::AttachmentFormats), as the form intends, and divergent at case/notices:
our side announced device-interpolation, which the case declared nowhere.
The between case's fragment, cg_five, writes every colour from an interpolated varying,
so the case now declares device-interpolation (a notice declaration, which loosens no
value). known-gaps-rt.tsv gains the refused row, venue *: the refusal is the same on every
device (lacked_past answers None for that shape). docs/CONFORMANCE-COVERAGE.md is
regenerated: 191 case modules, 1339 recordings, both new modules every field compared.
Verified: the replay rerun and the conformance crate's tests follow in the next job.
README, Render encoders: a pipeline state that names colours past its pass's last colour
attachment, the rest of its formats and its sample count the pass's, is drawn as plain
Metal draws it (pass-pipeline-color-unattached, Apple M3 Max, macOS 27.0.1, job
m3-max-75903), through the state of its descriptor without those colours. The costs, each
from a run:
- the first such set and draw: about 3.3 ms once per state and pass shape on an RTX 5080
Laptop card, from a proxy (a state of the same functions with colour 0 alone; jobs
m3-max-75918 and m3-max-75925);
- each later such set: about 14,500 user-space instructions on lavapipe (job m3-max-75974,
release, five runs, 14,510 to 14,517), where a set of a state that renders into its pass
is 140;
- the descriptor each render state keeps: in states-only plays of two recorded replay
streams on lavapipe it kept no library alive that was not alive without it (jobs
m3-max-75968 and m3-max-75969: the bytes of released libraries still alive, at each
change, equal at this tree and at its base, 29 and 140 changes).
The between shape stays refused (job m3-max-75934). The Gap::Draw list's "a pipeline state
whose formats are not the pass's attachments'" now excepts the shape drawn, and the
first-use list names that state's pipeline under first_use_unfinished_waits.
docs/REFUSALS.md is regenerated (refusal_surface.py): Gap::Draw gains its site in
render.rs (without_colors).
`conformance times --runs 8 --write pass-pipeline-color-unattached
pass-pipeline-color-unattached-between`, built --release at d2d96151a8, on the Apple M3
Max, macOS 27.0.1 (26A434), job m3-max-75970 (the build: job m3-max-75963). Each
recording gained one time record (native Metal, 8 rounds) and nothing else: a comparison
of the JSON before and after shows `times` the one key added and every other key equal.
metals_recording_draws_colour_0_and_keeps_the_clear_elsewhere holds the recording of
pass-pipeline-color-unattached to the case's codes: colour 0 holds the fragment's codes in
the scissor's rows and the clear in the others, and the command buffer has no error.
metals_recording_writes_colour_1_into_colour_2 holds the recording of
pass-pipeline-color-unattached-between to what job m3-max-75934 showed: the lacking pass's
colour 0 equals the reference's, its colour 2 holds the reference's colour 1 in the drawn
rows (and differs from the reference's colour 2 there), and its clear elsewhere.
Verified: a Python reading of both committed recordings gives each assertion true; the
Rust tests run in the conformance suite's job that follows.
Plain Metal on the Apple M3 Max, macOS 27.0.1 (26A434), job m3-max-75934: three runs,
one outcome, the command buffer complete with no error. Colour 0 of the pass that
leaves colour 1 unset equals the reference pass's at all 64 texels; its colour 2 holds,
at all 32 drawn texels, the reference's colour 1 bytes (RG16Float bits written into the
RGBA8Unorm attachment) and its clear elsewhere. The validated leg stops at the render
call: "For color attachment 1, the renderPipelineState pixelFormat must be
MTLPixelFormatInvalid, as no texture is set."
Verified: the recording is the file record mode wrote in that job, copied back
unchanged; the planes were compared texel by texel.
A pipeline state that names colours past its pass's last colour attachment, its
formats up to that attachment, its depth and stencil formats and its raster sample
count all the pass's, was refused at the draw as DrawKind::AttachmentFormats. Plain
Metal draws it (pass-pipeline-color-unattached, the Apple M3 Max, job m3-max-75903):
the attachments it has hold the fragment's values, and its validation alone stops it.
set_render_pipeline_state now binds, for such a pass, the state of the descriptor
without those colours (RenderPipelineState::without_colors): a content of its own in
the device's map of contents, lowered on the calling thread where the device holds
none, its fragment function storing those colours nowhere as for any descriptor that
leaves them unset, its samplers numbered at the state's indices, and its pipeline made
by its first draw (a first-use wait). That content renders into the pass under the
exact match draws already take, so no new attachment rule enters a pipeline's make. A
state that renders into its pass takes the same path as before: one renders_into and
the lend. Each state now keeps the descriptor it was made of.
A colour the state names before the pass's last colour attachment that the pass
leaves unset stays refused: plain Metal writes the next colour's value into the
attachment after it (pass-pipeline-color-unattached-between, job m3-max-75934). So do
another format, a depth or stencil format the pass lacks and another sample count.
Test: tests/unattached_colors.rs. Verified: formatted only; the device runs follow.
pass-pipeline-color-unattached-between: a pipeline of colour 0 BGRA8Unorm, colour 1
RG16Float and colour 2 RGBA8Unorm over the owned color_groups fixture (cg_cover,
cg_five), drawn twice in one command buffer: into a pass of all three colours, the
reference, and into a pass of colours 0 and 2 with colour 1's descriptor unset. It
reads both passes' colours 0 and 2, the reference's colour 1, and the command
buffer's status and error.
Why: the runtime's form for a pipeline colour its pass lacks covers a missing colour
between two present ones only if Metal draws that shape too; this case is Metal's
answer for it, taken next on the Apple M3 Max.
Verified: nothing yet (formatted only); the build and the record run follow.
Plain Metal on the Apple M3 Max, macOS 27.0.1 (26A434), job m3-max-75903: three runs,
one outcome. Colour 0 holds the fragment's value at all 32 texels of the drawn rows
and the clear at the other 32; the command buffer completes with no error. The
validated leg (MTL_DEBUG_LAYER=1, nslog) stops at the render call: "For color
attachment 1, the renderPipelineState pixelFormat must be MTLPixelFormatInvalid, as no
texture is set."
Verified: the recording is the file record mode wrote in that job, copied back
unchanged (potluck cp), and every texel was checked against the case's codes.
pass-pipeline-color-unattached: a pipeline of colour 0 BGRA8Unorm and colour 1
RG16Float over the owned rt6_pair fixture (rt6_pair_two writes both), drawn in a
pass that attaches colour 0 alone and leaves colour 1's descriptor unset. The case
reads colour 0's level 0, the command buffer's status and its error.
Why: the runtime refuses such a draw as DrawKind::AttachmentFormats (renders_into
asks equal colour counts), and Metal's answer for the shape is not in the tree.
The case is that answer's carrier; its recording is taken next on the Apple M3 Max.
Verified: nothing yet (formatted only); the build and the record run follow.
coherence.rs's list of what a command buffer may write named each texture over a Shared buffer
in an image of its own, and a texture over one as a command names it, without saying which bytes
they count for. As in the runtime README's clause (a129f2cb7f), the code counts the whole buffer
the texture lies over: TextureObject::shared_range (texture.rs:5780) is its named buffer's
BufferObject::shared_range (buffer.rs:654). Comment only; no behaviour change.
Verified: fmt --check and rustdoc -D warnings in the job that follows.
The runtime README's list of what a command buffer may write, which its completion flushes and
invalidates, names every texture over a Shared buffer in an image of its own (and a pass's
attachments, a binding, a use_resource write, a copy's destination, which may be such a texture)
but did not say which bytes such a texture's settle covers. The code settles the whole buffer the
texture lies over: TextureObject::shared_range (crates/metal2vulkan-runtime/src/texture.rs:5780)
is its named buffer's BufferObject::shared_range (buffer.rs:654, the buffer's whole span), and
coherence::Ranges::of (coherence.rs:212) adds that range to what is written for a texture in an
image of its own. The list now says so, in one clause. Docs only; nothing narrowed.
Verified: fmt --check and rustdoc -D warnings in the job that follows.
On the RTX 5080 (b5080 entry in job m3-max-75853) the event test's completion read
[2, 128, 1, 64, 0, 64, 64, 0, 0]: the command buffer's segment after its wait for the host's value
is a submission of its own, which flushes the buffer again at the submission's point (64 bytes),
then the completion settles it at the retirement's (64). The test asserted no flush at the
submission's point there. It now asserts both flushes and their points; the doc comment says so.
Verified: cargo fmt only; the 5080 run follows.
The first run (lavapipe, job m3-max-75846) settled at the submission's point too, which the
runtime never does, so the identity calls() asserts (the invalidated bytes are the retirements',
the events' and at most the staging's) failed there: [1, 128, 1, 128, 0, 128, 0, 0, 0]. The test
now flushes at the submission's point, settles at the retirement's and the event's, and does both
at the staging point, as the product's sites do.
Verified: cargo fmt only; the lavapipe job follows.
What: six public Metrics fields, after shared_coherence_failures.
- shared_reach_flushed_bytes, shared_retire_flushed_bytes, shared_event_flushed_bytes and
shared_staging_flushed_bytes: each flush's bytes once more, by the point that made it
(coherence::Point: the flush before a submission; the settle as a command buffer retires; the
settle before a GPU-raised shared event value is seen; the runtime's own host accesses:
replace_region, upload_region, get_bytes and the zero source). A settle's flush counts at its
settle's point.
- shared_flush_nanos and shared_invalidate_nanos: host_time() read at each
vkFlushMappedMemoryRanges and vkInvalidateMappedMemoryRanges call and at its return (a settle
times its two calls apart), one Relaxed add each. The zero source's flush, made outside
Coherence, is timed the same way.
The identity: reach + retire + event + staging == shared_flushed_bytes, and
retire + event <= shared_invalidated_bytes <= retire + event + staging (the excess is get_bytes's
settles), for a read made while no call is under way and for the difference of two such reads.
A device whose Shared type is host-coherent holds no Coherence, reads no clock for these and
keeps all six at 0.
Why: issue 182's Meteor Lake session averages 67 MB a frame of flushed and settled bytes, and its
counters cannot say which point carries them, nor how long the driver's calls take. Counting and
timing only: no site narrowed, no form, switch or device check.
Tests (crates/metal2vulkan-runtime/src/tests/coherence.rs): calls() returns the four points with
the five totals and asserts the identity on every delta it reads; each site under the forced view
asserts its bytes at its own point (a fill, a blit, replace_region, get_bytes, a GPU-signalled
event seen, the texture-over-buffer, use_resource, use_heap, function-table, upload and
written-only sites through one_submission); a device with no coherence state counts nothing and
no time over its life; where calls ran the time fields are not 0. A new device test,
a_coherence_state_counts_each_call_at_its_point_and_times_it, makes a coherence state of its own
over the viewed Shared type, so it runs on lavapipe too, where the floor refuses the view: a
flush and a settle at each point count there alone.
Docs: the Metrics fields' comments, coherence.rs's module doc, the runtime README's Shared memory's
coherence and its known gap; api_signatures.tsv blessed (six field lines). refusal_surface.py
--check passes unchanged.
Verified: cargo fmt only when committed; the build and device jobs follow.