diff --git a/crates/metal2vulkan/src/lower/sampler/select.rs b/crates/metal2vulkan/src/lower/sampler/select.rs index 79b3002d1..e1efbf2fb 100644 --- a/crates/metal2vulkan/src/lower/sampler/select.rs +++ b/crates/metal2vulkan/src/lower/sampler/select.rs @@ -2188,7 +2188,8 @@ fn select_one( // On a device that samples through Metal's own texture unit, the `half` routine reads an // access's lanes only for a YCbCr field's one texel (`texture::half`): no sampler word decides // them. A slot's texture of a YCbCr format on the grid `8192` (`TexelFormat::YCBCR_8192`) then - // rounds a sample of its one texel to nearest even, where Metal rounds it with ties away, + // takes the device's rounding of a sample of its one texel (toward zero on MoltenVK over the + // M3 Max, measured; unmeasured on other Apple GPUs), where Metal rounds it with ties away, // noted where it is bound. let one_texel = match one_texel { crate::lower::texture::OneTexel::Word(_) diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 3fc35d269..ed9f5d616 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -965,9 +965,11 @@ pub enum PrecisionNote { /// texture record it wherever they are accessed. A two-plane YCbCr texture on the grid `8192` /// (the `_sRGB` twins, the unpacked 12-bit and the extended-range formats) keeps Metal's /// rounding of one texel's step with ties away from zero, but in a sample through a runtime - /// sampler slot: where its word reads one texel, the step rounds to nearest even, one `half` - /// ulp apart at a tie, announced by the runtime at a draw or dispatch that binds such a texture - /// there. + /// sampler slot: where its word reads one texel, the `half` is the device's rounding of the + /// step's `float`, announced by the runtime at a draw or dispatch that binds such a texture + /// there. Measured on MoltenVK 1.4.2 over the Apple M3 Max (macOS 27.0.1): toward zero, within + /// one `half` ulp of Metal's (8,409 channels of the `_sRGB` twins over six surfaces and three + /// matrices, `runtime_lane::ycbcr_textures`); unmeasured on other Apple GPUs. HalfTexelConversion, /// The module samples a texture with a `half` result through a filter (linear minification /// or magnification, a linear mip filter, anisotropy, or a runtime sampler) that Metal's own diff --git a/docs/API.md b/docs/API.md index 9bd74e61d..cd94a2d6e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3116,8 +3116,10 @@ bound. texel is Metal's, announced at a draw or dispatch that binds a texture of a class whose Metal `half` differs from it (a 32-bit float texel's sample, a 16-bit normalized texel, a format not measured) and a two-plane YCbCr texture on the grid `8192` at a slot sampled through a runtime - sampler (a sample of one texel rounds to nearest even, one `half` ulp from Metal's ties-away - rounding at a tie); a heap element or a depth texture wherever it is accessed. + sampler (a sample of one texel is the device's rounding of its step: toward zero on MoltenVK + 1.4.2 over the Apple M3 Max, within one `half` ulp of Metal's ties-away rounding, measured over + 8,409 channels; unmeasured on other Apple GPUs); a heap element or a depth texture wherever it + is accessed. - `metal2vulkan-degrade-half-sample-filter` (precision). `PrecisionNote::HalfSampleFilter`: The module samples a texture with a `half` result through a filter (linear minification or magnification, or a runtime sampler) that Metal's own sampler (MoltenVK) answers otherwise than diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index 484ad9602..b962f1ea2 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -64,7 +64,7 @@ known. The rest of the differences are docs/API.md section 9's precision notes. | Samples, gathers, depth comparisons and level queries are the device's own sampler's on every device whose sampler is not Metal's (every device but MoltenVK): its filter, footprint, level, anisotropy, sRGB decode and comparison, its level clamp (the descriptor's as given, which Metal holds on a `1/64` grid) and its reading of a subnormal coordinate (which Metal reads as the zero of its sign before addressing). A sample's or gather's residency on a device with `shaderResourceResidency` is the device's `OpImageSparse*` word and non-resident value (`SparseResidency`); Metal's footprint rule answers it only where the device has no residency and the slot's tile map does. A two-plane YCbCr texture's linear sample is the device's filter of its texels (the device's own Y′CbCr conversion's where it converts the format, next row; Metal's reads exactly elsewhere); where the device's memory is the host's, a sample that reads the planes in place is Metal's filter exactly. An 8-bit sRGB format the device cannot sample (`R8_SRGB` on lavapipe, `R8G8_SRGB` on lavapipe, ANV and NVIDIA) is held as its UNORM twin, the device lacking its decode: a read, a sample, a fetch, a gather and a bicubic tap decode what the twin's view reads (one texel's codes, or the device's filter of them) by the MSL transfer through the device's `Pow`. | The device's sampler is the contract. | Linear filter within one code (1/255) on the measured devices, sRGB within 1.83, a two-plane YCbCr texture's within 1.183; levels, anisotropy, cubes, 3D, gathers and comparisons unmeasured. A twin's texel: the transfer within the device's `Pow` (MoltenVK's within 1.83e-7 through a storage alias, `runtime_lane::srgb_storage`) where Metal's table rounds it to a twelve-bit step (up to 1/8190 apart); a filtered sample decodes the filtered codes, up to 0.286 off for a blend of codes 0 and 255 (`SrgbTexelDecode`). `DeviceSampling` (`device-sampling`) | | A pixel-coordinate sampler's linear sample, gather, comparison and level query is the device's normalized sampler's at the coordinate divided by the texture's level-0 size in the shader, on every device, MoltenVK included, where no other form takes it: through a runtime sampler slot or an argument buffer's sampler, whose state the function does not know, and through a constexpr one of an array, a 3D texture or a texture whose residency the function observes. The device reads its texels and weights from that coordinate in its own arithmetic, where Metal's sampler reads the coordinate as given on its own sub-texel grid. A constexpr pixel sampler's sample or gather of a 1D or 2D texture that is no array hands the coordinate itself, moved by its offset, to the device's unnormalized sampler at level 0 (a nearest sample with an offset its texel's centre `floor(x) + 0.5 + k`), which reads it as Metal's does on MoltenVK; a nearest sample elsewhere hands the device's normalized sampler its texel's centre `floor(x) + 0.5` over the size, where the device reads exactly Metal's texel `floor(x)` (a runtime slot's behind its `NearestPixelSampler` specialization, an argument buffer's by its state's word); a constexpr sampler that filters nearest and clamps to the edge fetches its texel (`sampler.pixel_fetch`). | The device's sampler is the contract. Vulkan's unnormalized samplers take no offset operand, comparison, array, 3D image, mip level or anisotropy, and a runtime or argument buffer's state is not known when the function is made, so the shader scales the coordinate there; no path reproduces Metal's sub-texel grid. | The device answers as its normalized sampler at a coordinate within one `f32` ulp of the quotient on MoltenVK (10 of 800 cells of each mirror-clamp linear configuration move by it) and at the quotient itself on lavapipe (`runtime_lane::pixel_samplers`: 800 coordinates at and around each texel edge of a 5x3 texture, every filter and address mode); on MoltenVK a linear sample through a runtime or argument buffer's sampler, or of an array, reads another weight step than Metal's at under 1% of the coordinates at and around each texel edge of textures 258, 21 and 37 texels wide, where `x - 0.5` lies at a half step of Metal's `1/256` grid (`runtime_lane::pixel_edges`); a linear downscale by 8 of textures 1000 to 1920 texels wide within 1/255 of Metal's on MoltenVK and 2/255 on lavapipe (`runtime_lane::pixel_downscales`); other devices unmeasured. Every nearest access of those edge probes reads Metal's texel on MoltenVK and on lavapipe, and every constexpr sample and gather of a 1D or 2D texture answers Metal's on MoltenVK (`runtime_lane::pixel_edges`); elsewhere a constexpr linear sample is the device's own filter in unnormalized coordinates (`device-sampling`), which on lavapipe differs from its normalized filter in the last bits of 79 to 107 of 800 cells of clamp to zero and to the border (`runtime_lane::pixel_samplers`). `PixelSamplerScaling` (`pixel-sampler-scaling`), `ArgumentPixelSamplerScaling` (`argument-pixel-sampler-scaling`) | | A two-plane YCbCr texture's texels are the device's own sampler Y′CbCr conversion of its planes where the device converts their format (`ycbcr_device.rs`): unpacked 8- or 10-bit codes of a 4:2:0, 4:2:2 or 4:4:4 layout over plane 0 that form one image (no chroma codes 0, no rows past the buffer; a 4:4:4 layout read as codes aside, whose identity conversion converts nothing), on a device that enables `samplerYcbcrConversion` (a 4:4:4 layout also needs Vulkan 1.3 or `VK_EXT_ycbcr_2plane_444_formats`), reports the multi-planar format's conversion and, for a 4:2:0 or 4:2:2 layout, Metal's reconstruction (midpoint chroma through a linear chroma filter), and has no defect in the format; the planes are copied into an image of it and sampled once per texel into the texture's image (`bind::ycbcr_sample_module`), through the refresh's indirect arguments. The conversion takes the surface's matrix and range (the identity model for the code-reading formats), and Metal's reconstruction of a subsampled layout; a device's cosited or nearest reconstruction would move what the codes mean to Metal (cosited, up to 1340/2048 of random planes on lavapipe), a capability it lacks, so such a layout converts through Metal's arithmetic. A render pass's load stays Metal's arithmetic, which our store inverts, so a loaded texel no draw changes keeps its codes, as `MTLLoadActionLoad` keeps the attachment's contents. lavapipe (Mesa 26.0.8) converts the 8-bit 4:4:4 layout (its 4:2:0 and 4:2:2 ones are cosited only, and it reads 10-bit codes as 16-bit words, `RuntimeDriverDefect::TenBitCodesReadAsWords`); MoltenVK 1.4.2 converts none (its 4:2:0 and 4:2:2 reconstruction is misplaced, `RuntimeDriverDefect::TwoPlaneChromaMisplaced`, and it reports no 4:4:4 two-plane format). RADV (Mesa 26.2.4) reads 10-bit codes as 16-bit words too (measured on a linear image of the 4:2:0 format on the Radeon 780M), so its 10-bit layouts convert through Metal's arithmetic; so do NVIDIA's (615.71.09, RTX 5080 Laptop GPU), whose conversion reads a 10-bit code's six unused low bits as its fraction, and which converts the 8-bit 4:2:0, 4:2:2 and 4:4:4 layouts. Elsewhere, and for packed codes, chroma codes 0 and plane 1, Metal's fixed-point conversion stays as capability (`WorkCounts::ycbcr_device_conversions`). | The device's conversion is the contract: Vulkan states the reconstruction's weights and the model's matrices, the precision of each step at least the format's, and the clamp of the result into `[0, 1]` the implementation's. | Each channel within 0.04/2048 of Vulkan's conversion past the `half` its image stores on lavapipe's 8-bit 4:4:4 layout, and within 0.034/2048 on NVIDIA's 8-bit layouts; of Metal's read within 6/2048 where the result lies in `[0, 1]` on lavapipe, 12.4/2048 on NVIDIA's 4:2:0 (19.1 through an `_sRGB` twin's curve; Metal rounds each reconstructed chroma to a code), and unclamped outside it; a code-reading format's codes the nearest to Vulkan's reconstruction, NVIDIA's Metal's (random planes, every texel, `tests/ycbcr_device.rs`). `YCbCrFilterNotExact` (`ycbcr-filter-not-exact`) | -| A texel's `float` value is the device's conversion of its codes on every device whose texture unit is not Metal's (every device but MoltenVK), and a `half` result the device's `float` texel rounded to nearest even on every device: on MoltenVK the `float` texel is Metal's, whose `half` Metal rounds otherwise for a 32-bit float texel's sample (toward zero, saturating at `±65504`) and the 16-bit normalized grids (three steps round twice through `float`); a two-plane YCbCr field on the grid `8192` keeps Metal's ties away from zero in one texel's read, sample and gather. An sRGB texel (the 8-bit sRGB formats, and the sRGB forms of BC1 to BC3, BC7, PVRTC, ETC2, EAC and ASTC, a decoded twin's through its `R8G8B8A8_SRGB` view) is the device's sRGB decode through the texture's sRGB view, in every read, sample, gather, bicubic tap and input-attachment read, where Metal decodes each code through its twelve-bit table; so is a resolve's into an 8-bit UNORM attachment's sRGB twin, which decodes the samples and encodes their average through the twin's sRGB views where Metal's resolve takes its own tables (`DeviceRoundedResolve`). An 8-bit sRGB storage texture held through its UNORM alias (Vulkan has no sRGB storage view) reads its codes by the MSL transfer through the device's `Pow`, and writes them by that transfer and `PackUnorm4x8` (`DevicePackConversion`). | The device's conversion is the contract. | One `f32` ulp for 8- and 16-bit codes, and for 10-bit ones but where the device replicates their bits to 16 (NVIDIA's RTX 5080 Laptop GPU: 0.015 of a code); 0.18 of a code for 5- and 6-bit packed channels; `half` within one ulp, but a 32-bit float texel's sample past `±65504` the infinity of its sign where Metal saturates (MoltenVK included); NaN bits the device's. An sRGB decode: lavapipe's within 5.25 steps of Metal's table (0.00128) at every code, MoltenVK's Metal's at every code (`runtime_lane::srgb_decode`); Vulkan sets no precision for it, and other devices are not measured. `DeviceTexelConversion` (`device-texel-conversion`), `HalfTexelConversion` (`half-texel-conversion`, also recorded for heap textures and unmeasured formats), `SrgbTexelDecode` (`srgb-texel-decode`, under the bound format) | +| A texel's `float` value is the device's conversion of its codes on every device whose texture unit is not Metal's (every device but MoltenVK), and a `half` result the device's `float` texel rounded to nearest even on every device: on MoltenVK the `float` texel is Metal's, whose `half` Metal rounds otherwise for a 32-bit float texel's sample (toward zero, saturating at `±65504`) and the 16-bit normalized grids (three steps round twice through `float`); a two-plane YCbCr field on the grid `8192` keeps Metal's ties away from zero in one texel's read, sample and gather, but in a sample through a runtime sampler slot, whose `half` is the device's rounding of the step (toward zero on MoltenVK 1.4.2 over the Apple M3 Max, measured over 8,409 channels by `runtime_lane::ycbcr_textures`; unmeasured on other Apple GPUs). An sRGB texel (the 8-bit sRGB formats, and the sRGB forms of BC1 to BC3, BC7, PVRTC, ETC2, EAC and ASTC, a decoded twin's through its `R8G8B8A8_SRGB` view) is the device's sRGB decode through the texture's sRGB view, in every read, sample, gather, bicubic tap and input-attachment read, where Metal decodes each code through its twelve-bit table; so is a resolve's into an 8-bit UNORM attachment's sRGB twin, which decodes the samples and encodes their average through the twin's sRGB views where Metal's resolve takes its own tables (`DeviceRoundedResolve`). An 8-bit sRGB storage texture held through its UNORM alias (Vulkan has no sRGB storage view) reads its codes by the MSL transfer through the device's `Pow`, and writes them by that transfer and `PackUnorm4x8` (`DevicePackConversion`). | The device's conversion is the contract. | One `f32` ulp for 8- and 16-bit codes, and for 10-bit ones but where the device replicates their bits to 16 (NVIDIA's RTX 5080 Laptop GPU: 0.015 of a code); 0.18 of a code for 5- and 6-bit packed channels; `half` within one ulp, but a 32-bit float texel's sample past `±65504` the infinity of its sign where Metal saturates (MoltenVK included); NaN bits the device's. An sRGB decode: lavapipe's within 5.25 steps of Metal's table (0.00128) at every code, MoltenVK's Metal's at every code (`runtime_lane::srgb_decode`); Vulkan sets no precision for it, and other devices are not measured. `DeviceTexelConversion` (`device-texel-conversion`), `HalfTexelConversion` (`half-texel-conversion`, also recorded for heap textures and unmeasured formats), `SrgbTexelDecode` (`srgb-texel-decode`, under the bound format) | | A texture of a BC format (`BC1_RGBA` to `BC7_RGBAUnorm_sRGB`) is the device's decode of its own BC image on every device: where its driver is not measured to decode the format as Metal does (BC1 to BC3 off MoltenVK and RADV on the 780M; BC4 and BC5 off MoltenVK; BC7 on lavapipe), its reads, samples and gathers answer the device's interpolation of the blocks, where Metal's weights are 6-bit (an sRGB form's code then through the device's sRGB decode, the texel-conversion row). No BC texture keeps a decoded twin. | The device has the format: its decode is the contract. | A BC1 to BC3 channel within 3/255 of Metal's on NVIDIA (BC3's alpha 6/255) and lavapipe, 1/255 on ANV; a BC4 or BC5 channel within 7.3/255 (signed 0.064) on NVIDIA, 1.3/255 (signed 0.013) on ANV, 2.4/255 (signed 0.022) on lavapipe, a signed one with an endpoint of -128 within 1.7/255 on RADV; a BC7 channel a `float` ulp on lavapipe; other drivers unmeasured. `CompressedTexelDecode` (`compressed-texel-decode`) | | A vertex attribute that fixed-function vertex input fetches is the device's conversion of its format: a normalized one (`UCharNormalized` through `Short4Normalized` of either sign, `UChar4Normalized_BGRA`, `Int1010102Normalized`, `UInt1010102Normalized`) through its own Vulkan `UNORM` or `SNORM` vertex format, where Metal divides each code by its maximum correctly rounded (an `Int1010102Normalized` 10-bit field it multiplies by `float(1 / 511)` in `float`) and rounds the quotient once to a `half` attribute; a narrow float's (a `half` format, `FloatRG11B10`) read as `float` by the device's widening, NaNs included. The format is `VertexAttribute` state that no instruction names, so every format the device fetches shares one module, and the render pipeline's link notes the conversion on its vertex stage (`pipeline::link::vertex`). A normalized attribute the shader pulls instead (an offset, stride or step fixed-function input cannot fetch, a kernel's `[[stage_in]]` attribute) is the module's product of the code and its maximum's reciprocal, `float(c) · float(1 / (2^b - 1))`, the signed one clamped to -1 (`lower::stage_io::fetch`), noted by the function on every device where it misses Metal's fetch. **Exempt:** a normalized attribute on a profile that takes `DriverDeviation::MetalNormalizedVertexFetch`, MoltenVK on Apple's GPUs of the Apple M3 Max's macOS 27 identity, which hands the format to Metal's own fetch and was measured to answer Metal's `float` at every code of all 19 normalized formats, per vertex and per instance (`runtime_lane::normalized_vertex_fetch`): its pipeline records no note and requires `VkProperty::MetalNormalizedVertexFetch`, but for a 16-bit format read as `half`, whose `float` the module rounds to `half` again. | The device's conversion is the contract. | One `f32` ulp at some codes on a driver that multiplies by the reciprocal: llvmpipe, read at every code (Mesa 26.0.8 on LLVM 21.1.8, arm64), is within one ulp per vertex at every normalized format (127/255 as `0x3EFEFF00` where Metal reads `0x3EFEFEFF`; `Int1010102Normalized` Metal's), and per instance reads the most negative code of an 8- or 16-bit signed format unclamped (-128/127, -32768/32767) where Metal reads -1; RADV's unsigned formats are Metal's at the sites measured. A 16-bit format read as `half`: one `half` ulp at codes 65455 and 65519 unsigned, 32759 and -32759 signed, on a device whose `float` is Metal's (the quotient rounded to `half` twice). The signed formats are **unaudited** on RADV, ANV and NVIDIA. A pulled attribute's product, on every device: one `f32` ulp from Metal's quotient at 126 of the 256 8-bit unsigned codes (high), and toward zero at 16 signed 8-bit codes, 24 unsigned 10-bit codes, 512 unsigned and 1,536 signed 16-bit codes; `Int1010102Normalized` read as `float`, and an 8- or 10-bit format read as `half`, Metal's at every code; a 16-bit format read as `half`, one `half` ulp at the same four codes. A narrow float's NaN is the device's widening's, where Metal answers `0x7fc00000`. `DeviceVertexConversion` (`device-vertex-conversion`), `DeviceNanEncoding` (`device-nan-encoding`) | | A texture of an ASTC LDR format on a device without that ASTC format reads a decoded twin of 8-bit codes, each channel the code nearest Metal's 12-bit value (`C >> 4` over 4095); an sRGB form's twin holds Metal's own 8-bit codes, which its slots read through the twin's `R8G8B8A8_SRGB` view, the device's sRGB decode (the texel-conversion row). A texture of an EAC 11-bit format (`R11`, `RG11`, unsigned and signed) on a device without ETC2 reads one of 16-bit normalized codes, each nearest Metal's value (`c / 2047`, signed `c / 1023`). | The device lacks the format; the twin's codes are the compact form the device samples. | Within 1/510 of Metal's value; an EAC 11-bit channel within half a 16-bit step (1/131070, signed 1/65534). `decoded-texel-precision`, announced where a command first reads the twin (a sampled binding of the texture, or a heap set holding it), not where the texture is made |