From ee21fca2f4a4eda01bdd3cf7ef84f4e8adc4d225 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 22 Oct 2026 20:45:47 +0300 Subject: [PATCH] Write Metal's bytes in texture fills and two-plane buffer blits The steps this packet landed as, in order: - Hold RGB10A2Unorm_sRGB textures with Metal's conversions - Name the runtime's gap, not a missing feature, for fetch on interlock devices - Take clippy's forms in the RGB10A2Unorm_sRGB tests - Fill multisample textures' samples as Metal's private fills write them - Check fill units only for the formats the crate holds textures of - Hold a two-plane texture's bytes between rows, which Metal's buffer blits read back - Fill texture buffers as Metal does: bytes of the buffer, the pattern streamed - Drop the multisample fill from apple_only's refusals, which fills it - Meet the rows of a two-plane buffer blit into the texture in Metal's order - Announce narrow two-plane row meetings across groups of 32 rows as one of Metal's Content: the tree of `development` at 9d3447dec9, unchanged. --- crates/metal2vulkan-runtime/src/apple_only.rs | 24 +- crates/metal2vulkan-runtime/src/blit_fill.rs | 756 ++++++++++++++---- .../metal2vulkan-runtime/src/blit_texture.rs | 19 +- .../src/command_buffer/mod.rs | 16 + .../metal2vulkan-runtime/src/degradation.rs | 67 +- crates/metal2vulkan-runtime/src/error.rs | 5 + crates/metal2vulkan-runtime/src/exactness.rs | 9 +- .../src/families/features.rs | 29 +- crates/metal2vulkan-runtime/src/fill_value.rs | 81 +- .../src/private_properties.rs | 5 +- crates/metal2vulkan-runtime/src/replay.rs | 12 +- .../metal2vulkan-runtime/src/sample_planes.rs | 134 +++- .../src/tests/apple_only.rs | 1 - .../src/tests/blit_fill.rs | 212 +++++ .../src/tests/degradation_codes.txt | 2 + .../src/tests/exactness.rs | 8 +- .../src/tests/families.rs | 8 + .../src/tests/fill_value.rs | 284 ++++++- crates/metal2vulkan-runtime/src/tests/mod.rs | 2 + .../src/tests/private_properties.rs | 6 +- .../src/tests/two_plane_rows.rs | 75 ++ .../src/tests/view_plan.rs | 32 + crates/metal2vulkan-runtime/src/texture.rs | 55 +- .../metal2vulkan-runtime/src/texture/heap.rs | 4 +- .../src/texture/wrapped.rs | 3 +- crates/metal2vulkan-runtime/src/two_planes.rs | 24 +- .../src/two_planes/buffer_rows.rs | 357 +++++++++ crates/metal2vulkan-runtime/src/view_plan.rs | 12 +- .../src/runtime_lane.rs | 8 + .../src/runtime_lane/color_fills.rs | 27 +- .../src/runtime_lane/degrade_notices.rs | 9 +- .../src/runtime_lane/heap_metal_sizes.rs | 14 +- .../src/runtime_lane/rgb10a2_srgb.rs | 657 +++++++++++++++ .../src/runtime_lane/sample_fills.rs | 534 +++++++++++++ .../src/runtime_lane/surface_fills.rs | 638 +++++++++++++++ .../src/runtime_lane/texture_buffer_fills.rs | 358 +++++++++ .../src/runtime_lane/texture_fills.rs | 77 +- .../src/runtime_lane/two_plane_copies.rs | 485 ++++++++++- crates/metal2vulkan/src/bind/unused_bits.rs | 42 +- crates/metal2vulkan/src/cache/codec.rs | 2 +- .../src/lower/arith/extended_range.rs | 73 +- .../src/lower/arith/extended_range/table.rs | 5 +- .../src/lower/arith/extended_range/tests.rs | 115 ++- .../src/lower/arith/tests/float_texel.rs | 3 +- .../src/lower/arith/tests/half_texel.rs | 2 +- .../src/lower/sampler/bicubic/routines.rs | 16 +- .../src/lower/sampler/extended.rs | 15 + crates/metal2vulkan/src/lower/texture/half.rs | 7 +- crates/metal2vulkan/src/metal/format/mod.rs | 64 +- crates/metal2vulkan/src/metal/format/tests.rs | 10 +- crates/metal2vulkan/src/metal/texel_format.rs | 69 +- .../src/pipeline/link/graphics.rs | 3 +- .../tests/engine_extended_range/samples.rs | 1 + docs/API.md | 60 +- docs/REFUSALS.md | 180 +++-- docs/RUNTIME-PORTING.md | 4 +- scripts/refusal-surface/reach.tsv | 1 - 57 files changed, 5206 insertions(+), 515 deletions(-) create mode 100644 crates/metal2vulkan-runtime/src/tests/blit_fill.rs create mode 100644 crates/metal2vulkan-runtime/src/tests/two_plane_rows.rs create mode 100644 crates/metal2vulkan-runtime/src/two_planes/buffer_rows.rs create mode 100644 crates/metal2vulkan-validation/src/runtime_lane/rgb10a2_srgb.rs create mode 100644 crates/metal2vulkan-validation/src/runtime_lane/sample_fills.rs create mode 100644 crates/metal2vulkan-validation/src/runtime_lane/surface_fills.rs create mode 100644 crates/metal2vulkan-validation/src/runtime_lane/texture_buffer_fills.rs diff --git a/crates/metal2vulkan-runtime/src/apple_only.rs b/crates/metal2vulkan-runtime/src/apple_only.rs index 17f3e7713..9f62b195d 100644 --- a/crates/metal2vulkan-runtime/src/apple_only.rs +++ b/crates/metal2vulkan-runtime/src/apple_only.rs @@ -30,11 +30,12 @@ //! Metal is not measured; //! - a texture over an IOSurface made with `kIOSurfaceClientDirection`, a key in no header of the //! public macOS SDK, refused by the IOSurface plane's stand-in -//! (`Buffer::new_texture_with_iosurface_plane`), which is no call of the table; -//! - the texture fills' cases whose answer is unmeasured (`blit_fill.rs`): a fill of a texture -//! type, region, pattern or two-plane level the probes did not cover. A color fill packed in a -//! format with no color packing, where Metal's bytes differ between processes, is built: one of -//! Metal's answers, announced as `unpacked-fill-color`. +//! (`Buffer::new_texture_with_iosurface_plane`), which is no call of the table. +//! +//! Texture fills (`blit_fill.rs`) refuse nothing here: a multisample texture's samples, a texture +//! buffer's bytes and a color packed in a format Metal packs no color in (the command buffer's +//! last packed texel, announced as `unpacked-fill-color`) are built. A multisample fill a device +//! cannot copy into the texture is refused there, `Unsupported`, as the device's gap. //! //! [`AppleOnlyCall`] is the table, and every call of it is here: the command buffer's, the //! compute, render and blit encoders', and the texture's protection options. A texture's @@ -76,16 +77,6 @@ pub enum AppleOnly { /// a surface made with value 2 (read-only), without a fault; the runtime does not model the /// key's values. SurfaceClientDirection, - /// A texture fill (`fillTexture:level:slice:region:bytes:length:` or a color form) whose - /// answer on Apple's GPU is unmeasured: a multisample texture or a texture buffer, an empty - /// pattern, a format outside the measured families (a color packed in a format the probes - /// did not fill, such as the private 10-bit, PQ and HLG formats), and a two-plane - /// extended-range texture whose fill Metal writes where the runtime holds no bytes (one of its - /// own memory at a width that is not a multiple of 4, where Metal's blit rows move texels - /// between rows; a heap's texture other than a one-level 2D one) or whose bytes Metal's blits - /// read back no rule fits (one of its own of more than one level). - /// 1D, 3D, cube and array textures and regions of several depth images are measured and built. - FillUnmeasured, } /// Why the runtime refuses an [`AppleOnly`] feature. None is a device's gap: no measured Vulkan @@ -110,8 +101,7 @@ impl AppleOnly { | Self::VertexAmplificationMode | Self::DepthCleared | Self::StencilCleared - | Self::SurfaceClientDirection - | Self::FillUnmeasured => AppleOnlyGap::Unmeasured, + | Self::SurfaceClientDirection => AppleOnlyGap::Unmeasured, } } } diff --git a/crates/metal2vulkan-runtime/src/blit_fill.rs b/crates/metal2vulkan-runtime/src/blit_fill.rs index fa4ef9859..cdb6ae0df 100644 --- a/crates/metal2vulkan-runtime/src/blit_fill.rs +++ b/crates/metal2vulkan-runtime/src/blit_fill.rs @@ -5,45 +5,104 @@ //! //! **Metal's answer** (an Apple M4 under macOS 27.0.1, our own probes; every byte of every level, //! slice and aspect read back after one fill over bytes of `0xEE`, 112 formats, one case a -//! process). A fill writes the pattern, cut at a unit's bytes or repeated to them, into every unit -//! of the region, and leaves every other byte: +//! process; and an Apple M3 Max under macOS 27.0.1, our probes `surface.m`, `tp.m`, `ds.m` and +//! `misc.m`, every byte of the surface, buffer or texture read back). A fill writes the pattern, +//! cut at a unit's bytes or repeated to them, into every unit of the region, and leaves every +//! other byte: //! - a **compressed** format's unit is a block: the region's origin and size count blocks, cut at //! the level's blocks (74 formats, PVRTC at square power-of-two extents); //! - every other format's unit is a texel, and the region counts texels, cut at the level: an //! ordinary color or depth format's texel (31 formats); a 4:2:2 format's 2 bytes (`GBGR422`, //! `BGRG422`, at bytes `2x` and `2x + 1` of a row, which the 4:2:2 copies move); a stencil -//! format's 1 byte (`Stencil8`, `X32Stencil8`); `Depth32Float_Stencil8`'s 4 depth bytes, its +//! format's 1 byte (`Stencil8`, `X32Stencil8`, an `X32_Stencil8` view's too); `Depth32Float_Stencil8`'s 4 depth bytes, its //! stencil kept; +//! - a **two-plane YCbCr** texture over a surface's plane (every one of the 24 formats the runtime +//! makes, over plane 0 of `420v` to `x444` and plane 1 of the 4:2:2 and 4:4:4 surfaces) has +//! the plane's code as its unit, 1 byte or 2 (a 10-bit code's word), at the plane's rows, the +//! other plane kept, as its blits move it; a **packed** one's (`YCBCR10_420_2P_PACKED` to +//! `YCBCR10_444_2P_PACKED_sRGB`, over `p420` to `p444`) every fill writes one zero byte at each +//! texel's `x` of its row of the plane, whatever the pattern or color; +//! - a **padded 10-bit** texture (`R10Unorm_X6`, `RG10Unorm_X12` and their `_sRGB` twins, which +//! Metal holds over memory alone) has its 2 or 4 bytes as its unit, at the buffer's or plane's +//! rows; //! - a **two-plane extended-range** texel (`RGB10A8_2P_XR10` and its sRGB twin) is its color word -//! in plane 0, 4 bytes, its alpha kept, at Metal's blit rows (`⌊4 w / 16⌋ · 16` bytes apart): +//! in plane 0, 4 bytes, its alpha kept. Metal writes row `y` of the region `⌊4 w / 16⌋ · 16` +//! bytes apart (16 below a width of 4), its texel `x` at byte `4 x` of it, `w` level 0's width: //! where a heap's bytes hold the planes (a one-level 2D texture), the fill writes those bytes -//! there, rows overlapping included. A texture of its own memory (one level, 8 and 12 texels -//! wide, a 2D array's slice too) is written at its rows when its width is a multiple of 4; at -//! another width Metal's blit rows move texels between rows and into bytes between them, which -//! the runtime does not hold, and of a texture of more than one level Metal's blits read back -//! bytes no rule fits (both refused). A texture over a surface's planes is written at its GPU -//! rows (plane 0's `bytesPerRow` rounded down to 16, the rows Metal's blits address it at) at any -//! width, its alpha plane and every byte between the rows kept (`RGB10A8_2P_XR10` over 7 surfaces -//! and the sRGB twin over one, 16, 33, 37, 61, 64 and the consumer's 384 texels wide, a region, a -//! whole texture with a 3-byte pattern and a region past the level, every byte of each surface -//! read back). +//! there, rows overlapping included. A texture of its own memory, and a heap's of more levels +//! or slices, which the runtime holds apart from the heap's bytes, takes the same bytes of +//! level 0 of the slice at any level, the region cut at the level's extent (3D: image 0): each +//! word lands on the texel of level 0's rows (`align(4 w, 16)` bytes apart) it meets, or between +//! them, which Metal's blits with a buffer read back and the runtime holds apart for a texture +//! of one level (`two_planes/buffer_rows.rs`; of more, not) (`getBytes` of every texel after fills of 1 to 37 +//! texels wide, 1 to 3 levels, arrays of 2, 1D and 3D, of its own memory and a heap's; a +//! texture's levels and slices past the first lie in bytes that overlap, which Metal's own +//! copies show and the runtime holds apart). A texture over a surface's planes is written at +//! its GPU rows (plane 0's `bytesPerRow` rounded down to 16, the rows Metal's blits address it +//! at) at any width, its alpha plane and every byte between the rows kept (`RGB10A8_2P_XR10` +//! over 7 surfaces and the sRGB twin over one, 16, 33, 37, 61, 64 and the consumer's 384 texels +//! wide, a region, a whole texture with a 3-byte pattern and a region past the level, every +//! byte of each surface read back). //! //! A **color fill** packs the color in `pixelFormat:` (the texture's own format without it) by //! the fill's own rules (`fill_value.rs`), which are not a `Clear` load action's, and fills that //! pattern: the packed texel's bytes, repeated or cut at the texture's texel (12 pairs of formats, //! 256 colors each: 128 colors packed in each of 70 formats into textures of 18 formats of 1 to 16 -//! bytes). Packed in a format whose fills do not follow the color (compressed, 4:2:2, depth, -//! stencil, two-plane, padded 10-bit), Metal's bytes are one constant -//! for every color of a process, bytes it did not write for the color, which differ between -//! processes and machines. (Refused before.) The runtime fills zero bytes there, one constant for -//! every color, and announces it once (`Degradation::UnpackedFillColor`, one of Metal's answers). +//! bytes; on the M3 Max the 88 formats Metal packs a color in, 1,144 colors each, into +//! `RGBA32Uint` texels). In every other format (213: compressed, 4:2:2, depth, stencil, +//! two-plane, YCbCr, padded, `Invalid` and the private formats) Metal packs nothing and fills +//! bytes of the calling thread's stack, the texel's bytes of a 16-byte buffer the packing writes: +//! a probe that set the stack below its call to one byte read that byte back in every texel, and +//! two consecutive color fills in one encoder find the first's packed texel there. Whether calls +//! between them keep it depends on the calling code's stack: in our probe `slot.m` an encoder's +//! end, a blit or a byte fill between them left other bytes (pointers of the process, differing +//! between processes), while the consumer's process found the first's packed texel across the +//! encoders of one command buffer. The runtime holds that buffer per command buffer, zeros at its +//! start, each color fill's packed texel over its first bytes, and fills its bytes there, as +//! Metal's consecutive fills and the consumer's encoders do; announced once +//! (`Degradation::UnpackedFillColor`). Metal's +//! validation stops such a fill ("must be a color format", "is not compatible with the texture +//! format"). //! //! **Placement** (31 cases of a byte fill of `RGBA8Unorm` textures of each type, //! every byte of every slice and level read back): a level past the texture's writes nothing; a 1D, //! 2D or 3D texture ignores the slice, a cube takes the slice's face modulo 6, and an array (1D, 2D //! or cube) writes nothing at a slice past its own; a 3D texture writes the region's depth images, //! cut at the level's depth, and every other type one image, ignoring the region's `z` and depth. A -//! texture of another type (multisample, texture buffer) is unmeasured. +//! 2D multisample texture ignores the slice, as a 2D one does, and a multisample array writes +//! nothing at a slice past its own. +//! +//! **Texture buffers** (the M3 Max, our probe `tb.m`: 1,493 cases of 5 formats of 1 to 16 bytes +//! a texel, patterns of 1 to 256 bytes and packed colors, over a 12-texel texture at offsets 0 +//! to 68 of a 512-byte buffer, every byte read back, the consumer's cases among them). A fill +//! writes bytes of the buffer, not texels: the `w · b` bytes from the texture's offset plus +//! `x · b` (`b` the texel's bytes), past the texture's width too, cut at the buffer's end; +//! the level, slice, row, height and depth change nothing (a height or depth of 0 writes the row), +//! and a width of 0 writes nothing. The pattern of `n` bytes runs across the region's bytes: byte +//! `j` of the region is `pattern[j & (n - 1)]` (the pattern repeated where `n` is a power of two; +//! `n` 3 writes `p0 p0 p2 p2`), except in each 16-byte chunk of the buffer the region covers +//! whole, which takes 16 bytes of a block from its byte `(j & (n - 1)) & !3`, `j` the chunk's +//! first. The block is the power of two of bytes at least `n` and 16, holding the pattern's whole +//! copies from its start and, past them and past the block, bytes of the calling thread's stack: +//! zeros in every probe of ours, a 9-byte fill after an 8-byte one in the same encoder too, while +//! the consumer's process read an earlier fill's bytes there. The runtime writes zeros there, +//! announced once where a chunk reads them (`Degradation::TextureBufferFillLeftover`). +//! +//! **Multisample textures** (the M3 Max, our probe `ms.m`: 32 formats at 4 samples and 11 at 2, +//! every sample of a 5 x 3 texture or 2-slice array read back through an unsigned view, as its +//! depth's bits or as its stencil): a fill writes every sample of the region's texels and no +//! other, each sample `s` its own `b` bytes (`b` the texel's, or its aspect's: the depth of +//! `Depth32Float_Stencil8`, its stencil kept). Where the `n · b` bytes of a texel's `n` samples +//! are 16 or fewer, the pattern is repeated from its start and cut at `n · b`, and sample `s` +//! takes its bytes from `s · b` (`RGBA8Unorm` at 4 samples a 16-byte pattern's 4 bytes each, +//! `R8Unorm` its first 4 bytes one each); past 16, every sample takes the pattern cut at `b` +//! (`RGBA16Float` at 4 samples, `RGBA32Float` at 2 and 4). A color fill's pattern is the packed +//! texel, which every sample then takes; packed in no format, the 16-byte buffer, which the +//! samples take a part each (`Depth32Float` at 2 and 4). Every value lands as given, a depth's +//! NaN, 2.0, -1.0 and denormal too. +//! +//! An empty pattern Metal's validation stops; plain Metal reads a unit's bytes from the pattern's +//! address all the same, which the call does not give (`Problem::EmptyFillPattern`). //! //! **`fillBuffer:range:pattern4:`** ([`BlitCommandEncoder::fill_buffer_pattern4`]; 10 ranges of a //! 256-byte buffer) writes the 4-byte pattern from the range's start, restarting it at each @@ -53,28 +112,43 @@ //! **How.** Each fill is copies the encoder already makes: a staging buffer of the pattern's units //! (4 MiB at most, copied again for a larger region) and `copy_from_buffer_to_texture` into the //! region's units of each image, so shadows, twins, carriers and two planes take their own paths; -//! a heap's two-plane texture, one copy of the color words into the heap's bytes. A pattern4 -//! fill copies its bytes from a staging buffer. Refused (`AppleOnly::FillUnmeasured`): what the -//! probes did not cover. +//! a heap's two-plane texture, one copy of the color words into the heap's bytes; a two-plane +//! texture held apart, the plane words' copy (`two_planes.rs`) into the rectangles of texels the +//! words land on; a texture buffer (its bytes before the first whole chunk, its chunks' period +//! repeated, its bytes after the last) and a packed YCbCr texture, copies into the buffer's bytes. A +//! multisample texture's samples: the sample planes' merge writes each sample's bits into a +//! multisampled image of the unsigned-integer format of the texel's size +//! (`sample_planes::BitsCopy::fill`), and a copy between multisampled textures moves the region +//! into the texture (`blit_texture.rs`): a color image's bits by an image copy, or by the sample +//! planes' copies where the device's own converts float NaNs; a depth or stencil aspect by +//! `sample_copy.rs`'s copies or draws, exact or announced as those are (`drawn-depth-copy` into a +//! 32-bit float depth whose driver's fragment depth changes values). A pattern4 fill copies its +//! bytes from a staging buffer. -use super::apple_only::AppleOnly; use super::blit::{bytes_in, reads, writes, BlitCommandEncoder}; +use super::blit_plan::BufferLayout; +use super::blit_plan::ImageCopyRegion; +use super::blit_texture; use super::chroma_pairs::{is_four_two_two, TEXEL_BYTES}; use super::clear_value::has_channels; -use super::copy_plan::{block_bytes, block_extent, level_extent, BlitOption}; -use super::error::Error; +use super::copy_plan::{ + block_bytes, block_extent, level_extent, BlitOption, CopyUnit, ImageRegion, +}; +use super::error::{internal, invalid, Error, Problem}; use super::fill_value::fill_texel; use super::heap::Heap; use super::render_values::ClearColor; use super::replay::BlitCall; +use super::sample_planes::{BitsCopy, BITS_COPY_STAGES}; use super::texture::Texture; use super::two_planes; use super::values::{Origin, Region, Size}; use super::{Buffer, Degradation}; use ash::vk; -use metal2vulkan::bind::PlaneRows; -use metal2vulkan::metal::format::{is_depth_stencil, padded_only_over_memory, ExtendedRange}; +use metal2vulkan::bind::{PlanesCopy, YCbCrCodes}; +use metal2vulkan::metal::format::{padded_only_over_memory, ycbcr_format, ExtendedRange}; use metal2vulkan::metal::{PixelFormat, TextureType}; +use metal2vulkan::vk::ImageAspectFlags; use std::ops::Range; /// The most bytes a fill stages at once: a larger region copies them again. @@ -82,17 +156,21 @@ const STAGING_BYTES: u64 = 4 << 20; /// What a fill writes into one unit of a format (the module docs). #[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum FillUnit { +pub(super) enum FillUnit { /// A compressed format's block of `bytes`, `extent` texels: the region counts blocks. Blocks { bytes: u32, extent: [u32; 2] }, /// A texel's `bytes`, which a copy with `option` writes: the region counts texels. Texels { bytes: u32, option: BlitOption }, /// A two-plane extended-range texel's color word, its alpha kept. PlaneWords, + /// A packed two-plane YCbCr texel (`YCBCR10_420_2P_PACKED`, ...): one zero byte at the + /// texel's `x` of its row of the plane, whatever the pattern. + PackedCodes, } -/// The fill unit of `pf`, `None` for a format the probes did not cover. -fn fill_unit(pf: PixelFormat) -> Option { +/// The fill unit of `pf`, `None` for a format the runtime makes no texture of (`Invalid`, the +/// private formats it holds none of, the 24-bit depth formats, which Apple GPUs make none of). +pub(super) fn fill_unit(pf: PixelFormat) -> Option { use PixelFormat as P; let texels = |bytes, option| Some(FillUnit::Texels { bytes, option }); if two_planes::holds_planes(pf) { @@ -107,6 +185,17 @@ fn fill_unit(pf: PixelFormat) -> Option { if is_four_two_two(pf) { return texels(TEXEL_BYTES, BlitOption::None); } + // A two-plane YCbCr texel is its plane's code, 1 or 2 bytes, as Metal's blits move it. + if let Some(codes) = ycbcr_format(pf).and_then(YCbCrCodes::of) { + if codes.packed { + return Some(FillUnit::PackedCodes); + } + return texels(codes.bytes, BlitOption::None); + } + // A padded 10-bit texel (a texture over memory alone) is its 2 or 4 bytes. + if padded_only_over_memory(pf) { + return texels(block_bytes(pf)?, BlitOption::None); + } match pf { P::Stencil8 => texels(1, BlitOption::None), P::X32Stencil8 => texels(1, BlitOption::StencilFromDepthStencil), @@ -114,17 +203,9 @@ fn fill_unit(pf: PixelFormat) -> Option { P::Depth16Unorm => texels(2, BlitOption::None), P::Depth32Float => texels(4, BlitOption::None), _ if has_channels(pf).is_some() => texels(block_bytes(pf)?, BlitOption::None), - // A bfloat texel's words (color fills of single texels and of 4 x 1). - _ if ExtendedRange::of(pf).is_some_and(|form| { - form.bfloat() - || matches!( - form, - ExtendedRange::Bgr10 { .. } | ExtendedRange::Bgra10 { .. } - ) - }) => - { - texels(block_bytes(pf)?, BlitOption::None) - } + // Every other extended-range texel: a bfloat or 10-bit one's words (color fills of + // single texels and of 4 x 1), `RGB10A2Unorm_sRGB`'s 4 bytes (byte fills, the M3 Max). + _ if ExtendedRange::of(pf).is_some() => texels(block_bytes(pf)?, BlitOption::None), _ => None, } } @@ -139,24 +220,191 @@ fn unit_of(pattern: &[u8], bytes: u32) -> Vec { .collect() } +/// The bits each sample of a multisampled texel of `bytes` bytes and `samples` samples takes +/// from `pattern` (the module docs): where the samples' bytes are 16 or fewer, the pattern +/// repeated from its start and cut at them, sample `s` its bytes from `s · bytes`; else each +/// sample the pattern cut at `bytes`. +pub(super) fn sample_units(pattern: &[u8], bytes: u32, samples: u32) -> Vec> { + let all = bytes * samples; + let unit = unit_of(pattern, if all <= 16 { all } else { bytes }); + let bytes = bytes as usize; + (0..samples as usize) + .map(|sample| { + let at = sample * bytes % unit.len(); + unit[at..at + bytes].to_vec() + }) + .collect() +} + +/// The texel `unit` (1, 2, 4, 8 or 16 bytes) as the words of a clear value of the +/// unsigned-integer format of its size: one zero-extended word up to 4 bytes, else its words, low +/// bytes first. +pub(super) fn words(unit: &[u8]) -> [u32; 4] { + let mut out = [0; 4]; + for (index, byte) in unit.iter().enumerate() { + out[index / 4] |= u32::from(*byte) << (8 * (index % 4)); + } + out +} + +/// The bytes Metal's fill of a texture buffer writes into its buffer's bytes `start..end` (the +/// region's texels from the texture's offset), from `pattern` of `n` bytes (the module docs): +/// byte `j` of the region (from its first) is `pattern[j & (n - 1)]`, but a 16-byte chunk of the +/// buffer the region covers whole, `j` its first byte's, takes 16 bytes of the fill's block from +/// byte `(j & (n - 1)) & !3`. The block is the power of two of bytes at least `n` and 16, holding +/// the pattern's whole copies from its start; its other bytes, and those after it, are Metal's +/// stack's, zeros in our probes, which the runtime writes. +pub(super) struct StreamFill { + pattern: Vec, + /// The block and the bytes after it, as many as a chunk may read. + memory: Vec, + /// The bytes of the pattern's whole copies at the block's start. + copies: usize, +} + +impl StreamFill { + /// The fill of `pattern` (not empty). + pub(super) fn new(pattern: &[u8]) -> StreamFill { + let block = StreamFill::block(pattern.len()); + let copies = block / pattern.len() * pattern.len(); + let mut memory: Vec = pattern.iter().copied().cycle().take(copies).collect(); + // A chunk reads 16 bytes from at most `n - 1` (rounded down to 4) into the block. + memory.resize(block + 16, 0); + StreamFill { + pattern: pattern.to_vec(), + memory, + copies, + } + } + + /// The bytes of the block of a pattern of `n` bytes: the power of two at least `n` and 16. + fn block(n: usize) -> usize { + n.next_power_of_two().max(16) + } + + /// The mask of a byte's index into the pattern. + fn mask(&self) -> u64 { + self.pattern.len() as u64 - 1 + } + + /// The whole 16-byte chunks of the buffer that `bytes` covers. + fn chunks(bytes: &Range) -> Range { + let first = bytes.start.next_multiple_of(16); + let last = bytes.end / 16 * 16; + if first < last { + first..last + } else { + bytes.end..bytes.end + } + } + + /// Byte `at` of the buffer, of the fill of `bytes`. + pub(super) fn byte(&self, bytes: &Range, at: u64) -> u8 { + let chunks = StreamFill::chunks(bytes); + let j = at - bytes.start; + if chunks.contains(&at) { + let chunk = at / 16 * 16; + let from = ((chunk - bytes.start) & self.mask()) & !3; + self.memory[(from + at % 16) as usize] + } else { + self.pattern[(j & self.mask()) as usize] + } + } + + /// Whether the fill of `bytes` writes a byte of the block past the pattern's whole copies. + pub(super) fn reads_leftover(&self, bytes: Range) -> bool { + let chunks = StreamFill::chunks(&bytes); + let period = (self.mask() + 1).next_power_of_two().max(16); + (chunks.start..chunks.end.min(chunks.start + period)) + .step_by(16) + .any(|chunk| { + let from = ((chunk - bytes.start) & self.mask()) & !3; + from as usize + 16 > self.copies + }) + } + + /// The fill of `bytes` as spans of the buffer, each with the unit it holds repeated from its + /// first byte: the bytes before the first whole chunk, the chunks (a period of them), and the + /// bytes after the last. + pub(super) fn spans(&self, bytes: Range) -> Vec<(Range, Vec)> { + let chunks = StreamFill::chunks(&bytes); + let explicit = |span: Range| { + let unit: Vec = span.clone().map(|at| self.byte(&bytes, at)).collect(); + (span, unit) + }; + if chunks.is_empty() { + return vec![explicit(bytes.clone())]; + } + // The chunks repeat every `period` bytes: `j & (n - 1)` repeats every power of two + // past `n - 1`. + let period = (self.mask() + 1).next_power_of_two().max(16); + let first = chunks.start..(chunks.start + period).min(chunks.end); + let unit: Vec = first.map(|at| self.byte(&bytes, at)).collect(); + [ + explicit(bytes.start..chunks.start), + (chunks.clone(), unit), + explicit(chunks.end..bytes.end), + ] + .into_iter() + .filter(|(span, _)| !span.is_empty()) + .collect() + } +} + /// The units `from..from + count` of an axis of `units`, cut there. fn cut(from: u64, count: u64, units: u64) -> Range { from.min(units)..from.saturating_add(count).min(units) } -/// A refusal of what the probes did not cover. -fn unmeasured() -> Error { - Error::AppleOnly(AppleOnly::FillUnmeasured) -} - -/// Whether Metal's color fills of a color packed in `pf` write bytes that do not follow the color -/// (the module docs): a compressed, 4:2:2, depth, stencil, two-plane or padded 10-bit format. -fn unpacked(pf: PixelFormat) -> bool { - block_extent(pf).is_some() - || is_four_two_two(pf) - || is_depth_stencil(pf) - || two_planes::holds_planes(pf) - || padded_only_over_memory(pf) +/// The texels of a two-plane extended-range level `width` texels wide that a fill of the units +/// `x` by `y` writes (the module docs): each row `y` written at [`two_planes::buffer_blit_rows`] apart, its +/// words landing on the texels of the level's rows `align(4 w, 16)` bytes apart, those past a row's +/// texels in the bytes between the rows. As rectangles `(x, y)` of the level, in rows that +/// ascend. +fn plane_rectangles(width: u64, x: Range, y: Range) -> Vec<(Range, Range)> { + let rows = two_planes::buffer_blit_rows(width, true); + let pitch = (4 * width).next_multiple_of(16); + // The words written, as spans of bytes of the level that ascend and do not meet. + let mut spans: Vec> = Vec::new(); + for row in y { + let span = row * rows + 4 * x.start..row * rows + 4 * x.end; + match spans.last_mut() { + Some(last) if span.start <= last.end => last.end = last.end.max(span.end), + _ => spans.push(span), + } + } + // Each row's runs of texels, in order. + let mut runs: Vec<(u64, Range)> = Vec::new(); + for span in spans { + let mut at = span.start; + while at < span.end { + let row = at / pitch; + let row_end = ((row + 1) * pitch).min(span.end); + let texels = (at - row * pitch) / 4..((row_end - row * pitch) / 4).min(width); + if !texels.is_empty() { + match runs.last_mut() { + Some((last, run)) if *last == row && texels.start <= run.end => { + run.end = run.end.max(texels.end); + } + _ => runs.push((row, texels)), + } + } + at = row_end; + } + } + // Consecutive rows of one run each, the same, make one rectangle. + let mut out: Vec<(Range, Range)> = Vec::new(); + for (i, (row, run)) in runs.iter().enumerate() { + let alone = |j: usize| runs.iter().filter(|(r, _)| *r == runs[j].0).count() == 1; + if let Some((columns, rows)) = out.last_mut() { + if alone(i) && rows.end == *row && columns == run && i > 0 && alone(i - 1) { + rows.end += 1; + continue; + } + } + out.push((run.clone(), *row..row + 1)); + } + out } /// Where a fill of `region` at `level` and `slice` of `texture` writes, as plain Metal places it @@ -168,14 +416,6 @@ fn placement( region: Region, ) -> Result)>, Error> { let record = texture.record(); - if matches!( - texture.texture_type(), - TextureType::Type2DMultisample - | TextureType::Type2DMultisampleArray - | TextureType::TextureBuffer - ) { - return Err(unmeasured()); - } let Some(level) = u32::try_from(level) .ok() .filter(|&level| level < record.level_count) @@ -184,7 +424,7 @@ fn placement( }; let slices = u64::from(record.layer_count); let (slice, images) = match texture.texture_type() { - TextureType::Type1D | TextureType::Type2D => (0, 0..1), + TextureType::Type1D | TextureType::Type2D | TextureType::Type2DMultisample => (0, 0..1), TextureType::Type3D => { let depth = u64::from(level_extent(record, level)[2]); (0, cut(region.origin.z, region.size.depth, depth)) @@ -193,7 +433,6 @@ fn placement( TextureType::Type1DArray | TextureType::Type2DArray | TextureType::CubeArray - | TextureType::Type2DMultisample | TextureType::Type2DMultisampleArray | TextureType::TextureBuffer => { if slice >= slices { @@ -211,18 +450,28 @@ impl BlitCommandEncoder { /// unit's bytes, as plain Metal writes it (`blit_fill.rs`). A compressed format's unit is a /// block, and the region's origin and size count blocks; every other format's is a texel (a /// 4:2:2 format's 2 bytes, a stencil format's 1, the depth of `Depth32Float_Stencil8`, a - /// two-plane extended-range texel's color word). The region is cut at the level; an empty one - /// writes nothing. + /// two-plane YCbCr texture's plane code, a two-plane extended-range texel's color word). A + /// packed two-plane YCbCr texture's texels each take one zero byte, whatever the pattern. The + /// region is cut at the level, and an empty one writes nothing, but a texture buffer's (below). /// /// Placed as plain Metal places it (the module docs): a level past the texture's, or a slice /// past an array's, writes nothing; a 1D, 2D or 3D texture ignores the slice and a cube takes - /// it modulo 6; a 3D texture writes the region's depth images, every other type one image. + /// it modulo 6; a 3D texture writes the region's depth images, every other type one image; a + /// texture buffer's fill writes its buffer's bytes from the region's first texel, as many as + /// its texels', past the texture's width and cut at the buffer's end, whatever the level, + /// slice, row, height and depth, the pattern running across them, not started again at each + /// texel (`texture-buffer-fill-leftover` where Metal's bytes are its stack's). A two-plane + /// extended-range texture's rows are Metal's fill rows, and a level past its first writes level + /// 0, as Metal's fills do. A multisample texture's samples each take their own bytes of the + /// pattern where a texel's samples hold 16 bytes or fewer, else the pattern cut at the texel + /// (the module docs). /// - /// Refused: a texture of another device (`Invalid`); `AppleOnly::FillUnmeasured`, what the - /// probes did not cover: a multisample texture or a texture buffer, an empty pattern, a - /// format outside the measured families (the module docs), and a two-plane texture other - /// than a heap's one-level 2D one, one over a surface's planes, or a one-level texture of its - /// own a multiple of 4 wide. + /// Refused: a texture of another device (`Invalid`), and an empty pattern + /// (`Invalid(EmptyFillPattern)`), which Metal's validation stops and whose bytes plain Metal + /// reads from past the call's. A multisample texture's fill is refused, `Unsupported`, where + /// the device cannot run the sample planes' merge (sample-rate shading, the sample count among + /// its integer color attachments') or the copy into the texture (`copy_from_texture`'s + /// refusals of copies between multisampled textures). pub fn fill_texture( &mut self, texture: &Texture, @@ -248,13 +497,13 @@ impl BlitCommandEncoder { /// even, an integer channel's NaN is 0 or the extreme by its kind, and the extended-range /// formats are packed. /// - /// A color packed in a format whose fills do not follow the color (compressed, 4:2:2, depth, - /// stencil, two-plane, padded 10-bit) fills zero bytes, one constant for every color, as - /// Metal's fills write one constant of their process's there, and the device announces - /// `Degradation::UnpackedFillColor` once. + /// A color packed in a format Metal packs no color in (compressed, 4:2:2, depth, stencil, + /// two-plane, YCbCr, padded 10-bit, `Invalid`, the private formats) fills the command buffer's + /// last color fill's packed texel, over zeros at its start (the module docs): Metal fills bytes + /// of the calling thread's stack there, which hold that texel only where no other call used + /// them since. The device announces `Degradation::UnpackedFillColor` once. /// - /// Refused as [`fill_texture`] refuses; `AppleOnly::FillUnmeasured` for a color packed in a - /// format whose fills the probes did not cover. + /// Refused as [`fill_texture`] refuses. /// /// [`fill_texture`]: BlitCommandEncoder::fill_texture pub fn fill_texture_color( @@ -266,38 +515,36 @@ impl BlitCommandEncoder { color: ClearColor, pixel_format: Option, ) -> Result<(), Error> { - self.log(|_| { - BlitCall::FillTextureColor(Box::new(( - texture.clone(), - level, - slice, - region, - color, - pixel_format, - ))) - }); const CALL: &str = "fill_texture_color"; - self.core().check_device(CALL, texture.device())?; let packed_in = pixel_format.unwrap_or(texture.pixel_format()); let channels = [color.red, color.green, color.blue, color.alpha]; - if let Some(pattern) = fill_texel(packed_in, channels) { - return self.fill(CALL, texture, (level, slice), region, &pattern); + // The texel, which the command buffer's slot takes; else the slot's bytes. + let texel = fill_texel(packed_in, channels); + let slot = self.core().command_buffer().fill_slot(texel.as_deref()); + let pattern = texel.clone().unwrap_or(slot.to_vec()); + // Logged as the bytes it fills, which a call encoded again fills again. + self.log(|log| { + BlitCall::FillTexture( + Box::new((texture.clone(), level, slice, region)), + log.byte_span(&pattern), + ) + }); + self.fill(CALL, texture, (level, slice), region, &pattern)?; + if texel.is_none() { + let format = texture.pixel_format(); + self.core() + .device() + .degrade(Degradation::UnpackedFillColor, || { + ( + format!("a color fill of a {format:?} texture, packed in {packed_in:?}"), + "Metal packs no color there and fills bytes of the calling thread's \ + stack, which hold the last color fill's packed texel only where no \ + other call used them since; the runtime fills the command buffer's last \ + color fill's packed texels, over zeros" + .to_owned(), + ) + }); } - if !unpacked(packed_in) { - return Err(unmeasured()); - } - self.fill(CALL, texture, (level, slice), region, &[0])?; - let format = texture.pixel_format(); - self.core() - .device() - .degrade(Degradation::UnpackedFillColor, || { - ( - format!("a color fill of a {format:?} texture, packed in {packed_in:?}"), - "Metal's fills there write one constant of its process's for every color; \ - the runtime fills zero bytes" - .to_owned(), - ) - }); Ok(()) } @@ -382,11 +629,14 @@ impl BlitCommandEncoder { self.core().check_device(call, texture.device())?; self.see(texture); if pattern.is_empty() { - return Err(unmeasured()); + return Err(invalid(call, Problem::EmptyFillPattern)); + } + let unit = fill_unit(texture.pixel_format()) + .ok_or_else(|| internal("a fill of a format the runtime makes no texture of"))?; + // A texture buffer's fill writes one row whatever the region's height and depth. + if texture.texture_type() == TextureType::TextureBuffer { + return self.texture_buffer_fill(texture, unit, region, pattern); } - let Some((slice, images)) = placement(texture, level, slice, region)? else { - return Ok(()); - }; let Size { width, height, @@ -395,13 +645,16 @@ impl BlitCommandEncoder { if width == 0 || height == 0 || depth == 0 { return Ok(()); } - let unit = fill_unit(texture.pixel_format()).ok_or_else(unmeasured)?; - let level_u32 = u32::try_from(level).map_err(|_| unmeasured())?; + let Some((slice, images)) = placement(texture, level, slice, region)? else { + return Ok(()); + }; + let level_u32 = u32::try_from(level).map_err(|_| internal("a fill's level"))?; let [w, h, _] = level_extent(texture.record(), level_u32).map(u64::from); let (bytes, extent, option) = match unit { FillUnit::Blocks { bytes, extent } => (bytes, extent, BlitOption::None), FillUnit::Texels { bytes, option } => (bytes, [1, 1], option), FillUnit::PlaneWords => (4, [1, 1], BlitOption::None), + FillUnit::PackedCodes => (1, [1, 1], BlitOption::None), }; let [bw, bh] = extent.map(u64::from); let x = cut(region.origin.x, width, w.div_ceil(bw)); @@ -409,18 +662,19 @@ impl BlitCommandEncoder { if x.is_empty() || y.is_empty() { return Ok(()); } + if texture.record().samples > 1 { + return self.sample_fill(call, texture, (level_u32, slice), option, (x, y), pattern); + } let unit_bytes = unit_of(pattern, bytes); + if unit == FillUnit::PackedCodes { + return self.packed_code_fill(texture, (x, y)); + } if unit == FillUnit::PlaneWords && !texture.over_buffer() { if let Some((heap, at)) = texture.heap_planes() { return self.plane_heap_fill(texture, (heap, at), w, (x, y), &unit_bytes); } - // Metal's fill rows are its blits' (`⌊4 w / 16⌋ · 16` bytes apart), the texture's own - // only at a width that is a multiple of 4; of a texture of more than one level, its - // blits read back bytes no rule fits. - if texture.heap().is_some() || texture.mipmap_level_count() > 1 || !w.is_multiple_of(4) - { - return Err(unmeasured()); - } + // Every level is filled as level 0, at Metal's fill rows (the module docs). + return self.plane_texel_fill(texture, slice, (x, y), &unit_bytes); } self.fill_rows( texture, @@ -432,6 +686,78 @@ impl BlitCommandEncoder { ) } + /// The fill of `pattern` into the texels `x` by `y` of the multisampled `texture`'s `level` + /// and `slice`, in the aspect `option` names (the module docs): each sample its own bits + /// ([`sample_units`]), written by the sample planes' merge into a multisampled image of the + /// unsigned-integer format of the texel's size ([`BitsCopy::fill`]), which a blit copy then + /// moves into the texture's region as a copy between multisampled textures moves it + /// (`blit_texture.rs`: an image copy, the planes' copies where the device's copy converts + /// float NaNs, a depth or stencil aspect's copies or draws, `sample_copy.rs`, exact or + /// announced as there). + fn sample_fill( + &mut self, + call: &'static str, + texture: &Texture, + (level, slice): (u32, u64), + option: BlitOption, + (x, y): (Range, Range), + pattern: &[u8], + ) -> Result<(), Error> { + let record = texture.record(); + let samples = record.samples; + let CopyUnit { bytes, aspect, .. } = blit_texture::unit(call, texture, option)?; + let copy = match bytes { + 1 => PlanesCopy::R8, + 2 => PlanesCopy::R16, + 4 => PlanesCopy::R32, + 8 => PlanesCopy::Rg32, + 16 => PlanesCopy::Rgba32, + _ => { + return Err(internal( + "a multisampled texel of no unsigned format's size", + )) + } + }; + let values: Vec<[u32; 4]> = sample_units(pattern, bytes, samples) + .iter() + .map(|unit| words(unit)) + .collect(); + let narrow = |range: &Range| -> Result<[u32; 2], Error> { + let start = u32::try_from(range.start).map_err(|_| internal("a fill's origin"))?; + let end = u32::try_from(range.end).map_err(|_| internal("a fill's extent"))?; + Ok([start, end - start]) + }; + let ([left, width], [top, height]) = (narrow(&x)?, narrow(&y)?); + let (scratch, fill) = BitsCopy::fill( + self.core().command_buffer(), + copy, + &values, + [left, top], + [width, height], + )?; + self.command_in(BITS_COPY_STAGES, &fill.uses, |device, raw| { + // SAFETY: the encoder's command buffer is recording outside a render pass; the + // scratch image and the fill's planes and objects are live until it completes + // (retained below). + unsafe { fill.record(device, raw) }; + })?; + self.core().retain(vec![fill]); + let slice = u32::try_from(slice).map_err(|_| internal("a fill's slice"))?; + let region = |aspect, level, layer| ImageRegion { + aspect, + level, + layer, + layers: 1, + origin: [left, top, 0], + size: [width, height, 1], + }; + let copy = ImageCopyRegion { + src: region(ImageAspectFlags::COLOR, 0, 0), + dst: region(aspect, record.base_level + level, record.base_layer + slice), + }; + self.texture_copies(call, &scratch, texture, &[copy]) + } + /// Copy `unit` into the units `x` by `y` of each depth image `images` of `texture`'s `level` /// and `slice`, `block` texels each (cut at the level's `size`), through `option`: copies /// from one staging buffer of whole rows of units, in rows of at most `STAGING_BYTES`. @@ -476,7 +802,7 @@ impl BlitCommandEncoder { } /// Write `word` at each texel `x` by `y` of the one-level two-plane `texture` of `width` - /// texels whose planes lie in `heap`'s bytes from byte `at`, at Metal's blit rows: the + /// texels whose planes lie in `heap`'s bytes from byte `at`, at Metal's fill rows: the /// texels' color words, rows that meet merged, in one copy into the heap's bytes. Its alpha /// bytes are not written. fn plane_heap_fill( @@ -488,56 +814,214 @@ impl BlitCommandEncoder { word: &[u8], ) -> Result<(), Error> { let Some(bytes) = heap.bytes() else { - return Err(unmeasured()); + return Err(internal("a two-plane texture's bytes in a heap of none")); }; - let width = u32::try_from(width).map_err(|_| unmeasured())?; - let blit = u64::from(PlaneRows::of(width).blit); - // Each row's words, from byte `at + row * blit + 4 x`; rows ascend, so a row that meets + let rows = two_planes::buffer_blit_rows(width, true); + // Each row's words, from byte `at + row * rows + 4 x`; rows ascend, so a row that meets // the one before extends it. let mut spans: Vec> = Vec::new(); for row in y { - let span = at + row * blit + 4 * x.start..at + row * blit + 4 * x.end; + let span = at + row * rows + 4 * x.start..at + row * rows + 4 * x.end; match spans.last_mut() { Some(last) if span.start <= last.end => last.end = last.end.max(span.end), _ => spans.push(span), } } + self.fill_spans(bytes, &spans, word)?; + self.core().retain(texture.clone()); + Ok(()) + } + + /// Write `unit` repeated from each span's first byte into the bytes `spans` of `buffer` + /// (ascending, disjoint), in one command of copies from a staging buffer. + fn fill_spans( + &mut self, + buffer: &Buffer, + spans: &[Range], + unit: &[u8], + ) -> Result<(), Error> { let (Some(first), Some(last)) = (spans.first(), spans.last()) else { return Ok(()); }; let written = first.start..last.end; - // Every span starts on a word (the texture's place and `blit` are multiples of 4) and is - // whole words long, so the staging buffer's words land on them. + // A staging buffer of whole units, so each copy from its start begins the unit again. let longest = spans.iter().map(|s| s.end - s.start).max().unwrap_or(0); - let length = longest.min(STAGING_BYTES); - let staging = self.staging(word, length)?; + let whole = unit.len() as u64; + let length = longest.min((STAGING_BYTES / whole).max(1) * whole); + let staging = self.staging(unit, length)?; let (source, from) = staging.at(0); - let (destination, _) = bytes.at(written.start); + // Read as a blit's (`host_residency.rs`). + let (destination, base) = self.core().blit_at(buffer, written.start)?; let mut regions = Vec::new(); - for span in &spans { + for span in spans { let mut start = span.start; while start < span.end { let size = (span.end - start).min(length); regions.push(vk::BufferCopy { src_offset: from, - dst_offset: bytes.at(start).1, + dst_offset: base + (start - written.start), size, }); start += size; } } - let uses = [reads(&staging, 0..length), writes(bytes, written)]; + let uses = [reads(&staging, 0..length), writes(buffer, written)]; self.command(&uses, |device, raw| { // SAFETY: the encoder's command buffer is recording; the staging buffer and the - // heap's bytes are live and retained until it completes; each region lies inside - // both, and the heap's regions are disjoint. + // buffer are live and retained until it completes; each region lies inside both, + // and the buffer's regions are disjoint. unsafe { device.cmd_copy_buffer(raw, source, destination, ®ions) }; })?; self.core().retain(staging); + self.core().retain(buffer.clone()); + Ok(()) + } + + /// Write `pattern` into the bytes of the texture buffer `texture`'s buffer that the texels `x` + /// to `x + width` of `region` cover from its offset, past its width too (cut at the buffer's + /// end), whatever the level, slice, row, height and depth, as Metal writes them + /// ([`StreamFill`]; the module docs): a width of 0 writes nothing. + fn texture_buffer_fill( + &mut self, + texture: &Texture, + unit: FillUnit, + region: Region, + pattern: &[u8], + ) -> Result<(), Error> { + let FillUnit::Texels { bytes, .. } = unit else { + return Err(internal("a texture buffer of no texel format")); + }; + let Some(texels) = texture.buffer_texels() else { + return Err(internal("a texture buffer over no buffer")); + }; + let buffer = texels.buffer.clone(); + let bytes = u64::from(bytes); + let length = buffer.length(); + let start = texels + .layout + .offset + .saturating_add(region.origin.x.saturating_mul(bytes)) + .min(length); + let end = start + .saturating_add(region.size.width.saturating_mul(bytes)) + .min(length); + if start >= end { + return Ok(()); + } + let stream = StreamFill::new(pattern); + for (span, unit) in stream.spans(start..end) { + self.fill_spans(&buffer, &[span], &unit)?; + } + if stream.reads_leftover(start..end) { + let format = texture.pixel_format(); + self.core() + .device() + .degrade(Degradation::TextureBufferFillLeftover, || { + ( + format!( + "a fill of a {format:?} texture buffer with a pattern of {} bytes", + pattern.len() + ), + "Metal reads bytes of its stack past the pattern's whole copies there, \ + zeros in our probes and other bytes in other processes; the runtime \ + reads zeros" + .to_owned(), + ) + }); + } self.core().retain(texture.clone()); Ok(()) } + /// Fill the texels `x` by `y` of a packed two-plane YCbCr `texture` over a surface's plane: + /// one zero byte at each texel's `x` of its row of the plane (the module docs). + fn packed_code_fill( + &mut self, + texture: &Texture, + (x, y): (Range, Range), + ) -> Result<(), Error> { + let Some(texels) = texture.buffer_texels() else { + return Err(internal("a packed two-plane texture over no surface")); + }; + let (offset, pitch) = (texels.layout.offset, texels.layout.row_pitch); + let spans: Vec> = y + .map(|row| offset + row * pitch) + .map(|start| start + x.start..start + x.end) + .collect(); + let buffer = texels.buffer.clone(); + self.fill_spans(&buffer, &spans, &[0])?; + self.core().retain(texture.clone()); + Ok(()) + } + + /// Write `word` at the texels of level 0 of `slice` of the two-plane extended-range `texture` + /// (of its own memory, or a heap's held apart) that a fill of the units `x` by `y` of any of + /// its levels writes (the module docs): copies of the color words alone, at Metal's fill + /// rows mapped onto the texels' rows. + fn plane_texel_fill( + &mut self, + texture: &Texture, + slice: u64, + (x, y): (Range, Range), + word: &[u8], + ) -> Result<(), Error> { + let [width, height, _] = level_extent(texture.record(), 0).map(u64::from); + let layer = u32::try_from(slice).map_err(|_| internal("a fill's slice"))?; + // The words a fill writes between the level's rows: held where its blits with a buffer + // read them back (one level, `two_planes::rows_held`), as the rows of plane 0 Metal's + // fill writes, rows that meet merged; else not held, noted, so a blit that reads them + // back announces it (`two_planes.rs`). + let size = [x.end - x.start, y.end - y.start]; + let spans = two_planes::row_spans(width, [x.start, y.start], size, true); + if spans + .iter() + .flatten() + .any(|span| two_planes::between_rows(span, width)) + { + if two_planes::rows_held(texture) { + let held = self.held_between_rows(texture, [width, height])?; + let base = slice * height * (4 * width).next_multiple_of(16); + let mut merged: Vec> = Vec::new(); + for span in spans.into_iter().flatten() { + let span = base + span.start..base + span.end; + match merged.last_mut() { + Some(last) if span.start <= last.end => last.end = last.end.max(span.end), + _ => merged.push(span), + } + } + self.fill_spans(&held, &merged, word)?; + } else { + texture.keep_outside(); + } + } + for (columns, rows) in plane_rectangles(width, x, y) { + let w = columns.end - columns.start; + let per_copy = (STAGING_BYTES / (4 * w)).clamp(1, rows.end - rows.start); + let staging = self.staging(word, 4 * w * per_copy)?; + let mut row = rows.start; + while row < rows.end { + let end = (row + per_copy).min(rows.end); + let region = ImageRegion { + aspect: ImageAspectFlags::COLOR, + level: 0, + layer, + layers: 1, + origin: [columns.start, row, 0].map(|v| v as u32), + size: [w, end - row, 1].map(|v| v as u32), + }; + let layout = BufferLayout { + offset: 0, + bytes_per_row: 4 * w, + bytes_per_image: 4 * w * (end - row), + }; + self.plane_words_copy(&staging, texture, ®ion, &layout, true)?; + row = end; + } + self.core().retain(staging); + } + Ok(()) + } + /// A `Shared` buffer of `length` bytes of `unit` repeated, the source of a fill's copies. fn staging(&mut self, unit: &[u8], length: u64) -> Result { let bytes: Vec = unit.iter().copied().cycle().take(length as usize).collect(); diff --git a/crates/metal2vulkan-runtime/src/blit_texture.rs b/crates/metal2vulkan-runtime/src/blit_texture.rs index 8ae269141..7d58322c0 100644 --- a/crates/metal2vulkan-runtime/src/blit_texture.rs +++ b/crates/metal2vulkan-runtime/src/blit_texture.rs @@ -218,7 +218,11 @@ fn multisampled_texels(region: &TextureRegion) -> Written { } /// The copy unit of `texture` copied with `option`. -fn unit(call: &'static str, texture: &Texture, option: BlitOption) -> Result { +pub(super) fn unit( + call: &'static str, + texture: &Texture, + option: BlitOption, +) -> Result { // A texture over a buffer holds a colour format (`linear_plan.rs`): its copy unit is its // texel, whatever holds it. if texture.over_buffer() { @@ -714,9 +718,13 @@ impl BlitCommandEncoder { ))); } // At a width that is not a multiple of 4 Metal's blit addresses the level's rows short of - // where they lie, moving texels between rows: announced, the texels moved as `getBytes` - // and `replaceRegion` move them. + // where they lie, moving texels between rows: at those rows for a 2D texture or array of + // one level (`two_planes/buffer_rows.rs`); for another (more levels, a view, 1D, 3D, a + // surface's), announced, the texels moved as `getBytes` and `replaceRegion` move them. let width = level_extent(texture.record(), region.level)[0]; + if !width.is_multiple_of(4) && two_planes::rows_held(texture) { + return self.plane_rows_copy(buffer, texture, &image, layout, into_texture); + } if !width.is_multiple_of(4) { let pf = texture.pixel_format(); self.core() @@ -726,7 +734,8 @@ impl BlitCommandEncoder { "`{call}` between a buffer and a {} texture level {width} texels wide", pf.name() ); - let reason = "the texels move at the rows the texture holds them in, where \ + let reason = "a texture of more than one level, a view, a 1D or 3D texture or a surface's: \ + the texels move at the rows the texture holds them in, where \ Metal's blit addresses its rows floor(4w/16)*16 bytes apart, \ short of them, and so moves texels between rows" .to_owned(); @@ -1145,7 +1154,7 @@ impl BlitCommandEncoder { /// buffer of the encoder out of the image the source's texels are read from. So out of a /// texture with a twin into a depth texture without one they read its twin, and into it from a /// depth texture they write its twin directly and its image through the buffer. - fn texture_copies( + pub(super) fn texture_copies( &mut self, call: &'static str, source: &Texture, diff --git a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs index bb0fdc56c..49884bae8 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs @@ -219,6 +219,10 @@ pub(super) struct CommandBufferShared { /// from `UNDEFINED` to `GENERAL` (`texture/first_move.rs`). Apart from the state, so a texture /// is made under no lock of the command buffer's. own_textures: Mutex>, + /// The bytes a color fill of a color Metal packs no color in writes (`blit_fill.rs`): the + /// last color fill's packed texel over the ones before, from zeros. Apart from the state, + /// as `own_textures`. + fill_slot: Mutex<[u8; 16]>, /// Rebinds since its commit, of buffers its replayable encoders named, whose encoders are /// not yet encoded again (`reencode.rs`): its first submission waits until none is. Raised /// under the device's lock of its buffers over host pages (`Rebinds::replace`), which its @@ -1677,6 +1681,7 @@ impl CommandBuffer { relayed: Arc::default(), step_numbers: OnceLock::new(), own_textures: Mutex::new(Vec::new()), + fill_slot: Mutex::new([0; 16]), reencode: AtomicU64::new(0), reencoding: Mutex::new(()), raws_ended: AtomicU64::new(0), @@ -1692,6 +1697,17 @@ impl CommandBuffer { &self.0.device } + /// The color fill slot (`fill_slot`), after a color fill packed `packed` (`None` for one + /// that packs nothing): its first bytes become the texel's. + pub(super) fn fill_slot(&self, packed: Option<&[u8]>) -> [u8; 16] { + let mut slot = lock(&self.0.fill_slot); + if let Some(texel) = packed { + let n = texel.len().min(slot.len()); + slot[..n].copy_from_slice(&texel[..n]); + } + *slot + } + /// Hold `texture`, which one of its encoders made for its own commands, as its /// `own_textures` says. pub(super) fn hold_own_texture(&self, texture: Texture) { diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index dc0fea9c7..3fe59fbd3 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -1175,7 +1175,8 @@ degradations! { Metal keeps"; /// A draw in a render pass that loads a color attachment of an extended-range or padded /// 10-bit format (`BGR10_XR`, `BGRA10_XR`, `RGB10A8_2P_XR10`, `R10Unorm_X6`, - /// `RG10Unorm_X12` and their sRGB twins) and does not discard it at the store, where the + /// `RG10Unorm_X12` and their sRGB twins, and `RGB10A2Unorm_sRGB`) and does not discard it + /// at the store, where the /// pass's load pass (`render/unused_bits_load.rs`) does not take it (`render.rs`): a /// multisampled attachment, a texture held as a shadow of another image or of a heap's /// bytes, a sparse one, or one whose image the device does not copy both ways (a padded @@ -1230,16 +1231,37 @@ degradations! { draw reaches: a texel whose bytes no Metal write left (uploaded or copied words) \ keeps a word Metal's pass would change, of the same value"; /// A blit between a buffer and a level of `RGB10A8_2P_XR10` or its sRGB twin whose width - /// is not a multiple of 4 (`two_planes.rs`): it moves the texels at the rows the texture - /// holds them in, where Metal's blit addresses the level's rows `⌊4 w / 16⌋ · 16` bytes - /// apart, short of its rows, and so moves texels into and out of other rows (into the - /// texture overlapping rows, in an order that varies). + /// is not a multiple of 4 (`two_planes.rs`), where Metal's blit addresses the level's rows + /// `⌊4 w / 16⌋ · 16` bytes apart, short of where they lie, and so moves texels into and + /// out of other rows and the bytes between them. A 2D texture or array of one level is + /// blitted at Metal's rows (`two_planes/buffer_rows.rs`), the row whose bytes Metal's GPU + /// leaves where two meet standing; announced here are a blit into a texture 32 texels wide + /// or wider whose rows meet, which keeps the earlier row's bytes where Metal's GPU writes + /// the two in an order that varies from run to run (narrower, `two-plane-buffer-blit-order`), + /// and a blit out of a texture of the + /// device's memory that reads bytes between its rows after a copy from another texture + /// wrote some there, which reads them as its fills and blits with a buffer left them (held + /// apart, `Texture::between_rows`). Any other such texture (more levels, a view, 1D, 3D, + /// a surface's) moves the texels at the rows the texture holds them in, announced. TwoPlaneBufferBlit = "two-plane-buffer-blit", Precision, - "the texels move between the buffer's rows and the texture's as getBytes and \ - replaceRegion move them; Metal's blit addresses the texture's rows floor(4w/16)*16 \ - bytes apart where they lie align(4w,16) bytes apart, so out of the texture it reads \ - texels of earlier rows and padding (0) into later rows of the buffer, and into it \ - writes rows over each other in an order that varies"; + "where rows meet in a blit into a texture 32 texels wide or wider the earlier row's \ + bytes stand, where Metal's GPU writes them in an order that varies from run to run, \ + at some sizes never all the earlier row's; a blit out of a \ + texture of the device's memory reads the bytes between its rows that a copy from \ + another texture wrote as its fills and blits with a buffer left them, where Metal's \ + reads the copy's back; and a texture of more than one level, a \ + view, a 1D or 3D texture or a surface's moves its texels at the rows it holds them in, \ + where Metal's blit addresses its rows floor(4w/16)*16 bytes apart"; + /// A blit from a buffer into a level of `RGB10A8_2P_XR10` or its sRGB twin narrower than 32 + /// texels, at a width not a multiple of 4, whose rows meet between Metal's groups of 32 + /// rows of the region (`two_planes/buffer_rows.rs`): Metal's GPU writes the two rows there + /// in an order that varies from run to run (the earlier row's bytes at 556 of 560 such + /// meetings in our probes), and in its fixed order at every other meeting. The runtime + /// keeps the earlier row's bytes there and Metal's order elsewhere: Metal's most frequent + /// whole outcome. + TwoPlaneBufferBlitOrder = "two-plane-buffer-blit-order", Precision, + "where the rows of two of Metal's groups of 32 meet the earlier row's bytes stand, \ + where Metal's GPU leaves either row's from run to run"; /// A render pipeline state whose vertex function runs simdgroup functions on a driver /// measured to run a vertex function's subgroup operations as Metal does though its /// `subgroupSupportedStages` leaves the vertex stage out @@ -1366,7 +1388,8 @@ degradations! { never makes one the older release stops"; /// A render pass that loads a color attachment of an extended-range or padded 10-bit /// format (`BGR10_XR`, `BGRA10_XR`, `RGB10A8_2P_XR10`, `R10Unorm_X6`, `RG10Unorm_X12` and - /// their sRGB twins), or under [`metal2vulkan::device::TileStorePolicy::Exact`] of a + /// their sRGB twins, and `RGB10A2Unorm_sRGB`), or under + /// [`metal2vulkan::device::TileStorePolicy::Exact`] of a /// signed normalized format or `RGB9E5Float`, stores it and draws, whose load pass /// (`render/unused_bits_load.rs`) rewrites every 32 x 32 tile of its render area: Metal's /// pass rewrites only the tiles a draw's primitives reach (on @@ -1863,13 +1886,23 @@ degradations! { "the device gives no answer for them (`PrivateAnswer::value` is `None`); Metal's \ measured answers on Apple's GPUs ride beside, never as this device's"; /// A color fill (`BlitCommandEncoder::fill_texture_color`) whose color is packed in a - /// format whose fills do not follow the color: compressed, 4:2:2, depth, stencil, - /// two-plane or padded 10-bit (`blit_fill.rs`). Metal writes one constant there for every - /// color of a process, bytes it did not write for the color, which differ between - /// processes and machines. The runtime writes zero bytes, one constant for every color. + /// format Metal packs no color in: compressed, 4:2:2, depth, stencil, two-plane, YCbCr, + /// padded 10-bit, `Invalid` or a private format (`blit_fill.rs`). Metal fills bytes of the + /// calling thread's stack there, which hold the last color fill's packed texel only where + /// no other call used them since. The runtime fills the command buffer's last color fill's + /// packed texel, over zeros. UnpackedFillColor = "unpacked-fill-color", Precision, - "every unit of the region holds zero bytes, whatever the color, where Metal's \ - constant is its own process's"; + "every unit of the region holds the command buffer's last packed texel over zeros, \ + whatever the color, where Metal's bytes are its stack's"; + /// A fill of a texture buffer (`BlitCommandEncoder::fill_texture`, + /// `BlitCommandEncoder::fill_texture_color`) whose 16-byte chunks read bytes of its block + /// past the pattern's whole copies, or past the block (`blit_fill.rs`): most patterns + /// whose length is not a power of two, and most regions whose first byte is not at a + /// multiple of 16 of the buffer. Metal reads bytes of the calling + /// thread's stack there: zeros in our probes, an earlier fill's bytes in the consumer's + /// process. The runtime writes zeros there. + TextureBufferFillLeftover = "texture-buffer-fill-leftover", Precision, + "those bytes of each chunk are zeros, where Metal's are its stack's"; /// A draw of points that rasterizes, of some vertices and instances, under a render /// pipeline state whose vertex function writes no `[[point_size]]` and whose input /// primitive topology class is not the point class (`render.rs`'s `draw_settings`): a diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 0fc14726e..2b6c8ded4 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -604,6 +604,11 @@ pub enum Problem { HandlerAfterCommit, /// The given slices' lengths differ. LengthMismatch, + /// A texture fill given no pattern bytes (`fillTexture:...:bytes:length:` of length 0). + /// Metal's validation stops it ("buffer length for format ... must be at least" a unit's + /// bytes); plain Metal reads a unit's bytes from the pattern's address all the same, bytes the + /// call does not give (an Apple M3 Max under macOS 27.0.1). + EmptyFillPattern, /// `offset..offset + size` runs past a resource of `length` bytes: Metal stops it /// (`Invalid`). A resource placed past its heap's end is [`HeapProblem::PastEnd`]. RangeOutOfBounds { diff --git a/crates/metal2vulkan-runtime/src/exactness.rs b/crates/metal2vulkan-runtime/src/exactness.rs index 63c941f33..d32bdf81b 100644 --- a/crates/metal2vulkan-runtime/src/exactness.rs +++ b/crates/metal2vulkan-runtime/src/exactness.rs @@ -62,7 +62,9 @@ impl Degradation { // near-equivalent, not one of Metal's. A removed argument's read: Metal gives it no // one value (its compiler drops or folds it, and its debug layer reads zero), and // the runtime gives zero. A color fill packed where fills ignore the color: Metal - // writes a constant of its process's, and the runtime one constant, zero. + // writes a constant of its process's, and the runtime one constant, zero. A texture + // buffer fill's bytes past its pattern's copies: Metal's stack's, zeros in our + // probes, and the runtime's zeros. D::ZeroedIndexFetch | D::DontCareStore | D::NarrowSurfaceRows @@ -71,6 +73,11 @@ impl Degradation { | D::PlainStateUniqueIdentifier | D::AbsentArgumentRead | D::UnpackedFillColor + | D::TextureBufferFillLeftover + // Rows of a two-plane buffer blit meeting between Metal's groups of 32 rows: Metal + // leaves either row's bytes from run to run, the runtime its most frequent whole + // outcome. + | D::TwoPlaneBufferBlitOrder // Points Metal sizes none of: what it draws is undefined, mostly nothing, and the // runtime draws nothing. | D::UnsizedPoints => Exactness::OneOfMetals, diff --git a/crates/metal2vulkan-runtime/src/families/features.rs b/crates/metal2vulkan-runtime/src/families/features.rs index fe36369bb..3a28b4c6f 100644 --- a/crates/metal2vulkan-runtime/src/families/features.rs +++ b/crates/metal2vulkan-runtime/src/families/features.rs @@ -32,7 +32,7 @@ use super::formats::{FormatRow, Missing}; use super::{Column, Facts, FormatCapability, Framework, Refusal, RowState}; use crate::capabilities::Query; use crate::error::RuntimeGap; -use crate::framebuffer_fetch::through_inputs; +use crate::framebuffer_fetch::{through_inputs, through_storage}; use crate::rate_mapped_pass::RegionRefusal; use metal2vulkan::device::{OpBits, StageSimd, SubgroupOp, VkExtension, VkFeature, VkProperty}; use metal2vulkan::error::{Capability, Feature, LowerFamily, Unsupported}; @@ -1000,15 +1000,24 @@ impl FeatureRow { // ---- Render passes and attachments ---- // Framebuffer fetch (the compile layer's color inputs, the runtime's - // `framebuffer_fetch`): exact through input attachments in rasterization order. The - // pixel interlock's storage form keeps no blended or sRGB fetched attachment exact - // (`lower::fragment::fetch`). - F::ProgrammableBlending => first([(!through_inputs(f.profile)).then(|| { - refused(Unsupported::needs( - Feature::FramebufferFetch, - Capability::Feature(VkFeature::RasterizationOrderColorAttachmentAccess), - )) - })]), + // `framebuffer_fetch`): exact through input attachments in rasterization order. A + // device with the ordered pixel interlock but not that access (MoltenVK, whose + // interlock is Metal's raster order groups, and RADV and ANV) fetches through the + // interlock's storage form (`lower::fragment::fetch`), exact for a fetch and for an + // unblended write; its blend of an attachment of another format than an + // extended-range, a 16-bit float, an 8-bit unorm or a packed 16-bit one, and its + // fetch of a one- or two-channel sRGB attachment, are not built, refused per pipeline: + // the row's gap. A device with neither has no ordered fetch. + F::ProgrammableBlending => first([ + match (through_inputs(f.profile), through_storage(f.profile)) { + (true, _) => None, + (false, true) => not_implemented(Feature::FramebufferFetch), + (false, false) => Some(refused(Unsupported::needs( + Feature::FramebufferFetch, + Capability::Feature(VkFeature::RasterizationOrderColorAttachmentAccess), + ))), + }, + ]), // Separate depth and stencil textures of one pass: their resolve of a stencil drawn // after the pass (`DepthResolvedSample` after `Min` or `Max`) is not built. F::SeparateDepthStencilAttachments => first([gap(G::DepthStencilResolve)]), diff --git a/crates/metal2vulkan-runtime/src/fill_value.rs b/crates/metal2vulkan-runtime/src/fill_value.rs index 8568b1dfb..684740a12 100644 --- a/crates/metal2vulkan-runtime/src/fill_value.rs +++ b/crates/metal2vulkan-runtime/src/fill_value.rs @@ -11,7 +11,12 @@ //! and signs and 26 doubles at rounding edges into each format; our probe packed 128 colors in each //! format into textures of 18 others, which hold the packed texel repeated, as an Apple M3 Max //! under macOS 26.7 does too, a fill at a time and 2,249 fills in one encoder alike (our probe -//! `fil5.m`). This module reproduces every texel and every threshold. +//! `fil5.m`). On an Apple M3 Max under macOS 27.0.1 our probe `pack.m` packed 1,144 colors (88 +//! specials, 1,024 random, 32 NaNs) in each of the 88 formats Metal packs a color in, into +//! `RGBA32Uint` texels, each holding the packed texel repeated, the extended-range `_sRGB` twins' +//! too, in one encoder, an encoder a fill and a process a fill alike (`twins.m`); `classify.m` +//! found the 213 other formats pack nothing. This module reproduces every texel and every +//! threshold. //! //! Each channel converts its double; every rule but the integers' takes the double's `float` //! first (rounded to nearest even, an overflow the infinity): @@ -55,11 +60,17 @@ //! 16-bit words, blue, green, red and alpha, each code in the word's top 10 bits; `BGR10_XR` is //! blue in bits 0 to 9, green, then red, the top two bits zero; `RGB9E5Float`'s exponent is last. //! -//! A format whose filled bytes do not follow the color has no packing here: compressed, 4:2:2, -//! depth, stencil and two-plane formats (one constant for every color of a process), and the padded -//! 10-bit formats (`R10Unorm_X6`, `RG10Unorm_X12` and their `_sRGB` twins: one texel for every -//! color, of bytes that differ between machines and runs). Neither has a format whose fills the -//! probes did not cover. +//! These formats are packed by the same rules: the `RGB8`, `RGB16` and `RGB32` ones (their +//! `RGBA` twins' first three channels), `BGRA4Unorm` (blue in bits 0 to 3, then +//! green, red and alpha), `ARGB8Unorm_sRGB` (alpha first, then the sRGB red, green and blue), +//! `BGRA10Unorm` and `BGRA10Uint` (four 16-bit words, blue, green, red and alpha, each code in the +//! word's top 10 bits), and `RGBA16Float_XR` (halves of the `float` clamped to `[-384/510, +//! 639/510]`, alpha to `[0, 1]`, NaN 0, an alpha of 0 or less `+0`). +//! +//! In every other format Metal packs no color (compressed, 4:2:2, depth, stencil, two-plane, +//! YCbCr, padded 10-bit, `Invalid`, the private 10- and 12-bit, PQ and HLG formats, and +//! `RGB10A2Unorm_sRGB`): its fill writes bytes it did not pack for the color (`blit_fill.rs`), and +//! there is no packing here. use metal2vulkan::metal::PixelFormat; @@ -92,6 +103,10 @@ enum Conversion { XrAlpha, /// An extended-range `_sRGB` color channel's 10-bit code. XrSrgb, + /// An extended-range half color channel: the `float` clamped to Apple's extended range. + XrHalf, + /// An extended-range half alpha: the `float` clamped to `[0, 1]`. + XrHalfAlpha, } impl Conversion { @@ -104,7 +119,10 @@ impl Conversion { | Conversion::Sint(bits) | Conversion::Zero(bits) => bits, Conversion::Srgb => 8, - Conversion::Half | Conversion::Bfloat => 16, + Conversion::Half + | Conversion::Bfloat + | Conversion::XrHalf + | Conversion::XrHalfAlpha => 16, Conversion::Float => 32, Conversion::Ufloat(mantissa) => mantissa + 5, Conversion::XrColor | Conversion::XrAlpha | Conversion::XrSrgb => 10, @@ -127,6 +145,21 @@ impl Conversion { Conversion::XrColor => extended(x, XR_LOW, XR_HIGH), Conversion::XrAlpha => extended(x, 0.0, 1.0), Conversion::XrSrgb => first_at_most(&XR_SRGB_FIRST, x, XR_ZERO), + Conversion::XrHalf => { + let v = x as f32; + let v = if v.is_nan() { + 0.0 + } else { + v.clamp(XR_LOW, XR_HIGH) + }; + u64::from(super::clear_value::f32_to_f16(v)) + } + // Zero or less, `-0` and NaN among them, is `+0`. + Conversion::XrHalfAlpha => { + let v = x as f32; + let v = if v > 0.0 { v.min(1.0) } else { 0.0 }; + u64::from(super::clear_value::f32_to_f16(v)) + } } } } @@ -193,6 +226,17 @@ fn fields(pf: PixelFormat) -> Option> { } out }; + // Blue, green, red and alpha, each in the top 10 bits of a 16-bit word. + let words = |conversion| { + [(2, 6), (1, 22), (0, 38), (3, 54)] + .into_iter() + .map(|(channel, at)| Field { + channel, + at, + conversion, + }) + .collect() + }; Some(match pf { P::A8Unorm => packed(&[(3, C::Unorm(8))]), P::R8Unorm => same(1, C::Unorm(8)), @@ -289,6 +333,29 @@ fn fields(pf: PixelFormat) -> Option> { P::RGBX32Uint => in_order(4, C::Uint(32), C::Zero(32)), P::RGBX32Sint => in_order(4, C::Sint(32), C::Zero(32)), P::RGBX32Float => same(4, C::Float), + P::RGB8Unorm => same(3, C::Unorm(8)), + P::RGB8Snorm => same(3, C::Snorm(8)), + P::RGB8Uint => same(3, C::Uint(8)), + P::RGB8Sint => same(3, C::Sint(8)), + P::RGB16Unorm => same(3, C::Unorm(16)), + P::RGB16Snorm => same(3, C::Snorm(16)), + P::RGB16Uint => same(3, C::Uint(16)), + P::RGB16Sint => same(3, C::Sint(16)), + P::RGB16Float => same(3, C::Half), + P::RGB16Bfloat => same(3, C::Bfloat), + P::RGB32Uint => same(3, C::Uint(32)), + P::RGB32Sint => same(3, C::Sint(32)), + P::RGB32Float => same(3, C::Float), + P::BGRA4Unorm => packed(&[ + (2, C::Unorm(4)), + (1, C::Unorm(4)), + (0, C::Unorm(4)), + (3, C::Unorm(4)), + ]), + P::ARGB8UnormSRGB => packed(&[(3, C::Unorm(8)), (0, C::Srgb), (1, C::Srgb), (2, C::Srgb)]), + P::RGBA16FloatXR => in_order(4, C::XrHalf, C::XrHalfAlpha), + P::BGRA10Unorm => words(C::Unorm(10)), + P::BGRA10Uint => words(C::Uint(10)), P::BGRA10XR => xr(false, Some(54), [6, 22, 38]), P::BGRA10XRSRGB => xr(true, Some(54), [6, 22, 38]), P::BGR10XR => xr(false, None, [0, 10, 20]), diff --git a/crates/metal2vulkan-runtime/src/private_properties.rs b/crates/metal2vulkan-runtime/src/private_properties.rs index 1a29d9de7..f87f156af 100644 --- a/crates/metal2vulkan-runtime/src/private_properties.rs +++ b/crates/metal2vulkan-runtime/src/private_properties.rs @@ -276,8 +276,9 @@ pub enum PrivateFlag { /// `isLargeMRTSupported`: Metal's. IsLargeMrtSupported, /// `isRGB10A2GammaSupported`: the device's: whether the runtime filters a texture of - /// `RGB10A2Unorm_sRGB` on it ([`Device::pixel_format_capabilities`]): no on every device - /// while the runtime holds no texture of that format. + /// `RGB10A2Unorm_sRGB` on it ([`Device::pixel_format_capabilities`]): yes on every device, + /// whose function filters the texture's held words as Metal does (Metal's answer on an Apple + /// M3 Max under macOS 27.0.1: yes). IsRgb10a2GammaSupported, /// `supportsBufferWithAddressRanges`: the device's, no (the runtime makes no buffer over /// address ranges). diff --git a/crates/metal2vulkan-runtime/src/replay.rs b/crates/metal2vulkan-runtime/src/replay.rs index d80c3f735..81a7370a2 100644 --- a/crates/metal2vulkan-runtime/src/replay.rs +++ b/crates/metal2vulkan-runtime/src/replay.rs @@ -57,7 +57,6 @@ use super::indirect_command_buffer::IndirectCommandBuffer; use super::pipeline::{ComputePipelineState, RenderPipelineState}; use super::render::{RenderLog, RenderRoom}; use super::render_pass::RenderPassDescriptor; -use super::render_values::ClearColor; use super::residency::Residency; use super::resource::ResourceRef; use super::sampler::SamplerState; @@ -66,7 +65,7 @@ use super::used_resources::EncoderKind; use super::values::{Origin, Region, Size}; use super::{BlitCommandEncoder, ComputeCommandEncoder}; use crate::copy_plan::BlitOption; -use metal2vulkan::metal::{BarrierScope, DispatchType, PixelFormat, ResourceUsage}; +use metal2vulkan::metal::{BarrierScope, DispatchType, ResourceUsage}; use std::cell::Cell; use std::ops::Range; use std::sync::{Arc, Mutex}; @@ -616,14 +615,14 @@ pub(super) struct SamplersWithLodClamps { pub(super) first: u32, } -/// One public call of a blit encoder, its arguments owned (the method of each variant's name). +/// One public call of a blit encoder, its arguments owned (the method of each variant's name; a +/// color fill as the byte fill of the bytes it fills). pub(super) enum BlitCall { CopyBufferToBuffer(Buffer, u64, Buffer, u64, u64), FillBuffer(Buffer, Range, u8), FillBufferPattern4(Buffer, Range, u32), SynchronizeResource(Resource), FillTexture(Box<(Texture, u64, u64, Region)>, Span), - FillTextureColor(Box<(Texture, u64, u64, Region, ClearColor, Option)>), CopyBufferToTexture(Box), CopyTextureToBuffer(Box), CopyTextureToTexture(Box), @@ -656,7 +655,6 @@ impl BlitCall { pub(super) fn extra(&self) -> usize { match self { BlitCall::FillTexture(call, _) => std::mem::size_of_val(&**call), - BlitCall::FillTextureColor(call) => std::mem::size_of_val(&**call), BlitCall::CopyBufferToTexture(call) => std::mem::size_of_val(&**call), BlitCall::CopyTextureToBuffer(call) => std::mem::size_of_val(&**call), BlitCall::CopyTextureToTexture(call) => std::mem::size_of_val(&**call), @@ -919,10 +917,6 @@ fn blit( let (texture, level, slice, region) = &**call; encoder.fill_texture(texture, *level, *slice, *region, log.bytes_of(*pattern)) } - B::FillTextureColor(call) => { - let (texture, level, slice, region, color, format) = &**call; - encoder.fill_texture_color(texture, *level, *slice, *region, *color, *format) - } B::CopyBufferToTexture(call) => encoder.copy_from_buffer_to_texture( &call.source, call.source_offset, diff --git a/crates/metal2vulkan-runtime/src/sample_planes.rs b/crates/metal2vulkan-runtime/src/sample_planes.rs index de879f250..b7058b17b 100644 --- a/crates/metal2vulkan-runtime/src/sample_planes.rs +++ b/crates/metal2vulkan-runtime/src/sample_planes.rs @@ -57,7 +57,10 @@ //! //! The same two copies move a blit copy's samples between two multisampled color images where the //! device's own copy converts float NaNs ([`BitsCopy`]): the split out of the source's level and -//! layer, the merge into the destination's over the region, through planes of their own. +//! layer, the merge into the destination's over the region, through planes of their own. And +//! the merge alone writes a multisampled fill's samples (`blit_fill.rs`, [`BitsCopy::fill`]): +//! planes of the unsigned-integer format of the texel's size, each layer cleared to its sample's +//! bits, merged over the region into a multisampled image of that format. use super::binding_view::VkView; use super::command_buffer::CommandBuffer; @@ -88,11 +91,12 @@ use metal2vulkan::cache::Hash256; use metal2vulkan::device::{FormatUsage, VkProperty}; use metal2vulkan::error::{Capability, Feature, Unsupported}; use metal2vulkan::metal::format::FormatMapping; -use metal2vulkan::metal::{TextureType, TextureUsage}; +use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage}; use metal2vulkan::vk::{ ComponentMapping, Format, FormatFeatureFlags2, ImageAspectFlags, ImageCreateFlags, ImageType, ImageUsageFlags, ImageViewType, }; +use std::ops::Range; /// One fetched attachment's sample planes for a pass (the module docs). #[derive(Clone, Debug)] @@ -897,7 +901,7 @@ enum Recorded { Clear { image: vk::Image, value: vk::ClearColorValue, - layers: u32, + layers: Range, }, } @@ -1075,7 +1079,7 @@ impl PlanesCommands { recorded.push(Recorded::Clear { image: planes.texture.raw_image()?, value: color.clear, - layers: planes.layers, + layers: 0..planes.layers, }); } } @@ -1114,8 +1118,9 @@ impl PlanesCommands { /// Copies of regions between two multisampled color images by the sample planes' two copies, /// the split out of the source and the merge into the destination, through the unsigned-integer /// view of the texel size of both, so every sample's bits cross unchanged: where the device's own -/// multisampled copy converts float NaNs (`nan_clear::converting_copy`). Held until the command -/// buffer completes: the planes, the steps, their uses, and the objects the steps hold. +/// multisampled copy converts float NaNs (`nan_clear::converting_copy`); or the merge alone, a +/// multisampled fill's ([`BitsCopy::fill`]). Held until the command buffer completes: the +/// planes, the steps, their uses, and the objects the steps hold. pub(super) struct BitsCopy { _planes: Vec, steps: Vec, @@ -1123,9 +1128,11 @@ pub(super) struct BitsCopy { _objects: PassObjects, } -/// The stages a [`BitsCopy`] runs in: the split's compute, and the merge's draw. +/// The stages a [`BitsCopy`] runs in: a fill's clears, the split's compute, and the merge's +/// draw. pub(super) const BITS_COPY_STAGES: vk::PipelineStageFlags2 = vk::PipelineStageFlags2::from_raw( - vk::PipelineStageFlags2::COMPUTE_SHADER.as_raw() + vk::PipelineStageFlags2::ALL_TRANSFER.as_raw() + | vk::PipelineStageFlags2::COMPUTE_SHADER.as_raw() | vk::PipelineStageFlags2::FRAGMENT_SHADER.as_raw() | vk::PipelineStageFlags2::COLOR_ATTACHMENT_OUTPUT.as_raw(), ); @@ -1206,6 +1213,113 @@ impl BitsCopy { })) } + /// A fill of the region `origin` by `size` of a new multisampled image of `copy`'s format + /// (an unsigned-integer one) over the region's far corner, whose sample `s` of each texel there + /// takes the bits `values[s]` (the format's words): the image, a texture the command buffer + /// holds, and the steps that fill it, the sample planes each cleared to its sample's value + /// (`vkCmdClearColorImage` in the format itself, which takes the value's bits) and merged + /// into the image over the region. Refused, `Unsupported`, where the device cannot run the + /// merge (`Planes::new`) or make the image. + pub(super) fn fill( + maker: &CommandBuffer, + copy: PlanesCopy, + values: &[[u32; 4]], + [x, y]: [u32; 2], + [width, height]: [u32; 2], + ) -> Result<(Texture, BitsCopy), Error> { + let pixel_format = match copy { + PlanesCopy::R8 => PixelFormat::R8Uint, + PlanesCopy::R16 => PixelFormat::R16Uint, + PlanesCopy::R32 => PixelFormat::R32Uint, + PlanesCopy::Rg32 => PixelFormat::RG32Uint, + PlanesCopy::Rgba32 => PixelFormat::RGBA32Uint, + _ => return Err(internal("a multisampled fill of no unsigned format")), + }; + let samples = u32::try_from(values.len()).map_err(|_| internal("a sample count"))?; + let format = copy.format(); + let extent = [x + width, y + height]; + let descriptor = TextureDescriptor { + texture_type: TextureType::Type2DMultisample, + pixel_format, + width: extent[0].into(), + height: extent[1].into(), + sample_count: samples.into(), + usage: TextureUsage::RENDER_TARGET + | TextureUsage::SHADER_READ + | TextureUsage::PIXEL_FORMAT_VIEW, + resource_options: ResourceOptions::private(), + ..TextureDescriptor::default() + }; + // Mutable, as the merge's views and the copies out of it (into another format of the + // size, `blit_texture.rs`) view it. + let plan = ImagePlan { + pixel_format, + flags: ImageCreateFlags::MUTABLE_FORMAT, + image_type: ImageType::TYPE_2D, + format, + extent: [extent[0], extent[1], 1], + levels: 1, + layers: 1, + samples: sample_count(samples) + .ok_or_else(|| internal("a fill of a sample count Vulkan lacks"))?, + usage: ImageUsageFlags::COLOR_ATTACHMENT + | ImageUsageFlags::SAMPLED + | ImageUsageFlags::TRANSFER_SRC + | ImageUsageFlags::TRANSFER_DST, + view_formats: Vec::new(), + mapping: FormatMapping::direct(format, ImageAspectFlags::COLOR), + unavailable: TextureUsage::SHADER_WRITE | TextureUsage::SHADER_ATOMIC, + }; + let texture = Device::new_planned_texture(maker, &descriptor, plan)?; + let target = Target { + texture: texture.clone(), + level: 0, + layer: 0, + layers: 1, + format, + samples, + extent, + }; + let planes = Planes::new(maker, &target, samples, extent)?; + if !planes.clearable { + return Err(internal( + "planes of an unsigned format without transfer writes", + )); + } + let mut objects = PassObjects::new(maker.device(), 0, 1)?; + let write = Access::new( + vk::PipelineStageFlags2::ALL_TRANSFER, + vk::AccessFlags2::TRANSFER_WRITE, + ); + let mut uses = vec![planes.image_use(write, true)?]; + let image = planes.texture.raw_image()?; + let mut steps: Vec = (0..samples) + .zip(values) + .map(|(layer, &uint32)| Recorded::Clear { + image, + value: vk::ClearColorValue { uint32 }, + layers: layer..layer + 1, + }) + .collect(); + let area = vk::Rect2D { + offset: vk::Offset2D { + x: x as i32, + y: y as i32, + }, + extent: vk::Extent2D { width, height }, + }; + steps.push(objects.merge(&planes, &target, area, &mut uses)?); + Ok(( + texture, + BitsCopy { + _planes: vec![planes], + steps, + uses, + _objects: objects, + }, + )) + } + /// Record the copies into `command_buffer`, each step between barriers from everything /// before and to everything after. /// @@ -1312,8 +1426,8 @@ unsafe fn record_steps(raw: &Vk, command_buffer: vk::CommandBuffer, steps: &[Rec aspect_mask: vk::ImageAspectFlags::COLOR, base_mip_level: 0, level_count: 1, - base_array_layer: 0, - layer_count: *layers, + base_array_layer: layers.start, + layer_count: layers.end - layers.start, }; raw.cmd_clear_color_image( command_buffer, diff --git a/crates/metal2vulkan-runtime/src/tests/apple_only.rs b/crates/metal2vulkan-runtime/src/tests/apple_only.rs index 07acb806d..3d22ee5c0 100644 --- a/crates/metal2vulkan-runtime/src/tests/apple_only.rs +++ b/crates/metal2vulkan-runtime/src/tests/apple_only.rs @@ -159,7 +159,6 @@ fn each_apple_only_refusal_names_its_gap() { (AppleOnly::DepthCleared, Unmeasured), (AppleOnly::StencilCleared, Unmeasured), (AppleOnly::SurfaceClientDirection, Unmeasured), - (AppleOnly::FillUnmeasured, Unmeasured), ]; for (feature, gap) in table { assert_eq!(feature.gap(), gap, "{feature:?}"); diff --git a/crates/metal2vulkan-runtime/src/tests/blit_fill.rs b/crates/metal2vulkan-runtime/src/tests/blit_fill.rs new file mode 100644 index 000000000..ab656778a --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/blit_fill.rs @@ -0,0 +1,212 @@ +//! The bytes Metal's private texture fills write (`blit_fill.rs`): each multisampled sample's, +//! from our probe `ms.m`'s read-backs, and a texture buffer's, from our probe `tb.m`'s (the M3 +//! Max under macOS 27.0.1), and the formats a fill has a unit for. + +use crate::blit_fill::{fill_unit, sample_units, words, StreamFill}; +use metal2vulkan::metal::PixelFormat; +use std::ops::Range; + +/// Bytes from hex. +fn hex(text: &str) -> Vec { + (0..text.len()) + .step_by(2) + .map(|at| u8::from_str_radix(&text[at..at + 2], 16).unwrap()) + .collect() +} + +/// Each sample's bytes as hex. +fn samples(pattern: &str, bytes: u32, count: u32) -> Vec { + sample_units(&hex(pattern), bytes, count) + .iter() + .map(|unit| unit.iter().map(|b| format!("{b:02x}")).collect()) + .collect() +} + +/// The probe's 16-byte pattern. +const P16: &str = "00112233445566778899aabbccddeeff"; + +/// The probe's 32-byte pattern. +const P32: &str = "00112233445566778899aabbccddeeff102132435465768798a9bacbdcedfe0f"; + +/// Where a texel's samples hold 16 bytes or fewer, sample `s` takes the pattern's bytes from +/// `s · b`, the pattern repeated and cut at the samples' bytes; past 16, each sample the pattern +/// cut at its texel. +#[test] +fn multisampled_texels_take_metal_s_bytes_of_the_pattern() { + // `R8Unorm`, `Stencil8` at 4 and 2 samples. + assert_eq!(samples(P16, 1, 4), ["00", "11", "22", "33"]); + assert_eq!(samples(P32, 1, 2), ["00", "11"]); + // `RG8Unorm`, `Depth16Unorm` and the 16-bit packed formats. + assert_eq!(samples(P16, 2, 4), ["0011", "2233", "4455", "6677"]); + assert_eq!(samples(P32, 2, 2), ["0011", "2233"]); + // `RGBA8Unorm`, `Depth32Float`, `BGR10_XR`, `RGB10A2Unorm_sRGB`; a 32-byte pattern cut at 16. + let four = ["00112233", "44556677", "8899aabb", "ccddeeff"]; + assert_eq!(samples(P16, 4, 4), four); + assert_eq!(samples(P32, 4, 4), four); + assert_eq!(samples(P32, 4, 2), ["00112233", "44556677"]); + // `RGBA16Float`, `BGRA10_XR`: 16 bytes at 2 samples, the texel's 8 each at 4. + assert_eq!(samples(P32, 8, 2), ["0011223344556677", "8899aabbccddeeff"]); + assert_eq!(samples(P16, 8, 4), ["0011223344556677"; 4]); + // `RGBA32Float` at 2 and 4. + assert_eq!(samples(P32, 16, 2), [P16; 2]); + assert_eq!(samples(P16, 16, 4), [P16; 4]); + // Patterns that do not divide the samples' bytes. + assert_eq!(samples("a1b2c3", 1, 4), ["a1", "b2", "c3", "a1"]); + assert_eq!(samples("a1b2c3", 2, 4), ["a1b2", "c3a1", "b2c3", "a1b2"]); + assert_eq!( + samples("a1b2c3d4e5", 4, 4), + ["a1b2c3d4", "e5a1b2c3", "d4e5a1b2", "c3d4e5a1"] + ); + assert_eq!(samples("a1b2c3d4e5", 4, 2), ["a1b2c3d4", "e5a1b2c3"]); + assert_eq!( + samples("a1b2c3d4e5f6", 8, 2), + ["a1b2c3d4e5f6a1b2", "c3d4e5f6a1b2c3d4"] + ); + assert_eq!( + samples("a1b2c3", 16, 4), + ["a1b2c3a1b2c3a1b2c3a1b2c3a1b2c3a1"; 4] + ); + // A 20-byte pattern into 16. + assert_eq!( + samples("0102030405060708090a0b0c0d0e0f1011121314", 4, 4), + ["01020304", "05060708", "090a0b0c", "0d0e0f10"] + ); +} + +/// A sample's bytes as the words of a clear value of the unsigned format of its size. +#[test] +fn sample_bytes_become_clear_words() { + assert_eq!(words(&hex("a1")), [0xa1, 0, 0, 0]); + assert_eq!(words(&hex("a1b2")), [0xb2a1, 0, 0, 0]); + assert_eq!(words(&hex("00112233")), [0x3322_1100, 0, 0, 0]); + assert_eq!( + words(&hex("0011223344556677")), + [0x3322_1100, 0x7766_5544, 0, 0] + ); + assert_eq!( + words(&hex(P16)), + [0x3322_1100, 0x7766_5544, 0xbbaa_9988, 0xffee_ddcc] + ); +} + +/// Every pixel format the crate holds a texture of (one with aspects) has a fill unit, but the +/// 24-bit depth formats, which Apple GPUs make no texture of (refused at the texture's making). +#[test] +fn every_texture_format_has_a_fill_unit() { + use metal2vulkan::metal::format::aspects; + use PixelFormat as P; + let none: Vec = PixelFormat::ALL + .iter() + .copied() + .filter(|&pf| aspects(pf).is_some() && fill_unit(pf).is_none()) + .collect(); + assert_eq!( + none, + [P::Depth24UnormStencil8, P::X24Stencil8], + "formats without a fill unit" + ); +} + +/// The pattern of `n` bytes `a1 a2 ..`, the probe's. +fn counting(n: usize, from: u8) -> Vec { + (0..n).map(|i| from.wrapping_add(i as u8)).collect() +} + +/// The bytes `bytes` of a texture buffer's buffer a fill of `pattern` writes, as hex. +fn streamed(pattern: &[u8], bytes: Range) -> String { + let stream = StreamFill::new(pattern); + bytes + .clone() + .map(|at| format!("{:02x}", stream.byte(&bytes, at))) + .collect() +} + +/// A texture buffer's fill writes the bytes Metal's writes: the pattern by the masked index of the +/// region's byte, but in each 16-byte chunk of the buffer the region covers whole, 16 bytes of the +/// block of the pattern's whole copies, zeros past them (`tb.m`'s cases, the region's bytes from +/// the texture's offset plus `x` texels). +#[test] +fn texture_buffer_fills_write_metal_s_bytes() { + // 8 bytes into 5 `R8Unorm` texels from byte 7, and 8 `RGBA8Unorm` texels from byte 80. + assert_eq!(streamed(&counting(8, 0xa1), 7..12), "a1a2a3a4a5"); + assert_eq!( + streamed(&counting(8, 0xa1), 80..112), + "a1a2a3a4a5a6a7a8a1a2a3a4a5a6a7a8a1a2a3a4a5a6a7a8a1a2a3a4a5a6a7a8" + ); + // 3 bytes, 12 `RGBA8Unorm` texels from 0: 5 copies a chunk, a zero past them. + assert_eq!( + streamed(&counting(3, 0xa1), 0..48), + "a1a2a3a1a2a3a1a2a3a1a2a3a1a2a300a1a2a3a1a2a3a1a2a3a1a2a3a1a2a300a1a2a3a1a2a3a1a2a3a1a2a3a1a2a300" + ); + // 3 bytes, 30 `R8Unorm` texels from 5: `p0 p0 p2 p2` outside the chunk. + assert_eq!( + streamed(&counting(3, 0xa1), 5..35), + "a1a1a3a3a1a1a3a3a1a1a3a1a2a3a1a2a3a1a2a3a1a2a3a1a2a300a3a1a1" + ); + // 12 bytes from byte 8: the chunks read from the block's byte 8, past the one copy. + assert_eq!( + streamed(&counting(12, 0xa1), 8..48), + "a1a2a3a4a1a2a3a4a9aaabac000000000000000000000000a9aaabac000000000000000000000000" + ); + // 5 bytes into 40 `RG8Unorm` texels from byte 12. + assert_eq!( + streamed(&counting(5, 0xa1), 12..92), + "a1a1a1a1a5a1a2a3a4a5a1a2a3a4a50000000000a5a1a2a3a4a5a1a2a3a4a50000000000\ + a5a1a2a3a4a5a1a2a3a4a50000000000a5a1a2a3a4a5a1a2a3a4a50000000000a5a5a5a5a1a1a1a1a5a5a5a5" + ); + // 17 bytes into 12 `RGBA32Float` texels: a 32-byte block of one copy. + let seventeen = "a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1000000000000000000000000000000"; + assert_eq!(streamed(&counting(17, 0xa1), 0..192), seventeen.repeat(6)); + // 24 bytes into 30 `RGBA16Float` texels from byte 88. + let copy = "a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b80000000000000000"; + assert_eq!( + streamed(&counting(24, 0xa1), 88..328), + format!("a1a2a3a4a5a6a7a8{}a1a2a3a4a5a6a7a8", copy.repeat(7)) + ); + // 100 bytes into 40 `RGBA8Unorm` texels from byte 4: a 128-byte block. + assert_eq!( + streamed(&counting(100, 0x10), 4..164), + "101112131011121310111213101112131415161718191a1b1c1d1e1f101112131415161718191a1b1c1d1e1f\ + 303132333435363738393a3b3c3d3e3f303132333435363738393a3b3c3d3e3f505152535455565758595a5b\ + 5c5d5e5f505152535455565758595a5b5c5d5e5f707172730000000000000000000000007071727300000000\ + 0000000000000000101112131415161718191a1b1c1d1e1f10111213" + ); +} + +/// A texture buffer's fill as its spans (each its unit repeated from the span's first byte) +/// writes every byte the fill does, and announces the bytes past the pattern's copies where a +/// chunk reads one: patterns of 1 to 70 bytes over regions of 0 to 200 bytes from 0 to 47. +#[test] +fn texture_buffer_fill_spans_are_its_bytes() { + for n in 1..=70 { + let pattern = counting(n, 0x01); + let stream = StreamFill::new(&pattern); + let copies = (16.max(n.next_power_of_two()) / n * n) as u64; + for start in 0..48u64 { + for length in 0..200u64 { + let bytes = start..start + length; + let mut written = vec![None; (start + length) as usize]; + for (span, unit) in stream.spans(bytes.clone()) { + for (k, at) in span.enumerate() { + assert!(written[at as usize].is_none(), "{n} {bytes:?}: twice"); + written[at as usize] = Some(unit[k % unit.len()]); + } + } + let want: Vec> = (0..start + length) + .map(|at| bytes.contains(&at).then(|| stream.byte(&bytes, at))) + .collect(); + assert_eq!(written, want, "{n} {bytes:?}"); + // Brute force: a whole chunk's byte read from the block's copies or past them. + let leftover = (start.next_multiple_of(16)..(start + length) / 16 * 16).any(|at| { + let chunk = at / 16 * 16; + ((chunk - start) & (n as u64 - 1) & !3) + at % 16 >= copies + }); + assert_eq!( + stream.reads_leftover(bytes.clone()), + leftover, + "{n} {bytes:?}" + ); + } + } + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/degradation_codes.txt b/crates/metal2vulkan-runtime/src/tests/degradation_codes.txt index ce0f75ec7..e57864001 100644 --- a/crates/metal2vulkan-runtime/src/tests/degradation_codes.txt +++ b/crates/metal2vulkan-runtime/src/tests/degradation_codes.txt @@ -199,8 +199,10 @@ metal2vulkan-degrade-tessellation-factor-instance metal2vulkan-degrade-tessellation-factor-scale metal2vulkan-degrade-tessellation-triangle-order metal2vulkan-degrade-tessellation-winding +metal2vulkan-degrade-texture-buffer-fill-leftover metal2vulkan-degrade-tile-dispatch-scratch metal2vulkan-degrade-two-plane-buffer-blit +metal2vulkan-degrade-two-plane-buffer-blit-order metal2vulkan-degrade-two-plane-texture-copy metal2vulkan-degrade-unadvertised-vertex-simdgroups metal2vulkan-degrade-uncalibrated-gpu-times diff --git a/crates/metal2vulkan-runtime/src/tests/exactness.rs b/crates/metal2vulkan-runtime/src/tests/exactness.rs index 073327c3c..53947366a 100644 --- a/crates/metal2vulkan-runtime/src/tests/exactness.rs +++ b/crates/metal2vulkan-runtime/src/tests/exactness.rs @@ -34,7 +34,7 @@ fn the_kinds_metal_answers_otherwise_are_named() { .copied() .filter(|k| k.exactness() == Exactness::OneOfMetals) .collect(); - assert_eq!(one_of_metals.len(), 9, "{one_of_metals:?}"); + assert_eq!(one_of_metals.len(), 11, "{one_of_metals:?}"); for kind in [ D::ZeroedIndexFetch, D::DontCareStore, @@ -48,6 +48,12 @@ fn the_kinds_metal_answers_otherwise_are_named() { // Metal writes one constant of its process's for a color packed where fills ignore the // color, which differs between processes and machines: the runtime's zero bytes are one. D::UnpackedFillColor, + // A texture buffer fill's bytes past its pattern's whole copies Metal reads from its + // stack, zeros in our probes: the runtime's zeros are those. + D::TextureBufferFillLeftover, + // Rows of a two-plane buffer blit meeting between Metal's groups of 32 rows: Metal leaves + // either row's bytes from run to run; the runtime's earlier row's is its most frequent. + D::TwoPlaneBufferBlitOrder, // Metal sizes no point outside the point class without a point size, and draws mostly // nothing there, sometimes a few points or a box: the runtime's nothing is one. D::UnsizedPoints, diff --git a/crates/metal2vulkan-runtime/src/tests/families.rs b/crates/metal2vulkan-runtime/src/tests/families.rs index 3988f29db..af5a94318 100644 --- a/crates/metal2vulkan-runtime/src/tests/families.rs +++ b/crates/metal2vulkan-runtime/src/tests/families.rs @@ -272,8 +272,16 @@ fn states_follow_their_sources() { let (enabled, _) = created(&stem, &desc); let apple9 = &all[&GpuFamily::Apple9]; let blending = state(apple9, feature(F::ProgrammableBlending)).unwrap(); + // Through input attachments in rasterization order exact; through the pixel interlock's + // storage form the blends it does not build are the runtime's gap; with neither, refused. if enabled.has(VkFeature::RasterizationOrderColorAttachmentAccess) { assert_eq!(blending, RowState::Exact, "{stem}"); + } else if enabled.has(VkFeature::FragmentShaderPixelInterlock) { + assert_eq!( + blending, + not_implemented(Feature::FramebufferFetch), + "{stem}" + ); } else { assert_eq!( blending, diff --git a/crates/metal2vulkan-runtime/src/tests/fill_value.rs b/crates/metal2vulkan-runtime/src/tests/fill_value.rs index 2137ba798..2901b0d5e 100644 --- a/crates/metal2vulkan-runtime/src/tests/fill_value.rs +++ b/crates/metal2vulkan-runtime/src/tests/fill_value.rs @@ -414,20 +414,6 @@ fn shared_exponents_round_half_up() { assert_eq!(texel(-1.0), 0); } -/// A padded 10-bit format's fills have no defined result (one texel for every color, of bytes that -/// differ between machines and runs): no packing. -#[test] -fn padded_formats_have_no_fill_packing() { - for pf in [ - P::R10UnormX6, - P::R10UnormX6SRGB, - P::RG10UnormX12, - P::RG10UnormX12SRGB, - ] { - assert_eq!(fill_texel(pf, [0.5; 4]), None, "{pf:?}"); - } -} - /// The texel a color fill without a pixel format wrote into a texture of each format on an M4 /// under macOS 27.0.1 (our probe `tfl3`): the colors (0.25, 0.5, 0.75, 1), /// (2, -1, 0.5, 0.3) and (0, 0, 0, 0). The fill with the texture's own format wrote the same. @@ -759,3 +745,273 @@ fn a_color_packed_in_another_format_repeats_its_texel() { } assert!(wrong.is_empty(), "packings unlike Metal's: {wrong:?}"); } + +/// The special values of our probe `pack.m`: color `i` of its first colors is +/// `(s[i], s[i + 1], s[i + 2], s[i + 3])`, indices modulo the count. +const PACK_SPECIALS: [f64; 88] = [ + 0.0, + -0.0, + 1.0, + -1.0, + 0.5, + -0.5, + 2.0, + -2.0, + 0.25, + 0.75, + 1.0 / 3.0, + 1e-3, + -1e-3, + f64::INFINITY, + f64::NEG_INFINITY, + 5e-324, + -5e-324, + 1e-310, + 1.401298464324817e-45, + 1.1754943508222875e-38, + 5.960464477539063e-08, + 2.9802322387695312e-08, + 4.470348358154297e-08, + 6.103515625e-05, + 65504.0, + 65519.99999999999, + 65520.0, + 65536.0, + 1e10, + -1e10, + 3.4028234663852886e38, + 3.4028235677973366e38, + 1e39, + -1e39, + 2147483647.0, + 2147483648.0, + -2147483648.0, + -2147483649.0, + 4294967295.0, + 4294967295.5, + 4294967296.0, + 255.5, + 127.5, + -128.5, + 32767.5, + 65535.5, + 0.5 / 255.0, + 1.5 / 255.0, + 1.0 / 510.0, + 384.0 / 510.0, + 894.0 / 510.0, + -384.0 / 510.0, + 1.2529411764705882, + -0.7529411764705882, + 0.5 / 1023.0, + 1.5 / 1023.0, + 0.5 / 65535.0, + 64512.0, + 0.04045, + 0.0031308, + 1e-300, + 1e300, + 65408.0, + 65409.0, + 65472.0, + 4.0, + 15.5, + 31.5, + 0.5 / 15.0, + 1.5 / 15.0, + 0.5 / 31.0, + 0.5 / 63.0, + 7.5, + 127.0, + 128.0, + 255.0, + 256.0, + -127.0, + -129.0, + 32767.0, + 32768.0, + -32768.0, + -32769.0, + 65535.0, + 65536.5, + 1023.0, + 1024.0, + 3.0, +]; + +/// Metal's packed texels on the M3 Max: per raw format, FNV-1a 64 of each color's 16 bytes. +const M3_PACKED: [(u32, u64); 88] = [ + (1, 0x09edfec5ceb46c15), + (10, 0xc9c13c3903ee05c5), + (11, 0x91840698df2fb605), + (12, 0x8c34d3a3b420f295), + (13, 0xa30563d1b5860fc5), + (14, 0x7a06935f97b26a95), + (20, 0xc68135c31da61975), + (22, 0xd52cb0e596e5e745), + (23, 0x49edaec300395f25), + (24, 0xf4f5acc15bc1c8a5), + (25, 0x55724d4ab40b2ff5), + (30, 0xa8c53744806ef6a5), + (31, 0x11b930bc12d532f5), + (32, 0x13106c5643ad0915), + (33, 0xb7a7b47ede539845), + (34, 0x7adcca3460058905), + (40, 0x3fc0aabdf07ed805), + (41, 0x7fac691931059b95), + (42, 0x786ebc82b38e2f25), + (43, 0x93dffcdb93bdb775), + (45, 0xff23f3bfc14a8de9), + (46, 0x819c9cc67ae4c0f1), + (47, 0xdb9aae03dd1048af), + (48, 0x0096ddf59054447f), + (53, 0xd9b569bf0bbab065), + (54, 0xa60a7baf26ce086d), + (55, 0x94f4d16646f6d9a5), + (60, 0xc77a5424bbb783e5), + (62, 0xdde97108d590f225), + (63, 0xbcf717c6a1a4ff6d), + (64, 0x9f6f4a4e74ed7705), + (65, 0x2199e75fae189785), + (70, 0xe53edf01bb6f303d), + (71, 0xbc2b181e0d9a0d75), + (72, 0xf251a7f2f355f4cd), + (73, 0xdade99c5318f42cd), + (74, 0xebd7b4edfa7fc595), + (80, 0xd251a65f568ed3dd), + (81, 0x062e31c5a7c12b85), + (90, 0xbcd8486fe7fb2fcd), + (91, 0xe88d71af8a76776d), + (92, 0x197e32a73afd2edd), + (93, 0xbf905eba1ea91305), + (94, 0xa8e269919fa4af4d), + (554, 0x1a355cbcdf254f85), + (555, 0xa3e7e7627a037ea5), + (95, 0x6e5a585f02d9d6f6), + (96, 0x162c1d4e842c288d), + (97, 0x0053089b91be3522), + (98, 0xc919f9f873a5096f), + (99, 0xd93a5277330f8870), + (103, 0xd1eb13b2e48809dd), + (104, 0xe383cd9bd4cd3715), + (105, 0x66524edfb6e70455), + (110, 0xa7bb1705af705785), + (112, 0x5cbe5bff4a89d42d), + (113, 0xbcacf412ae240b25), + (114, 0x331d1a1c86612dc1), + (115, 0xafcf19bb02807b41), + (552, 0x2c686bb72df7ed55), + (553, 0x00aa8ffa43139175), + (120, 0xab081fb39e2d9619), + (121, 0x30e12dd8a6191db4), + (122, 0x6f446a2ed5ecf115), + (123, 0xd188239b19020738), + (124, 0x82f23e151c22d281), + (125, 0x9665315fcfe99c0d), + (84, 0x153cbd6614195e0d), + (556, 0xe0eae52c31abe409), + (26, 0x67e399d5c9c84ea5), + (44, 0x1a0f09262b647425), + (66, 0x87e99425fb7ee38d), + (85, 0xd39dcc42959a4285), + (100, 0xe6d2826c04edd16d), + (116, 0xb19bd6f18907e405), + (300, 0x3227de0cfe6987d5), + (301, 0x6fd02644396c579d), + (302, 0x73da0649d9d0ec65), + (303, 0xe9be188576515e65), + (304, 0xde7a0a42b5222c25), + (313, 0x5ce2bd9ecff9ac71), + (314, 0xff1039e411496579), + (315, 0xafcf19bb02807b41), + (323, 0x034d7a4213b5384d), + (324, 0x7475d06a8616a702), + (325, 0x9665315fcfe99c0d), + (637, 0xd973f20b29bc22f5), + (638, 0x522fb7d7164e51e5), +]; + +/// The raw formats a color fill packs no color in on the M3 Max: its bytes are the calling +/// thread's stack. +const M3_UNPACKED: [u32; 213] = [ + 0, 130, 131, 132, 133, 134, 135, 140, 141, 142, 143, 150, 151, 152, 153, 160, 161, 162, 163, + 164, 165, 166, 167, 170, 172, 174, 176, 178, 179, 180, 181, 182, 183, 186, 187, 188, 189, 190, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 204, 205, 206, 207, 208, 210, 211, 212, 213, 214, + 215, 216, 217, 218, 222, 223, 224, 225, 226, 228, 229, 230, 231, 232, 233, 234, 235, 236, 240, + 241, 250, 252, 253, 255, 260, 261, 262, 263, 550, 551, 500, 502, 503, 505, 506, 507, 508, 509, + 510, 520, 522, 523, 525, 526, 527, 528, 529, 530, 540, 541, 542, 543, 544, 545, 546, 547, 548, + 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 580, 581, 582, 583, 584, 585, 591, + 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 608, 609, 610, 611, 612, 613, 615, 616, + 617, 618, 619, 620, 651, 652, 185, 191, 203, 209, 221, 227, 501, 504, 521, 524, 560, 562, 563, + 576, 577, 578, 579, 586, 587, 588, 589, 590, 603, 604, 605, 606, 607, 621, 622, 623, 624, 625, + 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 639, 640, 641, 642, 643, 644, 645, 646, + 647, 648, 649, 650, +]; + +/// The NaNs of our probe `pack.m`, by their bits: each in turn in every channel of a color whose +/// other channels are 0.5. +const PACK_NANS: [u64; 8] = [ + 0x7ff8_0000_0000_0000, + 0xfff8_0000_0000_0000, + 0x7ff0_0000_0000_0001, + 0xfff0_0000_0000_0001, + 0x7ffc_0000_0000_0000, + 0x7ff4_0000_0000_0000, + 0x7fff_ffff_ffff_ffff, + 0x7ff8_0000_0012_3456, +]; + +/// The colors of our probe `pack.m`, in its order: the specials' colors, 1024 colors of four +/// doubles from its xorshift (the top 53 bits of a step as a fraction of `2^53`, times 6, less +/// 3), then the NaNs'. +fn pack_colors() -> Vec<[f64; 4]> { + let n = PACK_SPECIALS.len(); + let mut colors: Vec<[f64; 4]> = (0..n) + .map(|i| [0, 1, 2, 3].map(|c| PACK_SPECIALS[(i + c) % n])) + .collect(); + let mut state = 0x9e37_79b9_7f4a_7c15u64; + for _ in 0..1024 { + colors.push([0; 4].map(|_| { + state ^= state << 13; + state ^= state >> 7; + state ^= state << 17; + (state >> 11) as f64 / 9_007_199_254_740_992.0 * 6.0 - 3.0 + })); + } + for bits in PACK_NANS { + for channel in 0..4 { + let mut color = [0.5; 4]; + color[channel] = f64::from_bits(bits); + colors.push(color); + } + } + colors +} + +/// Every pixel format on an Apple M3 Max under macOS 27.0.1 (our probes `classify.m` and +/// `pack.m`): a color fill packed in one of 88 formats writes its texel, which the runtime packs +/// byte for byte for each of the probe's 1,144 colors (each texel repeated or cut to the 16 bytes +/// of an `RGBA32Uint` texel); in each of the other 213 it writes bytes of the calling thread's +/// stack (a probe that set the stack below its call to one byte read that byte back), and the +/// runtime packs nothing. +#[test] +fn the_m3_packs_these_formats_and_no_other() { + let colors = pack_colors(); + assert_eq!(colors.len(), 1144); + let mut wrong = Vec::new(); + for (raw, metal) in M3_PACKED { + let pf = PixelFormat::try_from(raw).unwrap(); + let ours = colors.iter().flat_map(|&c| { + let texel = bytes(pf, c); + texel.iter().copied().cycle().take(16).collect::>() + }); + if fnv(ours) != metal { + wrong.push(pf); + } + } + assert!(wrong.is_empty(), "packings unlike Metal's: {wrong:?}"); + for raw in M3_UNPACKED { + let pf = PixelFormat::try_from(raw).unwrap(); + assert_eq!(fill_texel(pf, [0.5; 4]), None, "{pf:?}"); + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 28bfcefe1..098f20cad 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -23,6 +23,7 @@ mod binding_view; mod blit; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod blit_cover; +mod blit_fill; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod blit_holds; #[cfg(any(m2v_gpu, m2v_cpu_icd))] @@ -203,6 +204,7 @@ mod tracker; mod trails; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod twin_flights; +mod two_plane_rows; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod uniform_bind_offsets; mod unique_identifier; diff --git a/crates/metal2vulkan-runtime/src/tests/private_properties.rs b/crates/metal2vulkan-runtime/src/tests/private_properties.rs index 797898cb4..c35e861f0 100644 --- a/crates/metal2vulkan-runtime/src/tests/private_properties.rs +++ b/crates/metal2vulkan-runtime/src/tests/private_properties.rs @@ -282,8 +282,8 @@ fn the_core_count_and_fp16_are_the_devices() { /// The answers read from the device: the texture alignments are the 16 bytes the runtime takes a /// linear texture and an IOSurface plane at; ordered atomics follow the Vulkan memory model at /// device scope; the XR10 formats follow their family row; a half-float texture is filtered -/// bicubically everywhere; and `RGB10A2Unorm_sRGB`, which the runtime holds no texture of, is -/// filtered nowhere. +/// bicubically everywhere; and `RGB10A2Unorm_sRGB`, held as its raw word and filtered by the +/// function (`ExtendedRange::Rgb10A2Srgb`), is filtered everywhere. #[test] fn the_alignments_atomics_and_formats_are_the_devices() { use crate::families::{FamilyRow, FeatureRow, RowState}; @@ -323,6 +323,6 @@ fn the_alignments_atomics_and_formats_are_the_devices() { Some(true), "{stem}" ); - assert_eq!(flag(F::IsRgb10a2GammaSupported), Some(false), "{stem}"); + assert_eq!(flag(F::IsRgb10a2GammaSupported), Some(true), "{stem}"); } } diff --git a/crates/metal2vulkan-runtime/src/tests/two_plane_rows.rs b/crates/metal2vulkan-runtime/src/tests/two_plane_rows.rs new file mode 100644 index 000000000..af7b7bccf --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/two_plane_rows.rs @@ -0,0 +1,75 @@ +//! Which row's bytes stand where the rows of a blit into a two-plane extended-range texture at a +//! width off 4 meet (`two_planes/buffer_rows.rs`), against our probe `bpm.m`'s meetings (the M3 +//! Max under macOS 27.0.1, alike in two runs but between groups of 32 rows). + +use crate::two_planes::later_row_stands; + +/// Each case: the level's width, the region's origin, and Metal's meetings of its 70 rows, `E` +/// where the earlier row's bytes stood and `L` the later's. +const MEETINGS: [(u64, [u64; 2], &str); 8] = [ + ( + 5, + [0, 0], + "ELELELELELELELELELELELELELELELEEELELELELELELELELELELELELELELELEEELELE", + ), + ( + 5, + [0, 1], + "EEELEEELEEELEEELEEELEEELEEELEEEEEEELEEELEEELEEELEEELEEELEEELEEEEEEELE", + ), + ( + 7, + [1, 0], + "EEELEEELEEELEEELEEELEEELEEELEEEEEEELEEELEEELEEELEEELEEELEEELEEEEEEELE", + ), + ( + 7, + [2, 3], + "EEELEEELEEELEEELEEELEEELEEELEEEEEEELEEELEEELEEELEEELEEELEEELEEEEEEELE", + ), + ( + 13, + [0, 2], + "ELELELELELELELELELELELELELELELEEELELELELELELELELELELELELELELELEEELELE", + ), + ( + 19, + [1, 1], + "EEELEEELEEELEEELEEELEEELEEELEEEEEEELEEELEEELEEELEEELEEELEEELEEEEEEELE", + ), + ( + 31, + [2, 0], + "ELELELELELELELELELELELELELELELEEELELELELELELELELELELELELELELELEEELELE", + ), + ( + 31, + [1, 2], + "EEELEEELEEELEEELEEELEEELEEELEEEEEEELEEELEEELEEELEEELEEELEEELEEEEEEELE", + ), +]; + +/// Below a width of 32 the later row's bytes stand between pairs of rows from an even origin and +/// between fours from another, the earlier row's within them, as Metal's did; between groups of +/// 32 rows, and at a width of 32 or more, Metal's order varies and the rule names none. +#[test] +fn rows_meet_as_metal_s_gpu_writes_them() { + for (width, origin, metal) in MEETINGS { + for (r, letter) in metal.chars().enumerate() { + let r = r as u64; + let stands = later_row_stands(width, origin, r); + if r % 32 == 31 { + assert_eq!(stands, None, "{width} {origin:?} meeting {r}"); + } else { + assert_eq!( + stands, + Some(letter == 'L'), + "{width} {origin:?} meeting {r}" + ); + } + } + } + for width in [33, 37, 41, 101] { + assert!((0..64).all(|r| later_row_stands(width, [0, 0], r).is_none())); + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/view_plan.rs b/crates/metal2vulkan-runtime/src/tests/view_plan.rs index 8e8fd0ebd..9c8d5fcce 100644 --- a/crates/metal2vulkan-runtime/src/tests/view_plan.rs +++ b/crates/metal2vulkan-runtime/src/tests/view_plan.rs @@ -766,3 +766,35 @@ fn a_ycbcr_texture_retyped_is_refused_typed() { } } } + +/// Plain Metal views an `RGB10A2Unorm_sRGB` texture as `RGB10A2Unorm` and the other order (an +/// Apple M3 Max under macOS 27.0.1); their reads are not measured, so each is refused typed +/// (`NotImplemented(Format)`, naming the view's format), not as a pair Metal stops. A view in its +/// own format is made. +#[test] +fn an_rgb10a2_srgb_view_in_another_format_is_the_runtimes_gap() { + let (_, device) = lavapipe(); + let usage = TextureUsage::SHADER_READ | TextureUsage::PIXEL_FORMAT_VIEW; + for (pf, view) in [ + (PixelFormat::RGB10A2UnormSRGB, PixelFormat::RGB10A2Unorm), + (PixelFormat::RGB10A2Unorm, PixelFormat::RGB10A2UnormSRGB), + ] { + let source = texture(pf, usage); + let own = ViewRequest::of_format(&source, pf); + assert!( + check_view(&source, &own, device.profile()).is_ok(), + "{pf:?}" + ); + match check_view( + &source, + &ViewRequest::of_format(&source, view), + device.profile(), + ) { + Err(ViewRefusal::Unsupported(u)) => { + assert_eq!(u.feature, Feature::Format, "{pf:?} as {view:?}"); + assert_eq!(u.needs, Needs::NotImplemented, "{pf:?} as {view:?}"); + } + other => panic!("{pf:?} as {view:?}: {:?}", other.map(|_| ())), + } + } +} diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 3f68396de..9a548c1dd 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -528,6 +528,11 @@ struct Image { /// Whether a blit wrote bytes outside the image's texels, which Metal's blit of a two-plane /// extended-range texture keeps and the runtime does not hold (`two_planes.rs`). kept_outside: AtomicBool, + /// A two-plane extended-range texture's bytes between the rows of plane 0, which Metal's + /// fills and blits with a buffer write and its blits read back, and the image does not hold + /// (`two_planes/buffer_rows.rs`): plane 0 of each slice laid out as Metal lays it, made at + /// the first such write. + between: OnceLock, /// Its 32-bit float depth may hold a value whose magnitude stand-in is not itself (a negative /// value, a NaN, or, where the device's depth test compares a denormal as zero, a denormal), /// which a write that may store one set: a pass that loads it renders over its magnitude @@ -1781,6 +1786,7 @@ impl Device { second: OnceLock::new(), form: Default::default(), kept_outside: AtomicBool::new(false), + between: OnceLock::new(), signed_depth: AtomicBool::new(false), detached: Mutex::new(None), first_move: Mutex::new(Some(first)), @@ -1908,6 +1914,7 @@ impl Device { second: OnceLock::new(), form: Default::default(), kept_outside: AtomicBool::new(false), + between: OnceLock::new(), signed_depth: AtomicBool::new(false), detached: Mutex::new(None), first_move: Mutex::new(Some(first)), @@ -2530,6 +2537,7 @@ impl Device { second: OnceLock::new(), form: Default::default(), kept_outside: AtomicBool::new(false), + between: OnceLock::new(), signed_depth: AtomicBool::new(false), detached: Mutex::new(None), first_move: Mutex::new(None), @@ -2577,6 +2585,7 @@ impl Device { second: OnceLock::new(), form: Default::default(), kept_outside: AtomicBool::new(false), + between: OnceLock::new(), signed_depth: AtomicBool::new(false), detached: Mutex::new(None), first_move: Mutex::new(None), @@ -2973,6 +2982,7 @@ impl Device { second: OnceLock::new(), form: Default::default(), kept_outside: AtomicBool::new(false), + between: OnceLock::new(), signed_depth: AtomicBool::new(false), detached: Mutex::new(None), first_move: Mutex::new(None), @@ -4120,6 +4130,42 @@ impl Texture { } } + /// Whether bytes outside the texels of the texture's image were written: ones the runtime + /// holds ([`Texture::between_rows`]) or not ([`Texture::kept_outside`]). + pub(super) fn outside_written(&self) -> bool { + self.kept_outside() || self.between_rows().is_some() + } + + /// The bytes between the rows of a two-plane extended-range texture's plane 0 that its fills + /// and blits with a buffer wrote (`two_planes/buffer_rows.rs`); `None` before the first. + pub(super) fn between_rows(&self) -> Option<&Buffer> { + self.kept_image()?.between.get() + } + + /// [`Texture::between_rows`], made by `make` where none is yet: the buffer, and whether + /// `make` made it (its bytes, then, the caller's to zero). + pub(super) fn hold_between_rows( + &self, + make: impl FnOnce() -> Result, + ) -> Result<(Buffer, bool), Error> { + let image = self + .kept_image() + .ok_or_else(|| internal("bytes between the rows of a texture without an image"))?; + if let Some(held) = image.between.get() { + return Ok((held.clone(), false)); + } + let made = make()?; + match image.between.set(made.clone()) { + Ok(()) => Ok((made, true)), + Err(_) => image + .between + .get() + .cloned() + .map(|held| (held, false)) + .ok_or_else(|| internal("bytes between rows neither made nor held")), + } + } + /// Where the texture's two planes lie in its heap's bytes, as Metal lays them (a heap's /// one-level 2D two-plane texture, `texture/heap_two_planes.rs`): the heap, and the /// texture's first byte in it; `None` for any other texture, a view among them. @@ -5336,8 +5382,13 @@ impl Texture { if host.host_len().is_none_or(|len| (bytes.len() as u64) < len) { return Err(invalid(CALL, Problem::Copy(CopyProblem::BufferRange))); } - // A two-plane texture's color words, each texel's first word. - if planes { + // A two-plane texture's color words, each texel's first word; a heap shadow's are the + // heap's bytes, which `read_region` reads (as `replace_region` writes them). + let heap_shadow = matches!( + &self.0.storage, + Storage::Image(image) if matches!(image.owner, Owner::HeapShadow(_)) + ); + if planes && !heap_shadow { let mut words = vec![0; host.packed_len() as usize]; self.read_color_words(&image_region, &mut words)?; host.unpack(&words, bytes); diff --git a/crates/metal2vulkan-runtime/src/texture/heap.rs b/crates/metal2vulkan-runtime/src/texture/heap.rs index 839acddec..9338047c0 100644 --- a/crates/metal2vulkan-runtime/src/texture/heap.rs +++ b/crates/metal2vulkan-runtime/src/texture/heap.rs @@ -192,7 +192,7 @@ use metal2vulkan::vk::{ }; use std::ptr::NonNull; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, Mutex, OnceLock}; /// The alignment of a heap's memory: a heap texture whose answered alignment exceeds it is /// refused (`RuntimeGap::HeapTextureAlignment`, [`check_heap_base`]). It is the largest image @@ -2289,6 +2289,7 @@ impl Device { second: std::sync::OnceLock::new(), form: Default::default(), kept_outside: AtomicBool::new(false), + between: OnceLock::new(), signed_depth: AtomicBool::new(false), detached: Mutex::new(None), first_move: Mutex::new(None), @@ -2330,6 +2331,7 @@ impl Device { second: std::sync::OnceLock::new(), form: Default::default(), kept_outside: AtomicBool::new(false), + between: OnceLock::new(), signed_depth: AtomicBool::new(false), detached: Mutex::new(Some(DetachedImage { stand_in, diff --git a/crates/metal2vulkan-runtime/src/texture/wrapped.rs b/crates/metal2vulkan-runtime/src/texture/wrapped.rs index ce0ffd303..515a619ee 100644 --- a/crates/metal2vulkan-runtime/src/texture/wrapped.rs +++ b/crates/metal2vulkan-runtime/src/texture/wrapped.rs @@ -47,7 +47,7 @@ use metal2vulkan::vk::{ ImageUsageFlags, SampleCountFlags, }; use std::sync::atomic::AtomicBool; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, Mutex, OnceLock}; /// No Metal counterpart (an interop hook): the layouts of an image the caller owns around the /// runtime's work on it. The runtime finds the image in `initial` at the first batch that uses it, @@ -623,6 +623,7 @@ impl Device { second: std::sync::OnceLock::new(), form: Default::default(), kept_outside: AtomicBool::new(false), + between: OnceLock::new(), signed_depth: AtomicBool::new(false), detached: Mutex::new(None), first_move: Mutex::new(None), diff --git a/crates/metal2vulkan-runtime/src/two_planes.rs b/crates/metal2vulkan-runtime/src/two_planes.rs index 326a3dfe5..e31a3a0b0 100644 --- a/crates/metal2vulkan-runtime/src/two_planes.rs +++ b/crates/metal2vulkan-runtime/src/two_planes.rs @@ -19,8 +19,9 @@ //! 0's texels are lost or moved too. It is Metal's defect, which depends on the planes' layout in //! memory. A copy into the other format of the pair copies the same way. //! - At widths that are not a multiple of 4, blits between a buffer and the texture address its -//! rows the same way, so they move texels between rows too (into the texture, overlapping rows -//! in an order that varies); `getBytes` and `replaceRegion` move the texels at every width. +//! rows the same way, so they move texels between rows and the bytes between them too +//! (`two_planes/buffer_rows.rs` states the rows, measured on an Apple M3 Max under macOS +//! 27.0.1); `getBytes` and `replaceRegion` move the texels at every width. //! //! **Held** as one `R32G32_UINT` image (`metal::format::ExtendedRange::Planes`): each texel's //! color word, then its alpha byte in the second word. @@ -33,10 +34,12 @@ //! bands of rows ([`bands`]), one blit command: per band, one copy of its texels out of the //! image, one dispatch of `bind::plane_words_module` moving each texel's first word into the //! buffer's bytes or out of them, and, into the texture, one copy of the texels back. -//! - **Blits between a buffer and the texture** at a width that is not a multiple of 4 move the -//! texels at the texture's rows, a near-equivalent announced once per device -//! (`two-plane-buffer-blit`, precision): Metal's answer out of the texture is the model's -//! reads, but into it its rows overlap in an order that varies. +//! - **Blits between a buffer and the texture** at a width that is not a multiple of 4: a 2D +//! texture or array of one level is blitted at Metal's rows through a scratch buffer laid out +//! as plane 0 (`buffer_rows.rs`), announced (`two-plane-buffer-blit`, precision) where rows meet +//! in a blit into it and where a blit out of a texture of the device's memory reads bytes +//! between its rows that a fill or a blit wrote; any other such texture moves the texels at the +//! texture's rows, announced the same way. //! - **Blits between two such textures** of one level and one slice, 2D, each level within a //! storage buffer, move both planes' bytes as Metal's blit does (`modelled_plane_copies`): //! one command of the encoder, both levels copied into a scratch buffer, the kernel @@ -82,8 +85,13 @@ use metal2vulkan::metal::{PixelFormat, TextureType}; use metal2vulkan::vk::ImageAspectFlags; use std::ops::Range; +mod buffer_rows; mod heap_bytes; +#[cfg(test)] +pub(super) use buffer_rows::later_row_stands; +pub(super) use buffer_rows::{between_rows, buffer_blit_rows, row_spans, rows_held}; + use heap_bytes::{stage_planes, BytePlanes, Staged}; /// Whether `pf` is a two-plane extended-range format. @@ -530,7 +538,7 @@ impl BlitCommandEncoder { if let Some(planes) = BytePlanes::of(destination, to) { if self.plane_bytes_copy(source, destination, &planes, from, copy)? { if outside_texels(from, [sx, sy], size) - && source.kept_outside() + && source.outside_written() && BytePlanes::of(source, from).is_none() { announce_texture_copy( @@ -557,7 +565,7 @@ impl BlitCommandEncoder { // A source over a surface's planes is read as its bytes lie (`plane_texture_copy`). if !surfaces[0] && outside_texels(from, [sx, sy], size) - && (source.kept_outside() || source.heap().is_some()) + && (source.outside_written() || source.heap().is_some()) { announce_texture_copy( &device, diff --git a/crates/metal2vulkan-runtime/src/two_planes/buffer_rows.rs b/crates/metal2vulkan-runtime/src/two_planes/buffer_rows.rs new file mode 100644 index 000000000..03b0ba2c3 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/two_planes/buffer_rows.rs @@ -0,0 +1,357 @@ +//! Blits between a buffer and a two-plane extended-range texture of one level whose width is not a +//! multiple of 4, at the rows Metal's blit addresses. +//! +//! **Metal's answers** (an Apple M3 Max under macOS 27.0.1, our probe `bp.m`: 2D textures and +//! slices of arrays of their own memory, 3 to 101 texels wide, regions at origins; each texel's +//! color word set by `replaceRegion`, the texels read by `getBytes`; alike in every run): +//! +//! - Out of the texture, row `r` of the region reads the `4 w` bytes of plane 0 from +//! `(y + r) · ⌊4 W / 16⌋ · 16 + 4 x` (`W` the level's width), where the level's rows lie +//! `align(4 W, 16)` bytes apart: texels of the row it starts in and of the next, and the bytes +//! between the rows, 0 in a new texture and what a fill or a blit wrote there after. Below a +//! width of 4 the level's first row reads as it lies and every later row as 0. +//! - Into the texture, row `r` writes from `(y + r) · max(16, ⌊4 W / 16⌋ · 16) + 4 x`, the rows +//! a fill addresses (`blit_fill.rs`). Rows `r` and `r + 1` of the region meet where `w` +//! passes `⌊4 W / 16⌋ · 4` texels (probe `bpm.m`: 5 to 101 texels wide, 2 to 128 rows, origins +//! 0 to 2 across and 0 to 64 down, every meeting, run 2 to 5 times; alike for a buffer of +//! other rows and offsets, a slice of an array, a heap's texture, a `Private` one and the sRGB +//! twin). Below a width of 32 Metal's GPU writes the region's rows in groups of 32, and in each +//! in pairs where the origin's `x` and `y` are even, else in fours: within a pair or four the +//! earlier row's bytes stand where two meet, and between them the later row's, alike in every +//! run. Between groups of 32 rows, and at every meeting 32 texels wide or wider, the order +//! varies from run to run (the earlier row's bytes at 556 of 560 meetings between groups, and +//! at most meetings of the wider ones, the later row's at most meetings 3 or 5 rows high). +//! +//! **Held:** the level's rows the blit reaches go through a scratch buffer of the encoder laid +//! out as Metal's plane 0, rows `align(4 W, 16)` apart, one blit command a step: the scratch +//! zeroed, then the texels copied into it (`plane_words_copy`; for a heap's texture whose planes +//! lie in the heap's bytes, those bytes). Out of the texture, the region's rows are copied from +//! the scratch at Metal's addresses into the buffer (a row Metal reads as 0 from the scratch's +//! zeroed tail). Into it, the buffer's rows are copied into the scratch at Metal's addresses, the +//! row whose bytes Metal's stand where two meet ([`later_row_stands`]; the earlier row's where +//! Metal's order varies), and the scratch back into the texels (or the heap's bytes). A texture of the device's memory holds the bytes between its rows apart +//! (`Texture::between_rows`, plane 0 of each slice as Metal lays it out, made zeroed at the first +//! write there): a blit into the texture whose rows reach them, and a fill whose words land +//! there (`blit_fill.rs`), write them, and the scratch of a blit out of it starts from them. A +//! copy from another texture that writes bytes there does not (`two_planes.rs`): it notes them +//! (`Texture::keep_outside`), and a later blit out of the texture that reads them reads them as +//! the held bytes, announced (`two-plane-buffer-blit`), as is a blit into it 32 texels wide or +//! wider whose rows meet; one narrower whose rows meet between groups of 32 rows announces +//! `two-plane-buffer-blit-order`, the earlier row's bytes there, with Metal's order elsewhere, being +//! Metal's most frequent whole outcome. + +use super::super::blit::{reads, writes, BlitCommandEncoder}; +use super::super::blit_plan::BufferLayout; +use super::super::copy_plan::{level_extent, ImageRegion}; +use super::super::degradation::Degradation; +use super::super::error::Error; +use super::super::texture::Texture; +use super::super::values::ResourceOptions; +use super::super::Buffer; +use super::heap_bytes::BytePlanes; +use ash::vk; +use std::ops::Range; + +/// The bytes apart that Metal's blit addresses plane 0's rows of a level `width` texels wide at: +/// out of the texture (0 below a width of 4), or into it (`into_texture`). +pub(in super::super) fn buffer_blit_rows(width: u64, into_texture: bool) -> u64 { + let rows = 4 * width / 16 * 16; + if into_texture { + rows.max(16) + } else { + rows + } +} + +/// The bytes of plane 0 that each row of a blit of `size` texels (width, height) at `origin` +/// addresses in a level `width` texels wide, in order: `None` for a row Metal's blit out of the +/// texture reads as 0. +pub(in super::super) fn row_spans( + width: u64, + [x, y]: [u64; 2], + [w, h]: [u64; 2], + into_texture: bool, +) -> Vec>> { + let rows = buffer_blit_rows(width, into_texture); + (y..y + h) + .map(|row| { + let start = row * rows + 4 * x; + (rows > 0 || row == 0).then_some(start..start + 4 * w) + }) + .collect() +} + +/// Where rows `r` and `r + 1` of a blit into a level `width` texels wide from `origin` (`x`, `y`) +/// meet, whether the later row's bytes stand as Metal's GPU writes them (the module docs): +/// `Some(true)` between pairs of rows (an even origin) or fours (another) in a group of 32 rows, +/// `Some(false)` within them, `None` where Metal's order varies from run to run (between groups, +/// or 32 texels wide or wider). +pub(in super::super) fn later_row_stands(width: u64, [x, y]: [u64; 2], r: u64) -> Option { + if width >= 32 || r % 32 == 31 { + return None; + } + let rows = if x % 2 == 0 && y % 2 == 0 { 2 } else { 4 }; + Some(r % rows == rows - 1) +} + +/// Whether `span` of plane 0 of a level `width` texels wide holds bytes between its rows, which +/// lie `align(4 width, 16)` bytes apart. +pub(in super::super) fn between_rows(span: &Range, width: u64) -> bool { + let pitch = (4 * width).next_multiple_of(16); + if span.is_empty() || pitch == 4 * width { + return false; + } + (span.start / pitch..=(span.end - 1) / pitch).any(|row| { + let padding = row * pitch + 4 * width..(row + 1) * pitch; + padding.start.max(span.start) < padding.end.min(span.end) + }) +} + +/// Whether a texture's blits with a buffer at a width off 4 go through Metal's rows: a 2D +/// texture or array of one level, not a view, whose texels are not a surface's bytes. Metal's +/// answer for another (more levels: its blits read back bytes that vary from run to run) is not +/// measured. +pub(in super::super) fn rows_held(texture: &Texture) -> bool { + use metal2vulkan::metal::TextureType; + !texture.over_buffer() + && texture.parent_texture().is_none() + && texture.record().level_count == 1 + && matches!( + texture.texture_type(), + TextureType::Type2D | TextureType::Type2DArray + ) +} + +impl BlitCommandEncoder { + /// A blit between `buffer`, laid out as `layout`, and `region` (one slice) of a two-plane + /// extended-range texture of one level ([`rows_held`]) whose width is not a multiple of 4, at + /// Metal's rows (`into_texture` from the buffer; the module docs). + pub(in super::super) fn plane_rows_copy( + &mut self, + buffer: &Buffer, + texture: &Texture, + region: &ImageRegion, + layout: &BufferLayout, + into_texture: bool, + ) -> Result<(), Error> { + let [width, height, _] = level_extent(texture.record(), region.level).map(u64::from); + let [x, y, _] = region.origin.map(u64::from); + let [w, h, _] = region.size.map(u64::from); + if w == 0 || h == 0 { + return Ok(()); + } + let pitch = (4 * width).next_multiple_of(16); + let row_bytes = 4 * w; + let spans = row_spans(width, [x, y], [w, h], into_texture); + let first = spans.iter().flatten().map(|s| s.start / pitch).min(); + let last = spans.iter().flatten().map(|s| (s.end - 1) / pitch).max(); + // The level's rows `first..first + rows` in the scratch, then a zeroed row of the region. + let (first, rows) = match (first, last) { + (Some(first), Some(last)) => (first, last + 1 - first), + _ => (0, 0), + }; + let bytes = rows * pitch; + let total = bytes + row_bytes; + let device = self.core().device().clone(); + let scratch = device.own_buffer(total, ResourceOptions::private())?; + let (raw_scratch, at) = scratch.at(0); + self.command(&[writes(&scratch, 0..total)], |device, raw| { + // SAFETY: the command buffer is recording, outside a render pass; the scratch is + // retained until it completes; the fill covers its bytes, from a 4-byte multiple. + unsafe { device.cmd_fill_buffer(raw, raw_scratch, at, total, 0) }; + })?; + self.core().retain(scratch.clone()); + // Plane 0's bytes in a heap's, where they lie there; else the image's texels, over the + // bytes between its rows that fills and blits wrote (held from the slice's plane 0 on, + // `Texture::between_rows`). + let level = [width, height].map(|v| v as u32); + let planes = BytePlanes::of(texture, level).filter(|planes| !planes.surface); + let slice_at = u64::from(region.layer) * height * pitch + first * pitch; + if let (None, Some(held), true) = (&planes, texture.between_rows(), rows > 0) { + let held = held.clone(); + self.byte_copies(&held, &scratch, &[(slice_at, 0, bytes)])?; + } + let level_rows = ImageRegion { + origin: [0, first as u32, 0], + size: [width as u32, rows as u32, 1], + layers: 1, + ..*region + }; + let scratch_layout = BufferLayout { + offset: 0, + bytes_per_row: pitch, + bytes_per_image: bytes, + }; + if rows > 0 { + match &planes { + Some(planes) => { + let from = planes.color + first * pitch; + self.byte_copies(planes.bytes, &scratch, &[(from, 0, bytes)])?; + } + None => { + self.plane_words_copy(&scratch, texture, &level_rows, &scratch_layout, false)? + } + } + } + let pf = texture.pixel_format(); + let announce_as = |kind: Degradation, reason: &'static str| { + device.degrade(kind, || { + let object = format!( + "a blit between a buffer and a {} texture {width} texels wide", + pf.name() + ); + (object, reason.to_owned()) + }); + }; + let announce = |reason| announce_as(Degradation::TwoPlaneBufferBlit, reason); + let reaches_between = spans.iter().flatten().any(|s| between_rows(s, width)); + if !into_texture { + let copies: Vec<(u64, u64, u64)> = spans + .iter() + .enumerate() + .map(|(r, span)| { + let from = span.as_ref().map_or(bytes, |s| s.start - first * pitch); + ( + from, + layout.offset + r as u64 * layout.bytes_per_row, + row_bytes, + ) + }) + .collect(); + self.byte_copies(&scratch, buffer, &copies)?; + if planes.is_none() && reaches_between && texture.kept_outside() { + announce( + "out of the texture it reads the bytes between the texture's rows that a \ + copy from another texture wrote as 0; Metal's blit reads them back", + ); + } + return Ok(()); + } + // Each row cut where it meets the next and the later row's bytes stand, and from where + // the row before it ends where the earlier row's do (the earlier row's where Metal's + // order varies). Into the texture every row has a span, and only neighbours meet. + let spans: Vec> = spans.into_iter().flatten().collect(); + let stands = |r: usize| { + let meets = spans + .get(r + 1) + .is_some_and(|next| next.start < spans[r].end); + meets.then(|| later_row_stands(width, [x, y], r as u64)) + }; + let mut copies = Vec::with_capacity(spans.len()); + let mut varies = false; + for (r, span) in spans.iter().enumerate() { + let start = match r.checked_sub(1).and_then(stands) { + Some(Some(true)) | None => span.start, + Some(Some(false) | None) => span.start.max(spans[r - 1].end), + }; + let end = match stands(r) { + Some(Some(true)) => span.end.min(spans[r + 1].start), + Some(None) => { + varies = true; + span.end + } + Some(Some(false)) | None => span.end, + }; + if start < end { + let from = layout.offset + r as u64 * layout.bytes_per_row + (start - span.start); + copies.push((from, start - first * pitch, end - start)); + } + } + self.byte_copies(buffer, &scratch, &copies)?; + match &planes { + Some(planes) => { + let to = planes.color + first * pitch; + self.byte_copies(&scratch, planes.bytes, &[(0, to, bytes)])?; + } + None => { + self.plane_words_copy(&scratch, texture, &level_rows, &scratch_layout, true)?; + if reaches_between { + let held = self.held_between_rows(texture, [width, height])?; + self.byte_copies(&scratch, &held, &[(0, slice_at, bytes)])?; + } + } + } + if varies && width >= 32 { + announce( + "into the texture, where its rows meet, the earlier row's bytes stand; Metal's GPU \ + writes such rows of a texture 32 texels wide or wider in an order that varies \ + from run to run", + ); + } else if varies { + announce_as( + Degradation::TwoPlaneBufferBlitOrder, + "into the texture, where its rows meet between Metal's groups of 32 rows, the \ + earlier row's bytes stand, Metal's most frequent; Metal's GPU writes such rows \ + in an order that varies from run to run", + ); + } + Ok(()) + } + + /// The bytes between the rows of plane 0 of every slice of `texture`, a two-plane + /// extended-range texture of one level `level` (width, height) texels ([`rows_held`]), laid + /// out as Metal's plane 0 (`Texture::between_rows`): made, and zeroed in the command buffer, + /// at the first write that lands there. + pub(in super::super) fn held_between_rows( + &mut self, + texture: &Texture, + [width, height]: [u64; 2], + ) -> Result { + let pitch = (4 * width).next_multiple_of(16); + let length = u64::from(texture.record().layer_count) * height * pitch; + let device = self.core().device().clone(); + let (held, made) = + texture.hold_between_rows(|| device.own_buffer(length, ResourceOptions::private()))?; + if made { + let (raw, at) = held.at(0); + self.command(&[writes(&held, 0..length)], |device, command_buffer| { + // SAFETY: the command buffer is recording, outside a render pass; the buffer is + // the texture's, live while it is; the fill covers its bytes, a multiple of 16. + unsafe { device.cmd_fill_buffer(command_buffer, raw, at, length, 0) }; + })?; + } + self.core().retain(held.clone()); + Ok(held) + } + + /// Copy each `(from, to, bytes)` of `regions` from `source`'s bytes into `destination`'s, in + /// one command (the destinations disjoint; `source` and `destination` other buffers). + pub(in super::super) fn byte_copies( + &mut self, + source: &Buffer, + destination: &Buffer, + regions: &[(u64, u64, u64)], + ) -> Result<(), Error> { + let regions: Vec<(u64, u64, u64)> = regions.iter().copied().filter(|r| r.2 > 0).collect(); + let span = |at: fn(&(u64, u64, u64)) -> u64| -> Range { + let start = regions.iter().map(at).min().unwrap_or(0); + let end = regions.iter().map(|r| at(r) + r.2).max().unwrap_or(0); + start..end + }; + let (read, written) = (span(|r| r.0), span(|r| r.1)); + if read.is_empty() { + return Ok(()); + } + // Read as a blit's (`host_residency.rs`). + let (raw_source, source_base) = self.core().blit_at(source, 0)?; + let (raw_destination, destination_base) = self.core().blit_at(destination, 0)?; + let copies: Vec = regions + .iter() + .map(|&(from, to, size)| vk::BufferCopy { + src_offset: source_base + from, + dst_offset: destination_base + to, + size, + }) + .collect(); + let uses = [reads(source, read), writes(destination, written)]; + self.command(&uses, |device, raw| { + // SAFETY: the command buffer is recording, outside a render pass; both buffers are + // live and retained until it completes; every region lies inside both, and the two + // are other buffers. + unsafe { device.cmd_copy_buffer(raw, raw_source, raw_destination, &copies) }; + })?; + self.core().retain(source.clone()); + self.core().retain(destination.clone()); + Ok(()) + } +} diff --git a/crates/metal2vulkan-runtime/src/view_plan.rs b/crates/metal2vulkan-runtime/src/view_plan.rs index a64d05abd..5eb2eb188 100644 --- a/crates/metal2vulkan-runtime/src/view_plan.rs +++ b/crates/metal2vulkan-runtime/src/view_plan.rs @@ -401,11 +401,13 @@ fn check_format( )); } // A padded 10-bit texture's view in another format, or another texture's in one, is not - // measured: the runtime's gap. - if [source, view] - .into_iter() - .any(metal2vulkan::metal::format::padded_only_over_memory) - { + // measured: the runtime's gap. Nor is an `RGB10A2Unorm_sRGB` texture's view as + // `RGB10A2Unorm`, or the other order, which plain Metal makes (an Apple M3 Max under macOS + // 27.0.1), its reads unmeasured. + if [source, view].into_iter().any(|pf| { + metal2vulkan::metal::format::padded_only_over_memory(pf) + || ExtendedRange::of(pf) == Some(ExtendedRange::Rgb10A2Srgb) + }) { return Err(ViewRefusal::Unsupported( Unsupported::not_implemented(Feature::Format).naming_format(view), )); diff --git a/crates/metal2vulkan-validation/src/runtime_lane.rs b/crates/metal2vulkan-validation/src/runtime_lane.rs index 843ab522e..6402df74c 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane.rs @@ -677,6 +677,8 @@ mod resource_ids; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod restart; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] +mod rgb10a2_srgb; +#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod rgbx_textures; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod rotated_targets; @@ -693,6 +695,8 @@ mod same_texture_strips; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod sample_copies; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] +mod sample_fills; +#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod sample_positions; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod separate_samples; @@ -732,6 +736,8 @@ mod submit_per_import; mod sum_regroup; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod surface_aliases; +#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] +mod surface_fills; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd), target_os = "linux"))] mod surface_texture_costs; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] @@ -749,6 +755,8 @@ mod texture_accesses; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod texture_blits; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] +mod texture_buffer_fills; +#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod texture_creators; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod texture_fills; diff --git a/crates/metal2vulkan-validation/src/runtime_lane/color_fills.rs b/crates/metal2vulkan-validation/src/runtime_lane/color_fills.rs index 087f7a42b..60c790ce4 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/color_fills.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/color_fills.rs @@ -18,9 +18,10 @@ //! `0x04030201`: the SHA-256 of each range's `[start, length]` words and the buffer's bytes. //! //! - **Packed in another format** (our probe `fil5.m` on an Apple M3 Max under macOS 26.7 and an M4 -//! under macOS 27.0.1): 8 colors packed by `pixelFormat:` in each extended-range `_sRGB` format -//! into `RGBA32` textures first set to `0x5a`, every fill in one encoder, against Metal's texels; -//! a padded 10-bit packing is refused. +//! under macOS 27.0.1; `twins.m` on an M3 Max under macOS 27.0.1): 8 colors packed by +//! `pixelFormat:` in each extended-range `_sRGB` format into `RGBA32` textures first set to +//! `0x5a`, every fill in one encoder, against Metal's texels (alike one fill an encoder and one +//! a process); then one packed in each padded 10-bit format, in which Metal packs no color. //! //! The packing is the runtime's (`fill_value.rs`), checked against every measured texel without a //! device (`tests::fill_value`); this lane checks that each format's texture stores it as Metal's @@ -986,11 +987,12 @@ const PACKED_INTO_RGBA32: [(PixelFormat, [&str; 8]); 2] = [ /// A color packed by `pixelFormat:` in an extended-range `_sRGB` format into an `RGBA32` /// texture repeats the packed texel, as Metal's fills write it, every fill in one encoder; one -/// packed in a padded 10-bit format, whose texel Metal leaves one constant of its process's, fills -/// zero bytes, one constant for every color, and the device announces `unpacked-fill-color` once -/// (Refused `FillColorUnpacked` before). +/// packed in a padded 10-bit format, in which Metal packs no color, fills the 16 bytes the last +/// fills packed over zeros (the last `BGR10_XR_sRGB` texel over the last `BGRA10_XR_sRGB` one), +/// as Metal's consecutive fills find their packing's bytes, and the device announces +/// `unpacked-fill-color` once. #[test] -fn packings_in_another_format_repeat_and_padded_ones_fill_zero() { +fn packings_in_another_format_repeat_and_padded_ones_fill_the_last_packing() { let (messages, _cache, lane) = lane(); let name = lane.device.name().to_owned(); let mut wrong = Vec::new(); @@ -1057,12 +1059,11 @@ fn packings_in_another_format_repeat_and_padded_ones_fill_zero() { } } } - // The padded packings' fills wrote zero bytes into the texel past the packed ones. - let zeroed = hex(texel.next().unwrap()); - if zeroed != "00".repeat(16) { - wrong.push(format!( - "{target:?}: a padded packing's fill wrote {zeroed}" - )); + // The padded packings' fills wrote the last packings' bytes into the texel past the + // packed ones. + let slot = hex(texel.next().unwrap()); + if slot != "f7de7b2fc0bdc09f0000000000000000" { + wrong.push(format!("{target:?}: a padded packing's fill wrote {slot}")); } } // The `Shared` pattern buffers lie in system memory on a device without unified memory. diff --git a/crates/metal2vulkan-validation/src/runtime_lane/degrade_notices.rs b/crates/metal2vulkan-validation/src/runtime_lane/degrade_notices.rs index 930272cf0..33716e917 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/degrade_notices.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/degrade_notices.rs @@ -21,7 +21,9 @@ //! ([`WRAPPED`]), the shader-side stencil ([`SHADOW`]), tile dispatches ([`TILE_DISPATCHES`]), //! fragment imageblocks ([`FRAGMENT_IMAGEBLOCKS`]), command buffers' GPU times ([`GPU_TIMES`], //! [`UNTIMED`], [`FROM_HOST`]), color fills packed where fills ignore the color -//! ([`UNPACKED_FILL`]), draws of points no state sizes in `topology_classes` ([`UNSIZED_POINTS`]), +//! ([`UNPACKED_FILL`]), texture buffers' fills reading bytes past their pattern's copies in +//! `texture_buffer_fills` ([`TEXTURE_BUFFER_FILL`]), draws of points no state sizes in +//! `topology_classes` ([`UNSIZED_POINTS`]), //! resource IDs ([`RESOURCE_IDS`], [`UNLISTED`]), //! indirect command buffers' commands naming a released state ([`RELEASED_STATES`]) and their host //! steps ([`HOST_STEPS`]), indirect dispatches' host reads ([`INDIRECT_DISPATCHES`]), indexed draws @@ -321,6 +323,10 @@ pub(super) const UNTIMED: [Degradation; 1] = [Degradation::UntimedCommandBuffer] /// The kind `color_fills` takes on every venue, with a color packed in a padded 10-bit format. pub(super) const UNPACKED_FILL: [Degradation; 1] = [Degradation::UnpackedFillColor]; +/// The kind `texture_buffer_fills` takes on every venue, with fills whose chunks read bytes past +/// their pattern's whole copies. +pub(super) const TEXTURE_BUFFER_FILL: [Degradation; 1] = [Degradation::TextureBufferFillLeftover]; + /// The kind `gpu_times` takes on every venue, on a device made with `gpu_times_from_host`, and /// `first_use`'s busy work where the driver answers GPU times from the host /// (`gpu_times::read_kinds`). @@ -462,6 +468,7 @@ fn every_kind_has_a_site_a_lane_test_takes() { &GPU_TIMES, &UNTIMED, &UNPACKED_FILL, + &TEXTURE_BUFFER_FILL, &FROM_HOST, &RESOURCE_IDS, &UNLISTED, diff --git a/crates/metal2vulkan-validation/src/runtime_lane/heap_metal_sizes.rs b/crates/metal2vulkan-validation/src/runtime_lane/heap_metal_sizes.rs index 7a914e363..3ee90bc8c 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/heap_metal_sizes.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/heap_metal_sizes.rs @@ -126,7 +126,10 @@ fn pattern(n: u64, seed: u8) -> Vec { } /// Two textures of `descriptor` (2D, `extent`, `texel` bytes a texel), side by side at its -/// `answer` in a placement heap: each keeps its own texels, the second's written first. +/// `answer` in a placement heap: each keeps its own texels, the second's written first, reading +/// back what one texture of the descriptor alone reads back after the same blits (its bytes, but +/// where Metal's blits address other rows: a two-plane texture's at a width off 4, +/// `two_plane_copies.rs`). fn side_by_side( device: &Device, descriptor: &TextureDescriptor, @@ -150,14 +153,19 @@ fn side_by_side( let (a, b) = (pattern(row * extent[1], 3), pattern(row * extent[1], 101)); upload(&queue, &second, &b, row, extent); upload(&queue, &first, &a, row, extent); + let alone = |bytes: &[u8]| { + let texture = device.new_texture(descriptor).unwrap(); + upload(&queue, &texture, bytes, row, extent); + download(&queue, &texture, row, extent) + }; assert_eq!( download(&queue, &first, row, extent), - a, + alone(&a), "{what}: the first" ); assert_eq!( download(&queue, &second, row, extent), - b, + alone(&b), "{what}: the second" ); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/rgb10a2_srgb.rs b/crates/metal2vulkan-validation/src/runtime_lane/rgb10a2_srgb.rs new file mode 100644 index 000000000..bc95bb04f --- /dev/null +++ b/crates/metal2vulkan-validation/src/runtime_lane/rgb10a2_srgb.rs @@ -0,0 +1,657 @@ +//! `RGB10A2Unorm_sRGB` (586) textures on the device the cfg selects, under the validation layer, +//! against Metal's answers. +//! +//! Metal's answers: an Apple M3 Max under macOS 27.0.1, our own probes (`codes.m`, `s.m` and +//! `r.m`, no guest data), each the SHA-256 (first 16 hex digits) of the probe's printed lines, +//! which the lane prints alike from what the device returns: +//! +//! - **Reads.** A 1024 x 1 texture of words `c | (1023 - c) << 10 | (7 c mod 1024) << 20 | +//! (c mod 4) << 30`, each texel read by a kernel (`fpv_bfloat_fetch`): `read +//! `, the `float` lanes' bits. +//! - **Writes.** A kernel's write (`fpv_bfloat_write`) of `k / 16384` in red, green and blue and +//! `(k mod 4096) / 4095` in alpha, `k` from 0 to 16384, then 16 specials in every channel, into a +//! texture 4096 texels wide: `write `. +//! - **Samples.** A 16 x 16 texture of the probe's xorshift words, sampled through a runtime +//! sampler (clamp to edge, nearest and linear) at 4096 of its positions `(n, m) / 4096`, with +//! `float` and `half` results (`xr_sample_runtime`, `xr_sample_runtime_half`): `s +//! ` and the lanes' bits. +//! - **Clears.** 2,069 clear colors `(v, v / 2, v / 4, a)` through a `Clear` load action and no +//! draw, into a 1 x 1 target of render target and shader read usage and a 64 x 64 one of render +//! target usage alone: `clear ` of its last texel. Both shapes clear through +//! `half`. +//! - **Stores.** A full-screen draw of the owned fixture `rt6_samples`'s fill (`float4` and +//! `half4` outputs) of the writes' values into a new 4096 x 5 target: `store +//! `. A `float` output rounds to `half` toward zero first. +//! - **Loads.** A 1024 x 4 target holding every color code in each channel and each alpha code, +//! loaded and stored by a pass whose draw writes another attachment alone: `load +//! `. Each color code moves as `R10Unorm_X6_sRGB`'s does (`ExtendedRange::load_code`, +//! the runtime's load pass), alpha's stays. +//! +//! The device's `isRGB10A2GammaSupported` answers as the texture's linear filter does. A +//! difference is printed on an `RGB10A2-SRGB-DIFFERS` line. + +use super::degrade_notices::on_device; +use super::extended_range_samples::state_of; +use super::resolves::{lane_with, quiet, Lane}; +use super::{buffer_with, read_buffer, WAIT}; +use crate::candidate::runtime_samples::{library, shape}; +use metal2vulkan::bind::SamplerDescriptor; +use metal2vulkan::metal::{PixelFormat, PrimitiveType, SamplerMinMagFilter, TextureUsage}; +use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource}; +use metal2vulkan_runtime::{ + BlitOption, Buffer, ClearColor, CommandBufferStatus, ComputePipelineState, Device, LoadAction, + Origin, PipelineOptions, PrivateFlag, Region, RenderPassDescriptor, RenderPipelineState, + ResourceOptions, SamplerState, Size, StoreAction, Texture, TextureDescriptor, +}; +use sha2::{Digest, Sha256}; +use std::fmt::Write as _; + +const PF: PixelFormat = PixelFormat::RGB10A2UnormSRGB; + +/// Metal's digests: reads, writes, samples (nearest `float`, nearest `half`, linear `float`, +/// linear `half`), clears (1 x 1, 64 x 64), stores (`float`, `half`) and loads. +const READS: &str = "492c1e326a4685c8"; +const WRITES: &str = "631db99cd110dab6"; +const SAMPLES: [[&str; 2]; 2] = [ + ["5f73627c39064d55", "4460054d432720d8"], + ["36b79f318a83d9ac", "e1978cceb4591a05"], +]; +const CLEARS: [&str; 2] = ["325c8263917a086f", "8b361b1736bc7625"]; +const STORES: [&str; 2] = ["27b2e44d676d4976", "26b22082a3e6db54"]; +const LOADS: &str = "308f150fdcbbb82a"; + +/// The first 16 hex digits of the SHA-256 of `text`. +fn digest(text: &str) -> String { + Sha256::digest(text.as_bytes()) + .iter() + .take(8) + .map(|b| format!("{b:02x}")) + .collect() +} + +/// A 2D texture of the format, `width` x `height`, of `usage`, in `options`' storage. +fn texture( + device: &Device, + (width, height): (u64, u64), + usage: TextureUsage, + options: ResourceOptions, +) -> Texture { + let mut descriptor = TextureDescriptor::texture_2d(PF, width, height, false); + descriptor.usage = usage; + descriptor.resource_options = options; + device + .new_texture(&descriptor) + .unwrap_or_else(|e| panic!("a 586 texture: {e}")) +} + +/// A texture's words, row after row. +fn words_of(texture: &Texture, (width, height): (u64, u64)) -> Vec { + let mut bytes = vec![0u8; (4 * width * height) as usize]; + texture + .get_bytes( + &mut bytes, + 4 * width, + 0, + Region::new_2d(0, 0, width, height), + 0, + 0, + ) + .unwrap(); + words(&bytes) +} + +fn words(bytes: &[u8]) -> Vec { + bytes + .as_chunks::<4>() + .0 + .iter() + .map(|w| u32::from_le_bytes(*w)) + .collect() +} + +/// Run `state` over `texture` with `buffers` at 0 and up, `threads` (width, height) of them. +fn dispatch( + device: &Device, + state: &ComputePipelineState, + texture: &Texture, + (sampler, buffers): (Option<&SamplerState>, &[&Buffer]), + threads: (u64, u64), +) { + let queue = device.new_command_queue().unwrap(); + let command_buffer = queue.command_buffer().unwrap(); + let mut encoder = command_buffer.compute_command_encoder().unwrap(); + encoder.set_compute_pipeline_state(state).unwrap(); + encoder.set_texture(Some(texture), 0).unwrap(); + if let Some(sampler) = sampler { + encoder.set_sampler_state(Some(sampler), 0).unwrap(); + } + for (index, buffer) in buffers.iter().enumerate() { + encoder.set_buffer(Some(buffer), 0, index as u32).unwrap(); + } + encoder + .dispatch_threads(Size::new(threads.0, threads.1, 1), Size::new(64, 1, 1)) + .unwrap(); + encoder.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(command_buffer.status(), CommandBufferStatus::Completed); + assert_eq!(command_buffer.error(), None); +} + +/// The writes' and stores' specials (`codes.m`). +const WRITE_SPECIALS: [f32; 16] = [ + -0.0, + -1.0, + f32::NAN, + -f32::NAN, + f32::INFINITY, + f32::NEG_INFINITY, + 1.5, + 2.0, + 1e-30, + 1e-45, + 0.999_999_94, + 1.000_000_1, + 0.5 / 8192.0, + 1.5 / 8192.0, + 0.003_130_8, + 0.040_45, +]; + +/// The clears' and stores' specials (`r.m`). +const RENDER_SPECIALS: [f32; 20] = [ + -0.0, + -1.0, + f32::NAN, + f32::INFINITY, + f32::NEG_INFINITY, + 1.5, + 2.0, + 1e-30, + 0.999_999_94, + 1.000_000_1, + 0.5 / 8192.0, + 1.5 / 8192.0, + 0.003_130_8, + 0.040_45, + 65504.0, + 65520.0, + 0.333_333_34, + 0.166_666_67, + 0.5, + 0.833_333_3, +]; + +/// The values the probes write or draw at `k`: `k / 16384` in red, green and blue and `(k mod +/// 4096) / 4095` in alpha, then each special in every channel; zeros up to `len`. +fn values(specials: &[f32], len: usize) -> Vec<[f32; 4]> { + let n = 16385 + specials.len(); + (0..len) + .map(|k| match k { + _ if k < 16385 => { + let v = k as f32 / 16384.0; + [v, v, v, (k % 4096) as f32 / 4095.0] + } + _ if k < n => [specials[k - 16385]; 4], + _ => [0.0; 4], + }) + .collect() +} + +/// The `half` of `v`, rounded to nearest even (MSL's conversion), a NaN `0x7e00`. +fn half_bits(v: f32) -> u16 { + if v.is_nan() { + return 0x7e00; + } + let b = v.to_bits(); + let sign = ((b >> 16) & 0x8000) as u16; + let a = f64::from(v.abs()); + if a >= 65520.0 { + return sign | 0x7c00; + } + // The nearest multiple of the `half` ulp at `a`, ties to even, exactly in `f64`. + let e = if a < 2f64.powi(-14) { + -24 + } else { + a.log2().floor() as i32 - 10 + }; + let q = (a / 2f64.powi(e)).round_ties_even() * 2f64.powi(e); + let h = if q < 2f64.powi(-14) { + (q / 2f64.powi(-24)) as u16 + } else { + let e = q.log2().floor() as i32; + let m = (q / 2f64.powi(e) - 1.0) * 1024.0; + (((e + 15) as u16) << 10) | m as u16 + }; + sign | h +} + +/// The xorshift step of the sample probe (`s.m`). +fn xorshift(s: &mut u64) -> u64 { + *s ^= *s << 13; + *s ^= *s >> 7; + *s ^= *s << 17; + *s +} + +/// Reads, writes and samples of a 586 texture by a kernel are Metal's. +#[test] +fn kernels_read_write_and_sample_rgb10a2_srgb_as_metal_does() { + on_device(|device, _| { + let mut wrong = Vec::new(); + let shared = ResourceOptions::shared(); + // Reads. + let fetch = state_of(device, "fpv_bfloat_textures", "fpv_bfloat_fetch"); + let source: Vec = (0..1024u32) + .map(|c| c | (1023 - c) << 10 | (7 * c % 1024) << 20 | (c % 4) << 30) + .collect(); + let t = texture(device, (1024, 1), TextureUsage::SHADER_READ, shared); + let bytes: Vec = source.iter().flat_map(|w| w.to_le_bytes()).collect(); + t.replace_region(Region::new_2d(0, 0, 1024, 1), 0, 0, &bytes, 4096, 0) + .unwrap(); + let out = buffer_with(device, &vec![0xab; 1024 * 16]).unwrap(); + let width = buffer_with(device, &1024u32.to_le_bytes()).unwrap(); + dispatch(device, &fetch, &t, (None, &[&out, &width]), (1024, 1)); + let got = words(&read_buffer(&out, 0, 1024 * 16).unwrap()); + let mut text = String::new(); + for (c, w) in got.as_chunks::<4>().0.iter().enumerate() { + writeln!( + text, + "read {c} {:08x} {:08x} {:08x} {:08x}", + w[0], w[1], w[2], w[3] + ) + .unwrap(); + } + if digest(&text) != READS { + wrong.push(format!("reads {} (Metal's {READS})", digest(&text))); + } + // Writes. + let write = state_of(device, "fpv_bfloat_textures", "fpv_bfloat_write"); + let n = 16385 + WRITE_SPECIALS.len(); + let height = n.div_ceil(4096) as u64; + let input: Vec = values(&WRITE_SPECIALS, 4096 * height as usize) + .iter() + .flatten() + .flat_map(|v| v.to_le_bytes()) + .collect(); + let input = buffer_with(device, &input).unwrap(); + let width = buffer_with(device, &4096u32.to_le_bytes()).unwrap(); + let t = texture(device, (4096, height), TextureUsage::SHADER_WRITE, shared); + dispatch( + device, + &write, + &t, + (None, &[&input, &width]), + (4096, height), + ); + let got = words_of(&t, (4096, height)); + let mut text = String::new(); + for (k, w) in got.iter().take(n).enumerate() { + writeln!(text, "write {k} {w:08x}").unwrap(); + } + if digest(&text) != WRITES { + wrong.push(format!("writes {} (Metal's {WRITES})", digest(&text))); + } + // Samples. + let mut s = 0x243f_6a88_85a3_08d3u64; + let texels: Vec = (0..256) + .flat_map(|_| ((xorshift(&mut s) >> 17) as u32).to_le_bytes()) + .collect(); + let t = texture(device, (16, 16), TextureUsage::SHADER_READ, shared); + t.replace_region(Region::new_2d(0, 0, 16, 16), 0, 0, &texels, 64, 0) + .unwrap(); + let positions: Vec<(i64, i64)> = (0..4096) + .map(|_| { + let s = xorshift(&mut s); + ((s % 4608) as i64 - 256, ((s >> 20) % 4608) as i64 - 256) + }) + .collect(); + let coords: Vec = positions + .iter() + .flat_map(|&(n, m)| [n as f32 / 4096.0, m as f32 / 4096.0]) + .flat_map(f32::to_le_bytes) + .collect(); + let coords = buffer_with(device, &coords).unwrap(); + for (linear, filter) in [SamplerMinMagFilter::Nearest, SamplerMinMagFilter::Linear] + .into_iter() + .enumerate() + { + let mut descriptor = SamplerDescriptor::new(); + descriptor.min_filter = filter; + descriptor.mag_filter = filter; + let sampler = device.new_sampler_state(&descriptor).unwrap(); + for (half, name) in ["xr_sample_runtime", "xr_sample_runtime_half"] + .into_iter() + .enumerate() + { + let state = state_of(device, "xr_samples", name); + let size = if half == 1 { 8 } else { 16 }; + let out = buffer_with(device, &vec![0xab; 4096 * size]).unwrap(); + dispatch( + device, + &state, + &t, + (Some(&sampler), &[&coords, &out]), + (4096, 1), + ); + let bytes = read_buffer(&out, 0, 4096 * size as u64).unwrap(); + let mut text = String::new(); + for (&(n, m), v) in positions.iter().zip(bytes.chunks_exact(size)) { + match half { + 1 => { + let h = |c: usize| u16::from_le_bytes([v[2 * c], v[2 * c + 1]]); + writeln!( + text, + "s {linear} h {n} {m} {:04x} {:04x} {:04x} {:04x}", + h(0), + h(1), + h(2), + h(3) + ) + } + _ => { + let w = words(v); + writeln!( + text, + "s {linear} f {n} {m} {:08x} {:08x} {:08x} {:08x}", + w[0], w[1], w[2], w[3] + ) + } + } + .unwrap(); + } + let want = SAMPLES[linear][half]; + if digest(&text) != want { + wrong.push(format!( + "samples linear {linear} half {half}: {} (Metal's {want}); first: {}", + digest(&text), + text.lines().next().unwrap_or_default() + )); + } + } + } + for line in &wrong { + println!("RGB10A2-SRGB-DIFFERS {}: {line}", device.name()); + } + assert!( + wrong.is_empty(), + "{} answers differ from Metal's", + wrong.len() + ); + let gamma = device + .private_properties() + .flag(PrivateFlag::IsRgb10a2GammaSupported); + assert_eq!(gamma.value(), Some(true), "isRGB10A2GammaSupported"); + }); +} + +/// The pipeline of the fixture `rt6_samples`'s fill `fragment` into a 586 color attachment +/// `index` (attachment 0 an `RGBA32Float` one where `index` is 1). +fn pipeline(lane: &Lane, fragment: &str, index: usize) -> RenderPipelineState { + let library = library(&lane.device).unwrap(); + let function = |name: &str| { + StageSource::Function( + library + .new_function_with_name(name) + .unwrap() + .function_descriptor(), + ) + }; + let mut state = RenderPipelineDescriptor::new(function("rt6_fill_vertex")); + state.fragment = Some(function(fragment)); + if index == 1 { + state.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Float)); + } + state.color_attachments[index] = Some(ColorAttachmentDescriptor::new(PF)); + lane.device + .new_render_pipeline_state(&state, &PipelineOptions::default()) + .unwrap_or_else(|e| panic!("{fragment}: the pipeline: {e}")) +} + +/// A private texture's words through a blit into a buffer. +fn blit_words(lane: &Lane, target: &Texture, (width, height): (u64, u64)) -> Vec { + let length = 4 * width * height; + let back = buffer_with(&lane.device, &vec![0xcd; length as usize]).unwrap(); + let command_buffer = lane.queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + blit.copy_from_texture_to_buffer( + target, + 0, + 0, + Origin::new(0, 0, 0), + Size::new(width, height, 1), + &back, + 0, + 4 * width, + length, + BlitOption::None, + ) + .unwrap(); + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(command_buffer.error(), None); + words(&read_buffer(&back, 0, length).unwrap()) +} + +/// Clears, a draw's stores and a loading pass's rewrite of a 586 attachment are Metal's. +#[test] +fn passes_clear_store_and_load_rgb10a2_srgb_as_metal_does() { + let (messages, _cache, lane) = lane_with(|_| {}); + let mut wrong = Vec::new(); + // Clears. + let colors: Vec<[f64; 4]> = (0..2049 + RENDER_SPECIALS.len()) + .map(|k| match k { + _ if k < 2049 => { + let v = k as f64 / 2048.0; + [v, v * 0.5, v * 0.25, (k % 64) as f64 / 63.0] + } + _ => { + let v = f64::from(RENDER_SPECIALS[k - 2049]); + [v, v * 0.5, v * 0.25, v] + } + }) + .collect(); + for (shape_index, (side, usage)) in [ + ( + 1u64, + TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ, + ), + (64, TextureUsage::RENDER_TARGET), + ] + .into_iter() + .enumerate() + { + let target = texture( + &lane.device, + (side, side), + usage, + ResourceOptions::private(), + ); + let n = colors.len() as u64; + let out = buffer_with(&lane.device, &vec![0xab; (4 * n) as usize]).unwrap(); + for batch in (0..n).step_by(256) { + let command_buffer = lane.queue.command_buffer().unwrap(); + for i in batch..(batch + 256).min(n) { + let [r, g, b, a] = colors[i as usize]; + let mut pass = RenderPassDescriptor::new(); + let color = &mut pass.color_attachments[0]; + color.texture = Some(target.clone()); + color.load_action = LoadAction::Clear; + color.store_action = StoreAction::Store; + color.clear_color = ClearColor::new(r, g, b, a); + command_buffer + .render_command_encoder(&pass) + .unwrap() + .end_encoding() + .unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + blit.copy_from_texture_to_buffer( + &target, + 0, + 0, + Origin::new(side - 1, side - 1, 0), + Size::new(1, 1, 1), + &out, + 4 * i, + 4, + 4, + BlitOption::None, + ) + .unwrap(); + blit.end_encoding().unwrap(); + } + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(command_buffer.error(), None); + } + let got = words(&read_buffer(&out, 0, 4 * n).unwrap()); + let mut text = String::new(); + for (k, w) in got.iter().enumerate() { + writeln!(text, "clear {shape_index} {k} {w:08x}").unwrap(); + } + let want = CLEARS[shape_index]; + if digest(&text) != want { + wrong.push(format!( + "clears {side}x{side}: {} (Metal's {want})", + digest(&text) + )); + } + } + // Stores. + let n = 16385 + RENDER_SPECIALS.len(); + let height = n.div_ceil(4096) as u64; + let all = values(&RENDER_SPECIALS, 4096 * height as usize); + for (half, fragment) in ["rt6_fill_rgba32float", "rt6_fill_rgba16float"] + .into_iter() + .enumerate() + { + let state = pipeline(&lane, fragment, 0); + let bytes: Vec = match half { + 1 => all + .iter() + .flatten() + .flat_map(|&v| half_bits(v).to_le_bytes()) + .collect(), + _ => all.iter().flatten().flat_map(|v| v.to_le_bytes()).collect(), + }; + let values = buffer_with(&lane.device, &bytes).unwrap(); + let shape = shape(&lane.device, 4096, 1).unwrap(); + let target = texture( + &lane.device, + (4096, height), + TextureUsage::RENDER_TARGET, + ResourceOptions::private(), + ); + let mut descriptor = RenderPassDescriptor::new(); + let color = &mut descriptor.color_attachments[0]; + color.texture = Some(target.clone()); + color.load_action = LoadAction::DontCare; + color.store_action = StoreAction::Store; + lane.run(&descriptor, |_, e, _| { + e.set_render_pipeline_state(&state).unwrap(); + e.set_fragment_buffer(Some(&values), 0, 0).unwrap(); + e.set_fragment_buffer(Some(&shape), 0, 1).unwrap(); + e.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0) + .unwrap(); + }) + .unwrap_or_else(|e| panic!("{fragment}: the pass: {e}")); + let got = blit_words(&lane, &target, (4096, height)); + let kind = if half == 1 { "half" } else { "float" }; + let mut text = String::new(); + for (k, w) in got.iter().take(n).enumerate() { + writeln!(text, "store {kind} {k} {w:08x}").unwrap(); + } + if digest(&text) != STORES[half] { + wrong.push(format!( + "stores {kind}: {} (Metal's {})", + digest(&text), + STORES[half] + )); + } + } + // Loads: the 586 target is attachment 1, the fill's attachment 0. + let before: Vec = (0..4096u32) + .map(|i| { + let c = i % 1024; + c | (c * 7 % 1024) << 10 | (c * 13 % 1024) << 20 | (i / 1024) << 30 + }) + .collect(); + let target = texture( + &lane.device, + (1024, 4), + TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ, + ResourceOptions::shared(), + ); + let bytes: Vec = before.iter().flat_map(|w| w.to_le_bytes()).collect(); + target + .replace_region(Region::new_2d(0, 0, 1024, 4), 0, 0, &bytes, 4096, 0) + .unwrap(); + let state = pipeline(&lane, "rt6_fill_rgba32float", 1); + let fill: Vec = (0..4096) + .flat_map(|_| [1.0f32; 4]) + .flat_map(f32::to_le_bytes) + .collect(); + let fill = buffer_with(&lane.device, &fill).unwrap(); + let shape = shape(&lane.device, 1024, 1).unwrap(); + let drawn = lane + .device + .new_texture(&{ + let mut d = TextureDescriptor::texture_2d(PixelFormat::RGBA32Float, 1024, 4, false); + d.usage = TextureUsage::RENDER_TARGET; + d.resource_options = ResourceOptions::private(); + d + }) + .unwrap(); + let mut descriptor = RenderPassDescriptor::new(); + let other = &mut descriptor.color_attachments[0]; + other.texture = Some(drawn); + other.load_action = LoadAction::DontCare; + other.store_action = StoreAction::Store; + let color = &mut descriptor.color_attachments[1]; + color.texture = Some(target.clone()); + color.load_action = LoadAction::Load; + color.store_action = StoreAction::Store; + lane.run(&descriptor, |_, e, _| { + e.set_render_pipeline_state(&state).unwrap(); + e.set_fragment_buffer(Some(&fill), 0, 0).unwrap(); + e.set_fragment_buffer(Some(&shape), 0, 1).unwrap(); + e.draw_primitives(PrimitiveType::Triangle, 0, 3, 1, 0) + .unwrap(); + }) + .unwrap_or_else(|e| panic!("the load pass: {e}")); + let after = words_of(&target, (1024, 4)); + let mut text = String::new(); + for (i, (b, a)) in before.iter().zip(&after).enumerate() { + writeln!(text, "load {i} {b:08x} {a:08x}").unwrap(); + } + if digest(&text) != LOADS { + wrong.push(format!("loads {} (Metal's {LOADS})", digest(&text))); + } + for line in &wrong { + println!("RGB10A2-SRGB-DIFFERS {}: {line}", lane.device.name()); + } + assert!( + wrong.is_empty(), + "{} answers differ from Metal's", + wrong.len() + ); + quiet(lane, &messages); +} + +/// The lane's `half` conversion is MSL's round to nearest even. +#[test] +fn half_bits_round_to_nearest_even() { + assert_eq!(half_bits(1.0), 0x3c00); + assert_eq!(half_bits(-2.0), 0xc000); + assert_eq!(half_bits(65504.0), 0x7bff); + assert_eq!(half_bits(65520.0), 0x7c00); + assert_eq!(half_bits(f32::NEG_INFINITY), 0xfc00); + assert_eq!(half_bits(1.0 + 1.0 / 2048.0), 0x3c00); + assert_eq!(half_bits(1.0 + 3.0 / 2048.0), 0x3c02); + assert_eq!(half_bits(2f32.powi(-24)), 0x0001); + assert_eq!(half_bits(2f32.powi(-25)), 0x0000); + assert_eq!(half_bits(3.0 * 2f32.powi(-25)), 0x0002); + assert_eq!(half_bits(0.333_333_34), 0x3555); + assert_eq!(half_bits(1e-30), 0); +} diff --git a/crates/metal2vulkan-validation/src/runtime_lane/sample_fills.rs b/crates/metal2vulkan-validation/src/runtime_lane/sample_fills.rs new file mode 100644 index 000000000..ec8e91a1a --- /dev/null +++ b/crates/metal2vulkan-validation/src/runtime_lane/sample_fills.rs @@ -0,0 +1,534 @@ +//! Metal's private texture fills of multisample textures (`BlitCommandEncoder::fill_texture` and +//! `fill_texture_color`), on the device the cfg selects, under the validation layer, against +//! Metal's samples. +//! +//! Each case replays one of our probe `ms.m`'s (an Apple M3 Max under macOS 27.0.1): a private +//! multisample texture of 5 x 3 texels (a 2-slice array for one), every slice cleared by a pass +//! (color `(0.25, 0.5, 0.75, 1)`, depth 0.25, stencil `0x5a`), one fill, and every sample read +//! back by a dispatch: a color format's bits through an unsigned view of its components +//! (`candidate::runtime_samples`), a depth's bits, a stencil's value (`Depth32Float_Stencil8`'s +//! through its `X32_Stencil8` view). Metal's answer per case is the first 16 hex digits of the +//! SHA-256 of the probe's read-back lines, `after s y:` and each texel's samples as +//! it printed them. A sample whose bytes `n · b` of a texel's are 16 or fewer takes its own bytes +//! of the pattern, past 16 every sample the pattern cut at the texel (`tests::blit_fill` checks +//! the rule on every measured case without a device). The depths outside `[0, 1]` (`d32-wide-4`) +//! are not compared where the device's depth copies go by a draw that announced the values it +//! changes (`drawn-depth-copy`), whose samples it prints on a `SAMPLE-FILLS-DRAWN` line; a +//! differing case prints a `SAMPLE-FILLS-DIFFERS` line. + +use super::resolves::{lane, quiet, Lane}; +use super::WAIT; +use crate::candidate::runtime_samples::encode_through; +use crate::executor_contract::multisample::{ReadbackView, SampleRead}; +use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage}; +use metal2vulkan_runtime::{ + ClearColor, CommandBufferStatus, Degradation, LoadAction, Region, RenderPassDescriptor, + ResourceOptions, StoreAction, Texture, TextureDescriptor, +}; +use sha2::{Digest, Sha256}; + +/// The probe's 16-byte pattern. +const P16: &str = "00112233445566778899aabbccddeeff"; + +/// The probe's 32-byte pattern. +const P32: &str = "00112233445566778899aabbccddeeff102132435465768798a9bacbdcedfe0f"; + +/// Depths in `[0, 1]`, one a sample: a denormal, 1, 0 and 0.25. +const DEPTHS: &str = "010000000000803f000000000000803e"; + +/// What a case fills: bytes, or a color packed in the texture's format. +#[derive(Clone, Copy, Debug)] +enum Fill { + Bytes(&'static str), + Color([f64; 4]), +} + +/// One case: its name, the format's raw value, samples, the array's slices (0 for a 2D +/// multisample texture), the fill's slice, its region's origin and size, what it fills, and +/// Metal's answer. +type Case = ( + &'static str, + u32, + u64, + u64, + u64, + [u64; 3], + [u64; 3], + Fill, + &'static str, +); + +/// The cases, as the probe ran them. +const CASES: [Case; 17] = [ + ( + "r8-4", + 10, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P16), + "6a3cb9659495a014", + ), + ( + "rg8-4", + 30, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P16), + "7ae02f8d059eb534", + ), + ( + "rgba8-4", + 70, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P16), + "d2933cdc42077ec8", + ), + ( + "rgba8-2", + 70, + 2, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P32), + "030f2a7c3939ede7", + ), + ( + "bgra8srgb-4", + 81, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P16), + "fb44c4e915f05b98", + ), + ( + "rgba16f-4", + 115, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P16), + "5d2db7b16bf04af2", + ), + ( + "rgba16f-2", + 115, + 2, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P32), + "a729da908613bd7e", + ), + ( + "rgba32f-2", + 125, + 2, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P32), + "93c2217f450a212d", + ), + ( + "r32f-4", + 55, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P16), + "9c5b7be066d1c9fc", + ), + ( + "d32-4", + 252, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(DEPTHS), + "2098b9445cd43b96", + ), + ( + "d32-2", + 252, + 2, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(DEPTHS), + "869ba839ce907836", + ), + ( + "d32-wide-4", + 252, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P16), + "9c5b7be066d1c9fc", + ), + ( + "s8-4", + 253, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(P16), + "7f346b34bb6eabfb", + ), + ( + "d32s8-4", + 260, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Bytes(DEPTHS), + "51cb2e517b1b1dd0", + ), + ( + "array-4", + 70, + 4, + 2, + 1, + [1, 0, 0], + [3, 2, 1], + Fill::Bytes(P16), + "a626fded296f9cfd", + ), + ( + "color-4", + 70, + 4, + 0, + 0, + [1, 1, 0], + [2, 1, 1], + Fill::Color([0.5, 0.25, 1.0, 0.75]), + "ecfad086c3dc487a", + ), + ( + "whole-2", + 70, + 2, + 0, + 3, + [0, 0, 1], + [9, 9, 2], + Fill::Bytes("a1b2c3d4"), + "98c79dda44dbd307", + ), +]; + +/// The texture's side. +const WIDTH: u32 = 5; +const HEIGHT: u32 = 3; + +/// How a texture of `pf` is read back, as the probe printed it: the kernel, its view's format, +/// what the readback reads, and the bytes of each printed value (a depth or stencil aspect's +/// word, else the texel's). +fn reading(pf: PixelFormat) -> (&'static str, Option, SampleRead, usize) { + use PixelFormat as P; + use ReadbackView as V; + match pf { + P::R8Unorm => ( + "rt6_read_words1", + Some(P::R8Uint), + SampleRead::Color(V::R8Uint), + 1, + ), + P::RG8Unorm => ( + "rt6_read_bytes4", + Some(P::RG8Uint), + SampleRead::Color(V::R16Uint), + 2, + ), + P::RGBA8Unorm | P::BGRA8UnormSRGB => ( + "rt6_read_bytes4", + Some(P::RGBA8Uint), + SampleRead::Color(V::R32Uint), + 4, + ), + P::RGBA16Float => ( + "rt6_read_halves4", + Some(P::RGBA16Uint), + SampleRead::Color(V::Rg32Uint), + 8, + ), + P::RGBA32Float => ( + "rt6_read_words4", + Some(P::RGBA32Uint), + SampleRead::Color(V::Rgba32Uint), + 16, + ), + P::R32Float => ( + "rt6_read_words1", + Some(P::R32Uint), + SampleRead::Color(V::R32Uint), + 4, + ), + P::Stencil8 => ("rt6_read_stencil", None, SampleRead::Stencil, 1), + _ => ("rt6_read_depth", None, SampleRead::Depth, 4), + } +} + +/// One value as the probe printed it: a texel of 1 or 2 bytes as one hex number, else its 32-bit +/// words in order, each `%08x`. +fn printed(bytes: &[u8]) -> String { + match bytes.len() { + 1 => format!("{:02x}", bytes[0]), + 2 => format!("{:04x}", u16::from_le_bytes([bytes[0], bytes[1]])), + _ => bytes + .chunks(4) + .map(|word| format!("{:08x}", u32::from_le_bytes(word.try_into().unwrap()))) + .collect(), + } +} + +/// The probe's lines of every sample `bytes` holds (the readback's layout: texels in rows, each +/// texel's samples, `unit` bytes each) of slice `slice`, labelled `label`. +fn lines(label: &str, slice: u64, bytes: &[u8], samples: usize, unit: usize) -> Vec { + (0..HEIGHT as usize) + .map(|y| { + let mut line = format!("{label} s{slice} y{y}:"); + for x in 0..WIDTH as usize { + line.push_str(" |"); + for s in 0..samples { + let at = ((y * WIDTH as usize + x) * samples + s) * unit; + line.push(' '); + line.push_str(&printed(&bytes[at..at + unit])); + } + } + line + }) + .collect() +} + +/// Bytes from hex. +fn hex(text: &str) -> Vec { + (0..text.len()) + .step_by(2) + .map(|at| u8::from_str_radix(&text[at..at + 2], 16).unwrap()) + .collect() +} + +/// The first 16 hex digits of the SHA-256 of `lines`, joined by newlines. +fn digest(lines: &[String]) -> String { + let sum = Sha256::digest(lines.join("\n").as_bytes()); + sum.iter().take(8).map(|b| format!("{b:02x}")).collect() +} + +/// A 2D multisample view of `texture`'s `slice` in `pf`, or `texture` itself. +fn slice_of(texture: &Texture, pf: PixelFormat, slice: u64, array: bool) -> Texture { + if !array && pf == texture.pixel_format() { + return texture.clone(); + } + let kind = if array { + TextureType::Type2DMultisample + } else { + texture.texture_type() + }; + texture + .new_texture_view_with_levels_slices(pf, kind, 0..1, slice..slice + 1) + .unwrap() +} + +/// Run `case` on `lane`: the probe's lines of every slice's samples after the fill. +fn run(lane: &Lane, case: &Case) -> Vec { + let &(name, raw, samples, slices, slice, origin, size, fill, _) = case; + let pf = PixelFormat::try_from(raw).unwrap(); + let device = &lane.device; + let array = slices > 0; + let mut descriptor = TextureDescriptor::texture_2d(pf, WIDTH.into(), HEIGHT.into(), false); + descriptor.texture_type = if array { + TextureType::Type2DMultisampleArray + } else { + TextureType::Type2DMultisample + }; + descriptor.array_length = slices.max(1); + descriptor.sample_count = samples; + descriptor.usage = + TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ | TextureUsage::PIXEL_FORMAT_VIEW; + descriptor.resource_options = ResourceOptions::private(); + let texture = device.new_texture(&descriptor).unwrap(); + let depth = matches!( + pf, + PixelFormat::Depth32Float | PixelFormat::Depth32FloatStencil8 + ); + let stencil = matches!( + pf, + PixelFormat::Stencil8 | PixelFormat::Depth32FloatStencil8 + ); + let command_buffer = lane.queue.command_buffer().unwrap(); + for layer in 0..slices.max(1) { + let mut pass = RenderPassDescriptor::new(); + if depth { + pass.depth_attachment.texture = Some(texture.clone()); + pass.depth_attachment.slice = layer; + pass.depth_attachment.load_action = LoadAction::Clear; + pass.depth_attachment.clear_depth = 0.25; + pass.depth_attachment.store_action = StoreAction::Store; + } + if stencil { + pass.stencil_attachment.texture = Some(texture.clone()); + pass.stencil_attachment.slice = layer; + pass.stencil_attachment.load_action = LoadAction::Clear; + pass.stencil_attachment.clear_stencil = 0x5a; + pass.stencil_attachment.store_action = StoreAction::Store; + } + if !depth && !stencil { + let color = &mut pass.color_attachments[0]; + color.texture = Some(texture.clone()); + color.slice = layer; + color.load_action = LoadAction::Clear; + color.clear_color = ClearColor::new(0.25, 0.5, 0.75, 1.0); + color.store_action = StoreAction::Store; + } + let encoder = command_buffer.render_command_encoder(&pass).unwrap(); + encoder.end_encoding().unwrap(); + } + let mut blit = command_buffer.blit_command_encoder().unwrap(); + let region = Region::new_3d(origin[0], origin[1], origin[2], size[0], size[1], size[2]); + match fill { + Fill::Bytes(pattern) => blit.fill_texture(&texture, 0, slice, region, &hex(pattern)), + Fill::Color([r, g, b, a]) => blit.fill_texture_color( + &texture, + 0, + slice, + region, + ClearColor::new(r, g, b, a), + None, + ), + } + .unwrap_or_else(|error| panic!("{name}: fill_texture: {error}")); + blit.end_encoding().unwrap(); + let (kernel, view, read, unit) = reading(pf); + let extent = [WIDTH, HEIGHT]; + let read_slice = |pf: PixelFormat, kernel, read, layer| { + let source = slice_of(&texture, pf, layer, array); + encode_through( + device, + &command_buffer, + &source, + kernel, + read, + extent, + samples as u32, + ) + .unwrap() + }; + let readbacks: Vec<_> = (0..slices.max(1)) + .map(|layer| { + let color = read_slice(view.unwrap_or(pf), kernel, read, layer); + let stencil = (pf == PixelFormat::Depth32FloatStencil8).then(|| { + read_slice( + PixelFormat::X32Stencil8, + "rt6_read_stencil", + SampleRead::Stencil, + layer, + ) + }); + (color, stencil) + }) + .collect(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!( + command_buffer.status(), + CommandBufferStatus::Completed, + "{name}" + ); + let mut out = Vec::new(); + let mut stencils = Vec::new(); + for (layer, (color, stencil)) in (0..).zip(&readbacks) { + out.extend(lines( + "after ", + layer, + &color.bytes().unwrap(), + samples as usize, + unit, + )); + if let Some(stencil) = stencil { + // `Depth32Float_Stencil8`'s stencil, printed as a word. + let words: Vec = stencil + .bytes() + .unwrap() + .iter() + .flat_map(|&s| u32::from(s).to_le_bytes()) + .collect(); + stencils.extend(lines("afterS ", layer, &words, samples as usize, 4)); + } + } + out.extend(stencils); + out +} + +/// Every case's samples are Metal's, but a depth whose drawn copy announced (once a device, at +/// the first depth fill) that it changes values out of `[0, 1]`. +#[test] +fn multisample_fills_write_metal_s_samples() { + let (messages, _cache, lane) = lane(); + let name = lane.device.name().to_owned(); + let mut wrong = Vec::new(); + let mut drawn = false; + for case in &CASES { + let lines = run(&lane, case); + let got = digest(&lines); + drawn |= messages + .take_notices() + .iter() + .filter_map(|m| m.degradation.as_ref()) + .any(|n| n.degradation == Degradation::DrawnDepthCopy); + let (case_name, metal) = (case.0, case.8); + if got == metal { + continue; + } + if drawn && case_name == "d32-wide-4" { + println!( + "SAMPLE-FILLS-DRAWN {name}: {case_name}: the drawn depth copy announced its \ + changes: {}", + lines[1] + ); + continue; + } + wrong.push(format!("{case_name}: {got}, Metal's {metal}")); + } + for line in &wrong { + println!("SAMPLE-FILLS-DIFFERS {name}: {line}"); + } + assert!( + wrong.is_empty(), + "{} cases differ from Metal's", + wrong.len() + ); + quiet(lane, &messages); +} diff --git a/crates/metal2vulkan-validation/src/runtime_lane/surface_fills.rs b/crates/metal2vulkan-validation/src/runtime_lane/surface_fills.rs new file mode 100644 index 000000000..cdbd6610f --- /dev/null +++ b/crates/metal2vulkan-validation/src/runtime_lane/surface_fills.rs @@ -0,0 +1,638 @@ +//! Metal's private texture fills (`BlitCommandEncoder::fill_texture` and `fill_texture_color`) +//! whose bytes a blit's read-back does not show, on the device the cfg selects, under the +//! validation layer, against Metal's bytes: our probes `surface.m`, `tp.m`, `misc.m` and `slot.m` +//! on an Apple M3 Max under macOS 27.0.1 (no guest data). +//! +//! - **Over a surface's plane, or a buffer.** A two-plane YCbCr texture over plane 0 or 1 of a +//! CoreVideo surface, the buffer here standing for the surface with its planes where the +//! surface's lie, and a padded 10-bit texture over a buffer, every byte first `0xEE`: the runs +//! of bytes one fill changed, as the probe printed them. A YCbCr texture's unit is its plane's +//! code, and a packed one's texels each take one zero byte at the texel's `x` of its row. +//! - **Two-plane extended-range.** A `Shared` texture of its own memory, or at byte 0 of a +//! placement heap of Metal's size, every texel's color word set to its index (each slice's and +//! level's own top bits) by `replace_region`, one fill of `a1 a2 a3 a4`, and the texels whose +//! word `get_bytes` reads changed: Metal fills level 0 of the slice at Metal's fill rows, +//! whatever the level, so a width off a multiple of 4 moves the fill between the texels' rows. +//! - **A color with nothing to pack.** Fills packed in `Depth32Float`, `BC1_RGBA` and +//! `RGBA8Unorm` after one packed in `RGBA32Uint`, in one encoder with fills alone between, as +//! Metal's warm runs write them (its 16-byte texel, cut and overwritten as the runtime's slot +//! is). +//! - **An empty pattern** is refused `Invalid(EmptyFillPattern)`; Metal's validation stops it. +//! +//! A difference prints a `SURFACE-FILLS-DIFFERS` line. + +use super::{buffer_with, read_buffer, WAIT}; +use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage}; +use metal2vulkan_runtime::{ + BlitOption, ClearColor, CommandQueue, Device, Error, HeapDescriptor, HeapType, Invalid, + IoSurfacePlane, IoSurfaceYCbCr, Origin, Problem, Region, ResourceOptions, Size, Texture, + TextureDescriptor, +}; + +use super::degrade_notices::on_device; + +/// A plane of a surface: its first byte in the surface and its `bytesPerRow`. +type Plane = (u64, u64); + +/// One fill over a surface's plane (`ostype` `Some`) or a buffer. +struct Over { + /// The surface's OSType, `None` for a buffer. + ostype: Option<&'static [u8; 4]>, + /// The surface's size, or the texture's over a buffer. + size: [u64; 2], + format: u32, + /// The plane the texture is made over. + plane: u64, + /// The surface's bytes (a buffer's: its rows and 256 more) and planes (a buffer's texture + /// at 0, its rows the first's `bytesPerRow`). + length: u64, + planes: [Plane; 2], + /// The probe's case: `b` the whole texture with a pattern of `n` bytes `01 02 ..`, `r` + /// the region at 1, 1 of 2 x 1, `x,,` the region at `x`, `y` of 3 x 2, `p` the + /// whole texture, the color (0.25, 0.5, 0.75, 1) packed in `pf`. + case: &'static str, + /// The changed runs Metal's probe printed. + metal: &'static str, +} + +/// The surfaces' layouts, as CoreVideo made them (`surface.m`). +const S8X4: (u64, [Plane; 2]) = (1344, [(512, 64), (1024, 64)]); +const S8X4_444: (u64, [Plane; 2]) = (1600, [(512, 64), (1024, 64)]); + +const fn surf( + ostype: &'static [u8; 4], + size: [u64; 2], + (format, plane): (u32, u64), + (length, planes): (u64, [Plane; 2]), + case: &'static str, + metal: &'static str, +) -> Over { + Over { + ostype: Some(ostype), + size, + format, + plane, + length, + planes, + case, + metal, + } +} + +const fn buf( + format: u32, + size: [u64; 2], + row: u64, + case: &'static str, + metal: &'static str, +) -> Over { + Over { + ostype: None, + size, + format, + plane: 0, + length: row * size[1] + 256, + planes: [(0, row), (0, 0)], + case, + metal, + } +} + +/// Metal's fills over a surface's plane or a buffer (`cases.sh`). +const OVER: [Over; 19] = [ + surf(b"420v", [8, 4], (500, 0), S8X4, "b4", + " [0x200+8: 01 01 01 01 01 01 01 01] [0x240+8: 01 01 01 01 01 01 01 01] [0x280+8: 01 01 01 01 01 01 01 01] [0x2c0+8: 01 01 01 01 01 01 01 01]"), + surf(b"420v", [8, 4], (500, 0), S8X4, "x5,2,3", " [0x285+3: 01 01 01] [0x2c5+3: 01 01 01]"), + surf(b"420v", [8, 4], (520, 0), S8X4, "p70", + " [0x200+8: 40 40 40 40 40 40 40 40] [0x240+8: 40 40 40 40 40 40 40 40] [0x280+8: 40 40 40 40 40 40 40 40] [0x2c0+8: 40 40 40 40 40 40 40 40]"), + surf(b"x420", [8, 4], (505, 0), S8X4, "b4", + " [0x200+16: 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x240+16: 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x280+16: 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x2c0+16: 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02]"), + surf(b"x420", [8, 4], (505, 0), S8X4, "x5,2,3", " [0x28a+6: 01 02 01 02 01 02] [0x2ca+6: 01 02 01 02 01 02]"), + surf(b"x420", [8, 4], (505, 0), S8X4, "p70", + " [0x200+16: 40 80 40 80 40 80 40 80 40 80 40 80 40 80 40 80] [0x240+16: 40 80 40 80 40 80 40 80 40 80 40 80 40 80 40 80] [0x280+16: 40 80 40 80 40 80 40 80 40 80 40 80 40 80 40 80] [0x2c0+16: 40 80 40 80 40 80 40 80 40 80 40 80 40 80 40 80]"), + surf(b"x420", [8, 4], (543, 0), S8X4, "p20", + " [0x200+16: 00 40 00 40 00 40 00 40 00 40 00 40 00 40 00 40] [0x240+16: 00 40 00 40 00 40 00 40 00 40 00 40 00 40 00 40] [0x280+16: 00 40 00 40 00 40 00 40 00 40 00 40 00 40 00 40] [0x2c0+16: 00 40 00 40 00 40 00 40 00 40 00 40 00 40 00 40]"), + surf(b"x420", [38, 6], (505, 0), (2128, [(512, 128), (1536, 128)]), "x35,4,3", + " [0x446+6: 01 02 01 02 01 02] [0x4c6+6: 01 02 01 02 01 02]"), + surf(b"xf20", [8, 4], (525, 0), S8X4, "x6,3,3", " [0x2cc+4: 01 02 01 02]"), + surf(b"444v", [8, 4], (503, 1), S8X4_444, "b4", + " [0x400+8: 01 01 01 01 01 01 01 01] [0x440+8: 01 01 01 01 01 01 01 01] [0x480+8: 01 01 01 01 01 01 01 01] [0x4c0+8: 01 01 01 01 01 01 01 01]"), + surf(b"x444", [8, 4], (507, 1), S8X4_444, "x1,1,3", " [0x442+6: 01 02 01 02 01 02] [0x482+6: 01 02 01 02 01 02]"), + surf(b"x422", [8, 4], (544, 0), S8X4_444, "b3", + " [0x200+16: 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x240+16: 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x280+16: 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x2c0+16: 01 02 01 02 01 02 01 02 01 02 01 02 01 02 01 02]"), + surf(b"p420", [12, 4], (508, 0), S8X4, "x5,2,1", " [0x285+3: 00 00 00] [0x2c5+3: 00 00 00]"), + surf(b"p444", [12, 4], (510, 0), S8X4_444, "p10", + " [0x200+12: 00 00 00 00 00 00 00 00 00 00 00 00] [0x240+12: 00 00 00 00 00 00 00 00 00 00 00 00] [0x280+12: 00 00 00 00 00 00 00 00 00 00 00 00] [0x2c0+12: 00 00 00 00 00 00 00 00 00 00 00 00]"), + surf(b"p422", [8, 4], (529, 0), S8X4_444, "b4", + " [0x200+8: 00 00 00 00 00 00 00 00] [0x240+8: 00 00 00 00 00 00 00 00] [0x280+8: 00 00 00 00 00 00 00 00] [0x2c0+8: 00 00 00 00 00 00 00 00]"), + buf(576, [8, 4], 64, "x5,2,3", " [0x8a+6: 01 02 01 02 01 02] [0xca+6: 01 02 01 02 01 02]"), + buf(577, [7, 3], 32, "b4", + " [0+14: 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x20+14: 01 02 01 02 01 02 01 02 01 02 01 02 01 02] [0x40+14: 01 02 01 02 01 02 01 02 01 02 01 02 01 02]"), + buf(578, [8, 4], 64, "r3", " [0x44+8: 01 02 03 01 01 02 03 01]"), + buf(579, [8, 4], 64, "p70", + " [0+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff ..] [0x40+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff ..] [0x80+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff ..] [0xc0+32: 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff 40 80 bf ff ..]"), +]; + +/// One fill of a two-plane extended-range texture (`tp.m`'s arguments): its format, extent, +/// levels and slices, the fill's level, slice and region, whether in a heap, and the lines +/// Metal's probe printed. +struct Planes { + format: u32, + extent: [u64; 2], + levels: u64, + slices: u64, + level: u64, + slice: u64, + region: [u64; 4], + heap: bool, + metal: &'static [&'static str], +} + +const fn planes( + format: u32, + (extent, levels, slices): ([u64; 2], u64, u64), + (level, slice, region): (u64, u64, [u64; 4]), + heap: bool, + metal: &'static [&'static str], +) -> Planes { + Planes { + format, + extent, + levels, + slices, + level, + slice, + region, + heap, + metal, + } +} + +/// Metal's fills of two-plane extended-range textures (`lane-cases.sh`). +const PLANES: [Planes; 10] = [ + planes(550, ([5, 3], 1, 1), (0, 0, [0, 0, 5, 3]), false, &[ + "slice 0 level 0 (5x3): 0,0,0 1,0,0 2,0,0 3,0,0 4,0,0 0,1,0 1,1,0 2,1,0 3,1,0 4,1,0", + ]), + planes(550, ([5, 3], 1, 1), (0, 0, [1, 1, 2, 1]), false, &["slice 0 level 0 (5x3):"]), + planes(551, ([7, 5], 1, 1), (0, 0, [2, 1, 3, 3]), false, &[ + "slice 0 level 0 (7x5): 6,0,0 0,1,0 2,1,0 3,1,0 4,1,0 6,1,0 0,2,0", + ]), + planes(550, ([3, 4], 1, 1), (0, 0, [0, 1, 2, 2]), false, &[ + "slice 0 level 0 (3x4): 0,1,0 1,1,0 0,2,0 1,2,0", + ]), + planes(550, ([8, 8], 3, 1), (1, 0, [0, 0, 4, 4]), false, &[ + "slice 0 level 0 (8x8): 0,0,0 1,0,0 2,0,0 3,0,0 0,1,0 1,1,0 2,1,0 3,1,0 0,2,0 1,2,0 2,2,0 3,2,0 0,3,0 1,3,0 2,3,0 3,3,0", + "slice 0 level 1 (4x4):", + "slice 0 level 2 (2x2):", + ]), + planes(551, ([6, 4], 1, 2), (0, 1, [1, 0, 3, 2]), false, &[ + "slice 0 level 0 (6x4):", + "slice 1 level 0 (6x4): 1,0,0 2,0,0 3,0,0 5,0,0", + ]), + planes(550, ([5, 3], 1, 1), (0, 0, [0, 0, 5, 3]), true, &[ + "slice 0 level 0 (5x3): 0,0,0 1,0,0 2,0,0 3,0,0 4,0,0 0,1,0 1,1,0 2,1,0 3,1,0 4,1,0", + ]), + planes(550, ([8, 8], 3, 1), (2, 0, [0, 0, 1, 1]), true, &[ + "slice 0 level 0 (8x8): 0,0,0", + "slice 0 level 1 (4x4):", + "slice 0 level 2 (2x2):", + ]), + planes(551, ([6, 4], 1, 2), (0, 1, [1, 0, 3, 2]), true, &[ + "slice 0 level 0 (6x4):", + "slice 1 level 0 (6x4): 1,0,0 2,0,0 3,0,0 5,0,0", + ]), + planes(550, ([9, 2], 1, 1), (0, 0, [3, 0, 100, 100]), false, &[ + "slice 0 level 0 (9x2): 3,0,0 4,0,0 5,0,0 6,0,0 7,0,0 8,0,0 0,1,0 1,1,0 2,1,0 3,1,0 4,1,0", + ]), +]; + +fn format(raw: u32) -> PixelFormat { + PixelFormat::try_from(raw).unwrap() +} + +/// `bytes`' runs of bytes other than `0xEE`, as `surface.m` prints them: each ` [+:`, +/// at most 24 of its bytes, ` ..` past them, and `]`. +fn runs(bytes: &[u8]) -> String { + let mut out = String::new(); + let mut i = 0; + while i < bytes.len() { + if bytes[i] == 0xee { + i += 1; + continue; + } + let mut j = i; + while j < bytes.len() && bytes[j] != 0xee { + j += 1; + } + let at = if i == 0 { + "0".to_owned() + } else { + format!("{i:#x}") + }; + out += &format!(" [{at}+{}:", j - i); + for b in &bytes[i..j.min(i + 24)] { + out += &format!(" {b:02x}"); + } + if j - i > 24 { + out += " .."; + } + out += "]"; + i = j; + } + out +} + +/// The fill `case` (as [`Over::case`] reads) into `texture` of `width` by `height`. +fn fill_case( + blit: &mut metal2vulkan_runtime::BlitCommandEncoder, + texture: &Texture, + [width, height]: [u64; 2], + case: &str, +) -> Result<(), Error> { + let pattern: Vec = (1..=64).collect(); + let number = |s: &str| s.parse::().unwrap(); + let (kind, rest) = case.split_at(1); + match kind { + "b" => blit.fill_texture( + texture, + 0, + 0, + Region::new_2d(0, 0, width, height), + &pattern[..number(rest) as usize], + ), + "r" => blit.fill_texture( + texture, + 0, + 0, + Region::new_2d(1, 1, 2, 1), + &pattern[..number(rest) as usize], + ), + "x" => { + let v: Vec = rest.split(',').map(number).collect(); + blit.fill_texture( + texture, + 0, + 0, + Region::new_2d(v[0], v[1], 3, 2), + &pattern[..v[2] as usize], + ) + } + "p" => blit.fill_texture_color( + texture, + 0, + 0, + Region::new_2d(0, 0, width, height), + ClearColor::new(0.25, 0.5, 0.75, 1.0), + Some(format(number(rest) as u32)), + ), + _ => unreachable!("no case {case}"), + } +} + +/// `over`'s texture: over its surface's plane (the plane's size: the surface's, or a 4:4:4 +/// surface's chroma plane, the same), or over its buffer. +fn over_texture(over: &Over, surface: &metal2vulkan_runtime::Buffer) -> Texture { + let [w, h] = over.size; + let mut d = TextureDescriptor::texture_2d(format(over.format), w, h, false); + d.resource_options = ResourceOptions::shared(); + let made = match over.ostype { + Some(ostype) => { + d.usage = TextureUsage::SHADER_READ; + let (offset, row) = over.planes[over.plane as usize]; + let [_, (chroma, chroma_row)] = over.planes; + let facts = IoSurfaceYCbCr::new( + u32::from_be_bytes(*ostype), + over.plane, + over.size, + chroma, + chroma_row, + ); + let plane = IoSurfacePlane::new(offset, row, true).with_ycbcr(facts); + surface.new_texture_with_iosurface_plane(&d, plane) + } + None => { + d.usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE; + surface.new_texture(&d, 0, over.planes[0].1) + } + }; + made.unwrap_or_else(|e| panic!("{} {}: {e}", over.format, over.case)) +} + +/// Each fill over a surface's plane or a buffer changes the bytes Metal's changes, and only +/// those. +#[test] +fn fills_over_surfaces_and_buffers_write_metal_s_bytes() { + on_device(|device, _messages| { + let queue = device.new_command_queue().unwrap(); + let mut wrong = Vec::new(); + for over in &OVER { + let surface = buffer_with(device, &vec![0xee; over.length as usize]).unwrap(); + let texture = over_texture(over, &surface); + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + let size = [texture.width(), texture.height()]; + fill_case(&mut blit, &texture, size, over.case) + .unwrap_or_else(|e| panic!("{} {}: {e}", over.format, over.case)); + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + let ours = runs(&read_buffer(&surface, 0, over.length).unwrap()); + if ours != over.metal { + println!( + "SURFACE-FILLS-DIFFERS {} {}:{ours} (Metal's{})", + over.format, over.case, over.metal + ); + wrong.push((over.format, over.case)); + } + } + assert!(wrong.is_empty(), "fills unlike Metal's: {wrong:?}"); + }); +} + +/// A level's extent of `extent`. +fn level_extent([w, h]: [u64; 2], level: u64) -> [u64; 2] { + [(w >> level).max(1), (h >> level).max(1)] +} + +/// The word `tp.m` writes at texel `i` of `level` and `slice`. +fn index_word(slice: u64, level: u64, i: u64) -> u32 { + (0x1000_0000 * (slice + 1) + 0x0100_0000 * level + i) as u32 +} + +/// `case`'s texture: of its own memory, or at byte 0 of a placement heap of Metal's size. +fn planes_texture(device: &Device, case: &Planes) -> Texture { + let [w, h] = case.extent; + let mut d = TextureDescriptor::texture_2d(format(case.format), w, h, false); + d.mipmap_level_count = case.levels; + if case.slices > 1 { + d.texture_type = TextureType::Type2DArray; + d.array_length = case.slices; + } + d.usage = TextureUsage::SHADER_READ; + d.resource_options = ResourceOptions::shared(); + if !case.heap { + return device.new_texture(&d).unwrap(); + } + let size = device.heap_texture_size_and_align(&d).unwrap().size; + let heap = device + .new_heap(&HeapDescriptor::new( + HeapType::Placement, + size, + ResourceOptions::shared(), + )) + .unwrap(); + heap.new_texture_at_offset(&d, 0).unwrap() +} + +/// `case`'s lines as `tp.m` prints them: each slice's and level's texels whose word changed. +fn planes_case(device: &Device, queue: &CommandQueue, case: &Planes) -> Vec { + let texture = planes_texture(device, case); + let each = || { + (0..case.slices) + .flat_map(|s| (0..case.levels).map(move |l| (s, l, level_extent(case.extent, l)))) + }; + for (slice, level, [w, h]) in each() { + let words: Vec = (0..w * h) + .flat_map(|i| index_word(slice, level, i).to_le_bytes()) + .collect(); + texture + .replace_region( + Region::new_2d(0, 0, w, h), + level, + slice, + &words, + 4 * w, + 4 * w * h, + ) + .unwrap(); + } + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + let [x, y, rw, rh] = case.region; + blit.fill_texture( + &texture, + case.level, + case.slice, + Region::new_2d(x, y, rw, rh), + &[0xa1, 0xa2, 0xa3, 0xa4], + ) + .unwrap(); + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + each() + .map(|(slice, level, [w, h])| { + let mut words = vec![0; (4 * w * h) as usize]; + texture + .get_bytes( + &mut words, + 4 * w, + 4 * w * h, + Region::new_2d(0, 0, w, h), + level, + slice, + ) + .unwrap(); + let mut line = format!("slice {slice} level {level} ({w}x{h}):"); + for (i, word) in words.as_chunks::<4>().0.iter().enumerate() { + let (i, word) = (i as u64, u32::from_le_bytes(*word)); + let at = format!("{},{},0", i % w, i / w); + if word == 0xa4a3_a2a1 { + line += &format!(" {at}"); + } else if word != index_word(slice, level, i) { + line += &format!(" {at}={word:08x}"); + } + } + line + }) + .collect() +} + +/// Each fill of a two-plane extended-range texture, of its own memory or a heap's, changes the +/// texels Metal's changes as `get_bytes` reads them, and only those. +#[test] +fn two_plane_fills_write_metal_s_texels() { + on_device(|device, _messages| { + let queue = device.new_command_queue().unwrap(); + let mut wrong = Vec::new(); + for (n, case) in PLANES.iter().enumerate() { + let ours = planes_case(device, &queue, case); + if ours != case.metal { + println!( + "SURFACE-FILLS-DIFFERS planes {n}: {ours:?} (Metal's {:?})", + case.metal + ); + wrong.push(n); + } + } + assert!(wrong.is_empty(), "fills unlike Metal's: {wrong:?}"); + }); +} + +/// A 1-texel-high texture of `pf` and `width`, every byte `0x5A` (`slot.m`'s). +fn set_texture( + device: &Device, + queue: &CommandQueue, + pf: PixelFormat, + width: u64, + texel: u64, +) -> Texture { + let mut d = TextureDescriptor::texture_2d(pf, width, 1, false); + d.usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE; + d.resource_options = ResourceOptions::private(); + let texture = device.new_texture(&d).unwrap(); + let bytes = buffer_with(device, &vec![0x5a; (width * texel) as usize]).unwrap(); + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + blit.copy_from_buffer_to_texture( + &bytes, + 0, + width * texel, + width * texel, + Size::new(width, 1, 1), + &texture, + 0, + 0, + Origin::new(0, 0, 0), + BlitOption::None, + ) + .unwrap(); + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + texture +} + +/// `texture`'s bytes (`width` texels of `texel` bytes) through a blit into a buffer. +fn texture_bytes(device: &Device, queue: &CommandQueue, texture: &Texture, texel: u64) -> Vec { + let length = texture.width() * texel; + let out = buffer_with(device, &vec![0; length as usize]).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(texture.width(), 1, 1), + &out, + 0, + length, + length, + BlitOption::None, + ) + .unwrap(); + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + read_buffer(&out, 0, length).unwrap() +} + +/// A color fill packed where Metal packs no color fills the 16-byte texel of the encoder's last +/// packed fill, cut at the texture's texel and overwritten by a shorter one's bytes, as Metal's +/// warm runs write it with fills alone between (`slot.m`'s sequences `same`, `short`, `into8` +/// and `twice`); a fill packed in `BC1_RGBA` likewise. +#[test] +fn unpacked_color_fills_repeat_the_last_packed_texel() { + on_device(|device, _messages| { + let queue = device.new_command_queue().unwrap(); + let earlier = ClearColor::new(7.0, 9.0, 3.0, 1.0); + let asked = ClearColor::new(0.25, 0.5, 0.75, 1.0); + let whole = |t: &Texture| Region::new_2d(0, 0, t.width(), 1); + let rgba32 = "07000000090000000300000001000000"; + let sequences: [(&str, [&str; 3]); 4] = [ + ( + "same", + [rgba32, "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a", "5a5a5a5a"], + ), + ( + "short", + [ + "ffffffff090000000300000001000000", + "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a", + "5a5a5a5a", + ], + ), + ( + "into8", + [rgba32, "07000000070000000700000007000000", "07070707"], + ), + ( + "twice", + [rgba32, "07000000070000000700000007000000", "5a5a5a5a"], + ), + ]; + for (name, metal) in sequences { + let src = set_texture(device, &queue, PixelFormat::RGBA32Uint, 1, 16); + let other = set_texture(device, &queue, PixelFormat::RGBA8Unorm, 4, 4); + let t = set_texture(device, &queue, PixelFormat::RGBA32Uint, 1, 16); + let t8 = set_texture(device, &queue, PixelFormat::RGBA8Unorm, 4, 4); + let r8 = set_texture(device, &queue, PixelFormat::R8Unorm, 4, 1); + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + let mut fc = |texture: &Texture, color, pf| { + blit.fill_texture_color(texture, 0, 0, whole(texture), color, Some(pf)) + .unwrap(); + }; + let none = PixelFormat::Depth32Float; + fc(&src, earlier, PixelFormat::RGBA32Uint); + match name { + "same" => fc(&t, asked, none), + "short" => { + fc( + &other, + ClearColor::new(1.0, 1.0, 1.0, 1.0), + PixelFormat::RGBA8Unorm, + ); + fc(&t, asked, none); + } + "into8" => { + fc(&t8, asked, none); + fc(&r8, asked, none); + fc(&t, asked, none); + } + _ => { + fc(&t, asked, none); + fc( + &t8, + ClearColor::new(0.5, 0.5, 0.5, 0.5), + PixelFormat::BC1RGBA, + ); + } + } + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + let hex = |bytes: Vec| bytes.iter().map(|b| format!("{b:02x}")).collect::(); + let ours = [ + hex(texture_bytes(device, &queue, &t, 16)), + hex(texture_bytes(device, &queue, &t8, 4)), + hex(texture_bytes(device, &queue, &r8, 1)), + ]; + assert_eq!(ours, metal.map(str::to_owned), "{name}"); + } + }); +} + +/// A fill of no pattern bytes is refused as Metal's validation stops it, and writes nothing. +#[test] +fn an_empty_pattern_is_refused() { + on_device(|device, _messages| { + let queue = device.new_command_queue().unwrap(); + let t = set_texture(device, &queue, PixelFormat::RGBA8Unorm, 4, 4); + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + let refused = blit.fill_texture(&t, 0, 0, Region::new_2d(0, 0, 4, 1), &[]); + assert_eq!( + refused, + Err(Error::Invalid(Invalid::new( + "fill_texture", + Problem::EmptyFillPattern + ))) + ); + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(texture_bytes(device, &queue, &t, 4), vec![0x5a; 16]); + }); +} diff --git a/crates/metal2vulkan-validation/src/runtime_lane/texture_buffer_fills.rs b/crates/metal2vulkan-validation/src/runtime_lane/texture_buffer_fills.rs new file mode 100644 index 000000000..ec440cb6f --- /dev/null +++ b/crates/metal2vulkan-validation/src/runtime_lane/texture_buffer_fills.rs @@ -0,0 +1,358 @@ +//! Metal's private texture fills of texture buffers (`BlitCommandEncoder::fill_texture` and +//! `fill_texture_color`), on the device the cfg selects, under the validation layer, against +//! Metal's bytes. +//! +//! Each case replays our probe `tb.m`'s (an Apple M3 Max under macOS 27.0.1): a texture buffer +//! 12 texels wide, of a format of 1 to 16 bytes a texel, at an offset into a `Shared` buffer of +//! 512 bytes whose byte `i` is first `i · 37 mod 251` (256 bytes a row), its fills in one +//! encoder, and every byte of the buffer read back. A fill is the probe's argument +//! `x,w[,y,h,d,level,slice,z]:` (`y` 0, `h` and `d` 1, the rest 0 where left out) and its pattern: +//! `p` the `n` bytes `a1 a2 ..`, `p@` from the byte `b`, `c` the color +//! (0.25, -0.5, 1.25, 0.75) packed in `pf`. Metal's answer is the first 16 hex digits of the +//! SHA-256 of the buffer's bytes; a group's, of its cases' buffers in order. +//! +//! - **Streams**: patterns longer than the texel, of lengths not a power of two, and up to 256 +//! bytes; regions past the texture's width, past the buffer's end, of no rows, of no images, at +//! a level, slice, row and depth past 0, and of no texels; a fill after a fill (the consumer's 9 +//! cases among them). Metal writes the buffer's bytes, the pattern across them, and the bytes of +//! its block past the pattern's copies as zeros, which the runtime writes and announces once +//! (`texture-buffer-fill-leftover`). +//! - **Groups** (the consumer's set): each format at offsets 0 and 64, and 4 and 68 for a texel of +//! 4 bytes or fewer, a pattern of each power of two of bytes up to the texel whole, inside, +//! ending at the width and at a level, slice, row, height and depth past 0 and 1, a color packed +//! in each format of no more bytes than the texel, and fills of no texels between others. +//! +//! `tests::blit_fill` checks the bytes of the fills without a device. A differing case prints a +//! `TEXTURE-BUFFER-FILLS-DIFFERS` line with the runs of bytes its fills changed. + +use super::degrade_notices::{ + assert_once, forced, on_device, shared_in_system_memory, TEXTURE_BUFFER_FILL, +}; +use super::{buffer_with, read_buffer, WAIT}; +use metal2vulkan::metal::{PixelFormat, TextureUsage}; +use metal2vulkan_runtime::{ + ClearColor, CommandQueue, Degradation, Device, Origin, Region, ResourceOptions, Size, + TextureDescriptor, +}; +use sha2::{Digest, Sha256}; + +/// The buffer's bytes. +const BYTES: usize = 512; + +/// A stream: its name, the format's raw value, the texture's offset, its fills, and Metal's +/// answer. +type Stream = ( + &'static str, + u32, + u64, + &'static [&'static str], + &'static str, +); + +/// A group: its name, the format's raw value, the texture's offset, its cases' fills, and +/// Metal's answer. +type Group = ( + &'static str, + u32, + u64, + &'static [&'static [&'static str]], + &'static str, +); + +/// The streams, as the probe ran them. +const STREAMS: [Stream; 26] = [ + ("r8-8-whole", 10, 0, &["0,12:p8"], "0ee2aff21c7fc968"), + ("r8-8-odd", 10, 4, &["3,5:p8"], "4e2a928549345a34"), + ("rgba8-8-whole", 70, 0, &["0,12:p8"], "84f5d37ca71f4e7f"), + ("rgba8-8-x4", 70, 64, &["4,8:p8"], "5a2c0a26da0f6e23"), + ("rgba8-c115", 70, 0, &["4,6:c115"], "4db1e92e18d57d38"), + ("r8-past-width", 10, 0, &["12,3:p1"], "0260417c8c16e763"), + ("rgba8-ending-past", 70, 0, &["10,5:p4"], "e78f2f4f540bb93d"), + ("r8-no-rows", 10, 0, &["1,2,0,0,1:p1"], "4bd9db7e5278e209"), + ( + "rgba8-no-images", + 70, + 64, + &["1,2,0,1,0:p4"], + "85a8c2ef070cc49a", + ), + ("rgba8-3-whole", 70, 0, &["0,12:p3"], "e3999e838bee0e1c"), + ( + "rgba8-9-after-8", + 70, + 0, + &["0,12:p8", "0,12:p9@b1"], + "456210529ae74916", + ), + ("rgba8-12-x1", 70, 4, &["1,10:p12"], "19ce1fc8bdec16f0"), + ("rgba32-17", 125, 0, &["0,12:p17"], "d31c4c6fb6e0e200"), + ("rgba32-24-x1", 125, 64, &["1,10:p24"], "2178521d4be0aa92"), + ("rgba8-33-past", 70, 0, &["0,40:p33"], "5f7b1f135056b512"), + ("r8-65-long", 10, 0, &["3,300:p65"], "3366332bf93b2371"), + ("rgba8-100", 70, 4, &["1,100:p100"], "8d688b0eca7b3728"), + ("rgba8-256", 70, 0, &["0,100:p256"], "9096b69c455dc4e0"), + ("rg8-5-x6", 30, 0, &["6,40:p5"], "f2b4ec3d60883b4e"), + ("rgba16-24", 115, 64, &["3,30:p24"], "53fb1bd384886492"), + ( + "rgba32-past-end", + 125, + 64, + &["20,20:p16"], + "b11323ede905084e", + ), + ("r8-past-buffer", 10, 0, &["600,3:p1"], "d71bdb461ee51a7e"), + ("rgba8-width-0", 70, 0, &["2,0:p3"], "d71bdb461ee51a7e"), + ( + "rgba8-level-slice-z", + 70, + 4, + &["2,4,5,3,2,3,7,4:p3"], + "c8766e71a2d1ea36", + ), + ( + "rgba8-c115-then-12", + 70, + 0, + &["0,12:c115", "0,12:p12"], + "f5e35d82b4b3bcd8", + ), + ("r8-3-odd", 10, 4, &["1,30:p3"], "8faf563f27272b2b"), +]; + +/// The fills of a group of `r8` texels, one case each. +const R8: &[&[&str]] = &[ + &["0,12:p1"], + &["3,5:p1"], + &["7,5:p1"], + &["2,4,5,3,2,3,7,4:p1"], + &["1,6,4,2,1,1,2,0:c10"], + &["0,12:p1", "5,0:p1", "12,0:p1", "9,2:c10"], +]; + +/// The fills of a group of `rg8` texels, one case each. +const RG8: &[&[&str]] = &[ + &["0,12:p1"], + &["3,5:p1"], + &["7,5:p1"], + &["2,4,5,3,2,3,7,4:p1"], + &["0,12:p2"], + &["3,5:p2"], + &["7,5:p2"], + &["2,4,5,3,2,3,7,4:p2"], + &["1,6,4,2,1,1,2,0:c10"], + &["1,6,4,2,1,1,2,0:c30"], + &["0,12:p1", "5,0:p1", "12,0:p1", "9,2:c10"], +]; + +/// The fills of a group of `rgba8` texels, one case each. +const RGBA8: &[&[&str]] = &[ + &["0,12:p1"], + &["3,5:p1"], + &["7,5:p1"], + &["2,4,5,3,2,3,7,4:p1"], + &["0,12:p2"], + &["3,5:p2"], + &["7,5:p2"], + &["2,4,5,3,2,3,7,4:p2"], + &["0,12:p4"], + &["3,5:p4"], + &["7,5:p4"], + &["2,4,5,3,2,3,7,4:p4"], + &["1,6,4,2,1,1,2,0:c10"], + &["1,6,4,2,1,1,2,0:c30"], + &["1,6,4,2,1,1,2,0:c70"], + &["0,12:p1", "5,0:p1", "12,0:p1", "9,2:c10"], +]; + +/// The fills of a group of `rgba16` texels, one case each. +const RGBA16: &[&[&str]] = &[ + &["0,12:p1"], + &["3,5:p1"], + &["7,5:p1"], + &["2,4,5,3,2,3,7,4:p1"], + &["0,12:p2"], + &["3,5:p2"], + &["7,5:p2"], + &["2,4,5,3,2,3,7,4:p2"], + &["0,12:p4"], + &["3,5:p4"], + &["7,5:p4"], + &["2,4,5,3,2,3,7,4:p4"], + &["0,12:p8"], + &["3,5:p8"], + &["7,5:p8"], + &["2,4,5,3,2,3,7,4:p8"], + &["1,6,4,2,1,1,2,0:c10"], + &["1,6,4,2,1,1,2,0:c30"], + &["1,6,4,2,1,1,2,0:c70"], + &["1,6,4,2,1,1,2,0:c115"], + &["0,12:p1", "5,0:p1", "12,0:p1", "9,2:c10"], +]; + +/// The fills of a group of `rgba32` texels, one case each. +const RGBA32: &[&[&str]] = &[ + &["0,12:p1"], + &["3,5:p1"], + &["7,5:p1"], + &["2,4,5,3,2,3,7,4:p1"], + &["0,12:p2"], + &["3,5:p2"], + &["7,5:p2"], + &["2,4,5,3,2,3,7,4:p2"], + &["0,12:p4"], + &["3,5:p4"], + &["7,5:p4"], + &["2,4,5,3,2,3,7,4:p4"], + &["0,12:p8"], + &["3,5:p8"], + &["7,5:p8"], + &["2,4,5,3,2,3,7,4:p8"], + &["0,12:p16"], + &["3,5:p16"], + &["7,5:p16"], + &["2,4,5,3,2,3,7,4:p16"], + &["1,6,4,2,1,1,2,0:c10"], + &["1,6,4,2,1,1,2,0:c30"], + &["1,6,4,2,1,1,2,0:c70"], + &["1,6,4,2,1,1,2,0:c115"], + &["1,6,4,2,1,1,2,0:c125"], + &["0,12:p1", "5,0:p1", "12,0:p1", "9,2:c10"], +]; + +/// The groups, as the probe ran them. +const GROUPS: [Group; 16] = [ + ("r8-at-0", 10, 0, R8, "715e234bffb7dcf7"), + ("r8-at-4", 10, 4, R8, "e1f8ea12e12b9db9"), + ("r8-at-64", 10, 64, R8, "de7442c0bb4f290f"), + ("r8-at-68", 10, 68, R8, "1a85c929b8d80219"), + ("rg8-at-0", 30, 0, RG8, "b8fcc13a29cea9c1"), + ("rg8-at-4", 30, 4, RG8, "62103fb7d6791aea"), + ("rg8-at-64", 30, 64, RG8, "fa35a4670beb6d3a"), + ("rg8-at-68", 30, 68, RG8, "9ddd3dab429ace88"), + ("rgba8-at-0", 70, 0, RGBA8, "94b6756df9a34a32"), + ("rgba8-at-4", 70, 4, RGBA8, "dde8bea1606de5aa"), + ("rgba8-at-64", 70, 64, RGBA8, "14795fa2287dd1c0"), + ("rgba8-at-68", 70, 68, RGBA8, "bf7d8a1f8a105af8"), + ("rgba16-at-0", 115, 0, RGBA16, "f9d0a1f338d87e0b"), + ("rgba16-at-64", 115, 64, RGBA16, "c2a934eb4a41e124"), + ("rgba32-at-0", 125, 0, RGBA32, "c9332419d8b8bfad"), + ("rgba32-at-64", 125, 64, RGBA32, "ebaf73cdcde2c014"), +]; + +/// The buffer's first bytes: byte `i` is `i · 37 mod 251`. +fn first_bytes() -> Vec { + (0..BYTES).map(|i| (i * 37 % 251) as u8).collect() +} + +/// The buffer's bytes after `fills` of a texture buffer of `format` at `offset`. +fn case( + device: &Device, + queue: &CommandQueue, + format: u32, + offset: u64, + fills: &[&str], +) -> Vec { + let buffer = buffer_with(device, &first_bytes()).unwrap(); + let d = TextureDescriptor::texture_buffer( + PixelFormat::try_from(format).unwrap(), + 12, + ResourceOptions::shared(), + TextureUsage::SHADER_READ, + ); + let texture = buffer.new_texture(&d, offset, 256).unwrap(); + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + for fill in fills { + let (spec, pattern) = fill.split_once(':').unwrap(); + let mut v = [0, 0, 0, 1, 1, 0, 0, 0]; + for (k, number) in spec.split(',').enumerate() { + v[k] = number.parse().unwrap(); + } + let [x, w, y, h, depth, level, slice, z] = v; + let region = Region { + origin: Origin::new(x, y, z), + size: Size::new(w, h, depth), + }; + if let Some(packed) = pattern.strip_prefix('c') { + let pf = PixelFormat::try_from(packed.parse::().unwrap()).unwrap(); + let color = ClearColor::new(0.25, -0.5, 1.25, 0.75); + blit.fill_texture_color(&texture, level, slice, region, color, Some(pf)) + .unwrap(); + } else { + let counted = pattern.strip_prefix('p').unwrap(); + let (n, from) = counted.split_once('@').unwrap_or((counted, "a1")); + let n: usize = n.parse().unwrap(); + let from = u8::from_str_radix(from, 16).unwrap(); + let bytes: Vec = (0..n).map(|i| from.wrapping_add(i as u8)).collect(); + blit.fill_texture(&texture, level, slice, region, &bytes) + .unwrap(); + } + } + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + read_buffer(&buffer, 0, BYTES as u64).unwrap() +} + +/// The first 16 hex digits of the SHA-256 of `bytes`. +fn digest(bytes: &[u8]) -> String { + Sha256::digest(bytes) + .iter() + .take(8) + .map(|b| format!("{b:02x}")) + .collect() +} + +/// The runs of `bytes` that differ from the buffer's first bytes, as the probe prints them. +fn runs(bytes: &[u8]) -> String { + let first = first_bytes(); + let mut line = String::new(); + let mut previous = false; + for (at, (&byte, &was)) in bytes.iter().zip(&first).enumerate() { + let changed = byte != was; + if changed && !previous { + line += &format!(" | {at:#x}:"); + } + if changed { + line += &format!(" {byte:02x}"); + } + previous = changed; + } + line +} + +/// Every stream and group writes the buffer's bytes as Metal's fills do, and the fills that read +/// bytes past their pattern's copies announce it once. +#[test] +fn texture_buffer_fills_write_metal_s_bytes() { + on_device(|device, messages| { + let queue = device.new_command_queue().unwrap(); + let mut wrong = Vec::new(); + for (name, format, offset, fills, metal) in STREAMS { + let ours = case(device, &queue, format, offset, fills); + if digest(&ours) != metal { + println!("TEXTURE-BUFFER-FILLS-DIFFERS {name}:{}", runs(&ours)); + wrong.push(name.to_owned()); + } + } + for (name, format, offset, cases, metal) in GROUPS { + let ours: Vec> = cases + .iter() + .map(|fills| case(device, &queue, format, offset, fills)) + .collect(); + if digest(&ours.concat()) != metal { + for (k, bytes) in ours.iter().enumerate() { + println!("TEXTURE-BUFFER-FILLS-DIFFERS {name} {k}:{}", runs(bytes)); + } + wrong.push(name.to_owned()); + } + } + let mut kinds = forced(&[( + Degradation::SharedInSystemMemory, + shared_in_system_memory(device), + )]); + kinds.extend(TEXTURE_BUFFER_FILL); + assert_once(&messages.take_notices(), &Vec::from_iter(kinds)); + assert!(wrong.is_empty(), "fills unlike Metal's: {wrong:?}"); + }); +} diff --git a/crates/metal2vulkan-validation/src/runtime_lane/texture_fills.rs b/crates/metal2vulkan-validation/src/runtime_lane/texture_fills.rs index 2a4edea6d..68431d6ff 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/texture_fills.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/texture_fills.rs @@ -9,17 +9,18 @@ //! set to `0xEE` through a buffer over it and the heap's changed bytes read back. Metal's answer //! per format: the first 16 hex digits of the SHA-256 of its cases' lines, ` `, each //! answer the first 16 hex digits of the SHA-256 of the case's read-back lines as the probe printed -//! them, `unpacked` where Metal's bytes do not follow the color (one constant of its process's for -//! every color; the runtime's fill there must write what the bytes form writes for one zero byte, -//! its one constant, and the device announce `unpacked-fill-color` once: changed), or the refusal -//! the runtime gives where it has no measured layout (`unmeasured`: a heap's two-plane texture of -//! more than one level or slice, which Metal fills). A format the device holds no texture of is +//! them, `unpacked` where Metal's bytes do not follow the color (bytes of its stack's; the +//! runtime's fill there, in a command buffer of no earlier color fill, must write what the bytes +//! form writes for one zero byte, and the device announce `unpacked-fill-color` once: changed), +//! or `held-apart` for a heap's two-plane texture of more than one level or slice, which the +//! runtime holds apart from the heap's bytes Metal's fill writes (its fills are checked through +//! `get_bytes` in `surface_fills.rs`). A format the device holds no texture of is //! skipped, with an `XR-TEXTURE-FILLS-SKIPPED` line, and so is `Depth32Float_Stencil8` where its //! uploads announce that the device may store depth outside `[0, 1]` clamped //! (`restricted-depth-upload`, checked to fire exactly where the runtime plans a depth image that //! may clamp); a differing format prints its cases on one `XR-TEXTURE-FILLS-DIFFERS` line. The -//! two-plane formats in private textures of their own memory replay `tfl4.swift` the same way, 5 -//! and 8 texels wide. +//! two-plane formats in private textures of their own memory replay `tfl4.swift` the same way, 8 +//! texels wide (`OWN_TWO_PLANES`). use super::degrade_notices::{assert_made_once, forced, loses_depth_denormals, on_device}; use super::degrade_notices::{ @@ -32,8 +33,8 @@ use super::{buffer_with, read_buffer}; use metal2vulkan::metal::format::{is_depth_stencil, padded_only_over_memory, ExtendedRange}; use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage}; use metal2vulkan_runtime::{ - AppleOnly, BlitOption, ClearColor, CommandBufferStatus, CommandQueue, Degradation, Device, - Error, HeapDescriptor, HeapType, Origin, Region, ResourceOptions, Size, TextureDescriptor, + BlitOption, ClearColor, CommandBufferStatus, CommandQueue, Degradation, Device, Error, + HeapDescriptor, HeapType, Origin, Region, ResourceOptions, Size, TextureDescriptor, }; use sha2::{Digest, Sha256}; use std::time::Duration; @@ -92,8 +93,8 @@ const FORMATS: [(u32, u64, &str); 50] = [ (253, 0, "3e98e4db29723b7e"), (260, 0, "6bad089e9ea96a78"), (261, 0, "dbb9a8f56e387de0"), - (550, 180224, "d9a9085f09b969dd"), - (551, 180224, "d9a9085f09b969dd"), + (550, 180224, "dadda8e50239e9ba"), + (551, 180224, "dadda8e50239e9ba"), ]; /// A format's unit as the probes count it: its block's bytes, width and height (a texel's for an @@ -226,14 +227,12 @@ fn case(raw: u32, name: &str, wide: bool) -> Case { } } -/// Metal's answers for two-plane textures of their own memory (`tfl4.swift`): -/// each format's raw value, whether 8 texels wide (else 5), and the digest of its cases' lines. -const OWN_TWO_PLANES: [(u32, bool, &str); 4] = [ - (550, false, "6254dd68bd6a8801"), - (550, true, "3abe0fd65c9b2fc9"), - (551, false, "6254dd68bd6a8801"), - (551, true, "3abe0fd65c9b2fc9"), -]; +/// Metal's answers for two-plane textures of their own memory, 8 texels wide (`tfl4.swift`): +/// each format's raw value and the digest of its cases' lines, a case of more than one level +/// `many-levels` (Metal's blits read such a texture back in bytes that vary from run to run; its +/// fills are checked through `get_bytes` in `surface_fills.rs`, as are fills 5 texels wide, whose +/// blits move texels between rows). +const OWN_TWO_PLANES: [(u32, &str); 2] = [(550, "81c7070a27e42420"), (551, "81c7070a27e42420")]; /// The cases `tfl4.swift` ran. const OWN_CASES: [&str; 15] = [ @@ -300,8 +299,7 @@ fn unpacked(raw: u32, case: &Case) -> bool { /// Case `name` of format `raw` (of a heap of `heap` bytes where a two-plane format's, else /// `wide` as [`case`] takes it): [`two_plane_case`]'s or [`texture_case`]'s answer, and whether /// the case is [`unpacked`]. Such a case's answer is `unpacked`, as Metal's table records it, -/// where its fill wrote what the same case's fill of one zero byte writes, else both answers (or -/// the refusal, where the fill was refused). +/// where its fill wrote what the same case's fill of one zero byte writes, else both answers. fn case_answer( device: &Device, queue: &CommandQueue, @@ -322,8 +320,6 @@ fn case_answer( } let zeros = run(true); let answer = match (answer, zeros) { - // A refusal stays the answer: the fill wrote nothing. - (Some(answer), _) if answer == "unmeasured" => Some(answer), (Some(answer), Some(zeros)) if answer == zeros => Some("unpacked".to_owned()), (Some(answer), Some(zeros)) => Some(format!("unpacked-differs:{answer}/{zeros}")), (answer, _) => answer, @@ -331,14 +327,6 @@ fn case_answer( (answer, true) } -/// The answer a refused fill gives. -fn refusal(error: Error) -> String { - match error { - Error::AppleOnly(AppleOnly::FillUnmeasured) => "unmeasured".to_owned(), - other => panic!("a fill refused: {other}"), - } -} - /// The descriptor of `case`'s texture of `raw`. fn descriptor(raw: u32, case: &Case, options: ResourceOptions) -> TextureDescriptor { let mut d = TextureDescriptor::texture_2d(format(raw), case.extent.0, case.extent.1, false); @@ -386,7 +374,12 @@ fn two_plane_case( command_buffer.commit().unwrap(); command_buffer.wait_until_completed_for(WAIT).unwrap(); if let Err(error) = filled { - return refusal(error); + panic!("{raw} {name}: a fill refused: {error}"); + } + // A texture of more levels or slices is held apart from the heap's bytes, which Metal's fill + // writes (`heap-two-plane-texture`). + if case.levels > 1 || case.slices > 1 { + return "held-apart".to_owned(); } let got = get(device, queue, &bytes, heap); let mut runs = Vec::new(); @@ -522,7 +515,7 @@ fn texture_case( "{raw} {name}" ); if let Err(error) = filled { - return Some(refusal(error)); + panic!("{raw} {name}: a fill refused: {error}"); } let got = read_buffer(&readback, 0, total).unwrap(); let lines: Vec = parts @@ -554,7 +547,7 @@ fn texture_fills_write_metal_s_bytes() { for name in CASES { let (answer, unpacked) = case_answer(device, &queue, (raw, name), heap, false); // A color fill packed where fills ignore the color, which the runtime ran. - unpacked_here |= unpacked && answer.as_deref().is_some_and(|a| a != "unmeasured"); + unpacked_here |= unpacked && answer.is_some(); match answer { Some(answer) => answers.push(format!("{name} {answer}")), // A 4:2:2 texture Metal makes none of; another skip is the device's. @@ -646,17 +639,21 @@ fn texture_fills_write_metal_s_bytes() { }); } -/// Every case of a two-plane texture of its own memory writes Metal's bytes, or is refused where -/// the runtime refuses it (5 texels wide, or of more than one level). +/// Every case of a two-plane texture of its own memory, 8 texels wide, writes Metal's bytes as +/// Metal's blits read them back (a case of more than one level `many-levels`, `OWN_TWO_PLANES`). #[test] fn own_two_plane_fills_write_metal_s_bytes() { on_device(|device, _messages| { let queue = device.new_command_queue().unwrap(); let mut wrong = Vec::new(); - for &(raw, wide, metal) in &OWN_TWO_PLANES { + for &(raw, metal) in &OWN_TWO_PLANES { let mut answers = Vec::new(); for name in OWN_CASES { - let answer = case_answer(device, &queue, (raw, name), 0, wide) + if case(raw, name, true).levels > 1 { + answers.push(format!("{name} many-levels")); + continue; + } + let answer = case_answer(device, &queue, (raw, name), 0, true) .0 .unwrap_or_else(|| panic!("no {raw} texture of its own")); answers.push(format!("{name} {answer}")); @@ -664,10 +661,10 @@ fn own_two_plane_fills_write_metal_s_bytes() { let ours = digest(&answers.join("\n")); if ours != metal { println!( - "XR-TEXTURE-FILLS-DIFFERS {raw} wide {wide} {ours} (Metal's {metal}): {}", + "XR-TEXTURE-FILLS-DIFFERS {raw} {ours} (Metal's {metal}): {}", answers.join("; ") ); - wrong.push((raw, wide)); + wrong.push(raw); } } assert!(wrong.is_empty(), "fills unlike Metal's: {wrong:?}"); diff --git a/crates/metal2vulkan-validation/src/runtime_lane/two_plane_copies.rs b/crates/metal2vulkan-validation/src/runtime_lane/two_plane_copies.rs index 897630604..a2bd4adf6 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/two_plane_copies.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/two_plane_copies.rs @@ -24,7 +24,11 @@ //! probe keeps. A texture-to-texture copy's planes are also checked against Metal's byte model //! (`bind::plane_copy`, which Metal's measured copies pin), at 48 x 20 and at widths that are not a //! multiple of 4; a copy whose rows overlap in the destination is announced once -//! (`two-plane-texture-copy`), and so is a buffer blit at a width off 4 (`two-plane-buffer-blit`). +//! (`two-plane-texture-copy`). A buffer blit at a width off 4 is checked against `bp.m`'s words +//! (an Apple M3 Max under macOS 27.0.1, `ROW_BLITS`): Metal's rows, and where rows meet in a blit +//! into the texture the row whose bytes Metal's stand, announced (`two-plane-buffer-blit`) where +//! Metal's order varies from run to run; and a fill read back by +//! such a blit against `pad.m`'s bytes (`PAD_CASES`), the bytes between rows included. //! A differing output is printed whole, on one `XR-TWO-PLANE-COPIES-DIFFERS` line. use super::degrade_notices::{counts, on_device}; @@ -36,6 +40,7 @@ use metal2vulkan_runtime::{ BlitOption, Buffer, CommandBufferStatus, CommandQueue, Degradation, Device, Origin, Region, Size, Texture, }; +use sha2::{Digest, Sha256}; use std::time::Duration; /// The longest a command buffer may take. @@ -48,10 +53,12 @@ const H: u64 = 20; const BIG: usize = 16 * (W * H) as usize + 1024; /// The kinds a blit between two such textures, and one between a buffer and such a texture at -/// a width that is not a multiple of 4, announce. -pub(super) const TWO_PLANE_COPIES: [Degradation; 2] = [ +/// a width that is not a multiple of 4, announce: a wide one's, and a narrower one's whose rows +/// meet between Metal's groups of 32 rows. +pub(super) const TWO_PLANE_COPIES: [Degradation; 3] = [ Degradation::TwoPlaneTextureCopy, Degradation::TwoPlaneBufferBlit, + Degradation::TwoPlaneBufferBlitOrder, ]; /// Metal's outputs: the probe's case, the output, and the SHA-256 of its bytes. @@ -858,39 +865,461 @@ fn chained_blits_reading_kept_bytes_are_announced() { }); } -/// A blit between a buffer and a level whose width is not a multiple of 4 moves the texels as -/// `get_bytes` and `replace_region` do, announced once (`two-plane-buffer-blit`): Metal's blit -/// addresses the level's rows short of where they lie. -#[test] -fn buffer_blits_at_widths_off_4_are_announced() { - on_device(|device, messages| { - let lane = lane(device); - let (w, h) = (5u64, 4u64); - let (t, _, alpha) = lane.filled(FORMATS[0].0, 1, (w, h)); - let input = random_bytes(2, (4 * w * h) as usize); - let buffer = buffer_with(device, &input).unwrap(); - lane.blit(|e| { - e.copy_from_buffer_to_texture( - &buffer, - 0, - 4 * w, - 4 * w * h, - Size::new(w, h, 1), +/// One of `bp.m`'s blits between a buffer and a two-plane texture of one level at a width off 4 +/// (an Apple M3 Max under macOS 27.0.1): the texture's width, height and slices, whether in a +/// placement heap of Metal's size, the slice, a fill of `a1 a2 a3 a4` first (x, y, width, +/// height), out of the texture or into it, the region (x, y, width, height), and Metal's words as +/// the probe printed them: out of the texture, the buffer's; into it, the texels' by `get_bytes` +/// (`t.` texel `i`'s word of slice `s` as `replace_region` set it, `t` slice 0's). +struct RowBlit { + extent: [u64; 3], + heap: bool, + slice: u64, + fill: Option<[u64; 4]>, + out: bool, + region: [u64; 4], + metal: &'static str, +} + +const fn row_blit( + (extent, heap, slice): ([u64; 3], bool, u64), + fill: Option<[u64; 4]>, + (out, region): (bool, [u64; 4]), + metal: &'static str, +) -> RowBlit { + RowBlit { + extent, + heap, + slice, + fill, + out, + region, + metal, + } +} + +const OWN: bool = false; +const OUT: bool = true; +const IN: bool = false; + +/// Metal's blits that the runtime answers alike and announces nothing for, rows that meet into +/// the texture below a width of 32 among them (in pairs of rows from an even origin, in fours +/// from another). +const ROW_BLITS: [RowBlit; 22] = [ + row_blit(([5, 3, 1], OWN, 0), None, (OUT, [0, 0, 5, 3]), + "t0 t1 t2 t3 t4 | t4 00000000 00000000 00000000 t5 | t5 t6 t7 t8 t9"), + row_blit(([5, 3, 1], OWN, 0), None, (OUT, [1, 1, 3, 2]), "00000000 00000000 00000000 | t6 t7 t8"), + row_blit(([7, 4, 1], OWN, 0), None, (OUT, [2, 1, 4, 3]), + "t6 00000000 t7 t8 | t9 t10 t11 t12 | t13 00000000 t14 t15"), + row_blit(([3, 4, 1], OWN, 0), None, (OUT, [0, 0, 3, 4]), + "t0 t1 t2 | 00000000 00000000 00000000 | 00000000 00000000 00000000 | 00000000 00000000 00000000"), + row_blit(([3, 4, 1], OWN, 0), None, (OUT, [1, 0, 2, 3]), + "t1 t2 | 00000000 00000000 | 00000000 00000000"), + row_blit(([1, 5, 1], OWN, 0), None, (OUT, [0, 0, 1, 5]), + "t0 | 00000000 | 00000000 | 00000000 | 00000000"), + row_blit(([5, 3, 2], OWN, 1), None, (OUT, [0, 0, 5, 3]), + "t1.0 t1.1 t1.2 t1.3 t1.4 | t1.4 00000000 00000000 00000000 t1.5 | t1.5 t1.6 t1.7 t1.8 t1.9"), + row_blit(([7, 4, 1], OWN, 0), None, (IN, [2, 1, 4, 3]), + "t0 t1 t2 t3 t4 t5 b0000000 | b0000002 b0000003 b0000100 b0000101 b0000102 b0000103 b0000200 | b0000202 b0000203 t16 t17 t18 t19 t20 | t21 t22 t23 t24 t25 t26 t27"), + row_blit(([3, 4, 1], OWN, 0), None, (IN, [0, 0, 3, 4]), + "b0000000 b0000001 b0000002 | b0000100 b0000101 b0000102 | b0000200 b0000201 b0000202 | b0000300 b0000301 b0000302"), + row_blit(([3, 4, 1], OWN, 0), None, (IN, [1, 1, 2, 2]), + "t0 t1 t2 | t3 b0000000 b0000001 | t6 b0000100 b0000101 | t9 t10 t11"), + row_blit(([5, 3, 1], true, 0), Some([1, 1, 2, 1]), (OUT, [0, 0, 5, 3]), + "t0 t1 t2 t3 t4 | t4 a4a3a2a1 a4a3a2a1 00000000 t5 | t5 t6 t7 t8 t9"), + row_blit(([7, 4, 1], true, 0), None, (IN, [2, 1, 4, 3]), + "t0 t1 t2 t3 t4 t5 b0000000 | b0000002 b0000003 b0000100 b0000101 b0000102 b0000103 b0000200 | b0000202 b0000203 t16 t17 t18 t19 t20 | t21 t22 t23 t24 t25 t26 t27"), + row_blit(([3, 4, 1], true, 0), None, (OUT, [0, 0, 3, 4]), + "t0 t1 t2 | 00000000 00000000 00000000 | 00000000 00000000 00000000 | 00000000 00000000 00000000"), + row_blit(([5, 3, 1], OWN, 0), Some([1, 1, 2, 1]), (OUT, [0, 0, 5, 3]), + "t0 t1 t2 t3 t4 | t4 a4a3a2a1 a4a3a2a1 00000000 t5 | t5 t6 t7 t8 t9"), row_blit(([5, 6, 1], OWN, 0), None, (IN, [0, 1, 5, 4]), + "t0 t1 t2 t3 b0000000 | b0000004 b0000101 b0000102 b0000103 b0000104 | b0000204 b0000301 b0000302 b0000303 b0000304 | t15 t16 t17 t18 t19 | t20 t21 t22 t23 t24 | t25 t26 t27 t28 t29"), + row_blit(([5, 6, 1], true, 0), None, (IN, [0, 1, 5, 4]), + "t0 t1 t2 t3 b0000000 | b0000004 b0000101 b0000102 b0000103 b0000104 | b0000204 b0000301 b0000302 b0000303 b0000304 | t15 t16 t17 t18 t19 | t20 t21 t22 t23 t24 | t25 t26 t27 t28 t29"), + row_blit(([7, 4, 3], OWN, 2), None, (IN, [1, 1, 5, 3]), + "t2.0 t2.1 t2.2 t2.3 t2.4 b0000000 b0000001 | b0000003 b0000004 b0000101 b0000102 b0000103 b0000104 b0000201 | b0000203 b0000204 t2.16 t2.17 t2.18 t2.19 t2.20 | t2.21 t2.22 t2.23 t2.24 t2.25 t2.26 t2.27"), + row_blit(([7, 3, 1], OWN, 0), None, (IN, [0, 0, 7, 3]), + "b0000000 b0000001 b0000002 b0000003 b0000004 b0000005 b0000006 | b0000200 b0000201 b0000202 b0000203 b0000204 b0000205 b0000206 | t14 t15 t16 t17 t18 t19 t20"), + row_blit(([5, 8, 1], OWN, 0), None, (IN, [0, 1, 5, 6]), + "t0 t1 t2 t3 b0000000 | b0000004 b0000101 b0000102 b0000103 b0000104 | b0000204 b0000301 b0000302 b0000303 b0000400 | b0000404 b0000501 b0000502 b0000503 b0000504 | t20 t21 t22 t23 t24 | t25 t26 t27 t28 t29 | t30 t31 t32 t33 t34 | t35 t36 t37 t38 t39"), + row_blit(([5, 6, 1], OWN, 0), None, (IN, [0, 0, 5, 6]), + "b0000000 b0000001 b0000002 b0000003 b0000004 | b0000200 b0000201 b0000202 b0000203 b0000204 | b0000400 b0000401 b0000402 b0000403 b0000404 | b0000504 t16 t17 t18 t19 | t20 t21 t22 t23 t24 | t25 t26 t27 t28 t29"), + row_blit(([6, 5, 1], OWN, 0), None, (IN, [0, 0, 6, 5]), + "b0000000 b0000001 b0000002 b0000003 b0000004 b0000005 | b0000200 b0000201 b0000202 b0000203 b0000204 b0000205 | b0000400 b0000401 b0000402 b0000403 b0000404 b0000405 | t18 t19 t20 t21 t22 t23 | t24 t25 t26 t27 t28 t29"), + row_blit(([9, 4, 1], OWN, 0), None, (IN, [0, 0, 9, 4]), + "b0000000 b0000001 b0000002 b0000003 b0000004 b0000005 b0000006 b0000007 b0000008 | b0000104 b0000105 b0000106 b0000107 b0000200 b0000201 b0000202 b0000203 b0000204 | b0000208 b0000301 b0000302 b0000303 b0000304 b0000305 b0000306 b0000307 b0000308 | t27 t28 t29 t30 t31 t32 t33 t34 t35"), +]; + +/// Metal's blits that the runtime announces: into the texture with rows that meet where Metal's +/// order varies from run to run, 32 texels wide or wider (`two-plane-buffer-blit`) and between +/// groups of 32 rows (`two-plane-buffer-blit-order`), each answered as Metal's in three runs here, +/// where the earlier row's bytes stood. +const ANNOUNCED_ROW_BLITS: [RowBlit; 2] = [ + row_blit(([41, 2, 1], OWN, 0), None, (IN, [0, 0, 41, 2]), + "b0000000 b0000001 b0000002 b0000003 b0000004 b0000005 b0000006 b0000007 b0000008 b0000009 b000000a b000000b b000000c b000000d b000000e b000000f b0000010 b0000011 b0000012 b0000013 b0000014 b0000015 b0000016 b0000017 b0000018 b0000019 b000001a b000001b b000001c b000001d b000001e b000001f b0000020 b0000021 b0000022 b0000023 b0000024 b0000025 b0000026 b0000027 b0000028 | b0000104 b0000105 b0000106 b0000107 b0000108 b0000109 b000010a b000010b b000010c b000010d b000010e b000010f b0000110 b0000111 b0000112 b0000113 b0000114 b0000115 b0000116 b0000117 b0000118 b0000119 b000011a b000011b b000011c b000011d b000011e b000011f b0000120 b0000121 b0000122 b0000123 b0000124 b0000125 b0000126 b0000127 b0000128 t78 t79 t80 t81"), + row_blit(([5, 33, 1], OWN, 0), None, (IN, [0, 0, 5, 33]), + "b0000000 b0000001 b0000002 b0000003 b0000004 | b0000200 b0000201 b0000202 b0000203 b0000204 | b0000400 b0000401 b0000402 b0000403 b0000404 | b0000600 b0000601 b0000602 b0000603 b0000604 | b0000800 b0000801 b0000802 b0000803 b0000804 | b0000a00 b0000a01 b0000a02 b0000a03 b0000a04 | b0000c00 b0000c01 b0000c02 b0000c03 b0000c04 | b0000e00 b0000e01 b0000e02 b0000e03 b0000e04 | b0001000 b0001001 b0001002 b0001003 b0001004 | b0001200 b0001201 b0001202 b0001203 b0001204 | b0001400 b0001401 b0001402 b0001403 b0001404 | b0001600 b0001601 b0001602 b0001603 b0001604 | b0001800 b0001801 b0001802 b0001803 b0001804 | b0001a00 b0001a01 b0001a02 b0001a03 b0001a04 | b0001c00 b0001c01 b0001c02 b0001c03 b0001c04 | b0001e00 b0001e01 b0001e02 b0001e03 b0001e04 | b0001f04 b0002001 b0002002 b0002003 b0002004 | t85 t86 t87 t88 t89 | t90 t91 t92 t93 t94 | t95 t96 t97 t98 t99 | t100 t101 t102 t103 t104 | t105 t106 t107 t108 t109 | t110 t111 t112 t113 t114 | t115 t116 t117 t118 t119 | t120 t121 t122 t123 t124 | t125 t126 t127 t128 t129 | t130 t131 t132 t133 t134 | t135 t136 t137 t138 t139 | t140 t141 t142 t143 t144 | t145 t146 t147 t148 t149 | t150 t151 t152 t153 t154 | t155 t156 t157 t158 t159 | t160 t161 t162 t163 t164"), +]; + +/// The words `printed` names, as `bp.m` printed them. +fn printed_words(printed: &str) -> Vec { + printed + .split_whitespace() + .filter(|token| *token != "|") + .map(|token| match token.strip_prefix('t') { + Some(texel) => { + let (slice, index) = texel.split_once('.').unwrap_or(("0", texel)); + 0x1000_0000 + + (u32::from_str_radix(slice, 16).unwrap() << 16) + + index.parse::().unwrap() + } + None => u32::from_str_radix(token, 16).unwrap(), + }) + .collect() +} + +/// `blit`'s words, as the runtime answers them. +fn row_blit_words(device: &Device, queue: &CommandQueue, blit: &RowBlit) -> Vec { + let [w, h, slices] = blit.extent; + let mut d = metal2vulkan_runtime::TextureDescriptor::texture_2d(FORMATS[0].0, w, h, false); + if slices > 1 { + d.texture_type = metal2vulkan::metal::TextureType::Type2DArray; + d.array_length = slices; + } + d.usage = metal2vulkan::metal::TextureUsage::SHADER_READ; + d.resource_options = metal2vulkan_runtime::ResourceOptions::shared(); + let t = match blit.heap { + true => { + let size = device.heap_texture_size_and_align(&d).unwrap().size; + let heap = device + .new_heap(&metal2vulkan_runtime::HeapDescriptor::new( + metal2vulkan_runtime::HeapType::Placement, + size, + metal2vulkan_runtime::ResourceOptions::shared(), + )) + .unwrap(); + heap.new_texture_at_offset(&d, 0).unwrap() + } + false => device.new_texture(&d).unwrap(), + }; + for s in 0..slices { + let words: Vec = (0..w * h) + .flat_map(|i| (0x1000_0000 + (s << 16) as u32 + i as u32).to_le_bytes()) + .collect(); + t.replace_region(Region::new_2d(0, 0, w, h), 0, s, &words, 4 * w, 4 * w * h) + .unwrap(); + } + let run = |body: &dyn Fn(&mut metal2vulkan_runtime::BlitCommandEncoder)| { + let command_buffer = queue.command_buffer().unwrap(); + let mut encoder = command_buffer.blit_command_encoder().unwrap(); + body(&mut encoder); + encoder.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(command_buffer.status(), CommandBufferStatus::Completed); + }; + if let Some([x, y, fw, fh]) = blit.fill { + run(&|e| { + e.fill_texture( &t, 0, 0, - Origin::new(0, 0, 0), + Region::new_2d(x, y, fw, fh), + &[0xa1, 0xa2, 0xa3, 0xa4], + ) + .unwrap() + }); + } + let [x, y, rw, rh] = blit.region; + let row = 4 * rw; + let words = |bytes: Vec| -> Vec { + bytes + .as_chunks::<4>() + .0 + .iter() + .map(|b| u32::from_le_bytes(*b)) + .collect() + }; + if blit.out { + let buffer = buffer_with(device, &vec![0xee; (row * rh) as usize]).unwrap(); + run(&|e| { + e.copy_from_texture_to_buffer( + &t, + blit.slice, + 0, + Origin::new(x, y, 0), + Size::new(rw, rh, 1), + &buffer, + 0, + row, + row * rh, BlitOption::None, ) .unwrap() }); - assert_eq!(lane.planes_sized(&t, (w, h)), (input, alpha)); + return words(read_buffer(&buffer, 0, row * rh).unwrap()); + } + let input: Vec = (0..rh) + .flat_map(|r| (0..rw).map(move |c| 0xb000_0000u32 + ((r as u32) << 8) + c as u32)) + .flat_map(u32::to_le_bytes) + .collect(); + let buffer = buffer_with(device, &input).unwrap(); + run(&|e| { + e.copy_from_buffer_to_texture( + &buffer, + 0, + row, + row * rh, + Size::new(rw, rh, 1), + &t, + blit.slice, + 0, + Origin::new(x, y, 0), + BlitOption::None, + ) + .unwrap() + }); + let mut texels = vec![0; (4 * w * h) as usize]; + t.get_bytes( + &mut texels, + 4 * w, + 4 * w * h, + Region::new_2d(0, 0, w, h), + 0, + blit.slice, + ) + .unwrap(); + words(texels) +} + +/// A blit between a buffer and a two-plane texture of one level at a width off 4, of its own +/// memory or a heap's, moves Metal's words at Metal's rows: out of the texture the bytes between +/// rows too (0 in a new texture, as a fill left them, held apart in a texture of the device's +/// memory), and below a width of 4 only the first row; into it, where rows meet, the row whose +/// bytes Metal's GPU leaves; announced only where rows meet in a blit into it where Metal's order +/// varies from run to run. +#[test] +fn buffer_blits_at_widths_off_4_take_metal_s_rows() { + on_device(|device, messages| { + let queue = device.new_command_queue().unwrap(); + let mut wrong = Vec::new(); + let mut check = |n: usize, blit: &RowBlit, want: &str| { + let ours = row_blit_words(device, &queue, blit); + if ours != printed_words(want) { + println!("XR-TWO-PLANE-COPIES-DIFFERS rows {n}: {ours:08x?} (Metal's {want})"); + wrong.push(n); + } + }; + for (n, blit) in ROW_BLITS.iter().enumerate() { + check(n, blit, blit.metal); + } let notices = counts(&messages.take_notices()); - assert_eq!( - notices.get(&TWO_PLANE_COPIES[1]).copied(), - Some(1), - "{notices:?}" - ); + assert_eq!(notices.get(&TWO_PLANE_COPIES[1]), None, "{notices:?}"); + assert_eq!(notices.get(&TWO_PLANE_COPIES[2]), None, "{notices:?}"); + for (n, blit) in ANNOUNCED_ROW_BLITS.iter().enumerate() { + check(100 + n, blit, blit.metal); + } + // The wide blit's kind and the one across groups of 32 rows', each once. + let notices = counts(&messages.take_notices()); + for kind in &TWO_PLANE_COPIES[1..] { + assert_eq!(notices.get(kind).copied(), Some(1), "{notices:?}"); + } + assert!(wrong.is_empty(), "blits unlike Metal's: {wrong:?}"); + }); +} + +/// Our probe `pad.m`'s cases (an Apple M3 Max under macOS 27.0.1, alike in two runs): a private +/// texture of the format, width, height and slices, every color word set to `0xee` by a blit +/// from a buffer, one fill of a slice's region (a pattern, or a color packed in `RGBA8Unorm`), +/// and every slice read back by a blit into a buffer, rows `4 w` bytes apart; Metal's answer, the +/// first 16 hex digits of the SHA-256 of the probe's lines (`s r:` and the row's +/// bytes). +type PadCase = ( + u32, + [u64; 3], + u64, + [u64; 4], + Result<&'static str, [f64; 4]>, + &'static str, +); + +const PAD_CASES: [PadCase; 9] = [ + ( + 550, + [7, 3, 1], + 0, + [0, 0, 7, 3], + Ok("0102030405060708"), + "a22dfa6fdd93570d", + ), + ( + 550, + [7, 3, 1], + 0, + [2, 1, 9, 5], + Ok("090a0b"), + "5b9fcd63521fb5dc", + ), + ( + 551, + [33, 5, 1], + 0, + [3, 1, 20, 3], + Err([1.0, 0.5, 0.25, 1.0]), + "ce168b61643ecebb", + ), + ( + 550, + [6, 2, 1], + 0, + [0, 0, 6, 2], + Ok("0102030405060708"), + "dcc033fcbab11d58", + ), + ( + 550, + [7, 3, 1], + 0, + [0, 0, 0, 0], + Ok("01"), + "37ba266b851a2342", + ), + ( + 550, + [13, 4, 1], + 0, + [1, 1, 5, 2], + Ok("a1b2c3d4"), + "94b181522346b0df", + ), + ( + 550, + [5, 3, 2], + 1, + [0, 0, 5, 3], + Ok("a1b2c3d4"), + "fea04cfb6251b2ab", + ), + ( + 550, + [3, 4, 1], + 0, + [0, 0, 3, 4], + Ok("a1b2c3d4"), + "683193cef365dc59", + ), + ( + 551, + [9, 3, 1], + 0, + [1, 0, 7, 3], + Ok("c1c2c3c4"), + "b6719f0cdbc1e202", + ), +]; + +/// `case`'s lines, as the runtime answers them. +fn pad_lines(device: &Device, queue: &CommandQueue, case: &PadCase) -> Vec { + let &(raw, [w, h, slices], slice, [x, y, rw, rh], fill, _) = case; + let pf = PixelFormat::try_from(raw).unwrap(); + let mut d = metal2vulkan_runtime::TextureDescriptor::texture_2d(pf, w, h, false); + if slices > 1 { + d.texture_type = metal2vulkan::metal::TextureType::Type2DArray; + d.array_length = slices; + } + d.usage = metal2vulkan::metal::TextureUsage::SHADER_READ; + d.resource_options = metal2vulkan_runtime::ResourceOptions::private(); + let t = device.new_texture(&d).unwrap(); + let (row, image) = (4 * w, 4 * w * h); + let source = buffer_with(device, &vec![0xee; image as usize]).unwrap(); + let out = buffer_with(device, &vec![0x55; (image * slices) as usize]).unwrap(); + let command_buffer = queue.command_buffer().unwrap(); + let mut e = command_buffer.blit_command_encoder().unwrap(); + for s in 0..slices { + e.copy_from_buffer_to_texture( + &source, + 0, + row, + image, + Size::new(w, h, 1), + &t, + s, + 0, + Origin::new(0, 0, 0), + BlitOption::None, + ) + .unwrap(); + } + let region = Region::new_2d(x, y, rw, rh); + match fill { + Ok(pattern) => { + let bytes: Vec = (0..pattern.len()) + .step_by(2) + .map(|at| u8::from_str_radix(&pattern[at..at + 2], 16).unwrap()) + .collect(); + e.fill_texture(&t, 0, slice, region, &bytes).unwrap(); + } + Err([r, g, b, a]) => { + let color = metal2vulkan_runtime::ClearColor::new(r, g, b, a); + e.fill_texture_color(&t, 0, slice, region, color, Some(PixelFormat::RGBA8Unorm)) + .unwrap(); + } + } + for s in 0..slices { + e.copy_from_texture_to_buffer( + &t, + s, + 0, + Origin::new(0, 0, 0), + Size::new(w, h, 1), + &out, + s * image, + row, + image, + BlitOption::None, + ) + .unwrap(); + } + e.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(command_buffer.status(), CommandBufferStatus::Completed); + let bytes = read_buffer(&out, 0, image * slices).unwrap(); + (0..slices) + .flat_map(|s| (0..h).map(move |r| (s, r))) + .map(|(s, r)| { + let at = (s * image + r * row) as usize; + let hex: String = bytes[at..at + row as usize] + .iter() + .map(|b| format!(" {b:02x}")) + .collect(); + format!("s{s} r{r}:{hex}") + }) + .collect() +} + +/// A fill of a two-plane texture of the device's memory at a width off 4, read back by a blit +/// into a buffer, gives Metal's bytes: the words the fill (and the blit that set the texture up) +/// wrote between the rows read back where Metal's do. +#[test] +fn fills_read_back_between_rows_as_metal_s() { + on_device(|device, messages| { + let queue = device.new_command_queue().unwrap(); + let mut wrong = Vec::new(); + for (n, case) in PAD_CASES.iter().enumerate() { + let lines = pad_lines(device, &queue, case); + let sum = Sha256::digest(lines.join("\n").as_bytes()); + let got: String = sum.iter().take(8).map(|b| format!("{b:02x}")).collect(); + if got != case.5 { + println!( + "XR-TWO-PLANE-COPIES-DIFFERS pad {n}: {got} (Metal's {}): {lines:?}", + case.5 + ); + wrong.push(n); + } + } + messages.take_notices(); + assert!(wrong.is_empty(), "fills unlike Metal's: {wrong:?}"); }); } diff --git a/crates/metal2vulkan/src/bind/unused_bits.rs b/crates/metal2vulkan/src/bind/unused_bits.rs index 7efbc5478..69a061027 100644 --- a/crates/metal2vulkan/src/bind/unused_bits.rs +++ b/crates/metal2vulkan/src/bind/unused_bits.rs @@ -2,11 +2,11 @@ //! //! A render pass on an Apple GPU stores its attachments a 32 x 32 tile at a time. A pass that //! loads a color attachment of an extended-range format (`BGR10_XR`, `BGRA10_XR`, -//! `RGB10A8_2P_XR10`, their `_sRGB` twins) or a padded 10-bit one (`R10Unorm_X6`, -//! `RG10Unorm_X12`, their `_sRGB` twins) and records a draw writes every texel of each tile it -//! stores back, where a channel a fragment writes takes the write; every other texel keeps its -//! codes, the bits they leave unused made canonical (on an Apple M4 and the consumer's Apple M3 -//! Max): +//! `RGB10A8_2P_XR10`, their `_sRGB` twins), a padded 10-bit one (`R10Unorm_X6`, +//! `RG10Unorm_X12`, their `_sRGB` twins) or `RGB10A2Unorm_sRGB` and records a draw writes every +//! texel of each tile it stores back, where a channel a fragment writes takes the write; every +//! other texel keeps its codes, the bits they leave unused made canonical (on an Apple M4 and the +//! consumer's Apple M3 Max): //! //! - `BGR10_XR`'s word: bits 30 and 31 set; //! - `BGRA10_XR`'s four 16-bit fields: each field's low six bits cleared, and the alpha field's @@ -15,6 +15,8 @@ //! - a padded 16-bit word: its low six bits cleared, an `_sRGB` twin's code through Metal's table //! (`ExtendedRange::load_code`: 23 codes of `R10Unorm_X6_sRGB` move, 1021 of //! `RG10Unorm_X12_sRGB`); +//! - `RGB10A2Unorm_sRGB`'s word: each color field's code through `R10Unorm_X6_sRGB`'s table, alpha's +//! kept (an Apple M3 Max under macOS 27.0.1: 260 of 4096 words move); //! - a bfloat format's 16-bit code (`R16Bfloat`, `RG16Bfloat`, `RGBA16Bfloat`): its value through //! `half` to nearest even and back to the nearest bfloat code, ties to even, a NaN `0x7fc0` //! (`ExtendedRange::load_code`; on an Apple M4 under macOS 27.0.1: 56,829 of the @@ -170,6 +172,9 @@ enum Rule { /// A padded form's two 16-bit words: each one's low six bits cleared, or each one's code /// replaced by the table's word for it (an `_sRGB` twin's, [`rewritten_words`]). Padded(Option>), + /// `RGB10A2Unorm_sRGB`'s word: each color field's code replaced by the table's code for it + /// (`ExtendedRange::load_code`), alpha's kept. + SrgbFields(Vec), /// A bfloat form's two 16-bit codes: each one's value through `half` and back /// (`ExtendedRange::load_code`, [`bfloat_load`]). Bfloat, @@ -207,6 +212,11 @@ fn extended_rule(form: ExtendedRange, words: TexelWords) -> Option { (ExtendedRange::Planes { .. }, TexelWords::Raw) => Rule::PlaneTexel, (ExtendedRange::Planes { .. }, TexelWords::ColorPlane) => Rule::ZerosOnTop, (_, TexelWords::ColorPlane) => return None, + (ExtendedRange::Rgb10A2Srgb, TexelWords::Raw) => Rule::SrgbFields( + (0..1024u32) + .map(|c| form.load_code(c)) + .collect::>()?, + ), _ if form.padded() => Rule::Padded(rewritten_words(form)), _ if form.bfloat() => Rule::Bfloat, _ => return None, @@ -337,6 +347,26 @@ fn rewritten( let hi = f.binary(BinOp::ShiftLeftLogical, hi, k16)?; f.binary(BinOp::BitwiseOr, lo, hi)? } + Rule::SrgbFields(_) => { + let table = table.ok_or(crate::spirv::error::BuildError::Operand { + op: crate::spv::Op::AccessChain, + rule: crate::spirv::error::OperandRule::NotPointer, + })?; + let table = f.module().global_value(table)?; + let field = u32_value(f, 0x3ff)?; + let alpha = u32_value(f, !CODES)?; + let mut out = f.binary(BinOp::BitwiseAnd, word, alpha)?; + for shift in [0u32, 10, 20] { + let k = u32_value(f, shift)?; + let c = f.binary(BinOp::ShiftRightLogical, word, k)?; + let c = f.binary(BinOp::BitwiseAnd, c, field)?; + let c = f.access_chain(table, &[c])?; + let c = f.load(c, MemAccess::default())?; + let c = f.binary(BinOp::ShiftLeftLogical, c, k)?; + out = f.binary(BinOp::BitwiseOr, out, c)?; + } + out + } Rule::Bfloat => { let (k16, low) = (u32_value(f, 16)?, u32_value(f, 0xffff)?); let lo = f.binary(BinOp::BitwiseAnd, word, low)?; @@ -547,7 +577,7 @@ fn typed_module(rule: &Rule, texel_bytes: u32) -> BResult { let tiles = words_buffer(&mut b, TILES, u32_)?; let shape = words_buffer(&mut b, SHAPE, u32_)?; let table = match rule { - Rule::Padded(Some(t)) => Some(words_table(&mut b, u32_, t)?), + Rule::Padded(Some(t)) | Rule::SrgbFields(t) => Some(words_table(&mut b, u32_, t)?), _ => None, }; let invocation = b.builtin(crate::spv::BuiltIn::GlobalInvocationId, IoDir::Input, uvec3)?; diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index 2649c6298..ec02c5cd7 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -1122,7 +1122,7 @@ codec_enum! { } ExtendedRange { Bgr10 { srgb }, Bgra10 { srgb }, Planes { srgb }, R10X6, Rg10X12, R10X6Srgb, Rg10X12Srgb, - R16Bfloat, Rg16Bfloat, Rgba16Bfloat, + R16Bfloat, Rg16Bfloat, Rgba16Bfloat, Rgb10A2Srgb, } WordAttachment { Packed16 { fields }, Srgb8 { fields }, Rgb9e5 } FactorLane { Zero, One, Output(f0) } diff --git a/crates/metal2vulkan/src/lower/arith/extended_range.rs b/crates/metal2vulkan/src/lower/arith/extended_range.rs index e389456cb..196fb9848 100644 --- a/crates/metal2vulkan/src/lower/arith/extended_range.rs +++ b/crates/metal2vulkan/src/lower/arith/extended_range.rs @@ -124,6 +124,16 @@ fn codes(fb: &mut FunctionBuilder<'_>, form: ExtendedRange, raw: Value) -> BResu let fill = per_lane(fb, [0, 0, 0, 1023])?; fb.vector_shuffle(c, fill, padded_lanes(form)) } + // `RGB10A2Unorm_sRGB`'s word: red, green and blue in 10-bit fields from bit 0, alpha's + // 2-bit code in bits 30 and 31. + ExtendedRange::Rgb10A2Srgb => { + let w = fb.composite_extract(raw, &[0])?; + let w = fb.composite_construct(ut, &[w, w, w, w])?; + let shifts = per_lane(fb, [0, 10, 20, 30])?; + let c = fb.binary(BinOp::ShiftRightLogical, w, shifts)?; + let m = per_lane(fb, [0x3FF, 0x3FF, 0x3FF, 0x3])?; + fb.binary(BinOp::BitwiseAnd, c, m) + } // A bfloat form has no codes of this kind: its texels convert by [`bfloat_value`] and // [`bfloat_texel`], and no attachment of one is held. ExtendedRange::R16Bfloat | ExtendedRange::Rg16Bfloat | ExtendedRange::Rgba16Bfloat => Err( @@ -343,19 +353,28 @@ fn value_of_codes( // A padded format's lane reads `c / 1023` correctly rounded, its `half` to nearest even // (every code; `c / 1023` is never a `half` tie), `RG10Unorm_X12_sRGB`'s too. // `R10Unorm_X6_sRGB`'s red reads its code's decode step `s / 8192` (every code), its `half` - // with ties away from zero (every code). + // with ties away from zero (every code); so do `RGB10A2Unorm_sRGB`'s red, green and blue, + // and its alpha `a / 3` correctly rounded, never a `half` tie (an Apple M3 Max, every code). if form.padded() { - let d = splat(fb, u, 1023)?; + let d = match form { + ExtendedRange::Rgb10A2Srgb => per_lane(fb, [1023, 1023, 1023, 3])?, + _ => splat(fb, u, 1023)?, + }; let v = ratio_to_f32(fb, u, c, d)?; let (v, rounding) = match form { - ExtendedRange::R10X6Srgb => { + ExtendedRange::R10X6Srgb | ExtendedRange::Rgb10A2Srgb => { let table = table.ok_or_else(missing_table)?; - let c0 = fb.composite_extract(c, &[0])?; - let red = table_step(fb, table, c0)?; + let colors = srgb_channels(form); let ft = crate::lower::arith::ops::ty(fb, f)?; - let mut lanes = vec![red]; - for lane in 1..4u32 { - lanes.push(fb.composite_extract(v, &[lane])?); + let mut lanes = Vec::with_capacity(4); + for lane in 0..4u32 { + lanes.push(match lane < colors { + true => { + let code = fb.composite_extract(c, &[lane])?; + table_step(fb, table, code)? + } + false => fb.composite_extract(v, &[lane])?, + }); } let v = fb.composite_construct(ft, &lanes)?; (v, HalfRounding::NearestAway) @@ -443,14 +462,32 @@ pub fn encode( let v = fb.select(nan, zero, v)?; let one = fsplat(fb, f, 1.0)?; let v = fb.glsl(GlslOp::FClamp, &[v, zero, one])?; - let k = round_exact_product_lanes(fb, f, v, &[1023], false)?; + let scales: &[u32] = match form { + ExtendedRange::Rgb10A2Srgb => &[1023, 1023, 1023, 3], + _ => &[1023], + }; + let k = round_exact_product_lanes(fb, f, v, scales, false)?; let k = match form { - ExtendedRange::R10X6Srgb | ExtendedRange::Rg10X12Srgb => { + ExtendedRange::R10X6Srgb | ExtendedRange::Rg10X12Srgb | ExtendedRange::Rgb10A2Srgb => { let table = table.ok_or_else(missing_table)?; padded_srgb_codes(fb, form, table, v, k)? } _ => k, }; + // `RGB10A2Unorm_sRGB`'s fields from bit 0, alpha in bits 30 and 31. + if form == ExtendedRange::Rgb10A2Srgb { + let shifts = per_lane(fb, [0, 10, 20, 30])?; + let k = fb.binary(BinOp::ShiftLeftLogical, k, shifts)?; + let mut w = fb.composite_extract(k, &[0])?; + for lane in 1..4u32 { + let x = fb.composite_extract(k, &[lane])?; + w = fb.binary(BinOp::BitwiseOr, w, x)?; + } + let z = fb.u32_const(0)?; + let z = fb.module().const_value(z)?; + let ut = crate::lower::arith::ops::ty(fb, u)?; + return fb.composite_construct(ut, &[w, z, z, z]); + } let six = splat(fb, u, 6)?; let w = fb.binary(BinOp::ShiftLeftLogical, k, six)?; let z = splat(fb, u, 0)?; @@ -721,6 +758,7 @@ fn pack(fb: &mut FunctionBuilder<'_>, form: ExtendedRange, code: Value) -> BResu | ExtendedRange::Rg10X12 | ExtendedRange::R10X6Srgb | ExtendedRange::Rg10X12Srgb + | ExtendedRange::Rgb10A2Srgb | ExtendedRange::R16Bfloat | ExtendedRange::Rg16Bfloat | ExtendedRange::Rgba16Bfloat => Err(crate::spirv::error::BuildError::Type( @@ -735,7 +773,8 @@ fn pack(fb: &mut FunctionBuilder<'_>, form: ExtendedRange, code: Value) -> BResu /// and a grid). `R10Unorm_X6_sRGB`'s red is the largest code whose first encode index is at most /// `RoundEven(v · 8192)` (exact: `v` below 1 times `2^13`), as an extended-range `_sRGB` channel's /// offset is ([`search`]); `RG10Unorm_X12_sRGB`'s red and green are the table's code of each linear -/// code. The other lanes stay `k`'s. +/// code. `RGB10A2Unorm_sRGB`'s red, green and blue are `R10Unorm_X6_sRGB`'s red's (an Apple M3 +/// Max, 16,385 values). The other lanes stay `k`'s. fn padded_srgb_codes( fb: &mut FunctionBuilder<'_>, form: ExtendedRange, @@ -749,12 +788,12 @@ fn padded_srgb_codes( signed: false, })?; let f1 = fb.module().ty(Type::Float { width: 32 })?; - let channels = form.raw_components(); + let channels = srgb_channels(form); let mut lanes = Vec::with_capacity(4); for lane in 0..4u32 { let code = match (lane < channels, form) { (false, _) => fb.composite_extract(k, &[lane])?, - (true, ExtendedRange::R10X6Srgb) => { + (true, ExtendedRange::R10X6Srgb | ExtendedRange::Rgb10A2Srgb) => { let grid = fb.module().constant(Constant::Scalar { ty: f1, bits: ConstBits(u64::from(8192.0f32.to_bits())), @@ -776,6 +815,14 @@ fn padded_srgb_codes( fb.composite_construct(ut, &lanes) } +/// The lanes, from red, a padded `_sRGB` form's table converts: its color channels. +fn srgb_channels(form: ExtendedRange) -> u32 { + match form { + ExtendedRange::Rgb10A2Srgb => 3, + _ => form.raw_components(), + } +} + /// A `vec4` constant of the four `f32` lanes `v`. fn per_lane_f(fb: &mut FunctionBuilder<'_>, v: [f32; 4]) -> BResult { let ft = crate::lower::arith::ops::ty(fb, floats())?; diff --git a/crates/metal2vulkan/src/lower/arith/extended_range/table.rs b/crates/metal2vulkan/src/lower/arith/extended_range/table.rs index 662073a8d..b63a66952 100644 --- a/crates/metal2vulkan/src/lower/arith/extended_range/table.rs +++ b/crates/metal2vulkan/src/lower/arith/extended_range/table.rs @@ -34,11 +34,12 @@ pub fn declare(mb: &mut ModuleBuilder) -> BResult { /// Declare the module's table of the padded `_sRGB` form `form`, a `Private` `u32[1024]` /// indexed by code (`metal::format::padded_srgb`): `R10Unorm_X6_sRGB`'s holds each code's /// decode step in its low half and its first encode index in its high half, as [`declare`]'s -/// does an offset's, so [`search`] encodes through it; `RG10Unorm_X12_sRGB`'s holds the code a +/// does an offset's, so [`search`] encodes through it (`RGB10A2Unorm_sRGB`'s color channels +/// take the same); `RG10Unorm_X12_sRGB`'s holds the code a /// write of each linear code stores. `None` for every other form, which has no such table. pub fn declare_padded(mb: &mut ModuleBuilder, form: ExtendedRange) -> BResult> { let words: Vec = match form { - ExtendedRange::R10X6Srgb => R10X6_SRGB_DECODE_STEPS + ExtendedRange::R10X6Srgb | ExtendedRange::Rgb10A2Srgb => R10X6_SRGB_DECODE_STEPS .iter() .zip(&R10X6_SRGB_ENCODE_FIRST) .map(|(&step, &first)| u64::from(step) | (u64::from(first) << 16)) diff --git a/crates/metal2vulkan/src/lower/arith/extended_range/tests.rs b/crates/metal2vulkan/src/lower/arith/extended_range/tests.rs index 6dad2b336..84e0fce89 100644 --- a/crates/metal2vulkan/src/lower/arith/extended_range/tests.rs +++ b/crates/metal2vulkan/src/lower/arith/extended_range/tests.rs @@ -556,7 +556,8 @@ pub(crate) fn tile_model(form: ExtendedRange, rgba: [u32; 4]) -> [f32; 4] { ExtendedRange::R10X6 | ExtendedRange::Rg10X12 | ExtendedRange::R10X6Srgb - | ExtendedRange::Rg10X12Srgb => { + | ExtendedRange::Rg10X12Srgb + | ExtendedRange::Rgb10A2Srgb => { panic!("{form:?}: a padded form's tile value is not measured") } ExtendedRange::R16Bfloat | ExtendedRange::Rg16Bfloat | ExtendedRange::Rgba16Bfloat => { @@ -1994,6 +1995,118 @@ fn padded_srgb_forms_read_and_write_metals_codes() { } } +/// `a / 3` correctly rounded to `f32` (`a` below 4): the `f64` quotient's neighbours compared +/// exactly (each `f32` times 3 is exact in `f64`). +fn third(a: u32) -> f32 { + let q = f64::from(a) / 3.0; + let y = q as f32; + [ + y, + f32::from_bits(y.to_bits().wrapping_sub(1)), + f32::from_bits(y.to_bits() + 1), + ] + .into_iter() + .min_by(|x, z| { + let d = |v: &f32| (f64::from(*v) * 3.0 - f64::from(a)).abs(); + d(x).total_cmp(&d(z)) + }) + .expect("a candidate") +} + +/// `RGB10A2Unorm_sRGB` (an Apple M3 Max under macOS 27.0.1, our probe: every code of each +/// channel read, 16,385 values and the specials written in each) reads each color field's code as +/// `R10Unorm_X6_sRGB`'s red (its decode step over 8192, a `half` with ties away from zero) and +/// alpha's 2-bit code `a` as `a / 3`, and writes each color channel as `R10Unorm_X6_sRGB`'s red +/// and alpha as the exact product with 3 of the value clamped to `[0, 1]` (a NaN 0), rounded to +/// nearest, into one word: red from bit 0, green 10, blue 20, alpha 30. Its clear texels and load +/// codes follow the same rules. +#[test] +fn rgb10a2_srgb_reads_and_writes_metals_codes() { + let form = ExtendedRange::Rgb10A2Srgb; + let step = |c: u32| f32::from(R10X6_SRGB_DECODE_STEPS[c as usize]) / 8192.0; + // The probe's words: red c, green 1023 - c, blue 7c mod 1024, alpha c mod 4. + let lanes: Vec<[u32; 4]> = (0..1024u32) + .map(|c| { + [ + c | (1023 - c) << 10 | (7 * c % 1024) << 20 | (c % 4) << 30, + 0, + 0, + 0, + ] + }) + .collect(); + let got = run(form, Op::Decode, &lanes); + let halves = run(form, Op::DecodeHalf, &lanes); + for ((l, g), h) in lanes.iter().zip(&got).zip(&halves) { + let w = l[0]; + let want = [ + step(w & 1023), + step(w >> 10 & 1023), + step(w >> 20 & 1023), + third(w >> 30), + ]; + assert_eq!(*g, want.map(f32::to_bits), "word {w:08x}"); + let want = want.map(|v| to_half(f64::from(v), true)); + assert_eq!(*h, want.map(f32::to_bits), "half, word {w:08x}"); + } + let mut values: Vec = (0..=16384u32).map(|k| k as f32 / 16384.0).collect(); + for &first in &R10X6_SRGB_ENCODE_FIRST { + let first = f64::from(first); + if first > 0.0 { + let edge = ((first - 0.5) / 8192.0) as f32; + values.extend((0..5).map(|d| f32::from_bits(edge.to_bits() + d - 2))); + } + } + for a in [1.0f64, 2.0] { + let mid = ((a - 0.5) / 3.0) as f32; + values.extend((0..5).map(|d| f32::from_bits(mid.to_bits() + d - 2))); + } + values.extend([ + f32::NAN, + -f32::NAN, + f32::INFINITY, + f32::NEG_INFINITY, + -0.0, + -1.0, + 1.5, + f32::from_bits(1), + ]); + let alpha_code = |v: f32| match v.is_nan() { + true => 0, + false => (f64::from(v.clamp(0.0, 1.0)) * 3.0).round_ties_even() as u32, + }; + let lanes: Vec<[u32; 4]> = (0..values.len()) + .map(|i| { + let v = |k: usize| values[(i * k) % values.len()].to_bits(); + [v(1), v(7919), v(104_729), v(31)] + }) + .collect(); + let got = run(form, Op::Encode, &lanes); + for (l, g) in lanes.iter().zip(&got) { + let v = l.map(f32::from_bits); + let code = |c: usize| padded_srgb_code(ExtendedRange::R10X6Srgb, v[c]); + let word = code(0) | code(1) << 10 | code(2) << 20 | alpha_code(v[3]) << 30; + assert_eq!(*g, [word, 0, 0, 0], "values {v:?}"); + } + // The crate's clear texels and load codes agree with the rules (the runtime's clear writes + // `clear_texel`, its load pass `load_code`, alpha kept). + for c in 0..1024u32 { + let code = padded_srgb_code(ExtendedRange::R10X6Srgb, step(c)); + assert_eq!(form.load_code(c), Some(code), "code {c}"); + } + let half = |v: f64| crate::float16::f16_bits_to_f32(crate::float16::f32_to_f16_bits(v as f32)); + for color in [ + [0.25, 0.5, 0.75, 0.4], + [1.0, 0.0, 0.1, 1.0], + [-1.0, 2.0, f64::NAN, 0.2], + ] { + let route = crate::metal::format::ClearRoute::ThroughHalf; + let code = |c: usize| padded_srgb_code(ExtendedRange::R10X6Srgb, half(color[c])); + let word = code(0) | code(1) << 10 | code(2) << 20 | alpha_code(half(color[3])) << 30; + assert_eq!(form.clear_texel(color, route), [word, 0, 0, 0], "{color:?}"); + } +} + /// The texel words [`run`] reads of a table texel of `layout`: its plane-0 bytes `plane` and a /// two-plane texel's alpha byte `alpha`. fn table_texel(layout: xr_blends::Layout, plane: &[u8], alpha: Option<&u8>) -> [u32; 4] { diff --git a/crates/metal2vulkan/src/lower/arith/tests/float_texel.rs b/crates/metal2vulkan/src/lower/arith/tests/float_texel.rs index 8cd04fc3f..6802b1b62 100644 --- a/crates/metal2vulkan/src/lower/arith/tests/float_texel.rs +++ b/crates/metal2vulkan/src/lower/arith/tests/float_texel.rs @@ -217,7 +217,8 @@ fn a_packed_texel_is_its_codes_value() { | PackedTexels::Argb8 | PackedTexels::YCbCr2048 | PackedTexels::YCbCr8192 - | PackedTexels::YCbCrExtended8192 => continue, + | PackedTexels::YCbCrExtended8192 + | PackedTexels::Rgb10A2Srgb => continue, }; let full = texel_format(full); assert!(full.packed_exact(), "{p:?}"); diff --git a/crates/metal2vulkan/src/lower/arith/tests/half_texel.rs b/crates/metal2vulkan/src/lower/arith/tests/half_texel.rs index 31f05b15c..ee2a2b704 100644 --- a/crates/metal2vulkan/src/lower/arith/tests/half_texel.rs +++ b/crates/metal2vulkan/src/lower/arith/tests/half_texel.rs @@ -479,7 +479,7 @@ fn a_packed_texel_converts_from_its_codes() { (HalfForm::Sample, TexelLanes::Filtered), (HalfForm::Read, TexelLanes::Gathered(1)), ] { - let away = p.ycbcr() && lanes != TexelLanes::Filtered; + let away = p.ties_away() && lanes != TexelLanes::Filtered; let mode = match away { true => HalfRounding::NearestAway, false => HalfRounding::NearestEven, diff --git a/crates/metal2vulkan/src/lower/sampler/bicubic/routines.rs b/crates/metal2vulkan/src/lower/sampler/bicubic/routines.rs index 2fbe46337..400354bc9 100644 --- a/crates/metal2vulkan/src/lower/sampler/bicubic/routines.rs +++ b/crates/metal2vulkan/src/lower/sampler/bicubic/routines.rs @@ -136,18 +136,18 @@ pub enum Routine { impl Routine { /// An upper estimate of the routines' SPIR-V words, counted once per module. Measured 9062 /// words for [`Routine::Plane`] and 3663 for [`Routine::Line`] since the extended-range grids, - /// and 4954 for [`Routine::Quad`], 3750 for [`Routine::Span`], and 7839 for [`Routine::Block`] - /// since YCbCr's grid and truncation (`bicubic_routines_words_bound_their_emission`). + /// and 5218 for [`Routine::Quad`], 4014 for [`Routine::Span`], and 8103 for [`Routine::Block`] + /// since `RGB10A2Unorm_sRGB`'s field (`bicubic_routines_words_bound_their_emission`). pub fn words(self) -> u32 { match self { Routine::Plane => 9216, Routine::Line => 3712, - Routine::Quad => 5184, - Routine::Span => 3968, + Routine::Quad => 5440, + Routine::Span => 4224, Routine::Block => BLOCK_WORDS, Routine::Cube => CUBE_WORDS, Routine::Levels => LEVELS_WORDS, - Routine::QuadSteps => 5184, + Routine::QuadSteps => 5440, } } @@ -504,7 +504,7 @@ pub fn define_block(mb: &mut ModuleBuilder) -> BResult { } /// [`Routine::words`] of [`Routine::Block`]. -const BLOCK_WORDS: u32 = 8064; +const BLOCK_WORDS: u32 = 8320; /// A linear cube sample's routines, beside [`Quad`]'s sums of the four taps. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -1409,7 +1409,7 @@ fn packed_grids( let these_d = lanes(fb, grids)?; let these_s = lanes(fb, scales)?; let these_per = lanes(fb, steps)?; - let these_cut = lanes(fb, [cut; 4])?; + let these_cut = lanes(fb, cut)?; d = fb.select(is, these_d, d)?; s = fb.select(is, these_s, s)?; per = fb.select(is, these_per, per)?; @@ -1418,7 +1418,7 @@ fn packed_grids( if p.filter_extended() { wide = bin(fb, BinOp::LogicalOr, wide, is)?; } - if p.ycbcr() { + if p.ties_away() { away = bin(fb, BinOp::LogicalOr, away, is)?; } } diff --git a/crates/metal2vulkan/src/lower/sampler/extended.rs b/crates/metal2vulkan/src/lower/sampler/extended.rs index c4429c39d..d83e5ba25 100644 --- a/crates/metal2vulkan/src/lower/sampler/extended.rs +++ b/crates/metal2vulkan/src/lower/sampler/extended.rs @@ -1625,6 +1625,10 @@ pub(super) fn flags(form: ExtendedRange) -> u32 { // linear filter of it (an Apple M4 and an Apple M3 Max, byte-identical); `RG10Unorm_X12_sRGB`'s // reads and filter are `RG10Unorm_X12`'s. let padded_srgb = BicubicTexels::UNORM | PackedTexels::YCbCr8192.class().0; + // `RGB10A2Unorm_sRGB`'s color channels sum as `R10Unorm_X6_sRGB`'s red, its alpha on the grid + // `16 · 255` ([`PackedTexels::Rgb10A2Srgb`]; an Apple M3 Max, every channel of 4,096 2D + // samples, `float` and `half` results). + let rgb10a2_srgb = BicubicTexels::UNORM | PackedTexels::Rgb10A2Srgb.class().0; let (pf, channels, family) = match form { ExtendedRange::Bgr10 { srgb: false } => (PixelFormat::BGR10XR, 0b0111, extended), ExtendedRange::Bgr10 { srgb: true } => (PixelFormat::BGR10XRSRGB, 0b0111, extended), @@ -1636,6 +1640,7 @@ pub(super) fn flags(form: ExtendedRange) -> u32 { ExtendedRange::Rg10X12 => (PixelFormat::RG10UnormX12, 0b0011, padded), ExtendedRange::R10X6Srgb => (PixelFormat::R10UnormX6SRGB, 0b0001, padded_srgb), ExtendedRange::Rg10X12Srgb => (PixelFormat::RG10UnormX12SRGB, 0b0011, padded), + ExtendedRange::Rgb10A2Srgb => (PixelFormat::RGB10A2UnormSRGB, 0b1111, rgb10a2_srgb), // A bfloat form's samples and gathers read its texels unfiltered: its bits name its // channels and border texels alone. ExtendedRange::R16Bfloat => (PixelFormat::R16Bfloat, 0b0001, 0), @@ -1670,5 +1675,15 @@ mod tests { assert_ne!(f & BicubicTexels::EXTENDED, 0); assert_eq!(f & BicubicTexels::SRGB != 0, srgb); } + // `RGB10A2Unorm_sRGB` has four channels, and its own packed field. + assert_eq!(border(ExtendedRange::Rgb10A2Srgb), four); + let field = flags(ExtendedRange::Rgb10A2Srgb) + & crate::metal::texel_format::TexelFormat::PACKED_MASK; + assert_eq!( + field, + crate::metal::texel_format::PackedTexels::Rgb10A2Srgb + .class() + .0 + ); } } diff --git a/crates/metal2vulkan/src/lower/texture/half.rs b/crates/metal2vulkan/src/lower/texture/half.rs index 2062d4695..47e7ec85c 100644 --- a/crates/metal2vulkan/src/lower/texture/half.rs +++ b/crates/metal2vulkan/src/lower/texture/half.rs @@ -288,7 +288,8 @@ struct PackedField { coded: SValue, /// Whether the field is `PackedTexels::SmallFloat`. small: SValue, - /// Whether the field is a two-plane YCbCr format's (`PackedTexels::ycbcr`). + /// Whether the field's one texel rounds with ties away from zero, a two-plane YCbCr format's + /// or `RGB10A2Unorm_sRGB`'s (`PackedTexels::ties_away`). ycbcr: SValue, /// Whether the lanes are a gather's, each its channel's (`channel` below 4). gathered: SValue, @@ -314,12 +315,12 @@ impl PackedField { let mut ycbcr = coded; let mut fields = Vec::with_capacity(PackedTexels::ALL.len()); for p in PackedTexels::ALL { - if !p.ycbcr() && p.scales().is_none() { + if !p.ties_away() && p.scales().is_none() { continue; } let k = u1(fb, p as u32)?; let is = fb.binary(BinOp::IEqual, field, k)?; - if p.ycbcr() { + if p.ties_away() { ycbcr = fb.binary(BinOp::LogicalOr, ycbcr, is)?; } let Some(s) = p.scales() else { diff --git a/crates/metal2vulkan/src/metal/format/mod.rs b/crates/metal2vulkan/src/metal/format/mod.rs index c8a23c09c..65b5977f3 100644 --- a/crates/metal2vulkan/src/metal/format/mod.rs +++ b/crates/metal2vulkan/src/metal/format/mod.rs @@ -334,6 +334,17 @@ pub enum ExtendedRange { /// are `RG10Unorm_X12`'s, `c / 1023`; a write stores, for the code `m` `RG10Unorm_X12` writes, /// Metal's code of `m` (a measured table of 1024 codes up to 137). Rg10X12Srgb, + /// `RGB10A2Unorm_sRGB` (586): `RGB10A2Unorm`'s little-endian word, red in bits 0-9, green + /// 10-19, blue 20-29 and alpha 30-31, held as `R32_UINT`. Measured on an Apple M3 Max under + /// macOS 27.0.1, which makes it in every storage mode and usage: each color channel's code + /// converts as `R10Unorm_X6_sRGB`'s (its tables, every code read and 16,385 values written; + /// a `half` read with ties away from zero), and alpha's 2-bit code `a` reads `a / 3` + /// correctly rounded and a write stores the exact product of the value, clamped to `[0, 1]` + /// (a NaN 0), with 3, rounded to nearest. A render pass's store rounds a `float` output to + /// `half` toward zero first, a clear goes through `half` (nearest even), and a pass that loads + /// it and draws elsewhere writes each color code back as `R10Unorm_X6_sRGB`'s + /// ([`load_code`](Self::load_code)), alpha kept. + Rgb10A2Srgb, /// `R16Bfloat` (26): a bfloat code (the top 16 bits of an IEEE `float`) in a little-endian /// 16-bit word, held as `R16_UINT` ([`FormatEmulation::Bfloat`]). Measured on an Apple M4 /// under macOS 27.0.1, every code of each bfloat format: a read (`read` and `read_write`, a @@ -369,6 +380,7 @@ impl ExtendedRange { PixelFormat::RG10UnormX12 => Some(ExtendedRange::Rg10X12), PixelFormat::R10UnormX6SRGB => Some(ExtendedRange::R10X6Srgb), PixelFormat::RG10UnormX12SRGB => Some(ExtendedRange::Rg10X12Srgb), + PixelFormat::RGB10A2UnormSRGB => Some(ExtendedRange::Rgb10A2Srgb), PixelFormat::R16Bfloat => Some(ExtendedRange::R16Bfloat), PixelFormat::RG16Bfloat => Some(ExtendedRange::Rg16Bfloat), PixelFormat::RGBA16Bfloat => Some(ExtendedRange::Rgba16Bfloat), @@ -379,7 +391,7 @@ impl ExtendedRange { /// The unsigned integer format of the texels' bytes, which holds them. pub fn raw_format(self) -> vk::Format { match self { - ExtendedRange::Bgr10 { .. } => vk::Format::R32_UINT, + ExtendedRange::Bgr10 { .. } | ExtendedRange::Rgb10A2Srgb => vk::Format::R32_UINT, ExtendedRange::Bgra10 { .. } => vk::Format::R16G16B16A16_UINT, ExtendedRange::Planes { .. } => vk::Format::R32G32_UINT, ExtendedRange::R10X6 | ExtendedRange::R10X6Srgb => vk::Format::R16_UINT, @@ -402,6 +414,7 @@ impl ExtendedRange { | ExtendedRange::Rg10X12 | ExtendedRange::R10X6Srgb | ExtendedRange::Rg10X12Srgb + | ExtendedRange::Rgb10A2Srgb | ExtendedRange::R16Bfloat | ExtendedRange::Rg16Bfloat | ExtendedRange::Rgba16Bfloat => false, @@ -418,14 +431,19 @@ impl ExtendedRange { } /// Whether the codes convert through the padded `_sRGB` formats' tables - /// (`R10Unorm_X6_sRGB`, `RG10Unorm_X12_sRGB`; `lower::arith::extended_range::declare_padded`). + /// (`R10Unorm_X6_sRGB`, `RG10Unorm_X12_sRGB`, and `RGB10A2Unorm_sRGB`'s color channels + /// through `R10Unorm_X6_sRGB`'s; `lower::arith::extended_range::declare_padded`). pub fn padded_srgb(self) -> bool { - matches!(self, ExtendedRange::R10X6Srgb | ExtendedRange::Rg10X12Srgb) + matches!( + self, + ExtendedRange::R10X6Srgb | ExtendedRange::Rg10X12Srgb | ExtendedRange::Rgb10A2Srgb + ) } - /// Whether the codes are the padded 10-bit unsigned normalized ones (`R10Unorm_X6`, - /// `RG10Unorm_X12` and their `_sRGB` twins), each in a 16-bit word's top 10 bits, rather - /// than Apple's extended-range `(c - 384) / 510`. + /// Whether the codes are 10-bit unsigned normalized ones rather than Apple's extended-range + /// `(c - 384) / 510`: the padded formats' (`R10Unorm_X6`, `RG10Unorm_X12` and their `_sRGB` + /// twins), each in a 16-bit word's top 10 bits, and `RGB10A2Unorm_sRGB`'s packed fields + /// ([`Rgb10A2Srgb`](Self::Rgb10A2Srgb), its alpha a 2-bit code). pub fn padded(self) -> bool { matches!( self, @@ -433,6 +451,7 @@ impl ExtendedRange { | ExtendedRange::Rg10X12 | ExtendedRange::R10X6Srgb | ExtendedRange::Rg10X12Srgb + | ExtendedRange::Rgb10A2Srgb ) } @@ -484,7 +503,9 @@ impl ExtendedRange { let rgb = M::RED.union(M::GREEN).union(M::BLUE); match self { ExtendedRange::Bgr10 { .. } => rgb, - ExtendedRange::Bgra10 { .. } | ExtendedRange::Planes { .. } => rgb.union(M::ALPHA), + ExtendedRange::Bgra10 { .. } + | ExtendedRange::Planes { .. } + | ExtendedRange::Rgb10A2Srgb => rgb.union(M::ALPHA), ExtendedRange::R10X6 | ExtendedRange::R10X6Srgb => M::RED, ExtendedRange::Rg10X12 | ExtendedRange::Rg10X12Srgb => M::RED.union(M::GREEN), ExtendedRange::R16Bfloat => M::RED, @@ -497,7 +518,10 @@ impl ExtendedRange { /// word, the two-plane formats' color word and alpha byte, `BGRA10_XR`'s four fields. pub fn raw_components(self) -> u32 { match self { - ExtendedRange::Bgr10 { .. } | ExtendedRange::R10X6 | ExtendedRange::R10X6Srgb => 1, + ExtendedRange::Bgr10 { .. } + | ExtendedRange::R10X6 + | ExtendedRange::R10X6Srgb + | ExtendedRange::Rgb10A2Srgb => 1, ExtendedRange::Planes { .. } | ExtendedRange::Rg10X12 | ExtendedRange::Rg10X12Srgb => 2, ExtendedRange::Bgra10 { .. } => 4, ExtendedRange::R16Bfloat => 1, @@ -632,12 +656,14 @@ impl ExtendedRange { let v = if v.is_nan() { 0.0 } else { v }; // A padded format's code: the exact product of the value clamped to [0, 1] with 1023, // rounded to nearest even (its one tie, 0.5, stores 512); an `_sRGB` - // twin's through Metal's tables. + // twin's through Metal's tables. `RGB10A2Unorm_sRGB`'s alpha: the product with 3, never a + // tie. if self.padded() { let v = f64::from(v.clamp(0.0, 1.0)); let linear = (v * 1023.0).round_ties_even() as usize; return match self { - ExtendedRange::R10X6Srgb => { + ExtendedRange::Rgb10A2Srgb if alpha => (v * 3.0).round_ties_even() as u32, + ExtendedRange::R10X6Srgb | ExtendedRange::Rgb10A2Srgb => { // `v` times 2^13 is exact. let i = (v * 8192.0).round_ties_even() as u16; let first = &padded_srgb::R10X6_SRGB_ENCODE_FIRST; @@ -689,6 +715,12 @@ impl ExtendedRange { } // Each code in its word's top 10 bits, the low 6 bits zero. ExtendedRange::R10X6 | ExtendedRange::R10X6Srgb => [rgba[0] << 6, 0, 0, 0], + ExtendedRange::Rgb10A2Srgb => [ + rgba[3] << 30 | rgba[2] << 20 | rgba[1] << 10 | rgba[0], + 0, + 0, + 0, + ], ExtendedRange::Rg10X12 | ExtendedRange::Rg10X12Srgb => { [rgba[0] << 6, rgba[1] << 6, 0, 0] } @@ -703,7 +735,9 @@ impl ExtendedRange { /// draws, where no draw writes it: Metal's pass reads the word and writes it back, its /// decoded value encoded again (an Apple M4 and an Apple M3 Max, byte-identical). `c` itself /// for `R10Unorm_X6` and `RG10Unorm_X12`; `R10Unorm_X6_sRGB`'s write of its read, which moves - /// the 23 codes no write stores; `RG10Unorm_X12_sRGB`'s write code of `c`. A bfloat form's code + /// the 23 codes no write stores, and so does each color channel's code of `RGB10A2Unorm_sRGB` + /// (an Apple M3 Max under macOS 27.0.1, every code; its alpha's code stays); + /// `RG10Unorm_X12_sRGB`'s write code of `c`. A bfloat form's code /// `c` (each channel's 16-bit word) holds the code a `Clear` of its value stores under /// [`ClearRoute::ThroughHalf`] ([`clear_texel`](Self::clear_texel)): the `float` of its bits /// rounded to `half` to nearest even (past the largest `half`, the infinity), then the bfloat @@ -720,7 +754,7 @@ impl ExtendedRange { let at = usize::try_from(c).ok().filter(|&c| c < 1024)?; match self { ExtendedRange::R10X6 | ExtendedRange::Rg10X12 => Some(c), - ExtendedRange::R10X6Srgb => { + ExtendedRange::R10X6Srgb | ExtendedRange::Rgb10A2Srgb => { let step = padded_srgb::R10X6_SRGB_DECODE_STEPS[at]; let first = &padded_srgb::R10X6_SRGB_ENCODE_FIRST; Some(first.partition_point(|&f| f <= step).saturating_sub(1) as u32) @@ -1103,7 +1137,6 @@ macro_rules! formats_named_not_held { | PixelFormat::YCBCRA84441P | PixelFormat::YCBCR84221PREV | PixelFormat::YCBCR104441PPQ - | PixelFormat::RGB10A2UnormSRGB | PixelFormat::RGB10A2UnormPQ | PixelFormat::R10UnormPACKED | PixelFormat::RG10UnormPACKED @@ -1429,6 +1462,9 @@ fn make_repr(pf: PixelFormat) -> Repr { P::RG10UnormX12 | P::RG10UnormX12SRGB => { color(vec![combined(F::R16G16_UINT, E::ExtendedRange)]) } + // `RGB10A2Unorm`'s word, its color codes sRGB-encoded by Metal's own tables, which no + // Vulkan format has: held raw ([`ExtendedRange::Rgb10A2Srgb`]). + P::RGB10A2UnormSRGB => color(vec![combined(F::R32_UINT, E::ExtendedRange)]), // The bfloat formats: each code held raw in the integer format of its words. P::R16Bfloat => color(vec![combined(F::R16_UINT, E::Bfloat)]), P::RG16Bfloat => color(vec![combined(F::R16G16_UINT, E::Bfloat)]), @@ -2164,6 +2200,7 @@ pub(crate) fn color_output_components(pf: PixelFormat) -> Option { | P::BGRA10XRSRGB | P::RGB10A82PXR10 | P::RGB10A82PXR10SRGB + | P::RGB10A2UnormSRGB | P::RGBA16Bfloat | P::RGBA32Uint | P::RGBA32Sint @@ -2396,6 +2433,7 @@ pub(crate) fn out_of_bounds_alpha_one(pf: PixelFormat) -> Option { | P::ARGB8Unorm | P::RGB10A82PXR10 | P::RGB10A82PXR10SRGB + | P::RGB10A2UnormSRGB | P::RGBA32Uint | P::RGBA32Sint | P::RGBA32Float diff --git a/crates/metal2vulkan/src/metal/format/tests.rs b/crates/metal2vulkan/src/metal/format/tests.rs index 5dcdc78ee..232a844c0 100644 --- a/crates/metal2vulkan/src/metal/format/tests.rs +++ b/crates/metal2vulkan/src/metal/format/tests.rs @@ -87,7 +87,8 @@ fn refused_formats_are_exactly_the_documented_set() { // - their `_sRGB` twins, held raw. // - the eleven RGBX formats, held in their RGBA twins. // - the three bfloat formats, held raw. - assert_eq!(count("not_implemented"), 45 + 3 + 6 + 62, "{refused:?}"); + // - `RGB10A2Unorm_sRGB`, held raw. + assert_eq!(count("not_implemented"), 45 + 3 + 6 + 61, "{refused:?}"); assert!(refused["not_implemented"].iter().all(|&pf| { (ycbcr_format(pf).is_some() && !ycbcr(pf)) || matches!(pf, P::RGBA16FloatXR | P::AnyDepth | P::AnyStencil) @@ -1107,20 +1108,21 @@ fn formats_metal_names_are_named_and_refused_typed() { // All but `R10Unorm_X6`, `RG10Unorm_X12` and their `_sRGB` twins, held raw // (`padded_only_over_memory`). // And the eleven RGBX formats, held in their RGBA twins (`x_channel`). - // And the three bfloat formats, held raw (`ExtendedRange::bfloat`). + // And the three bfloat formats and `RGB10A2Unorm_sRGB`, held raw (`ExtendedRange`). let bfloat = |pf| ExtendedRange::of(pf).is_some_and(ExtendedRange::bfloat); + let rgb10a2_srgb = |pf| ExtendedRange::of(pf) == Some(ExtendedRange::Rgb10A2Srgb); assert_eq!( PixelFormat::ALL .iter() .filter(|&&pf| matches!(pf, formats_named_not_held!())) .count(), - named.len() - 4 - 11 - 3 + named.len() - 4 - 11 - 3 - 1 ); for (raw, name) in named { let pf = PixelFormat::try_from(raw).unwrap_or_else(|e| panic!("{raw}: {e}")); assert_eq!(pf.name(), name); assert_eq!(PixelFormat::from_name(name), Some(pf)); - if padded_only_over_memory(pf) || x_channel(pf) || bfloat(pf) { + if padded_only_over_memory(pf) || x_channel(pf) || bfloat(pf) || rgb10a2_srgb(pf) { continue; } assert!(matches!(pf, formats_named_not_held!()), "{name}"); diff --git a/crates/metal2vulkan/src/metal/texel_format.rs b/crates/metal2vulkan/src/metal/texel_format.rs index c15630432..3cbff684e 100644 --- a/crates/metal2vulkan/src/metal/texel_format.rs +++ b/crates/metal2vulkan/src/metal/texel_format.rs @@ -196,9 +196,9 @@ impl TexelFormat { /// The [`PACKED`](Self::PACKED) field's mask, in place. pub const PACKED_MASK: u32 = 0xF << TexelFormat::PACKED; - /// The [`PACKED`](Self::PACKED) field's top bit, set in exactly the fields of the YCbCr grid - /// `8192` ([`PackedTexels::YCbCr8192`] and [`PackedTexels::YCbCrExtended8192`]), whose one - /// texel's `half` rounds with ties away from zero: what the `half` routine of a device that + /// The [`PACKED`](Self::PACKED) field's top bit, set in exactly the fields of the grid `8192` + /// ([`PackedTexels::YCbCr8192`], [`PackedTexels::YCbCrExtended8192`] and + /// [`PackedTexels::Rgb10A2Srgb`]), whose one texel's `half` rounds with ties away from zero: what the `half` routine of a device that /// samples through Metal's own texture unit reads of the field (`lower::texture::half`), so /// that every other field's class specializes as a slot bound to nothing does. pub const YCBCR_8192: u32 = 8 << TexelFormat::PACKED; @@ -430,11 +430,19 @@ pub enum PackedTexels { /// [`YCbCr8192`](Self::YCbCr8192)'s, the steps and the sums signed /// ([`filter_extended`](Self::filter_extended)). YCbCrExtended8192 = 9, + /// `RGB10A2Unorm_sRGB`'s channels as the function decodes its held word + /// (`ExtendedRange::Rgb10A2Srgb`): red, green and blue steps `k / 8192` of `[0, 1]`, which + /// Metal's linear filter sums as [`YCbCr8192`](Self::YCbCr8192)'s, and alpha's 2-bit code + /// `a` read `a / 3`, which it sums on the grid `16 · 255` (the code `1360 a`), each 2D term + /// truncated by `2^4`; a `half` result's color steps rounded with ties away from zero (an + /// Apple M3 Max under macOS 27.0.1: every channel of 4,096 2D samples of a 16 x 16 texture, + /// `float` and `half` results). Its filter of more than one level is not measured. + Rgb10A2Srgb = 10, } impl PackedTexels { /// Every value, in field order. - pub const ALL: [PackedTexels; 9] = [ + pub const ALL: [PackedTexels; 10] = [ PackedTexels::Rgb565, PackedTexels::Rgb5A1, PackedTexels::Rgba4, @@ -444,6 +452,7 @@ impl PackedTexels { PackedTexels::YCbCr2048, PackedTexels::YCbCr8192, PackedTexels::YCbCrExtended8192, + PackedTexels::Rgb10A2Srgb, ]; /// The packed channels of `pf`, where Metal's reads of them are measured, a two-plane YCbCr @@ -492,8 +501,8 @@ impl PackedTexels { } /// Each channel's code scale `2^b - 1`, red to alpha (an absent alpha's 1, which its value - /// 1 recovers), or `None` where the device's value is Metal's exactly: the small floats and - /// the YCbCr fields. + /// 1 recovers), or `None` where the device's value is Metal's exactly: the small floats, the + /// YCbCr fields and `RGB10A2Unorm_sRGB`'s, whose function decodes Metal's values itself. pub fn scales(self) -> Option<[u32; 4]> { Some(match self { PackedTexels::Rgb565 => [31, 63, 31, 1], @@ -504,7 +513,8 @@ impl PackedTexels { PackedTexels::SmallFloat | PackedTexels::YCbCr2048 | PackedTexels::YCbCr8192 - | PackedTexels::YCbCrExtended8192 => return None, + | PackedTexels::YCbCrExtended8192 + | PackedTexels::Rgb10A2Srgb => return None, }) } @@ -530,6 +540,7 @@ impl PackedTexels { PackedTexels::Rgba4 => [G8; 4], PackedTexels::YCbCr2048 => [2048; 4], PackedTexels::YCbCr8192 | PackedTexels::YCbCrExtended8192 => [8192; 4], + PackedTexels::Rgb10A2Srgb => [8192, 8192, 8192, G8], PackedTexels::SmallFloat | PackedTexels::Argb8 => return None, }) } @@ -538,14 +549,24 @@ impl PackedTexels { /// [`filter_grids`](Self::filter_grids) names the grids: the term of a code `c` on its grid /// under the weight `w` (in units of `2^-16`) is `⌊c · w / 2^s⌋`, and the sum's grid step /// `⌊(T + 2^(15 - s)) / 2^(16 - s)⌋` (module docs). 4 for a packed normalized format's 12-bit - /// grids, as for an 8-bit format's, and 7 for the YCbCr fields', measured on their 2D samples. - pub fn filter_truncation(self) -> Option { - self.filter_grids().map(|_| match self.ycbcr() { - true => 7, - false => 4, + /// grids, as for an 8-bit format's, and 7 for the YCbCr fields', measured on their 2D samples; + /// `RGB10A2Unorm_sRGB`'s 7 for its color channels and 4 for alpha. Red to alpha. + pub fn filter_truncation(self) -> Option<[u32; 4]> { + self.filter_grids().map(|_| match self { + PackedTexels::Rgb10A2Srgb => [7, 7, 7, 4], + _ if self.ycbcr() => [7; 4], + _ => [4; 4], }) } + /// Whether a `half` result of the field's one texel or linear filter rounds with ties away + /// from zero: the two-plane YCbCr fields' ([`ycbcr`](Self::ycbcr)) and + /// `RGB10A2Unorm_sRGB`'s, whose color steps lie on the grid `8192` (its alpha's values are + /// never a tie). + pub fn ties_away(self) -> bool { + self.ycbcr() || self == PackedTexels::Rgb10A2Srgb + } + /// Whether the field is a two-plane YCbCr format's: its view holds Metal's reads exactly, and a /// `half` result of its linear filter is the step's value rounded with ties away from zero (on /// the grid `8192`, where a step's value may lie between two halves; the grid `2048`'s are @@ -1391,7 +1412,13 @@ mod tests { p.filter_grids().is_some(), "{p:?}" ); - assert!(seen.contains(&(p as u32)), "{p:?} has no format"); + // `RGB10A2Unorm_sRGB`'s field is its extended-range form's class's + // (`lower::sampler::extended`), which no format's own class takes. + let extended = p == PackedTexels::Rgb10A2Srgb; + assert!( + seen.contains(&(p as u32)) || extended, + "{p:?} has no format" + ); } // A swizzle drops the field, and a packed normalized format's family with it. for (pf, alone) in [ @@ -1585,8 +1612,8 @@ mod tests { /// texture unit reads (`lower::texture::half`). const READ_ON_METAL_SAMPLER: u32 = T::LINEAR | T::SNORM | T::WIDE16 | TexelFormat::YCBCR_8192; - /// [`TexelFormat::YCBCR_8192`] is set in exactly the fields of the YCbCr grid `8192`, the - /// packed fields whose one texel's `half` rounds with ties away from zero. + /// [`TexelFormat::YCBCR_8192`] is set in exactly the fields of the grid `8192`, the packed + /// fields whose one texel's `half` rounds with ties away from zero. #[test] fn the_ycbcr_8192_bit_names_exactly_the_grid_8192_fields() { for p in PackedTexels::ALL { @@ -1594,7 +1621,17 @@ mod tests { assert_eq!(field & TexelFormat::PACKED_MASK, field, "{p:?}"); assert_eq!( field & TexelFormat::YCBCR_8192 != 0, - matches!(p, PackedTexels::YCbCr8192 | PackedTexels::YCbCrExtended8192), + matches!( + p, + PackedTexels::YCbCr8192 + | PackedTexels::YCbCrExtended8192 + | PackedTexels::Rgb10A2Srgb + ), + "{p:?}" + ); + assert_eq!( + field & TexelFormat::YCBCR_8192 != 0, + p.ties_away() && p != PackedTexels::YCbCr2048, "{p:?}" ); } diff --git a/crates/metal2vulkan/src/pipeline/link/graphics.rs b/crates/metal2vulkan/src/pipeline/link/graphics.rs index 7b3ed36da..a5ac9cb56 100644 --- a/crates/metal2vulkan/src/pipeline/link/graphics.rs +++ b/crates/metal2vulkan/src/pipeline/link/graphics.rs @@ -1089,7 +1089,8 @@ fn extended_write_mask( if kept.is_empty() { return Ok(C::empty()); } - if form.padded() { + // `RGB10A2Unorm_sRGB`'s channels share one word: a mask of some of them is refused as above. + if form.padded() && form.raw_components() == channels.as_raw().count_ones() { return Ok(kept); } if kept != channels { diff --git a/crates/metal2vulkan/src/tests/engine_extended_range/samples.rs b/crates/metal2vulkan/src/tests/engine_extended_range/samples.rs index 5db5677ef..f82492fc0 100644 --- a/crates/metal2vulkan/src/tests/engine_extended_range/samples.rs +++ b/crates/metal2vulkan/src/tests/engine_extended_range/samples.rs @@ -70,6 +70,7 @@ pub(super) fn raw_of(form: ExtendedRange, [r, g, b, a]: [u32; 4]) -> [u32; 4] { ExtendedRange::R16Bfloat => [r, 0, 0, 1], ExtendedRange::Rg16Bfloat => [r, g, 0, 1], ExtendedRange::Rgba16Bfloat => [r, g, b, a], + ExtendedRange::Rgb10A2Srgb => [a << 30 | b << 20 | g << 10 | r, 0, 0, 1], } } diff --git a/docs/API.md b/docs/API.md index cb775e37d..72b1f15a7 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1789,10 +1789,10 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound. and those an earlier blit left in a row's padding or past a plane, which Metal keeps. - `metal2vulkan-degrade-extended-range-bits-kept` (precision). `ExtendedRangeBitsKept`: A draw in a render pass that loads a color attachment of an extended-range or padded 10-bit format - (`BGR10_XR`, `BGRA10_XR`, `RGB10A8_2P_XR10`, `R10Unorm_X6`, `RG10Unorm_X12` and their sRGB twins) - and does not discard it at the store, where the pass's load pass does not take it: a multisampled - attachment, a texture held as a shadow of another image or of a heap's bytes, a sparse one, or one - whose image the device does not copy both ways (a padded format has none of these). Cost: the + (`BGR10_XR`, `BGRA10_XR`, `RGB10A8_2P_XR10`, `R10Unorm_X6`, `RG10Unorm_X12` and their sRGB twins, + and `RGB10A2Unorm_sRGB`) and does not discard it at the store, where the pass's load pass does + not take it: a multisampled attachment, a texture held as a shadow of another image or of a + heap's bytes, a sparse one, or one whose image the device does not copy both ways (a padded format has none of these). Cost: the texels the pass's draws do not write keep their bytes; Metal's pass keeps their codes but rewrites the bits they leave unused in each tile a draw reaches (BGR10_XR's bits 30 and 31 to ones, BGRA10_XR's low six bits of each field to zeros, the two-plane color word's top two bits to zeros) @@ -1816,14 +1816,30 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound. (`DriverFact::TileStoreIsMetals`), nor under `TileStorePolicy::Exact` for an attachment the load pass rewrites as Metal's store leaves it. - `metal2vulkan-degrade-two-plane-buffer-blit` (precision). `TwoPlaneBufferBlit`: A blit between a - buffer and a level of `RGB10A8_2P_XR10` or its sRGB twin whose width is not a multiple of 4: it - moves the texels at the rows the texture holds them in, where Metal's blit addresses the level's - rows `⌊4 w / 16⌋ · 16` bytes apart, short of its rows, and so moves texels into and out of other - rows (into the texture overlapping rows, in an order that varies). Cost: the texels move between - the buffer's rows and the texture's as getBytes and replaceRegion move them; Metal's blit - addresses the texture's rows floor(4w/16)*16 bytes apart where they lie align(4w,16) bytes apart, - so out of the texture it reads texels of earlier rows and padding (0) into later rows of the - buffer, and into it writes rows over each other in an order that varies. + buffer and a level of `RGB10A8_2P_XR10` or its sRGB twin whose width is not a multiple of 4, + where Metal's blit addresses the level's rows `⌊4 w / 16⌋ · 16` bytes apart, short of where they + lie, and so moves texels into and out of other rows and the bytes between them. A 2D texture or + array of one level is blitted at Metal's rows, the row whose bytes Metal's GPU leaves where two + meet standing, the bytes between its rows that its fills and blits with a buffer write held + apart; announced there are a blit into a texture 32 texels wide or wider whose rows meet (narrower, + `two-plane-buffer-blit-order`), and a blit out of a texture of the device's memory that reads bytes + between its rows after a copy from another texture wrote some there. Any other such texture (more + levels, a view, 1D, 3D, a surface's) moves the texels at the rows the texture holds them in. Cost: + where rows meet in a blit into a texture 32 texels wide or wider the earlier row's bytes stand, + where Metal's GPU writes them in an order that varies from run to run, at some sizes never all the + earlier row's; a blit out of a texture of the device's memory reads the bytes + between its rows that a copy from another texture wrote as its fills and blits with a buffer + left them, where Metal's reads the copy's back; and a texture of more than one + level, a view, a 1D or 3D texture or a surface's moves its texels at the rows it holds them in, + where Metal's blit addresses its rows floor(4w/16)*16 bytes apart. +- `metal2vulkan-degrade-two-plane-buffer-blit-order` (precision). `TwoPlaneBufferBlitOrder`: A blit + from a buffer into a level of `RGB10A8_2P_XR10` or its sRGB twin narrower than 32 texels, at a + width not a multiple of 4, whose rows meet between Metal's groups of 32 rows of the region: + Metal's GPU writes the two rows there in an order that varies from run to run (the earlier row's + bytes at 556 of 560 such meetings in our probes), and in its fixed order at every other meeting. + The runtime keeps the earlier row's bytes there and Metal's order elsewhere: Metal's most frequent + whole outcome. Cost: where the rows of two of Metal's groups of 32 meet the earlier row's bytes + stand, where Metal's GPU leaves either row's from run to run. - `metal2vulkan-degrade-unadvertised-vertex-simdgroups` (validity). `UnadvertisedVertexSimdgroups`: A render pipeline state whose vertex function runs simdgroup functions on a driver measured to run a vertex function's subgroup operations as Metal does though its `subgroupSupportedStages` leaves @@ -1902,7 +1918,8 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound. and never makes one the older release stops. - `metal2vulkan-degrade-unreached-tiles-rewritten` (precision). `UnreachedTilesRewritten`: A render pass that loads a color attachment of an extended-range or padded 10-bit format (`BGR10_XR`, - `BGRA10_XR`, `RGB10A8_2P_XR10`, `R10Unorm_X6`, `RG10Unorm_X12` and their sRGB twins), or under + `BGRA10_XR`, `RGB10A8_2P_XR10`, `R10Unorm_X6`, `RG10Unorm_X12` and their sRGB twins, and + `RGB10A2Unorm_sRGB`), or under `TileStorePolicy::Exact` of a signed normalized format or `RGB9E5Float`, stores it and draws, whose load pass rewrites every 32 x 32 tile of its render area: Metal's pass rewrites only the tiles a draw's primitives reach, and every tile only where a color attachment of the pass @@ -2228,9 +2245,20 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound. device reports maps to them. Cost: the device gives no answer for them (`PrivateAnswer::value` is `None`); Metal's measured answers on Apple's GPUs ride beside, never as this device's. - `metal2vulkan-degrade-unpacked-fill-color` (precision). `UnpackedFillColor`: A color fill - (`BlitCommandEncoder::fill_texture_color`) whose color is packed in a format whose fills do not - follow the color: compressed, 4:2:2, depth, stencil, two-plane or padded 10-bit. Cost: every unit - of the region holds zero bytes, whatever the color, where Metal's constant is its own process's. + (`BlitCommandEncoder::fill_texture_color`) whose color is packed in a format Metal packs no color + in: compressed, 4:2:2, depth, stencil, two-plane, YCbCr, padded 10-bit, `Invalid` or a private + format. Metal fills bytes of the calling thread's stack there, which hold the last color fill's + packed texel only where no other call used them since. Cost: every unit of the region holds the + command buffer's last packed texel over zeros, whatever the color, where Metal's bytes are its + stack's. +- `metal2vulkan-degrade-texture-buffer-fill-leftover` (precision). `TextureBufferFillLeftover`: A + fill of a texture buffer (`BlitCommandEncoder::fill_texture`, + `BlitCommandEncoder::fill_texture_color`) whose 16-byte chunks read bytes of its block past the + pattern's whole copies, or past the block: most patterns whose length is not a power of two, and + most regions whose first byte is not at a multiple of 16 of the buffer. Metal reads bytes of the + calling thread's stack there: zeros in our probes, an earlier fill's bytes in the consumer's + process. The runtime writes zeros there. Cost: those bytes of each chunk are zeros, where Metal's + are its stack's. - `metal2vulkan-degrade-unsized-points` (precision). `UnsizedPoints`: A draw of points that rasterizes, of some vertices and instances, under a render pipeline state whose vertex function writes no `[[point_size]]` and whose input primitive topology class is not the point class: a diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index e90f147c9..d66a04d1b 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -14,7 +14,7 @@ Columns: - `none`: no public API path: malformed or non-Metal input, Apple-private calls, or a cap no valid program of ordinary size meets; - `?`: not assessed yet. -Generated at `ce4b23e12`. +Generated at `6b9a3b33d`. ## Totals @@ -22,7 +22,7 @@ Generated at `ce4b23e12`. |---|---|---|---|---|---|---|---| | Translator and front-end refusals | 125 | 125 | 6 | 33 | 68 | 18 | 0 | | Runtime gaps | 68 | 68 | 1 | 8 | 41 | 18 | 0 | -| Apple-only calls | 9 | 9 | 1 | 0 | 0 | 8 | 0 | +| Apple-only calls | 8 | 8 | 0 | 0 | 0 | 8 | 0 | | Binder refusals at a device limit | 9 | 9 | 0 | 1 | 7 | 1 | 0 | | Translation caps | 14 | 14 | 0 | 0 | 7 | 7 | 0 | | Rate maps the compile layer does not compile | 5 | 5 | 0 | 0 | 4 | 1 | 0 | @@ -53,8 +53,8 @@ Generated at `ce4b23e12`. | `QuadOperations` | Quad operations in a stage without quad support | devices without VkLimit::MinSubgroupSize; devices without VkProperty::SubgroupQuadOperationsInAllStages | 2: `crates/metal2vulkan/src/device/subgroup.rs:371`, `crates/metal2vulkan/src/device/subgroup.rs:405` | `app`: quad shuffles in kernels on devices without quad operations there | | `SimdgroupMatrix` | Simdgroup matrix operations | every device (not implemented) | 1: `crates/metal2vulkan/src/lower/simd/matrix.rs:83` | `rare`: simdgroup matrix kernels | | `ArgumentBufferPointers` | Argument buffers holding buffer pointers (dynamic roots) | devices without buffer device addresses (`addressed_needs`) | 1: `crates/metal2vulkan/src/device/metal.rs:236` | `app`: argument buffers holding buffer pointers | -| `ArgumentBufferTextures` | Argument buffers holding textures or samplers (handle domain) | devices short of a device limit the site names; devices without a capability the site computes (`gaps`); devices without a capability the site computes (`missing`); devices without a capability the site computes (`needs`); every device (not implemented) | 17: `crates/metal2vulkan-runtime/src/families/features.rs:1621`, `crates/metal2vulkan-runtime/src/pipeline/objects.rs:1036` (+15) | `app`: argument buffers holding textures and samplers (bindless) | -| `ArgumentBufferObjects` | Argument-buffer members that are pipeline states, ICBs, function tables, or acceleration structures | every device (not implemented) | 5: `crates/metal2vulkan/src/lower/access/encode.rs:446`, `crates/metal2vulkan/src/lower/access/encode.rs:496` (+3) | `rare`: pipeline states and ICBs in argument buffers | +| `ArgumentBufferTextures` | Argument buffers holding textures or samplers (handle domain) | devices short of a device limit the site names; devices without a capability the site computes (`gaps`); devices without a capability the site computes (`missing`); devices without a capability the site computes (`needs`); every device (not implemented) | 17: `crates/metal2vulkan-runtime/src/families/features.rs:1630`, `crates/metal2vulkan-runtime/src/pipeline/objects.rs:1036` (+15) | `app`: argument buffers holding textures and samplers (bindless) | +| `ArgumentBufferObjects` | Argument-buffer members that are pipeline states, ICBs, function tables, or acceleration structures | every device (not implemented) | 5: `crates/metal2vulkan/src/lower/access/encode.rs:445`, `crates/metal2vulkan/src/lower/access/encode.rs:495` (+3) | `rare`: pipeline states and ICBs in argument buffers | | `DereferenceLoadedPointer` | Dereferencing a pointer loaded from memory or made from an integer | devices short of a Vulkan feature the site names; devices without buffer device addresses (`addressed_needs`); every device (no Vulkan mechanism) | 4: `crates/metal2vulkan/src/lower/access/dynamic.rs:407`, `crates/metal2vulkan/src/lower/access/local.rs:774` (+2) | `app`: pointers loaded from argument buffers | | `PointerToInteger` | Storing a pointer or converting it to an integer | - | via a helper: 1: `crates/metal2vulkan/src/lower/access/dynamic.rs:347` | `rare`: pointer to integer casts | | `PointerCompare` | Comparing pointers with different roots | - | via a helper: 1: `crates/metal2vulkan/src/lower/access/copy.rs:717` | `rare`: comparing pointers of different roots | @@ -82,21 +82,21 @@ Generated at `ce4b23e12`. | `SamplerLodBias` | Sampler LOD bias | devices short of a Vulkan feature the site names; devices without VkLimit::MaxSamplerLodBias; every device (no Vulkan mechanism) | 3: `crates/metal2vulkan/src/lower/sampler/constexpr.rs:258`, `crates/metal2vulkan/src/lower/sampler/constexpr.rs:265` (+1) | `app`: constexpr samplers with an LOD bias | | `SamplerCompare` | Sampler compare functions outside what Vulkan allows for the image | devices short of a Vulkan feature the site names | 1: `crates/metal2vulkan/src/metal/sampler.rs:260` | `app`: compare samplers a device cannot apply to the image | | `PixelSamplerCompare` | A constexpr sampler with pixel coordinates and a compare function, which Apple's compiler rejects ("invalid values combination in sampler... | every device (no Vulkan mechanism) | 1: `crates/metal2vulkan/src/lower/sampler/constexpr.rs:115` | `none`: Apple's compiler rejects it | -| `TexelBuffer` | Texture buffers beyond the device's texel-buffer limits | devices without a format's usage; every device (no Vulkan mechanism) | 3: `crates/metal2vulkan/src/bind/instantiate.rs:880`, `crates/metal2vulkan/src/bind/instantiate.rs:886` (+1) | `app`: texture buffers past a device's texel-buffer limits | +| `TexelBuffer` | Texture buffers beyond the device's texel-buffer limits | devices without a format's usage; every device (no Vulkan mechanism) | 3: `crates/metal2vulkan/src/bind/instantiate.rs:879`, `crates/metal2vulkan/src/bind/instantiate.rs:885` (+1) | `app`: texture buffers past a device's texel-buffer limits | | `RasterOrderGroups` | Raster order groups without fragment shader interlock | devices without VkFeature::FragmentShaderPixelInterlock; devices without VkFeature::FragmentShaderSampleInterlock; devices without a capability the site computes (`alternatives`); every device (not implemented) | 4: `crates/metal2vulkan/src/device/metal.rs:242`, `crates/metal2vulkan/src/lower/fragment/rog.rs:151` (+2) | `rare`: raster order groups | -| `FramebufferFetch` | Framebuffer fetch without an ordered form on the device (rasterization-order attachment access, or the pixel interlock's storage form where the... | devices short of a Vulkan property the site names; devices without VkFeature::FragmentShaderPixelInterlock; devices without VkFeature::RasterizationOrderColorAttachmentAccess; devices without VkFeature::SampleRateShading; devices without a capability the site computes; devices without a capability the site computes (`alternatives`); devices without a capability the site computes (`c`); devices without a capability the site computes (`capability`); devices without a capability the site computes (`missing`); devices without a format's usage; drivers with a defect; every device (not implemented) | 26: `crates/metal2vulkan-runtime/src/families/features.rs:1007`, `crates/metal2vulkan-runtime/src/render.rs:5709` (+24) | `system`: programmable blending (framebuffer fetch); macOS 26.6.2's login reaches it (two WindowServer and RenderBox pipelines fetch RGB10A8_2P_XR10 attachments, the consumer's boots) | -| `PrimitiveId` | `[[primitive_id]]` in a fragment function | devices without a capability the site computes; every device (not implemented) | 3: `crates/metal2vulkan-runtime/src/families/features.rs:1115`, `crates/metal2vulkan/src/lower/stage_io/plan.rs:3112` (+1) | `rare`: primitive_id on a device without geometry or tessellation shaders, in an indexed draw or behind a mesh function | +| `FramebufferFetch` | Framebuffer fetch without an ordered form on the device (rasterization-order attachment access, or the pixel interlock's storage form where the... | devices short of a Vulkan property the site names; devices without VkFeature::FragmentShaderPixelInterlock; devices without VkFeature::RasterizationOrderColorAttachmentAccess; devices without VkFeature::SampleRateShading; devices without a capability the site computes; devices without a capability the site computes (`alternatives`); devices without a capability the site computes (`c`); devices without a capability the site computes (`capability`); devices without a capability the site computes (`missing`); devices without a format's usage; drivers with a defect; every device (not implemented) | 26: `crates/metal2vulkan-runtime/src/families/features.rs:1015`, `crates/metal2vulkan-runtime/src/render.rs:5709` (+24) | `system`: programmable blending (framebuffer fetch); macOS 26.6.2's login reaches it (two WindowServer and RenderBox pipelines fetch RGB10A8_2P_XR10 attachments, the consumer's boots) | +| `PrimitiveId` | `[[primitive_id]]` in a fragment function | devices without a capability the site computes; every device (not implemented) | 3: `crates/metal2vulkan-runtime/src/families/features.rs:1124`, `crates/metal2vulkan/src/lower/stage_io/plan.rs:3112` (+1) | `rare`: primitive_id on a device without geometry or tessellation shaders, in an indexed draw or behind a mesh function | | `VertexAmplification` | Vertex amplification | devices without VkFeature::Multiview; devices without VkFeature::MultiviewTessellationShader; devices without VkLimit::MaxMultiviewInstanceIndex; devices without a capability the site computes (`needs`); every device (not implemented) | 5: `crates/metal2vulkan/src/bind/graphics.rs:3897`, `crates/metal2vulkan/src/lower/stage_io/plan.rs:1281` (+3) | `rare`: vertex amplification | | `LayeredRendering` | Layered rendering (`render_target_array_index`, `viewport_array_index`) | devices without VkFeature::ImageView2DOn3DImage; devices without VkFeature::MultiViewport; devices without VkFeature::ShaderOutputLayer; devices without VkFeature::ShaderOutputViewportIndex; devices without a capability the site computes (`needs`); every device (not implemented) | 7: `crates/metal2vulkan-runtime/src/render_pass.rs:1658`, `crates/metal2vulkan-runtime/src/render_state.rs:1078` (+5) | `rare`: layered rendering on a device without its features | | `ClipDistance` | Clip or cull distances | devices without VkFeature::ShaderClipDistance; devices without VkLimit::MaxClipDistances | 2: `crates/metal2vulkan/src/lower/mesh/mod.rs:934`, `crates/metal2vulkan/src/lower/mesh/mod.rs:942` | `rare`: clip distances on a device without them | | `DualSourceBlending` | Dual-source blending | devices without VkFeature::DualSrcBlend; devices without VkLimit::MaxFragmentDualSrcAttachments | 5: `crates/metal2vulkan-runtime/src/families/formats.rs:386`, `crates/metal2vulkan/src/metal/state.rs:37` (+3) | `rare`: dual-source blending on a device without it | | `Barycentrics` | Barycentric coordinates | devices without VkFeature::FragmentShaderBarycentric; devices without VkFeature::GeometryShader; devices without a capability the site computes (`needs`); drivers with a defect; every device (not implemented) | 5: `crates/metal2vulkan/src/device/metal.rs:263`, `crates/metal2vulkan/src/lower/stage_io/plan.rs:1876` (+3) | `rare`: barycentric coordinates | -| `StencilExport` | Stencil export | devices without VkExtension::ExtShaderStencilExport; every device (not implemented) | 6: `crates/metal2vulkan-runtime/src/families/features.rs:1102`, `crates/metal2vulkan/src/bind/graphics.rs:2606` (+4) | `rare`: stencil from the shader | +| `StencilExport` | Stencil export | devices without VkExtension::ExtShaderStencilExport; every device (not implemented) | 6: `crates/metal2vulkan-runtime/src/families/features.rs:1111`, `crates/metal2vulkan/src/bind/graphics.rs:2606` (+4) | `rare`: stencil from the shader | | `SampleRateShading` | Per-sample shading | devices without VkFeature::SampleRateShading; devices without a capability the site computes (`needs`); every device (not implemented) | 3: `crates/metal2vulkan/src/pipeline/link/graphics.rs:832`, `crates/metal2vulkan/src/pipeline/link/graphics.rs:834` (+1) | `rare`: per-sample shading | | `PixelCoverageAtSampleRate` | The pixel's coverage (`[[sample_mask]]` read) in a fragment function that runs once per sample | drivers with a defect; every device (no Vulkan mechanism); every device (not implemented) | 3: `crates/metal2vulkan/src/lower/fragment/coverage.rs:291`, `crates/metal2vulkan/src/lower/simd/mod.rs:754` (+1) | `rare`: coverage read at sample rate | | `InterfaceComponents` | Too many interface components or locations | devices short of a device limit the site names; devices without VkLimit::MaxColorAttachments; devices without VkLimit::MaxVertexInputAttributes | 4: `crates/metal2vulkan/src/pipeline/compile/color_group.rs:202`, `crates/metal2vulkan/src/pipeline/link/graphics.rs:301` (+2) | `rare`: too many varyings or attachments for a device | | `UnmatchedVarying` | A fragment input without a vertex producer (a Metal link error) | every device (no Vulkan mechanism) | 3: `crates/metal2vulkan/src/pipeline/link/varyings.rs:318`, `crates/metal2vulkan/src/pipeline/link/varyings.rs:537` (+1) | `none`: a Metal link error | -| `KernelStageIn` | Kernel `[[stage_in]]` | every device (not implemented) | 3: `crates/metal2vulkan-runtime/src/indirect_execute.rs:376`, `crates/metal2vulkan/src/bind/dispatch.rs:877` (+1) | `rare`: kernel stage-in combinations Metal leaves unestablished | +| `KernelStageIn` | Kernel `[[stage_in]]` | every device (not implemented) | 3: `crates/metal2vulkan-runtime/src/indirect_execute.rs:350`, `crates/metal2vulkan/src/bind/dispatch.rs:877` (+1) | `rare`: kernel stage-in combinations Metal leaves unestablished | | `Tessellation` | Tessellation | devices without VkLimit::MaxPushConstantsSize; devices without VkLimit::MaxStorageBufferRange; devices without VkLimit::MaxTessellationGenerationLevel; every device (not implemented) | 13: `crates/metal2vulkan-air/src/canon/mod.rs:1256`, `crates/metal2vulkan-air/src/canon/mod.rs:1347` (+11) | `rare`: tessellation | | `MeshShading` | | devices short of a device limit the site names; devices without VkLimit::MaxMeshOutputLayers; devices without VkLimit::MaxTaskPayloadSize; devices without a capability the site computes (`missing`); every device (not implemented) | 7: `crates/metal2vulkan/src/bind/graphics.rs:1536`, `crates/metal2vulkan/src/bind/graphics.rs:2966` (+5) | `rare`: mesh pipelines | | `TileShading` | | devices without VkLimit::MaxStorageBufferRange; devices without a format's usage; every device (not implemented) | 5: `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:521`, `crates/metal2vulkan/src/bind/plan/compute.rs:237` (+3) | `rare`: tile shaders (Apple GPU families) | @@ -110,7 +110,7 @@ Generated at `ce4b23e12`. | `Attribute` | An LLVM attribute kind that changes the calling ABI and that AIR does not use (`inalloca`, `preallocated`, `byref`, `nest`, the `swift*` kinds) | - | via a helper: 2: `crates/metal2vulkan-air/src/bitcode/attrs.rs:493`, `crates/metal2vulkan/src/error/mod.rs:256` | `none`: LLVM ABI attributes AIR does not use | | `BitcodeRecord` | A bitcode record LLVM defines in `block` that the typed model does not cover and that has no more specific variant (legacy spellings predating... | - | via a helper: 7: `crates/metal2vulkan-air/src/bitcode/attrs.rs:337`, `crates/metal2vulkan-air/src/bitcode/function.rs:572` (+5) | `none`: bitcode records AIR does not emit | | `SyncScope` | An atomic access or fence in a synchronization scope other than LLVM's built-in `singlethread` and system scopes | - | via a helper: 2: `crates/metal2vulkan-air/src/bitcode/function.rs:1255`, `crates/metal2vulkan/src/error/mod.rs:258` | `none`: synchronization scopes AIR does not use | -| `SubgroupOperations` | Simdgroup operations of a class the stage's subgroups do not support (the stage is not in `subgroupSupportedStages`, or an operation class is... | devices without VkFeature::ShaderQuadControl; devices without VkFeature::ShaderSubgroupExtendedTypes; devices without VkProperty::SubgroupStage | 4: `crates/metal2vulkan-runtime/src/families/features.rs:1686`, `crates/metal2vulkan/src/lower/simd/mod.rs:407` (+2) | `app`: simdgroup functions in a stage a device's subgroups do not support | +| `SubgroupOperations` | Simdgroup operations of a class the stage's subgroups do not support (the stage is not in `subgroupSupportedStages`, or an operation class is... | devices without VkFeature::ShaderQuadControl; devices without VkFeature::ShaderSubgroupExtendedTypes; devices without VkProperty::SubgroupStage | 4: `crates/metal2vulkan-runtime/src/families/features.rs:1695`, `crates/metal2vulkan/src/lower/simd/mod.rs:407` (+2) | `app`: simdgroup functions in a stage a device's subgroups do not support | | `DirectCall` | A call to a defined function the inliner cannot take | every device (not implemented) | 1: `crates/metal2vulkan-air/src/canon/mod.rs:1319` | `rare`: variadic or byval calls the inliner cannot take | | `WideSwitchLiteral` | A switch case literal wider than 32 bits | every device (not implemented) | 1: `crates/metal2vulkan/src/structurize/emit.rs:207` | `rare`: 64-bit switch literals | | `Lowering` | An instruction, intrinsic, or interface element of a lowering family whose lowering has not landed yet (each family narrows its refusals as it lands) | devices short of a device limit the site names; devices without VkFeature::ShaderDemoteToHelperInvocation; every device (not implemented) | 35: `crates/metal2vulkan/src/bind/plan/resources.rs:762`, `crates/metal2vulkan/src/lower/access/handle.rs:1062` (+33) | `system`: the catch-all of lowering families not landed: any shader can meet one | @@ -132,11 +132,11 @@ Generated at `ce4b23e12`. | `TextureSampleCount` | A texture sample count the device does not take for its format, type, and usage | devices short of a Vulkan property the site names; devices without VkFeature::MultisampleArrayImage; every device (no Vulkan mechanism) | 3: `crates/metal2vulkan-runtime/src/image_plan.rs:1244`, `crates/metal2vulkan-runtime/src/image_plan.rs:598` (+1) | `app`: a sample count a device lacks for the texture | | `TextureView` | A texture view Vulkan cannot make exactly on this image | every device (no Vulkan mechanism); every device (not implemented) | 7: `crates/metal2vulkan-runtime/src/binding_view.rs:156`, `crates/metal2vulkan-runtime/src/texture.rs:5032` (+5) | `app`: a texture view Vulkan cannot make exactly | | `TextureSwizzle` | A texture swizzle whose Metal behavior is not measured | devices short of a Vulkan feature the site names; every device (not implemented) | 7: `crates/metal2vulkan-runtime/src/binding_view.rs:167`, `crates/metal2vulkan-runtime/src/texture.rs:980` (+5) | `app`: texture swizzles whose Metal behaviour is unmeasured | -| `MipmapGeneration` | `generateMipmapsForTexture:` where the device's filter is not shown to give Metal's answer | devices without VkFeature::ShaderInt64; devices without a format's usage; every device (not implemented) | 7: `crates/metal2vulkan-runtime/src/blit_texture.rs:1787`, `crates/metal2vulkan-runtime/src/mipmap_pick.rs:37` (+5) | `app`: generateMipmapsForTexture: where the device's filter is not Metal's | +| `MipmapGeneration` | `generateMipmapsForTexture:` where the device's filter is not shown to give Metal's answer | devices without VkFeature::ShaderInt64; devices without a format's usage; every device (not implemented) | 7: `crates/metal2vulkan-runtime/src/blit_texture.rs:1796`, `crates/metal2vulkan-runtime/src/mipmap_pick.rs:37` (+5) | `app`: generateMipmapsForTexture: where the device's filter is not Metal's | | `HostMemory` | A buffer over the caller's host memory without a copy (`newBufferWithBytesNoCopy:`) | devices without VkExtension::ExtExternalMemoryHost; every device (no Vulkan mechanism); every device (not implemented) | 5: `crates/metal2vulkan-runtime/src/host_memory.rs:393`, `crates/metal2vulkan-runtime/src/host_memory.rs:433` (+3) | `system`: newBufferWithBytesNoCopy: where the device cannot import the memory | -| `GpuTimes` | A command buffer's GPU times (`GPUStartTime`, `GPUEndTime`) on a device whose queue family writes no timestamps (`timestampValidBits` 0) | every device (no Vulkan mechanism) | 1: `crates/metal2vulkan-runtime/src/command_buffer/mod.rs:2555` | `rare`: GPU times on a queue without timestamps | +| `GpuTimes` | A command buffer's GPU times (`GPUStartTime`, `GPUEndTime`) on a device whose queue family writes no timestamps (`timestampValidBits` 0) | every device (no Vulkan mechanism) | 1: `crates/metal2vulkan-runtime/src/command_buffer/mod.rs:2558` | `rare`: GPU times on a queue without timestamps | | `CountingVisibility` | A `Counting` visibility result (`MTLVisibilityResultModeCounting`) on a device without `occlusionQueryPrecise` | devices without VkFeature::OcclusionQueryPrecise | 1: `crates/metal2vulkan-runtime/src/visibility.rs:452` | `rare`: counting occlusion queries on a device without precise queries | -| `ViewFormatReinterpretation` | A texture view whose format has other components, or components of other widths, than its texture's (`RGBA8Unorm` as `R32Uint`), on a device whose... | every device (no Vulkan mechanism) | 1: `crates/metal2vulkan-runtime/src/view_plan.rs:568` | `app`: a view of another component layout on a portability subset (MoltenVK) | +| `ViewFormatReinterpretation` | A texture view whose format has other components, or components of other widths, than its texture's (`RGBA8Unorm` as `R32Uint`), on a device whose... | every device (no Vulkan mechanism) | 1: `crates/metal2vulkan-runtime/src/view_plan.rs:570` | `app`: a view of another component layout on a portability subset (MoltenVK) | | `SeparateMultisampledDepthStencil` | A render pass whose depth and stencil attachments are separate multisampled textures that it loads or may store, on a device without maintenance8,... | - | via a helper: 7: `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:188`, `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:294` (+5) | `rare`: separate multisampled depth and stencil textures | | `PixelCoverage` | The fragment's coverage (`[[sample_mask]]` read) in a fragment function of a pipeline of more than one sample that runs once per pixel | drivers with a defect | 1: `crates/metal2vulkan/src/pipeline/link/graphics.rs:771` | `rare`: coverage reads at pixel rate in a multisampled pipeline | | `CentroidVarying` | A centroid varying (`[[centroid_perspective]]`, `[[centroid_no_perspective]]`) in a fragment function of a pipeline of more than one sample | drivers with a defect | 1: `crates/metal2vulkan/src/pipeline/link/graphics.rs:789` | `rare`: centroid varyings in a multisampled pipeline | @@ -149,7 +149,7 @@ Generated at `ce4b23e12`. | `ViewportDepthRange` | A viewport depth range past `[0, 1]` (`setViewport:`), which Metal takes and the runtime draws natively (`VK_EXT_depth_range_unrestricted`) or... | drivers with a defect | 1: `crates/metal2vulkan-runtime/src/render_state.rs:1186` | `rare`: viewport depth outside [0, 1] | | `UndeclaredTextureUsage` | A shader write to a texture made without `ShaderWrite` (or `ShaderAtomic`), or a read of one made without `ShaderRead`, which plain Metal runs,... | every device (not implemented) | 2: `crates/metal2vulkan-runtime/src/binding_view.rs:141`, `crates/metal2vulkan-runtime/src/texture/usage_shadow.rs:72` | `app`: a shader write to a texture made without ShaderWrite, which plain Metal runs | | `RenderTargetSize` | A render pass whose render area or layers are past the device's framebuffer limits (`Capability::Limit` names `MaxFramebufferWidth`,... | devices short of a device limit the site names | 1: `crates/metal2vulkan-runtime/src/render_pass.rs:1264` | `rare`: a render area past a device's framebuffer limits | -| `IndirectRenderState` | A render state a function sets on an indirect render command (`render_command::set_cull_mode`, `set_front_facing_winding`,... | every device (not implemented) | 1: `crates/metal2vulkan/src/lower/access/encode.rs:568` | `rare`: render state set by a kernel on an indirect command | +| `IndirectRenderState` | A render state a function sets on an indirect render command (`render_command::set_cull_mode`, `set_front_facing_winding`,... | every device (not implemented) | 1: `crates/metal2vulkan/src/lower/access/encode.rs:567` | `rare`: render state set by a kernel on an indirect command | | `GlobalBuiltinInFragment` | A fragment function's read of a Metal 3.1 program-scope built-in variable that Metal does not lower there | every device (not implemented) | 1: `crates/metal2vulkan/src/lower/select.rs:912` | `rare`: Metal 3.1 global built-ins in fragment functions | | `PrivateRenderState` | A private fixed-function property of Metal's pipeline descriptor (Apple SPI, OpenGL on Metal's) set to a value whose effect the translation has... | every device (not implemented) | 4: `crates/metal2vulkan/src/bind/heap.rs:1300`, `crates/metal2vulkan/src/bind/plan/resources.rs:887` (+2) | `none`: Apple-private pipeline fields of OpenGL on Metal (no public header) | | `ExtendedRangeBlend` | Metal's blend into an extended-range attachment (`BGRA10_XR`, `BGR10_XR`, `RGB10A8_2P_XR10` and their `_sRGB` twins), which the function computes... | every device (not implemented) | 4: `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:305`, `crates/metal2vulkan/src/lower/fragment/fetch.rs:1553` (+2) | `system`: the parts of a blend into an extended-range (XR10) attachment the measured model does not hold (second-source factors, the color blend color difference, a one-color-channel mask, float4 and sRGB outside the measured forms); the consumer's guests blend RGB10A8_2P_XR10 attachments | @@ -170,9 +170,9 @@ Generated at `ce4b23e12`. | `HeapTextureAlignment` | A heap texture whose image needs an alignment past the heap memory's base alignment (256 KiB) | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/texture/heap.rs:980` | `rare`: a heap texture needing more than 256 KiB alignment | | `HeapTextureMemory` | A heap texture whose image the heap's memory type does not take | every device (runtime piece not built) | 5: `crates/metal2vulkan-runtime/src/texture/heap.rs:1418`, `crates/metal2vulkan-runtime/src/texture/heap.rs:1425` (+3) | `app`: a heap texture the heap's memory type does not take | | `FunctionTablePastMaxBufferLength` | A visible-function table of more entries than one buffer of the device's `max_buffer_length` holds words for, or than its size word holds | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/function_table.rs:622` | `none`: a function table past one buffer | -| `IndirectCommandBufferPastMaxBufferLength` | An indirect command buffer of more commands than one buffer of the device's `max_buffer_length` holds the records of | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:522` | `none`: an ICB past one buffer | -| `IndirectRenderCommands` | What indirect command buffers lack of their render commands | every device (runtime piece not built) | 17: `crates/metal2vulkan-runtime/src/compute.rs:1091`, `crates/metal2vulkan-runtime/src/compute.rs:1171` (+15) | `rare`: indirect render commands' remaining pieces | -| `IndirectImageblockSize` | An indirect compute command's imageblock side past 65535, which Metal keeps | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:3351` | `none`: an imageblock side past 65535 | +| `IndirectCommandBufferPastMaxBufferLength` | An indirect command buffer of more commands than one buffer of the device's `max_buffer_length` holds the records of | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:516` | `none`: an ICB past one buffer | +| `IndirectRenderCommands` | What indirect command buffers lack of their render commands | every device (runtime piece not built) | 17: `crates/metal2vulkan-runtime/src/compute.rs:1084`, `crates/metal2vulkan-runtime/src/compute.rs:1163` (+15) | `rare`: indirect render commands' remaining pieces | +| `IndirectImageblockSize` | An indirect compute command's imageblock side past 65535, which Metal keeps | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:2757` | `none`: an imageblock side past 65535 | | `CommandReplay` | The device replay of indirect command buffers | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/binding.rs:694`, `crates/metal2vulkan-runtime/src/binding.rs:697` | `rare`: the device replay of indirect command buffers | | `RenderAttachments` | Render attachments and their binding forms | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/binding.rs:1839` | `rare`: render attachment forms not built | | `AccelerationStructures` | Acceleration structures | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/binding.rs:1842` | `rare`: ray tracing (out of scope by ruling) | @@ -192,23 +192,23 @@ Generated at `ce4b23e12`. | `TileAtSampleCount` | The tile memory of a render pass of a sample count Apple's GPUs lack (theirs are 1, 2 and 4), which a Vulkan device may have | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/render_pass.rs:1600`, `crates/metal2vulkan-runtime/src/render_pass.rs:930` | `none`: tile memory at a sample count Apple's GPUs lack | | `ImageblockMasters` | A draw or tile dispatch whose imageblock is of another size than the pass's, or a draw whose fragment function's layouts are of another alignment... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/render.rs:7115`, `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:930` | `rare`: imageblocks of mixed sizes in one pass | | `TileAndFragmentImageblocks` | A render pass that reaches its imageblock storage, from a draw whose fragment function declares an explicit imageblock or a tile dispatch whose... | every device (runtime piece not built) | 3: `crates/metal2vulkan-runtime/src/render.rs:7107`, `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:797` (+1) | `rare`: explicit imageblocks shared by tile and fragment functions | -| `Metal4Api` | Metal 4's API (`MTL4CommandQueue`, `MTL4CommandBuffer`, `MTL4ArgumentTable`, `MTL4Compiler` and the rest), with the features only its programming... (not scheduled) | every device (runtime piece not built) | family audit only: 3: `crates/metal2vulkan-runtime/src/families/features.rs:1460`, `crates/metal2vulkan-runtime/src/families/limits.rs:1022` (+1) | `app`: Metal 4 (the API is missing: METAL-COVERAGE.md) | +| `Metal4Api` | Metal 4's API (`MTL4CommandQueue`, `MTL4CommandBuffer`, `MTL4ArgumentTable`, `MTL4Compiler` and the rest), with the features only its programming... (not scheduled) | every device (runtime piece not built) | family audit only: 3: `crates/metal2vulkan-runtime/src/families/features.rs:1469`, `crates/metal2vulkan-runtime/src/families/limits.rs:1022` (+1) | `app`: Metal 4 (the API is missing: METAL-COVERAGE.md) | | `CounterSampleBuffers` | Counter sample buffers (`MTLCounterSampleBuffer`) and the commands that sample into them (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/limits.rs:1013` | `app`: GPU counters and timestamps by sample buffer (missing API) | -| `ResidencySets` | Residency sets (`MTLResidencySet`) (not scheduled) | every device (runtime piece not built) | family audit only: 2: `crates/metal2vulkan-runtime/src/families/features.rs:1442`, `crates/metal2vulkan-runtime/src/families/limits.rs:1015` | `app`: residency sets (missing API) | -| `TextureAccessCounters` | A sparse texture's access counters (`getTextureAccessCounters:...` and `resetTextureAccessCounters:...` of a blit encoder) (not scheduled) | every device (runtime piece not built) | family audit only: 2: `crates/metal2vulkan-runtime/src/families/features.rs:1429`, `crates/metal2vulkan-runtime/src/families/features.rs:1434` | `rare`: sparse texture access counters | -| `IoCommandQueues` | Fast resource loading (not scheduled) | every device (runtime piece not built) | family audit only: 2: `crates/metal2vulkan-runtime/src/families/features.rs:1439`, `crates/metal2vulkan-runtime/src/families/limits.rs:1020` | `rare`: fast resource loading (missing API) | -| `TextureViewPools` | Texture view pools (`MTLTextureViewPool`) (not scheduled) | every device (runtime piece not built) | family audit only: 2: `crates/metal2vulkan-runtime/src/families/features.rs:1443`, `crates/metal2vulkan-runtime/src/families/limits.rs:1021` | `rare`: texture view pools (missing API) | -| `ColorAttachmentMapping` | Color attachment mapping (`MTLLogicalToPhysicalColorAttachmentMap`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1444` | `rare`: color attachment mapping (missing API) | -| `LossyTextureCompression` | Lossy texture compression (`MTLTextureCompressionTypeLossy`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1438` | `rare`: lossy texture compression | -| `ShaderValidation` | Per-pipeline shader validation (`MTLShaderValidation`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1440` | `rare`: per-pipeline shader validation | -| `ShaderLogging` | Shader logging (`MTLLogState`, a shader's `os_log`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1441` | `rare`: shader os_log | -| `DeviceNotifications` | Device notifications (`MTLCopyAllDevicesWithObserver`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1445` | `rare`: device hotplug notifications (deprecated) | +| `ResidencySets` | Residency sets (`MTLResidencySet`) (not scheduled) | every device (runtime piece not built) | family audit only: 2: `crates/metal2vulkan-runtime/src/families/features.rs:1451`, `crates/metal2vulkan-runtime/src/families/limits.rs:1015` | `app`: residency sets (missing API) | +| `TextureAccessCounters` | A sparse texture's access counters (`getTextureAccessCounters:...` and `resetTextureAccessCounters:...` of a blit encoder) (not scheduled) | every device (runtime piece not built) | family audit only: 2: `crates/metal2vulkan-runtime/src/families/features.rs:1438`, `crates/metal2vulkan-runtime/src/families/features.rs:1443` | `rare`: sparse texture access counters | +| `IoCommandQueues` | Fast resource loading (not scheduled) | every device (runtime piece not built) | family audit only: 2: `crates/metal2vulkan-runtime/src/families/features.rs:1448`, `crates/metal2vulkan-runtime/src/families/limits.rs:1020` | `rare`: fast resource loading (missing API) | +| `TextureViewPools` | Texture view pools (`MTLTextureViewPool`) (not scheduled) | every device (runtime piece not built) | family audit only: 2: `crates/metal2vulkan-runtime/src/families/features.rs:1452`, `crates/metal2vulkan-runtime/src/families/limits.rs:1021` | `rare`: texture view pools (missing API) | +| `ColorAttachmentMapping` | Color attachment mapping (`MTLLogicalToPhysicalColorAttachmentMap`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1453` | `rare`: color attachment mapping (missing API) | +| `LossyTextureCompression` | Lossy texture compression (`MTLTextureCompressionTypeLossy`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1447` | `rare`: lossy texture compression | +| `ShaderValidation` | Per-pipeline shader validation (`MTLShaderValidation`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1449` | `rare`: per-pipeline shader validation | +| `ShaderLogging` | Shader logging (`MTLLogState`, a shader's `os_log`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1450` | `rare`: shader os_log | +| `DeviceNotifications` | Device notifications (`MTLCopyAllDevicesWithObserver`) (not scheduled) | every device (runtime piece not built) | family audit only: 1: `crates/metal2vulkan-runtime/src/families/features.rs:1454` | `rare`: device hotplug notifications (deprecated) | | `RateMapRegions` | A draw in a rate-mapped pass that the region path does not draw, for the compile layer's reason (`rate_mapped_pass.rs`) | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/rate_mapped_pass.rs:349` | `rare`: draws in rate-mapped passes the region path does not draw | | `LayeredPass` | A layered render pass (`renderTargetArrayLength` 2 or more) that needs a step of one layer | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/color_resolve.rs:890` | `rare`: layered passes needing a per-layer color resolve | | `FunctionOptions` | A function descriptor's options beyond `CompileToBinary` and `StoreFunctionInMetalPipelinesScript` (`Library::new_function_with_descriptor`) | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/library.rs:215` | `rare`: function descriptor options beyond CompileToBinary | -| `OverlappingTextureCopies` | A blit copy between overlapping regions of one texture's texels (`copyFromTexture:...` with the source's region meeting the destination's, through... (not scheduled) | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/blit_texture.rs:1242` | `rare`: overlapping texture copies (Metal races) | +| `OverlappingTextureCopies` | A blit copy between overlapping regions of one texture's texels (`copyFromTexture:...` with the source's region meeting the destination's, through... (not scheduled) | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/blit_texture.rs:1251` | `rare`: overlapping texture copies (Metal races) | | `RebindTextures` | `Buffer::rebind_bytes_no_copy` of a no-copy buffer with a live texture over its bytes, given memory at another offset in its page than the old | every device (runtime piece not built) | 5: `crates/metal2vulkan-runtime/src/buffer_descriptor.rs:600`, `crates/metal2vulkan-runtime/src/texture/heap.rs:2431` (+3) | `none`: a runtime extension's rebind with a live texture | -| `PvrtcBlockOrder` | A PVRTC texture's blocks in a Metal block order the runtime does not lay out | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/texture.rs:5575` | `rare`: PVRTC regions off whole levels | +| `PvrtcBlockOrder` | A PVRTC texture's blocks in a Metal block order the runtime does not lay out | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/texture.rs:5580` | `rare`: PVRTC regions off whole levels | | `DecodedHeapTexture` | A heap's or a sparse heap's texture of an ASTC format on a device without that ASTC format (`astc.rs`), or a sparse heap's texture of an ETC2 or... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/texture.rs:1637`, `crates/metal2vulkan-runtime/src/texture/heap.rs:1281` | `app`: an ASTC texture in a heap on a device without ASTC | | `VertexFetchPast4GiB` | A draw (`drawPrimitives:` and its forms, or an indirect command buffer's command) that may read a vertex attribute the pipeline fetches in its... | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/render/vertex_reach.rs:72` | `rare`: vertex fetch past 4 GiB of a bind offset | | `StageInFetchPast4GiB` | A dispatch (`dispatchThreads:threadsPerThreadgroup:` and its forms, or an indirect command buffer's command) whose kernel may read a... | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/fetch_reach.rs:126` | `rare`: stage-in fetch past 4 GiB of a bind offset | @@ -216,47 +216,46 @@ Generated at `ce4b23e12`. | `LibrarySource` | A library compiled from Metal Shading Language source | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/library.rs:107` | `app`: a library compiled from Metal source (newLibraryWithSource:); the runtime takes metallibs and AIR | | `RestartedStrip` | An indexed strip after `set_primitive_restart_enabled` with an index Vulkan does not restart at, which the runtime draws as a list an index... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/index_rewrite.rs:110`, `crates/metal2vulkan-runtime/src/render.rs:7219` | `none`: a strip after the Apple-private setPrimitiveRestartEnabled:index: whose rewrite pass cannot run as Metal draws | | `PrimitiveIdIndices` | An indexed draw (`drawIndexedPrimitives:`) of a pipeline whose fragment function reads `[[primitive_id]]` on a device whose fragment stage cannot... | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/render.rs:7596` | `rare`: an indexed draw of a primitive_id pipeline, on a device without geometry or tessellation shaders, whose indices the encoder wrote since its last barrier | -| `RotatedTexture` | A rotated texture (`TextureDescriptor::rotation`) where the runtime does not build what Metal does | every device (runtime piece not built) | 9: `crates/metal2vulkan-runtime/src/blit_texture.rs:1571`, `crates/metal2vulkan-runtime/src/buffer_texture.rs:715` (+7) | `rare`: a rotated drawable's views, blits with images over overlapping rows, rows past its buffer | +| `RotatedTexture` | A rotated texture (`TextureDescriptor::rotation`) where the runtime does not build what Metal does | every device (runtime piece not built) | 9: `crates/metal2vulkan-runtime/src/blit_texture.rs:1580`, `crates/metal2vulkan-runtime/src/buffer_texture.rs:715` (+7) | `rare`: a rotated drawable's views, blits with images over overlapping rows, rows past its buffer | | `DetachTextures` | A texture over a no-copy buffer's or heap's bytes (a heap's texture, or a texture over the buffer or over one of the heap's buffers) that no... | every device (runtime piece not built) | 8: `crates/metal2vulkan-runtime/src/buffer_descriptor.rs:604`, `crates/metal2vulkan-runtime/src/buffer_texture.rs:622` (+6) | `none`: a runtime extension's detach with a texture no stand-in presents exactly | | `TextureBufferLevels` | A texture buffer of more than one level (`TextureDescriptor::mipmap_level_count`, up to its width's full chain) from the device's, a heap's or the... | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/texture_descriptor.rs:540` | `rare`: a texture buffer of more than one level (public, unusual) | | `WriteSwizzle` | A texture of `TextureDescriptor::write_swizzle_enabled` whose swizzle is not the default, with `ShaderWrite` or `RenderTarget` usage, from the... | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/texture_descriptor.rs:547` | `none`: Apple-private writeSwizzleEnabled with a swizzle that writes | | `DetachedTexelAccess` | `Texture::replace_region` or `get_bytes` of a texture whose bytes (a no-copy buffer's or heap's) are detached (`detach_backing`) | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/texture.rs:4820` | `none`: CPU texel access while a runtime extension detached the bytes | -| `SurfaceDepthStencil` | A use of a texture of a depth or stencil format (`Depth16Unorm`, `Depth32Float`, `Depth32Float_Stencil8`, `Stencil8`, `X32_Stencil8`) over a plane... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/blit_texture.rs:236`, `crates/metal2vulkan-runtime/src/texture/surface_depth.rs:57` | `rare`: a blit of the stencil of a Depth32Float_Stencil8 texture over a plane of an IOSurface with planes, or a pass on an X32_Stencil8 one's view as Depth32Float_Stencil8 | +| `SurfaceDepthStencil` | A use of a texture of a depth or stencil format (`Depth16Unorm`, `Depth32Float`, `Depth32Float_Stencil8`, `Stencil8`, `X32_Stencil8`) over a plane... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/blit_texture.rs:240`, `crates/metal2vulkan-runtime/src/texture/surface_depth.rs:57` | `rare`: a blit of the stencil of a Depth32Float_Stencil8 texture over a plane of an IOSurface with planes, or a pass on an X32_Stencil8 one's view as Depth32Float_Stencil8 | | `HostHeapUncompressedMultisample` | A multisample texture in a heap over host pages (`Device::new_heap_with_bytes_no_copy`) that Metal keeps uncompressed | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/texture/heap.rs:1924` | `none`: a multisample texture Metal keeps uncompressed in a runtime extension's heap over host pages | | `PredicationUnbalanced` | An unbalanced command-predication record (`ComputeCommandEncoder::encode_end_if` and the other ends, or `encode_start_else`, with no block open;... | every device (runtime piece not built) | 4: `crates/metal2vulkan-runtime/src/predication.rs:371`, `crates/metal2vulkan-runtime/src/predication.rs:403` (+2) | `none`: an unbalanced Apple-private command-predication record, whose dropped work Metal decides by no rule measured | | `PredicationOpenAtUnitEnd` | A command buffer one of whose units of predication ended with an If still open that no misused record killed, refused at `CommandBuffer::commit` | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/predication.rs:280`, `crates/metal2vulkan-runtime/src/predication.rs:296` | `none`: an Apple-private predication If left open, live, where its unit ends | | `PredicationWordPastBuffer` | A predication condition word (`encode_start_if`'s offset, rounded down to a multiple of 4) past its buffer's end | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/predication.rs:139` | `none`: an Apple-private predication condition word past its buffer | | `PredicatedLoopDepth` | A predicated loop started (`ComputeCommandEncoder::encode_start_while`, `encode_start_do_while`) with three loops already open in its unit | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/predication.rs:483` | `none`: an Apple-private predicated loop four deep | | `PredicatedLoopAcrossEncoders` | A command buffer one of whose live predicated loops started in one compute encoder and ended in a later one of its unit, refused at... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/predication.rs:284`, `crates/metal2vulkan-runtime/src/predication.rs:300` | `none`: a live Apple-private predicated loop spanning compute encoders | -| `MultisampledBufferCopy` | A blit copy between a buffer and a multisampled texture (`copyFromBuffer:...toTexture:` into, or `copyFromTexture:...toBuffer:` out of, a texture... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/blit_texture.rs:485`, `crates/metal2vulkan-runtime/src/blit_texture.rs:641` | `rare`: a buffer<->multisampled-texture copy on a device without sample-rate shading, an integer multisample attachment at the count, or the copy format's storage; and, where maintenance8's depth/colour copies are missing or wrong, what the sample-rate draws cannot move: a 16-bit depth, or a depth or stencil texture they cannot sample or render to (emulated elsewhere; the consumer's Maps pans and screensaver make the copy) | +| `MultisampledBufferCopy` | A blit copy between a buffer and a multisampled texture (`copyFromBuffer:...toTexture:` into, or `copyFromTexture:...toBuffer:` out of, a texture... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/blit_texture.rs:489`, `crates/metal2vulkan-runtime/src/blit_texture.rs:645` | `rare`: a buffer<->multisampled-texture copy on a device without sample-rate shading, an integer multisample attachment at the count, or the copy format's storage; and, where maintenance8's depth/colour copies are missing or wrong, what the sample-rate draws cannot move: a 16-bit depth, or a depth or stencil texture they cannot sample or render to (emulated elsewhere; the consumer's Maps pans and screensaver make the copy) | | `ColorAttachmentGroups` | What a render pass the device draws in color groups does not build | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/render/color_groups.rs:106` | `app`: in a render pass of more color attachments than the device draws at once (five or more on a device of four), or one at an index past them: a pipeline state of other colors, a tile state, an execution of render commands, a draw reading another group's attachment | ## 3. Apple-only calls (`Error::AppleOnly`) | Variant | What it blocks | Where | Sites | Reach | |---|---|---|---|---| -| `ProtectedContent` | Protected content | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:200` | `none`: Apple-private (no public header) | -| `LineWidth` | A line width other than 1 (`setLineWidth:`) | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:202` | `none`: Apple-private (no public header) | -| `ProvokingVertexMode` | `setProvokingVertexMode:` other than 0 | every device (Apple-private, not built) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:207` | `none`: Apple-private (no public header) | -| `ViewportTransformDisabled` | The viewport transform turned off (`setViewportTransformEnabled:NO`) | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:204` | `none`: Apple-private (no public header) | -| `VertexAmplificationMode` | `setVertexAmplificationMode:value:` | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:210` | `none`: Apple-private (no public header) | -| `DepthCleared` | `setDepthCleared` | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:212` | `none`: Apple-private (no public header) | -| `StencilCleared` | `setStencilCleared` | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:213` | `none`: Apple-private (no public header) | +| `ProtectedContent` | Protected content | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:189` | `none`: Apple-private (no public header) | +| `LineWidth` | A line width other than 1 (`setLineWidth:`) | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:191` | `none`: Apple-private (no public header) | +| `ProvokingVertexMode` | `setProvokingVertexMode:` other than 0 | every device (Apple-private, not built) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:196` | `none`: Apple-private (no public header) | +| `ViewportTransformDisabled` | The viewport transform turned off (`setViewportTransformEnabled:NO`) | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:193` | `none`: Apple-private (no public header) | +| `VertexAmplificationMode` | `setVertexAmplificationMode:value:` | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:199` | `none`: Apple-private (no public header) | +| `DepthCleared` | `setDepthCleared` | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:201` | `none`: Apple-private (no public header) | +| `StencilCleared` | `setStencilCleared` | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/apple_only.rs:202` | `none`: Apple-private (no public header) | | `SurfaceClientDirection` | A texture over an IOSurface made with `kIOSurfaceClientDirection` (`newTextureWithDescriptor:iosurface:plane:` of such a surface) | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/buffer_texture.rs:417` | `none`: an IOSurface key in no public header | -| `FillUnmeasured` | A texture fill (`fillTexture:level:slice:region:bytes:length:` or a color form) whose answer on Apple's GPU is unmeasured | every device (Apple-private, Metal's answer not measured) | 1: `crates/metal2vulkan-runtime/src/blit_fill.rs:149` | `system`: Apple-private texture fills, which macOS system software encodes | ## 4. Binder refusals at a device limit (`BindError`) | Variant | What it blocks | Where | Sites | Reach | |---|---|---|---|---| -| `DescriptorRangeExceeded` | A descriptor-form slot's window exceeds the descriptor range limit (Profile F) | at the device's limit | 1: `crates/metal2vulkan/src/bind/instantiate.rs:653` | `app`: a buffer window past a device's descriptor range | -| `TexelBufferTooLarge` | A texel buffer exceeds `maxTexelBufferElements` | at the device's limit | 1: `crates/metal2vulkan/src/bind/instantiate.rs:892` | `rare`: a texture buffer past maxTexelBufferElements | +| `DescriptorRangeExceeded` | A descriptor-form slot's window exceeds the descriptor range limit (Profile F) | at the device's limit | 1: `crates/metal2vulkan/src/bind/instantiate.rs:652` | `app`: a buffer window past a device's descriptor range | +| `TexelBufferTooLarge` | A texel buffer exceeds `maxTexelBufferElements` | at the device's limit | 1: `crates/metal2vulkan/src/bind/instantiate.rs:891` | `rare`: a texture buffer past maxTexelBufferElements | | `HeapTooLarge` | The set-1 heap's elements (one per resident texture a handle can name, plus the null element) exceed the pipeline's heap capacity | at the device's limit | 7: `crates/metal2vulkan/src/bind/heap.rs:1014`, `crates/metal2vulkan/src/bind/heap.rs:1748` (+5) | `rare`: more resident textures than the pipeline's heap holds (bindless at scale) | | `TessellationFactorRange` | The tessellation factors a draw reads span more bytes (`needed`) than one storage-buffer descriptor can bind (`limit`, `maxStorageBufferRange`),... | at the device's limit | 1: `crates/metal2vulkan/src/bind/graphics.rs:3551` | `rare`: tessellation factors past one storage descriptor | | `PatchIndexRange` | The patch indices a draw reads span more bytes (`needed`) than one storage-buffer descriptor can bind (`limit`, `maxStorageBufferRange`) | at the device's limit | 1: `crates/metal2vulkan/src/bind/graphics.rs:3595` | `rare`: patch indices past one storage descriptor | | `ControlPointIndexRange` | The control-point indices a draw reads span more bytes (`needed`) than one storage-buffer descriptor can bind (`limit`, `maxStorageBufferRange`) | at the device's limit | 1: `crates/metal2vulkan/src/bind/graphics.rs:3633` | `rare`: control-point indices past one storage descriptor | | `MissingStageInRegion` | The kernel reads the compute encoder's stage-in region (a `[[stage_in]]` attribute stepping by thread position, or `[[grid_origin]]` or... | at the device's limit | 1: `crates/metal2vulkan/src/bind/dispatch.rs:802` | `none`: a stage-in region never set, which Metal leaves undefined | -| `UniformViewAliased` | A `device` buffer slot the pipeline reads through a uniform view (Profile F's per-stage storage-buffer fallback,... | at the device's limit | 1: `crates/metal2vulkan/src/bind/instantiate.rs:607` | `rare`: Profile F's uniform-view fallback aliased by a write | +| `UniformViewAliased` | A `device` buffer slot the pipeline reads through a uniform view (Profile F's per-stage storage-buffer fallback,... | at the device's limit | 1: `crates/metal2vulkan/src/bind/instantiate.rs:606` | `rare`: Profile F's uniform-view fallback aliased by a write | | `MissingDeviceAddress` | A device-address slot received a buffer without a device address | at the device's limit | 1: `crates/metal2vulkan/src/bind/plan/slots.rs:133` | `rare`: a slot reached through a pointer loaded from memory, bound with inline bytes or on a device without device addresses | ## 5. Translation caps (`Error::LimitExceeded(Limit)`) @@ -319,8 +318,8 @@ Each refusal's sites, with the function that builds it. - `feature::QuadOperations`: `crates/metal2vulkan/src/device/subgroup.rs:371 (subgroup_tier)`; `crates/metal2vulkan/src/device/subgroup.rs:405 (subgroup_tier)` - `feature::SimdgroupMatrix`: `crates/metal2vulkan/src/lower/simd/matrix.rs:83 (not_implemented)` - `feature::ArgumentBufferPointers`: `crates/metal2vulkan/src/device/metal.rs:236 (unsupported_features)` -- `feature::ArgumentBufferTextures`: `crates/metal2vulkan-runtime/src/families/features.rs:1621 (tier2)`; `crates/metal2vulkan-runtime/src/pipeline/objects.rs:1036 (create_set_layout)`; `crates/metal2vulkan-runtime/src/resource_ids.rs:1243 (check_capacity)`; `crates/metal2vulkan/src/bind/heap.rs:1325 (array)`; `crates/metal2vulkan/src/bind/heap.rs:415 (member_view)`; `crates/metal2vulkan/src/bind/heap.rs:423 (member_view)`; `crates/metal2vulkan/src/bind/heap.rs:467 (member_view)`; `crates/metal2vulkan/src/bind/heap.rs:472 (member_view)`; `crates/metal2vulkan/src/bind/heap.rs:485 (member_view)`; `crates/metal2vulkan/src/lower/access/handle.rs:708 (select)`; `crates/metal2vulkan/src/lower/sampler/select.rs:2362 (select_one)`; `crates/metal2vulkan/src/lower/sampler/select.rs:308 (select_sampling)`; `crates/metal2vulkan/src/lower/sampler/select.rs:469 (select_heap_sampling)`; `crates/metal2vulkan/src/lower/texture/atomic.rs:140 (select)`; `crates/metal2vulkan/src/lower/texture/slot.rs:465 (declare_heap)`; `crates/metal2vulkan/src/lower/texture/slot.rs:534 (declare_heap)`; `crates/metal2vulkan/src/pipeline/link.rs:977 (heap_set)` -- `feature::ArgumentBufferObjects`: `crates/metal2vulkan/src/lower/access/encode.rs:446 (select_command)`; `crates/metal2vulkan/src/lower/access/encode.rs:496 (select_command)`; `crates/metal2vulkan/src/lower/access/encode.rs:624 (select_command)`; `crates/metal2vulkan/src/memory/provenance.rs:2185 (classify)`; `crates/metal2vulkan/src/memory/provenance.rs:2547 (access)` +- `feature::ArgumentBufferTextures`: `crates/metal2vulkan-runtime/src/families/features.rs:1630 (tier2)`; `crates/metal2vulkan-runtime/src/pipeline/objects.rs:1036 (create_set_layout)`; `crates/metal2vulkan-runtime/src/resource_ids.rs:1097 (check_capacity)`; `crates/metal2vulkan/src/bind/heap.rs:1325 (array)`; `crates/metal2vulkan/src/bind/heap.rs:415 (member_view)`; `crates/metal2vulkan/src/bind/heap.rs:423 (member_view)`; `crates/metal2vulkan/src/bind/heap.rs:467 (member_view)`; `crates/metal2vulkan/src/bind/heap.rs:472 (member_view)`; `crates/metal2vulkan/src/bind/heap.rs:485 (member_view)`; `crates/metal2vulkan/src/lower/access/handle.rs:708 (select)`; `crates/metal2vulkan/src/lower/sampler/select.rs:2362 (select_one)`; `crates/metal2vulkan/src/lower/sampler/select.rs:308 (select_sampling)`; `crates/metal2vulkan/src/lower/sampler/select.rs:469 (select_heap_sampling)`; `crates/metal2vulkan/src/lower/texture/atomic.rs:140 (select)`; `crates/metal2vulkan/src/lower/texture/slot.rs:465 (declare_heap)`; `crates/metal2vulkan/src/lower/texture/slot.rs:534 (declare_heap)`; `crates/metal2vulkan/src/pipeline/link.rs:977 (heap_set)` +- `feature::ArgumentBufferObjects`: `crates/metal2vulkan/src/lower/access/encode.rs:445 (select_command)`; `crates/metal2vulkan/src/lower/access/encode.rs:495 (select_command)`; `crates/metal2vulkan/src/lower/access/encode.rs:623 (select_command)`; `crates/metal2vulkan/src/memory/provenance.rs:2185 (classify)`; `crates/metal2vulkan/src/memory/provenance.rs:2547 (access)` - `feature::DereferenceLoadedPointer`: `crates/metal2vulkan/src/lower/access/dynamic.rs:407 (plan_misses)`; `crates/metal2vulkan/src/lower/access/local.rs:774 (access_ptr)`; `crates/metal2vulkan/src/lower/access/local.rs:796 (threadgroup_constant_refusal)`; `crates/metal2vulkan/src/memory/plan.rs:593 (analyze)` - `feature::PointerToInteger`: `crates/metal2vulkan/src/lower/access/dynamic.rs:347 (require_addresses)` - `feature::PointerCompare`: `crates/metal2vulkan/src/lower/access/copy.rs:717 (addressed)` @@ -331,10 +330,10 @@ Each refusal's sites, with the function that builds it. - `feature::Int64Atomics`: `crates/metal2vulkan/src/lower/access/atomic.rs:624 (select)`; `crates/metal2vulkan/src/lower/access/atomic.rs:633 (select)` - `feature::ImageAtomics`: `crates/metal2vulkan-runtime/src/families/formats.rs:464 (atomic_gap)`; `crates/metal2vulkan-runtime/src/families/formats.rs:468 (atomic_gap)`; `crates/metal2vulkan/src/lower/texture/slot.rs:900 (atomic_format)` - `feature::DescriptorCount`: `crates/metal2vulkan/src/lower/access/mod.rs:1684 (accept_placement)`; `crates/metal2vulkan/src/lower/select.rs:1641 (finish)`; `crates/metal2vulkan/src/pipeline/link.rs:1135 (limit_error)` -- `feature::BufferRange`: `crates/metal2vulkan-runtime/src/function_table.rs:569 (past_storage_buffer_range)`; `crates/metal2vulkan/src/bind/graphics.rs:3556 (patch_binding)`; `crates/metal2vulkan/src/bind/graphics.rs:3600 (patch_binding)`; `crates/metal2vulkan/src/bind/graphics.rs:3638 (patch_binding)`; `crates/metal2vulkan/src/bind/instantiate.rs:659 (bind_buffers)`; `crates/metal2vulkan/src/lower/access/function_table.rs:226 (select)`; `crates/metal2vulkan/src/lower/access/mod.rs:1184 (place_slots)` +- `feature::BufferRange`: `crates/metal2vulkan-runtime/src/function_table.rs:569 (past_storage_buffer_range)`; `crates/metal2vulkan/src/bind/graphics.rs:3556 (patch_binding)`; `crates/metal2vulkan/src/bind/graphics.rs:3600 (patch_binding)`; `crates/metal2vulkan/src/bind/graphics.rs:3638 (patch_binding)`; `crates/metal2vulkan/src/bind/instantiate.rs:658 (bind_buffers)`; `crates/metal2vulkan/src/lower/access/function_table.rs:226 (select)`; `crates/metal2vulkan/src/lower/access/mod.rs:1184 (place_slots)` - `feature::Int64Arithmetic`: `crates/metal2vulkan/src/lower/arith/legal.rs:582 (check_scalar)`; `crates/metal2vulkan/src/lower/select.rs:1133 (selector_form)` - `feature::Float64Arithmetic`: `crates/metal2vulkan/src/device/metal.rs:230 (unsupported_features)`; `crates/metal2vulkan/src/lower/arith/legal.rs:587 (check_scalar)` -- `feature::Format`: `crates/metal2vulkan-runtime/src/binding_view.rs:146 (binding_view)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:462 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:469 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:484 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:541 (pair_unit)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:633 (plan_levels_copy)`; `crates/metal2vulkan-runtime/src/blit_texture.rs:2087 (through_buffer)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:519 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:582 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:614 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:851 (texture_buffer_texel)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:269 (colour_unit)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:297 (copy_unit)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:343 (copy_unit)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:346 (scratch)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:526 (usable_twin)`; `crates/metal2vulkan-runtime/src/families/features.rs:1598 (read_write_tier)`; `crates/metal2vulkan-runtime/src/families/formats.rs:1628 (sparse_missing)`; `crates/metal2vulkan-runtime/src/families/formats.rs:227 (none)`; `crates/metal2vulkan-runtime/src/families/formats.rs:271 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:291 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:306 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:353 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:392 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:474 (atomic_gap)`; `crates/metal2vulkan-runtime/src/families/formats.rs:508 (lacking)`; `crates/metal2vulkan-runtime/src/families/formats.rs:522 (unsupported)`; `crates/metal2vulkan-runtime/src/image_plan.rs:544 (check_own_memory)`; `crates/metal2vulkan-runtime/src/image_plan.rs:670 (plan_held)`; `crates/metal2vulkan-runtime/src/image_plan.rs:787 (plan_held)`; `crates/metal2vulkan-runtime/src/image_plan.rs:907 (plan_held)`; `crates/metal2vulkan-runtime/src/render.rs:2155 (viewing)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1024 (check_target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1362 (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1698 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1791 (attachment_format)`; `crates/metal2vulkan-runtime/src/resolve.rs:392 (unmodelled_resolve)`; `crates/metal2vulkan-runtime/src/resolve.rs:482 (color)`; `crates/metal2vulkan-runtime/src/sample_copy.rs:177 (checked_twin)`; `crates/metal2vulkan-runtime/src/sample_copy.rs:205 (plan)`; `crates/metal2vulkan-runtime/src/sample_interleave.rs:296 (interleave_merge)`; `crates/metal2vulkan-runtime/src/shadow.rs:644 (unmerged)`; `crates/metal2vulkan-runtime/src/shadow.rs:651 (unmerged)`; `crates/metal2vulkan-runtime/src/texture.rs:2000 (texture_as)`; `crates/metal2vulkan-runtime/src/texture.rs:3540 (two_planes_refused)`; `crates/metal2vulkan-runtime/src/texture/decoded_twin.rs:498 (astc_texels)`; `crates/metal2vulkan-runtime/src/texture/decoded_twin.rs:534 (etc_texels)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:1810 (planned_heap_texture)`; `crates/metal2vulkan-runtime/src/texture/surface_two_planes.rs:80 (refused)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:115 (converted_storage)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:278 (ycbcr_write_shadow)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:384 (new_render_shadow)`; `crates/metal2vulkan-runtime/src/two_planes.rs:114 (unmeasured)`; `crates/metal2vulkan-runtime/src/view_plan.rs:380 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:393 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:400 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:410 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:420 (check_format)`; `crates/metal2vulkan-runtime/src/ycbcr.rs:285 (refused)`; `crates/metal2vulkan/src/bind/extended_shadow.rs:184 (extended_shadow_module)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1134 (plain_texture)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1814 (extended_sampler)`; `crates/metal2vulkan/src/bind/plan/resources.rs:193 (require_filter_features)`; `crates/metal2vulkan/src/bind/plan/resources.rs:959 (plain_texture)`; `crates/metal2vulkan/src/bind/sample_interleave.rs:304 (finish)`; `crates/metal2vulkan/src/bind/sample_interleave.rs:328 (interleave_split_module)`; `crates/metal2vulkan/src/bind/shadow_copy_in.rs:259 (shadow_copy_in_module)`; `crates/metal2vulkan/src/bind/unused_bits.rs:657 (unused_bits_module)`; `crates/metal2vulkan/src/lower/access/tile.rs:1029 (storage_format)`; `crates/metal2vulkan/src/lower/fragment/color.rs:160 (select_param)`; `crates/metal2vulkan/src/lower/fragment/color.rs:166 (select_param)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1138 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1159 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1165 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1171 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1196 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1371 (plan)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1762 (select_read)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1870 (select_output)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1897 (select_output)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1916 (select_output)`; `crates/metal2vulkan/src/lower/sampler/select.rs:1093 (select_extended)`; `crates/metal2vulkan/src/lower/sampler/select.rs:691 (texel_in)`; `crates/metal2vulkan/src/lower/stage_io/extended_color.rs:77 (plan)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2288 (entry)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:865 (zeroed_output)`; `crates/metal2vulkan/src/lower/stage_io/word_color.rs:83 (plan)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2342 (select)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2984 (cross_class)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3156 (select_image)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3326 (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3363 (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3696 (select_write)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1035 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1048 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1054 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:739 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:742 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:753 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:771 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:791 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:815 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:826 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:873 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:908 (atomic_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:917 (atomic_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1657 (vk_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1659 (vk_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1789 (candidates)`; `crates/metal2vulkan/src/metal/format/mod.rs:2745 (storage_choice_viewed)`; `crates/metal2vulkan/src/metal/format/mod.rs:2763 (held_storage_choice)`; `crates/metal2vulkan/src/metal/format/mod.rs:2771 (held_storage_choice)`; `crates/metal2vulkan/src/metal/format/mod.rs:2868 (held_storage_choice)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:1087 (extended_write_mask)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:428 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:474 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:546 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:957 (reads_alpha_to_coverage)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:978 (reads_alpha_to_coverage)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:449 (rotated_blend)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:593 (alpha_in_red_blend)` +- `feature::Format`: `crates/metal2vulkan-runtime/src/binding_view.rs:146 (binding_view)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:462 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:469 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:484 (check_formats)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:541 (pair_unit)`; `crates/metal2vulkan-runtime/src/blit_plan.rs:633 (plan_levels_copy)`; `crates/metal2vulkan-runtime/src/blit_texture.rs:2096 (through_buffer)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:519 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:582 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:614 (make_texture_over)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:851 (texture_buffer_texel)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:269 (colour_unit)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:297 (copy_unit)`; `crates/metal2vulkan-runtime/src/copy_plan.rs:343 (copy_unit)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:346 (scratch)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:526 (usable_twin)`; `crates/metal2vulkan-runtime/src/families/features.rs:1607 (read_write_tier)`; `crates/metal2vulkan-runtime/src/families/formats.rs:1628 (sparse_missing)`; `crates/metal2vulkan-runtime/src/families/formats.rs:227 (none)`; `crates/metal2vulkan-runtime/src/families/formats.rs:271 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:291 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:306 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:353 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:392 (answers)`; `crates/metal2vulkan-runtime/src/families/formats.rs:474 (atomic_gap)`; `crates/metal2vulkan-runtime/src/families/formats.rs:508 (lacking)`; `crates/metal2vulkan-runtime/src/families/formats.rs:522 (unsupported)`; `crates/metal2vulkan-runtime/src/image_plan.rs:544 (check_own_memory)`; `crates/metal2vulkan-runtime/src/image_plan.rs:670 (plan_held)`; `crates/metal2vulkan-runtime/src/image_plan.rs:787 (plan_held)`; `crates/metal2vulkan-runtime/src/image_plan.rs:907 (plan_held)`; `crates/metal2vulkan-runtime/src/render.rs:2155 (viewing)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1024 (check_target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1362 (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1698 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1791 (attachment_format)`; `crates/metal2vulkan-runtime/src/resolve.rs:392 (unmodelled_resolve)`; `crates/metal2vulkan-runtime/src/resolve.rs:482 (color)`; `crates/metal2vulkan-runtime/src/sample_copy.rs:177 (checked_twin)`; `crates/metal2vulkan-runtime/src/sample_copy.rs:205 (plan)`; `crates/metal2vulkan-runtime/src/sample_interleave.rs:296 (interleave_merge)`; `crates/metal2vulkan-runtime/src/shadow.rs:644 (unmerged)`; `crates/metal2vulkan-runtime/src/shadow.rs:651 (unmerged)`; `crates/metal2vulkan-runtime/src/texture.rs:2000 (texture_as)`; `crates/metal2vulkan-runtime/src/texture.rs:3540 (two_planes_refused)`; `crates/metal2vulkan-runtime/src/texture/decoded_twin.rs:498 (astc_texels)`; `crates/metal2vulkan-runtime/src/texture/decoded_twin.rs:534 (etc_texels)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:1810 (planned_heap_texture)`; `crates/metal2vulkan-runtime/src/texture/surface_two_planes.rs:80 (refused)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:115 (converted_storage)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:278 (ycbcr_write_shadow)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs:384 (new_render_shadow)`; `crates/metal2vulkan-runtime/src/two_planes.rs:120 (unmeasured)`; `crates/metal2vulkan-runtime/src/view_plan.rs:380 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:393 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:400 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:412 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:422 (check_format)`; `crates/metal2vulkan-runtime/src/ycbcr.rs:285 (refused)`; `crates/metal2vulkan/src/bind/extended_shadow.rs:184 (extended_shadow_module)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1134 (plain_texture)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1814 (extended_sampler)`; `crates/metal2vulkan/src/bind/plan/resources.rs:193 (require_filter_features)`; `crates/metal2vulkan/src/bind/plan/resources.rs:959 (plain_texture)`; `crates/metal2vulkan/src/bind/sample_interleave.rs:304 (finish)`; `crates/metal2vulkan/src/bind/sample_interleave.rs:328 (interleave_split_module)`; `crates/metal2vulkan/src/bind/shadow_copy_in.rs:259 (shadow_copy_in_module)`; `crates/metal2vulkan/src/bind/unused_bits.rs:687 (unused_bits_module)`; `crates/metal2vulkan/src/lower/access/tile.rs:1029 (storage_format)`; `crates/metal2vulkan/src/lower/fragment/color.rs:160 (select_param)`; `crates/metal2vulkan/src/lower/fragment/color.rs:166 (select_param)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1138 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1159 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1165 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1171 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1196 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1371 (plan)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1762 (select_read)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1870 (select_output)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1897 (select_output)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1916 (select_output)`; `crates/metal2vulkan/src/lower/sampler/select.rs:1093 (select_extended)`; `crates/metal2vulkan/src/lower/sampler/select.rs:691 (texel_in)`; `crates/metal2vulkan/src/lower/stage_io/extended_color.rs:77 (plan)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2288 (entry)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:865 (zeroed_output)`; `crates/metal2vulkan/src/lower/stage_io/word_color.rs:83 (plan)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2342 (select)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2984 (cross_class)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3156 (select_image)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3326 (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3363 (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3696 (select_write)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1035 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1048 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:1054 (declare_slot)`; `crates/metal2vulkan/src/lower/texture/slot.rs:739 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:742 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:753 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:771 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:791 (storage_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:815 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:826 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:873 (ulong_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:908 (atomic_format)`; `crates/metal2vulkan/src/lower/texture/slot.rs:917 (atomic_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1693 (vk_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1695 (vk_format)`; `crates/metal2vulkan/src/metal/format/mod.rs:1825 (candidates)`; `crates/metal2vulkan/src/metal/format/mod.rs:2783 (storage_choice_viewed)`; `crates/metal2vulkan/src/metal/format/mod.rs:2801 (held_storage_choice)`; `crates/metal2vulkan/src/metal/format/mod.rs:2809 (held_storage_choice)`; `crates/metal2vulkan/src/metal/format/mod.rs:2906 (held_storage_choice)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:1088 (extended_write_mask)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:428 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:474 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:546 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:957 (reads_alpha_to_coverage)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:978 (reads_alpha_to_coverage)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:449 (rotated_blend)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:593 (alpha_in_red_blend)` - `feature::DivergentImplicitLod`: `crates/metal2vulkan/src/lower/sampler/select.rs:352 (select_sampling)` - `feature::ImplicitLodOutsideFragment`: `crates/metal2vulkan/src/lower/sampler/constexpr.rs:136 (query_min_level)`; `crates/metal2vulkan/src/lower/sampler/select.rs:229 (query_level_measured)`; `crates/metal2vulkan/src/lower/sampler/select.rs:255 (query_min_level)` - `feature::MinLodClamp`: `crates/metal2vulkan/src/lower/sampler/select.rs:1572 (select_one)`; `crates/metal2vulkan/src/lower/sampler/select.rs:973 (min_lod)` @@ -348,21 +347,21 @@ Each refusal's sites, with the function that builds it. - `feature::SamplerLodBias`: `crates/metal2vulkan/src/lower/sampler/constexpr.rs:258 (constexpr_desc)`; `crates/metal2vulkan/src/lower/sampler/constexpr.rs:265 (constexpr_desc)`; `crates/metal2vulkan/src/lower/sampler/constexpr.rs:271 (constexpr_desc)` - `feature::SamplerCompare`: `crates/metal2vulkan/src/metal/sampler.rs:260 (check_sampler)` - `feature::PixelSamplerCompare`: `crates/metal2vulkan/src/lower/sampler/constexpr.rs:115 (lowered)` -- `feature::TexelBuffer`: `crates/metal2vulkan/src/bind/instantiate.rs:880 (texel_ranges)`; `crates/metal2vulkan/src/bind/instantiate.rs:886 (texel_ranges)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1147 (plain_texture)` +- `feature::TexelBuffer`: `crates/metal2vulkan/src/bind/instantiate.rs:879 (texel_ranges)`; `crates/metal2vulkan/src/bind/instantiate.rs:885 (texel_ranges)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1147 (plain_texture)` - `feature::RasterOrderGroups`: `crates/metal2vulkan/src/device/metal.rs:242 (unsupported_features)`; `crates/metal2vulkan/src/lower/fragment/rog.rs:151 (mode)`; `crates/metal2vulkan/src/lower/fragment/rog.rs:172 (mode)`; `crates/metal2vulkan/src/lower/fragment/snapshot.rs:158 (finish)` -- `feature::FramebufferFetch`: `crates/metal2vulkan-runtime/src/families/features.rs:1007 (state)`; `crates/metal2vulkan-runtime/src/render.rs:5709 (next_instance)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:116 (lacks)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:143 (new)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:514 (planes_merge)`; `crates/metal2vulkan/src/bind/extended_shadow.rs:190 (extended_shadow_module)`; `crates/metal2vulkan/src/bind/graphics.rs:1453 (plan)`; `crates/metal2vulkan/src/bind/graphics.rs:1490 (plan)`; `crates/metal2vulkan/src/bind/graphics.rs:1509 (plan)`; `crates/metal2vulkan/src/bind/sample_planes.rs:477 (finish)`; `crates/metal2vulkan/src/device/metal.rs:252 (unsupported_features)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1198 (unorm8)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1216 (unorm8)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1230 (unorm8)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1273 (packed16)`; `crates/metal2vulkan/src/lower/fragment/color.rs:215 (select_param)`; `crates/metal2vulkan/src/lower/fragment/color.rs:279 (unordered)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:195 (not_implemented)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:272 (depth_test_form)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:318 (stencil_test_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1024 (storage_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1114 (storage_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1151 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1716 (plan_sample)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:749 (not_implemented)`; `crates/metal2vulkan/src/pipeline/link/fetch.rs:164 (storage_attachments)` -- `feature::PrimitiveId`: `crates/metal2vulkan-runtime/src/families/features.rs:1115 (state)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:3112 (finish)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs:240 (check_primitive_id)` +- `feature::FramebufferFetch`: `crates/metal2vulkan-runtime/src/families/features.rs:1015 (state)`; `crates/metal2vulkan-runtime/src/render.rs:5709 (next_instance)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:120 (lacks)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:147 (new)`; `crates/metal2vulkan-runtime/src/sample_planes.rs:518 (planes_merge)`; `crates/metal2vulkan/src/bind/extended_shadow.rs:190 (extended_shadow_module)`; `crates/metal2vulkan/src/bind/graphics.rs:1453 (plan)`; `crates/metal2vulkan/src/bind/graphics.rs:1490 (plan)`; `crates/metal2vulkan/src/bind/graphics.rs:1509 (plan)`; `crates/metal2vulkan/src/bind/sample_planes.rs:477 (finish)`; `crates/metal2vulkan/src/device/metal.rs:252 (unsupported_features)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1198 (unorm8)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1216 (unorm8)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1230 (unorm8)`; `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:1273 (packed16)`; `crates/metal2vulkan/src/lower/fragment/color.rs:215 (select_param)`; `crates/metal2vulkan/src/lower/fragment/color.rs:279 (unordered)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:195 (not_implemented)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:272 (depth_test_form)`; `crates/metal2vulkan/src/lower/fragment/depth_test.rs:318 (stencil_test_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1024 (storage_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1114 (storage_form)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1151 (extended_range_blend)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1716 (plan_sample)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:749 (not_implemented)`; `crates/metal2vulkan/src/pipeline/link/fetch.rs:164 (storage_attachments)` +- `feature::PrimitiveId`: `crates/metal2vulkan-runtime/src/families/features.rs:1124 (state)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:3112 (finish)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs:240 (check_primitive_id)` - `feature::VertexAmplification`: `crates/metal2vulkan/src/bind/graphics.rs:3897 (multiview_instances)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:1281 (own_index_store)`; `crates/metal2vulkan/src/lower/tessellation/mod.rs:718 (select_param)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:258 (vertex_amplification)`; `crates/metal2vulkan/src/pipeline/link/tessellation/mod.rs:228 (control_plan)` - `feature::LayeredRendering`: `crates/metal2vulkan-runtime/src/render_pass.rs:1658 (target)`; `crates/metal2vulkan-runtime/src/render_state.rs:1078 (needs_viewports)`; `crates/metal2vulkan/src/lower/mesh/mod.rs:778 (target_index)`; `crates/metal2vulkan/src/lower/mesh/mod.rs:797 (target_index)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:1282 (own_index_store)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs:150 (not_implemented)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs:172 (refused)` - `feature::ClipDistance`: `crates/metal2vulkan/src/lower/mesh/mod.rs:934 (select)`; `crates/metal2vulkan/src/lower/mesh/mod.rs:942 (select)` -- `feature::DualSourceBlending`: `crates/metal2vulkan-runtime/src/families/formats.rs:386 (answers)`; `crates/metal2vulkan/src/metal/state.rs:37 (blend_factor)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:1144 (check_outputs)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:463 (rotated_blend)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:538 (rotated_blend)` +- `feature::DualSourceBlending`: `crates/metal2vulkan-runtime/src/families/formats.rs:386 (answers)`; `crates/metal2vulkan/src/metal/state.rs:37 (blend_factor)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:1145 (check_outputs)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:463 (rotated_blend)`; `crates/metal2vulkan/src/pipeline/rotated_blend.rs:538 (rotated_blend)` - `feature::Barycentrics`: `crates/metal2vulkan/src/device/metal.rs:263 (unsupported_features)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:1876 (input_builtin)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:742 (param)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs:148 (not_implemented)`; `crates/metal2vulkan/src/pipeline/link/geometry.rs:170 (refused)` -- `feature::StencilExport`: `crates/metal2vulkan-runtime/src/families/features.rs:1102 (state)`; `crates/metal2vulkan/src/bind/graphics.rs:2606 (shadow_stencil_words)`; `crates/metal2vulkan/src/lower/fragment/stencil.rs:157 (device_form)`; `crates/metal2vulkan/src/lower/fragment/stencil.rs:168 (not_implemented)`; `crates/metal2vulkan/src/pipeline/link/stencil.rs:55 (shadow_stencil)`; `crates/metal2vulkan/src/pipeline/link/stencil.rs:73 (shadow_stencil)` +- `feature::StencilExport`: `crates/metal2vulkan-runtime/src/families/features.rs:1111 (state)`; `crates/metal2vulkan/src/bind/graphics.rs:2606 (shadow_stencil_words)`; `crates/metal2vulkan/src/lower/fragment/stencil.rs:157 (device_form)`; `crates/metal2vulkan/src/lower/fragment/stencil.rs:168 (not_implemented)`; `crates/metal2vulkan/src/pipeline/link/stencil.rs:55 (shadow_stencil)`; `crates/metal2vulkan/src/pipeline/link/stencil.rs:73 (shadow_stencil)` - `feature::SampleRateShading`: `crates/metal2vulkan/src/pipeline/link/graphics.rs:832 (sample_invocations)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:834 (sample_invocations)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:916 (sample_invocations)` - `feature::PixelCoverageAtSampleRate`: `crates/metal2vulkan/src/lower/fragment/coverage.rs:291 (finish)`; `crates/metal2vulkan/src/lower/simd/mod.rs:754 (select_param)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:867 (sample_invocations)` - `feature::InterfaceComponents`: `crates/metal2vulkan/src/pipeline/compile/color_group.rs:202 (refusal)`; `crates/metal2vulkan/src/pipeline/link/graphics.rs:301 (graphics_state)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs:409 (assign)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs:90 (limit_error)` - `feature::UnmatchedVarying`: `crates/metal2vulkan/src/pipeline/link/varyings.rs:318 (mesh_fragment)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs:537 (varyings)`; `crates/metal2vulkan/src/pipeline/link/varyings.rs:548 (varyings)` -- `feature::KernelStageIn`: `crates/metal2vulkan-runtime/src/indirect_execute.rs:376 (record)`; `crates/metal2vulkan/src/bind/dispatch.rs:877 (instantiate)`; `crates/metal2vulkan/src/lower/stage_io/stage_in.rs:133 (select)` +- `feature::KernelStageIn`: `crates/metal2vulkan-runtime/src/indirect_execute.rs:350 (record)`; `crates/metal2vulkan/src/bind/dispatch.rs:877 (instantiate)`; `crates/metal2vulkan/src/lower/stage_io/stage_in.rs:133 (select)` - `feature::Tessellation`: `crates/metal2vulkan-air/src/canon/mod.rs:1256 (post_check)`; `crates/metal2vulkan-air/src/canon/mod.rs:1347 (post_check)`; `crates/metal2vulkan/src/bind/graphics.rs:3754 (tessellation_dispatch)`; `crates/metal2vulkan/src/lower/stage_io/fetch.rs:519 (select)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:1457 (primitive_id_output)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:1750 (input_builtin)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:799 (param)`; `crates/metal2vulkan/src/lower/tessellation/mod.rs:150 (not_implemented)`; `crates/metal2vulkan/src/lower/tessellation/mod.rs:489 (plan_entry)`; `crates/metal2vulkan/src/metal/vertex.rs:219 (fetch_as)`; `crates/metal2vulkan/src/pipeline/link/tessellation/mod.rs:212 (control_plan)`; `crates/metal2vulkan/src/pipeline/link/tessellation/mod.rs:292 (check_fragment)`; `crates/metal2vulkan/src/pipeline/link/tessellation/mod.rs:316 (push_offset)` - `feature::MeshShading`: `crates/metal2vulkan/src/bind/graphics.rs:1536 (plan)`; `crates/metal2vulkan/src/bind/graphics.rs:2966 (mesh_limit)`; `crates/metal2vulkan/src/lower/mesh/mod.rs:499 (check_payload)`; `crates/metal2vulkan/src/lower/mesh/mod.rs:538 (plan_entry)`; `crates/metal2vulkan/src/lower/mesh/mod.rs:572 (plan_entry)`; `crates/metal2vulkan/src/memory/plan.rs:2056 (reprs)`; `crates/metal2vulkan/src/pipeline/link/mesh.rs:95 (records)` - `feature::TileShading`: `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:521 (scratch)`; `crates/metal2vulkan/src/bind/plan/compute.rs:237 (tile_memory)`; `crates/metal2vulkan/src/lower/access/tile.rs:151 (not_implemented)`; `crates/metal2vulkan/src/lower/sync/barrier.rs:275 (tile_shading)`; `crates/metal2vulkan/src/pipeline/compile/api.rs:687 (tile_pipeline)` @@ -370,13 +369,13 @@ Each refusal's sites, with the function that builds it. - `feature::RayTracing`: `crates/metal2vulkan/src/bind/acceleration.rs:202 (instance_record)`; `crates/metal2vulkan/src/bind/acceleration.rs:216 (instance_record)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1087 (primitive_data_read)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1202 (instance_count)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1245 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1257 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1282 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1297 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:1312 (intersect)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:344 (slot_of)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:385 (select_param)`; `crates/metal2vulkan/src/lower/select.rs:899 (route_air)` - `feature::Tensors`: `crates/metal2vulkan-air/src/canon/matmul2d/synth.rs:32 (refuse)`; `crates/metal2vulkan/src/lower/select.rs:903 (route_air)` - `feature::RasterizationRateMap`: `crates/metal2vulkan/src/lower/fragment/mod.rs:925 (select)` -- `feature::GpuEncodedIndirectCommands`: `crates/metal2vulkan/src/bind/replay.rs:556 (preprocess)`; `crates/metal2vulkan/src/bind/replay.rs:796 (replay_preprocess_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs:280 (draw_replay_preprocess)`; `crates/metal2vulkan/src/bind/replay/draws.rs:482 (draw_replay_module)`; `crates/metal2vulkan/src/bind/replay/flat.rs:247 (flat_dispatch_module)`; `crates/metal2vulkan/src/bind/replay/merged.rs:242 (draw_merge_module)`; `crates/metal2vulkan/src/lower/access/encode.rs:394 (needs)`; `crates/metal2vulkan/src/lower/access/encode.rs:410 (needs)`; `crates/metal2vulkan/src/lower/access/encode.rs:527 (select_command)`; `crates/metal2vulkan/src/lower/access/mod.rs:1539 (plan_replay)`; `crates/metal2vulkan/src/lower/access/mod.rs:1562 (plan_replay)`; `crates/metal2vulkan/src/lower/access/mod.rs:1565 (plan_replay)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2613 (merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2669 (finish_merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:455 (param)`; `crates/metal2vulkan/src/pipeline/compile.rs:2110 (plan_one)`; `crates/metal2vulkan/src/pipeline/compile.rs:2115 (plan_one)` +- `feature::GpuEncodedIndirectCommands`: `crates/metal2vulkan/src/bind/replay.rs:556 (preprocess)`; `crates/metal2vulkan/src/bind/replay.rs:796 (replay_preprocess_module)`; `crates/metal2vulkan/src/bind/replay/draws.rs:280 (draw_replay_preprocess)`; `crates/metal2vulkan/src/bind/replay/draws.rs:482 (draw_replay_module)`; `crates/metal2vulkan/src/bind/replay/flat.rs:247 (flat_dispatch_module)`; `crates/metal2vulkan/src/bind/replay/merged.rs:242 (draw_merge_module)`; `crates/metal2vulkan/src/lower/access/encode.rs:393 (needs)`; `crates/metal2vulkan/src/lower/access/encode.rs:409 (needs)`; `crates/metal2vulkan/src/lower/access/encode.rs:526 (select_command)`; `crates/metal2vulkan/src/lower/access/mod.rs:1539 (plan_replay)`; `crates/metal2vulkan/src/lower/access/mod.rs:1562 (plan_replay)`; `crates/metal2vulkan/src/lower/access/mod.rs:1565 (plan_replay)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2613 (merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:2669 (finish_merged)`; `crates/metal2vulkan/src/lower/stage_io/plan.rs:455 (param)`; `crates/metal2vulkan/src/pipeline/compile.rs:2110 (plan_one)`; `crates/metal2vulkan/src/pipeline/compile.rs:2115 (plan_one)` - `feature::VulkanVersion`: `crates/metal2vulkan/src/ash_interop/query.rs:915 (query)`; `crates/metal2vulkan/src/device/derive.rs:105 (with_deviations)` - `feature::Constant`: `crates/metal2vulkan-air/src/bitcode/constants.rs:210 (record)`; `crates/metal2vulkan-air/src/bitcode/constants.rs:268 (record)`; `crates/metal2vulkan/src/error/mod.rs:255 (from)` - `feature::Attribute`: `crates/metal2vulkan-air/src/bitcode/attrs.rs:493 (known)`; `crates/metal2vulkan/src/error/mod.rs:256 (from)` - `feature::BitcodeRecord`: `crates/metal2vulkan-air/src/bitcode/attrs.rs:337 (decode_lists)`; `crates/metal2vulkan-air/src/bitcode/function.rs:572 (symtab)`; `crates/metal2vulkan-air/src/bitcode/metadata.rs:130 (decode)`; `crates/metal2vulkan-air/src/bitcode/metadata.rs:157 (decode)`; `crates/metal2vulkan-air/src/bitcode/module.rs:727 (check_bodies)`; `crates/metal2vulkan-air/src/bitcode/module.rs:872 (symtab)`; `crates/metal2vulkan/src/error/mod.rs:257 (from)` - `feature::SyncScope`: `crates/metal2vulkan-air/src/bitcode/function.rs:1255 (atomic)`; `crates/metal2vulkan/src/error/mod.rs:258 (from)` -- `feature::SubgroupOperations`: `crates/metal2vulkan-runtime/src/families/features.rs:1686 (simd)`; `crates/metal2vulkan/src/lower/simd/mod.rs:407 (finish)`; `crates/metal2vulkan/src/lower/simd/mod.rs:466 (full_quads)`; `crates/metal2vulkan/src/lower/simd/mod.rs:990 (select_group)` +- `feature::SubgroupOperations`: `crates/metal2vulkan-runtime/src/families/features.rs:1695 (simd)`; `crates/metal2vulkan/src/lower/simd/mod.rs:407 (finish)`; `crates/metal2vulkan/src/lower/simd/mod.rs:466 (full_quads)`; `crates/metal2vulkan/src/lower/simd/mod.rs:990 (select_group)` - `feature::DirectCall`: `crates/metal2vulkan-air/src/canon/mod.rs:1319 (post_check)` - `feature::WideSwitchLiteral`: `crates/metal2vulkan/src/structurize/emit.rs:207 (check_tree)` - `feature::Lowering`: `crates/metal2vulkan/src/bind/plan/resources.rs:762 (level_views)`; `crates/metal2vulkan/src/lower/access/handle.rs:1062 (texture_target)`; `crates/metal2vulkan/src/lower/access/handle.rs:1073 (sampler_target)`; `crates/metal2vulkan/src/lower/access/handle.rs:318 (domain_kind)`; `crates/metal2vulkan/src/lower/access/imageblock.rs:175 (operand)`; `crates/metal2vulkan/src/lower/access/mod.rs:571 (not_lowered)`; `crates/metal2vulkan/src/lower/access/pulled.rs:76 (share)`; `crates/metal2vulkan/src/lower/arith/legal.rs:53 (not_lowered)`; `crates/metal2vulkan/src/lower/dispatch.rs:113 (not_lowered)`; `crates/metal2vulkan/src/lower/fragment/discard.rs:144 (not_lowered)`; `crates/metal2vulkan/src/lower/fragment/discard.rs:653 (plan)`; `crates/metal2vulkan/src/lower/fragment/mod.rs:123 (not_lowered)`; `crates/metal2vulkan/src/lower/fragment/snapshot.rs:168 (finish)`; `crates/metal2vulkan/src/lower/mesh/mod.rs:147 (not_lowered)`; `crates/metal2vulkan/src/lower/raytracing/mod.rs:126 (not_lowered)`; `crates/metal2vulkan/src/lower/sampler/mod.rs:212 (refuse)`; `crates/metal2vulkan/src/lower/sampler/select.rs:30 (refuse)`; `crates/metal2vulkan/src/lower/select.rs:829 (not_lowered)`; `crates/metal2vulkan/src/lower/select.rs:918 (route_air)`; `crates/metal2vulkan/src/lower/simd/mod.rs:136 (not_lowered)`; `crates/metal2vulkan/src/lower/simd/mod.rs:747 (select_param)`; `crates/metal2vulkan/src/lower/simd/workgroup.rs:353 (check)`; `crates/metal2vulkan/src/lower/stage_io/fetch.rs:96 (not_lowered)`; `crates/metal2vulkan/src/lower/stage_io/mod.rs:177 (not_lowered)`; `crates/metal2vulkan/src/lower/sync/barrier.rs:72 (not_lowered)`; `crates/metal2vulkan/src/lower/sync/memory_model.rs:269 (not_implemented)`; `crates/metal2vulkan/src/lower/sync/memory_model.rs:310 (select)`; `crates/metal2vulkan/src/lower/tessellation/mod.rs:146 (not_lowered)`; `crates/metal2vulkan/src/lower/texture/mod.rs:180 (refuse)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3665 (select_write)`; `crates/metal2vulkan/src/memory/alloca.rs:54 (not_lowered)`; `crates/metal2vulkan/src/memory/leaf.rs:183 (not_lowered)`; `crates/metal2vulkan/src/memory/plan.rs:490 (not_lowered)`; `crates/metal2vulkan/src/memory/provenance.rs:665 (not_lowered)`; `crates/metal2vulkan/src/pipeline/link/tessellation/mod.rs:96 (patch_fetch_projection)` @@ -396,13 +395,13 @@ Each refusal's sites, with the function that builds it. - `feature::SparseTexture`: `crates/metal2vulkan/src/bind/plan/slots.rs:583 (check_sparse_textures)`; `crates/metal2vulkan/src/bind/plan/slots.rs:607 (check_sparse_textures)` - `feature::TextureSize`: `crates/metal2vulkan-runtime/src/image_plan.rs:1196 (check_image_limits)` - `feature::TextureSampleCount`: `crates/metal2vulkan-runtime/src/image_plan.rs:1244 (check_image_limits)`; `crates/metal2vulkan-runtime/src/image_plan.rs:598 (plan_held)`; `crates/metal2vulkan-runtime/src/image_plan.rs:608 (plan_held)` -- `feature::TextureView`: `crates/metal2vulkan-runtime/src/binding_view.rs:156 (binding_view)`; `crates/metal2vulkan-runtime/src/texture.rs:5032 (view)`; `crates/metal2vulkan-runtime/src/texture/decoded_twin.rs:1420 (make_second_twin)`; `crates/metal2vulkan-runtime/src/texture/view_shadow.rs:298 (apart_refusal)`; `crates/metal2vulkan-runtime/src/view_plan.rs:431 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:481 (check_view)`; `crates/metal2vulkan-runtime/src/view_plan.rs:503 (check_view)` +- `feature::TextureView`: `crates/metal2vulkan-runtime/src/binding_view.rs:156 (binding_view)`; `crates/metal2vulkan-runtime/src/texture.rs:5032 (view)`; `crates/metal2vulkan-runtime/src/texture/decoded_twin.rs:1420 (make_second_twin)`; `crates/metal2vulkan-runtime/src/texture/view_shadow.rs:298 (apart_refusal)`; `crates/metal2vulkan-runtime/src/view_plan.rs:433 (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs:483 (check_view)`; `crates/metal2vulkan-runtime/src/view_plan.rs:505 (check_view)` - `feature::TextureSwizzle`: `crates/metal2vulkan-runtime/src/binding_view.rs:167 (binding_view)`; `crates/metal2vulkan-runtime/src/texture.rs:980 (may_view)`; `crates/metal2vulkan/src/bind/plan/resources.rs:1102 (plain_texture)`; `crates/metal2vulkan/src/lower/sampler/select.rs:2587 (select_one)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3391 (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs:3738 (select_write)`; `crates/metal2vulkan/src/lower/texture/slice.rs:307 (select)` -- `feature::MipmapGeneration`: `crates/metal2vulkan-runtime/src/blit_texture.rs:1787 (mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_pick.rs:37 (pick_mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs:262 (plan_mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs:270 (plan_mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs:275 (plan_mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs:304 (plan_mipmaps)`; `crates/metal2vulkan/src/bind/mipmap_filter.rs:973 (mipmap_filter_module)` +- `feature::MipmapGeneration`: `crates/metal2vulkan-runtime/src/blit_texture.rs:1796 (mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_pick.rs:37 (pick_mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs:262 (plan_mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs:270 (plan_mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs:275 (plan_mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs:304 (plan_mipmaps)`; `crates/metal2vulkan/src/bind/mipmap_filter.rs:973 (mipmap_filter_module)` - `feature::HostMemory`: `crates/metal2vulkan-runtime/src/host_memory.rs:393 (not_importable)`; `crates/metal2vulkan-runtime/src/host_memory.rs:433 (refuse_unwritable)`; `crates/metal2vulkan-runtime/src/host_memory.rs:652 (new)`; `crates/metal2vulkan-runtime/src/host_memory.rs:657 (new)`; `crates/metal2vulkan-runtime/src/host_memory.rs:675 (new)` -- `feature::GpuTimes`: `crates/metal2vulkan-runtime/src/command_buffer/mod.rs:2555 (gpu_times)` +- `feature::GpuTimes`: `crates/metal2vulkan-runtime/src/command_buffer/mod.rs:2558 (gpu_times)` - `feature::CountingVisibility`: `crates/metal2vulkan-runtime/src/visibility.rs:452 (check_mode)` -- `feature::ViewFormatReinterpretation`: `crates/metal2vulkan-runtime/src/view_plan.rs:568 (reinterpretation_refused)` +- `feature::ViewFormatReinterpretation`: `crates/metal2vulkan-runtime/src/view_plan.rs:570 (reinterpretation_refused)` - `feature::SeparateMultisampledDepthStencil`: `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:188 (sampled_candidate)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:294 (by_draws)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:336 (scratch)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:376 (scratch)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:777 (plan)`; `crates/metal2vulkan-runtime/src/nan_clear.rs:651 (nan_write)`; `crates/metal2vulkan-runtime/src/texture/signed_depth.rs:191 (sample_strip)` - `feature::PixelCoverage`: `crates/metal2vulkan/src/pipeline/link/graphics.rs:771 (split_pixel_fragments)` - `feature::CentroidVarying`: `crates/metal2vulkan/src/pipeline/link/graphics.rs:789 (split_pixel_fragments)` @@ -415,7 +414,7 @@ Each refusal's sites, with the function that builds it. - `feature::ViewportDepthRange`: `crates/metal2vulkan-runtime/src/render_state.rs:1186 (depth_ranges_refused)` - `feature::UndeclaredTextureUsage`: `crates/metal2vulkan-runtime/src/binding_view.rs:141 (binding_view)`; `crates/metal2vulkan-runtime/src/texture/usage_shadow.rs:72 (refused)` - `feature::RenderTargetSize`: `crates/metal2vulkan-runtime/src/render_pass.rs:1264 (framebuffer_fits)` -- `feature::IndirectRenderState`: `crates/metal2vulkan/src/lower/access/encode.rs:568 (select_command)` +- `feature::IndirectRenderState`: `crates/metal2vulkan/src/lower/access/encode.rs:567 (select_command)` - `feature::GlobalBuiltinInFragment`: `crates/metal2vulkan/src/lower/select.rs:912 (route_air)` - `feature::PrivateRenderState`: `crates/metal2vulkan/src/bind/heap.rs:1300 (array)`; `crates/metal2vulkan/src/bind/plan/resources.rs:887 (write_rounding)`; `crates/metal2vulkan/src/lower/texture/mod.rs:2902 (mode_rounded_write)`; `crates/metal2vulkan/src/pipeline/private_state.rs:46 (refused)` - `feature::ExtendedRangeBlend`: `crates/metal2vulkan/src/lower/arith/extended_range/blend.rs:305 (refused)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1553 (plan)`; `crates/metal2vulkan/src/lower/fragment/fetch.rs:1556 (plan)`; `crates/metal2vulkan/src/lower/fragment/input_blend.rs:153 (plan)` @@ -423,7 +422,7 @@ Each refusal's sites, with the function that builds it. - `feature::CommandPredication`: `crates/metal2vulkan/src/bind/replay/predication.rs:414 (predication_step_module)` - `feature::ProgramScopeBinding`: `crates/metal2vulkan-air/src/abi/module.rs:77 (decode)`; `crates/metal2vulkan/src/error/mod.rs:267 (from)` - `feature::SeqCstFence`: `crates/metal2vulkan/src/lower/sync/barrier.rs:443 (require_seq_cst)` -- `gap::Textures`: `crates/metal2vulkan-runtime/src/blit_texture.rs:163 (check_depth_view)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:1554 (view_usage)`; `crates/metal2vulkan-runtime/src/pipeline/mod.rs:1522 (compile_error)`; `crates/metal2vulkan-runtime/src/texture.rs:1445 (image_error)`; `crates/metal2vulkan-runtime/src/texture.rs:2174 (storage_over_buffer)`; `crates/metal2vulkan-runtime/src/texture.rs:2986 (new_image_starting)`; `crates/metal2vulkan-runtime/src/texture.rs:4030 (image)`; `crates/metal2vulkan-runtime/src/texture.rs:5503 (host_copy)`; `crates/metal2vulkan-runtime/src/texture/surface_two_planes.rs:207 (new_surface_planes_texture)` +- `gap::Textures`: `crates/metal2vulkan-runtime/src/blit_texture.rs:163 (check_depth_view)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:1554 (view_usage)`; `crates/metal2vulkan-runtime/src/pipeline/mod.rs:1499 (compile_error)`; `crates/metal2vulkan-runtime/src/texture.rs:1445 (image_error)`; `crates/metal2vulkan-runtime/src/texture.rs:2174 (storage_over_buffer)`; `crates/metal2vulkan-runtime/src/texture.rs:2986 (new_image_starting)`; `crates/metal2vulkan-runtime/src/texture.rs:4030 (image)`; `crates/metal2vulkan-runtime/src/texture.rs:5508 (host_copy)`; `crates/metal2vulkan-runtime/src/texture/surface_two_planes.rs:207 (new_surface_planes_texture)` - `gap::ResourceHeap`: `crates/metal2vulkan-runtime/src/binding.rs:2016 (descriptor)` - `gap::SparseHeaps`: `crates/metal2vulkan-runtime/src/sparse/encoder.rs:458 (first_slice)`; `crates/metal2vulkan-runtime/src/texture.rs:1629 (plan_sparse_texture)`; `crates/metal2vulkan-runtime/src/texture.rs:4722 (make_aliasable)` - `gap::SparseTileMaps`: `crates/metal2vulkan-runtime/src/binding.rs:553 (slot_tile_map)`; `crates/metal2vulkan-runtime/src/sparse/texture.rs:30 (sparse_refusal)`; `crates/metal2vulkan-runtime/src/texture.rs:1662 (plan_sparse_texture)` @@ -431,15 +430,15 @@ Each refusal's sites, with the function that builds it. - `gap::HeapTextureAlignment`: `crates/metal2vulkan-runtime/src/texture/heap.rs:980 (check_heap_base)` - `gap::HeapTextureMemory`: `crates/metal2vulkan-runtime/src/texture/heap.rs:1418 (heap_plan)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:1425 (heap_plan)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:1919 (host_heap_plan)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:2132 (memory_shadow)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:489 (memory_refusal)` - `gap::FunctionTablePastMaxBufferLength`: `crates/metal2vulkan-runtime/src/function_table.rs:622 (past_limit)` -- `gap::IndirectCommandBufferPastMaxBufferLength`: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:522 (new_indirect_command_buffer)` -- `gap::IndirectRenderCommands`: `crates/metal2vulkan-runtime/src/compute.rs:1091 (execute_range)`; `crates/metal2vulkan-runtime/src/compute.rs:1171 (execute_indirect_range)`; `crates/metal2vulkan-runtime/src/depth_stencil.rs:85 (gpu_resource_id)`; `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:4344 (render_state)`; `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:517 (new_indirect_command_buffer)`; `crates/metal2vulkan-runtime/src/pipeline/mod.rs:1529 (compile_error)`; `crates/metal2vulkan-runtime/src/render.rs:6979 (draw_resident)`; `crates/metal2vulkan-runtime/src/render.rs:7342 (draw_resident)`; `crates/metal2vulkan-runtime/src/render.rs:7747 (draw_resident)`; `crates/metal2vulkan-runtime/src/render.rs:8196 (draw_resident)`; `crates/metal2vulkan-runtime/src/render/executions.rs:1100 (back_memoryless)`; `crates/metal2vulkan-runtime/src/render/executions.rs:2003 (record)`; `crates/metal2vulkan-runtime/src/render/executions.rs:2046 (record)`; `crates/metal2vulkan-runtime/src/render/executions.rs:2894 (record_forms)`; `crates/metal2vulkan-runtime/src/render/executions.rs:380 (execute_range)`; `crates/metal2vulkan-runtime/src/render/executions.rs:439 (execute_indirect_range)`; `crates/metal2vulkan-runtime/src/render/executions.rs:454 (execute_indirect_range)` -- `gap::IndirectImageblockSize`: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:3351 (set_imageblock_size)` +- `gap::IndirectCommandBufferPastMaxBufferLength`: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:516 (new_indirect_command_buffer)` +- `gap::IndirectRenderCommands`: `crates/metal2vulkan-runtime/src/compute.rs:1084 (execute_range)`; `crates/metal2vulkan-runtime/src/compute.rs:1163 (execute_indirect_range)`; `crates/metal2vulkan-runtime/src/depth_stencil.rs:85 (gpu_resource_id)`; `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:3638 (render_state)`; `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:511 (new_indirect_command_buffer)`; `crates/metal2vulkan-runtime/src/pipeline/mod.rs:1506 (compile_error)`; `crates/metal2vulkan-runtime/src/render.rs:6979 (draw_resident)`; `crates/metal2vulkan-runtime/src/render.rs:7342 (draw_resident)`; `crates/metal2vulkan-runtime/src/render.rs:7747 (draw_resident)`; `crates/metal2vulkan-runtime/src/render.rs:8196 (draw_resident)`; `crates/metal2vulkan-runtime/src/render/executions.rs:1086 (back_memoryless)`; `crates/metal2vulkan-runtime/src/render/executions.rs:1989 (record)`; `crates/metal2vulkan-runtime/src/render/executions.rs:2032 (record)`; `crates/metal2vulkan-runtime/src/render/executions.rs:2827 (record_forms)`; `crates/metal2vulkan-runtime/src/render/executions.rs:375 (execute_range)`; `crates/metal2vulkan-runtime/src/render/executions.rs:434 (execute_indirect_range)`; `crates/metal2vulkan-runtime/src/render/executions.rs:449 (execute_indirect_range)` +- `gap::IndirectImageblockSize`: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs:2757 (set_imageblock_size)` - `gap::CommandReplay`: `crates/metal2vulkan-runtime/src/binding.rs:694 (bind)`; `crates/metal2vulkan-runtime/src/binding.rs:697 (bind)` - `gap::RenderAttachments`: `crates/metal2vulkan-runtime/src/binding.rs:1839 (unexpected)` - `gap::AccelerationStructures`: `crates/metal2vulkan-runtime/src/binding.rs:1842 (unexpected)` - `gap::FeatureEnable`: `crates/metal2vulkan-runtime/src/enables.rs:1155 (of)` - `gap::ExtensionEnable`: `crates/metal2vulkan-runtime/src/enables.rs:1146 (of)` -- `gap::Render`: `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:404 (stand_in_as)`; `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:460 (stand_in_as)`; `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:684 (check_copies)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:796 (attachment_twin)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:283 (check_sizes)`; `crates/metal2vulkan-runtime/src/kept_bytes.rs:138 (settle)`; `crates/metal2vulkan-runtime/src/linear_attachment.rs:293 (settle)`; `crates/metal2vulkan-runtime/src/nan_clear.rs:197 (plan)`; `crates/metal2vulkan-runtime/src/pipeline/render.rs:1150 (imageblock_sample_length)`; `crates/metal2vulkan-runtime/src/render.rs:2086 (check_pipeline)`; `crates/metal2vulkan-runtime/src/render.rs:5755 (next_instance)`; `crates/metal2vulkan-runtime/src/render.rs:7436 (draw_resident)`; `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:517 (scratch)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1306 (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1665 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1719 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1780 (attachment_format)`; `crates/metal2vulkan-runtime/src/render_pass.rs:2013 (depth_stencil)`; `crates/metal2vulkan-runtime/src/resolve.rs:1010 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:1027 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:1091 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:901 (attach)`; `crates/metal2vulkan-runtime/src/resolve.rs:969 (color_copy)` +- `gap::Render`: `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:404 (stand_in_as)`; `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:460 (stand_in_as)`; `crates/metal2vulkan-runtime/src/attachment_stand_in.rs:684 (check_copies)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:796 (attachment_twin)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:283 (check_sizes)`; `crates/metal2vulkan-runtime/src/kept_bytes.rs:138 (settle)`; `crates/metal2vulkan-runtime/src/linear_attachment.rs:293 (settle)`; `crates/metal2vulkan-runtime/src/nan_clear.rs:197 (plan)`; `crates/metal2vulkan-runtime/src/pipeline/render.rs:1131 (imageblock_sample_length)`; `crates/metal2vulkan-runtime/src/render.rs:2086 (check_pipeline)`; `crates/metal2vulkan-runtime/src/render.rs:5755 (next_instance)`; `crates/metal2vulkan-runtime/src/render.rs:7436 (draw_resident)`; `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:517 (scratch)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1306 (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1665 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1719 (target)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1780 (attachment_format)`; `crates/metal2vulkan-runtime/src/render_pass.rs:2013 (depth_stencil)`; `crates/metal2vulkan-runtime/src/resolve.rs:1010 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:1027 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:1091 (destination)`; `crates/metal2vulkan-runtime/src/resolve.rs:901 (attach)`; `crates/metal2vulkan-runtime/src/resolve.rs:969 (color_copy)` - `gap::TexelsPastBufferLength`: `crates/metal2vulkan-runtime/src/buffer_texture.rs:261 (refusal_error)`; `crates/metal2vulkan-runtime/src/texture/surface_depth.rs:105 (surface_depth_twin)` - `gap::OverlappingSurfaceRows`: `crates/metal2vulkan-runtime/src/buffer_texture.rs:263 (refusal_error)` - `gap::SamplePositionsAtBegin`: `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs:145 (stencil_scratch)`; `crates/metal2vulkan-runtime/src/render_pass.rs:1850 (positioned_stand_in)`; `crates/metal2vulkan-runtime/src/sample_positions.rs:185 (grid)` @@ -453,23 +452,23 @@ Each refusal's sites, with the function that builds it. - `gap::TileAtSampleCount`: `crates/metal2vulkan-runtime/src/render_pass.rs:1600 (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs:930` - `gap::ImageblockMasters`: `crates/metal2vulkan-runtime/src/render.rs:7115 (draw_resident)`; `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:930 (dispatch_tiles_resident)` - `gap::TileAndFragmentImageblocks`: `crates/metal2vulkan-runtime/src/render.rs:7107 (draw_resident)`; `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:797 (dispatch_tiles_resident)`; `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs:922 (dispatch_tiles_resident)` -- `gap::Metal4Api`: `crates/metal2vulkan-runtime/src/families/features.rs:1460 (state)`; `crates/metal2vulkan-runtime/src/families/limits.rs:1022 (state)`; `crates/metal2vulkan-runtime/src/families/mod.rs:362 (audit)` +- `gap::Metal4Api`: `crates/metal2vulkan-runtime/src/families/features.rs:1469 (state)`; `crates/metal2vulkan-runtime/src/families/limits.rs:1022 (state)`; `crates/metal2vulkan-runtime/src/families/mod.rs:362 (audit)` - `gap::CounterSampleBuffers`: `crates/metal2vulkan-runtime/src/families/limits.rs:1013 (state)` -- `gap::ResidencySets`: `crates/metal2vulkan-runtime/src/families/features.rs:1442 (state)`; `crates/metal2vulkan-runtime/src/families/limits.rs:1015 (state)` -- `gap::TextureAccessCounters`: `crates/metal2vulkan-runtime/src/families/features.rs:1429 (state)`; `crates/metal2vulkan-runtime/src/families/features.rs:1434 (state)` -- `gap::IoCommandQueues`: `crates/metal2vulkan-runtime/src/families/features.rs:1439 (state)`; `crates/metal2vulkan-runtime/src/families/limits.rs:1020 (state)` -- `gap::TextureViewPools`: `crates/metal2vulkan-runtime/src/families/features.rs:1443 (state)`; `crates/metal2vulkan-runtime/src/families/limits.rs:1021 (state)` -- `gap::ColorAttachmentMapping`: `crates/metal2vulkan-runtime/src/families/features.rs:1444 (state)` -- `gap::LossyTextureCompression`: `crates/metal2vulkan-runtime/src/families/features.rs:1438 (state)` -- `gap::ShaderValidation`: `crates/metal2vulkan-runtime/src/families/features.rs:1440 (state)` -- `gap::ShaderLogging`: `crates/metal2vulkan-runtime/src/families/features.rs:1441 (state)` -- `gap::DeviceNotifications`: `crates/metal2vulkan-runtime/src/families/features.rs:1445 (state)` +- `gap::ResidencySets`: `crates/metal2vulkan-runtime/src/families/features.rs:1451 (state)`; `crates/metal2vulkan-runtime/src/families/limits.rs:1015 (state)` +- `gap::TextureAccessCounters`: `crates/metal2vulkan-runtime/src/families/features.rs:1438 (state)`; `crates/metal2vulkan-runtime/src/families/features.rs:1443 (state)` +- `gap::IoCommandQueues`: `crates/metal2vulkan-runtime/src/families/features.rs:1448 (state)`; `crates/metal2vulkan-runtime/src/families/limits.rs:1020 (state)` +- `gap::TextureViewPools`: `crates/metal2vulkan-runtime/src/families/features.rs:1452 (state)`; `crates/metal2vulkan-runtime/src/families/limits.rs:1021 (state)` +- `gap::ColorAttachmentMapping`: `crates/metal2vulkan-runtime/src/families/features.rs:1453 (state)` +- `gap::LossyTextureCompression`: `crates/metal2vulkan-runtime/src/families/features.rs:1447 (state)` +- `gap::ShaderValidation`: `crates/metal2vulkan-runtime/src/families/features.rs:1449 (state)` +- `gap::ShaderLogging`: `crates/metal2vulkan-runtime/src/families/features.rs:1450 (state)` +- `gap::DeviceNotifications`: `crates/metal2vulkan-runtime/src/families/features.rs:1454 (state)` - `gap::RateMapRegions`: `crates/metal2vulkan-runtime/src/rate_mapped_pass.rs:349 (refusal)` - `gap::LayeredPass`: `crates/metal2vulkan-runtime/src/color_resolve.rs:890 (plan)` - `gap::FunctionOptions`: `crates/metal2vulkan-runtime/src/library.rs:215 (new_function_with_descriptor)` -- `gap::OverlappingTextureCopies`: `crates/metal2vulkan-runtime/src/blit_texture.rs:1242 (texture_copies_of_bytes)` +- `gap::OverlappingTextureCopies`: `crates/metal2vulkan-runtime/src/blit_texture.rs:1251 (texture_copies_of_bytes)` - `gap::RebindTextures`: `crates/metal2vulkan-runtime/src/buffer_descriptor.rs:600 (rebind_host_pages)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:2431 (rebound_heap_images)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:2446 (rebound_heap_images)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:2457 (rebound_heap_images)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:2500 (dma_buf_heap_images_again)` -- `gap::PvrtcBlockOrder`: `crates/metal2vulkan-runtime/src/texture.rs:5575 (host_copy)` +- `gap::PvrtcBlockOrder`: `crates/metal2vulkan-runtime/src/texture.rs:5580 (host_copy)` - `gap::DecodedHeapTexture`: `crates/metal2vulkan-runtime/src/texture.rs:1637 (plan_sparse_texture)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:1281 (heap_plan)` - `gap::VertexFetchPast4GiB`: `crates/metal2vulkan-runtime/src/render/vertex_reach.rs:72 (check_vertex_reach)` - `gap::StageInFetchPast4GiB`: `crates/metal2vulkan-runtime/src/fetch_reach.rs:126 (check_stage_in_reach)` @@ -477,37 +476,36 @@ Each refusal's sites, with the function that builds it. - `gap::LibrarySource`: `crates/metal2vulkan-runtime/src/library.rs:107 (new_library_with_source)` - `gap::RestartedStrip`: `crates/metal2vulkan-runtime/src/index_rewrite.rs:110 (new)`; `crates/metal2vulkan-runtime/src/render.rs:7219 (draw_resident)` - `gap::PrimitiveIdIndices`: `crates/metal2vulkan-runtime/src/render.rs:7596 (draw_resident)` -- `gap::RotatedTexture`: `crates/metal2vulkan-runtime/src/blit_texture.rs:1571 (texel_copies)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:715 (turned_plane)`; `crates/metal2vulkan-runtime/src/rotated.rs:185 (new)`; `crates/metal2vulkan-runtime/src/rotated.rs:201 (new)`; `crates/metal2vulkan-runtime/src/shadow.rs:638 (unmerged)`; `crates/metal2vulkan-runtime/src/texture.rs:4990 (view)`; `crates/metal2vulkan-runtime/src/texture/rotation.rs:100 (check_rotated_reach)`; `crates/metal2vulkan-runtime/src/texture/rotation.rs:322 (copied_image)`; `crates/metal2vulkan-runtime/src/texture/usage_shadow.rs:238 (new_usage_shadow)` +- `gap::RotatedTexture`: `crates/metal2vulkan-runtime/src/blit_texture.rs:1580 (texel_copies)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:715 (turned_plane)`; `crates/metal2vulkan-runtime/src/rotated.rs:185 (new)`; `crates/metal2vulkan-runtime/src/rotated.rs:201 (new)`; `crates/metal2vulkan-runtime/src/shadow.rs:638 (unmerged)`; `crates/metal2vulkan-runtime/src/texture.rs:4990 (view)`; `crates/metal2vulkan-runtime/src/texture/rotation.rs:100 (check_rotated_reach)`; `crates/metal2vulkan-runtime/src/texture/rotation.rs:322 (copied_image)`; `crates/metal2vulkan-runtime/src/texture/usage_shadow.rs:238 (new_usage_shadow)` - `gap::DetachTextures`: `crates/metal2vulkan-runtime/src/buffer_descriptor.rs:604 (rebind_host_pages)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs:622 (make_texture_over)`; `crates/metal2vulkan-runtime/src/detach.rs:152 (detach_host_pages)`; `crates/metal2vulkan-runtime/src/texture/heap.rs:2639 (heap_texture_at)`; `crates/metal2vulkan-runtime/src/texture/stand_in.rs:143 (new_stand_in)`; `crates/metal2vulkan-runtime/src/texture/stand_in.rs:248 (stand_in_while_detached)`; `crates/metal2vulkan-runtime/src/texture/stand_in.rs:298 (stand_ins)`; `crates/metal2vulkan-runtime/src/texture/stand_in.rs:304 (stand_ins)` - `gap::TextureBufferLevels`: `crates/metal2vulkan-runtime/src/texture_descriptor.rs:540 (check_made)` - `gap::WriteSwizzle`: `crates/metal2vulkan-runtime/src/texture_descriptor.rs:547 (check_made)` - `gap::DetachedTexelAccess`: `crates/metal2vulkan-runtime/src/texture.rs:4820 (refuse_detached_texels)` -- `gap::SurfaceDepthStencil`: `crates/metal2vulkan-runtime/src/blit_texture.rs:236 (unit)`; `crates/metal2vulkan-runtime/src/texture/surface_depth.rs:57 (surface_depth_twin)` +- `gap::SurfaceDepthStencil`: `crates/metal2vulkan-runtime/src/blit_texture.rs:240 (unit)`; `crates/metal2vulkan-runtime/src/texture/surface_depth.rs:57 (surface_depth_twin)` - `gap::HostHeapUncompressedMultisample`: `crates/metal2vulkan-runtime/src/texture/heap.rs:1924 (host_heap_plan)` - `gap::PredicationUnbalanced`: `crates/metal2vulkan-runtime/src/predication.rs:371 (nil)`; `crates/metal2vulkan-runtime/src/predication.rs:403 (start_else)`; `crates/metal2vulkan-runtime/src/predication.rs:455 (end_if)`; `crates/metal2vulkan-runtime/src/predication.rs:575 (end_loop)` - `gap::PredicationOpenAtUnitEnd`: `crates/metal2vulkan-runtime/src/predication.rs:280 (commit_refusal)`; `crates/metal2vulkan-runtime/src/predication.rs:296 (commit)` - `gap::PredicationWordPastBuffer`: `crates/metal2vulkan-runtime/src/predication.rs:139 (new)` - `gap::PredicatedLoopDepth`: `crates/metal2vulkan-runtime/src/predication.rs:483 (start_loop)` - `gap::PredicatedLoopAcrossEncoders`: `crates/metal2vulkan-runtime/src/predication.rs:284 (commit_refusal)`; `crates/metal2vulkan-runtime/src/predication.rs:300 (commit)` -- `gap::MultisampledBufferCopy`: `crates/metal2vulkan-runtime/src/blit_texture.rs:485 (copy_from_buffer_to_texture)`; `crates/metal2vulkan-runtime/src/blit_texture.rs:641 (copy_from_texture_to_buffer)` +- `gap::MultisampledBufferCopy`: `crates/metal2vulkan-runtime/src/blit_texture.rs:489 (copy_from_buffer_to_texture)`; `crates/metal2vulkan-runtime/src/blit_texture.rs:645 (copy_from_texture_to_buffer)` - `gap::ColorAttachmentGroups`: `crates/metal2vulkan-runtime/src/render/color_groups.rs:106 (gap)` -- `apple::ProtectedContent`: `crates/metal2vulkan-runtime/src/apple_only.rs:200 (check)` -- `apple::LineWidth`: `crates/metal2vulkan-runtime/src/apple_only.rs:202 (check)` -- `apple::ProvokingVertexMode`: `crates/metal2vulkan-runtime/src/apple_only.rs:207 (check)` -- `apple::ViewportTransformDisabled`: `crates/metal2vulkan-runtime/src/apple_only.rs:204 (check)` -- `apple::VertexAmplificationMode`: `crates/metal2vulkan-runtime/src/apple_only.rs:210 (check)` -- `apple::DepthCleared`: `crates/metal2vulkan-runtime/src/apple_only.rs:212 (check)` -- `apple::StencilCleared`: `crates/metal2vulkan-runtime/src/apple_only.rs:213 (check)` +- `apple::ProtectedContent`: `crates/metal2vulkan-runtime/src/apple_only.rs:189 (check)` +- `apple::LineWidth`: `crates/metal2vulkan-runtime/src/apple_only.rs:191 (check)` +- `apple::ProvokingVertexMode`: `crates/metal2vulkan-runtime/src/apple_only.rs:196 (check)` +- `apple::ViewportTransformDisabled`: `crates/metal2vulkan-runtime/src/apple_only.rs:193 (check)` +- `apple::VertexAmplificationMode`: `crates/metal2vulkan-runtime/src/apple_only.rs:199 (check)` +- `apple::DepthCleared`: `crates/metal2vulkan-runtime/src/apple_only.rs:201 (check)` +- `apple::StencilCleared`: `crates/metal2vulkan-runtime/src/apple_only.rs:202 (check)` - `apple::SurfaceClientDirection`: `crates/metal2vulkan-runtime/src/buffer_texture.rs:417 (new_texture_with_iosurface_plane)` -- `apple::FillUnmeasured`: `crates/metal2vulkan-runtime/src/blit_fill.rs:149 (unmeasured)` -- `bind::DescriptorRangeExceeded`: `crates/metal2vulkan/src/bind/instantiate.rs:653 (bind_buffers)` -- `bind::TexelBufferTooLarge`: `crates/metal2vulkan/src/bind/instantiate.rs:892 (texel_ranges)` +- `bind::DescriptorRangeExceeded`: `crates/metal2vulkan/src/bind/instantiate.rs:652 (bind_buffers)` +- `bind::TexelBufferTooLarge`: `crates/metal2vulkan/src/bind/instantiate.rs:891 (texel_ranges)` - `bind::HeapTooLarge`: `crates/metal2vulkan/src/bind/heap.rs:1014 (new)`; `crates/metal2vulkan/src/bind/heap.rs:1748 (directory_bytes)`; `crates/metal2vulkan/src/bind/heap.rs:1863 (listed_sampler_tables)`; `crates/metal2vulkan/src/bind/heap.rs:1913 (placed)`; `crates/metal2vulkan/src/bind/heap.rs:2069 (heap_elements)`; `crates/metal2vulkan/src/bind/heap.rs:949 (new)`; `crates/metal2vulkan/src/bind/heap.rs:965 (new)` - `bind::TessellationFactorRange`: `crates/metal2vulkan/src/bind/graphics.rs:3551 (patch_binding)` - `bind::PatchIndexRange`: `crates/metal2vulkan/src/bind/graphics.rs:3595 (patch_binding)` - `bind::ControlPointIndexRange`: `crates/metal2vulkan/src/bind/graphics.rs:3633 (patch_binding)` - `bind::MissingStageInRegion`: `crates/metal2vulkan/src/bind/dispatch.rs:802 (instantiate)` -- `bind::UniformViewAliased`: `crates/metal2vulkan/src/bind/instantiate.rs:607 (check_uniform_aliasing)` +- `bind::UniformViewAliased`: `crates/metal2vulkan/src/bind/instantiate.rs:606 (check_uniform_aliasing)` - `bind::MissingDeviceAddress`: `crates/metal2vulkan/src/bind/plan/slots.rs:133 (plan_buffer)` - `limit::InlinedInstructions`: `crates/metal2vulkan-air/src/canon/inline.rs:330 (u32_of)`; `crates/metal2vulkan-air/src/canon/inline.rs:334 (usize_of)`; `crates/metal2vulkan-air/src/canon/inline.rs:61 (inline)` - `limit::OutputBlocks`: `crates/metal2vulkan/src/structurize/irreducible.rs:90 (round)`; `crates/metal2vulkan/src/structurize/mod.rs:187 (structure_prepared)`; `crates/metal2vulkan/src/structurize/structurizer_properties/mod.rs:423 (output_cap_is_checked_before_allocating)`; `crates/metal2vulkan/src/structurize/structurizer_properties/trees.rs:232 (the_output_cap_is_checked_before_emission)` diff --git a/docs/RUNTIME-PORTING.md b/docs/RUNTIME-PORTING.md index 6911b3b5e..43f78da1b 100644 --- a/docs/RUNTIME-PORTING.md +++ b/docs/RUNTIME-PORTING.md @@ -99,8 +99,8 @@ narrow refusal that the call's rustdoc describes. | `EndEncoding` | `endEncoding` | `BlitCommandEncoder::end_encoding` | | `FillBuffer` | `fillBuffer:range:value:` | `BlitCommandEncoder::fill_buffer` | | `FillBufferPattern4` | `fillBuffer:range:pattern4:` (SPI) | `BlitCommandEncoder::fill_buffer_pattern4` | -| `FillTexture` | `fillTexture:level:slice:region:bytes:length:` (SPI) | `BlitCommandEncoder::fill_texture`: every texture type but multisample ones and texture buffers, placed as Metal places it, of the measured formats *(partial)* | -| `FillTextureColor` | `fillTexture:level:slice:region:color:pixelFormat:` (SPI), and `...color:` | `BlitCommandEncoder::fill_texture_color`, packed as Metal's fills pack; a color packed in a format whose fills do not follow the color fills zero bytes (announced, `unpacked-fill-color`), and one the probes did not cover is refused `AppleOnly::FillUnmeasured` *(partial)* | +| `FillTexture` | `fillTexture:level:slice:region:bytes:length:` (SPI) | `BlitCommandEncoder::fill_texture`: every texture type, placed as Metal places it, every format; a multisample texture's samples each take their own bytes of the pattern, as Metal's do; a texture buffer's fill writes its buffer's bytes, the pattern across them, as Metal's does (zeros where Metal's are its stack's, announced, `texture-buffer-fill-leftover`) *(partial)* | +| `FillTextureColor` | `fillTexture:level:slice:region:color:pixelFormat:` (SPI), and `...color:` | `BlitCommandEncoder::fill_texture_color`, packed as Metal's fills pack; a color packed in a format Metal packs none in fills the command buffer's last packed texel (announced, `unpacked-fill-color`) *(partial)* | | `GenerateMipmaps` | `generateMipmapsForTexture:` | `BlitCommandEncoder::generate_mipmaps` *(partial)* | | `InvalidateCompressedTexture` | `invalidateCompressedTexture:` (SPI) | `BlitCommandEncoder::invalidate_compressed_texture`: a no-op (Vulkan shows no compression) | | `InvalidateCompressedTextureSlice` | `invalidateCompressedTexture:slice:level:` (SPI) | `BlitCommandEncoder::invalidate_compressed_texture_slice`: a no-op | diff --git a/scripts/refusal-surface/reach.tsv b/scripts/refusal-surface/reach.tsv index 45dcd7b70..0f02bae5b 100644 --- a/scripts/refusal-surface/reach.tsv +++ b/scripts/refusal-surface/reach.tsv @@ -184,7 +184,6 @@ apple VertexAmplificationMode none Apple-private (no public header) apple DepthCleared none Apple-private (no public header) apple StencilCleared none Apple-private (no public header) apple SurfaceClientDirection none an IOSurface key in no public header -apple FillUnmeasured system Apple-private texture fills, which macOS system software encodes bind DescriptorRangeExceeded app a buffer window past a device's descriptor range bind TexelBufferTooLarge rare a texture buffer past maxTexelBufferElements bind HeapTooLarge rare more resident textures than the pipeline's heap holds (bindless at scale)