From 2e5a2b0d209bf6454fc64a7d55201931726bb29e Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 7 Nov 2026 15:47:55 -0800 Subject: [PATCH] Say why short_row_kinds.m's multisampled copies died: its forked children, not Metal short_row_kinds.m ran each case in a child that forked and did not exec, and every copy between a buffer and a multisampled texture there ended in SIGABRT inside Metal's blit. API.md read that as Metal's answer and so as a reason the multisampled short-pitch copy is unmeasured, which contradicted sample_interleave.rs's measured placement of such copies on the same GPU. multisample_buffer_copies.m (M3 Max, macOS 27.0.1, job m3-max-5571) separates the candidates. Forked without an exec, each case aborted: Metal's blit makes its program through its compiler (findOrCreateDriverProgramVariant -> MTLCompiler compileBuiltinRequestInternal -> _os_crash_msg). Spawned, every case returned with its bytes as written: RGBA8Unorm x4 and R8Unorm x2, at RenderTarget|ShaderRead, with PixelFormatView, ShaderRead alone and with PixelFormatView, Private and Shared, with and without options:, with and without a clearing pass, and without allowGPUOptimizedContents. The nine layouts multisample_buffer_layouts holds the runtime to lay exactly where it expects, at both render-target usages. So the runtime's multisampled copies stand on a measurement that holds, and the multisampled short-pitch copy stays refused only because it is not measured. The probe records that answer; short_row_kinds.m, API.md, sample_interleave.rs and the layouts test say it. No behaviour changes. (cherry picked from commit 3660f4ec2f16c6ae8e0443b9989756116c1ffc0e) --- .../probes/multisample_buffer_copies.m | 15 +++++++++++++++ .../probes/short_row_kinds.m | 7 +++++-- .../metal2vulkan-runtime/src/sample_interleave.rs | 5 ++++- .../src/tests/multisample_buffer_layouts.rs | 6 ++++-- docs/API.md | 8 ++++++-- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/crates/metal2vulkan-conformance/probes/multisample_buffer_copies.m b/crates/metal2vulkan-conformance/probes/multisample_buffer_copies.m index 481fd7f6d..2f6311bd1 100644 --- a/crates/metal2vulkan-conformance/probes/multisample_buffer_copies.m +++ b/crates/metal2vulkan-conformance/probes/multisample_buffer_copies.m @@ -36,6 +36,21 @@ // Run without MTL_DEBUG_LAYER (its validation stops the layouts off the pixel): // // ./multisample_buffer_copies +// +// **What it answered** (an Apple M3 Max under macOS 27.0.1, 26A434; one run): +// +// * How the process started is what decides. Each `fork` case ended its process (`DIED 6`, +// `SIGABRT`), at the copy in or the copy out: Metal's blit made its program +// (`findOrCreateDriverProgramVariant` of a `BlitFragmentProgram` or a `BlitComputeProgram`) +// through its compiler (`-[MTLCompiler compileBuiltinRequestInternal:...]`), which aborts +// (`_os_crash_msg`) in a child that forked and has not exec'd. Every spawned case returned +// and gave its bytes back as written: both kinds, at all four usages, `Private` and `Shared` +// (Metal made a `Shared` multisample texture), with and without `options:`, with and without +// a clearing pass, `plain` too. Usage, storage mode and the call change nothing here. +// * `place`: every layout's rows lay where `multisample_buffer_layouts` expects them, at both +// usages: into the texture `(5, 20)` at 4 20 36 52, `(28, 143)` at 28 156 284 412, `(4, 64)` +// at 4 68 132 196, `(7, 32)` at 6 38 70 102, `(4, 4)` at 4 4 4 4; out of it `(7, 64)` at 4 68 +// 132 196, `(22, 32)` at 22 54 86 118, `(21, 64)` at 20 84 148 212, `(0, 54)` at 0 48 96 144. #import #import diff --git a/crates/metal2vulkan-conformance/probes/short_row_kinds.m b/crates/metal2vulkan-conformance/probes/short_row_kinds.m index 907239c6f..99df86c99 100644 --- a/crates/metal2vulkan-conformance/probes/short_row_kinds.m +++ b/crates/metal2vulkan-conformance/probes/short_row_kinds.m @@ -45,8 +45,11 @@ // * Every multisampled case ended its process (`DIED 6`, `SIGABRT` in Metal's blit, as it // made the blit's program) before the copy at the short pitch: the `RGBA8Unorm` and // `R32Uint` ones at the copy out at the packed row, after the copy in at it returned, the -// `R8Unorm` one at the copy in at the packed row. Where Metal places such a texture's rows -// at a short pitch is not answered. +// `R8Unorm` one at the copy in at the packed row. That is this probe's harness, not Metal's +// answer to the copy: a case runs in a child that forked and has not exec'd, where Metal's +// compiler, which makes a multisampled blit's program, aborts; spawned, the same copies +// return (`multisample_buffer_copies.m`). Where Metal places such a texture's rows at a +// short pitch is not answered. // * Every other kind returned at every pitch, both ways. `in`: every row read whole from // `y x bytesPerRow` (`whole 8 of 8`), none on the aligned path, at pitches that are // multiples of 16 too. `out`: each row's bytes at `y x bytesPerRow`, nothing past the rows' diff --git a/crates/metal2vulkan-runtime/src/sample_interleave.rs b/crates/metal2vulkan-runtime/src/sample_interleave.rs index 3fe90cb5e..e499b169c 100644 --- a/crates/metal2vulkan-runtime/src/sample_interleave.rs +++ b/crates/metal2vulkan-runtime/src/sample_interleave.rs @@ -801,7 +801,10 @@ pub(super) enum Unplaced { /// consecutive) are `pixel` bytes, `row_bytes` a row (`into_texture` from the buffer): each row's /// offset from the buffer's byte 0, in order. Measured on an Apple M3 Max under macOS 27.0.1 (its /// API validation stops every offset off the pixel), for 1-, 2-, 4-, 8- and 16-byte colour, depth -/// and stencil samples at 2 and 4 samples, both ways, 1 to 8 texels wide: +/// and stencil samples at 2 and 4 samples, both ways, 1 to 8 texels wide, and nine of those +/// layouts measured again at render-target usage with and without `PixelFormatView` +/// (`metal2vulkan-conformance/probes/multisample_buffer_copies.m`, each copy in a spawned process: +/// in a child that forked and has not exec'd, Metal's blit aborts making its program): /// /// - the first row lies at the offset rounded down to 4 bytes, or to the pixel where that is /// smaller, and to 2 bytes for a 32-byte pixel; diff --git a/crates/metal2vulkan-runtime/src/tests/multisample_buffer_layouts.rs b/crates/metal2vulkan-runtime/src/tests/multisample_buffer_layouts.rs index 2beb2c2f3..00e592e57 100644 --- a/crates/metal2vulkan-runtime/src/tests/multisample_buffer_layouts.rs +++ b/crates/metal2vulkan-runtime/src/tests/multisample_buffer_layouts.rs @@ -2,8 +2,10 @@ //! bytes) copy the bytes plain Metal copies: each row where Metal places it //! (`sample_interleave::placed_rows`), through a staging buffer where a row's offset in the //! buffer's `VkBuffer` is off a sample, announced as `staged-texture-copy`. Every case's rows are -//! what the probe measured on an Apple M3 Max under macOS 27.0.1, for its format, sample count, -//! width, offset and `bytesPerRow`, four rows tall. +//! what plain Metal placed on an Apple M3 Max under macOS 27.0.1, for its format, sample count, +//! width, offset and `bytesPerRow`, four rows tall, measured again by +//! `metal2vulkan-conformance/probes/multisample_buffer_copies.m` at the texture's usage here +//! (render target and shader read) and with `PixelFormatView`. //! //! Into the texture, the copy back out at the pixel's own layout gives each placed row's bytes //! (rows that overlap included); out of it, the buffer holds the texture's rows at the placed diff --git a/docs/API.md b/docs/API.md index af8f6669b..637c54472 100644 --- a/docs/API.md +++ b/docs/API.md @@ -4224,8 +4224,12 @@ each item named states the rule in full. out of it in no one order, the even rows' bytes standing or neither order's, varying from run to run (`probes/short_row_kinds.m`, three runs); the runtime's answer is the later row's there too. A multisampled texture's copy out at such a pitch stays refused (`Copy(BytesPerRow)`): where - Metal places its rows there is not measured, as that probe's every copy between a buffer and a - multisampled texture, at the packed row too, ended its process in Metal's blit (`SIGABRT`). + Metal places its rows there is not measured. That probe's every copy between a buffer and a + multisampled texture, at the packed row too, ended its process in Metal's blit (`SIGABRT`) + because each case ran in a child that forked and had not exec'd, where Metal's compiler, which + makes a multisampled blit's program, aborts. Spawned, the same copies return at every usage, + storage mode and call tried, and nine of the multisampled layouts the runtime copies lie where + it places them (`probes/multisample_buffer_copies.m`). **Render passes**