diff --git a/AGENTS.md b/AGENTS.md index 334e065c9..7223ed3cf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -63,7 +63,7 @@ order, and a lower one never overrides a higher one. and maximal reconvergence), unified memory (decided by Vulkan's physical device type alone: one copy of a Managed buffer on an integrated or CPU device, two elsewhere, and a texture over a host-pointer import in place on an integrated or - CPU device, after one counted copy pair at its first use, and through its per-use counted copy + CPU device, after one counted copy pair at its making, and through its per-use counted copy elsewhere), the attachment feedback loop (a device without it reads a render target through a counted copy of that target, recorded as a known gap), run-time texel offsets (a device with the maintenance8 feature takes a run-time texel offset as the sampling @@ -112,7 +112,7 @@ order, and a lower one never overrides a higher one. exceptions. A texture over a Shared buffer: a linear image on that buffer's memory, in the device's own layout, created so its first use keeps the bytes, and where that memory is a host-pointer import on an integrated or CPU device (rule 2's unified memory), whose images - must start undefined, a counted copy pair once at the texture's first use restores the bytes, + must start undefined, a counted copy pair at the texture's making restores the bytes, with the alignment the guest reads from Metal's minimum linear texture alignment, and where a format query offers no linear image for the format and usage, a counted copy at commit. A plane texture of an exported diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 847724c56..4687d5205 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -857,22 +857,29 @@ discard the bytes ("If the old layout is VK_IMAGE_LAYOUT_UNDEFINED, the contents be discarded", section 7.1.1), and host memory has no other side whose release an acquire could match ("Importing memory from a host pointer shares ownership of the memory between the host and the Vulkan implementation", section 11.2.6). So the image's one move home goes between a copy of the -bytes bound under it into a Private block of the runtime's and a copy of them back, all in the -upload ahead of the first command buffer submitted after the texture's making, from any queue: a -barrier from every earlier command's writes (earlier submissions on the runtime's one queue among -them) to the save, the save, the move in a barrier that waits for the save's reads, the write-back, -and a barrier from it to every later command and the host. Nothing of the consumer's runs between -the save and the write-back. The bytes the host wrote before the commit, and those the commands -submitted before it wrote, are what the image holds after it (the save runs on the GPU after the -submission, section 7.9). The two copies count in `Metrics::over_copies_host_memory_restore` -(`OverCause::HostMemoryRestore`, a cause of their own, so that `over_copies_host_memory` counts a -copied texture's copies at its uses alone), each of the bytes bound under the image (and in `over_copies`, `over_copies_imported` and `bytes_copied`), the -block goes back once the upload retires, and the texture counts in +bytes bound under it into a Private block of the runtime's and a copy of them back, inside the +make: the make has the upload that holds them go at once, alone, in a submission of the runtime's +own, and returns once that submission completed. The upload records a barrier from every earlier +command's writes (earlier submissions on the runtime's one queue among them) to the save, the save, +the move in a barrier that waits for the save's reads, the write-back, and a barrier from it to +every later command and the host. Nothing of the consumer's runs between the save and the +write-back. The bytes the host wrote before the make, and those the commands submitted before it +wrote, are what the image holds after it (the save runs on the GPU after the submission, section +7.9), and a host write once the make returns is the program's, which no later submission from any +queue touches. Metal's make touches no bytes, and a CPU write to a Shared buffer that no pending GPU +command uses is defined; a save and write-back at a later submission would let one thread's commit +revert another thread's write. The make waits for the GPU work already submitted, so it is refused +in a scheduled handler, which runs on the submit thread (`Refusal::InScheduledHandler`). The two +copies count in `Metrics::over_copies_host_memory_restore` (`OverCause::HostMemoryRestore`, a cause +of their own, so that `over_copies_host_memory` counts a copied texture's copies at its uses alone), +each of the bytes bound under the image (and in `over_copies`, `over_copies_imported` and +`bytes_copied`), the block goes back once the upload retires, and the texture counts in `Metrics::textures_in_place_over_imports` at its making. From then on the image stays in the general layout, a host-accessible alias of the buffer (section 12.11): a later use copies nothing, and the -host and the device see each other's writes through it as through the buffer. While that upload -runs, a host write to those bytes may be lost and a host read of them may see them undefined (Known -gaps of memory blocks). On a discrete or virtual device the texture is the counted copy below, since +host and the device see each other's writes through it as through the buffer. While the make runs, +a host write to those bytes from another thread may be lost and a host read of them may see them +undefined (Known gaps of memory blocks). On a discrete or virtual device the texture is the counted +copy below, since its shaders would read the host's memory across the device's link at each use, slower there than the copy (Known gaps of memory blocks). @@ -1457,9 +1464,11 @@ exported block, an exported surface in either form, and a Direct3D 11 import. nothing: the save and the write-back of the bytes bound under its image around its move out of the undefined layout, the layout Vulkan makes such an image start in (`VUID-vkBindImageMemory-memory-02989`, `VUID-VkImageCreateInfo-pNext-01443`) and lets that move - discard the bytes. While the upload that carries the pair runs, a host write to those bytes may - be lost, which races the guest's own use of the texture, as Metal leaves it; and a host read of - them may see them undefined, where Metal would answer the bytes. In place, every read of the + discard the bytes. The make runs the pair in a submission of the runtime's own and returns once + it completed (Imported blocks), so a host write before the make, or after it returns, holds. A + host write to those bytes from another thread while the make runs may be lost, and a host read + of them then may see them undefined, where Metal's make touches no bytes; the make waits for the + GPU work already submitted, as well as for its own. In place, every read of the texture is a read of a linear image, as of any texture over a Shared buffer in place, where the copy's image is optimal. The device type chooses because of what a frame costs each way. Measured with a 1920 by 1080 RGBA8Unorm texture over host memory that the CPU writes whole each frame @@ -1471,6 +1480,8 @@ exported block, an exported surface in either form, and a Direct3D 11 import. one draw, 4810 against 5381 at four. A full 1080p read of the linear image costs about 360 more than a read of the copy's optimal image, and the copy it replaces about 480 to 500 a frame, so in place costs more from about two full reads a frame. + - AMD Radeon 780M (Phoenix), integrated (RADV, Mesa 26.2.6, job m3-max-81673): 696 against 537 + at one draw, 1025 against 793 at four (in place 0.770 and 0.774 of the copy). - AMD Radeon RX 7900 XTX, discrete on OCuLink (RADV, Mesa 26.2.6, job m3-max-81416): 1602 against 1561 at one draw, 1743 against 1579 at four, within the runs' spread: its shaders read host memory in place at the copy's own rate, about 6.7 GB/s. diff --git a/crates/metal2vulkan-runtime/src/counters.rs b/crates/metal2vulkan-runtime/src/counters.rs index 838cbef3c..636bf6bc0 100644 --- a/crates/metal2vulkan-runtime/src/counters.rs +++ b/crates/metal2vulkan-runtime/src/counters.rs @@ -663,7 +663,7 @@ pub enum OverCause { HostMemory, /// Not a copied texture: one in place over host memory's import, on an integrated or CPU /// device, whose move home comes between a save of the bytes under it and their write-back, - /// one pair of copies in the texture's life, at its first use + /// one pair of copies in the texture's life, inside its make /// ([`Metrics::over_copies_host_memory_restore`]). HostMemoryRestore, /// A dma-buf's one import that takes no image here ([`Metrics::over_copies_dma_buf`]). @@ -3214,9 +3214,10 @@ pub struct Metrics { /// The bytes of those copies, which count in [`over_copy_bytes`](Self::over_copy_bytes) too. pub over_copy_bytes_host_memory: u64, /// Of [`over_copies`](Self::over_copies), those of a texture in place over a buffer in host - /// memory's import, on an integrated or CPU device: two in the texture's life, at its first - /// use. An image made for that memory starts undefined, and its move from there may discard - /// the bytes, so the move comes between a save of the bytes under it and their write-back + /// memory's import, on an integrated or CPU device: two in the texture's life, inside its + /// make, which runs them in a submission of the runtime's own and returns once it completed. + /// An image made for that memory starts undefined, and its move from there may discard the + /// bytes, so the move comes between a save of the bytes under it and their write-back /// ([`textures_in_place_over_imports`](Self::textures_in_place_over_imports)). pub over_copies_host_memory_restore: u64, /// The bytes of those copies, which count in [`over_copy_bytes`](Self::over_copy_bytes) too. diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 4594671b1..98d0060fd 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -272,8 +272,11 @@ pub enum Refusal { /// [`Texture::upload_region`](crate::Texture::upload_region), /// [`Texture::get_bytes`](crate::Texture::get_bytes), /// [`Device::zero_block_range`](crate::Device::zero_block_range)), and the objects that take - /// an upload ([`Device::new_managed_buffer`](crate::Device::new_managed_buffer), and - /// [`Device::new_buffer`](crate::Device::new_buffer) zeroing a buffer in a Private block). + /// an upload ([`Device::new_managed_buffer`](crate::Device::new_managed_buffer), + /// [`Device::new_buffer`](crate::Device::new_buffer) zeroing a buffer in a Private block, and + /// [`Buffer::new_texture`](crate::Buffer::new_texture) and + /// [`Buffer::new_texture_in_place`](crate::Buffer::new_texture_in_place) of a texture in + /// place over host memory's import, whose make runs its restore in a submission of its own). /// Refused on every device and whatever the runtime holds: a scheduled handler runs on the /// submit thread, before its command buffer's submission, and each of these calls may wait /// for that thread to submit. On Metal (Apple M3 Max, macOS 27.0.1, the conformance probe diff --git a/crates/metal2vulkan-runtime/src/tests/host_in_place.rs b/crates/metal2vulkan-runtime/src/tests/host_in_place.rs index 2117d75b5..f942456cc 100644 --- a/crates/metal2vulkan-runtime/src/tests/host_in_place.rs +++ b/crates/metal2vulkan-runtime/src/tests/host_in_place.rs @@ -5,16 +5,16 @@ //! offers its linear image for host memory's handle (on lavapipe, every image: Mesa's //! `lvp_formats.c` answers that handle importable), the texture is in place: its image is bound in //! the import's own memory, made undefined, as an image for imported memory is -//! (`VUID-VkImageCreateInfo-pNext-01443`), and moved to the general layout once, in the upload -//! ahead of the first command buffer submitted after its making, between a save of the bytes under -//! it and their write-back: one pair of counted copies, the restore pair -//! (`Metrics::over_copies_host_memory_restore`), no other. Three command buffers, each read exact: +//! (`VUID-VkImageCreateInfo-pNext-01443`), and moved to the general layout once, inside its +//! making, in a submission of the runtime's own that the make waits for, between a save of the +//! bytes under it and their write-back: one pair of counted copies by the make's return, the +//! restore pair (`Metrics::over_copies_host_memory_restore`), no other. Three command buffers, each +//! read exact: //! //! - the CPU wrote the pages before the texture's making and again after it, before the commit, and //! a fill of one row through the buffer, committed before the making and not waited for, wrote -//! them too: a blit reads all three writes through the texture (the save runs on the GPU, after -//! the commit's submission and after every command submitted before it), and the pair is the -//! command buffer's only copies; +//! them too: a blit reads all three writes through the texture (the make's save runs on the GPU +//! after every command submitted before it), and the read counts no copy; //! - the CPU writes the pages again: a blit reads the new bytes, and no copy is counted; //! - a blit writes the texture: once the command buffer completed, the pages hold its texels at the //! pitch, every other byte as the CPU wrote it, and no copy is counted. @@ -96,7 +96,7 @@ mod on_device { } /// The restore pair's move from `before` to `after`, an in-place texture's save and - /// write-back at its first use: its copies and their bytes. + /// write-back inside its make: its copies and their bytes. fn restore_pair(before: &Metrics, after: &Metrics) -> (u64, u64) { ( after.over_copies_host_memory_restore - before.over_copies_host_memory_restore, @@ -165,6 +165,22 @@ mod on_device { u64::from(in_place), "{name}: {taken}: counted at its making" ); + if in_place { + // One save and one write-back of the bytes under the image, which hold at least + // its texels' rows and at most the import, counted as the restore pair by the + // make's return, and no other copy. + let spans = (u64::from(HEIGHT) - 1) * pitch + ROW; + let (count, bytes) = restore_pair(&start, &made); + assert_eq!( + (count, made.over_copies - start.over_copies), + (2, 2), + "{name}: the make's restore pair alone" + ); + assert!( + bytes % 2 == 0 && bytes / 2 >= spans && bytes / 2 <= len, + "{name}: the pair's bytes {bytes}, of {spans} to {len} each" + ); + } // The CPU's second bytes, after the making and before the commit. write_row(pointer, pitch, 1, 0xa5); @@ -180,22 +196,11 @@ mod on_device { "{name}: {taken}: the first read holds the fill submitted before the making" ); let after = counters.metrics(); - let pair = restore_pair(&before, &after); - let copies = after.over_copies - before.over_copies; if in_place { - // One save and one write-back of the bytes under the image, which hold at least - // its texels' rows and at most the import, counted as the restore pair, and no - // copy at a use. - let spans = (u64::from(HEIGHT) - 1) * pitch + ROW; - let (count, bytes) = pair; assert_eq!( - (count, copies, host_pair(&before, &after)), - (2, 2, (0, 0)), - "{name}: the first use's restore pair alone" - ); - assert!( - bytes % 2 == 0 && bytes / 2 >= spans && bytes / 2 <= len, - "{name}: the pair's bytes {bytes}, of {spans} to {len} each" + after.over_copies - before.over_copies, + 0, + "{name}: the first use copies nothing" ); } @@ -306,9 +311,9 @@ mod on_device { /// Vulkan's device type): on an integrated or CPU device the texture is in place (every device /// the tests run on offers the linear image of RGBA8Unorm read for host memory's handle), and /// on any other, as through the two-copy view of an integrated or CPU device, it is the counted - /// copy at each use. Two reads by a blit, each in a command buffer of its own: in place, the - /// first carries the restore pair, two copies under `OverCause::HostMemoryRestore`, and the - /// second copies nothing; copied, each copies the texels' bytes in once and nothing back, + /// copy at each use. In place, its make counts the restore pair, two copies under + /// `OverCause::HostMemoryRestore`. Two reads by a blit, each in a command buffer of its own: + /// in place, neither copies; copied, each copies the texels' bytes in once and nothing back, /// under `OverCause::HostMemory`. The texture counts in /// `Metrics::textures_in_place_over_imports` where it is in place alone. #[test] @@ -348,6 +353,7 @@ mod on_device { let made = counters.metrics(); let counted = made.textures_in_place_over_imports - start.textures_in_place_over_imports; + let restored = restore_pair(&start, &made).0; let mut reads = Vec::new(); for round in 0..2u64 { write_row(pointer, pitch, round, 0x40 + round as u8); @@ -366,18 +372,19 @@ mod on_device { } println!( "host_by_type: {name}: unified memory {unified}: in place {in_place}; \ - textures_in_place_over_imports +{counted}; per read, host-memory copies \ - (count, bytes), restore copies and all copies: {reads:?}" + textures_in_place_over_imports +{counted}; restore copies at the make \ + {restored}; per read, host-memory copies (count, bytes), restore copies and all \ + copies: {reads:?}" ); assert_eq!( - (in_place, counted), - (unified, u64::from(unified)), - "{name}: unified memory {unified}: in place and counted so" + (in_place, counted, restored), + (unified, u64::from(unified), 2 * u64::from(unified)), + "{name}: unified memory {unified}: in place, counted and restored so" ); // Host memory's copies, the restore pair's and all. let want = match unified { - // The restore pair at the first use, nothing after. - true => [(0, 2, 2), (0, 0, 0)], + // The restore pair at the make, nothing at a use. + true => [(0, 0, 0), (0, 0, 0)], // The copy in at each use, its texels' bytes, and none back. false => [(1, 0, 1), (1, 0, 1)], }; diff --git a/crates/metal2vulkan-runtime/src/tests/import.rs b/crates/metal2vulkan-runtime/src/tests/import.rs index 5e7ba0135..5c057230f 100644 --- a/crates/metal2vulkan-runtime/src/tests/import.rs +++ b/crates/metal2vulkan-runtime/src/tests/import.rs @@ -698,8 +698,8 @@ pub(crate) mod on_device { /// blit's read of it into a Shared buffer finds the host's rows, and a blit's write to it /// reaches the host's memory. In place on an integrated or CPU device where its external image /// query offers its linear image for host memory's handle (on lavapipe), its move home's save - /// and write-back are the two copies counted, both in the first command buffer, and the write - /// copies nothing; else it is the counted copy, its copies between the buffer and its image + /// and write-back are the two copies counted, both inside its make, and the read and the + /// write copy nothing; else it is the counted copy, its copies between the buffer and its image /// each its texels' bytes. Either way each copy counts in `Metrics::over_copies` and, being /// over an imported block, in `Metrics::over_copies_imported`. #[test] @@ -729,6 +729,9 @@ pub(crate) mod on_device { let mut d = TextureDescriptor::new(TextureType::Type2D, PixelFormat::RGBA8Unorm, WIDTH, HEIGHT); d.usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE; + let copies = || device.counters().metrics().over_copies; + let start = device.counters().metrics(); + let before = copies(); let texture = (buffer.new_texture(&d, Some(first), 0, pitch)) .unwrap_or_else(|error| panic!("{name}: a texture over the import: {error}")); assert_eq!( @@ -743,9 +746,6 @@ pub(crate) mod on_device { "{name}: lavapipe offers the linear image: in place" ); } - let copies = || device.counters().metrics().over_copies; - let start = device.counters().metrics(); - let before = copies(); // The host's rows, as the image's texels. let host = |at: u64| { // SAFETY: `at` is inside the imported memory, which the test still maps. diff --git a/crates/metal2vulkan-runtime/src/tests/over_causes.rs b/crates/metal2vulkan-runtime/src/tests/over_causes.rs index 09a54d90e..7bfaa5e27 100644 --- a/crates/metal2vulkan-runtime/src/tests/over_causes.rs +++ b/crates/metal2vulkan-runtime/src/tests/over_causes.rs @@ -12,8 +12,8 @@ //! cause's pair and the other class's bytes still; one in place moves nothing. On lavapipe each is //! copied for the cause it was made for: pitch (twice), alignment and render reach. The one over //! host memory's import is in place there, a CPU device whose external image query offers its -//! linear image: its move home's save and write-back, carried by a command buffer ahead of its -//! read, move the restore pair (`OverCause::HostMemoryRestore`) by two copies and no other. +//! linear image: its move home's save and write-back, which its make runs, move the restore pair +//! (`OverCause::HostMemoryRestore`) by two copies and no other. //! lavapipe's linear tiling has its optimal tiling's features for every color format (Mesa's //! `lvp_formats.c`), so no texture here is copied for a format or usage. @@ -400,20 +400,13 @@ mod on_device { .unwrap_or_else(|error| panic!("{name}: an import: {error}")); let imported = (device.new_buffer(import.id, 0, len, None)).expect("a buffer"); let usage = TextureUsage::SHADER_READ; + let counters = device.counters(); + let before = counters.metrics(); let texture = over(name, &imported, (height, usage), first + 3, (0, pitch)); - // In place, its move home's save and write-back go in the upload ahead of the - // next commit: one of its own, so that the read counts none. + let after = counters.metrics(); + // In place, its make runs its move home's save and write-back, so that the read + // counts none. if texture.copied_over().is_none() { - let counters = device.counters(); - let before = counters.metrics(); - let carrier = queue.command_buffer().expect("a command buffer"); - let mut encoder = carrier.blit_command_encoder().expect("an encoder"); - (encoder.fill_buffer(&target_buffer, 0..4, 7)) - .unwrap_or_else(|error| panic!("{name}: a fill: {error}")); - encoder.end_encoding(); - carrier.commit().expect("a commit"); - finished(name, &carrier); - let after = counters.metrics(); for (other, (copies, _)) in moved(&before, &after) { let expected = match other { OverCause::HostMemoryRestore => 2, diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 8c0832833..b54b7d729 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -1083,8 +1083,9 @@ impl Image { // the undefined layout "may" discard the bytes (Vulkan 1.4, section 7.1.1): it comes // after a copy of the range under the image into the save block and before the copy // of it back (`crate::submit::Upload::home`), so it waits for the save's reads and the - // write-back for it. From then on the image stays general, a host-accessible alias of - // the buffer (section 12.11). + // write-back for it, in the submission the make runs and waits for + // (`Device::texture`). From then on the image stays general, a host-accessible alias + // of the buffer (section 12.11). let Some(scratch) = lock(scratch).take() else { unreachable!( "an image moves home once, and its move home alone takes its save block" @@ -2264,12 +2265,31 @@ impl Device { inner: Arc::new(inner), device: self.clone(), }; + // In place over host memory's import, its move home, between the save of the bytes under + // it and their write-back, runs in a submission of the runtime's own that the make waits + // for: Metal's make touches no bytes, and a CPU write to them once the make returns is + // the program's, which no later submission, from any queue, may revert. The submit thread + // makes that submission, so the make is refused in a scheduled handler, which runs there. + let restored = matches!( + texture.inner.imaged().imported, + Some(Imported { + keep: Keep::Restore { .. }, + .. + }) + ); + if restored { + crate::command::not_in_scheduled_handler()?; + } if !unmoved { core.work.home(core, texture.inner.imaged())?; } if texture.inner.imaged().imported.is_some() { core.counters.count(Metric::TexturesInPlaceOverImports); } + if restored { + let value = core.work.flush(); + core.done.wait(core, value)?; + } // Over a Managed buffer's device copy, its buffer keeps what Metal's Managed events owe it // (`crate::over::ManagedOvers`), once the move to its home layout goes ahead of every // later commit, a capture's copy in among them. @@ -2665,13 +2685,12 @@ fn check_over( // with the host ("Importing memory from a host pointer shares ownership of the memory between // the host and the Vulkan implementation"), whose accesses are host accesses, never a release // that an acquire could match, so the move home comes between a save of the bytes and their - // write-back, one counted pair in the texture's life (`Image::homing`). On a discrete or - // virtual device, the copy at each use: its shaders would read the host's memory across the - // device's link at each use, slower than the copy (the crate's README, known gaps of memory - // blocks). Over several dma-bufs, - // the copy: the block's buffer is sparse, bound to many imports. Over an exported block, the - // copy too: its memory is dedicated to its buffer, and no image is bound in it - // (VUID-vkBindImageMemory-memory-10926). + // write-back, one counted pair in the texture's life, run inside the make (`Image::homing`, + // `Device::texture`). On a discrete or virtual device, the copy at each use: its shaders would + // read the host's memory across the device's link at each use, slower than the copy (the + // crate's README, known gaps of memory blocks). Over several dma-bufs, the copy: the block's + // buffer is sparse, bound to many imports. Over an exported block, the copy too: its memory is + // dedicated to its buffer, and no image is bound in it (VUID-vkBindImageMemory-memory-10926). let laid = match (copy, block.memory.own) { (Some(_), _) | (None, None) => Laid::Own, ( @@ -6801,16 +6820,17 @@ impl Buffer { /// Over a buffer in host memory's import ([`Device::import_host_memory`]), the image is so on /// an integrated or CPU device ([`Device::has_unified_memory`]) where the device's external /// image query takes a linear image made for host memory's handle (importable, compatible and - /// not dedicated-only): made undefined, as Vulkan requires - /// of an image for imported memory, and moved home once, in the upload ahead of the first - /// command buffer submitted after the making, from any queue, between a copy of the bytes - /// under it into a block of the runtime's and a copy of them back, since Vulkan lets a move - /// out of the undefined layout discard them: one pair of copies in the texture's life, counted - /// in + /// not dedicated-only): made undefined, as Vulkan requires of an image for imported memory, + /// and moved home once, inside the make, between a copy of the bytes under it into a block of + /// the runtime's and a copy of them back, since Vulkan lets a move out of the undefined layout + /// discard them. The make runs them in a submission of the runtime's own, after the GPU work + /// already submitted, and returns once it completed: one pair of copies in the texture's life, + /// counted in /// [`Metrics::over_copies_host_memory_restore`](crate::Metrics::over_copies_host_memory_restore) - /// ([`OverCause::HostMemoryRestore`]), and none at its later uses. While that upload runs, a host write to those bytes may be lost and a - /// host read of them may see them undefined. Metal copies nothing here. A texture in place - /// over either import counts in + /// ([`OverCause::HostMemoryRestore`]), and none at its uses. A host write to those bytes from + /// another thread while the make runs may be lost, and a host read of them then may see them + /// undefined; one before the make or after it returns holds. Metal copies nothing here. A + /// texture in place over either import counts in /// [`Metrics::textures_in_place_over_imports`](crate::Metrics::textures_in_place_over_imports). /// /// Where the device's linear image does not take the texture (another pitch, an offset off @@ -6849,7 +6869,10 @@ impl Buffer { /// number of texels, or texels past the buffer; [`Gap::TextureOverBuffer`] for a texture /// other than 2D of one level, sample and slice, or of a format of other than one color texel /// an element, or whose first texel in the bytes shaders reach is not a whole number of - /// texels in. Of a texture buffer: what Metal refuses of its descriptor + /// texels in; [`Refusal::InScheduledHandler`] in a scheduled handler for a texture in place + /// over host memory's import, whose make waits for a submission of the submit thread, and + /// [`Error::Vulkan`] where the device is lost before that submission completes. Of a texture + /// buffer: what Metal refuses of its descriptor /// ([`Refusal::TextureZeroExtent`], [`Refusal::TextureExtentForType`] for a height or depth /// other than 1, [`Refusal::TextureArrayLength`], [`Refusal::TextureSampleCount`], /// [`Refusal::TextureLevelCount`], [`Refusal::TextureSwizzleWithWrites`]); @@ -6891,7 +6914,8 @@ impl Buffer { /// passes its rows or the buffer, an import the external query does not take, a dma-buf's on /// a device without the foreign queue family, host memory's on a discrete or virtual device, /// an import over several dma-bufs, and an exported block. Such a refusal makes no texture - /// and counts no copy. + /// and counts no copy. In place over host memory's import, the make runs and waits for its + /// restore as `new_texture`'s does, refused in a scheduled handler as there. pub fn new_texture_in_place( &self, descriptor: &TextureDescriptor, diff --git a/docs/REPLAY-STREAM.md b/docs/REPLAY-STREAM.md index 122bc9237..549bfbfb6 100644 --- a/docs/REPLAY-STREAM.md +++ b/docs/REPLAY-STREAM.md @@ -644,7 +644,7 @@ contract (below) where the surface is made, and each check matches where the sta A texture over an imported buffer is in place where the runtime's linear image takes it, each frame's `textures_in_place_over_imports` counting those made, a host-memory import's (on an - integrated or CPU device alone) with one save and write-back pair at its first submission in + integrated or CPU device alone) with one save and write-back pair inside its making in `over_copies_host_memory_restore`; else it is the runtime's counted copy. Each frame's `over_copies` and `over_copy_bytes` count every copy of a texture over a buffer, and its `over_copies_imported` and `over_copy_bytes_imported` those over an imported one alone; the rest are over the runtime's own