From 4551aa9f3cd631aa024de944e99f19c6076f325c Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 22 Nov 2026 22:02:33 -0800 Subject: [PATCH] Float depth upload note: names what each measured device keeps The note RestrictedDepthUpload and the runtime README's known-gap line now say what the upload kept on one card per vendor, under the validation layer 1.4.363.0, on a Private 4x4 Depth32Float filled by a blit's copy_from_buffer with 16 values: - NVIDIA 620.70.06 (RTX 3090, m3-max-69834) kept every value bit for bit and compared it unclamped, as Metal does. - RADV, Mesa 26.2.6 (Radeon 780M, m3-max-69832), and ANV, Mesa 26.2.6 (Iris Xe, m3-max-69833), clamped to [0, 1]. NaN of either sign, -inf, negatives, denormals and -0.0 became +0.0, and +inf with values above 1 became 1.0. Comparisons followed the stored value. - The validation layer reported none of these copies. The note's line "a value within [0, 1] is copied exactly" now excepts a denormal and -0.0, which RADV and ANV store as +0.0. Docs only: artifact.rs, the runtime's texture.rs, docs/API.md, the runtime README. --- crates/metal2vulkan-runtime/README.md | 11 ++++++++--- crates/metal2vulkan-runtime/src/texture.rs | 3 ++- crates/metal2vulkan/src/pipeline/artifact.rs | 11 +++++++---- docs/API.md | 13 ++++++++++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 878282fa4..921c87993 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1694,15 +1694,20 @@ made, with no lock, and never rewritten for layouts. - An upload into a 32-bit float depth (`Depth32Float`, or the depth of `Depth32Float_Stencil8`) by `replace_region`, `upload_region` or a blit's `copy_from_buffer` is the device's copy into the depth aspect, on every device, under the static note `PrecisionNote::RestrictedDepthUpload` - (`Texture::FLOAT_DEPTH_UPLOAD_NOTE`). A value within `[0, 1]` is copied exactly. Metal keeps - every `float` there bit for bit, and its depth comparisons compare it unclamped: measured on an + (`Texture::FLOAT_DEPTH_UPLOAD_NOTE`). A value within `[0, 1]` is copied exactly, except a + denormal or `-0.0`, which a device may store as `+0.0`. Metal keeps every `float` there bit for + bit, and its depth comparisons compare it unclamped: measured on an Apple M3 Max under macOS 27.0.1, and an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 under macOS 26.7.1, for negative values, values above 1, denormals, infinities and NaNs. Vulkan takes no value outside `[0, 1]` into a depth aspect without `VK_EXT_depth_range_unrestricted` (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), which the floor does not require and the runtime enables on no device, and the runtime reads no uploaded value: so on every device, whether or not it offers the extension, a value outside `[0, 1]` is the device's own, and so is - every read, sample, comparison and copy of it. + every read, sample, comparison and copy of it. Measured: NVIDIA's driver (620.70.06, an RTX + 3090) keeps every value bit for bit, as Metal does; RADV and ANV (Mesa 26.2.6, a Radeon 780M and + an Iris Xe) clamp it to `[0, 1]`, store a NaN of either sign, a denormal and `-0.0` as `+0.0`, + and compare what they stored, so a shadow map uploaded outside `[0, 1]` compares otherwise + there. - Their bytes are not copied for a format of depth and stencil both or a multisample texture (`Gap::TextureBytes`). - `Device::pixel_format_info` answers as an Apple M3 Max under macOS 27.0.1, which describes diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index b109e371d..0291e5838 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -4161,7 +4161,8 @@ impl Texture { /// the device's copy into the depth aspect, which Vulkan defines for a value within `[0, 1]` /// alone (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), where Metal keeps every `float`. The /// runtime enables no `VK_EXT_depth_range_unrestricted` and reads no uploaded value, so on - /// every device a texel uploaded outside `[0, 1]` is the device's. + /// every device a texel uploaded outside `[0, 1]` is the device's, and a denormal or `-0.0` + /// may be stored as `+0.0` (docs/API.md's catalogue names what the devices measured keep). pub const FLOAT_DEPTH_UPLOAD_NOTE: PrecisionNote = PrecisionNote::RestrictedDepthUpload; /// `replaceRegion:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage:`: the bytes of diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index ab2da76c6..c7819dd57 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -2084,10 +2084,13 @@ pub enum PrecisionNote { /// a depth aspect without `VK_EXT_depth_range_unrestricted` /// (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), which no runtime enables: a texel uploaded /// outside `[0, 1]` is the device's, and so is every later read, sample, comparison and copy - /// of it. A value within `[0, 1]` is copied exactly, a denormal as `DepthDenormals` says. - /// Static per operation, decided by the format and never by the bytes: no pipeline stage - /// records it; `metal2vulkan-runtime`'s texture carries it - /// (`Texture::FLOAT_DEPTH_UPLOAD_NOTE`). + /// of it. A value within `[0, 1]` is copied exactly, except a denormal or `-0.0`, which a + /// device may store as `+0.0`. Measured: NVIDIA's driver (620.70.06, an RTX 3090) keeps every + /// value bit for bit and compares it as Metal does; RADV and ANV (Mesa 26.2.6, a Radeon 780M + /// and an Iris Xe) clamp a value to `[0, 1]`, store a NaN of either sign, a denormal and `-0.0` + /// as `+0.0`, and compare what they stored. Static per operation, decided by the format and + /// never by the bytes: no pipeline stage records it; `metal2vulkan-runtime`'s texture carries + /// it (`Texture::FLOAT_DEPTH_UPLOAD_NOTE`). /// /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. diff --git a/docs/API.md b/docs/API.md index 8d66fff94..efe6844a4 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1848,9 +1848,16 @@ bound. under macOS 27.0.1, and an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 under macOS 26.7.1: negative values, values above 1, denormals, infinities and NaNs). Vulkan takes no value outside `[0, 1]` into a depth aspect without `VK_EXT_depth_range_unrestricted` - (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), which no runtime enables. Cost: a depth uploaded - outside `[0, 1]` is the device's, and so is every read, sample, comparison and copy of it; one - within it is copied exactly, a denormal as `metal2vulkan-degrade-depth-denormals` says. + (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), which no runtime enables. Measured on a + Private 4 x 4 texture by a blit's copy (16 values: `-0.0`, three denormals of either sign, -1, + -0.25, 2, the next float above 1, 1e30, both infinities, three NaNs, 0.25 and 0.5): NVIDIA's + driver (620.70.06, an RTX 3090) keeps every value bit for bit and compares it unclamped, as + Metal does; RADV (Mesa 26.2.6, the Radeon 780M) and ANV (Mesa 26.2.6, the Iris Xe) store a value + below 0, `-inf` and a NaN of either sign as `+0.0`, one above 1 and `+inf` as 1.0, and a + denormal and `-0.0` as `+0.0`, and compare what they stored; the validation layer reports none + of these copies. Cost: a depth uploaded outside `[0, 1]` is the device's, and so is every read, + sample, comparison and copy of it; one within it is copied exactly, except a denormal or + `-0.0`, which a device may store as `+0.0` (`metal2vulkan-degrade-depth-denormals`). - `metal2vulkan-degrade-cube-gradient-footprint` (precision). `PrecisionNote::CubeGradientFootprint`: An explicit-gradient sample of a cube texture takes Metal's footprint in the form Vulkan's rule reads, in every stage on every device. Cost: the