In-place check: a kernel's writes of a texture over a buffer may change its rows' padding

What: a second verdict for a kernel's writes, Access::BufferWrites, taken by a texture over a
buffer's rows (no IOSurface plane's) whose buffer holds its last row to its pitch and whose rows,
each to its pitch, start and end on a line of the device's memory (in_place::Padding::Free). The
same Writes rounds give it: the writer and the compare tell a change of a byte of the shape's
rows' padding (after a row's last texel, before its pitch, the last row's included) apart from
any other change. A round that changed only such bytes (Round::Padded) fails Writes for its row
ends, as before, and counts as kept for BufferWrites, and the rounds go on through every shape;
any other change (a texel, a byte past the last row's pitch) fails both and ends the class's
rounds. in_place() asks BufferWrites in the stead of Writes for such a texture; renders, an
IOSurface plane's rows and a render target's storage usage (storable) keep the strict verdict.
The rebind's choice of fresh pages carries whether the padding is the buffer's own. 24 verdicts,
CHECK_VERSION 7; the report adds `{class} buffer writes` lines.

Why: real Macs disagree on those bytes, so Metal leaves them to the GPU. The probe
(row_padding_writes.m) found an Intel UHD Graphics 630 under macOS 26.7.1 writing older values
back over the CPU's writes to the padding of textures over a buffer under a kernel's writes
(10,197 and 28,162 bytes in 100 rounds of 3662x64 and 61x64 BGRA8, 304 and 307 in the last row;
m3-max-7240, m3-max-7269), keeping them over IOSurfaces and under clears, stores and draws; an M3
Max under 27.0.1 (arm64 and x86_64, m3-max-7241) and a Radeon Pro 5300M (static check, 7269) kept
every byte. The owner's ruling: follow the x86 Macs' envelope and remove the shadow copy where
possible. On the Iris Xe, whose writes write back the 64-byte line holding a row's last texels,
written textures over a buffer whose rows end inside a line now take the image in place.

Docs: in_place.rs and in_place_check.rs module docs, docs/API.md (the in-place paragraph, the
shadowed-texture notice, section 10 Kernels with the three probe results), FAST-PATHS row 41, the
runtime README. Lanes: in_place_textures' VERDICTS 24 and its written-texture checks ask the
buffer writes verdict where the padding is free (in_place_rows::padding_free/writes), the
padding bytes of a texture in place with free padding no longer held to the pattern.

Tests: tests::in_place's decision test over both paddings; Padding::of cases (the guest's
3662x2039 surface at a 14656-byte pitch is free, 416x51 at 64-byte lines kept, slices apart);
Bytes::compare telling a change of each row's padding (the last row's last byte included) apart
from one past the last row's pitch or of a texel, and from padding that is not free; Tally's
verdicts for the Iris's walk and the others.

Verified: pending.
(cherry picked from commit 200f2a9e2b26eeaff45c1cc5ec71decf42d8437e)
This commit is contained in:
Anees Iqbal committed 2026-11-07 23:57:05 -08:00
1 parent 573b3bf5b1
commit 3f8b07c044
17 files changed
+770 -197

No files matched your search

+25 -2
View File
@@ -354,7 +354,12 @@ that share none (their first byte, their end and, with bytes between rows, each
end on a line): a device that writes back a texel's line whole puts an older value back over a
CPU write in the first alone, as the Iris Xe's clear and store and draws do, so its render targets
and written textures whose rows end on a line, a 3840x2160 `BGRA8Unorm` surface's among them,
take the image in place where the others keep the shadow. It runs
take the image in place where the others keep the shadow. A kernel's writes of a texture over a
buffer's rows (no IOSurface plane's) whose rows, each to its pitch, start and end on a line, its
buffer holding the last row to its pitch, may change the rows' padding (section 10, **Kernels**):
the same rounds give a second verdict for such textures, which a round that changed only bytes of
its rows' padding passes, so the Iris Xe's written textures over a buffer take the image in place
whatever their rows' ends. It runs
on a thread of its own, which the first such texture starts; a texture made before its kind of
pages and access has its verdict is a shadow, made without waiting for the check
(`WorkCounts::host_texture_shadows_check_pending`), and moves in place, with no copy, at a quiet
@@ -1545,7 +1550,9 @@ bound.
(`HostPageTexturePolicy::Shadow`), a shader writes the texture's texels of 1 or 2 bytes, which
the device's check stores none of, the device's check that the operations of an access of the
texture (the first move; a render pass's load and store; a kernel's storage writes) keep every
byte over that kind of pages, for texels that share a line of the device's memory
byte (but, for a kernel's writes of a texture over a buffer's rows whose padding is free, that
padding: section 10, **Kernels**) over that kind of pages, for texels that share a line of the
device's memory
(`nonCoherentAtomSize`) with bytes beside them or not as the texture's do, has not answered yet,
found a byte changed or made no image, or no
image in place serves the texels (its rows share bytes, the device lays no linear image's rows at
@@ -4567,6 +4574,22 @@ each item named states the rule in full.
**Kernels**
- **A kernel's writes of a texture over a buffer may change its rows' padding** (each row's bytes
after its last texel to its pitch, the last row's included), where the texture is an image in
place over host pages whose rows, each to its pitch, start and end on a line of the device's
memory (`nonCoherentAtomSize`), its buffer holding the last row to its pitch, and the device's
check found its kernel's storage writes changing no byte but of such padding (the check
report's `buffer writes` verdicts). Metal leaves those bytes to the GPU, and the rule follows
the x86 Macs' envelope. Measured over 100 rounds of each operation, the CPU writing the padding
while the GPU ran, `BGRA8Unorm` textures of 3662x64 and 61x64 over a buffer (14848 and 256-byte
pitches) and over an IOSurface (14656 and 256): an Intel UHD Graphics 630 (macOS 26.7.1) wrote
older values back over the CPU's writes to the padding of the textures over a buffer under a
kernel's writes (10,197 and 28,162 bytes, 304 and 307 of them in the last row), and over the
IOSurfaces and under a pass's clear and store or a draw kept every byte; an M3 Max (macOS
27.0.1, arm64 and x86_64) kept every byte under each; a Radeon Pro 5300M (macOS 26.7.1), its
rows read once each operation completed, with no CPU write meanwhile, kept every byte under
each. A render target's rows, an IOSurface plane's, and the bytes past the last row's pitch or
between slices keep every byte (`crates/metal2vulkan-conformance/probes/row_padding_writes.m`).
- **An imageblock's length rounds its cell as an M4 does**
(`ComputePipelineState::imageblock_memory_length_for_dimensions`), never less than what a
dispatch counts against the device's threadgroup memory.