diff --git a/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs b/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs index ca10053f9..c7033c0ae 100644 --- a/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs +++ b/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs @@ -7,18 +7,17 @@ //! places by before it answers it, and answers the failure where it does not hold: //! //! 1. the alignment is a power of two, for every query; -//! 2. for a Private query, a heap of `align + size` bytes takes a texture of the descriptor at -//! offset `align`; +//! 2. for a Private or Shared query, a heap of its storage mode, `align + size` bytes, takes a +//! texture of the descriptor at offset `align`; //! 3. there, where the runtime moves the format's bytes, level 0's first slice written from a //! buffer reads back unchanged: a `Depth32Float` slice's bytes are depths within `[0, 1]`, the //! only ones a copy into a depth aspect keeps on every device //! (`Texture::FLOAT_DEPTH_UPLOAD_NOTE`), and any other's a pattern of bytes. //! -//! A Shared, Managed or Memoryless query is held to the first alone: the runtime places a heap -//! texture in a Private block only (`Gap::HeapTexture`), and placing the descriptor in a Private -//! heap would answer another query. A query whose bytes the runtime does not move, which its copy -//! answers `Gap::TextureBytes` (depth and stencil both, or multisample) for, is held to the first -//! two. +//! A Managed or Memoryless query is held to the first alone: no heap of either mode is made, and +//! placing the descriptor in a heap of another mode would answer another query. A query whose +//! bytes the runtime does not move, which its copy answers `Gap::TextureBytes` (depth and stencil +//! both, or multisample) for, is held to the first two. use super::{waited_for, work, RtDevice, WAIT}; use crate::case::{Answer, Failure}; @@ -41,7 +40,7 @@ pub(super) fn hold( format!("step 1: the alignment {align} is not a power of two"), )); } - if query.storage != Storage::Private { + if !matches!(query.storage, Storage::Private | Storage::Shared) { return Ok(()); } let heap_size = align.checked_add(size).ok_or_else(|| { @@ -50,7 +49,7 @@ pub(super) fn hold( format!("step 2: a heap of {align} + {size} bytes"), ) })?; - let (_block, heap) = work::heap_of(on, heap_size, Storage::Private)?; + let (_block, heap) = work::heap_of(on, heap_size, query.storage)?; let index = on.texture_index(descriptor.pixel_format, descriptor.usage); let texture = (on.device.new_heap_texture(descriptor, index, heap, align)) .map_err(|error| on.failure(&error))?; diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index d7b15bab5..1c0ac98f5 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1805,16 +1805,28 @@ made, with no lock, and never rewritten for layouts. call on every queue; the copy reads the bytes when the GPU reaches it. On such a texture `replace_region` writes the named bytes and uploads them, and `get_bytes` reads the named bytes, with no submission, as Metal reads a Managed texture's CPU copy. -- A heap is a range of a Private block the consumer took at the heap's creation (`HeapRange`: - block, offset, length). `Device::heap_texture_size_and_align(descriptor)` answers Metal's +- A heap is a range of a Private or Shared block the consumer took at the heap's creation + (`HeapRange`: block, offset, length), of the heap's storage mode. An exported block holds no + heap texture (`Gap::HeapTexture`, Exported blocks). + `Device::heap_texture_size_and_align(descriptor)` answers Metal's `heapTextureSizeAndAlignWithDescriptor:` with the device's own image requirements, not Metal's: the size rounded up to, and the alignment raised to, the device's `bufferImageGranularity`, so a buffer placed by the same answers never shares a granularity page with the texture. The - answers differ by device, so the consumer places by this device's. + answers differ by device, so the consumer places by this device's. An image the device requires + an allocation of its own for, or whose memory types leave out the heap's + (`VkMemoryRequirements::memoryTypeBits`), is `Gap::HeapTexture`: at the size query, the heap the + descriptor's storage mode names (Shared's for `StorageMode::Shared`, Private's for any other); + at the placement, the block's. `Device::new_heap_texture(descriptor, index, heap, offset)` binds the texture's image at that offset in the heap, where the consumer's own placement put it: no allocation and no texture - block, the bytes those the memory holds, as Metal does not zero heap textures. Textures may - alias one another and the heap's buffers. A heap texture whose bytes another resource of its + block, the bytes those the memory holds, as Metal does not zero heap textures. In a Shared + block the image is the device's optimal image, bound in the Shared type's memory as one in a + Private block is in the Private type's. The host reaches its texels as any texture's, through + `Texture::replace_region` and `Texture::get_bytes`, whose copies go through the GPU and flush or + invalidate only their own staging bytes. The block's mapping over the image holds the device's + own layout, which Metal's texture states nothing of, so the image's range needs no flush or + invalidate of its own (Shared memory's coherence). Textures may alias one another and the + heap's buffers. A heap texture whose bytes another resource of its heap wrote since its last write moves from undefined before its next write, a GPU command's or `Texture::replace_region`'s copy (`Metrics::heap_moves`), as Vulkan's memory aliasing asks. A heap texture placed over another resource's bytes moves from undefined at its first use, and no @@ -2183,7 +2195,9 @@ made, with no lock, and never rewritten for layouts. define what it does. The UHD Graphics 630's Windows driver (101.2145) answers neither bit for any format: there a texture buffer a function writes or reads through `access::read_write` is refused, but at a slot a texture atomic updates, and - one it reads through `access::read` runs. + one it reads through `access::read` runs. No second form is built for it; that changes on a + second device above the floor whose formats lack those buffer features, or on a guest's walk + that meets the refusal on any device. - An upload into a 32-bit float depth (`Depth32Float`, or the depth of `Depth32Float_Stencil8`) by `replace_region`, `upload_region` or a blit's `copy_from_buffer` is the device's copy into the depth aspect, on every device, under the static note `PrecisionNote::RestrictedDepthUpload` @@ -2326,7 +2340,6 @@ made, with no lock, and never rewritten for layouts. - A drawable's texture (see "Presenting") has no view of another pixel format (`Gap::TextureView`), and a draw that reads it as an attachment of its own pass is `Gap::Draw` of `AttachmentRead`: the swapchain's image lists no other format and has no feedback usage. - Heap textures are placed only in Private heaps (`Gap::HeapTexture` for a Shared block). - A texture of Metal's 4:2:2 chroma-pair formats, `GBGR422` and `BGRG422`, is `Gap::TextureFormat` at every make and at `heap_texture_size_and_align`. Vulkan's 4:2:2 formats (`G8B8G8R8_422_UNORM`, `B8G8R8G8_422_UNORM`) are viewed only through a sampler Y′CbCr diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index ece3abd2e..ff7666ad6 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -1391,14 +1391,14 @@ pub enum Gap { /// A heap texture the runtime does not place /// ([`Device::new_heap_texture`](crate::Device::new_heap_texture), /// [`Device::new_heap_texture_for_views`](crate::Device::new_heap_texture_for_views) and - /// [`Device::heap_texture_size_and_align`](crate::Device::heap_texture_size_and_align)): in a - /// Shared block, or an exported one, whose memory is dedicated to its buffer + /// [`Device::heap_texture_size_and_align`](crate::Device::heap_texture_size_and_align)): in an + /// exported block, whose memory is dedicated to its buffer /// (`VUID-vkBindImageMemory-memory-10926`), or one whose image the device requires an - /// allocation of its own for, or that does not take the Private memory type. No recorded - /// stream makes a Shared heap, and every optimal image measured on the lab's devices takes - /// the Private type. + /// allocation of its own for, or that does not take the memory type of its heap's class + /// (`VkMemoryRequirements::memoryTypeBits`): the block's, or at the size query the class the + /// descriptor's storage mode names, Shared for Shared and Private for any other. /// - /// Basis: ours (heap textures are built for Private heaps of placeable images). + /// Basis: ours (heap textures are built for Private and Shared heaps of placeable images). HeapTexture { /// The texture's pixel format. pixel_format: PixelFormat, diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 83164a1b1..9a668a57e 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -1381,13 +1381,19 @@ impl Device { /// /// Err: as [`Device::new_texture`], but for the index and allocation errors; /// [`Gap::HeapTexture`] for an image the device requires an allocation of its own for, or - /// that does not take the Private memory type. + /// that does not take the memory type of the heap the descriptor's storage mode names: a + /// Shared heap's for [`StorageMode::Shared`], a Private heap's for any other. pub fn heap_texture_size_and_align( &self, descriptor: &TextureDescriptor, ) -> Result { let (requirements, dedicated) = self.heap_image_requirements(descriptor)?; - heap_fit(self.core(), descriptor, &requirements, dedicated) + // The heap the descriptor's storage mode names: Shared's, or Private's for any other. + let class = match descriptor.storage_mode { + StorageMode::Shared => MemoryClass::Shared, + _ => MemoryClass::Private, + }; + heap_fit(self.core(), descriptor, class, &requirements, dedicated) } /// The memory requirements of the device's image of `descriptor`, and whether the device @@ -1511,12 +1517,20 @@ impl Device { /// encoders' hazard sets, as a heap buffer's do ([`Device::new_heap_buffer`]). The texture /// holds the block. /// + /// The heap's block is Private or Shared, as Metal's heap is: in either, the image is the + /// device's optimal one, bound in the block's memory alike. The host reaches a Shared heap's + /// texture as any texture's, through [`Texture::replace_region`] and [`Texture::get_bytes`], + /// whose copies go through the GPU; the block's mapping over the image holds the device's own + /// layout, which Metal's texture states nothing of. On a discrete device, whose Shared memory + /// is system memory, the image's reads and writes cross the device's bus (the crate's README, + /// the known gaps of textures). + /// /// Err: as [`Device::new_texture`]; [`Error::NoSuchBlock`] for a block the consumer does not - /// hold; [`Gap::HeapTexture`] for a Shared block or an exported one - /// ([`Device::new_exported_block`](crate::Device::new_exported_block)), or as - /// [`Device::heap_texture_size_and_align`]; [`Refusal::HeapTexturePlace`] for a heap range - /// that leaves its block, or an image that does not fit in the heap at `offset` or is not - /// aligned there as the device requires. + /// hold; [`Gap::HeapTexture`] for an exported block + /// ([`Device::new_exported_block`](crate::Device::new_exported_block)), or an image the device + /// requires an allocation of its own for or that does not take the memory type of the block's + /// class; [`Refusal::HeapTexturePlace`] for a heap range that leaves its block, or an image + /// that does not fit in the heap at `offset` or is not aligned there as the device requires. pub fn new_heap_texture( &self, descriptor: &TextureDescriptor, @@ -1550,9 +1564,10 @@ impl Device { } /// The source of a texture placed at `offset` in `heap`: the heap's block, which the consumer - /// holds and which is a Private block of the pool's memory. + /// holds and which is a Private or Shared block of the pool's memory. /// - /// Err: [`Error::NoSuchBlock`]; [`Gap::HeapTexture`] for a Shared or exported block. + /// Err: [`Error::NoSuchBlock`]; [`Gap::HeapTexture`] for an exported block, whose memory is + /// dedicated to its buffer (`VUID-vkBindImageMemory-memory-10926`). fn heap_source( &self, descriptor: &TextureDescriptor, @@ -1560,7 +1575,7 @@ impl Device { offset: u64, ) -> Result, Error> { let block = self.block(heap.block)?; - if block.memory.class != MemoryClass::Private || block.memory.own.is_some() { + if block.memory.own.is_some() { return Err(Error::Unsupported(Gap::HeapTexture { pixel_format: descriptor.pixel_format, })); @@ -1847,6 +1862,7 @@ impl Device { Source::Heap(block, heap, offset) => { let bind = Bind::Heap { memory: block.memory.device_memory(), + class: block.memory.class, base: block.memory.base(), block_len: block.memory.len, heap, @@ -3526,10 +3542,11 @@ enum Bind { bytes_per_row: u64, reach: Option, }, - /// `offset` in `heap`, whose block of `block_len` bytes lies at `base` in the allocation - /// `memory`. + /// `offset` in `heap`, whose block of `block_len` bytes and of the memory class `class` lies + /// at `base` in the allocation `memory`. Heap { memory: vk::DeviceMemory, + class: MemoryClass, base: u64, block_len: u64, heap: HeapRange, @@ -3567,21 +3584,21 @@ fn image_info<'a, 'b: 'a>( } } -/// A heap texture's size and alignment from its image's `requirements`: rounded to the device's -/// buffer-image granularity, so that no buffer shares a granularity page with the image. -/// -/// `dedicated`: the device requires an allocation of its own for the image. +/// A heap texture's size and alignment from its image's `requirements`, in a heap of `class`: +/// rounded to the device's buffer-image granularity, so that no buffer shares a granularity page +/// with the image. `dedicated`: the device requires an allocation of its own for the image. /// /// Err: [`Gap::HeapTexture`] where the image requires an allocation of its own or does not take -/// the Private memory type. +/// the memory type of `class`. fn heap_fit( core: &Core, d: &TextureDescriptor, + class: MemoryClass, requirements: &vk::MemoryRequirements, dedicated: bool, ) -> Result { - let private = 1 << core.memory_type(MemoryClass::Private); - if dedicated || requirements.memory_type_bits & private == 0 { + let taken = 1 << core.memory_type(class); + if dedicated || requirements.memory_type_bits & taken == 0 { return Err(Error::Unsupported(Gap::HeapTexture { pixel_format: d.pixel_format, })); @@ -3703,6 +3720,7 @@ impl Made { (Backing::InBlock, memory, base + at) } else if let Bind::Heap { memory, + class, base, block_len, heap, @@ -3710,7 +3728,7 @@ impl Made { } = bind { let dedicated = dedicated.requires_dedicated_allocation != vk::FALSE; - let fit = heap_fit(core, d, &requirements, dedicated)?; + let fit = heap_fit(core, d, class, &requirements, dedicated)?; let refused = Error::Refused(Refusal::HeapTexturePlace { offset, size: fit.size, diff --git a/docs/API.md b/docs/API.md index 9b9f7fe90..310823f3d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2665,9 +2665,10 @@ named states the rule in full. conformance suite does not compare the two numbers with Metal's; it holds each answer to three steps: (1) the alignment is a power of two; (2) a Private descriptor's texture is made at offset `align` in a heap of `align + size` bytes; (3) there, level 0's first slice written from a buffer - reads back unchanged. A Shared, Managed or Memoryless descriptor is held to step 1 alone, as the - runtime places heap textures in Private blocks only. A descriptor whose bytes the runtime does not - move (depth and stencil both, multisample, `Depth32Float`) is held to steps 1 and 2. + reads back unchanged. A Shared descriptor is held to the same steps in a heap of a Shared block. + A Managed or Memoryless descriptor is held to step 1 alone, as no heap of either mode is made. A + descriptor whose bytes the runtime does not move (depth and stencil both, multisample, + `Depth32Float`) is held to steps 1 and 2. - **Apple's private texture usage bits are kept** in `TextureUsage` (`NO_CONCURRENT_ACCESS`, `VIDEO`, `BLOCK_WRITES_ONLY`). - **A heap's buffer and texture over the same bytes alias them, in the device's layout**, not diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 0ba3ccc05..7b1f2561b 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -364,7 +364,7 @@ Columns: | `TextureCopy` | `BlitCommandEncoder::copy_from_texture` that the floor's `vkCmdCopyImage` does not make | every device (a public call's own check of its arguments) | `ours`: Vulkan 1.3 copies none of these with one command; each is built when a replay stream makes one | 2: `crates/metal2vulkan-runtime/src/blit.rs (copy_from_texture)`, `crates/metal2vulkan-runtime/src/blit.rs (texture_copy)` | `-` | | `OverlappingCopy` | A blit copy whose source and destination share memory where no copy command orders it as from the source before the copy, which Metal leaves... | every device (a public call's own check of its arguments) | `ours`: no copy command reads bytes it writes, `VUID-vkCmdCopyImage-pRegions-00124` and its twins; rows of two pitches that cross are built, in an order of rows from where they cross, when a replay stream or a walk counts one | 2: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-runtime/src/blit.rs (copy_from_texture)` | `-` | | `TextureOverBuffer` | A texture over a buffer (`Buffer::new_texture`) the runtime does not make | every device (a public call's own check of its arguments) | `ours`: the in-place linear image and the copy form take one 2D color image, and a texture buffer's view the texel-buffer offset alignment of Vulkan 1.3 | 4: `crates/metal2vulkan-runtime/src/texture.rs (check_over)`, `crates/metal2vulkan-runtime/src/texture.rs (error)` (+2) | `-` | -| `HeapTexture` | A heap texture the runtime does not place (`Device::new_heap_texture`, `Device::new_heap_texture_for_views` and `Device::heap_texture_size_and_align`) | every device (a public call's own check of its arguments) | `ours`: heap textures are built for Private heaps of placeable images | 2: `crates/metal2vulkan-runtime/src/texture.rs (heap_fit)`, `crates/metal2vulkan-runtime/src/texture.rs (heap_source)` | `-` | +| `HeapTexture` | A heap texture the runtime does not place (`Device::new_heap_texture`, `Device::new_heap_texture_for_views` and `Device::heap_texture_size_and_align`) | every device (a public call's own check of its arguments) | `ours`: heap textures are built for Private and Shared heaps of placeable images | 2: `crates/metal2vulkan-runtime/src/texture.rs (heap_fit)`, `crates/metal2vulkan-runtime/src/texture.rs (heap_source)` | `-` | | `SurfaceUsage` | A surface plane in place (`Device::new_exported_surface`) whose texture's uses ask an image usage its linear tiling lacks (storage, for one) | at the device's limit | `device`: the image format query and the format features of the plane's tiling | 3: `crates/metal2vulkan-runtime/src/d3d11.rs (d3d11_plane_form)`, `crates/metal2vulkan-runtime/src/surface.rs (plane)` (+1) | `-` | | `D3d11SurfaceBuffer` | The buffer of a surface of Direct3D 11 textures (`Surface::buffer` of `Device::import_d3d11_surface`'s, a Windows host's) | every device (a public call's own check of its arguments) | `ours`: each plane is a Direct3D 11 texture of its own, imported into memory of its own as an optimal image, so no one memory holds the picture's bytes for a buffer | 1: `crates/metal2vulkan-runtime/src/surface.rs (buffer)` | `-` | | `BufferCopyAlignment` | `BlitCommandEncoder::copy_from_buffer` or `BlitCommandEncoder::copy_from_texture_to_buffer` whose bytes no copy command in the floor addresses,... | every device (a public call's own check of its arguments) | `ours`: Vulkan 1.3 places a copy's rows in a buffer by a count of texels from an aligned offset; each is built when a replay stream makes one | 1: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)` | `-` |