From 19d642612dacc66a09d2fa197ba36dc0e6e7f36b Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 2 Dec 2026 19:31:48 -0800 Subject: [PATCH] Tests: copies between a heap texture and memory it aliases are Metal's own refusal, but a whole level between two heap textures Row L212. These copies were all Gap::OverlappingCopy: a copy between a texture placed in a heap and a resource whose memory meets it. On an Apple M3 Max, macOS 27.0.1, the conformance probe overlapping_alias_copies.m (jobs m3-max-81486 and m3-max-81493) shows that Metal's API validation stops most of these shapes with "blitting between aliasing resources is defined on a placement heap only when using a blit method copying entire texture surfaces, or when copying between buffers": - a buffer and a texture over its bytes, either way; - the region method between two heap textures that alias. It stops a heap texture and a linear texture over a heap buffer at its bytes with "... only when both textures are linear and have the same bufferBytesPerRow value". It passes copyFromTexture:toTexture: between two heap textures that alias. The consumer copies that as whole levels through copy_from_texture. The new Refusal::AliasingCopy (Basis: metal-measured) names the shapes Metal stops. docs/REFUSALS.md, error/basis.rs and api_signatures.tsv are regenerated. A whole level into a whole level between two heap textures stays Gap::OverlappingCopy, per the planner's ruling. Nothing produces the new variant yet. Tests: - textures_whose_memory_meets_where_one_is_laid_out_by_the_device_are_refused_or_copy_in_no_order (unit, renamed) expects the two heap textures' whole-level copy still to copy in no order. It expects part of a level, either way and at an offset, and a texture in place over the heap texture's bytes, either way, to be Refusal::AliasingCopy. - a_buffer_copy_over_its_texture_s_own_bytes_copies_in_slabs_or_in_no_order (unit) expects a region meeting a heap texture's memory, into it and out of it, to be Refusal::AliasingCopy. - every_device_refuses_a_copy_between_heap_resources_whose_memory_meets (device) expects the whole level onto its alias to be the counted gap, and part of a level onto its alias and the heap buffer either way to be Refusal::AliasingCopy. Nothing is recorded, and one refusal is counted. Verified: refusal_surface.py --check exits 0, and signatures.py --bless adds the one variant row. Red as expected, under the validation layer, on lavapipe (llvmpipe, LLVM 23.1.4; job m3-max-81597), the AMD Radeon 780M (RADV PHOENIX; m3-max-81592), the NVIDIA GeForce RTX 2080 (m3-max-81600) and the AMD Radeon RX 7900 XTX (RADV NAVI31; m3-max-81671): the three tests fail. The device test says "part of a level onto its alias: Err(Unsupported(OverlappingCopy { pixel_format: RGBA8Unorm }))", the unit tests "not a refusal: it was checked". The runs built the series before its rebase onto development; the patches are the same. --- crates/metal2vulkan-runtime/src/error.rs | 30 +++++ .../metal2vulkan-runtime/src/error/basis.rs | 1 + crates/metal2vulkan-runtime/src/tests/blit.rs | 118 +++++++++++++----- crates/metal2vulkan/tests/api_signatures.tsv | 1 + docs/REFUSALS.md | 5 +- 5 files changed, 124 insertions(+), 31 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 1b85dc417..d4cd7bac2 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -821,6 +821,32 @@ pub enum Refusal { /// The destination texture's pixel format. destination: PixelFormat, }, + /// A blit copy between a texture placed in a heap + /// ([`Device::new_heap_texture`](crate::Device::new_heap_texture)) and a resource whose + /// memory meets the texture's, which the two then alias, other than a copy of a whole level + /// into a whole level between two textures placed in a heap: a region of a buffer + /// ([`BlitCommandEncoder::copy_from_buffer`](crate::BlitCommandEncoder::copy_from_buffer), + /// [`BlitCommandEncoder::copy_from_texture_to_buffer`](crate::BlitCommandEncoder::copy_from_texture_to_buffer) + /// and their options forms), a texture in place over a buffer + /// ([`Buffer::new_texture`](crate::Buffer::new_texture)), or part of a level of another + /// texture placed in a heap + /// ([`BlitCommandEncoder::copy_from_texture`](crate::BlitCommandEncoder::copy_from_texture)). + /// The whole-level copy is [`Gap::OverlappingCopy`]. + /// + /// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1, probe `overlapping_alias_copies.m` + /// in the conformance crate, jobs m3-max-81486 and m3-max-81493: Metal's validation layer + /// stops a copy between a buffer and a texture over its bytes in a placement heap, either way, + /// and the region method between two textures over each other's bytes, over part of a level + /// or all of it, with "blitting between aliasing resources is defined on a placement heap + /// only when using a blit method copying entire texture surfaces, or when copying between + /// buffers", and `copyFromTexture:toTexture:` between a heap texture and a linear texture + /// over a heap buffer at its bytes with "blitting between aliasing resources is defined on a + /// placement heap only when both textures are linear and have the same bufferBytesPerRow + /// value"; with the layer off, each gives the source's bytes from before the copy). + AliasingCopy { + /// The texture's pixel format. + pixel_format: PixelFormat, + }, /// A Managed texture's bytes the device cannot copy in place /// ([`Device::new_managed_texture`](crate::Device::new_managed_texture)): a place for each /// level and slice, in order, not given; a buffer the host does not reach; a place whose rows @@ -2992,6 +3018,10 @@ impl fmt::Display for Refusal { f, "a copy from {source:?} to {destination:?} is between two formats or two sample counts, which Metal refuses" ), + Refusal::AliasingCopy { pixel_format } => write!( + f, + "a copy between a heap texture of {pixel_format:?} and a resource over its memory is not a whole level into a whole level of two heap textures, which Metal refuses" + ), Refusal::ManagedTextureBytes { level, slice } => write!( f, "a Managed texture's bytes of level {level}, slice {slice} are not where a copy reads them in place" diff --git a/crates/metal2vulkan-runtime/src/error/basis.rs b/crates/metal2vulkan-runtime/src/error/basis.rs index 23bd321f4..994640713 100644 --- a/crates/metal2vulkan-runtime/src/error/basis.rs +++ b/crates/metal2vulkan-runtime/src/error/basis.rs @@ -68,6 +68,7 @@ impl Refusal { Refusal::TextureViewFormat { .. } => RefusalBasis::MetalMeasured, Refusal::MipmapFormat { .. } => RefusalBasis::MetalMeasured, Refusal::TextureCopyMismatch { .. } => RefusalBasis::MetalMeasured, + Refusal::AliasingCopy { .. } => RefusalBasis::MetalMeasured, Refusal::ManagedTextureBytes { .. } => RefusalBasis::Ours, Refusal::BufferTextureLayout { .. } => RefusalBasis::Ours, Refusal::TextureNotInPlace { .. } => RefusalBasis::Ours, diff --git a/crates/metal2vulkan-runtime/src/tests/blit.rs b/crates/metal2vulkan-runtime/src/tests/blit.rs index 3215b9a73..6aa850482 100644 --- a/crates/metal2vulkan-runtime/src/tests/blit.rs +++ b/crates/metal2vulkan-runtime/src/tests/blit.rs @@ -10,9 +10,12 @@ //! axis of fewest, each no thicker than the shift there, the far end of the shift first; so do //! regions of two textures in place over one buffer whose bytes meet, each shift that from a //! destination row to a source row on its bytes, and where no axis cuts them so they are -//! `Gap::OverlappingCopy`, while rows that interleave or other bytes copy whole; so are two -//! textures whose memory meets where one is placed in a heap, though not two slices of one; a -//! level, slice or region outside a texture or off its block grid is `Refusal::TextureRegion`; +//! `Gap::OverlappingCopy`, while rows that interleave or other bytes copy whole; so is a whole +//! level into a whole level of two textures placed in a heap whose memory meets, which Metal's +//! validation takes, while any other copy between two textures whose memory meets where one is +//! placed in a heap is `Refusal::AliasingCopy`, as Metal's validation stops it, though not one +//! between two slices of one; a level, slice or region outside a texture or off its block grid +//! is `Refusal::TextureRegion`; //! a size of 0 on an axis a texture lacks copies one texel there, and on another copies //! nothing; a 3D texture's image copies to and from a 2D slice. //! - Under a device cfg, on every device of the cfg's kind: the bytes of a level of a 2D texture @@ -35,12 +38,14 @@ //! count of texels apart; what Metal's validation stops is `Refusal::BufferCopyLayout`, and an //! offset or row stride a copy command cannot address `Gap::BufferCopyAlignment`. A region whose //! bytes meet those of a texture in place over the buffer copies in slabs as two textures over -//! one buffer do, either way, its own texels copying nothing, and where no axis cuts them so, -//! or where a texture placed in a heap holds bytes of the region, is `Gap::OverlappingCopy`. +//! one buffer do, either way, its own texels copying nothing, and where no axis cuts them so +//! is `Gap::OverlappingCopy`; one where a texture placed in a heap holds bytes of the region +//! is `Refusal::AliasingCopy`, as Metal's validation stops it. //! Under a device cfg: such regions a row on and back and within the rows, into the texture //! and out of it, leave the source's bytes from before the copy at one barrier more a slab -//! after the first, and the refused shape records nothing and is counted; so are copies between -//! heap textures, and a heap buffer and a texture, whose memory meets, while ones apart run. +//! after the first, and the refused shape records nothing and is counted; copies between heap +//! textures, and a heap buffer and a texture, whose memory meets record nothing, the whole +//! level's gap counted, while ones apart run. //! Bytes from a buffer land in a mipmap level, a slice of a 1D array and BC1 blocks, and a //! slice's and a 3D region's bytes land in buffers at padded strides, everything around each //! region kept and each result plain Metal's (job m3-max-43555); one copy into a Shared buffer @@ -480,7 +485,8 @@ fn in_heap(d: &TextureDescriptor, base: u64, len: u64) -> Side<'_> { } #[test] -fn textures_whose_memory_meets_where_one_is_laid_out_by_the_device_copy_in_no_order() { +fn textures_whose_memory_meets_where_one_is_laid_out_by_the_device_are_refused_or_copy_in_no_order() +{ let d = descriptor(TextureType::Type2D, PixelFormat::RGBA8Unorm, [16, 4, 1]); let slabs = |from: &Side<'_>, to: &Side<'_>| { let size = [16, 4, 1]; @@ -493,10 +499,36 @@ fn textures_whose_memory_meets_where_one_is_laid_out_by_the_device_copy_in_no_or reversed: false, }); let (a, b) = (in_heap(&d, 0, 4096), in_heap(&d, 2048, 4096)); - // Two heap textures whose ranges meet, either way, and a texture in place whose image's - // memory lies in a heap texture's: no order, which the encoder refuses. + // Two heap textures whose ranges meet, a whole level into a whole level, either way: Metal's + // `copyFromTexture:toTexture:`, which its validation takes, the source's bytes from before + // the copy on an Apple M3 Max (probe `overlapping_alias_copies.m`, job m3-max-81493). No + // order, which the encoder refuses as a gap. assert_eq!(slabs(&a, &b), None); assert_eq!(slabs(&b, &a), None); + // Part of a level of either, or into a place past its origin: Metal's validation stops the + // region method between aliases. + let aliasing = Refusal::AliasingCopy { + pixel_format: PixelFormat::RGBA8Unorm, + }; + let origin = at(0, 0, [0; 3]); + assert_eq!( + refused(texture_copy(&a, origin, [8, 4, 1], &b, origin, false)), + aliasing + ); + assert_eq!( + refused(texture_copy( + &b, + origin, + [8, 4, 1], + &a, + at(0, 0, [8, 0, 0]), + false + )), + aliasing + ); + // A texture in place whose image's memory lies in a heap texture's, either way, a whole level + // too: Metal's validation stops a copy between aliases both linear and of one row stride + // alone. let laid = Side { bound: Some(Span { buffer: vk::Buffer::from_raw(1), @@ -505,7 +537,15 @@ fn textures_whose_memory_meets_where_one_is_laid_out_by_the_device_copy_in_no_or }), ..over(&d, 1, 3072, 64) }; - assert_eq!(slabs(&laid, &b), None); + let full = [16, 4, 1]; + assert_eq!( + refused(texture_copy(&laid, origin, full, &b, origin, false)), + aliasing + ); + assert_eq!( + refused(texture_copy(&b, origin, full, &laid, origin, false)), + aliasing + ); // Ranges that touch, ranges in another buffer, and a texture whose memory no other resource // shares: one slab. assert_eq!(slabs(&a, &in_heap(&d, 4096, 4096)), whole); @@ -1016,15 +1056,20 @@ fn a_buffer_copy_over_its_texture_s_own_bytes_copies_in_slabs_or_in_no_order() { copy(whole, lies(0, 1024, 0, 64, 0), true), Ok(None) )); - // A texture placed in a heap: a region whose bytes meet its memory copies in no order, one - // whose bytes do not in one slab. + // A texture placed in a heap: a region whose bytes meet its memory, into the texture or out + // of it, is refused as Metal's validation stops it between aliases (probe + // `overlapping_alias_copies.m`, job m3-max-81486); one whose bytes do not copies in one slab. let heap = in_heap(&d, 512, 256); - let placed = |offset| { + let placed = |offset, into_image| { let layout = lies(0, 1024, offset, 64, 0); - buffer_copied(buffer_copy(&heap, at(0, 0, [0; 3]), whole, layout, true)).slabs + buffer_copy(&heap, at(0, 0, [0; 3]), whole, layout, into_image) }; - assert_eq!(placed(400), None); - assert_eq!(placed(256), cut(0, 16, false)); + let aliasing = Refusal::AliasingCopy { + pixel_format: PixelFormat::RGBA8Unorm, + }; + assert_eq!(refused(placed(400, true)), aliasing); + assert_eq!(refused(placed(400, false)), aliasing); + assert_eq!(buffer_copied(placed(256, true)).slabs, cut(0, 16, false)); } #[test] @@ -2569,12 +2614,15 @@ pub(crate) mod on_device { }); } - /// Textures placed in one heap, on every device: a copy between two whose ranges meet, and - /// between a heap buffer and a texture whose ranges meet, either way, is - /// `Gap::OverlappingCopy`, counted, and records nothing, the device laying the texels out as - /// it chooses. Copies between a texture and another, and a heap buffer, whose ranges do not - /// meet run: bytes from a Shared buffer through both textures and the heap buffer come back - /// as they went in, at one submission. + /// Textures placed in one heap, on every device: a copy of a whole level into a whole level + /// between two whose ranges meet is `Gap::OverlappingCopy`, counted, and records nothing, the + /// device laying the texels out as it chooses. A copy of part of a level between them, and + /// one between a heap buffer and a texture whose ranges meet, either way, is + /// `Refusal::AliasingCopy`, as Metal's validation stops each (probe + /// `overlapping_alias_copies.m`, jobs m3-max-81486 and m3-max-81493), and records nothing. + /// Copies between a texture and another, and a heap buffer, whose ranges do not meet run: + /// bytes from a Shared buffer through both textures and the heap buffer come back as they + /// went in, at one submission. #[test] fn every_device_refuses_a_copy_between_heap_resources_whose_memory_meets() { const SIDE: u32 = 16; @@ -2629,15 +2677,25 @@ pub(crate) mod on_device { bytes_per_image: 0, }; - // Ranges that meet: each copy refused, counted, and nothing recorded. + // Ranges that meet: each copy refused and nothing recorded; the whole level, a gap, + // counted. settled(&device); let metrics = counters.metrics(); let command_buffer = queue.command_buffer().expect("a command buffer"); let mut encoder = command_buffer.blit_command_encoder().expect("an encoder"); + let whole_level = encoder.copy_from_texture(&first, at, size, &alias, at); + assert!( + matches!( + whole_level, + Err(Error::Unsupported(Gap::OverlappingCopy { .. })) + ), + "{name}: a whole level onto its alias: {whole_level:?}" + ); + let half = [SIDE / 2, SIDE, 1]; let refusals = [ ( - "texture onto its alias", - encoder.copy_from_texture(&first, at, size, &alias, at), + "part of a level onto its alias", + encoder.copy_from_texture(&first, at, half, &alias, at), ), ( "texture into a buffer over its bytes", @@ -2652,7 +2710,9 @@ pub(crate) mod on_device { assert!( matches!( refused, - Err(Error::Unsupported(Gap::OverlappingCopy { .. })) + Err(Error::Refused(Refusal::AliasingCopy { + pixel_format: PixelFormat::RGBA8Unorm + })) ), "{name}: {case}: {refused:?}" ); @@ -2666,8 +2726,8 @@ pub(crate) mod on_device { after_refusals.barriers - metrics.barriers, after_refusals.overlapping_copies_refused - metrics.overlapping_copies_refused, ), - (0, 0, 3), - "{name}: the refused copies record nothing and are counted" + (0, 0, 1), + "{name}: the refused copies record nothing, and the gap is counted" ); // Ranges apart: bytes through both textures and the heap buffer, as they went in. diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index bb1b437cd..b000b4307 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -8655,6 +8655,7 @@ variant metal2vulkan-runtime::RangeKind::Preprocess Preprocess variant metal2vulkan-runtime::RangeKind::RingBlock RingBlock variant metal2vulkan-runtime::RangeKind::Sparse Sparse variant metal2vulkan-runtime::RangeKind::Surface Surface +variant metal2vulkan-runtime::Refusal::AliasingCopy AliasingCopy { pixel_format: PixelFormat } variant metal2vulkan-runtime::Refusal::ArgumentPlace ArgumentPlace { place: u64, alignment: u64 } variant metal2vulkan-runtime::Refusal::AttachmentFormat AttachmentFormat { pixel_format: PixelFormat } variant metal2vulkan-runtime::Refusal::AttachmentPlace AttachmentPlace { level: u32, slice: u32 } diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index e5e312525..95016ae3e 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -31,7 +31,7 @@ Columns: | Rate maps the compile layer does not compile | 5 | 5 | 0 | 0 | 4 | 1 | 0 | | The translation deadline | 1 | 1 | 0 | 0 | 0 | 1 | 0 | | Devices below the runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 | -| The runtime's `Refusal` | 94 | 94 | 0 | 0 | 0 | 0 | 0 | +| The runtime's `Refusal` | 95 | 94 | 0 | 0 | 0 | 0 | 0 | | The runtime's `Limit` | 21 | 21 | 0 | 0 | 0 | 0 | 0 | | The runtime's `Gap` | 31 | 31 | 0 | 0 | 0 | 0 | 0 | @@ -44,7 +44,7 @@ Columns: | Rate maps the compile layer does not compile | 0 | 0 | 0 | 0 | 5 | 0 | 0 | 0 | | The translation deadline | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | | Devices below the runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 | -| The runtime's `Refusal` | 29 | 26 | 0 | 0 | 39 | 0 | 0 | 0 | +| The runtime's `Refusal` | 30 | 26 | 0 | 0 | 39 | 0 | 0 | 0 | | The runtime's `Limit` | 0 | 0 | 0 | 15 | 6 | 0 | 0 | 0 | | The runtime's `Gap` | 0 | 0 | 0 | 2 | 29 | 0 | 0 | 0 | @@ -287,6 +287,7 @@ Columns: | `TextureViewFormat` | `Texture::new_texture_view` of a pixel format Metal does not view the texture as | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, probe `texture_view_rules.m` in the conformance crate, jobs m3-max-43677 and m3-max-59523: Metal's validation layer stops a view of another format of a texture of `ShaderRead` usage, `R32Uint`, `RGBA8Uint`, `BGRA8Unorm` and `BGRA8Unorm_sRGB` of `RGBA8Unorm`, `A8Unorm`, `R8Snorm` and `R8Uint` of `R8Unorm`, `R16Unorm` of `RG8Unorm`, "texture usage (0x01) doesn't specify MTLTextureUsagePixelFormatView (0x10)", and makes it where the usage adds `PixelFormatView`; plain Metal makes each, a blit out of it reading the texture's bytes; Apple's `makeTextureView` and `MTLTextureUsage.pixelFormatView` pages state the rest | 2: `crates/metal2vulkan-runtime/src/d3d11.rs (d3d11_plane_form)`, `crates/metal2vulkan-runtime/src/texture.rs (view)` | `-` | | `MipmapFormat` | `BlitCommandEncoder::generate_mipmaps` of a texture of more than one level whose pixel format is not a colour-renderable, filterable one | every device (a public call's own check of its arguments) | `metal-measured`: Apple's `generateMipmaps(for:)` page: mipmap generation works only for textures with colour-renderable and colour-filterable pixel formats; Metal's API validation stops the others, measured on an Apple M3 Max and an M4 | 1: `crates/metal2vulkan-runtime/src/blit.rs (generate_mipmaps)` | `-` | | `TextureCopyMismatch` | `BlitCommandEncoder::copy_from_texture` between textures of two pixel formats, or of two sample counts | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, probe `blit_copy_format_pairs.m` in the conformance crate: Metal's validation layer stops every pair of two formats it was given, sRGB, integer, float, channel order, depth and compressed pairs among them, with `[sourceTexture pixelFormat](...) must equal [destinationTexture pixelFormat](...)`, and a source of four samples into one of one with `[sourceTexture sampleCount](4) must equal [destinationTexture sampleCount](1)` | 2: `crates/metal2vulkan-runtime/src/blit.rs (texel_texture_copy)`, `crates/metal2vulkan-runtime/src/blit.rs (texture_copy)` | `-` | +| `AliasingCopy` | A blit copy between a texture placed in a heap (`Device::new_heap_texture`) and a resource whose memory meets the texture's, which the two then... | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1, probe `overlapping_alias_copies.m` in the conformance crate, jobs m3-max-81486 and m3-max-81493: Metal's validation layer stops a copy between a buffer and a texture over its bytes in a placement heap, either way, and the region method between two textures over each other's bytes, over part of a level or all of it, with "blitting between aliasing resources is defined on a placement heap only when using a blit method copying entire texture surfaces, or when copying between buffers", and `copyFromTexture:toTexture:` between a heap texture and a linear texture over a heap buffer at its bytes with "blitting between aliasing resources is defined on a placement heap only when both textures are linear and have the same bufferBytesPerRow value"; with the layer off, each gives the source's bytes from before the copy | 0 | `-` | | `ManagedTextureBytes` | A Managed texture's bytes the device cannot copy in place (`Device::new_managed_texture`) | every device (a public call's own check of its arguments) | `ours`: a buffer-to-image copy reads a place only so laid out, and the consumer's bytes are the place the copy reads | 5: `crates/metal2vulkan-runtime/src/texture.rs (check_places)`, `crates/metal2vulkan-runtime/src/texture.rs (named)` (+2) | `-` | | `BufferTextureLayout` | A texture over a buffer (`Buffer::new_texture`) whose rows are not a whole number of texels apart or are closer than a row, whose offset is not a... | every device (a public call's own check of its arguments) | `ours`: a linear image and a copy read rows whole texels apart from a texel's start, and texels past the buffer would lie in memory it does not hold | 2: `crates/metal2vulkan-runtime/src/texture.rs (check_over)`, `crates/metal2vulkan-runtime/src/texture.rs (texel_texture)` | `-` | | `TextureNotInPlace` | A texture over a buffer asked of `Buffer::new_texture_in_place` that `Buffer::new_texture` would make as the counted copy, an image of its own... | every device (a public call's own check of its arguments) | `ours`: the call makes a texture in place or none, so that the consumer keeps the bytes in a texture of its own where the device's linear image does not take them | 2: `crates/metal2vulkan-runtime/src/texture.rs (texture, 2 sites)` | `-` |