From b136c2531afb93fcb1ce7be15e9bc7796fd47e57 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 8 Nov 2026 00:55:30 -0800 Subject: [PATCH] Buffers: a declaration that the bytes between a texture's rows are unobserved A consumer's cache buffer of the runtime's own memory (the 780M guest's 3662x2038 desktop surface, more guest-page pieces than udmabuf takes) holds textures whose rows lie 14848 bytes apart, 14648 bytes of texels each. linear_plan::holding shadows every such texture, since an image at that pitch holds the bytes between rows and Vulkan lets its layout moves and a render pass's load and store write them; the consumer's download copies each row's texels alone, so it never reads those bytes, and the shadow's copies cost it about 1 G texels/s in a Finder drag. BufferDescriptor::padding_unobserved (with_padding_unobserved) is the maker's declaration that nothing reads the bytes between a texture's rows over the buffer (each row's bytes after its texels to its pitch, the last row's included) nor between its slices. A runtime extension with no Metal counterpart, only for the runtime's own memory: refused, Invalid (PaddingUnobservedNoCopy), with NoCopy contents. The buffer keeps it (Buffer::padding_unobserved). - The route (texture/route.rs) decides it for a buffer of the device's own memory: Route::Device { holds } carries linear_plan::holding's answer, which with the declaration holds rows and slices that lie apart (rows that share bytes stay refused). The making and the placement query share it: the query answers NotHostPages where an image may hold the texels, and the new TextureShadowReason::BytesBetweenRows where it may not (it answered NotHostPages for both before). - aliases takes the declaration: the image's subresources may then hold the padding (linear_plan::within_padding: each subresource ends at its slice's last row's pitch or before, slices at Metal's stride), never a byte past the last row's pitch, nor memory past the buffer's. A byte of the image's memory past every subresource is reached by no operation on it, the reading texels_alone already rests on, so no new check class is needed. - WorkCounts::unobserved_padding_aliases counts the aliasing images that hold such bytes. - A buffer the runtime lays in fresh pages (a long one where pointer imports cost submissions nothing) keeps the in-place check's route: the declaration lets nothing more there (documented). Docs: the field and builder, NotHostPages and BytesBetweenRows, HOWTO's paragraph on textures over the runtime's own memory, API.md's shadow reasons and placement answers, the runtime README; REFUSALS.md and api_signatures.tsv regenerated. Tests: linear_plan's unit tests of the declared holding and aliasing (padding to the last row's pitch held, past it or past the buffer refused, slices at Metal's stride alone, shared rows refused); the route's placement test of both Route::Device answers; a device test (tests/padding_unobserved.rs): a 101x48 BGRA8Unorm texture at 416, 448 and 512 bytes a row over an undeclared buffer answers Shadow(BytesBetweenRows) and is a shadow, over a declared one answers NotHostPages and is an aliasing image wherever the device lays one at the pitch (counted), at least one pitch aliasing, its texels read back by a blit; and the declaration refused over the caller's memory. The in-place lane's unobserved_padding_costs times a frame reading the consumer's surface shape over a declared and an undeclared buffer. Verified: pending (lavapipe and MoltenVK device tests, the 780M lane run next). (cherry picked from commit 430523ce0e4dbd8433eb2b514f837d44ce1c5a9a) --- crates/metal2vulkan-runtime/README.md | 10 +- crates/metal2vulkan-runtime/src/buffer.rs | 18 ++ .../src/buffer_descriptor.rs | 38 +++ crates/metal2vulkan-runtime/src/error.rs | 7 + .../metal2vulkan-runtime/src/linear_plan.rs | 50 +++- .../src/tests/linear_plan.rs | 137 +++++++++-- crates/metal2vulkan-runtime/src/tests/mod.rs | 2 + .../src/tests/padding_unobserved.rs | 224 ++++++++++++++++++ .../src/tests/texture_placement.rs | 9 +- .../src/tests/texture_placement_device.rs | 2 +- crates/metal2vulkan-runtime/src/texture.rs | 20 +- .../metal2vulkan-runtime/src/texture/route.rs | 19 +- .../src/texture_placement.rs | 19 +- .../metal2vulkan-runtime/src/work_counts.rs | 16 ++ .../src/runtime_lane/in_place_textures.rs | 138 +++++++++-- crates/metal2vulkan/tests/api_signatures.tsv | 5 + docs/API.md | 14 +- docs/HOWTO.md | 10 +- docs/REFUSALS.md | 6 +- 19 files changed, 671 insertions(+), 73 deletions(-) create mode 100644 crates/metal2vulkan-runtime/src/tests/padding_unobserved.rs diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 3dc4cedda..1f0083568 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -361,7 +361,8 @@ the record the pass is making. naming why) for every other texture there (under `HostPageTexturePolicy::Shadow`, one a shader writes of 1- or 2-byte texels, one made before the check answered or whose check did not pass), where the device's linear images cannot hold Metal's layout, and where the rows lie with - bytes between them. On a discrete GPU, a `Managed` texture + bytes between them (but over a buffer whose maker declared them unobserved, + `BufferDescriptor::padding_unobserved`, below). On a discrete GPU, a `Managed` texture over a no-copy buffer's bytes (not an IOSurface plane's) that only samples or reads, whose policy takes the image in place, over memory that carries a log of its writes (`HostMemory::with_dirty_pages`), tracked and laid out as one copy, is instead such a copy in @@ -501,6 +502,13 @@ Calls Metal does not have, for a consumer that emulates a Metal device: or a no-copy heap's buffer's: the caller's pages, imported by their pointer, as dma-bufs or in a guest RAM's chunk, or a copy of them (`copied-host-pages`), which Metal never makes; a rebind may change it ([HOWTO](../../docs/HOWTO.md#copied-host-buffers)). +- `BufferDescriptor::padding_unobserved` (`with_padding_unobserved`): the maker of a buffer of + the runtime's own memory declares that nothing reads the bytes between a texture's rows over it + (each row's after its texels to its pitch, the last row's included) or between its slices, so + such a texture is a linear image aliasing the buffer where the device lays one out at its + pitches, not a shadow, and those bytes may change whenever it is made or used; no other byte + does (`WorkCounts::unobserved_padding_aliases`). No Metal counterpart; refused + (`PaddingUnobservedNoCopy`) with `NoCopy` contents. - `Buffer::texture_placement` and `texture_placement_with_iosurface_plane` (with `TexturePlacement` and `TextureShadowReason`): where a texture `new_texture` or `new_texture_with_iosurface_plane` makes of the same arguments lies if made now: in place over diff --git a/crates/metal2vulkan-runtime/src/buffer.rs b/crates/metal2vulkan-runtime/src/buffer.rs index d1a7fdfc7..2b029bc60 100644 --- a/crates/metal2vulkan-runtime/src/buffer.rs +++ b/crates/metal2vulkan-runtime/src/buffer.rs @@ -98,6 +98,10 @@ struct BufferShared { /// bytes, so no shadow over them keeps a standing across command buffers /// (`shadow_standing.rs`). handed_out: Arc, + /// Its maker declared that nothing reads the bytes between a texture's rows and slices over + /// it (`BufferDescriptor::padding_unobserved`), set as it is made: an image over such a + /// texture's memory may hold them (`linear_plan::holding`). + padding_unobserved: AtomicBool, } /// Where a buffer's bytes are. @@ -2755,6 +2759,7 @@ impl Device { bytes: Bytes::Own(own), held_by: HeldBy::default(), handed_out: Arc::default(), + padding_unobserved: AtomicBool::new(false), })) } @@ -2975,6 +2980,7 @@ impl Heap { }), held_by: HeldBy::default(), handed_out: Arc::default(), + padding_unobserved: AtomicBool::new(false), })) } } @@ -3173,6 +3179,18 @@ impl Buffer { self.0.handed_out.store(true, Ordering::Release); } + /// Note, as it is made, that its maker declared the bytes between a texture's rows and slices + /// over it unobserved (`BufferDescriptor::padding_unobserved`). + pub(super) fn declare_padding_unobserved(&self) { + self.0.padding_unobserved.store(true, Ordering::Release); + } + + /// Whether its maker declared the bytes between a texture's rows and slices over it + /// unobserved (`BufferDescriptor::padding_unobserved`). + pub(super) fn padding_unobserved(&self) -> bool { + self.0.padding_unobserved.load(Ordering::Acquire) + } + /// [`Buffer::at`] for `reason`, which a no-copy buffer's import counts its read apart for /// (`HostImport::note_read_apart`). pub(super) fn at_for(&self, offset: u64, reason: ReadApart) -> (vk::Buffer, u64) { diff --git a/crates/metal2vulkan-runtime/src/buffer_descriptor.rs b/crates/metal2vulkan-runtime/src/buffer_descriptor.rs index fe18b6d2d..88d9bcbc0 100644 --- a/crates/metal2vulkan-runtime/src/buffer_descriptor.rs +++ b/crates/metal2vulkan-runtime/src/buffer_descriptor.rs @@ -123,6 +123,23 @@ pub struct BufferDescriptor<'a> { /// of the pool; `None` for a range of the space. A runtime extension: Metal places a buffer /// shorter than a page in a slot of a pool of its own, which its API does not name. pub pool_slot: Option<(&'a AddressPool, u64)>, + /// The maker declares that nothing reads the bytes between the rows of a texture over the + /// buffer, nor between its slices: each row's bytes after its last texel to its pitch, the + /// last row's included, and the bytes from a slice's last row's pitch to the next slice. A + /// texture over the buffer whose rows (or slices) lie apart is then a linear image aliasing + /// the buffer's memory where the device lays one out at its pitches, as one whose rows lie one + /// after another is, not a shadow: its image holds those bytes, and Vulkan lets the image's + /// layout moves and a render pass's load and store operations write them, so they may change + /// to any value whenever the texture is made or used. No other byte changes: one past the + /// image's subresources is reached by no operation on it, and a texel's bytes are the + /// texture's. Only for a buffer of the runtime's own memory (`Zero`, `Copy` or `CopyHost` + /// contents); refused (`Invalid`, `PaddingUnobservedNoCopy`) with `NoCopy` contents. A buffer + /// the runtime lays in fresh pages it imports (a long one on a device whose pointer imports + /// cost submissions nothing, `WorkCounts::fresh_page_buffers_made`) takes its textures in place + /// where the device's check of such pages passed, which keeps every byte, so there the + /// declaration lets nothing more. A runtime extension with no Metal counterpart, for a consumer + /// that owns every read of the buffer's bytes; `false` by default, as Metal keeps every byte. + pub padding_unobserved: bool, } impl<'a> BufferDescriptor<'a> { @@ -140,6 +157,7 @@ impl<'a> BufferDescriptor<'a> { range_token: None, range_of: None, pool_slot: None, + padding_unobserved: false, } } @@ -171,6 +189,15 @@ impl<'a> BufferDescriptor<'a> { ..self } } + + /// This descriptor declaring the bytes between a texture's rows and slices over the buffer + /// unobserved (`padding_unobserved`). + pub fn with_padding_unobserved(self) -> BufferDescriptor<'a> { + BufferDescriptor { + padding_unobserved: true, + ..self + } + } } impl Device { @@ -197,6 +224,10 @@ impl Device { /// `PlacementConflict::OffSlot` for an offset that is not a multiple of 256 or a placement /// other than `Any` or that address; `OutsidePool` for bytes past the pool's end; `Held` for /// bytes a live buffer in the pool holds; `Unshared` with `range_of`. + /// + /// With `padding_unobserved`, a texture over the buffer may hold the bytes between its rows + /// and slices in its image (the field's docs). Refused: `Invalid` (`PaddingUnobservedNoCopy`) + /// with `NoCopy` contents. pub fn new_buffer_with_descriptor( &self, descriptor: BufferDescriptor<'_>, @@ -221,7 +252,11 @@ impl Device { range_token, range_of, pool_slot, + padding_unobserved, } = descriptor; + if padding_unobserved && matches!(contents, BufferContents::NoCopy { .. }) { + return Err(invalid(CALL, Problem::PaddingUnobservedNoCopy)); + } let place = match (range_of, pool_slot) { (Some(other), slot) => { let in_pool = slot.is_some(); @@ -280,6 +315,9 @@ impl Device { if let Some(token) = range_token { buffer.keep_range_token(token)?; } + if padding_unobserved { + buffer.declare_padding_unobserved(); + } Ok(self.visible(buffer)) } diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 8368182d4..4b4511af8 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -690,6 +690,13 @@ pub enum Problem { /// /// Basis: ours (this crate's paired slices: Metal's calls take a count). LengthMismatch, + /// A buffer descriptor that declares the bytes between a texture's rows unobserved + /// (`BufferDescriptor::padding_unobserved`) with `NoCopy` contents: the declaration is for a + /// buffer of the runtime's own memory, whose every reader the caller owns, never the caller's + /// pages, which others may read. + /// + /// Basis: ours (a runtime extension: Metal has no such declaration). + PaddingUnobservedNoCopy, /// A texture buffer's fill given a pattern of more than 32752 bytes /// (`fillTexture:...:bytes:length:`): Metal's process ends in the call, in the blit's /// dispatch, whatever the region, of no texels or past the buffer too (an Apple M3 Max under diff --git a/crates/metal2vulkan-runtime/src/linear_plan.rs b/crates/metal2vulkan-runtime/src/linear_plan.rs index 2c948065c..c4c7da4ab 100644 --- a/crates/metal2vulkan-runtime/src/linear_plan.rs +++ b/crates/metal2vulkan-runtime/src/linear_plan.rs @@ -537,6 +537,11 @@ impl BufferLayout { } } + /// Whether its rows, or its slices, lie with bytes between them that are not texels. + pub(super) fn padded(&self) -> bool { + apart(self) != (false, false) + } + /// One past the texture's last texel byte in the buffer. pub(super) fn end(&self) -> u64 { self.offset @@ -1249,21 +1254,29 @@ pub(super) struct LinearImage { /// memory block), holds exactly Metal's texels in the `room` bytes from there to the end of the /// buffer's memory: the binding is a multiple of the image's alignment, its texels start at the /// binding, its row pitch is Metal's and so is its slice pitch where it has several slices, its -/// subresources hold no byte but the texture's texels ([`texels_alone`]), and its memory stays in -/// the buffer's. A driver may report a pitch other than the one asked of it (NVIDIA does for -/// explicit layouts it does not support), so the image's own report decides. +/// subresources hold no byte but the texture's texels ([`texels_alone`]), or, where the buffer +/// declares the bytes between rows and slices unobserved (`padding_unobserved`, +/// `BufferDescriptor::padding_unobserved`), none but its texels and those bytes +/// ([`within_padding`]), and its memory stays in the buffer's. A driver may report a pitch other +/// than the one asked of it (NVIDIA does for explicit layouts it does not support), so the image's +/// own report decides. pub(super) fn aliases( layout: &BufferLayout, memory_offset: u64, room: u64, image: &LinearImage, + padding_unobserved: bool, ) -> bool { + let held = match padding_unobserved { + true => within_padding(layout, image.subresource, image.array_pitch), + false => texels_alone(layout, image.subresource, image.array_pitch), + }; image.alignment != 0 && memory_offset.is_multiple_of(image.alignment) && image.offset == 0 && image.row_pitch == layout.row_pitch && (layout.slices == 1 || image.array_pitch == layout.slice_pitch) - && texels_alone(layout, image.subresource, image.array_pitch) + && held && image.size <= room } @@ -1298,8 +1311,14 @@ pub(super) fn aliases( /// `Keep`), undoing a CPU write made to them meanwhile, where Metal keeps every one; and lavapipe's /// shader writes read the bytes its 4-texel blocks reach past a row's texels and write them back, a /// signaling NaN's bits quieted. So such a texture is a shadow, whose copies address its texels -/// alone. -pub(super) fn holding(layout: &BufferLayout, usage: TextureUsage) -> Result<(), String> { +/// alone; but where `padding_unobserved` (the buffer, of the runtime's own memory, declares that +/// nothing reads those bytes: `BufferDescriptor::padding_unobserved`), an image over its rows and +/// slices may hold the bytes between them, which those operations may then change. +pub(super) fn holding( + layout: &BufferLayout, + usage: TextureUsage, + padding_unobserved: bool, +) -> Result<(), String> { // An IOSurface plane's rows that overlap: no image holds them, whatever its usage. let shared = layout.shared_bytes(); if shared != 0 { @@ -1310,6 +1329,9 @@ pub(super) fn holding(layout: &BufferLayout, usage: TextureUsage) -> Result<(), )); } let (rows, slices) = apart(layout); + if padding_unobserved { + return Ok(()); + } let apart = if rows { format!( "its rows lie {} bytes apart, {} bytes of texels each", @@ -1350,6 +1372,22 @@ pub(super) fn texels_alone(layout: &BufferLayout, size: u64, array_pitch: u64) - apart(layout) == (false, false) && last.saturating_add(size) <= texels } +/// Whether a linear image over `layout`'s texels, whose subresources take `size` bytes each from +/// the first texel of their slice, `array_pitch` apart, holds no byte but the texture's texels and +/// the bytes between its rows and its slices, those of a buffer that declares them unobserved +/// (`BufferDescriptor::padding_unobserved`): its rows share no byte, its slices lie its slice +/// pitch apart (where it has several), each at or past the end of the one before's last row to +/// its pitch, and each subresource ends at its slice's last row's pitch or before. Each row's +/// bytes after its texels to its pitch, the last row's included, are such bytes; a byte past the +/// last row's pitch is not, so a driver that lays rows out past the texture's (lavapipe rounds the +/// height up to 4) has the texture refused. A byte of the image's memory past every subresource +/// is no texel's and no padding's, and no operation on the image reaches it ([`texels_alone`]). +pub(super) fn within_padding(layout: &BufferLayout, size: u64, array_pitch: u64) -> bool { + let rows = layout.row_pitch.saturating_mul(layout.rows); + let slices = layout.slices == 1 || (array_pitch == layout.slice_pitch && array_pitch >= rows); + layout.shared_bytes() == 0 && slices && size <= rows +} + /// Whether `layout`'s rows, and its slices, lie with bytes between them that are not texels. fn apart(layout: &BufferLayout) -> (bool, bool) { let rows = layout.rows > 1 && layout.row_pitch != layout.row_bytes; diff --git a/crates/metal2vulkan-runtime/src/tests/linear_plan.rs b/crates/metal2vulkan-runtime/src/tests/linear_plan.rs index c83d0af23..0658b243f 100644 --- a/crates/metal2vulkan-runtime/src/tests/linear_plan.rs +++ b/crates/metal2vulkan-runtime/src/tests/linear_plan.rs @@ -797,7 +797,7 @@ fn a_linear_image_aliases_only_metals_layout() { row_pitch: 80, array_pitch: 320, }; - assert!(aliases(&single, 4096 + 256, 320, &image)); + assert!(aliases(&single, 4096 + 256, 320, &image, false)); // The binding off the image's alignment (RADV's 256 at a 16-byte offset). assert!(!aliases( &single, @@ -806,7 +806,8 @@ fn a_linear_image_aliases_only_metals_layout() { &LinearImage { alignment: 256, ..image - } + }, + false )); // The driver's own pitch where another was asked for (NVIDIA's explicit layouts). assert!(!aliases( @@ -816,7 +817,8 @@ fn a_linear_image_aliases_only_metals_layout() { &LinearImage { row_pitch: 128, ..image - } + }, + false )); // Texels not at the binding, or memory past the buffer's. assert!(!aliases( @@ -826,9 +828,10 @@ fn a_linear_image_aliases_only_metals_layout() { &LinearImage { offset: 64, ..image - } + }, + false )); - assert!(!aliases(&single, 4096, 319, &image)); + assert!(!aliases(&single, 4096, 319, &image, false)); // Memory past the subresource, within the buffer's: no write through the image reaches it. assert!(aliases( &single, @@ -837,11 +840,12 @@ fn a_linear_image_aliases_only_metals_layout() { &LinearImage { size: 4096, ..image - } + }, + false )); // A subresource past the texels (lavapipe's rows rounded up to 4, of a texture of 3). let three = BufferLayout { rows: 3, ..single }; - assert!(!aliases(&three, 4096, 320, &image)); + assert!(!aliases(&three, 4096, 320, &image, false)); assert!(aliases( &three, 4096, @@ -849,21 +853,22 @@ fn a_linear_image_aliases_only_metals_layout() { &LinearImage { subresource: 240, ..image - } + }, + false )); // Rows with the buffer's bytes between them, at Metal's pitch and the image's alike. let padded = BufferLayout { row_bytes: 68, ..single }; - assert!(!aliases(&padded, 4096, 320, &image)); + assert!(!aliases(&padded, 4096, 320, &image, false)); // Whatever its usage: a texture that only reads takes a first move over them too. for usage in [ TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ, TextureUsage::SHADER_READ, ] { - assert!(holding(&padded, usage).is_err(), "{usage:?}"); - assert_eq!(holding(&single, usage), Ok(()), "{usage:?}"); + assert!(holding(&padded, usage, false).is_err(), "{usage:?}"); + assert_eq!(holding(&single, usage, false), Ok(()), "{usage:?}"); } // One row has nothing between rows, but its pitch's padding past the texels. let row = BufferLayout { @@ -871,7 +876,7 @@ fn a_linear_image_aliases_only_metals_layout() { slice_pitch: 80, ..padded }; - assert_eq!(holding(&row, TextureUsage::SHADER_READ), Ok(())); + assert_eq!(holding(&row, TextureUsage::SHADER_READ, false), Ok(())); assert!(!aliases( &row, 4096, @@ -880,7 +885,8 @@ fn a_linear_image_aliases_only_metals_layout() { size: 80, subresource: 80, ..image - } + }, + false )); assert!(aliases( &row, @@ -890,7 +896,8 @@ fn a_linear_image_aliases_only_metals_layout() { size: 80, subresource: 68, ..image - } + }, + false )); // An array's slices at Metal's stride, and at no other. let slices = BufferLayout { @@ -898,7 +905,7 @@ fn a_linear_image_aliases_only_metals_layout() { ..single }; let stacked = LinearImage { size: 960, ..image }; - assert!(aliases(&slices, 4096, 960, &stacked)); + assert!(aliases(&slices, 4096, 960, &stacked, false)); assert!(!aliases( &slices, 4096, @@ -906,7 +913,8 @@ fn a_linear_image_aliases_only_metals_layout() { &LinearImage { array_pitch: 384, ..stacked - } + }, + false )); // Slices with the buffer's bytes between them (an array's slices rounded up to 128). let apart = BufferLayout { @@ -917,7 +925,7 @@ fn a_linear_image_aliases_only_metals_layout() { TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ, TextureUsage::SHADER_READ, ] { - assert!(holding(&apart, usage).is_err(), "{usage:?}"); + assert!(holding(&apart, usage, false).is_err(), "{usage:?}"); } assert!(!aliases( &apart, @@ -927,7 +935,8 @@ fn a_linear_image_aliases_only_metals_layout() { size: 1088, array_pitch: 384, ..image - } + }, + false )); // A driver that reports the array's whole bytes as its first subresource's. assert!(!aliases( @@ -937,7 +946,8 @@ fn a_linear_image_aliases_only_metals_layout() { &LinearImage { subresource: 960, ..stacked - } + }, + false )); // A single slice ignores the array pitch a driver reports. assert!(aliases( @@ -947,10 +957,89 @@ fn a_linear_image_aliases_only_metals_layout() { &LinearImage { array_pitch: 0, ..image - } + }, + false )); } +/// Over a buffer whose maker declares the bytes between rows and slices unobserved +/// (`BufferDescriptor::padding_unobserved`), an image may hold each row's bytes after its texels +/// to its pitch, the last row's included, and the bytes between slices, and nothing past the last +/// row's pitch or the buffer's memory; rows that share bytes stay refused. +#[test] +fn unobserved_padding_lets_an_image_hold_the_bytes_between_rows_alone() { + let padded = BufferLayout { + offset: 256, + row_pitch: 80, + slice_pitch: 320, + row_bytes: 68, + rows: 4, + slices: 1, + }; + let image = LinearImage { + alignment: 16, + size: 320, + offset: 0, + subresource: 320, + row_pitch: 80, + array_pitch: 320, + }; + for usage in [ + TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ, + TextureUsage::SHADER_READ, + TextureUsage::SHADER_WRITE, + ] { + assert_eq!(holding(&padded, usage, true), Ok(()), "{usage:?}"); + } + // The subresource to the last row's pitch, and one that stops at its texels. + assert!(aliases(&padded, 4096, 320, &image, true)); + let to_texels = LinearImage { + subresource: 308, + ..image + }; + assert!(aliases(&padded, 4096, 320, &to_texels, true)); + assert!(!aliases(&padded, 4096, 320, &image, false)); + // Past the last row's pitch (lavapipe's rows rounded up to 4, of a texture of 3). + let three = BufferLayout { + rows: 3, + slice_pitch: 240, + ..padded + }; + assert!(!aliases(&three, 4096, 320, &image, true)); + let three_rows = LinearImage { + subresource: 240, + ..image + }; + assert!(aliases(&three, 4096, 320, &three_rows, true)); + // Memory past the buffer's. + assert!(!aliases(&padded, 4096, 319, &image, true)); + // Slices with the buffer's bytes between them, at Metal's stride and at no other. + let apart = BufferLayout { + slices: 3, + slice_pitch: 384, + ..padded + }; + assert_eq!(holding(&apart, TextureUsage::SHADER_READ, true), Ok(())); + let stacked = LinearImage { + size: 1088, + array_pitch: 384, + ..image + }; + assert!(aliases(&apart, 4096, 1088, &stacked, true)); + let other_stride = LinearImage { + array_pitch: 320, + ..stacked + }; + assert!(!aliases(&apart, 4096, 1088, &other_stride, true)); + // Rows that share bytes (an IOSurface plane's): no image holds a texel twice. + let shared = BufferLayout { + row_bytes: 96, + ..padded + }; + assert!(holding(&shared, TextureUsage::SHADER_READ, true).is_err()); + assert!(!aliases(&shared, 4096, 320, &image, true)); +} + /// A texture over padded rows is a shadow, whatever its usage, naming the operations Vulkan lets /// write the padding: a render target its image's layout transitions (its first move among them) /// and a render pass's load and store operations; any other (one that only reads, or that a @@ -981,7 +1070,7 @@ fn a_padded_texture_s_shadow_names_what_may_write_its_padding() { TextureUsage::BLOCK_WRITES_ONLY, ] { assert_eq!( - holding(&padded, usage), + holding(&padded, usage, false), Err(transitions.to_owned()), "{usage:?}" ); @@ -991,7 +1080,11 @@ fn a_padded_texture_s_shadow_names_what_may_write_its_padding() { TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ, effective_usage(TextureUsage::UNKNOWN), ] { - assert_eq!(holding(&padded, usage), Err(passes.to_owned()), "{usage:?}"); + assert_eq!( + holding(&padded, usage, false), + Err(passes.to_owned()), + "{usage:?}" + ); } } diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 5a87ce8ba..837f92cd0 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -295,6 +295,8 @@ mod owned_kernel_builds; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod owned_pushes; #[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod padding_unobserved; +#[cfg(any(m2v_gpu, m2v_cpu_icd))] mod pass_end_tiles; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod passing_holds; diff --git a/crates/metal2vulkan-runtime/src/tests/padding_unobserved.rs b/crates/metal2vulkan-runtime/src/tests/padding_unobserved.rs new file mode 100644 index 000000000..c0d719d77 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/padding_unobserved.rs @@ -0,0 +1,224 @@ +//! A buffer of the runtime's own memory whose maker declares the bytes between a texture's rows +//! unobserved (`BufferDescriptor::padding_unobserved`): +//! +//! - **Declared.** A `BGRA8Unorm` texture of 101x48 texels (404 bytes a row) over it at pitches +//! past its rows (416, 448 and 512 bytes, the next multiples of 16, 64 and 256 that drivers lay +//! linear rows at: MoltenVK, llvmpipe and ANV, RADV and NVIDIA) answers `NotHostPages`, and its +//! making takes a linear image aliasing the buffer wherever the device lays one at the pitch, +//! counted in `WorkCounts::unobserved_padding_aliases` and not in `shadowed_textures`, else a +//! shadow; at least one pitch takes the image. Through such an image, a blit of the texture into +//! a buffer reads the texels the CPU wrote into the declared buffer's rows, at its pitch. +//! - **Undeclared.** The same texture over a buffer made without the declaration answers +//! `Shadow(BytesBetweenRows)` and is a shadow (`shadowed_textures`), at every pitch. +//! - **Over the caller's memory**, the declaration is refused: `Invalid` +//! (`PaddingUnobservedNoCopy`). +//! +//! A device test: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, +//! `m2v_cpu_icd`), on the kind of device the cfg selects. Printed (`UNOBSERVED-PADDING`): each +//! pitch's answers and paths. + +use super::blit_holds::{device, Host, Scratch}; +use crate::{ + BlitOption, Buffer, BufferContents, BufferDescriptor, Device, Error, Invalid, Origin, Problem, + ResourceOptions, Size, Texture, TextureDescriptor, TexturePlacement, TextureShadowReason, + WorkCounts, +}; +use metal2vulkan::metal::{PixelFormat, TextureUsage}; +use std::time::Duration; + +/// The texture's texels a row, and its rows. +const WIDTH: u64 = 101; +const HEIGHT: u64 = 48; + +/// The pitches past its 404-byte rows the texture is made at. +const PITCHES: [u64; 3] = [416, 448, 512]; + +/// The longest a command buffer may take here. +const WAIT: Duration = Duration::from_secs(20); + +/// A buffer of the device's own memory of `length` bytes, declaring its padding unobserved where +/// `declared`. +fn own_buffer(device: &Device, length: u64, declared: bool) -> Buffer { + let descriptor = BufferDescriptor::new(length, ResourceOptions::shared(), BufferContents::Zero); + let descriptor = match declared { + true => descriptor.with_padding_unobserved(), + false => descriptor, + }; + device.new_buffer_with_descriptor(descriptor).unwrap() +} + +/// The texture's descriptor: `ShaderRead`, `Shared`. +fn texture_descriptor() -> TextureDescriptor { + let mut descriptor = + TextureDescriptor::texture_2d(PixelFormat::BGRA8Unorm, WIDTH, HEIGHT, false); + descriptor.usage = TextureUsage::SHADER_READ; + descriptor.resource_options = ResourceOptions::shared(); + descriptor +} + +/// The texture `buffer` makes at `pitch`, the counts before and after its making. +fn made(device: &Device, buffer: &Buffer, pitch: u64) -> (Texture, WorkCounts, WorkCounts) { + let before = device.work_counts(); + let texture = buffer.new_texture(&texture_descriptor(), 0, pitch).unwrap(); + (texture, before, device.work_counts()) +} + +/// Byte `x` of row `y` the CPU writes into the texels. +fn texel_byte(x: u64, y: u64) -> u8 { + (x * 7 + y * 31 + 3) as u8 +} + +/// The texels of `texture` as a blit copies them into a buffer of rows one after another. +fn blitted(device: &Device, texture: &Texture) -> Vec { + let row = WIDTH * 4; + let read = device + .new_buffer(row * HEIGHT, ResourceOptions::shared()) + .unwrap(); + let queue = device.new_command_queue().unwrap(); + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + blit.copy_from_texture_to_buffer( + texture, + 0, + 0, + Origin::new(0, 0, 0), + Size::new(WIDTH, HEIGHT, 1), + &read, + 0, + row, + row * HEIGHT, + BlitOption::None, + ) + .unwrap(); + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + // SAFETY: the read buffer's mapped bytes, which no command uses now. + unsafe { + std::slice::from_raw_parts(read.contents().unwrap().as_ptr(), (row * HEIGHT) as usize) + } + .to_vec() +} + +#[test] +fn a_texture_over_unobserved_padding_aliases_its_buffer_and_over_observed_padding_is_a_shadow() { + let scratch = Scratch::new("padding-unobserved"); + let device = device(&scratch.0); + let length = PITCHES[2] * HEIGHT; + let descriptor = texture_descriptor(); + let mut aliased = Vec::new(); + for pitch in PITCHES { + let observed = own_buffer(&device, length, false); + let answer = observed.texture_placement(&descriptor, 0, pitch).unwrap(); + assert_eq!( + answer, + TexturePlacement::Shadow(TextureShadowReason::BytesBetweenRows), + "undeclared at {pitch}: the answer" + ); + let (texture, before, after) = made(&device, &observed, pitch); + assert!( + texture.shadow().is_some() && !texture.aliases_buffer(), + "undeclared at {pitch}: a shadow" + ); + assert_eq!(after.shadowed_textures - before.shadowed_textures, 1); + assert_eq!( + after.unobserved_padding_aliases, + before.unobserved_padding_aliases + ); + + let declared = own_buffer(&device, length, true); + assert!( + !declared.in_fresh_pages(), + "a short buffer lies in no fresh pages" + ); + let answer = declared.texture_placement(&descriptor, 0, pitch).unwrap(); + assert_eq!( + answer, + TexturePlacement::NotHostPages, + "declared at {pitch}: the answer" + ); + // SAFETY: the declared buffer's mapped bytes, which no command uses yet. + let bytes = unsafe { + std::slice::from_raw_parts_mut(declared.contents().unwrap().as_ptr(), length as usize) + }; + for y in 0..HEIGHT { + for x in 0..WIDTH * 4 { + bytes[(y * pitch + x) as usize] = texel_byte(x, y); + } + } + let (texture, before, after) = made(&device, &declared, pitch); + let aliases = texture.aliases_buffer(); + assert_eq!( + aliases, + texture.shadow().is_none(), + "declared at {pitch}: an aliasing image or a shadow" + ); + assert_eq!( + after.unobserved_padding_aliases - before.unobserved_padding_aliases, + u64::from(aliases), + "declared at {pitch}: counted as an aliasing image over unobserved padding" + ); + assert_eq!( + after.shadowed_textures - before.shadowed_textures, + u64::from(!aliases), + "declared at {pitch}: counted as a shadow" + ); + let read = blitted(&device, &texture); + for y in 0..HEIGHT { + for x in 0..WIDTH * 4 { + assert_eq!( + read[(y * WIDTH * 4 + x) as usize], + texel_byte(x, y), + "declared at {pitch}: byte {x} of row {y}" + ); + } + } + if aliases { + aliased.push(pitch); + } + eprintln!( + "UNOBSERVED-PADDING on {}: {WIDTH}x{HEIGHT} BGRA8Unorm at {pitch}: undeclared a \ + shadow ({:?}); declared {} ({:?})", + device.name(), + TexturePlacement::Shadow(TextureShadowReason::BytesBetweenRows), + match aliases { + true => "an aliasing image", + false => "a shadow (the device lays no linear image at the pitch)", + }, + TexturePlacement::NotHostPages, + ); + } + assert!( + !aliased.is_empty(), + "no pitch of {PITCHES:?} took an aliasing image on {}", + device.name() + ); +} + +#[test] +fn padding_unobserved_is_refused_over_the_callers_memory() { + let scratch = Scratch::new("padding-unobserved-no-copy"); + let device = device(&scratch.0); + let host = Host::new(); + // SAFETY: the memory outlives the call, which refuses it before any import. + let memory = unsafe { host.memory() }; + let contents = BufferContents::NoCopy { + memory, + deallocator: None, + keep_alive: None, + }; + let descriptor = BufferDescriptor::new(1 << 16, ResourceOptions::shared(), contents) + .with_padding_unobserved(); + let made = device.new_buffer_with_descriptor(descriptor); + assert!( + matches!( + made, + Err(Error::Invalid(Invalid { + problem: Problem::PaddingUnobservedNoCopy, + .. + })) + ), + "the declaration over the caller's memory: {:?}", + made.err() + ); +} diff --git a/crates/metal2vulkan-runtime/src/tests/texture_placement.rs b/crates/metal2vulkan-runtime/src/tests/texture_placement.rs index a854fa0ee..ab9c8e13f 100644 --- a/crates/metal2vulkan-runtime/src/tests/texture_placement.rs +++ b/crates/metal2vulkan-runtime/src/tests/texture_placement.rs @@ -25,7 +25,14 @@ fn each_route_answers_its_own_placement() { P::Shadow(R::Mipmapped { levels: 6 }) ); assert_eq!(Route::Past.placement(), P::Shadow(R::PastLength)); - assert_eq!(Route::Device.placement(), P::NotHostPages); + assert_eq!(Route::Device { holds: Ok(()) }.placement(), P::NotHostPages); + assert_eq!( + Route::Device { + holds: Err("its rows lie apart".to_owned()) + } + .placement(), + P::Shadow(R::BytesBetweenRows) + ); assert_eq!( host(HostWay::DeviceCopy).placement(), P::Shadow(R::DeviceCopy) diff --git a/crates/metal2vulkan-runtime/src/tests/texture_placement_device.rs b/crates/metal2vulkan-runtime/src/tests/texture_placement_device.rs index 2fd23ffd7..849aa288e 100644 --- a/crates/metal2vulkan-runtime/src/tests/texture_placement_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/texture_placement_device.rs @@ -82,7 +82,7 @@ fn expected(placement: TexturePlacement) -> Took { TexturePlacement::Shadow(R::Unchecked { .. }) => Took::Unchecked, TexturePlacement::Shadow(R::Refused(refusal)) => Took::Refused(refusal), TexturePlacement::Shadow(R::DeviceCopy) => Took::DeviceCopy, - TexturePlacement::Shadow(R::PastLength | R::Mipmapped { .. }) + TexturePlacement::Shadow(R::PastLength | R::Mipmapped { .. } | R::BytesBetweenRows) | TexturePlacement::NotHostPages | TexturePlacement::OtherShape => Took::Uncounted, } diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index cf7548f1d..14f7152f2 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -83,9 +83,7 @@ use super::image_plan::{ }; use super::in_place::{self, PagesClass, ShadowCause}; use super::key_hash::KeyMap; -use super::linear_plan::{ - aliases, check_linear_limits, holding, linear_lack, LinearImage, LinearLack, -}; +use super::linear_plan::{aliases, check_linear_limits, linear_lack, LinearImage, LinearLack}; use super::memory::{MemoryClass, Placement}; use super::nan_clear; use super::neutral::Neutrals; @@ -2390,10 +2388,7 @@ impl Device { let shadowed = (class, (rows, padding), cause); self.host_shadowed(shadowed, (usage, &plan), descriptor, pending)? } - Route::Device => { - // Whether an image may hold the texels: none where their rows (or slices) lie - // with the buffer's bytes between them (`linear_plan::holding`), and else why. - let holds = holding(&texels.layout, usage); + Route::Device { holds } => { // The usage the texture lacks, as for a texture of its own: plain Metal writes a // texture over a buffer made without `ShaderWrite` and reads one made without // `ShaderRead`. A linear image aliasing the buffer's memory takes it where one @@ -2778,7 +2773,10 @@ impl Device { /// an image bound to it would have to be made for (a texture over the caller's host pages /// takes the image in place or a shadow: `storage_over_buffer`, `in_place.rs`). It starts `PREINITIALIZED`, which its move to /// `GENERAL` keeps. The image's hazard tracking is the buffer's. `holds`: whether an image may - /// hold the texels (`linear_plan::holding`), or why not. + /// hold the texels (`linear_plan::holding`), or why not. Over a buffer that declares the bytes + /// between rows and slices unobserved (`BufferDescriptor::padding_unobserved`), the image may + /// hold those bytes too (`linear_plan::within_padding`), counted where its rows or slices lie + /// apart (`WorkCounts::unobserved_padding_aliases`). fn alias_image( &self, plan: ImagePlan, @@ -2833,7 +2831,8 @@ impl Device { row_pitch: report.row_pitch, array_pitch: report.array_pitch, }; - let why = if !aliases(&texels.layout, memory_offset, room, &image) { + let unobserved = texels.buffer.padding_unobserved(); + let why = if !aliases(&texels.layout, memory_offset, room, &image, unobserved) { Some(format!( "the device's linear image of the texture lays its texels out otherwise than \ Metal at the texels' offset and row pitch, or holds other bytes than its texels \ @@ -2897,6 +2896,9 @@ impl Device { // Leaving `PREINITIALIZED` keeps the bytes the image holds: the buffer's. let first = FirstMove::new(raw, image.plan().format, initial, None); *lock(&image.first_move) = Some(first); + if unobserved && texels.layout.padded() { + self.shared().counts.unobserved_padding_alias(); + } Ok(Ok(image.shared())) } diff --git a/crates/metal2vulkan-runtime/src/texture/route.rs b/crates/metal2vulkan-runtime/src/texture/route.rs index 9898b9431..663df2374 100644 --- a/crates/metal2vulkan-runtime/src/texture/route.rs +++ b/crates/metal2vulkan-runtime/src/texture/route.rs @@ -14,6 +14,7 @@ use crate::buffer::CallerMemory; use crate::buffer_texture::Texels; use crate::image_plan::{plan_image, ImageFacts, ImagePlan}; use crate::in_place::{self, Access, Padding, PagesClass, Refusal, RowEnds, ShadowCause, Verdict}; +use crate::linear_plan::holding; use crate::texture_descriptor::{texture_usage, TextureDescriptor, TextureLayout}; use crate::texture_placement::TexturePlacement; use crate::{Device, Error}; @@ -29,9 +30,12 @@ pub(crate) enum Route { /// Its texels run past the buffer's length, which no image over the buffer's memory reaches: /// the shadow, its tail holding them. Past, - /// The buffer's bytes are no host pages: an image aliasing the buffer's memory where the - /// device makes one on Metal's layout, else the shadow. - Device, + /// The buffer's bytes are no host pages: an image aliasing the buffer's memory where `holds` + /// (an image over the texels may hold them, `linear_plan::holding`: their rows lie one after + /// another, or the buffer declares the bytes between them unobserved, + /// `BufferDescriptor::padding_unobserved`) and the device makes one on Metal's layout, else + /// the shadow; `holds` says why not where it does not. + Device { holds: Result<(), String> }, /// Over host pages of `class`, its texels lying in the device's lines as `rows` says, and /// `padding` saying whether a shader's writes may change their rows' padding. Host { @@ -140,7 +144,14 @@ impl Device { Some(CallerMemory::HostPages) if texels.buffer.over_dma_buf() => PagesClass::DmaBuf, Some(CallerMemory::HostPages) => PagesClass::Pointer, None if texels.buffer.in_fresh_pages() => PagesClass::Fresh, - _ => return Route::Device, + _ => { + // Whether an image may hold the texels: none where their rows (or slices) lie + // with the buffer's bytes between them, unless the buffer declares those bytes + // unobserved (`linear_plan::holding`), and else why. + let unobserved = texels.buffer.padding_unobserved(); + let holds = holding(&texels.layout, usage, unobserved); + return Route::Device { holds }; + } }; // How the texels lie in the device's lines of memory, each checked apart // (`in_place::RowEnds`), and whether a shader's writes may change their rows' padding diff --git a/crates/metal2vulkan-runtime/src/texture_placement.rs b/crates/metal2vulkan-runtime/src/texture_placement.rs index f25ed2bc9..ec68eb88c 100644 --- a/crates/metal2vulkan-runtime/src/texture_placement.rs +++ b/crates/metal2vulkan-runtime/src/texture_placement.rs @@ -38,7 +38,11 @@ pub enum TexturePlacement { Shadow(TextureShadowReason), /// The buffer's bytes are no host pages (a buffer of the device's own memory, or the caller's /// `VkBuffer`): the texture is a linear image aliasing the buffer's memory where the device - /// lays one out as Metal does, else a shadow. The device's check does not decide it. + /// lays one out as Metal does, else a shadow. The device's check does not decide it. Its rows + /// (and slices) lie one after another, or the buffer declares the bytes between them + /// unobserved ([`BufferDescriptor::padding_unobserved`](crate::BufferDescriptor::padding_unobserved)), + /// which the image then holds; else the answer is + /// [`TextureShadowReason::BytesBetweenRows`]. NotHostPages, /// A texture of a shape no image in place takes, over any buffer: a texture buffer (its /// functions view the buffer's bytes, or a staging copy of them), a rotated texture, a @@ -95,6 +99,14 @@ pub enum TextureShadowReason { /// The texels run past the buffer's length, which no image over the buffer's memory reaches: /// the texture's tail holds those past it, zero when made. PastLength, + /// Over a buffer of the device's own memory ([`TexturePlacement::NotHostPages`]'s): its rows + /// (or slices) lie with bytes of the buffer between them that are not its texels, or share + /// bytes, which an image over the memory would hold, and Vulkan lets an image's layout moves + /// and a render pass's load and store write the bytes it holds; the buffer does not declare + /// the bytes between rows unobserved + /// ([`BufferDescriptor::padding_unobserved`](crate::BufferDescriptor::padding_unobserved), + /// which no rows that share bytes take). + BytesBetweenRows, /// On a discrete GPU, a `Managed` texture over a no-copy buffer's bytes (not an IOSurface /// plane's) that only samples or reads, over memory that carries a log of its writes, tracked, /// one slice laid out as one copy: a copy in the device's memory whose copies in take only the @@ -213,7 +225,10 @@ impl Route { return TexturePlacement::Shadow(TextureShadowReason::Mipmapped { levels }); } Route::Past => return TexturePlacement::Shadow(TextureShadowReason::PastLength), - Route::Device => return TexturePlacement::NotHostPages, + Route::Device { holds: Ok(()) } => return TexturePlacement::NotHostPages, + Route::Device { holds: Err(_) } => { + return TexturePlacement::Shadow(TextureShadowReason::BytesBetweenRows) + } Route::Host { way, .. } => match way { HostWay::InPlace { .. } => return TexturePlacement::InPlace, HostWay::DeviceCopy => { diff --git a/crates/metal2vulkan-runtime/src/work_counts.rs b/crates/metal2vulkan-runtime/src/work_counts.rs index b7783cda4..5d6774a6e 100644 --- a/crates/metal2vulkan-runtime/src/work_counts.rs +++ b/crates/metal2vulkan-runtime/src/work_counts.rs @@ -477,6 +477,7 @@ pub(crate) struct Counters { reading_draws_pinned: AtomicU64, stand_ins_after_pins: AtomicU64, feedback_loop_alias_images: AtomicU64, + unobserved_padding_aliases: AtomicU64, feedback_loop_shadow_images: AtomicU64, depth_attachments_moved: AtomicU64, depth_instances_held: AtomicU64, @@ -3475,6 +3476,14 @@ impl Counters { .fetch_add(1, Ordering::Relaxed); } + /// The device made a linear image aliasing a buffer's bytes that holds the bytes between the + /// texture's rows or slices, which the buffer declared unobserved + /// (`BufferDescriptor::padding_unobserved`, `Device::storage_over_buffer`). + pub(crate) fn unobserved_padding_alias(&self) { + self.unobserved_padding_aliases + .fetch_add(1, Ordering::Relaxed); + } + /// The device made the image of a texture over a buffer's bytes that the encoders copy them /// into and back (`shadow.rs`) with feedback loop usage (`texture::feedback_candidate`). pub(crate) fn feedback_loop_shadow_image(&self) { @@ -6607,6 +6616,12 @@ pub struct WorkCounts { /// its pass renders it (`render/snapshot.rs`): one per image made. Where the device makes no /// such image with the usage, it makes one without, and the texture's readers split. pub feedback_loop_alias_images: u64, + /// Linear images aliasing a buffer of the device's own memory, of textures whose rows or + /// slices lie with bytes between them that the buffer declares unobserved + /// (`BufferDescriptor::padding_unobserved`): each image holds those bytes, where without the + /// declaration the texture is a shadow (`shadowed_textures`). One per image made. A runtime + /// extension: Metal has none. + pub unobserved_padding_aliases: u64, /// Images of textures over a buffer's bytes that the encoders copy them into and back (the /// texture's shadow, `shadow.rs`: a texture over host pages that renders, among others) that /// the device made with feedback loop usage where it cost them nothing @@ -7509,6 +7524,7 @@ impl Device { reading_draws_pinned: counters.reading_draws_pinned.load(Ordering::Relaxed), stand_ins_after_pins: counters.stand_ins_after_pins.load(Ordering::Relaxed), feedback_loop_alias_images: counters.feedback_loop_alias_images.load(Ordering::Relaxed), + unobserved_padding_aliases: counters.unobserved_padding_aliases.load(Ordering::Relaxed), feedback_loop_shadow_images: counters .feedback_loop_shadow_images .load(Ordering::Relaxed), diff --git a/crates/metal2vulkan-validation/src/runtime_lane/in_place_textures.rs b/crates/metal2vulkan-validation/src/runtime_lane/in_place_textures.rs index 61be405e2..7227f0ace 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/in_place_textures.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/in_place_textures.rs @@ -108,10 +108,10 @@ use crate::gpu::TEST_DEVICE; use metal2vulkan::device::HostPageTexturePolicy; use metal2vulkan::metal::{PixelFormat, PrimitiveType, TextureUsage}; use metal2vulkan_runtime::{ - BlitOption, Buffer, ClearColor, CommandBuffer, CommandQueue, ComputePipelineState, Degradation, - Device, DeviceOptions, EventRef, LoadAction, Origin, RenderPassDescriptor, RenderPipelineState, - ResourceOptions, ScissorRect, SharedEvent, Size, StoreAction, Texture, TextureDescriptor, - WorkCounts, + BlitOption, Buffer, BufferContents, BufferDescriptor, ClearColor, CommandBuffer, CommandQueue, + ComputePipelineState, Degradation, Device, DeviceOptions, EventRef, LoadAction, Origin, + RenderPassDescriptor, RenderPipelineState, ResourceOptions, ScissorRect, SharedEvent, Size, + StoreAction, Texture, TextureDescriptor, WorkCounts, }; /// The bytes of a buffer of the runtime's own that lies in fresh pages (past half a pooled block). @@ -1367,7 +1367,6 @@ fn surface_costs( rows: u64, passes: usize, ) -> bool { - const FRAMES: usize = 40; let len = ((bpr * h) as usize).next_multiple_of(GUEST_PAGE); let mapping = Mapping::anonymous(len); mapping.write(0, &counting(len, 5)); @@ -1393,14 +1392,53 @@ fn surface_costs( Some(_) => "in place", None => "shadow", }; + // The CPU writes a row each frame, as a guest's surface changes. + let write = + |frame: usize| mapping.write(((frame as u64 % h) * bpr) as usize, &[frame as u8; 64]); + let times = frame_times( + device, + queue, + (reads, corners), + &texture, + write, + rows, + passes, + ); + eprintln!( + "IN-PLACE-COST on {}: {policy:?} ({form}): a frame's GPU time median {:.1} us, fastest \ + {:.1} us, over {} frames of {passes} pass(es) each reading the top {rows} rows of a \ + {w}x{h} surface", + device.name(), + times[times.len() / 2] * 1e6, + times[0] * 1e6, + times.len(), + ); + drop((texture, buffer)); + drop(mapping); + true +} + +/// The GPU times of [`FRAMES`] frames, fastest first, each frame `write(frame)` by the CPU and one +/// command buffer of `queue` that renders `passes` passes, each reading the top `rows` rows of the +/// `BGRA8Unorm` `texture` through `reads` (a fragment function's `read`, over `corners`) into a +/// private target of its size. +fn frame_times( + device: &Device, + queue: &CommandQueue, + (reads, corners): (&RenderPipelineState, &Buffer), + texture: &Texture, + mut write: impl FnMut(usize), + rows: u64, + passes: usize, +) -> Vec { + let (w, h) = (texture.width(), texture.height()); let mut d = TextureDescriptor::texture_2d(PixelFormat::BGRA8Unorm, w, h, false); d.usage = TextureUsage::RENDER_TARGET; d.resource_options = ResourceOptions::private(); let target = device.new_texture(&d).unwrap(); let mut times = Vec::with_capacity(FRAMES); for frame in 0..FRAMES { - // The CPU writes a row each frame, as a guest's surface changes. - mapping.write(((frame as u64 % h) * bpr) as usize, &[frame as u8; 64]); + write(frame); let command_buffer = queue.command_buffer().unwrap(); for _ in 0..passes { let mut pass = RenderPassDescriptor::new(); @@ -1414,7 +1452,7 @@ fn surface_costs( .set_scissor_rect(ScissorRect::new(0, 0, w, rows)) .unwrap(); encoder.set_vertex_buffer(Some(corners), 0, 0).unwrap(); - encoder.set_fragment_texture(Some(&texture), 0).unwrap(); + encoder.set_fragment_texture(Some(texture), 0).unwrap(); encoder .draw_primitives(PrimitiveType::Triangle, 0, 6, 1, 0) .unwrap(); @@ -1427,15 +1465,77 @@ fn surface_costs( times.push(gpu); } times.sort_by(f64::total_cmp); - eprintln!( - "IN-PLACE-COST on {}: {policy:?} ({form}): a frame's GPU time median {:.1} us, fastest \ - {:.1} us, over {FRAMES} frames of {passes} pass(es) each reading the top {rows} rows of \ - a {w}x{h} surface", - device.name(), - times[FRAMES / 2] * 1e6, - times[0] * 1e6, - ); - drop((texture, buffer, target)); - drop(mapping); - true + times +} + +/// The frames [`frame_times`] times. +const FRAMES: usize = 40; + +/// The consumer's desktop surface over a buffer of the runtime's own memory: 3662x2038 +/// `BGRA8Unorm`, rows 14848 bytes apart (14648 bytes of texels, the pitch rounded up to 256). +const OWN_SURFACE: (u64, u64, u64) = (3662, 2038, 14848); + +/// A texture over a buffer of the runtime's own memory whose rows lie apart, the consumer's +/// desktop surface's shape ([`OWN_SURFACE`]): over a buffer that declares the bytes between rows +/// unobserved (`BufferDescriptor::padding_unobserved`) and over one that does not. The undeclared +/// one is a shadow (`shadowed_textures`); the declared one a linear image aliasing the buffer +/// wherever the device lays one at the pitch (`unobserved_padding_aliases`), else a shadow. Each +/// frame the CPU writes a row of the buffer, and one command buffer reads the whole surface +/// through a fragment function's `read` (the in-place cost lane's frame). Printed +/// (`UNOBSERVED-PADDING-COST`): each form's median and fastest GPU time of a frame. +#[test] +fn unobserved_padding_costs() { + let cache = ScratchCache::new().unwrap(); + let messages = Messages::default(); + let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), |options| { + options.layers.clear(); + }) + .unwrap(); + let queue = device.new_command_queue().unwrap(); + let reads = reading(&device, PixelFormat::BGRA8Unorm, "tob_read"); + let corners = staged(&device, &floats([-1.0, -1.0, 1.0, 1.0])); + let (w, h, bpr) = OWN_SURFACE; + for declared in [false, true] { + let descriptor = + BufferDescriptor::new(bpr * h, ResourceOptions::shared(), BufferContents::Zero); + let descriptor = match declared { + true => descriptor.with_padding_unobserved(), + false => descriptor, + }; + let buffer = device.new_buffer_with_descriptor(descriptor).unwrap(); + let contents = buffer.contents().unwrap(); + let before = device.work_counts(); + let texture = sampled(&buffer, PixelFormat::BGRA8Unorm, (w, h, bpr)); + let after = device.work_counts(); + let aliases = after.unobserved_padding_aliases - before.unobserved_padding_aliases; + let shadows = after.shadowed_textures - before.shadowed_textures; + assert_eq!( + aliases + shadows, + 1, + "declared {declared}: one form, counted" + ); + assert!(declared || shadows == 1, "undeclared: a shadow"); + let form = match aliases { + 1 => "an aliasing image", + _ => "a shadow", + }; + let write = |frame: usize| { + let at = (frame as u64 % h) * bpr; + // SAFETY: 64 of the buffer's mapped bytes, inside it, which no command uses between + // frames. + unsafe { std::ptr::write_bytes(contents.as_ptr().add(at as usize), frame as u8, 64) }; + }; + let times = frame_times(&device, &queue, (&reads, &corners), &texture, write, h, 1); + eprintln!( + "UNOBSERVED-PADDING-COST on {}: declared {declared} ({form}): a frame's GPU time \ + median {:.1} us, fastest {:.1} us, over {} frames each reading a {w}x{h} surface \ + with rows {bpr} bytes apart", + device.name(), + times[times.len() / 2] * 1e6, + times[0] * 1e6, + times.len(), + ); + } + messages.take_notices(); + layer_reported_nothing_at_all(&messages); } diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index a0804c223..217b24aaa 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -2001,6 +2001,7 @@ field metal2vulkan-runtime::BinaryArchiveMiss.function pub function: String field metal2vulkan-runtime::BinaryArchiveMiss.pipeline pub pipeline: ArchivedPipeline field metal2vulkan-runtime::BufferDescriptor.contents pub contents: BufferContents<'a> field metal2vulkan-runtime::BufferDescriptor.length pub length: u64 +field metal2vulkan-runtime::BufferDescriptor.padding_unobserved pub padding_unobserved: bool field metal2vulkan-runtime::BufferDescriptor.placement pub placement: AddressPlacement field metal2vulkan-runtime::BufferDescriptor.pool_slot pub pool_slot: Option<(&'a AddressPool, u64)> field metal2vulkan-runtime::BufferDescriptor.range_of pub range_of: Option<&'a Buffer> @@ -3131,6 +3132,7 @@ field metal2vulkan-runtime::WorkCounts.trail_waits_blocked pub trail_waits_block field metal2vulkan-runtime::WorkCounts.two_plane_draws pub two_plane_draws: u64 field metal2vulkan-runtime::WorkCounts.uncached_host_images pub uncached_host_images: u64 field metal2vulkan-runtime::WorkCounts.unlisted_argument_sampler_buffers pub unlisted_argument_sampler_buffers: u64 +field metal2vulkan-runtime::WorkCounts.unobserved_padding_aliases pub unobserved_padding_aliases: u64 field metal2vulkan-runtime::WorkCounts.unrun_instances_ended pub unrun_instances_ended: u64 field metal2vulkan-runtime::WorkCounts.untouched_passes_skipped pub untouched_passes_skipped: u64 field metal2vulkan-runtime::WorkCounts.upload_chunks_in_device_memory pub upload_chunks_in_device_memory: u64 @@ -7818,6 +7820,7 @@ method metal2vulkan-runtime::Buffer::tiled_texture_placement pub fn tiled_textur method metal2vulkan-runtime::Buffer::vk_buffer pub unsafe fn vk_buffer(&self) -> (vk::Buffer, u64) method metal2vulkan-runtime::Buffer::vk_host_memory pub unsafe fn vk_host_memory(&self) -> Option method metal2vulkan-runtime::BufferDescriptor::new pub fn new(length: u64, resource_options: ResourceOptions, contents: BufferContents<'a>) -> BufferDescriptor<'a> +method metal2vulkan-runtime::BufferDescriptor::with_padding_unobserved pub fn with_padding_unobserved(self) -> BufferDescriptor<'a> method metal2vulkan-runtime::BufferDescriptor::with_placement pub fn with_placement(self, placement: AddressPlacement) -> BufferDescriptor<'a> method metal2vulkan-runtime::BufferDescriptor::with_pool_slot pub fn with_pool_slot(self, pool: &'a AddressPool, offset: u64) -> BufferDescriptor<'a> method metal2vulkan-runtime::BufferDescriptor::with_range_of pub fn with_range_of(self, buffer: &'a Buffer) -> BufferDescriptor<'a> @@ -12129,6 +12132,7 @@ variant metal2vulkan-runtime::Problem::NotExportable NotExportable variant metal2vulkan-runtime::Problem::NotShareable NotShareable variant metal2vulkan-runtime::Problem::OffsetOutOfRange OffsetOutOfRange { offset: u64, length: u64 } variant metal2vulkan-runtime::Problem::OutsidePlacement OutsidePlacement +variant metal2vulkan-runtime::Problem::PaddingUnobservedNoCopy PaddingUnobservedNoCopy variant metal2vulkan-runtime::Problem::PointSizeTopology PointSizeTopology variant metal2vulkan-runtime::Problem::ProtectedEncoder ProtectedEncoder { options: u64 } variant metal2vulkan-runtime::Problem::RangeOutOfBounds RangeOutOfBounds { offset: u64, size: u64, length: u64 } @@ -12374,6 +12378,7 @@ variant metal2vulkan-runtime::TextureProblem::Unspecialized Unspecialized variant metal2vulkan-runtime::TextureProblem::UsageForFormat UsageForFormat variant metal2vulkan-runtime::TextureProblem::ViewOnlyFormat ViewOnlyFormat variant metal2vulkan-runtime::TextureProblem::ZeroExtent ZeroExtent +variant metal2vulkan-runtime::TextureShadowReason::BytesBetweenRows BytesBetweenRows variant metal2vulkan-runtime::TextureShadowReason::CheckFailed CheckFailed { access: InPlaceAccess, row_ends: InPlaceRowEnds } variant metal2vulkan-runtime::TextureShadowReason::DeviceCopy DeviceCopy variant metal2vulkan-runtime::TextureShadowReason::Mipmapped Mipmapped { levels: u32 } diff --git a/docs/API.md b/docs/API.md index 5cdaffb94..3f689faf2 100644 --- a/docs/API.md +++ b/docs/API.md @@ -390,10 +390,12 @@ arguments of `new_texture` and `new_texture_with_iosurface_plane`, where the tex then (`TexturePlacement`): in place; `Pending`, a shadow made before its verdict that moves in place where the verdict passes; a shadow and why (`TextureShadowReason`: the policy, the texel width, the check's failed or unchecked verdict with its access and row ends, a refusal, a tiled texture's -levels, texels past the buffer's length, a device copy); no host pages; or a shape no image in place -takes; `Buffer::tiled_texture_placement` answers it for `new_tiled_texture`'s. The making's -own route answers it (`texture/route.rs`), after every check the making runs before it makes -anything, so the same arguments are refused with the same errors; where the route is the image in +levels, texels past the buffer's length, a device copy, and over the device's own memory rows with +bytes between them the buffer does not declare unobserved, `BytesBetweenRows`); no host pages (an +image aliasing the buffer's memory where the device lays one out as Metal does); or a shape no +image in place takes; `Buffer::tiled_texture_placement` answers it for `new_tiled_texture`'s. The +making's own route answers it (`texture/route.rs`), after every check the making runs before it +makes anything, so the same arguments are refused with the same errors; where the route is the image in place, the query runs the image's making up to the bind (`texture/in_place_image.rs`): it makes the driver's linear image, and the `DRM_FORMAT_MOD_LINEAR` one where the driver lays the first out at another pitch, checks their requirements against the bytes' place and memory type, and releases @@ -1584,7 +1586,9 @@ bound. which an image over them would hold in its subresource, where Vulkan lets the image's layout transitions read and write any byte of its subresources, and a render pass's load and store operations read and write back any byte of an attachment's image subresource, and Metal leaves - them as the program writes them; or no linear image of the device lays its texels out as Metal + them as the program writes them, unless the buffer, of the runtime's own memory, declares them + unobserved (`BufferDescriptor::padding_unobserved`, a runtime extension: they may then change, + and no other byte does); or no linear image of the device lays its texels out as Metal does in the buffer's memory, holding no byte past them; or the buffer is over the caller's `VkBuffer`, whose memory backs no image of the runtime's; or it is a tiled texture of more than one level (`Buffer::new_tiled_texture`), over any buffer: no image over the buffer's memory holds diff --git a/docs/HOWTO.md b/docs/HOWTO.md index 2f374eaf0..a56436ef9 100644 --- a/docs/HOWTO.md +++ b/docs/HOWTO.md @@ -338,7 +338,15 @@ includes any extra memory that is required based on rowPitch"), which its layout render pass's load and store operations ("read and write back any memory locations within the image subresource bound for that attachment"; lavapipe writes back the bytes its 4-texel blocks reach past a row, a signaling NaN's bits quieted) may write, where Metal leaves them as the program writes -them. +them. A consumer that owns every read of such a buffer's bytes (a cache it fills and reads back by +rows of texels, say) may make it with `BufferDescriptor::with_padding_unobserved()`: a runtime +extension, no Metal counterpart, refused over the caller's memory (`NoCopy` contents). A texture +over it is then a linear image at its pitch wherever the device lays one out so, its subresources +holding each row's bytes after its texels to its pitch (the last row's included) and nothing past +the last row's pitch; those bytes and the bytes between slices may change whenever the texture is +made or used, and no other byte does (`WorkCounts::unobserved_padding_aliases` counts such images; +`Buffer::texture_placement` answers `NotHostPages` for it, and +`Shadow(TextureShadowReason::BytesBetweenRows)` without the declaration). A blit that names a texture over a buffer runs on the buffers' bytes, a region per row where its rows lie apart, and a buffer-texture copy in a layout Vulkan cannot state moves its rows through a diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 69a273e34..cfe165f07 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -34,7 +34,7 @@ Columns: | Translation caps | 14 | 14 | 0 | 0 | 7 | 7 | 0 | | 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 | -| What a call did wrong | 67 | 67 | 0 | 0 | 0 | 0 | 0 | +| What a call did wrong | 68 | 68 | 0 | 0 | 0 | 0 | 0 | | What a call did wrong, in detail | 167 | 150 | 0 | 0 | 0 | 0 | 0 | ## Totals by basis @@ -48,7 +48,7 @@ Columns: | Translation caps | 0 | 0 | 0 | 0 | 14 | 0 | 0 | 0 | | Rate maps the compile layer does not compile | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 | | The translation deadline | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | -| What a call did wrong | 22 | 3 | 5 | 0 | 12 | 8 | 17 | 0 | +| What a call did wrong | 22 | 3 | 5 | 0 | 13 | 8 | 17 | 0 | | What a call did wrong, in detail | 59 | 26 | 23 | 0 | 33 | 26 | 0 | 0 | ## 1. Translator and front-end refusals (`Unsupported`: a `Feature` and its `Needs`) @@ -352,6 +352,7 @@ Columns: | `StorageMode` | A storage mode this call does not take (`Memoryless` for a buffer, for one) | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max: a buffer of the Memoryless mode asserts "Invalid storageMode", the API validation layer off | 15: `crates/metal2vulkan-runtime/src/argument_encoder.rs (target)`, `crates/metal2vulkan-runtime/src/buffer.rs (buffer_class)` (+13) | `-` | | `HandlerAfterCommit` | A handler added after the command buffer was committed | every device (a public call's own check of its arguments) | `metal-documented`: Metal asserts "Completed handler provided after commit call" | 5: `crates/metal2vulkan-runtime/src/command_buffer/mod.rs (add_completed_handler)`, `crates/metal2vulkan-runtime/src/command_buffer/mod.rs (add_completion_seen_handler)` (+3) | `-` | | `LengthMismatch` | The given slices' lengths differ | every device (a public call's own check of its arguments) | `ours`: this crate's paired slices: Metal's calls take a count | 8: `crates/metal2vulkan-runtime/src/argument_encoder.rs (set_buffers)`, `crates/metal2vulkan-runtime/src/argument_table.rs (set_buffers_with_strides)` (+5) | `-` | +| `PaddingUnobservedNoCopy` | A buffer descriptor that declares the bytes between a texture's rows unobserved (`BufferDescriptor::padding_unobserved`) with `NoCopy` contents | every device (a public call's own check of its arguments) | `ours`: a runtime extension: Metal has no such declaration | 1: `crates/metal2vulkan-runtime/src/buffer_descriptor.rs (new_buffer_with_descriptor_now)` | `-` | | `LongTextureBufferFillPattern` | A texture buffer's fill given a pattern of more than 32752 bytes (`fillTexture:...:bytes:length:`) | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: Metal's process ends in the call | 1: `crates/metal2vulkan-runtime/src/blit_fill.rs (check_pattern)` | `-` | | `RangeOutOfBounds` | `offset..offset + size` runs past a resource of `length` bytes | every device (a public call's own check of its arguments) | `metal-takes`: an Apple M3 Max, macOS 27.0.1: didModifyRange of 0+512 and of 240+64 on a buffer of 256 bytes both return; Metal's API validation alone refuses them | 4: `crates/metal2vulkan-runtime/src/argument_encoder.rs (target_offset)`, `crates/metal2vulkan-runtime/src/blit.rs (out_of_bounds)` (+2) | `-` | | `ShaderCacheCapacity` | A shader cache capacity, on disk or in memory, of zero | every device (a public call's own check of its arguments) | `ours`: this crate's shader caches: Metal exposes no capacity | 1: `crates/metal2vulkan-runtime/src/shader_cache/mod.rs (of)` | `-` | @@ -834,6 +835,7 @@ Each refusal's sites, with the function that builds it. - `invalid::StorageMode`: `crates/metal2vulkan-runtime/src/argument_encoder.rs (target)`; `crates/metal2vulkan-runtime/src/buffer.rs (buffer_class)`; `crates/metal2vulkan-runtime/src/buffer_descriptor.rs (buffer_over_host_memory)`; `crates/metal2vulkan-runtime/src/heap.rs (heap_with_token)`; `crates/metal2vulkan-runtime/src/heap.rs (new_sparse_heap)`; `crates/metal2vulkan-runtime/src/heap.rs (no_copy_heap_with_token)`; `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs (new_indirect_command_buffer_now)`; `crates/metal2vulkan-runtime/src/rate_map.rs (copy_parameter_data_to_buffer)`; `crates/metal2vulkan-runtime/src/texture.rs (check_viewable)`; `crates/metal2vulkan-runtime/src/texture.rs (host_copy)`; `crates/metal2vulkan-runtime/src/texture/heap.rs (heap_layout)`; `crates/metal2vulkan-runtime/src/texture/shared.rs (new_shared_texture_now)`; `crates/metal2vulkan-runtime/src/texture/wrapped.rs (new_texture_with_vk_image)`; `crates/metal2vulkan-runtime/src/texture/wrapped.rs (new_texture_with_vk_image_plane)`; `crates/metal2vulkan-runtime/src/wrapped_buffer.rs (new_buffer_with_vk_buffer)` - `invalid::HandlerAfterCommit`: `crates/metal2vulkan-runtime/src/command_buffer/mod.rs (add_completed_handler)`; `crates/metal2vulkan-runtime/src/command_buffer/mod.rs (add_completion_seen_handler)`; `crates/metal2vulkan-runtime/src/command_buffer/mod.rs (add_scheduled_handler)`; `crates/metal2vulkan-runtime/src/command_buffer/mod.rs (add_submission_handler)`; `crates/metal2vulkan-runtime/src/executed_commands.rs (add_executed_commands_handler)` - `invalid::LengthMismatch`: `crates/metal2vulkan-runtime/src/argument_encoder.rs (set_buffers)`; `crates/metal2vulkan-runtime/src/argument_table.rs (set_buffers_with_strides)`; `crates/metal2vulkan-runtime/src/argument_table.rs (set_samplers)`; `crates/metal2vulkan-runtime/src/buffer_descriptor.rs (new_buffer_with_descriptor_now, 2 sites)`; `crates/metal2vulkan-runtime/src/render/table_facts.rs (check_samplers)`; `crates/metal2vulkan-runtime/src/render/table_facts.rs (set_buffers)`; `crates/metal2vulkan-runtime/src/sparse/mod.rs (convert_sparse_pixel_regions_now)` +- `invalid::PaddingUnobservedNoCopy`: `crates/metal2vulkan-runtime/src/buffer_descriptor.rs (new_buffer_with_descriptor_now)` - `invalid::LongTextureBufferFillPattern`: `crates/metal2vulkan-runtime/src/blit_fill.rs (check_pattern)` - `invalid::RangeOutOfBounds`: `crates/metal2vulkan-runtime/src/argument_encoder.rs (target_offset)`; `crates/metal2vulkan-runtime/src/blit.rs (out_of_bounds)`; `crates/metal2vulkan-runtime/src/managed.rs (did_modify_range)`; `crates/metal2vulkan-runtime/src/rate_map.rs (copy_parameter_data_to_buffer)` - `invalid::ShaderCacheCapacity`: `crates/metal2vulkan-runtime/src/shader_cache/mod.rs (of)`